mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
a way forward
This commit is contained in:
parent
8a4975ee8a
commit
6cc8f8624c
5 changed files with 18 additions and 6 deletions
|
@ -75,7 +75,7 @@ const num = @import("num.zig");
|
|||
comptime {
|
||||
exportNumFn(num.atan, "atan");
|
||||
exportNumFn(num.isFinite, "is_finite");
|
||||
exportNumFn(num.powInt, "pow_int");
|
||||
// exportNumFn(num.powInt, "pow_int");
|
||||
exportNumFn(num.acos, "acos");
|
||||
exportNumFn(num.asin, "asin");
|
||||
exportNumFn(num.bytesToU16C, "bytes_to_u16");
|
||||
|
|
|
@ -11,8 +11,20 @@ pub fn isFinite(num: f64) callconv(.C) bool {
|
|||
return @call(.{ .modifier = always_inline }, math.isFinite, .{num});
|
||||
}
|
||||
|
||||
pub fn powInt(base: i64, exp: i64) callconv(.C) i64 {
|
||||
return @call(.{ .modifier = always_inline }, math.pow, .{ i64, base, exp });
|
||||
comptime {
|
||||
var types = [_]type{ i32, i64, i16 };
|
||||
inline for (types) |T| {
|
||||
exportFunctions(T);
|
||||
}
|
||||
}
|
||||
fn exportFunctions(comptime T: type) 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);
|
||||
}
|
||||
|
||||
pub fn acos(num: f64) callconv(.C) f64 {
|
||||
|
|
|
@ -7,7 +7,7 @@ pub const NUM_ASIN: &str = "roc_builtins.num.asin";
|
|||
pub const NUM_ACOS: &str = "roc_builtins.num.acos";
|
||||
pub const NUM_ATAN: &str = "roc_builtins.num.atan";
|
||||
pub const NUM_IS_FINITE: &str = "roc_builtins.num.is_finite";
|
||||
pub const NUM_POW_INT: &str = "roc_builtins.num.pow_int";
|
||||
pub const NUM_POW_INT_I64: &str = "roc_builtins.num.pow_int_i64";
|
||||
pub const NUM_BYTES_TO_U16: &str = "roc_builtins.num.bytes_to_u16";
|
||||
pub const NUM_BYTES_TO_U32: &str = "roc_builtins.num.bytes_to_u32";
|
||||
pub const NUM_ROUND: &str = "roc_builtins.num.round";
|
||||
|
|
|
@ -437,7 +437,7 @@ where
|
|||
}
|
||||
LowLevel::NumPowInt => self.build_fn_call(
|
||||
sym,
|
||||
bitcode::NUM_POW_INT.to_string(),
|
||||
bitcode::NUM_POW_INT_I64.to_string(),
|
||||
args,
|
||||
arg_layouts,
|
||||
ret_layout,
|
||||
|
|
|
@ -6072,7 +6072,7 @@ fn build_int_binop<'a, 'ctx, 'env>(
|
|||
}
|
||||
}
|
||||
NumDivUnchecked => bd.build_int_signed_div(lhs, rhs, "div_int").into(),
|
||||
NumPowInt => call_bitcode_fn(env, &[lhs.into(), rhs.into()], bitcode::NUM_POW_INT),
|
||||
NumPowInt => call_bitcode_fn(env, &[lhs.into(), rhs.into()], bitcode::NUM_POW_INT_I64),
|
||||
NumBitwiseAnd => bd.build_and(lhs, rhs, "int_bitwise_and").into(),
|
||||
NumBitwiseXor => bd.build_xor(lhs, rhs, "int_bitwise_xor").into(),
|
||||
NumBitwiseOr => bd.build_or(lhs, rhs, "int_bitwise_or").into(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue