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

Func call only works for comptime values. #2

Open
somethingelseentirely opened this issue Feb 24, 2022 · 0 comments
Open

Func call only works for comptime values. #2

somethingelseentirely opened this issue Feb 24, 2022 · 0 comments

Comments

@somethingelseentirely
Copy link
Contributor

somethingelseentirely commented Feb 24, 2022

It looks like Func.call can only be called with comptime known values.
I'm not sure if this was missed because all the examples only use literals, or if the semantic of zig has changed recently.

Not being able to call functions with dynamic values makes calling them rather moot, so I'll see what I can do to fix this 😅

Code in question is here:

wasm-zig/src/main.zig

Lines 170 to 186 in 8f9a0d1

pub fn call(self: *Func, comptime ResultType: type, args: anytype) CallError!ResultType {
if (!comptime trait.isTuple(@TypeOf(args)))
@compileError("Expected 'args' to be a tuple, but found type '" ++ @typeName(@TypeOf(args)) ++ "'");
const args_len = args.len;
comptime var wasm_args: [args_len]Value = undefined;
inline for (wasm_args) |*arg, i| {
arg.* = switch (@TypeOf(args[i])) {
i32, u32 => .{ .kind = .i32, .of = .{ .i32 = @intCast(i32, args[i]) } },
i64, u64 => .{ .kind = .i64, .of = .{ .i64 = @intCast(i64, args[i]) } },
f32 => .{ .kind = .f32, .of = .{ .f32 = args[i] } },
f64 => .{ .kind = .f64, .of = .{ .f64 = args[i] } },
*Func => .{ .kind = .funcref, .of = .{ .ref = args[i] } },
*Extern => .{ .kind = .anyref, .of = .{ .ref = args[i] } },
else => |ty| @compileError("Unsupported argument type '" ++ @typeName(ty) + "'"),
};
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant