@@ -4,8 +4,10 @@ use astoir_hir::{
44 ctx:: HIRContext ,
55 nodes:: { HIRNode , HIRNodeKind } ,
66} ;
7- use astoir_mir:: ctx:: MIRContext ;
8- use compiler_typing:: { SizedType , raw:: RawType , structs:: LoweredStructTypeContainer , tree:: Type } ;
7+ use astoir_mir:: { ctx:: MIRContext , funcs:: MIRFunction } ;
8+ use compiler_typing:: {
9+ SizedType , TypedGlobalScopeEntry , raw:: RawType , structs:: LoweredStructTypeContainer , tree:: Type ,
10+ } ;
911use compiler_utils:: utils:: indexed:: IndexStorage ;
1012use diagnostics:: { DiagnosticResult , unsure_panic} ;
1113
@@ -53,12 +55,49 @@ pub fn lower_hir(ctx: HIRContext) -> DiagnosticResult<MIRContext> {
5355 block_introduction_var_queue : vec ! [ ] ,
5456 } ;
5557
56- let declarations = lowering_ctx. hir_ctx . function_declarations . clone ( ) ;
58+ for entry in lowering_ctx. hir_ctx . global_scope . scope . entries . clone ( ) {
59+ match entry. entry_type {
60+ TypedGlobalScopeEntry :: Function {
61+ descriptor_ind : _,
62+ impl_ind,
63+ } => {
64+ let node = lowering_ctx. hir_ctx . global_scope . implementations [ impl_ind]
65+ . 1
66+ . clone ( ) ;
67+
68+ lower_hir_top_level ( node, & mut lowering_ctx) ?;
69+ }
5770
58- for decl in declarations {
59- if let Some ( node) = decl {
60- lower_hir_top_level ( node, & mut lowering_ctx) ?;
61- }
71+ TypedGlobalScopeEntry :: ImplLessFunction ( descriptor_ind) => {
72+ let descriptor =
73+ lowering_ctx. hir_ctx . global_scope . descriptors [ descriptor_ind] . clone ( ) ;
74+
75+ let name = descriptor. 2 . clone ( ) ;
76+
77+ let mut args = vec ! [ ] ;
78+
79+ for argument in descriptor. 1 {
80+ args. push ( lower_hir_type ( & mut lowering_ctx, argument. 1 ) ?) ;
81+ }
82+
83+ let ret_type;
84+
85+ if descriptor. 0 . is_some ( ) {
86+ ret_type = Some ( lower_hir_type (
87+ & mut lowering_ctx,
88+ descriptor. 0 . clone ( ) . unwrap ( ) ,
89+ ) ?)
90+ } else {
91+ ret_type = None
92+ }
93+
94+ let func = MIRFunction :: new ( name, args, ret_type, false , & mut lowering_ctx. mir_ctx ) ;
95+
96+ lowering_ctx. mir_ctx . append_function ( func) ;
97+ }
98+
99+ _ => todo ! ( "Add support for remaining nodes" ) ,
100+ } ;
62101 }
63102
64103 return Ok ( lowering_ctx. mir_ctx ) ;
0 commit comments