diff options
| author | mryouse | 2023-05-27 01:48:18 +0000 |
|---|---|---|
| committer | mryouse | 2023-05-27 01:48:18 +0000 |
| commit | ea424bbc160ba84c4069a2889689be8685d35a1d (patch) | |
| tree | a4e829437d99e94a9dcdb8b6f8f9ce1632157192 | |
| parent | 334eafaff25014b0326b2b42e62e9b4f486736e6 (diff) | |
fix empty (list)
| -rw-r--r-- | compiler.d | 6 | ||||
| -rw-r--r-- | vm.d | 8 |
2 files changed, 11 insertions, 3 deletions
@@ -615,6 +615,12 @@ class Compiler { } void compileList(Form[] args) { + if (args.length == 0) { + this.func.chunk.writeOp(OpCode.OP_LIST, -1); + this.func.chunk.writeOp(to!ubyte(0), -1); + this.advance(); + return; + } int length = to!int(args.length); foreach (Form arg ; args) { resolve(arg, ValueType.ANY); // resolve everything onto the stack @@ -396,9 +396,11 @@ class VM { case OpCode.OP_LIST: int length = to!int(this.readByte()); List lst = new List(length); - for (int i = length - 1; i >= 0; i--) { - //lst.appendItem(this.popA()); - lst.addItemAtIndex(this.popA(), i); + if (length > 0) { + for (int i = length - 1; i >= 0; i--) { + //lst.appendItem(this.popA()); + lst.addItemAtIndex(this.popA(), i); + } } this.pushA(makeSeqValue(lst)); break; |
