aboutsummaryrefslogtreecommitdiff
path: root/compiler.d
diff options
context:
space:
mode:
authormryouse2023-06-06 19:45:47 -0400
committermryouse2023-06-06 19:45:47 -0400
commit87ee44163d0f7ec86963cefea51e721ce4eb156c (patch)
tree7f3ef821f7ee1437b1df5558255f37d00bb6198e /compiler.d
parent7393da674216aa3dd737db7ec4a3418ca025871c (diff)
initial commit of most and last
Diffstat (limited to 'compiler.d')
-rw-r--r--compiler.d28
1 files changed, 28 insertions, 0 deletions
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;