Compare commits

..

3 Commits

4 changed files with 75 additions and 34 deletions

View File

@@ -1435,9 +1435,13 @@ check_node :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Variable_H
variable, handle := new_type_variable(checker); variable, handle := new_type_variable(checker);
lhs_type := from_handle(checker, lhs_var); lhs_type := from_handle(checker, lhs_var);
variable.type = lhs_type.type; rhs_type := from_handle(checker, rhs_var);
variable.type = lhs_type.type;
variable.typename = lhs_type.typename; variable.typename = lhs_type.typename;
variable.scope = lhs_type.scope; variable.scope = lhs_type.scope;
variable.source_node = node; variable.source_node = node;
node.type_variable = handle; node.type_variable = handle;
add_child(variable, lhs_var); add_child(variable, lhs_var);
@@ -1452,6 +1456,16 @@ check_node :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Variable_H
type_mismatch(checker, node, node.children[1], lhs_var, rhs_var); type_mismatch(checker, node, node.children[1], lhs_var, rhs_var);
return 0; return 0;
} }
if lhs_type.type == .Struct {
variable.type = lhs_type.type;
variable.typename = lhs_type.typename;
variable.scope = lhs_type.scope;
} else if rhs_type.type == .Struct {
variable.type = rhs_type.type;
variable.typename = rhs_type.typename;
variable.scope = rhs_type.scope;
}
} }
case .TOKEN_ASSIGN; { case .TOKEN_ASSIGN; {
if !types_compatible(checker, lhs_var, rhs_var) { if !types_compatible(checker, lhs_var, rhs_var) {

View File

@@ -201,7 +201,7 @@ run_codegen_test :: (result : *Compile_Result, output_type : Output_Type = 0) ->
run_compile_test :: (path : string, output_type : Output_Type = 0) -> Result, Compile_Result { run_compile_test :: (path : string, output_type : Output_Type = 0) -> Result, Compile_Result {
compiler : Shader_Compiler; compiler : Shader_Compiler;
result : Result; result : Result;
compilation_result := compile_file(*compiler, .[path]); compilation_result := compile_file(*compiler, path);
print("\n"); print("\n");
if compilation_result.had_error { if compilation_result.had_error {
@@ -372,8 +372,8 @@ run_test_new :: (file_path : string, stage_flags : Stage_Flags, results : *[..]R
} }
} }
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, builder : *String_Builder) {
print("%Running test: %......", cyan(), test_case.path); print_to_builder(builder, "%Running test: %......", cyan(), test_case.path);
// path 30 // path 30
// len 35 // len 35
@@ -387,7 +387,7 @@ run_test :: (test_case : Test_Case, results : *[..]Result, output_type : Output_
len := 50; len := 50;
rest := len - test_case.path.count; rest := len - test_case.path.count;
for i: 0..rest { for i: 0..rest {
print(" "); append(builder, " ");
} }
run_test_new(test_case.path, test_case.stage_flags, results, output_type); run_test_new(test_case.path, test_case.stage_flags, results, output_type);
@@ -416,7 +416,7 @@ run_test_suite :: (using suite : *Test_Suite, output_type : Output_Type = 0) {
init_string_builder(*builder,, temp); init_string_builder(*builder,, temp);
for test_case : test_cases { for test_case : test_cases {
run_test(test_case, *suite.results, output_type); run_test(test_case, *suite.results, output_type, *builder);
for < suite.results { for < suite.results {
result := suite.results[it_index]; result := suite.results[it_index];
@@ -432,7 +432,7 @@ run_test_suite :: (using suite : *Test_Suite, output_type : Output_Type = 0) {
array_add(*failed_test_paths, .{ result.path, tprint("golden file not found for %", stage_to_string(result.stage)) }); array_add(*failed_test_paths, .{ result.path, tprint("golden file not found for %", stage_to_string(result.stage)) });
} }
} }
evaluate_result(result); evaluate_result(result, *builder);
} else { } else {
break; break;
} }
@@ -440,7 +440,7 @@ run_test_suite :: (using suite : *Test_Suite, output_type : Output_Type = 0) {
// print("\n"); // print("\n");
} }
print("\n"); append(*builder, "\n");
if output_type == 0 { if output_type == 0 {
if failed_test_paths.count == 0 { if failed_test_paths.count == 0 {
@@ -530,42 +530,42 @@ stage_to_string :: (stage : Stage_Flags) -> string {
} }
} }
evaluate_result :: (result : Result) { evaluate_result :: (result : Result, builder : *String_Builder) {
stage : string = stage_to_string(result.stage); stage : string = stage_to_string(result.stage);
if #complete result.type == { if #complete result.type == {
case .File_Read_Failed; { case .File_Read_Failed; {
print(" %", red()); print_to_builder(builder, " %", red());
print("failed with File_Read_Failed\n"); print_to_builder(builder, "failed with File_Read_Failed\n");
} }
case .Golden_File_Not_Found; { case .Golden_File_Not_Found; {
print(" %", red()); print_to_builder(builder, " %", red());
print("failed with Golden File Not Found for stage %\n", stage); print_to_builder(builder, "failed with Golden File Not Found for stage %\n", stage);
} }
case .StdOut; { case .StdOut; {
} }
case .Golden_Output; { case .Golden_Output; {
print(" %", yellow()); print_to_builder(builder, " %", yellow());
print("output new golden file at %\n", result.golden_path); print_to_builder(builder, "output new golden file at %\n", result.golden_path);
} }
case .Passed; { case .Passed; {
print(" %", green()); print_to_builder(builder, " %", green());
print("passed %\n", stage); print_to_builder(builder, "passed %\n", stage);
} }
case .Failed; { case .Failed; {
print(" %", red()); print_to_builder(builder, " %", red());
print("failed %\n", stage); print_to_builder(builder, "failed %\n", stage);
} }
} }
if result.info_text.count > 0 { if result.info_text.count > 0 {
print("%", cyan()); print_to_builder(builder, "%", cyan());
print("--- Info text ---\n"); print_to_builder(builder, "--- Info text ---\n");
print("%", yellow()); print_to_builder(builder, "%", yellow());
print("%\n", result.info_text); print_to_builder(builder, "%\n", result.info_text);
} }
print("%", reset_color()); print_to_builder(builder, "%", reset_color());
} }
main :: () { main :: () {

View File

@@ -186,12 +186,20 @@ Compile_Result :: struct {
arena : Arena; arena : Arena;
} }
record_error :: (result : *Compile_Result, format : string, args : .. Any) {
error : Compiler_Message;
error.message_kind = .Error;
error.message = sprint(format, args);
array_add(*result.messages, error);
}
//@Incomplete(niels): need to consider allocation //@Incomplete(niels): need to consider allocation
add_file :: (result : *Compile_Result, path : string) { add_file :: (result : *Compile_Result, path : string) {
file_string, ok := read_entire_file(path); file_string, ok := read_entire_file(path);
if !ok { if !ok {
// record_error(.File_Load_Failed, "Unable to load file: %", path); record_error(result, "Unable to load file: %", path);
return; return;
} }
@@ -484,7 +492,7 @@ generate_output_data :: (result : *Compile_Result) {
} }
} }
compile_file :: (compiler : *Shader_Compiler, paths : []string) -> Compile_Result { compile_file :: (compiler : *Shader_Compiler, paths : ..string) -> Compile_Result {
result : Compile_Result; result : Compile_Result;
for path : paths { for path : paths {
@@ -495,11 +503,6 @@ compile_file :: (compiler : *Shader_Compiler, paths : []string) -> Compile_Resul
parse(*result); parse(*result);
check(*result); check(*result);
codegen(*result); codegen(*result);
if result.had_error {
return result;
}
generate_output_data(*result); generate_output_data(*result);
return result; return result;

View File

@@ -1,4 +1,28 @@
test/wrong_multiply.ink:4,34: error: Type mismatch. Expected float got float2 test/wrong_multiply.ink:4,18: error: Procedure call did not match any of the possible overloads for 'float4'
 found:
result : float4 = float4(1.0, foo * res, 0.0, 1.0);
^^^^^^
 While matching argument 2 in function call.
 result : float4 = float4(1.0, foo * res, 0.0, 1.0);
^
 Possible overloads:
 foreign float4 :: (float, float, float, float) -> float4; (test/wrong_multiply.ink:86)
 foreign float4 :: (float4) -> float4; (test/wrong_multiply.ink:87)
 foreign float4 :: (float2, float2) -> float4; (test/wrong_multiply.ink:88)
 foreign float4 :: (float2, float, float) -> float4; (test/wrong_multiply.ink:89)
 foreign float4 :: (float, float2, float) -> float4; (test/wrong_multiply.ink:90)
 foreign float4 :: (float, float2, float) -> float4; (test/wrong_multiply.ink:90)
 foreign float4 :: (float, float, float2) -> float4; (test/wrong_multiply.ink:91)
 foreign float4 :: (float, float, float2) -> float4; (test/wrong_multiply.ink:91)
 foreign float4 :: (float3, float) -> float4; (test/wrong_multiply.ink:92)
 foreign float4 :: (float3, float) -> float4; (test/wrong_multiply.ink:92)
 foreign float4 :: (float, float3) -> float4; (test/wrong_multiply.ink:93)
 foreign float4 :: (float, float3) -> float4; (test/wrong_multiply.ink:93)
 foreign float4 :: (float) -> float4; (test/wrong_multiply.ink:94)
 foreign float4 :: (float) -> float4; (test/wrong_multiply.ink:94)
test/wrong_multiply.ink:4,34: error: Type mismatch. Expected float got float2
 found:  found:
result : float4 = float4(1.0, foo * res, 0.0, 1.0); result : float4 = float4(1.0, foo * res, 0.0, 1.0);
^ ^
@@ -6,6 +30,6 @@
float float
got: got:
res : float2 = float2(2.0, 2.0) result : float4 = float4(1.0, foo * res, 0.0, 1.0);