forked from nulang-org/nulang
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_wasm_err.rs
More file actions
24 lines (24 loc) · 1.14 KB
/
Copy pathtest_wasm_err.rs
File metadata and controls
24 lines (24 loc) · 1.14 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
fn main() {
let source = "let x = 42; match x { 00 => false, _ => true }";
let mut type_checker = nulang::typechecker::TypeChecker::new();
let ast = nulang::parser::Parser::new(nulang::lexer::Lexer::new(source).lex().unwrap()).parse_module().unwrap();
type_checker.check_module(&ast).unwrap();
let hir = nulang::hir_lower::lower_module(&ast, &type_checker.inferred_decl_types);
let mir = nulang::mir_lower::lower_module(&hir).unwrap();
let mut backend = nulang::backends::DefaultWasmBackend;
let bytes = nulang::backends::WasmBackend::compile(&mut backend, &mir, "main").unwrap();
match nulang::backends::WasmBackend::run(&mut backend, &bytes) {
Err(e) => {
println!("Error: {}", e);
let mut current: Option<&dyn std::error::Error> = std::error::Error::source(&e);
while let Some(cause) = current {
println!("Caused by: {}", cause);
current = cause.source();
}
if let nulang::types::NuError::VMError { msg, .. } = e {
println!("Msg: {}", msg);
}
},
Ok(v) => println!("Ok: {:?}", v),
}
}