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) --- chunk.d | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'chunk.d') diff --git a/chunk.d b/chunk.d index ad5774c..0573687 100644 --- a/chunk.d +++ b/chunk.d @@ -3,6 +3,7 @@ import std.string; import std.conv; import parser; +import dbg; enum ObjType { FUNCTION, @@ -37,22 +38,19 @@ class Function : Obj { } class List : Obj { - int[] addresses; + Value[] inner; - this() { + this(int length) { + this.inner = new Value[length]; this.type = ObjType.LIST; } - void addItem(int addr) { - addresses ~= addr; - } - - int first() { - return addresses[0]; // TODO this fails on empty lists + void addItemAtIndex(Value item, int idx) { + this.inner[idx] = item; } override string toString() { - return format("list (%d)", addresses.length); + return format("list ('%s' + %d)", printableValue(this.inner[0]), this.inner.length - 1); } } @@ -82,6 +80,8 @@ enum OpCode { OP_CALL, + OP_LIST, + OP_CONCAT, // No? OP_FIRST, // No? -- cgit v1.2.3