From 4cf1e1fa0e11307005a724225ea3ae2f80a5c037 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Sun, 30 Jun 2024 21:37:14 +0100 Subject: add array index setting syntax --- vm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'vm.c') diff --git a/vm.c b/vm.c index 4a65832..0857571 100644 --- a/vm.c +++ b/vm.c @@ -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(); -- cgit v1.2.3