diff options
author | ubq323 <ubq323@ubq323.website> | 2024-06-26 19:27:42 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2024-06-26 19:27:42 +0100 |
commit | 2e62b41072738142dea9f0b5dd5d2d22455c7616 (patch) | |
tree | f47ce547de39fb69b02eb70990c9485489f1e574 /vm.c | |
parent | 6deeb9630d4b4e7d672ab851dcd4fe3d0d3d2865 (diff) |
add arrays, appending, getting length, indexing
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -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; } |