@@ -182,7 +182,7 @@ LLVMValueRef gen_while(compile_t* c, ast_t* ast)
182
182
}
183
183
184
184
// Push the loop status.
185
- codegen_pushloop (c , init_block , post_block );
185
+ codegen_pushloop (c , init_block , post_block , else_block );
186
186
187
187
// init
188
188
// This jumps either to the body or the else clause. This is not evaluated
@@ -300,7 +300,7 @@ LLVMValueRef gen_repeat(compile_t* c, ast_t* ast)
300
300
}
301
301
302
302
// Push the loop status.
303
- codegen_pushloop (c , cond_block , post_block );
303
+ codegen_pushloop (c , cond_block , post_block , else_block );
304
304
305
305
// Body.
306
306
LLVMPositionBuilderAtEnd (c -> builder , body_block );
@@ -383,33 +383,41 @@ LLVMValueRef gen_repeat(compile_t* c, ast_t* ast)
383
383
LLVMValueRef gen_break (compile_t * c , ast_t * ast )
384
384
{
385
385
ast_t * body = ast_child (ast );
386
- ast_t * body_type = ast_type (body );
387
386
388
- // Get the break target.
389
- LLVMBasicBlockRef target = c -> frame -> break_target ;
387
+ LLVMBasicBlockRef target ;
390
388
391
- // Get the phi node.
392
- LLVMValueRef post_phi = LLVMGetFirstInstruction (target );
393
- bool needed = (post_phi != NULL ) && LLVMIsAPHINode (post_phi );
389
+ if (ast_id (body ) == TK_NONE )
390
+ {
391
+ target = c -> frame -> break_novalue_target ;
392
+ } else {
393
+ ast_t * body_type = ast_type (body );
394
394
395
- // Build the break expression .
396
- LLVMValueRef value = gen_expr ( c , body ) ;
395
+ // Get the break target .
396
+ target = c -> frame -> break_target ;
397
397
398
- if (needed )
399
- {
400
- // Cast it to the phi type if we need to.
401
- LLVMTypeRef phi_type = LLVMTypeOf (post_phi );
402
- value = gen_assign_cast (c , phi_type , value , body_type );
403
- }
398
+ // Get the phi node.
399
+ LLVMValueRef post_phi = LLVMGetFirstInstruction (target );
400
+ bool needed = (post_phi != NULL ) && LLVMIsAPHINode (post_phi );
404
401
405
- if ( value == NULL )
406
- return NULL ;
402
+ // Build the break expression.
403
+ LLVMValueRef value = gen_expr ( c , body ) ;
407
404
408
- // Add break value to the post block phi node.
409
- if (needed )
410
- {
411
- LLVMBasicBlockRef insert_block = LLVMGetInsertBlock (c -> builder );
412
- LLVMAddIncoming (post_phi , & value , & insert_block , 1 );
405
+ if (needed )
406
+ {
407
+ // Cast it to the phi type if we need to.
408
+ LLVMTypeRef phi_type = LLVMTypeOf (post_phi );
409
+ value = gen_assign_cast (c , phi_type , value , body_type );
410
+ }
411
+
412
+ if (value == NULL )
413
+ return NULL ;
414
+
415
+ // Add break value to the post block phi node.
416
+ if (needed )
417
+ {
418
+ LLVMBasicBlockRef insert_block = LLVMGetInsertBlock (c -> builder );
419
+ LLVMAddIncoming (post_phi , & value , & insert_block , 1 );
420
+ }
413
421
}
414
422
415
423
// Jump to the break target.
0 commit comments