Compare commits

..

No commits in common. "ba4861a5fb8cef7e5f85d22015dc94aeaa923741" and "e581c245bd02a7502de34ac5998a62e256284b58" have entirely different histories.

5 changed files with 5 additions and 7 deletions

View File

@ -45,7 +45,7 @@ export type ExprKind =
| { type: "call"; subject: Expr; args: Expr[] } | { type: "call"; subject: Expr; args: Expr[] }
| { type: "unary"; unaryType: UnaryType; subject: Expr } | { type: "unary"; unaryType: UnaryType; subject: Expr }
| { type: "binary"; binaryType: BinaryType; left: Expr; right: Expr } | { type: "binary"; binaryType: BinaryType; left: Expr; right: Expr }
| { type: "if"; cond: Expr; truthy: Expr; falsy?: Expr; elsePos?: Pos } | { type: "if"; cond: Expr; truthy: Expr; falsy?: Expr }
| { type: "bool"; value: boolean } | { type: "bool"; value: boolean }
| { type: "null" } | { type: "null" }
| { type: "loop"; body: Expr } | { type: "loop"; body: Expr }

View File

@ -47,7 +47,7 @@ export class Compiler {
const lowerer = new Lowerer(lexer.currentPos()); const lowerer = new Lowerer(lexer.currentPos());
lowerer.lower(ast); lowerer.lower(ast);
// lowerer.printProgram(); lowerer.printProgram();
const { program, fnNames } = lowerer.finish(); const { program, fnNames } = lowerer.finish();
return { program, fnNames }; return { program, fnNames };

View File

@ -490,7 +490,7 @@ export class Lowerer {
this.program.setLabel(falseLabel); this.program.setLabel(falseLabel);
if (expr.kind.falsy) { if (expr.kind.falsy) {
this.addSourceMap(expr.kind.elsePos!); this.addSourceMap(expr.kind.falsy.pos);
this.lowerExpr(expr.kind.falsy); this.lowerExpr(expr.kind.falsy);
} else { } else {
this.program.add(Ops.PushNull); this.program.add(Ops.PushNull);

View File

@ -456,18 +456,17 @@ export class Parser {
if (!this.test("else")) { if (!this.test("else")) {
return this.expr({ type: "if", cond, truthy }, pos); return this.expr({ type: "if", cond, truthy }, pos);
} }
const elsePos = this.pos();
this.step(); this.step();
if (this.test("if")) { if (this.test("if")) {
const falsy = this.parseIf(); const falsy = this.parseIf();
return this.expr({ type: "if", cond, truthy, falsy, elsePos }, pos); return this.expr({ type: "if", cond, truthy, falsy }, pos);
} }
if (!this.test("{")) { if (!this.test("{")) {
this.report("expected block"); this.report("expected block");
return this.expr({ type: "error" }, pos); return this.expr({ type: "error" }, pos);
} }
const falsy = this.parseBlock(); const falsy = this.parseBlock();
return this.expr({ type: "if", cond, truthy, falsy, elsePos }, pos); return this.expr({ type: "if", cond, truthy, falsy }, pos);
} }
private parseBinary(): Expr { private parseBinary(): Expr {

View File

@ -154,7 +154,6 @@ function syntaxHighlight(code: string): string {
"or", "or",
"and", "and",
"not", "not",
"loop",
"while", "while",
"for", "for",
"in", "in",