diff options
Diffstat (limited to 'compiler.d')
| -rw-r--r-- | compiler.d | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -603,6 +603,17 @@ class Compiler { this.func.chunk.writeOp(OpCode.OP_FIRST, args[0].line); } + void compileLast(Form[] args) { + // TODO how do we identify/propagate errors? + if (args.length != 1) { + this.error("'last': expected [1] argument, received ?", -1); + return; + } + 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); + this.func.chunk.writeOp(OpCode.OP_LAST, args[0].line); + } + void compileIn(Form[] args) { // TODO how do we identify/propagate errors? if (args.length != 2) { @@ -628,6 +639,17 @@ class Compiler { this.func.chunk.writeOp(OpCode.OP_LENGTH, args[0].line); } + void compileMost(Form[] args) { + // TODO how do we identify/propagate errors? + if (args.length != 1) { + this.error("'most': expected [1] argument, received ?", -1); + 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_MOST, args[0].line); + } + void compileRest(Form[] args) { // TODO how do we identify/propagate errors? if (args.length != 1) { @@ -806,12 +828,18 @@ class Compiler { case "in?": this.compileIn(cons.tail); break; + case "last": + this.compileLast(cons.tail); + break; case "length": this.compileLength(cons.tail); break; case "list": this.compileList(cons.tail); break; + case "most": + this.compileMost(cons.tail); + break; case "rest": this.compileRest(cons.tail); break; |
