diff options
author | ubq323 <ubq323@ubq323.website> | 2024-06-30 21:37:14 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2024-06-30 21:37:14 +0100 |
commit | 4cf1e1fa0e11307005a724225ea3ae2f80a5c037 (patch) | |
tree | 600c6ddc587f011f10a125e6dd31eb07ca8137b7 /vm.c | |
parent | 83382cb1b46eb17f94f16fbbf05b5e471284d797 (diff) |
add array index setting syntax
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -228,6 +228,18 @@ int runvm(State *S) { break; } + case OP_SETIDX: { + Val vix = POP(); + Val varr = POP(); + Val v = PEEK(); + CHECK(IS_NUM(vix), "can only index numerically"); + CHECK(IS_ARR(varr), "can only set index on array"); + size_t ix = (size_t)AS_NUM(vix); + ObjArr *arr = AS_ARR(varr); + objarr_put(S, arr, ix, v); + break; + } + case OP_ENDSCOPE: { uint8_t nlocals = RBYTE(); Val retval = POP(); |