summaryrefslogtreecommitdiff
path: root/src/mods/vm.zig
diff options
context:
space:
mode:
authorluccie-cmd <luccie@sideros.org>2025-03-21 12:43:49 +0100
committerLorenzo Torres <torres@sideros.org>2025-03-21 22:49:37 +0100
commitbbe9213573943f2ac5cc840bfb1788e756353449 (patch)
treea6752402d53f85ff456a61be3695a7f701f3eaf0 /src/mods/vm.zig
parente1f1441a38ebd648765d7c3d8771413ccd08a8af (diff)
Added block instruction in WASM VM
Signed-off-by: luccie-cmd <luccie@sideros.org>
Diffstat (limited to 'src/mods/vm.zig')
-rw-r--r--src/mods/vm.zig19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/mods/vm.zig b/src/mods/vm.zig
index f8c7db5..2558ced 100644
--- a/src/mods/vm.zig
+++ b/src/mods/vm.zig
@@ -79,6 +79,23 @@ pub const Runtime = struct {
frame.program_counter += 1;
std.debug.print("b: {x}\n", .{byte});
switch (byte) {
+ 0x02 => {
+ var depth: usize = 1;
+ var pc = frame.program_counter;
+ while (depth > 0) {
+ const opcode = frame.code[pc];
+ const operand = frame.code[pc+1];
+ if (opcode == 0x02 and operand == 0x40) {
+ depth += 1;
+ } else if (opcode == 0x0B) {
+ depth -= 1;
+ }
+
+ pc += 1; // Move forward
+ }
+ try self.labels.append(pc);
+ frame.program_counter += 1;
+ },
0x03 => {
try self.labels.append(frame.program_counter);
frame.program_counter += 1;
@@ -479,6 +496,8 @@ pub const Runtime = struct {
pub fn callExternal(self: *Runtime, allocator: Allocator, name: []const u8, parameters: []usize) !void {
if (self.module.exports.get(name)) |function| {
try self.call(allocator, function, parameters);
+ } else {
+ std.debug.panic("Function `{s}` not avaliable", .{name});
}
}