From 4784c4d2ae944f5ef1f7f4fc00271ab2ca825101 Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Sun, 30 Jul 2023 16:56:50 +0100 Subject: [PATCH] Patch call to fast_call --- src/instance/vm.zig | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/instance/vm.zig b/src/instance/vm.zig index e351550e..7ebe8688 100644 --- a/src/instance/vm.zig +++ b/src/instance/vm.zig @@ -263,6 +263,18 @@ pub const VirtualMachine = struct { // Make space for locals (again, params already on stack) self.op_ptr += f.locals_count; + // Only patch (for the moment) functions in the same instance + if (self.inst == f.instance) { + // Switch call with fast_call + code[ip] = .{ .fast_call = .{ + .start = @as(u32, @truncate(f.start)), + .locals = @as(u16, @truncate(f.locals_count)), + .params = @as(u16, @truncate(function.params.len)), + .results = @as(u16, @truncate(function.results.len)), + .required_stack_space = @as(u16, @truncate(f.required_stack_space)), + } }; + } + self.inst = f.instance; // Consume parameters from the stack