Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for zig 0.10 (stage 2) #139

Merged
merged 15 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ jobs:
- uses: actions/checkout@v2
- uses: goto-bus-stop/setup-zig@v1
with:
version: 0.9.1
version: master
- run: zig build test
testsuite:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: goto-bus-stop/setup-zig@v1
with:
version: 0.9.1
version: master
- run: zig build --build-file test/build.zig --prefix ./
- run: cp bin/testrunner testrunner
- run: cp test/testsuite-generated/* ./
Expand Down Expand Up @@ -101,5 +101,5 @@ jobs:
- uses: actions/checkout@v2
- uses: goto-bus-stop/setup-zig@v1
with:
version: 0.9.1
version: master
- run: zig fmt --check src/*.zig
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
zig-cache
zig-out
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn main() !void {

### Compile-time

- Zig 0.9.1
- Zig 0.10.0

### Run-time

Expand Down Expand Up @@ -93,4 +93,4 @@ zig build --build-file test/build.zig --prefix ./

```
sh test/run-generated.sh
```
```
Binary file added examples/fib/src/fib.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/fib/src/fib.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn main() !void {

const alloc = arena.allocator();

const bytes = @embedFile("../../../test/fib.wasm");
const bytes = @embedFile("fib.wasm");

var store: Store = Store.init(alloc);

Expand Down
2 changes: 1 addition & 1 deletion src/function.zig
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub const Function = union(enum) {
instance: usize,
},
host_function: struct {
func: fn (*Interpreter) WasmError!void,
func: *const fn (*Interpreter) WasmError!void,
params: []const ValueType,
results: []const ValueType,
},
Expand Down
22 changes: 11 additions & 11 deletions src/instruction.zig
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,8 @@ pub const ParseIterator = struct {

if (block_type >= 0) {
const func_type = self.module.types.list.items[@intCast(usize, block_type)];
block_params = try math.cast(u16, func_type.params.len);
block_returns = try math.cast(u16, func_type.results.len);
block_params = math.cast(u16, func_type.params.len) orelse return error.FailedCast;
block_returns = math.cast(u16, func_type.results.len) orelse return error.FailedCast;
try self.validator.validateBlock(func_type.params, func_type.results);
} else {
if (block_type == -0x40) {
Expand Down Expand Up @@ -599,8 +599,8 @@ pub const ParseIterator = struct {
var block_returns: u16 = if (block_type == -0x40) 0 else 1;
if (block_type >= 0) {
const func_type = self.module.types.list.items[@intCast(usize, block_type)];
block_params = try math.cast(u16, func_type.params.len);
block_returns = try math.cast(u16, func_type.results.len);
block_params = math.cast(u16, func_type.params.len) orelse return error.FailedCast;
block_returns = math.cast(u16, func_type.results.len) orelse return error.FailedCast;
try self.validator.validateLoop(func_type.params, func_type.results);
} else {
if (block_type == -0x40) {
Expand All @@ -621,7 +621,7 @@ pub const ParseIterator = struct {
.loop = .{
.param_arity = block_params,
.return_arity = block_params,
.branch_target = try math.cast(u32, self.code_ptr),
.branch_target = math.cast(u32, self.code_ptr) orelse return error.FailedCast,
},
};
},
Expand All @@ -637,8 +637,8 @@ pub const ParseIterator = struct {
var block_returns: u16 = if (block_type == -0x40) 0 else 1;
if (block_type >= 0) {
const func_type = self.module.types.list.items[@intCast(usize, block_type)];
block_params = try math.cast(u16, func_type.params.len);
block_returns = try math.cast(u16, func_type.results.len);
block_params = math.cast(u16, func_type.params.len) orelse return error.FailedCast;
block_returns = math.cast(u16, func_type.results.len) orelse return error.FailedCast;
try self.validator.validateIf(func_type.params, func_type.results);
} else {
if (block_type == -0x40) {
Expand Down Expand Up @@ -673,7 +673,7 @@ pub const ParseIterator = struct {
.param_arity = b.param_arity,
.return_arity = b.return_arity,
.branch_target = 0,
.else_ip = try math.cast(u32, self.code_ptr + 1),
.else_ip = math.cast(u32, self.code_ptr + 1) orelse return error.FailedCast,
},
};
},
Expand All @@ -688,16 +688,16 @@ pub const ParseIterator = struct {
const parsed_code_offset = try self.popContinuationStack();

switch (self.parsed.items[parsed_code_offset]) {
.block => |*b| b.branch_target = try math.cast(u32, self.code_ptr + 1),
.block => |*b| b.branch_target = math.cast(u32, self.code_ptr + 1) orelse return error.FailedCast,
.loop => {},
.@"if" => |*b| {
b.branch_target = try math.cast(u32, self.code_ptr + 1);
b.branch_target = math.cast(u32, self.code_ptr + 1) orelse return error.FailedCast;
},
.if_no_else => |*b| {
// We have an if with no else, check that this works arity-wise and replace with fast if
if (b.param_arity -% b.return_arity != 0) return error.ValidatorElseBranchExpected;

b.branch_target = try math.cast(u32, self.code_ptr + 1);
b.branch_target = math.cast(u32, self.code_ptr + 1) orelse return error.FailedCast;
},
else => return error.UnexpectedInstruction,
}
Expand Down
Loading