From a559125a2d7af771784614b7a2092cc7fb707345 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Wed, 26 Jun 2024 22:45:16 +0100 Subject: array literals --- com.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'com.c') diff --git a/com.c b/com.c index 0ae79f6..695802a 100644 --- a/com.c +++ b/com.c @@ -38,6 +38,7 @@ static int stack_effect_of(Op opcode) { case OP_NIL: case OP_TRUE: case OP_FALSE: + case OP_ARRNEW: return 1; case OP_SKIP: case OP_REDO: @@ -55,6 +56,7 @@ static int stack_effect_of(Op opcode) { case OP_CMP: case OP_EQU: case OP_MOD: + case OP_ARRAPPEND: return -1; // these ones depend on their argument. handle them specifically @@ -402,6 +404,16 @@ static void compile_node(Compiler *C, AstNode a) { compile_byte(C, compile_constant(C, VAL_OBJ(o))); break; } + case AST_ARR: { + compile_opcode(C, OP_ARRNEW); + AstVec v = a.as.list; + for (int i = 0; i < v.len; i++) { + compile_node(C, v.vals[i]); + compile_opcode(C, OP_ARRAPPEND); + } + break; + } + case AST_LIST: { AstVec l = a.as.list; -- cgit v1.2.3