From d95e4f6f988b16bbd95a9c78c0355d190390f003 Mon Sep 17 00:00:00 2001 From: mryouse Date: Thu, 25 May 2023 20:27:36 +0000 Subject: make list creation simpler (and allow nesting) --- compiler.d | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'compiler.d') diff --git a/compiler.d b/compiler.d index 1c9e507..6a1424d 100644 --- a/compiler.d +++ b/compiler.d @@ -510,24 +510,12 @@ class Compiler { } void compileList(Form[] args) { - List lst = new List(); - ValueType vt; - int addr; + int length = to!int(args.length); foreach (Form arg ; args) { - vt = this.resolve(arg, ValueType.ANY); - // how do we get at the address? - addr = to!int(this.func.chunk.constants.length) - 1; // this is probably often wrong - lst.addItem(addr); - this.func.chunk.writeOp(OpCode.OP_POP, arg.line); // shouldn't use the stack for this (but how?) + resolve(arg, ValueType.ANY); // resolve everything onto the stack } - - this.func.chunk.writeOp(OpCode.OP_CONSTANT, args[0].line); - int idx = this.func.chunk.addConstant(makeObjValue(lst)); - this.func.chunk.writeOp(to!ubyte(idx), args[0].line); - //return ValueType.OBJ; - - - //advance(); // ?? + this.func.chunk.writeOp(OpCode.OP_LIST, args[0].line); + this.func.chunk.writeOp(to!ubyte(length), args[0].line); } void compileFirst(Form[] args) { -- cgit v1.2.3