-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathmain.rs
More file actions
65 lines (58 loc) · 1.52 KB
/
Copy pathmain.rs
File metadata and controls
65 lines (58 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#![feature(map_first_last)]
mod bigint;
mod bitmap;
mod bitrel;
mod continuation_table;
mod crc32;
mod gc;
mod leb128;
mod memory;
mod principal_id;
mod remembered_set;
mod stream;
mod text;
mod utf8;
use motoko_rts::types::Bytes;
fn main() {
if std::mem::size_of::<usize>() != 4 {
println!("Motoko RTS only works on 32-bit architectures");
std::process::exit(1);
}
unsafe {
bigint::test();
bitmap::test();
bitrel::test();
continuation_table::test();
crc32::test();
gc::test();
leb128::test();
principal_id::test();
stream::test();
text::test();
utf8::test();
remembered_set::test();
}
}
// Called by the RTS to panic
#[no_mangle]
extern "C" fn rts_trap(ptr: *const u8, len: Bytes<u32>) -> ! {
let msg = unsafe { std::slice::from_raw_parts(ptr, len.as_usize()) };
match core::str::from_utf8(msg) {
Err(err) => panic!(
"rts_trap_with called with non-UTF8 string (error={:?}, string={:?})",
err, msg
),
Ok(str) => panic!("rts_trap_with: {:?}", str),
}
}
// Called by RTS BigInt functions to panic. Normally generated by the compiler
#[no_mangle]
extern "C" fn bigint_trap() -> ! {
panic!("bigint_trap called");
}
// Called by the RTS for debug prints
#[no_mangle]
unsafe extern "C" fn print_ptr(ptr: usize, len: u32) {
let str: &[u8] = core::slice::from_raw_parts(ptr as *const u8, len as usize);
println!("[RTS] {}", String::from_utf8_lossy(str));
}