1
+ mod call;
1
2
mod short_circuit;
2
3
3
4
use super :: {
4
5
builder:: Builder ,
5
6
cast:: { integer_cast, integer_extend, integer_truncate} ,
6
7
datatype:: lower_type,
7
8
error:: { LowerError , LowerErrorKind } ,
8
- function:: lower_func_head,
9
9
stmts:: lower_stmts,
10
10
} ;
11
11
use crate :: {
@@ -16,11 +16,10 @@ use crate::{
16
16
ast:: { FloatSize , IntegerBits , IntegerRigidity } ,
17
17
ir:: { self , IntegerSign , Literal , OverflowOperator , Value , ValueReference } ,
18
18
lower:: structure:: mono,
19
- resolve:: { PolyCatalog , PolyRecipe , PolyValue } ,
19
+ resolve:: PolyCatalog ,
20
20
} ;
21
- use indexmap :: IndexMap ;
21
+ use call :: { lower_expr_call , lower_expr_poly_call } ;
22
22
use short_circuit:: lower_short_circuiting_binary_operation;
23
- use std:: borrow:: Borrow ;
24
23
25
24
pub fn lower_expr (
26
25
builder : & mut Builder ,
@@ -134,59 +133,7 @@ pub fn lower_expr(
134
133
"String literals are not fully implemented yet, still need ability to lower"
135
134
)
136
135
}
137
- ExprKind :: Call ( call) => {
138
- let callee = asg
139
- . funcs
140
- . get ( call. callee . function )
141
- . expect ( "referenced function to exist" ) ;
142
-
143
- let args = call
144
- . args
145
- . iter ( )
146
- . map ( |arg| lower_expr ( builder, ir_module, & arg. expr , function, asg) )
147
- . collect :: < Result < Box < [ _ ] > , _ > > ( ) ?;
148
-
149
- let variadic_arg_types = call. args [ callee. params . required . len ( ) ..]
150
- . iter ( )
151
- . map ( |arg| lower_type ( ir_module, & builder. unpoly ( & arg. ty ) ?, asg) )
152
- . collect :: < Result < Box < [ _ ] > , _ > > ( ) ?;
153
-
154
- // NOTE: We have to resolve our own polymorphs in the mapping
155
- let mut polymorphs = IndexMap :: < String , PolyValue > :: new ( ) ;
156
-
157
- for ( name, value) in call. callee . recipe . polymorphs . iter ( ) {
158
- match value {
159
- PolyValue :: Type ( ty) => {
160
- polymorphs. insert (
161
- name. clone ( ) ,
162
- PolyValue :: Type (
163
- Borrow :: < asg:: Type > :: borrow ( & builder. unpoly ( ty) ?. 0 ) . clone ( ) ,
164
- ) ,
165
- ) ;
166
- }
167
- PolyValue :: Expr ( _) => {
168
- todo ! ( "compile-time expression parameters are not supported when calling generic functions yet" )
169
- }
170
- PolyValue :: Impl ( impl_ref) => {
171
- polymorphs. insert ( name. clone ( ) , PolyValue :: Impl ( * impl_ref) ) ;
172
- }
173
- }
174
- }
175
-
176
- let recipe = PolyRecipe { polymorphs } ;
177
-
178
- let function = ir_module
179
- . funcs
180
- . translate ( call. callee . function , & recipe, || {
181
- lower_func_head ( ir_module, call. callee . function , & recipe, asg)
182
- } ) ?;
183
-
184
- Ok ( builder. push ( ir:: Instr :: Call ( ir:: Call {
185
- func : function,
186
- args,
187
- unpromoted_variadic_arg_types : variadic_arg_types,
188
- } ) ) )
189
- }
136
+ ExprKind :: Call ( call) => lower_expr_call ( builder, ir_module, expr, function, asg, call) ,
190
137
ExprKind :: Variable ( variable) => {
191
138
let pointer_to_variable = lower_variable_to_value ( variable. key ) ;
192
139
let variable_type = lower_type ( ir_module, & builder. unpoly ( & variable. ty ) ?, asg) ?;
@@ -544,67 +491,7 @@ pub fn lower_expr(
544
491
Ok ( builder. push ( ir:: Instr :: InterpreterSyscall ( * syscall, values) ) )
545
492
}
546
493
ExprKind :: PolyCall ( poly_call) => {
547
- let impl_ref = builder
548
- . poly_recipe ( )
549
- . resolve_impl ( & poly_call. callee . polymorph , expr. source )
550
- . map_err ( LowerError :: from) ?;
551
-
552
- let imp = asg. impls . get ( impl_ref) . expect ( "referenced impl to exist" ) ;
553
-
554
- let func_ref = imp
555
- . body
556
- . get ( & poly_call. callee . member )
557
- . expect ( "expected impl body function referenced by poly call to exist" ) ;
558
-
559
- let callee = asg
560
- . funcs
561
- . get ( * func_ref)
562
- . expect ( "referenced function to exist" ) ;
563
-
564
- let args = poly_call
565
- . args
566
- . iter ( )
567
- . map ( |arg| lower_expr ( builder, ir_module, & arg. expr , function, asg) )
568
- . collect :: < Result < Box < [ _ ] > , _ > > ( ) ?;
569
-
570
- let variadic_arg_types = poly_call. args [ callee. params . required . len ( ) ..]
571
- . iter ( )
572
- . map ( |arg| lower_type ( ir_module, & builder. unpoly ( & arg. ty ) ?, asg) )
573
- . collect :: < Result < Box < [ _ ] > , _ > > ( ) ?;
574
-
575
- // NOTE: We have to resolve our own polymorphs in the mapping
576
- let mut polymorphs = IndexMap :: < String , PolyValue > :: new ( ) ;
577
-
578
- for ( name, value) in poly_call. callee . recipe . polymorphs . iter ( ) {
579
- match value {
580
- PolyValue :: Type ( ty) => {
581
- polymorphs. insert (
582
- name. clone ( ) ,
583
- PolyValue :: Type (
584
- Borrow :: < asg:: Type > :: borrow ( & builder. unpoly ( & ty) ?. 0 ) . clone ( ) ,
585
- ) ,
586
- ) ;
587
- }
588
- PolyValue :: Expr ( _) => {
589
- todo ! ( "compile-time expression parameters are not supported when calling generic functions yet" )
590
- }
591
- PolyValue :: Impl ( impl_ref) => {
592
- polymorphs. insert ( name. clone ( ) , PolyValue :: Impl ( * impl_ref) ) ;
593
- }
594
- }
595
- }
596
-
597
- let recipe = PolyRecipe { polymorphs } ;
598
-
599
- let function = ir_module. funcs . translate ( * func_ref, & recipe, || {
600
- lower_func_head ( ir_module, * func_ref, & recipe, asg)
601
- } ) ?;
602
-
603
- Ok ( builder. push ( ir:: Instr :: Call ( ir:: Call {
604
- func : function,
605
- args,
606
- unpromoted_variadic_arg_types : variadic_arg_types,
607
- } ) ) )
494
+ lower_expr_poly_call ( builder, ir_module, expr, function, asg, poly_call)
608
495
}
609
496
}
610
497
}
0 commit comments