mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
add special repl functions for string and list
This commit is contained in:
parent
984000095f
commit
dfbad3c322
3 changed files with 69 additions and 14 deletions
|
@ -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>(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue