Compare commits

...

5 Commits

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");
body := node.children[1];
indent(builder,indentation + 4);
append(builder, "(");
pretty_print_node(body, indentation + 5, builder, true);
append(builder, ")");
// indent(builder,indentation + 4);
// append(builder, "(");
pretty_print_node(body, indentation + 4, builder);
// append(builder, ")");
if node.children.count == 3 {
append(builder, "\n");

View File

@@ -21,7 +21,7 @@ Parse_State :: struct {
child_allocator : Allocator;
child_arena : Arena;
had_error : bool;
// had_error : bool;
path : string;
@@ -792,6 +792,9 @@ argument_list :: (parse_state : *Parse_State) -> *AST_Node {
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) {
arg := expression(parse_state);
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.");
if node {

View File

@@ -1629,7 +1629,7 @@ types_compatible :: (checker : *Semantic_Checker, lhs : Type_Variable_Handle, rh
lhs_node := lhs_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 == {
case "float2"; #through;
case "float3"; #through;
@@ -2083,7 +2083,7 @@ pretty_print_symbol_table :: (result : *Compile_Result, allocator : Allocator) -
init_string_builder(*builder,, allocator);
for *file : result.files {
current_scope := cast(Scope_Handle)0;
current_scope := cast(Scope_Handle)1;
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);

132
Test.jai
View File

@@ -119,40 +119,40 @@ get_golden_path :: (file_path : string, stage : Stage_Flags, allocator := contex
return final_path;
}
run_lexer_test :: (file_path : string, lexer : *Lexer, output_type : Output_Type = 0) -> Result {
ok := read_input_from_file(lexer, file_path);
// run_lexer_test :: (file_path : string, lexer : *Lexer, output_type : Output_Type = 0) -> Result {
// ok := read_input_from_file(lexer, file_path);
result_data : Result;
result_data.path = file_path;
result_data.stage = .Lexer;
// result_data : Result;
// result_data.path = file_path;
// result_data.stage = .Lexer;
if !ok {
result_data.type = .File_Read_Failed;
result_data.info_text = tprint("Unable to read file: %\n", file_path);
// if !ok {
// result_data.type = .File_Read_Failed;
// result_data.info_text = tprint("Unable to read file: %\n", file_path);
return result_data;
} else {
result_text : string;
result := lex(lexer, *temp);
// return result_data;
// } else {
// result_text : string;
// result := lex(lexer, *temp);
if result.had_error {
result_data.type = .Failed;
result_text = report_messages(result.messages);
} else {
result_text = pretty_print_tokens(result.tokens, *temp);
}
// if result.had_error {
// result_data.type = .Failed;
// result_text = report_messages(result.messages);
// } else {
// result_text = pretty_print_tokens(result.tokens, *temp);
// }
if output_type & .StdOut {
result_data.info_text = result_text;
result_data.type = .StdOut;
return result_data;
}
// if output_type & .StdOut {
// result_data.info_text = result_text;
// result_data.type = .StdOut;
// return result_data;
// }
golden_path := get_golden_path(file_path, .Lexer);
do_golden_comparison(golden_path, result_text, *result_data, output_type);
return result_data;
}
}
// golden_path := get_golden_path(file_path, .Lexer);
// do_golden_comparison(golden_path, result_text, *result_data, output_type);
// return result_data;
// }
// }
run_parser_test :: (file_path : string, output_type : Output_Type = 0) -> Result, *AST_Node {
lexer : Lexer;
@@ -490,14 +490,11 @@ run_parser_test :: (result : *Compile_Result, output_type : Output_Type = 0) ->
return result_data;
}
run_semantic_analysis_test :: (file_path : string, result : *Compile_Result, output_type : Output_Type = 0) -> Result {
add_file(result, file_path);
run_semantic_analysis_test :: (result : *Compile_Result, output_type : Output_Type = 0) -> Result {
result_data : Result;
result_data.path = file_path;
result_data.stage = .Semantic_Analysis;
result_data.path = result.files[0].file.path;
result_text : string;
check(result);
if result.had_error {
@@ -513,11 +510,29 @@ run_semantic_analysis_test :: (file_path : string, result : *Compile_Result, out
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);
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 {
test_case : Test_Case;
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) {
print("%Running test: %......", cyan(), test_case.path);
@@ -631,7 +602,8 @@ run_test :: (test_case : Test_Case, results : *[..]Result, output_type : Output_
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) {

View File

@@ -8,11 +8,11 @@ float4 vs_main(float3 pos : POSITION) : SV_POSITION
}
else
{
return float4(1.0f);
return float4(1.0f, 1.0f, 1.0f, 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
{
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(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
{
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) [
[properties] : {color : float4}
[pixel__ps_main] : () -> float4
[vertex__vs_main] : (pos : float3) -> float3
[properties] : {color : float4}
scope (properties) [
[color] : float4
]

View File

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

View File

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