Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
5a5cbea
change memory layout for lists
lim-rachel May 31, 2022
3b42b91
add tests from lists-design that were previously behaving undesireably
lim-rachel May 31, 2022
a935adf
Clean up package.json and update Lezer
xChickens May 25, 2022
aa38583
Move all designs into designs folder
xChickens May 25, 2022
287c741
Better test command and update package-lock.json
xChickens Jun 1, 2022
582d898
Update to new error-reporting interface
xChickens Jun 1, 2022
ad1993a
Reorder imports and clean unneccesary ones
xChickens Jun 1, 2022
6251de1
Remove settings from vscode folder
xChickens Jun 1, 2022
8f151b4
Merge remote-tracking branch 'upstream/2022' into 2022
xChickens Jun 1, 2022
3e6c0b4
Remove coverage from git
xChickens Jun 1, 2022
f13b91f
Negative index rectification
xChickens Jun 1, 2022
7f4d65c
add list.wat
Jun 1, 2022
0414a1d
update lezer version
Jun 1, 2022
a6174bf
solve print bug
Jun 1, 2022
045882d
Add slice parsing
xChickens Jun 1, 2022
e442d3d
Merge remote-tracking branch 'upstream/2022' into 2022
xChickens Jun 1, 2022
a441d4f
Add index slicing type-check
xChickens Jun 1, 2022
61f9bcb
Add new test cases
xChickens Jun 1, 2022
d444d2d
Add print functionality (for numbers only)
xChickens Jun 1, 2022
8d43b65
Make list into a class
xChickens Jun 1, 2022
590295c
Add printing of all types
xChickens Jun 1, 2022
5dbab52
add append
Jun 1, 2022
f3447f5
Add positive list slicing
xChickens Jun 2, 2022
7dc5ac4
Fix negative indexing, and add correct default values
xChickens Jun 2, 2022
a303cf8
Add wat for copy, type-check still doesn't work
xChickens Jun 2, 2022
f85bdb7
add insert, tc for copy not solved
Jun 2, 2022
aad2828
add pop, tc for copy not solved
Jun 2, 2022
7733254
fix pop with 0 argument in tc, tc for copy not solved
Jun 2, 2022
26048bb
Merge remote-tracking branch 'upstream/2022' into 2022
xChickens Jun 2, 2022
98e0249
fix copy
Jun 2, 2022
5150e10
Merge branch '2022' of https://github.com/lim-rachel/chocopy-wasm-com…
Jun 2, 2022
5db3c49
list concat
lim-rachel Jun 2, 2022
8dbb6fb
Merge branch '2022' of https://github.com/lim-rachel/chocopy-wasm-com…
lim-rachel Jun 2, 2022
e71b62f
Fix some stuff
xChickens Jun 2, 2022
0407af9
Fix all tests
xChickens Jun 2, 2022
a215a8d
Reset sets function imports
xChickens Jun 2, 2022
cf88785
BuiltinLib must be imported after BasicREPL
xChickens Jun 6, 2022
792f10c
Implement list constructor
xChickens Jun 7, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ mochawesome-report
**/*.svg
!/designs/example.svg
**/.DS_Store
.vscode
.vscode
.nyc_output
coverage
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
stdlib: build/memory.wasm build/sets.wasm

stdlib: build/memory.wasm build/sets.wasm build/list.wasm

build/%.wasm: stdlib/%.wat
mkdir -p build/
npx wat2wasm $< -o $@
npx wat2wasm $< -o $@
7 changes: 3 additions & 4 deletions ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ export type Type =
| {tag: "number"}
| {tag: "bool"}
| {tag: "none"}
| {tag: "list", type: Type}
| {tag: "class", name: string, genericArgs?: Array<Type>}
| {tag: "class", name: string, genericArgs?: Array<Type>, type?: Type}
| {tag: "either", left: Type, right: Type }
| {tag: "generator", type: Type } // generator type
| {tag: "set", valueType: Type }
Expand Down Expand Up @@ -46,7 +45,7 @@ export type Expr<A> =
| { a?: A, tag: "call", name: string, arguments: Array<Expr<A>>, genericArgs?: Array<Type>}
| { a?: A, tag: "lookup", obj: Expr<A>, field: string }
| { a?: A, tag: "listliteral", elements: Array<Expr<A>> }
| { a?: A, tag: "index", obj: Expr<A>, index: Expr<A> }
| { a?: A, tag: "index", obj: Expr<A>, index: Expr<A>, end?: Expr<A>, steps?: Expr<A> }
| { a?: A, tag: "method-call", obj: Expr<A>, method: string, arguments: Array<Expr<A>> }
| { a?: A, tag: "construct", name: string }
| { a?: A, tag: "set", values: Array<Expr<A>>}
Expand Down Expand Up @@ -74,4 +73,4 @@ export type DestructureLHS<A> = { a?: A, lhs: AssignTarget<A>, isStarred : boole
export type AssignTarget<A> =
| { a?: A, tag : "id", name : string}
| { a?: A, tag : "lookup", obj: Expr<A>, field: string }
| { a?: A, tag: "index", obj: Expr<A>, index: Expr<A> }
| { a?: A, tag: "index", obj: Expr<A>, index: Expr<A> }
58 changes: 36 additions & 22 deletions compiler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Program, Stmt, Expr, Value, Class, VarInit, FunDef } from "./ir"
import { BinOp, Type, UniOp, SourceLocation } from "./ast"
import { BOOL, NONE, NUM } from "./utils";
import { BinOp, SourceLocation, Type, UniOp } from "./ast";
import { RunTimeError } from "./error_reporting";
import { Class, Expr, FunDef, Program, Stmt, Value, VarInit } from "./ir";
import { equalType } from "./type-check";
import { BOOL, CLASS, PrintType, NONE, NUM } from "./utils";

export type GlobalEnv = {
globals: Map<string, boolean>;
Expand Down Expand Up @@ -86,7 +87,7 @@ function codeGenStmt(stmt: Stmt<[Type, SourceLocation]>, env: GlobalEnv): Array<
...codeGenValue(stmt.start, env),
...codeGenValue(stmt.offset, env),
...codeGenValue(stmt.value, env),
`call $store`
`(call $store)`
]
case "assign":
var valStmts = codeGenExpr(stmt.value, env);
Expand Down Expand Up @@ -165,18 +166,35 @@ function codeGenExpr(expr: Expr<[Type, SourceLocation]>, env: GlobalEnv): Array<
}
var valStmts = expr.arguments.map(arg=>{
let argCode = codeGenValue(arg, env);
switch (arg.a[0]){
case NUM:
argCode.push("(call $print_num)");
break;
case BOOL:
argCode.push("(call $print_bool)");
break;
case NONE:
argCode.push("(call $print_none)");
break;
default:
throw new RunTimeError("not implemented object print")
if (arg.a[0].tag === "class" && arg.a[0].name === "list") {
var typeToPrint = 0;
var listType = arg.a[0].type;
while (listType.tag === "class" && listType.name === "list") {
typeToPrint += PrintType["list"];
listType = listType.type;
}
if (listType.tag in PrintType) {
typeToPrint += PrintType[listType.tag as keyof typeof PrintType];
}
else {
throw new RunTimeError("List print type not supported: " + listType.tag);
}
argCode.push(`(i32.const ${typeToPrint})`);
argCode.push("(call $print_list)");
} else {
switch (arg.a[0]){
case NUM:
argCode.push("(call $print_num)");
break;
case BOOL:
argCode.push("(call $print_bool)");
break;
case NONE:
argCode.push("(call $print_none)");
break;
default:
throw new RunTimeError("not implemented object print")
}
}
argCode.push("drop");
return argCode;
Expand All @@ -186,24 +204,20 @@ function codeGenExpr(expr: Expr<[Type, SourceLocation]>, env: GlobalEnv): Array<
var valStmts = expr.arguments.map((arg) => codeGenValue(arg, env)).flat();
valStmts.push(`(i32.const ${expr.a[1].line})`);
valStmts.push(`(call $stack_push)`);
if(expr.name === 'assert_not_none'){
valStmts.push(`(i32.const ${expr.a[1].line})(i32.const ${expr.a[1].column}) `);
}
valStmts.push(`(call $${expr.name})`);
return valStmts;

case "alloc":
return [
...codeGenValue(expr.amount, env),
`call $alloc`
`(call $alloc)`
];
case "load":
return [
...codeGenValue(expr.start, env),
`(i32.const ${expr.a[1].line})(i32.const ${expr.a[1].column}) (call $assert_not_none)`,
// `call $assert_not_none`,
...codeGenValue(expr.offset, env),
`call $load`
`(call $load)`
]
}
}
Expand Down
21 changes: 4 additions & 17 deletions debugstart.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
import { parser } from "@lezer/python";
import { parse } from "./parser";
import { BasicREPL } from "./repl";
import { importObject, addLibs } from "./tests/import-object.test";
import { stringifyTree } from "./treeprinter";

// entry point for debugging
async function debug() {
var source = `
a: [int] = None
set_x: set[int] = None
set_x = set([1,2,3])
set_x.update([2,3,4])
print(set_x)
a = [1, 2, 3]
a.insert(1, 6)
`

// set_1 : set[int] = None
// a : int = 0
// b : bool = True
// l: [int] = None
// set_1 = set([1, 2, 3])

// set_1.add(3)
// set_1.add(3)
// set_1.remove(1)
// a = len(set_1)
// b = 1 in set_1
// print(a)
// print(b)
const ast = parse(source);
console.log(`AST: \n ${ast}`)

Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions design/frontEnd-design.md → designs/front-end-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ We will implement the render to hanle other objects like list, string and dictio
### 8. highlight the error area

shown in the picture below, CodeMirror is able to underline the error
![underline error](./Screen%20Shot%202022-05-20%20at%2023.59.27.png)
![underline error](./front-end-error-highlighting.png)

### 9. front end test

Our team have comunicated with team A and find that there is a tool called [phantomjs](https://learnku.com/docs/node-lessons/browser-side-test-mocha-chai-phantomjs/6131) for front end testing.


The overall front page will looks like below:
![final front end](./Screen%20Shot%202022-05-21%20at%2000.09.37.png)
![final front end](./front-end-final-design.png)
1 change: 1 addition & 0 deletions designs/lists-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ print(b)
a: [int] = None
a = [1, 2, 3]
a.insert(1, 4)
print(a)
```
*Output:*
```
Expand Down
1 change: 0 additions & 1 deletion error_reporting.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { SourceLocation } from "./ast";
import { stackTrace } from "./runtime_error";

export class CompileTimeError extends Error {
__proto__: Error
Expand Down
2 changes: 1 addition & 1 deletion ir.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Type, BinOp, UniOp, Parameter} from './ast';
import { BinOp, Parameter, Type, UniOp } from './ast';

export type Program<A> = { a: A, funs: Array<FunDef<A>>, inits: Array<VarInit<A>>, classes: Array<Class<A>>, body: Array<BasicBlock<A>> }

Expand Down
Loading