try adding more sourcemap

This commit is contained in:
SimonFJ20 2024-12-13 11:09:16 +01:00
parent 88e08db57e
commit c86cf105b9

View File

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