diff options
| author | mryouse | 2023-05-25 20:27:36 +0000 |
|---|---|---|
| committer | mryouse | 2023-05-25 20:27:36 +0000 |
| commit | d95e4f6f988b16bbd95a9c78c0355d190390f003 (patch) | |
| tree | 88c47ec85d16ebc3654ebae64c5e9905702d3c49 /vm.d | |
| parent | f90b882fe50d982293be5427457efea565173261 (diff) | |
make list creation simpler (and allow nesting)
Diffstat (limited to 'vm.d')
| -rw-r--r-- | vm.d | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -322,7 +322,16 @@ class VM { //bStack[bTop + slot - 1] = peekA(0); this.popA(); break; - case OpCode.OP_CONSTANT: + 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); + } + this.pushA(makeObjValue(lst)); + break; + case OpCode.OP_CONSTANT: Value constant = this.current.func.chunk.constants[this.readByte()]; //Value constant = current.func.chunk.constants[b]; this.pushA(constant); @@ -359,6 +368,7 @@ class VM { return InterpretResult.RUNTIME_ERROR; // TODO error } break; + /* case OpCode.OP_FIRST: Value val = this.popA(); List lst = cast(List)val.as.obj; // TODO this needs better checking @@ -367,6 +377,7 @@ class VM { Value first = this.current.func.chunk.constants[to!ubyte(addr)]; this.pushA(first); break; + */ case OpCode.OP_ADD: Value b = this.popA(); /* |
