Dummy implementation that doesn't do what we want

This commit is contained in:
Joshua Hoeflich 2021-08-14 17:59:53 -05:00
parent b031eb0e54
commit ff2c3d7945
10 changed files with 79 additions and 2 deletions

View file

@ -79,6 +79,7 @@ comptime {
exportNumFn(num.powInt, "pow_int");
exportNumFn(num.acos, "acos");
exportNumFn(num.asin, "asin");
exportNumFn(num.bytesToU16C, "bytes_to_u16");
}
// Str Module

View file

@ -21,3 +21,9 @@ pub fn acos(num: f64) callconv(.C) f64 {
pub fn asin(num: f64) callconv(.C) f64 {
return @call(.{ .modifier = always_inline }, math.asin, .{num});
}
/// TODO: Obviously, this should not be an alias for arcsin(x);
/// fix me!
pub fn bytesToU16C(num: f64) callconv(.C) f64 {
return @call(.{ .modifier = always_inline }, math.asin, .{num});
}

View file

@ -8,6 +8,8 @@ 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_BYTES_TO_U16: &str = "roc_builtins.num.bytes_to_u16";
pub const STR_INIT: &str = "roc_builtins.str.init";
pub const STR_COUNT_SEGMENTS: &str = "roc_builtins.str.count_segments";

View file

@ -501,6 +501,14 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
Box::new(float_type(flex(TVAR1))),
);
// TODO: This is obviously wrong! Fix me!
// bytesToU16 : Float a -> Float a
add_top_level_function_type!(
Symbol::NUM_BYTES_TO_U16,
vec![float_type(flex(TVAR1))],
Box::new(float_type(flex(TVAR1))),
);
// Bool module
// and : Bool, Bool -> Bool

View file

@ -161,6 +161,7 @@ pub fn builtin_defs_map(symbol: Symbol, var_store: &mut VarStore) -> Option<Def>
NUM_ATAN => num_atan,
NUM_ACOS => num_acos,
NUM_ASIN => num_asin,
NUM_BYTES_TO_U16 => num_bytes_to_u16,
NUM_MAX_INT => num_max_int,
NUM_MIN_INT => num_min_int,
NUM_BITWISE_AND => num_bitwise_and,
@ -1088,6 +1089,27 @@ fn num_asin(symbol: Symbol, var_store: &mut VarStore) -> Def {
)
}
/// TODO: This is obviously wrong! Fix me!
/// Num.bytesToU16 : Float -> Float
fn num_bytes_to_u16(symbol: Symbol, var_store: &mut VarStore) -> Def {
let arg_float_var = var_store.fresh();
let ret_float_var = var_store.fresh();
let body = RunLowLevel {
op: LowLevel::NumAsin,
args: vec![(arg_float_var, Var(Symbol::ARG_1))],
ret_var: ret_float_var,
};
defn(
symbol,
vec![(arg_float_var, Symbol::ARG_1)],
var_store,
body,
ret_float_var,
)
}
/// Num.bitwiseAnd : Int a, Int a -> Int a
fn num_bitwise_and(symbol: Symbol, var_store: &mut VarStore) -> Def {
num_binop(symbol, var_store, LowLevel::NumBitwiseAnd)

View file

@ -4738,6 +4738,36 @@ fn run_low_level<'a, 'ctx, 'env>(
}
}
}
// TODO: Obviously, this is completely wrong! Fix me!
NumBytesToU16 => {
debug_assert_eq!(args.len(), 1);
let (arg, arg_layout) = load_symbol_and_layout(scope, &args[0]);
match arg_layout {
Layout::Builtin(arg_builtin) => {
use roc_mono::layout::Builtin::*;
match arg_builtin {
Usize | Int128 | Int64 | Int32 | Int16 | Int8 => {
build_int_unary_op(env, arg.into_int_value(), arg_builtin, op)
}
Float128 | Float64 | Float32 | Float16 => {
build_float_unary_op(env, arg.into_float_value(), op)
}
_ => {
unreachable!("Compiler bug: tried to run numeric operation {:?} on invalid builtin layout: ({:?})", op, arg_layout);
}
}
}
_ => {
unreachable!(
"Compiler bug: tried to run numeric operation {:?} on invalid layout: {:?}",
op, arg_layout
);
}
}
}
NumCompare => {
use inkwell::FloatPredicate;

View file

@ -87,6 +87,7 @@ pub enum LowLevel {
NumAtan,
NumAcos,
NumAsin,
NumBytesToU16,
NumBitwiseAnd,
NumBitwiseXor,
NumBitwiseOr,
@ -122,7 +123,7 @@ impl LowLevel {
| NumRemUnchecked | NumIsMultipleOf | NumAbs | NumNeg | NumSin | NumCos
| NumSqrtUnchecked | NumLogUnchecked | NumRound | NumToFloat | NumPow | NumCeiling
| NumPowInt | NumFloor | NumIsFinite | NumAtan | NumAcos | NumAsin | NumBitwiseAnd
| NumBitwiseXor | NumBitwiseOr | NumShiftLeftBy | NumShiftRightBy
| NumBitwiseXor | NumBitwiseOr | NumShiftLeftBy | NumShiftRightBy | NumBytesToU16
| NumShiftRightZfBy | NumIntCast | Eq | NotEq | And | Or | Not | Hash | ExpectTrue => {
false
}

View file

@ -891,7 +891,7 @@ define_builtins! {
100 NUM_AT_DECIMAL: "@Decimal"
101 NUM_DECIMAL: "Decimal" imported
102 NUM_DEC: "Dec" imported // the Num.Dectype alias
103 NUM_BYTES_TO_U16: "bytesToU16"
}
2 BOOL: "Bool" => {
0 BOOL_BOOL: "Bool" imported // the Bool.Bool type alias

View file

@ -1012,6 +1012,8 @@ pub fn lowlevel_borrow_signature(arena: &Bump, op: LowLevel) -> &[bool] {
NumAbs | NumNeg | NumSin | NumCos | NumSqrtUnchecked | NumLogUnchecked | NumRound
| NumCeiling | NumFloor | NumToFloat | Not | NumIsFinite | NumAtan | NumAcos | NumAsin
| NumIntCast => arena.alloc_slice_copy(&[irrelevant]),
// TODO: Fix me! I am wrong!
NumBytesToU16 => arena.alloc_slice_copy(&[irrelevant]),
StrStartsWith | StrEndsWith => arena.alloc_slice_copy(&[owned, borrowed]),
StrStartsWithCodePt => arena.alloc_slice_copy(&[borrowed, irrelevant]),
StrFromUtf8 => arena.alloc_slice_copy(&[owned]),

View file

@ -1620,4 +1620,9 @@ mod gen_num {
// overflow
assert_evals_to!("Num.isMultipleOf -9223372036854775808 -1", true, bool);
}
#[test]
fn num_bytes_to_u16_ascii() {
assert_evals_to!("Num.bytesToU16 0", 0.0, f64);
}
}