Compare commits

...

3 Commits

4 changed files with 75 additions and 34 deletions

View File

@@ -1435,6 +1435,10 @@ check_node :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Variable_H
variable, handle := new_type_variable(checker);
lhs_type := from_handle(checker, lhs_var);
rhs_type := from_handle(checker, rhs_var);
variable.type = lhs_type.type;
variable.typename = lhs_type.typename;
variable.scope = lhs_type.scope;
@@ -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);
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; {
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 {
compiler : Shader_Compiler;
result : Result;
compilation_result := compile_file(*compiler, .[path]);
compilation_result := compile_file(*compiler, path);
print("\n");
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) {
print("%Running test: %......", cyan(), test_case.path);
run_test :: (test_case : Test_Case, results : *[..]Result, output_type : Output_Type = 0, builder : *String_Builder) {
print_to_builder(builder, "%Running test: %......", cyan(), test_case.path);
// path 30
// len 35
@@ -387,7 +387,7 @@ run_test :: (test_case : Test_Case, results : *[..]Result, output_type : Output_
len := 50;
rest := len - test_case.path.count;
for i: 0..rest {
print(" ");
append(builder, " ");
}
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);
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 {
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)) });
}
}
evaluate_result(result);
evaluate_result(result, *builder);
} else {
break;
}
@@ -440,7 +440,7 @@ run_test_suite :: (using suite : *Test_Suite, output_type : Output_Type = 0) {
// print("\n");
}
print("\n");
append(*builder, "\n");
if output_type == 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);
if #complete result.type == {
case .File_Read_Failed; {
print(" %", red());
print("failed with File_Read_Failed\n");
print_to_builder(builder, " %", red());
print_to_builder(builder, "failed with File_Read_Failed\n");
}
case .Golden_File_Not_Found; {
print(" %", red());
print("failed with Golden File Not Found for stage %\n", stage);
print_to_builder(builder, " %", red());
print_to_builder(builder, "failed with Golden File Not Found for stage %\n", stage);
}
case .StdOut; {
}
case .Golden_Output; {
print(" %", yellow());
print("output new golden file at %\n", result.golden_path);
print_to_builder(builder, " %", yellow());
print_to_builder(builder, "output new golden file at %\n", result.golden_path);
}
case .Passed; {
print(" %", green());
print("passed %\n", stage);
print_to_builder(builder, " %", green());
print_to_builder(builder, "passed %\n", stage);
}
case .Failed; {
print(" %", red());
print("failed %\n", stage);
print_to_builder(builder, " %", red());
print_to_builder(builder, "failed %\n", stage);
}
}
if result.info_text.count > 0 {
print("%", cyan());
print("--- Info text ---\n");
print("%", yellow());
print("%\n", result.info_text);
print_to_builder(builder, "%", cyan());
print_to_builder(builder, "--- Info text ---\n");
print_to_builder(builder, "%", yellow());
print_to_builder(builder, "%\n", result.info_text);
}
print("%", reset_color());
print_to_builder(builder, "%", reset_color());
}
main :: () {

View File

@@ -186,12 +186,20 @@ Compile_Result :: struct {
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
add_file :: (result : *Compile_Result, path : string) {
file_string, ok := read_entire_file(path);
if !ok {
// record_error(.File_Load_Failed, "Unable to load file: %", path);
record_error(result, "Unable to load file: %", path);
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;
for path : paths {
@@ -495,11 +503,6 @@ compile_file :: (compiler : *Shader_Compiler, paths : []string) -> Compile_Resul
parse(*result);
check(*result);
codegen(*result);
if result.had_error {
return result;
}
generate_output_data(*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:
result : float4 = float4(1.0, foo * res, 0.0, 1.0);
^
@@ -6,6 +30,6 @@
float
got:
res : float2 = float2(2.0, 2.0)
result : float4 = float4(1.0, foo * res, 0.0, 1.0);