| ... | ... | @@ -211,8 +211,6 @@ static LLVMValueRef gen_arithmetic_bin_op_expr(CodeGen *g, AstNode *node) { |
| 211 | 211 | LLVMValueRef val2 = gen_expr(g, node->data.bin_op_expr.op2); |
| 212 | 212 | |
| 213 | 213 | switch (node->data.bin_op_expr.bin_op) { |
| 214 | | case BinOpTypeAssign: |
| 215 | | zig_panic("TODO assignment"); |
| 216 | 214 | case BinOpTypeBinOr: |
| 217 | 215 | add_debug_source_node(g, node); |
| 218 | 216 | return LLVMBuildOr(g->builder, val1, val2, ""); |
| ... | ... | @@ -258,6 +256,7 @@ static LLVMValueRef gen_arithmetic_bin_op_expr(CodeGen *g, AstNode *node) { |
| 258 | 256 | case BinOpTypeCmpLessOrEq: |
| 259 | 257 | case BinOpTypeCmpGreaterOrEq: |
| 260 | 258 | case BinOpTypeInvalid: |
| 259 | case BinOpTypeAssign: |
| 261 | 260 | zig_unreachable(); |
| 262 | 261 | } |
| 263 | 262 | zig_unreachable(); |
| ... | ... | @@ -520,18 +519,22 @@ static LLVMValueRef gen_expr(CodeGen *g, AstNode *node) { |
| 520 | 519 | return gen_return_expr(g, node); |
| 521 | 520 | case NodeTypeVariableDeclaration: |
| 522 | 521 | { |
| 523 | | LocalVariableTableEntry *variable = find_local_variable(node->codegen_node->expr_node.block_context, &node->data.variable_declaration.symbol); |
| 524 | | if (variable->is_const) { |
| 525 | | assert(node->data.variable_declaration.expr); |
| 526 | | variable->value_ref = gen_expr(g, node->data.variable_declaration.expr); |
| 522 | LocalVariableTableEntry *variable = find_local_variable( |
| 523 | node->codegen_node->expr_node.block_context, |
| 524 | &node->data.variable_declaration.symbol); |
| 525 | |
| 526 | assert(variable); |
| 527 | assert(variable->is_ptr); |
| 528 | |
| 529 | LLVMValueRef value; |
| 530 | if (node->data.variable_declaration.expr) { |
| 531 | value = gen_expr(g, node->data.variable_declaration.expr); |
| 532 | } else { |
| 533 | value = LLVMConstNull(variable->type->type_ref); |
| 534 | } |
| 535 | if (variable->type == g->builtin_types.entry_void) { |
| 527 | 536 | return nullptr; |
| 528 | 537 | } else { |
| 529 | | LLVMValueRef value; |
| 530 | | if (node->data.variable_declaration.expr) { |
| 531 | | value = gen_expr(g, node->data.variable_declaration.expr); |
| 532 | | } else { |
| 533 | | value = LLVMConstNull(variable->type->type_ref); |
| 534 | | } |
| 535 | 538 | add_debug_source_node(g, node); |
| 536 | 539 | return LLVMBuildStore(g->builder, value, variable->value_ref); |
| 537 | 540 | } |
| ... | ... | @@ -575,11 +578,16 @@ static LLVMValueRef gen_expr(CodeGen *g, AstNode *node) { |
| 575 | 578 | } |
| 576 | 579 | case NodeTypeSymbol: |
| 577 | 580 | { |
| 578 | | LocalVariableTableEntry *variable = find_local_variable(node->codegen_node->expr_node.block_context, &node->data.symbol); |
| 579 | | if (variable->is_const) { |
| 580 | | return variable->value_ref; |
| 581 | | } else { |
| 581 | LocalVariableTableEntry *variable = find_local_variable( |
| 582 | node->codegen_node->expr_node.block_context, |
| 583 | &node->data.symbol); |
| 584 | assert(variable); |
| 585 | if (variable->type == g->builtin_types.entry_void) { |
| 586 | return nullptr; |
| 587 | } else if (variable->is_ptr) { |
| 582 | 588 | return LLVMBuildLoad(g->builder, variable->value_ref, ""); |
| 589 | } else { |
| 590 | return variable->value_ref; |
| 583 | 591 | } |
| 584 | 592 | } |
| 585 | 593 | case NodeTypeBlock: |
| ... | ... | @@ -742,6 +750,11 @@ static void do_code_gen(CodeGen *g) { |
| 742 | 750 | for (int i = 0; i < codegen_fn_def->all_block_contexts.length; i += 1) { |
| 743 | 751 | BlockContext *block_context = codegen_fn_def->all_block_contexts.at(i); |
| 744 | 752 | |
| 753 | // skip the block context for function parameters |
| 754 | if (block_context->node->type == NodeTypeFnDef) { |
| 755 | continue; |
| 756 | } |
| 757 | |
| 745 | 758 | auto it = block_context->variable_table.entry_iterator(); |
| 746 | 759 | for (;;) { |
| 747 | 760 | auto *entry = it.next(); |
| ... | ... | @@ -749,10 +762,11 @@ static void do_code_gen(CodeGen *g) { |
| 749 | 762 | break; |
| 750 | 763 | |
| 751 | 764 | LocalVariableTableEntry *var = entry->value; |
| 752 | | if (!var->is_const) { |
| 753 | | add_debug_source_node(g, var->decl_node); |
| 754 | | var->value_ref = LLVMBuildAlloca(g->builder, var->type->type_ref, buf_ptr(&var->name)); |
| 755 | | } |
| 765 | if (var->type == g->builtin_types.entry_void) |
| 766 | continue; |
| 767 | |
| 768 | add_debug_source_node(g, var->decl_node); |
| 769 | var->value_ref = LLVMBuildAlloca(g->builder, var->type->type_ref, buf_ptr(&var->name)); |
| 756 | 770 | } |
| 757 | 771 | } |
| 758 | 772 | |