diff options
author | Lorenzo Torres <lorenzotorres@outlook.it> | 2025-03-12 19:56:19 +0100 |
---|---|---|
committer | Lorenzo Torres <lorenzotorres@outlook.it> | 2025-03-12 19:56:19 +0100 |
commit | 4f45899a3c28440724ffcaa3a604ad48f18a25c8 (patch) | |
tree | cecd79da4e3e3cb17ffd86ec1a58d6e77a44cb83 /src/main.zig | |
parent | fc39b277155044366f1647b238a415fab4028d83 (diff) |
base code
Diffstat (limited to 'src/main.zig')
-rw-r--r-- | src/main.zig | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/main.zig b/src/main.zig new file mode 100644 index 0000000..5cbeef2 --- /dev/null +++ b/src/main.zig @@ -0,0 +1,45 @@ +const std = @import("std"); +const c = @import("c.zig"); +const window = @import("render/window.zig"); + +const config = @import("config"); +const Renderer = @import("render/renderer_vulkan.zig"); +const math = @import("math.zig"); +const Parser = @import("vm/parse.zig"); +const vm = @import("vm/vm.zig"); +const wasm = @import("vm/wasm.zig"); + +pub fn main() !void { + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + const allocator = gpa.allocator(); + { + var global_runtime = wasm.GlobalRuntime.init(allocator); + defer global_runtime.deinit(); + try global_runtime.addFunction("debug", wasm.debug); + + const file = try std.fs.cwd().openFile("assets/core.wasm", .{}); + const module = try Parser.parseWasm(allocator, file.reader()); + var runtime = try vm.Runtime.init(allocator, module, &global_runtime); + defer runtime.deinit(allocator); + + var parameters = [_]usize{}; + try runtime.callExternal(allocator, "fibonacci", ¶meters); + + const w = try window.Window.create(800, 600, "sideros"); + defer w.destroy(); + + // TODO: Renderer.destroy should not return an error? + var r = try Renderer.create(allocator, w); + defer r.destroy() catch {}; + + while (!w.shouldClose()) { + c.glfwPollEvents(); + try r.tick(); + } + try r.device.waitIdle(); + } + + if (gpa.detectLeaks()) { + return error.leaked_memory; + } +} |