diff --git a/compiler/lowerer.ts b/compiler/lowerer.ts index ac7e7af..685558b 100644 --- a/compiler/lowerer.ts +++ b/compiler/lowerer.ts @@ -15,7 +15,7 @@ export class Lowerer { public constructor(private lastPos: Pos) {} public lower(stmts: Stmt[]) { - this.addSourceMap({ index: 0, line: 1, col: 1 }); + this.addClearingSourceMap(); this.program.add(Ops.PushPtr, { label: "_start" }); this.program.add(Ops.Jump); this.scoutFnHeaders(stmts); @@ -37,6 +37,10 @@ export class Lowerer { this.program.add(Ops.SourceMap, index, line, col); } + private addClearingSourceMap() { + this.program.add(Ops.SourceMap, 0, 1, 1); + } + private scoutFnHeaders(stmts: Stmt[]) { for (const stmt of stmts) { if (stmt.kind.type !== "fn") { @@ -123,6 +127,7 @@ export class Lowerer { if (stmt.kind.expr) { this.lowerExpr(stmt.kind.expr); } + this.addClearingSourceMap(); this.program.add(Ops.PushPtr, this.breakStack.at(-1)!); this.program.add(Ops.Jump); } @@ -374,12 +379,14 @@ export class Lowerer { this.lowerExpr(expr.kind.cond); this.program.add(Ops.Not); + this.addClearingSourceMap(); this.program.add(Ops.PushPtr, falseLabel); this.program.add(Ops.JumpIfTrue); this.addSourceMap(expr.kind.truthy.pos); this.lowerExpr(expr.kind.truthy); + this.addClearingSourceMap(); this.program.add(Ops.PushPtr, doneLabel); this.program.add(Ops.Jump); @@ -408,9 +415,11 @@ export class Lowerer { this.addSourceMap(expr.kind.body.pos); this.lowerExpr(expr.kind.body); this.program.add(Ops.Pop); + this.addClearingSourceMap(); this.program.add(Ops.PushPtr, contineLabel); this.program.add(Ops.Jump); this.program.setLabel(breakLabel); + this.addSourceMap({ index: 0, line: 1, col: 1 }); if (expr.vtype!.type === "null") { this.program.add(Ops.PushNull); }