diff --git a/compiler/ast.ts b/compiler/ast.ts index bb29a98..38bfe0a 100644 --- a/compiler/ast.ts +++ b/compiler/ast.ts @@ -8,28 +8,6 @@ export type File = { stmts: Stmt[]; }; -export type UnaryType = "not"; -export type BinaryType = - | "+" - | "*" - | "==" - | "-" - | "/" - | "!=" - | "<" - | ">" - | "<=" - | ">=" - | "or" - | "and"; - -export type Param = { - ident: string; - etype?: EType; - pos: Pos; - vtype?: VType; -}; - export type Stmt = { kind: StmtKind; pos: Pos; @@ -83,6 +61,28 @@ export type ExprKind = sym: Sym; }; +export type UnaryType = "not"; +export type BinaryType = + | "+" + | "*" + | "==" + | "-" + | "/" + | "!=" + | "<" + | ">" + | "<=" + | ">=" + | "or" + | "and"; + +export type Param = { + ident: string; + etype?: EType; + pos: Pos; + vtype?: VType; +}; + export type Sym = { ident: string; pos?: Pos; @@ -108,6 +108,12 @@ export type ETypeKind = | { type: "array"; inner: EType } | { type: "struct"; fields: Param[] }; +export type ETypeParam = { + ident: string; + pos: Pos; + vtype?: VType; +}; + export type Anno = { ident: string; values: Expr[]; diff --git a/compiler/lowerer.ts b/compiler/lowerer.ts index c4dd06f..62fe2e7 100644 --- a/compiler/lowerer.ts +++ b/compiler/lowerer.ts @@ -136,6 +136,7 @@ export class Lowerer { ? "main" : `${stmt.kind.ident}_${stmt.id}`; this.program.setLabel({ label }); + this.addSourceMap(stmt.pos); const outerLocals = this.locals; const fnRoot = new LocalsFnRoot(outerLocals); @@ -377,6 +378,7 @@ export class Lowerer { this.program.add(Ops.PushPtr, falseLabel); this.program.add(Ops.JumpIfTrue); + this.addSourceMap(expr.kind.truthy.pos); this.lowerExpr(expr.kind.truthy); this.program.add(Ops.PushPtr, doneLabel); @@ -385,6 +387,7 @@ export class Lowerer { this.program.setLabel(falseLabel); if (expr.kind.falsy) { + this.addSourceMap(expr.kind.truthy.pos); this.lowerExpr(expr.kind.falsy!); } else { this.program.add(Ops.PushNull); @@ -403,6 +406,7 @@ export class Lowerer { this.breakStack.push(breakLabel); this.program.setLabel(contineLabel); + this.addSourceMap(expr.kind.body.pos); this.lowerExpr(expr.kind.body); this.program.add(Ops.Pop); this.program.add(Ops.PushPtr, contineLabel);