diff --git a/Ink.jai b/Ink.jai index 44bca3c..9c06276 100644 --- a/Ink.jai +++ b/Ink.jai @@ -207,17 +207,48 @@ run_codegen_test :: (ctx : *Compiler_Context, output_type : Output_Type = 0) -> } run_compile_test :: (path : string, output_type : Output_Type = 0) -> Result, Compiler_Context { - compiler : Compiler_Context; + ctx : Compiler_Context; result : Result; - compile_file(*compiler, path); - print("\n"); + result.path = path; + compile_file(*ctx, path); - if compiler.had_error { + if ctx.had_error { result.type = .Failed; result.info_text = tprint("Failed compiling: %\n", path); + } else { + sc := get_scratch(); + defer scratch_end(sc); + sb : String_Builder; + init_string_builder(*sb,, sc.allocator); + if ctx.vertex_entry_point.name.count > 0 { + print_to_builder(*sb, "[vertex entry point] - %\n", ctx.vertex_entry_point.name); + } + if ctx.pixel_entry_point.name.count > 0 { + print_to_builder(*sb, "[pixel entry point] - %\n", ctx.pixel_entry_point.name); + } + + for cb : ctx.cbuffers { + print_to_builder(*sb, "[constant_buffer] - % - %\n", cb.name, cb.buffer_index); + + indent(*sb, 1); + for field : cb.fields { + append(*sb, "[field] - "); + pretty_print_field(*sb, *field.base_field); + } + } + + result.info_text = builder_to_string(*sb,, ctx.allocator); } - return result, compiler; + if output_type & .StdOut { + result.type = .StdOut; + return result, ctx; + } + + golden_path := get_golden_path(ctx.file.path, .Compile); + do_golden_comparison(golden_path, result.info_text, *result, output_type); + + return result, ctx; } run_lexer_test :: (file_path : string, ctx : *Compiler_Context, output_type : Output_Type = 0) -> Result { @@ -376,6 +407,7 @@ run_test_new :: (file_path : string, stage_flags : Stage_Flags, results : *[..]R if stage_flags & .Compile { result = run_compile_test(file_path, output_type); + record_result(results, result); } } diff --git a/Semantic_Analysis.jai b/Semantic_Analysis.jai index f9ac87b..16d151f 100644 --- a/Semantic_Analysis.jai +++ b/Semantic_Analysis.jai @@ -1874,6 +1874,196 @@ add_builtins_new :: (checker : *Semantic_Checker) { new_builtin_function(checker, "float4", .[targ("float4")], targ("float4")); new_builtin_function(checker, "float4", .[farg()], targ("float4")); + new_builtin_function(checker, "cross", .[targ("float3"), targ("float3")], targ("float3")); + new_builtin_function(checker, "distance", .[targ("float2"), targ("float2")], farg()); + new_builtin_function(checker, "distance", .[targ("float3"), targ("float3")], farg()); + new_builtin_function(checker, "distance", .[targ("float4"), targ("float4")], farg()); + + new_builtin_function(checker, "length", .[targ("float2")], farg()); + new_builtin_function(checker, "length", .[targ("float3")], farg()); + new_builtin_function(checker, "length", .[targ("float3")], farg()); + + new_builtin_function(checker, "dot", .[targ("float2"), targ("float2")], farg()); + new_builtin_function(checker, "dot", .[targ("float3"), targ("float3")], farg()); + new_builtin_function(checker, "dot", .[targ("float4"), targ("float4")], farg()); + + new_builtin_function(checker, "normalize", .[targ("float2")], farg()); + new_builtin_function(checker, "normalize", .[targ("float3")], farg()); + new_builtin_function(checker, "normalize", .[targ("float3")], farg()); + + new_builtin_function(checker, "transpose", .[targ("float4x4")], targ("float4x4")); + + new_builtin_function(checker, "mul", .[targ("float2"), targ("float2")], farg()); + new_builtin_function(checker, "mul", .[targ("float3"), targ("float3")], farg()); + new_builtin_function(checker, "mul", .[targ("float4"), targ("float4")], farg()); + new_builtin_function(checker, "mul", .[targ("float4x4"), targ("float4x4")], targ("float4x4")); + + new_builtin_function(checker, "mul", .[farg(), targ("float2")], targ("float2")); + new_builtin_function(checker, "mul", .[farg(), targ("float3")], targ("float3")); + new_builtin_function(checker, "mul", .[farg(), targ("float4")], targ("float4")); + + new_builtin_function(checker, "mul", .[farg(), targ("float4x4")], targ("float4x4")); + new_builtin_function(checker, "mul", .[targ("float4x4"), targ("float4x4")], targ("float4x4")); + new_builtin_function(checker, "mul", .[targ("float4x4"), targ("float4")], targ("float4")); + + new_builtin_function(checker, "mul", .[targ("float2"), farg()], targ("float2")); + new_builtin_function(checker, "mul", .[targ("float3"), farg()], targ("float3")); + new_builtin_function(checker, "mul", .[targ("float4"), farg()], targ("float4")); + + new_builtin_function(checker, "mul", .[targ("float4"), targ("float4x4")], targ("float4")); + + new_builtin_function(checker, "abs", .[farg()], farg()); + new_builtin_function(checker, "abs", .[targ("float2")], targ("float2")); + new_builtin_function(checker, "abs", .[targ("float3")], targ("float3")); + new_builtin_function(checker, "abs", .[targ("float4")], targ("float4")); + new_builtin_function(checker, "abs", .[targ("float4x4")], targ("float4x4")); + + new_builtin_function(checker, "min", .[farg()], farg()); + new_builtin_function(checker, "min", .[targ("float2")], targ("float2")); + new_builtin_function(checker, "min", .[targ("float3")], targ("float3")); + new_builtin_function(checker, "min", .[targ("float4")], targ("float4")); + new_builtin_function(checker, "min", .[targ("float4x4")], targ("float4x4")); + + new_builtin_function(checker, "max", .[farg()], farg()); + new_builtin_function(checker, "max", .[targ("float2")], targ("float2")); + new_builtin_function(checker, "max", .[targ("float3")], targ("float3")); + new_builtin_function(checker, "max", .[targ("float4")], targ("float4")); + new_builtin_function(checker, "max", .[targ("float4x4")], targ("float4x4")); + + new_builtin_function(checker, "ceil", .[farg()], farg()); + new_builtin_function(checker, "ceil", .[targ("float2")], targ("float2")); + new_builtin_function(checker, "ceil", .[targ("float3")], targ("float3")); + new_builtin_function(checker, "ceil", .[targ("float4")], targ("float4")); + new_builtin_function(checker, "ceil", .[targ("float4x4")], targ("float4x4")); + + new_builtin_function(checker, "floor", .[farg()], farg()); + new_builtin_function(checker, "floor", .[targ("float2")], targ("float2")); + new_builtin_function(checker, "floor", .[targ("float3")], targ("float3")); + new_builtin_function(checker, "floor", .[targ("float4")], targ("float4")); + new_builtin_function(checker, "floor", .[targ("float4x4")], targ("float4x4")); + + new_builtin_function(checker, "round", .[farg()], farg()); + new_builtin_function(checker, "round", .[targ("float2")], targ("float2")); + new_builtin_function(checker, "round", .[targ("float3")], targ("float3")); + new_builtin_function(checker, "round", .[targ("float4")], targ("float4")); + new_builtin_function(checker, "round", .[targ("float4x4")], targ("float4x4")); + + new_builtin_function(checker, "clamp", .[farg(), farg(), farg()], farg()); + new_builtin_function(checker, "clamp", .[targ("float2"), targ("float2"), targ("float2")], targ("float2")); + new_builtin_function(checker, "clamp", .[targ("float3"), targ("float3"), targ("float3")], targ("float3")); + new_builtin_function(checker, "clamp", .[targ("float4"), targ("float4"), targ("float4")], targ("float4")); + new_builtin_function(checker, "clamp", .[targ("float4x4"), targ("float4x4"), targ("float4x4")], targ("float4x4")); + + new_builtin_function(checker, "log", .[farg()], farg()); + new_builtin_function(checker, "log", .[targ("float2")], targ("float2")); + new_builtin_function(checker, "log", .[targ("float3")], targ("float3")); + new_builtin_function(checker, "log", .[targ("float4")], targ("float4")); + new_builtin_function(checker, "log", .[targ("float4x4")], targ("float4x4")); + + new_builtin_function(checker, "log2", .[farg()], farg()); + new_builtin_function(checker, "log2", .[targ("float2")], targ("float2")); + new_builtin_function(checker, "log2", .[targ("float3")], targ("float3")); + new_builtin_function(checker, "log2", .[targ("float4")], targ("float4")); + new_builtin_function(checker, "log2", .[targ("float4x4")], targ("float4x4")); + + new_builtin_function(checker, "log10", .[farg()], farg()); + new_builtin_function(checker, "log10", .[targ("float2")], targ("float2")); + new_builtin_function(checker, "log10", .[targ("float3")], targ("float3")); + new_builtin_function(checker, "log10", .[targ("float4")], targ("float4")); + new_builtin_function(checker, "log10", .[targ("float4x4")], targ("float4x4")); + + new_builtin_function(checker, "pow", .[farg(), farg(), farg()], farg()); + new_builtin_function(checker, "pow", .[targ("float2"), targ("float2"), targ("float2")], targ("float2")); + new_builtin_function(checker, "pow", .[targ("float3"), targ("float3"), targ("float3")], targ("float3")); + new_builtin_function(checker, "pow", .[targ("float4"), targ("float4"), targ("float4")], targ("float4")); + new_builtin_function(checker, "pow", .[targ("float4x4"), targ("float4x4"), targ("float4x4")], targ("float4x4")); + + new_builtin_function(checker, "smoothstep", .[farg(), farg(), farg()], farg()); + new_builtin_function(checker, "smoothstep", .[targ("float2"), targ("float2"), targ("float2")], targ("float2")); + new_builtin_function(checker, "smoothstep", .[targ("float3"), targ("float3"), targ("float3")], targ("float3")); + new_builtin_function(checker, "smoothstep", .[targ("float4"), targ("float4"), targ("float4")], targ("float4")); + new_builtin_function(checker, "smoothstep", .[targ("float4x4"), targ("float4x4"), targ("float4x4")], targ("float4x4")); + + new_builtin_function(checker, "step", .[farg()], farg()); + new_builtin_function(checker, "step", .[targ("float2")], targ("float2")); + new_builtin_function(checker, "step", .[targ("float3")], targ("float3")); + new_builtin_function(checker, "step", .[targ("float4")], targ("float4")); + new_builtin_function(checker, "step", .[targ("float4x4")], targ("float4x4")); + + new_builtin_function(checker, "sqrt", .[farg()], farg()); + new_builtin_function(checker, "sqrt", .[targ("float2")], targ("float2")); + new_builtin_function(checker, "sqrt", .[targ("float3")], targ("float3")); + new_builtin_function(checker, "sqrt", .[targ("float4")], targ("float4")); + new_builtin_function(checker, "sqrt", .[targ("float4x4")], targ("float4x4")); + + new_builtin_function(checker, "cos", .[farg()], farg()); + new_builtin_function(checker, "cos", .[targ("float2")], targ("float2")); + new_builtin_function(checker, "cos", .[targ("float3")], targ("float3")); + new_builtin_function(checker, "cos", .[targ("float4")], targ("float4")); + new_builtin_function(checker, "cos", .[targ("float4x4")], targ("float4x4")); + + new_builtin_function(checker, "cosh", .[farg()], farg()); + new_builtin_function(checker, "cosh", .[targ("float2")], targ("float2")); + new_builtin_function(checker, "cosh", .[targ("float3")], targ("float3")); + new_builtin_function(checker, "cosh", .[targ("float4")], targ("float4")); + new_builtin_function(checker, "cosh", .[targ("float4x4")], targ("float4x4")); + + new_builtin_function(checker, "acos", .[farg()], farg()); + new_builtin_function(checker, "acos", .[targ("float2")], targ("float2")); + new_builtin_function(checker, "acos", .[targ("float3")], targ("float3")); + new_builtin_function(checker, "acos", .[targ("float4")], targ("float4")); + new_builtin_function(checker, "acos", .[targ("float4x4")], targ("float4x4")); + + new_builtin_function(checker, "sin", .[farg()], farg()); + new_builtin_function(checker, "sin", .[targ("float2")], targ("float2")); + new_builtin_function(checker, "sin", .[targ("float3")], targ("float3")); + new_builtin_function(checker, "sin", .[targ("float4")], targ("float4")); + new_builtin_function(checker, "sin", .[targ("float4x4")], targ("float4x4")); + + new_builtin_function(checker, "sinh", .[farg()], farg()); + new_builtin_function(checker, "sinh", .[targ("float2")], targ("float2")); + new_builtin_function(checker, "sinh", .[targ("float3")], targ("float3")); + new_builtin_function(checker, "sinh", .[targ("float4")], targ("float4")); + new_builtin_function(checker, "sinh", .[targ("float4x4")], targ("float4x4")); + + new_builtin_function(checker, "asin", .[farg()], farg()); + new_builtin_function(checker, "asin", .[targ("float2")], targ("float2")); + new_builtin_function(checker, "asin", .[targ("float3")], targ("float3")); + new_builtin_function(checker, "asin", .[targ("float4")], targ("float4")); + new_builtin_function(checker, "asin", .[targ("float4x4")], targ("float4x4")); + + new_builtin_function(checker, "tan", .[farg()], farg()); + new_builtin_function(checker, "tan", .[targ("float2")], targ("float2")); + new_builtin_function(checker, "tan", .[targ("float3")], targ("float3")); + new_builtin_function(checker, "tan", .[targ("float4")], targ("float4")); + new_builtin_function(checker, "tan", .[targ("float4x4")], targ("float4x4")); + + new_builtin_function(checker, "tanh", .[farg()], farg()); + new_builtin_function(checker, "tanh", .[targ("float2")], targ("float2")); + new_builtin_function(checker, "tanh", .[targ("float3")], targ("float3")); + new_builtin_function(checker, "tanh", .[targ("float4")], targ("float4")); + new_builtin_function(checker, "tanh", .[targ("float4x4")], targ("float4x4")); + + new_builtin_function(checker, "atan", .[farg()], farg()); + new_builtin_function(checker, "atan", .[targ("float2")], targ("float2")); + new_builtin_function(checker, "atan", .[targ("float3")], targ("float3")); + new_builtin_function(checker, "atan", .[targ("float4")], targ("float4")); + new_builtin_function(checker, "atan", .[targ("float4x4")], targ("float4x4")); + + new_builtin_function(checker, "atan2", .[farg(), farg()], farg()); + new_builtin_function(checker, "atan2", .[targ("float2"), targ("float2")], farg()); + new_builtin_function(checker, "atan2", .[targ("float3"), targ("float3")], farg()); + new_builtin_function(checker, "atan2", .[targ("float4"), targ("float4")], farg()); + new_builtin_function(checker, "atan2", .[targ("float4x4"), targ("float4x4")], targ("float4x4")); + + new_builtin_function(checker, "sample", .[targ(Typenames[Type_Kind.Texture2D]), targ(Typenames[Type_Kind.Sampler])], targ("float4")); + + new_builtin_function(checker, "pow", .[farg(), farg(), farg()], farg()); + new_builtin_function(checker, "pow", .[targ("float2"), targ("float2"), farg()], targ("float2")); + new_builtin_function(checker, "pow", .[targ("float3"), targ("float3"), farg()], targ("float3")); + new_builtin_function(checker, "pow", .[targ("float4"), targ("float4"), farg()], targ("float4")); + + checker.state = .Type_Checking; } diff --git a/module.jai b/module.jai index a6fddd5..0149067 100644 --- a/module.jai +++ b/module.jai @@ -507,8 +507,6 @@ compile_file :: (ctx : *Compiler_Context, path : string, allocator : Allocator = init_context_allocators(); defer clear_context_allocators(); - ctx.allocator = make_arena(Megabytes(128)); - ctx.file = make_file(ctx, path); lex(ctx); diff --git a/test/semant/basic_property_and_return_value.golden b/test/semant/basic_property_and_return_value.golden index b34e8e7..6f84e05 100644 --- a/test/semant/basic_property_and_return_value.golden +++ b/test/semant/basic_property_and_return_value.golden @@ -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 ] diff --git a/test/semant/constant_buffer.golden b/test/semant/constant_buffer.golden index 59d4e95..1f36c81 100644 --- a/test/semant/constant_buffer.golden +++ b/test/semant/constant_buffer.golden @@ -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 diff --git a/test/semant/for_i_loop.golden b/test/semant/for_i_loop.golden new file mode 100644 index 0000000..47663f8 --- /dev/null +++ b/test/semant/for_i_loop.golden @@ -0,0 +1,7 @@ +scope (global) [ + [vertex__vs_main] : () + scope (vertex__vs_main) [ + [i] : int + [x] : int + ] +] diff --git a/test/semant/property_rename.golden b/test/semant/property_rename.golden index 2098354..53c4920 100644 --- a/test/semant/property_rename.golden +++ b/test/semant/property_rename.golden @@ -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 ] diff --git a/test/semant/wrong_multiply.golden b/test/semant/wrong_multiply.golden index 506863e..1e10581 100644 --- a/test/semant/wrong_multiply.golden +++ b/test/semant/wrong_multiply.golden @@ -7,20 +7,15 @@  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) + float4 :: (float, float, float, float); (test/wrong_multiply.ink:0) + float4 :: (float2, float2); (test/wrong_multiply.ink:0) + float4 :: (float2, float, float); (test/wrong_multiply.ink:0) + float4 :: (float, float2, float); (test/wrong_multiply.ink:0) + float4 :: (float, float, float2); (test/wrong_multiply.ink:0) + float4 :: (float, float3); (test/wrong_multiply.ink:0) + float4 :: (float3, float); (test/wrong_multiply.ink:0) + float4 :: (float4); (test/wrong_multiply.ink:0) + float4 :: (float); (test/wrong_multiply.ink:0) test/wrong_multiply.ink:4,34: error: Type mismatch. Expected float got float2  found: diff --git a/test/semant/wrong_type_for_function.golden b/test/semant/wrong_type_for_function.golden index f9d22c8..0adc791 100644 --- a/test/semant/wrong_type_for_function.golden +++ b/test/semant/wrong_type_for_function.golden @@ -7,20 +7,15 @@  color : float4 = float4(y, 1.0, 1.0, 1.0); ^  Possible overloads: - foreign float4 :: (float, float, float, float) -> float4; (test/wrong_type_for_function.ink:86) - foreign float4 :: (float4) -> float4; (test/wrong_type_for_function.ink:87) - foreign float4 :: (float2, float2) -> float4; (test/wrong_type_for_function.ink:88) - foreign float4 :: (float2, float, float) -> float4; (test/wrong_type_for_function.ink:89) - foreign float4 :: (float, float2, float) -> float4; (test/wrong_type_for_function.ink:90) - foreign float4 :: (float, float2, float) -> float4; (test/wrong_type_for_function.ink:90) - foreign float4 :: (float, float, float2) -> float4; (test/wrong_type_for_function.ink:91) - foreign float4 :: (float, float, float2) -> float4; (test/wrong_type_for_function.ink:91) - foreign float4 :: (float3, float) -> float4; (test/wrong_type_for_function.ink:92) - foreign float4 :: (float3, float) -> float4; (test/wrong_type_for_function.ink:92) - foreign float4 :: (float, float3) -> float4; (test/wrong_type_for_function.ink:93) - foreign float4 :: (float, float3) -> float4; (test/wrong_type_for_function.ink:93) - foreign float4 :: (float) -> float4; (test/wrong_type_for_function.ink:94) - foreign float4 :: (float) -> float4; (test/wrong_type_for_function.ink:94) + float4 :: (float, float, float, float); (test/wrong_type_for_function.ink:0) + float4 :: (float2, float2); (test/wrong_type_for_function.ink:0) + float4 :: (float2, float, float); (test/wrong_type_for_function.ink:0) + float4 :: (float, float2, float); (test/wrong_type_for_function.ink:0) + float4 :: (float, float, float2); (test/wrong_type_for_function.ink:0) + float4 :: (float, float3); (test/wrong_type_for_function.ink:0) + float4 :: (float3, float); (test/wrong_type_for_function.ink:0) + float4 :: (float4); (test/wrong_type_for_function.ink:0) + float4 :: (float); (test/wrong_type_for_function.ink:0) test/wrong_type_for_function.ink:11,24: error: Type mismatch. Expected float got float2  found: