From 8e1f84b1369909745859777d07a5e8e74b5df334 Mon Sep 17 00:00:00 2001 From: Ben Winston Date: Sun, 21 May 2023 20:26:59 -0400 Subject: move disassembly into compiler, preparing for functions --- compiler.d | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'compiler.d') diff --git a/compiler.d b/compiler.d index 6482f50..ae4cb4a 100644 --- a/compiler.d +++ b/compiler.d @@ -7,11 +7,6 @@ import parser; import chunk; import dbg; -enum FunctionType { - FUNCTION, - SCRIPT, -} - struct Local { Symbol sym; int depth; @@ -20,7 +15,6 @@ struct Local { class Compiler { Function func; - FunctionType type; Parser* parser; Local[] locals; int localCount; @@ -369,15 +363,16 @@ class Compiler { Function finish() { this.func.chunk.writeOp(OpCode.OP_RETURN, current.line); + disassembleChunk(func.chunk, to!string(func)); return func; } - this(FunctionType type, Parser* parser) { + this(ObjType type, Parser* parser) { this.parser = parser; - this.func = new Function(); - this.type = type; - localCount = 0; - //locals ~= Local(new Symbol("", -1), 0); - //localCount++; + this.func = new Function(type); + //localCount = 0; + + locals ~= Local(new Symbol("", -1), 0); + localCount++; } } -- cgit v1.2.3