mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
Merge remote-tracking branch 'origin/trunk' into i/2792
This commit is contained in:
commit
07383e96f0
363 changed files with 29960 additions and 14183 deletions
|
@ -310,9 +310,7 @@ pub const RocDec = extern struct {
|
|||
|
||||
// (n / 0) is an error
|
||||
if (denominator_i128 == 0) {
|
||||
// The compiler frontend does the `denominator == 0` check for us,
|
||||
// therefore this case is unreachable from roc user code
|
||||
unreachable;
|
||||
@panic("TODO runtime exception for dividing by 0!");
|
||||
}
|
||||
|
||||
// If they're both negative, or if neither is negative, the final answer
|
||||
|
|
|
@ -1355,3 +1355,9 @@ pub fn listFindUnsafe(
|
|||
return .{ .value = null, .found = false };
|
||||
}
|
||||
}
|
||||
|
||||
pub fn listIsUnique(
|
||||
list: RocList,
|
||||
) callconv(.C) bool {
|
||||
return list.isEmpty() or list.isUnique();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const math = std.math;
|
||||
const utils = @import("utils.zig");
|
||||
const expect = @import("expect.zig");
|
||||
|
@ -55,6 +56,7 @@ comptime {
|
|||
exportListFn(list.listAny, "any");
|
||||
exportListFn(list.listAll, "all");
|
||||
exportListFn(list.listFindUnsafe, "find_unsafe");
|
||||
exportListFn(list.listIsUnique, "is_unique");
|
||||
}
|
||||
|
||||
// Dict Module
|
||||
|
@ -163,6 +165,32 @@ comptime {
|
|||
exportExpectFn(expect.deinitFailuresC, "deinit_failures");
|
||||
|
||||
@export(utils.panic, .{ .name = "roc_builtins.utils." ++ "panic", .linkage = .Weak });
|
||||
|
||||
if (builtin.target.cpu.arch == .aarch64) {
|
||||
@export(__roc_force_setjmp, .{ .name = "__roc_force_setjmp", .linkage = .Weak });
|
||||
@export(__roc_force_longjmp, .{ .name = "__roc_force_longjmp", .linkage = .Weak });
|
||||
}
|
||||
}
|
||||
|
||||
// Utils continued - SJLJ
|
||||
// For tests (in particular test_gen), roc_panic is implemented in terms of
|
||||
// setjmp/longjmp. LLVM is unable to generate code for longjmp on AArch64 (https://github.com/rtfeldman/roc/issues/2965),
|
||||
// so instead we ask Zig to please provide implementations for us, which is does
|
||||
// (seemingly via musl).
|
||||
pub usingnamespace @import("std").c.builtins;
|
||||
pub extern fn setjmp([*c]c_int) c_int;
|
||||
pub extern fn longjmp([*c]c_int, c_int) noreturn;
|
||||
pub extern fn _setjmp([*c]c_int) c_int;
|
||||
pub extern fn _longjmp([*c]c_int, c_int) noreturn;
|
||||
pub extern fn sigsetjmp([*c]c_int, c_int) c_int;
|
||||
pub extern fn siglongjmp([*c]c_int, c_int) noreturn;
|
||||
pub extern fn longjmperror() void;
|
||||
// Zig won't expose the externs (and hence link correctly) unless we force them to be used.
|
||||
fn __roc_force_setjmp(it: [*c]c_int) callconv(.C) c_int {
|
||||
return setjmp(it);
|
||||
}
|
||||
fn __roc_force_longjmp(a0: [*c]c_int, a1: c_int) callconv(.C) noreturn {
|
||||
longjmp(a0, a1);
|
||||
}
|
||||
|
||||
// Export helpers - Must be run inside a comptime
|
||||
|
@ -195,7 +223,6 @@ fn exportExpectFn(comptime func: anytype, comptime func_name: []const u8) void {
|
|||
|
||||
// Custom panic function, as builtin Zig version errors during LLVM verification
|
||||
pub fn panic(message: []const u8, stacktrace: ?*std.builtin.StackTrace) noreturn {
|
||||
const builtin = @import("builtin");
|
||||
if (builtin.is_test) {
|
||||
std.debug.print("{s}: {?}", .{ message, stacktrace });
|
||||
} else {
|
||||
|
|
|
@ -111,7 +111,7 @@ pub fn exportRoundF64(comptime T: type, comptime name: []const u8) void {
|
|||
pub fn exportDivCeil(comptime T: type, comptime name: []const u8) void {
|
||||
comptime var f = struct {
|
||||
fn func(a: T, b: T) callconv(.C) T {
|
||||
return math.divCeil(T, a, b) catch unreachable;
|
||||
return math.divCeil(T, a, b) catch @panic("TODO runtime exception for dividing by 0!");
|
||||
}
|
||||
}.func;
|
||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
||||
|
|
|
@ -468,8 +468,10 @@ fn strFromIntHelp(comptime T: type, int: T) RocStr {
|
|||
const size = comptime blk: {
|
||||
// the string representation of the minimum i128 value uses at most 40 characters
|
||||
var buf: [40]u8 = undefined;
|
||||
var result = std.fmt.bufPrint(&buf, "{}", .{std.math.minInt(T)}) catch unreachable;
|
||||
break :blk result.len;
|
||||
var resultMin = std.fmt.bufPrint(&buf, "{}", .{std.math.minInt(T)}) catch unreachable;
|
||||
var resultMax = std.fmt.bufPrint(&buf, "{}", .{std.math.maxInt(T)}) catch unreachable;
|
||||
var result = if (resultMin.len > resultMax.len) resultMin.len else resultMax.len;
|
||||
break :blk result;
|
||||
};
|
||||
|
||||
var buf: [size]u8 = undefined;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue