aboutsummaryrefslogtreecommitdiff
path: root/compiler.d
diff options
context:
space:
mode:
authorBen Winston2023-05-21 20:26:59 -0400
committerBen Winston2023-05-21 20:26:59 -0400
commit8e1f84b1369909745859777d07a5e8e74b5df334 (patch)
tree460f42755407e9ddf1b3e6dfabea6a09b3d1585d /compiler.d
parenta26bfccdc52ab50a83b8f8d170c9e1a3be0164a5 (diff)
move disassembly into compiler, preparing for functions
Diffstat (limited to 'compiler.d')
-rw-r--r--compiler.d19
1 files changed, 7 insertions, 12 deletions
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++;
}
}