mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
support intrinsics/builtins for more integer types
This commit is contained in:
parent
6cc8f8624c
commit
78c49d3095
7 changed files with 308 additions and 115 deletions
|
@ -3,36 +3,58 @@ const always_inline = std.builtin.CallOptions.Modifier.always_inline;
|
|||
const math = std.math;
|
||||
const RocList = @import("list.zig").RocList;
|
||||
|
||||
pub fn atan(num: f64) callconv(.C) f64 {
|
||||
return @call(.{ .modifier = always_inline }, math.atan, .{num});
|
||||
}
|
||||
|
||||
pub fn isFinite(num: f64) callconv(.C) bool {
|
||||
return @call(.{ .modifier = always_inline }, math.isFinite, .{num});
|
||||
}
|
||||
|
||||
comptime {
|
||||
var types = [_]type{ i32, i64, i16 };
|
||||
inline for (types) |T| {
|
||||
exportFunctions(T);
|
||||
}
|
||||
}
|
||||
fn exportFunctions(comptime T: type) void {
|
||||
pub fn exportPow(comptime T: type, comptime name: []const u8) void {
|
||||
comptime var f = struct {
|
||||
fn func(base: T, exp: T) callconv(.C) T {
|
||||
return std.math.pow(T, base, exp);
|
||||
}
|
||||
}.func;
|
||||
const args = .{ .name = "roc_builtins.num.pow_int_" ++ @typeName(T), .linkage = .Strong };
|
||||
@export(f, args);
|
||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
||||
}
|
||||
|
||||
pub fn acos(num: f64) callconv(.C) f64 {
|
||||
return @call(.{ .modifier = always_inline }, math.acos, .{num});
|
||||
pub fn exportIsFinite(comptime T: type, comptime name: []const u8) void {
|
||||
comptime var f = struct {
|
||||
fn func(input: T) callconv(.C) bool {
|
||||
return std.math.isFinite(input);
|
||||
}
|
||||
}.func;
|
||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
||||
}
|
||||
|
||||
pub fn asin(num: f64) callconv(.C) f64 {
|
||||
return @call(.{ .modifier = always_inline }, math.asin, .{num});
|
||||
pub fn exportAsin(comptime T: type, comptime name: []const u8) void {
|
||||
comptime var f = struct {
|
||||
fn func(input: T) callconv(.C) T {
|
||||
return std.math.asin(input);
|
||||
}
|
||||
}.func;
|
||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
||||
}
|
||||
|
||||
pub fn exportAcos(comptime T: type, comptime name: []const u8) void {
|
||||
comptime var f = struct {
|
||||
fn func(input: T) callconv(.C) T {
|
||||
return std.math.acos(input);
|
||||
}
|
||||
}.func;
|
||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
||||
}
|
||||
|
||||
pub fn exportAtan(comptime T: type, comptime name: []const u8) void {
|
||||
comptime var f = struct {
|
||||
fn func(input: T) callconv(.C) T {
|
||||
return std.math.atan(input);
|
||||
}
|
||||
}.func;
|
||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
||||
}
|
||||
|
||||
pub fn exportRound(comptime T: type, comptime name: []const u8) void {
|
||||
comptime var f = struct {
|
||||
fn func(input: T) callconv(.C) i64 {
|
||||
return @floatToInt(i64, (@round(input)));
|
||||
}
|
||||
}.func;
|
||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
||||
}
|
||||
|
||||
pub fn bytesToU16C(arg: RocList, position: usize) callconv(.C) u16 {
|
||||
|
@ -52,7 +74,3 @@ fn bytesToU32(arg: RocList, position: usize) u32 {
|
|||
const bytes = @ptrCast([*]const u8, arg.bytes);
|
||||
return @bitCast(u32, [_]u8{ bytes[position], bytes[position + 1], bytes[position + 2], bytes[position + 3] });
|
||||
}
|
||||
|
||||
pub fn round(num: f64) callconv(.C) i64 {
|
||||
return @floatToInt(i32, (@round(num)));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue