Ifdefs, moved semantic to check, fixed error reporting for builtins

This commit is contained in:
2025-09-16 11:04:57 +02:00
parent f99f86bc37
commit 7fefe0ecf6
71 changed files with 739 additions and 385 deletions

View File

@@ -0,0 +1,6 @@
scope (global) [
[vertex__vs_main] : ()
scope (vertex__vs_main) [
[x] : float
]
]

View File

@@ -0,0 +1,12 @@
scope (global) [
[pixel__ps_main] : () -> float4
[vertex__vs_main] : (pos : float3) -> float3
[properties] : {color : float4}
scope (properties) [
[color] : float4
]
scope (vertex__vs_main) [
[pos] : float3
]
scope (pixel__ps_main) []
]

View File

@@ -0,0 +1,11 @@
scope (global) [
[vertex__vs_main] : ()
scope (vertex__vs_main) [
[v2] : float2
[v4] : float4
[v3] : float3
[p] : float
[m] : float4x4
[q] : float
]
]

View File

@@ -0,0 +1,8 @@
scope (global) [
[vertex__vs_main] : ()
scope (vertex__vs_main) [
[x] : float
[z] : float
[y] : float
]
]

View File

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

View File

@@ -0,0 +1,15 @@
scope (global) [
[pixel__ps_main] : (pos : float4) -> float4
[vertex__vs_main] : (pos : float3) -> float4
[p] : {time : float}
scope (p) [
[time] : float
]
scope (vertex__vs_main) [
[pos] : float3
]
scope (pixel__ps_main) [
[t] : float
[pos] : float4
]
]

View File

@@ -0,0 +1,4 @@
scope (global) [
[Foo] : {}
scope (Foo) []
]

View File

@@ -0,0 +1,4 @@
scope (global) [
[vertex__vs_main] : ()
scope (vertex__vs_main) []
]

View File

@@ -0,0 +1,6 @@
scope (global) [
[vertex__vs_main] : (pos : float3) -> float3
scope (vertex__vs_main) [
[pos] : float3
]
]

View File

@@ -0,0 +1,7 @@
scope (global) [
[vertex__vs_main] : (pos : float4) -> float4
scope (vertex__vs_main) [
[x] : float
[pos] : float4
]
]

View File

@@ -0,0 +1,4 @@
test/field_without_type_specifier.shd:2,0: error: Expected type specifier after field name.
x := 5.0;
^


View File

@@ -0,0 +1,6 @@
test/float_if_cond.ink:0,0: error: Type of expression in if condition has to be bool.
if 1.0
^^^
1.0 has type float


View File

@@ -0,0 +1,4 @@
test/float_suffix.shd:2,12: error: We don't use 'f' suffixes for floating point values.
 x : float = 2.0f
^^^^


View File

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

View File

@@ -0,0 +1,6 @@
scope (global) [
[foo] : () -> int
[vertex__vs_main] : ()
scope (foo) []
scope (vertex__vs_main) []
]

View File

@@ -0,0 +1,6 @@
scope (global) [
[foo] : ()
[vertex__vs_main] : ()
scope (vertex__vs_main) []
scope (foo) []
]

View File

@@ -0,0 +1,6 @@
scope (global) [
[pixel__ps_main] : () -> float4
[vertex__vs_main] : ()
scope (vertex__vs_main) []
scope (pixel__ps_main) []
]

View File

@@ -0,0 +1,6 @@
scope (global) [
[vertex__vs_main] : (pos : float3) -> int
scope (vertex__vs_main) [
[pos] : float3
]
]

View File

@@ -0,0 +1,8 @@
test/functions_with_same_name.ink:2,0: error: Redeclaration of 'foo'
 foo :: () {
^^^
test/functions_with_same_name.ink:1,0: info: Here is the first declaration of 'foo'
 foo :: () {
^^^


View File

@@ -0,0 +1,6 @@
test/if_cond_assign.ink:0,0: error: Type of expression in if condition has to be bool.
if 0 = 100
^^^^^^
if 0 = 100 { has type int


View File

@@ -0,0 +1,15 @@
scope (global) [
[foo] : () -> float
[vertex__vs_main] : (pos : float3) -> float4
[bar] : () -> float
scope (bar) []
scope (foo) []
scope (vertex__vs_main) [
[v2] : float2
[i] : int
[v4] : float4
[pos] : float3
[v3] : float3
[f] : float
]
]

View File

@@ -0,0 +1,13 @@
scope (global) [
[pixel__ps_main] : () -> float4
[vertex__vs_main] : (pos : float3, uv : float2) -> float3
[properties] : properties
scope (properties) [
[color] : float4
]
scope (vertex__vs_main) [
[pos] : float3
[uv] : float2
]
scope (pixel__ps_main) []
]

View File

@@ -0,0 +1,11 @@
scope (global) [
[foo] : () -> int
[vertex__vs_main] : ()
[bar] : () -> float
scope (foo) []
scope (bar) []
scope (vertex__vs_main) [
[x] : int
[y] : float
]
]

View File

@@ -0,0 +1,13 @@
scope (global) [
[pixel__ps_main] : () -> float4
[foo] : () -> float4
[vertex__vs_main] : (pos : float3) -> float3
scope (vertex__vs_main) [
[pos] : float3
]
scope (foo) []
scope (pixel__ps_main) [
[y] : float4
[color] : float4
]
]

View File

@@ -0,0 +1,6 @@
scope (global) [
[vertex__vs_main] : (pos : float3) -> float4
scope (vertex__vs_main) [
[pos] : float3
]
]

View File

@@ -0,0 +1,6 @@
test/non_bool_cond.ink:0,0: error: Type of expression in if condition has to be bool.
if 1.0
^^^
1.0 has type float


View File

@@ -0,0 +1,15 @@
scope (global) [
[foo] : (f : Foo) -> float
[vertex__vs_main] : ()
[Foo] : {some_data : float}
scope (Foo) [
[some_data] : float
]
scope (foo) [
[f] : Foo
]
scope (vertex__vs_main) [
[d] : float
[f] : Foo
]
]

View File

@@ -0,0 +1,8 @@
scope (global) [
[pixel__ps_main] : () -> float4
[vertex__vs_main] : (pos : float3) -> float3
scope (vertex__vs_main) [
[pos] : float3
]
scope (pixel__ps_main) []
]

View File

@@ -0,0 +1,9 @@
scope (global) [
[vertex__vs_main] : (x : float, y : float, z : float, w : float)
scope (vertex__vs_main) [
[x] : float
[z] : float
[y] : float
[w] : float
]
]

View File

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

View File

@@ -0,0 +1,8 @@
test/redeclared_variable.ink:3,0: error: Redeclaration of 'x'
 x : float = 5.0
^
test/redeclared_variable.ink:2,0: info: Here is the first declaration of 'x'
 x : float = 1.0
^


View File

@@ -0,0 +1,6 @@
scope (global) [
[vertex__vs_main] : (pos : float3) -> float4
scope (vertex__vs_main) [
[pos] : float3
]
]

View File

@@ -0,0 +1,6 @@
scope (global) [
[vertex__vs_main] : (pos : float3) -> float4
scope (vertex__vs_main) [
[pos] : float3
]
]

View File

@@ -0,0 +1,6 @@
scope (global) [
[vertex__vs_main] : (pos : float3) -> float4
scope (vertex__vs_main) [
[pos] : float3
]
]

View File

@@ -0,0 +1,11 @@
scope (global) [
[Data] : {color : float4}
[vertex__vs_main] : ()
scope (Data) [
[color] : float4
]
scope (vertex__vs_main) [
[x] : float4
[d] : Data
]
]

View File

@@ -0,0 +1,6 @@
test/struct_access_primitive_type.ink:3,0: error: Attempting to access a field on a primitive type 'int'.
x.d = 4;
^
declaration:
x : int = 5


View File

@@ -0,0 +1,15 @@
scope (global) [
[Bar] : {t : Foo}
[vertex__vs_main] : ()
[Foo] : {color : float4}
scope (Foo) [
[color] : float4
]
scope (Bar) [
[t] : Foo
]
scope (vertex__vs_main) [
[b] : Bar
[f] : Foo
]
]

View File

@@ -0,0 +1,4 @@
test/type_as_function_name.shd:1,0: error: Invalid function name 'int'
 int :: () {
^^^


View File

@@ -0,0 +1,4 @@
test/type_as_variable_name.ink:2,0: error: Invalid variable name 'int'
 int : float = 4.0
^^^


10
test/check/unary.golden Normal file
View File

@@ -0,0 +1,10 @@
scope (global) [
[pixel__ps_ps_main] : (position : float4) -> float4
[vertex__vs_vs_main] : (position : float3) -> float4
scope (vertex__vs_vs_main) [
[position] : float3
]
scope (pixel__ps_ps_main) [
[position] : float4
]
]

View File

@@ -0,0 +1,7 @@
test/undeclared_function.ink:2,0: error: Attempt to call undeclared function 'foo'.
 foo();
^^^


View File

@@ -0,0 +1,4 @@
test/undeclared_symbol.ink:2,10: error: Use of undeclared symbol 'f'
 b : int = f;
^


View File

@@ -0,0 +1,33 @@
test/unknown_overload.ink:6,0: error: Procedure call did not match any of the possible overloads for 'foo'
 found:
foo(v, v);
^^^
 While matching argument 1 in function call.
 foo(v, v);
^
 Possible overloads:
 foo :: (v1 : float3, v2 : float3) { (test/unknown_overload.ink:1)
 foo :: (v1 : float2, v2 : float2, v3 : float2) { (test/unknown_overload.ink:2)
test/unknown_overload.ink:6,4: error: Type mismatch. Expected float3 got float
 found:
foo(v, v);
^
expected:
float3
got:
v : float = 2.0
test/unknown_overload.ink:6,7: error: Type mismatch. Expected float3 got float
 found:
foo(v, v);
^
expected:
float3
got:
v : float = 2.0


View File

@@ -0,0 +1,6 @@
scope (global) [
[vertex__vs_main] : ()
scope (vertex__vs_main) [
[f] : float4
]
]

View File

@@ -0,0 +1,16 @@
test/wrong_argument_count.ink:5,19: error: Use of undeclared symbol 'w'
 return x * y * z * w;
^
test/wrong_argument_count.ink:9,0: error: Procedure call did not match any of the possible overloads for 'foo'
 found:
foo(2.0, 3.0);
^^^
 Possible overloads:
 foo :: (x : float, y : float, z : float) -> float { (test/wrong_argument_count.ink:1)
 Not enough arguments: Wanted 3, got 2.
 foo :: (x : float, y : float, z : float, w : float) -> float { (test/wrong_argument_count.ink:4)
 Not enough arguments: Wanted 4, got 2.


View File

@@ -0,0 +1,30 @@
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:
 float4 :: (float, float, float, float)
 float4 :: (float2, float2)
 float4 :: (float2, float, float)
 float4 :: (float, float2, float)
 float4 :: (float, float, float2)
 float4 :: (float, float3)
 float4 :: (float3, float)
 float4 :: (float4)
 float4 :: (float)
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);
^
expected:
float
got:
result : float4 = float4(1.0, foo * res, 0.0, 1.0);


View File

@@ -0,0 +1,30 @@
test/wrong_type_for_function.ink:11,17: error: Procedure call did not match any of the possible overloads for 'float4'
 found:
color : float4 = float4(y, 1.0, 1.0, 1.0);
^^^^^^
 While matching argument 1 in function call.
 color : float4 = float4(y, 1.0, 1.0, 1.0);
^
 Possible overloads:
 float4 :: (float, float, float, float)
 float4 :: (float2, float2)
 float4 :: (float2, float, float)
 float4 :: (float, float2, float)
 float4 :: (float, float, float2)
 float4 :: (float, float3)
 float4 :: (float3, float)
 float4 :: (float4)
 float4 :: (float)
test/wrong_type_for_function.ink:11,24: error: Type mismatch. Expected float got float2
 found:
color : float4 = float4(y, 1.0, 1.0, 1.0);
^
expected:
float
got:
y : float2 = foo()