add sourcemaps

This commit is contained in:
SimonFJ20 2024-12-13 10:26:34 +01:00
parent da1dbb92cd
commit 3032f0867c
2 changed files with 32 additions and 22 deletions

View File

@ -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[];

View File

@ -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);