| ... | ... | @@ -16233,6 +16233,98 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t |
| 16233 | 16233 | struct_field_val->data.x_struct.parent.data.p_array.elem_index = struct_field_index; |
| 16234 | 16234 | } |
| 16235 | 16235 | // @TODO Definitions |
| 16236 | break; |
| 16237 | } |
| 16238 | case TypeTableEntryIdFn: |
| 16239 | { |
| 16240 | result = create_const_vals(1); |
| 16241 | result->special = ConstValSpecialStatic; |
| 16242 | result->type = ir_type_info_get_type(ira, "Fn"); |
| 16243 | |
| 16244 | ConstExprValue *fields = create_const_vals(5); |
| 16245 | result->data.x_struct.fields = fields; |
| 16246 | |
| 16247 | // @TODO Fix type = undefined with ?type |
| 16248 | |
| 16249 | // calling_convention: TypeInfo.CallingConvention |
| 16250 | ensure_field_index(result->type, "calling_convention", 0); |
| 16251 | fields[0].special = ConstValSpecialStatic; |
| 16252 | fields[0].type = ir_type_info_get_type(ira, "CallingConvention"); |
| 16253 | bigint_init_unsigned(&fields[0].data.x_enum_tag, type_entry->data.fn.fn_type_id.cc); |
| 16254 | // is_generic: bool |
| 16255 | ensure_field_index(result->type, "is_generic", 1); |
| 16256 | bool is_generic = type_entry->data.fn.is_generic; |
| 16257 | fields[1].special = ConstValSpecialStatic; |
| 16258 | fields[1].type = ira->codegen->builtin_types.entry_bool; |
| 16259 | fields[1].data.x_bool = is_generic; |
| 16260 | // is_varargs: bool |
| 16261 | ensure_field_index(result->type, "is_var_args", 2); |
| 16262 | bool is_varargs = type_entry->data.fn.fn_type_id.is_var_args; |
| 16263 | fields[2].special = ConstValSpecialStatic; |
| 16264 | fields[2].type = ira->codegen->builtin_types.entry_bool; |
| 16265 | fields[2].data.x_bool = type_entry->data.fn.fn_type_id.is_var_args; |
| 16266 | // return_type: type |
| 16267 | ensure_field_index(result->type, "return_type", 3); |
| 16268 | fields[3].special = ConstValSpecialStatic; |
| 16269 | fields[3].type = ira->codegen->builtin_types.entry_type; |
| 16270 | if (type_entry->data.fn.fn_type_id.return_type == nullptr) |
| 16271 | fields[3].data.x_type = ira->codegen->builtin_types.entry_undef; |
| 16272 | else |
| 16273 | fields[3].data.x_type = type_entry->data.fn.fn_type_id.return_type; |
| 16274 | // async_allocator_type: type |
| 16275 | ensure_field_index(result->type, "async_allocator_type", 4); |
| 16276 | fields[4].special = ConstValSpecialStatic; |
| 16277 | fields[4].type = ira->codegen->builtin_types.entry_type; |
| 16278 | if (type_entry->data.fn.fn_type_id.async_allocator_type == nullptr) |
| 16279 | fields[4].data.x_type = ira->codegen->builtin_types.entry_undef; |
| 16280 | else |
| 16281 | fields[4].data.x_type = type_entry->data.fn.fn_type_id.async_allocator_type; |
| 16282 | // args: []TypeInfo.FnArg |
| 16283 | TypeTableEntry *type_info_fn_arg_type = ir_type_info_get_type(ira, "FnArg"); |
| 16284 | size_t fn_arg_count = type_entry->data.fn.fn_type_id.param_count - |
| 16285 | (is_varargs && type_entry->data.fn.fn_type_id.cc != CallingConventionC); |
| 16286 | |
| 16287 | ConstExprValue *fn_arg_array = create_const_vals(1); |
| 16288 | fn_arg_array->special = ConstValSpecialStatic; |
| 16289 | fn_arg_array->type = get_array_type(ira->codegen, type_info_fn_arg_type, fn_arg_count); |
| 16290 | fn_arg_array->data.x_array.special = ConstArraySpecialNone; |
| 16291 | fn_arg_array->data.x_array.s_none.parent.id = ConstParentIdNone; |
| 16292 | fn_arg_array->data.x_array.s_none.elements = create_const_vals(fn_arg_count); |
| 16293 | |
| 16294 | init_const_slice(ira->codegen, &fields[5], fn_arg_array, 0, fn_arg_count, false); |
| 16295 | |
| 16296 | for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) |
| 16297 | { |
| 16298 | FnTypeParamInfo *fn_param_info = &type_entry->data.fn.fn_type_id.param_info[fn_arg_index]; |
| 16299 | ConstExprValue *fn_arg_val = &fn_arg_array->data.x_array.s_none.elements[fn_arg_index]; |
| 16300 | |
| 16301 | fn_arg_val->special = ConstValSpecialStatic; |
| 16302 | fn_arg_val->type = type_info_fn_arg_type; |
| 16303 | |
| 16304 | bool arg_is_generic = fn_param_info->type == nullptr; |
| 16305 | if (arg_is_generic) assert(is_generic); |
| 16306 | |
| 16307 | ConstExprValue *inner_fields = create_const_vals(3); |
| 16308 | inner_fields[0].special = ConstValSpecialStatic; |
| 16309 | inner_fields[0].type = ira->codegen->builtin_types.entry_bool; |
| 16310 | inner_fields[0].data.x_bool = arg_is_generic; |
| 16311 | inner_fields[1].special = ConstValSpecialStatic; |
| 16312 | inner_fields[1].type = ira->codegen->builtin_types.entry_bool; |
| 16313 | inner_fields[1].data.x_bool = fn_param_info->is_noalias; |
| 16314 | inner_fields[2].special = ConstValSpecialStatic; |
| 16315 | inner_fields[2].type = ira->codegen->builtin_types.entry_type; |
| 16316 | |
| 16317 | if (arg_is_generic) |
| 16318 | inner_fields[2].data.x_type = ira->codegen->builtin_types.entry_undef; |
| 16319 | else |
| 16320 | inner_fields[2].data.x_type = fn_param_info->type; |
| 16321 | |
| 16322 | fn_arg_val->data.x_struct.fields = inner_fields; |
| 16323 | fn_arg_val->data.x_struct.parent.id = ConstParentIdArray; |
| 16324 | fn_arg_val->data.x_struct.parent.data.p_array.array_val = fn_arg_array; |
| 16325 | fn_arg_val->data.x_struct.parent.data.p_array.elem_index = fn_arg_index; |
| 16326 | } |
| 16327 | |
| 16236 | 16328 | break; |
| 16237 | 16329 | } |
| 16238 | 16330 | } |