mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 14:25:16 +00:00
Implement @Type() for EnumLiteral and FnFrame
This commit is contained in:
parent
1696e943ac
commit
ca6db2d008
@ -157,7 +157,7 @@ pub const TypeInfo = union(enum) {
|
||||
Fn: Fn,
|
||||
BoundFn: Fn,
|
||||
Opaque: void,
|
||||
Frame: void,
|
||||
Frame: Frame,
|
||||
AnyFrame: AnyFrame,
|
||||
Vector: Vector,
|
||||
EnumLiteral: void,
|
||||
@ -315,6 +315,12 @@ pub const TypeInfo = union(enum) {
|
||||
args: []FnArg,
|
||||
};
|
||||
|
||||
/// This data structure is used by the Zig language code generation and
|
||||
/// therefore must be kept in sync with the compiler implementation.
|
||||
pub const Frame = struct {
|
||||
function: var,
|
||||
};
|
||||
|
||||
/// This data structure is used by the Zig language code generation and
|
||||
/// therefore must be kept in sync with the compiler implementation.
|
||||
pub const AnyFrame = struct {
|
||||
|
||||
12
src/ir.cpp
12
src/ir.cpp
@ -25446,10 +25446,18 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
|
||||
ZigType *child_type = get_const_field_meta_type_optional(ira, source_instr->source_node, payload, "child", 0);
|
||||
return get_any_frame_type(ira->codegen, child_type);
|
||||
}
|
||||
case ZigTypeIdEnumLiteral:
|
||||
return ira->codegen->builtin_types.entry_enum_literal;
|
||||
case ZigTypeIdFnFrame: {
|
||||
assert(payload->special == ConstValSpecialStatic);
|
||||
assert(payload->type == ir_type_info_get_type(ira, "Frame", nullptr));
|
||||
ZigValue *function = get_const_field(ira, source_instr->source_node, payload, "function", 0);
|
||||
assert(function->type->id == ZigTypeIdFn);
|
||||
ZigFn *fn = function->data.x_ptr.data.fn.fn_entry;
|
||||
return get_fn_frame_type(ira->codegen, fn);
|
||||
}
|
||||
case ZigTypeIdErrorSet:
|
||||
case ZigTypeIdEnum:
|
||||
case ZigTypeIdFnFrame:
|
||||
case ZigTypeIdEnumLiteral:
|
||||
ir_add_error(ira, source_instr, buf_sprintf(
|
||||
"TODO implement @Type for 'TypeInfo.%s': see https://github.com/ziglang/zig/issues/2907", type_id_name(tagTypeId)));
|
||||
return ira->codegen->invalid_inst_gen->value->type;
|
||||
|
||||
@ -213,3 +213,19 @@ test "Type.AnyFrame" {
|
||||
anyframe->anyframe->u8,
|
||||
});
|
||||
}
|
||||
|
||||
test "Type.EnumLiteral" {
|
||||
testTypes(&[_]type{
|
||||
@TypeOf(.Dummy),
|
||||
});
|
||||
}
|
||||
|
||||
fn add(a: i32, b: i32) i32 {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
test "Type.Frame" {
|
||||
testTypes(&[_]type{
|
||||
@Frame(add),
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user