Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/zig-fmt.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: zig-fmt

env:
ZIG_VERSION: 0.13.0
ZIG_VERSION: 0.14.0

on:
pull_request:
Expand Down
6 changes: 4 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
28 changes: 21 additions & 7 deletions src/bench.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand All @@ -118,26 +119,39 @@ 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;
}

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 {
Expand Down
12 changes: 6 additions & 6 deletions src/engines/v8/callback.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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(
Expand Down
12 changes: 6 additions & 6 deletions src/engines/v8/generate.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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();
}
}
Expand All @@ -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;
}
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions src/engines/v8/types_primitives.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/engines/v8/v8.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
16 changes: 8 additions & 8 deletions src/generate.zig
Original file line number Diff line number Diff line change
Expand Up @@ -112,28 +112,28 @@ 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;
}

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;
}
Expand All @@ -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),
};
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/pretty.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Expand Down Expand Up @@ -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),
};
Expand All @@ -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) {
Expand Down
Loading