Skip to content

Commit 8ce5572

Browse files
committed
Inline immediates
1 parent 6ba995f commit 8ce5572

File tree

7 files changed

+1183
-910
lines changed

7 files changed

+1183
-910
lines changed

src/instance.zig

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const Global = @import("store/global.zig").Global;
1313
const Elem = @import("store/elem.zig").Elem;
1414
const Data = @import("store/data.zig").Data;
1515
const VirtualMachine = @import("instance/vm.zig").VirtualMachine;
16+
const Instruction = VirtualMachine.Instruction;
1617

1718
const VirtualMachineOptions = struct {
1819
frame_stack_size: comptime_int = 1024,
@@ -348,7 +349,7 @@ pub const Instance = struct {
348349
try vm.pushLabel(VirtualMachine.Label{
349350
.return_arity = function.results.len,
350351
.op_stack_len = locals_start,
351-
.branch_target = 0,
352+
.branch_target = @as([*]Instruction, @ptrCast(&self.module.instructions.items[0])),
352353
});
353354

354355
// 8. Execute our function
@@ -397,7 +398,7 @@ pub const Instance = struct {
397398
try vm.pushLabel(VirtualMachine.Label{
398399
.return_arity = 0,
399400
.op_stack_len = locals_start,
400-
.branch_target = 0,
401+
.branch_target = @as([*]Instruction, @ptrCast(&self.module.instructions.items[0])),
401402
});
402403

403404
try vm.invoke(f.start);
@@ -409,7 +410,7 @@ pub const Instance = struct {
409410
}
410411
}
411412

412-
pub fn invokeExpression(self: *Instance, start: usize, comptime Result: type, comptime options: VirtualMachineOptions) !Result {
413+
pub fn invokeExpression(self: *Instance, start: [*]Instruction, comptime Result: type, comptime options: VirtualMachineOptions) !Result {
413414
var frame_stack: [options.frame_stack_size]VirtualMachine.Frame = [_]VirtualMachine.Frame{undefined} ** options.frame_stack_size;
414415
var label_stack: [options.label_stack_size]VirtualMachine.Label = [_]VirtualMachine.Label{undefined} ** options.label_stack_size;
415416
var op_stack: [options.operand_stack_size]u64 = [_]u64{0} ** options.operand_stack_size;
@@ -428,6 +429,7 @@ pub const Instance = struct {
428429
try vm.pushLabel(VirtualMachine.Label{
429430
.return_arity = 1,
430431
.op_stack_len = locals_start,
432+
.branch_target = @as([*]Instruction, @ptrCast(&self.module.instructions.items[0])),
431433
});
432434

433435
try vm.invoke(start);

0 commit comments

Comments
 (0)