Added the rest of current builtins. Started properly implementing compile tests.

This commit is contained in:
2025-09-11 11:03:02 +02:00
parent 9461fe626f
commit 79ec6cc42f
9 changed files with 255 additions and 38 deletions

42
Ink.jai
View File

@@ -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 { run_compile_test :: (path : string, output_type : Output_Type = 0) -> Result, Compiler_Context {
compiler : Compiler_Context; ctx : Compiler_Context;
result : Result; result : Result;
compile_file(*compiler, path); result.path = path;
print("\n"); compile_file(*ctx, path);
if compiler.had_error { if ctx.had_error {
result.type = .Failed; result.type = .Failed;
result.info_text = tprint("Failed compiling: %\n", path); 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 { 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 { if stage_flags & .Compile {
result = run_compile_test(file_path, output_type); result = run_compile_test(file_path, output_type);
record_result(results, result);
} }
} }

View File

@@ -1874,6 +1874,196 @@ add_builtins_new :: (checker : *Semantic_Checker) {
new_builtin_function(checker, "float4", .[targ("float4")], targ("float4")); new_builtin_function(checker, "float4", .[targ("float4")], targ("float4"));
new_builtin_function(checker, "float4", .[farg()], 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; checker.state = .Type_Checking;
} }

View File

@@ -507,8 +507,6 @@ compile_file :: (ctx : *Compiler_Context, path : string, allocator : Allocator =
init_context_allocators(); init_context_allocators();
defer clear_context_allocators(); defer clear_context_allocators();
ctx.allocator = make_arena(Megabytes(128));
ctx.file = make_file(ctx, path); ctx.file = make_file(ctx, path);
lex(ctx); lex(ctx);

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

@@ -0,0 +1,7 @@
scope (global) [
[vertex__vs_main] : ()
scope (vertex__vs_main) [
[i] : int
[x] : int
]
]

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
] ]

View File

@@ -7,20 +7,15 @@
 result : float4 = float4(1.0, foo * res, 0.0, 1.0);  result : float4 = float4(1.0, foo * res, 0.0, 1.0);
^ ^
 Possible overloads:  Possible overloads:
 foreign float4 :: (float, float, float, float) -> float4; (test/wrong_multiply.ink:86)  float4 :: (float, float, float, float); (test/wrong_multiply.ink:0)
 foreign float4 :: (float4) -> float4; (test/wrong_multiply.ink:87)  float4 :: (float2, float2); (test/wrong_multiply.ink:0)
 foreign float4 :: (float2, float2) -> float4; (test/wrong_multiply.ink:88)  float4 :: (float2, float, float); (test/wrong_multiply.ink:0)
 foreign float4 :: (float2, float, float) -> float4; (test/wrong_multiply.ink:89)  float4 :: (float, float2, float); (test/wrong_multiply.ink:0)
 foreign float4 :: (float, float2, float) -> float4; (test/wrong_multiply.ink:90)  float4 :: (float, float, float2); (test/wrong_multiply.ink:0)
 foreign float4 :: (float, float2, float) -> float4; (test/wrong_multiply.ink:90)  float4 :: (float, float3); (test/wrong_multiply.ink:0)
 foreign float4 :: (float, float, float2) -> float4; (test/wrong_multiply.ink:91)  float4 :: (float3, float); (test/wrong_multiply.ink:0)
 foreign float4 :: (float, float, float2) -> float4; (test/wrong_multiply.ink:91)  float4 :: (float4); (test/wrong_multiply.ink:0)
 foreign float4 :: (float3, float) -> float4; (test/wrong_multiply.ink:92)  float4 :: (float); (test/wrong_multiply.ink:0)
 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 test/wrong_multiply.ink:4,34: error: Type mismatch. Expected float got float2
 found:  found:

View File

@@ -7,20 +7,15 @@
 color : float4 = float4(y, 1.0, 1.0, 1.0);  color : float4 = float4(y, 1.0, 1.0, 1.0);
^ ^
 Possible overloads:  Possible overloads:
 foreign float4 :: (float, float, float, float) -> float4; (test/wrong_type_for_function.ink:86)  float4 :: (float, float, float, float); (test/wrong_type_for_function.ink:0)
 foreign float4 :: (float4) -> float4; (test/wrong_type_for_function.ink:87)  float4 :: (float2, float2); (test/wrong_type_for_function.ink:0)
 foreign float4 :: (float2, float2) -> float4; (test/wrong_type_for_function.ink:88)  float4 :: (float2, float, float); (test/wrong_type_for_function.ink:0)
 foreign float4 :: (float2, float, float) -> float4; (test/wrong_type_for_function.ink:89)  float4 :: (float, float2, float); (test/wrong_type_for_function.ink:0)
 foreign float4 :: (float, float2, float) -> float4; (test/wrong_type_for_function.ink:90)  float4 :: (float, float, float2); (test/wrong_type_for_function.ink:0)
 foreign float4 :: (float, float2, float) -> float4; (test/wrong_type_for_function.ink:90)  float4 :: (float, float3); (test/wrong_type_for_function.ink:0)
 foreign float4 :: (float, float, float2) -> float4; (test/wrong_type_for_function.ink:91)  float4 :: (float3, float); (test/wrong_type_for_function.ink:0)
 foreign float4 :: (float, float, float2) -> float4; (test/wrong_type_for_function.ink:91)  float4 :: (float4); (test/wrong_type_for_function.ink:0)
 foreign float4 :: (float3, float) -> float4; (test/wrong_type_for_function.ink:92)  float4 :: (float); (test/wrong_type_for_function.ink:0)
 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)
test/wrong_type_for_function.ink:11,24: error: Type mismatch. Expected float got float2 test/wrong_type_for_function.ink:11,24: error: Type mismatch. Expected float got float2
 found:  found: