summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-06-26 19:27:42 +0100
committerubq323 <ubq323@ubq323.website>2024-06-26 19:27:42 +0100
commit2e62b41072738142dea9f0b5dd5d2d22455c7616 (patch)
treef47ce547de39fb69b02eb70990c9485489f1e574 /vm.c
parent6deeb9630d4b4e7d672ab851dcd4fe3d0d3d2865 (diff)
add arrays, appending, getting length, indexing
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c12
1 files changed, 12 insertions, 0 deletions
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;
}