Fixed a bunch of semant back and forth but now it looks like I broke some parameter checking in functions.

This commit is contained in:
2025-08-14 14:04:54 +02:00
parent af42b61ed6
commit 6b6c7bce62
3 changed files with 208 additions and 198 deletions

View File

@@ -215,13 +215,13 @@ from_files :: (paths : []string) -> Compile_Result {
return result;
}
Compilation_Result :: struct {
messages : [..]Compiler_Message;
// Compilation_Result :: struct {
// messages : [..]Compiler_Message;
had_error : bool;
// had_error : bool;
collection : Shader_Variant_Collection;
}
// collection : Shader_Variant_Collection;
// }
pretty_print_field :: (field : *Field) -> string {
builder : String_Builder;
@@ -492,146 +492,3 @@ compile_file :: (compiler : *Shader_Compiler, paths : []string) -> Compile_Resul
return result;
}
compile_file :: (compiler : *Shader_Compiler, path : string) -> Compilation_Result {
result : Compilation_Result;
lexer : Lexer;
init_lexer_from_file(*lexer, path);
if lexer.result.had_error {
copy_messages(lexer.result.messages, *result.messages);
result.had_error = true;
return result;
}
lex_result := lex(*lexer,, *temp);
if lex_result.had_error {
copy_messages(lex_result.messages, *result.messages);
result.had_error = true;
return result;
}
parse_state : Parse_State;
init_parse_state(*parse_state, lex_result.tokens, lexer.path);
parse_result := parse(*parse_state);
if parse_result.had_error {
copy_messages(parse_result.messages, *result.messages);
result.had_error = true;
return result;
}
checker : Semantic_Checker;
init_semantic_checker(*checker, parse_result.root, path);
check_result := check(*checker);
if check_result.had_error {
copy_messages(check_result.messages, *result.messages);
result.had_error = true;
return result;
}
state : Codegen_State;
init_codegen_state(*state, parse_result.root, check_result, .HLSL);
result_text : string;
codegen_result := codegen(*state);
if codegen_result.had_error {
copy_messages(codegen_result.messages, *result.messages);
result.had_error = true;
return result;
}
// @Incomplete(nb): Assumes only a single variant for now
variant : Shader_Variant;
variant.text = codegen_result.result_text;
if checker.result.vertex_entry_point {
variant.vertex_entry_point.name = checker.result.vertex_entry_point.name;
type_variable := from_handle(*checker, checker.result.vertex_entry_point.type_variable);
assert(type_variable.type == .Function);
node := type_variable.source_node;
if node.children.count > 0 {
if node.children[0].kind == .FieldList {
field_list := node.children[0];
for child : field_list.children {
tv := from_handle(*checker, child.type_variable);
field := type_variable_to_field(*checker, tv);
array_add(*variant.vertex_entry_point.input, field);
}
}
}
}
for buffer_variable : to_array(*check_result.constant_buffers) {
variable := from_handle(check_result.type_variables, buffer_variable);
cb := array_add(*result.collection.cbuffers);
for i : 0..variable.children.count - 1 {
child := variable.children[i];
field : Property_Field;
field.base_field = type_variable_to_field(*checker, from_handle(*checker, child));;
array_add(*cb.fields, field);
}
cb.buffer_index = variable.resource_index;
}
find_result := find_symbol(*check_result.scope_stack, check_result.property_name, xx 1);
if find_result {
property_variable := from_handle(check_result.type_variables, find_result.type_variable);
for i : 0..property_variable.children.count - 1 {
child := property_variable.children[i];
field := type_variable_to_field(*checker, from_handle(*checker, child));
prop_field : Property_Field;
prop_field.base_field = field;
array_add(*result.collection.properties.fields, prop_field);
}
result.collection.properties.buffer_index = property_variable.resource_index;
}
if checker.result.pixel_entry_point {
variant.pixel_entry_point.name = checker.result.pixel_entry_point.name;
type_variable := from_handle(*checker, checker.result.pixel_entry_point.type_variable);
assert(type_variable.type == .Function);
field := type_variable_to_field(*checker, type_variable.return_type_variable);
for hint : type_variable.source_node.hint_tokens {
field_hint : Field_Hint;
if hint.ident_value == "position" {
// @Incomplete(nb): Should be a lookup table somewhere
field_hint.kind = .Position;
} else if starts_with(hint.ident_value, "target") {
// @Incomplete(nb): Should be a lookup table somewhere
index_str : string;
index_str.data = *hint.ident_value.data[7];
index_str.count = 1;
result, ok, remainder := string_to_int(index_str);
if ok {
field_hint.target_index = result;
}
field_hint.kind = .Target;
} else {
// @Incomplete(nb): custo hints
}
array_add(*field.hints, field_hint);
}
variant.pixel_entry_point.return_value = field;
}
array_add(*result.collection.variants, variant);
return result;
}