summaryrefslogtreecommitdiff
path: root/src/mods/wasm.zig
diff options
context:
space:
mode:
authorLorenzo Torres <torres@sideros.org>2025-03-17 19:44:08 +0100
committerLorenzo Torres <torres@sideros.org>2025-03-17 19:44:08 +0100
commit1d64275dee5e5716b1a32f22e2f0ccba885898db (patch)
treef1aaf8d487cff5853495a1e19563aa09e5889e23 /src/mods/wasm.zig
parent5bab2c4bcf5870e421ae40123963f0c3b13af88a (diff)
Refactored source code structure.
Diffstat (limited to 'src/mods/wasm.zig')
-rw-r--r--src/mods/wasm.zig35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/mods/wasm.zig b/src/mods/wasm.zig
new file mode 100644
index 0000000..579309b
--- /dev/null
+++ b/src/mods/wasm.zig
@@ -0,0 +1,35 @@
+const vm = @import("vm.zig");
+const std = @import("std");
+const Allocator = std.mem.Allocator;
+
+pub const Type = enum(u8) {
+ i32 = 0x7f,
+ i64 = 0x7e,
+ f32 = 0x7d,
+ f64 = 0x7c,
+ v128 = 0x7b,
+};
+
+pub const GlobalRuntime = struct {
+ functions: std.StringHashMap(*const fn (stack: *std.ArrayList(vm.Value)) void),
+
+ pub fn init(allocator: Allocator) GlobalRuntime {
+ return GlobalRuntime{
+ .functions = std.StringHashMap(*const fn (stack: *std.ArrayList(vm.Value)) void).init(allocator),
+ };
+ }
+
+ pub fn deinit(self: *GlobalRuntime) void {
+ self.functions.deinit();
+ }
+
+ pub fn addFunction(self: *GlobalRuntime, name: []const u8, function: *const fn (stack: *std.ArrayList(vm.Value)) void) !void {
+ try self.functions.put(name, function);
+ }
+};
+
+pub fn debug(stack: *std.ArrayList(vm.Value)) void {
+ const a = stack.pop().?;
+
+ std.debug.print("{}\n", .{a.i32});
+}