mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 22:09:09 +00:00
Tests for different bitwidth integers
This commit is contained in:
parent
8407e8ad4c
commit
408c31ebcc
3 changed files with 210 additions and 110 deletions
|
@ -103,7 +103,6 @@ impl WasmLayout {
|
||||||
|
|
||||||
// LocalOnly(F32, 2) => Ok(), // convert F16 to F32 (lowlevel function? Wasm-only?)
|
// LocalOnly(F32, 2) => Ok(), // convert F16 to F32 (lowlevel function? Wasm-only?)
|
||||||
// StackMemory(size) => Ok(), // would this be some kind of memcpy in the IR?
|
// StackMemory(size) => Ok(), // would this be some kind of memcpy in the IR?
|
||||||
|
|
||||||
HeapMemory => {
|
HeapMemory => {
|
||||||
if PTR_TYPE == I64 {
|
if PTR_TYPE == I64 {
|
||||||
Ok(I64Load(ALIGN_8, offset))
|
Ok(I64Load(ALIGN_8, offset))
|
||||||
|
@ -134,7 +133,6 @@ impl WasmLayout {
|
||||||
|
|
||||||
// LocalOnly(F32, 2) => Ok(), // convert F32 to F16 (lowlevel function? Wasm-only?)
|
// LocalOnly(F32, 2) => Ok(), // convert F32 to F16 (lowlevel function? Wasm-only?)
|
||||||
// StackMemory(size) => Ok(), // would this be some kind of memcpy in the IR?
|
// StackMemory(size) => Ok(), // would this be some kind of memcpy in the IR?
|
||||||
|
|
||||||
HeapMemory => {
|
HeapMemory => {
|
||||||
if PTR_TYPE == I64 {
|
if PTR_TYPE == I64 {
|
||||||
Ok(I64Store(ALIGN_8, offset))
|
Ok(I64Store(ALIGN_8, offset))
|
||||||
|
@ -498,20 +496,27 @@ impl<'a> WasmBackend<'a> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Literal::Int(x) => {
|
Literal::Int(x) => {
|
||||||
match layout {
|
let instruction = match layout {
|
||||||
Layout::Builtin(Builtin::Int32) => {
|
Layout::Builtin(Builtin::Int64) => I64Const(*x as i64),
|
||||||
self.instructions.push(I32Const(*x as i32));
|
Layout::Builtin(
|
||||||
}
|
Builtin::Int32
|
||||||
Layout::Builtin(Builtin::Int64) => {
|
| Builtin::Int16
|
||||||
self.instructions.push(I64Const(*x as i64));
|
| Builtin::Int8
|
||||||
}
|
| Builtin::Int1
|
||||||
|
| Builtin::Usize,
|
||||||
|
) => I32Const(*x as i32),
|
||||||
x => panic!("loading literal, {:?}, is not yet implemented", x),
|
x => panic!("loading literal, {:?}, is not yet implemented", x),
|
||||||
}
|
};
|
||||||
|
self.instructions.push(instruction);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Literal::Float(x) => {
|
Literal::Float(x) => {
|
||||||
let val: f64 = *x;
|
let instruction = match layout {
|
||||||
self.instructions.push(F64Const(val.to_bits()));
|
Layout::Builtin(Builtin::Float64) => F64Const((*x as f64).to_bits()),
|
||||||
|
Layout::Builtin(Builtin::Float32) => F32Const((*x as f32).to_bits()),
|
||||||
|
x => panic!("loading literal, {:?}, is not yet implemented", x),
|
||||||
|
};
|
||||||
|
self.instructions.push(instruction);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
x => Err(format!("loading literal, {:?}, is not yet implemented", x)),
|
x => Err(format!("loading literal, {:?}, is not yet implemented", x)),
|
||||||
|
|
|
@ -36,6 +36,101 @@ mod wasm_num {
|
||||||
assert_evals_to!(&format!("{:0.1}", f64::MAX), f64::MAX, f64);
|
assert_evals_to!(&format!("{:0.1}", f64::MAX), f64::MAX, f64);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn i8_add_wrap() {
|
||||||
|
assert_evals_to!(
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
x : I8
|
||||||
|
x = 0x7f + 0x7f
|
||||||
|
|
||||||
|
x
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
-2,
|
||||||
|
i8
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn i16_add_wrap() {
|
||||||
|
assert_evals_to!(
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
x : I16
|
||||||
|
x = 0x7fff + 0x7fff
|
||||||
|
|
||||||
|
x
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
-2,
|
||||||
|
i16
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn i32_add_wrap() {
|
||||||
|
assert_evals_to!(
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
x : I32
|
||||||
|
x = 0x7fffffff + 0x7fffffff
|
||||||
|
|
||||||
|
x
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
-2,
|
||||||
|
i32
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn u8_add_wrap() {
|
||||||
|
assert_evals_to!(
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
x : U8
|
||||||
|
x = 0xff + 0xff
|
||||||
|
|
||||||
|
x
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
0xfe,
|
||||||
|
u8
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn u16_add_wrap() {
|
||||||
|
assert_evals_to!(
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
x : U16
|
||||||
|
x = 0xffff + 0xffff
|
||||||
|
|
||||||
|
x
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
0xfffe,
|
||||||
|
u16
|
||||||
|
);
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
fn u32_add_wrap() {
|
||||||
|
assert_evals_to!(
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
x : U32
|
||||||
|
x = 0xffffffff + 0xffffffff
|
||||||
|
|
||||||
|
x
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
0xfffffffe,
|
||||||
|
u32
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn gen_add_i64() {
|
fn gen_add_i64() {
|
||||||
assert_evals_to!(
|
assert_evals_to!(
|
||||||
|
@ -154,44 +249,44 @@ mod wasm_num {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn gen_add_f64() {
|
fn gen_add_f64() {
|
||||||
// assert_evals_to!(
|
assert_evals_to!(
|
||||||
// indoc!(
|
indoc!(
|
||||||
// r#"
|
r#"
|
||||||
// 1.1 + 2.4 + 3
|
1.1 + 2.4 + 3
|
||||||
// "#
|
"#
|
||||||
// ),
|
),
|
||||||
// 6.5,
|
6.5,
|
||||||
// f64
|
f64
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn gen_sub_i64() {
|
fn gen_sub_i64() {
|
||||||
// assert_evals_to!(
|
assert_evals_to!(
|
||||||
// indoc!(
|
indoc!(
|
||||||
// r#"
|
r#"
|
||||||
// 1 - 2 - 3
|
1 - 2 - 3
|
||||||
// "#
|
"#
|
||||||
// ),
|
),
|
||||||
// -4,
|
-4,
|
||||||
// i64
|
i64
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn gen_mul_i64() {
|
fn gen_mul_i64() {
|
||||||
// assert_evals_to!(
|
assert_evals_to!(
|
||||||
// indoc!(
|
indoc!(
|
||||||
// r#"
|
r#"
|
||||||
// 2 * 4 * 6
|
2 * 4 * 6
|
||||||
// "#
|
"#
|
||||||
// ),
|
),
|
||||||
// 48,
|
48,
|
||||||
// i64
|
i64
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn i64_force_stack() {
|
fn i64_force_stack() {
|
||||||
|
@ -476,18 +571,18 @@ mod wasm_num {
|
||||||
// );
|
// );
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn gen_sub_f64() {
|
fn gen_sub_f64() {
|
||||||
// assert_evals_to!(
|
assert_evals_to!(
|
||||||
// indoc!(
|
indoc!(
|
||||||
// r#"
|
r#"
|
||||||
// 1.5 - 2.4 - 3
|
1.5 - 2.4 - 3
|
||||||
// "#
|
"#
|
||||||
// ),
|
),
|
||||||
// -3.9,
|
-3.9,
|
||||||
// f64
|
f64
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
// #[test]
|
||||||
// fn gen_div_i64() {
|
// fn gen_div_i64() {
|
||||||
|
@ -685,31 +780,31 @@ mod wasm_num {
|
||||||
// assert_evals_to!("0.0 >= 0.0", true, bool);
|
// assert_evals_to!("0.0 >= 0.0", true, bool);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn gen_order_of_arithmetic_ops() {
|
fn gen_order_of_arithmetic_ops() {
|
||||||
// assert_evals_to!(
|
assert_evals_to!(
|
||||||
// indoc!(
|
indoc!(
|
||||||
// r#"
|
r#"
|
||||||
// 1 + 3 * 7 - 2
|
1 + 3 * 7 - 2
|
||||||
// "#
|
"#
|
||||||
// ),
|
),
|
||||||
// 20,
|
20,
|
||||||
// i64
|
i64
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn gen_order_of_arithmetic_ops_complex_float() {
|
fn gen_order_of_arithmetic_ops_complex_float() {
|
||||||
// assert_evals_to!(
|
assert_evals_to!(
|
||||||
// indoc!(
|
indoc!(
|
||||||
// r#"
|
r#"
|
||||||
// 3 - 48 * 2.0
|
3 - 48 * 2.0
|
||||||
// "#
|
"#
|
||||||
// ),
|
),
|
||||||
// -93.0,
|
-93.0,
|
||||||
// f64
|
f64
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
// #[test]
|
||||||
// fn if_guard_bind_variable_false() {
|
// fn if_guard_bind_variable_false() {
|
||||||
|
|
|
@ -389,18 +389,18 @@ mod wasm_records {
|
||||||
// // );
|
// // );
|
||||||
// // }
|
// // }
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn i64_record1_literal() {
|
fn i64_record1_literal() {
|
||||||
// assert_evals_to!(
|
assert_evals_to!(
|
||||||
// indoc!(
|
indoc!(
|
||||||
// r#"
|
r#"
|
||||||
// { a: 3 }
|
{ a: 3 }
|
||||||
// "#
|
"#
|
||||||
// ),
|
),
|
||||||
// 3,
|
3,
|
||||||
// i64
|
i64
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // #[test]
|
// // #[test]
|
||||||
// // fn i64_record9_literal() {
|
// // fn i64_record9_literal() {
|
||||||
|
@ -428,21 +428,21 @@ mod wasm_records {
|
||||||
// // );
|
// // );
|
||||||
// // }
|
// // }
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn bool_literal() {
|
fn bool_literal() {
|
||||||
// assert_evals_to!(
|
assert_evals_to!(
|
||||||
// indoc!(
|
indoc!(
|
||||||
// r#"
|
r#"
|
||||||
// x : Bool
|
x : Bool
|
||||||
// x = True
|
x = True
|
||||||
|
|
||||||
// x
|
x
|
||||||
// "#
|
"#
|
||||||
// ),
|
),
|
||||||
// true,
|
true,
|
||||||
// bool
|
bool
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
// #[test]
|
||||||
// fn optional_field_when_use_default() {
|
// fn optional_field_when_use_default() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue