mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
get most cli tests to pass
This commit is contained in:
parent
4151dac452
commit
3c8d675378
4 changed files with 57 additions and 32 deletions
|
@ -600,7 +600,12 @@ pub fn promote_to_main_function<'a, 'ctx, 'env>(
|
||||||
let main_fn_name = "$Test.main";
|
let main_fn_name = "$Test.main";
|
||||||
|
|
||||||
// Add main to the module.
|
// Add main to the module.
|
||||||
let main_fn = expose_function_to_host_help(env, roc_main_fn, main_fn_name);
|
let main_fn = expose_function_to_host_help(
|
||||||
|
env,
|
||||||
|
&inlinable_string::InlinableString::from(main_fn_name),
|
||||||
|
roc_main_fn,
|
||||||
|
main_fn_name,
|
||||||
|
);
|
||||||
|
|
||||||
(main_fn_name, main_fn)
|
(main_fn_name, main_fn)
|
||||||
}
|
}
|
||||||
|
@ -2744,11 +2749,12 @@ fn expose_function_to_host<'a, 'ctx, 'env>(
|
||||||
let ident_string = symbol.ident_string(&env.interns);
|
let ident_string = symbol.ident_string(&env.interns);
|
||||||
let c_function_name: String = format!("roc__{}_1_exposed", ident_string);
|
let c_function_name: String = format!("roc__{}_1_exposed", ident_string);
|
||||||
|
|
||||||
expose_function_to_host_help(env, roc_function, &c_function_name);
|
expose_function_to_host_help(env, ident_string, roc_function, &c_function_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expose_function_to_host_help<'a, 'ctx, 'env>(
|
fn expose_function_to_host_help<'a, 'ctx, 'env>(
|
||||||
env: &Env<'a, 'ctx, 'env>,
|
env: &Env<'a, 'ctx, 'env>,
|
||||||
|
ident_string: &inlinable_string::InlinableString,
|
||||||
roc_function: FunctionValue<'ctx>,
|
roc_function: FunctionValue<'ctx>,
|
||||||
c_function_name: &str,
|
c_function_name: &str,
|
||||||
) -> FunctionValue<'ctx> {
|
) -> FunctionValue<'ctx> {
|
||||||
|
@ -2809,8 +2815,7 @@ fn expose_function_to_host_help<'a, 'ctx, 'env>(
|
||||||
|
|
||||||
// STEP 3: build a {} -> u64 function that gives the size of the return type
|
// STEP 3: build a {} -> u64 function that gives the size of the return type
|
||||||
let size_function_type = env.context.i64_type().fn_type(&[], false);
|
let size_function_type = env.context.i64_type().fn_type(&[], false);
|
||||||
let size_function_name: String =
|
let size_function_name: String = format!("roc__{}_size", ident_string);
|
||||||
format!("roc_{}_size", roc_function.get_name().to_str().unwrap());
|
|
||||||
|
|
||||||
let size_function = add_func(
|
let size_function = add_func(
|
||||||
env.module,
|
env.module,
|
||||||
|
@ -2889,7 +2894,7 @@ where
|
||||||
let info = builder
|
let info = builder
|
||||||
.build_catch_all_landing_pad(
|
.build_catch_all_landing_pad(
|
||||||
&landing_pad_type,
|
&landing_pad_type,
|
||||||
BasicValueEnum::IntValue(context.i8_type().const_zero()),
|
&BasicValueEnum::IntValue(context.i8_type().const_zero()),
|
||||||
context.i8_type().ptr_type(AddressSpace::Generic),
|
context.i8_type().ptr_type(AddressSpace::Generic),
|
||||||
"main_landing_pad",
|
"main_landing_pad",
|
||||||
)
|
)
|
||||||
|
@ -3172,6 +3177,7 @@ fn build_procedures_help<'a, 'ctx, 'env>(
|
||||||
|
|
||||||
build_proc(
|
build_proc(
|
||||||
&env,
|
&env,
|
||||||
|
mod_solutions,
|
||||||
&mut layout_ids,
|
&mut layout_ids,
|
||||||
func_spec_solutions,
|
func_spec_solutions,
|
||||||
scope.clone(),
|
scope.clone(),
|
||||||
|
@ -3242,8 +3248,6 @@ fn build_proc_header<'a, 'ctx, 'env>(
|
||||||
|
|
||||||
let fn_name = func_spec_name(env.arena, &env.interns, symbol, func_spec);
|
let fn_name = func_spec_name(env.arena, &env.interns, symbol, func_spec);
|
||||||
|
|
||||||
dbg!(&fn_name);
|
|
||||||
|
|
||||||
let ret_type = basic_type_from_layout(env, &proc.ret_layout);
|
let ret_type = basic_type_from_layout(env, &proc.ret_layout);
|
||||||
let mut arg_basic_types = Vec::with_capacity_in(args.len(), arena);
|
let mut arg_basic_types = Vec::with_capacity_in(args.len(), arena);
|
||||||
|
|
||||||
|
@ -3289,7 +3293,7 @@ pub fn build_closure_caller<'a, 'ctx, 'env>(
|
||||||
|
|
||||||
// e.g. `roc__main_1_Fx_caller`
|
// e.g. `roc__main_1_Fx_caller`
|
||||||
let function_name = format!(
|
let function_name = format!(
|
||||||
"roc_{}_{}_caller",
|
"roc__{}_{}_caller",
|
||||||
def_name,
|
def_name,
|
||||||
alias_symbol.ident_string(&env.interns)
|
alias_symbol.ident_string(&env.interns)
|
||||||
);
|
);
|
||||||
|
@ -3510,14 +3514,14 @@ fn build_host_exposed_alias_size_help<'a, 'ctx, 'env>(
|
||||||
let size_function_type = env.context.i64_type().fn_type(&[], false);
|
let size_function_type = env.context.i64_type().fn_type(&[], false);
|
||||||
let size_function_name: String = if let Some(label) = opt_label {
|
let size_function_name: String = if let Some(label) = opt_label {
|
||||||
format!(
|
format!(
|
||||||
"roc_{}_{}_{}_size",
|
"roc__{}_{}_{}_size",
|
||||||
def_name,
|
def_name,
|
||||||
alias_symbol.ident_string(&env.interns),
|
alias_symbol.ident_string(&env.interns),
|
||||||
label
|
label
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
format!(
|
format!(
|
||||||
"roc_{}_{}_size",
|
"roc__{}_{}_size",
|
||||||
def_name,
|
def_name,
|
||||||
alias_symbol.ident_string(&env.interns)
|
alias_symbol.ident_string(&env.interns)
|
||||||
)
|
)
|
||||||
|
@ -3541,6 +3545,7 @@ fn build_host_exposed_alias_size_help<'a, 'ctx, 'env>(
|
||||||
|
|
||||||
pub fn build_proc<'a, 'ctx, 'env>(
|
pub fn build_proc<'a, 'ctx, 'env>(
|
||||||
env: &'a Env<'a, 'ctx, 'env>,
|
env: &'a Env<'a, 'ctx, 'env>,
|
||||||
|
mod_solutions: &'a ModSolutions,
|
||||||
layout_ids: &mut LayoutIds<'a>,
|
layout_ids: &mut LayoutIds<'a>,
|
||||||
func_spec_solutions: &FuncSpecSolutions,
|
func_spec_solutions: &FuncSpecSolutions,
|
||||||
mut scope: Scope<'a, 'ctx>,
|
mut scope: Scope<'a, 'ctx>,
|
||||||
|
@ -3560,19 +3565,30 @@ pub fn build_proc<'a, 'ctx, 'env>(
|
||||||
//
|
//
|
||||||
// * roc__mainForHost_1_Update_size() -> i64
|
// * roc__mainForHost_1_Update_size() -> i64
|
||||||
// * roc__mainForHost_1_Update_result_size() -> i64
|
// * roc__mainForHost_1_Update_result_size() -> i64
|
||||||
continue;
|
|
||||||
|
|
||||||
let evaluator_layout = env.arena.alloc(top_level).full();
|
let evaluator_layout = env.arena.alloc(top_level).full();
|
||||||
let evaluator_name = layout_ids
|
|
||||||
.get(symbol, &evaluator_layout)
|
|
||||||
.to_symbol_string(symbol, &env.interns);
|
|
||||||
|
|
||||||
let evaluator = function_value_by_name_help(
|
let it = top_level.arguments.iter().copied();
|
||||||
env,
|
let bytes = roc_mono::alias_analysis::func_name_bytes_help(
|
||||||
evaluator_layout,
|
|
||||||
symbol,
|
symbol,
|
||||||
&evaluator_name,
|
it,
|
||||||
|
top_level.result,
|
||||||
);
|
);
|
||||||
|
let func_name = FuncName(&bytes);
|
||||||
|
let func_solutions = mod_solutions.func_solutions(func_name).unwrap();
|
||||||
|
|
||||||
|
let mut it = func_solutions.specs();
|
||||||
|
let func_spec = it.next().unwrap();
|
||||||
|
debug_assert!(
|
||||||
|
it.next().is_none(),
|
||||||
|
"we expect only one specialization of this symbol"
|
||||||
|
);
|
||||||
|
|
||||||
|
let evaluator =
|
||||||
|
function_value_by_func_spec(env, *func_spec, symbol, evaluator_layout);
|
||||||
|
|
||||||
|
let ident_string = proc.name.ident_string(&env.interns);
|
||||||
|
let fn_name: String = format!("{}_1", ident_string);
|
||||||
|
|
||||||
build_closure_caller(
|
build_closure_caller(
|
||||||
env, &fn_name, evaluator, name, arguments, closure, result,
|
env, &fn_name, evaluator, name, arguments, closure, result,
|
||||||
|
|
|
@ -39,9 +39,24 @@ where
|
||||||
let mut hasher = DefaultHasher::new();
|
let mut hasher = DefaultHasher::new();
|
||||||
|
|
||||||
for layout in argument_layouts {
|
for layout in argument_layouts {
|
||||||
|
match layout {
|
||||||
|
Layout::Closure(_, lambda_set, _) => {
|
||||||
|
lambda_set.runtime_representation().hash(&mut hasher);
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
layout.hash(&mut hasher);
|
layout.hash(&mut hasher);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
match return_layout {
|
||||||
|
Layout::Closure(_, lambda_set, _) => {
|
||||||
|
lambda_set.runtime_representation().hash(&mut hasher);
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
return_layout.hash(&mut hasher);
|
return_layout.hash(&mut hasher);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
hasher.finish()
|
hasher.finish()
|
||||||
};
|
};
|
||||||
|
@ -84,12 +99,6 @@ where
|
||||||
for proc in procs {
|
for proc in procs {
|
||||||
let spec = proc_spec(proc)?;
|
let spec = proc_spec(proc)?;
|
||||||
|
|
||||||
dbg!(proc.name);
|
|
||||||
for b in &func_name_bytes(proc) {
|
|
||||||
eprint!("{:x}", b);
|
|
||||||
}
|
|
||||||
eprintln!("");
|
|
||||||
|
|
||||||
m.add_func(FuncName(&func_name_bytes(proc)), spec)?;
|
m.add_func(FuncName(&func_name_bytes(proc)), spec)?;
|
||||||
|
|
||||||
if format!("{:?}", proc.name).contains("mainForHost") {
|
if format!("{:?}", proc.name).contains("mainForHost") {
|
||||||
|
@ -133,7 +142,7 @@ where
|
||||||
p.build()?
|
p.build()?
|
||||||
};
|
};
|
||||||
|
|
||||||
eprintln!("{}", program.to_source_string());
|
// eprintln!("{}", program.to_source_string());
|
||||||
|
|
||||||
morphic_lib::solve(program)
|
morphic_lib::solve(program)
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ use roc_types::subs::{Content, FlatType, Subs, Variable};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use ven_pretty::{BoxAllocator, DocAllocator, DocBuilder};
|
use ven_pretty::{BoxAllocator, DocAllocator, DocBuilder};
|
||||||
|
|
||||||
pub const PRETTY_PRINT_IR_SYMBOLS: bool = true;
|
pub const PRETTY_PRINT_IR_SYMBOLS: bool = false;
|
||||||
|
|
||||||
macro_rules! return_on_layout_error {
|
macro_rules! return_on_layout_error {
|
||||||
($env:expr, $layout_result:expr) => {
|
($env:expr, $layout_result:expr) => {
|
||||||
|
@ -2575,8 +2575,8 @@ fn cleanup_attempted_type<'a>(
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct TopLevelFunctionLayout<'a> {
|
pub struct TopLevelFunctionLayout<'a> {
|
||||||
arguments: &'a [Layout<'a>],
|
pub arguments: &'a [Layout<'a>],
|
||||||
result: Layout<'a>,
|
pub result: Layout<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> TopLevelFunctionLayout<'a> {
|
impl<'a> TopLevelFunctionLayout<'a> {
|
||||||
|
|
|
@ -24,7 +24,7 @@ const mem = std.mem;
|
||||||
const Allocator = mem.Allocator;
|
const Allocator = mem.Allocator;
|
||||||
|
|
||||||
extern fn roc__mainForHost_1_exposed([*]u8) void;
|
extern fn roc__mainForHost_1_exposed([*]u8) void;
|
||||||
extern fn roc__mainForHost_1_size() i64;
|
extern fn roc__mainForHost_size() i64;
|
||||||
extern fn roc__mainForHost_1_Fx_caller(*const u8, [*]u8, [*]u8) void;
|
extern fn roc__mainForHost_1_Fx_caller(*const u8, [*]u8, [*]u8) void;
|
||||||
extern fn roc__mainForHost_1_Fx_size() i64;
|
extern fn roc__mainForHost_1_Fx_size() i64;
|
||||||
extern fn roc__mainForHost_1_Fx_result_size() i64;
|
extern fn roc__mainForHost_1_Fx_result_size() i64;
|
||||||
|
@ -51,7 +51,7 @@ pub export fn main() u8 {
|
||||||
const stdout = std.io.getStdOut().writer();
|
const stdout = std.io.getStdOut().writer();
|
||||||
const stderr = std.io.getStdErr().writer();
|
const stderr = std.io.getStdErr().writer();
|
||||||
|
|
||||||
const size = @intCast(usize, roc__mainForHost_1_size());
|
const size = @intCast(usize, roc__mainForHost_size());
|
||||||
const raw_output = std.heap.c_allocator.alloc(u8, size) catch unreachable;
|
const raw_output = std.heap.c_allocator.alloc(u8, size) catch unreachable;
|
||||||
var output = @ptrCast([*]u8, raw_output);
|
var output = @ptrCast([*]u8, raw_output);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue