Implement crash in gen-wasm

This commit is contained in:
Ayaz Hafiz 2022-11-22 17:04:49 -06:00
parent a8122662c2
commit 32400e37e1
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
4 changed files with 32 additions and 14 deletions

View file

@ -718,7 +718,7 @@ impl<'a> WasmBackend<'a> {
Stmt::ExpectFx { .. } => todo!("expect-fx is not implemented in the wasm backend"),
Stmt::RuntimeError(msg) => self.stmt_runtime_error(msg),
Stmt::Crash(_, _) => todo!(),
Stmt::Crash(sym, _) => self.stmt_crash(*sym),
}
}
@ -1016,6 +1016,16 @@ impl<'a> WasmBackend<'a> {
self.code_builder.unreachable_();
}
pub fn stmt_crash(&mut self, msg: Symbol) {
let tag_id = 1;
// load the pointer
self.storage.load_symbols(&mut self.code_builder, &[msg]);
self.code_builder.i32_const(tag_id);
self.call_host_fn_after_loading_args("roc_panic", 2, false);
self.code_builder.unreachable_();
}
/**********************************************************
EXPRESSIONS