From 2e62b41072738142dea9f0b5dd5d2d22455c7616 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Wed, 26 Jun 2024 19:27:42 +0100 Subject: add arrays, appending, getting length, indexing --- vm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'vm.c') diff --git a/vm.c b/vm.c index b8fcbd6..679a6a5 100644 --- a/vm.c +++ b/vm.c @@ -10,6 +10,7 @@ #include "mem.h" #include "dis.h" #include "com.h" +#include "util.h" @@ -196,6 +197,17 @@ int runvm(State *S) { Val res = AS_CFUNC(callee)(S, len - 1, firstarg); th->sp -= len; PUSH(res); + } else if (IS_ARR(callee)) { + ObjArr *arr = AS_ARR(callee); + CHECK(len == 2, "can only index arr with single argument"); + Val vix = PEEK(); + CHECK(IS_NUM(vix), "can only index numerically"); + size_t ix = (size_t)AS_NUM(vix); + Val res = objarr_get(S, arr, ix); + th->sp -= 2; + PUSH(res); + } else { + ERROR("cannot call %s",typename_str(callee)); } break; } -- cgit v1.2.3