about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNguyễn Gia Phong <cnx@loang.net>2024-03-12 16:15:03 +0900
committerNguyễn Gia Phong <cnx@loang.net>2024-03-12 16:15:03 +0900
commite1ab3ce53de9495253a2e7ebe4f438b6d1181f6b (patch)
treeace3ff4c9658e06a92c50523c8752b2f1271216b
parent54ad16f5516b235f304c789e134c5321c22ef913 (diff)
downloadjz-e1ab3ce53de9495253a2e7ebe4f438b6d1181f6b.tar.gz
Use std.meta.Tuple HEAD main
-rw-r--r--src/main.zig24
1 files 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);