diff --git a/src/account_batch.zig b/src/account_batch.zig index 064d88a..122de63 100644 --- a/src/account_batch.zig +++ b/src/account_batch.zig @@ -11,10 +11,10 @@ const AccountFlags = tb.AccountFlags; pub const AccountBatch = batch.Batch(Account); pub const AccountBatchResource = batch.BatchResource(Account); -pub fn create(env: beam.env, argc: c_int, argv: [*c]const beam.term) callconv(.C) beam.term { +pub fn create(env: beam.Env, argc: c_int, argv: [*c]const beam.Term) callconv(.C) beam.Term { assert(argc == 1); - const args = @ptrCast([*]const beam.term, argv)[0..@intCast(usize, argc)]; + const args = @ptrCast([*]const beam.Term, argv)[0..@intCast(usize, argc)]; const capacity: u32 = beam.get_u32(env, args[0]) catch return beam.raise_function_clause_error(env); @@ -22,10 +22,10 @@ pub fn create(env: beam.env, argc: c_int, argv: [*c]const beam.term) callconv(.C return batch.create(Account, env, capacity); } -pub fn add_account(env: beam.env, argc: c_int, argv: [*c]const beam.term) callconv(.C) beam.term { +pub fn add_account(env: beam.Env, argc: c_int, argv: [*c]const beam.Term) callconv(.C) beam.Term { assert(argc == 1); - const args = @ptrCast([*]const beam.term, argv)[0..@intCast(usize, argc)]; + const args = @ptrCast([*]const beam.Term, argv)[0..@intCast(usize, argc)]; return batch.add_item(Account, env, args[0]) catch |err| switch (err) { error.MutexLocked => return scheduler.reschedule(env, "add_account", add_account, argc, argv), @@ -39,18 +39,18 @@ pub const set_account_code = field_setter_fn(.code); pub const set_account_flags = field_setter_fn(.flags); fn field_setter_fn(comptime field: std.meta.FieldEnum(Account)) fn ( - beam.env, + beam.Env, c_int, - [*c]const beam.term, -) callconv(.C) beam.term { + [*c]const beam.Term, +) callconv(.C) beam.Term { const field_name = @tagName(field); const setter_name = "set_account_" ++ field_name; return struct { - fn setter_fn(env: beam.env, argc: c_int, argv: [*c]const beam.term) callconv(.C) beam.term { + fn setter_fn(env: beam.Env, argc: c_int, argv: [*c]const beam.Term) callconv(.C) beam.Term { assert(argc == 3); - const args = @ptrCast([*]const beam.term, argv)[0..@intCast(usize, argc)]; + const args = @ptrCast([*]const beam.Term, argv)[0..@intCast(usize, argc)]; const batch_term = args[0]; const account_batch_resource = AccountBatchResource.from_term_handle(env, batch_term) catch |err| @@ -88,7 +88,7 @@ fn field_setter_fn(comptime field: std.meta.FieldEnum(Account)) fn ( fn term_to_value_fn( comptime field: std.meta.FieldEnum(Account), -) fn (beam.env, beam.term) beam.GetError!std.meta.fieldInfo(Account, field).field_type { +) fn (beam.Env, beam.Term) beam.GetError!std.meta.fieldInfo(Account, field).field_type { return switch (field) { .id, .user_data => beam.get_u128, .ledger => beam.get_u32, @@ -98,7 +98,7 @@ fn term_to_value_fn( }; } -fn term_to_account_flags(env: beam.env, term: beam.term) beam.GetError!AccountFlags { +fn term_to_account_flags(env: beam.Env, term: beam.Term) beam.GetError!AccountFlags { const flags_uint = beam.get_u16(env, term) catch return beam.GetError.ArgumentError; diff --git a/src/batch.zig b/src/batch.zig index 8c6ec13..522868a 100644 --- a/src/batch.zig +++ b/src/batch.zig @@ -16,7 +16,7 @@ pub fn Batch(comptime T: anytype) type { }; } -pub fn create(comptime T: anytype, env: beam.env, capacity: u32) beam.term { +pub fn create(comptime T: anytype, env: beam.Env, capacity: u32) beam.Term { const items = beam.general_purpose_allocator.alloc(T, capacity) catch |err| switch (err) { error.OutOfMemory => return beam.make_error_atom(env, "out_of_memory"), @@ -37,7 +37,7 @@ pub fn create(comptime T: anytype, env: beam.env, capacity: u32) beam.term { return beam.make_ok_term(env, term_handle); } -pub fn add_item(comptime T: anytype, env: beam.env, batch_term: beam.term) !beam.term { +pub fn add_item(comptime T: anytype, env: beam.Env, batch_term: beam.Term) !beam.Term { const batch_resource = BatchResource(T).from_term_handle(env, batch_term) catch |err| switch (err) { error.InvalidResourceTerm => return beam.make_error_atom(env, "invalid_batch"), @@ -65,9 +65,9 @@ pub fn BatchResource(comptime T: anytype) type { fn batch_resource_deinit_fn( comptime T: anytype, -) fn (env: beam.env, ptr: ?*anyopaque) callconv(.C) void { +) fn (env: beam.Env, ptr: ?*anyopaque) callconv(.C) void { return struct { - fn deinit_fn(_: beam.env, ptr: ?*anyopaque) callconv(.C) void { + fn deinit_fn(_: beam.Env, ptr: ?*anyopaque) callconv(.C) void { if (ptr) |p| { const batch: *T = @ptrCast(*T, @alignCast(@alignOf(*T), p)); beam.general_purpose_allocator.free(batch.items); diff --git a/src/beam.zig b/src/beam.zig index e845230..b2d44c4 100644 --- a/src/beam.zig +++ b/src/beam.zig @@ -10,10 +10,10 @@ pub const resource = @import("beam/resource.zig"); pub const scheduler = @import("beam/scheduler.zig"); pub const Binary = @import("beam/Binary.zig"); -pub const env = ?*e.ErlNifEnv; -pub const pid = e.ErlNifPid; -pub const resource_type = ?*e.ErlNifResourceType; -pub const term = e.ERL_NIF_TERM; +pub const Env = ?*e.ErlNifEnv; +pub const Pid = e.ErlNifPid; +pub const ResourceType = ?*e.ErlNifResourceType; +pub const Term = e.ERL_NIF_TERM; /// The raw BEAM allocator with the standard Zig Allocator interface. pub const raw_allocator = allocator.raw_allocator; @@ -26,99 +26,99 @@ pub const large_allocator = allocator.large_allocator; pub const general_purpose_allocator = allocator.general_purpose_allocator; /// Raises a generic exception -pub fn raise(env_: env, reason: []const u8) term { - return e.enif_raise_exception(env_, make_atom(env_, reason)); +pub fn raise(env: Env, reason: []const u8) Term { + return e.enif_raise_exception(env, make_atom(env, reason)); } /// Raises a `:function_clause` exception -pub fn raise_function_clause_error(env_: env) term { - return raise(env_, "function_clause"); +pub fn raise_function_clause_error(env: Env) Term { + return raise(env, "function_clause"); } /// Creates a ref -pub fn make_ref(env_: env) term { - return e.enif_make_ref(env_); +pub fn make_ref(env: Env) Term { + return e.enif_make_ref(env); } /// Creates an atom from a Zig char slice -pub fn make_atom(env_: env, atom_str: []const u8) term { - return e.enif_make_atom_len(env_, atom_str.ptr, atom_str.len); +pub fn make_atom(env: Env, atom_str: []const u8) Term { + return e.enif_make_atom_len(env, atom_str.ptr, atom_str.len); } /// Creates a beam `nil` atom -pub fn make_nil(env_: env) term { - return e.enif_make_atom(env_, "nil"); +pub fn make_nil(env: Env) Term { + return e.enif_make_atom(env, "nil"); } /// Creates a beam `:ok` atom -pub fn make_ok(env_: env) term { - return e.enif_make_atom(env_, "ok"); +pub fn make_ok(env: Env) Term { + return e.enif_make_atom(env, "ok"); } /// Helper to create an `{:ok, term}` tuple -pub fn make_ok_term(env_: env, val: term) term { - return e.enif_make_tuple(env_, 2, make_ok(env_), val); +pub fn make_ok_term(env: Env, val: Term) Term { + return e.enif_make_tuple(env, 2, make_ok(env), val); } /// Helper to create an `{:ok, atom}` tuple, taking the atom value from a slice -pub fn make_ok_atom(env_: env, atom_str: []const u8) term { - return make_ok_term(env_, make_atom(env_, atom_str)); +pub fn make_ok_atom(env: Env, atom_str: []const u8) Term { + return make_ok_term(env, make_atom(env, atom_str)); } /// Creates a beam `:error` atom. -pub fn make_error(env_: env) term { - return e.enif_make_atom(env_, "error"); +pub fn make_error(env: Env) Term { + return e.enif_make_atom(env, "error"); } /// Helper to create an `{:error, term}` tuple -pub fn make_error_term(env_: env, val: term) term { - return e.enif_make_tuple(env_, 2, make_error(env_), val); +pub fn make_error_term(env: Env, val: Term) Term { + return e.enif_make_tuple(env, 2, make_error(env), val); } /// Helper to create an `{:error, atom}` tuple, taking the atom value from a slice -pub fn make_error_atom(env_: env, atom_str: []const u8) term { - return make_error_term(env_, make_atom(env_, atom_str)); +pub fn make_error_atom(env: Env, atom_str: []const u8) Term { + return make_error_term(env, make_atom(env, atom_str)); } /// Creates a binary term from a Zig slice -pub fn make_slice(environment: env, val: []const u8) term { - var result: term = undefined; - var bin: [*]u8 = @ptrCast([*]u8, e.enif_make_new_binary(environment, val.len, &result)); +pub fn make_slice(env: Env, val: []const u8) Term { + var result: Term = undefined; + var bin: [*]u8 = @ptrCast([*]u8, e.enif_make_new_binary(env, val.len, &result)); std.mem.copy(u8, bin[0..val.len], val); return result; } /// Creates a u8 value term. -pub fn make_u8(env_: env, val: u8) term { - return e.enif_make_uint(env_, val); +pub fn make_u8(env: Env, val: u8) Term { + return e.enif_make_uint(env, val); } /// Creates a u32 value term. -pub fn make_u32(env_: env, val: u32) term { - return e.enif_make_uint(env_, val); +pub fn make_u32(env: Env, val: u32) Term { + return e.enif_make_uint(env, val); } /// Creates an BEAM tuple from a Zig tuple of terms -pub fn make_tuple(env_: env, tuple: anytype) term { +pub fn make_tuple(env: Env, tuple: anytype) Term { const type_info = @typeInfo(@TypeOf(tuple)); if (type_info != .Struct or !type_info.Struct.is_tuple) @compileError("invalid argument to make_tuple: not a tuple"); - var tuple_list: [tuple.len]term = undefined; + var tuple_list: [tuple.len]Term = undefined; inline for (tuple_list) |*tuple_item, index| { const tuple_term = tuple[index]; tuple_item.* = tuple_term; } - return e.enif_make_tuple_from_array(env_, &tuple_list, tuple.len); + return e.enif_make_tuple_from_array(env, &tuple_list, tuple.len); } pub const GetError = error{ArgumentError}; /// Extract a binary from a term, returning it as a slice -pub fn get_char_slice(env_: env, src_term: term) GetError![]u8 { +pub fn get_char_slice(env: Env, src_term: Term) GetError![]u8 { var bin: e.ErlNifBinary = undefined; - if (e.enif_inspect_binary(env_, src_term, &bin) == 0) { + if (e.enif_inspect_binary(env, src_term, &bin) == 0) { return GetError.ArgumentError; } @@ -126,8 +126,8 @@ pub fn get_char_slice(env_: env, src_term: term) GetError![]u8 { } /// Extract a u128 from a binary (little endian) term -pub fn get_u128(env_: env, src_term: term) GetError!u128 { - const bin = try get_char_slice(env_, src_term); +pub fn get_u128(env: Env, src_term: Term) GetError!u128 { + const bin = try get_char_slice(env, src_term); const required_length = @sizeOf(u128) / @sizeOf(u8); // We represent the u128 as a 16 byte binary, little endian (required by TigerBeetle) @@ -137,9 +137,9 @@ pub fn get_u128(env_: env, src_term: term) GetError!u128 { } /// Extract a u64 from a term -pub fn get_u64(env_: env, src_term: term) GetError!u64 { +pub fn get_u64(env: Env, src_term: Term) GetError!u64 { var result: c_ulong = undefined; - if (e.enif_get_ulong(env_, src_term, &result) == 0) { + if (e.enif_get_ulong(env, src_term, &result) == 0) { return GetError.ArgumentError; } @@ -147,9 +147,9 @@ pub fn get_u64(env_: env, src_term: term) GetError!u64 { } /// Extract a u32 from a term -pub fn get_u32(env_: env, src_term: term) GetError!u32 { +pub fn get_u32(env: Env, src_term: Term) GetError!u32 { var result: c_uint = undefined; - if (e.enif_get_uint(env_, src_term, &result) == 0) { + if (e.enif_get_uint(env, src_term, &result) == 0) { return GetError.ArgumentError; } @@ -157,9 +157,9 @@ pub fn get_u32(env_: env, src_term: term) GetError!u32 { } /// Extract a u16 from a term, checking it does not go outside the boundaries -pub fn get_u16(env_: env, src_term: term) GetError!u16 { +pub fn get_u16(env: Env, src_term: Term) GetError!u16 { var result: c_uint = undefined; - if (e.enif_get_uint(env_, src_term, &result) == 0) { + if (e.enif_get_uint(env, src_term, &result) == 0) { return GetError.ArgumentError; } @@ -173,9 +173,9 @@ pub fn get_u16(env_: env, src_term: term) GetError!u16 { pub const TermToBinaryError = error{OutOfMemory}; /// Serializes a term to a beam.Binary -pub fn term_to_binary(env_: env, src_term: term) TermToBinaryError!Binary { +pub fn term_to_binary(env: Env, src_term: Term) TermToBinaryError!Binary { var bin: e.ErlNifBinary = undefined; - if (e.enif_term_to_binary(env_, src_term, &bin) == 0) { + if (e.enif_term_to_binary(env, src_term, &bin) == 0) { return error.OutOfMemory; } @@ -183,11 +183,11 @@ pub fn term_to_binary(env_: env, src_term: term) TermToBinaryError!Binary { } /// Allocates a process independent environment -pub fn alloc_env() env { +pub fn alloc_env() Env { return e.enif_alloc_env(); } /// Clears a process independent environment -pub fn clear_env(env_: env) void { - e.enif_clear_env(env_); +pub fn clear_env(env: Env) void { + e.enif_clear_env(env); } diff --git a/src/beam/Binary.zig b/src/beam/Binary.zig index f3d8bc0..79d1e80 100644 --- a/src/beam/Binary.zig +++ b/src/beam/Binary.zig @@ -1,6 +1,5 @@ const e = @import("../erl_nif.zig"); -const env = @import("../beam.zig").env; -const term = @import("../beam.zig").term; +const beam = @import("../beam.zig"); const Self = @This(); binary: e.ErlNifBinary, @@ -11,9 +10,9 @@ pub fn slice(self: Self) []const u8 { pub const ToTermError = error{InvalidBinaryTerm}; -pub fn to_term(self: Self, env_: env) ToTermError!term { - var result: term = undefined; - if (e.enif_binary_to_term(env_, self.binary.data, self.binary.size, &result, 0) == 0) { +pub fn to_term(self: Self, env: beam.Env) ToTermError!beam.Term { + var result: beam.Term = undefined; + if (e.enif_binary_to_term(env, self.binary.data, self.binary.size, &result, 0) == 0) { return error.InvalidBinaryTerm; } diff --git a/src/beam/resource.zig b/src/beam/resource.zig index 5eac03e..0c0c906 100644 --- a/src/beam/resource.zig +++ b/src/beam/resource.zig @@ -9,16 +9,16 @@ pub const Error = error{ OutOfMemory, }; -const DeinitFn = *const fn (beam.env, ?*anyopaque) callconv(.C) void; +const DeinitFn = *const fn (beam.Env, ?*anyopaque) callconv(.C) void; pub fn Resource(comptime T: anytype, comptime deinit_fn: ?DeinitFn) type { return struct { const Self = @This(); const Type = struct { - beam_type: beam.resource_type, + beam_type: beam.ResourceType, - pub fn open(env: beam.env) Type { + pub fn open(env: beam.Env) Type { const beam_type = e.enif_open_resource_type( env, null, @@ -40,7 +40,7 @@ pub fn Resource(comptime T: anytype, comptime deinit_fn: ?DeinitFn) type { /// Initializes the type of the resource. This must be called exactly once /// in the load or upgrade callback of the NIF. - pub fn create_type(env: beam.env) void { + pub fn create_type(env: beam.Env) void { // TODO: is this required or are we allowed to re-open a type? assert(resource_type == null); @@ -69,7 +69,7 @@ pub fn Resource(comptime T: anytype, comptime deinit_fn: ?DeinitFn) type { } /// Recreates the resource from the term handle obtained with `term_handle` - pub fn from_term_handle(env: beam.env, term: beam.term) !Self { + pub fn from_term_handle(env: beam.Env, term: beam.Term) !Self { var raw_ptr: ?*anyopaque = undefined; if (0 == e.enif_get_resource(env, term, res_type(), &raw_ptr)) { @@ -80,7 +80,7 @@ pub fn Resource(comptime T: anytype, comptime deinit_fn: ?DeinitFn) type { } /// Obtains a term handle to the resource - pub fn term_handle(self: Self, env: beam.env) beam.term { + pub fn term_handle(self: Self, env: beam.Env) beam.Term { return e.enif_make_resource(env, self.raw_ptr); } @@ -115,7 +115,7 @@ pub fn Resource(comptime T: anytype, comptime deinit_fn: ?DeinitFn) type { return @ptrCast(*T, @alignCast(@alignOf(*T), self.raw_ptr)); } - fn res_type() beam.resource_type { + fn res_type() beam.ResourceType { return resource_type.?.beam_type; } }; diff --git a/src/beam/scheduler.zig b/src/beam/scheduler.zig index d805492..09c51ca 100644 --- a/src/beam/scheduler.zig +++ b/src/beam/scheduler.zig @@ -2,11 +2,11 @@ const e = @import("../erl_nif.zig"); const beam = @import("../beam.zig"); pub fn reschedule( - env_: beam.env, + env: beam.Env, name: [*c]const u8, - fun: *const fn (beam.env, argc: c_int, argv: [*c]const beam.term) callconv(.C) beam.term, + fun: *const fn (beam.Env, argc: c_int, argv: [*c]const beam.Term) callconv(.C) beam.Term, argc: c_int, - argv: [*c]const beam.term, -) beam.term { - return e.enif_schedule_nif(env_, name, 0, fun, argc, argv); + argv: [*c]const beam.Term, +) beam.Term { + return e.enif_schedule_nif(env, name, 0, fun, argc, argv); } diff --git a/src/client.zig b/src/client.zig index 748abc7..eaf50ae 100644 --- a/src/client.zig +++ b/src/client.zig @@ -19,15 +19,15 @@ pub const Client = tb_client.tb_client_t; pub const ClientResource = Resource(Client, client_resource_deinit_fn); const RequestContext = struct { - caller_pid: beam.pid, + caller_pid: beam.Pid, request_ref_binary: beam.Binary, payload_resource_ptr: *anyopaque, }; -pub fn init(env: beam.env, argc: c_int, argv: [*c]const beam.term) callconv(.C) beam.term { +pub fn init(env: beam.Env, argc: c_int, argv: [*c]const beam.Term) callconv(.C) beam.Term { assert(argc == 3); - const args = @ptrCast([*]const beam.term, argv)[0..@intCast(usize, argc)]; + const args = @ptrCast([*]const beam.Term, argv)[0..@intCast(usize, argc)]; const cluster_id: u32 = beam.get_u32(env, args[0]) catch return beam.raise_function_clause_error(env); @@ -80,10 +80,10 @@ fn batch_item_type_for_operation(comptime operation: tb_client.tb_operation_t) t fn submit( comptime operation: tb_client.tb_operation_t, - env: beam.env, - client_term: beam.term, - payload_term: beam.term, -) beam.term { + env: beam.Env, + client_term: beam.Term, + payload_term: beam.Term, +) beam.Term { const client_resource = ClientResource.from_term_handle(env, client_term) catch |err| switch (err) { error.InvalidResourceTerm => return beam.make_error_atom(env, "invalid_client"), @@ -146,34 +146,34 @@ fn submit( return beam.make_ok_term(env, ref); } -pub fn create_accounts(env: beam.env, argc: c_int, argv: [*c]const beam.term) callconv(.C) beam.term { +pub fn create_accounts(env: beam.Env, argc: c_int, argv: [*c]const beam.Term) callconv(.C) beam.Term { assert(argc == 2); - const args = @ptrCast([*]const beam.term, argv)[0..@intCast(usize, argc)]; + const args = @ptrCast([*]const beam.Term, argv)[0..@intCast(usize, argc)]; return submit(.create_accounts, env, args[0], args[1]); } -pub fn create_transfers(env: beam.env, argc: c_int, argv: [*c]const beam.term) callconv(.C) beam.term { +pub fn create_transfers(env: beam.Env, argc: c_int, argv: [*c]const beam.Term) callconv(.C) beam.Term { assert(argc == 2); - const args = @ptrCast([*]const beam.term, argv)[0..@intCast(usize, argc)]; + const args = @ptrCast([*]const beam.Term, argv)[0..@intCast(usize, argc)]; return submit(.create_transfers, env, args[0], args[1]); } -pub fn lookup_accounts(env: beam.env, argc: c_int, argv: [*c]const beam.term) callconv(.C) beam.term { +pub fn lookup_accounts(env: beam.Env, argc: c_int, argv: [*c]const beam.Term) callconv(.C) beam.Term { assert(argc == 2); - const args = @ptrCast([*]const beam.term, argv)[0..@intCast(usize, argc)]; + const args = @ptrCast([*]const beam.Term, argv)[0..@intCast(usize, argc)]; return submit(.lookup_accounts, env, args[0], args[1]); } -pub fn lookup_transfers(env: beam.env, argc: c_int, argv: [*c]const beam.term) callconv(.C) beam.term { +pub fn lookup_transfers(env: beam.Env, argc: c_int, argv: [*c]const beam.Term) callconv(.C) beam.Term { assert(argc == 2); - const args = @ptrCast([*]const beam.term, argv)[0..@intCast(usize, argc)]; + const args = @ptrCast([*]const beam.Term, argv)[0..@intCast(usize, argc)]; return submit(.lookup_transfers, env, args[0], args[1]); } @@ -192,7 +192,7 @@ fn on_completion( // This is a raw object pointer so we call resource.raw_release resource.raw_release(ctx.payload_resource_ptr); - const env = @intToPtr(beam.env, context); + const env = @intToPtr(beam.Env, context); defer beam.clear_env(env); var ref_binary = ctx.request_ref_binary; @@ -222,7 +222,7 @@ fn on_completion( process.send(caller_pid, env, msg) catch unreachable; } -fn client_resource_deinit_fn(_: beam.env, ptr: ?*anyopaque) callconv(.C) void { +fn client_resource_deinit_fn(_: beam.Env, ptr: ?*anyopaque) callconv(.C) void { if (ptr) |p| { const cl: *Client = @ptrCast(*Client, @alignCast(@alignOf(*Client), p)); // TODO: this can now potentially block for a long time since it waits diff --git a/src/id_batch.zig b/src/id_batch.zig index 32c0c39..48fc30f 100644 --- a/src/id_batch.zig +++ b/src/id_batch.zig @@ -8,10 +8,10 @@ const scheduler = beam.scheduler; pub const IdBatch = batch.Batch(u128); pub const IdBatchResource = batch.BatchResource(u128); -pub fn create(env: beam.env, argc: c_int, argv: [*c]const beam.term) callconv(.C) beam.term { +pub fn create(env: beam.Env, argc: c_int, argv: [*c]const beam.Term) callconv(.C) beam.Term { assert(argc == 1); - const args = @ptrCast([*]const beam.term, argv)[0..@intCast(usize, argc)]; + const args = @ptrCast([*]const beam.Term, argv)[0..@intCast(usize, argc)]; const capacity: u32 = beam.get_u32(env, args[0]) catch return beam.raise_function_clause_error(env); @@ -19,11 +19,11 @@ pub fn create(env: beam.env, argc: c_int, argv: [*c]const beam.term) callconv(.C return batch.create(u128, env, capacity); } -pub fn add_id(env: beam.env, argc: c_int, argv: [*c]const beam.term) callconv(.C) beam.term { +pub fn add_id(env: beam.Env, argc: c_int, argv: [*c]const beam.Term) callconv(.C) beam.Term { // We don't use beam.add_item since we increase len and directly add the id in a single call assert(argc == 2); - const args = @ptrCast([*]const beam.term, argv)[0..@intCast(usize, argc)]; + const args = @ptrCast([*]const beam.Term, argv)[0..@intCast(usize, argc)]; const id = beam.get_u128(env, args[1]) catch return beam.raise_function_clause_error(env); @@ -51,10 +51,10 @@ pub fn add_id(env: beam.env, argc: c_int, argv: [*c]const beam.term) callconv(.C } } -pub fn set_id(env: beam.env, argc: c_int, argv: [*c]const beam.term) callconv(.C) beam.term { +pub fn set_id(env: beam.Env, argc: c_int, argv: [*c]const beam.Term) callconv(.C) beam.Term { assert(argc == 3); - const args = @ptrCast([*]const beam.term, argv)[0..@intCast(usize, argc)]; + const args = @ptrCast([*]const beam.Term, argv)[0..@intCast(usize, argc)]; const batch_term = args[0]; const id_batch_resource = IdBatchResource.from_term_handle(env, batch_term) catch |err| diff --git a/src/process.zig b/src/process.zig index 2a60277..1a1af7e 100644 --- a/src/process.zig +++ b/src/process.zig @@ -3,8 +3,8 @@ const e = @import("erl_nif.zig"); pub const SelfError = error{NotProcessBound}; -pub fn self(env: beam.env) SelfError!beam.pid { - var result: beam.pid = undefined; +pub fn self(env: beam.Env) SelfError!beam.Pid { + var result: beam.Pid = undefined; if (e.enif_self(env, &result) == null) { return error.NotProcessBound; } @@ -14,7 +14,7 @@ pub fn self(env: beam.env) SelfError!beam.pid { pub const SendError = error{NotDelivered}; -pub fn send(dest: beam.pid, msg_env: beam.env, msg: beam.term) !void { +pub fn send(dest: beam.Pid, msg_env: beam.Env, msg: beam.Term) !void { // Needed since enif_send is not const-correct var to_pid = dest; diff --git a/src/tigerbeetlex.zig b/src/tigerbeetlex.zig index ebc90cb..0021564 100644 --- a/src/tigerbeetlex.zig +++ b/src/tigerbeetlex.zig @@ -217,7 +217,7 @@ export fn nif_init() *const e.ErlNifEntry { return &entry; } -export fn nif_load(env: beam.env, _: [*c]?*anyopaque, _: beam.term) c_int { +export fn nif_load(env: beam.Env, _: [*c]?*anyopaque, _: beam.Term) c_int { ClientResource.create_type(env); AccountBatchResource.create_type(env); IdBatchResource.create_type(env); diff --git a/src/transfer_batch.zig b/src/transfer_batch.zig index bb02878..8bf52cb 100644 --- a/src/transfer_batch.zig +++ b/src/transfer_batch.zig @@ -11,10 +11,10 @@ const TransferFlags = tb.TransferFlags; pub const TransferBatch = batch.Batch(Transfer); pub const TransferBatchResource = batch.BatchResource(Transfer); -pub fn create(env: beam.env, argc: c_int, argv: [*c]const beam.term) callconv(.C) beam.term { +pub fn create(env: beam.Env, argc: c_int, argv: [*c]const beam.Term) callconv(.C) beam.Term { assert(argc == 1); - const args = @ptrCast([*]const beam.term, argv)[0..@intCast(usize, argc)]; + const args = @ptrCast([*]const beam.Term, argv)[0..@intCast(usize, argc)]; const capacity: u32 = beam.get_u32(env, args[0]) catch return beam.raise_function_clause_error(env); @@ -22,10 +22,10 @@ pub fn create(env: beam.env, argc: c_int, argv: [*c]const beam.term) callconv(.C return batch.create(Transfer, env, capacity); } -pub fn add_transfer(env: beam.env, argc: c_int, argv: [*c]const beam.term) callconv(.C) beam.term { +pub fn add_transfer(env: beam.Env, argc: c_int, argv: [*c]const beam.Term) callconv(.C) beam.Term { assert(argc == 1); - const args = @ptrCast([*]const beam.term, argv)[0..@intCast(usize, argc)]; + const args = @ptrCast([*]const beam.Term, argv)[0..@intCast(usize, argc)]; return batch.add_item(Transfer, env, args[0]) catch |err| switch (err) { error.MutexLocked => return scheduler.reschedule(env, "add_transfer", add_transfer, argc, argv), @@ -44,18 +44,18 @@ pub const set_transfer_flags = field_setter_fn(.flags); pub const set_transfer_amount = field_setter_fn(.amount); fn field_setter_fn(comptime field: std.meta.FieldEnum(Transfer)) fn ( - beam.env, + beam.Env, c_int, - [*c]const beam.term, -) callconv(.C) beam.term { + [*c]const beam.Term, +) callconv(.C) beam.Term { const field_name = @tagName(field); const setter_name = "set_transfer_" ++ field_name; return struct { - fn setter_fn(env: beam.env, argc: c_int, argv: [*c]const beam.term) callconv(.C) beam.term { + fn setter_fn(env: beam.Env, argc: c_int, argv: [*c]const beam.Term) callconv(.C) beam.Term { assert(argc == 3); - const args = @ptrCast([*]const beam.term, argv)[0..@intCast(usize, argc)]; + const args = @ptrCast([*]const beam.Term, argv)[0..@intCast(usize, argc)]; const batch_term = args[0]; const transfer_batch_resource = TransferBatchResource.from_term_handle(env, batch_term) catch |err| @@ -93,7 +93,7 @@ fn field_setter_fn(comptime field: std.meta.FieldEnum(Transfer)) fn ( fn term_to_value_fn( comptime field: std.meta.FieldEnum(Transfer), -) fn (beam.env, beam.term) beam.GetError!std.meta.fieldInfo(Transfer, field).field_type { +) fn (beam.Env, beam.Term) beam.GetError!std.meta.fieldInfo(Transfer, field).field_type { return switch (field) { .id, .debit_account_id, .credit_account_id, .user_data, .pending_id => beam.get_u128, .timeout, .amount => beam.get_u64, @@ -104,7 +104,7 @@ fn term_to_value_fn( }; } -fn term_to_transfer_flags(env: beam.env, term: beam.term) beam.GetError!TransferFlags { +fn term_to_transfer_flags(env: beam.Env, term: beam.Term) beam.GetError!TransferFlags { const flags_uint = beam.get_u16(env, term) catch return beam.GetError.ArgumentError;