Proper pretty printing and error handling on non-cool if condition.

This commit is contained in:
2025-01-15 21:32:18 +01:00
parent a72a9ff50d
commit b4d119230b
16 changed files with 249 additions and 85 deletions

View File

@@ -16,6 +16,9 @@ test/multiple_semicolons_everywhere.ink codegen
test/pass_and_access_struct_fields_in_functions.ink codegen
test/passthrough.ink codegen
test/property_rename.ink codegen
test/simple_else_if.ink codegen
test/simple_if_else.ink codegen
test/simple_if.ink codegen
test/simple_struct_access.ink codegen
test/struct_within_struct.ink codegen
test/unary.ink codegen

View File

@@ -16,6 +16,9 @@ test/multiple_functions.ink compile
test/multiple_semicolons_everywhere.ink compile
test/pass_and_access_struct_fields_in_functions.ink compile
test/passthrough.ink compile
test/simple_else_if.ink compile
test/simple_if_else.ink compile
test/simple_if.ink compile
test/simple_struct_access.ink compile
test/struct_within_struct.ink compile
test/unary.ink compile

View File

@@ -0,0 +1,35 @@
{kind = TOKEN_VERTEX; ; index = 0 ; length = 6 line = 1 ; column = 0 ; value ='vertex'; }
{kind = TOKEN_IDENTIFIER; ; index = 7 ; length = 4 line = 1 ; column = 7 ; value ='main'; }
{kind = TOKEN_DOUBLECOLON; ; index = 12 ; length = 2 line = 1 ; column = 12 ; value ='::'; }
{kind = TOKEN_LEFTPAREN; ; index = 15 ; length = 1 line = 1 ; column = 15 ; value ='('; }
{kind = TOKEN_IDENTIFIER; ; index = 16 ; length = 3 line = 1 ; column = 16 ; value ='pos'; }
{kind = TOKEN_COLON; ; index = 20 ; length = 1 line = 1 ; column = 20 ; value =':'; }
{kind = TOKEN_IDENTIFIER; ; index = 22 ; length = 6 line = 1 ; column = 22 ; value ='float3'; }
{kind = TOKEN_AT; ; index = 29 ; length = 1 line = 1 ; column = 29 ; value ='@'; }
{kind = TOKEN_IDENTIFIER; ; index = 30 ; length = 8 line = 1 ; column = 30 ; value ='position'; }
{kind = TOKEN_RIGHTPAREN; ; index = 38 ; length = 1 line = 1 ; column = 38 ; value =')'; }
{kind = TOKEN_ARROW; ; index = 40 ; length = 2 line = 1 ; column = 40 ; value ='->'; }
{kind = TOKEN_IDENTIFIER; ; index = 43 ; length = 6 line = 1 ; column = 43 ; value ='float4'; }
{kind = TOKEN_AT; ; index = 50 ; length = 1 line = 1 ; column = 50 ; value ='@'; }
{kind = TOKEN_IDENTIFIER; ; index = 51 ; length = 8 line = 1 ; column = 51 ; value ='position'; }
{kind = TOKEN_LEFTBRACE; ; index = 60 ; length = 1 line = 1 ; column = 60 ; value ='{'; }
{kind = TOKEN_IF; ; index = 64 ; length = 2 line = 2 ; column = 0 ; value ='if'; }
{kind = TOKEN_FLOATLITERAL; ; index = 67 ; length = 3 line = 2 ; column = 3 ; value ='1'; }
{kind = TOKEN_LEFTBRACE; ; index = 71 ; length = 1 line = 2 ; column = 7 ; value ='{'; }
{kind = TOKEN_RETURN; ; index = 76 ; length = 6 line = 3 ; column = 0 ; value ='return'; }
{kind = TOKEN_IDENTIFIER; ; index = 83 ; length = 6 line = 3 ; column = 7 ; value ='float4'; }
{kind = TOKEN_LEFTPAREN; ; index = 89 ; length = 1 line = 3 ; column = 13 ; value ='('; }
{kind = TOKEN_IDENTIFIER; ; index = 90 ; length = 3 line = 3 ; column = 14 ; value ='pos'; }
{kind = TOKEN_COMMA; ; index = 93 ; length = 1 line = 3 ; column = 17 ; value =','; }
{kind = TOKEN_FLOATLITERAL; ; index = 95 ; length = 3 line = 3 ; column = 19 ; value ='1'; }
{kind = TOKEN_RIGHTPAREN; ; index = 98 ; length = 1 line = 3 ; column = 22 ; value =')'; }
{kind = TOKEN_SEMICOLON; ; index = 99 ; length = 1 line = 3 ; column = 23 ; value =';'; }
{kind = TOKEN_RIGHTBRACE; ; index = 103 ; length = 1 line = 4 ; column = 0 ; value ='}'; }
{kind = TOKEN_RETURN; ; index = 107 ; length = 6 line = 5 ; column = 0 ; value ='return'; }
{kind = TOKEN_IDENTIFIER; ; index = 114 ; length = 6 line = 5 ; column = 7 ; value ='float4'; }
{kind = TOKEN_LEFTPAREN; ; index = 120 ; length = 1 line = 5 ; column = 13 ; value ='('; }
{kind = TOKEN_FLOATLITERAL; ; index = 121 ; length = 3 line = 5 ; column = 14 ; value ='0'; }
{kind = TOKEN_RIGHTPAREN; ; index = 124 ; length = 1 line = 5 ; column = 17 ; value =')'; }
{kind = TOKEN_SEMICOLON; ; index = 125 ; length = 1 line = 5 ; column = 18 ; value =';'; }
{kind = TOKEN_RIGHTBRACE; ; index = 128 ; length = 1 line = 6 ; column = 0 ; value ='}'; }
{kind = TOKEN_EOF; ; index = 131 ; length = 0 line = 7 ; column = 0 ; value =''; }

37
test/lex/simple_if.golden Normal file
View File

@@ -0,0 +1,37 @@
{kind = TOKEN_VERTEX; ; index = 0 ; length = 6 line = 1 ; column = 0 ; value ='vertex'; }
{kind = TOKEN_IDENTIFIER; ; index = 7 ; length = 4 line = 1 ; column = 7 ; value ='main'; }
{kind = TOKEN_DOUBLECOLON; ; index = 12 ; length = 2 line = 1 ; column = 12 ; value ='::'; }
{kind = TOKEN_LEFTPAREN; ; index = 15 ; length = 1 line = 1 ; column = 15 ; value ='('; }
{kind = TOKEN_IDENTIFIER; ; index = 16 ; length = 3 line = 1 ; column = 16 ; value ='pos'; }
{kind = TOKEN_COLON; ; index = 20 ; length = 1 line = 1 ; column = 20 ; value =':'; }
{kind = TOKEN_IDENTIFIER; ; index = 22 ; length = 6 line = 1 ; column = 22 ; value ='float3'; }
{kind = TOKEN_AT; ; index = 29 ; length = 1 line = 1 ; column = 29 ; value ='@'; }
{kind = TOKEN_IDENTIFIER; ; index = 30 ; length = 8 line = 1 ; column = 30 ; value ='position'; }
{kind = TOKEN_RIGHTPAREN; ; index = 38 ; length = 1 line = 1 ; column = 38 ; value =')'; }
{kind = TOKEN_ARROW; ; index = 40 ; length = 2 line = 1 ; column = 40 ; value ='->'; }
{kind = TOKEN_IDENTIFIER; ; index = 43 ; length = 6 line = 1 ; column = 43 ; value ='float4'; }
{kind = TOKEN_AT; ; index = 50 ; length = 1 line = 1 ; column = 50 ; value ='@'; }
{kind = TOKEN_IDENTIFIER; ; index = 51 ; length = 8 line = 1 ; column = 51 ; value ='position'; }
{kind = TOKEN_LEFTBRACE; ; index = 60 ; length = 1 line = 1 ; column = 60 ; value ='{'; }
{kind = TOKEN_IF; ; index = 64 ; length = 2 line = 2 ; column = 0 ; value ='if'; }
{kind = TOKEN_INTLITERAL; ; index = 67 ; length = 1 line = 2 ; column = 3 ; value ='0'; }
{kind = TOKEN_GREATER; ; index = 69 ; length = 1 line = 2 ; column = 5 ; value ='>'; }
{kind = TOKEN_INTLITERAL; ; index = 71 ; length = 3 line = 2 ; column = 7 ; value ='100'; }
{kind = TOKEN_LEFTBRACE; ; index = 75 ; length = 1 line = 2 ; column = 11 ; value ='{'; }
{kind = TOKEN_RETURN; ; index = 80 ; length = 6 line = 3 ; column = 0 ; value ='return'; }
{kind = TOKEN_IDENTIFIER; ; index = 87 ; length = 6 line = 3 ; column = 7 ; value ='float4'; }
{kind = TOKEN_LEFTPAREN; ; index = 93 ; length = 1 line = 3 ; column = 13 ; value ='('; }
{kind = TOKEN_IDENTIFIER; ; index = 94 ; length = 3 line = 3 ; column = 14 ; value ='pos'; }
{kind = TOKEN_COMMA; ; index = 97 ; length = 1 line = 3 ; column = 17 ; value =','; }
{kind = TOKEN_FLOATLITERAL; ; index = 99 ; length = 3 line = 3 ; column = 19 ; value ='1'; }
{kind = TOKEN_RIGHTPAREN; ; index = 102 ; length = 1 line = 3 ; column = 22 ; value =')'; }
{kind = TOKEN_SEMICOLON; ; index = 103 ; length = 1 line = 3 ; column = 23 ; value =';'; }
{kind = TOKEN_RIGHTBRACE; ; index = 107 ; length = 1 line = 4 ; column = 0 ; value ='}'; }
{kind = TOKEN_RETURN; ; index = 111 ; length = 6 line = 5 ; column = 0 ; value ='return'; }
{kind = TOKEN_IDENTIFIER; ; index = 118 ; length = 6 line = 5 ; column = 7 ; value ='float4'; }
{kind = TOKEN_LEFTPAREN; ; index = 124 ; length = 1 line = 5 ; column = 13 ; value ='('; }
{kind = TOKEN_FLOATLITERAL; ; index = 125 ; length = 3 line = 5 ; column = 14 ; value ='0'; }
{kind = TOKEN_RIGHTPAREN; ; index = 128 ; length = 1 line = 5 ; column = 17 ; value =')'; }
{kind = TOKEN_SEMICOLON; ; index = 129 ; length = 1 line = 5 ; column = 18 ; value =';'; }
{kind = TOKEN_RIGHTBRACE; ; index = 132 ; length = 1 line = 6 ; column = 0 ; value ='}'; }
{kind = TOKEN_EOF; ; index = 135 ; length = 0 line = 7 ; column = 0 ; value =''; }

View File

@@ -17,10 +17,14 @@ test/inferred_types.ink lex
test/meta_block.ink lex
test/multiple_functions.ink lex
test/multiple_semicolons_everywhere.ink lex
test/non_bool_cond.ink lex
test/pass_and_access_struct_fields_in_functions.ink lex
test/passthrough.ink lex
test/property_rename.ink lex
test/redeclared_variable.ink lex
test/simple_else_if.ink lex
test/simple_if_else.ink lex
test/simple_if.ink lex
test/simple_struct_access.ink lex
test/struct_access_primitive_type.ink lex
test/struct_within_struct.ink lex

6
test/non_bool_cond.ink Normal file
View File

@@ -0,0 +1,6 @@
vertex main :: (pos : float3 @position) -> float4 @position {
if 1.0 {
return float4(pos, 1.0);
}
return float4(0.0);
}

View File

@@ -0,0 +1,6 @@
(program
(fun vertex vs_main -> float4 (@position)
[(:= pos float3 (@position))]
(if 1
(return (float4 pos 1)))
(return (float4 0))))

View File

@@ -1,9 +1,9 @@
(program
(fun vertex vs_main -> float4 (@position)
[(:= pos float3 (@position))]
(if (> pos.x 100)
(return (float4 pos 1))
(if (> pos.x 50)
(return (float4 pos 1))
(return (float4 1))))
(return (float4 0))))
[(:= pos float3 (@position))]
(if (> pos.x 100)
(return (float4 pos 1))
(if (> pos.x 50)
(return (float4 pos 1))
(return (float4 1))))
(return (float4 0))))

View File

@@ -0,0 +1,6 @@
(program
(fun vertex vs_main -> float4 (@position)
[(:= pos float3 (@position))]
(if (> 0 100)
(return (float4 pos 1)))
(return (float4 0))))

View File

@@ -0,0 +1,7 @@
(program
(fun vertex vs_main -> float4 (@position)
[(:= pos float3 (@position))]
(if (> 0 100)
(return (float4 pos 1))
(return (float4 1)))
(return (float4 0))))

View File

@@ -17,10 +17,14 @@ test/inferred_types.ink parse
test/meta_block.ink parse
test/multiple_functions.ink parse
test/multiple_semicolons_everywhere.ink parse
test/non_bool_cond.ink parse
test/pass_and_access_struct_fields_in_functions.ink parse
test/passthrough.ink parse
test/property_rename.ink parse
test/redeclared_variable.ink parse
test/simple_else_if.ink parse
test/simple_if_else.ink parse
test/simple_if.ink parse
test/simple_struct_access.ink parse
test/struct_access_primitive_type.ink parse
test/struct_within_struct.ink parse

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

@@ -14,10 +14,14 @@ test/function_with_int_return.ink semant
test/inferred_types.ink semant
test/multiple_functions.ink semant
test/multiple_semicolons_everywhere.ink semant
test/non_bool_cond.ink semant
test/pass_and_access_struct_fields_in_functions.ink semant
test/passthrough.ink semant
test/property_rename.ink semant
test/redeclared_variable.ink semant
test/simple_else_if.ink semant
test/simple_if_else.ink semant
test/simple_if.ink semant
test/simple_struct_access.ink semant
test/struct_access_primitive_type.ink semant
test/struct_within_struct.ink semant