Commit e2fd3b2b1b
Changed files (2)
src/ast_render.cpp
@@ -406,10 +406,6 @@ static void render_node(AstRender *ar, AstNode *node) {
render_node(ar, node->data.fn_def.body);
break;
}
- case NodeTypeFnDecl:
- zig_panic("TODO");
- case NodeTypeParamDecl:
- zig_panic("TODO");
case NodeTypeBlock:
fprintf(ar->f, "{\n");
ar->indent += ar->indent_size;
@@ -463,8 +459,6 @@ static void render_node(AstRender *ar, AstNode *node) {
render_node(ar, node->data.type_decl.child_type);
break;
}
- case NodeTypeErrorValueDecl:
- zig_panic("TODO");
case NodeTypeBinOpExpr:
fprintf(ar->f, "(");
render_node(ar, node->data.bin_op_expr.op1);
@@ -472,8 +466,6 @@ static void render_node(AstRender *ar, AstNode *node) {
render_node(ar, node->data.bin_op_expr.op2);
fprintf(ar->f, ")");
break;
- case NodeTypeUnwrapErrorExpr:
- zig_panic("TODO");
case NodeTypeNumberLiteral:
switch (node->data.number_literal.bignum->kind) {
case BigNumKindInt:
@@ -544,8 +536,6 @@ static void render_node(AstRender *ar, AstNode *node) {
render_node(ar, node->data.array_access_expr.subscript);
fprintf(ar->f, "]");
break;
- case NodeTypeSliceExpr:
- zig_panic("TODO");
case NodeTypeFieldAccessExpr:
{
AstNode *lhs = node->data.field_access_expr.struct_expr;
@@ -555,42 +545,9 @@ static void render_node(AstRender *ar, AstNode *node) {
print_symbol(ar, rhs);
break;
}
- case NodeTypeUse:
- zig_panic("TODO");
- case NodeTypeBoolLiteral:
- zig_panic("TODO");
- case NodeTypeNullLiteral:
- zig_panic("TODO");
case NodeTypeUndefinedLiteral:
- zig_panic("TODO");
- case NodeTypeZeroesLiteral:
- zig_panic("TODO");
- case NodeTypeThisLiteral:
- zig_panic("TODO");
- case NodeTypeIfBoolExpr:
- zig_panic("TODO");
- case NodeTypeIfVarExpr:
- zig_panic("TODO");
- case NodeTypeWhileExpr:
- zig_panic("TODO");
- case NodeTypeForExpr:
- zig_panic("TODO");
- case NodeTypeSwitchExpr:
- zig_panic("TODO");
- case NodeTypeSwitchProng:
- zig_panic("TODO");
- case NodeTypeSwitchRange:
- zig_panic("TODO");
- case NodeTypeLabel:
- zig_panic("TODO");
- case NodeTypeGoto:
- zig_panic("TODO");
- case NodeTypeBreak:
- zig_panic("TODO");
- case NodeTypeContinue:
- zig_panic("TODO");
- case NodeTypeAsmExpr:
- zig_panic("TODO");
+ fprintf(ar->f, "undefined");
+ break;
case NodeTypeContainerDecl:
{
const char *struct_name = buf_ptr(node->data.struct_decl.name);
@@ -612,8 +569,6 @@ static void render_node(AstRender *ar, AstNode *node) {
fprintf(ar->f, "}");
break;
}
- case NodeTypeStructField:
- zig_panic("TODO");
case NodeTypeContainerInitExpr:
fprintf(ar->f, "(");
render_node(ar, node->data.container_init_expr.type);
@@ -621,8 +576,6 @@ static void render_node(AstRender *ar, AstNode *node) {
assert(node->data.container_init_expr.entries.length == 0);
fprintf(ar->f, "}");
break;
- case NodeTypeStructValueField:
- zig_panic("TODO");
case NodeTypeArrayType:
{
fprintf(ar->f, "[");
@@ -645,6 +598,31 @@ static void render_node(AstRender *ar, AstNode *node) {
case NodeTypeVarLiteral:
fprintf(ar->f, "var");
break;
+ case NodeTypeFnDecl:
+ case NodeTypeParamDecl:
+ case NodeTypeErrorValueDecl:
+ case NodeTypeUnwrapErrorExpr:
+ case NodeTypeSliceExpr:
+ case NodeTypeStructField:
+ case NodeTypeStructValueField:
+ case NodeTypeUse:
+ case NodeTypeBoolLiteral:
+ case NodeTypeNullLiteral:
+ case NodeTypeZeroesLiteral:
+ case NodeTypeThisLiteral:
+ case NodeTypeIfBoolExpr:
+ case NodeTypeIfVarExpr:
+ case NodeTypeWhileExpr:
+ case NodeTypeForExpr:
+ case NodeTypeSwitchExpr:
+ case NodeTypeSwitchProng:
+ case NodeTypeSwitchRange:
+ case NodeTypeLabel:
+ case NodeTypeGoto:
+ case NodeTypeBreak:
+ case NodeTypeContinue:
+ case NodeTypeAsmExpr:
+ zig_panic("TODO more ast rendering");
}
}
src/ir.cpp
@@ -1678,6 +1678,11 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, AstNode *node) {
}
}
+static IrInstruction *ir_gen_undefined_literal(IrBuilder *irb, AstNode *node) {
+ assert(node->type == NodeTypeUndefinedLiteral);
+ return ir_build_const_undefined(irb, node);
+}
+
static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, BlockContext *block_context,
LValPurpose lval)
{
@@ -1721,6 +1726,8 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, BlockCont
return ir_gen_array_type(irb, node);
case NodeTypeStringLiteral:
return ir_gen_string_literal(irb, node);
+ case NodeTypeUndefinedLiteral:
+ return ir_gen_undefined_literal(irb, node);
case NodeTypeUnwrapErrorExpr:
case NodeTypeDefer:
case NodeTypeSliceExpr:
@@ -1733,7 +1740,6 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, BlockCont
case NodeTypeSwitchExpr:
case NodeTypeCharLiteral:
case NodeTypeNullLiteral:
- case NodeTypeUndefinedLiteral:
case NodeTypeZeroesLiteral:
case NodeTypeErrorType:
case NodeTypeTypeLiteral:
@@ -2497,7 +2503,9 @@ static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira,
}
static TypeTableEntry *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *const_instruction) {
- const_instruction->base.other = &const_instruction->base;
+ bool depends_on_compile_var = const_instruction->base.static_value.depends_on_compile_var;
+ ConstExprValue *out_val = ir_build_const_from(ira, &const_instruction->base, depends_on_compile_var);
+ *out_val = const_instruction->base.static_value;
return const_instruction->base.type_entry;
}
@@ -3084,9 +3092,9 @@ static TypeTableEntry *ir_analyze_unary_address_of(IrAnalyze *ira, IrInstruction
zig_unreachable();
}
- TypeTableEntry *child_type = value->type_entry;
- TypeTableEntry *canon_child_type = get_underlying_type(child_type);
- switch (canon_child_type->id) {
+ TypeTableEntry *target_type = value->type_entry;
+ TypeTableEntry *canon_target_type = get_underlying_type(target_type);
+ switch (canon_target_type->id) {
case TypeTableEntryIdTypeDecl:
zig_unreachable();
case TypeTableEntryIdInvalid:
@@ -3100,13 +3108,15 @@ static TypeTableEntry *ir_analyze_unary_address_of(IrAnalyze *ira, IrInstruction
case TypeTableEntryIdUnreachable:
case TypeTableEntryIdVar:
add_node_error(ira->codegen, un_op_instruction->base.source_node,
- buf_sprintf("unable to get address of type '%s'", buf_ptr(&child_type->name)));
+ buf_sprintf("unable to get address of type '%s'", buf_ptr(&target_type->name)));
// TODO if type decl, add note pointing to type decl declaration
return ira->codegen->builtin_types.entry_invalid;
case TypeTableEntryIdMetaType:
{
ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base,
value->static_value.depends_on_compile_var);
+ assert(value->static_value.ok);
+ TypeTableEntry *child_type = value->static_value.data.x_type;
out_val->data.x_type = get_pointer_to_type(ira->codegen, child_type, is_const);
return ira->codegen->builtin_types.entry_type;
}