From 87ee44163d0f7ec86963cefea51e721ce4eb156c Mon Sep 17 00:00:00 2001 From: mryouse Date: Tue, 6 Jun 2023 19:45:47 -0400 Subject: initial commit of most and last --- compiler.d | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'compiler.d') diff --git a/compiler.d b/compiler.d index 0c90a45..6756882 100644 --- a/compiler.d +++ b/compiler.d @@ -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; -- cgit v1.2.3