mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
fix zig build errors
This commit is contained in:
parent
011c13fb17
commit
a8dd6244e9
5 changed files with 83 additions and 78 deletions
|
@ -244,8 +244,11 @@ pub const RocDec = extern struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn abs(self: RocDec) !RocDec {
|
pub fn abs(self: RocDec) !RocDec {
|
||||||
const absolute = try math.absInt(self.num);
|
const absolute = @abs(self.num);
|
||||||
return RocDec{ .num = absolute };
|
if (absolute <= @as(u128, @intCast(std.math.maxInt(i128)))) {
|
||||||
|
return RocDec{ .num = @intCast(absolute) };
|
||||||
|
}
|
||||||
|
return error.OutOfRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn addWithOverflow(self: RocDec, other: RocDec) WithOverflow(RocDec) {
|
pub fn addWithOverflow(self: RocDec, other: RocDec) WithOverflow(RocDec) {
|
||||||
|
@ -314,7 +317,8 @@ pub const RocDec = extern struct {
|
||||||
|
|
||||||
const is_answer_negative = (self_i128 < 0) != (other_i128 < 0);
|
const is_answer_negative = (self_i128 < 0) != (other_i128 < 0);
|
||||||
|
|
||||||
const self_u128 = @as(u128, @intCast(math.absInt(self_i128) catch {
|
const self_u128 = @abs(self_i128);
|
||||||
|
if (self_u128 > @as(u128, @intCast(std.math.maxInt(i128)))) {
|
||||||
if (other_i128 == 0) {
|
if (other_i128 == 0) {
|
||||||
return .{ .value = RocDec{ .num = 0 }, .has_overflowed = false };
|
return .{ .value = RocDec{ .num = 0 }, .has_overflowed = false };
|
||||||
} else if (other_i128 == RocDec.one_point_zero.num) {
|
} else if (other_i128 == RocDec.one_point_zero.num) {
|
||||||
|
@ -324,9 +328,10 @@ pub const RocDec = extern struct {
|
||||||
} else {
|
} else {
|
||||||
return .{ .value = RocDec.max, .has_overflowed = true };
|
return .{ .value = RocDec.max, .has_overflowed = true };
|
||||||
}
|
}
|
||||||
}));
|
}
|
||||||
|
|
||||||
const other_u128 = @as(u128, @intCast(math.absInt(other_i128) catch {
|
const other_u128 = @abs(other_i128);
|
||||||
|
if (other_u128 > @as(u128, @intCast(std.math.maxInt(i128)))) {
|
||||||
if (self_i128 == 0) {
|
if (self_i128 == 0) {
|
||||||
return .{ .value = RocDec{ .num = 0 }, .has_overflowed = false };
|
return .{ .value = RocDec{ .num = 0 }, .has_overflowed = false };
|
||||||
} else if (self_i128 == RocDec.one_point_zero.num) {
|
} else if (self_i128 == RocDec.one_point_zero.num) {
|
||||||
|
@ -336,7 +341,7 @@ pub const RocDec = extern struct {
|
||||||
} else {
|
} else {
|
||||||
return .{ .value = RocDec.max, .has_overflowed = true };
|
return .{ .value = RocDec.max, .has_overflowed = true };
|
||||||
}
|
}
|
||||||
}));
|
}
|
||||||
|
|
||||||
const unsigned_answer: i128 = mul_and_decimalize(self_u128, other_u128);
|
const unsigned_answer: i128 = mul_and_decimalize(self_u128, other_u128);
|
||||||
|
|
||||||
|
@ -464,7 +469,8 @@ pub const RocDec = extern struct {
|
||||||
//
|
//
|
||||||
// We do checked_abs because if we had -i128::MAX before, this will overflow.
|
// We do checked_abs because if we had -i128::MAX before, this will overflow.
|
||||||
|
|
||||||
const numerator_abs_i128 = math.absInt(numerator_i128) catch {
|
const numerator_u128 = @abs(numerator_i128);
|
||||||
|
if (numerator_u128 > @as(u128, @intCast(std.math.maxInt(i128)))) {
|
||||||
// Currently, if you try to do multiplication on i64::MIN, panic
|
// Currently, if you try to do multiplication on i64::MIN, panic
|
||||||
// unless you're specifically multiplying by 0 or 1.
|
// unless you're specifically multiplying by 0 or 1.
|
||||||
//
|
//
|
||||||
|
@ -474,10 +480,10 @@ pub const RocDec = extern struct {
|
||||||
} else {
|
} else {
|
||||||
roc_panic("Decimal division overflow in numerator!", 0);
|
roc_panic("Decimal division overflow in numerator!", 0);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
const numerator_u128 = @as(u128, @intCast(numerator_abs_i128));
|
|
||||||
|
|
||||||
const denominator_abs_i128 = math.absInt(denominator_i128) catch {
|
const denominator_u128 = @abs(denominator_i128);
|
||||||
|
if (denominator_u128 > @as(u128, @intCast(std.math.maxInt(i128)))) {
|
||||||
// Currently, if you try to do multiplication on i64::MIN, panic
|
// Currently, if you try to do multiplication on i64::MIN, panic
|
||||||
// unless you're specifically multiplying by 0 or 1.
|
// unless you're specifically multiplying by 0 or 1.
|
||||||
//
|
//
|
||||||
|
@ -487,8 +493,7 @@ pub const RocDec = extern struct {
|
||||||
} else {
|
} else {
|
||||||
roc_panic("Decimal division overflow in denominator!", 0);
|
roc_panic("Decimal division overflow in denominator!", 0);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
const denominator_u128 = @as(u128, @intCast(denominator_abs_i128));
|
|
||||||
|
|
||||||
const numerator_u256: U256 = mul_u128(numerator_u128, math.pow(u128, 10, decimal_places));
|
const numerator_u256: U256 = mul_u128(numerator_u128, math.pow(u128, 10, decimal_places));
|
||||||
const answer = div_u256_by_u128(numerator_u256, denominator_u128);
|
const answer = div_u256_by_u128(numerator_u256, denominator_u128);
|
||||||
|
@ -516,7 +521,7 @@ pub const RocDec = extern struct {
|
||||||
// This is dec/(b0+1), but as a multiplication.
|
// This is dec/(b0+1), but as a multiplication.
|
||||||
// So dec * (1/(b0+1)). This is way faster.
|
// So dec * (1/(b0+1)). This is way faster.
|
||||||
const dec = self.num;
|
const dec = self.num;
|
||||||
const tmp = @as(i128, @intCast(num_.mul_u128(math.absCast(dec), 249757942369376157886101012127821356963).hi >> (190 - 128)));
|
const tmp = @as(i128, @intCast(num_.mul_u128(@abs(dec), 249757942369376157886101012127821356963).hi >> (190 - 128)));
|
||||||
const q0 = if (dec < 0) -tmp else tmp;
|
const q0 = if (dec < 0) -tmp else tmp;
|
||||||
|
|
||||||
const upper = q0 * b0;
|
const upper = q0 * b0;
|
||||||
|
@ -1468,7 +1473,7 @@ pub fn exportFromInt(comptime T: type, comptime name: []const u8) void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fromU64C(arg: u64) callconv(.C) i128 {
|
pub fn fromU64C(arg: u64) callconv(.C) i128 {
|
||||||
|
@ -1582,7 +1587,7 @@ pub fn exportRound(comptime T: type, comptime name: []const u8) void {
|
||||||
return @as(T, @intCast(@divFloor(input.round().num, RocDec.one_point_zero_i128)));
|
return @as(T, @intCast(@divFloor(input.round().num, RocDec.one_point_zero_i128)));
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportFloor(comptime T: type, comptime name: []const u8) void {
|
pub fn exportFloor(comptime T: type, comptime name: []const u8) void {
|
||||||
|
@ -1591,7 +1596,7 @@ pub fn exportFloor(comptime T: type, comptime name: []const u8) void {
|
||||||
return @as(T, @intCast(@divFloor(input.floor().num, RocDec.one_point_zero_i128)));
|
return @as(T, @intCast(@divFloor(input.floor().num, RocDec.one_point_zero_i128)));
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportCeiling(comptime T: type, comptime name: []const u8) void {
|
pub fn exportCeiling(comptime T: type, comptime name: []const u8) void {
|
||||||
|
@ -1600,5 +1605,5 @@ pub fn exportCeiling(comptime T: type, comptime name: []const u8) void {
|
||||||
return @as(T, @intCast(@divFloor(input.ceiling().num, RocDec.one_point_zero_i128)));
|
return @as(T, @intCast(@divFloor(input.ceiling().num, RocDec.one_point_zero_i128)));
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
|
|
||||||
const Atomic = std.atomic.Atomic;
|
const Atomic = std.atomic.Value;
|
||||||
|
|
||||||
const O_RDWR: c_int = 2;
|
const O_RDWR: c_int = 2;
|
||||||
const O_CREAT: c_int = 64;
|
const O_CREAT: c_int = 64;
|
||||||
|
@ -83,11 +83,10 @@ pub fn notifyParent(shared_buffer: [*]u8, tag: u32) callconv(.C) void {
|
||||||
if (builtin.os.tag == .macos or builtin.os.tag == .linux) {
|
if (builtin.os.tag == .macos or builtin.os.tag == .linux) {
|
||||||
const usize_ptr = @as([*]u32, @ptrCast(@alignCast(shared_buffer)));
|
const usize_ptr = @as([*]u32, @ptrCast(@alignCast(shared_buffer)));
|
||||||
const atomic_ptr = @as(*Atomic(u32), @ptrCast(&usize_ptr[5]));
|
const atomic_ptr = @as(*Atomic(u32), @ptrCast(&usize_ptr[5]));
|
||||||
atomic_ptr.storeUnchecked(tag);
|
atomic_ptr.store(tag, .unordered);
|
||||||
|
|
||||||
// wait till the parent is done before proceeding
|
// wait till the parent is done before proceeding
|
||||||
const Ordering = std.atomic.Ordering;
|
while (atomic_ptr.load(.acquire) != 0) {
|
||||||
while (atomic_ptr.load(Ordering.Acquire) != 0) {
|
|
||||||
std.atomic.spinLoopHint();
|
std.atomic.spinLoopHint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ pub fn exportParseInt(comptime T: type, comptime name: []const u8) void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportParseFloat(comptime T: type, comptime name: []const u8) void {
|
pub fn exportParseFloat(comptime T: type, comptime name: []const u8) void {
|
||||||
|
@ -95,7 +95,7 @@ pub fn exportParseFloat(comptime T: type, comptime name: []const u8) void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportNumToFloatCast(comptime T: type, comptime F: type, comptime name: []const u8) void {
|
pub fn exportNumToFloatCast(comptime T: type, comptime F: type, comptime name: []const u8) void {
|
||||||
|
@ -104,7 +104,7 @@ pub fn exportNumToFloatCast(comptime T: type, comptime F: type, comptime name: [
|
||||||
return @floatFromInt(x);
|
return @floatFromInt(x);
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportPow(comptime T: type, comptime name: []const u8) void {
|
pub fn exportPow(comptime T: type, comptime name: []const u8) void {
|
||||||
|
@ -113,7 +113,7 @@ pub fn exportPow(comptime T: type, comptime name: []const u8) void {
|
||||||
return std.math.pow(T, base, exp);
|
return std.math.pow(T, base, exp);
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportIsNan(comptime T: type, comptime name: []const u8) void {
|
pub fn exportIsNan(comptime T: type, comptime name: []const u8) void {
|
||||||
|
@ -122,7 +122,7 @@ pub fn exportIsNan(comptime T: type, comptime name: []const u8) void {
|
||||||
return std.math.isNan(input);
|
return std.math.isNan(input);
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportIsInfinite(comptime T: type, comptime name: []const u8) void {
|
pub fn exportIsInfinite(comptime T: type, comptime name: []const u8) void {
|
||||||
|
@ -131,7 +131,7 @@ pub fn exportIsInfinite(comptime T: type, comptime name: []const u8) void {
|
||||||
return std.math.isInf(input);
|
return std.math.isInf(input);
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportIsFinite(comptime T: type, comptime name: []const u8) void {
|
pub fn exportIsFinite(comptime T: type, comptime name: []const u8) void {
|
||||||
|
@ -140,7 +140,7 @@ pub fn exportIsFinite(comptime T: type, comptime name: []const u8) void {
|
||||||
return std.math.isFinite(input);
|
return std.math.isFinite(input);
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportAsin(comptime T: type, comptime name: []const u8) void {
|
pub fn exportAsin(comptime T: type, comptime name: []const u8) void {
|
||||||
|
@ -149,7 +149,7 @@ pub fn exportAsin(comptime T: type, comptime name: []const u8) void {
|
||||||
return std.math.asin(input);
|
return std.math.asin(input);
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportAcos(comptime T: type, comptime name: []const u8) void {
|
pub fn exportAcos(comptime T: type, comptime name: []const u8) void {
|
||||||
|
@ -158,7 +158,7 @@ pub fn exportAcos(comptime T: type, comptime name: []const u8) void {
|
||||||
return std.math.acos(input);
|
return std.math.acos(input);
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportAtan(comptime T: type, comptime name: []const u8) void {
|
pub fn exportAtan(comptime T: type, comptime name: []const u8) void {
|
||||||
|
@ -167,7 +167,7 @@ pub fn exportAtan(comptime T: type, comptime name: []const u8) void {
|
||||||
return std.math.atan(input);
|
return std.math.atan(input);
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportSin(comptime T: type, comptime name: []const u8) void {
|
pub fn exportSin(comptime T: type, comptime name: []const u8) void {
|
||||||
|
@ -176,7 +176,7 @@ pub fn exportSin(comptime T: type, comptime name: []const u8) void {
|
||||||
return math.sin(input);
|
return math.sin(input);
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportCos(comptime T: type, comptime name: []const u8) void {
|
pub fn exportCos(comptime T: type, comptime name: []const u8) void {
|
||||||
|
@ -185,7 +185,7 @@ pub fn exportCos(comptime T: type, comptime name: []const u8) void {
|
||||||
return math.cos(input);
|
return math.cos(input);
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportTan(comptime T: type, comptime name: []const u8) void {
|
pub fn exportTan(comptime T: type, comptime name: []const u8) void {
|
||||||
|
@ -194,7 +194,7 @@ pub fn exportTan(comptime T: type, comptime name: []const u8) void {
|
||||||
return math.tan(input);
|
return math.tan(input);
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportLog(comptime T: type, comptime name: []const u8) void {
|
pub fn exportLog(comptime T: type, comptime name: []const u8) void {
|
||||||
|
@ -203,16 +203,16 @@ pub fn exportLog(comptime T: type, comptime name: []const u8) void {
|
||||||
return @log(input);
|
return @log(input);
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportFAbs(comptime T: type, comptime name: []const u8) void {
|
pub fn exportFAbs(comptime T: type, comptime name: []const u8) void {
|
||||||
const f = struct {
|
const f = struct {
|
||||||
fn func(input: T) callconv(.C) T {
|
fn func(input: T) callconv(.C) T {
|
||||||
return @fabs(input);
|
return @abs(input);
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportSqrt(comptime T: type, comptime name: []const u8) void {
|
pub fn exportSqrt(comptime T: type, comptime name: []const u8) void {
|
||||||
|
@ -221,7 +221,7 @@ pub fn exportSqrt(comptime T: type, comptime name: []const u8) void {
|
||||||
return math.sqrt(input);
|
return math.sqrt(input);
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportRound(comptime F: type, comptime T: type, comptime name: []const u8) void {
|
pub fn exportRound(comptime F: type, comptime T: type, comptime name: []const u8) void {
|
||||||
|
@ -230,7 +230,7 @@ pub fn exportRound(comptime F: type, comptime T: type, comptime name: []const u8
|
||||||
return @as(T, @intFromFloat((math.round(input))));
|
return @as(T, @intFromFloat((math.round(input))));
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportFloor(comptime F: type, comptime T: type, comptime name: []const u8) void {
|
pub fn exportFloor(comptime F: type, comptime T: type, comptime name: []const u8) void {
|
||||||
|
@ -239,7 +239,7 @@ pub fn exportFloor(comptime F: type, comptime T: type, comptime name: []const u8
|
||||||
return @as(T, @intFromFloat((math.floor(input))));
|
return @as(T, @intFromFloat((math.floor(input))));
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportCeiling(comptime F: type, comptime T: type, comptime name: []const u8) void {
|
pub fn exportCeiling(comptime F: type, comptime T: type, comptime name: []const u8) void {
|
||||||
|
@ -248,7 +248,7 @@ pub fn exportCeiling(comptime F: type, comptime T: type, comptime name: []const
|
||||||
return @as(T, @intFromFloat((math.ceil(input))));
|
return @as(T, @intFromFloat((math.ceil(input))));
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportDivCeil(comptime T: type, comptime name: []const u8) void {
|
pub fn exportDivCeil(comptime T: type, comptime name: []const u8) void {
|
||||||
|
@ -259,7 +259,7 @@ pub fn exportDivCeil(comptime T: type, comptime name: []const u8) void {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ToIntCheckedResult(comptime T: type) type {
|
pub fn ToIntCheckedResult(comptime T: type) type {
|
||||||
|
@ -280,7 +280,7 @@ pub fn exportToIntCheckingMax(comptime From: type, comptime To: type, comptime n
|
||||||
return .{ .out_of_bounds = false, .value = @as(To, @intCast(input)) };
|
return .{ .out_of_bounds = false, .value = @as(To, @intCast(input)) };
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(From), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(From), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportToIntCheckingMaxAndMin(comptime From: type, comptime To: type, comptime name: []const u8) void {
|
pub fn exportToIntCheckingMaxAndMin(comptime From: type, comptime To: type, comptime name: []const u8) void {
|
||||||
|
@ -292,7 +292,7 @@ pub fn exportToIntCheckingMaxAndMin(comptime From: type, comptime To: type, comp
|
||||||
return .{ .out_of_bounds = false, .value = @as(To, @intCast(input)) };
|
return .{ .out_of_bounds = false, .value = @as(To, @intCast(input)) };
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(From), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(From), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
fn isMultipleOf(comptime T: type, lhs: T, rhs: T) bool {
|
fn isMultipleOf(comptime T: type, lhs: T, rhs: T) bool {
|
||||||
|
@ -316,7 +316,7 @@ pub fn exportIsMultipleOf(comptime T: type, comptime name: []const u8) void {
|
||||||
return @call(.always_inline, isMultipleOf, .{ T, self, other });
|
return @call(.always_inline, isMultipleOf, .{ T, self, other });
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
fn addWithOverflow(comptime T: type, self: T, other: T) WithOverflow(T) {
|
fn addWithOverflow(comptime T: type, self: T, other: T) WithOverflow(T) {
|
||||||
|
@ -339,7 +339,7 @@ pub fn exportAddWithOverflow(comptime T: type, comptime name: []const u8) void {
|
||||||
return @call(.always_inline, addWithOverflow, .{ T, self, other });
|
return @call(.always_inline, addWithOverflow, .{ T, self, other });
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportAddSaturatedInt(comptime T: type, comptime name: []const u8) void {
|
pub fn exportAddSaturatedInt(comptime T: type, comptime name: []const u8) void {
|
||||||
|
@ -358,7 +358,7 @@ pub fn exportAddSaturatedInt(comptime T: type, comptime name: []const u8) void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportAddOrPanic(comptime T: type, comptime name: []const u8) void {
|
pub fn exportAddOrPanic(comptime T: type, comptime name: []const u8) void {
|
||||||
|
@ -372,7 +372,7 @@ pub fn exportAddOrPanic(comptime T: type, comptime name: []const u8) void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
fn subWithOverflow(comptime T: type, self: T, other: T) WithOverflow(T) {
|
fn subWithOverflow(comptime T: type, self: T, other: T) WithOverflow(T) {
|
||||||
|
@ -395,7 +395,7 @@ pub fn exportSubWithOverflow(comptime T: type, comptime name: []const u8) void {
|
||||||
return @call(.always_inline, subWithOverflow, .{ T, self, other });
|
return @call(.always_inline, subWithOverflow, .{ T, self, other });
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportSubSaturatedInt(comptime T: type, comptime name: []const u8) void {
|
pub fn exportSubSaturatedInt(comptime T: type, comptime name: []const u8) void {
|
||||||
|
@ -415,7 +415,7 @@ pub fn exportSubSaturatedInt(comptime T: type, comptime name: []const u8) void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportSubOrPanic(comptime T: type, comptime name: []const u8) void {
|
pub fn exportSubOrPanic(comptime T: type, comptime name: []const u8) void {
|
||||||
|
@ -429,7 +429,7 @@ pub fn exportSubOrPanic(comptime T: type, comptime name: []const u8) void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mulWithOverflow(comptime T: type, comptime W: type, self: T, other: T) WithOverflow(T) {
|
fn mulWithOverflow(comptime T: type, comptime W: type, self: T, other: T) WithOverflow(T) {
|
||||||
|
@ -440,7 +440,8 @@ fn mulWithOverflow(comptime T: type, comptime W: type, self: T, other: T) WithOv
|
||||||
const max = std.math.maxInt(i128);
|
const max = std.math.maxInt(i128);
|
||||||
const min = std.math.minInt(i128);
|
const min = std.math.minInt(i128);
|
||||||
|
|
||||||
const self_u128 = @as(u128, @intCast(math.absInt(self) catch {
|
const self_u128 = @abs(self);
|
||||||
|
if (self_u128 > @as(u128, @intCast(std.math.maxInt(i128)))) {
|
||||||
if (other == 0) {
|
if (other == 0) {
|
||||||
return .{ .value = 0, .has_overflowed = false };
|
return .{ .value = 0, .has_overflowed = false };
|
||||||
} else if (other == 1) {
|
} else if (other == 1) {
|
||||||
|
@ -450,9 +451,10 @@ fn mulWithOverflow(comptime T: type, comptime W: type, self: T, other: T) WithOv
|
||||||
} else {
|
} else {
|
||||||
return .{ .value = max, .has_overflowed = true };
|
return .{ .value = max, .has_overflowed = true };
|
||||||
}
|
}
|
||||||
}));
|
}
|
||||||
|
|
||||||
const other_u128 = @as(u128, @intCast(math.absInt(other) catch {
|
const other_u128 = @abs(other);
|
||||||
|
if (other_u128 > @as(u128, @intCast(std.math.maxInt(i128)))) {
|
||||||
if (self == 0) {
|
if (self == 0) {
|
||||||
return .{ .value = 0, .has_overflowed = false };
|
return .{ .value = 0, .has_overflowed = false };
|
||||||
} else if (self == 1) {
|
} else if (self == 1) {
|
||||||
|
@ -462,7 +464,7 @@ fn mulWithOverflow(comptime T: type, comptime W: type, self: T, other: T) WithOv
|
||||||
} else {
|
} else {
|
||||||
return .{ .value = max, .has_overflowed = true };
|
return .{ .value = max, .has_overflowed = true };
|
||||||
}
|
}
|
||||||
}));
|
}
|
||||||
|
|
||||||
const answer256: U256 = mul_u128(self_u128, other_u128);
|
const answer256: U256 = mul_u128(self_u128, other_u128);
|
||||||
|
|
||||||
|
@ -512,7 +514,7 @@ pub fn exportMulWithOverflow(comptime T: type, comptime W: type, comptime name:
|
||||||
return @call(.always_inline, mulWithOverflow, .{ T, W, self, other });
|
return @call(.always_inline, mulWithOverflow, .{ T, W, self, other });
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportMulSaturatedInt(comptime T: type, comptime W: type, comptime name: []const u8) void {
|
pub fn exportMulSaturatedInt(comptime T: type, comptime W: type, comptime name: []const u8) void {
|
||||||
|
@ -522,7 +524,7 @@ pub fn exportMulSaturatedInt(comptime T: type, comptime W: type, comptime name:
|
||||||
return result.value;
|
return result.value;
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportMulWrappedInt(comptime T: type, comptime name: []const u8) void {
|
pub fn exportMulWrappedInt(comptime T: type, comptime name: []const u8) void {
|
||||||
|
@ -531,7 +533,7 @@ pub fn exportMulWrappedInt(comptime T: type, comptime name: []const u8) void {
|
||||||
return self *% other;
|
return self *% other;
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn shiftRightZeroFillI128(self: i128, other: u8) callconv(.C) i128 {
|
pub fn shiftRightZeroFillI128(self: i128, other: u8) callconv(.C) i128 {
|
||||||
|
@ -613,7 +615,7 @@ pub fn exportMulOrPanic(comptime T: type, comptime W: type, comptime name: []con
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportCountLeadingZeroBits(comptime T: type, comptime name: []const u8) void {
|
pub fn exportCountLeadingZeroBits(comptime T: type, comptime name: []const u8) void {
|
||||||
|
@ -622,7 +624,7 @@ pub fn exportCountLeadingZeroBits(comptime T: type, comptime name: []const u8) v
|
||||||
return @as(u8, @clz(self));
|
return @as(u8, @clz(self));
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportCountTrailingZeroBits(comptime T: type, comptime name: []const u8) void {
|
pub fn exportCountTrailingZeroBits(comptime T: type, comptime name: []const u8) void {
|
||||||
|
@ -631,7 +633,7 @@ pub fn exportCountTrailingZeroBits(comptime T: type, comptime name: []const u8)
|
||||||
return @as(u8, @ctz(self));
|
return @as(u8, @ctz(self));
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportCountOneBits(comptime T: type, comptime name: []const u8) void {
|
pub fn exportCountOneBits(comptime T: type, comptime name: []const u8) void {
|
||||||
|
@ -640,7 +642,7 @@ pub fn exportCountOneBits(comptime T: type, comptime name: []const u8) void {
|
||||||
return @as(u8, @popCount(self));
|
return @as(u8, @popCount(self));
|
||||||
}
|
}
|
||||||
}.func;
|
}.func;
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn f32ToParts(self: f32) callconv(.C) F32Parts {
|
pub fn f32ToParts(self: f32) callconv(.C) F32Parts {
|
||||||
|
|
|
@ -274,7 +274,7 @@ pub const RocStr = extern struct {
|
||||||
const source_ptr = self.asU8ptr();
|
const source_ptr = self.asU8ptr();
|
||||||
const dest_ptr = result.asU8ptrMut();
|
const dest_ptr = result.asU8ptrMut();
|
||||||
|
|
||||||
std.mem.copy(u8, dest_ptr[0..old_length], source_ptr[0..old_length]);
|
@memcpy(dest_ptr[0..old_length], source_ptr[0..old_length]);
|
||||||
@memset(dest_ptr[old_length..new_length], 0);
|
@memset(dest_ptr[old_length..new_length], 0);
|
||||||
|
|
||||||
self.decref();
|
self.decref();
|
||||||
|
@ -290,7 +290,7 @@ pub const RocStr = extern struct {
|
||||||
|
|
||||||
const source_ptr = self.asU8ptr();
|
const source_ptr = self.asU8ptr();
|
||||||
|
|
||||||
std.mem.copy(u8, dest_ptr[0..old_length], source_ptr[0..old_length]);
|
@memcpy(dest_ptr[0..old_length], source_ptr[0..old_length]);
|
||||||
@memset(dest_ptr[old_length..new_length], 0);
|
@memset(dest_ptr[old_length..new_length], 0);
|
||||||
|
|
||||||
self.decref();
|
self.decref();
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
const Monotonic = std.builtin.AtomicOrder.Monotonic;
|
|
||||||
|
|
||||||
const DEBUG_INCDEC = false;
|
const DEBUG_INCDEC = false;
|
||||||
const DEBUG_TESTING_ALLOC = false;
|
const DEBUG_TESTING_ALLOC = false;
|
||||||
|
@ -181,10 +180,10 @@ const Refcount = enum {
|
||||||
atomic,
|
atomic,
|
||||||
};
|
};
|
||||||
|
|
||||||
const RC_TYPE = Refcount.normal;
|
const RC_TYPE: Refcount = .normal;
|
||||||
|
|
||||||
pub fn increfRcPtrC(ptr_to_refcount: *isize, amount: isize) callconv(.C) void {
|
pub fn increfRcPtrC(ptr_to_refcount: *isize, amount: isize) callconv(.C) void {
|
||||||
if (RC_TYPE == Refcount.none) return;
|
if (RC_TYPE == .none) return;
|
||||||
|
|
||||||
if (DEBUG_INCDEC and builtin.target.cpu.arch != .wasm32) {
|
if (DEBUG_INCDEC and builtin.target.cpu.arch != .wasm32) {
|
||||||
std.debug.print("| increment {*}: ", .{ptr_to_refcount});
|
std.debug.print("| increment {*}: ", .{ptr_to_refcount});
|
||||||
|
@ -195,7 +194,7 @@ pub fn increfRcPtrC(ptr_to_refcount: *isize, amount: isize) callconv(.C) void {
|
||||||
// Note: we assume that a refcount will never overflow.
|
// Note: we assume that a refcount will never overflow.
|
||||||
// As such, we do not need to cap incrementing.
|
// As such, we do not need to cap incrementing.
|
||||||
switch (RC_TYPE) {
|
switch (RC_TYPE) {
|
||||||
Refcount.normal => {
|
.normal => {
|
||||||
if (DEBUG_INCDEC and builtin.target.cpu.arch != .wasm32) {
|
if (DEBUG_INCDEC and builtin.target.cpu.arch != .wasm32) {
|
||||||
const old = @as(usize, @bitCast(ptr_to_refcount.*));
|
const old = @as(usize, @bitCast(ptr_to_refcount.*));
|
||||||
const new = old + @as(usize, @intCast(amount));
|
const new = old + @as(usize, @intCast(amount));
|
||||||
|
@ -208,10 +207,10 @@ pub fn increfRcPtrC(ptr_to_refcount: *isize, amount: isize) callconv(.C) void {
|
||||||
|
|
||||||
ptr_to_refcount.* += amount;
|
ptr_to_refcount.* += amount;
|
||||||
},
|
},
|
||||||
Refcount.atomic => {
|
.atomic => {
|
||||||
_ = @atomicRmw(isize, ptr_to_refcount, std.builtin.AtomicRmwOp.Add, amount, Monotonic);
|
_ = @atomicRmw(isize, ptr_to_refcount, .Add, amount, .monotonic);
|
||||||
},
|
},
|
||||||
Refcount.none => unreachable,
|
.none => unreachable,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -321,7 +320,7 @@ inline fn free_ptr_to_refcount(
|
||||||
alignment: u32,
|
alignment: u32,
|
||||||
elements_refcounted: bool,
|
elements_refcounted: bool,
|
||||||
) void {
|
) void {
|
||||||
if (RC_TYPE == Refcount.none) return;
|
if (RC_TYPE == .none) return;
|
||||||
const ptr_width = @sizeOf(usize);
|
const ptr_width = @sizeOf(usize);
|
||||||
const required_space: usize = if (elements_refcounted) (2 * ptr_width) else ptr_width;
|
const required_space: usize = if (elements_refcounted) (2 * ptr_width) else ptr_width;
|
||||||
const extra_bytes = @max(required_space, alignment);
|
const extra_bytes = @max(required_space, alignment);
|
||||||
|
@ -340,7 +339,7 @@ inline fn decref_ptr_to_refcount(
|
||||||
element_alignment: u32,
|
element_alignment: u32,
|
||||||
elements_refcounted: bool,
|
elements_refcounted: bool,
|
||||||
) void {
|
) void {
|
||||||
if (RC_TYPE == Refcount.none) return;
|
if (RC_TYPE == .none) return;
|
||||||
|
|
||||||
if (DEBUG_INCDEC and builtin.target.cpu.arch != .wasm32) {
|
if (DEBUG_INCDEC and builtin.target.cpu.arch != .wasm32) {
|
||||||
std.debug.print("| decrement {*}: ", .{refcount_ptr});
|
std.debug.print("| decrement {*}: ", .{refcount_ptr});
|
||||||
|
@ -354,7 +353,7 @@ inline fn decref_ptr_to_refcount(
|
||||||
const refcount: isize = refcount_ptr[0];
|
const refcount: isize = refcount_ptr[0];
|
||||||
if (refcount != REFCOUNT_MAX_ISIZE) {
|
if (refcount != REFCOUNT_MAX_ISIZE) {
|
||||||
switch (RC_TYPE) {
|
switch (RC_TYPE) {
|
||||||
Refcount.normal => {
|
.normal => {
|
||||||
const old = @as(usize, @bitCast(refcount));
|
const old = @as(usize, @bitCast(refcount));
|
||||||
refcount_ptr[0] = refcount -% 1;
|
refcount_ptr[0] = refcount -% 1;
|
||||||
const new = @as(usize, @bitCast(refcount -% 1));
|
const new = @as(usize, @bitCast(refcount -% 1));
|
||||||
|
@ -370,13 +369,13 @@ inline fn decref_ptr_to_refcount(
|
||||||
free_ptr_to_refcount(refcount_ptr, alignment, elements_refcounted);
|
free_ptr_to_refcount(refcount_ptr, alignment, elements_refcounted);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Refcount.atomic => {
|
.atomic => {
|
||||||
const last = @atomicRmw(isize, &refcount_ptr[0], std.builtin.AtomicRmwOp.Sub, 1, Monotonic);
|
const last = @atomicRmw(isize, &refcount_ptr[0], .Sub, 1, .monotonic);
|
||||||
if (last == REFCOUNT_ONE_ISIZE) {
|
if (last == REFCOUNT_ONE_ISIZE) {
|
||||||
free_ptr_to_refcount(refcount_ptr, alignment, elements_refcounted);
|
free_ptr_to_refcount(refcount_ptr, alignment, elements_refcounted);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Refcount.none => unreachable,
|
.none => unreachable,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -478,7 +477,7 @@ pub fn allocateWithRefcount(
|
||||||
|
|
||||||
const data_ptr = new_bytes + extra_bytes;
|
const data_ptr = new_bytes + extra_bytes;
|
||||||
const refcount_ptr = @as([*]usize, @ptrCast(@as([*]align(ptr_width) u8, @alignCast(data_ptr)) - ptr_width));
|
const refcount_ptr = @as([*]usize, @ptrCast(@as([*]align(ptr_width) u8, @alignCast(data_ptr)) - ptr_width));
|
||||||
refcount_ptr[0] = if (RC_TYPE == Refcount.none) REFCOUNT_MAX_ISIZE else REFCOUNT_ONE;
|
refcount_ptr[0] = if (RC_TYPE == .none) REFCOUNT_MAX_ISIZE else REFCOUNT_ONE;
|
||||||
|
|
||||||
return data_ptr;
|
return data_ptr;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue