zig-webgpu-gen

git clone git://git.electrosoup.com/zig-webgpu-gen
Log | Files | Refs

commit 32c6bdf44e7a212a683eb19df03a2722d781e723
parent 00159740b8978a757f6e3c67bf61586ad4a286a1
Author: Christian Ermann <christianermann@gmail.com>
Date:   Mon,  2 Mar 2026 18:39:50 -0800

Add function args

Diffstat:
Msrc/main.zig | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 59 insertions(+), 2 deletions(-)

diff --git a/src/main.zig b/src/main.zig @@ -97,6 +97,18 @@ const PrimitiveType = enum { @"array<float32>", @"array<float64>", + pub fn isInt(self: PrimitiveType) bool { + return switch (self) { + .uint16 => true, + .uint32 => true, + .uint64 => true, + .usize => true, + .int16 => true, + .int32 => true, + else => false, + }; + } + pub fn isArray(self: PrimitiveType) bool { return switch (self) { .@"array<bool>" => true, @@ -314,6 +326,14 @@ const Type = union(enum) { complex: ComplexType, callback: CallbackType, + pub fn isInt(self: Type) bool { + return switch (self) { + .primitive => |inner| inner.isInt(), + .complex => false, + .callback => false, + }; + } + pub fn isArray(self: Type) bool { return switch (self) { .primitive => |inner| inner.isArray(), @@ -644,12 +664,22 @@ const Callback = struct { const ReturnType = struct { doc: []const u8, type: Type, - optional: ?bool = null, + optional: bool = false, passed_with_ownership: ?bool = null, pointer: ?Pointer = null, pub fn render(self: ReturnType, writer: anytype) !void { - try self.type.render(writer); + if (self.pointer) |pointer| { + if (!self.type.isArray()) { + try writer.writeAll("*"); + } + switch (pointer) { + .immutable => try self.type.renderConst(writer), + .mutable => try self.type.render(writer), + } + } else { + try self.type.render(writer); + } } }; @@ -682,11 +712,38 @@ const Function = struct { } try writer.writeAll(" {\n"); + // return try renderIndent(indent + 1, writer); + if (self.returns) |returns| { + try writer.writeAll("return "); + if (returns.pointer) |_| { + try writer.writeAll("@ptrCast("); + } + if (returns.type.isInt()) { + try writer.writeAll("@intCast("); + } + } + // c func try writer.writeAll("c.wgpu"); try snakeToPascal(self.name, writer); try writer.writeAll("(\n"); + // c func args + if (self.args) |args| { + for (args) |arg| { + try renderIndent(indent + 1, writer); + try writer.writeAll(arg.name); + try writer.writeAll(",\n"); + } + } try renderIndent(indent + 1, writer); + if (self.returns) |returns| { + if (returns.pointer) |_| { + try writer.writeAll(")"); + } + if (returns.type.isInt()) { + try writer.writeAll(")"); + } + } try writer.writeAll(");\n"); try renderIndent(indent, writer);