Skip to content

Commit

Permalink
implement basic builder
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgmbb committed Dec 16, 2023
1 parent 57325e4 commit 0e796bc
Show file tree
Hide file tree
Showing 29 changed files with 2,909 additions and 1,265 deletions.
388 changes: 257 additions & 131 deletions bootstrap/Compilation.zig

Large diffs are not rendered by default.

842 changes: 594 additions & 248 deletions bootstrap/backend/c_transpiler.zig

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions bootstrap/data_structures.zig
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn BlockList(comptime T: type) type {

return struct {
// TODO: make this not reallocate the whole block. Instead, use a pointer to the block as the ArrayList item
blocks: ArrayList(Block) = .{},
blocks: ArrayList(*Block) = .{},
len: usize = 0,
first_block: u32 = 0,

Expand Down Expand Up @@ -136,7 +136,7 @@ pub fn BlockList(comptime T: type) type {
const max_allocation = list.blocks.items.len * item_count;
const result = switch (list.len < max_allocation) {
true => blk: {
const block = &list.blocks.items[list.first_block];
const block = list.blocks.items[list.first_block];
if (block.allocateIndex()) |element_index| {
break :blk Index{
.element = element_index,
Expand All @@ -148,13 +148,11 @@ pub fn BlockList(comptime T: type) type {
},
false => blk: {
const block_index = list.blocks.items.len;
const new_block = list.blocks.addOneAssumeCapacity();
const new_block = try allocator.create(Block);
new_block.* = .{};
list.blocks.appendAssumeCapacity(new_block);
const element_index = new_block.allocateIndex() catch unreachable;
const ptr = &new_block.items[element_index];
_ = ptr;
list.first_block += @intFromBool(block_index != 0);

break :blk Index{
.element = element_index,
.block = @intCast(block_index),
Expand Down
5 changes: 4 additions & 1 deletion bootstrap/frontend/lexical_analyzer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const File = Compilation.File;
const logln = Compilation.logln;
const fs = @import("../fs.zig");

pub const Token = packed struct(u64) {
// TODO: switch to packed struct when speed is important
pub const Token = struct {
start: u32,
len: u24,
id: Id,
Expand Down Expand Up @@ -85,6 +86,7 @@ pub const Token = packed struct(u64) {
fixed_keyword_cc = 0x98,
fixed_keyword_for = 0x99,
fixed_keyword_undefined = 0x9a,
fixed_keyword_break = 0x9b,
};

pub const Index = u32;
Expand Down Expand Up @@ -119,6 +121,7 @@ pub const FixedKeyword = enum {
cc,
@"for",
undefined,
@"break",
};

pub const Result = struct {
Expand Down
1,893 changes: 1,252 additions & 641 deletions bootstrap/frontend/semantic_analyzer.zig

Large diffs are not rendered by default.

Loading

0 comments on commit 0e796bc

Please sign in to comment.