Fix incorrect stack popping order in set_dynamic opcode

This commit is contained in:
kayomn 2023-07-31 00:30:44 +01:00
parent 9435348877
commit 4ee0bcab67
1 changed files with 4 additions and 4 deletions

View File

@ -378,6 +378,10 @@ fn execute(self: *Self, env: *kym.RuntimeEnv) kym.RuntimeError!?*kym.RuntimeRef
},
.set_dynamic => {
const value_ref = try env.pop_local();
defer env.discard(value_ref);
const index_ref = try env.pop_local() orelse {
return env.raise(error.TypeMismatch, "nil is not a valid index");
};
@ -390,10 +394,6 @@ fn execute(self: *Self, env: *kym.RuntimeEnv) kym.RuntimeError!?*kym.RuntimeRef
defer env.discard(indexable_ref);
const value_ref = try env.pop_local();
defer env.discard(value_ref);
try env.set_dynamic(try kym.unbox_dynamic(env, indexable_ref), index_ref, value_ref);
},