mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
WIP send panics to the repl more gracefully
This commit is contained in:
parent
45e800c328
commit
a36ddbf6cb
5 changed files with 31 additions and 14 deletions
|
@ -118,9 +118,9 @@ macro_rules! run_jit_function {
|
||||||
// only if there are no exceptions thrown, check for errors
|
// only if there are no exceptions thrown, check for errors
|
||||||
assert!($errors.is_empty(), "Encountered errors:\n{}", $errors);
|
assert!($errors.is_empty(), "Encountered errors:\n{}", $errors);
|
||||||
|
|
||||||
$transform(success)
|
Ok($transform(success))
|
||||||
}
|
}
|
||||||
Err(error_msg) => panic!("Roc failed with message: {}", error_msg),
|
Err(error_msg) => Err(error_msg.to_string()),
|
||||||
}
|
}
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,11 @@ impl<'a> ReplApp<'a> for CliApp {
|
||||||
|
|
||||||
/// Run user code that returns a type with a `Builtin` layout
|
/// Run user code that returns a type with a `Builtin` layout
|
||||||
/// Size of the return value is statically determined from its Rust type
|
/// Size of the return value is statically determined from its Rust type
|
||||||
fn call_function<Return, F>(&mut self, main_fn_name: &str, mut transform: F) -> Expr<'a>
|
fn call_function<Return, F>(
|
||||||
|
&mut self,
|
||||||
|
main_fn_name: &str,
|
||||||
|
mut transform: F,
|
||||||
|
) -> Result<Expr<'a>, String>
|
||||||
where
|
where
|
||||||
F: FnMut(&'a Self::Memory, Return) -> Expr<'a>,
|
F: FnMut(&'a Self::Memory, Return) -> Expr<'a>,
|
||||||
Self::Memory: 'a,
|
Self::Memory: 'a,
|
||||||
|
|
|
@ -49,7 +49,7 @@ pub fn jit_to_ast<'a, A: ReplApp<'a>>(
|
||||||
interns: &'a Interns,
|
interns: &'a Interns,
|
||||||
layout_interner: LayoutInterner<'a>,
|
layout_interner: LayoutInterner<'a>,
|
||||||
target_info: TargetInfo,
|
target_info: TargetInfo,
|
||||||
) -> Expr<'a> {
|
) -> Result<Expr<'a>, String> {
|
||||||
let mut env = Env {
|
let mut env = Env {
|
||||||
arena,
|
arena,
|
||||||
subs,
|
subs,
|
||||||
|
@ -330,7 +330,7 @@ fn jit_to_ast_help<'a, A: ReplApp<'a>>(
|
||||||
main_fn_name: &str,
|
main_fn_name: &str,
|
||||||
layout: &Layout<'a>,
|
layout: &Layout<'a>,
|
||||||
var: Variable,
|
var: Variable,
|
||||||
) -> Expr<'a> {
|
) -> Result<Expr<'a>, String> {
|
||||||
let (newtype_containers, alias_content, raw_var) = unroll_newtypes_and_aliases(env, var);
|
let (newtype_containers, alias_content, raw_var) = unroll_newtypes_and_aliases(env, var);
|
||||||
|
|
||||||
macro_rules! num_helper {
|
macro_rules! num_helper {
|
||||||
|
@ -341,7 +341,7 @@ fn jit_to_ast_help<'a, A: ReplApp<'a>>(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let expr = match layout {
|
let result = match layout {
|
||||||
Layout::Builtin(Builtin::Bool) => {
|
Layout::Builtin(Builtin::Bool) => {
|
||||||
app.call_function(main_fn_name, |mem: &A::Memory, num: bool| {
|
app.call_function(main_fn_name, |mem: &A::Memory, num: bool| {
|
||||||
bool_to_ast(
|
bool_to_ast(
|
||||||
|
@ -499,7 +499,7 @@ fn jit_to_ast_help<'a, A: ReplApp<'a>>(
|
||||||
Layout::RecursivePointer => {
|
Layout::RecursivePointer => {
|
||||||
unreachable!("RecursivePointers can only be inside structures")
|
unreachable!("RecursivePointers can only be inside structures")
|
||||||
}
|
}
|
||||||
Layout::LambdaSet(_) => OPAQUE_FUNCTION,
|
Layout::LambdaSet(_) => Ok(OPAQUE_FUNCTION),
|
||||||
Layout::Boxed(_) => {
|
Layout::Boxed(_) => {
|
||||||
let size = layout.stack_size(&env.layout_cache.interner, env.target_info);
|
let size = layout.stack_size(&env.layout_cache.interner, env.target_info);
|
||||||
|
|
||||||
|
@ -516,7 +516,7 @@ fn jit_to_ast_help<'a, A: ReplApp<'a>>(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
apply_newtypes(env, newtype_containers.into_bump_slice(), expr)
|
result.map(|expr| apply_newtypes(env, newtype_containers.into_bump_slice(), expr))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tag_name_to_expr<'a>(env: &Env<'a, '_>, tag_name: &TagName) -> Expr<'a> {
|
fn tag_name_to_expr<'a>(env: &Env<'a, '_>, tag_name: &TagName) -> Expr<'a> {
|
||||||
|
|
|
@ -11,12 +11,20 @@ pub trait ReplApp<'a> {
|
||||||
/// Run user code that returns a type with a `Builtin` layout
|
/// Run user code that returns a type with a `Builtin` layout
|
||||||
/// Size of the return value is statically determined from its Rust type
|
/// Size of the return value is statically determined from its Rust type
|
||||||
/// The `transform` callback takes the app's memory and the returned value
|
/// The `transform` callback takes the app's memory and the returned value
|
||||||
fn call_function<Return, F>(&mut self, main_fn_name: &str, transform: F) -> Expr<'a>
|
fn call_function<Return, F>(
|
||||||
|
&mut self,
|
||||||
|
main_fn_name: &str,
|
||||||
|
transform: F,
|
||||||
|
) -> Result<Expr<'a>, String>
|
||||||
where
|
where
|
||||||
F: FnMut(&'a Self::Memory, Return) -> Expr<'a>,
|
F: FnMut(&'a Self::Memory, Return) -> Expr<'a>,
|
||||||
Self::Memory: 'a;
|
Self::Memory: 'a;
|
||||||
|
|
||||||
fn call_function_returns_roc_list<F>(&mut self, main_fn_name: &str, transform: F) -> Expr<'a>
|
fn call_function_returns_roc_list<F>(
|
||||||
|
&mut self,
|
||||||
|
main_fn_name: &str,
|
||||||
|
transform: F,
|
||||||
|
) -> Result<Expr<'a>, String>
|
||||||
where
|
where
|
||||||
F: FnMut(&'a Self::Memory, (usize, usize, usize)) -> Expr<'a>,
|
F: FnMut(&'a Self::Memory, (usize, usize, usize)) -> Expr<'a>,
|
||||||
Self::Memory: 'a,
|
Self::Memory: 'a,
|
||||||
|
@ -29,7 +37,7 @@ pub trait ReplApp<'a> {
|
||||||
target_info: TargetInfo,
|
target_info: TargetInfo,
|
||||||
main_fn_name: &str,
|
main_fn_name: &str,
|
||||||
transform: F,
|
transform: F,
|
||||||
) -> T
|
) -> Result<T, String>
|
||||||
where
|
where
|
||||||
F: Fn(&'a Self::Memory, usize) -> T,
|
F: Fn(&'a Self::Memory, usize) -> T,
|
||||||
Self::Memory: 'a,
|
Self::Memory: 'a,
|
||||||
|
@ -49,7 +57,7 @@ pub trait ReplApp<'a> {
|
||||||
main_fn_name: &str,
|
main_fn_name: &str,
|
||||||
ret_bytes: usize,
|
ret_bytes: usize,
|
||||||
transform: F,
|
transform: F,
|
||||||
) -> T
|
) -> Result<T, String>
|
||||||
where
|
where
|
||||||
F: FnMut(&'a Self::Memory, usize) -> T,
|
F: FnMut(&'a Self::Memory, usize) -> T,
|
||||||
Self::Memory: 'a;
|
Self::Memory: 'a;
|
||||||
|
|
|
@ -84,7 +84,11 @@ impl<'a> ReplApp<'a> for ExpectReplApp<'a> {
|
||||||
/// Size of the return value is statically determined from its Rust type
|
/// Size of the return value is statically determined from its Rust type
|
||||||
/// The `transform` callback takes the app's memory and the returned value
|
/// The `transform` callback takes the app's memory and the returned value
|
||||||
/// _main_fn_name is always the same and we don't use it here
|
/// _main_fn_name is always the same and we don't use it here
|
||||||
fn call_function<Return, F>(&mut self, _main_fn_name: &str, mut transform: F) -> Expr<'a>
|
fn call_function<Return, F>(
|
||||||
|
&mut self,
|
||||||
|
_main_fn_name: &str,
|
||||||
|
mut transform: F,
|
||||||
|
) -> Result<Expr<'a>, String>
|
||||||
where
|
where
|
||||||
F: FnMut(&'a Self::Memory, Return) -> Expr<'a>,
|
F: FnMut(&'a Self::Memory, Return) -> Expr<'a>,
|
||||||
Self::Memory: 'a,
|
Self::Memory: 'a,
|
||||||
|
@ -95,7 +99,8 @@ impl<'a> ReplApp<'a> for ExpectReplApp<'a> {
|
||||||
ptr.read()
|
ptr.read()
|
||||||
};
|
};
|
||||||
|
|
||||||
transform(self.memory, result)
|
// TODO if it panicked, return Err
|
||||||
|
Ok(transform(self.memory, result))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call_function_returns_roc_list<F>(&mut self, main_fn_name: &str, transform: F) -> Expr<'a>
|
fn call_function_returns_roc_list<F>(&mut self, main_fn_name: &str, transform: F) -> Expr<'a>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue