@@ -28,7 +28,7 @@ impl<'src> AST<'src> for IfAST<'src> {
28
28
fn nodes ( & self ) -> usize {
29
29
self . cond . nodes ( ) + self . if_true . nodes ( ) + self . if_false . nodes ( ) + 1
30
30
}
31
- fn codegen < ' ctx > (
31
+ fn codegen_impl < ' ctx > (
32
32
& self ,
33
33
ctx : & CompCtx < ' src , ' ctx > ,
34
34
) -> ( Value < ' src , ' ctx > , Vec < CobaltError < ' src > > ) {
@@ -38,19 +38,15 @@ impl<'src> AST<'src> for IfAST<'src> {
38
38
let mut errs = vec ! [ ] ;
39
39
let ( cond, mut es) = self . cond . codegen ( ctx) ;
40
40
errs. append ( & mut es) ;
41
- let cv = ops:: expl_convert (
42
- self . cond . loc ( ) ,
43
- ( cond, None ) ,
44
- ( Type :: Int ( 1 , false ) , None ) ,
45
- ctx,
46
- )
47
- . unwrap_or_else ( |e| {
48
- errs. push ( e) ;
49
- Value :: compiled (
50
- ctx. context . bool_type ( ) . const_int ( 0 , false ) . into ( ) ,
51
- Type :: Int ( 1 , false ) ,
52
- )
53
- } ) ;
41
+ let cv = cond
42
+ . impl_convert ( ( types:: Int :: bool ( ) , None ) , ctx)
43
+ . unwrap_or_else ( |e| {
44
+ errs. push ( e) ;
45
+ Value :: compiled (
46
+ ctx. context . bool_type ( ) . const_int ( 0 , false ) . into ( ) ,
47
+ types:: Int :: bool ( ) ,
48
+ )
49
+ } ) ;
54
50
if let Some ( inkwell:: values:: BasicValueEnum :: IntValue ( v) ) = cv. value ( ctx) {
55
51
(
56
52
{
@@ -67,31 +63,20 @@ impl<'src> AST<'src> for IfAST<'src> {
67
63
let if_true = self . if_true . codegen_errs ( ctx, & mut errs) ;
68
64
ctx. builder . position_at_end ( ifb) ;
69
65
let if_false = self . if_false . codegen_errs ( ctx, & mut errs) ;
70
- if let Some ( ty) = ops:: common ( & if_true. data_type , & if_false. data_type , ctx)
71
- {
66
+ if let Some ( ty) = if_true. data_type . common ( if_false. data_type , ctx) {
72
67
ctx. builder . position_at_end ( itb) ;
73
- let if_true = ops:: impl_convert (
74
- self . if_true . loc ( ) ,
75
- ( if_true, None ) ,
76
- ( ty. clone ( ) , None ) ,
77
- ctx,
78
- )
79
- . unwrap_or_else ( |e| {
80
- errs. push ( e) ;
81
- Value :: error ( )
82
- } ) ;
68
+ let if_true =
69
+ if_true. impl_convert ( ( ty, None ) , ctx) . unwrap_or_else ( |e| {
70
+ errs. push ( e) ;
71
+ Value :: error ( ) . with_loc ( self . if_true . loc ( ) )
72
+ } ) ;
83
73
ctx. builder . build_unconditional_branch ( mb) ;
84
74
ctx. builder . position_at_end ( ifb) ;
85
- let if_false = ops:: impl_convert (
86
- self . if_false . loc ( ) ,
87
- ( if_false, None ) ,
88
- ( ty. clone ( ) , None ) ,
89
- ctx,
90
- )
91
- . unwrap_or_else ( |e| {
92
- errs. push ( e) ;
93
- Value :: error ( )
94
- } ) ;
75
+ let if_false =
76
+ if_false. impl_convert ( ( ty, None ) , ctx) . unwrap_or_else ( |e| {
77
+ errs. push ( e) ;
78
+ Value :: error ( ) . with_loc ( self . if_false . loc ( ) )
79
+ } ) ;
95
80
ctx. builder . build_unconditional_branch ( mb) ;
96
81
ctx. builder . position_at_end ( mb) ;
97
82
Value :: new (
@@ -166,7 +151,7 @@ impl<'src> AST<'src> for WhileAST<'src> {
166
151
fn nodes ( & self ) -> usize {
167
152
self . cond . nodes ( ) + self . body . nodes ( ) + 1
168
153
}
169
- fn codegen < ' ctx > (
154
+ fn codegen_impl < ' ctx > (
170
155
& self ,
171
156
ctx : & CompCtx < ' src , ' ctx > ,
172
157
) -> ( Value < ' src , ' ctx > , Vec < CobaltError < ' src > > ) {
@@ -184,17 +169,17 @@ impl<'src> AST<'src> for WhileAST<'src> {
184
169
ctx. builder . build_unconditional_branch ( cond) ;
185
170
ctx. builder . position_at_end ( cond) ;
186
171
let ( c, mut errs) = self . cond . codegen ( ctx) ;
187
- let val =
188
- ops :: expl_convert ( self . cond . loc ( ) , ( c , None ) , ( Type :: Int ( 1 , false ) , None ) , ctx)
189
- . unwrap_or_else ( |e| {
190
- errs. push ( e) ;
191
- Value :: compiled (
192
- ctx. context . bool_type ( ) . const_int ( 0 , false ) . into ( ) ,
193
- Type :: Int ( 1 , false ) ,
194
- )
195
- } )
196
- . into_value ( ctx)
197
- . unwrap_or ( ctx. context . bool_type ( ) . const_int ( 0 , false ) . into ( ) ) ;
172
+ let val = c
173
+ . expl_convert ( ( types :: Int :: bool ( ) , None ) , ctx)
174
+ . unwrap_or_else ( |e| {
175
+ errs. push ( e) ;
176
+ Value :: compiled (
177
+ ctx. context . bool_type ( ) . const_int ( 0 , false ) . into ( ) ,
178
+ types :: Int :: bool ( ) ,
179
+ )
180
+ } )
181
+ . value ( ctx)
182
+ . unwrap_or ( ctx. context . bool_type ( ) . const_int ( 0 , false ) . into ( ) ) ;
198
183
ctx. builder
199
184
. build_conditional_branch ( val. into_int_value ( ) , body, exit) ;
200
185
ctx. builder . position_at_end ( body) ;
0 commit comments