Skip to content

Commit

Permalink
convert BuiltinFunction to a def file
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexu committed Oct 16, 2023
1 parent 633b2fc commit f85b310
Show file tree
Hide file tree
Showing 16 changed files with 17,115 additions and 14,036 deletions.
1 change: 1 addition & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub fn build(b: *Build) !void {
try aro_module.dependencies.put("system_defaults", system_defaults.createModule());

exe.addModule("aro", aro_module);
GenerateDef.add(b, "src/Builtins/Builtin.def", exe, aro_module);

system_defaults.addOption(bool, "enable_linker_build_id", enable_linker_build_id);
system_defaults.addOption([]const u8, "linker", default_linker);
Expand Down
10 changes: 5 additions & 5 deletions build/GenerateDef.zig
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ fn generate(self: *GenerateDef, input: []const u8) ![]const u8 {
while (it.next()) |line_untrimmed| {
const line = std.mem.trim(u8, line_untrimmed, " \t");
if (line.len == 0 or line[0] == '#') continue;
if (std.mem.startsWith(u8, line, "const ")) {
if (std.mem.startsWith(u8, line, "const ") or std.mem.startsWith(u8, line, "pub const ")) {
try headers.append(line);
continue;
}
Expand Down Expand Up @@ -252,7 +252,7 @@ fn generate(self: *GenerateDef, input: []const u8) ![]const u8 {
\\/// Search siblings of `first_child_index` for the `char`
\\/// If found, returns the index of the node within the `dafsa` array.
\\/// Otherwise, returns `null`.
\\fn findInList(first_child_index: u16, char: u8) ?u16 {
\\pub fn findInList(first_child_index: u16, char: u8) ?u16 {
\\ var index = first_child_index;
\\ while (true) {
\\ if (dafsa[index].char == char) return index;
Expand All @@ -264,7 +264,7 @@ fn generate(self: *GenerateDef, input: []const u8) ![]const u8 {
\\
\\/// Returns a unique (minimal perfect hash) index (starting at 1) for the `name`,
\\/// or null if the name was not found.
\\fn uniqueIndex(name: []const u8) ?u16 {
\\pub fn uniqueIndex(name: []const u8) ?u16 {
\\ if (name.len < shortest_name or name.len > longest_name) return null;
\\
\\ var index: u16 = 0;
Expand Down Expand Up @@ -295,7 +295,7 @@ fn generate(self: *GenerateDef, input: []const u8) ![]const u8 {
\\/// This function should only be called with an `index` that
\\/// is already known to exist within the `dafsa`, e.g. an index
\\/// returned from `uniqueIndex`.
\\fn nameFromUniqueIndex(index: u16, buf: []u8) []u8 {
\\pub fn nameFromUniqueIndex(index: u16, buf: []u8) []u8 {
\\ std.debug.assert(index >= 1 and index <= data.len);
\\
\\ var node_index: u16 = 0;
Expand Down Expand Up @@ -369,7 +369,7 @@ fn generate(self: *GenerateDef, input: []const u8) ![]const u8 {
}

fn writeData(writer: anytype, values: []const Value) !void {
try writer.writeAll("const data = blk: {\n");
try writer.writeAll("pub const data = blk: {\n");
try writer.print(" @setEvalBranchQuota({});\n", .{values.len});
try writer.writeAll(" break :blk [_]@This(){\n");
for (values, 0..) |value, i| {
Expand Down
Loading

0 comments on commit f85b310

Please sign in to comment.