Much better allocation strategy with new ncore arenas. Add more builtin node gen stuff. It's kind of wonky.

This commit is contained in:
2025-09-06 23:30:45 +02:00
parent 9cf51a1534
commit f4a9592f26
6 changed files with 133 additions and 36 deletions

View File

@@ -388,9 +388,84 @@ make_node :: (parse_state : *Parse_State, kind : AST_Kind) -> *AST_Node {
// return node;
// }
// new_builtin_struct_node :: (nodes : *[..]AST_Node, name : string, member_names : []string, allocator : Allocator) -> *AST_Node {
make_builtin_token :: (builder : *String_Builder, kind : Token_Kind, text : string, col : *int, line : *int) -> Token {
tok : Token;
tok.kind = kind;
start := 0;
buffer := get_current_buffer(builder);
if buffer {
start := buffer.count;
}
// }
print_to_builder(builder, "%", text);
buffer = get_current_buffer(builder);
end := buffer.count;
for c : text {
if c == #char "\n" {
line.* ++ 1;
col.* = 0;
} else {
col.* += 1;
}
}
tok.column = col.*;
tok.index = buffer.count;
tok.length = text.count;
tok.builtin = true;
return tok;
}
new_builtin_struct_node :: (result : *Compile_Result, name : string, members : []Arg, allocator : Allocator) -> *AST_Node {
sc := get_scratch(result, allocator);
defer scratch_end(sc);
builder : String_Builder;
builder.allocator = sc.allocator; // I want to find a good way to use scratch here...
node := make_node(*result.nodes, .Struct, allocator);
col := 0;
line := 0;
tok_index := result.tokens.count;
array_add(*result.tokens, make_builtin_token(*builder, .TOKEN_IDENTIFIER, tprint("%", name), *col, *line));
append(*builder, " ");
array_add(*result.tokens, make_builtin_token(*builder, .TOKEN_DOUBLECOLON, "::", *col, *line));
append(*builder, " ");
array_add(*result.tokens, make_builtin_token(*builder, .TOKEN_STRUCT, "struct", *col, *line));
append(*builder, " ");
array_add(*result.tokens, make_builtin_token(*builder, .TOKEN_LEFTBRACE, "{", *col, *line));
append(*builder, "\n");
for member : members {
// @Incomplete: Missing field list
array_add(*result.tokens, make_builtin_token(*builder, .TOKEN_IDENTIFIER, tprint("%", member.name), *col, *line));
append(*builder, " ");
array_add(*result.tokens, make_builtin_token(*builder, .TOKEN_COLON, ":", *col, *line));
append(*builder, " ");
array_add(*result.tokens, make_builtin_token(*builder, .TOKEN_IDENTIFIER, tprint("%", member.typename), *col, *line));
array_add(*result.tokens, make_builtin_token(*builder, .TOKEN_SEMICOLON, ";", *col, *line));
append(*builder, "\n");
}
array_add(*result.tokens, make_builtin_token(*builder, .TOKEN_RIGHTBRACE, "}", *col, *line));
append(*builder, "\n");
source := builder_to_string(*builder,, allocator);
for i : tok_index..result.tokens.count - 1 {
tok := *result.tokens[i];
tok.source = *source.data[tok.column];
}
return node;
}
add_child :: (node : *AST_Node, child : *AST_Node) {
child.parent = node;