mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 00:01:16 +00:00
Code gen toplevel module functions
This commit is contained in:
parent
1a2367c8aa
commit
ee31eac0c5
7 changed files with 183 additions and 141 deletions
|
@ -16,7 +16,7 @@ use roc_gen::llvm::build::{
|
|||
use roc_gen::llvm::convert::basic_type_from_layout;
|
||||
use roc_load::file::{LoadedModule, LoadingProblem};
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_mono::expr::{Expr, PartialProc, Procs};
|
||||
use roc_mono::expr::{Env, Expr, PartialProc, Procs};
|
||||
use roc_mono::layout::Layout;
|
||||
use std::time::SystemTime;
|
||||
|
||||
|
@ -354,6 +354,18 @@ fn gen(
|
|||
ptr_bytes,
|
||||
};
|
||||
let mut procs = Procs::default();
|
||||
let mut mono_problems = std::vec::Vec::new();
|
||||
let mut ident_ids = env.interns.all_ident_ids.remove(&home).unwrap();
|
||||
let mut mono_env = Env {
|
||||
arena,
|
||||
subs: &mut subs,
|
||||
problems: &mut mono_problems,
|
||||
home,
|
||||
ident_ids: &mut ident_ids,
|
||||
pointer_size: ptr_bytes,
|
||||
symbol_counter: 0,
|
||||
jump_counter: arena.alloc(0),
|
||||
};
|
||||
|
||||
// TODO remove this
|
||||
decls_by_id.insert(loaded.module_id, home_decls);
|
||||
|
@ -368,20 +380,31 @@ fn gen(
|
|||
match decl {
|
||||
Declare(def) => match def.loc_pattern.value {
|
||||
Identifier(symbol) => {
|
||||
let proc = match def.loc_expr.value {
|
||||
Closure(_, _, _, _, _) => {
|
||||
todo!("TODO register PartialProc for Closure");
|
||||
}
|
||||
body => PartialProc {
|
||||
annotation: def.expr_var,
|
||||
// This is a 0-arity thunk, so it has no arguments.
|
||||
patterns: bumpalo::collections::Vec::new_in(arena),
|
||||
body,
|
||||
},
|
||||
};
|
||||
match def.loc_expr.value {
|
||||
Closure(annotation, _, _, loc_args, boxed_body) => {
|
||||
let (loc_body, ret_var) = *boxed_body;
|
||||
|
||||
procs.user_defined.insert(symbol, proc);
|
||||
procs.module_decls.insert(symbol);
|
||||
procs.insert_closure(
|
||||
&mut mono_env,
|
||||
Some(symbol),
|
||||
annotation,
|
||||
loc_args,
|
||||
loc_body,
|
||||
ret_var,
|
||||
);
|
||||
}
|
||||
body => {
|
||||
let proc = PartialProc {
|
||||
annotation: def.expr_var,
|
||||
// This is a 0-arity thunk, so it has no arguments.
|
||||
patterns: bumpalo::collections::Vec::new_in(arena),
|
||||
body,
|
||||
};
|
||||
|
||||
procs.user_defined.insert(symbol, proc);
|
||||
procs.module_thunks.insert(symbol);
|
||||
}
|
||||
};
|
||||
}
|
||||
other => {
|
||||
todo!("TODO gracefully handle Declare({:?})", other);
|
||||
|
@ -397,20 +420,8 @@ fn gen(
|
|||
}
|
||||
}
|
||||
|
||||
let mut ident_ids = env.interns.all_ident_ids.remove(&home).unwrap();
|
||||
|
||||
// Populate Procs further and get the low-level Expr from the canonical Expr
|
||||
let mut mono_problems = std::vec::Vec::new();
|
||||
let main_body = Expr::new(
|
||||
&arena,
|
||||
&mut subs,
|
||||
&mut mono_problems,
|
||||
loc_expr.value,
|
||||
&mut procs,
|
||||
home,
|
||||
&mut ident_ids,
|
||||
ptr_bytes,
|
||||
);
|
||||
let main_body = Expr::new(&mut mono_env, loc_expr.value, &mut procs);
|
||||
|
||||
// Put this module's ident_ids back in the interns, so we can use them in env.
|
||||
env.interns.all_ident_ids.insert(home, ident_ids);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue