mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
Type shenanigans work
This commit is contained in:
parent
c8f6762deb
commit
5115a004ed
4 changed files with 19 additions and 8 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue