mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
use toplevel more
This commit is contained in:
parent
88f4b6bc9b
commit
d894a06290
2 changed files with 39 additions and 21 deletions
|
@ -602,7 +602,9 @@ fn promote_to_main_function<'a, 'ctx, 'env>(
|
|||
"we expect only one specialization of this symbol"
|
||||
);
|
||||
|
||||
let roc_main_fn = function_value_by_func_spec(env, *func_spec, symbol, Layout::Struct(&[]));
|
||||
// NOTE fake layout; it is only used for debug prints
|
||||
let roc_main_fn =
|
||||
function_value_by_func_spec(env, *func_spec, symbol, &[], &Layout::Struct(&[]));
|
||||
|
||||
let main_fn_name = "$Test.main";
|
||||
|
||||
|
@ -800,8 +802,9 @@ pub fn build_exp_call<'a, 'ctx, 'env>(
|
|||
match call_type {
|
||||
CallType::ByName {
|
||||
name,
|
||||
full_layout,
|
||||
specialization_id,
|
||||
arg_layouts,
|
||||
ret_layout,
|
||||
..
|
||||
} => {
|
||||
let mut arg_tuples: Vec<BasicValueEnum> =
|
||||
|
@ -817,7 +820,8 @@ pub fn build_exp_call<'a, 'ctx, 'env>(
|
|||
|
||||
roc_call_with_args(
|
||||
env,
|
||||
&full_layout,
|
||||
arg_layouts,
|
||||
ret_layout,
|
||||
*name,
|
||||
func_spec,
|
||||
arg_tuples.into_bump_slice(),
|
||||
|
@ -2050,7 +2054,8 @@ pub fn build_exp_stmt<'a, 'ctx, 'env>(
|
|||
} => match call.call_type {
|
||||
CallType::ByName {
|
||||
name,
|
||||
ref full_layout,
|
||||
arg_layouts,
|
||||
ref ret_layout,
|
||||
specialization_id,
|
||||
..
|
||||
} => {
|
||||
|
@ -2059,7 +2064,7 @@ pub fn build_exp_stmt<'a, 'ctx, 'env>(
|
|||
let func_spec = func_spec_solutions.callee_spec(callee_var).unwrap();
|
||||
|
||||
let function_value =
|
||||
function_value_by_func_spec(env, func_spec, name, *full_layout);
|
||||
function_value_by_func_spec(env, func_spec, name, arg_layouts, ret_layout);
|
||||
|
||||
invoke_roc_function(
|
||||
env,
|
||||
|
@ -3591,8 +3596,6 @@ pub fn build_proc<'a, 'ctx, 'env>(
|
|||
// * roc__mainForHost_1_Update_size() -> i64
|
||||
// * roc__mainForHost_1_Update_result_size() -> i64
|
||||
|
||||
let evaluator_layout = env.arena.alloc(top_level).full();
|
||||
|
||||
let it = top_level.arguments.iter().copied();
|
||||
let bytes = roc_mono::alias_analysis::func_name_bytes_help(
|
||||
symbol,
|
||||
|
@ -3609,8 +3612,13 @@ pub fn build_proc<'a, 'ctx, 'env>(
|
|||
"we expect only one specialization of this symbol"
|
||||
);
|
||||
|
||||
let evaluator =
|
||||
function_value_by_func_spec(env, *func_spec, symbol, evaluator_layout);
|
||||
let evaluator = function_value_by_func_spec(
|
||||
env,
|
||||
*func_spec,
|
||||
symbol,
|
||||
top_level.arguments,
|
||||
&top_level.result,
|
||||
);
|
||||
|
||||
let ident_string = proc.name.ident_string(&env.interns);
|
||||
let fn_name: String = format!("{}_1", ident_string);
|
||||
|
@ -3684,17 +3692,19 @@ fn function_value_by_func_spec<'a, 'ctx, 'env>(
|
|||
env: &Env<'a, 'ctx, 'env>,
|
||||
func_spec: FuncSpec,
|
||||
symbol: Symbol,
|
||||
layout: Layout<'a>,
|
||||
arguments: &[Layout<'a>],
|
||||
result: &Layout<'a>,
|
||||
) -> FunctionValue<'ctx> {
|
||||
let fn_name = func_spec_name(env.arena, &env.interns, symbol, func_spec);
|
||||
let fn_name = fn_name.as_str();
|
||||
|
||||
function_value_by_name_help(env, layout, symbol, fn_name)
|
||||
function_value_by_name_help(env, arguments, result, symbol, fn_name)
|
||||
}
|
||||
|
||||
fn function_value_by_name_help<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
layout: Layout<'a>,
|
||||
arguments: &[Layout<'a>],
|
||||
result: &Layout<'a>,
|
||||
symbol: Symbol,
|
||||
fn_name: &str,
|
||||
) -> FunctionValue<'ctx> {
|
||||
|
@ -3702,7 +3712,8 @@ fn function_value_by_name_help<'a, 'ctx, 'env>(
|
|||
if symbol.is_builtin() {
|
||||
eprintln!(
|
||||
"Unrecognized builtin function: {:?}\nLayout: {:?}\n",
|
||||
fn_name, layout
|
||||
fn_name,
|
||||
(arguments, result)
|
||||
);
|
||||
eprintln!("Is the function defined? If so, maybe there is a problem with the layout");
|
||||
|
||||
|
@ -3714,7 +3725,9 @@ fn function_value_by_name_help<'a, 'ctx, 'env>(
|
|||
// Unrecognized non-builtin function:
|
||||
eprintln!(
|
||||
"Unrecognized non-builtin function: {:?}\n\nSymbol: {:?}\nLayout: {:?}\n",
|
||||
fn_name, symbol, layout
|
||||
fn_name,
|
||||
symbol,
|
||||
(arguments, result)
|
||||
);
|
||||
eprintln!("Is the function defined? If so, maybe there is a problem with the layout");
|
||||
|
||||
|
@ -3730,12 +3743,14 @@ fn function_value_by_name_help<'a, 'ctx, 'env>(
|
|||
#[inline(always)]
|
||||
fn roc_call_with_args<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
layout: &Layout<'a>,
|
||||
argument_layouts: &[Layout<'a>],
|
||||
result_layout: &Layout<'a>,
|
||||
symbol: Symbol,
|
||||
func_spec: FuncSpec,
|
||||
args: &[BasicValueEnum<'ctx>],
|
||||
) -> BasicValueEnum<'ctx> {
|
||||
let fn_val = function_value_by_func_spec(env, func_spec, symbol, *layout);
|
||||
let fn_val =
|
||||
function_value_by_func_spec(env, func_spec, symbol, argument_layouts, result_layout);
|
||||
|
||||
let call = env.builder.build_call(fn_val, args, "call");
|
||||
|
||||
|
@ -3831,9 +3846,14 @@ fn run_higher_order_low_level<'a, 'ctx, 'env>(
|
|||
macro_rules! passed_function_at_index {
|
||||
($index:expr) => {{
|
||||
let function_symbol = args[$index];
|
||||
let function_layout = Layout::FunctionPointer(argument_layouts, return_layout);
|
||||
|
||||
function_value_by_func_spec(env, func_spec, function_symbol, function_layout)
|
||||
function_value_by_func_spec(
|
||||
env,
|
||||
func_spec,
|
||||
function_symbol,
|
||||
argument_layouts,
|
||||
return_layout,
|
||||
)
|
||||
}};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue