From e1ab3ce53de9495253a2e7ebe4f438b6d1181f6b Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Tue, 12 Mar 2024 16:15:03 +0900 Subject: Use std.meta.Tuple --- src/main.zig | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/src/main.zig b/src/main.zig index 33288c1..90f67c5 100644 --- a/src/main.zig +++ b/src/main.zig @@ -19,10 +19,10 @@ const SourceLocation = std.builtin.SourceLocation; const Struct = std.builtin.Type.Struct; const StructField = std.builtin.Type.StructField; +const Tuple = std.meta.Tuple; const assert = std.debug.assert; const c = @cImport(@cInclude("janet.h")); const expectEqual = std.testing.expectEqual; -const formatIntBuf = std.fmt.formatIntBuf; const log10 = std.math.log10; const std = @import("std"); const zeroes = std.mem.zeroes; @@ -108,27 +108,13 @@ pub fn def(env: *Table, comptime fun: anytype, reg: struct { if (function.is_var_args) @compileError("fun is variadic"); const n = function.params.len; - comptime var fields: [n]StructField = undefined; - comptime for (&fields, 0.., function.params) |*field, i, param| { - const digits = if (i == 0) 1 else log10(i) + 1; - var name: [digits]u8 = undefined; - assert(formatIntBuf(&name, i, 10, .lower, .{}) == digits); - field.name = &name; - field.type = param.type.?; - field.default_value = null; - field.is_comptime = false; - field.alignment = 0; - }; - const Tuple = Struct{ - .layout = .Auto, - .fields = &fields, - .decls = &.{}, - .is_tuple = true, - }; + comptime var fields: [n]type = undefined; + inline for (&fields, function.params) |*field, param| + field.* = param.type.?; const cfun = struct { fn cfun(argc: i32, argv: [*c]Value) callconv(.C) Value { c.janet_fixarity(argc, n); - var args: @Type(.{ .Struct = Tuple }) = undefined; + var args: Tuple(&fields) = undefined; inline for (&args, function.params, 0..) |*arg, param, i| arg.* = get(param.type.?, argv, i); const result = @call(.auto, fun, args); -- cgit 1.4.1