From 277f7110b01a510e42fd8a75682ebe3c4daa3d40 Mon Sep 17 00:00:00 2001 From: Ben Winston Date: Tue, 23 May 2023 22:49:42 -0400 Subject: first crack at lists (rather naive) --- chunk.d | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'chunk.d') diff --git a/chunk.d b/chunk.d index afaba8b..ad5774c 100644 --- a/chunk.d +++ b/chunk.d @@ -7,6 +7,7 @@ import parser; enum ObjType { FUNCTION, SCRIPT, + LIST, } abstract class Obj { @@ -35,6 +36,26 @@ class Function : Obj { } } +class List : Obj { + int[] addresses; + + this() { + this.type = ObjType.LIST; + } + + void addItem(int addr) { + addresses ~= addr; + } + + int first() { + return addresses[0]; // TODO this fails on empty lists + } + + override string toString() { + return format("list (%d)", addresses.length); + } +} + enum OpCode { OP_ADD, OP_LESS, @@ -61,8 +82,14 @@ enum OpCode { OP_CALL, + OP_CONCAT, // No? + + OP_FIRST, // No? + OP_TYPE_CHECK_NUMBER, OP_TYPE_CHECK_BOOLEAN, + OP_TYPE_CHECK_STRING, + OP_TYPE_CHECK_LIST, } class Chunk { -- cgit v1.2.3