Added block instruction in WASM VM

Signed-off-by: luccie-cmd <luccie@sideros.org>
This commit is contained in:
luccie-cmd 2025-03-21 12:43:49 +01:00 committed by Lorenzo Torres
parent e1f1441a38
commit bbe9213573
3 changed files with 20 additions and 1 deletions

BIN
assets/core.wasm Normal file → Executable file

Binary file not shown.

View file

@ -25,7 +25,7 @@ pub fn main() !void {
//defer runtime.deinit(allocator);
//var parameters = [_]usize{};
//try runtime.callExternal(allocator, "calculate_fibonacci", &parameters);
//try runtime.callExternal(allocator, "preinit", &parameters);
const w = try window.Window.create(800, 600, "sideros");
defer w.destroy();

View file

@ -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});
}
}