authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-18 17:50:47-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-18 17:50:47-05:00
logba008fb9d7bb6cbffba57dcde0853a9f7cc2f674
tree671b4e4619d18023613c9cbac1ab354355d7fc0f
parent37b13bf1512d8eed7308a2194c1935d91a33796c

IR: ability to return a container from a function


1 files changed, 18 insertions(+), 7 deletions(-)

src/ir.cpp+18-7
......@@ -3872,7 +3872,11 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope,
38723872 } else {
38733873 FnTableEntry *fn_entry = exec_fn_entry(irb->exec);
38743874 if (fn_entry) {
3875 zig_panic("TODO name the container inside the function");
3875 name = buf_alloc();
3876 buf_append_buf(name, &fn_entry->symbol_name);
3877 buf_appendf(name, "(");
3878 // TODO render args
3879 buf_appendf(name, ")");
38763880 } else {
38773881 name = buf_sprintf("(anonymous %s at %s:%zu:%zu)", container_string(kind),
38783882 buf_ptr(node->owner->path), node->line + 1, node->column + 1);
......@@ -6115,18 +6119,25 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
61156119 }
61166120 }
61176121
6118 auto existing_entry = ira->codegen->generic_table.put_unique(generic_id, impl_fn);
6119 if (existing_entry) {
6120 // throw away all our work and use the existing function
6121 impl_fn = existing_entry->value;
6122 } else {
6123 // finish instantiating the function
6122 {
61246123 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;
61256124 TypeTableEntry *return_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, return_type_node);
61266125 if (return_type->id == TypeTableEntryIdInvalid)
61276126 return ira->codegen->builtin_types.entry_invalid;
61286127 fn_type_id.return_type = return_type;
61296128
6129 if (type_requires_comptime(return_type)) {
6130 // Throw out our work and call the function as if it were inline.
6131 return ir_analyze_fn_call(ira, call_instruction, fn_entry, fn_type, fn_ref, first_arg_ptr, true);
6132 }
6133 }
6134
6135 auto existing_entry = ira->codegen->generic_table.put_unique(generic_id, impl_fn);
6136 if (existing_entry) {
6137 // throw away all our work and use the existing function
6138 impl_fn = existing_entry->value;
6139 } else {
6140 // finish instantiating the function
61306141 impl_fn->type_entry = get_fn_type(ira->codegen, &fn_type_id);
61316142 if (impl_fn->type_entry->id == TypeTableEntryIdInvalid)
61326143 return ira->codegen->builtin_types.entry_invalid;