| author | |
| committer | |
| log | 7c453b91b85bab6800d24feb57c4f35b8ce48d57 |
| tree | cf091f9555b03f3a28eba96b1774fb6e62d78e99 |
| parent | 3d637e6dd257d617867e12ac949d966d2c2ef48a |
6 files changed, 66 insertions(+), 0 deletions(-)
src/AstGen.zig+13| ... | ... | @@ -6135,6 +6135,9 @@ fn builtinCall( |
| 6135 | 6135 | } |
| 6136 | 6136 | const ident_token = main_tokens[params[0]]; |
| 6137 | 6137 | const decl_name = try gz.identAsString(ident_token); |
| 6138 | // TODO look for local variables in scope matching `decl_name` and emit a compile | |
| 6139 | // error. Only top-level declarations can be exported. Until this is done, the | |
| 6140 | // compile error will end up being "use of undeclared identifier" in Sema. | |
| 6138 | 6141 | const options = try comptimeExpr(gz, scope, .{ .ty = .export_options_type }, params[1]); |
| 6139 | 6142 | _ = try gz.addPlNode(.@"export", node, Zir.Inst.Export{ |
| 6140 | 6143 | .decl_name = decl_name, |
| ... | ... | @@ -6142,6 +6145,16 @@ fn builtinCall( |
| 6142 | 6145 | }); |
| 6143 | 6146 | return rvalue(gz, scope, rl, .void_value, node); |
| 6144 | 6147 | }, |
| 6148 | .@"extern" => { | |
| 6149 | const type_inst = try typeExpr(gz, scope, params[0]); | |
| 6150 | const options = try comptimeExpr(gz, scope, .{ .ty = .extern_options_type }, params[1]); | |
| 6151 | const result = try gz.addExtendedPayload(.builtin_extern, Zir.Inst.BinNode{ | |
| 6152 | .node = gz.nodeIndexToRelative(node), | |
| 6153 | .lhs = type_inst, | |
| 6154 | .rhs = options, | |
| 6155 | }); | |
| 6156 | return rvalue(gz, scope, rl, result, node); | |
| 6157 | }, | |
| 6145 | 6158 | |
| 6146 | 6159 | .breakpoint => return simpleNoOpVoid(gz, scope, rl, node, .breakpoint), |
| 6147 | 6160 | .fence => return simpleNoOpVoid(gz, scope, rl, node, .fence), |
src/BuiltinFn.zig+8| ... | ... | @@ -39,6 +39,7 @@ pub const Tag = enum { |
| 39 | 39 | error_to_int, |
| 40 | 40 | err_set_cast, |
| 41 | 41 | @"export", |
| 42 | @"extern", | |
| 42 | 43 | fence, |
| 43 | 44 | field, |
| 44 | 45 | field_parent_ptr, |
| ... | ... | @@ -387,6 +388,13 @@ pub const list = list: { |
| 387 | 388 | .param_count = 2, |
| 388 | 389 | }, |
| 389 | 390 | }, |
| 391 | .{ | |
| 392 | "@extern", | |
| 393 | .{ | |
| 394 | .tag = .@"extern", | |
| 395 | .param_count = 2, | |
| 396 | }, | |
| 397 | }, | |
| 390 | 398 | .{ |
| 391 | 399 | "@fence", |
| 392 | 400 | .{ |
src/Sema.zig+11| ... | ... | @@ -517,6 +517,7 @@ fn zirExtended(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro |
| 517 | 517 | .frame => return sema.zirFrame( block, extended), |
| 518 | 518 | .frame_address => return sema.zirFrameAddress( block, extended), |
| 519 | 519 | .alloc => return sema.zirAllocExtended( block, extended), |
| 520 | .builtin_extern => return sema.zirBuiltinExtern( block, extended), | |
| 520 | 521 | .c_undef => return sema.zirCUndef( block, extended), |
| 521 | 522 | .c_include => return sema.zirCInclude( block, extended), |
| 522 | 523 | .c_define => return sema.zirCDefine( block, extended), |
| ... | ... | @@ -5488,6 +5489,16 @@ fn zirWasmMemoryGrow( |
| 5488 | 5489 | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirWasmMemoryGrow", .{}); |
| 5489 | 5490 | } |
| 5490 | 5491 | |
| 5492 | fn zirBuiltinExtern( | |
| 5493 | sema: *Sema, | |
| 5494 | block: *Scope.Block, | |
| 5495 | extended: Zir.Inst.Extended.InstData, | |
| 5496 | ) InnerError!*Inst { | |
| 5497 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; | |
| 5498 | const src: LazySrcLoc = .{ .node_offset = extra.node }; | |
| 5499 | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirBuiltinExtern", .{}); | |
| 5500 | } | |
| 5501 | ||
| 5491 | 5502 | fn requireFunctionBlock(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void { |
| 5492 | 5503 | if (sema.func == null) { |
| 5493 | 5504 | return sema.mod.fail(&block.base, src, "instruction illegal outside function body", .{}); |
src/Zir.zig+9| ... | ... | @@ -1258,6 +1258,9 @@ pub const Inst = struct { |
| 1258 | 1258 | /// * 0b0X00 - 1=const, 0=var |
| 1259 | 1259 | /// * 0bX000 - is comptime |
| 1260 | 1260 | alloc, |
| 1261 | /// The `@extern` builtin. | |
| 1262 | /// `operand` is payload index to `BinNode`. | |
| 1263 | builtin_extern, | |
| 1261 | 1264 | /// `operand` is payload index to `UnNode`. |
| 1262 | 1265 | c_undef, |
| 1263 | 1266 | /// `operand` is payload index to `UnNode`. |
| ... | ... | @@ -1353,6 +1356,7 @@ pub const Inst = struct { |
| 1353 | 1356 | reduce_op_type, |
| 1354 | 1357 | call_options_type, |
| 1355 | 1358 | export_options_type, |
| 1359 | extern_options_type, | |
| 1356 | 1360 | |
| 1357 | 1361 | /// `undefined` (untyped) |
| 1358 | 1362 | undef, |
| ... | ... | @@ -1580,6 +1584,10 @@ pub const Inst = struct { |
| 1580 | 1584 | .ty = Type.initTag(.type), |
| 1581 | 1585 | .val = Value.initTag(.export_options_type), |
| 1582 | 1586 | }, |
| 1587 | .extern_options_type = .{ | |
| 1588 | .ty = Type.initTag(.type), | |
| 1589 | .val = Value.initTag(.extern_options_type), | |
| 1590 | }, | |
| 1583 | 1591 | |
| 1584 | 1592 | .undef = .{ |
| 1585 | 1593 | .ty = Type.initTag(.@"undefined"), |
| ... | ... | @@ -2598,6 +2606,7 @@ const Writer = struct { |
| 2598 | 2606 | |
| 2599 | 2607 | .func, |
| 2600 | 2608 | .alloc, |
| 2609 | .builtin_extern, | |
| 2601 | 2610 | .c_undef, |
| 2602 | 2611 | .c_include, |
| 2603 | 2612 | .c_define, |
src/type.zig+18| ... | ... | @@ -100,6 +100,7 @@ pub const Type = extern union { |
| 100 | 100 | .@"struct", |
| 101 | 101 | .call_options, |
| 102 | 102 | .export_options, |
| 103 | .extern_options, | |
| 103 | 104 | => return .Struct, |
| 104 | 105 | |
| 105 | 106 | .enum_full, |
| ... | ... | @@ -618,6 +619,7 @@ pub const Type = extern union { |
| 618 | 619 | .reduce_op, |
| 619 | 620 | .call_options, |
| 620 | 621 | .export_options, |
| 622 | .extern_options, | |
| 621 | 623 | => unreachable, |
| 622 | 624 | |
| 623 | 625 | .array_u8, |
| ... | ... | @@ -797,6 +799,7 @@ pub const Type = extern union { |
| 797 | 799 | .reduce_op => return writer.writeAll("std.builtin.ReduceOp"), |
| 798 | 800 | .call_options => return writer.writeAll("std.builtin.CallOptions"), |
| 799 | 801 | .export_options => return writer.writeAll("std.builtin.ExportOptions"), |
| 802 | .extern_options => return writer.writeAll("std.builtin.ExternOptions"), | |
| 800 | 803 | .function => { |
| 801 | 804 | const payload = ty.castTag(.function).?.data; |
| 802 | 805 | try writer.writeAll("fn("); |
| ... | ... | @@ -1012,6 +1015,7 @@ pub const Type = extern union { |
| 1012 | 1015 | .reduce_op => return Value.initTag(.reduce_op_type), |
| 1013 | 1016 | .call_options => return Value.initTag(.call_options_type), |
| 1014 | 1017 | .export_options => return Value.initTag(.export_options_type), |
| 1018 | .extern_options => return Value.initTag(.extern_options_type), | |
| 1015 | 1019 | .inferred_alloc_const => unreachable, |
| 1016 | 1020 | .inferred_alloc_mut => unreachable, |
| 1017 | 1021 | else => return Value.Tag.ty.create(allocator, self), |
| ... | ... | @@ -1070,6 +1074,7 @@ pub const Type = extern union { |
| 1070 | 1074 | .reduce_op, |
| 1071 | 1075 | .call_options, |
| 1072 | 1076 | .export_options, |
| 1077 | .extern_options, | |
| 1073 | 1078 | => true, |
| 1074 | 1079 | |
| 1075 | 1080 | .@"struct" => { |
| ... | ... | @@ -1181,6 +1186,7 @@ pub const Type = extern union { |
| 1181 | 1186 | .reduce_op, |
| 1182 | 1187 | .call_options, |
| 1183 | 1188 | .export_options, |
| 1189 | .extern_options, | |
| 1184 | 1190 | => return 1, |
| 1185 | 1191 | |
| 1186 | 1192 | .fn_noreturn_no_args, // represents machine code; not a pointer |
| ... | ... | @@ -1359,6 +1365,7 @@ pub const Type = extern union { |
| 1359 | 1365 | .reduce_op, |
| 1360 | 1366 | .call_options, |
| 1361 | 1367 | .export_options, |
| 1368 | .extern_options, | |
| 1362 | 1369 | => return 1, |
| 1363 | 1370 | |
| 1364 | 1371 | .array_u8 => self.castTag(.array_u8).?.data, |
| ... | ... | @@ -1623,6 +1630,7 @@ pub const Type = extern union { |
| 1623 | 1630 | .reduce_op, |
| 1624 | 1631 | .call_options, |
| 1625 | 1632 | .export_options, |
| 1633 | .extern_options, | |
| 1626 | 1634 | => @panic("TODO at some point we gotta resolve builtin types"), |
| 1627 | 1635 | }; |
| 1628 | 1636 | } |
| ... | ... | @@ -2247,6 +2255,7 @@ pub const Type = extern union { |
| 2247 | 2255 | .reduce_op, |
| 2248 | 2256 | .call_options, |
| 2249 | 2257 | .export_options, |
| 2258 | .extern_options, | |
| 2250 | 2259 | => return null, |
| 2251 | 2260 | |
| 2252 | 2261 | .@"struct" => { |
| ... | ... | @@ -2413,6 +2422,7 @@ pub const Type = extern union { |
| 2413 | 2422 | .reduce_op, |
| 2414 | 2423 | .call_options, |
| 2415 | 2424 | .export_options, |
| 2425 | .extern_options, | |
| 2416 | 2426 | => @panic("TODO resolve std.builtin types"), |
| 2417 | 2427 | |
| 2418 | 2428 | else => unreachable, |
| ... | ... | @@ -2436,6 +2446,7 @@ pub const Type = extern union { |
| 2436 | 2446 | .reduce_op, |
| 2437 | 2447 | .call_options, |
| 2438 | 2448 | .export_options, |
| 2449 | .extern_options, | |
| 2439 | 2450 | => @panic("TODO resolve std.builtin types"), |
| 2440 | 2451 | else => unreachable, |
| 2441 | 2452 | } |
| ... | ... | @@ -2458,6 +2469,7 @@ pub const Type = extern union { |
| 2458 | 2469 | .reduce_op, |
| 2459 | 2470 | .call_options, |
| 2460 | 2471 | .export_options, |
| 2472 | .extern_options, | |
| 2461 | 2473 | => @panic("TODO resolve std.builtin types"), |
| 2462 | 2474 | else => unreachable, |
| 2463 | 2475 | } |
| ... | ... | @@ -2502,6 +2514,7 @@ pub const Type = extern union { |
| 2502 | 2514 | .reduce_op, |
| 2503 | 2515 | .call_options, |
| 2504 | 2516 | .export_options, |
| 2517 | .extern_options, | |
| 2505 | 2518 | => @panic("TODO resolve std.builtin types"), |
| 2506 | 2519 | else => unreachable, |
| 2507 | 2520 | } |
| ... | ... | @@ -2532,6 +2545,7 @@ pub const Type = extern union { |
| 2532 | 2545 | .reduce_op, |
| 2533 | 2546 | .call_options, |
| 2534 | 2547 | .export_options, |
| 2548 | .extern_options, | |
| 2535 | 2549 | => @panic("TODO resolve std.builtin types"), |
| 2536 | 2550 | else => unreachable, |
| 2537 | 2551 | } |
| ... | ... | @@ -2563,6 +2577,7 @@ pub const Type = extern union { |
| 2563 | 2577 | .reduce_op, |
| 2564 | 2578 | .call_options, |
| 2565 | 2579 | .export_options, |
| 2580 | .extern_options, | |
| 2566 | 2581 | => @panic("TODO resolve std.builtin types"), |
| 2567 | 2582 | else => unreachable, |
| 2568 | 2583 | } |
| ... | ... | @@ -2603,6 +2618,7 @@ pub const Type = extern union { |
| 2603 | 2618 | .reduce_op, |
| 2604 | 2619 | .call_options, |
| 2605 | 2620 | .export_options, |
| 2621 | .extern_options, | |
| 2606 | 2622 | => @panic("TODO resolve std.builtin types"), |
| 2607 | 2623 | |
| 2608 | 2624 | else => unreachable, |
| ... | ... | @@ -2660,6 +2676,7 @@ pub const Type = extern union { |
| 2660 | 2676 | reduce_op, |
| 2661 | 2677 | call_options, |
| 2662 | 2678 | export_options, |
| 2679 | extern_options, | |
| 2663 | 2680 | @"null", |
| 2664 | 2681 | @"undefined", |
| 2665 | 2682 | fn_noreturn_no_args, |
| ... | ... | @@ -2772,6 +2789,7 @@ pub const Type = extern union { |
| 2772 | 2789 | .reduce_op, |
| 2773 | 2790 | .call_options, |
| 2774 | 2791 | .export_options, |
| 2792 | .extern_options, | |
| 2775 | 2793 | => @compileError("Type Tag " ++ @tagName(t) ++ " has no payload"), |
| 2776 | 2794 | |
| 2777 | 2795 | .array_u8, |
src/value.zig+7| ... | ... | @@ -73,6 +73,7 @@ pub const Value = extern union { |
| 73 | 73 | reduce_op_type, |
| 74 | 74 | call_options_type, |
| 75 | 75 | export_options_type, |
| 76 | extern_options_type, | |
| 76 | 77 | |
| 77 | 78 | undef, |
| 78 | 79 | zero, |
| ... | ... | @@ -187,6 +188,7 @@ pub const Value = extern union { |
| 187 | 188 | .reduce_op_type, |
| 188 | 189 | .call_options_type, |
| 189 | 190 | .export_options_type, |
| 191 | .extern_options_type, | |
| 190 | 192 | => @compileError("Value Tag " ++ @tagName(t) ++ " has no payload"), |
| 191 | 193 | |
| 192 | 194 | .int_big_positive, |
| ... | ... | @@ -354,6 +356,7 @@ pub const Value = extern union { |
| 354 | 356 | .reduce_op_type, |
| 355 | 357 | .call_options_type, |
| 356 | 358 | .export_options_type, |
| 359 | .extern_options_type, | |
| 357 | 360 | => unreachable, |
| 358 | 361 | |
| 359 | 362 | .ty => { |
| ... | ... | @@ -510,6 +513,7 @@ pub const Value = extern union { |
| 510 | 513 | .reduce_op_type => return out_stream.writeAll("std.builtin.ReduceOp"), |
| 511 | 514 | .call_options_type => return out_stream.writeAll("std.builtin.CallOptions"), |
| 512 | 515 | .export_options_type => return out_stream.writeAll("std.builtin.ExportOptions"), |
| 516 | .extern_options_type => return out_stream.writeAll("std.builtin.ExternOptions"), | |
| 513 | 517 | .abi_align_default => return out_stream.writeAll("(default ABI alignment)"), |
| 514 | 518 | |
| 515 | 519 | .empty_struct_value => return out_stream.writeAll("struct {}{}"), |
| ... | ... | @@ -640,6 +644,7 @@ pub const Value = extern union { |
| 640 | 644 | .reduce_op_type => Type.initTag(.reduce_op), |
| 641 | 645 | .call_options_type => Type.initTag(.call_options), |
| 642 | 646 | .export_options_type => Type.initTag(.export_options), |
| 647 | .extern_options_type => Type.initTag(.extern_options), | |
| 643 | 648 | |
| 644 | 649 | .int_type => { |
| 645 | 650 | const payload = self.castTag(.int_type).?.data; |
| ... | ... | @@ -1187,6 +1192,7 @@ pub const Value = extern union { |
| 1187 | 1192 | .reduce_op_type, |
| 1188 | 1193 | .call_options_type, |
| 1189 | 1194 | .export_options_type, |
| 1195 | .extern_options_type, | |
| 1190 | 1196 | => @panic("TODO this hash function looks pretty broken. audit it"), |
| 1191 | 1197 | } |
| 1192 | 1198 | return hasher.final(); |
| ... | ... | @@ -1343,6 +1349,7 @@ pub const Value = extern union { |
| 1343 | 1349 | .reduce_op_type, |
| 1344 | 1350 | .call_options_type, |
| 1345 | 1351 | .export_options_type, |
| 1352 | .extern_options_type, | |
| 1346 | 1353 | => true, |
| 1347 | 1354 | |
| 1348 | 1355 | .zero, |