diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2023-03-04 13:21:11 +0000 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2023-03-21 15:04:39 +0200 |
| commit | f9b5829508e4f9a7e2eee2f05f58a38c00318d91 (patch) | |
| tree | d56e7826469317dfebe7d7c87fa58071b1d38546 /src | |
| parent | 5e161c102d4a99be4903d0074ea2513ebcdb985b (diff) | |
| download | zig-f9b5829508e4f9a7e2eee2f05f58a38c00318d91.tar.gz zig-f9b5829508e4f9a7e2eee2f05f58a38c00318d91.zip | |
Sema: implement @export for arbitrary values
Diffstat (limited to 'src')
| -rw-r--r-- | src/Sema.zig | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 6d6a9a13e8..d01535cdaa 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -5668,7 +5668,15 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError }; const decl_index = switch (operand.val.tag()) { .function => operand.val.castTag(.function).?.data.owner_decl, - else => return sema.fail(block, operand_src, "TODO implement exporting arbitrary Value objects", .{}), // TODO put this Value into an anonymous Decl and then export it. + else => blk: { + var anon_decl = try block.startAnonDecl(); + defer anon_decl.deinit(); + break :blk try anon_decl.finish( + try operand.ty.copy(anon_decl.arena()), + try operand.val.copy(anon_decl.arena()), + 0, + ); + }, }; try sema.analyzeExport(block, src, options, decl_index); } @@ -5704,6 +5712,14 @@ pub fn analyzeExport( return sema.failWithOwnedErrorMsg(msg); } + // TODO: some backends might support re-exporting extern decls + if (exported_decl.isExtern()) { + return sema.fail(block, src, "export target cannot be extern", .{}); + } + + // This decl is alive no matter what, since it's being exported + mod.markDeclAlive(exported_decl); + const gpa = mod.gpa; try mod.decl_exports.ensureUnusedCapacity(gpa, 1); |
