| ... | ... | @@ -15911,6 +15911,10 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop |
| 15911 | 15911 | FnTableEntry *fn_entry = ((TldFn *)curr_entry->value)->fn_entry; |
| 15912 | 15912 | assert(!fn_entry->is_test); |
| 15913 | 15913 | |
| 15914 | analyze_fn_body(ira->codegen, fn_entry); |
| 15915 | if (fn_entry->anal_state == FnAnalStateInvalid) |
| 15916 | return; |
| 15917 | |
| 15914 | 15918 | AstNodeFnProto *fn_node = (AstNodeFnProto *)(fn_entry->proto_node); |
| 15915 | 15919 | |
| 15916 | 15920 | ConstExprValue *fn_def_val = create_const_vals(1); |
| ... | ... | @@ -15919,8 +15923,7 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop |
| 15919 | 15923 | fn_def_val->data.x_struct.parent.id = ConstParentIdUnion; |
| 15920 | 15924 | fn_def_val->data.x_struct.parent.data.p_union.union_val = &inner_fields[2]; |
| 15921 | 15925 | |
| 15922 | | // @TODO Add fields |
| 15923 | | ConstExprValue *fn_def_fields = create_const_vals(7); |
| 15926 | ConstExprValue *fn_def_fields = create_const_vals(9); |
| 15924 | 15927 | fn_def_val->data.x_struct.fields = fn_def_fields; |
| 15925 | 15928 | |
| 15926 | 15929 | // fn_type: type |
| ... | ... | @@ -15940,9 +15943,10 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop |
| 15940 | 15943 | bigint_init_unsigned(&fn_def_fields[2].data.x_enum_tag, fn_node->cc); |
| 15941 | 15944 | // is_var_args: bool |
| 15942 | 15945 | ensure_field_index(fn_def_val->type, "is_var_args", 3); |
| 15946 | bool is_varargs = fn_node->is_var_args; |
| 15943 | 15947 | fn_def_fields[3].special = ConstValSpecialStatic; |
| 15944 | 15948 | fn_def_fields[3].type = ira->codegen->builtin_types.entry_bool; |
| 15945 | | fn_def_fields[3].data.x_bool = fn_node->is_var_args; |
| 15949 | fn_def_fields[3].data.x_bool = is_varargs; |
| 15946 | 15950 | // is_extern: bool |
| 15947 | 15951 | ensure_field_index(fn_def_val->type, "is_extern", 4); |
| 15948 | 15952 | fn_def_fields[4].special = ConstValSpecialStatic; |
| ... | ... | @@ -15959,18 +15963,47 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop |
| 15959 | 15963 | fn_def_fields[6].type = get_maybe_type(ira->codegen, |
| 15960 | 15964 | get_slice_type(ira->codegen, get_pointer_to_type(ira->codegen, |
| 15961 | 15965 | ira->codegen->builtin_types.entry_u8, true))); |
| 15962 | | |
| 15963 | | |
| 15964 | 15966 | if (fn_node->is_extern && buf_len(fn_node->lib_name) > 0) |
| 15965 | 15967 | { |
| 15966 | 15968 | fn_def_fields[6].data.x_maybe = create_const_vals(1); |
| 15967 | | // @TODO Figure out if lib_name is always non-null for extern fns. |
| 15968 | 15969 | ConstExprValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name); |
| 15969 | 15970 | init_const_slice(ira->codegen, fn_def_fields[6].data.x_maybe, lib_name, 0, buf_len(fn_node->lib_name), true); |
| 15970 | 15971 | } |
| 15971 | 15972 | else |
| 15972 | | { |
| 15973 | 15973 | fn_def_fields[6].data.x_maybe = nullptr; |
| 15974 | // return_type: type |
| 15975 | ensure_field_index(fn_def_val->type, "return_type", 7); |
| 15976 | fn_def_fields[7].special = ConstValSpecialStatic; |
| 15977 | fn_def_fields[7].type = ira->codegen->builtin_types.entry_type; |
| 15978 | // @TODO Check whether this is correct. |
| 15979 | if (fn_entry->src_implicit_return_type != nullptr) |
| 15980 | fn_def_fields[7].data.x_type = fn_entry->src_implicit_return_type; |
| 15981 | else if (fn_entry->type_entry->data.fn.gen_return_type != nullptr) |
| 15982 | fn_def_fields[7].data.x_type = fn_entry->type_entry->data.fn.gen_return_type; |
| 15983 | else |
| 15984 | fn_def_fields[7].data.x_type = fn_entry->type_entry->data.fn.fn_type_id.return_type; |
| 15985 | // arg_names: [][] const u8 |
| 15986 | ensure_field_index(fn_def_val->type, "arg_names", 8); |
| 15987 | size_t fn_arg_count = fn_entry->variable_list.length; |
| 15988 | ConstExprValue *fn_arg_name_array = create_const_vals(1); |
| 15989 | fn_arg_name_array->special = ConstValSpecialStatic; |
| 15990 | fn_arg_name_array->type = get_array_type(ira->codegen, get_slice_type(ira->codegen, |
| 15991 | get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true)), fn_arg_count); |
| 15992 | fn_arg_name_array->data.x_array.special = ConstArraySpecialNone; |
| 15993 | fn_arg_name_array->data.x_array.s_none.parent.id = ConstParentIdNone; |
| 15994 | fn_arg_name_array->data.x_array.s_none.elements = create_const_vals(fn_arg_count); |
| 15995 | |
| 15996 | init_const_slice(ira->codegen, &fn_def_fields[8], fn_arg_name_array, 0, fn_arg_count, false); |
| 15997 | |
| 15998 | for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) |
| 15999 | { |
| 16000 | VariableTableEntry *arg_var = fn_entry->variable_list.at(fn_arg_index); |
| 16001 | ConstExprValue *fn_arg_name_val = &fn_arg_name_array->data.x_array.s_none.elements[fn_arg_index]; |
| 16002 | ConstExprValue *arg_name = create_const_str_lit(ira->codegen, &arg_var->name); |
| 16003 | init_const_slice(ira->codegen, fn_arg_name_val, arg_name, 0, buf_len(&arg_var->name), true); |
| 16004 | fn_arg_name_val->data.x_struct.parent.id = ConstParentIdArray; |
| 16005 | fn_arg_name_val->data.x_struct.parent.data.p_array.array_val = fn_arg_name_array; |
| 16006 | fn_arg_name_val->data.x_struct.parent.data.p_array.elem_index = fn_arg_index; |
| 15974 | 16007 | } |
| 15975 | 16008 | |
| 15976 | 16009 | inner_fields[2].data.x_union.payload = fn_def_val; |