diff options
Diffstat (limited to 'compiler.d')
| -rw-r--r-- | compiler.d | 27 |
1 files changed, 25 insertions, 2 deletions
@@ -345,9 +345,12 @@ class Compiler { */ int resolveLocal(Symbol sym) { + writefln("resolving local: %s", sym.name); for (int i = this.localCount - 1; i >= 0; i--) { Local local = this.locals[i]; + writefln(" > [%d] %s (%s)", i, local.sym.name, local.depth); if (local.sym.name == sym.name) { + writeln("got it!"); return i; } } @@ -524,8 +527,8 @@ class Compiler { writeln("COMPILE ERROR: 'first' expects exactly one argument"); return; } - ValueType vt = this.resolve(args[0], ValueType.OBJ); // TODO need a new type - this.func.chunk.writeOp(OpCode.OP_TYPE_CHECK_LIST, args[0].line); + ValueType vt = this.resolve(args[0], ValueType.SEQ); // TODO need a new type + this.func.chunk.writeOp(OpCode.OP_TYPE_CHECK_SEQ, args[0].line); // pop the value off the stack // get the address of the first item in the list @@ -535,6 +538,23 @@ class Compiler { this.func.chunk.writeOp(OpCode.OP_FIRST, args[0].line); } + void compileRest(Form[] args) { + // TODO how do we identify/propagate errors? + if (args.length != 1) { + writeln("COMPILE ERROR: 'first' expects exactly one argument"); + return; + } + ValueType vt = this.resolve(args[0], ValueType.OBJ); // TODO need a new type + this.func.chunk.writeOp(OpCode.OP_TYPE_CHECK_SEQ, args[0].line); + + this.func.chunk.writeOp(OpCode.OP_REST, args[0].line); + + // there's probably a nicer way to copy + //List lst = new List(); + + // create a copy of the list + } + void compileFunc(Form form) { Func f = cast(Func)form; @@ -629,6 +649,9 @@ class Compiler { //return compileList(cons.tail); this.compileList(cons.tail); break; + case "rest": + this.compileRest(cons.tail); + break; default: /* writefln("unsure how to compile %s", sym.name); |
