lib/choir/src/composition/module/symbol.zig
daab053ee43316e1809a84551d573ddd1e5bf3d2
1 const std = @import("std");
2
3 const Allocator = std.mem.Allocator;
4
5 pub const ExportSpec = struct {
6 name: []const u8,
7 symbol: []const u8,
8 abi_version: u32,
9 };
10
11 pub const Export = struct {
12 name: []const u8,
13 symbol: []const u8,
14 abi_version: u32,
15
16 pub fn init(allocator: Allocator, spec: ExportSpec) Allocator.Error!Export {
17 const name = try allocator.dupe(u8, spec.name);
18 errdefer allocator.free(name);
19 return .{
20 .name = name,
21 .symbol = try allocator.dupe(u8, spec.symbol),
22 .abi_version = spec.abi_version,
23 };
24 }
25
26 pub fn deinit(self: *Export, allocator: Allocator) void {
27 allocator.free(self.symbol);
28 allocator.free(self.name);
29 self.* = undefined;
30 }
31 };
32
33 pub const ImportKind = enum(u32) {
34 fragment = 1,
35 runtime = 2,
36 };
37
38 pub const ImportSpec = struct {
39 name: []const u8,
40 symbol: []const u8,
41 abi_version: u32,
42 kind: ImportKind,
43 };
44
45 pub const Import = struct {
46 name: []const u8,
47 symbol: []const u8,
48 abi_version: u32,
49 kind: ImportKind,
50
51 pub fn init(allocator: Allocator, spec: ImportSpec) Allocator.Error!Import {
52 const name = try allocator.dupe(u8, spec.name);
53 errdefer allocator.free(name);
54 return .{
55 .name = name,
56 .symbol = try allocator.dupe(u8, spec.symbol),
57 .abi_version = spec.abi_version,
58 .kind = spec.kind,
59 };
60 }
61
62 pub fn deinit(self: *Import, allocator: Allocator) void {
63 allocator.free(self.symbol);
64 allocator.free(self.name);
65 self.* = undefined;
66 }
67 };