diff --git a/.github/actions/install/action.yml b/.github/actions/install/action.yml index eb70d75..e1698c4 100644 --- a/.github/actions/install/action.yml +++ b/.github/actions/install/action.yml @@ -5,7 +5,7 @@ inputs: zig: description: 'Zig version to install' required: false - default: '0.13.0' + default: '0.14.0' arch: description: 'CPU arch used to select the v8 lib' required: false diff --git a/.github/workflows/zig-fmt.yml b/.github/workflows/zig-fmt.yml index e4e39ed..621209f 100644 --- a/.github/workflows/zig-fmt.yml +++ b/.github/workflows/zig-fmt.yml @@ -1,7 +1,7 @@ name: zig-fmt env: - ZIG_VERSION: 0.13.0 + ZIG_VERSION: 0.14.0 on: pull_request: diff --git a/.gitmodules b/.gitmodules index 9fd4441..123d361 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,11 @@ [submodule "vendor/zig-v8"] path = vendor/zig-v8 - url = https://github.com/Browsercore/zig-v8-fork.git/ + url = https://github.com/lightpanda-io/zig-v8-fork.git/ + branch = zig-0.14 [submodule "vendor/tigerbeetle-io"] path = vendor/tigerbeetle-io - url = https://github.com/Browsercore/tigerbeetle-io.git/ + url = https://github.com/lightpanda-io/tigerbeetle-io.git/ + branch = zig-0.14 [submodule "vendor/linenoise-mob"] path = vendor/linenoise-mob url = https://github.com/rain-1/linenoise-mob.git/ diff --git a/README.md b/README.md index 181f519..0da005f 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ exit with Ctrl+D or "exit" ### Prerequisites -zig-js-runtime is written with [Zig](https://ziglang.org/) `0.13.0`. You have to +zig-js-runtime is written with [Zig](https://ziglang.org/) `0.14.0`. You have to install it with the right version in order to build the project. To be able to build the v8 engine, you have to install some libs: diff --git a/build.zig b/build.zig index 444782b..ff02827 100644 --- a/build.zig +++ b/build.zig @@ -20,7 +20,7 @@ const pkgs = packages(""); /// Do not rename this constant. It is scanned by some scripts to determine /// which zig version to install. -pub const recommended_zig_version = "0.13.0"; +pub const recommended_zig_version = "0.14.0"; pub fn build(b: *std.Build) !void { switch (comptime builtin.zig_version.order(std.SemanticVersion.parse(recommended_zig_version) catch unreachable)) { @@ -67,7 +67,7 @@ pub fn build(b: *std.Build) !void { .optimize = mode, }); - try common(b, &bench.root_module, options); + try common(b, bench.root_module, options); if (mode == .ReleaseSafe) { // remove debug info // TODO: check if mandatory in release-safe @@ -95,7 +95,7 @@ pub fn build(b: *std.Build) !void { .target = target, .optimize = mode, }); - try common(b, &shell.root_module, options); + try common(b, shell.root_module, options); try pkgs.add_shell(shell); if (mode == .ReleaseSafe) { // remove debug info @@ -121,11 +121,11 @@ pub fn build(b: *std.Build) !void { // compile const tests = b.addTest(.{ .root_source_file = b.path("src/run_tests.zig"), + .test_runner = .{ .path = b.path("src/test_runner.zig"), .mode = .simple }, .target = target, .optimize = mode, }); - try common(b, &tests.root_module, options); - tests.test_runner = b.path("src/test_runner.zig"); + try common(b, tests.root_module, options); const run_tests = b.addRunArtifact(tests); // step diff --git a/src/bench.zig b/src/bench.zig index ddcecf2..540fc7e 100644 --- a/src/bench.zig +++ b/src/bench.zig @@ -42,7 +42,7 @@ pub fn call( if (i == 0) { // TODO: handle more return cases const info = @typeInfo(@TypeOf(res)); - if (info == .ErrorUnion) { + if (info == .error_union) { is_error_union = true; } } @@ -99,17 +99,18 @@ pub const Allocator = struct { .alloc = alloc, .resize = resize, .free = free, + .remap = remap, } }; } fn alloc( ctx: *anyopaque, len: usize, - log2_ptr_align: u8, + alignment: std.mem.Alignment, return_address: usize, ) ?[*]u8 { const self: *Allocator = @ptrCast(@alignCast(ctx)); - const result = self.parent_allocator.rawAlloc(len, log2_ptr_align, return_address); + const result = self.parent_allocator.rawAlloc(len, alignment, return_address); self.alloc_nb += 1; self.size += len; return result; @@ -118,12 +119,12 @@ pub const Allocator = struct { fn resize( ctx: *anyopaque, old_mem: []u8, - log2_old_align: u8, + alignment: std.mem.Alignment, new_len: usize, ra: usize, ) bool { const self: *Allocator = @ptrCast(@alignCast(ctx)); - const result = self.parent_allocator.rawResize(old_mem, log2_old_align, new_len, ra); + const result = self.parent_allocator.rawResize(old_mem, alignment, new_len, ra); self.realloc_nb += 1; // TODO: only if result is not null? return result; } @@ -131,13 +132,26 @@ pub const Allocator = struct { fn free( ctx: *anyopaque, old_mem: []u8, - log2_old_align: u8, + alignment: std.mem.Alignment, ra: usize, ) void { const self: *Allocator = @ptrCast(@alignCast(ctx)); - self.parent_allocator.rawFree(old_mem, log2_old_align, ra); + self.parent_allocator.rawFree(old_mem, alignment, ra); self.free_nb += 1; } + + fn remap( + ctx: *anyopaque, + memory: []u8, + alignment: std.mem.Alignment, + new_len: usize, + ret_addr: usize, + ) ?[*]u8 { + const self: *Allocator = @ptrCast(@alignCast(ctx)); + const result = self.parent_allocator.rawRemap(memory, alignment, new_len, ret_addr); + self.realloc_nb += 1; // TODO: only if result is not null? + return result; + } }; pub fn allocator(parent_allocator: std.mem.Allocator) Allocator { diff --git a/src/engines/v8/callback.zig b/src/engines/v8/callback.zig index 8f39927..d0352e2 100644 --- a/src/engines/v8/callback.zig +++ b/src/engines/v8/callback.zig @@ -314,7 +314,7 @@ pub const Func = struct { pub fn call(self: Func, nat_args: anytype) anyerror!void { // ensure Native args and JS args are not both provided const info = @typeInfo(@TypeOf(nat_args)); - if (comptime info != .Null) { + if (comptime info != .null) { // TODO: could be a compile error if we use generics for JS args std.debug.assert(self.js_args_pers.len == 0); } @@ -330,16 +330,16 @@ pub const Func = struct { // retrieve arguments var args = try self.nat_ctx.alloc.alloc(v8.Value, self.js_args_pers.len); defer self.nat_ctx.alloc.free(args); - if (comptime info == .Struct) { + if (comptime info == .@"struct") { // - Native arguments provided on function call - std.debug.assert(info.Struct.is_tuple); - args = try self.nat_ctx.alloc.alloc(v8.Value, info.Struct.fields.len); + std.debug.assert(info.@"struct".is_tuple); + args = try self.nat_ctx.alloc.alloc(v8.Value, info.@"struct".fields.len); comptime var i = 0; - inline while (i < info.Struct.fields.len) { + inline while (i < info.@"struct".fields.len) { comptime var ret: refl.Type = undefined; comptime { - ret = try refl.Type.reflect(info.Struct.fields[i].type, null); + ret = try refl.Type.reflect(info.@"struct".fields[i].type, null); try ret.lookup(gen.Types); } args[i] = try setNativeType( diff --git a/src/engines/v8/generate.zig b/src/engines/v8/generate.zig index b4f0074..ea41b30 100644 --- a/src/engines/v8/generate.zig +++ b/src/engines/v8/generate.zig @@ -618,7 +618,7 @@ pub fn setNativeType( const info = @typeInfo(@TypeOf(res)); // Optional - if (info == .Optional) { + if (info == .optional) { if (res == null) { // if null just return JS null return isolate.initNull().toValue(); @@ -919,7 +919,7 @@ fn callFunc( const function = @field(T_refl.T, func.name); const res_T = comptime func.return_type.underErr() orelse func.return_type.T; var res: res_T = undefined; - if (comptime @typeInfo(func.return_type.T) == .ErrorUnion) { + if (comptime @typeInfo(func.return_type.T) == .error_union) { res = @call(.auto, function, args) catch |err| { // TODO: how to handle internal errors vs user errors const js_err = throwError( @@ -1106,7 +1106,7 @@ fn staticAttrsKeys( return; } const attrs_T = T_refl.static_attrs_T.?; - inline for (@typeInfo(attrs_T).Struct.fields, 0..) |field, i| { + inline for (@typeInfo(attrs_T).@"struct".fields, 0..) |field, i| { keys[i] = v8.String.initUtf8(isolate, field.name).toName(); } } @@ -1121,7 +1121,7 @@ fn staticAttrsValues( } const attrs_T = T_refl.static_attrs_T.?; const attrs = comptime T_refl.staticAttrs(attrs_T); - inline for (@typeInfo(attrs_T).Struct.fields, 0..) |field, i| { + inline for (@typeInfo(attrs_T).@"struct".fields, 0..) |field, i| { const value = comptime @field(attrs, field.name); values[i] = nativeToJS(@TypeOf(value), value, isolate) catch unreachable; } @@ -1137,7 +1137,7 @@ fn setStaticAttrs( return; } const attrs_T = T_refl.static_attrs_T.?; - inline for (@typeInfo(attrs_T).Struct.fields, 0..) |_, i| { + inline for (@typeInfo(attrs_T).@"struct".fields, 0..) |_, i| { template.set(keys[i], values[i], v8.PropertyAttribute.ReadOnly + v8.PropertyAttribute.DontDelete); } } @@ -1198,7 +1198,7 @@ pub fn loadFunctionTemplate( // static attributes keys and values comptime var static_nb: usize = undefined; if (T_refl.static_attrs_T) |attr_T| { - static_nb = @typeInfo(attr_T).Struct.fields.len; + static_nb = @typeInfo(attr_T).@"struct".fields.len; } else { static_nb = 0; } diff --git a/src/engines/v8/types_primitives.zig b/src/engines/v8/types_primitives.zig index 82c662a..2161390 100644 --- a/src/engines/v8/types_primitives.zig +++ b/src/engines/v8/types_primitives.zig @@ -91,7 +91,7 @@ pub fn jsToNative( // JS Null or Undefined value if (js_val.isNull() or js_val.isUndefined()) { // if Native optional type return null - if (comptime info == .Optional) { + if (comptime info == .optional) { return null; } // Here we should normally return an error @@ -104,8 +104,8 @@ pub fn jsToNative( } // unwrap Optional - if (info == .Optional) { - return try jsToNative(alloc, info.Optional.child, js_val, isolate, ctx); + if (info == .optional) { + return try jsToNative(alloc, info.optional.child, js_val, isolate, ctx); } // JS values @@ -185,7 +185,7 @@ pub fn jsToObject( // JS Null or Undefined value if (js_val.isNull() or js_val.isUndefined()) { // if Native optional type return null - if (comptime info == .Optional) { + if (comptime info == .optional) { return null; } } @@ -196,8 +196,8 @@ pub fn jsToObject( } // unwrap Optional - if (comptime info == .Optional) { - return try jsToObject(alloc, nested_T, info.Optional.child, js_val, isolate, ctx); + if (comptime info == .optional) { + return try jsToObject(alloc, nested_T, info.optional.child, js_val, isolate, ctx); } const js_obj = js_val.castTo(v8.Object); diff --git a/src/engines/v8/v8.zig b/src/engines/v8/v8.zig index a1dbc52..4021698 100644 --- a/src/engines/v8/v8.zig +++ b/src/engines/v8/v8.zig @@ -531,7 +531,7 @@ pub const JSObject = struct { var js_value: v8.Value = undefined; if (comptime refl.isBuiltinType(@TypeOf(value))) { js_value = try nativeToJS(@TypeOf(value), value, isolate); - } else if (@typeInfo(@TypeOf(value)) == .Union) { + } else if (@typeInfo(@TypeOf(value)) == .@"union") { // NOTE: inspired by std.meta.TagPayloadByName const activeTag = @tagName(std.meta.activeTag(value)); inline for (std.meta.fields(@TypeOf(value))) |field| { diff --git a/src/generate.zig b/src/generate.zig index 44bc78e..fc37fe6 100644 --- a/src/generate.zig +++ b/src/generate.zig @@ -112,17 +112,17 @@ fn itoa(comptime i: u8) []const u8 { // retrieve the number of elements in a tuple fn tupleNb(comptime tuple: anytype) usize { var nb = 0; - for (@typeInfo(@TypeOf(tuple)).Struct.fields) |member| { + for (@typeInfo(@TypeOf(tuple)).@"struct".fields) |member| { const member_info = @typeInfo(member.type); - if (member_info != .Struct or (member_info == .Struct and !member_info.Struct.is_tuple)) { + if (member_info != .@"struct" or (member_info == .@"struct" and !member_info.@"struct".is_tuple)) { @compileError("GenerateMemberNotTypeOrTuple"); } - for (member_info.Struct.fields) |field| { + for (member_info.@"struct".fields) |field| { if (field.type != type) { @compileError("GenerateMemberTupleChildNotType"); } } - nb += member_info.Struct.fields.len; + nb += member_info.@"struct".fields.len; } return nb; } @@ -130,10 +130,10 @@ fn tupleNb(comptime tuple: anytype) usize { fn tupleTypes(comptime nb: usize, comptime tuple: anytype) [nb]type { var types: [nb]type = undefined; var i = 0; - for (@typeInfo(@TypeOf(tuple)).Struct.fields) |member| { + for (@typeInfo(@TypeOf(tuple)).@"struct".fields) |member| { const T = @field(tuple, member.name); const info = @typeInfo(@TypeOf(T)); - for (info.Struct.fields) |field| { + for (info.@"struct".fields) |field| { types[i] = @field(T, field.name); i += 1; } @@ -153,7 +153,7 @@ fn MergeTupleT(comptime value: anytype) type { // u8`. .name = itoa(i) ++ "", .type = type, - .default_value = null, + .default_value_ptr = null, .is_comptime = false, .alignment = @alignOf(type), }; @@ -166,7 +166,7 @@ fn MergeTupleT(comptime value: anytype) type { .decls = &decls, .is_tuple = true, }; - return @Type(std.builtin.Type{ .Struct = info }); + return @Type(std.builtin.Type{ .@"struct" = info }); } pub fn MergeTuple(comptime value: anytype) MergeTupleT(value) { diff --git a/src/interfaces.zig b/src/interfaces.zig index 9151df8..3d32f8f 100644 --- a/src/interfaces.zig +++ b/src/interfaces.zig @@ -29,10 +29,10 @@ const public = @import("api.zig"); pub fn API(comptime T: type, comptime LoadFnType: type) void { // nativeT(), the reflected type of a native struct - assertDecl(T, "nativeT", fn (self: T) callconv(.Inline) refl.Struct); + assertDecl(T, "nativeT", fn (comptime self: T) callconv(.Inline) refl.Struct); // loadFn(), the function loading and binding this native struct into the JS engine - assertDecl(T, "loadFn", fn (self: T) callconv(.Inline) LoadFnType); + assertDecl(T, "loadFn", fn (comptime self: T) callconv(.Inline) LoadFnType); } pub fn VM(comptime T: type) void { diff --git a/src/pretty.zig b/src/pretty.zig index 03a11a9..3e22bb4 100644 --- a/src/pretty.zig +++ b/src/pretty.zig @@ -17,7 +17,7 @@ const std = @import("std"); fn checkArgs(args: anytype) void { comptime { const info = @typeInfo(@TypeOf(args)); - if (info != .Struct or !info.Struct.is_tuple) { + if (info != .@"struct" or !info.@"struct".is_tuple) { @compileError("should be a tuple"); } } @@ -62,7 +62,7 @@ pub fn GenerateTable( // u8`. .name = name ++ "", .type = T, - .default_value = null, + .default_value_ptr = null, .is_comptime = false, .alignment = @alignOf(T), }; @@ -74,7 +74,7 @@ pub fn GenerateTable( .decls = &decls, .is_tuple = true, }; - const shape = @Type(std.builtin.Type{ .Struct = shape_info }); + const shape = @Type(std.builtin.Type{ .@"struct" = shape_info }); var table_c: TableConf = undefined; if (table_conf != null) { diff --git a/src/reflect.zig b/src/reflect.zig index 46aca12..ddb0c64 100644 --- a/src/reflect.zig +++ b/src/reflect.zig @@ -106,7 +106,7 @@ pub const Type = struct { // check if the error returned is part of the exception // (ie. the ErrorSet of the return type is a superset of the exception) const errName = @errorName(err); - for (@typeInfo(exceptSet).ErrorSet.?) |e| { + for (@typeInfo(exceptSet).error_set.?) |e| { if (std.mem.eql(u8, errName, e.name)) { return true; } @@ -117,10 +117,10 @@ pub const Type = struct { // If the Type is an ErrorUnion, returns it's ErrorSet pub fn errorSet(comptime self: Type) ?type { std.debug.assert(@inComptime()); - if (@typeInfo(self.T) != .ErrorUnion) { + if (@typeInfo(self.T) != .error_union) { return null; } - return @typeInfo(self.T).ErrorUnion.error_set; + return @typeInfo(self.T).error_union.error_set; } // NOTE: underlying types @@ -139,10 +139,10 @@ pub const Type = struct { // !Type fn _underErr(comptime T: type) ?type { const info = @typeInfo(T); - if (info != .ErrorUnion) { + if (info != .error_union) { return null; } - return info.ErrorUnion.payload; + return info.error_union.payload; } pub inline fn underErr(comptime self: Type) ?type { std.debug.assert(@inComptime()); @@ -154,10 +154,10 @@ pub const Type = struct { fn _underOpt(comptime T: type) ?type { const TT = Type._underErr(T) orelse T; const info = @typeInfo(TT); - if (info != .Optional) { + if (info != .optional) { return null; } - return info.Optional.child; + return info.optional.child; } pub inline fn underOpt(comptime self: Type) ?type { std.debug.assert(@inComptime()); @@ -177,9 +177,9 @@ pub const Type = struct { TT = T; } const info = @typeInfo(TT); - if (info == .Pointer and info.Pointer.size != .Slice) { + if (info == .pointer and info.pointer.size != .slice) { // NOTE: slice are pointers but we handle them as single value - return info.Pointer.child; + return info.pointer.child; } return null; } @@ -210,25 +210,25 @@ pub const Type = struct { const info = @typeInfo(T); // it's a struct - if (info != .Struct) { + if (info != .@"struct") { return null; } // with only 1 field - if (info.Struct.fields.len != 1) { + if (info.@"struct".fields.len != 1) { return null; } // which is called "slice" - const slice_field = info.Struct.fields[0]; + const slice_field = info.@"struct".fields[0]; if (!std.mem.eql(u8, slice_field.name, "slice")) { return null; } // and it's a slice const slice_info = @typeInfo(slice_field.type); - if (slice_info == .Pointer and slice_info.Pointer.size == .Slice) { - return slice_info.Pointer.child; + if (slice_info == .pointer and slice_info.pointer.size == .slice) { + return slice_info.pointer.child; } return null; @@ -258,6 +258,7 @@ pub const Type = struct { // check that user-defined types have been provided as an API pub fn lookup(comptime self: *Type, comptime structs: []const Struct) Error!void { std.debug.assert(@inComptime()); + @setEvalBranchQuota(10_000); // lookup unecessary for (builtin_types) |builtin_T| { @@ -321,13 +322,13 @@ pub const Type = struct { } fn reflectUnion(comptime T: type, comptime info: std.builtin.Type) Error![]const Type { - if (info.Union.tag_type == null) { + if (info.@"union".tag_type == null) { const msg = "union should be a tagged"; fmtErr(msg.len, msg, T); return error.TypeTaggedUnion; } - var union_types: [info.Union.fields.len]Type = undefined; - inline for (info.Union.fields, 0..) |field, i| { + var union_types: [info.@"union".fields.len]Type = undefined; + inline for (info.@"union".fields, 0..) |field, i| { union_types[i] = try Type.reflect(field.type, field.name); } @@ -342,7 +343,7 @@ pub const Type = struct { // union T var union_T: ?[]const Type = null; - if (info == .Union) { + if (info == .@"union") { union_T = try reflectUnion(T, info); } @@ -374,14 +375,14 @@ const Args = struct { var fields: [len]std.builtin.Type.StructField = undefined; if (self_T != null) { const name = try itoa(0); - fields[0] = std.builtin.Type.StructField{ + fields[0] = .{ // StructField.name expect a null terminated string. // concatenate the `[]const u8` string with an empty string // literal (`name ++ ""`) to explicitly coerce it to `[:0]const // u8`. .name = name ++ "", .type = self_T.?, - .default_value = null, + .default_value_ptr = null, .is_comptime = false, .alignment = @alignOf(self_T.?), }; @@ -391,28 +392,26 @@ const Args = struct { if (self_T != null) { x += 1; } - fields[x] = std.builtin.Type.StructField{ + fields[x] = .{ // StructField.name expect a null terminated string. // concatenate the `[]const u8` string with an empty string // literal (`name ++ ""`) to explicitly coerce it to `[:0]const // u8`. .name = arg.name.? ++ "", .type = arg.T, - .default_value = null, + .default_value_ptr = null, .is_comptime = false, .alignment = @alignOf(arg.T), }; } const decls = [_]std.builtin.Type.Declaration{}; const cfields = fields; - const s = std.builtin.Type.Struct{ + return @Type(.{ .@"struct" = .{ .layout = .auto, .fields = &cfields, .decls = &decls, .is_tuple = true, - }; - const t = std.builtin.Type{ .Struct = s }; - return @Type(t); + } }); } }; @@ -439,7 +438,7 @@ pub const FuncKind = enum { fn reflect(comptime T: type, decl: std.builtin.Type.Declaration) FuncKind { // exclude declarations who are not functions - if (@typeInfo(@TypeOf(@field(T, decl.name))) != .Fn) { + if (@typeInfo(@TypeOf(@field(T, decl.name))) != .@"fn") { return FuncKind.ignore; } @@ -490,6 +489,7 @@ pub const Func = struct { kind: FuncKind, fn lookupTypes(comptime self: *Func, comptime structs: []const Struct) Error!void { + @setEvalBranchQuota(100_000_000); // copy args var args: [self.args.len]Type = undefined; inline for (self.args, 0..) |arg, i| { @@ -520,13 +520,13 @@ pub const Func = struct { // T should be a func const func = @typeInfo(T); - if (func != .Fn) { + if (func != .@"fn") { // should not happen as Funckind.reflect has been called before @panic("func is not a function"); } // check self is present - var args = func.Fn.params; + var args = func.@"fn".params; if (kind != .constructor and args.len == 0) { // TODO: handle "class methods" const msg = "getter/setter/methods should have at least 1 argument, self"; @@ -684,7 +684,7 @@ pub const Func = struct { const args_T = comptime Args.reflect(self_T, &args_slice); // reflect return type - const return_type = try Type.reflect(func.Fn.return_type.?, null); + const return_type = try Type.reflect(func.@"fn".return_type.?, null); if (Type._is_variadic(return_type.underT())) return error.FuncReturnTypeVariadic; return Func{ @@ -736,7 +736,7 @@ pub const StructNested = struct { } // exclude types who are not structs - if (@typeInfo(decl_type) != .Struct) { + if (@typeInfo(decl_type) != .@"struct") { return false; } @@ -746,8 +746,8 @@ pub const StructNested = struct { fn reflect(comptime T: type) StructNested { const info = @typeInfo(T); - var fields: [info.Struct.fields.len]Type = undefined; - inline for (info.Struct.fields, 0..) |field, i| { + var fields: [info.@"struct".fields.len]Type = undefined; + inline for (info.@"struct".fields, 0..) |field, i| { fields[i] = try Type.reflect(field.type, field.name); } const cfields = fields; @@ -819,7 +819,7 @@ pub const Struct = struct { } pub inline fn isEmpty(comptime self: Struct) bool { - if (@typeInfo(self.Self()) == .Opaque) { + if (@typeInfo(self.Self()) == .@"opaque") { return false; } return @sizeOf(self.Self()) == 0; @@ -908,7 +908,7 @@ pub const Struct = struct { // exclude declarations of wrong type const attr_T = @TypeOf(@field(T, decl.name)); const attr_info = @typeInfo(attr_T); - if (attr_info == .Fn) { // functions + if (attr_info == .@"fn") { // functions return null; } for (builtin_types) |builtin_T| { @@ -951,7 +951,7 @@ pub const Struct = struct { } fn reflectAttrs(comptime T: type) ?type { - const decls = @typeInfo(T).Struct.decls; + const decls = @typeInfo(T).@"struct".decls; // first pass for attrs nb var attrs_nb = 0; @@ -973,30 +973,28 @@ pub const Struct = struct { if (attr_T == null) { continue; } - fields[attrs_done] = std.builtin.Type.StructField{ + fields[attrs_done] = .{ .name = decl.name[1..decl.name.len], // remove _ .type = attr_T.?, - .default_value = null, + .default_value_ptr = null, .is_comptime = false, // TODO: should be true here? .alignment = if (@sizeOf(attr_T.?) > 0) @alignOf(attr_T.?) else 0, }; attrs_done += 1; } const cfields = fields; - return @Type(.{ - .Struct = .{ - .layout = .auto, - .fields = &cfields, - .decls = &.{}, - .is_tuple = false, - }, - }); + return @Type(.{ .@"struct" = .{ + .layout = .auto, + .fields = &cfields, + .decls = &.{}, + .is_tuple = false, + } }); } pub fn staticAttrs(comptime self: Struct, comptime attrs_T: type) attrs_T { var attrs: attrs_T = undefined; var done = 0; - for (@typeInfo(self.T).Struct.decls) |decl| { + for (@typeInfo(self.T).@"struct".decls) |decl| { const attr_T = AttrT(self.T, decl); if (attr_T == null) { continue; @@ -1029,7 +1027,7 @@ pub const Struct = struct { return error.StructExceptionWithoutErrorSet; } const errSet = @field(T, "ErrorSet"); - if (@typeInfo(errSet) != .ErrorSet) { + if (@typeInfo(errSet) != .error_set) { return error.StructExceptionWrongErrorSet; } @@ -1106,12 +1104,12 @@ pub const Struct = struct { // check the 'protoype' declaration is a pointer const proto_info = @typeInfo(@field(T, "prototype")); - if (proto_info != .Pointer) { + if (proto_info != .pointer) { const msg = "struct 'prototype' declared must be a Pointer"; fmtErr(msg.len, msg, T); return error.StructPrototypeNotPointer; } - proto_T = proto_info.Pointer.child; + proto_T = proto_info.pointer.child; if (@hasDecl(T, "mem_guarantied")) { return proto_T; @@ -1122,13 +1120,13 @@ pub const Struct = struct { if (@hasField(real_T, "proto")) { // check the 'proto' field - inline for (@typeInfo(real_T).Struct.fields, 0..) |field, i| { + inline for (@typeInfo(real_T).@"struct".fields, 0..) |field, i| { if (!std.mem.eql(u8, field.name, "proto")) { continue; } // check the 'proto' field is not a pointer - if (@typeInfo(field.type) == .Pointer) { + if (@typeInfo(field.type) == .pointer) { const msg = "struct {s} 'proto' field should not be a Pointer"; fmtErr(msg.len, msg, T); return error.StructProtoPointer; @@ -1136,7 +1134,7 @@ pub const Struct = struct { // for layout where fields memory order is guarantied, // check the 'proto' field is the first one - if (@typeInfo(T).Struct.layout != .auto) { + if (@typeInfo(T).@"struct".layout != .auto) { if (i != 0) { const msg = "'proto' field should be the first one if memory layout is guarantied (extern)"; fmtErr(msg.len, msg, T); @@ -1151,10 +1149,10 @@ pub const Struct = struct { // check that 'protoCast' is a compatible function const proto_func = @typeInfo(@TypeOf(@field(proto_T.?, "protoCast"))); - if (proto_func != .Fn) { + if (proto_func != .@"fn") { return error.StructProtoCastNotFunction; } else { - const proto_args = proto_func.Fn.params; + const proto_args = proto_func.@"fn".params; if (proto_args.len != 1) { return error.StructProtoCastWrongFunction; } @@ -1165,12 +1163,12 @@ pub const Struct = struct { return error.StructProtoCastWrongFunction; } } - const ret_T = proto_func.Fn.return_type.?; + const ret_T = proto_func.@"fn".return_type.?; // can be a pointer or a value const ret_T_info = @typeInfo(ret_T); - if (ret_T_info == .Pointer) { - proto_res = ret_T_info.Pointer.child; + if (ret_T_info == .pointer) { + proto_res = ret_T_info.pointer.child; } else { proto_res = ret_T; } @@ -1199,7 +1197,7 @@ pub const Struct = struct { // T should be a struct const obj = @typeInfo(T); - if (obj != .Struct) { + if (obj != .@"struct") { const msg = "type is not a struct"; fmtErr(msg.len, msg, T); return error.StructNotStruct; @@ -1210,7 +1208,7 @@ pub const Struct = struct { // with unknown memory fields, like slices // see: https://github.com/ziglang/zig/issues/2201 // and https://github.com/ziglang/zig/issues/3133 - if (obj.Struct.layout == .@"packed") { + if (obj.@"struct".layout == .@"packed") { const msg = "type packed struct are not supported"; fmtErr(msg.len, msg, T); return error.StructPacked; @@ -1222,7 +1220,7 @@ pub const Struct = struct { if (@hasDecl(T, "Self")) { self_T = @field(T, "Self"); real_T = self_T.?; - if (@typeInfo(real_T) == .Pointer) { + if (@typeInfo(real_T) == .pointer) { const msg = "type Self type should not be a pointer"; fmtErr(msg.len, msg, T); return error.StructSelfPointer; @@ -1230,7 +1228,7 @@ pub const Struct = struct { } else { real_T = T; } - if (@typeInfo(real_T) != .Struct and @typeInfo(real_T) != .Opaque) { + if (@typeInfo(real_T) != .@"struct" and @typeInfo(real_T) != .@"opaque") { const msg = "type is not a struct or opaque"; fmtErr(msg.len, msg, T); return error.StructNotStruct; @@ -1245,13 +1243,13 @@ pub const Struct = struct { if (@hasDecl(T, "mem_guarantied")) { mem_guarantied = true; } else { - mem_guarantied = @typeInfo(T).Struct.layout != .auto; + mem_guarantied = @typeInfo(T).@"struct".layout != .auto; } // nested types var nested_nb: usize = 0; // first iteration to retrieve the number of nested structs - inline for (obj.Struct.decls) |decl| { + inline for (obj.@"struct".decls) |decl| { if (StructNested.isNested(T, decl)) { nested_nb += 1; } @@ -1259,7 +1257,7 @@ pub const Struct = struct { var nested: [nested_nb]StructNested = undefined; if (nested_nb > 0) { var nested_done: usize = 0; - inline for (obj.Struct.decls) |decl| { + inline for (obj.@"struct".decls) |decl| { if (StructNested.isNested(T, decl)) { const decl_type = @field(T, decl.name); nested[nested_done] = StructNested.reflect(decl_type); @@ -1276,7 +1274,7 @@ pub const Struct = struct { // iterate over struct declarations // struct fields are considerated private and ignored // first iteration to retrieve the number of each method kind - inline for (obj.Struct.decls) |decl| { + inline for (obj.@"struct".decls) |decl| { const kind = comptime FuncKind.reflect(T, decl); switch (kind) { .ignore => continue, @@ -1299,7 +1297,7 @@ pub const Struct = struct { // iterate over struct declarations // second iteration to generate funcs - inline for (obj.Struct.decls) |decl| { + inline for (obj.@"struct".decls) |decl| { // check declaration kind const kind = comptime FuncKind.reflect(T, decl); @@ -1518,12 +1516,12 @@ pub fn do(comptime types: anytype) Error![]const Struct { // check types provided const types_T = @TypeOf(types); const types_info = @typeInfo(types_T); - if (types_info != .Struct or !types_info.Struct.is_tuple) { + if (types_info != .@"struct" or !types_info.@"struct".is_tuple) { const msg = "arg 'types' should be a tuple of types"; fmtErr(msg.len, msg, types_T); return error.TypesNotTuple; } - const types_fields = types_info.Struct.fields; + const types_fields = types_info.@"struct".fields; // reflect each type var all: [types_fields.len]Struct = undefined; @@ -1582,12 +1580,12 @@ fn assertT(comptime T: type, comptime X: type, comptime opts: EqlOptions) !void const err = error.AssertT; const info = @typeInfo(X); switch (info) { - .ErrorUnion => { - if (opts.err) return try assertT(T, info.ErrorUnion.payload, opts); + .error_union => { + if (opts.err) return try assertT(T, info.error_union.payload, opts); return err; }, - .Optional => { - if (opts.opt) return try assertT(T, info.Optional.child, opts); + .optional => { + if (opts.opt) return try assertT(T, info.optional.child, opts); return err; }, else => return err, @@ -1596,7 +1594,7 @@ fn assertT(comptime T: type, comptime X: type, comptime opts: EqlOptions) !void pub fn isPointer(comptime T: type) bool { std.debug.assert(@inComptime()); - return @typeInfo(T) == .Pointer; + return @typeInfo(T) == .pointer; } // assert T is a supported container type @@ -1604,14 +1602,14 @@ pub fn isPointer(comptime T: type) bool { fn assertApi(comptime T: type) !void { const info = @typeInfo(T); return switch (info) { - .Struct, .Union => {}, + .@"struct", .@"union" => {}, else => error.AssertAPI, }; } // assert func is a function fn assertFunc(comptime func: type) !void { - if (@typeInfo(func) != .Fn) return error.AssertFunc; + if (@typeInfo(func) != .@"fn") return error.AssertFunc; } // assert func is a method of T @@ -1619,7 +1617,7 @@ fn assertFunc(comptime func: type) !void { fn assertFuncIsMethod(comptime T: type, comptime func: type, comptime strict: bool) !void { try assertFunc(func); const err = error.AssertFuncIsMethod; - const info = @typeInfo(func).Fn; + const info = @typeInfo(func).@"fn"; if (info.params.len == 0) return err; const first = info.params[0].type.?; @@ -1633,7 +1631,7 @@ fn assertFuncIsMethod(comptime T: type, comptime func: type, comptime strict: bo // ie. excluding internal types fn assertFuncParamsJSNb(comptime func: type, comptime nb: u8) !void { try assertFunc(func); - const info = @typeInfo(func).Fn; + const info = @typeInfo(func).@"fn"; var js_params = 0; for (info.params) |param| { if (!isInternalType(param.type.?)) { @@ -1647,7 +1645,7 @@ fn assertFuncParamsJSNb(comptime func: type, comptime nb: u8) !void { fn assertFuncParamIsT(comptime func: type, comptime T: type, comptime index: u8) !void { try assertFunc(func); const err = error.AssertFuncHasParam; - const info = @typeInfo(func).Fn; + const info = @typeInfo(func).@"fn"; if (info.params.len < index + 1) return err; if (info.params[index].type.? != T) { @@ -1658,7 +1656,7 @@ fn assertFuncParamIsT(comptime func: type, comptime T: type, comptime index: u8) // assert function has at least 1 parameter of type T fn assertFuncHasParamT(comptime func: type, comptime T: type) !void { try assertFunc(func); - const info = @typeInfo(func).Fn; + const info = @typeInfo(func).@"fn"; for (info.params) |param| { if (param.type.? == T) { @@ -1672,7 +1670,7 @@ fn assertFuncHasParamT(comptime func: type, comptime T: type) !void { // see EqlOptions for behavior details fn assertFuncReturnT(comptime func: type, comptime T: type, comptime opts: EqlOptions) !void { try assertFunc(func); - const ret = @typeInfo(func).Fn.return_type.?; + const ret = @typeInfo(func).@"fn".return_type.?; assertT(T, ret, opts) catch return error.AssertFuncReturnT; } @@ -1688,27 +1686,25 @@ fn createTupleT(comptime members: []const type) type { // u8`. .name = try itoa(i) ++ "", .type = member, - .default_value = null, + .default_value_ptr = null, .is_comptime = false, .alignment = @alignOf(member), }; } const cfields = fields; - const s = std.builtin.Type.Struct{ + return @Type(.{ .@"struct" = .{ .layout = .auto, .fields = &cfields, .decls = &.{}, .is_tuple = true, - }; - const t = std.builtin.Type{ .Struct = s }; - return @Type(t); + } }); } // argsT generate from the func parameters // a tuple type suitable for the @call builtin func fn argsT(comptime func: type) type { try assertFunc(func); - const info = @typeInfo(func).Fn; + const info = @typeInfo(func).@"fn"; var params: [info.params.len]type = undefined; for (info.params, 0..) |param, i| { params[i] = param.type.?; @@ -1724,10 +1720,10 @@ pub fn tupleTypes(comptime tuple: type) []type { std.debug.assert(@inComptime()); const info = @typeInfo(tuple); const err = error.TupleTypes; - if (info != .Struct) return err; - if (!info.Struct.is_tuple) return err; - var fields: [info.Struct.fields.len]type = undefined; - for (info.Struct.fields, 0..) |field, i| { + if (info != .@"struct") return err; + if (!info.@"struct".is_tuple) return err; + var fields: [info.@"struct".fields.len]type = undefined; + for (info.@"struct".fields, 0..) |field, i| { fields[i] = field.type; } return &fields; @@ -1737,7 +1733,7 @@ pub fn tupleTypes(comptime tuple: type) []type { pub fn funcReturnType(comptime func: type) !type { std.debug.assert(@inComptime()); try assertFunc(func); - const info = @typeInfo(func).Fn; + const info = @typeInfo(func).@"fn"; return info.return_type.?; } @@ -1745,7 +1741,7 @@ pub fn funcReturnType(comptime func: type) !type { pub fn isErrorUnion(comptime T: type) bool { std.debug.assert(@inComptime()); const info = @typeInfo(T); - return info == .ErrorUnion; + return info == .error_union; } // postAttachFunc check if T has `postAttach` function @@ -1767,7 +1763,7 @@ pub fn postAttachFunc(comptime T: type) !?type { pub fn hasDefaultValue(comptime T: type, comptime index: usize) bool { std.debug.assert(@inComptime()); - return @typeInfo(T).Struct.fields[index].default_value != null; + return @typeInfo(T).@"struct".fields[index].default_value_ptr != null; } pub fn isGlobalType(comptime T: type) bool { @@ -1808,7 +1804,7 @@ fn jsName(comptime name: []const u8) []const u8 { } fn shortName(comptime T: type) []const u8 { - var it = std.mem.splitBackwards(u8, @typeName(T), "."); + var it = std.mem.splitBackwardsScalar(u8, @typeName(T), '.'); return it.first(); } @@ -1821,7 +1817,7 @@ pub fn itoa(i: u8) ![]const u8 { fn isStringLiteral(comptime T: type) bool { // string literals are const pointers to null-terminated arrays of u8 - if (@typeInfo(T) != .Pointer) { + if (@typeInfo(T) != .pointer) { return false; } const elem = std.meta.Elem(T); diff --git a/src/shell.zig b/src/shell.zig index 5e1e31f..61f3c70 100644 --- a/src/shell.zig +++ b/src/shell.zig @@ -147,7 +147,7 @@ fn cmdCallback( input, "shell.js", ) catch { - const except = ctx.try_catch.exception(ctx.alloc, ctx.js_env.*) catch unreachable; + const except = ctx.try_catch.exception(ctx.alloc, ctx.js_env) catch unreachable; if (except) |msg| { defer ctx.alloc.free(msg); printStdout("\x1b[38;5;242mUncaught {s}\x1b[0m\n", .{msg}); @@ -156,7 +156,7 @@ fn cmdCallback( }; // JS print result - const s = res.toString(ctx.alloc, ctx.js_env.*) catch unreachable; + const s = res.toString(ctx.alloc, ctx.js_env) catch unreachable; defer ctx.alloc.free(s); if (std.mem.eql(u8, s, "undefined")) { printStdout("<- \x1b[38;5;242m{s}\x1b[0m\n", .{s}); @@ -191,7 +191,7 @@ pub fn shellExec( // JS try cache var try_catch: public.TryCatch = undefined; - try_catch.init(js_env.*); + try_catch.init(js_env); defer try_catch.deinit(); // create I/O contexts and callbacks @@ -226,7 +226,7 @@ pub fn shellExec( while (true) { try loop.io.run_for_ns(10 * std.time.ns_per_ms); if (loop.cbk_error) { - if (try try_catch.exception(alloc, js_env.*)) |msg| { + if (try try_catch.exception(alloc, js_env)) |msg| { defer alloc.free(msg); printStdout("\x1b[38;5;242mUncaught {s}\x1b[0m\n", .{msg}); } diff --git a/vendor/tigerbeetle-io b/vendor/tigerbeetle-io index a3a0145..bf55154 160000 --- a/vendor/tigerbeetle-io +++ b/vendor/tigerbeetle-io @@ -1 +1 @@ -Subproject commit a3a0145ad2a17115541078b3753eb23d9f270170 +Subproject commit bf55154bdfb9b76f23bbcd401a8a92e21d712438 diff --git a/vendor/zig-v8 b/vendor/zig-v8 index 1afd9fb..14ea439 160000 --- a/vendor/zig-v8 +++ b/vendor/zig-v8 @@ -1 +1 @@ -Subproject commit 1afd9fb2df3cad665bd204dbf4d9acc5d871ba97 +Subproject commit 14ea439e7fa8cb4f5cbbc3564d9234478cc8a740