diff --git a/AST.jai b/AST.jai index 9f28ea4..b9a9f97 100644 --- a/AST.jai +++ b/AST.jai @@ -12,9 +12,7 @@ AST_Kind :: enum { // Directives If_Directive; - // Hint; - // Type; - // Operator; + Access; Call; Struct; If; @@ -257,21 +255,35 @@ pretty_print_binary :: (node : *AST_Node, indentation : int, builder : *String_B if !skip_indent { indent(builder, indentation); } - append(builder, "("); - is_array_access := false; + if node.token.kind == .TOKEN_LEFTBRACKET { - print_to_builder(builder, "[]"); + pretty_print_node(node.children[0], 0, builder); + append(builder, "["); + pretty_print_node(node.children[1], 0, builder); + append(builder, "]"); } else { + append(builder, "("); op := node.token; print_to_builder(builder, op_to_string(op)); + append(builder, " "); + + pretty_print_node(node.children[0], 0, builder); + append(builder, " "); + pretty_print_node(node.children[1], 0, builder); + append(builder, ")"); } + - append(builder, " "); +} +pretty_print_access :: (node : *AST_Node, indentation : int, builder : *String_Builder, skip_indent := false) { + if !skip_indent { + indent(builder, indentation); + } + pretty_print_node(node.children[0], 0, builder); - append(builder, " "); + append(builder, "."); pretty_print_node(node.children[1], 0, builder); - append(builder, ")"); } pretty_print_unary :: (node : *AST_Node, indentation : int, builder : *String_Builder, skip_indent := false) { @@ -402,6 +414,9 @@ pretty_print_node :: (node : *AST_Node, indentation : int, builder : *String_Bui case .Binary; { pretty_print_binary(node, indentation, builder, skip_indent); } + case .Access; { + pretty_print_access(node, indentation, builder, skip_indent); + } case .Unary; { pretty_print_unary(node, indentation, builder, skip_indent); } diff --git a/Check.jai b/Check.jai index aff2f0d..a5ded95 100644 --- a/Check.jai +++ b/Check.jai @@ -5,9 +5,12 @@ ///////////////////////////////////// //~ nbr: Error reporting TODOs // +// [ ] Add a sentinel variable that works for from_handle // [ ] Add and error for using keywords as names, or rename the dx11 keywords in the resulting hlsl shader. // [ ] Add missing scope in for loop for loop iterator // [ ] Maybe we remove the resource index on type variables, seems like we don't need it there. +// [ ] Add swizzling +// [ ] Add temp assignment fail check: (a + b).x = float2(0, 0); // [x] Improve error reporting on mismatched overloads when types don't match, but arity does. // [x] Improve error reporting for type mismatches in general. It seems like the expect node is not always correct. @@ -472,12 +475,10 @@ Attempting to access a field on a primitive type '%'. print_to_builder(*builder, "%\n", print_from_source_location(checker.ctx, node.source_location)); indent(*builder, 1); - node_variable := from_handle(checker, node.type_variable); - - for 0..node.name.count - 1 { - append(*builder, " "); - } - print_token_pointer(*builder, node.source_location.begin); + // for 0..variable.source_node.name.count - 1 { + // append(*builder, " "); + // } + print_token_pointer(*builder, node.source_location.main_token); append(*builder, "\n"); @@ -1081,10 +1082,31 @@ declare_buffer :: (checker : *Checker, node : *AST_Node) -> Type_Variable_Handle variable.source_kind = .Declaration; variable.name = node.name; - variable.element_type = declare_struct(checker, node); // Won't work entirely like this. At least we're going to need some access changes + find_result := find_symbol(checker, node.name, checker.current_scope); + if !find_result { + symbol : Defined_Symbol; + symbol.name = node.name; + symbol.source_node = node; + symbol.type_variable = handle; + add_symbol_to_scope(checker.state, *checker.ctx.scope_stack, checker.current_scope, node.name, symbol); + } else { + symbol_redeclaration(checker, node, find_result); + return 0; + } + + buffer_struct_name := sprint("%_buffer_substruct___%", random_get(), node.name); + variable.element_type = declare_struct(checker, node, buffer_struct_name); // Won't work entirely like this. At least we're going to need some access changes variable.resource_index = checker.current_buffer_index; + element := from_handle(checker, variable.element_type); + scope := get_scope(checker, element.scope); + scope.builtin = true; + variable.scope = element.scope; + checker.current_buffer_index += 1; + + node.type_variable = handle; + array_add(*checker.ctx.buffers, handle); return handle; } @@ -1139,7 +1161,7 @@ declare_function :: (checker : *Checker, node : *AST_Node, builtin : bool = fals symbol.source_node = node; symbol.type_variable = 0; symbol.functions.allocator = get_current_scope(checker).allocator; - array_reserve(*symbol.functions, 32); + array_reserve(*symbol.functions, 4); array_add(*symbol.functions, function); add_symbol_to_scope(checker.state, *checker.ctx.scope_stack, checker.current_scope, name_to_check, symbol); @@ -1202,7 +1224,8 @@ declare_function :: (checker : *Checker, node : *AST_Node, builtin : bool = fals variable.scope = scope_handle; } - for child : node.children { + for i : 0..node.children.count - 1 { + child := node.children[i]; if child.kind == .FieldList { for field : child.children { type_var := check_node(checker, field); @@ -1573,6 +1596,33 @@ check_node :: (checker : *Checker, node : *AST_Node) -> Type_Variable_Handle { return handle; } + case .Access; { + lhs_handle := check_node(checker, node.children[0]); + if lhs_handle == 0 { + return 0; + } + + lhs_variable := from_handle(checker, lhs_handle); + if lhs_variable.type != .Struct && lhs_variable.type != .CBuffer { + field_access_on_primitive_type(checker, node.children[0], lhs_handle); + return 0; + } + lookup_name := lhs_variable.typename; + struct_symbol := find_symbol(checker, lookup_name, checker.current_scope); + type_variable := from_handle(checker, struct_symbol.type_variable); + + previous_scope := use_scope(checker, type_variable.scope); + member := node.children[1]; + var := find_symbol(checker, member.name, type_variable.scope); + if var == null { + field_not_defined_on_struct(checker, member, struct_symbol); + return 0; + } + + access := check_node(checker, member); + use_scope(checker, previous_scope); + return access; + } case .Binary; { lhs_var := check_node(checker, node.children[0]); if lhs_var == 0 { @@ -1587,7 +1637,14 @@ check_node :: (checker : *Checker, node : *AST_Node) -> Type_Variable_Handle { lhs_type := from_handle(checker, lhs_var); rhs_type := from_handle(checker, rhs_var); - variable.type = lhs_type.type; + if lhs_type.type == .Array { + element := from_handle(checker, lhs_type.element_type); + variable.type = element.type; + variable.typename = element.typename; + } else { + variable.type = lhs_type.type; + } + variable.typename = lhs_type.typename; variable.scope = lhs_type.scope; variable.source_node = node; @@ -1621,9 +1678,16 @@ check_node :: (checker : *Checker, node : *AST_Node) -> Type_Variable_Handle { } } case .TOKEN_ASSIGN; { - if !types_compatible(checker, lhs_var, rhs_var) { - type_mismatch(checker, node.parent, node.children[1], lhs_var, rhs_var); - return 0; + if lhs_type.type == .Array { + if !types_compatible(checker, lhs_type.element_type, rhs_var) { + type_mismatch(checker, node.parent, node.children[1], lhs_var, rhs_var); + return 0; + } + } else { + if !types_compatible(checker, lhs_var, rhs_var) { + type_mismatch(checker, node.parent, node.children[1], lhs_var, rhs_var); + return 0; + } } } case .TOKEN_GREATER; #through; @@ -1746,7 +1810,17 @@ is_valid_define :: (checker : *Checker, def : string) -> bool { } check_env_expression :: (checker : *Checker, expr : *AST_Node, directive : *AST_Node) -> bool { - if expr.kind == .Binary { + if expr.kind == .Access { + lhs := expr.children[0]; + if lhs.kind == .Variable && lhs.name == "Env" { + rhs := expr.children[1]; + + return is_valid_define(checker, rhs.name); + } else { + return check_env_expression(checker, lhs, directive); + } + } + else if expr.kind == .Binary { lhs := expr.children[0]; rhs := expr.children[1]; @@ -1759,6 +1833,7 @@ check_env_expression :: (checker : *Checker, expr : *AST_Node, directive : *AST_ return lhs_valid && rhs_valid; } } else if expr.kind == .Variable { + assert(false, ""); if expr.name == "Env" { child := expr.children[0]; // The variable in the environment @@ -1883,8 +1958,6 @@ types_compatible :: (checker : *Checker, lhs : Type_Variable_Handle, rhs : Type_ return rhs_var.type == lhs_var.type; } case .Struct; { - lhs_node := lhs_var.source_node; - rhs_node := rhs_var.source_node; if rhs_var.type != .Struct && !param_matching { if lhs_var.typename == { case "float2"; #through; @@ -2451,14 +2524,21 @@ pretty_print_scope :: (ctx : *Compiler_Context, current_scope : Scope_Handle, sc pretty_print_struct(ctx, *scope_stack, current_scope, variables, builder, key, type_variable, 1); append(builder, "\n"); } + case .Buffer; { + element := from_handle(variables, type_variable.element_type); + pretty_print_struct(ctx, *scope_stack, current_scope, variables, builder, key, element, 1); + append(builder, "\n"); + } case .Struct; { - if type_variable.typename.count > 0 && !type_variable.builtin && (type_variable.source_kind != .Declaration || type_variable.source_node.kind != .Struct) { - indent(builder, indentation + 1); - print_key(*scope_stack, current_scope, builder, key); - print_to_builder(builder, "%\n", type_variable.typename); - } else { - pretty_print_struct(ctx, *scope_stack, current_scope, variables, builder, key, type_variable, indentation); - append(builder, "\n"); + if type_variable.source_node.kind != .Buffer { + if type_variable.typename.count > 0 && !type_variable.builtin && (type_variable.source_kind != .Declaration || type_variable.source_node.kind != .Struct) { + indent(builder, indentation + 1); + print_key(*scope_stack, current_scope, builder, key); + print_to_builder(builder, "%\n", type_variable.typename); + } else { + pretty_print_struct(ctx, *scope_stack, current_scope, variables, builder, key, type_variable, indentation); + append(builder, "\n"); + } } } case; { @@ -2501,6 +2581,9 @@ print_type_variable :: (ctx : *Compiler_Context, builder : *String_Builder, vari } print_to_builder(builder, "%", node.name); + } + case .Access; { + } case .Binary; { left_most := node.children[0]; @@ -2582,3 +2665,4 @@ pretty_print_symbol_table :: (ctx : *Compiler_Context, allocator : Allocator) -> #import "ncore"; #import "Hash_Table"; #import "String"; +#import "Random"; diff --git a/Codegen.jai b/Codegen.jai index 8ba13f8..6e9d867 100644 --- a/Codegen.jai +++ b/Codegen.jai @@ -146,13 +146,20 @@ emit_field :: (state : *Codegen_State, node : *AST_Node, indentation : int) { } emit_block :: (state : *Codegen_State, node : *AST_Node, indentation : int) { + previous_scope := state.current_scope; + for statement : node.children { + if statement.type_variable { + state.current_scope = from_handle(state.ctx.type_variables, statement.type_variable).scope; + } + emit_node(state, statement, indentation); if it_index < node.children.count { append(*state.builder, "\n"); } } + state.current_scope = previous_scope; } emit_call :: (state : *Codegen_State, node : *AST_Node, indentation : int) { @@ -379,11 +386,24 @@ emit_node :: (state : *Codegen_State, node : *AST_Node, indentation : int) { emit_node(state, node.children[0], 0); } } + case .Access; { + indent(*state.builder, indentation); + + lhs := node.children[0]; + rhs := node.children[1]; + + emit_node(state, lhs, 0); + + print_to_builder(*state.builder, "%.", node.name); + emit_node(state, rhs, 0); + } case .Binary; { indent(*state.builder, indentation); if node.token.kind != .TOKEN_ASSIGN && node.token.kind != .TOKEN_LEFTBRACKET { - append(*state.builder, "("); + if node.parent.kind == .Binary && node.parent.token.kind != .TOKEN_ASSIGN { + append(*state.builder, "("); + } } lhs := node.children[0]; @@ -405,7 +425,9 @@ emit_node :: (state : *Codegen_State, node : *AST_Node, indentation : int) { if node.token.kind != .TOKEN_ASSIGN && node.token.kind != .TOKEN_LEFTBRACKET { - append(*state.builder, ")"); + if node.parent.kind == .Binary && node.parent.token.kind != .TOKEN_ASSIGN { + append(*state.builder, ")"); + } } } case .Unary; { @@ -455,7 +477,9 @@ emit_node :: (state : *Codegen_State, node : *AST_Node, indentation : int) { append(*state.builder, "if "); cond := node.children[0]; + append(*state.builder, "("); emit_node(state, cond, 0); + append(*state.builder, ")"); body := node.children[1]; append(*state.builder, "\n"); @@ -543,6 +567,17 @@ emit_cbuffer :: (state : *Codegen_State, node : *AST_Node, indentation : int) { state.current_scope = current_scope; } +emit_buffer :: (state : *Codegen_State, node : *AST_Node, indentation : int) { + variable := from_handle(state.ctx.type_variables, node.type_variable); + element := from_handle(state.ctx.type_variables, variable.element_type); + + emit_struct(state, node, indentation); + // print_to_builder(*state.builder, "struct %\n", element.name); + + print_to_builder(*state.builder, "StructuredBuffer<%> %;\n\n", element.typename, variable.name); + +} + emit_declaration :: (state : *Codegen_State, node : *AST_Node) { if node.kind == { case .Function; { @@ -551,6 +586,9 @@ emit_declaration :: (state : *Codegen_State, node : *AST_Node) { case .CBuffer; { emit_cbuffer(state, node, 0); } + case .Buffer; { + emit_buffer(state, node, 0); + } case .Struct; { emit_struct(state, node, 0); } diff --git a/Parsing.jai b/Parsing.jai index 8e09a92..7d8b41f 100644 --- a/Parsing.jai +++ b/Parsing.jai @@ -818,50 +818,7 @@ directive :: (state : *Parse_State) -> *AST_Node { if_directive.source_location = source_location; return if_directive; - } else if state.current.ident_value == "load" { - advance(state); - - if check(state, .TOKEN_STRING) { - // path_tok := state.current; - // path := path_tok.string_value; - - // advance(state); - - // result : Compiler_Context; - // ctx.allocator = state.ctx.allocator; - // ctx.environment = state.ctx.environment; - - // ctx.file = make_file(*result, path); - - // if ctx.file.source.count == 0 { - // unable_to_open_file(state, path, path_tok); - // advance_to_sync_point(state); - // advance(state); - // return null; - // } - - // consume(state, .TOKEN_SEMICOLON, "Expected ';' after #load directive"); - - // lex(*result); - - // count := state.ctx.tokens..count; - // current_idx := state.current_token_index; - // result_count := ctx.tokens..count; - - // // state.ctx.tokens..count -= 1; - // array_resize(*state.ctx.tokens., count + result_count - 1); - - // memcpy(*state.ctx.tokens[current_idx + result_count - 1], *state.ctx.tokens[current_idx], size_of(Token) * (count - current_idx)); - - // for *tok : ctx.tokens. { - // if tok.kind == .TOKEN_EOF { - // break; - // } - // tok.builtin = true; - // state.ctx.tokens[it_index] = tok.*; - // } - } - } + } return null; } @@ -898,34 +855,30 @@ dot :: (parse_state : *Parse_State, left : *AST_Node) -> *AST_Node { source_location : Source_Range; source_location.begin = left.source_location.begin; + source_location.main_token = identifier; - if check_any(parse_state, .TOKEN_ASSIGN, .TOKEN_MINUSEQUALS, .TOKEN_PLUSEQUALS, .TOKEN_DIVEQUALS, .TOKEN_MODEQUALS, .TOKEN_TIMESEQUALS) { - advance(parse_state); - variable := make_node(parse_state, .Variable); - variable.source_location = generate_source_location_from_token(parse_state, identifier); - variable.name = identifier.ident_value; - - add_child(left, variable); - - node := make_node(parse_state, .Binary); - node.token = parse_state.previous; - add_child(node, left); - add_child(node, expression(parse_state)); - return node; - } + access := make_node(parse_state, .Access); + variable := make_node(parse_state, .Variable); variable.name = identifier.ident_value; - if check(parse_state, .TOKEN_DOT) { - advance(parse_state); - dot(parse_state, variable); - } - - add_child(left, variable); + add_child(access, left); + add_child(access, variable); - source_location.end = parse_state.previous; - variable.source_location = source_location; - return left; + if check_any(parse_state, .TOKEN_ASSIGN, .TOKEN_MINUSEQUALS, .TOKEN_PLUSEQUALS, .TOKEN_DIVEQUALS, .TOKEN_MODEQUALS, .TOKEN_TIMESEQUALS) { + advance(parse_state); + access.source_location = generate_source_location_from_token(parse_state, identifier); + + node := make_node(parse_state, .Binary); + node.token = parse_state.previous; + add_child(node, access); + add_child(node, expression(parse_state)); + return node; + } + + source_location.end = parse_state.current; + access.source_location = source_location; + return access; } integer :: (parse_state : *Parse_State, left : *AST_Node) -> *AST_Node { @@ -1557,4 +1510,4 @@ parse :: (ctx : *Compiler_Context, allocator := temp) { } } -#load "AST.jai"; +#load "ast.jai"; diff --git a/first.jai b/first.jai index 5fc2bc5..90b6e89 100644 --- a/first.jai +++ b/first.jai @@ -13,7 +13,7 @@ build :: () { } EXECUTABLE_NAME :: "ink"; - MAIN_FILE :: "Ink.jai"; + MAIN_FILE :: "ink.jai"; options := get_build_options(w); diff --git a/module.jai b/module.jai index a4b4ec2..af15024 100644 --- a/module.jai +++ b/module.jai @@ -1,8 +1,8 @@ -#load "Lexing.jai"; -#load "Error.jai"; -#load "Parsing.jai"; -#load "Check.jai"; -#load "Codegen.jai"; +#load "lexing.jai"; +#load "error.jai"; +#load "parsing.jai"; +#load "check.jai"; +#load "codegen.jai"; #import "File_Utilities"; diff --git a/test/arithmetic_parens.ink b/test/arithmetic_parens.ink new file mode 100644 index 0000000..a3f41ae --- /dev/null +++ b/test/arithmetic_parens.ink @@ -0,0 +1,4 @@ +vertex main :: () { + v : float2; + v.x = (2.0 + ((4.0 - 2.0) * 1.5)) * 3.0; +} diff --git a/test/arrays.ink b/test/arrays.ink index 30edcb9..65924e0 100644 --- a/test/arrays.ink +++ b/test/arrays.ink @@ -1,5 +1,6 @@ vertex main :: () -> float4 @position { arr : [16].float4; - // arr[0] = float4(1,1,1); - return arr[0]; + arr[0] = float4(1, 1, 1, 1); + pos := arr[1]; + return pos; } diff --git a/test/assign_temporary.ink b/test/assign_temporary.ink new file mode 100644 index 0000000..28eb3fb --- /dev/null +++ b/test/assign_temporary.ink @@ -0,0 +1,5 @@ +vertex main :: () { + a : float2; + b : float2; + (a + b).x = 2.0; +} diff --git a/test/bad_double_access.ink b/test/bad_double_access.ink new file mode 100644 index 0000000..06a5af9 --- /dev/null +++ b/test/bad_double_access.ink @@ -0,0 +1,10 @@ +P :: struct { + v : float2; +} + +vertex main :: () { + p : P; + p.v.x.y = 2.0; + // v : float2; + // v.x.y.z = 2.0; +} diff --git a/test/buffers.ink b/test/buffers.ink index 284777d..5686b6e 100644 --- a/test/buffers.ink +++ b/test/buffers.ink @@ -2,7 +2,7 @@ property_buffer :: buffer { color : float4; } -cbuffer :: constant_buffer { +const_buffer :: constant_buffer { color : float4; } diff --git a/test/check/arithmetic_parens.golden b/test/check/arithmetic_parens.golden new file mode 100644 index 0000000..87669a5 --- /dev/null +++ b/test/check/arithmetic_parens.golden @@ -0,0 +1,6 @@ +scope (global) [ + [vertex__vs_main] : () + scope (vertex__vs_main) [ + [v] : float2 + ] +] diff --git a/test/check/arrays.golden b/test/check/arrays.golden new file mode 100644 index 0000000..0d76cac --- /dev/null +++ b/test/check/arrays.golden @@ -0,0 +1,7 @@ +scope (global) [ + [vertex__vs_main] : () -> float4 + scope (vertex__vs_main) [ + [pos] : float4 + [arr] : [16].float4 + ] +] diff --git a/test/check/bad_double_access.golden b/test/check/bad_double_access.golden new file mode 100644 index 0000000..526698b --- /dev/null +++ b/test/check/bad_double_access.golden @@ -0,0 +1,6 @@ +test/bad_double_access.ink:7,4: error: Attempting to access a field on a primitive type 'float'. + p.v.x. + ^ + declaration: + x: float + \ No newline at end of file diff --git a/test/check/double_access.golden b/test/check/double_access.golden new file mode 100644 index 0000000..b3ad007 --- /dev/null +++ b/test/check/double_access.golden @@ -0,0 +1,10 @@ +scope (global) [ + [vertex__vs_main] : () + [p] : {v : float2} + scope (p) [ + [v] : float2 + ] + scope (vertex__vs_main) [ + [x] : float + ] +] diff --git a/test/check/struct_access_primitive_type.golden b/test/check/struct_access_primitive_type.golden index abffb44..7c4130f 100644 --- a/test/check/struct_access_primitive_type.golden +++ b/test/check/struct_access_primitive_type.golden @@ -1,6 +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  \ No newline at end of file diff --git a/test/check_all.suite b/test/check_all.suite index 74433b4..bb2defe 100644 --- a/test/check_all.suite +++ b/test/check_all.suite @@ -1,8 +1,11 @@ test/assign_arithmetic_expression.ink check +test/arithmetic_parens.ink check test/basic_property_and_return_value.ink check test/builtin_types.ink check test/complicated_computation.ink check test/constant_buffer.ink check +test/bad_double_access.ink check +test/double_access.ink check test/empty_struct.ink check test/empty_vertex_main.ink check test/empty_vertex_main_with_position_parameter.ink check diff --git a/test/codegen/arithmetic_parens.golden b/test/codegen/arithmetic_parens.golden new file mode 100644 index 0000000..12ef3e9 --- /dev/null +++ b/test/codegen/arithmetic_parens.golden @@ -0,0 +1,6 @@ +void vs_main() +{ + float2 v; + v.x = (2.0f + ((4.0f - 2.0f) * 1.5f)) * 3.0f; +} + diff --git a/test/codegen/assign_arithmetic_expression.golden b/test/codegen/assign_arithmetic_expression.golden index 5e3f49c..81b0e2f 100644 --- a/test/codegen/assign_arithmetic_expression.golden +++ b/test/codegen/assign_arithmetic_expression.golden @@ -1,5 +1,5 @@ void vs_main() { - float x = (2.0f + 5.0f); + float x = 2.0f + 5.0f; } diff --git a/test/codegen/builtin_types.golden b/test/codegen/builtin_types.golden index 3d6de21..a4b5e80 100644 --- a/test/codegen/builtin_types.golden +++ b/test/codegen/builtin_types.golden @@ -21,8 +21,8 @@ void vs_main() v4 = float4(2.0f, 2.0f, 2.0f, 2.0f); v2.x = 2.0f; v2.y = 2.0f; - float p = (v2.x + v3.z); - float q = (v4.w + v2.x); + float p = v2.x + v3.z; + float q = v4.w + v2.x; float4x4 m; } diff --git a/test/codegen/complicated_computation.golden b/test/codegen/complicated_computation.golden index 901e40e..2f5340d 100644 --- a/test/codegen/complicated_computation.golden +++ b/test/codegen/complicated_computation.golden @@ -2,6 +2,6 @@ void vs_main() { float x = 5.0f; float y = 3000.0f; - float z = ((y * y) + x); + float z = (y * y) + x; } diff --git a/test/codegen/multiple_functions.golden b/test/codegen/multiple_functions.golden index 047de23..a2a8be4 100644 --- a/test/codegen/multiple_functions.golden +++ b/test/codegen/multiple_functions.golden @@ -8,7 +8,7 @@ int foo() float bar() { - return (1235.0f * 500); + return 1235.0f * 500; } void vs_main() diff --git a/test/codegen/pass_and_access_struct_fields_in_functions.golden b/test/codegen/pass_and_access_struct_fields_in_functions.golden index e54492e..4f97657 100644 --- a/test/codegen/pass_and_access_struct_fields_in_functions.golden +++ b/test/codegen/pass_and_access_struct_fields_in_functions.golden @@ -7,7 +7,7 @@ struct Foo float foo(Foo f) { - return (f.some_data * 2.0f); + return f.some_data * 2.0f; } void vs_main() diff --git a/test/codegen_all.suite b/test/codegen_all.suite index aea0f03..dee580a 100644 --- a/test/codegen_all.suite +++ b/test/codegen_all.suite @@ -1,4 +1,5 @@ test/assign_arithmetic_expression.ink codegen +test/arithmetic_parens.ink codegen test/basic_property_and_return_value.ink codegen test/builtin_types.ink codegen test/complicated_computation.ink codegen diff --git a/test/compile_all.suite b/test/compile_all.suite index bbbedd4..e183372 100644 --- a/test/compile_all.suite +++ b/test/compile_all.suite @@ -1,4 +1,5 @@ test/assign_arithmetic_expression.ink compile +test/arithmetic_parens.ink compile test/basic_property_and_return_value.ink compile test/builtin_types.ink compile test/complicated_computation.ink compile diff --git a/test/double_access.ink b/test/double_access.ink index ccec911..13948cf 100644 --- a/test/double_access.ink +++ b/test/double_access.ink @@ -1,4 +1,4 @@ -p :: properties { +p :: constant_buffer { v : float2; } diff --git a/test/lex/arithmetic_parens.golden b/test/lex/arithmetic_parens.golden new file mode 100644 index 0000000..c4ce08a --- /dev/null +++ b/test/lex/arithmetic_parens.golden @@ -0,0 +1,32 @@ +{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_RIGHTPAREN; ; index = 16 ; length = 1 line = 1 ; column = 16 ; value =')'; } +{kind = TOKEN_LEFTBRACE; ; index = 18 ; length = 1 line = 1 ; column = 18 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 22 ; length = 1 line = 2 ; column = 0 ; value ='v'; } +{kind = TOKEN_COLON; ; index = 24 ; length = 1 line = 2 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 26 ; length = 6 line = 2 ; column = 4 ; value ='float2'; } +{kind = TOKEN_SEMICOLON; ; index = 32 ; length = 1 line = 2 ; column = 10 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 36 ; length = 1 line = 3 ; column = 0 ; value ='v'; } +{kind = TOKEN_DOT; ; index = 37 ; length = 1 line = 3 ; column = 1 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 38 ; length = 1 line = 3 ; column = 2 ; value ='x'; } +{kind = TOKEN_ASSIGN; ; index = 40 ; length = 1 line = 3 ; column = 4 ; value ='='; } +{kind = TOKEN_LEFTPAREN; ; index = 42 ; length = 1 line = 3 ; column = 6 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 43 ; length = 3 line = 3 ; column = 7 ; value ='2'; } +{kind = TOKEN_PLUS; ; index = 47 ; length = 1 line = 3 ; column = 11 ; value ='+'; } +{kind = TOKEN_LEFTPAREN; ; index = 49 ; length = 1 line = 3 ; column = 13 ; value ='('; } +{kind = TOKEN_LEFTPAREN; ; index = 50 ; length = 1 line = 3 ; column = 14 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 51 ; length = 3 line = 3 ; column = 15 ; value ='4'; } +{kind = TOKEN_MINUS; ; index = 55 ; length = 1 line = 3 ; column = 19 ; value ='-'; } +{kind = TOKEN_FLOATLITERAL; ; index = 57 ; length = 3 line = 3 ; column = 21 ; value ='2'; } +{kind = TOKEN_RIGHTPAREN; ; index = 60 ; length = 1 line = 3 ; column = 24 ; value =')'; } +{kind = TOKEN_STAR; ; index = 62 ; length = 1 line = 3 ; column = 26 ; value ='*'; } +{kind = TOKEN_FLOATLITERAL; ; index = 64 ; length = 3 line = 3 ; column = 28 ; value ='1.5'; } +{kind = TOKEN_RIGHTPAREN; ; index = 67 ; length = 1 line = 3 ; column = 31 ; value =')'; } +{kind = TOKEN_RIGHTPAREN; ; index = 68 ; length = 1 line = 3 ; column = 32 ; value =')'; } +{kind = TOKEN_STAR; ; index = 70 ; length = 1 line = 3 ; column = 34 ; value ='*'; } +{kind = TOKEN_FLOATLITERAL; ; index = 72 ; length = 3 line = 3 ; column = 36 ; value ='3'; } +{kind = TOKEN_SEMICOLON; ; index = 75 ; length = 1 line = 3 ; column = 39 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 78 ; length = 1 line = 4 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 81 ; length = 0 line = 5 ; column = 0 ; value =''; } diff --git a/test/lex/bad_double_access.golden b/test/lex/bad_double_access.golden new file mode 100644 index 0000000..87daa28 --- /dev/null +++ b/test/lex/bad_double_access.golden @@ -0,0 +1,31 @@ +{kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 1 line = 1 ; column = 0 ; value ='P'; } +{kind = TOKEN_DOUBLECOLON; ; index = 2 ; length = 2 line = 1 ; column = 2 ; value ='::'; } +{kind = TOKEN_STRUCT; ; index = 5 ; length = 6 line = 1 ; column = 5 ; value ='struct'; } +{kind = TOKEN_LEFTBRACE; ; index = 12 ; length = 1 line = 1 ; column = 12 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 16 ; length = 1 line = 2 ; column = 0 ; value ='v'; } +{kind = TOKEN_COLON; ; index = 18 ; length = 1 line = 2 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 20 ; length = 6 line = 2 ; column = 4 ; value ='float2'; } +{kind = TOKEN_SEMICOLON; ; index = 26 ; length = 1 line = 2 ; column = 10 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 29 ; length = 1 line = 3 ; column = 0 ; value ='}'; } +{kind = TOKEN_VERTEX; ; index = 34 ; length = 6 line = 5 ; column = 0 ; value ='vertex'; } +{kind = TOKEN_IDENTIFIER; ; index = 41 ; length = 4 line = 5 ; column = 7 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 46 ; length = 2 line = 5 ; column = 12 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 49 ; length = 1 line = 5 ; column = 15 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 50 ; length = 1 line = 5 ; column = 16 ; value =')'; } +{kind = TOKEN_LEFTBRACE; ; index = 52 ; length = 1 line = 5 ; column = 18 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 56 ; length = 1 line = 6 ; column = 0 ; value ='p'; } +{kind = TOKEN_COLON; ; index = 58 ; length = 1 line = 6 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 60 ; length = 1 line = 6 ; column = 4 ; value ='P'; } +{kind = TOKEN_SEMICOLON; ; index = 61 ; length = 1 line = 6 ; column = 5 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 65 ; length = 1 line = 7 ; column = 0 ; value ='p'; } +{kind = TOKEN_DOT; ; index = 66 ; length = 1 line = 7 ; column = 1 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 67 ; length = 1 line = 7 ; column = 2 ; value ='v'; } +{kind = TOKEN_DOT; ; index = 68 ; length = 1 line = 7 ; column = 3 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 69 ; length = 1 line = 7 ; column = 4 ; value ='x'; } +{kind = TOKEN_DOT; ; index = 70 ; length = 1 line = 7 ; column = 5 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 71 ; length = 1 line = 7 ; column = 6 ; value ='y'; } +{kind = TOKEN_ASSIGN; ; index = 73 ; length = 1 line = 7 ; column = 8 ; value ='='; } +{kind = TOKEN_FLOATLITERAL; ; index = 75 ; length = 3 line = 7 ; column = 10 ; value ='2'; } +{kind = TOKEN_SEMICOLON; ; index = 78 ; length = 1 line = 7 ; column = 13 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 118 ; length = 1 line = 10 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 121 ; length = 0 line = 11 ; column = 0 ; value =''; } diff --git a/test/lex/double_access.golden b/test/lex/double_access.golden new file mode 100644 index 0000000..4e79e91 --- /dev/null +++ b/test/lex/double_access.golden @@ -0,0 +1,33 @@ +{kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 1 line = 1 ; column = 0 ; value ='p'; } +{kind = TOKEN_DOUBLECOLON; ; index = 2 ; length = 2 line = 1 ; column = 2 ; value ='::'; } +{kind = TOKEN_CONSTANT_BUFFER; ; index = 5 ; length = 15 line = 1 ; column = 5 ; value ='constant_buffer'; } +{kind = TOKEN_LEFTBRACE; ; index = 21 ; length = 1 line = 1 ; column = 21 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 25 ; length = 1 line = 2 ; column = 0 ; value ='v'; } +{kind = TOKEN_COLON; ; index = 27 ; length = 1 line = 2 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 29 ; length = 6 line = 2 ; column = 4 ; value ='float2'; } +{kind = TOKEN_SEMICOLON; ; index = 35 ; length = 1 line = 2 ; column = 10 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 38 ; length = 1 line = 3 ; column = 0 ; value ='}'; } +{kind = TOKEN_VERTEX; ; index = 43 ; length = 6 line = 5 ; column = 0 ; value ='vertex'; } +{kind = TOKEN_IDENTIFIER; ; index = 50 ; length = 4 line = 5 ; column = 7 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 55 ; length = 2 line = 5 ; column = 12 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 57 ; length = 1 line = 5 ; column = 14 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 58 ; length = 1 line = 5 ; column = 15 ; value =')'; } +{kind = TOKEN_LEFTBRACE; ; index = 60 ; length = 1 line = 5 ; column = 17 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 64 ; length = 1 line = 6 ; column = 0 ; value ='x'; } +{kind = TOKEN_COLON; ; index = 66 ; length = 1 line = 6 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 68 ; length = 5 line = 6 ; column = 4 ; value ='float'; } +{kind = TOKEN_ASSIGN; ; index = 74 ; length = 1 line = 6 ; column = 10 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 76 ; length = 1 line = 6 ; column = 12 ; value ='p'; } +{kind = TOKEN_DOT; ; index = 77 ; length = 1 line = 6 ; column = 13 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 78 ; length = 1 line = 6 ; column = 14 ; value ='v'; } +{kind = TOKEN_DOT; ; index = 79 ; length = 1 line = 6 ; column = 15 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 80 ; length = 1 line = 6 ; column = 16 ; value ='x'; } +{kind = TOKEN_SLASH; ; index = 82 ; length = 1 line = 6 ; column = 18 ; value ='/'; } +{kind = TOKEN_IDENTIFIER; ; index = 84 ; length = 1 line = 6 ; column = 20 ; value ='p'; } +{kind = TOKEN_DOT; ; index = 85 ; length = 1 line = 6 ; column = 21 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 86 ; length = 1 line = 6 ; column = 22 ; value ='v'; } +{kind = TOKEN_DOT; ; index = 87 ; length = 1 line = 6 ; column = 23 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 88 ; length = 1 line = 6 ; column = 24 ; value ='y'; } +{kind = TOKEN_SEMICOLON; ; index = 89 ; length = 1 line = 6 ; column = 25 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 92 ; length = 1 line = 7 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 95 ; length = 0 line = 8 ; column = 0 ; value =''; } diff --git a/test/lex_all.suite b/test/lex_all.suite index dc0a147..a7ad7f3 100644 --- a/test/lex_all.suite +++ b/test/lex_all.suite @@ -1,8 +1,11 @@ test/assign_arithmetic_expression.ink lex +test/arithmetic_parens.ink lex +test/bad_double_access.ink lex test/basic_property_and_return_value.ink lex test/builtin_types.ink lex test/complicated_computation.ink lex test/constant_buffer.ink lex +test/double_access.ink lex test/else_if_after_else.ink lex test/empty_struct.ink lex test/empty_vertex_main.ink lex diff --git a/test/parse/arithmetic_parens.golden b/test/parse/arithmetic_parens.golden new file mode 100644 index 0000000..c8faa17 --- /dev/null +++ b/test/parse/arithmetic_parens.golden @@ -0,0 +1,5 @@ +(program + (fun vertex vs_main + [] + (:= v float2) + (= v.x (* (+ 2 (* (- 4 2) 1.5)) 3)))) \ No newline at end of file diff --git a/test/parse/bad_double_access.golden b/test/parse/bad_double_access.golden new file mode 100644 index 0000000..7cd16a8 --- /dev/null +++ b/test/parse/bad_double_access.golden @@ -0,0 +1,8 @@ +(program + (struct P + [(:= v float2)]) + + (fun vertex vs_main + [] + (:= p P) + (= p.v.x.y 2))) \ No newline at end of file diff --git a/test/parse/buffers.golden b/test/parse/buffers.golden new file mode 100644 index 0000000..7e145d0 --- /dev/null +++ b/test/parse/buffers.golden @@ -0,0 +1,10 @@ +(program + (buffer property_buffer + [(:= color float4)]) + + (constant_buffer cbuffer + [(:= color float4)]) + + (fun pixel ps_main + [(:= index int)] + (return property_buffer[index].color))) \ No newline at end of file diff --git a/test/parse/double_access.golden b/test/parse/double_access.golden new file mode 100644 index 0000000..0d7fa26 --- /dev/null +++ b/test/parse/double_access.golden @@ -0,0 +1,7 @@ +(program + (constant_buffer p + [(:= v float2)]) + + (fun vertex vs_main + [] + (:= x float (/ p.v.x p.v.y)))) \ No newline at end of file diff --git a/test/parse_all.suite b/test/parse_all.suite index d4e1841..e35fd1c 100644 --- a/test/parse_all.suite +++ b/test/parse_all.suite @@ -1,8 +1,11 @@ test/assign_arithmetic_expression.ink parse +test/arithmetic_parens.ink parse +test/bad_double_access.ink parse test/basic_property_and_return_value.ink parse test/builtin_types.ink parse test/complicated_computation.ink parse test/constant_buffer.ink parse +test/double_access.ink parse test/else_if_after_else.ink parse test/empty_struct.ink parse test/empty_vertex_main.ink parse