add special repl functions for string and list

This commit is contained in:
Folkert 2022-07-23 13:38:10 +02:00
parent 984000095f
commit dfbad3c322
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
3 changed files with 69 additions and 14 deletions

View file

@ -1,5 +1,6 @@
use roc_parse::ast::Expr;
use roc_std::RocDec;
use roc_target::TargetInfo;
pub mod eval;
pub mod gen;
@ -15,6 +16,32 @@ pub trait ReplApp<'a> {
F: Fn(&'a Self::Memory, Return) -> Expr<'a>,
Self::Memory: 'a;
fn call_function_returns_roc_list<F>(&self, main_fn_name: &str, transform: F) -> Expr<'a>
where
F: Fn(&'a Self::Memory, (usize, usize, usize)) -> Expr<'a>,
Self::Memory: 'a,
{
self.call_function(main_fn_name, transform)
}
fn call_function_returns_roc_str<T, F>(
&self,
target_info: TargetInfo,
main_fn_name: &str,
transform: F,
) -> T
where
F: Fn(&'a Self::Memory, usize) -> T,
Self::Memory: 'a,
{
let roc_str_width = match target_info.ptr_width() {
roc_target::PtrWidth::Bytes4 => 12,
roc_target::PtrWidth::Bytes8 => 24,
};
self.call_function_dynamic_size(main_fn_name, roc_str_width, transform)
}
/// Run user code that returns a struct or union, whose size is provided as an argument
/// The `transform` callback takes the app's memory and the address of the returned value
fn call_function_dynamic_size<T, F>(