authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-11-13 13:42:04-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-11-13 13:42:04-05:00
loge2fd3b2b1b512197e100af0a6b6e5bd96707d792
tree1815c217144c4ad8760b4acfc1a391d99aa12aba
parentd4f2394dcf8e5fc9e5be26c3022f8ce435b722a8

IR: fix prefix op eval setting wrong type


2 files changed, 43 insertions(+), 55 deletions(-)

src/ast_render.cpp+27-49
...@@ -406,10 +406,6 @@ static void render_node(AstRender *ar, AstNode *node) {...@@ -406,10 +406,6 @@ static void render_node(AstRender *ar, AstNode *node) {
406 render_node(ar, node->data.fn_def.body);406 render_node(ar, node->data.fn_def.body);
407 break;407 break;
408 }408 }
409 case NodeTypeFnDecl:
410 zig_panic("TODO");
411 case NodeTypeParamDecl:
412 zig_panic("TODO");
413 case NodeTypeBlock:409 case NodeTypeBlock:
414 fprintf(ar->f, "{\n");410 fprintf(ar->f, "{\n");
415 ar->indent += ar->indent_size;411 ar->indent += ar->indent_size;
...@@ -463,8 +459,6 @@ static void render_node(AstRender *ar, AstNode *node) {...@@ -463,8 +459,6 @@ static void render_node(AstRender *ar, AstNode *node) {
463 render_node(ar, node->data.type_decl.child_type);459 render_node(ar, node->data.type_decl.child_type);
464 break;460 break;
465 }461 }
466 case NodeTypeErrorValueDecl:
467 zig_panic("TODO");
468 case NodeTypeBinOpExpr:462 case NodeTypeBinOpExpr:
469 fprintf(ar->f, "(");463 fprintf(ar->f, "(");
470 render_node(ar, node->data.bin_op_expr.op1);464 render_node(ar, node->data.bin_op_expr.op1);
...@@ -472,8 +466,6 @@ static void render_node(AstRender *ar, AstNode *node) {...@@ -472,8 +466,6 @@ static void render_node(AstRender *ar, AstNode *node) {
472 render_node(ar, node->data.bin_op_expr.op2);466 render_node(ar, node->data.bin_op_expr.op2);
473 fprintf(ar->f, ")");467 fprintf(ar->f, ")");
474 break;468 break;
475 case NodeTypeUnwrapErrorExpr:
476 zig_panic("TODO");
477 case NodeTypeNumberLiteral:469 case NodeTypeNumberLiteral:
478 switch (node->data.number_literal.bignum->kind) {470 switch (node->data.number_literal.bignum->kind) {
479 case BigNumKindInt:471 case BigNumKindInt:
...@@ -544,8 +536,6 @@ static void render_node(AstRender *ar, AstNode *node) {...@@ -544,8 +536,6 @@ static void render_node(AstRender *ar, AstNode *node) {
544 render_node(ar, node->data.array_access_expr.subscript);536 render_node(ar, node->data.array_access_expr.subscript);
545 fprintf(ar->f, "]");537 fprintf(ar->f, "]");
546 break;538 break;
547 case NodeTypeSliceExpr:
548 zig_panic("TODO");
549 case NodeTypeFieldAccessExpr:539 case NodeTypeFieldAccessExpr:
550 {540 {
551 AstNode *lhs = node->data.field_access_expr.struct_expr;541 AstNode *lhs = node->data.field_access_expr.struct_expr;
...@@ -555,42 +545,9 @@ static void render_node(AstRender *ar, AstNode *node) {...@@ -555,42 +545,9 @@ static void render_node(AstRender *ar, AstNode *node) {
555 print_symbol(ar, rhs);545 print_symbol(ar, rhs);
556 break;546 break;
557 }547 }
558 case NodeTypeUse:
559 zig_panic("TODO");
560 case NodeTypeBoolLiteral:
561 zig_panic("TODO");
562 case NodeTypeNullLiteral:
563 zig_panic("TODO");
564 case NodeTypeUndefinedLiteral:548 case NodeTypeUndefinedLiteral:
565 zig_panic("TODO");549 fprintf(ar->f, "undefined");
566 case NodeTypeZeroesLiteral:550 break;
567 zig_panic("TODO");
568 case NodeTypeThisLiteral:
569 zig_panic("TODO");
570 case NodeTypeIfBoolExpr:
571 zig_panic("TODO");
572 case NodeTypeIfVarExpr:
573 zig_panic("TODO");
574 case NodeTypeWhileExpr:
575 zig_panic("TODO");
576 case NodeTypeForExpr:
577 zig_panic("TODO");
578 case NodeTypeSwitchExpr:
579 zig_panic("TODO");
580 case NodeTypeSwitchProng:
581 zig_panic("TODO");
582 case NodeTypeSwitchRange:
583 zig_panic("TODO");
584 case NodeTypeLabel:
585 zig_panic("TODO");
586 case NodeTypeGoto:
587 zig_panic("TODO");
588 case NodeTypeBreak:
589 zig_panic("TODO");
590 case NodeTypeContinue:
591 zig_panic("TODO");
592 case NodeTypeAsmExpr:
593 zig_panic("TODO");
594 case NodeTypeContainerDecl:551 case NodeTypeContainerDecl:
595 {552 {
596 const char *struct_name = buf_ptr(node->data.struct_decl.name);553 const char *struct_name = buf_ptr(node->data.struct_decl.name);
...@@ -612,8 +569,6 @@ static void render_node(AstRender *ar, AstNode *node) {...@@ -612,8 +569,6 @@ static void render_node(AstRender *ar, AstNode *node) {
612 fprintf(ar->f, "}");569 fprintf(ar->f, "}");
613 break;570 break;
614 }571 }
615 case NodeTypeStructField:
616 zig_panic("TODO");
617 case NodeTypeContainerInitExpr:572 case NodeTypeContainerInitExpr:
618 fprintf(ar->f, "(");573 fprintf(ar->f, "(");
619 render_node(ar, node->data.container_init_expr.type);574 render_node(ar, node->data.container_init_expr.type);
...@@ -621,8 +576,6 @@ static void render_node(AstRender *ar, AstNode *node) {...@@ -621,8 +576,6 @@ static void render_node(AstRender *ar, AstNode *node) {
621 assert(node->data.container_init_expr.entries.length == 0);576 assert(node->data.container_init_expr.entries.length == 0);
622 fprintf(ar->f, "}");577 fprintf(ar->f, "}");
623 break;578 break;
624 case NodeTypeStructValueField:
625 zig_panic("TODO");
626 case NodeTypeArrayType:579 case NodeTypeArrayType:
627 {580 {
628 fprintf(ar->f, "[");581 fprintf(ar->f, "[");
...@@ -645,6 +598,31 @@ static void render_node(AstRender *ar, AstNode *node) {...@@ -645,6 +598,31 @@ static void render_node(AstRender *ar, AstNode *node) {
645 case NodeTypeVarLiteral:598 case NodeTypeVarLiteral:
646 fprintf(ar->f, "var");599 fprintf(ar->f, "var");
647 break;600 break;
601 case NodeTypeFnDecl:
602 case NodeTypeParamDecl:
603 case NodeTypeErrorValueDecl:
604 case NodeTypeUnwrapErrorExpr:
605 case NodeTypeSliceExpr:
606 case NodeTypeStructField:
607 case NodeTypeStructValueField:
608 case NodeTypeUse:
609 case NodeTypeBoolLiteral:
610 case NodeTypeNullLiteral:
611 case NodeTypeZeroesLiteral:
612 case NodeTypeThisLiteral:
613 case NodeTypeIfBoolExpr:
614 case NodeTypeIfVarExpr:
615 case NodeTypeWhileExpr:
616 case NodeTypeForExpr:
617 case NodeTypeSwitchExpr:
618 case NodeTypeSwitchProng:
619 case NodeTypeSwitchRange:
620 case NodeTypeLabel:
621 case NodeTypeGoto:
622 case NodeTypeBreak:
623 case NodeTypeContinue:
624 case NodeTypeAsmExpr:
625 zig_panic("TODO more ast rendering");
648 }626 }
649}627}
650628
src/ir.cpp+16-6
...@@ -1678,6 +1678,11 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, AstNode *node) {...@@ -1678,6 +1678,11 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, AstNode *node) {
1678 }1678 }
1679}1679}
16801680
1681static IrInstruction *ir_gen_undefined_literal(IrBuilder *irb, AstNode *node) {
1682 assert(node->type == NodeTypeUndefinedLiteral);
1683 return ir_build_const_undefined(irb, node);
1684}
1685
1681static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, BlockContext *block_context,1686static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, BlockContext *block_context,
1682 LValPurpose lval)1687 LValPurpose lval)
1683{1688{
...@@ -1721,6 +1726,8 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, BlockCont...@@ -1721,6 +1726,8 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, BlockCont
1721 return ir_gen_array_type(irb, node);1726 return ir_gen_array_type(irb, node);
1722 case NodeTypeStringLiteral:1727 case NodeTypeStringLiteral:
1723 return ir_gen_string_literal(irb, node);1728 return ir_gen_string_literal(irb, node);
1729 case NodeTypeUndefinedLiteral:
1730 return ir_gen_undefined_literal(irb, node);
1724 case NodeTypeUnwrapErrorExpr:1731 case NodeTypeUnwrapErrorExpr:
1725 case NodeTypeDefer:1732 case NodeTypeDefer:
1726 case NodeTypeSliceExpr:1733 case NodeTypeSliceExpr:
...@@ -1733,7 +1740,6 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, BlockCont...@@ -1733,7 +1740,6 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, BlockCont
1733 case NodeTypeSwitchExpr:1740 case NodeTypeSwitchExpr:
1734 case NodeTypeCharLiteral:1741 case NodeTypeCharLiteral:
1735 case NodeTypeNullLiteral:1742 case NodeTypeNullLiteral:
1736 case NodeTypeUndefinedLiteral:
1737 case NodeTypeZeroesLiteral:1743 case NodeTypeZeroesLiteral:
1738 case NodeTypeErrorType:1744 case NodeTypeErrorType:
1739 case NodeTypeTypeLiteral:1745 case NodeTypeTypeLiteral:
...@@ -2497,7 +2503,9 @@ static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira,...@@ -2497,7 +2503,9 @@ static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira,
2497}2503}
24982504
2499static TypeTableEntry *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *const_instruction) {2505static TypeTableEntry *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *const_instruction) {
2500 const_instruction->base.other = &const_instruction->base;2506 bool depends_on_compile_var = const_instruction->base.static_value.depends_on_compile_var;
2507 ConstExprValue *out_val = ir_build_const_from(ira, &const_instruction->base, depends_on_compile_var);
2508 *out_val = const_instruction->base.static_value;
2501 return const_instruction->base.type_entry;2509 return const_instruction->base.type_entry;
2502}2510}
25032511
...@@ -3084,9 +3092,9 @@ static TypeTableEntry *ir_analyze_unary_address_of(IrAnalyze *ira, IrInstruction...@@ -3084,9 +3092,9 @@ static TypeTableEntry *ir_analyze_unary_address_of(IrAnalyze *ira, IrInstruction
3084 zig_unreachable();3092 zig_unreachable();
3085 }3093 }
30863094
3087 TypeTableEntry *child_type = value->type_entry;3095 TypeTableEntry *target_type = value->type_entry;
3088 TypeTableEntry *canon_child_type = get_underlying_type(child_type);3096 TypeTableEntry *canon_target_type = get_underlying_type(target_type);
3089 switch (canon_child_type->id) {3097 switch (canon_target_type->id) {
3090 case TypeTableEntryIdTypeDecl:3098 case TypeTableEntryIdTypeDecl:
3091 zig_unreachable();3099 zig_unreachable();
3092 case TypeTableEntryIdInvalid:3100 case TypeTableEntryIdInvalid:
...@@ -3100,13 +3108,15 @@ static TypeTableEntry *ir_analyze_unary_address_of(IrAnalyze *ira, IrInstruction...@@ -3100,13 +3108,15 @@ static TypeTableEntry *ir_analyze_unary_address_of(IrAnalyze *ira, IrInstruction
3100 case TypeTableEntryIdUnreachable:3108 case TypeTableEntryIdUnreachable:
3101 case TypeTableEntryIdVar:3109 case TypeTableEntryIdVar:
3102 add_node_error(ira->codegen, un_op_instruction->base.source_node,3110 add_node_error(ira->codegen, un_op_instruction->base.source_node,
3103 buf_sprintf("unable to get address of type '%s'", buf_ptr(&child_type->name)));3111 buf_sprintf("unable to get address of type '%s'", buf_ptr(&target_type->name)));
3104 // TODO if type decl, add note pointing to type decl declaration3112 // TODO if type decl, add note pointing to type decl declaration
3105 return ira->codegen->builtin_types.entry_invalid;3113 return ira->codegen->builtin_types.entry_invalid;
3106 case TypeTableEntryIdMetaType:3114 case TypeTableEntryIdMetaType:
3107 {3115 {
3108 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base,3116 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base,
3109 value->static_value.depends_on_compile_var);3117 value->static_value.depends_on_compile_var);
3118 assert(value->static_value.ok);
3119 TypeTableEntry *child_type = value->static_value.data.x_type;
3110 out_val->data.x_type = get_pointer_to_type(ira->codegen, child_type, is_const);3120 out_val->data.x_type = get_pointer_to_type(ira->codegen, child_type, is_const);
3111 return ira->codegen->builtin_types.entry_type;3121 return ira->codegen->builtin_types.entry_type;
3112 }3122 }