Update gen_wasm's error handling to remove Result and use macros consistently

This commit is contained in:
Brian Carroll 2021-12-09 00:04:21 +00:00
parent 588b6fcce9
commit 1dda8859c4
8 changed files with 80 additions and 94 deletions

View file

@ -1,6 +1,7 @@
use bumpalo::collections::vec::Vec;
use bumpalo::Bump;
use core::panic;
use roc_reporting::internal_error;
use roc_module::symbol::Symbol;
@ -108,7 +109,7 @@ impl From<u32> for Align {
16 => Align::Bytes16,
32 => Align::Bytes32,
64 => Align::Bytes64,
_ => panic!("{:?}-byte alignment not supported", x),
_ => internal_error!("{:?}-byte alignment not supported", x),
}
}
}
@ -236,7 +237,7 @@ impl<'a> CodeBuilder<'a> {
let pushed_at = self.code.len();
let top_symbol: &mut Symbol = current_stack
.last_mut()
.unwrap_or_else(|| unreachable!("Empty stack when trying to set Symbol {:?}", sym));
.unwrap_or_else(|| internal_error!("Empty stack when trying to set Symbol {:?}", sym));
*top_symbol = sym;
VmSymbolState::Pushed { pushed_at }
@ -296,7 +297,9 @@ impl<'a> CodeBuilder<'a> {
use VmSymbolState::*;
match vm_state {
NotYetPushed => unreachable!("Symbol {:?} has no value yet. Nothing to load.", symbol),
NotYetPushed => {
internal_error!("Symbol {:?} has no value yet. Nothing to load.", symbol)
}
Pushed { pushed_at } => {
match self.current_stack().last() {
@ -648,7 +651,7 @@ impl<'a> CodeBuilder<'a> {
}
#[allow(dead_code)]
fn br_table() {
panic!("TODO");
todo!("br instruction");
}
instruction_no_args!(return_, RETURN, 0, false);
@ -684,7 +687,9 @@ impl<'a> CodeBuilder<'a> {
#[allow(dead_code)]
fn call_indirect() {
panic!("Not implemented. Roc doesn't use function pointers");
unimplemented!(
"There is no plan to implement call_indirect. Roc doesn't use function pointers"
);
}
instruction_no_args!(drop_, DROP, 1, false);