mirror of
				https://git.sfja.dk/Mikkel/slige.git
				synced 2025-10-29 04:18:30 +00:00 
			
		
		
		
	source map else
This commit is contained in:
		
							parent
							
								
									e581c245bd
								
							
						
					
					
						commit
						f90fcd431f
					
				| @ -45,7 +45,7 @@ export type ExprKind = | ||||
|     | { type: "call"; subject: Expr; args: Expr[] } | ||||
|     | { type: "unary"; unaryType: UnaryType; subject: Expr } | ||||
|     | { type: "binary"; binaryType: BinaryType; left: Expr; right: Expr } | ||||
|     | { type: "if"; cond: Expr; truthy: Expr; falsy?: Expr } | ||||
|     | { type: "if"; cond: Expr; truthy: Expr; falsy?: Expr; elsePos?: Pos } | ||||
|     | { type: "bool"; value: boolean } | ||||
|     | { type: "null" } | ||||
|     | { type: "loop"; body: Expr } | ||||
|  | ||||
| @ -47,7 +47,7 @@ export class Compiler { | ||||
| 
 | ||||
|         const lowerer = new Lowerer(lexer.currentPos()); | ||||
|         lowerer.lower(ast); | ||||
|         lowerer.printProgram(); | ||||
|         // lowerer.printProgram();
 | ||||
|         const { program, fnNames } = lowerer.finish(); | ||||
| 
 | ||||
|         return { program, fnNames }; | ||||
|  | ||||
| @ -490,7 +490,7 @@ export class Lowerer { | ||||
|         this.program.setLabel(falseLabel); | ||||
| 
 | ||||
|         if (expr.kind.falsy) { | ||||
|             this.addSourceMap(expr.kind.falsy.pos); | ||||
|             this.addSourceMap(expr.kind.elsePos!); | ||||
|             this.lowerExpr(expr.kind.falsy); | ||||
|         } else { | ||||
|             this.program.add(Ops.PushNull); | ||||
|  | ||||
| @ -456,17 +456,18 @@ export class Parser { | ||||
|         if (!this.test("else")) { | ||||
|             return this.expr({ type: "if", cond, truthy }, pos); | ||||
|         } | ||||
|         const elsePos = this.pos(); | ||||
|         this.step(); | ||||
|         if (this.test("if")) { | ||||
|             const falsy = this.parseIf(); | ||||
|             return this.expr({ type: "if", cond, truthy, falsy }, pos); | ||||
|             return this.expr({ type: "if", cond, truthy, falsy, elsePos }, pos); | ||||
|         } | ||||
|         if (!this.test("{")) { | ||||
|             this.report("expected block"); | ||||
|             return this.expr({ type: "error" }, pos); | ||||
|         } | ||||
|         const falsy = this.parseBlock(); | ||||
|         return this.expr({ type: "if", cond, truthy, falsy }, pos); | ||||
|         return this.expr({ type: "if", cond, truthy, falsy, elsePos }, pos); | ||||
|     } | ||||
| 
 | ||||
|     private parseBinary(): Expr { | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user