Type shenanigans work

This commit is contained in:
Joshua Hoeflich 2021-08-14 18:50:49 -05:00
parent c8f6762deb
commit 5115a004ed
4 changed files with 19 additions and 8 deletions

View file

@ -24,10 +24,11 @@ pub fn asin(num: f64) callconv(.C) f64 {
/// TODO: Obviously, this should not be an alias for x + 1. /// TODO: Obviously, this should not be an alias for x + 1.
/// fix me! /// fix me!
pub fn bytesToU16C(num: usize) callconv(.C) usize { pub fn bytesToU16C(num: usize) callconv(.C) u16 {
return @call(.{ .modifier = always_inline }, bytesToU16, .{num}); return @call(.{ .modifier = always_inline }, bytesToU16, .{num});
} }
fn bytesToU16(num: usize) usize { fn bytesToU16(num: usize) u16 {
return num + 1; const exampleAnswer: u16 = 40;
return 40;
} }

View file

@ -5,7 +5,7 @@ use roc_region::all::Region;
use roc_types::builtin_aliases::{ use roc_types::builtin_aliases::{
bool_type, dict_type, float_type, i128_type, int_type, list_type, nat_type, num_type, bool_type, dict_type, float_type, i128_type, int_type, list_type, nat_type, num_type,
ordering_type, result_type, set_type, str_type, str_utf8_byte_problem_type, u32_type, u64_type, ordering_type, result_type, set_type, str_type, str_utf8_byte_problem_type, u32_type, u64_type,
u8_type, u8_type, u16_type
}; };
use roc_types::solved_types::SolvedType; use roc_types::solved_types::SolvedType;
use roc_types::subs::VarId; use roc_types::subs::VarId;
@ -502,11 +502,11 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
); );
// TODO: This is obviously wrong! Fix me! // TODO: This is obviously wrong! Fix me!
// bytesToU16 : Float a -> Float a // bytesToU16 : Nat -> U16
add_top_level_function_type!( add_top_level_function_type!(
Symbol::NUM_BYTES_TO_U16, Symbol::NUM_BYTES_TO_U16,
vec![nat_type()], vec![nat_type()],
Box::new(nat_type()), Box::new(u16_type()),
); );
// Bool module // Bool module

View file

@ -1623,11 +1623,11 @@ mod gen_num {
#[test] #[test]
fn num_bytes_to_u16_ascii() { fn num_bytes_to_u16_ascii() {
assert_evals_to!("Num.bytesToU16 1", 2, usize); assert_evals_to!("Num.bytesToU16 1", 40, u16);
} }
#[test] #[test]
fn num_bytes_to_u16_ascii_2() { fn num_bytes_to_u16_ascii_2() {
assert_evals_to!("Num.bytesToU16 0", 1, usize); assert_evals_to!("Num.bytesToU16 0", 40, u16);
} }
} }

View file

@ -521,6 +521,16 @@ pub fn u8_type() -> SolvedType {
) )
} }
#[inline(always)]
pub fn u16_type() -> SolvedType {
SolvedType::Alias(
Symbol::NUM_U16,
vec![],
vec![],
Box::new(int_alias_content(unsigned16_type())),
)
}
#[inline(always)] #[inline(always)]
pub fn binary64_type() -> SolvedType { pub fn binary64_type() -> SolvedType {
SolvedType::Alias( SolvedType::Alias(