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) {
406406 render_node(ar, node->data.fn_def.body);
407407 break;
408408 }
409 case NodeTypeFnDecl:
410 zig_panic("TODO");
411 case NodeTypeParamDecl:
412 zig_panic("TODO");
413409 case NodeTypeBlock:
414410 fprintf(ar->f, "{\n");
415411 ar->indent += ar->indent_size;
......@@ -463,8 +459,6 @@ static void render_node(AstRender *ar, AstNode *node) {
463459 render_node(ar, node->data.type_decl.child_type);
464460 break;
465461 }
466 case NodeTypeErrorValueDecl:
467 zig_panic("TODO");
468462 case NodeTypeBinOpExpr:
469463 fprintf(ar->f, "(");
470464 render_node(ar, node->data.bin_op_expr.op1);
......@@ -472,8 +466,6 @@ static void render_node(AstRender *ar, AstNode *node) {
472466 render_node(ar, node->data.bin_op_expr.op2);
473467 fprintf(ar->f, ")");
474468 break;
475 case NodeTypeUnwrapErrorExpr:
476 zig_panic("TODO");
477469 case NodeTypeNumberLiteral:
478470 switch (node->data.number_literal.bignum->kind) {
479471 case BigNumKindInt:
......@@ -544,8 +536,6 @@ static void render_node(AstRender *ar, AstNode *node) {
544536 render_node(ar, node->data.array_access_expr.subscript);
545537 fprintf(ar->f, "]");
546538 break;
547 case NodeTypeSliceExpr:
548 zig_panic("TODO");
549539 case NodeTypeFieldAccessExpr:
550540 {
551541 AstNode *lhs = node->data.field_access_expr.struct_expr;
......@@ -555,42 +545,9 @@ static void render_node(AstRender *ar, AstNode *node) {
555545 print_symbol(ar, rhs);
556546 break;
557547 }
558 case NodeTypeUse:
559 zig_panic("TODO");
560 case NodeTypeBoolLiteral:
561 zig_panic("TODO");
562 case NodeTypeNullLiteral:
563 zig_panic("TODO");
564548 case NodeTypeUndefinedLiteral:
565 zig_panic("TODO");
566 case NodeTypeZeroesLiteral:
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");
549 fprintf(ar->f, "undefined");
550 break;
594551 case NodeTypeContainerDecl:
595552 {
596553 const char *struct_name = buf_ptr(node->data.struct_decl.name);
......@@ -612,8 +569,6 @@ static void render_node(AstRender *ar, AstNode *node) {
612569 fprintf(ar->f, "}");
613570 break;
614571 }
615 case NodeTypeStructField:
616 zig_panic("TODO");
617572 case NodeTypeContainerInitExpr:
618573 fprintf(ar->f, "(");
619574 render_node(ar, node->data.container_init_expr.type);
......@@ -621,8 +576,6 @@ static void render_node(AstRender *ar, AstNode *node) {
621576 assert(node->data.container_init_expr.entries.length == 0);
622577 fprintf(ar->f, "}");
623578 break;
624 case NodeTypeStructValueField:
625 zig_panic("TODO");
626579 case NodeTypeArrayType:
627580 {
628581 fprintf(ar->f, "[");
......@@ -645,6 +598,31 @@ static void render_node(AstRender *ar, AstNode *node) {
645598 case NodeTypeVarLiteral:
646599 fprintf(ar->f, "var");
647600 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");
648626 }
649627}
650628
src/ir.cpp+16-6
......@@ -1678,6 +1678,11 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, AstNode *node) {
16781678 }
16791679}
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
16811686static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, BlockContext *block_context,
16821687 LValPurpose lval)
16831688{
......@@ -1721,6 +1726,8 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, BlockCont
17211726 return ir_gen_array_type(irb, node);
17221727 case NodeTypeStringLiteral:
17231728 return ir_gen_string_literal(irb, node);
1729 case NodeTypeUndefinedLiteral:
1730 return ir_gen_undefined_literal(irb, node);
17241731 case NodeTypeUnwrapErrorExpr:
17251732 case NodeTypeDefer:
17261733 case NodeTypeSliceExpr:
......@@ -1733,7 +1740,6 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, BlockCont
17331740 case NodeTypeSwitchExpr:
17341741 case NodeTypeCharLiteral:
17351742 case NodeTypeNullLiteral:
1736 case NodeTypeUndefinedLiteral:
17371743 case NodeTypeZeroesLiteral:
17381744 case NodeTypeErrorType:
17391745 case NodeTypeTypeLiteral:
......@@ -2497,7 +2503,9 @@ static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira,
24972503}
24982504
24992505static 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;
25012509 return const_instruction->base.type_entry;
25022510}
25032511
......@@ -3084,9 +3092,9 @@ static TypeTableEntry *ir_analyze_unary_address_of(IrAnalyze *ira, IrInstruction
30843092 zig_unreachable();
30853093 }
30863094
3087 TypeTableEntry *child_type = value->type_entry;
3088 TypeTableEntry *canon_child_type = get_underlying_type(child_type);
3089 switch (canon_child_type->id) {
3095 TypeTableEntry *target_type = value->type_entry;
3096 TypeTableEntry *canon_target_type = get_underlying_type(target_type);
3097 switch (canon_target_type->id) {
30903098 case TypeTableEntryIdTypeDecl:
30913099 zig_unreachable();
30923100 case TypeTableEntryIdInvalid:
......@@ -3100,13 +3108,15 @@ static TypeTableEntry *ir_analyze_unary_address_of(IrAnalyze *ira, IrInstruction
31003108 case TypeTableEntryIdUnreachable:
31013109 case TypeTableEntryIdVar:
31023110 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)));
31043112 // TODO if type decl, add note pointing to type decl declaration
31053113 return ira->codegen->builtin_types.entry_invalid;
31063114 case TypeTableEntryIdMetaType:
31073115 {
31083116 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base,
31093117 value->static_value.depends_on_compile_var);
3118 assert(value->static_value.ok);
3119 TypeTableEntry *child_type = value->static_value.data.x_type;
31103120 out_val->data.x_type = get_pointer_to_type(ira->codegen, child_type, is_const);
31113121 return ira->codegen->builtin_types.entry_type;
31123122 }