Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closures & First-class Functions - Milestone 2 Implementation #84

Open
wants to merge 21 commits into
base: 2022
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 removed .DS_Store
Binary file not shown.
26 changes: 0 additions & 26 deletions .vscode/launch.json

This file was deleted.

2 changes: 1 addition & 1 deletion ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export type AssignVar<A> = { a?: A, target: Assignable<A>, ignorable: boolean, s
export type Lambda<A> = { a?: A, tag: "lambda", params: Array<string>, type: Callable, expr: Expr<A> };
export type Expr<A> =
{ a?: A, tag: "literal", value: Literal<A> }
| { a?: A, tag: "id", name: string }
| { a?: A, tag: "id", name: string, transform?: boolean }
| { a?: A, tag: "binop", op: BinOp, left: Expr<A>, right: Expr<A>}
| { a?: A, tag: "uniop", op: UniOp, expr: Expr<A> }
| { a?: A, tag: "builtin1", name: string, arg: Expr<A> }
Expand Down
9 changes: 8 additions & 1 deletion compiler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Program, Stmt, Expr, Value, Class, VarInit, FunDef } from "./ir"
import { Annotation, BinOp, Type, UniOp } from "./ast"
import * as AST from "./ast";
import { APPLY, BOOL, createMethodName, makeWasmFunType, NONE, NUM } from "./utils";
import { equalType } from "./type-check";

Expand All @@ -12,6 +13,9 @@ export type GlobalEnv = {
labels: Array<string>;
offset: number;
vtableMethods: Array<[string, number]>;
nonlocalMap: Map<string, Map<string, [ancestorList: string[], isFunction: boolean, funName: string]>>;
lambdaStack: Array<AST.FunDef<Annotation>>;
ancestorMap: Map<string, Array<AST.FunDef<Annotation>>>;
}

export const emptyEnv : GlobalEnv = {
Expand All @@ -22,7 +26,10 @@ export const emptyEnv : GlobalEnv = {
locals: new Set(),
labels: [],
offset: 0,
vtableMethods: []
vtableMethods: [],
nonlocalMap: new Map(),
lambdaStack: [],
ancestorMap: new Map(),
};

type CompileResult = {
Expand Down
Loading