diff options
| author | Ben Winston | 2023-05-22 20:26:27 -0400 |
|---|---|---|
| committer | Ben Winston | 2023-05-22 20:26:27 -0400 |
| commit | ab6deb5eb1244f566c8a8b22022c68d50d5eb4d7 (patch) | |
| tree | 58295e80efb472836e8c226f10e00ffd16468b68 | |
| parent | b7fba62e9f1f9f7a5a67fd64d4aed55646d1b58e (diff) | |
make the REPL actually remember things
| -rw-r--r-- | compiler.d | 11 | ||||
| -rw-r--r-- | main.d | 5 | ||||
| -rw-r--r-- | vm.d | 4 |
3 files changed, 4 insertions, 16 deletions
@@ -50,12 +50,9 @@ class Compiler { } void compileAdd(Form[] args) { - writeln("compiling add"); int line = args[0].line; resolve(args[0]); - writeln("resolved the first argument"); func.chunk.writeOp(OpCode.OP_TYPE_CHECK_NUMBER, line); - writeln("wrote the typecheck op"); // (+ n) always returns n if (args.length == 1) { @@ -208,7 +205,6 @@ class Compiler { } void compileIf(Form form) { - writeln("compiling if..."); If if_ = cast(If)form; resolve(if_.cond); @@ -281,9 +277,7 @@ class Compiler { Block block = cast(Block)form; beginScope(); foreach (Form inner; block.blockBody) { - writeln("about to compile an inner form"); resolve(inner); - writeln("finished compiling inner form"); } endScope(); } @@ -314,7 +308,6 @@ class Compiler { } void compileFunc(Form form) { - writeln("compiling func"); Func f = cast(Func)form; // name the function @@ -335,8 +328,6 @@ class Compiler { } } - writeln("got the arguments"); - /* // compile each inner Form foreach (Form inner; f.funcBody) { @@ -350,8 +341,6 @@ class Compiler { b.blockBody = f.funcBody; compiler.compileBlock(b); - writeln("compiled the body"); - // write the function as a Value Function outFunc = compiler.finish(); func.chunk.writeOp(OpCode.OP_CONSTANT, f.line); @@ -21,6 +21,7 @@ import vm; void repl() { + VM vm = new VM(); while(true) { write("> "); @@ -41,7 +42,7 @@ void repl() { VM vm = new VM(func); vm.run(); */ - interpret(input); + interpret(input, vm); } } @@ -70,7 +71,7 @@ int main(string[] args) { string data = readFile(fname); - interpret(data); + interpret(data, new VM()); } return 0; } @@ -457,13 +457,11 @@ class VM { } } -InterpretResult interpret(string source) { +InterpretResult interpret(string source, VM vm) { Parser parser = new Parser(source); Compiler compiler = new Compiler(ObjType.SCRIPT, &parser); Function func = compiler.compile(); - VM vm = new VM(); - // vm.globals[":int"] = makeTypeValue(":int"); vm.pushA(makeObjValue(func)); |
