Dont remove stmt_error

This commit is contained in:
Ayaz Hafiz 2022-11-22 18:25:51 -06:00
parent ce5636d94f
commit ea386bf0af
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
2 changed files with 25 additions and 4 deletions

View file

@ -987,6 +987,27 @@ impl<'a> WasmBackend<'a> {
self.stmt(rc_stmt);
}
pub fn stmt_internal_error(&mut self, msg: &'a str) {
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 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);
self.stmt_crash(msg_sym, CrashTag::Roc);
}
pub fn stmt_crash(&mut self, msg: Symbol, tag: CrashTag) {
// load the pointer
self.storage.load_symbols(&mut self.code_builder, &[msg]);

View file

@ -1362,7 +1362,7 @@ impl<'a> LowLevelCall<'a> {
backend.code_builder.i32_const(i32::MIN);
backend.code_builder.i32_eq();
backend.code_builder.if_();
backend.stmt_runtime_error(PANIC_MSG);
backend.stmt_internal_error(PANIC_MSG);
backend.code_builder.end();
// x
@ -1388,7 +1388,7 @@ impl<'a> LowLevelCall<'a> {
backend.code_builder.i64_const(i64::MIN);
backend.code_builder.i64_eq();
backend.code_builder.if_();
backend.stmt_runtime_error(PANIC_MSG);
backend.stmt_internal_error(PANIC_MSG);
backend.code_builder.end();
// x
@ -1422,7 +1422,7 @@ impl<'a> LowLevelCall<'a> {
backend.code_builder.i32_const(i32::MIN);
backend.code_builder.i32_eq();
backend.code_builder.if_();
backend.stmt_runtime_error(PANIC_MSG);
backend.stmt_internal_error(PANIC_MSG);
backend.code_builder.end();
backend.code_builder.i32_const(0);
@ -1433,7 +1433,7 @@ impl<'a> LowLevelCall<'a> {
backend.code_builder.i64_const(i64::MIN);
backend.code_builder.i64_eq();
backend.code_builder.if_();
backend.stmt_runtime_error(PANIC_MSG);
backend.stmt_internal_error(PANIC_MSG);
backend.code_builder.end();
backend.code_builder.i64_const(0);