More fixes to access and buffer compilation.

This commit is contained in:
2025-09-26 07:01:06 +02:00
parent 6528ca854b
commit 63a68b70b4
35 changed files with 401 additions and 119 deletions

View File

@@ -146,13 +146,20 @@ emit_field :: (state : *Codegen_State, node : *AST_Node, indentation : int) {
}
emit_block :: (state : *Codegen_State, node : *AST_Node, indentation : int) {
previous_scope := state.current_scope;
for statement : node.children {
if statement.type_variable {
state.current_scope = from_handle(state.ctx.type_variables, statement.type_variable).scope;
}
emit_node(state, statement, indentation);
if it_index < node.children.count {
append(*state.builder, "\n");
}
}
state.current_scope = previous_scope;
}
emit_call :: (state : *Codegen_State, node : *AST_Node, indentation : int) {
@@ -379,11 +386,24 @@ emit_node :: (state : *Codegen_State, node : *AST_Node, indentation : int) {
emit_node(state, node.children[0], 0);
}
}
case .Access; {
indent(*state.builder, indentation);
lhs := node.children[0];
rhs := node.children[1];
emit_node(state, lhs, 0);
print_to_builder(*state.builder, "%.", node.name);
emit_node(state, rhs, 0);
}
case .Binary; {
indent(*state.builder, indentation);
if node.token.kind != .TOKEN_ASSIGN && node.token.kind != .TOKEN_LEFTBRACKET {
append(*state.builder, "(");
if node.parent.kind == .Binary && node.parent.token.kind != .TOKEN_ASSIGN {
append(*state.builder, "(");
}
}
lhs := node.children[0];
@@ -405,7 +425,9 @@ emit_node :: (state : *Codegen_State, node : *AST_Node, indentation : int) {
if node.token.kind != .TOKEN_ASSIGN && node.token.kind != .TOKEN_LEFTBRACKET {
append(*state.builder, ")");
if node.parent.kind == .Binary && node.parent.token.kind != .TOKEN_ASSIGN {
append(*state.builder, ")");
}
}
}
case .Unary; {
@@ -455,7 +477,9 @@ emit_node :: (state : *Codegen_State, node : *AST_Node, indentation : int) {
append(*state.builder, "if ");
cond := node.children[0];
append(*state.builder, "(");
emit_node(state, cond, 0);
append(*state.builder, ")");
body := node.children[1];
append(*state.builder, "\n");
@@ -543,6 +567,17 @@ emit_cbuffer :: (state : *Codegen_State, node : *AST_Node, indentation : int) {
state.current_scope = current_scope;
}
emit_buffer :: (state : *Codegen_State, node : *AST_Node, indentation : int) {
variable := from_handle(state.ctx.type_variables, node.type_variable);
element := from_handle(state.ctx.type_variables, variable.element_type);
emit_struct(state, node, indentation);
// print_to_builder(*state.builder, "struct %\n", element.name);
print_to_builder(*state.builder, "StructuredBuffer<%> %;\n\n", element.typename, variable.name);
}
emit_declaration :: (state : *Codegen_State, node : *AST_Node) {
if node.kind == {
case .Function; {
@@ -551,6 +586,9 @@ emit_declaration :: (state : *Codegen_State, node : *AST_Node) {
case .CBuffer; {
emit_cbuffer(state, node, 0);
}
case .Buffer; {
emit_buffer(state, node, 0);
}
case .Struct; {
emit_struct(state, node, 0);
}