mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 22:09:09 +00:00
Add Integer/Float num aliases
This commit is contained in:
parent
80cfcd82f8
commit
0695dcac14
3 changed files with 439 additions and 127 deletions
|
@ -742,51 +742,61 @@ define_builtins! {
|
|||
1 NUM: "Num" => {
|
||||
0 NUM_NUM: "Num" imported // the Num.Num type alias
|
||||
1 NUM_AT_NUM: "@Num" // the Num.@Num private tag
|
||||
2 NUM_I64: "I64" imported // the Num.I64 type alias
|
||||
3 NUM_INTEGER: "Integer" imported // Int : Num Integer
|
||||
4 NUM_AT_INTEGER: "@Integer" // the Int.@Integer private tag
|
||||
5 NUM_F64: "F64" imported // the Num.F64 type alias
|
||||
6 NUM_FLOATINGPOINT: "FloatingPoint" imported // Float : Num FloatingPoint
|
||||
7 NUM_AT_FLOATINGPOINT: "@FloatingPoint" // the Float.@FloatingPoint private tag
|
||||
8 NUM_MAX_INT: "maxInt"
|
||||
9 NUM_MIN_INT: "minInt"
|
||||
10 NUM_MAX_FLOAT: "maxFloat"
|
||||
11 NUM_MIN_FLOAT: "minFloat"
|
||||
12 NUM_ABS: "abs"
|
||||
13 NUM_NEG: "neg"
|
||||
14 NUM_ADD: "add"
|
||||
15 NUM_SUB: "sub"
|
||||
16 NUM_MUL: "mul"
|
||||
17 NUM_LT: "isLt"
|
||||
18 NUM_LTE: "isLte"
|
||||
19 NUM_GT: "isGt"
|
||||
20 NUM_GTE: "isGte"
|
||||
21 NUM_TO_FLOAT: "toFloat"
|
||||
22 NUM_SIN: "sin"
|
||||
23 NUM_COS: "cos"
|
||||
24 NUM_TAN: "tan"
|
||||
25 NUM_IS_ZERO: "isZero"
|
||||
26 NUM_IS_EVEN: "isEven"
|
||||
27 NUM_IS_ODD: "isOdd"
|
||||
28 NUM_IS_POSITIVE: "isPositive"
|
||||
29 NUM_IS_NEGATIVE: "isNegative"
|
||||
30 NUM_REM: "rem"
|
||||
31 NUM_DIV_FLOAT: "div"
|
||||
32 NUM_DIV_INT: "divFloor"
|
||||
33 NUM_MOD_INT: "modInt"
|
||||
34 NUM_MOD_FLOAT: "modFloat"
|
||||
35 NUM_SQRT: "sqrt"
|
||||
36 NUM_ROUND: "round"
|
||||
37 NUM_COMPARE: "compare"
|
||||
38 NUM_POW: "pow"
|
||||
39 NUM_CEILING: "ceiling"
|
||||
40 NUM_POW_INT: "powInt"
|
||||
41 NUM_FLOOR: "floor"
|
||||
42 NUM_ADD_WRAP: "addWrap"
|
||||
43 NUM_ADD_CHECKED: "addChecked"
|
||||
44 NUM_ATAN: "atan"
|
||||
45 NUM_ACOS: "acos"
|
||||
46 NUM_ASIN: "asin"
|
||||
2 NUM_I128: "I128" imported // the Num.I128 type alias
|
||||
3 NUM_U128: "U128" imported // the Num.U128 type alias
|
||||
4 NUM_I64: "I64" imported // the Num.I64 type alias
|
||||
5 NUM_U64: "U64" imported // the Num.U64 type alias
|
||||
6 NUM_I32: "I32" imported // the Num.I32 type alias
|
||||
7 NUM_U32: "U32" imported // the Num.U32 type alias
|
||||
8 NUM_I16: "I16" imported // the Num.I16 type alias
|
||||
9 NUM_U16: "U16" imported // the Num.U16 type alias
|
||||
10 NUM_I8: "I8" imported // the Num.I8 type alias
|
||||
11 NUM_U8: "U8" imported // the Num.U8 type alias
|
||||
12 NUM_INTEGER: "Integer" imported // Int : Num Integer
|
||||
13 NUM_AT_INTEGER: "@Integer" // the Int.@Integer private tag
|
||||
14 NUM_F64: "F64" imported // the Num.F64 type alias
|
||||
15 NUM_F32: "F32" imported // the Num.F32 type alias
|
||||
16 NUM_FLOATINGPOINT: "FloatingPoint" imported // Float : Num FloatingPoint
|
||||
17 NUM_AT_FLOATINGPOINT: "@FloatingPoint" // the Float.@FloatingPoint private tag
|
||||
18 NUM_MAX_INT: "maxInt"
|
||||
19 NUM_MIN_INT: "minInt"
|
||||
20 NUM_MAX_FLOAT: "maxFloat"
|
||||
21 NUM_MIN_FLOAT: "minFloat"
|
||||
22 NUM_ABS: "abs"
|
||||
23 NUM_NEG: "neg"
|
||||
24 NUM_ADD: "add"
|
||||
25 NUM_SUB: "sub"
|
||||
26 NUM_MUL: "mul"
|
||||
27 NUM_LT: "isLt"
|
||||
28 NUM_LTE: "isLte"
|
||||
29 NUM_GT: "isGt"
|
||||
30 NUM_GTE: "isGte"
|
||||
31 NUM_TO_FLOAT: "toFloat"
|
||||
32 NUM_SIN: "sin"
|
||||
33 NUM_COS: "cos"
|
||||
34 NUM_TAN: "tan"
|
||||
35 NUM_IS_ZERO: "isZero"
|
||||
36 NUM_IS_EVEN: "isEven"
|
||||
37 NUM_IS_ODD: "isOdd"
|
||||
38 NUM_IS_POSITIVE: "isPositive"
|
||||
39 NUM_IS_NEGATIVE: "isNegative"
|
||||
40 NUM_REM: "rem"
|
||||
41 NUM_DIV_FLOAT: "div"
|
||||
42 NUM_DIV_INT: "divFloor"
|
||||
43 NUM_MOD_INT: "modInt"
|
||||
44 NUM_MOD_FLOAT: "modFloat"
|
||||
45 NUM_SQRT: "sqrt"
|
||||
46 NUM_ROUND: "round"
|
||||
47 NUM_COMPARE: "compare"
|
||||
48 NUM_POW: "pow"
|
||||
49 NUM_CEILING: "ceiling"
|
||||
50 NUM_POW_INT: "powInt"
|
||||
51 NUM_FLOOR: "floor"
|
||||
52 NUM_ADD_WRAP: "addWrap"
|
||||
53 NUM_ADD_CHECKED: "addChecked"
|
||||
54 NUM_ATAN: "atan"
|
||||
55 NUM_ACOS: "acos"
|
||||
56 NUM_ASIN: "asin"
|
||||
}
|
||||
2 BOOL: "Bool" => {
|
||||
0 BOOL_BOOL: "Bool" imported // the Bool.Bool type alias
|
||||
|
|
|
@ -1322,21 +1322,7 @@ mod solve_expr {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn annotation_using_int() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
int : I64
|
||||
|
||||
int
|
||||
"#
|
||||
),
|
||||
"I64",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn annotation_using_num_integer() {
|
||||
fn qualified_annotation_num_integer() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
|
@ -1348,44 +1334,12 @@ mod solve_expr {
|
|||
"I64",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn annotated_int() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
int : I64
|
||||
int = 5
|
||||
|
||||
int
|
||||
"#
|
||||
),
|
||||
"I64",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn qualified_annotated_int() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
int : Num.I64
|
||||
int = 5
|
||||
|
||||
int
|
||||
"#
|
||||
),
|
||||
"I64",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn annotated_num_integer() {
|
||||
fn annotation_num_integer() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
int : Num Integer
|
||||
int = 5
|
||||
|
||||
int
|
||||
"#
|
||||
|
@ -1395,12 +1349,78 @@ mod solve_expr {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn qualified_annotated_num_integer() {
|
||||
fn qualified_annotation_using_i128() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
int : Num.Num Num.Integer
|
||||
int = 5
|
||||
int : Num.I128
|
||||
|
||||
int
|
||||
"#
|
||||
),
|
||||
"I128",
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn annotation_using_i128() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
int : I128
|
||||
|
||||
int
|
||||
"#
|
||||
),
|
||||
"I128",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn qualified_annotation_using_u128() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
int : Num.U128
|
||||
|
||||
int
|
||||
"#
|
||||
),
|
||||
"U128",
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn annotation_using_u128() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
int : U128
|
||||
|
||||
int
|
||||
"#
|
||||
),
|
||||
"U128",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn qualified_annotation_using_i64() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
int : Num.I64
|
||||
|
||||
int
|
||||
"#
|
||||
),
|
||||
"I64",
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn annotation_using_i64() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
int : I64
|
||||
|
||||
int
|
||||
"#
|
||||
|
@ -1410,11 +1430,200 @@ mod solve_expr {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn annotation_using_float() {
|
||||
fn qualified_annotation_using_u64() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
float : F64
|
||||
int : Num.U64
|
||||
|
||||
int
|
||||
"#
|
||||
),
|
||||
"U64",
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn annotation_using_u64() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
int : U64
|
||||
|
||||
int
|
||||
"#
|
||||
),
|
||||
"U64",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn qualified_annotation_using_i32() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
int : Num.I32
|
||||
|
||||
int
|
||||
"#
|
||||
),
|
||||
"I32",
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn annotation_using_i32() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
int : I32
|
||||
|
||||
int
|
||||
"#
|
||||
),
|
||||
"I32",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn qualified_annotation_using_u32() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
int : Num.U32
|
||||
|
||||
int
|
||||
"#
|
||||
),
|
||||
"U32",
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn annotation_using_u32() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
int : U32
|
||||
|
||||
int
|
||||
"#
|
||||
),
|
||||
"U32",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn qualified_annotation_using_i16() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
int : Num.I16
|
||||
|
||||
int
|
||||
"#
|
||||
),
|
||||
"I16",
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn annotation_using_i16() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
int : I16
|
||||
|
||||
int
|
||||
"#
|
||||
),
|
||||
"I16",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn qualified_annotation_using_u16() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
int : Num.U16
|
||||
|
||||
int
|
||||
"#
|
||||
),
|
||||
"U16",
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn annotation_using_u16() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
int : U16
|
||||
|
||||
int
|
||||
"#
|
||||
),
|
||||
"U16",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn qualified_annotation_using_i8() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
int : Num.I8
|
||||
|
||||
int
|
||||
"#
|
||||
),
|
||||
"I8",
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn annotation_using_i8() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
int : I8
|
||||
|
||||
int
|
||||
"#
|
||||
),
|
||||
"I8",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn qualified_annotation_using_u8() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
int : Num.U8
|
||||
|
||||
int
|
||||
"#
|
||||
),
|
||||
"U8",
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn annotation_using_u8() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
int : U8
|
||||
|
||||
int
|
||||
"#
|
||||
),
|
||||
"U8",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn qualified_annotation_num_floatingpoint() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
float : Num.Num Num.FloatingPoint
|
||||
|
||||
float
|
||||
"#
|
||||
|
@ -1422,9 +1631,8 @@ mod solve_expr {
|
|||
"F64",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn annotation_using_num_floatingpoint() {
|
||||
fn annotation_num_floatingpoint() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
|
@ -1438,12 +1646,11 @@ mod solve_expr {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn qualified_annotated_float() {
|
||||
fn qualified_annotation_f64() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
float : Num.F64
|
||||
float = 5.5
|
||||
|
||||
float
|
||||
"#
|
||||
|
@ -1451,14 +1658,12 @@ mod solve_expr {
|
|||
"F64",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn annotated_float() {
|
||||
fn annotation_f64() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
float : F64
|
||||
float = 5.5
|
||||
|
||||
float
|
||||
"#
|
||||
|
@ -1468,17 +1673,29 @@ mod solve_expr {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn annotated_num_floatingpoint() {
|
||||
fn qualified_annotation_f32() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
float : Num FloatingPoint
|
||||
float = 5.5
|
||||
float : Num.F32
|
||||
|
||||
float
|
||||
"#
|
||||
),
|
||||
"F64",
|
||||
"F32",
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn annotation_f32() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
float : F32
|
||||
|
||||
float
|
||||
"#
|
||||
),
|
||||
"F32",
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1567,21 +1784,6 @@ mod solve_expr {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn qualified_annotated_num_floatingpoint() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
float : Num.Num Num.FloatingPoint
|
||||
float = 5.5
|
||||
|
||||
float
|
||||
"#
|
||||
),
|
||||
"F64",
|
||||
);
|
||||
}
|
||||
|
||||
// #[test]
|
||||
// fn annotation_using_num_used() {
|
||||
// // There was a problem where `I64`, because it is only an annotation
|
||||
|
|
|
@ -48,7 +48,27 @@ pub fn aliases() -> MutMap<Symbol, BuiltinAlias> {
|
|||
},
|
||||
);
|
||||
|
||||
// Int : Num Integer
|
||||
// I128 Num Integer
|
||||
add_alias(
|
||||
Symbol::NUM_I128,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: Vec::new(),
|
||||
typ: int_alias_content(),
|
||||
},
|
||||
);
|
||||
|
||||
// U128 : Num Integer
|
||||
add_alias(
|
||||
Symbol::NUM_U128,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: Vec::new(),
|
||||
typ: int_alias_content(),
|
||||
},
|
||||
);
|
||||
|
||||
// I64 Num Integer
|
||||
add_alias(
|
||||
Symbol::NUM_I64,
|
||||
BuiltinAlias {
|
||||
|
@ -58,6 +78,76 @@ pub fn aliases() -> MutMap<Symbol, BuiltinAlias> {
|
|||
},
|
||||
);
|
||||
|
||||
// U64 : Num Integer
|
||||
add_alias(
|
||||
Symbol::NUM_U64,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: Vec::new(),
|
||||
typ: int_alias_content(),
|
||||
},
|
||||
);
|
||||
|
||||
// I32 Num Integer
|
||||
add_alias(
|
||||
Symbol::NUM_I32,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: Vec::new(),
|
||||
typ: int_alias_content(),
|
||||
},
|
||||
);
|
||||
|
||||
// U32 : Num Integer
|
||||
add_alias(
|
||||
Symbol::NUM_U32,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: Vec::new(),
|
||||
typ: int_alias_content(),
|
||||
},
|
||||
);
|
||||
|
||||
// I16 Num Integer
|
||||
add_alias(
|
||||
Symbol::NUM_I16,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: Vec::new(),
|
||||
typ: int_alias_content(),
|
||||
},
|
||||
);
|
||||
|
||||
// U16 : Num Integer
|
||||
add_alias(
|
||||
Symbol::NUM_U16,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: Vec::new(),
|
||||
typ: int_alias_content(),
|
||||
},
|
||||
);
|
||||
|
||||
// I8 Num Integer
|
||||
add_alias(
|
||||
Symbol::NUM_I8,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: Vec::new(),
|
||||
typ: int_alias_content(),
|
||||
},
|
||||
);
|
||||
|
||||
// U8 : Num Integer
|
||||
add_alias(
|
||||
Symbol::NUM_U8,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: Vec::new(),
|
||||
typ: int_alias_content(),
|
||||
},
|
||||
);
|
||||
|
||||
// FloatingPoint : [ @FloatingPoint ]
|
||||
add_alias(
|
||||
Symbol::NUM_FLOATINGPOINT,
|
||||
|
@ -68,7 +158,7 @@ pub fn aliases() -> MutMap<Symbol, BuiltinAlias> {
|
|||
},
|
||||
);
|
||||
|
||||
// Float : Num FloatingPoint
|
||||
// F64 : Num FloatingPoint
|
||||
add_alias(
|
||||
Symbol::NUM_F64,
|
||||
BuiltinAlias {
|
||||
|
@ -78,6 +168,16 @@ pub fn aliases() -> MutMap<Symbol, BuiltinAlias> {
|
|||
},
|
||||
);
|
||||
|
||||
// F32 : Num FloatingPoint
|
||||
add_alias(
|
||||
Symbol::NUM_F32,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: Vec::new(),
|
||||
typ: float_alias_content(),
|
||||
},
|
||||
);
|
||||
|
||||
// Bool : [ True, False ]
|
||||
add_alias(
|
||||
Symbol::BOOL_BOOL,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue