diff options
| author | mryouse | 2023-05-25 22:52:07 +0000 |
|---|---|---|
| committer | mryouse | 2023-05-25 22:52:07 +0000 |
| commit | 785b43a7b6635e6fadb94e224a094e524c9e0ccd (patch) | |
| tree | 5c60ee3d25a747c21e480283a9dd4021457c43f3 /compiler.d | |
| parent | 3535bfefccea789169786767ac80c54241cae019 (diff) | |
length on seq
Diffstat (limited to 'compiler.d')
| -rw-r--r-- | compiler.d | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -521,6 +521,18 @@ class Compiler { this.func.chunk.writeOp(to!ubyte(length), args[0].line); } + void compileLength(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.SEQ); // TODO need a new type + this.func.chunk.writeOp(OpCode.OP_TYPE_CHECK_SEQ, args[0].line); + + this.func.chunk.writeOp(OpCode.OP_LENGTH, args[0].line); + } + void compileFirst(Form[] args) { // TODO how do we identify/propagate errors? if (args.length != 1) { @@ -676,6 +688,9 @@ class Compiler { case "first": this.compileFirst(cons.tail); break; + case "length": + this.compileLength(cons.tail); + break; case "list": //return compileList(cons.tail); this.compileList(cons.tail); |
