@@ -11,6 +11,7 @@ const Global = @import("store/global.zig").Global;
1111const Elem = @import ("store/elem.zig" ).Elem ;
1212const Data = @import ("store/data.zig" ).Data ;
1313const VirtualMachine = @import ("instance/vm.zig" ).VirtualMachine ;
14+ const Instruction = VirtualMachine .Instruction ;
1415
1516const VirtualMachineOptions = struct {
1617 frame_stack_size : comptime_int = 1024 ,
@@ -322,7 +323,7 @@ pub const Instance = struct {
322323 try vm .pushLabel (VirtualMachine.Label {
323324 .return_arity = function .results .len ,
324325 .op_stack_len = locals_start ,
325- .branch_target = 0 ,
326+ .branch_target = @ptrCast ([ * ] Instruction , & self . module . instructions . items [ 0 ]) ,
326327 });
327328
328329 // 8. Execute our function
@@ -371,7 +372,7 @@ pub const Instance = struct {
371372 try vm .pushLabel (VirtualMachine.Label {
372373 .return_arity = 0 ,
373374 .op_stack_len = locals_start ,
374- .branch_target = 0 ,
375+ .branch_target = @ptrCast ([ * ] Instruction , & self . module . instructions . items [ 0 ]) ,
375376 });
376377
377378 try vm .invoke (f .start );
@@ -383,7 +384,7 @@ pub const Instance = struct {
383384 }
384385 }
385386
386- pub fn invokeExpression (self : * Instance , start : usize , comptime Result : type , comptime options : VirtualMachineOptions ) ! Result {
387+ pub fn invokeExpression (self : * Instance , start : [ * ] Instruction , comptime Result : type , comptime options : VirtualMachineOptions ) ! Result {
387388 var frame_stack : [options .frame_stack_size ]VirtualMachine.Frame = [_ ]VirtualMachine.Frame {undefined } ** options .frame_stack_size ;
388389 var label_stack : [options .label_stack_size ]VirtualMachine.Label = [_ ]VirtualMachine.Label {undefined } ** options .label_stack_size ;
389390 var op_stack : [options .operand_stack_size ]u64 = [_ ]u64 {0 } ** options .operand_stack_size ;
@@ -402,6 +403,7 @@ pub const Instance = struct {
402403 try vm .pushLabel (VirtualMachine.Label {
403404 .return_arity = 1 ,
404405 .op_stack_len = locals_start ,
406+ .branch_target = @ptrCast ([* ]Instruction , & self .module .instructions .items [0 ]),
405407 });
406408
407409 try vm .invoke (start );
0 commit comments