Fix error propagation error in parsing. Semantic checker fix for compile result struct. Test cleanup

This commit is contained in:
2025-08-18 07:11:41 +02:00
parent c36712b3ed
commit b7e34a22b2
11 changed files with 76 additions and 99 deletions

View File

@@ -296,10 +296,10 @@ pretty_print_if :: (node : *AST_Node, indentation : int, builder : *String_Build
append(builder, "\n"); append(builder, "\n");
body := node.children[1]; body := node.children[1];
indent(builder,indentation + 4); // indent(builder,indentation + 4);
append(builder, "("); // append(builder, "(");
pretty_print_node(body, indentation + 5, builder, true); pretty_print_node(body, indentation + 4, builder);
append(builder, ")"); // append(builder, ")");
if node.children.count == 3 { if node.children.count == 3 {
append(builder, "\n"); append(builder, "\n");

View File

@@ -21,7 +21,7 @@ Parse_State :: struct {
child_allocator : Allocator; child_allocator : Allocator;
child_arena : Arena; child_arena : Arena;
had_error : bool; // had_error : bool;
path : string; path : string;
@@ -792,6 +792,9 @@ argument_list :: (parse_state : *Parse_State) -> *AST_Node {
source_location.main_token = parse_state.current; source_location.main_token = parse_state.current;
error_before := parse_state.result.had_error;
parse_state.result.had_error = false;
while !check(parse_state, .TOKEN_RIGHTPAREN) { while !check(parse_state, .TOKEN_RIGHTPAREN) {
arg := expression(parse_state); arg := expression(parse_state);
if !node { if !node {
@@ -808,6 +811,8 @@ argument_list :: (parse_state : *Parse_State) -> *AST_Node {
} }
} }
parse_state.result.had_error = error_before || parse_state.result.had_error;
consume(parse_state, .TOKEN_RIGHTPAREN, "Expect ')' after function call."); consume(parse_state, .TOKEN_RIGHTPAREN, "Expect ')' after function call.");
if node { if node {

View File

@@ -1625,11 +1625,11 @@ types_compatible :: (checker : *Semantic_Checker, lhs : Type_Variable_Handle, rh
case .Texture2D; { case .Texture2D; {
return rhs_var.type == lhs_var.type; return rhs_var.type == lhs_var.type;
} }
case .Struct; { case .Struct; {
lhs_node := lhs_var.source_node; lhs_node := lhs_var.source_node;
rhs_node := rhs_var.source_node; rhs_node := rhs_var.source_node;
if rhs_var.type != .Struct { if rhs_var.type != .Struct && !param_matching {
if lhs_var.typename == { if lhs_var.typename == {
case "float2"; #through; case "float2"; #through;
case "float3"; #through; case "float3"; #through;
@@ -2083,7 +2083,7 @@ pretty_print_symbol_table :: (result : *Compile_Result, allocator : Allocator) -
init_string_builder(*builder,, allocator); init_string_builder(*builder,, allocator);
for *file : result.files { for *file : result.files {
current_scope := cast(Scope_Handle)0; current_scope := cast(Scope_Handle)1;
check_result := file.semantic_check_result; check_result := file.semantic_check_result;
pretty_print_scope(current_scope, check_result.scope_stack, check_result.type_variables, *check_result.scope_stack.stack[0], *builder); pretty_print_scope(current_scope, check_result.scope_stack, check_result.type_variables, *check_result.scope_stack.stack[0], *builder);

134
Test.jai
View File

@@ -119,40 +119,40 @@ get_golden_path :: (file_path : string, stage : Stage_Flags, allocator := contex
return final_path; return final_path;
} }
run_lexer_test :: (file_path : string, lexer : *Lexer, output_type : Output_Type = 0) -> Result { // run_lexer_test :: (file_path : string, lexer : *Lexer, output_type : Output_Type = 0) -> Result {
ok := read_input_from_file(lexer, file_path); // ok := read_input_from_file(lexer, file_path);
result_data : Result; // result_data : Result;
result_data.path = file_path; // result_data.path = file_path;
result_data.stage = .Lexer; // result_data.stage = .Lexer;
if !ok { // if !ok {
result_data.type = .File_Read_Failed; // result_data.type = .File_Read_Failed;
result_data.info_text = tprint("Unable to read file: %\n", file_path); // result_data.info_text = tprint("Unable to read file: %\n", file_path);
return result_data; // return result_data;
} else { // } else {
result_text : string; // result_text : string;
result := lex(lexer, *temp); // result := lex(lexer, *temp);
if result.had_error { // if result.had_error {
result_data.type = .Failed; // result_data.type = .Failed;
result_text = report_messages(result.messages); // result_text = report_messages(result.messages);
} else { // } else {
result_text = pretty_print_tokens(result.tokens, *temp); // result_text = pretty_print_tokens(result.tokens, *temp);
} // }
if output_type & .StdOut { // if output_type & .StdOut {
result_data.info_text = result_text; // result_data.info_text = result_text;
result_data.type = .StdOut; // result_data.type = .StdOut;
return result_data; // return result_data;
} // }
golden_path := get_golden_path(file_path, .Lexer); // golden_path := get_golden_path(file_path, .Lexer);
do_golden_comparison(golden_path, result_text, *result_data, output_type); // do_golden_comparison(golden_path, result_text, *result_data, output_type);
return result_data; // return result_data;
} // }
} // }
run_parser_test :: (file_path : string, output_type : Output_Type = 0) -> Result, *AST_Node { run_parser_test :: (file_path : string, output_type : Output_Type = 0) -> Result, *AST_Node {
lexer : Lexer; lexer : Lexer;
@@ -490,14 +490,11 @@ run_parser_test :: (result : *Compile_Result, output_type : Output_Type = 0) ->
return result_data; return result_data;
} }
run_semantic_analysis_test :: (file_path : string, result : *Compile_Result, output_type : Output_Type = 0) -> Result { run_semantic_analysis_test :: (result : *Compile_Result, output_type : Output_Type = 0) -> Result {
add_file(result, file_path);
result_data : Result; result_data : Result;
result_data.path = result.files[0].file.path;
result_data.path = file_path;
result_data.stage = .Semantic_Analysis;
result_text : string; result_text : string;
check(result); check(result);
if result.had_error { if result.had_error {
@@ -513,11 +510,29 @@ run_semantic_analysis_test :: (file_path : string, result : *Compile_Result, out
return result_data; return result_data;
} }
golden_path := get_golden_path(file_path, .Semantic_Analysis); golden_path := get_golden_path(result.files[0].file.path, .Semantic_Analysis);
do_golden_comparison(golden_path, result_text, *result_data, output_type); do_golden_comparison(golden_path, result_text, *result_data, output_type);
return result_data; return result_data;
} }
run_semantic_analysis_test :: (file_path : string, result : *Compile_Result, output_type : Output_Type = 0) -> Result {
add_file(result, file_path);
result_data : Result;
result_data.path = file_path;
lex(result);
parse(result);
if result.had_error {
result_data.type = .Passed;
return result_data;
}
result_data = run_semantic_analysis_test(result, output_type);;
return result_data;
}
make_test_case :: (path : string, stage_flags : Stage_Flags, allocator := context.allocator) -> Test_Case { make_test_case :: (path : string, stage_flags : Stage_Flags, allocator := context.allocator) -> Test_Case {
test_case : Test_Case; test_case : Test_Case;
test_case.path = copy_string(path,, allocator); test_case.path = copy_string(path,, allocator);
@@ -569,50 +584,6 @@ run_test_new :: (file_path : string, stage_flags : Stage_Flags, results : *[..]R
// } // }
} }
run_test :: (file_path : string, stage_flags : Stage_Flags, results : *[..]Result, output_type : Output_Type = 0) {
lexer : Lexer;
result : Result;
if stage_flags & .Lexer {
result = run_lexer_test(file_path, *lexer, output_type);
record_result(results, result);
}
root_node : *AST_Node;
if stage_flags & .Parser {
if stage_flags & .Lexer && result.type == .Passed || result.type == .Golden_Output {
result, root_node = run_parser_test(*lexer, output_type);
} else {
result, root_node = run_parser_test(file_path, output_type);
}
record_result(results, result);
}
check_result : Semantic_Check_Result;
if stage_flags & .Semantic_Analysis {
if stage_flags & .Parser && (result.type == .Passed || result.type == .Golden_Output) {
result, check_result = run_semantic_analysis_test(file_path, root_node, output_type);
} else {
result, check_result = run_semantic_analysis_test(file_path, output_type);
}
record_result(results, result);
}
if stage_flags & .Codegen {
if stage_flags & .Semantic_Analysis && (result.type == .Passed || result.type == .Golden_Output) {
result = run_codegen_test(file_path, root_node, check_result, output_type);
} else if root_node {
result = run_codegen_test(file_path, root_node, output_type);
} else {
result = run_codegen_test(file_path, output_type);
}
record_result(results, result);
}
if stage_flags & .Compile {
result = run_compile_test(file_path, output_type);
}
}
run_test :: (test_case : Test_Case, results : *[..]Result, output_type : Output_Type = 0) { run_test :: (test_case : Test_Case, results : *[..]Result, output_type : Output_Type = 0) {
print("%Running test: %......", cyan(), test_case.path); print("%Running test: %......", cyan(), test_case.path);
@@ -630,8 +601,9 @@ run_test :: (test_case : Test_Case, results : *[..]Result, output_type : Output_
for i: 0..rest { for i: 0..rest {
print(" "); print(" ");
} }
run_test(test_case.path, test_case.stage_flags, results, output_type); run_test_new(test_case.path, test_case.stage_flags, results, output_type);
// run_test(test_case.path, test_case.stage_flags, results, output_type);
} }
record_result :: (results : *[..]Result, result : Result) { record_result :: (results : *[..]Result, result : Result) {

View File

@@ -8,11 +8,11 @@ float4 vs_main(float3 pos : POSITION) : SV_POSITION
} }
else else
{ {
return float4(1.0f); return float4(1.0f, 1.0f, 1.0f, 1.0f);
} }
return float4(pos, 1.0f); return float4(pos, 1.0f);
} }
return float4(0.0f); return float4(0.0f, 0.0f, 0.0f, 0.0f);
} }

View File

@@ -10,8 +10,8 @@ float4 vs_main(float3 pos : POSITION) : SV_POSITION
} }
else else
{ {
return float4(1.0f); return float4(1.0f, 1.0f, 1.0f, 1.0f);
} }
return float4(0.0f); return float4(0.0f, 0.0f, 0.0f, 0.0f);
} }

View File

@@ -5,6 +5,6 @@ float4 vs_main(float3 pos : POSITION) : SV_POSITION
return float4(pos, 1.0f); return float4(pos, 1.0f);
} }
return float4(0.0f); return float4(0.0f, 0.0f, 0.0f, 0.0f);
} }

View File

@@ -6,8 +6,8 @@ float4 vs_main(float3 pos : POSITION) : SV_POSITION
} }
else else
{ {
return float4(1.0f); return float4(1.0f, 1.0f, 1.0f, 1.0f);
} }
return float4(0.0f); return float4(0.0f, 0.0f, 0.0f, 0.0f);
} }

View File

@@ -1,7 +1,7 @@
scope (global) [ scope (global) [
[properties] : {color : float4}
[pixel__ps_main] : () -> float4 [pixel__ps_main] : () -> float4
[vertex__vs_main] : (pos : float3) -> float3 [vertex__vs_main] : (pos : float3) -> float3
[properties] : {color : float4}
scope (properties) [ scope (properties) [
[color] : float4 [color] : float4
] ]

View File

@@ -1,7 +1,7 @@
scope (global) [ scope (global) [
[camera] : {projection : float4x4, view : float4x4}
[pixel__ps_main] : () -> float4 [pixel__ps_main] : () -> float4
[vertex__vs_main] : (pos : float4) -> float4 [vertex__vs_main] : (pos : float4) -> float4
[camera] : {projection : float4x4, view : float4x4}
scope (camera) [ scope (camera) [
[projection] : float4x4 [projection] : float4x4
[view] : float4x4 [view] : float4x4

View File

@@ -1,7 +1,7 @@
scope (global) [ scope (global) [
[props] : {color : float4}
[pixel__ps_main] : () -> float4 [pixel__ps_main] : () -> float4
[vertex__vs_main] : (pos : float4) -> float4 [vertex__vs_main] : (pos : float4) -> float4
[props] : {color : float4}
scope (props) [ scope (props) [
[color] : float4 [color] : float4
] ]