authorgravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-04-28 11:16:11-06:00
committergravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-05-02 14:39:28-06:00
logca6db2d008cf3e0e3700e84400bd3d6e259e3c0f
treea5975ad5f4f6c655577152d087e3f31eb5d060ad
parent1696e943acd67119104f303467c0e26eecb94544
signature Commit is signed but in an unrecognized format.

Implement @Type() for EnumLiteral and FnFrame


3 files changed, 33 insertions(+), 3 deletions(-)

lib/std/builtin.zig+7-1
...@@ -157,7 +157,7 @@ pub const TypeInfo = union(enum) {...@@ -157,7 +157,7 @@ pub const TypeInfo = union(enum) {
157 Fn: Fn,157 Fn: Fn,
158 BoundFn: Fn,158 BoundFn: Fn,
159 Opaque: void,159 Opaque: void,
160 Frame: void,160 Frame: Frame,
161 AnyFrame: AnyFrame,161 AnyFrame: AnyFrame,
162 Vector: Vector,162 Vector: Vector,
163 EnumLiteral: void,163 EnumLiteral: void,
...@@ -315,6 +315,12 @@ pub const TypeInfo = union(enum) {...@@ -315,6 +315,12 @@ pub const TypeInfo = union(enum) {
315 args: []FnArg,315 args: []FnArg,
316 };316 };
317317
318 /// This data structure is used by the Zig language code generation and
319 /// therefore must be kept in sync with the compiler implementation.
320 pub const Frame = struct {
321 function: var,
322 };
323
318 /// This data structure is used by the Zig language code generation and324 /// This data structure is used by the Zig language code generation and
319 /// therefore must be kept in sync with the compiler implementation.325 /// therefore must be kept in sync with the compiler implementation.
320 pub const AnyFrame = struct {326 pub const AnyFrame = struct {
src/ir.cpp+10-2
...@@ -25446,10 +25446,18 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -25446,10 +25446,18 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
25446 ZigType *child_type = get_const_field_meta_type_optional(ira, source_instr->source_node, payload, "child", 0);25446 ZigType *child_type = get_const_field_meta_type_optional(ira, source_instr->source_node, payload, "child", 0);
25447 return get_any_frame_type(ira->codegen, child_type);25447 return get_any_frame_type(ira->codegen, child_type);
25448 }25448 }
25449 case ZigTypeIdEnumLiteral:
25450 return ira->codegen->builtin_types.entry_enum_literal;
25451 case ZigTypeIdFnFrame: {
25452 assert(payload->special == ConstValSpecialStatic);
25453 assert(payload->type == ir_type_info_get_type(ira, "Frame", nullptr));
25454 ZigValue *function = get_const_field(ira, source_instr->source_node, payload, "function", 0);
25455 assert(function->type->id == ZigTypeIdFn);
25456 ZigFn *fn = function->data.x_ptr.data.fn.fn_entry;
25457 return get_fn_frame_type(ira->codegen, fn);
25458 }
25449 case ZigTypeIdErrorSet:25459 case ZigTypeIdErrorSet:
25450 case ZigTypeIdEnum:25460 case ZigTypeIdEnum:
25451 case ZigTypeIdFnFrame:
25452 case ZigTypeIdEnumLiteral:
25453 ir_add_error(ira, source_instr, buf_sprintf(25461 ir_add_error(ira, source_instr, buf_sprintf(
25454 "TODO implement @Type for 'TypeInfo.%s': see https://github.com/ziglang/zig/issues/2907", type_id_name(tagTypeId)));25462 "TODO implement @Type for 'TypeInfo.%s': see https://github.com/ziglang/zig/issues/2907", type_id_name(tagTypeId)));
25455 return ira->codegen->invalid_inst_gen->value->type;25463 return ira->codegen->invalid_inst_gen->value->type;
test/stage1/behavior/type.zig+16
...@@ -213,3 +213,19 @@ test "Type.AnyFrame" {...@@ -213,3 +213,19 @@ test "Type.AnyFrame" {
213 anyframe->anyframe->u8,213 anyframe->anyframe->u8,
214 });214 });
215}215}
216
217test "Type.EnumLiteral" {
218 testTypes(&[_]type{
219 @TypeOf(.Dummy),
220 });
221}
222
223fn add(a: i32, b: i32) i32 {
224 return a + b;
225}
226
227test "Type.Frame" {
228 testTypes(&[_]type{
229 @Frame(add),
230 });
231}