authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-09-04 23:34:44+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-09-30 16:56:45+03:00
log20ae15917c5cded10a01b85c2cba77041dacef1c
tree583b4b57b3f0329b73e8198efbe4a797b0486005
parentfe117d9961c3622fda5c359733d01de686509af0
signature Commit is signed but in an unrecognized format.

stage2: add import builtin stub


6 files changed, 70 insertions(+), 0 deletions(-)

src/Module.zig+5
......@@ -2381,6 +2381,11 @@ pub fn analyzeSlice(self: *Module, scope: *Scope, src: usize, array_ptr: *Inst,
23812381 return self.fail(scope, src, "TODO implement analysis of slice", .{});
23822382}
23832383
2384pub fn analyzeImport(self: *Module, scope: *Scope, src: usize, target_string: []const u8) InnerError!*Inst {
2385 // TODO actually try to import
2386 return self.constType(scope, src, Type.initTag(.empty_struct));
2387}
2388
23842389/// Asserts that lhs and rhs types are both numeric.
23852390pub fn cmpNumeric(
23862391 self: *Module,
src/astgen.zig+11
......@@ -1973,6 +1973,15 @@ fn bitCast(mod: *Module, scope: *Scope, rl: ResultLoc, call: *ast.Node.BuiltinCa
19731973 }
19741974}
19751975
1976fn import(mod: *Module, scope: *Scope, call: *ast.Node.BuiltinCall) InnerError!*zir.Inst {
1977 try ensureBuiltinParamCount(mod, scope, call, 1);
1978 const tree = scope.tree();
1979 const src = tree.token_locs[call.builtin_token].start;
1980 const params = call.params();
1981 const target = try expr(mod, scope, .none, params[0]);
1982 return addZIRUnOp(mod, scope, src, .import, target);
1983}
1984
19761985fn builtinCall(mod: *Module, scope: *Scope, rl: ResultLoc, call: *ast.Node.BuiltinCall) InnerError!*zir.Inst {
19771986 const tree = scope.tree();
19781987 const builtin_name = tree.tokenSlice(call.builtin_token);
......@@ -1995,6 +2004,8 @@ fn builtinCall(mod: *Module, scope: *Scope, rl: ResultLoc, call: *ast.Node.Built
19952004 } else if (mem.eql(u8, builtin_name, "@breakpoint")) {
19962005 const src = tree.token_locs[call.builtin_token].start;
19972006 return rlWrap(mod, scope, rl, try addZIRNoOp(mod, scope, src, .breakpoint));
2007 } else if (mem.eql(u8, builtin_name, "@import")) {
2008 return rlWrap(mod, scope, rl, try import(mod, scope, call));
19982009 } else {
19992010 return mod.failTok(scope, call.builtin_token, "invalid builtin function: '{}'", .{builtin_name});
20002011 }
src/type.zig+29
......@@ -89,6 +89,8 @@ pub const Type = extern union {
8989 .anyerror_void_error_union, .error_union => return .ErrorUnion,
9090
9191 .anyframe_T, .@"anyframe" => return .AnyFrame,
92
93 .empty_struct => return .Struct,
9294 }
9395 }
9496
......@@ -352,6 +354,7 @@ pub const Type = extern union {
352354 .enum_literal,
353355 .anyerror_void_error_union,
354356 .@"anyframe",
357 .empty_struct,
355358 => unreachable,
356359
357360 .array_u8_sentinel_0 => return self.copyPayloadShallow(allocator, Payload.Array_u8_Sentinel0),
......@@ -505,6 +508,7 @@ pub const Type = extern union {
505508 .@"null" => return out_stream.writeAll("@Type(.Null)"),
506509 .@"undefined" => return out_stream.writeAll("@Type(.Undefined)"),
507510
511 .empty_struct => return out_stream.writeAll("struct {}"),
508512 .@"anyframe" => return out_stream.writeAll("anyframe"),
509513 .anyerror_void_error_union => return out_stream.writeAll("anyerror!void"),
510514 .const_slice_u8 => return out_stream.writeAll("[]const u8"),
......@@ -788,6 +792,7 @@ pub const Type = extern union {
788792 .@"null",
789793 .@"undefined",
790794 .enum_literal,
795 .empty_struct,
791796 => false,
792797 };
793798 }
......@@ -910,6 +915,7 @@ pub const Type = extern union {
910915 .@"null",
911916 .@"undefined",
912917 .enum_literal,
918 .empty_struct,
913919 => unreachable,
914920 };
915921 }
......@@ -932,6 +938,7 @@ pub const Type = extern union {
932938 .@"undefined" => unreachable,
933939 .enum_literal => unreachable,
934940 .single_const_pointer_to_comptime_int => unreachable,
941 .empty_struct => unreachable,
935942
936943 .u8,
937944 .i8,
......@@ -1107,6 +1114,7 @@ pub const Type = extern union {
11071114 .anyerror_void_error_union,
11081115 .error_set,
11091116 .error_set_single,
1117 .empty_struct,
11101118 => false,
11111119
11121120 .single_const_pointer,
......@@ -1181,6 +1189,7 @@ pub const Type = extern union {
11811189 .anyerror_void_error_union,
11821190 .error_set,
11831191 .error_set_single,
1192 .empty_struct,
11841193 => false,
11851194
11861195 .const_slice,
......@@ -1252,6 +1261,7 @@ pub const Type = extern union {
12521261 .anyerror_void_error_union,
12531262 .error_set,
12541263 .error_set_single,
1264 .empty_struct,
12551265 => false,
12561266
12571267 .single_const_pointer,
......@@ -1332,6 +1342,7 @@ pub const Type = extern union {
13321342 .anyerror_void_error_union,
13331343 .error_set,
13341344 .error_set_single,
1345 .empty_struct,
13351346 => false,
13361347
13371348 .pointer => {
......@@ -1407,6 +1418,7 @@ pub const Type = extern union {
14071418 .anyerror_void_error_union,
14081419 .error_set,
14091420 .error_set_single,
1421 .empty_struct,
14101422 => false,
14111423
14121424 .pointer => {
......@@ -1524,6 +1536,7 @@ pub const Type = extern union {
15241536 .anyerror_void_error_union,
15251537 .error_set,
15261538 .error_set_single,
1539 .empty_struct,
15271540 => unreachable,
15281541
15291542 .array => self.cast(Payload.Array).?.elem_type,
......@@ -1651,6 +1664,7 @@ pub const Type = extern union {
16511664 .anyerror_void_error_union,
16521665 .error_set,
16531666 .error_set_single,
1667 .empty_struct,
16541668 => unreachable,
16551669
16561670 .array => self.cast(Payload.Array).?.len,
......@@ -1716,6 +1730,7 @@ pub const Type = extern union {
17161730 .anyerror_void_error_union,
17171731 .error_set,
17181732 .error_set_single,
1733 .empty_struct,
17191734 => unreachable,
17201735
17211736 .single_const_pointer,
......@@ -1798,6 +1813,7 @@ pub const Type = extern union {
17981813 .anyerror_void_error_union,
17991814 .error_set,
18001815 .error_set_single,
1816 .empty_struct,
18011817 => false,
18021818
18031819 .int_signed,
......@@ -1872,6 +1888,7 @@ pub const Type = extern union {
18721888 .anyerror_void_error_union,
18731889 .error_set,
18741890 .error_set_single,
1891 .empty_struct,
18751892 => false,
18761893
18771894 .int_unsigned,
......@@ -1936,6 +1953,7 @@ pub const Type = extern union {
19361953 .anyerror_void_error_union,
19371954 .error_set,
19381955 .error_set_single,
1956 .empty_struct,
19391957 => unreachable,
19401958
19411959 .int_unsigned => .{ .signed = false, .bits = self.cast(Payload.IntUnsigned).?.bits },
......@@ -2018,6 +2036,7 @@ pub const Type = extern union {
20182036 .anyerror_void_error_union,
20192037 .error_set,
20202038 .error_set_single,
2039 .empty_struct,
20212040 => false,
20222041
20232042 .usize,
......@@ -2129,6 +2148,7 @@ pub const Type = extern union {
21292148 .anyerror_void_error_union,
21302149 .error_set,
21312150 .error_set_single,
2151 .empty_struct,
21322152 => unreachable,
21332153 };
21342154 }
......@@ -2206,6 +2226,7 @@ pub const Type = extern union {
22062226 .anyerror_void_error_union,
22072227 .error_set,
22082228 .error_set_single,
2229 .empty_struct,
22092230 => unreachable,
22102231 }
22112232 }
......@@ -2282,6 +2303,7 @@ pub const Type = extern union {
22822303 .anyerror_void_error_union,
22832304 .error_set,
22842305 .error_set_single,
2306 .empty_struct,
22852307 => unreachable,
22862308 }
22872309 }
......@@ -2358,6 +2380,7 @@ pub const Type = extern union {
23582380 .anyerror_void_error_union,
23592381 .error_set,
23602382 .error_set_single,
2383 .empty_struct,
23612384 => unreachable,
23622385 };
23632386 }
......@@ -2431,6 +2454,7 @@ pub const Type = extern union {
24312454 .anyerror_void_error_union,
24322455 .error_set,
24332456 .error_set_single,
2457 .empty_struct,
24342458 => unreachable,
24352459 };
24362460 }
......@@ -2504,6 +2528,7 @@ pub const Type = extern union {
25042528 .anyerror_void_error_union,
25052529 .error_set,
25062530 .error_set_single,
2531 .empty_struct,
25072532 => unreachable,
25082533 };
25092534 }
......@@ -2577,6 +2602,7 @@ pub const Type = extern union {
25772602 .anyerror_void_error_union,
25782603 .error_set,
25792604 .error_set_single,
2605 .empty_struct,
25802606 => false,
25812607 };
25822608 }
......@@ -2636,6 +2662,7 @@ pub const Type = extern union {
26362662 .error_set_single,
26372663 => return null,
26382664
2665 .empty_struct => return Value.initTag(.empty_struct_value),
26392666 .void => return Value.initTag(.void_value),
26402667 .noreturn => return Value.initTag(.unreachable_value),
26412668 .@"null" => return Value.initTag(.null_value),
......@@ -2743,6 +2770,7 @@ pub const Type = extern union {
27432770 .anyerror_void_error_union,
27442771 .error_set,
27452772 .error_set_single,
2773 .empty_struct,
27462774 => return false,
27472775
27482776 .c_const_pointer,
......@@ -2809,6 +2837,7 @@ pub const Type = extern union {
28092837 single_const_pointer_to_comptime_int,
28102838 anyerror_void_error_union,
28112839 @"anyframe",
2840 empty_struct,
28122841 const_slice_u8, // See last_no_payload_tag below.
28132842 // After this, the tag requires a payload.
28142843
src/value.zig+14
......@@ -68,6 +68,7 @@ pub const Value = extern union {
6868 one,
6969 void_value,
7070 unreachable_value,
71 empty_struct_value,
7172 empty_array,
7273 null_value,
7374 bool_true,
......@@ -182,6 +183,7 @@ pub const Value = extern union {
182183 .null_value,
183184 .bool_true,
184185 .bool_false,
186 .empty_struct_value,
185187 => unreachable,
186188
187189 .ty => {
......@@ -312,6 +314,7 @@ pub const Value = extern union {
312314 .enum_literal_type => return out_stream.writeAll("@Type(.EnumLiteral)"),
313315 .anyframe_type => return out_stream.writeAll("anyframe"),
314316
317 .empty_struct_value => return out_stream.writeAll("struct {}{}"),
315318 .null_value => return out_stream.writeAll("null"),
316319 .undef => return out_stream.writeAll("undefined"),
317320 .zero => return out_stream.writeAll("0"),
......@@ -475,6 +478,7 @@ pub const Value = extern union {
475478 .float_128,
476479 .enum_literal,
477480 .@"error",
481 .empty_struct_value,
478482 => unreachable,
479483 };
480484 }
......@@ -543,6 +547,7 @@ pub const Value = extern union {
543547 .enum_literal,
544548 .error_set,
545549 .@"error",
550 .empty_struct_value,
546551 => unreachable,
547552
548553 .undef => unreachable,
......@@ -626,6 +631,7 @@ pub const Value = extern union {
626631 .enum_literal,
627632 .error_set,
628633 .@"error",
634 .empty_struct_value,
629635 => unreachable,
630636
631637 .undef => unreachable,
......@@ -709,6 +715,7 @@ pub const Value = extern union {
709715 .enum_literal,
710716 .error_set,
711717 .@"error",
718 .empty_struct_value,
712719 => unreachable,
713720
714721 .undef => unreachable,
......@@ -820,6 +827,7 @@ pub const Value = extern union {
820827 .enum_literal,
821828 .error_set,
822829 .@"error",
830 .empty_struct_value,
823831 => unreachable,
824832
825833 .zero,
......@@ -907,6 +915,7 @@ pub const Value = extern union {
907915 .enum_literal,
908916 .error_set,
909917 .@"error",
918 .empty_struct_value,
910919 => unreachable,
911920
912921 .zero,
......@@ -1078,6 +1087,7 @@ pub const Value = extern union {
10781087 .enum_literal,
10791088 .error_set,
10801089 .@"error",
1090 .empty_struct_value,
10811091 => unreachable,
10821092
10831093 .zero,
......@@ -1152,6 +1162,7 @@ pub const Value = extern union {
11521162 .enum_literal,
11531163 .error_set,
11541164 .@"error",
1165 .empty_struct_value,
11551166 => unreachable,
11561167
11571168 .zero,
......@@ -1300,6 +1311,7 @@ pub const Value = extern union {
13001311 .enum_literal,
13011312 .error_set,
13021313 .@"error",
1314 .empty_struct_value,
13031315 => unreachable,
13041316
13051317 .ref_val => self.cast(Payload.RefVal).?.val,
......@@ -1383,6 +1395,7 @@ pub const Value = extern union {
13831395 .enum_literal,
13841396 .error_set,
13851397 .@"error",
1398 .empty_struct_value,
13861399 => unreachable,
13871400
13881401 .empty_array => unreachable, // out of bounds array index
......@@ -1483,6 +1496,7 @@ pub const Value = extern union {
14831496 .enum_literal,
14841497 .error_set,
14851498 .@"error",
1499 .empty_struct_value,
14861500 => false,
14871501
14881502 .undef => unreachable,
src/zir.zig+4
......@@ -161,6 +161,8 @@ pub const Inst = struct {
161161 @"fn",
162162 /// Returns a function type.
163163 fntype,
164 /// @import(operand)
165 import,
164166 /// Integer literal.
165167 int,
166168 /// Convert an integer value to another integer type, asserting that the destination type
......@@ -315,6 +317,7 @@ pub const Inst = struct {
315317 .ensure_err_payload_void,
316318 .anyframe_type,
317319 .bitnot,
320 .import,
318321 => UnOp,
319322
320323 .add,
......@@ -489,6 +492,7 @@ pub const Inst = struct {
489492 .error_set,
490493 .slice,
491494 .slice_start,
495 .import,
492496 => false,
493497
494498 .@"break",
src/zir_sema.zig+7
......@@ -134,6 +134,7 @@ pub fn analyzeInst(mod: *Module, scope: *Scope, old_inst: *zir.Inst) InnerError!
134134 .error_set => return analyzeInstErrorSet(mod, scope, old_inst.castTag(.error_set).?),
135135 .slice => return analyzeInstSlice(mod, scope, old_inst.castTag(.slice).?),
136136 .slice_start => return analyzeInstSliceStart(mod, scope, old_inst.castTag(.slice_start).?),
137 .import => return analyzeInstImport(mod, scope, old_inst.castTag(.import).?),
137138 }
138139}
139140
......@@ -1190,6 +1191,12 @@ fn analyzeInstSliceStart(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) Inn
11901191 return mod.analyzeSlice(scope, inst.base.src, array_ptr, start, null, null);
11911192}
11921193
1194fn analyzeInstImport(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
1195 const operand = try resolveConstString(mod, scope, inst.positionals.operand);
1196
1197 return mod.analyzeImport(scope, inst.base.src, operand);
1198}
1199
11931200fn analyzeInstShl(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
11941201 return mod.fail(scope, inst.base.src, "TODO implement analyzeInstShl", .{});
11951202}