Anonymous user
Compiler/code generator: Difference between revisions
m
Update Zig to 0.9.0
(Add Zig language implementation) |
m (Update Zig to 0.9.0) |
||
Line 5,907:
pub const CodeGenerator = struct {
allocator:
string_pool: std.ArrayList([]const u8),
globals: std.ArrayList([]const u8),
Line 5,916:
pub fn init(
allocator:
string_pool: std.ArrayList([]const u8),
globals: std.ArrayList([]const u8),
Line 6,231:
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
var arg_it = std.process.args();
Line 6,330:
value: ?NodeValue = null,
fn makeNode(allocator:
const result = try allocator.create(Tree);
result.* = Tree{ .left = left, .right = right, .typ = typ };
Line 6,336:
}
fn makeLeaf(allocator:
const result = try allocator.create(Tree);
result.* = Tree{ .left = null, .right = null, .typ = typ, .value = value };
Line 6,346:
fn loadAST(
allocator:
str: []const u8,
string_pool: *std.ArrayList([]const u8),
globals: *std.ArrayList([]const u8),
) LoadASTError!?*Tree {
var line_it = std.mem.split(u8, str, "\n");
return try loadASTHelper(allocator, &line_it, string_pool, globals);
}
fn loadASTHelper(
allocator:
line_it: *std.mem.SplitIterator(u8),
string_pool: *std.ArrayList([]const u8),
globals: *std.ArrayList([]const u8),
) LoadASTError!?*Tree {
if (line_it.next()) |line| {
var tok_it = std.mem.tokenize(u8, line, " ");
const tok_str = tok_it.next().?;
if (tok_str[0] == ';') return null;
Line 6,409:
return null;
}
}
</lang>
|