Implement user crash in llvm backend

This commit is contained in:
Ayaz Hafiz 2022-11-22 16:27:56 -06:00
parent d9a8cba821
commit c8accc90e8
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58

View file

@ -186,6 +186,7 @@ pub struct Env<'a, 'ctx, 'env> {
#[repr(u32)]
pub enum PanicTagId {
RocPanic = 0,
UserPanic = 1,
}
impl std::convert::TryFrom<u32> for PanicTagId {
@ -2715,7 +2716,13 @@ pub fn build_exp_stmt<'a, 'ctx, 'env>(
let zero = env.context.i64_type().const_zero();
zero.into()
}
Crash(_, _) => todo!(),
Crash(sym, _) => {
throw_user_exception(env, scope, parent, sym);
// unused value (must return a BasicValue)
let zero = env.context.i64_type().const_zero();
zero.into()
}
}
}
@ -5535,6 +5542,19 @@ pub(crate) fn throw_exception<'a, 'ctx, 'env>(
builder.build_unreachable();
}
pub(crate) fn throw_user_exception<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>,
scope: &mut Scope<'a, 'ctx>,
parent: FunctionValue<'ctx>,
message: &Symbol,
) {
let msg_val = load_symbol(scope, message);
env.call_panic(msg_val, PanicTagId::UserPanic);
env.builder.build_unreachable();
}
fn get_foreign_symbol<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>,
foreign_symbol: roc_module::ident::ForeignSymbol,