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