mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
RocStr roc_panic for wasm gen
This commit is contained in:
parent
2b49aee3d2
commit
d33985db92
3 changed files with 29 additions and 20 deletions
|
@ -988,17 +988,27 @@ impl<'a> WasmBackend<'a> {
|
|||
}
|
||||
|
||||
pub fn stmt_runtime_error(&mut self, msg: &'a str) {
|
||||
// Create a zero-terminated version of the message string
|
||||
let mut bytes = Vec::with_capacity_in(msg.len() + 1, self.env.arena);
|
||||
bytes.extend_from_slice(msg.as_bytes());
|
||||
bytes.push(0);
|
||||
let msg_sym = self.create_symbol("panic_str");
|
||||
let msg_storage = self.storage.allocate_var(
|
||||
self.env.layout_interner,
|
||||
Layout::Builtin(Builtin::Str),
|
||||
msg_sym,
|
||||
StoredVarKind::Variable,
|
||||
);
|
||||
|
||||
// Store it in the app's data section
|
||||
let elements_addr = self.store_bytes_in_data_section(&bytes);
|
||||
// Store the message as a RocStr on the stack
|
||||
let (local_id, offset) = match msg_storage {
|
||||
StoredValue::StackMemory { location, .. } => {
|
||||
location.local_and_offset(self.storage.stack_frame_pointer)
|
||||
}
|
||||
_ => internal_error!("String must always have stack memory"),
|
||||
};
|
||||
self.expr_string_literal(msg, local_id, offset);
|
||||
|
||||
// Pass its address to roc_panic
|
||||
let tag_id = 0;
|
||||
self.code_builder.i32_const(elements_addr as i32);
|
||||
// load the pointer
|
||||
self.storage
|
||||
.load_symbols(&mut self.code_builder, &[msg_sym]);
|
||||
self.code_builder.i32_const(tag_id);
|
||||
self.call_host_fn_after_loading_args("roc_panic", 2, false);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue