From b7854d7325dfe35ca41e56dcccfb8fb7b7d0aa22 Mon Sep 17 00:00:00 2001 From: Ernesto Lanchares Date: Sun, 23 Mar 2025 13:38:57 +0000 Subject: Big rework of the parser! It now follows a more functional style but it should be waaay easier to add functionality. Probably the parser is a bit slower than the previous one but the code is much cleaner and a good enough compiler should be able to inline the function calls and make it par with the previous one. As a TODO, runtime structs should not depends on the parser, but I think that is a topic for another commit. --- src/main.zig | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/main.zig') diff --git a/src/main.zig b/src/main.zig index 597011d..97aa5bf 100644 --- a/src/main.zig +++ b/src/main.zig @@ -5,7 +5,7 @@ const window = @import("rendering/window.zig"); const config = @import("config"); const Renderer = @import("rendering/renderer_vulkan.zig"); const math = @import("math.zig"); -const Parser = @import("mods/parse.zig"); +const Parser = @import("mods/Parser.zig"); const vm = @import("mods/vm.zig"); const wasm = @import("mods/wasm.zig"); const components = @import("ecs/components.zig"); @@ -28,10 +28,19 @@ pub fn main() !void { //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); + // const file = try std.fs.cwd().openFile("assets/core.wasm", .{}); + // const all = try file.readToEndAlloc(allocator, 1_000_000); // 1 MB + // var parser = Parser{ + // .bytes = all, + // .byte_idx = 0, + // .allocator = allocator, + // }; + // const module = parser.parseModule() catch |err| { + // std.debug.print("[ERROR]: error at byte {x}(0x{x})\n", .{ parser.byte_idx, parser.bytes[parser.byte_idx] }); + // return err; + // }; + // var runtime = try vm.Runtime.init(allocator, module, &global_runtime); + // defer runtime.deinit(allocator); //var parameters = [_]usize{}; //try runtime.callExternal(allocator, "preinit", ¶meters); -- cgit v1.2.3