commit 9ec1b9cf8276b17f5adea657ea7f1ad0ca4d9261 Author: Niels Bross Date: Tue Sep 30 07:27:58 2025 +0200 Added Ink and ncore to modules diff --git a/README.md b/README.md new file mode 100644 index 0000000..61c7c18 --- /dev/null +++ b/README.md @@ -0,0 +1,202 @@ +# Shader Compiler + +A compiler for a custom, platform-agnostic shader language that compiles to platform specific shader languages (currently only HLSL). + +## Features + +A simple passthrough shader (`passthrough.shd`) can look as follows +```hlsl +vertex main :: (position : float4 @position) -> float4 { + return position; +} + +pixel main :: () -> float4 @target { + return float4(1, 1, 1, 1); +} +``` +The shader contains both vertex and pixel shader code, where you specify the entry points as above. Entry points can have any and overlapping names, which will be exposed in the meta data of a compiled shader. +There is basic support for most HLSL built-in math functions for the following types: +- Scalar types: int, float +- Vector types: float2, float3, float4, int2, int3, int4 +- Matrices: float4x4 +All of the above can be constructed with their namesake constructors i.e. `float4(x, y, z, w);`. +We also support Samplers and Texture2D + +If you want to declare and use variables you can do it as follows +```hlsl +x : float = 2.0; // no 'f' suffix required or even supported (it gives an error) +y : float = 4.0; +v : float2 = float2(x, y); +v2 := float2(x, y); +``` + +You can also do arithmetic as you would expect +``` +x : float = 2.0 * 4.0 + (3 * 2); // int literals automatically convert to floats. +``` + +There is basic struct support +```hlsl +Camera_Data :: struct { + projection : float4x4; + view : float4x4; +} +``` +And there is a special struct called `properties`, which is used for custom data you want to pass in. +#### ** Note: Properties will likely be deprecated, since the language now supports `@` hints to easily mark buffers and values with metadata.** +```hlsl +properties { + projection : float4x4; + view : float4x4; +} +``` +which will be exposed in the compiled result. `properties` can be renamed to a custom/shorter name like +``` +p :: properties { + ... + + +``` + +You can also define constant buffers + +``` +camera :: constant_buffer { + projection : float4x4; + view : float4x4; +} +``` + +## Jai Usage Example + +To compile a shader and use the result, you can do the following in jai +```jai + +// In the future, you can pass environment defines to the compiler. +ctx : Compiler_Context; +compile_file(*compiler, "shader.shd", allocator); + +if ctx.had_error { + log_error("%\n", report_messages(ctx.messages),, temp); + return; +} + +// The ctx now contains all the needed information like the source text, entry points, constant buffers etc. +``` + +When parsing a shader you get the following struct as a result +``` +Compiler_Context :: struct { + file : Input_File; + + environment : Environment; + + tokens : [..]Token;; + root : *AST_Node; + nodes : [..]AST_Node; + + codegen_result_text : string; + + constant_buffers : Static_Array(Type_Variable_Handle, 16); + + scope_stack : Scope_Stack; + type_variables : [..]Type_Variable; + + property_name : string; + + vertex_entry_point : struct { + node : *AST_Node; + name : string; + input : [..]Field; + } + + pixel_entry_point : struct { + node : *AST_Node; + name : string; + return_value : Field; + } + + properties : Properties; + + max_constant_buffers :: 16; + + cbuffers : Static_Array(Constant_Buffer, max_constant_buffers); + + had_error : bool; + messages : [..]Compiler_Message; +} + +Constant_Buffer :: struct { + name : string; + + fields : Static_Array(Property_Field, 16); + + // hints : Field_Hint; // optional hint... + hints : [..]Field_Hint; + + buffer_index : u32; +} + +Properties :: struct { + fields : [..]Property_Field; + + buffer_index : u32; +} +``` + +A field is just a simple struct with a name and type (and hints such as semantics or custom hints in the future) +``` +Field_Hint :: struct { + kind : Hint_Kind; + + target_index : int; + custom_hint_name : string; +} + +Field :: struct { + name : string; + + type : Field_Type; + hints : [..]Field_Hint; +} + +Field_Kind :: enum { + Int :: 0; + Half :: 1; + Float :: 2; + Double :: 3; + Texture2D :: 8; + Sampler :: 9; + + Function; + Struct; + Array; // Not yet supported +} + +Field_Type :: struct { + kind : Field_Kind; + + name : string; //@Note(niels): for structs + + children : [..]Field; +} + +Hint_Kind :: enum { + None; + + Position; + Target; + + Custom; +} +``` + +## Notable missing features + +- While +- Arrays +- Multiple render targets +- Custom buffers/structured buffers +- Interpolation specifiers +- Proper variant handling with environment defines +- Importing files such as shared utils etc. with something other than textual `#load` \ No newline at end of file diff --git a/ast.jai b/ast.jai new file mode 100644 index 0000000..b9a9f97 --- /dev/null +++ b/ast.jai @@ -0,0 +1,581 @@ +///////////////////////////////////// +//~ nbr: Node data structure +// +// [ ] Add a way to infer or get file path from a node + +AST_Kind :: enum { + Program; + Function; + Return; + + //== + // Directives + If_Directive; + + Access; + Call; + Struct; + If; + For; + CBuffer; + Buffer; + FieldList; + ArgList; + Variable; + Binary; + Unary; + Integer; + Float; + Expression_Statement; + Field; + Unnamed_Field; + Block; + Error; +} + +AST_Node :: struct { + kind : AST_Kind; + + // @Note(niels): Children nodes can be interpreted as anything useful. + // for an if-statement we would have at most 2 children + // a property block has a field list child node which has + // a child node for each field declaration etc. + children : [..]*AST_Node; + parent : *AST_Node; + + // @Note(niels): Every node can have a name, but most nodes don't. A function or field declaration has one, + // but an if-statement does not + name : string; + + integer_value : int; + float_value : float; + + token : Token; + + array_field : bool; + + source_location : Source_Range; + + type_variable : Type_Variable_Handle; + + foreign_declaration : bool; + + // @Incomplete(nb): Change this to just be children and a single token_data field, + // then we can add new node types (hint, typespec, operator) and have them + // as children instead. + hint_tokens : [..]Token; + + vertex_entry_point : bool; + pixel_entry_point : bool; +} + +// =========================================================== +// Pretty printing +pretty_print_call :: (node : *AST_Node, indentation : int, builder : *String_Builder, skip_indent := false) { + if !skip_indent { + indent(builder, indentation); + } + append(builder, "("); + append(builder, node.name); + if node.children.count > 0 { + append(builder, " "); + pretty_print_children(node.children[0], indentation, builder, flags = 0, skip_indent = true); + } + append(builder, ")"); +} + +pretty_print_arglist :: (node : *AST_Node, indentation : int, builder : *String_Builder, skip_indent := false) { + if !skip_indent { + indent(builder, indentation); + } + append(builder, "["); + + pretty_print_children(node, indentation + 1, builder, flags = .NewLine); + + append(builder, "]"); +} + +pretty_print_fieldlist :: (node : *AST_Node, indentation : int, builder : *String_Builder, skip_indent := false) { + if !skip_indent { + indent(builder, indentation); + } + + append(builder, "["); + pretty_print_children(node, indentation + 1, builder, flags = .NewLine); + + append(builder, "]"); +} + +pretty_print_field :: (node : *AST_Node, indentation : int, builder : *String_Builder, skip_indent := false) { + if !skip_indent { + indent(builder, indentation); + } + print_to_builder(builder, tprint("(:= %", node.name)); + + if node.kind != .Unnamed_Field && node.token.ident_value.count > 0 { + if node.array_field { + append(builder, " ["); + pretty_print_node(node.children[0], indentation, builder, true); + append(builder, "]."); + print_to_builder(builder, "%", node.token.ident_value); + } else { + print_to_builder(builder, " %", node.token.ident_value); + } + + } + + for hint : node.hint_tokens { + if hint.string_value.count > 0 { + print_to_builder(builder, " (@%)", hint.string_value); + } + } + + if !node.array_field && node.children.count > 0 { + append(builder, " "); + pretty_print_node(node.children[0], indentation, builder, true); + } + + append(builder, ")"); +} + +Children_Print_Flags :: enum_flags { + NewLine :: 1 << 0; + Separator :: 1 << 1; + Space :: 1 << 2; + Dont_Skip_Indent_On_First :: 1 << 3; +} + +pretty_print_block :: (node : *AST_Node, indentation : int, builder : *String_Builder, skip_indent := false) { + if node.children.count == 0 { + if !skip_indent { + indent(builder, indentation); + } + append(builder, "()"); + } else { + flags := Children_Print_Flags.NewLine; + if !skip_indent { + flags |= .Dont_Skip_Indent_On_First; + } + pretty_print_children(node, indentation, builder, flags); + } +} + +pretty_print_children :: (parent : *AST_Node, indentation : int, builder : *String_Builder, flags : Children_Print_Flags = .Separator, skip_indent := false) { + if !parent { + return; + } + + children := parent.children; + for child : children { + // if it_index > 0 { + // indent(builder, indentation); + // } + + if !child continue; + + + ind := indentation; + if flags & .Dont_Skip_Indent_On_First { + ind = indentation; + } else { + if it_index == 0 { + ind = 0; + } + } + + if skip_indent{ + ind = 0; + } + // skip := ifx it_index > 0 then false else true; + + if child.kind == .Function { + pretty_print_declaration(child, ind, builder); + } else { + pretty_print_node(child, ind, builder); + } + + + if it_index != children.count - 1 { + if flags & .Separator { + append(builder, ","); + } + + append(builder, " "); + + if flags & .NewLine { + append(builder, "\n"); + } + } + } +} + +op_to_string :: (oper : Token) -> string { + if oper.kind == { + case .TOKEN_PLUS; + return "+"; + case .TOKEN_MINUS; + return "-"; + case .TOKEN_STAR; + return "*"; + case .TOKEN_SLASH; + return "/"; + case .TOKEN_MINUSEQUALS; + return "-="; + case .TOKEN_PLUSEQUALS; + return "+="; + case .TOKEN_DIVEQUALS; + return "/="; + case .TOKEN_TIMESEQUALS; + return "*="; + case .TOKEN_MODEQUALS; + return "%="; + case .TOKEN_ISEQUAL; + return "=="; + case .TOKEN_ASSIGN; + return "="; + case .TOKEN_ISNOTEQUAL; + return "!="; + case .TOKEN_LOGICALOR; + return "||"; + case .TOKEN_LOGICALAND; + return "&&"; + case .TOKEN_LESS; + return "<"; + case .TOKEN_LESSEQUALS; + return "<="; + case .TOKEN_GREATER; + return ">"; + case .TOKEN_GREATEREQUALS; + return ">="; + } + return ""; +} + +pretty_print_binary :: (node : *AST_Node, indentation : int, builder : *String_Builder, skip_indent := false) { + if !skip_indent { + indent(builder, indentation); + } + + if node.token.kind == .TOKEN_LEFTBRACKET { + 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, ")"); + } + + +} + +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, "."); + pretty_print_node(node.children[1], 0, builder); +} + +pretty_print_unary :: (node : *AST_Node, indentation : int, builder : *String_Builder, skip_indent := false) { + if !skip_indent { + indent(builder, indentation); + } + op := node.token; + + print_to_builder(builder, op_to_string(op)); + pretty_print_node(node.children[0], 0, builder); +} + +print_return_node :: (node : *AST_Node, indentation : int, builder : *String_Builder, skip_indent := false) { + if !skip_indent { + indent(builder, indentation); + } + append(builder, "(return "); + + pretty_print_children(node, indentation, builder); + + append(builder, ")"); +} + +pretty_print_if :: (node : *AST_Node, indentation : int, builder : *String_Builder, skip_indent := false) { + if !skip_indent { + indent(builder, indentation); + } + append(builder, "(if "); + + condition := node.children[0]; + pretty_print_node(condition, 0, builder); + append(builder, "\n"); + + body := node.children[1]; + // indent(builder,indentation + 4); + // append(builder, "("); + pretty_print_node(body, indentation + 4, builder); + // append(builder, ")"); + + if node.children.count == 3 { + append(builder, "\n"); + pretty_print_node(node.children[2], indentation + 4, builder); + } + + append(builder, ")"); +} + +pretty_print_for :: (node : *AST_Node, indentation : int, builder : *String_Builder, skip_indent := false) { + if !skip_indent { + indent(builder, indentation); + } + + append(builder, "(for "); + + loop_iterator := node.token; + print_to_builder(builder, "% : ", loop_iterator.ident_value); + + pretty_print_node(node.children[0], 0, builder); + append(builder, ".."); + pretty_print_node(node.children[1], 0, builder); + append(builder, "\n"); + + pretty_print_node(node.children[2], indentation + 4, builder); + + append(builder, ")"); +} + +print_expression_statement :: (node : *AST_Node, indentation : int, builder : *String_Builder, skip_indent := false) { + if !skip_indent { + indent(builder, indentation); + } + + if node.children[0] { + pretty_print_node(node.children[0], 0, builder); + } +} + +pretty_print_node :: (node : *AST_Node, indentation : int, builder : *String_Builder, skip_indent := false) { + if node.kind == { + case .Return; { + print_return_node(node, indentation, builder, skip_indent); + } + case .If; { + pretty_print_if(node, indentation, builder, skip_indent); + } + case .If_Directive; { + if !skip_indent { + indent(builder, indentation); + } + append(builder, "(#if "); + + condition := node.children[0]; + pretty_print_node(condition, 0, builder); + append(builder, "\n"); + + body := node.children[1]; + // indent(builder,indentation + 4); + // append(builder, "("); + pretty_print_node(body, indentation + 4, builder); + // append(builder, ")"); + + if node.children.count == 3 { //@Note: Else branch + append(builder, "\n"); + pretty_print_node(node.children[2], indentation + 4, builder); + } + + append(builder, ")"); + } + case .For; { + pretty_print_for(node, indentation, builder, skip_indent); + } + case .Struct; + case .ArgList; { + pretty_print_arglist(node, indentation + 2, builder, skip_indent); + } + case .FieldList; { + pretty_print_fieldlist(node, indentation + 2, builder, skip_indent); + } + case .Field; { + pretty_print_field(node, indentation, builder, skip_indent); + } + case .Unnamed_Field; { + pretty_print_field(node, indentation, builder, skip_indent); + } + case .Block; { + pretty_print_block(node, indentation, builder, skip_indent); + } + 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); + } + case .Variable; { + pretty_print_variable(node, indentation, builder, skip_indent); + } + case .Expression_Statement; { + print_expression_statement(node, indentation, builder, skip_indent); + } + case .Integer; { + print_to_builder(builder, "%", node.integer_value, skip_indent); + } + case .Float; { + print_to_builder(builder, "%", node.float_value, skip_indent); + } + case .Call; { + pretty_print_call(node, indentation, builder, skip_indent); + } + case .Error; { + print_to_builder(builder, "(error \"%\")", node.name, skip_indent); + } + } +} + +pretty_print_variable :: (node : *AST_Node, indentation : int, builder : *String_Builder, skip_indent := false) { + if !skip_indent { + indent(builder, indentation); + } + print_to_builder(builder, "%", node.name); + + for child : node.children { + if child.kind == .Variable { + append(builder, "."); + pretty_print_variable(child, indentation, builder, skip_indent = true); + } else if child.kind == .Unary { + append(builder, "["); + pretty_print_node(child.children[0], 0, builder); + append(builder, "]"); + } + } +} + +pretty_print_declaration :: (declaration : *AST_Node, indentation : int, builder : *String_Builder, skip_indent := false) { + if !skip_indent { + indent(builder, indentation); + } + append(builder, "("); + + if declaration.foreign_declaration { + append(builder, "foreign "); + } + + if declaration.kind == .Function { + append(builder, "fun "); + } + + if declaration.vertex_entry_point { + append(builder, "vertex "); + } + + if declaration.pixel_entry_point { + append(builder, "pixel "); + } + + if declaration.kind == .If_Directive { + append(builder, "#if "); + } + + if declaration.kind == .Struct { + append(builder, "struct "); + } else if declaration.kind == .CBuffer { + append(builder, "constant_buffer "); + } else if declaration.kind == .Buffer { + append(builder, "buffer "); + } + print_to_builder(builder, "%", declaration.name); + + if declaration.kind == .CBuffer || declaration.kind == .Buffer{ + for hint : declaration.hint_tokens { + if hint.string_value.count > 0 { + print_to_builder(builder, " (@%)", hint.string_value); + } + } + // if declaration.kind != .If_Directive { + // print_to_builder(builder, "%", declaration.name); + // } + } + + if declaration.kind == .Function && declaration.token.kind == .TOKEN_IDENTIFIER{ + print_to_builder(builder, " -> %", declaration.token.ident_value); + for hint : declaration.hint_tokens { + if hint.string_value.count > 0 { + print_to_builder(builder, " (@%)", hint.string_value); + } + } + } + + if declaration.children.count > 0 { + if declaration.kind == .If_Directive { + pretty_print_node(declaration.children[0], 0, builder); + append(builder, "\n"); + pretty_print_node(declaration.children[1], indentation + 5, builder); + + if declaration.children.count > 2 { + append(builder, "\n"); + if declaration.children[2].kind == .If_Directive { + pretty_print_declaration(declaration.children[2], indentation + 5, builder); + } else { + pretty_print_node(declaration.children[2], indentation + 5, builder); + } + } + } else { + print_to_builder(builder, "\n"); + + flags := Children_Print_Flags.NewLine; + + if declaration.parent && declaration.parent.parent { + if declaration.parent.parent.kind == .If_Directive { + indent(builder, indentation - 1); //@Note: Hack the indent for now... Wow this is stupid, but it works! + } + } + pretty_print_children(declaration, indentation + 1, builder, flags = flags); + } + + } + + append(builder, ")"); + +} + +pretty_print_ast :: (root : *AST_Node, allocator : Allocator) -> string { + builder : String_Builder; + init_string_builder(*builder,, allocator); + + indentation := 0; + + append(*builder, "("); + append(*builder, "program\t\n"); + + indentation += 1; + + declarations := root.children; + + for declaration : declarations { + pretty_print_declaration(declaration, indentation, *builder); + + if it_index < declarations.count - 1 { + append(*builder, "\n\n"); + } + } + + append(*builder, ")"); + + return builder_to_string(*builder,, allocator); +} + +#scope_file +indent :: (builder : *String_Builder, indentation : int) { + for 0..indentation - 1 { + append(builder, " "); + } +} diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..e26f66c --- /dev/null +++ b/build.bat @@ -0,0 +1,3 @@ +@echo off + +jai first.jai -natvis diff --git a/check.bat b/check.bat new file mode 100644 index 0000000..1e12322 --- /dev/null +++ b/check.bat @@ -0,0 +1,3 @@ +@echo off + +jai first.jai -natvis - check diff --git a/check.jai b/check.jai new file mode 100644 index 0000000..b900e4c --- /dev/null +++ b/check.jai @@ -0,0 +1,2686 @@ +///////////////////////////////////// +//~ nbr: +// + +///////////////////////////////////// +//~ 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 +// [ ] 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. + +VERTEX_MAIN_FUNCTION_PREFIX :: "vertex"; +PIXEL_MAIN_FUNCTION_PREFIX :: "pixel"; +PROPERTIES_PREFIX :: "properties"; + +Type_Kind :: enum { + Invalid :: 128; + + Int :: 0; + Half :: 1; + Float :: 2; + Double :: 3; + Texture2D :: 4; + Sampler :: 5; + + Bool :: 6; + + Max_Builtin :: Sampler + 1; + + Unit; + Function; + Call; + + Unresolved_Variable; + Unresolved_Expression; + + Struct; + CBuffer; + Buffer; + Array; +} + +Source_Kind :: enum { + Expression; + Declaration; // struct, cbuffers, function, etc. +} + +Typenames :: string.[ + "int" , + "half" , + "float" , + "double" , + "Texture2D", + "Sampler" , + "bool" , +]; + +//@Incomplete(niels): We can vastly simplify type handling +// There's really no reason to have these type variables anymore now that we don't do union find +// We can just have the built-in types and then we can declare structs, functions, buffers etc. as one time things. +Type_Variable :: struct { + type : Type_Kind; + source_kind : Source_Kind; + builtin : bool; + + name : string; + + + + //@Note(niels) For functions + return_type_variable : Type_Variable_Handle; + + //@Note(niels) The scope this variable creates (function, struct, global) + scope : Scope_Handle; + + //@Note(niels): For struct members + struct_field_parent : *AST_Node; + + typename : string; + element_type : Type_Variable_Handle; + element_count : int; + + MAX_TYPE_VARIABLE_CHILDREN :: 32; + children : Static_Array(Type_Variable_Handle, MAX_TYPE_VARIABLE_CHILDREN); + + //@Incomplete: Should we remove this and do it in the output generation instead? + // Seems kind of superfluous considering we auto-generate it. + // Otherwise if we want to specify it, it should be specified as a hint @binding(index) + // In the case of using hints, we can just have it on the AST node. + //@Note(niels): For constant buffers + resource_index : u32; + + source_node : *AST_Node; +} + +Type_Variable_Handle :: #type, distinct u32; + +Scope_Stack :: struct { + allocator : Allocator; + stack : [..]Scope; +} + +Defined_Symbol :: struct { + name : string; + + type_variable : Type_Variable_Handle; + source_node : *AST_Node; + + functions : [..]Defined_Symbol; + + builtin : bool; +} + +Scope_Kind :: enum { + Global; + Function; + Struct; + Block; +} + +Scope :: struct { + table : Table(string, Defined_Symbol); + + //@Note(nb): Only for pretty printing + longest_key_length : int; + + name : string; + children : [..]Scope_Handle; + parent : Scope_Handle; + + builtin : bool; + + kind : Scope_Kind; + + allocator : Allocator; +} + +Scope_Handle :: #type, distinct u32; + +Checker_State :: enum { + Type_Checking; + Adding_Builtins; +} + +Checker :: struct { + program_root : *AST_Node; + path : string; + + state : Checker_State; + + current_scope : Scope_Handle; + + ctx : *Compiler_Context; + + checking_lvalue : bool; + + current_buffer_index : u32 = 0; + current_sampler_index : u32 = 0; + current_texture_index : u32 = 0; + + had_error : bool; +} + +record_error :: (checker : *Checker, message : string, source_location : Source_Range, report_source_location : bool = true) { + locations : [1]Source_Range; + locations[0] = source_location; + record_error(checker, message, locations, report_source_location); +} + +invalid_symbol_name :: (checker : *Checker, node : *AST_Node, type : string) { + record_error(checker, tprint("Invalid % name '%'", type, node.name), node.source_location); +} + +symbol_redeclaration :: (checker : *Checker, redeclared_node : *AST_Node, symbol : *Defined_Symbol) { + /* + + Redeclaration of '%': + + foo : int; + ^^^ + + Here is the first redeclaration of 'foo': + + foo : int; + ^^^ + +*/ + + builder : String_Builder; + init_string_builder(*builder,, temp); + + print_to_builder(*builder, "Redeclaration of '%'\n", symbol.name); + + cyan(*builder); + indent(*builder, 1); + print_to_builder(*builder, "%\n", print_from_source_location(checker.ctx, redeclared_node.source_location)); + + indent(*builder, 1); + print_token_pointer(*builder, redeclared_node.source_location.main_token); + append(*builder, "\n\n"); + + white(*builder); + path := checker.path; + if path.count > 0 { + print_to_builder(*builder, "%:", checker.path); + } else { + append(*builder, "internal:"); + } + + if symbol.source_node { + location := symbol.source_node.source_location; + print_to_builder(*builder, "%,%: info: ", location.begin.line, location.begin.column); + print_to_builder(*builder, "Here is the first declaration of '%'\n", symbol.name); + + cyan(*builder); + indent(*builder, 1); + print_to_builder(*builder, "%\n", print_from_source_location(checker.ctx, location)); + indent(*builder, 1); + print_token_pointer(*builder, symbol.source_node.source_location.main_token); + } + + + message := builder_to_string(*builder); + + record_error(checker, message, redeclared_node.source_location, false); +} + +symbol_undeclared :: (checker : *Checker, node : *AST_Node) { + /* +Use of undeclard symbol '%'. + b = f; + ^ +*/ + + builder : String_Builder; + init_string_builder(*builder,, temp); + + print_to_builder(*builder, "Use of undeclared symbol '%'\n", node.name); + + cyan(*builder); + indent(*builder, 1); + + print_to_builder(*builder, "%\n", print_from_source_location(checker.ctx, node.source_location)); + indent(*builder, 1); + print_token_pointer(*builder, node.source_location.main_token); + + message := builder_to_string(*builder); + + record_error(checker, message, node.source_location, false); +} + +no_matching_overload_found :: (checker : *Checker, call : *AST_Node, overloads : *Defined_Symbol, arg_node : *AST_Node = null) { + builder : String_Builder; + init_string_builder(*builder,, temp); + + print_to_builder(*builder, "Procedure call did not match any of the possible overloads for '%'\n", overloads.name); + + cyan(*builder); + indent(*builder, 1); + append(*builder, "found:\n"); + indent(*builder, 2); + print_to_builder(*builder, "%\n", print_from_source_location(checker.ctx, call.source_location)); + indent(*builder, 2); + print_token_pointer(*builder, call.source_location.main_token); + newline(*builder); + + if arg_node { + newline(*builder); + + white(*builder); + + location := arg_node.source_location; + indent(*builder, 1); + + field_list := arg_node.parent; + index : s64 = -1; + for child : field_list.children { + if child == arg_node { + index = it_index + 1; + break; + } + } + print_to_builder(*builder, "While matching argument % in function call.\n", index); + + cyan(*builder); + indent(*builder, 2); + print_to_builder(*builder, "%\n", print_from_source_location(checker.ctx, location)); + indent(*builder, 2); + print_token_pointer(*builder, arg_node.source_location.main_token); + newline(*builder); + } + + white(*builder); + indent(*builder, 1); + append(*builder, "Possible overloads:\n"); + + for func : overloads.functions { + func_var := from_handle(checker, func.type_variable); + + cyan(*builder); + // foo :: (f : float) {} (file_path:line_num) + func_location := func_var.source_node.source_location; + indent(*builder, 2); + + if func.builtin { + print_to_builder(*builder, "%\n", print_from_source_location(checker.ctx, func_location)); + } else { + print_to_builder(*builder, "% (%:%)\n", print_from_source_location(checker.ctx, func_location), checker.path, + func_location.main_token.line); + } + // @Incomplete(niels): We need a way to properly save the path of the declaration + + + if !arg_node { + white(*builder); + + arg_list := call.children[0]; + indent(*builder, 2); + + func_var := from_handle(checker, func.type_variable); + + if arg_list.children.count != func_var.children.count { + print_to_builder(*builder, "Not enough arguments: Wanted %, got %.\n\n", func_var.children.count, arg_list.children.count); + } + } + } + + locations : [1]Source_Range; + locations[0] = call.source_location; + message := builder_to_string(*builder); + record_error(checker, message, locations, false); +} + + +not_all_control_paths_return_value :: (checker : *Checker, node : *AST_Node) { + builder : String_Builder; + init_string_builder(*builder,, temp); + + print_to_builder(*builder, "Not all control paths return a value.\n\n"); + + cyan(*builder); + + indent(*builder, 1); + + print_to_builder(*builder, "%\n", print_from_source_location(checker.ctx, node.source_location)); + indent(*builder, 1); + print_token_pointer(*builder, node.token); + + white(*builder); + + message := builder_to_string(*builder); + + record_error(checker, message, node.source_location, false); +} + +mismatched_arguments :: (checker : *Checker, call : *AST_Node, symbol : *Defined_Symbol, args_call : int, args_def : int) { + builder : String_Builder; + init_string_builder(*builder,, temp); + + if args_call > args_def { + print_to_builder(*builder, "Too many arguments: Wanted %, got %\n", args_def, args_call); + } else { + print_to_builder(*builder, "Too few arguments: Wanted %, got %\n", args_def, args_call); + } + + /* +Too many arguments: Expected %, got %. + + found + foo(2, 3) + ^^^ + + expected + foo :: (x : int, y : int, z : int) + +*/ + cyan(*builder); + indent(*builder, 1); + append(*builder, "found:\n"); + indent(*builder, 2); + print_to_builder(*builder, "%\n", print_from_source_location(checker.ctx, call.source_location)); + indent(*builder, 2); + print_token_pointer(*builder, call.source_location.main_token); + append(*builder, "\n\n"); + indent(*builder, 1); + append(*builder, "expected:\n"); + + indent(*builder, 2); + print_to_builder(*builder, "%\n", print_from_source_location(checker.ctx, symbol.source_node.source_location)); + + locations : [1]Source_Range; + locations[0] = call.source_location; + + message := builder_to_string(*builder); + record_error(checker, message, locations, false); +} + +function_undeclared :: (checker : *Checker, node : *AST_Node) { + /* +Error: Undeclared identifier 'name'. + + name(); + ^^^^ + +*/ + builder : String_Builder; + init_string_builder(*builder,, temp); + + print_to_builder(*builder, "Attempt to call undeclared function '%'.\n\n", node.name); + cyan(*builder); + indent(*builder, 1); + print_to_builder(*builder, "%\n", print_from_source_location(checker.ctx, node.source_location)); + indent(*builder, 1); + print_token_pointer(*builder, node.source_location.main_token); + newline(*builder); + newline(*builder); + message := builder_to_string(*builder); + record_error(checker, message, node.source_location, false); +} + +cannot_assign_to_lvalue :: (checker : *Checker, node : *AST_Node) { + /* + Cannot assign to an lvalue. + + (a + b).x = 2.0; +*/ + + builder : String_Builder; + init_string_builder(*builder,, temp); + + append(*builder, "Cannot assign to an lvalue.\n"); + + cyan(*builder); + indent(*builder, 1); + + location := node.source_location; + + begin : Token = node.token; + begin.index -= begin.column; + begin.length += begin.column; + begin.source -= begin.column; + begin.column = 0; + + location.begin = begin; + + print_to_builder(*builder, "%\n", print_from_source_location(checker.ctx, location)); + indent(*builder, 1); + print_token_pointer(*builder, location.begin); + newline(*builder); + newline(*builder); + + message := builder_to_string(*builder); + record_error(checker, message, node.source_location, false); +} + +field_not_defined_on_struct :: (checker : *Checker, node : *AST_Node, struct_symbol : *Defined_Symbol) { + /* +Field '%' is not defined in struct '%'. + b.t = f; + ^ + + declaration: + Bar :: struct { + f : Foo; + } +*/ + + builder : String_Builder; + init_string_builder(*builder,, temp); + + print_to_builder(*builder, "Field '%' is not defined in struct '%'.\n", node.name, struct_symbol.name); + + cyan(*builder); + indent(*builder, 1); + print_to_builder(*builder, "%\n", print_from_source_location(checker.ctx, node.source_location)); + indent(*builder, 1); + print_token_pointer(*builder, node.source_location.main_token); + newline(*builder); + newline(*builder); + + indent(*builder, 1); + append(*builder, "declaration:\n"); + print_from_source_location(checker.ctx, *builder, struct_symbol.source_node.source_location, 2); + + message := builder_to_string(*builder); + record_error(checker, message, node.source_location, false); +} + +field_access_on_primitive_type :: (checker : *Checker, node : *AST_Node, handle : Type_Variable_Handle) { + /* +Attempting to access a field on a primitive type '%'. + x.d = 5; + ^^ + + declaration: + x : int = 5; +*/ + + builder : String_Builder; + init_string_builder(*builder,, temp); + + variable := from_handle(checker, handle); + print_to_builder(*builder, "Attempting to access a field on a primitive type '%'.\n", proper_type_to_string(checker.ctx, checker.ctx.type_variables, variable)); + + indent(*builder, 1); + cyan(*builder); + print_to_builder(*builder, "%\n", print_from_source_location(checker.ctx, node.source_location)); + indent(*builder, 1); + + // for 0..variable.source_node.name.count - 1 { + // append(*builder, " "); + // } + print_token_pointer(*builder, node.source_location.main_token); + + append(*builder, "\n"); + + indent(*builder, 1); + append(*builder, "declaration:\n"); + + indent(*builder, 2); + print_to_builder(*builder, "%", print_from_source_location(checker.ctx, variable.source_node.source_location)); + + message := builder_to_string(*builder,, temp); + record_error(checker, message, node.source_location, false); + + white(*builder); +} + +if_condition_has_to_be_boolean_type :: (checker : *Checker, usage_site : *AST_Node, handle : Type_Variable_Handle) { + /* + Type of expression in if condition has to be bool. + if 100.0 + ^^^^^^^ + + 100.0 has type float + */ + + builder : String_Builder; + init_string_builder(*builder,, temp); + + variable := from_handle(checker, handle); + append(*builder, "Type of expression in if condition has to be bool.\n"); + + indent(*builder, 1); + cyan(*builder); + + location := usage_site.source_location; + + print_to_builder(*builder, "%\n", print_from_source_location(checker.ctx, location)); + indent(*builder, 1); + + print_token_pointer(*builder, usage_site.children[0].source_location.begin); + append(*builder, "\n"); + + indent(*builder, 1); + + var := from_handle(checker, handle); + + usage_child := usage_site.children[0]; + usage_loc := usage_child.source_location; + + print_to_builder(*builder, "% has type %\n", print_from_source_location(checker.ctx, *usage_loc), proper_type_to_string(checker.ctx, checker.ctx.type_variables, var)); + + message := builder_to_string(*builder,, temp); + record_error(checker, message, usage_site.source_location, false); + + white(*builder); +} + +type_mismatch :: (checker : *Checker, usage_site : *AST_Node, expect_node : *AST_Node, expect : Type_Variable_Handle, got : Type_Variable_Handle) { + expect_var := from_handle(checker, expect); + got_var := from_handle(checker, got); + + builder : String_Builder; + init_string_builder(*builder,, temp); + + if got_var.builtin { + print_to_builder(*builder, "% :: (", got_var.name); + + for i: 0..got_var.children.count - 1{ + child_handle := got_var.children[i]; + child := from_handle(checker, child_handle); + + print_to_builder(*builder, "% : %", child.name, type_to_string(checker.ctx.type_variables, child)); + } + } + + print_to_builder(*builder, "Type mismatch. Expected % got %\n", type_to_string(checker.ctx.type_variables, expect_var), type_to_string(checker.ctx.type_variables, got_var)); + + cyan(*builder); + location := usage_site.source_location; + indent(*builder, 1); + append(*builder, "found:\n"); + indent(*builder, 2); + print_to_builder(*builder, "%\n", print_from_source_location(checker.ctx, location)); + indent(*builder, 2); + + print_token_pointer(*builder, location.main_token); + append(*builder, "\n"); + + indent(*builder, 1); + print_to_builder(*builder, "expected:\n"); + indent(*builder, 2); + proper_type_to_string(checker.ctx, *builder, checker.ctx.type_variables, expect_var); + append(*builder, "\n"); + + // indent(*builder, 2); + + { + // expect_location := expect_var.source_node.source_location; + // // token.length = expect_location.end.index + token.length - token.index + expect_location.end.length - 1; + + // print_token_pointer(*builder, expect_location.main_token); + append(*builder, "\n"); + } + + indent(*builder, 1); + print_to_builder(*builder, "got:\n"); + + indent(*builder, 2); + + print_to_builder(*builder, "%\n", print_from_source_location(checker.ctx, got_var.source_node.source_location)); + + message := builder_to_string(*builder); + + record_error(checker, message, Source_Range.[usage_site.source_location], false); +} + +record_error :: (checker : *Checker, error_string : string, locations : []Source_Range, report_source_location : bool = true) { + error : Compiler_Message; + error.message_kind = .Error; + error.report_source_location = report_source_location; + + for location : locations { + array_add(*error.source_locations, location); + } + + error.path = checker.path; + error.message = error_string; + + checker.had_error = true; + array_add(*checker.ctx.messages, error); +} + +is_proper :: (var : Type_Variable) -> bool { + if var.type == { + case .Function; #through; + case .Int; #through; + case .Struct; #through; + case .Float; { + return true; + } + } + return false; +} + +use_scope :: (checker : *Checker, handle : Scope_Handle) -> Scope_Handle { + assert(handle > 0, "Invalid scope handle: %", handle); + previous_scope := checker.current_scope; + checker.current_scope = handle; + + return previous_scope; +} + +push_scope :: (checker : *Checker, name := "", kind : Scope_Kind = .Global) -> *Scope, Scope_Handle { + new_scope : Scope; + array_add(*checker.ctx.scope_stack.stack, new_scope); + + count := checker.ctx.scope_stack.stack.count; + scope := *checker.ctx.scope_stack.stack[count - 1]; + scope.allocator = make_arena(Kilobytes(512)); + scope.table.allocator = scope.allocator; + scope.parent = checker.current_scope; + scope.name = name; + scope.kind = kind; + if checker.state == .Adding_Builtins { + scope.builtin = true; + } + + scope.children.allocator = checker.ctx.scope_stack.stack.allocator; + + if checker.current_scope { + scope := get_current_scope(checker); + array_add(*scope.children, xx count); + } + + checker.current_scope = xx count; + return scope, xx count; +} + +pop_scope :: (checker : *Checker) -> Scope_Handle { + scope := get_scope(checker, checker.current_scope); + if !scope.parent { + return 0; + } + + checker.current_scope = scope.parent; + + return checker.current_scope; +} + +peek_scope :: (checker : *Checker) -> *Scope, Scope_Handle { + if checker.ctx.scope_stack.stack.count == 0 { + return null, 0; + } + + count := checker.ctx.scope_stack.stack.count; + scope := *checker.ctx.scope_stack.stack[count - 1]; + return scope, xx count; +} + +get_current_scope :: (checker : *Checker) -> *Scope { + return get_scope(checker, checker.current_scope); +} + +get_scope :: (scope_stack : Scope_Stack, handle : Scope_Handle) -> *Scope { + if handle == 0 { + return null; + } + + return *scope_stack.stack[handle - 1]; +} + +get_scope :: (checker : *Checker, handle : Scope_Handle) -> *Scope { + return get_scope(*checker.ctx.scope_stack, handle); +} + +add_symbol_to_scope :: (state : Checker_State, scope_stack : *Scope_Stack, scope_handle : Scope_Handle, name : string, symbol : Defined_Symbol) -> *Defined_Symbol { + scope := get_scope(scope_stack.*, scope_handle); + scope.longest_key_length = max(scope.longest_key_length, name.count); + + symbol_to_add : Defined_Symbol; + symbol_to_add.name = symbol.name; + symbol_to_add.type_variable = symbol.type_variable; + symbol_to_add.source_node = symbol.source_node; + symbol_to_add.functions = symbol.functions; + + if state == .Adding_Builtins { + symbol_to_add.builtin = true; + } + + return table_set(*scope.table, name, symbol_to_add); +} + +new_type_variable :: (checker : *Checker) -> *Type_Variable, Type_Variable_Handle { + variable : Type_Variable; + handle := cast(Type_Variable_Handle)checker.ctx.type_variables.count + 1; + array_add(*checker.ctx.type_variables, variable); + + return from_handle(checker, handle), handle; +} + +new_builtin_type_variable :: (checker : *Checker, type : Type_Kind, source : Source_Kind, name : string, typename : string = "") -> *Type_Variable, Type_Variable_Handle { + tv, handle := new_type_variable(checker); + + tv.name = name; + tv.type = type; + tv.source_kind = source; + tv.builtin = true; + tv.typename = typename; + + return tv, handle; +} + +Arg :: struct { + name : string; + typename : string; +} + +new_builtin_struct :: (checker : *Checker, name : string, members : []Arg) -> *Type_Variable, Type_Variable_Handle { + tv, handle := new_builtin_type_variable(checker, .Struct, .Declaration, name, name); + + builtin_node := new_builtin_struct_node(checker.ctx, name, members); + + symbol : Defined_Symbol; + symbol.name = name; + symbol.source_node = builtin_node; + symbol.builtin = true; + symbol.type_variable = handle; + add_symbol_to_scope(checker.state, *checker.ctx.scope_stack, checker.current_scope, name, symbol); + + tv.source_node = builtin_node; + + field_list := get_field_list(builtin_node); + + scope, scope_handle := push_scope(checker, name, .Struct); + tv.scope = scope_handle; + + for member : members { + typename : string; + kind := lookup_type(checker, checker.current_scope, member.typename, *typename); + + member_var, member_handle := new_builtin_type_variable(checker, kind, .Expression, member.name); + member_var.scope = tv.scope; + + member_symbol : Defined_Symbol; + member_symbol.name = member.name; + member_symbol.type_variable = member_handle; + add_symbol_to_scope(checker.state, *checker.ctx.scope_stack, checker.current_scope, member.name, member_symbol); + + field_list.children[it_index].type_variable = member_handle; + member_var.source_node = field_list.children[it_index]; + + add_child(checker, handle, member_handle); + } + + pop_scope(checker); + + return from_handle(checker, handle), handle; +} + +new_builtin_function :: (checker : *Checker, name : string, args : []Arg, return_arg : Arg) -> *Type_Variable, Type_Variable_Handle { + tv, handle := new_builtin_type_variable(checker, .Function, .Declaration, name); + + builtin_node := new_builtin_function_node(checker.ctx, name, args, return_arg); + + function : Defined_Symbol; + function.name = name; + function.source_node = builtin_node; + function.type_variable = handle; + function.builtin = true; + + find_result := find_symbol(checker, name, checker.current_scope); + if !find_result { + symbol : Defined_Symbol; + symbol.name = name; + symbol.source_node = builtin_node; + symbol.builtin = true; + symbol.type_variable = 0; + symbol.functions.allocator = get_current_scope(checker).allocator; + array_add(*symbol.functions, function); + add_symbol_to_scope(checker.state, *checker.ctx.scope_stack, checker.current_scope, name, symbol); + } else { + array_add(*find_result.functions, function); + } + + tv.source_node = builtin_node; + + field_list := get_field_list(builtin_node); + + for arg : args { + typename : string; + kind := lookup_type(checker, checker.current_scope, arg.typename, *typename); + + arg_var, arg_handle := new_builtin_type_variable(checker, kind, .Expression, arg.name); + arg_var.scope = tv.scope; + arg_var.type = kind; + arg_var.typename = typename; + + field_list.children[it_index].type_variable = arg_handle; + arg_var.source_node = field_list.children[it_index]; + + add_child(checker, handle, arg_handle); + } + + if return_arg.typename.count > 0 { + return_var, return_handle := new_type_variable(checker); + symb : Defined_Symbol; + return_var.type = lookup_type(checker, checker.current_scope, return_arg.typename, *return_var.typename, *symb); + if symb.type_variable > 0 { + symb_var := from_handle(checker, symb.type_variable); + if symb_var.type == .Array || symb_var.type == .Buffer { + return_var.element_type = symb_var.element_type; + // return_var.element_typename = symb_var.element_typename; + return_var.element_count = symb_var.element_count; + } + } + from_handle(checker, handle).return_type_variable = return_handle; + } + + return from_handle(checker, handle), handle; +} + +add_child :: (variable : *Type_Variable, child : Type_Variable_Handle) { + assert(variable.children.count < Type_Variable.MAX_TYPE_VARIABLE_CHILDREN); + array_add(*variable.children, child); + // variable.children[variable.children.count] = child; + // variable.children.count += 1; +} + +add_child :: (checker : *Checker, handle : Type_Variable_Handle, child : Type_Variable_Handle) { + variable := from_handle(checker, handle); + assert(variable.children.count < Type_Variable.MAX_TYPE_VARIABLE_CHILDREN); + array_add(*variable.children, child); +} + +init_semantic_checker :: (checker : *Checker, root : *AST_Node, path : string) { + checker.program_root = root; + checker.path = path; + + array_reserve(*checker.ctx.type_variables, 2048); + + checker.ctx.scope_stack.stack.allocator = checker.ctx.scope_stack.allocator; + array_reserve(*checker.ctx.scope_stack.stack, 256); + + global_scope, global_handle := push_scope(checker, kind = .Global); + array_reserve(*global_scope.children, 2048); +} + +find_symbol :: (scope_stack : Scope_Stack, name : string, current_scope : Scope_Handle, containing_scope : *Scope_Handle = null) -> *Defined_Symbol { + handle := current_scope; + current := get_scope(scope_stack, current_scope); + + while current { + table := current.table; + info := table_find_pointer(*table, name); + if info { + if containing_scope { + containing_scope.* = handle; + } + return info; + } + handle = current.parent; + current = get_scope(scope_stack, current.parent); + } + return null; +} + +find_symbol :: (checker : *Checker, name : string, current_scope : Scope_Handle, containing_scope : *Scope_Handle = null) -> *Defined_Symbol { + return find_symbol(checker.ctx.scope_stack, name, current_scope, containing_scope); +} + +find_symbol :: (name : string, checker : *Checker, containing_scope : *Scope_Handle = null) -> *Defined_Symbol { + return find_symbol(checker, name, checker.current_scope, containing_scope); +} + +from_handle :: (variables : []Type_Variable, handle : Type_Variable_Handle) -> *Type_Variable { + // assert(handle > 0 && xx handle <= variables.count, tprint("Invalid handle: %. Range is: 1-%", handle, variables.count - 1)); + return *variables[handle - 1]; +} + +from_handle :: (checker : *Checker, handle : Type_Variable_Handle) -> *Type_Variable { + return from_handle(checker.ctx.type_variables, handle); +} + +proper_type_to_string :: (ctx : *Compiler_Context, builder : *String_Builder, variables : []Type_Variable, var : Type_Variable) { + if var.type == { + case .Int; #through; + case .Half; #through; + case .Float; #through; + case .Double; { + print_to_builder(builder, "%", Typenames[var.type]); + } + case .Struct; { + print_to_builder(builder, "%", var.typename); + } + case .Function; { + + append(builder, "("); + + for child : var.source_node.children { + if child.kind == .FieldList { + for field : child.children { + var := field.type_variable; + print_type_variable(ctx, builder, variables, var); + + if it_index != child.children.count - 1 { + append(builder, ", "); + } + } + } + } + + append(builder, ")"); + if var.return_type_variable > 0 { + append(builder, " -> ", ); + return_var := from_handle(variables, var.return_type_variable); + if is_proper(return_var) { + proper_type_to_string(ctx, builder, variables, return_var); + } else { + append(builder, "[["); + print_type_variable(ctx, builder, variables, var.return_type_variable); + append(builder, "]]", ); + } + } else { + append(builder, " -> unit"); + } + } + case; { + append(builder, "______not proper type______"); + } + } +} + +proper_type_to_string :: (ctx : *Compiler_Context, variables : []Type_Variable, var : Type_Variable, allocator := context.allocator) -> string { + if var.type == { + case .Int; #through; + case .Half; #through; + case .Float; #through; + case .Double; { + return Typenames[var.type]; + } + case .Function; { + builder : String_Builder; + init_string_builder(*builder,, allocator); + + proper_type_to_string(ctx, *builder, variables, var); + return builder_to_string(*builder,, allocator); + } + case .Struct; { + return var.typename; + } + } + + return "______not proper type______"; +} + +lookup_type :: (scope_stack : Scope_Stack, variables : []Type_Variable, scope : Scope_Handle, type_string : string, typename : *string = null, out_symbol : *Defined_Symbol = null) -> Type_Kind { + if type_string == { + case Typenames[Type_Kind.Int]; return .Int; + case Typenames[Type_Kind.Half]; return .Half; + case Typenames[Type_Kind.Float]; return .Float; + case Typenames[Type_Kind.Double]; return .Double; + case Typenames[Type_Kind.Sampler]; return .Sampler; + case Typenames[Type_Kind.Texture2D]; return .Texture2D; + } + + symbol := find_symbol(scope_stack, type_string, scope); + if symbol { + if out_symbol { + out_symbol.* = symbol.*; + } + symbol_var := from_handle(variables, symbol.type_variable); + if symbol_var.type == .Struct { + if typename { + typename.* = symbol_var.typename; + } + return symbol_var.type; + } + } else { + return .Unresolved_Variable; + } + + return .Invalid; +} + +lookup_type :: (checker : *Checker, scope : Scope_Handle, type_string : string, typename : *string = null, out_symbol : *Defined_Symbol = null) -> Type_Kind { + return lookup_type(checker.ctx.scope_stack, checker.ctx.type_variables, scope, type_string, typename, out_symbol); +} + +lookup_type :: (checker : *Checker, scope : Scope_Handle, node : *AST_Node, typename : *string = null) -> Type_Kind { + type_string := node.token.ident_value; + return lookup_type(checker, scope, type_string, typename); +} + +check_block :: (checker : *Checker, node : *AST_Node) { + push_scope(checker, kind = Scope_Kind.Block); + for child : node.children { + check_node(checker, child); + } + pop_scope(checker); +} + +declare_struct :: (checker : *Checker, node : *AST_Node, name : string) -> Type_Variable_Handle { + variable, handle := new_type_variable(checker); + variable.type = .Struct; + variable.source_kind = .Declaration; + variable.name = name; + variable.source_node = node; + variable.typename = name; + node.type_variable = handle; + + find_result := find_symbol(checker, name, checker.current_scope); + + if !find_result { + symbol : Defined_Symbol; + symbol.name = name; + symbol.source_node = node; + symbol.type_variable = handle; + add_symbol_to_scope(checker.state, *checker.ctx.scope_stack, checker.current_scope, name, symbol); + } else { + symbol_redeclaration(checker, node, find_result); + return 0; + } + + scope, scope_handle := push_scope(checker, name, .Struct); + variable.scope = scope_handle; + + for child : node.children { + if child.kind == .FieldList { + for field : child.children { + type_var := check_field(checker, field); + + if type_var > 0 { + from_handle(checker, type_var).scope = scope_handle; + add_child(checker, handle, type_var); + } + } + } + } + + pop_scope(checker); + + return handle; +} + +declare_struct :: (checker : *Checker, node : *AST_Node) -> Type_Variable_Handle { + return declare_struct(checker, node, node.name); +} + +declare_cbuffer :: (checker : *Checker, node : *AST_Node) -> Type_Variable_Handle { + type_var := declare_struct(checker, node); + var := from_handle(checker, type_var); + var.type = .CBuffer; + var.resource_index = checker.current_buffer_index; + checker.current_buffer_index += 1; + array_add(*checker.ctx.typed_buffers, type_var); + return type_var; +} + +declare_buffer :: (checker : *Checker, node : *AST_Node) -> Type_Variable_Handle { + variable, handle := new_type_variable(checker); + variable.type = .Buffer; + variable.source_kind = .Declaration; + variable.name = node.name; + variable.source_node = node; + + 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); + variable.resource_index = checker.current_texture_index; + element := from_handle(checker, variable.element_type); + scope := get_scope(checker, element.scope); + scope.builtin = true; + variable.scope = element.scope; + + checker.current_texture_index += 1; + + node.type_variable = handle; + + array_add(*checker.ctx.typed_buffers, handle); + return handle; +} + +get_actual_function_name :: (node : *AST_Node) -> string { + name_to_check := node.name; + if node.vertex_entry_point { + name_to_check = sprint("%__%", VERTEX_MAIN_FUNCTION_PREFIX, node.name); + } else if node.pixel_entry_point { + name_to_check = sprint("%__%", PIXEL_MAIN_FUNCTION_PREFIX, node.name); + } + return name_to_check; +} + +declare_foreign_function :: (checker : *Checker, node : *AST_Node) -> Type_Variable_Handle { + return declare_function(checker, node, true); +} + +declare_function :: (checker : *Checker, node : *AST_Node, builtin : bool = false) -> Type_Variable_Handle { + if !node.foreign_declaration && !can_declare(checker, node.name) { + invalid_symbol_name(checker, node, "function"); + return 0; + } + + variable, handle := new_type_variable(checker); + variable.type = .Function; + variable.source_kind = .Declaration; + variable.name = node.name; + variable.source_node = node; + variable.builtin = builtin; + node.type_variable = handle; + + name_to_check := get_actual_function_name(node); + + if node.vertex_entry_point { + checker.ctx.vertex_entry_point.node = node; + } + + if node.pixel_entry_point { + checker.ctx.pixel_entry_point.node = node; + } + find_result := find_symbol(checker, name_to_check, checker.current_scope); + + if !find_result { + function : Defined_Symbol; + function.name = name_to_check; + function.source_node = node; + function.type_variable = handle; + + symbol : Defined_Symbol; + symbol.name = name_to_check; + symbol.source_node = node; + symbol.type_variable = 0; + symbol.functions.allocator = get_current_scope(checker).allocator; + 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); + } else { + //@Note(niels): This is some ugly code, but it's probably fine for now. + field_list := node.children[0]; + + for function : find_result.functions { + func_var := from_handle(checker, function.type_variable); + if func_var.source_node.children[0].children.count != field_list.children.count { + continue; + } + + all_same : bool = true; + for i : 0..func_var.children.count - 1 { + arg := func_var.children[i]; + node_child := field_list.children[i]; + + typename : string; + arg_type := lookup_type(checker, checker.current_scope, node_child, *typename); + other_arg := from_handle(checker, arg); + + if arg_type != other_arg.type { + all_same = false; + break; + } else { + if arg_type == .Struct && other_arg.type == .Struct { + if typename != other_arg.typename { + all_same = false; + break; + } + } + } + } + + if all_same { + symbol_redeclaration(checker, node, find_result); + return 0; + } else { + function : Defined_Symbol; + function.name = name_to_check; + function.source_node = node; + function.type_variable = handle; + + array_add(*find_result.functions, function); + break; + } + } + + function : Defined_Symbol; + function.name = name_to_check; + function.source_node = node; + function.type_variable = handle; + + array_add(*find_result.functions, function); + } + + if !builtin { + scope, scope_handle := push_scope(checker, name_to_check, .Function); + variable.scope = scope_handle; + } + + 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); + if type_var > 0 { + if builtin { + var := from_handle(checker, type_var); + var.builtin = true; + } + add_child(checker, handle, type_var); + } + } + } + } + + if builtin && node.token.ident_value.count > 0 { + return_var, return_handle := new_type_variable(checker); + return_var.type = lookup_type(checker, checker.current_scope, node, *return_var.typename); + from_handle(checker, handle).return_type_variable= return_handle; + } + + if !builtin { + pop_scope(checker); + } + + return handle; +} + +check_function :: (checker : *Checker, node : *AST_Node) { + name_to_check := get_actual_function_name(node); + find_result := find_symbol(checker, name_to_check, checker.current_scope); + + if !find_result { + assert(false, "Compiler error. Functions should all be declared at this point in time."); + } + + handle := find_result.type_variable; + if node.foreign_declaration { + return; + } + + for function : find_result.functions { + variable := from_handle(checker, function.type_variable); + + assert(variable.scope > 0, "Declared function is missing scope."); + + previous_scope := use_scope(checker, variable.scope); + + for child : node.children { + if child.kind == .Block { + for statement : child.children { + if statement.kind == .Return { + result_var := check_node(checker, statement); + if result_var > 0 { + variable.return_type_variable = result_var; + } + } else { + result_var := check_node(checker, statement); + if result_var > 0 { + stm := from_handle(checker, result_var); + add_child(variable, result_var); + } + + if statement.kind == .If_Directive { + break; + } + } + } + } + } + + if node.token.ident_value.count > 0 && !variable.return_type_variable{ + not_all_control_paths_return_value(checker, node); + } + + use_scope(checker, previous_scope); + } +} + +check_variable :: (checker : *Checker, node : *AST_Node) -> Type_Variable_Handle { + find_result := find_symbol(checker, node.name, checker.current_scope); + + if find_result { + node.type_variable = find_result.type_variable; + variable := from_handle(checker, find_result.type_variable); + + return find_result.type_variable; + } + + symbol_undeclared(checker, node); + return 0; +} + +can_declare :: (checker : *Checker, name : string) -> bool { + max_value := Type_Kind.Max_Builtin; + + for i : 0..max_value - 1 { + kind := cast(Type_Kind)i; + if name == Typenames[kind] { + return false; + } + } + return true; +} + +//@Incomplete(niels): Handle meta stuff here +check_field :: (checker : *Checker, node : *AST_Node) -> Type_Variable_Handle { + variable, handle := new_type_variable(checker); + variable.name = node.name; + typename : string; + + if node.array_field { + variable.type = .Array; + element_type, element_handle := new_type_variable(checker); + element_type.type = lookup_type(checker, checker.current_scope, node, *element_type.typename); + element_type.scope = checker.current_scope; + + variable.element_type = element_handle; + variable.element_count = node.children[0].integer_value; + } else { + variable.type = lookup_type(checker, checker.current_scope, node, *typename); + } + + if variable.type == .Array { + size_node := node.children[0]; + size_var := check_node(checker, size_node); + if from_handle(checker, size_var).type != .Int { + //@Incomplete(niels): Type mismatch here. With integral type required message. + } + } + + variable.typename = typename; + variable.source_node = node; + variable.scope = checker.current_scope; + node.type_variable = handle; + + if node.kind != .Unnamed_Field { + if !can_declare(checker, node.name) { + invalid_symbol_name(checker, node, "variable"); + return 0; + } + + 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); + variable.source_kind = .Declaration; + } else { + symbol_redeclaration(checker, node, find_result); + return 0; + } + } + + if variable.source_kind == .Declaration && variable.type == .Sampler { + variable.resource_index = checker.current_sampler_index; + checker.current_sampler_index += 1; + } + + if variable.source_kind == .Declaration && variable.type == .Texture2D { + variable.resource_index = checker.current_texture_index; + checker.current_texture_index += 1; + } + + if variable.type != .Array && node.children.count > 0 || variable.type == .Array && node.children.count > 1 { + rhs : Type_Variable_Handle; + assert(node.children.count == 1); + start_index := 0; + if variable.type == .Array { + start_index += 1; + } + + for i : start_index..node.children.count - 1 { + child := node.children[i]; + rhs = check_node(checker, child); + } + + if handle == 0 || rhs == 0 { + return handle; + } + + l := from_handle(checker, handle); + r := from_handle(checker, rhs); + assert(l.type != .Unresolved_Expression && r.type != .Unresolved_Expression); + + if l.type == .Unresolved_Variable { + l.type = r.type; + l.typename = r.typename; + } else { + if !types_compatible(checker, handle, rhs) { + type_mismatch(checker, l.source_node, r.source_node, rhs, handle); + return 0; + } + } + } + + return handle; +} + +check_call :: (checker : *Checker, node : *AST_Node, type_var : Type_Variable_Handle) -> error : bool { + find_result := find_symbol(checker, node.name, checker.current_scope); + + if !find_result { + function_undeclared(checker, node); + return true; + } + + overload_found := false; + arg_node : *AST_Node = null; + + Result :: struct { + var : Type_Variable_Handle; + node : *AST_Node; + } + arg_vars : [..]Result; + + // @incomplete(niels): Should be some kind of scratch allocator instead probably? + arg_vars.allocator = temp; + arg_count := 0; + + for child : node.children { + if child.kind == { + case .ArgList; { + arg_count = child.children.count; + for arg_child : child.children { + arg_var := check_node(checker, arg_child); + if arg_var != 0 { + array_add(*arg_vars, .{ arg_var, arg_child }); + } + } + } + } + } + + if arg_vars.count != arg_count { + return true; + } + + Type_Mismatch_Data :: struct { + lhs : Result; + rhs : Result; + } + + mismatches : [..]Type_Mismatch_Data; + mismatches.allocator = temp; + + for *func : find_result.functions { + if overload_found { + break; + } + + function := from_handle(checker, func.type_variable); + + field_list := function.source_node.children[0]; + if arg_count != field_list.children.count { + continue; + } + + if node.children.count == 0 && function.children.count == 0 { + overload_found = true; + } + + if overload_found && function.return_type_variable == 0 { + break; + } + + all_args_match : bool = true; + + for arg : arg_vars { + function_param := function.children[it_index]; + + if !types_compatible(checker, arg.var, function_param, true) { + if all_args_match { + arg_node = arg.node; + } + fun_param := from_handle(checker, function_param); + mismatch : Type_Mismatch_Data; + mismatch.lhs = arg; + mismatch.rhs = .{ function_param, fun_param.source_node }; + array_add(*mismatches, mismatch); + + all_args_match = false; + overload_found = false; + } else { + overload_found = all_args_match; + } + } + + if overload_found { + if function.return_type_variable > 0 { + return_var := from_handle(checker, function.return_type_variable); + constrained_var := from_handle(checker, type_var); + constrained_var.type = return_var.type; + constrained_var.typename = return_var.typename; + } + } + } + + if !overload_found { + no_matching_overload_found(checker, node, find_result, arg_node); + + for mismatch : mismatches { + type_mismatch(checker, mismatch.lhs.node, mismatch.rhs.node, mismatch.rhs.var, mismatch.lhs.var); + } + + return true; + } + + return false; +} + +check_node :: (checker : *Checker, node : *AST_Node) -> Type_Variable_Handle { + if node.kind == { + case .Function; { + check_function(checker, node); + return 0; + } + case. Field; { + field_var := check_field(checker, node); + return field_var; + } + case .Unnamed_Field; { + field_var := check_field(checker, node); + return field_var; + } + case .Unary; { + var := check_node(checker, node.children[0]); + variable, handle := new_type_variable(checker); + type := from_handle(checker, var); + variable.type = type.type; + variable.typename = type.typename; + variable.scope = type.scope; + variable.source_node = node; + node.type_variable = handle; + add_child(variable, var); + + 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; { + if checker.checking_lvalue { + cannot_assign_to_lvalue(checker, node.parent.parent); + return 0; + } + prev_checking_lvalue := checker.checking_lvalue; + if node.token.kind == .TOKEN_ASSIGN { + checker.checking_lvalue = true; + } + lhs_var := check_node(checker, node.children[0]); + checker.checking_lvalue = prev_checking_lvalue; + + if lhs_var == 0 { + return 0; + } + rhs_var := check_node(checker, node.children[1]); + if rhs_var == 0 { + return 0; + } + + variable, handle := new_type_variable(checker); + lhs_type := from_handle(checker, lhs_var); + rhs_type := from_handle(checker, rhs_var); + + 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; + node.type_variable = handle; + add_child(variable, lhs_var); + add_child(variable, rhs_var); + + if node.token.kind == { + case .TOKEN_LEFTBRACKET; { + element := from_handle(checker, lhs_type.element_type); + variable.type = element.type; + variable.typename = element.typename; + } + case .TOKEN_PLUS; #through; + case .TOKEN_MINUS; #through; + case .TOKEN_STAR; #through; + case .TOKEN_SLASH; { + if !types_compatible(checker, lhs_var, rhs_var) { + type_mismatch(checker, node, node.children[1], lhs_var, rhs_var); + return 0; + } + + if lhs_type.type == .Struct { + variable.type = lhs_type.type; + variable.typename = lhs_type.typename; + variable.scope = lhs_type.scope; + } else if rhs_type.type == .Struct { + variable.type = rhs_type.type; + variable.typename = rhs_type.typename; + variable.scope = rhs_type.scope; + } + } + case .TOKEN_ASSIGN; { + 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; + case .TOKEN_GREATEREQUALS; #through; + case .TOKEN_LESS; #through; + case .TOKEN_LESSEQUALS; #through; + case .TOKEN_LOGICALOR; #through; + case .TOKEN_ISEQUAL; #through; + case .TOKEN_ISNOTEQUAL; #through; + case .TOKEN_LOGICALAND; { + variable.type = .Bool; + variable.typename = Typenames[variable.type]; + } + } + return handle; + } + case .Return; { + return check_node(checker, node.children[0]); + } + case .For; { + loop_iterator := node.token; + // @Incomplete: Missing scope here? + + scope, scope_handle := push_scope(checker, kind = .Block); + + symbol : Defined_Symbol; + symbol.name = loop_iterator.ident_value; + symbol.source_node = node; + variable, handle := new_type_variable(checker); + variable.scope = scope_handle; + variable.name = symbol.name; + typename : string; + variable.type = .Int; + symbol.type_variable = handle; + add_symbol_to_scope(checker.state, *checker.ctx.scope_stack, checker.current_scope, symbol.name, symbol); + + begin_iter := check_node(checker, node.children[0]); + begin_var := from_handle(checker, begin_iter); + if begin_var.type != .Int { + + } + + end_iter := check_node(checker, node.children[1]); + end_var := from_handle(checker, end_iter); + if end_var.type != .Int { + + } + + check_block(checker, node.children[2]); + pop_scope(checker); + } + case .If; { + cond_var := check_node(checker, node.children[0]); + + if cond_var > 0 { + cond := from_handle(checker, cond_var); + if cond.type != .Bool { + if_condition_has_to_be_boolean_type(checker, node, cond_var); + } + } + + body_var := check_block(checker, node.children[1]); + + if node.children.count == 3 { + if node.children[2].kind == .If { + check_node(checker, node.children[2]); + } else { + check_block(checker, node.children[2]); + } + } + } + case .If_Directive; { + check_if_directive(checker, node); + } + case .Variable; { + return check_variable(checker, node); + } + case .Integer; { + type_variable, handle := new_type_variable(checker); + type_variable.type = .Int; + type_variable.source_node = node; + node.type_variable = handle; + + return handle; + } + case .Float; { + type_variable, handle := new_type_variable(checker); + type_variable.type = .Float; + type_variable.source_node = node; + node.type_variable = handle; + + return handle; + } + case .Expression_Statement; { + return check_node(checker, node.children[0]); + } + case .Call; { + type_variable, handle := new_type_variable(checker); + type_variable.type = .Unresolved_Expression; + type_variable.source_node = node; + node.type_variable = handle; + + if check_call(checker, node, handle) { + return 0; + } + + return handle; + } + } + return 0; +} + +is_valid_define :: (checker : *Checker, def : string) -> bool { + for env_def : checker.ctx.environment.defines { + if env_def == def { + return true; + } + } + return false; +} + +check_env_expression :: (checker : *Checker, expr : *AST_Node, directive : *AST_Node) -> bool { + 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]; + + lhs_valid := check_env_expression(checker, lhs, directive); + rhs_valid := check_env_expression(checker, rhs, directive); + + if expr.token.kind == .TOKEN_LOGICALOR { + return lhs_valid || rhs_valid; + } else if expr.token.kind == .TOKEN_LOGICALAND { + 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 + + return is_valid_define(checker, child.name); + } + } + + return false; +} + +check_if_directive :: (checker : *Checker, directive : *AST_Node) { + cond := directive.children[0]; + is_valid := check_env_expression(checker, cond, directive); + + if is_valid { + parent := directive.parent; + first_child : *AST_Node = directive.children[1]; + + if checker.current_scope == 1 { + traverse(checker, first_child); + } else { + check_block(checker, first_child); + } + + for child : directive.children[1].children { + add_child(parent, child); + } + + if directive.children.count > 2 { + directive.children.count = 0; + } + } else if directive.children.count > 2 { + parent := directive.parent; + + else_branch := directive.children[2]; + if else_branch.kind == .If_Directive { + check_if_directive(checker, else_branch); + } else { + for child : else_branch.children { + add_child(parent, child); + } + + if checker.current_scope == 1 { + if else_branch.kind == .If_Directive { + check_declaration(checker, else_branch); + } else { + traverse(checker, else_branch); + } + } + } + + directive.children.count = 0; + } +} + +check_declaration :: (checker : *Checker, declaration : *AST_Node) { + if declaration.kind == .Function { + if declaration.foreign_declaration { + fun_handle := declare_foreign_function(checker, declaration); + } else { + fun_handle := declare_function(checker, declaration); + } + } else if declaration.kind == .Struct { + declare_struct(checker, declaration); + } else if declaration.kind == .CBuffer { + declare_cbuffer(checker, declaration); + } else if declaration.kind == .If_Directive { + check_if_directive(checker, declaration); + } else if declaration.kind == .Buffer { + declare_buffer(checker, declaration); + } +} + +traverse :: (checker : *Checker, root : *AST_Node) { + declarations := root.children; + for declaration : declarations { + check_declaration(checker, declaration); + } + + if checker.had_error { + return; + } + + for declaration : declarations { + if declaration.kind == .If_Directive { + continue; + } + + check_node(checker, declaration); + } +} + +traverse :: (checker : *Checker) { + traverse(checker, checker.program_root); +} + +types_compatible :: (checker : *Checker, lhs : Type_Variable_Handle, rhs : Type_Variable_Handle, param_matching : bool = false) -> bool { + lhs_var := from_handle(checker, lhs); + rhs_var := from_handle(checker, rhs); + + if lhs_var.type == { + case .Int; #through; + case .Half; #through; + case .Float; #through; + case .Double; { + if !param_matching { + if rhs_var.type == .Struct { + if rhs_var.typename == { + case "float2"; #through; + case "float3"; #through; + case "float4"; { + return true; + } + } + } + } + return rhs_var.type == .Int || rhs_var.type == .Half || + rhs_var.type == .Float || rhs_var.type == .Double; + } + case .Sampler; #through; + case .Texture2D; { + return rhs_var.type == lhs_var.type; + } + case .Struct; { + if rhs_var.type != .Struct && !param_matching { + if lhs_var.typename == { + case "float2"; #through; + case "float3"; #through; + case "float4"; { + return rhs_var.type == .Int || rhs_var.type == .Half || rhs_var.type == .Double || rhs_var.type == .Float; + } + } + } + + if rhs_var.type != .Struct { + return false; + } + + lhs_struct := find_symbol(checker, lhs_var.typename, xx 1); + rhs_struct := find_symbol(checker, rhs_var.typename, xx 1); + + if !lhs_struct || !rhs_struct { + return false; + } + + if !lhs_struct.type_variable || !rhs_struct.type_variable { + return false; + } + + lhs_struct_var := from_handle(checker, lhs_struct.type_variable); + rhs_struct_var := from_handle(checker, rhs_struct.type_variable); + + if lhs_struct_var.children.count != rhs_struct_var.children.count { + return false; + } + + for i : 0..lhs_struct_var.children.count - 1 { + lhs_child := lhs_struct_var.children[i]; + rhs_child := rhs_struct_var.children[i]; + if !types_compatible(checker, lhs_child, rhs_child) { + return false; + } + } + + return true; + } + case .Unresolved_Expression; #through; + case .Unresolved_Variable; { + return true; + } + } + return false; +} + +add_builtins_new :: (checker : *Checker) { + + checker.state = .Adding_Builtins; + float_name := Typenames[Type_Kind.Float]; + int_name := Typenames[Type_Kind.Int]; + + arg :: (name : string = "", kind : Type_Kind) -> Arg { + return .{ name, Typenames[kind] }; + } + + targ :: (typename : string) -> Arg { + return .{ "", typename }; + } + + farg :: (name : string = "") -> Arg { + return arg(name, .Float); + } + + iarg :: (name : string = "") -> Arg { + return arg(name, .Int); + } + + float2_tv, f2h := new_builtin_struct(checker, "float2", .[farg("x"), farg("y")]); + float3_tv, f3h := new_builtin_struct(checker, "float3", .[farg("x"), farg("y"), farg("z")]); + float4_tv, f4h := new_builtin_struct(checker, "float4", .[farg("x"), farg("y"), farg("z"), farg("w")]); + + float4x4_members : [16]Arg; + i := 0; + for x : 0..3 { + for y : 0..3 { + float4x4_members[i] = farg(tprint("m%1%2", x + 1, y + 1)); + i += 1; + } + } + + float4x4_tv, f4x4h := new_builtin_struct(checker, "float4x4", float4x4_members); + + int2_tv, i2h := new_builtin_struct(checker, "int2", .[iarg("x"), iarg("y")]); + int3_tv, i3h := new_builtin_struct(checker, "int3", .[iarg("x"), iarg("y"), iarg("z")]); + int4_tv, i4h := new_builtin_struct(checker, "int4", .[iarg("x"), iarg("y"), iarg("z"), iarg("w")]); + + int4x4_members : [16]Arg; + i = 0; + for x : 0..3 { + for y : 0..3 { + int4x4_members[i].name = tprint("m%1%2", x + 1, y + 1); + int4x4_members[i].typename = int_name; + i += 1; + } + } + + int4x4_tv, i4x4h := new_builtin_struct(checker, "int4x4", int4x4_members); + + new_builtin_function(checker, "float2", .[farg(), farg()], targ("float2")); + new_builtin_function(checker, "float2", .[farg()], targ("float2")); + new_builtin_function(checker, "float2", .[targ("float2")], targ("float2")); + + + new_builtin_function(checker, "float3", .[farg(), farg(), farg()], targ("float3")); + new_builtin_function(checker, "float3", .[targ("float3")], targ("float3")); + new_builtin_function(checker, "float3", .[targ("float2"), farg()], targ("float3")); + new_builtin_function(checker, "float3", .[farg(), targ("float2")], targ("float3")); + new_builtin_function(checker, "float3", .[farg()], targ("float3")); + + + new_builtin_function(checker, "float4", .[farg(), farg(), farg(), farg()], targ("float4")); + new_builtin_function(checker, "float4", .[targ("float2"), targ("float2")], targ("float4")); + new_builtin_function(checker, "float4", .[targ("float2"), farg(), farg()], targ("float4")); + new_builtin_function(checker, "float4", .[farg(), targ("float2"), farg()], targ("float4")); + new_builtin_function(checker, "float4", .[farg(), farg(), targ("float2")], targ("float4")); + new_builtin_function(checker, "float4", .[farg(), targ("float3")], targ("float4")); + new_builtin_function(checker, "float4", .[targ("float3"), farg()], targ("float4")); + 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; +} + +add_builtins :: (checker : *Checker) { + source_location := #location().fully_pathed_filename; + path_array := split(source_location, "/"); + + sb : String_Builder; + for i : 0..path_array.count - 2 { + print_to_builder(*sb, path_array[i]); + append(*sb, "/"); + } + + append(*sb, "builtins.ink"); + + path := builder_to_string(*sb); + + BUILTIN, ok := read_entire_file(path); + + if !ok { + messages : [..]Compiler_Message; + internal_error_message(*messages, "Error loading builtin functions.", checker.path); + print("%\n", report_messages(checker.ctx, messages)); + assert(false); + return; + } + + checker.state = .Adding_Builtins; + + checker.ctx.file = make_file_from_string(BUILTIN); + + prev_file := checker.ctx.file; + prev_root := checker.ctx.root; + prev_tokens := checker.ctx.tokens; + + checker.ctx.root = null; + + tokens : [..]Token; + scratch := get_scratch(); + defer scratch_end(scratch); + tokens.allocator = scratch.allocator; + array_reserve(*tokens, 1024 * 1024); + checker.ctx.tokens = tokens; + + checker.ctx.tokens.count = 0; + + lex(checker.ctx); + parse(checker.ctx); + type_check(checker, checker.ctx.root); + + for *type_var : checker.ctx.type_variables { + type_var.builtin = true; + } + + checker.state = .Type_Checking; + + checker.ctx.file = prev_file; + checker.ctx.root = prev_root; + checker.ctx.tokens = prev_tokens; +} + +type_check :: (checker : *Checker, root : *AST_Node) { + traverse(checker, root); +} + +check :: (ctx : *Compiler_Context, allocator : Allocator = temp) { + if ctx.had_error { + return; + } + + new_context := context; + new_context.allocator = allocator; + push_context new_context { + init_context_allocators(); + defer clear_context_allocators(); + + checker : Checker; + + checker.ctx = ctx; + + init_semantic_checker(*checker, ctx.root, ctx.file.path); + + add_builtins_new(*checker); + // add_builtins(*checker); + + type_check(*checker, ctx.root); + + ctx.had_error |= checker.had_error; + } + + +} + +// =========================================================== +// Pretty printing + +#scope_file +type_to_string :: (variables : []Type_Variable, type_variable : Type_Variable, allocator := context.allocator) -> string { + if type_variable.type == { + case .Invalid; + return "{{invalid}}"; + case .Unit; + return "()"; + case .Int; #through; + case .Half; #through; + case .Float; #through; + case .Sampler; #through; + case .Texture2D; #through; + case .Double; { + return Typenames[type_variable.type]; + } + case .Function; #through; + case .Struct; { + return type_variable.typename; + } + case .Buffer; #through; + case .Array; + element_type := from_handle(variables, type_variable.element_type); + return sprint("[%].%", type_variable.element_count, type_to_string(variables, element_type)); + } + return ""; +} + +#scope_export + +print_key :: (scope_stack : *Scope_Stack, current_scope : Scope_Handle, builder : *String_Builder, name : string) { + scope := get_scope(scope_stack, current_scope); + target_length := scope.longest_key_length + 1; + missing_padding := target_length - name.count; + str := tprint("[%]", name); + append(builder, str); + for 0..missing_padding - 1 { + append(builder, " "); + } + + append(builder, ": "); +} + +pretty_print_function :: (scope_stack : *Scope_Stack, current_scope : Scope_Handle, variables : []Type_Variable, builder : *String_Builder, name : string, function : Type_Variable, indentation : int) { + indent(builder, indentation); + print_key(scope_stack, current_scope, builder, name); + append(builder, "("); + + for child : function.source_node.children { + if child.kind == .FieldList { + for field : child.children { + tv := from_handle(variables, field.type_variable); + if tv.type != .Function { + if tv.builtin { + print_to_builder(builder, "%", tv.name); + } else { + print_to_builder(builder, "% : %", tv.name, type_to_string(variables, tv)); + } + } else { + pretty_print_function(scope_stack, current_scope, variables, builder, "", tv, 0); + } + + if it_index < child.children.count - 1 { + append(builder, ", "); + } + } + } + } + + if function.return_type_variable> 0 { + print_to_builder(builder, ") -> %\n", type_to_string(variables, from_handle(variables, function.return_type_variable))); + } else { + append(builder, ")\n"); + } +} + +pretty_print_struct :: (ctx : *Compiler_Context, scope_stack : *Scope_Stack, current_scope : Scope_Handle, variables : []Type_Variable, builder : *String_Builder, name : string, struct_field : Type_Variable, indentation : int) { + indent(builder, indentation); + print_key(scope_stack, current_scope, builder, name); + + append(builder, "{"); + + struct_symbol : Defined_Symbol; + lookup_type(scope_stack, variables, current_scope, struct_field.typename, null, *struct_symbol); + struct_type := from_handle(variables, struct_symbol.type_variable); + + for 0..struct_type.children.count - 1 { + child_handle := struct_type.children[it]; + child := from_handle(variables, child_handle); + print_to_builder(builder, child.name); + append(builder, " : "); + print_to_builder(builder, type_to_string(variables, child)); + + if it < struct_type.children.count - 1 { + append(builder, ", "); + } + } + + append(builder, "}"); +} + +pretty_print_scope :: (ctx : *Compiler_Context, current_scope : Scope_Handle, scope_stack : Scope_Stack, variables : []Type_Variable, scope : *Scope, builder : *String_Builder, indentation : int = 0) { + if scope.builtin { + return; + } + + table := scope.table; + + indent(builder, indentation); + append(builder, "scope ("); + if scope.name.count > 0 { + print_to_builder(builder, "%", scope.name); + } else { + if scope.kind == { + case .Global; { + append(builder, "global"); + } + case .Block; { + append(builder, "block"); + } + case .Function; { + append(builder, "function"); + } + case .Struct; { + append(builder, "struct"); + } + } + } + append(builder, ") ["); + if scope.table.count > 0 { + append(builder, "\n"); + } + + for table { + key, value := it_index, it; + if value.builtin continue; + + if value.functions.count > 0 { + for func : value.functions { + type_variable := from_handle(variables, func.type_variable); + if type_variable.type == { + case .Function; { + pretty_print_function(*scope_stack, current_scope, variables, builder, key, type_variable, 1); + } + } + } + } else { + type_variable := from_handle(variables, value.type_variable); + if type_variable.type == { + case .Function; { + pretty_print_function(*scope_stack, current_scope, variables, builder, key, type_variable, 1); + } + case .CBuffer; { + 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.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; { + indent(builder, indentation + 1); + print_key(*scope_stack, current_scope, builder, key); + print_to_builder(builder, "%\n", type_to_string(variables, type_variable)); + } + } + } + } + + for child : scope.children { + child_scope := *scope_stack.stack[child - 1]; + pretty_print_scope(ctx, current_scope, *scope_stack, variables, child_scope, builder, indentation + 1); + } + + if (scope.table.count > 0 || scope.children.count > 0) { + indent(builder, indentation); + } + append(builder, "]\n"); +} + +print_type_variable :: (ctx : *Compiler_Context, builder : *String_Builder, variables : []Type_Variable, variable : Type_Variable) { + if variable.builtin { + if variable.type != .Function || variable.type != .Struct { + print_to_builder(builder, "%", type_to_string(variables, variable)); + } else { + print_to_builder(builder, "%", variable.name); + } + } else { + node := variable.source_node; + if node { + if node.kind == { + case .Function; #through; + case .Struct; #through; + case .CBuffer; #through; + case .Field; { + if variable.struct_field_parent { + print_to_builder(builder, "%.", variable.struct_field_parent.name); + } + + print_to_builder(builder, "%", node.name); + } + case .Access; { + + } + case .Binary; { + left_most := node.children[0]; + + while left_most.kind == .Binary { + left_most = left_most.children[0]; + } + + right_most := node.children[1]; + while right_most.kind == .Binary { + right_most = right_most.children[1]; + } + + source_location : Source_Range; + source_location.begin = left_most.source_location.main_token; + source_location.end = right_most.source_location.main_token; + source_location.main_token = node.source_location.main_token; + + print("%\n", print_from_source_location(ctx, builder, source_location,, temp)); + } + case .Call; { + if variable.return_type_variable{ + assert(false); + print_to_builder(builder, "%", variable.typename); + print_type_variable(ctx, builder, variables, variable.return_type_variable); + } + + print_to_builder(builder, "%(", node.name); + + + for child : node.children { + if child.kind == .ArgList { + for arg : child.children { + print_type_variable(ctx, builder, variables, arg.type_variable); + + if it_index < child.children.count - 1 { + append(builder, ", "); + } + } + } + } + + append(builder, ")"); + } + case; { + print("%\n", print_from_source_location(ctx, builder, node.source_location,, temp)); + } + } + } + } +} + +print_type_variable :: (ctx : *Compiler_Context, builder : *String_Builder, variables : []Type_Variable, handle : Type_Variable_Handle) { + variable := from_handle(variables, handle); + print_type_variable(ctx, builder, variables, variable); +} + +pretty_print_symbol_table :: (checker : *Checker, allocator : Allocator) -> string { + builder : String_Builder; + init_string_builder(*builder,, allocator); + + pretty_print_scope(checker.ctx, xx checker.current_scope, checker.ctx.scope_stack, checker.ctx.type_variables, *checker.ctx.scope_stack.stack[0], *builder); + + return builder_to_string(*builder,, allocator); +} + +pretty_print_symbol_table :: (ctx : *Compiler_Context, allocator : Allocator) -> string { + builder : String_Builder; + init_string_builder(*builder,, allocator); + + current_scope := cast(Scope_Handle)1; + pretty_print_scope(ctx, current_scope, ctx.scope_stack, ctx.type_variables, *ctx.scope_stack.stack[0], *builder); + + return builder_to_string(*builder,, allocator); +} + +#scope_module + +#import "ncore"; +#import "Hash_Table"; +#import "String"; +#import "Random"; diff --git a/codegen.jai b/codegen.jai new file mode 100644 index 0000000..05f1120 --- /dev/null +++ b/codegen.jai @@ -0,0 +1,664 @@ +///////////////////////////////////// +//~ nbr: +// + +///////////////////////////////////// +//~ nbr: Codegen TODOs +// + +Output_Language :: enum { + HLSL; + GLSL; // @Incomplete + MLSL; // @Incomplete + // SPIRV; // @Incomplete: Should we do this? +} + +Codegen_State :: struct { + path : string; + + current_scope : Scope_Handle; + + output_language : Output_Language; + + builder : String_Builder; + + ctx : *Compiler_Context; +} + +Reserved_HLSL_Words :: string.[ + "texture", + "sampler", + "matrix", + "line", + "precise", + "shared", + "triangle", + "triangleadj", +]; + +Reserved_MLSL_Words :: string.[ + "" +]; + +Reserved_GLSL_Words :: string.[ + "" +]; + +init_codegen_state :: (state : *Codegen_State, ctx : *Compiler_Context, output_language : Output_Language) { + state.current_scope = cast(Scope_Handle)1; + state.output_language = output_language; + init_string_builder(*state.builder); +} + +indent :: (state : *Codegen_State, indentation : int) { + for 1..indentation append(*state.builder, " "); +} + +hlsl_type_to_string :: (variables : []Type_Variable, type_handle : Type_Variable_Handle) -> string { + return hlsl_type_to_string(variables, from_handle(variables, type_handle)); +} + +hlsl_type_to_string :: (variables : []Type_Variable, type_variable : Type_Variable) -> string { + if type_variable.type == { + case .Invalid; + return "{{invalid}}"; + case .Unit; + return "()"; + case .Int; { + return "int"; + } + case .Half; { + return "half"; + } + case .Float; { + return "float"; + } + case .Double; { + return "double"; + } + case .Sampler; { + return "SamplerState"; + } + case .Texture2D; { + return "Texture2D"; + } + case .Function; #through; + case .Struct; { + return type_variable.typename; + } + case .Array; + return hlsl_type_to_string(variables, type_variable.element_type); + } + + return ""; +} + +emit_field :: (state : *Codegen_State, node : *AST_Node, indentation : int) { + find_result := find_symbol(state.ctx.scope_stack, node.name, state.current_scope); + + field := from_handle(state.ctx.type_variables, find_result.type_variable); + + indent(state, indentation); + + print_to_builder(*state.builder, "% ", hlsl_type_to_string(state.ctx.type_variables, field)); + + print_to_builder(*state.builder, "%", node.name); + + if field.type == .Sampler { + print_to_builder(*state.builder, " : register(s%)", field.resource_index); + } + + if field.type == .Texture2D { + print_to_builder(*state.builder, " : register(t%)", field.resource_index); + } + + if node.children.count == 1 { + child := node.children[0]; + + if field.type == .Array { + append(*state.builder, "["); + emit_node(state, child, 0); + append(*state.builder, "]"); + } else { + print_to_builder(*state.builder, " = "); + emit_node(state, child, 0); + } + } + + if node.parent.kind == .Block { + append(*state.builder, ";"); + } + + for i :0..field.children.count - 1 { + child := from_handle(state.ctx.type_variables, field.children[i]); + emit_node(state, child.source_node, 0); + } + + for hint : node.hint_tokens { + if lookup_hint(hint.ident_value) == .Position { + append(*state.builder, " : POSITION"); + } else if lookup_hint(hint.ident_value) == .UV { + append(*state.builder, " : TEXCOORD0"); + } else if lookup_hint(hint.ident_value) == .Output_Position { + append(*state.builder, " : SV_POSITION"); + } + } +} + +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) { + indent(state, indentation); + + if node.name == "sample" { + assert(node.children.count > 0); + args := node.children[0]; + + emit_node(state, args.children[0], 0); + append(*state.builder, "."); + print_to_builder(*state.builder, "Sample("); + + for i : 1..args.children.count - 1 { + child := args.children[i]; + + emit_node(state, child, 0); + + if i != args.children.count - 1 { + append(*state.builder, ", "); + } + } + } else if starts_with(node.name, "float") && node.children[0].children.count == 1 { + args := node.children[0]; + + print_to_builder(*state.builder, "%(", node.name); + + number : string; + number.data = *node.name.data[5]; + number.count = node.name.count - 5; + count := parse_int(*number, s32); + + for i : 0..count - 1 { + child := args.children[0]; + emit_node(state, child, 0); + + if i != count - 1 { + append(*state.builder, ", "); + } + } + + } else { + print_to_builder(*state.builder, "%(", node.name); + + if node.children.count > 0 { + args := node.children[0]; + + for child : args.children { + emit_node(state, child, 0); + + if it_index != args.children.count - 1 { + append(*state.builder, ", "); + } + } + } + + } + + append(*state.builder, ")"); +} + +emit_function :: (state : *Codegen_State, node : *AST_Node, indentation : int, emit_body := true) { + name := get_actual_function_name(node); + find_result := find_symbol(state.ctx.scope_stack, name, state.current_scope); + + assert(find_result != null, "Attempting to generate undeclared function. This should never happen at this stage."); + if !find_result { + message : Compiler_Message; + message.message_kind = .Internal_Error; + message.path = state.path; + message.message = "Attempting to generate undeclared function. This should never happen at this stage."; + array_add(*state.ctx.messages, message); + } + + for func : find_result.functions { + function_variable := from_handle(state.ctx.type_variables, func.type_variable); + + indent(state, indentation); + + if function_variable.return_type_variable { + return_variable := from_handle(state.ctx.type_variables, function_variable.return_type_variable); + print_to_builder(*state.builder, "% ", hlsl_type_to_string(state.ctx.type_variables, return_variable)); + } else { + append(*state.builder, "void "); + } + + print_to_builder(*state.builder, "%", node.name); + + previous_scope := state.current_scope; + state.current_scope = function_variable.scope; + + append(*state.builder, "("); + + if node.children.count > 0 && node.children[0].kind == .FieldList { + params := node.children[0]; + + for child : params.children { + emit_node(state, child, 0); + + if it_index != params.children.count - 1 { + append(*state.builder, ", "); + } + } + } + + append(*state.builder, ")"); + + for hint : node.hint_tokens { + if hint.ident_value == "position" { + // @Incomplete(nb): Should be a lookup table somewhere + append(*state.builder, " : SV_POSITION"); + } + + if starts_with(hint.ident_value, "target") { + // @Incomplete(nb): Should be a lookup table somewhere + append(*state.builder, " : SV_TARGET"); + } + } + + if emit_body { + append(*state.builder, "\n{\n"); + + + if node.children.count > 1 { + emit_block(state, node.children[1], indentation + 1); + } + + append(*state.builder, "}\n"); + } else { + append(*state.builder, ";"); + } + + append(*state.builder, "\n"); + + + state.current_scope = previous_scope; + } + +} + +emit_operator :: (state : *Codegen_State, op_kind : Token_Kind) { + if op_kind == { + case .TOKEN_PLUS; { + append(*state.builder, "+"); + } + case .TOKEN_MINUS; { + append(*state.builder, "-"); + } + case .TOKEN_STAR; { + append(*state.builder, "*"); + } + case .TOKEN_SLASH; { + append(*state.builder, "/"); + } + case .TOKEN_MINUSEQUALS; { + append(*state.builder, "-="); + } + case .TOKEN_PLUSEQUALS; { + append(*state.builder, "+="); + } + case .TOKEN_DIVEQUALS; { + append(*state.builder, "/="); + } + case .TOKEN_TIMESEQUALS; { + append(*state.builder, "*="); + } + case .TOKEN_MODEQUALS; { + append(*state.builder, "%="); + } + case .TOKEN_ISEQUAL; { + append(*state.builder, "=="); + } + case .TOKEN_ASSIGN; { + append(*state.builder, "="); + } + case .TOKEN_ISNOTEQUAL; { + append(*state.builder, "!="); + } + case .TOKEN_LOGICALOR; { + append(*state.builder, "||"); + } + case .TOKEN_LOGICALAND; { + append(*state.builder, "&&"); + } + case .TOKEN_LESS; { + append(*state.builder, "<"); + } + case .TOKEN_LESSEQUALS; { + append(*state.builder, "<="); + } + case .TOKEN_GREATER; { + append(*state.builder, ">"); + } + case .TOKEN_GREATEREQUALS; { + append(*state.builder, ">="); + } + } +} + +emit_node :: (state : *Codegen_State, node : *AST_Node, indentation : int) { + if node.kind == { + case .Integer; { + print_to_builder(*state.builder, "%", node.integer_value); + } + case .Float; { + print_to_builder(*state.builder, "%f", formatFloat(node.float_value, zero_removal=.ONE_ZERO_AFTER_DECIMAL)); + } + case .Field; { + emit_field(state, node, indentation); + } + case .Block; { + + assert(false, "Not implemented yet: block"); + } + case .Variable; { + indent(*state.builder, indentation); + + type_var := from_handle(state.ctx.type_variables, node.type_variable); + + print_to_builder(*state.builder, "%", node.name); + + if node.children.count > 0 { + append(*state.builder, "."); + 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 { + if (node.parent.kind == .Binary && node.parent.token.kind != .TOKEN_ASSIGN) || node.parent.kind == .Access { + append(*state.builder, "("); + } + } + + lhs := node.children[0]; + rhs := node.children[1]; + + if node.token.kind == .TOKEN_LEFTBRACKET { + emit_node(state, lhs, 0); + append(*state.builder, "["); + emit_node(state, rhs, 0); + append(*state.builder, "]"); + } else { + emit_node(state, lhs, 0); + append(*state.builder, " "); + emit_operator(state, node.token.kind); + append(*state.builder, " "); + emit_node(state, rhs, 0); + } + + if node.token.kind != .TOKEN_ASSIGN && node.token.kind != .TOKEN_LEFTBRACKET { + if (node.parent.kind == .Binary && node.parent.token.kind != .TOKEN_ASSIGN) || node.parent.kind == .Access { + append(*state.builder, ")"); + } + } + } + case .Unary; { + indent(*state.builder, indentation); + + emit_operator(state, node.token.kind); + emit_node(state, node.children[0], 0); + } + case .Expression_Statement; { + emit_node(state, node.children[0], indentation); + append(*state.builder, ";"); + } + case .Call; { + emit_call(state, node, indentation); + } + case .Return; { + indent(*state.builder, indentation); + append(*state.builder, "return "); + emit_node(state, node.children[0], 0); + append(*state.builder, ";"); + } + case .For; { + if node.parent.kind != .For { + indent(*state.builder, indentation); + } + + append(*state.builder, "for "); + + loop_ident := node.token.ident_value; + begin_val := node.children[0].integer_value; + end_val := node.children[1].integer_value; + print_to_builder(*state.builder, "(int % = %; % < %; %++)\n", loop_ident, begin_val, loop_ident, end_val, loop_ident); + + indent(*state.builder, indentation); + append(*state.builder, "{\n"); + + emit_block(state, node.children[2], indentation + 1); + + indent(*state.builder, indentation); + append(*state.builder, "}\n"); + } + case .If; { + if node.parent.kind != .If { + indent(*state.builder, indentation); + } + + 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"); + indent(*state.builder, indentation); + append(*state.builder, "{\n"); + + emit_block(state, body, indentation + 1); + + indent(*state.builder, indentation); + append(*state.builder, "}\n"); + + if node.children.count == 3 { + emit_else(state, node.children[2], indentation); + } + } + } +} + +emit_else :: (state : *Codegen_State, node : *AST_Node, indentation : int) { + indent(*state.builder, indentation); + append(*state.builder, "else "); + + if node.kind == .If { + emit_node(state, node, indentation); + } else if node.kind == .Block { + append(*state.builder, "\n"); + indent(*state.builder, indentation); + append(*state.builder, "{\n"); + + emit_block(state, node, indentation + 1); + + indent(*state.builder, indentation); + append(*state.builder, "}"); + } +} + +emit_field_list :: (state : *Codegen_State, field_list : *AST_Node, indentation : int) { + for child : field_list.children { + emit_node(state, child, 1); + + if it_index < field_list.children.count { + append(*state.builder, ";\n"); + } + } +} + +emit_struct :: (state : *Codegen_State, node : *AST_Node, indentation : int, name : string = "") { + if name.count > 0 { + print_to_builder(*state.builder, "struct %", name); + } else { + print_to_builder(*state.builder, "struct %", node.name); + } + + + current_scope := state.current_scope; + state.current_scope = from_handle(state.ctx.type_variables, node.type_variable).scope; + + field_list := node.children[0]; + + if field_list.children.count > 0 { + append(*state.builder, "\n{\n"); + } else { + append(*state.builder, " {"); + } + + emit_field_list(state, field_list, indentation); + + append(*state.builder, "};\n\n"); + state.current_scope = current_scope; +} + +emit_cbuffer :: (state : *Codegen_State, node : *AST_Node, indentation : int) { + variable := from_handle(state.ctx.type_variables, node.type_variable); + print_to_builder(*state.builder, "cbuffer % : register(b%)", variable.name, variable.resource_index); + + current_scope := state.current_scope; + state.current_scope = from_handle(state.ctx.type_variables, node.type_variable).scope; + + field_list := node.children[0]; + + if field_list.children.count > 0 { + append(*state.builder, "\n{\n"); + } else { + append(*state.builder, " {"); + } + + emit_field_list(state, field_list, indentation); + + append(*state.builder, "}\n\n"); + 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, element.typename); + + print_to_builder(*state.builder, "StructuredBuffer<%> % : register(t%);\n\n", element.typename, variable.name, variable.resource_index); +} + +emit_declaration :: (state : *Codegen_State, node : *AST_Node) { + if node.kind == { + case .Function; { + emit_function(state, node, 0); + } + case .CBuffer; { + emit_cbuffer(state, node, 0); + } + case .Buffer; { + emit_buffer(state, node, 0); + } + case .Struct; { + emit_struct(state, node, 0); + } + } +} + +codegen :: (result : *Compiler_Context, allocator := temp) { + codegen(result, .HLSL); +} + +codegen :: (result : *Compiler_Context, output_language : Output_Language, allocator := temp) { + if result.had_error { + return; + } + + new_context := context; + new_context.allocator = allocator; + push_context new_context { + init_context_allocators(); + defer clear_context_allocators(); + + state : Codegen_State; + state.ctx = result; + state.current_scope = cast(Scope_Handle)1; + state.output_language = output_language; + init_string_builder(*state.builder); + + codegen(*state); + } +} + +#scope_file +codegen :: (state : *Codegen_State) { + found_function : bool = false; + // found_struct : bool = false; + + // for variable : state.ctx.type_variables { + // if variable.type == .Struct && variable.kind == .Declaration && !variable.builtin { + // if variable.source_node.kind == .Properties continue; + // if variable.source_node.kind == .Meta continue; + // print_to_builder(*state.builder, "struct %;\n", variable.source_node.name); + // found_struct = true; + // } + // } + + // if found_struct { + // append(*state.builder, "\n"); + // } + + for variable : state.ctx.type_variables { + if variable.type == .Function && !variable.builtin + && !variable.source_node.vertex_entry_point && !variable.source_node.pixel_entry_point { + emit_function(state, variable.source_node, 0, false); + found_function = true; + } + } + if found_function { + append(*state.builder, "\n"); + } + + for declaration : state.ctx.root.children { + if declaration.foreign_declaration { + continue; + } + emit_declaration(state, declaration); + } + + state.ctx.codegen_result_text = builder_to_string(*state.builder); +} + +#scope_module +#import "ncore"; diff --git a/error.jai b/error.jai new file mode 100644 index 0000000..6feb05b --- /dev/null +++ b/error.jai @@ -0,0 +1,153 @@ +Message_Kind :: enum { + Log; + Warning; + Error; + Internal_Error; +} + +Compiler_Message :: struct { + message_kind : Message_Kind; + + message : string; + path : string; + source_locations : [..]Source_Range; + + report_source_location : bool = true; +} + +indent :: (builder : *String_Builder, indentation : int) { + for 1..indentation append(builder, " "); +} + +newline :: (builder : *String_Builder) { + append(builder, "\n"); +} + +green :: (builder : *String_Builder) { + append(builder, green()); +} + +green :: () -> string { + return "\x1b[92m"; +} + +red :: (builder : *String_Builder) { + append(builder, red()); +} + +red :: () -> string { + return "\x1b[91m"; +} + +yellow :: (builder : *String_Builder) { + append(builder, yellow()); +} + +yellow :: () -> string { + return "\x1b[93m"; +} + +cyan :: (builder : *String_Builder) { + append(builder, cyan()); +} + +cyan :: () -> string { + return "\x1b[96m"; +} + +white :: (builder : *String_Builder) { + append(builder, white()); +} + +white :: () -> string { + return "\x1b[97m"; +} + +reset_color :: () -> string { + return "\x1b[0m"; +} + +reset_color :: (builder : *String_Builder) { + append(builder, reset_color()); +} + +add_message :: (messages : *[..]Compiler_Message, text : string, path : string, kind : Message_Kind) { + message : Compiler_Message; + message.message = text; + message.path = path; + message.report_source_location = false; + message.message_kind = kind; + array_add(messages, message); +} + +log_message :: (messages : *[..]Compiler_Message, text : string, path : string) { + add_message(messages, text, path, .Log); +} + +warning_message :: (messages : *[..]Compiler_Message, text : string, path : string) { + add_message(messages, text, path, .Warning); +} + +error_message :: (messages : *[..]Compiler_Message, text : string, path : string) { + add_message(messages, text, path, .Error); +} + +internal_error_message :: (messages : *[..]Compiler_Message, text : string, path : string) { + add_message(messages, text, path, .Internal_Error); +} + +copy_messages :: (source : []Compiler_Message, dest : *[..]Compiler_Message) { + for message : source { + array_add(dest, message); + } +} + +report_messages :: (ctx : *Compiler_Context, messages : []Compiler_Message) -> string { + builder : String_Builder; + init_string_builder(*builder); + for message : messages { + report_message(ctx, *builder, message); + } + return builder_to_string(*builder); +} + +report_message :: (ctx : *Compiler_Context, builder : *String_Builder, message : Compiler_Message) { + report_message(ctx, builder, message.path, message.message, message.source_locations, message.message_kind, message.report_source_location); +} + +report_message :: (ctx : *Compiler_Context, builder : *String_Builder, path : string, message : string, source_locations : []Source_Range, kind : Message_Kind, report_source_location : bool = false) { + append(builder, "\x1b[1;37m"); + if path.count > 0 { + print_to_builder(builder, "%:", path); + } else { + append(builder, "internal:"); + } + + if source_locations.count > 0 { + print_to_builder(builder, "%,%: ", source_locations[0].main_token.line, source_locations[0].main_token.column); + } + + if kind == .Log { + append(builder, "\x1b[31mlog: "); + } else if kind == .Error { + append(builder, "\x1b[31merror: "); + } + + append(builder, "\x1b[37m"); + print_to_builder(builder, "%\n", message); + append(builder, "\x1b[36m"); + + if report_source_location { + for location : source_locations { + append(builder, "\t"); + print_from_source_location(ctx, builder, location); + append(builder, "\n\t"); + begin := location.begin; + + print_token_pointer(builder, location.main_token); + append(builder, "\n"); + } + } + append(builder, "\x1b[37m"); +} + diff --git a/first.jai b/first.jai new file mode 100644 index 0000000..c336437 --- /dev/null +++ b/first.jai @@ -0,0 +1,96 @@ +#import "Basic"; +#import "File"; +#import "Compiler"; +#import "Metaprogram_Plugins"; + +plugins: [..] *Metaprogram_Plugin; + +build :: () { + w := compiler_create_workspace("Ink Build"); + if !w { + print("Workspace creation failed.\n"); + return; + } + + EXECUTABLE_NAME :: "ink"; + MAIN_FILE :: "ink.jai"; + + options := get_build_options(w); + + args := options.compile_time_command_line; + + profile : bool = false; + + for arg : args { + if arg == { + case "check"; { + options.output_type = .NO_OUTPUT; + } + case "profile"; { + + } + } + } + + intercept_flags: Intercept_Flags; + plugins_to_create: [..] Plugin_To_Create; + + if profile { + tracy : Plugin_To_Create; + tracy.name = "tracy"; + array_add(*plugins_to_create, tracy); + } + + success := init_plugins(plugins_to_create, *plugins, w); + if !success { + log_error("A plugin init() failed. Exiting.\n"); + exit(0); + } + + new_path: [..] string; + array_add(*new_path, ..options.import_path); + array_add(*new_path, "modules"); + array_add(*new_path, "../."); + options.import_path = new_path; + options.output_executable_name = EXECUTABLE_NAME; + + wd := get_working_directory(); + + set_build_options(options, w); + + for plugins { + if it.before_intercept it.before_intercept(it, *intercept_flags); + } + + compiler_begin_intercept(w, intercept_flags); + + for plugins if it.add_source it.add_source(it); + + add_build_file(MAIN_FILE, w); + + // Call message_loop(), which is a routine of ours below that will receive the messages. + message_loop(w); + + compiler_end_intercept(w); + + for plugins if it.finish it.finish (it); + for plugins if it.shutdown it.shutdown(it); + + print("\nDone!\n\n"); + + set_build_options_dc(.{do_output=false, write_added_strings=false}); +} + +message_loop :: (w: Workspace) { + while true { + // We ask the compiler for the next message. If one is not available, + // we will wait until it becomes available. + message := compiler_wait_for_message(); + // Pass the message to all plugins. + for plugins if it.message it.message(it, message); + + if message.kind == .COMPLETE break; + } +} + +#run, stallable build(); diff --git a/ink.jai b/ink.jai new file mode 100644 index 0000000..40acd46 --- /dev/null +++ b/ink.jai @@ -0,0 +1,768 @@ +///////////////////////////////////// +/*~ nbr: General improvements +- [x] Print out all failed tests in a list at the end +- [x] Use new compiler API with Compile_Result and Compiled_File instead +- [ ] Use unix (posix? bash? ascii?) color codes for errors +- [ ] Print golden file as green and new output as red +- [ ] Rename to Ink.jai +- [ ] Add -test option. -test does the same as test.exe used to do +- [ ] Add -fuzz option to run fuzzer (add args later) +- [ ] Add -output option to output the compiled file. Issue with this is the generated data can't be output like that. Would require serialization. +*/ + +#import "Basic"; +#import "File"; +#import "String"; +#import "File_Utilities"; +#import "Print_Color"; + +#load "module.jai"; + +GOLDEN_EXTENSION :: "golden"; +LEXER_FOLDER :: "lex"; +PARSER_FOLDER :: "parse"; +CODEGEN_FOLDER :: "codegen"; +COMPILED_FOLDER :: "compiled"; +CHECK_FOLDER :: "check"; +TESTS_FOLDER :: "test"; + +SHADER_EXTENSION :: "ink"; +SUITE_EXTENSION :: "suite"; + +Stage_Flags :: enum_flags u16 { + Lexer :: 0x1; + Parser :: 0x2; + Check :: 0x4; + Codegen :: 0x8; + Compile :: 0x10; +} + +Output_Type :: enum_flags u16 { + Golden :: 0x1; + StdOut :: 0x2; +} + +Result_Type :: enum { + File_Read_Failed; + Golden_File_Not_Found; + StdOut; + Golden_Output; + Passed; + Failed; +} + +Result :: struct { + type : Result_Type; + path : string; + stage : Stage_Flags; + + golden_path : string; + info_text : string; +} + +Test_Case :: struct { + path : string; + stage_flags : Stage_Flags; +} + +Test_Suite :: struct { + name : string; + test_cases : [..]Test_Case; + + results : [..]Result; +} + +get_golden_path :: (file_path : string, stage : Stage_Flags) -> string { + sc := get_scratch(); + defer scratch_end(sc); + path := parse_path(file_path,, sc.allocator); + file_without_extension := split(path.words[path.words.count - 1], ".",, sc.allocator); + + builder : String_Builder; + builder.allocator = temp; + + final_path_length := file_path.count - SHADER_EXTENSION.count + GOLDEN_EXTENSION.count + 1; // +1 for dot + + path.words.count -= 1; + path.words.allocator = sc.allocator; + + if stage == { + case .Lexer; { + dir := tprint("%/%", TESTS_FOLDER, LEXER_FOLDER); + make_directory_if_it_does_not_exist(dir); + array_add(*path.words, LEXER_FOLDER); + } + case .Parser; { + dir := tprint("%/%", TESTS_FOLDER, PARSER_FOLDER); + make_directory_if_it_does_not_exist(dir); + array_add(*path.words, PARSER_FOLDER); + } + case .Check; { + dir := tprint("%/%", TESTS_FOLDER, CHECK_FOLDER); + make_directory_if_it_does_not_exist(dir); + array_add(*path.words, CHECK_FOLDER); + } + case .Codegen; { + dir := tprint("%/%", TESTS_FOLDER, CODEGEN_FOLDER); + make_directory_if_it_does_not_exist(dir); + array_add(*path.words, CODEGEN_FOLDER); + } + case .Compile; { + dir := tprint("%/%", TESTS_FOLDER, COMPILED_FOLDER); + make_directory_if_it_does_not_exist(dir); + array_add(*path.words, COMPILED_FOLDER); + } + } + + init_string_builder(*builder, file_without_extension.count + GOLDEN_EXTENSION.count + 1); + builder.allocator = sc.allocator; + append(*builder, file_without_extension[0]); + append(*builder, "."); + append(*builder, GOLDEN_EXTENSION); + golden_path := builder_to_string(*builder,, sc.allocator); + array_add(*path.words, golden_path); + + final_path := path_to_string(path); + + return final_path; +} + +do_golden_comparison :: (golden_path : string, comparison_text : string, result : *Result, output_type : Output_Type) { + sc := get_scratch(); + defer scratch_end(sc); + if output_type & .Golden { + // Output the comparison file + write_entire_file(golden_path, comparison_text); + result.golden_path = copy_string(golden_path); + result.type = .Golden_Output; + return; + } else { + // Do the comparison + if !file_exists(golden_path) { + result.info_text = tprint("Golden file % does not exist. Please run with -output-as-golden at least once.\n", golden_path); + result.type = .Golden_File_Not_Found; + return; + } + + golden_text, ok := read_entire_file(golden_path,, sc.allocator); + if !ok { + result.info_text = tprint("Unable to open golden file %\n", golden_path); + result.type = .Golden_File_Not_Found; + return; + } + + comp := replace(comparison_text, "\r\n", "\n",, sc.allocator); + gold := replace(golden_text, "\r\n", "\n",, sc.allocator); + ok = compare(comp, gold) == 0; + if !ok { + result.type = .Failed; + result.info_text = tprint("Golden file:\n%\n===============\n%", gold, comp); + } else { + result.type = .Passed; + } + } +} + +run_codegen_test :: (file_path : string, ctx : *Compiler_Context, output_type : Output_Type = 0) -> Result { + result : Result; + result.path = file_path; + + lex(ctx, context.allocator); + parse(ctx, context.allocator); + check(ctx, context.allocator); + + if ctx.had_error { + result.type = .Failed; + return result; + } + result = run_codegen_test(ctx, output_type); + + return result; +} + +run_codegen_test :: (ctx : *Compiler_Context, output_type : Output_Type = 0) -> Result { + result : Result; + result.path = ctx.file.path; + result_text : string; + + codegen(ctx, context.allocator); + + if ctx.had_error { + result.type = .Failed; + result_text = report_messages(ctx, ctx.messages); + return result; + } + + result_text = ctx.codegen_result_text; + + if output_type & .StdOut { + result.info_text = result_text; + result.type = .StdOut; + return result; + } + + golden_path := get_golden_path(ctx.file.path, .Codegen); + do_golden_comparison(golden_path, result_text, *result, output_type); + return result; +} + +run_compile_test :: (path : string, output_type : Output_Type = 0) -> Result, Compiler_Context { + ctx : Compiler_Context; + result : Result; + result.path = path; + compile_file(*ctx, path, context.allocator); + + 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 buf : ctx.buffers { + if buf.kind == { + case .Constant; { + print_to_builder(*sb, "[constant_buffer] - % - %", buf.name, buf.buffer_index); + + } + case .Structured; { + print_to_builder(*sb, "[buffer] - % - %", buf.name, buf.buffer_index); + } + + if buf.hints.count > 0 { + for hint : buf.hints { + print_to_builder(*sb, " (@%)", hint.custom_hint_name); + } + } + + append(*sb, "\n"); + + indent(*sb, 1); + for field : buf.fields { + append(*sb, "[field] - "); + pretty_print_field(*sb, *field); + append(*sb, "\n"); + indent(*sb, 1); + } + } + + } + + result.info_text = builder_to_string(*sb); + } + + 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 { + result : Result; + result.path = file_path; + result.stage = .Lexer; + + result_text : string; + + lex(ctx); + if ctx.had_error { + result.type = .Failed; + result_text = report_messages(ctx, ctx.messages); + } else { + result_text = pretty_print_tokens(ctx.tokens, context.allocator); + } + + if output_type & .StdOut { + result.info_text = result_text; + result.type = .StdOut; + return result; + } + + golden_path := get_golden_path(file_path, .Lexer); + do_golden_comparison(golden_path, result_text, *result, output_type); + return result; +} + +run_parser_test :: (file_path : string, ctx : *Compiler_Context, output_type : Output_Type = 0) -> Result { + result : Result; + result.path = file_path; + + lex(ctx); + if ctx.had_error { + result.type = .Passed; + return result; + } + + result = run_parser_test(ctx, output_type); + + return result; +} + +run_parser_test :: (ctx : *Compiler_Context, output_type : Output_Type = 0) -> Result { + parse(ctx, context.allocator); + result : Result; + result.path = ctx.file.path; + result_text : string; + + if ctx.had_error { + result.type = .Failed; + result_text = report_messages(ctx, ctx.messages); + } else { + result_text = pretty_print_ast(ctx.root, context.allocator); + } + + if output_type & .StdOut { + result.info_text = result_text; + result.type = .StdOut; + return result; + } + + golden_path := get_golden_path(ctx.file.path, .Parser); + do_golden_comparison(golden_path, result_text, *result, output_type); + return result; +} + +run_check_test :: (ctx : *Compiler_Context, output_type : Output_Type = 0) -> Result { + result : Result; + result.path = ctx.file.path; + result_text : string; + + check(ctx, context.allocator); + + if ctx.had_error { + result.type = .Failed; + result_text = report_messages(ctx, ctx.messages); + } else { + result_text = pretty_print_symbol_table(ctx, context.allocator); + } + + if output_type & .StdOut { + result.info_text = result_text; + result.type = .StdOut; + return result; + } + + golden_path := get_golden_path(ctx.file.path, .Check); + do_golden_comparison(golden_path, result_text, *result, output_type); + return result; +} + +run_check_test :: (file_path : string, ctx : *Compiler_Context, output_type : Output_Type = 0) -> Result { + result : Result; + result.path = file_path; + + lex(ctx, context.allocator); + parse(ctx, context.allocator); + if ctx.had_error { + result.type = .Failed; + return result; + } + + result = run_check_test(ctx, output_type); + + return result; +} + +make_test_case :: (path : string, stage_flags : Stage_Flags, allocator := context.allocator) -> Test_Case { + test_case : Test_Case; + test_case.path = copy_string(path,, allocator); + replace_chars(test_case.path, "\\", #char "/"); + test_case.stage_flags = stage_flags; + + return test_case; +} + +run_test_new :: (file_path : string, stage_flags : Stage_Flags, results : *[..]Result, output_type : Output_Type = 0, allocator := temp) { + new_context := context; + new_context.allocator = allocator; + push_context new_context { + ctx : Compiler_Context; + + ctx.file = make_file(*ctx, file_path); + + result : Result; + if stage_flags & .Lexer { + result = run_lexer_test(file_path, *ctx, output_type); + record_result(results, result); + } + + if stage_flags & .Parser { + if stage_flags & .Lexer && result.type == .Passed || result.type == .Golden_Output { + result = run_parser_test(*ctx, output_type); + } else { + result = run_parser_test(file_path, *ctx, output_type); + } + record_result(results, result); + } + + if stage_flags & .Check { + if stage_flags & .Parser && (result.type == .Passed || result.type == .Golden_Output) { + result = run_check_test(*ctx, output_type); + } else { + result = run_check_test(file_path, *ctx, output_type); + } + record_result(results, result); + } + + if stage_flags & .Codegen { + if stage_flags & .Check && (result.type == .Passed || result.type == .Golden_Output) { + result = run_codegen_test(*ctx, output_type); + } else { + result = run_codegen_test(file_path, *ctx, output_type); + } + record_result(results, result); + } + + if stage_flags & .Compile { + result = run_compile_test(file_path, output_type); + record_result(results, result); + } + } + +} + +run_test :: (test_case : Test_Case, results : *[..]Result, output_type : Output_Type = 0, allocator := temp) { + print("%Running test: %......", cyan(), test_case.path); + + // path 30 + // len 35 + // == 5 + + + // path 20 + // len = 35 + // == 15 + + len := 50; + rest := len - test_case.path.count; + for i: 0..rest { + print(" "); + } + + run_test_new(test_case.path, test_case.stage_flags, results, output_type, allocator); +} + +record_result :: (results : *[..]Result, result : Result) { + array_add(results, result); +} + +run_test_suite :: (using suite : *Test_Suite, output_type : Output_Type = 0) { + if suite.name.count > 0 { + print("%Running suite: %\n", green(), suite.name); + print("%", reset_color()); + } + + Fail_Data :: struct { + path : string; + stage : string; + } + + test_arena : Allocator = make_arena(Gigabytes(1)); + + failed_test_paths : [..]Fail_Data; + failed_test_paths.allocator = test_arena; + + builder : String_Builder; + init_string_builder(*builder,, test_arena); + + for test_case : test_cases { + run_test(test_case, *suite.results, output_type, allocator = test_arena); + + for < suite.results { + result := suite.results[it_index]; + if compare(result.path, test_case.path) == 0 { + if result.type == { + case .Failed; { + array_add(*failed_test_paths, .{ result.path, stage_to_string(result.stage) }); + } + case .File_Read_Failed; { + array_add(*failed_test_paths, .{ result.path, "file not found" }); + } + case .Golden_File_Not_Found; { + array_add(*failed_test_paths, .{ result.path, tprint("golden file not found for %", stage_to_string(result.stage)) }); + } + } + evaluate_result(result); + } else { + break; + } + } + + // print("\n"); + } + append(*builder, "\n"); + + if output_type == 0 { + if failed_test_paths.count == 0 { + green(*builder); + print_to_builder(*builder, "All % tests passed!\n", test_cases.count); + reset_color(*builder); + } else { + print_to_builder(*builder, "%/% tests passed\n", test_cases.count - failed_test_paths.count, test_cases.count); + red(*builder); + + print_to_builder(*builder, "% failed\n", failed_test_paths.count); + for failed_test : failed_test_paths { + print_to_builder(*builder, "% failed with error: %\n", failed_test.path, failed_test.stage); + } + reset_color(*builder); + } + } + + print("%\n", builder_to_string(*builder,, test_arena)); +} + +read_suite :: (file_path : string, suite : *Test_Suite, allocator := temp) -> bool { + sc := get_scratch(); + defer scratch_end(sc); + bytes, ok := read_entire_file(file_path,, sc.allocator); + if !ok { + log_error("Unable to read suite file %\n", file_path); + return false; + } + + path := parse_path(file_path,, sc.allocator); + file_without_extension := split(path.words[path.words.count - 1], ".",, sc.allocator); + suite.name = copy_string(file_without_extension[0],, allocator); + split_lines := split(bytes, "\n",, sc.allocator); + + for split_line : split_lines { + if split_line.count == 0 { + break; + } + + if split_line[0] == #char "#" { + continue; + } + + line := split(split_line, " ",, sc.allocator); + if line[0].count == 0 { + continue; + } + + if line[0].data[0] == #char "#" { + continue; + } + + if line.count == 1 { + line = split(split_line, "\t",, sc.allocator); + if line.count == 1 { + log_error("Invalid line - % - \n", it_index + 1); + continue; + } + } + test_case_path := line[0]; + stage_flags : Stage_Flags; + + for i: 0..line.count - 1 { + trimmed := trim(line[i]); + if equal(trimmed, "lex") { + stage_flags |= .Lexer; + } else if equal(trimmed, "parse") { + stage_flags |= .Parser; + } else if equal(trimmed, "check") { + stage_flags |= .Check; + } else if equal(trimmed, "codegen") { + stage_flags |= .Codegen; + } else if equal(trimmed, "compile") { + stage_flags |= .Compile; + } + } + test_case := make_test_case(test_case_path, stage_flags, allocator); + array_add(*suite.test_cases, test_case); + } + + return true; +} + +read_test :: () { + +} + +stage_to_string :: (stage : Stage_Flags) -> string { + if #complete stage == { + case .Lexer; return "lexing"; + case .Parser; return "parsing"; + case .Check; return "checking"; + case .Codegen; return "codegen"; + case .Compile; return "compiled"; + case; return ""; + } +} + +evaluate_result :: (result : Result) { + stage : string = stage_to_string(result.stage); + + if #complete result.type == { + case .File_Read_Failed; { + print(" %", red()); + print("failed with File_Read_Failed\n"); + } + case .Golden_File_Not_Found; { + print(" %", red()); + print("failed with Golden File Not Found for stage %\n", stage); + } + case .StdOut; { + } + case .Golden_Output; { + print(" %", yellow()); + print("output new golden file at %\n", result.golden_path); + } + case .Passed; { + print(" %", green()); + print("passed %\n", stage); + } + case .Failed; { + print(" %", red()); + print("failed %\n", stage); + } + } + + if result.info_text.count > 0 { + print("%", cyan()); + print("--- Info text ---\n"); + print("%", yellow()); + print("%\n", result.info_text); + } + + print("%", reset_color()); +} + +main :: () { + args := get_command_line_arguments(); + + init_context_allocators(); + + local_temp := make_arena(Megabytes(128)); + + suites : [..]Test_Suite; + suites.allocator = local_temp; + output_type : Output_Type = 0; + + Argument_Parse_State :: enum { + None; + Compile; + Run_Suite; + Run_Test; + } + + arg_parse_state : Argument_Parse_State; + current_suite : *Test_Suite; + + path : string; + + for i: 1..args.count - 1 { + arg := args[i]; + if arg == "-output-as-golden" { + output_type |= .Golden; + continue; + } else if arg == "-output" { + output_type |= .StdOut; + continue; + } + + if arg_parse_state == { + case .Run_Suite; { + if arg == "-output-as-golden" { + output_type |= .Golden; + } else if arg == "-output" { + output_type |= .StdOut; + } else { + print("%Unknown argument % %\n", red(), arg, reset_color()); + } + } + case .Run_Test; { + cases := current_suite.test_cases.count; + if arg == "-lex" { + current_suite.test_cases[cases - 1].stage_flags |= .Lexer; + } else if arg == "-parse" { + current_suite.test_cases[cases - 1].stage_flags |= .Parser; + } else if arg == "-check" { + current_suite.test_cases[cases - 1].stage_flags |= .Check; + } else if arg == "-codegen" { + current_suite.test_cases[cases - 1].stage_flags |= .Codegen; + } else if arg == "-compile" { + current_suite.test_cases[cases - 1].stage_flags |= .Compile; + } else if contains(arg, ".") { + sc := get_scratch(); + defer scratch_end(sc); + path_split := split(arg, "\\",, sc.allocator); + split_path := split(path_split[path_split.count - 1], ".",, sc.allocator); + extension := split_path[1]; + if extension == SHADER_EXTENSION { + path := copy_string(arg,, local_temp); + test_case := make_test_case(path, 0, local_temp); + array_add(*current_suite.test_cases, test_case); + } else { + print("%Invalid file as argument % %\n", red(), arg, reset_color()); + } + } else { + print("%Unknown argument % %\n", red(), arg, reset_color()); + } + } + case .None; { + if contains(arg, ".") { + sc := get_scratch(); + defer scratch_end(sc); + path_split := split(arg, "\\",, sc.allocator); + split_path := split(path_split[path_split.count - 1], ".",, sc.allocator); + extension := split_path[1]; + + if extension == SHADER_EXTENSION { + if arg_parse_state == .Run_Suite { + log_error("Unable to run a test while already running suite."); + continue; + } + + if !current_suite { + suite : Test_Suite; + suite.results.allocator = local_temp; + suite.test_cases.allocator = local_temp; + array_add(*suites, suite); + current_suite = *suites[0]; + } + arg_parse_state = .Run_Test; + path := copy_string(arg,, local_temp); + test_case := make_test_case(path, 0, local_temp); + array_add(*current_suite.test_cases, test_case); + } else if extension == SUITE_EXTENSION { + if arg_parse_state == .Run_Test { + log_error("Unable to run a suite while already running test."); + continue; + } + arg_parse_state = .Run_Suite; + path := copy_string(arg); + + suite : Test_Suite; + suite.results.allocator = local_temp; + suite.test_cases.allocator = local_temp; + read_suite(path, *suite, local_temp); + array_add(*suites, suite); + current_suite = *suites[0]; + } else { + print("%Invalid file as argument % %\n", red(), arg, reset_color()); + } + } + } + } + } + + for suite : suites { + run_test_suite(*suite, output_type); + } + + clear(local_temp); +} diff --git a/lexing.jai b/lexing.jai new file mode 100644 index 0000000..69c78cd --- /dev/null +++ b/lexing.jai @@ -0,0 +1,802 @@ +Lexer :: struct { + input : string; + cursor : int; + start : int; + current_line : int; + current_column : int; + + ctx : *Compiler_Context; + + path : string; +} + +Token_Kind :: enum { + TOKEN_INVALID :: 0; + TOKEN_FLOATLITERAL; + TOKEN_INTLITERAL; + + TOKEN_LOGICALOR; + TOKEN_LOGICALAND; + TOKEN_ISEQUAL; + TOKEN_ISNOTEQUAL; + TOKEN_PLUSEQUALS; + TOKEN_MINUSEQUALS; + TOKEN_TIMESEQUALS; + TOKEN_DIVEQUALS; + TOKEN_MODEQUALS; + TOKEN_LESSEQUALS; + TOKEN_LESS; + TOKEN_GREATEREQUALS; + TOKEN_GREATER; + TOKEN_COLON; + TOKEN_DOUBLECOLON; + TOKEN_ASSIGN; + TOKEN_ARROW; + TOKEN_AT; + + TOKEN_PLUS; + TOKEN_STAR; + TOKEN_SLASH; + TOKEN_MOD; + TOKEN_MINUS; + + TOKEN_LEFTBRACE; + TOKEN_RIGHTBRACE; + TOKEN_LEFTBRACKET; + TOKEN_RIGHTBRACKET; + TOKEN_LEFTPAREN; + TOKEN_RIGHTPAREN; + TOKEN_SEMICOLON; + TOKEN_COMMA; + TOKEN_DOT; + TOKEN_DOTDOT; + + TOKEN_IDENTIFIER; + + // Keywords + TOKEN_BOOL; + TOKEN_BUFFER; + + TOKEN_CASE; + TOKEN_CBUFFER; + TOKEN_COLUMNMAJOR; + TOKEN_CONST; + TOKEN_CONSTANT_BUFFER; + TOKEN_CONTINUE; + + TOKEN_DEFAULT; + TOKEN_DIRECTIVE; + TOKEN_DISCARD; + TOKEN_DO; + TOKEN_DOUBLE; + + TOKEN_ELSE; + TOKEN_EXPORT; + TOKEN_EXTERN; + + TOKEN_FALSE; + TOKEN_FOR; + + TOKEN_HALF; + TOKEN_HINT; + + TOKEN_IF; + TOKEN_IN; + TOKEN_INOUT; + TOKEN_INSTANCE; + + TOKEN_MATRIX; + TOKEN_META; + + TOKEN_OPTIONAL; + TOKEN_OUT; + + TOKEN_PIXEL; + TOKEN_PLEX; + + TOKEN_RETURN; + TOKEN_REGISTER; + + TOKEN_STRING; + TOKEN_STRUCT; + TOKEN_SWITCH; + + TOKEN_TRUE; + + TOKEN_UNORM; + TOKEN_UNSIGNED; + TOKEN_UINT; + + TOKEN_VECTOR; + TOKEN_VERTEX; + TOKEN_VOID; + + TOKEN_WHILE; + + TOKEN_EOF; + TOKEN_ERROR; +} + +Token :: struct { + kind : Token_Kind; + union { + ident_value : string; + integer_value : int; + float_value : float; + string_value : string; + } + + source : *u8; + + // This could all be derived on demand + line : int; + length : int; + column : int; + index : int; + + error : string; + + builtin : bool; // @Incomplete: This is kind of a bad idea, but let's just do it for now... +} + +Source_Range :: struct { + begin : Token; + end : Token; + main_token : Token; +} + +is_at_end :: (using lexer : *Lexer) -> bool { + return input.data[cursor] == #char "\0" || cursor == input.count; +} + +peek_char :: (using lexer : *Lexer) -> u8 { + return input.data[cursor]; +} + +peek_next_char :: (using lexer : *Lexer) -> u8 { + if is_at_end(lexer) return #char "\0"; + return input.data[cursor + 1]; +} + +match_character :: (lexer : *Lexer, expected : u8) -> bool { + if is_at_end(lexer) return false; + if lexer.input.data[lexer.cursor] != expected return false; + + lexer.cursor += 1; + return true; +} + +identifier :: (lexer : *Lexer) -> *Token { + while is_alpha(peek_char(lexer)) || is_digit(peek_char(lexer)) || peek_char(lexer) == #char "_" { + advance(lexer); + } + + return make_identifier(lexer, identifier_kind(lexer)); +} + +directive :: (lexer : *Lexer) -> *Token { + advance(lexer); + while is_alpha(peek_char(lexer)) || is_digit(peek_char(lexer)) || peek_char(lexer) == #char "_" { + advance(lexer); + } + + return make_directive(lexer); +} + +number :: (lexer : *Lexer) -> *Token { + while is_digit(peek_char(lexer)) advance(lexer); + + is_float := false; + + if peek_char(lexer) == #char "." && is_digit(peek_next_char(lexer)) { + is_float = true; + advance(lexer); + f_suffix := false; + while is_digit(peek_char(lexer)) { + advance(lexer); + } + if peek_char(lexer) == #char "f" { + advance(lexer); + record_error(lexer, "We don't use 'f' suffixes for floating point values."); + return null; + } + } + + if is_float { + return make_float(lexer); + } + return make_int(lexer); +} + +identifier_kind :: (using lexer : *Lexer) -> Token_Kind { + length := cursor - lexer.start; + + index := start; + identifier : string; + identifier.data = *input.data[start]; + identifier.count = length; + + if identifier == "bool" return .TOKEN_BOOL; + if identifier == "Buffer" return .TOKEN_BUFFER; + if identifier == "case" return .TOKEN_CASE; + if identifier == "columnmajor" return .TOKEN_COLUMNMAJOR; + if identifier == "const" return .TOKEN_CONST; + if identifier == "Constant_Buffer" return .TOKEN_CONSTANT_BUFFER; + if identifier == "continue" return .TOKEN_CONTINUE; + if identifier == "default" return .TOKEN_DEFAULT; + if identifier == "directive" return .TOKEN_DIRECTIVE; + if identifier == "discard" return .TOKEN_DIRECTIVE; + if identifier == "discard" return .TOKEN_DISCARD; + if identifier == "do" return .TOKEN_DO; + if identifier == "double" return .TOKEN_DOUBLE; + if identifier == "else" return .TOKEN_ELSE; + if identifier == "export" return .TOKEN_EXPORT; + if identifier == "extern" return .TOKEN_EXTERN; + if identifier == "false" return .TOKEN_FALSE; + if identifier == "for" return .TOKEN_FOR; + if identifier == "half" return .TOKEN_HALF; + if identifier == "hint" return .TOKEN_HINT; + if identifier == "if" return .TOKEN_IF; + if identifier == "in" return .TOKEN_IN; + if identifier == "inout" return .TOKEN_INOUT; + if identifier == "instance" return .TOKEN_INSTANCE; + if identifier == "matrix" return .TOKEN_MATRIX; + if identifier == "meta" return .TOKEN_META; + if identifier == "optional" return .TOKEN_OPTIONAL; + if identifier == "out" return .TOKEN_OUT; + if identifier == "pixel" return .TOKEN_PIXEL; + if identifier == "return" return .TOKEN_RETURN; + if identifier == "register" return .TOKEN_REGISTER; + if identifier == "struct" return .TOKEN_STRUCT; + if identifier == "plex" return .TOKEN_STRUCT; + if identifier == "switch" return .TOKEN_SWITCH; + if identifier == "true" return .TOKEN_TRUE; + if identifier == "unorm" return .TOKEN_UNORM; + if identifier == "unsigned" return .TOKEN_UNSIGNED; + if identifier == "uint" return .TOKEN_UINT; + if identifier == "vector" return .TOKEN_VECTOR; + if identifier == "vertex" return .TOKEN_VERTEX; + if identifier == "void" return .TOKEN_VOID; + if identifier == "while" return .TOKEN_WHILE; + + return .TOKEN_IDENTIFIER; +} + +error_token :: (lexer : *Lexer, message : string) -> *Token { + token : *Token = new_token(lexer, .TOKEN_ERROR); + + lexer.ctx.had_error = true; + token.error = copy_string(message); + + return token; +} + +// unable_to_open_file :: (state : *Parse_State, path : string, token : Token) { +// builder : String_Builder; +// init_string_builder(*builder,, temp); + +// print_to_builder(*builder, "Unable to open file '%' for reading\n\n", path); + +// location := generate_source_location_from_token(state, token); + +// indent(*builder, 1); +// cyan(*builder); +// print_to_builder(*builder, "%\n", print_from_source_location(location)); +// indent(*builder, 1); + +// loc := location.begin; +// print_token_pointer(*builder, loc); + +// final_message := builder_to_string(*builder); +// record_error(state, token, final_message, false); +// } + +record_error :: (lexer : *Lexer, message : string) { + error : Compiler_Message; + error.message_kind = .Error; + error.message = message; + error.path = lexer.path; + + token := error_token(lexer, message); + source_location : Source_Range; + source_location.main_token = token; + + token.length += token.column; + token.source -= token.column; + token.column = 0; + + source_location.begin = token; + length := source_location.begin.column; + + source_location.end = token; + + array_add(*error.source_locations, source_location); + + lexer.ctx.had_error = true; + array_add(*lexer.ctx.messages, error); +} + +make_int :: (lexer : *Lexer) -> *Token { + token : *Token = new_token(lexer, .TOKEN_INTLITERAL); + + str : string = .{ count = token.length, + data = *lexer.input.data[lexer.start] }; + value, ok := string_to_int(str); + + if ok { + token.integer_value = value; + } + return token; +} + + +make_float :: (lexer : *Lexer) -> *Token { + token : *Token = new_token(lexer, .TOKEN_FLOATLITERAL); + + str : string = .{ count = token.length, + data = *lexer.input.data[lexer.start] }; + value, ok := string_to_float(str); + if ok { + token.float_value = value; + } + + return token; +} + +new_token :: (lexer : *Lexer, kind : Token_Kind) -> *Token { + length := lexer.cursor - lexer.start; + token : Token; + token.kind = kind; + token.line = lexer.current_line; + token.length = length; + token.column = lexer.current_column; + token.index = lexer.cursor - token.length; + + if token.length > 0 { + token.source = *lexer.input[token.index]; + } else { + token.source = *lexer.input[token.index - 1]; + } + lexer.current_column += length; + + array_add(*lexer.ctx.tokens, token); + return *lexer.ctx.tokens[lexer.ctx.tokens.count - 1]; +} + +make_directive :: (lexer : *Lexer) -> *Token { + lexer.start += 1; + ident := make_identifier(lexer, .TOKEN_DIRECTIVE); + if ident.ident_value == "load" { + path_tok := scan_next_token(lexer); + path := path_tok.string_value; + ctx : Compiler_Context; + ctx.environment = lexer.ctx.environment; + + ctx.file = make_file(*ctx, path); + + if ctx.file.source.count == 0 { + // unable_to_open_file(lexer, path, path_tok); + record_error(lexer, tprint("Unable to open file '%' for reading\n", path)); + return error_token(lexer, tprint("Unable to open file '%' for reading\n", path)); + } + + lex(*ctx); + + ctx.tokens.count -= 1; // @Note: remote TOKEN_EOF + lexer.ctx.tokens.count -= 2; + array_resize(*lexer.ctx.tokens, lexer.ctx.tokens.count + ctx.tokens.count); + + for tok : ctx.tokens { + lexer.ctx.tokens[it_index] = tok; + } + return scan_next_token(lexer); + } else if ident.ident_value == "add_define" { + new_define := scan_next_token(lexer); + add_define(*lexer.ctx.environment, new_define.ident_value); + lexer.ctx.tokens.count -= 2; + return scan_next_token(lexer); + } + return ident; +} + +make_string :: (lexer : *Lexer) -> *Token { + token : *Token = new_token(lexer, .TOKEN_STRING); + + name : string = .{ count = token.length - 2, + data = *lexer.input.data[lexer.start + 1] }; + token.string_value = name; + + return token; +} + +make_identifier :: (lexer : *Lexer, kind : Token_Kind) -> *Token { + token : *Token = new_token(lexer, kind); + + name : string = .{ count = token.length, + data = *lexer.input.data[lexer.start] }; + token.ident_value = name; + + return token; +} + +make_token :: (lexer : *Lexer, token_kind : Token_Kind) -> *Token { + return new_token(lexer, token_kind); +} + +skip_whitespace :: (lexer : *Lexer) { + while true { + if is_at_end(lexer) return; + c := peek_char(lexer); + + if c == { + case #char " "; { + lexer.current_column += 1; + advance(lexer); + continue; + } + case #char "\r"; #through; + case #char "\t"; { + advance(lexer); + continue; + } + case #char "\n"; { + advance(lexer); + lexer.current_line += 1; + lexer.current_column = 0; + continue; + } + case #char "/"; { + next := peek_next_char(lexer); + if next == #char "/" { + while peek_char(lexer) != #char "\n" && !is_at_end(lexer) { + advance(lexer); + } + continue; + } else { + return; + } + } + } + return; + } +} + +advance :: (using lexer : *Lexer) -> u8 { + c := input.data[cursor]; + cursor += 1; + return c; +} + +scan_next_token :: (lexer : *Lexer) -> *Token { + skip_whitespace(lexer); + lexer.start = lexer.cursor; + + if is_at_end(lexer) return make_token(lexer, .TOKEN_EOF); + + c := advance(lexer); + + if c == #char "#" return directive(lexer); + if is_alpha(c) return identifier(lexer); + if is_digit(c) return number(lexer); + + if c == { + case #char "\""; { + c = advance(lexer); + // lexer.start = lexer.cursor; + while c != #char "\"" { + c = advance(lexer); + } + // lexer.cursor -= 1; + tok := make_string(lexer); + // advance(lexer); + return tok; + } + case #char "+"; { + if match_character(lexer, #char "=") return make_token(lexer, .TOKEN_PLUSEQUALS); + return make_token(lexer, .TOKEN_PLUS); + } + case #char "-"; { + if match_character(lexer, #char "=") return make_token(lexer, .TOKEN_MINUSEQUALS); + if match_character(lexer, #char ">") return make_token(lexer, .TOKEN_ARROW); + return make_token(lexer, .TOKEN_MINUS); + } + case #char "*"; { + if match_character(lexer, #char "=") return make_token(lexer, .TOKEN_TIMESEQUALS); + return make_token(lexer, .TOKEN_STAR); + } + case #char "/"; { + if match_character(lexer, #char "=") return make_token(lexer, .TOKEN_DIVEQUALS); + return make_token(lexer, .TOKEN_SLASH); + } + case #char "%"; { + if match_character(lexer, #char "=") return make_token(lexer, .TOKEN_MODEQUALS); + return make_token(lexer, .TOKEN_MOD); + } + case #char ":"; { + if match_character(lexer, #char ":") return make_token(lexer, .TOKEN_DOUBLECOLON); + return make_token(lexer, .TOKEN_COLON); + } + case #char "@"; { + return make_token(lexer, .TOKEN_AT); + } + case #char "|"; { + if match_character(lexer, #char "|") return make_token(lexer, .TOKEN_LOGICALOR); + } + case #char "&"; { + if match_character(lexer, #char "&") return make_token(lexer, .TOKEN_LOGICALAND); + } + case #char "!"; { + if match_character(lexer, #char "=") return make_token(lexer, .TOKEN_ISNOTEQUAL); + } + case #char "="; { + if match_character(lexer, #char "=") return make_token(lexer, .TOKEN_ISEQUAL); + return make_token(lexer, .TOKEN_ASSIGN); + } + case #char ">"; { + if match_character(lexer, #char "=") return make_token(lexer, .TOKEN_GREATEREQUALS); + return make_token(lexer, .TOKEN_GREATER); + } + case #char "<"; { + if match_character(lexer, #char "=") return make_token(lexer, .TOKEN_LESSEQUALS); + return make_token(lexer, .TOKEN_LESS); + } + case #char "{"; { + return make_token(lexer, .TOKEN_LEFTBRACE); + } + case #char "}"; { + return make_token(lexer, .TOKEN_RIGHTBRACE); + } + case #char "("; { + return make_token(lexer, .TOKEN_LEFTPAREN); + } + case #char ")"; { + return make_token(lexer, .TOKEN_RIGHTPAREN); + } + case #char "["; { + return make_token(lexer, .TOKEN_LEFTBRACKET); + } + case #char "]"; { + return make_token(lexer, .TOKEN_RIGHTBRACKET); + } + case #char ";"; return make_token(lexer, .TOKEN_SEMICOLON); + case #char ","; return make_token(lexer, .TOKEN_COMMA); + case #char "."; { + if match_character(lexer, #char ".") return make_token(lexer, .TOKEN_DOTDOT); + return make_token(lexer, .TOKEN_DOT); + } + } + + s : string = .{ count = 1, data = *c }; + record_error(lexer, tprint("Invalid token: %", s)); + return null; + // return error_token(lexer, tprint("Invalid token: %", s)); +} + +lex :: (ctx : *Compiler_Context, allocator := temp) { + if ctx.had_error { + return; + } + + new_context := context; + new_context.allocator = allocator; + push_context new_context { + init_context_allocators(); + defer clear_context_allocators(); + + lexer : Lexer; + lexer.ctx = ctx; + array_reserve(*lexer.ctx.tokens, 1024); + + init_lexer_from_string(*lexer, ctx.file.source); + lexer.path = ctx.file.path; + token : *Token = scan_next_token(*lexer); + while token && token.kind != .TOKEN_EOF { + token = scan_next_token(*lexer); + } + } +} + +init_lexer_from_string :: (lexer : *Lexer, input : string) { + ok := read_input_from_string(lexer, input); + if !ok { + record_error(lexer, "Unable to initialize from string\n"); + lexer.ctx.had_error = true; + } +} + +init_lexer_from_file :: (lexer : *Lexer, file_path : string) { + ok := read_input_from_file(lexer, file_path); + if !ok { + record_error(lexer, tprint("Unable to read file: %\n", file_path)); + lexer.ctx.had_error = true; + } +} + +read_input_from_string :: (lexer : *Lexer, input : string) -> bool { + lexer.input = input; + lexer.cursor = 0; + lexer.start = 0; + lexer.current_line = 1; + lexer.current_column = 0; + + return true; +} + +read_input_from_file :: (lexer : *Lexer, file_path : string) -> bool { + assert(file_path != ""); + + value, success := read_entire_file(file_path, true, true); + if !success { + free(value); + return false; + } + + lexer.path = copy_string(file_path); + lexer.input = value; + lexer.cursor = 0; + lexer.start = 0; + lexer.current_line = 1; + lexer.current_column = 0; + + return true; +} + +// =========================================================== +// Pretty printing +pretty_print_token :: (token : *Token, builder : *String_Builder) { + MAX :: 21; + kind_name := enum_names(Token_Kind)[cast(int)token.kind]; + diff := MAX - kind_name.count; + + print_to_builder(builder, "{kind = %; ", token.kind); + for i : 0..diff - 1 { + append(builder, " "); + } + + append_to_length :: (builder : *String_Builder, number : int) { + if number < 10 { + append(builder, " "); + } else if number < 100 { + append(builder, " "); + } else if number < 1000 { + append(builder, " "); + } else if number < 10000 { + append(builder, " "); + } + } + + print_to_builder(builder, "; index = %", token.index); + append_to_length(builder, token.index); + + print_to_builder(builder, "; length = %", token.length); + append_to_length(builder, token.length); + + print_to_builder(builder, "line = %", token.line); + append_to_length(builder, token.line); + + print_to_builder(builder, "; column = %", token.column); + append_to_length(builder, token.column); + + append(builder, "; value ='"); + value_length : int; + if token.kind == .TOKEN_IDENTIFIER { + print_to_builder(builder, "%", token.ident_value); + } else if token.kind == .TOKEN_INTLITERAL { + print_to_builder(builder, "%", token.integer_value); + } else if token.kind == .TOKEN_FLOATLITERAL { + print_to_builder(builder, "%", token.float_value); + } else if token.kind == .TOKEN_ERROR { + print_to_builder(builder, "%", token.error); + } else { + source : string = .{ count = token.length, + data = token.source }; + print_to_builder(builder, "%", source); + } + append(builder, "'; }\n"); +} + +pretty_print_tokens :: (lexer : *Lexer, allocator : Allocator) -> string { + builder : String_Builder; + + init_string_builder(*builder,, allocator); + + token : *Token = scan_next_token(lexer); + while token && token.kind != .TOKEN_EOF { + pretty_print_token(token, *builder); + token = scan_next_token(lexer); + } + + return builder_to_string(*builder,, allocator); +} + +pretty_print_tokens :: (tokens : []Token, allocator : Allocator) -> string { + builder : String_Builder; + + init_string_builder(*builder,, allocator); + + for token : tokens { + pretty_print_token(*token, *builder); + } + return builder_to_string(*builder,, allocator); +} + +output_as_code_string :: (lexer : *Lexer, allocator : *Allocator) -> string { + builder : String_Builder; + + new_context := context; + new_context.allocator = allocator; + push_context new_context { + init_string_builder(*builder); // @Incomplete: Consider passing builder as argument + + token : *Token = scan_next_token(lexer); + while token && token.kind != .TOKEN_EOF { + token = scan_next_token(lexer); + } + + return builder_to_string(*builder); + } +} + +print_token_pointer :: (builder : *String_Builder, token : Token) { + for i : 0..token.column - 1 { + append(builder, " "); + } + + for i : 0..token.length - 1 { + append(builder, "^"); + } +} + +print_from_source_location :: (ctx : *Compiler_Context, builder : *String_Builder, source_location : Source_Range, indentation : int = 0) { + current := source_location.begin; + begin := source_location.begin; + end := source_location.end; + + if begin.builtin { + for i : begin.index..end.index - 1 { + tok := ctx.tokens[i]; + text : string; + text.data = tok.source; + text.count = tok.length; + print_to_builder(builder, "%", text); + } + } else { + begin_pos := 0; + token_string : string; + count := end.index - begin.index + end.length; + + if indentation > 0 { + indent(builder, indentation); + for 0..count - 1 { + c := begin.source[it]; + if c == #char "\n" { + append(builder, "\n"); + indent(builder, indentation); + } else { + s : string; + s.count = 1; + s.data = *c; + print_to_builder(builder, "%", s); + } + + } + } else { + token_string = .{ count = count, data = begin.source }; + indent(builder, indentation); + print_to_builder(builder, "%", token_string); + } + } +} + +print_from_source_location :: (ctx : *Compiler_Context, source_location : Source_Range, allocator := context.allocator, indentation : int = 0) -> string { + sc := get_scratch(); + defer scratch_end(sc); + builder : String_Builder; + init_string_builder(*builder,, sc.allocator); + print_from_source_location(ctx, *builder, source_location,, sc.allocator); + return builder_to_string(*builder,, allocator); +} + + +#import "Basic"; +#import "File"; diff --git a/module.jai b/module.jai new file mode 100644 index 0000000..c33b1cb --- /dev/null +++ b/module.jai @@ -0,0 +1,519 @@ +#load "lexing.jai"; +#load "error.jai"; +#load "parsing.jai"; +#load "check.jai"; +#load "codegen.jai"; + +#import "File_Utilities"; + +/* TODO +- [x] Remove builtin stringbuilding and replace it with ad-hoc string building when error reporting. In that case we are already building a string anyway, so we can just pass in the string builder +- [ ] Support structured buffers (ro, rw, w) +- [ ] Support mesh and amplification shaders +- [ ] Support compute shaders +- [x] Support #if at top level +- [x] Support #if at block level +- [x] Remove properties block and just use hinted constant buffers instead + ``` + props :: constant_buffer @properties { + [...] + } + ``` +- [ ] while loops +- [ ] for-each loops +- [ ] add parameters to hints (meta properties, resource binding indices if needed) +- [ ] consider @entry(stage) syntax instead of the forced keyword +- [ ] Add flags to compiler + - [ ] Generate output flag(s) + - [ ] Possibly final stage flag, so you can just call compile_file and it only does what you need. + - Probably this flag is about which stage you need as the _last_ and not which stages to do, as that doesn't make sense. + - [ ] Multiple output languages? +*/ + +add_define :: (env : *Environment, key : string) { + for define : env.defines { + if define == key { + return; + } + } + + array_add(*env.defines, key); +} + +remove_define :: (env : *Environment, key : string) { + for define : env.defines { + if define == key { + env.defines[it_index] = env.defines[env.defines.count - 1]; + } + } +} + +Environment :: struct { + defines : [..]string; +} + +Field_Kind :: enum { + Int :: 0; + Half :: 1; + Float :: 2; + Double :: 3; + Texture2D :: 8; + Sampler :: 9; + + Function; + Struct; + Array; +} + +Field_Type :: struct { + kind : Field_Kind; + + name : string; //@Note(niels): for structs + + children : [..]Field; +} + +Hint_Kind :: enum { + None; + + Position; + UV; + Target; + Output_Position; + + Custom; +} + +Hint_Names :: #run -> [(cast(int)Hint_Kind.Target) + 1]string { + names : [(cast(int)Hint_Kind.Target) + 1]string; + names[Hint_Kind.Position] = "position"; + names[Hint_Kind.UV] = "uv"; + names[Hint_Kind.Target] = "target"; + + return names; +} + +lookup_hint :: (name : string) -> Hint_Kind { + if name == "position" { + return Hint_Kind.Position; + } else if name == "uv" { + return Hint_Kind.UV; + } else if starts_with(name, "target") { + return Hint_Kind.Target; + } else if name == "outposition" { + return Hint_Kind.Output_Position; + } + return .None; +} + +Field_Hint :: struct { + kind : Hint_Kind; + + target_index : int; + custom_hint_name : string; +} + +Field :: struct { + name : string; + + type : Field_Type; + resource_index : u32; + hints : [..]Field_Hint; +} + +Entry_Point :: struct { + name : string; + + function_input : [..]Field; + return_value : Field; +} + +Buffer_Kind :: enum { + Constant; + Structured; +} + +Buffer :: struct { + kind : Buffer_Kind; + name : string; + + fields : Static_Array(Field, 16); + + hints : [..]Field_Hint; + + buffer_index : u32; +} + +Input_File :: struct { + source : string; + path : string; +} + +Compiler_Context :: struct { + file : Input_File; + + environment : Environment; + + tokens : [..]Token;; + root : *AST_Node; + nodes : [..]AST_Node; + + codegen_result_text : string; + + typed_buffers : Static_Array(Type_Variable_Handle, 32); + // structured_buffers : Static_Array(Type_Variable_Handle, 16); + + scope_stack : Scope_Stack; + type_variables : [..]Type_Variable; + + vertex_entry_point : struct { + node : *AST_Node; + name : string; + input : [..]Field; + } + + pixel_entry_point : struct { + node : *AST_Node; + name : string; + return_value : Field; + } + + max_buffers :: 32; + + buffers : Static_Array(Buffer, max_buffers); + + had_error : bool; + messages : [..]Compiler_Message; +} + +#add_context scratch_allocators : [2]Allocator; +#add_context scratch_id : int = 0; + +init_context_allocators :: () { + if get_arena(context.scratch_allocators[0]) == null { + context.scratch_allocators[0] = make_arena(Megabytes(128)); + context.scratch_allocators[1] = make_arena(Megabytes(128)); + } +} + +clear_context_allocators :: () { + if get_arena(context.scratch_allocators[0]) != null { + clear(context.scratch_allocators[0]); + clear(context.scratch_allocators[1]); + } +} + +get_scratch :: (conflict : Allocator = .{}) -> Scratch { + arena := cast(*Arena)conflict.data; + if arena == get_arena(context.scratch_allocators[0]) || context.scratch_id == 0 { + context.scratch_id = 1; + return scratch_begin(*context.scratch_allocators[1]); + } + context.scratch_id = 0; + return scratch_begin(*context.scratch_allocators[0]); +} + +record_error :: (result : *Compiler_Context, format : string, args : .. Any) { + error : Compiler_Message; + error.message_kind = .Error; + error.message = sprint(format, args); + + array_add(*result.messages, error); +} + +make_file :: (result : *Compiler_Context, path : string) -> Input_File { + if !file_exists(path) { + record_error(result, "Unable to load file: %", path); + return .{}; + } + file_string, ok := read_entire_file(path); + + if !ok { + record_error(result, "Unable to load file: %", path); + return .{}; + } + + return make_file_from_string(file_string, path); +} + +make_file_from_string :: (source : string, path : string = "") -> Input_File { + input_file : Input_File; + + input_file.source = source; + input_file.path = path; + + return input_file; +} + +pretty_print_field :: (field : *Field) -> string { + builder : String_Builder; + init_string_builder(*builder,, temp); + + pretty_print_field(*builder, field); + + return builder_to_string(*builder); +} + +Min_Field_Name :: 10; + +pretty_print_field :: (builder : *String_Builder, field : *Field) { + if field.name.count > 0 { + print_to_builder(builder, "% ", field.name); + append(builder, ": "); + } else { + append(builder, "return - "); + } + + type := field.type; + + if type.kind == { + case .Int; { + append(builder, "int"); + } + case .Half; { + append(builder, "half"); + } + case .Float; { + append(builder, "float"); + } + case .Double; { + append(builder, "double"); + } + case .Texture2D; { + append(builder, "texture2D"); + } + case .Sampler; { + append(builder, "sampler"); + } + case .Struct; { + print_to_builder(builder, "struct : % {", type.name); + + newline_after := type.children.count / 4; + + for *child : type.children { + pretty_print_field(builder, child); + if it_index < type.children.count - 1 { + append(builder, ", "); + } + + if it_index % newline_after == 0 { + append(builder, "\n"); + indent(builder, 4); + } + } + + append(builder, "} "); + } + case .Array; { + + } + } + + for hint : field.hints { + if hint.kind == { + case .Position; { + append(builder, "(@position)"); + } + case .Target; { + print_to_builder(builder, "(@target%)", hint.target_index); + } + case .Custom; { + print_to_builder(builder, "(@%)", hint.custom_hint_name); + } + } + + if it_index != field.hints.count - 1 { + append(builder, ", "); + } + } +} + +type_variable_to_field :: (ctx : *Compiler_Context, variable : *Type_Variable) -> Field { + field : Field; + + field.name = variable.name; + + type : Field_Type; + + if variable.type == { + case .Int; { + type.kind = Field_Kind.Int; + } + case .Half; { + type.kind = Field_Kind.Half; + } + case .Float; { + type.kind = Field_Kind.Float; + } + case .Double; { + type.kind = Field_Kind.Double; + } + case .Texture2D; { + type.kind = Field_Kind.Texture2D; + + field.resource_index = variable.resource_index; + } + case .Sampler; { + type.kind = Field_Kind.Sampler; + + field.resource_index = variable.resource_index; + } + case .Struct; { + type.kind = Field_Kind.Struct; + + find_result := find_symbol(ctx.scope_stack, variable.typename, xx 1); + assert(find_result != null, "Internal compiler error\n"); + + type_var := from_handle(ctx.type_variables, find_result.type_variable); + + for i : 0..type_var.children.count - 1 { + child := type_var.children[i]; + child_field := type_variable_to_field(ctx, child); + array_add(*type.children, child_field); + } + + type.name = variable.typename; + } + } + + for hint : variable.source_node.hint_tokens { + field_hint : Field_Hint; + + if lookup_hint(hint.ident_value) == .Position { + field_hint.kind = .Position; + } else if lookup_hint(hint.ident_value) == .UV { + field_hint.kind = .UV; + } else if lookup_hint(hint.ident_value) == .Target { + index_str : string; + index_str.data = *hint.ident_value.data[7]; + index_str.count = 1; + + result, ok, remainder := string_to_int(index_str); + if ok { + field_hint.target_index = result; + } + field_hint.kind = .Target; + } else { + field_hint.custom_hint_name = hint.ident_value; + field_hint.kind = .Custom; + } + array_add(*field.hints, field_hint); + } + + field.type = type; + + return field; +} + +type_variable_to_field :: (ctx : *Compiler_Context, variable : Type_Variable_Handle) -> Field { + return type_variable_to_field(ctx, from_handle(ctx.type_variables, variable)); +} + +generate_buffer :: (ctx : *Compiler_Context, type_handle : Type_Variable_Handle, buffers : *Static_Array) { + variable := from_handle(ctx.type_variables, type_handle); + + buffer := array_add(buffers); + + if variable.type == { + case .CBuffer; { + buffer.kind = .Constant; + } + case .Buffer; { + buffer.kind = .Structured; + } + } + buffer.name = variable.name; + + for i : 0..variable.children.count - 1 { + child := variable.children[i]; + field : Field = type_variable_to_field(ctx, from_handle(ctx.type_variables, child)); + array_add(*buffer.fields, field); + } + + buffer.buffer_index = variable.resource_index; + + for hint : variable.source_node.hint_tokens { + field_hint : Field_Hint; + field_hint.custom_hint_name = hint.ident_value; + field_hint.kind = .Custom; + array_add(*buffer.hints, field_hint); + } +} + +generate_output_data :: (ctx : *Compiler_Context) { + if ctx.had_error { + return; + } + + if ctx.vertex_entry_point.node { + ctx.vertex_entry_point.name = ctx.vertex_entry_point.node.name; + + type_variable := from_handle(ctx.type_variables, ctx.vertex_entry_point.node.type_variable); + assert(type_variable.type == .Function); + + node := type_variable.source_node; + if node.children.count > 0 { + if node.children[0].kind == .FieldList { + field_list := node.children[0]; + for child : field_list.children { + tv := from_handle(ctx.type_variables, child.type_variable); + field := type_variable_to_field(ctx, tv); + array_add(*ctx.vertex_entry_point.input, field); + } + } + } + } + + for buffer_variable : ctx.typed_buffers { + generate_buffer(ctx, buffer_variable, *ctx.buffers); + } + + if ctx.pixel_entry_point.node { + ctx.pixel_entry_point.name = ctx.pixel_entry_point.node.name; + + type_variable := from_handle(ctx.type_variables, ctx.pixel_entry_point.node.type_variable); + assert(type_variable.type == .Function); + + if type_variable.return_type_variable > 0 { + field := type_variable_to_field(ctx, type_variable.return_type_variable); + for hint : type_variable.source_node.hint_tokens { + field_hint : Field_Hint; + + if lookup_hint(hint.ident_value) == .Position { + field_hint.kind = .Position; + } else if lookup_hint(hint.ident_value) == .Target { + index_str : string; + index_str.data = *hint.ident_value.data[7]; + index_str.count = 1; + + result, ok, remainder := string_to_int(index_str); + if ok { + field_hint.target_index = result; + } + field_hint.kind = .Target; + } else { + // @Incomplete(nb): custom hints + } + array_add(*field.hints, field_hint); + } + ctx.pixel_entry_point.return_value = field; + } + } +} + +compile_file :: (ctx : *Compiler_Context, path : string, allocator : Allocator = temp) { + new_context := context; + new_context.allocator = allocator; + push_context new_context { + init_context_allocators(); + defer clear_context_allocators(); + + ctx.file = make_file(ctx, path); + + lex(ctx, allocator); + parse(ctx, allocator); + check(ctx, allocator); + codegen(ctx, allocator); + generate_output_data(ctx); + } +} diff --git a/parsing.jai b/parsing.jai new file mode 100644 index 0000000..21a0188 --- /dev/null +++ b/parsing.jai @@ -0,0 +1,1493 @@ +//////////////////////////// +//@nb - Parse_state state +Parse_State :: struct { + current : *Token; + previous : *Token; + + current_token_index : int; + + ctx : *Compiler_Context; +} + +//////////////////////////// +//@nb - Parsing helper types +Separator_Type :: enum { + Comma; + Semicolon; +} + +Entry_Point_Type :: enum { + None; + Vertex; + Pixel; +} + +//////////////////////////// +//@nb - Expression parsing +Precedence :: enum { + PREC_NONE; + PREC_ASSIGNMENT; // = + PREC_OR; // || + PREC_AND; // && + PREC_BITWISE; // | & ^ + PREC_EQUALITY; // == != + PREC_COMPARISON; // < > <= >= + PREC_TERM; // + - + PREC_FACTOR; // * / + PREC_UNARY; // ! - + PREC_CALL; // . () + PREC_PRIMARY; +} + +Parse_Fn :: #type (parse_state: *Parse_State, left : *AST_Node) -> *AST_Node; +Parse_Rule :: struct { + prefix : Parse_Fn; + infix : Parse_Fn; + precedence : Precedence; +} + +parse_rules :: #run -> [(cast(int)Token_Kind.TOKEN_ERROR) + 1]Parse_Rule { + rules : [(cast(int)Token_Kind.TOKEN_ERROR) + 1]Parse_Rule; + rules[Token_Kind.TOKEN_LEFTPAREN] = .{grouping, call, .PREC_CALL}; + rules[Token_Kind.TOKEN_RIGHTPAREN] = .{null, null, .PREC_NONE}; + rules[Token_Kind.TOKEN_LEFTBRACE] = .{null, null, .PREC_NONE}; + rules[Token_Kind.TOKEN_RIGHTBRACE] = .{null, null, .PREC_NONE}; + rules[Token_Kind.TOKEN_LEFTBRACKET] = .{null, array_access, .PREC_CALL}; + rules[Token_Kind.TOKEN_RIGHTBRACKET] = .{null, null, .PREC_NONE}; + rules[Token_Kind.TOKEN_COMMA] = .{null, null, .PREC_NONE}; + rules[Token_Kind.TOKEN_DOT] = .{null, dot, .PREC_CALL}; + // rules[Token_Kind.TOKEN_PROPERTIES] = .{named_variable, null, .PREC_CALL}; + rules[Token_Kind.TOKEN_MINUS] = .{unary, binary, .PREC_TERM}; + rules[Token_Kind.TOKEN_PLUS] = .{null, binary, .PREC_TERM}; + rules[Token_Kind.TOKEN_SEMICOLON] = .{null, null, .PREC_NONE}; + rules[Token_Kind.TOKEN_SLASH] = .{null, binary, .PREC_FACTOR}; + rules[Token_Kind.TOKEN_STAR] = .{null, binary, .PREC_FACTOR}; + rules[Token_Kind.TOKEN_ISNOTEQUAL] = .{null, binary, .PREC_COMPARISON}; + rules[Token_Kind.TOKEN_ASSIGN] = .{null, binary, .PREC_COMPARISON}; + rules[Token_Kind.TOKEN_MINUSEQUALS] = .{null, binary, .PREC_COMPARISON}; + rules[Token_Kind.TOKEN_PLUSEQUALS] = .{null, binary, .PREC_COMPARISON}; + rules[Token_Kind.TOKEN_DIVEQUALS] = .{null, binary, .PREC_COMPARISON}; + rules[Token_Kind.TOKEN_TIMESEQUALS] = .{null, binary, .PREC_COMPARISON}; + rules[Token_Kind.TOKEN_MODEQUALS] = .{null, binary, .PREC_COMPARISON}; + rules[Token_Kind.TOKEN_ISEQUAL] = .{null, binary, .PREC_EQUALITY}; + rules[Token_Kind.TOKEN_GREATER] = .{null, binary, .PREC_COMPARISON}; + rules[Token_Kind.TOKEN_GREATEREQUALS] = .{null, binary, .PREC_COMPARISON}; + rules[Token_Kind.TOKEN_LESS] = .{null, binary, .PREC_COMPARISON}; + rules[Token_Kind.TOKEN_LESSEQUALS] = .{null, binary, .PREC_COMPARISON}; + rules[Token_Kind.TOKEN_IDENTIFIER] = .{named_variable, null, .PREC_NONE}; + rules[Token_Kind.TOKEN_INTLITERAL] = .{integer, null, .PREC_NONE}; + rules[Token_Kind.TOKEN_FLOATLITERAL] = .{floating, null, .PREC_NONE}; + rules[Token_Kind.TOKEN_ELSE] = .{null, null, .PREC_NONE}; + rules[Token_Kind.TOKEN_FALSE] = .{null, null, .PREC_NONE}; + rules[Token_Kind.TOKEN_FOR] = .{null, null, .PREC_NONE}; + rules[Token_Kind.TOKEN_IF] = .{null, null, .PREC_NONE}; + rules[Token_Kind.TOKEN_LOGICALOR] = .{null, binary, .PREC_OR}; + rules[Token_Kind.TOKEN_LOGICALAND] = .{null, binary, .PREC_AND}; + rules[Token_Kind.TOKEN_RETURN] = .{null, null, .PREC_NONE}; + rules[Token_Kind.TOKEN_TRUE] = .{null, null, .PREC_NONE}; + rules[Token_Kind.TOKEN_WHILE] = .{null, null, .PREC_NONE}; + rules[Token_Kind.TOKEN_ERROR] = .{null, null, .PREC_NONE}; + rules[Token_Kind.TOKEN_EOF] = .{null, null, .PREC_NONE}; + + return rules; +} + +//////////////////////////// +//@nb - Error handling functions + +//nb - Record an error and report it immediately to the user. +record_error :: (parse_state : *Parse_State, token : Token, message : string, report_source_location : bool = true) { + error : Compiler_Message; + error.message_kind = .Error; + error.message = message; + error.path = parse_state.ctx.file.path; + + source_location : Source_Range; + source_location.begin = token; + source_location.begin.column = 0; + source_location.begin.source = source_location.begin.source - source_location.begin.column; + source_location.main_token = token; + + snap := snapshot_state(parse_state); + advance_to_sync_point(parse_state); + error.report_source_location = report_source_location; + + source_location.end = parse_state.current; + array_add(*error.source_locations, source_location); + + parse_state.ctx.had_error = true; + array_add(*parse_state.ctx.messages, error); + + rewind_to_snapshot(parse_state, snap); +} + +generate_source_location_from_token :: (state : *Parse_State, token : Token) -> Source_Range { + location : Source_Range; + begin : Token = token; + begin.index -= begin.column; + begin.length += begin.column; + begin.source -= begin.column; + begin.column = 0; + + location.begin = begin; + location.main_token = token; + + snapshot := snapshot_state(state); + advance_to_sync_point(state); + + location.end = state.current; + + rewind_to_snapshot(state, snapshot); + + return location; +} + +unexpected_token :: (state : *Parse_State, token : Token, message : string) { + /* + +*/ + sc := get_scratch(); + defer scratch_end(sc); + builder : String_Builder; + init_string_builder(*builder,, sc.allocator); + + print_to_builder(*builder, "%\n\n", message); + + location : Source_Range; + location.begin = token; + location.begin.index -= location.begin.column; + location.begin.source -= location.begin.column; + location.begin.length += location.begin.column; + location.begin.column = 0; + + location.main_token = token; + location.end = token; + + // advance(state); + + indent(*builder, 1); + cyan(*builder); + print_to_builder(*builder, "%\n", print_from_source_location(state.ctx, location)); + + indent(*builder, 1); + print_token_pointer(*builder, token); + + final_message := builder_to_string(*builder,, context.allocator); + record_error(state, token, final_message, false); +} + +else_if_without_if :: (state : *Parse_State) { + builder : String_Builder; + init_string_builder(*builder,, temp); + + append(*builder, "'else if' without 'if'\n"); + + token := state.previous; + + location : Source_Range = generate_source_location_from_token(state, token); + + indent(*builder, 1); + cyan(*builder); + print_to_builder(*builder, "%\n", print_from_source_location(state.ctx, location)); + + indent(*builder, 1); + print_token_pointer(*builder, token); + white(*builder); + + final_message := builder_to_string(*builder); + record_error(state, token, final_message, false); +} + +else_without_if :: (state : *Parse_State) { + builder : String_Builder; + init_string_builder(*builder,, temp); + + append(*builder, "'else' without 'if'\n"); + + token := state.previous; + + location : Source_Range = generate_source_location_from_token(state, token); + + indent(*builder, 1); + cyan(*builder); + print_to_builder(*builder, "%\n", print_from_source_location(state.ctx, location)); + + indent(*builder, 1); + print_token_pointer(*builder, token); + white(*builder); + + final_message := builder_to_string(*builder); + record_error(state, token, final_message, false); +} + +unable_to_parse_statement :: (state : *Parse_State, token : Token, message : string = "") { + builder : String_Builder; + init_string_builder(*builder,, temp); + + print_to_builder(*builder, "Unable to parse statement here. %\n", message); + + location : Source_Range = generate_source_location_from_token(state, token); + + indent(*builder, 1); + cyan(*builder); + print_to_builder(*builder, "%\n", print_from_source_location(state.ctx, location)); + + + indent(*builder, 1); + print_token_pointer(*builder, token); + + final_message := builder_to_string(*builder); + record_error(state, token, final_message, false); +} + +expected_expression :: (state : *Parse_State, token : Token, message : string) { + builder : String_Builder; + init_string_builder(*builder,, temp); + + print_to_builder(*builder, "%\n", message); + + location : Source_Range = generate_source_location_from_token(state, token); + + indent(*builder, 1); + cyan(*builder); + print_to_builder(*builder, "%\n", print_from_source_location(state.ctx, location)); + + indent(*builder, 1); + print_token_pointer(*builder, token); + + final_message := builder_to_string(*builder); + record_error(state, token, final_message, false); +} + +missing_type_specifier :: (state : *Parse_State, token : Token, message : string) { + builder : String_Builder; + init_string_builder(*builder,, temp); + + print_to_builder(*builder, "%\n", message); + + location := generate_source_location_from_token(state, token); + + indent(*builder, 1); + cyan(*builder); + print_to_builder(*builder, "%\n", print_from_source_location(state.ctx, location)); + indent(*builder, 1); + + loc := location.begin; + increment := location.begin.length + 2; + loc.source += increment; + loc.index += increment; + loc.column += increment; + print_token_pointer(*builder, loc); + + final_message := builder_to_string(*builder); + record_error(state, token, final_message, false); +} + +empty_block :: (state : *Parse_State, token : Token, message : string) { + builder : String_Builder; + init_string_builder(*builder,, temp); + + print_to_builder(*builder, "%\n", message); + + location := generate_source_location_from_token(state, token); + + indent(*builder, 1); + cyan(*builder); + print_to_builder(*builder, "%\n", print_from_source_location(state.ctx, location)); + indent(*builder, 1); + + loc := location.begin; + // increment := location.begin.length + 2; + // loc.source += increment; + // loc.index += increment; + // loc.column += increment; + print_token_pointer(*builder, loc); + + final_message := builder_to_string(*builder); + record_error(state, token, final_message, false); +} + +unable_to_open_file :: (state : *Parse_State, path : string, token : Token) { + builder : String_Builder; + init_string_builder(*builder,, temp); + + print_to_builder(*builder, "Unable to open file '%' for reading\n\n", path); + + location := generate_source_location_from_token(state, token); + + indent(*builder, 1); + cyan(*builder); + print_to_builder(*builder, "%\n", print_from_source_location(state.ctx, location)); + indent(*builder, 1); + + loc := location.begin; + print_token_pointer(*builder, loc); + + final_message := builder_to_string(*builder); + record_error(state, token, final_message, false); +} + +entry_point_requires_return_value :: (state : *Parse_State, token : Token) { + builder : String_Builder; + init_string_builder(*builder,, temp); + + print_to_builder(*builder, "Entry point '%' requires return value\n\n", token.ident_value); + + location := generate_source_location_from_token(state, token); + indent(*builder, 1); + cyan(*builder); + print_to_builder(*builder, "%\n", print_from_source_location(state.ctx, location)); + indent(*builder, 1); + + loc := location.begin; + print_token_pointer(*builder, loc); + + final_message := builder_to_string(*builder); + record_error(state, token, final_message, false); +} + +error_node :: (parse_state : *Parse_State, message : string) -> *AST_Node { + node := make_node(parse_state, .Error); + node.name = copy_string(message); + + return node; +} + +//nb - Advance to the next sync point. +// A sync point is the next token that ends a statement or starts/ends a block. +advance_to_sync_point :: (parse_state : *Parse_State) { + while true { + if parse_state.current.kind == .TOKEN_SEMICOLON || parse_state.current.kind == .TOKEN_RIGHTBRACE || + parse_state.current.kind == .TOKEN_LEFTBRACE || parse_state.current.kind == .TOKEN_EOF { + break; + } + advance(parse_state); + } +} +//////////////////////////// + + +//////////////////////////// +//@nb - Base parsing functions + +make_node :: (nodes : *[..]AST_Node, kind : AST_Kind) -> *AST_Node { + node : AST_Node; + + node.kind = kind; + array_add(nodes, node); + + return *(nodes.*[nodes.count - 1]); +} + +make_node :: (parse_state : *Parse_State, kind : AST_Kind) -> *AST_Node { + return make_node(*parse_state.ctx.nodes, kind); +} + +make_builtin_token :: (tokens : *[..]Token, kind : Token_Kind, text : string, col : *int, line : *int) -> *Token { + tok : Token; + tok.kind = kind; + + start := 0; + + tok.column = col.*; + + for c : text { + if c == #char "\n" { + line.* ++ 1; + col.* = 0; + } else { + col.* += 1; + } + } + + tok.index = tokens.count; + tok.length = text.count; + tok.builtin = true; + tok.source = text.data; + tok.ident_value = text; + + array_add(tokens, tok); + + return *(tokens.*)[tokens.count - 1]; +} + +new_builtin_struct_node :: (ctx : *Compiler_Context, name : string, members : []Arg) -> *AST_Node { + sc := get_scratch(context.allocator); + defer scratch_end(sc); + node := make_node(*ctx.nodes, .Struct); + + source_location : Source_Range; + + col := 0; + line := 0; + + tok_index := ctx.tokens.count; + + ident_token := make_builtin_token(*ctx.tokens, .TOKEN_IDENTIFIER, name, *col, *line); + ident_token.ident_value = name; + source_location.begin = ident_token; + + make_builtin_token(*ctx.tokens, .TOKEN_DOUBLECOLON, " :: ", *col, *line); + make_builtin_token(*ctx.tokens, .TOKEN_STRUCT, "struct ", *col, *line); + make_builtin_token(*ctx.tokens, .TOKEN_LEFTBRACE, "{\n\t", *col, *line); + line += 1; + col = 0; + + field_list := make_node(*ctx.nodes, .FieldList); + add_child(node, field_list); + + for member : members { + field := make_node(*ctx.nodes, .Field); + field_source_loc : Source_Range; + + field_ident := make_builtin_token(*ctx.tokens, .TOKEN_IDENTIFIER, member.name, *col, *line); + field_source_loc.begin = field_ident; + field.token = field_ident; + field.name = member.name; + + make_builtin_token(*ctx.tokens, .TOKEN_COLON, ": ", *col, *line); + make_builtin_token(*ctx.tokens, .TOKEN_IDENTIFIER, member.typename, *col, *line); + semicolon_tok := make_builtin_token(*ctx.tokens, .TOKEN_SEMICOLON, ";", *col, *line); + col = 0; + line += 1; + + field_source_loc.end = semicolon_tok; + field.source_location = field_source_loc; + + add_child(field_list, field); + } + + brace_token := make_builtin_token(*ctx.tokens, .TOKEN_RIGHTBRACE, "\n}", *col, *line); + + source_location.end = brace_token; + + node.source_location = source_location; + + return node; +} + +new_builtin_function_node :: (ctx : *Compiler_Context, name : string, members : []Arg, return_var : Arg) -> *AST_Node { + sc := get_scratch(context.allocator); + defer scratch_end(sc); + + node := make_node(*ctx.nodes, .Function); + + source_location : Source_Range; + + col := 0; + line := 0; + + tok_index := ctx.tokens.count; + + ident_token := make_builtin_token(*ctx.tokens, .TOKEN_IDENTIFIER, name, *col, *line); + source_location.begin = ident_token; + + make_builtin_token(*ctx.tokens, .TOKEN_DOUBLECOLON, " :: ", *col, *line); + make_builtin_token(*ctx.tokens, .TOKEN_LEFTPAREN, "(", *col, *line); + field_list := make_node(*ctx.nodes, .FieldList); + add_child(node, field_list); + + for member : members { + field := make_node(*ctx.nodes, .Field); + field_source_loc : Source_Range; + + type_tok := make_builtin_token(*ctx.tokens, .TOKEN_IDENTIFIER, member.typename, *col, *line); + field_source_loc.begin = type_tok; + field.token = type_tok; + + if it_index < members.count - 1 { + make_builtin_token(*ctx.tokens, .TOKEN_COMMA, ", ", *col, *line); + } + + field_source_loc.end = type_tok; + field.source_location = field_source_loc; + + add_child(field_list, field); + } + + make_builtin_token(*ctx.tokens, .TOKEN_RIGHTPAREN, ")", *col, *line); + semicolon_tok := make_builtin_token(*ctx.tokens, .TOKEN_SEMICOLON, ";", *col, *line); + + source_location.end = semicolon_tok; + + node.source_location = source_location; + + return node; +} + +get_field_list :: (struct_or_func : *AST_Node) -> *AST_Node { + assert(struct_or_func.kind == .Function || struct_or_func.kind == .Struct || struct_or_func.kind == .CBuffer); + return struct_or_func.children[0]; +} + +add_child :: (node : *AST_Node, child : *AST_Node) { + child.parent = node; + array_add(*node.children, child); +} + +Sync_Snapshot :: struct { + current : *Token; + previous : *Token; + current_token_index : int; +} + +snapshot_state :: (parse_state : *Parse_State) -> Sync_Snapshot { + snapshot : Sync_Snapshot; + snapshot.current = parse_state.current; + snapshot.previous = parse_state.previous; + snapshot.current_token_index = parse_state.current_token_index; + + return snapshot; +} + +rewind_to_snapshot :: (parse_state : *Parse_State, snapshot : Sync_Snapshot) { + parse_state.current = snapshot.current; + parse_state.previous = snapshot.previous; + parse_state.current_token_index = snapshot.current_token_index; +} + +advance :: (parse_state : *Parse_State) { + parse_state.previous = parse_state.current; + + while true { + if parse_state.current_token_index >= parse_state.ctx.tokens.count { + break; + } + parse_state.current = *parse_state.ctx.tokens[parse_state.current_token_index]; + parse_state.current_token_index += 1; + if parse_state.current.kind != .TOKEN_ERROR break; + + err := tprint("unknown token \x1b[1;37m'%'\x1b[0m", parse_state.current.string_value); + unexpected_token(parse_state, parse_state.current, err); + return; + } +} + +//nb - Checks if the current token is of a certain kind and advances if it is +match :: (parse_state : *Parse_State, kind : Token_Kind) -> bool { + if !check(parse_state, kind) return false; + advance(parse_state); + return true; +} + +//nb - Checks if the current token is of a certain kind +check :: (parse_state : *Parse_State, kind : Token_Kind) -> bool { + return parse_state.current.kind == kind; +} + +check_any :: (parse_state : *Parse_State, kinds : ..Token_Kind) -> bool { + for kind : kinds { + if check(parse_state, kind) { + return true; + } + } + return false; +} + +//nb - Checks if the next token is of a certain kind +check_next :: (parse_state : *Parse_State, kind : Token_Kind) -> bool { + return parse_state.ctx.tokens[parse_state.current_token_index].kind == kind; +} + +//nb - Consume a token if +consume :: (parse_state : *Parse_State, kind : Token_Kind, message : string) { + if parse_state.current.kind == kind { + advance(parse_state); + return; + } + + token := parse_state.previous; + advance_to_sync_point(parse_state); + + unexpected_token(parse_state, token, message); + + if parse_state.current.kind == .TOKEN_EOF { + return; + } +} + +//////////////////////////// +//@nb - Expression parsing +get_rule :: (kind : Token_Kind) -> *Parse_Rule { + return *parse_rules[kind]; +} + +precedence :: (parse_state : *Parse_State, precedence : Precedence, message : string = "") -> *AST_Node { + prev := parse_state.previous; + advance(parse_state); + + prefix_rule := get_rule(parse_state.previous.kind).prefix; + if prefix_rule == null { + tok_s : string; + tok_s.data = prev.source; + tok_s.count = prev.length; + if message { + expected_expression(parse_state, prev, tprint("Expected expression after '%'. %", tok_s, message)); + } else { + expected_expression(parse_state, prev, tprint("Expected expression after '%'.", tok_s)); + } + + return error_node(parse_state, "Expected expression."); + } + + left := prefix_rule(parse_state, null); + + while precedence <= get_rule(parse_state.current.kind).precedence { + advance(parse_state); + if parse_state.current.kind == .TOKEN_EOF { + tok_s : string; + tok_s.data = parse_state.previous.source; + tok_s.count = parse_state.previous.length; + expected_expression(parse_state, parse_state.current, tprint("Reached end of file. Expected expression after '%'.", tok_s)); + // @Incomplete: Add error node here? + return null; + } + infix_rule := get_rule(parse_state.previous.kind).infix; + left = infix_rule(parse_state, left); + } + + return left; +} + +named_variable :: (parse_state : *Parse_State, left : *AST_Node) -> *AST_Node { + if check(parse_state, .TOKEN_LEFTPAREN) { + return call(parse_state, left); + } + + variable := make_node(parse_state, .Variable); + variable.source_location = generate_source_location_from_token(parse_state, parse_state.previous); + + variable.name = parse_state.previous.ident_value; + + return variable; +} + +binary :: (parse_state : *Parse_State, left : *AST_Node) -> *AST_Node { + op := parse_state.previous.*; + rule := get_rule(op.kind); + + source_location := generate_source_location_from_token(parse_state, op); + // source_location : Source_Range; + // source_location.begin = left.source_location.begin; + + binary_expression := make_node(parse_state, .Binary); + + add_child(binary_expression, left); + add_child(binary_expression, precedence(parse_state, rule.precedence + 1)); + + if op.kind == { + case .TOKEN_PLUS; #through; + case .TOKEN_PLUSEQUALS; #through; + case .TOKEN_MINUSEQUALS; #through; + case .TOKEN_TIMESEQUALS; #through; + case .TOKEN_DIVEQUALS; #through; + case .TOKEN_MINUS; #through; + case .TOKEN_STAR; #through; + case .TOKEN_SLASH; #through; + case .TOKEN_ISEQUAL; #through; + case .TOKEN_ASSIGN; #through; + case .TOKEN_ISNOTEQUAL; #through; + case .TOKEN_LOGICALOR; #through; + case .TOKEN_LOGICALAND; #through; + case .TOKEN_LESS; #through; + case .TOKEN_LESSEQUALS; #through; + case .TOKEN_GREATER; #through; + case .TOKEN_GREATEREQUALS; + { + binary_expression.token = op; + } + } + + // source_location.end = parse_state.previous; + binary_expression.source_location = source_location; + + return binary_expression; +} + +array_access :: (parse_state : *Parse_State, left : *AST_Node) -> *AST_Node { + identifier := parse_state.ctx.tokens[parse_state.current_token_index - 3]; + left_bracket := parse_state.ctx.tokens[parse_state.current_token_index - 2]; + + array_access := make_node(parse_state, .Binary); + array_access.token = left_bracket; + array_index := expression(parse_state); + add_child(array_access, left); + add_child(array_access, array_index); + + consume(parse_state, .TOKEN_RIGHTBRACKET, "Expected ']' after array index."); + + source_location : Source_Range; + source_location.begin = left.source_location.begin; + + if check(parse_state, .TOKEN_ASSIGN) { + advance(parse_state); + + node := make_node(parse_state, .Binary); + node.token = parse_state.previous; + add_child(node, left); + add_child(node, expression(parse_state)); + return node; + } + + source_location.end = parse_state.previous; + array_access.source_location = source_location; + return array_access; +} + +unary :: (parse_state : *Parse_State, left : *AST_Node) -> *AST_Node { + op := parse_state.previous.*; + rule := get_rule(op.kind); + + unary_expression := make_node(parse_state, .Unary); + + add_child(unary_expression, precedence(parse_state, rule.precedence + 1)); + + if op.kind == { + case .TOKEN_MINUS; { + unary_expression.token = op; + } + case .TOKEN_LEFTBRACKET; { + unary_expression.token = op; + consume(parse_state, .TOKEN_RIGHTBRACKET, "Expect ']' after array access."); + } + } + + return unary_expression; +} + +grouping :: (parse_state : *Parse_State, left : *AST_Node) -> *AST_Node { + grouping := expression(parse_state); + consume(parse_state, .TOKEN_RIGHTPAREN, "Expect ')' after group expression."); + return grouping; +} + +directive :: (state : *Parse_State) -> *AST_Node { + if state.current.ident_value == "foreign" { + advance(state); + identifier_token := state.current; + advance(state); + consume(state, .TOKEN_DOUBLECOLON, "Expect '::' after function name."); + func := function_declaration(state, identifier_token, .None, false, false); + func.foreign_declaration = true; + return func; + } else if state.current.ident_value == "if" { + if_directive := make_node(state, .If_Directive); + + source_location : Source_Range; + if state.previous { + source_location.begin = state.previous; + } else { + source_location.begin = state.current; + } + + advance(state); + + cond := expression(state); + add_child(if_directive, cond); + + source_location.end = state.previous; + advance_to_sync_point(state); + + if_body := block(state); + add_child(if_directive, if_body); + + if match(state, .TOKEN_ELSE) { + else_node := else_statement(state); + add_child(if_directive, else_node); + } + + if_directive.source_location = source_location; + + return if_directive; + } + + return null; +} + +call :: (parse_state : *Parse_State, left : *AST_Node) -> *AST_Node { + call := make_node(parse_state, .Call); + source_location := generate_source_location_from_token(parse_state, parse_state.previous); + // source_location : Source_Range; + // source_location.begin = parse_state.previous; + // source_location.main_token = parse_state.previous; + + prev := parse_state.previous; + call.name = prev.ident_value; + advance(parse_state); + arg_list := argument_list(parse_state); + if arg_list { + add_child(call, arg_list); + } + + snapshot := snapshot_state(parse_state); + + advance_to_sync_point(parse_state); + source_location.end = parse_state.current; + + rewind_to_snapshot(parse_state, snapshot); + call.source_location = source_location; + + return call; +} + +dot :: (parse_state : *Parse_State, left : *AST_Node) -> *AST_Node { + consume(parse_state, .TOKEN_IDENTIFIER, "Expect property name after '.'."); + identifier := parse_state.previous; + + source_location : Source_Range; + source_location.begin = left.source_location.begin; + source_location.main_token = identifier; + + access := make_node(parse_state, .Access); + + variable := make_node(parse_state, .Variable); + variable.name = identifier.ident_value; + + add_child(access, left); + add_child(access, variable); + + 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; + node.source_location = generate_source_location_from_token(parse_state, node.token); + 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 { + value := parse_state.previous.integer_value; + node := make_node(parse_state, .Integer); + node.source_location.begin = parse_state.previous; + node.source_location.end = parse_state.previous; + node.source_location.main_token = parse_state.previous; + node.integer_value = value; + return node; +} + +floating :: (parse_state : *Parse_State, left : *AST_Node) -> *AST_Node { + value := parse_state.previous.float_value; + node := make_node(parse_state, .Float); + node.source_location.begin = parse_state.previous; + node.source_location.end = parse_state.previous; + node.source_location.main_token = parse_state.previous; + node.float_value = value; + return node; +} + +expression :: (parse_state : *Parse_State, message : string = "") -> *AST_Node { + expression := precedence(parse_state, .PREC_ASSIGNMENT, message); + return expression; +} + +//////////////////////////// +//@nb - Statement parsing functions + +field_assignment :: (parse_state : *Parse_State, identifier_token : *Token) -> *AST_Node { + node : *AST_Node = make_node(parse_state, .Field); + + identifier := identifier_token.*; + source_location : Source_Range; + source_location.begin = identifier; + + source_location.main_token = identifier; + node.name = identifier.string_value; + + add_child(node, expression(parse_state)); + + source_location.end = parse_state.previous; + node.source_location = source_location; + + return node; +} + +//nb - Non-const field declarations +field_declaration :: (parse_state : *Parse_State, identifier_token : *Token) -> *AST_Node { + node : *AST_Node = make_node(parse_state, .Field); + + identifier := identifier_token.*; + source_location : Source_Range; + source_location.begin = identifier; + + source_location.main_token = identifier; + node.name = identifier.string_value; + + consume(parse_state, .TOKEN_COLON, "Expected ':' after field name for declarations."); + + if check(parse_state, .TOKEN_IDENTIFIER) { + type_identifier := parse_state.current; + node.token = type_identifier; + advance(parse_state); + } else if check(parse_state, .TOKEN_LEFTBRACKET) { + advance(parse_state); + array_size_expression := expression(parse_state); + add_child(node, array_size_expression); + consume(parse_state, .TOKEN_RIGHTBRACKET, "Expected closing ']' in array declaration."); + consume(parse_state, .TOKEN_DOT, "Expected '.' before array type."); + + type_identifier := parse_state.current; + node.token = type_identifier; + advance(parse_state); + node.array_field = true; + } else { + if !check(parse_state, .TOKEN_ASSIGN) { + internal_error_message(*parse_state.ctx.messages, "Unimplemented error message.", parse_state.ctx.file.path); + return node; + } + // missing_type_specifier(parse_state, identifier_token, "Expected type specifier after field name."); + + } + + if check(parse_state, .TOKEN_AT) { + while check(parse_state, .TOKEN_AT) { + advance(parse_state); + // @Incomplete(niels): this is a mapping + if check(parse_state, .TOKEN_IDENTIFIER) { + array_add(*node.hint_tokens, parse_state.current); + advance(parse_state); + } else if check(parse_state, .TOKEN_HINT) { + array_add(*node.hint_tokens, parse_state.current); + advance(parse_state); + } else if check(parse_state, .TOKEN_OPTIONAL) { + array_add(*node.hint_tokens, parse_state.current); + advance(parse_state); + } + } + } else if match(parse_state, .TOKEN_ASSIGN) { + add_child(node, expression(parse_state)); + } + + source_location.end = parse_state.previous; + node.source_location = source_location; + + return node; +} + +argument_list :: (parse_state : *Parse_State) -> *AST_Node { + node : *AST_Node; + + source_location : Source_Range; + source_location.begin = parse_state.previous; + source_location.begin.index -= source_location.begin.column; + source_location.begin.source -= source_location.begin.column; + source_location.begin.length += source_location.begin.column; + source_location.begin.column = 0; + + source_location.main_token = parse_state.current; + + error_before := parse_state.ctx.had_error; + parse_state.ctx.had_error = false; + + while !check(parse_state, .TOKEN_RIGHTPAREN) { + arg := expression(parse_state); + if !node { + node = make_node(parse_state, .ArgList); + } + + add_child(node, arg); + + if check(parse_state, .TOKEN_RIGHTPAREN) break; + consume(parse_state, .TOKEN_COMMA, "Expect ',' after function argument."); + + if parse_state.ctx.had_error { + break; + } + } + + parse_state.ctx.had_error = error_before || parse_state.ctx.had_error; + + consume(parse_state, .TOKEN_RIGHTPAREN, "Expect ')' after function call."); + + if node { + snapshot := snapshot_state(parse_state); + + advance_to_sync_point(parse_state); + source_location.end = parse_state.current; + + rewind_to_snapshot(parse_state, snapshot); + node.source_location = source_location; + } + + return node; +} + +expression_statement :: (parse_state : *Parse_State) -> *AST_Node { + node := make_node(parse_state, .Expression_Statement); + + source_location : Source_Range; + source_location.begin = parse_state.current; + + expr := expression(parse_state); + add_child(node, expr); + consume(parse_state, .TOKEN_SEMICOLON, "Expect ';' after expression."); + while parse_state.current.kind == .TOKEN_SEMICOLON { + advance(parse_state); + } + source_location.end = parse_state.previous; + + node.source_location = source_location; + return node; +} + +statement :: (parse_state : *Parse_State) -> *AST_Node { + if match(parse_state, .TOKEN_RETURN) { + node := make_node(parse_state, .Return); + + source_location : Source_Range; + source_location.begin = parse_state.previous; + + return_expression := expression(parse_state); + consume(parse_state, .TOKEN_SEMICOLON, "Expect ';' after return statement."); + while parse_state.current.kind == .TOKEN_SEMICOLON { + advance(parse_state); + } + + if return_expression { + add_child(node, return_expression); + } + source_location.end = parse_state.previous; + node.source_location = source_location; + return node; + } else if match(parse_state, .TOKEN_IF) { + node := make_node(parse_state, .If); + + source_location : Source_Range; + source_location.begin = parse_state.previous; + + if_cond := expression(parse_state, "Expected if condition."); + add_child(node, if_cond); + source_location.end = parse_state.previous; + advance_to_sync_point(parse_state); + + if_body := block(parse_state); + add_child(node, if_body); + + if match(parse_state, .TOKEN_ELSE) { + else_node := else_statement(parse_state); + add_child(node, else_node); + } + + node.source_location = source_location; + + return node; + } else if match(parse_state, .TOKEN_ELSE) { + if check(parse_state, .TOKEN_IF) { + else_if_without_if(parse_state); + advance_to_sync_point(parse_state); + if check(parse_state, .TOKEN_LEFTBRACE) { + return block(parse_state); + } + return error_node(parse_state, "'else if' without 'if'."); + } else { + else_without_if(parse_state); + advance_to_sync_point(parse_state); + if check(parse_state, .TOKEN_LEFTBRACE) { + return block(parse_state); + } + + return error_node(parse_state, "'else' without 'if'."); + } + } else if match(parse_state, .TOKEN_FOR) { + if check(parse_state, .TOKEN_IDENTIFIER) { + node := make_node(parse_state, .For); + + source_location : Source_Range; + source_location.begin = parse_state.previous; + + loop_iterator := parse_state.current; + node.token = loop_iterator; + advance(parse_state); + consume(parse_state, .TOKEN_COLON, "Expect ':' after for loop iterator."); + + snap := snapshot_state(parse_state); + + begin_iter := expression(parse_state, "Expected beginning of iterator."); + if begin_iter.kind == .Error { + unable_to_parse_statement(parse_state, source_location.begin); + rewind_to_snapshot(parse_state, snap); + if parse_state.current.kind == .TOKEN_LEFTBRACE { + block(parse_state); + } + return error_node(parse_state, "'for' without well-formed iterator expression."); + } + add_child(node, begin_iter); + + consume(parse_state, .TOKEN_DOTDOT, "Expect '..' after for loop iter left hand side."); + + snap = snapshot_state(parse_state); + end_iter := expression(parse_state, "Expected end of iterator."); + if end_iter.kind == .Error { + unable_to_parse_statement(parse_state, source_location.begin); + rewind_to_snapshot(parse_state, snap); + + if parse_state.current.kind == .TOKEN_LEFTBRACE { + + block(parse_state); + } + return error_node(parse_state, "'for' without well-formed iterator expression."); + } + add_child(node, end_iter); + + if check(parse_state, .TOKEN_LEFTBRACE) { + for_body := block(parse_state); + add_child(node, for_body); + } else { + unable_to_parse_statement(parse_state, source_location.begin, "'for' currently expects a brace-enclosed block as a body."); + return error_node(parse_state, "'for' currently expects a brace-enclosed block as a body."); + } + + node.source_location = source_location; + + return node; + } + } else { + return expression_statement(parse_state); + } + + return error_node(parse_state, "Couldn't parse statement."); +} + +else_statement :: (parse_state : *Parse_State) -> *AST_Node { + if check(parse_state, .TOKEN_IF) { + return statement(parse_state); + } else if check(parse_state, .TOKEN_DIRECTIVE) && parse_state.current.ident_value == "if" { + return directive(parse_state); + } + return block(parse_state); +} + +block :: (parse_state : *Parse_State) -> *AST_Node { + node : *AST_Node = make_node(parse_state, .Block); + array_reserve(*node.children, 32); + + source_location : Source_Range; + + consume(parse_state, .TOKEN_LEFTBRACE, "Expect '{' at start of block."); + source_location.begin = parse_state.previous; + + while !check(parse_state, .TOKEN_RIGHTBRACE) && !check(parse_state, .TOKEN_EOF) { + decl := declaration(parse_state); + if decl { + add_child(node, decl); + } + } + consume(parse_state, .TOKEN_RIGHTBRACE, "Expect '}' after block."); + source_location.end = parse_state.previous; + node.source_location = source_location; + + return node; +} + +field_list :: (parse_state : *Parse_State, separator : Separator_Type, require_field_names := true) -> *AST_Node { + node : *AST_Node = make_node(parse_state, .FieldList); + array_reserve(*node.children, 16); + source_location : Source_Range; + source_location.begin = parse_state.previous; + source_location.main_token = parse_state.current; + + while check(parse_state, .TOKEN_IDENTIFIER) { + field : *AST_Node; + identifier := parse_state.current; + advance(parse_state); + if require_field_names || check(parse_state, .TOKEN_COLON) { + field = field_declaration(parse_state, identifier); + } else { + field = make_node(parse_state, .Unnamed_Field); + + source_location : Source_Range; + source_location.begin = identifier; + + source_location.main_token = identifier; + field.name = identifier.ident_value; + field.token = identifier; + } + add_child(node, field); + + + if check(parse_state, .TOKEN_RIGHTPAREN) { + source_location.end = parse_state.current; + node.source_location = source_location; + return node; + } + + if separator == { + case .Comma; { + consume(parse_state, .TOKEN_COMMA, "Expect ',' after field declaration."); + } + case .Semicolon; { + consume(parse_state, .TOKEN_SEMICOLON, "Expect ';' after field declaration."); + } + } + } + + return node; +} + +function_declaration :: (parse_state : *Parse_State, identifier_token : *Token, entry_point_kind : Entry_Point_Type, expect_body : bool = true, require_field_names : bool = true) -> *AST_Node { + node : *AST_Node; + source_location : Source_Range; + + source_location = generate_source_location_from_token(parse_state, identifier_token); + + function_name_token := identifier_token; + + consume(parse_state, .TOKEN_LEFTPAREN, "Expect argument list after '::' in function declaration."); + + function_args := field_list(parse_state, .Comma, require_field_names); + + consume(parse_state, .TOKEN_RIGHTPAREN, "Expect right ')' after function argument list."); + return_type_token : Token; + hint_token : Token; + + if match(parse_state, .TOKEN_ARROW) { + return_type_token = parse_state.current; + advance(parse_state); + if check(parse_state, .TOKEN_AT) { + advance(parse_state); + hint_token = parse_state.current; + advance(parse_state); + } + } + + node = make_node(parse_state, .Function); + add_child(node, function_args); + name := function_name_token.ident_value; + + if entry_point_kind == { + case .Vertex; { + node.vertex_entry_point = true; + name = sprint("vs_%", function_name_token.ident_value); + + // if return_type_token.kind == .TOKEN_INVALID { + // entry_point_requires_return_value(parse_state, function_name_token); + // advance_to_sync_point(parse_state); + // return error_node(parse_state, ""); + // } + } + case .Pixel; { + node.pixel_entry_point = true; + name = sprint("ps_%", function_name_token.ident_value); + + // if return_type_token.kind == .TOKEN_INVALID { + // entry_point_requires_return_value(parse_state, function_name_token); + // advance_to_sync_point(parse_state); + // return error_node(parse_state, ""); + // } + } + } + + node.name = name; + node.token = return_type_token; + array_add(*node.hint_tokens, hint_token); + + if expect_body { + function_body := block(parse_state); + if function_body.children.count > 0 { + add_child(node, function_body); + } + } else { + consume(parse_state, .TOKEN_SEMICOLON, "Expect ';' after a function with no body."); + } + + node.source_location = source_location; + + return node; +} + +buffer :: (state : *Parse_State, identifier_token : *Token = null) -> *AST_Node { + node : *AST_Node = make_node(state, .Buffer); + source_location : Source_Range; + source_location.begin = state.current; + + if check(state, .TOKEN_AT) { + while check(state, .TOKEN_AT) { + advance(state); + // @Incomplete(niels): this is a mapping + if check(state, .TOKEN_IDENTIFIER) { + array_add(*node.hint_tokens, state.current); + advance(state); + } + } + } + + consume(state, .TOKEN_LEFTBRACE, "Expect '{' after 'buffer' keyword"); + buffer := field_list(state, .Semicolon); + node.array_field = true; + + if identifier_token { + node.name = identifier_token.ident_value; + } + add_child(node, buffer); + + consume(state, .TOKEN_RIGHTBRACE, "Expect '}' after 'buffer' block"); + source_location.end = state.previous; + node.source_location = source_location; + + return node; +} + +constant_buffer :: (parse_state : *Parse_State, identifier_token : *Token = null) -> *AST_Node { + node : *AST_Node = make_node(parse_state, .CBuffer); + source_location : Source_Range; + source_location.begin = parse_state.current; + + if check(parse_state, .TOKEN_AT) { + while check(parse_state, .TOKEN_AT) { + advance(parse_state); + // @Incomplete(niels): this is a mapping + if check(parse_state, .TOKEN_IDENTIFIER) { + array_add(*node.hint_tokens, parse_state.current); + advance(parse_state); + } + } + } + + consume(parse_state, .TOKEN_LEFTBRACE, "Expect '{' after 'constant_buffer' keyword"); + buffer := field_list(parse_state, .Semicolon); + + if identifier_token { + node.name = identifier_token.ident_value; + } + add_child(node, buffer); + + consume(parse_state, .TOKEN_RIGHTBRACE, "Expect '}' after 'constant_buffer' block"); + source_location.end = parse_state.previous; + node.source_location = source_location; + + return node; +} + +struct_declaration :: (parse_state : *Parse_State, identifier_token : *Token) -> *AST_Node { + source_location := generate_source_location_from_token(parse_state, identifier_token); + + consume(parse_state, .TOKEN_LEFTBRACE, "Expect '{' before struct declaration."); + + fields := field_list(parse_state, .Semicolon); + + node := make_node(parse_state, .Struct); + node.name = identifier_token.ident_value; + add_child(node, fields); + + consume(parse_state, .TOKEN_RIGHTBRACE, "Expect '}' after struct declaration."); + source_location.end = parse_state.previous; + node.source_location = source_location; + + return node; +} + +access :: (parse_state : *Parse_State, identifier_token : *Token) -> *AST_Node { + err_node := error_node(parse_state, tprint("Accessors not yet implemented. Token: %.", identifier_token.ident_value)); + advance(parse_state); + return err_node; +} + +const_declaration :: (parse_state : *Parse_State, identifier_token : *Token) -> *AST_Node { + if match(parse_state, .TOKEN_STRUCT) { + return struct_declaration(parse_state, identifier_token); + } else if check(parse_state, .TOKEN_LEFTPAREN) { + return function_declaration(parse_state, identifier_token, .None); + } else if match(parse_state, .TOKEN_CONSTANT_BUFFER) { + return constant_buffer(parse_state, identifier_token); + } else if match(parse_state, .TOKEN_BUFFER) { + return buffer(parse_state, identifier_token); + } + return error_node(parse_state, tprint("Couldn't parse constant declaration at token %\n", parse_state.current.*)); +} + +declaration :: (parse_state : *Parse_State) -> *AST_Node { + skip_statement := false; + decl_node : *AST_Node; + if match(parse_state, .TOKEN_VERTEX) { + vertex_token := parse_state.previous; + identifier := parse_state.current; + + advance(parse_state); + consume(parse_state, .TOKEN_DOUBLECOLON, "Expect '::' after vertex entry point declaration."); + + decl_node = function_declaration(parse_state, identifier, .Vertex); + } else if match(parse_state, .TOKEN_PIXEL) { + pixel_token := parse_state.previous; + identifier := parse_state.current; + + advance(parse_state); + consume(parse_state, .TOKEN_DOUBLECOLON, "Expect '::' after pixel entry point declaration."); + + decl_node = function_declaration(parse_state, identifier, .Pixel); + } else if check(parse_state, .TOKEN_DIRECTIVE) { + decl_node = directive(parse_state); + skip_statement = true; + } else if check(parse_state, .TOKEN_IDENTIFIER) { + identifier := parse_state.current; + + if check_next(parse_state, .TOKEN_DOUBLECOLON) { + advance(parse_state); + advance(parse_state); + decl_node = const_declaration(parse_state, identifier); + } else if check_next(parse_state, .TOKEN_LEFTPAREN) { + decl_node = statement(parse_state); + } else if check_next(parse_state, .TOKEN_COLON) { + advance(parse_state); + decl_node = field_declaration(parse_state, identifier); + consume(parse_state, .TOKEN_SEMICOLON, "Expect ';' after a field declaration."); + } else if check_next(parse_state, .TOKEN_ASSIGN) { + decl_node = expression_statement(parse_state); + } + } else if check(parse_state, .TOKEN_OUT) || check(parse_state, .TOKEN_IN) { + error := error_node(parse_state, tprint("Expected a declaration or function call. '%' not allowed as a declaration name.", parse_state.current.kind)); + advance(parse_state); + decl_node = error; + } + + if !decl_node && !skip_statement { + decl_node = statement(parse_state); + } + + while parse_state.current.kind == .TOKEN_SEMICOLON { + advance(parse_state); + } + + return decl_node; +} + +parse :: (ctx : *Compiler_Context, allocator := temp) { + if ctx.had_error { + return; + } + + new_context := context; + new_context.allocator = allocator; + push_context new_context { + init_context_allocators(); + defer clear_context_allocators(); + + parse_state : Parse_State; + array_reserve(*ctx.nodes, 4096); + parse_state.current_token_index = 0; + parse_state.ctx = ctx; + + advance(*parse_state); + + if !match(*parse_state, .TOKEN_EOF) { + parse_state.ctx.root = make_node(*parse_state, .Program); + array_reserve(*parse_state.ctx.root.children, 1024); + program := parse_state.ctx.root; + + while !check(*parse_state, .TOKEN_EOF) { + decl := declaration(*parse_state); + if decl { + add_child(program, decl); + } + } + } + } +} + +#load "ast.jai"; diff --git a/shader_parsing_session.rdbg b/shader_parsing_session.rdbg new file mode 100644 index 0000000..cf70660 Binary files /dev/null and b/shader_parsing_session.rdbg differ diff --git a/test/all.suite b/test/all.suite new file mode 100644 index 0000000..f218180 --- /dev/null +++ b/test/all.suite @@ -0,0 +1,12 @@ +test/assign_arithmetic_expression.inx lex parse +test/empty_vertex_main.inx lex parse +test/empty_vertex_main_with_position_parameter.inx lex parse +test/meta_block.inx lex parse +test/basic_property_and_return_value.inx lex parse +test/function_call_return.inx lex parse +test/struct_field_access_test.inx lex parse +test/pass_and_access_struct_fields_in_functions.inx lex parse +test/field_without_type_specifier.inx lex parse +test/functions_with_same_name.inx lex parse +test/function_with_int_return.inx lex parse +test/type_as_variable_name.inx lex parse \ No newline at end of file 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 new file mode 100644 index 0000000..65924e0 --- /dev/null +++ b/test/arrays.ink @@ -0,0 +1,6 @@ +vertex main :: () -> float4 @position { + arr : [16].float4; + arr[0] = float4(1, 1, 1, 1); + pos := arr[1]; + return pos; +} diff --git a/test/assign_arithmetic_expression.ink b/test/assign_arithmetic_expression.ink new file mode 100644 index 0000000..2f58d35 --- /dev/null +++ b/test/assign_arithmetic_expression.ink @@ -0,0 +1,3 @@ +vertex main :: () { + x : float = 2.0 + 5.0; +} 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/basic_property_and_return_value.ink b/test/basic_property_and_return_value.ink new file mode 100644 index 0000000..1473525 --- /dev/null +++ b/test/basic_property_and_return_value.ink @@ -0,0 +1,11 @@ +properties :: Constant_Buffer @properties { + color : float4; +} + +vertex main :: (pos : float3 @position) -> float3 @position { + return pos; +} + +pixel main :: () -> float4 @target0 { + return properties.color; +} diff --git a/test/binary_with_access.ink b/test/binary_with_access.ink new file mode 100644 index 0000000..d119f38 --- /dev/null +++ b/test/binary_with_access.ink @@ -0,0 +1,8 @@ +props :: properties { + resolution : float2; +} + +vertex main :: (pos : float3 @position) -> float4 @position { + p := float2(1.0 - 2.0 * props.resolution.x, 1.0 - 2.0 * props.resolution.y); + return float4(p, 1.0, 1.0); +} diff --git a/test/buffers.ink b/test/buffers.ink new file mode 100644 index 0000000..9cb608f --- /dev/null +++ b/test/buffers.ink @@ -0,0 +1,11 @@ +property_buffer :: Buffer { + color : float4; +} + +const_buffer :: Constant_Buffer { + color : float4; +} + +pixel main :: (index : int) { + return property_buffer[index].color; +} diff --git a/test/builtin_types.ink b/test/builtin_types.ink new file mode 100644 index 0000000..a2ea2b4 --- /dev/null +++ b/test/builtin_types.ink @@ -0,0 +1,34 @@ +vertex main :: () { + v2 : float2 = float2(2.0, 2.0); + v2 = float2(2.0); + v2 = float2(v2); + + v3 : float3 = float3(2.0, 2.0, 2.0); + v3 = float3(v2, 1.0); + v3 = float3(1.0, v2); + v3 = float3(1.0); + v3 = float3(v3); + + v4 : float4 = float4(2.0, 2.0, 2.0, 2.0); + v4 = float4(v4); + v4 = float4(v2, v2); + v4 = float4(v2, 1.0, 1.0); + v4 = float4(1.0, v2, 1.0); + v4 = float4(1.0, 1.0, v2); + v4 = float4(v3, 2.0); + v4 = float4(2.0, v3); + v4 = float4(2.0); + + + v4 = float4(1.0, 1.0, v2); + v4 = float4(2.0); + + v2.x = 2.0; + v2.y = 2.0; + + p := v2.x + v3.z; + q := v4.w + v2.x; + + m : float4x4; + +} 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/assign_arithmetic_expression.golden b/test/check/assign_arithmetic_expression.golden new file mode 100644 index 0000000..d17a764 --- /dev/null +++ b/test/check/assign_arithmetic_expression.golden @@ -0,0 +1,6 @@ +scope (global) [ + [vertex__vs_main] : () + scope (vertex__vs_main) [ + [x] : float + ] +] 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/basic_property_and_return_value.golden b/test/check/basic_property_and_return_value.golden new file mode 100644 index 0000000..6f84e05 --- /dev/null +++ b/test/check/basic_property_and_return_value.golden @@ -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) [] +] diff --git a/test/check/builtin_types.golden b/test/check/builtin_types.golden new file mode 100644 index 0000000..55614e5 --- /dev/null +++ b/test/check/builtin_types.golden @@ -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 + ] +] diff --git a/test/check/complicated_computation.golden b/test/check/complicated_computation.golden new file mode 100644 index 0000000..e0affca --- /dev/null +++ b/test/check/complicated_computation.golden @@ -0,0 +1,8 @@ +scope (global) [ + [vertex__vs_main] : () + scope (vertex__vs_main) [ + [x] : float + [z] : float + [y] : float + ] +] diff --git a/test/check/constant_buffer.golden b/test/check/constant_buffer.golden new file mode 100644 index 0000000..1f36c81 --- /dev/null +++ b/test/check/constant_buffer.golden @@ -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) [] +] diff --git a/test/check/custom_hint.golden b/test/check/custom_hint.golden new file mode 100644 index 0000000..d5c60c6 --- /dev/null +++ b/test/check/custom_hint.golden @@ -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 + ] +] 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/empty_struct.golden b/test/check/empty_struct.golden new file mode 100644 index 0000000..2886129 --- /dev/null +++ b/test/check/empty_struct.golden @@ -0,0 +1,4 @@ +scope (global) [ +[Foo] : {} + scope (Foo) [] +] diff --git a/test/check/empty_vertex_main.golden b/test/check/empty_vertex_main.golden new file mode 100644 index 0000000..38cee29 --- /dev/null +++ b/test/check/empty_vertex_main.golden @@ -0,0 +1,4 @@ +scope (global) [ + [vertex__vs_main] : () + scope (vertex__vs_main) [] +] diff --git a/test/check/empty_vertex_main_with_position_parameter.golden b/test/check/empty_vertex_main_with_position_parameter.golden new file mode 100644 index 0000000..078d32e --- /dev/null +++ b/test/check/empty_vertex_main_with_position_parameter.golden @@ -0,0 +1,6 @@ +scope (global) [ + [vertex__vs_main] : (pos : float3) -> float3 + scope (vertex__vs_main) [ + [pos] : float3 + ] +] diff --git a/test/check/field_assignment.golden b/test/check/field_assignment.golden new file mode 100644 index 0000000..93ebab8 --- /dev/null +++ b/test/check/field_assignment.golden @@ -0,0 +1,7 @@ +scope (global) [ + [vertex__vs_main] : (pos : float4) -> float4 + scope (vertex__vs_main) [ + [x] : float + [pos] : float4 + ] +] diff --git a/test/check/field_without_type_specifier.golden b/test/check/field_without_type_specifier.golden new file mode 100644 index 0000000..d3f51d8 --- /dev/null +++ b/test/check/field_without_type_specifier.golden @@ -0,0 +1,4 @@ +test/field_without_type_specifier.shd:2,0: error: Expected type specifier after field name. + x := 5.0; + ^ + \ No newline at end of file diff --git a/test/check/float_if_cond.golden b/test/check/float_if_cond.golden new file mode 100644 index 0000000..3cdaf2b --- /dev/null +++ b/test/check/float_if_cond.golden @@ -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 + + \ No newline at end of file diff --git a/test/check/float_suffix.golden b/test/check/float_suffix.golden new file mode 100644 index 0000000..b5bf71b --- /dev/null +++ b/test/check/float_suffix.golden @@ -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 + ^^^^ + \ No newline at end of file diff --git a/test/check/for_i_loop.golden b/test/check/for_i_loop.golden new file mode 100644 index 0000000..51a5d76 --- /dev/null +++ b/test/check/for_i_loop.golden @@ -0,0 +1,10 @@ +scope (global) [ + [vertex__vs_main] : () + scope (vertex__vs_main) [ + [x] : int + scope (block) [ + [i] : int + scope (block) [] + ] + ] +] diff --git a/test/check/for_index_outside.golden b/test/check/for_index_outside.golden new file mode 100644 index 0000000..8642679 --- /dev/null +++ b/test/check/for_index_outside.golden @@ -0,0 +1,4 @@ +test/for_index_outside.ink:6,0: error: Use of undeclared symbol 'i' + i += 1; + ^ + \ No newline at end of file diff --git a/test/check/function_call.golden b/test/check/function_call.golden new file mode 100644 index 0000000..b6710d7 --- /dev/null +++ b/test/check/function_call.golden @@ -0,0 +1,6 @@ +scope (global) [ + [foo] : () -> int + [vertex__vs_main] : () + scope (foo) [] + scope (vertex__vs_main) [] +] diff --git a/test/check/function_call_out_of_order_declaration.golden b/test/check/function_call_out_of_order_declaration.golden new file mode 100644 index 0000000..26a6aa9 --- /dev/null +++ b/test/check/function_call_out_of_order_declaration.golden @@ -0,0 +1,6 @@ +scope (global) [ + [foo] : () + [vertex__vs_main] : () + scope (vertex__vs_main) [] + scope (foo) [] +] diff --git a/test/check/function_call_return.golden b/test/check/function_call_return.golden new file mode 100644 index 0000000..91b7254 --- /dev/null +++ b/test/check/function_call_return.golden @@ -0,0 +1,6 @@ +scope (global) [ + [pixel__ps_main] : () -> float4 + [vertex__vs_main] : () + scope (vertex__vs_main) [] + scope (pixel__ps_main) [] +] diff --git a/test/check/function_with_int_return.golden b/test/check/function_with_int_return.golden new file mode 100644 index 0000000..7dbb733 --- /dev/null +++ b/test/check/function_with_int_return.golden @@ -0,0 +1,6 @@ +scope (global) [ + [vertex__vs_main] : (pos : float3) -> int + scope (vertex__vs_main) [ + [pos] : float3 + ] +] diff --git a/test/check/functions_with_same_name.golden b/test/check/functions_with_same_name.golden new file mode 100644 index 0000000..fcfc0cf --- /dev/null +++ b/test/check/functions_with_same_name.golden @@ -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 :: () { + ^^^ + \ No newline at end of file diff --git a/test/check/hinted_cbuffer.golden b/test/check/hinted_cbuffer.golden new file mode 100644 index 0000000..a8689ab --- /dev/null +++ b/test/check/hinted_cbuffer.golden @@ -0,0 +1,13 @@ +scope (global) [ + [vertex__vs_main] : (pos : float4) -> float4 + [props] : {projection : float4x4, view : float4x4} + scope (props) [ + [projection] : float4x4 + [view] : float4x4 + ] + scope (vertex__vs_main) [ + [pos] : float4 + [mv] : float4 + [mvp] : float4 + ] +] diff --git a/test/check/if_cond_assign.golden b/test/check/if_cond_assign.golden new file mode 100644 index 0000000..2fa9f46 --- /dev/null +++ b/test/check/if_cond_assign.golden @@ -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 + + \ No newline at end of file diff --git a/test/check/if_def_block.golden b/test/check/if_def_block.golden new file mode 100644 index 0000000..9dd53c6 --- /dev/null +++ b/test/check/if_def_block.golden @@ -0,0 +1,8 @@ +scope (global) [ + [pixel__ps_main] : () + scope (pixel__ps_main) [ scope (block) [ + [alpha_color] : float4 + [f] : float + ] + ] +] diff --git a/test/check/if_def_expression.golden b/test/check/if_def_expression.golden new file mode 100644 index 0000000..4f24f80 --- /dev/null +++ b/test/check/if_def_expression.golden @@ -0,0 +1,4 @@ +scope (global) [ + [vertex__vs_console_main] : () + scope (vertex__vs_console_main) [] +] diff --git a/test/check/ifdefs.golden b/test/check/ifdefs.golden new file mode 100644 index 0000000..c116c42 --- /dev/null +++ b/test/check/ifdefs.golden @@ -0,0 +1,8 @@ +scope (global) [ + [vertex__vs_skinning_main] : () + [pixel__ps_main] : () + scope (vertex__vs_skinning_main) [ + [x] : float + ] + scope (pixel__ps_main) [] +] diff --git a/test/check/inferred_types.golden b/test/check/inferred_types.golden new file mode 100644 index 0000000..40c9c9d --- /dev/null +++ b/test/check/inferred_types.golden @@ -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 + ] +] diff --git a/test/check/meta_block.golden b/test/check/meta_block.golden new file mode 100644 index 0000000..5d9be1e --- /dev/null +++ b/test/check/meta_block.golden @@ -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) [] +] diff --git a/test/check/multiple_functions.golden b/test/check/multiple_functions.golden new file mode 100644 index 0000000..4362a5b --- /dev/null +++ b/test/check/multiple_functions.golden @@ -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 + ] +] diff --git a/test/check/multiple_semicolons_everywhere.golden b/test/check/multiple_semicolons_everywhere.golden new file mode 100644 index 0000000..9eadf9c --- /dev/null +++ b/test/check/multiple_semicolons_everywhere.golden @@ -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 + ] +] diff --git a/test/check/nested_if.golden b/test/check/nested_if.golden new file mode 100644 index 0000000..a4ed3c6 --- /dev/null +++ b/test/check/nested_if.golden @@ -0,0 +1,9 @@ +scope (global) [ + [vertex__vs_main] : (pos : float3) -> float4 + scope (vertex__vs_main) [ + [pos] : float3 + scope (block) [ scope (block) [] + scope (block) [] + ] + ] +] diff --git a/test/check/non_bool_cond.golden b/test/check/non_bool_cond.golden new file mode 100644 index 0000000..87b2739 --- /dev/null +++ b/test/check/non_bool_cond.golden @@ -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 + + \ No newline at end of file diff --git a/test/check/pass_and_access_struct_fields_in_functions.golden b/test/check/pass_and_access_struct_fields_in_functions.golden new file mode 100644 index 0000000..27a0920 --- /dev/null +++ b/test/check/pass_and_access_struct_fields_in_functions.golden @@ -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 + ] +] diff --git a/test/check/passthrough.golden b/test/check/passthrough.golden new file mode 100644 index 0000000..81f0bde --- /dev/null +++ b/test/check/passthrough.golden @@ -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) [] +] diff --git a/test/check/precedence_test.golden b/test/check/precedence_test.golden new file mode 100644 index 0000000..d8e6aed --- /dev/null +++ b/test/check/precedence_test.golden @@ -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 + ] +] diff --git a/test/check/property_rename.golden b/test/check/property_rename.golden new file mode 100644 index 0000000..53c4920 --- /dev/null +++ b/test/check/property_rename.golden @@ -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) [] +] diff --git a/test/check/redeclared_variable.golden b/test/check/redeclared_variable.golden new file mode 100644 index 0000000..e1aca71 --- /dev/null +++ b/test/check/redeclared_variable.golden @@ -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 + ^ + \ No newline at end of file diff --git a/test/check/rvalue_binary.golden b/test/check/rvalue_binary.golden new file mode 100644 index 0000000..4d5b770 --- /dev/null +++ b/test/check/rvalue_binary.golden @@ -0,0 +1,8 @@ +scope (global) [ + [vertex__vs_main] : () + scope (vertex__vs_main) [ + [b] : float2 + [x] : float + [a] : float2 + ] +] diff --git a/test/check/simple_else_if.golden b/test/check/simple_else_if.golden new file mode 100644 index 0000000..d73d2fa --- /dev/null +++ b/test/check/simple_else_if.golden @@ -0,0 +1,9 @@ +scope (global) [ + [vertex__vs_main] : (pos : float3) -> float4 + scope (vertex__vs_main) [ + [pos] : float3 + scope (block) [] + scope (block) [] + scope (block) [] + ] +] diff --git a/test/check/simple_if.golden b/test/check/simple_if.golden new file mode 100644 index 0000000..a368773 --- /dev/null +++ b/test/check/simple_if.golden @@ -0,0 +1,7 @@ +scope (global) [ + [vertex__vs_main] : (pos : float3) -> float4 + scope (vertex__vs_main) [ + [pos] : float3 + scope (block) [] + ] +] diff --git a/test/check/simple_if_else.golden b/test/check/simple_if_else.golden new file mode 100644 index 0000000..04e1bf1 --- /dev/null +++ b/test/check/simple_if_else.golden @@ -0,0 +1,8 @@ +scope (global) [ + [vertex__vs_main] : (pos : float3) -> float4 + scope (vertex__vs_main) [ + [pos] : float3 + scope (block) [] + scope (block) [] + ] +] diff --git a/test/check/simple_struct_access.golden b/test/check/simple_struct_access.golden new file mode 100644 index 0000000..a2fbc11 --- /dev/null +++ b/test/check/simple_struct_access.golden @@ -0,0 +1,11 @@ +scope (global) [ +[Data] : {color : float4} + [vertex__vs_main] : () + scope (Data) [ + [color] : float4 + ] + scope (vertex__vs_main) [ + [x] : float4 + [d] : Data + ] +] diff --git a/test/check/struct_access_primitive_type.golden b/test/check/struct_access_primitive_type.golden new file mode 100644 index 0000000..7c4130f --- /dev/null +++ b/test/check/struct_access_primitive_type.golden @@ -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 + \ No newline at end of file diff --git a/test/check/struct_within_struct.golden b/test/check/struct_within_struct.golden new file mode 100644 index 0000000..47164d1 --- /dev/null +++ b/test/check/struct_within_struct.golden @@ -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 + ] +] diff --git a/test/check/temp_access.golden b/test/check/temp_access.golden new file mode 100644 index 0000000..0237713 --- /dev/null +++ b/test/check/temp_access.golden @@ -0,0 +1,6 @@ +test/temp_access.ink:5,10: error: Cannot assign to an lvalue. + (a + b).x = 2.0; + ^^^^^^^^^^^ + + + \ No newline at end of file diff --git a/test/check/type_as_function_name.golden b/test/check/type_as_function_name.golden new file mode 100644 index 0000000..cc4d143 --- /dev/null +++ b/test/check/type_as_function_name.golden @@ -0,0 +1,4 @@ +test/type_as_function_name.shd:1,0: error: Invalid function name 'int' + int :: () { + ^^^ + \ No newline at end of file diff --git a/test/check/type_as_variable_name.golden b/test/check/type_as_variable_name.golden new file mode 100644 index 0000000..59e7901 --- /dev/null +++ b/test/check/type_as_variable_name.golden @@ -0,0 +1,4 @@ +test/type_as_variable_name.ink:2,0: error: Invalid variable name 'int' + int : float = 4.0 + ^^^ + \ No newline at end of file diff --git a/test/check/unary.golden b/test/check/unary.golden new file mode 100644 index 0000000..75a59f9 --- /dev/null +++ b/test/check/unary.golden @@ -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 + ] +] diff --git a/test/check/undeclared_function.golden b/test/check/undeclared_function.golden new file mode 100644 index 0000000..296d548 --- /dev/null +++ b/test/check/undeclared_function.golden @@ -0,0 +1,7 @@ +test/undeclared_function.ink:2,0: error: Attempt to call undeclared function 'foo'. + + foo(); + ^^^ + + + \ No newline at end of file diff --git a/test/check/undeclared_symbol.golden b/test/check/undeclared_symbol.golden new file mode 100644 index 0000000..14ef641 --- /dev/null +++ b/test/check/undeclared_symbol.golden @@ -0,0 +1,4 @@ +test/undeclared_symbol.ink:2,10: error: Use of undeclared symbol 'f' + b : int = f; + ^ + \ No newline at end of file diff --git a/test/check/unknown_overload.golden b/test/check/unknown_overload.golden new file mode 100644 index 0000000..a317a2b --- /dev/null +++ b/test/check/unknown_overload.golden @@ -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 + + \ No newline at end of file diff --git a/test/check/use_builtin_functions.golden b/test/check/use_builtin_functions.golden new file mode 100644 index 0000000..ef03716 --- /dev/null +++ b/test/check/use_builtin_functions.golden @@ -0,0 +1,6 @@ +scope (global) [ + [vertex__vs_main] : () + scope (vertex__vs_main) [ + [f] : float4 + ] +] diff --git a/test/check/wrong_argument_count.golden b/test/check/wrong_argument_count.golden new file mode 100644 index 0000000..562a3c4 --- /dev/null +++ b/test/check/wrong_argument_count.golden @@ -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. + + + \ No newline at end of file diff --git a/test/check/wrong_multiply.golden b/test/check/wrong_multiply.golden new file mode 100644 index 0000000..1312d16 --- /dev/null +++ b/test/check/wrong_multiply.golden @@ -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); + + \ No newline at end of file diff --git a/test/check/wrong_type_for_function.golden b/test/check/wrong_type_for_function.golden new file mode 100644 index 0000000..5406253 --- /dev/null +++ b/test/check/wrong_type_for_function.golden @@ -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() + + \ No newline at end of file diff --git a/test/check_all.suite b/test/check_all.suite new file mode 100644 index 0000000..7f153a9 --- /dev/null +++ b/test/check_all.suite @@ -0,0 +1,47 @@ +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 +test/field_assignment.ink check +test/for_i_loop.ink check +test/function_call.ink check +test/function_call_out_of_order_declaration.ink check +test/function_call_return.ink check +test/functions_with_same_name.ink check +test/function_with_int_return.ink check +test/if_cond_assign.ink check +test/ifdefs.ink check +test/if_def_block.ink check +test/if_def_expression.ink check +test/inferred_types.ink check +test/multiple_functions.ink check +test/multiple_semicolons_everywhere.ink check +test/nested_if.ink check +test/non_bool_cond.ink check +test/pass_and_access_struct_fields_in_functions.ink check +test/passthrough.ink check +test/redeclared_variable.ink check +test/rvalue_binary.ink check +test/simple_else_if.ink check +test/simple_if_else.ink check +test/simple_if.ink check +test/simple_struct_access.ink check +test/struct_access_primitive_type.ink check +test/struct_within_struct.ink check +test/temp_access.ink check +test/type_as_variable_name.ink check +test/unary.ink check +test/undeclared_function.ink check +test/undeclared_symbol.ink check +test/unknown_overload.ink check +test/use_builtin_functions.ink check +test/wrong_argument_count.ink check +test/wrong_multiply.ink check +test/wrong_type_for_function.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/arrays.golden b/test/codegen/arrays.golden new file mode 100644 index 0000000..5347981 --- /dev/null +++ b/test/codegen/arrays.golden @@ -0,0 +1,6 @@ +float4 vs_main() : SV_POSITION +{ + float4 arr[16]; + return arr[0]; +} + diff --git a/test/codegen/assign_arithmetic_expression.golden b/test/codegen/assign_arithmetic_expression.golden new file mode 100644 index 0000000..81b0e2f --- /dev/null +++ b/test/codegen/assign_arithmetic_expression.golden @@ -0,0 +1,5 @@ +void vs_main() +{ + float x = 2.0f + 5.0f; +} + diff --git a/test/codegen/basic_property_and_return_value.golden b/test/codegen/basic_property_and_return_value.golden new file mode 100644 index 0000000..38e6d50 --- /dev/null +++ b/test/codegen/basic_property_and_return_value.golden @@ -0,0 +1,15 @@ +cbuffer properties : register(b0) +{ + float4 color; +} + +float3 vs_main(float3 pos : POSITION) : SV_POSITION +{ + return pos; +} + +float4 ps_main() : SV_TARGET +{ + return properties.color; +} + diff --git a/test/codegen/builtin_types.golden b/test/codegen/builtin_types.golden new file mode 100644 index 0000000..a4b5e80 --- /dev/null +++ b/test/codegen/builtin_types.golden @@ -0,0 +1,28 @@ +void vs_main() +{ + float2 v2 = float2(2.0f, 2.0f); + v2 = float2(2.0f, 2.0f); + v2 = float2(v2, v2); + float3 v3 = float3(2.0f, 2.0f, 2.0f); + v3 = float3(v2, 1.0f); + v3 = float3(1.0f, v2); + v3 = float3(1.0f, 1.0f, 1.0f); + v3 = float3(v3, v3, v3); + float4 v4 = float4(2.0f, 2.0f, 2.0f, 2.0f); + v4 = float4(v4, v4, v4, v4); + v4 = float4(v2, v2); + v4 = float4(v2, 1.0f, 1.0f); + v4 = float4(1.0f, v2, 1.0f); + v4 = float4(1.0f, 1.0f, v2); + v4 = float4(v3, 2.0f); + v4 = float4(2.0f, v3); + v4 = float4(2.0f, 2.0f, 2.0f, 2.0f); + v4 = float4(1.0f, 1.0f, v2); + 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; + float4x4 m; +} + diff --git a/test/codegen/complicated_computation.golden b/test/codegen/complicated_computation.golden new file mode 100644 index 0000000..2f5340d --- /dev/null +++ b/test/codegen/complicated_computation.golden @@ -0,0 +1,7 @@ +void vs_main() +{ + float x = 5.0f; + float y = 3000.0f; + float z = (y * y) + x; +} + diff --git a/test/codegen/constant_buffer.golden b/test/codegen/constant_buffer.golden new file mode 100644 index 0000000..1d52266 --- /dev/null +++ b/test/codegen/constant_buffer.golden @@ -0,0 +1,18 @@ +cbuffer camera : register(b0) +{ + float4x4 projection; + float4x4 view; +} + +float4 vs_main(float4 pos : POSITION) : SV_POSITION +{ + float4 mv = mul(camera.view, pos); + float4 mvp = mul(camera.projection, mv); + return mvp; +} + +float4 ps_main() : SV_TARGET +{ + return float4(0.5f, 0.5f, 0.5f, 1.0f); +} + diff --git a/test/codegen/custom_hint.golden b/test/codegen/custom_hint.golden new file mode 100644 index 0000000..0373787 --- /dev/null +++ b/test/codegen/custom_hint.golden @@ -0,0 +1,17 @@ +cbuffer __PROPERTIES : register(b0) +{ + float __PROPERTIES__time; +} + + +float4 vs_main(float3 pos : POSITION) : SV_POSITION +{ + return float4(pos.x, pos.y, pos.z, 1.0f); +} + +float4 ps_main(float4 pos : SV_POSITION) : SV_TARGET +{ + float t = __PROPERTIES__time; + return float4(1, 1, 1, 1); +} + diff --git a/test/codegen/empty_struct.golden b/test/codegen/empty_struct.golden new file mode 100644 index 0000000..7cf84fd --- /dev/null +++ b/test/codegen/empty_struct.golden @@ -0,0 +1,2 @@ +struct Foo {}; + diff --git a/test/codegen/empty_vertex_main.golden b/test/codegen/empty_vertex_main.golden new file mode 100644 index 0000000..3385d47 --- /dev/null +++ b/test/codegen/empty_vertex_main.golden @@ -0,0 +1,4 @@ +void vs_main() +{ +} + diff --git a/test/codegen/empty_vertex_main_with_position_parameter.golden b/test/codegen/empty_vertex_main_with_position_parameter.golden new file mode 100644 index 0000000..9a84e84 --- /dev/null +++ b/test/codegen/empty_vertex_main_with_position_parameter.golden @@ -0,0 +1,5 @@ +float3 vs_main(float3 pos : POSITION) +{ + return pos; +} + diff --git a/test/codegen/field_assignment.golden b/test/codegen/field_assignment.golden new file mode 100644 index 0000000..4cad7a0 --- /dev/null +++ b/test/codegen/field_assignment.golden @@ -0,0 +1,7 @@ +float4 vs_main(float4 pos : POSITION) : SV_POSITION +{ + float x = 5.0f; + x = 7.0f; + return pos; +} + diff --git a/test/codegen/function_call.golden b/test/codegen/function_call.golden new file mode 100644 index 0000000..d4c18a6 --- /dev/null +++ b/test/codegen/function_call.golden @@ -0,0 +1,12 @@ +int foo(); + +int foo() +{ + return 4; +} + +void vs_main() +{ + foo(); +} + diff --git a/test/codegen/function_call_out_of_order_declaration.golden b/test/codegen/function_call_out_of_order_declaration.golden new file mode 100644 index 0000000..5e4725d --- /dev/null +++ b/test/codegen/function_call_out_of_order_declaration.golden @@ -0,0 +1,11 @@ +void foo(); + +void vs_main() +{ + foo(); +} + +void foo() +{ +} + diff --git a/test/codegen/function_call_return.golden b/test/codegen/function_call_return.golden new file mode 100644 index 0000000..7799da6 --- /dev/null +++ b/test/codegen/function_call_return.golden @@ -0,0 +1,9 @@ +void vs_main() +{ +} + +float4 ps_main() : SV_TARGET +{ + return float4(1, 1, 1, 1); +} + diff --git a/test/codegen/hinted_cbuffer.golden b/test/codegen/hinted_cbuffer.golden new file mode 100644 index 0000000..307c23c --- /dev/null +++ b/test/codegen/hinted_cbuffer.golden @@ -0,0 +1,13 @@ +cbuffer props : register(b0) +{ + float4x4 projection; + float4x4 view; +} + +float4 vs_main(float4 pos : POSITION) : SV_POSITION +{ + float4 mv = mul(props.view, pos); + float4 mvp = mul(props.projection, mv); + return mvp; +} + diff --git a/test/codegen/if_def_block.golden b/test/codegen/if_def_block.golden new file mode 100644 index 0000000..eb5eb61 --- /dev/null +++ b/test/codegen/if_def_block.golden @@ -0,0 +1,7 @@ +void ps_main() +{ + + float4 alpha_color = float4(1, 0, 0, 1); + float f = 2.0f; +} + diff --git a/test/codegen/if_def_expression.golden b/test/codegen/if_def_expression.golden new file mode 100644 index 0000000..e856ca6 --- /dev/null +++ b/test/codegen/if_def_expression.golden @@ -0,0 +1,4 @@ +void vs_console_main() +{ +} + diff --git a/test/codegen/ifdefs.golden b/test/codegen/ifdefs.golden new file mode 100644 index 0000000..93b8e0e --- /dev/null +++ b/test/codegen/ifdefs.golden @@ -0,0 +1,9 @@ +void ps_main() +{ +} + +void vs_skinning_main() +{ + float x = 5.0f; +} + diff --git a/test/codegen/inferred_types.golden b/test/codegen/inferred_types.golden new file mode 100644 index 0000000..825439c --- /dev/null +++ b/test/codegen/inferred_types.golden @@ -0,0 +1,24 @@ +float bar(); +float foo(); + +float bar() +{ + return 5.0f; +} + +float foo() +{ + return bar(); +} + +float4 vs_main(float3 pos : POSITION) : SV_POSITION +{ + float f = 2.0f; + int i = 10; + f = foo(); + float2 v2 = float2(2, 2); + float3 v3 = float3(2, 2, 3); + float4 v4 = float4(4, 5, 6, 7); + return float4(1, 1, 1, 1); +} + diff --git a/test/codegen/meta_block.golden b/test/codegen/meta_block.golden new file mode 100644 index 0000000..6dd5a4a --- /dev/null +++ b/test/codegen/meta_block.golden @@ -0,0 +1,16 @@ +cbuffer __PROPERTIES : register(b0) +{ + float4 __PROPERTIES__color; +} + + +float3 vs_main(float3 pos : POSITION, float2 uv : TEXCOORD0) : SV_POSITION +{ + return pos; +} + +float4 ps_main() : SV_TARGET +{ + return __PROPERTIES__color; +} + diff --git a/test/codegen/multiple_functions.golden b/test/codegen/multiple_functions.golden new file mode 100644 index 0000000..a2a8be4 --- /dev/null +++ b/test/codegen/multiple_functions.golden @@ -0,0 +1,19 @@ +int foo(); +float bar(); + +int foo() +{ + return 5; +} + +float bar() +{ + return 1235.0f * 500; +} + +void vs_main() +{ + int x = foo(); + float y = bar(); +} + diff --git a/test/codegen/multiple_semicolons_everywhere.golden b/test/codegen/multiple_semicolons_everywhere.golden new file mode 100644 index 0000000..3991c4f --- /dev/null +++ b/test/codegen/multiple_semicolons_everywhere.golden @@ -0,0 +1,19 @@ +float4 foo(); + +float3 vs_main(float3 pos : POSITION) : SV_POSITION +{ + return pos; +} + +float4 foo() +{ + return float4(1.0f, 1.0f, 1.0f, 1.0f); +} + +float4 ps_main() : SV_TARGET +{ + float4 y = foo(); + float4 color = y; + return color; +} + diff --git a/test/codegen/nested_if.golden b/test/codegen/nested_if.golden new file mode 100644 index 0000000..33f1b5e --- /dev/null +++ b/test/codegen/nested_if.golden @@ -0,0 +1,18 @@ +float4 vs_main(float3 pos : POSITION) : SV_POSITION +{ + if (pos.x > 100) + { + if (pos.x > 50) + { + return float4(pos, 1.0f); + } + else + { + return float4(1.0f, 1.0f, 1.0f, 1.0f); + } + return float4(pos, 1.0f); + } + + return float4(0.0f, 0.0f, 0.0f, 0.0f); +} + diff --git a/test/codegen/night_time.golden b/test/codegen/night_time.golden new file mode 100644 index 0000000..1a176a5 --- /dev/null +++ b/test/codegen/night_time.golden @@ -0,0 +1,93 @@ +float4 apply_night(float4 color); +float4 apply_twilight(float4 color); +float4 apply_morning(float4 color); +float4 apply_dawn(float4 color); + +cbuffer __PROPERTIES : register(b0) +{ + float __PROPERTIES__hour_of_day; +} + +Texture2D __PROPERTIES__input_tex : register(t0); +SamplerState __PROPERTIES__tex_sampler : register(s0); + +struct VS_Input +{ + float3 pos : POSITION; + float2 uv : TEXCOORD0; +}; + +struct VS_Output +{ + float4 pos : SV_POSITION; + float2 uv : TEXCOORD0; +}; + +VS_Output vs_main(VS_Input input) +{ + VS_Output output; + output.pos = float4(input.pos, 1.0f); + output.uv = input.uv; + return output; +} + +float4 apply_night(float4 color) +{ + float4 result = color; + (result -= float4(0.3f, 0.2f, 0.0f, 0.0f)); + (result *= 0.8f); + return result; +} + +float4 apply_twilight(float4 color) +{ + float4 result = color; + (result += float4(0.2f, -0.1f, 0.1f, 0.0f)); + (result *= 0.9f); + return result; +} + +float4 apply_morning(float4 color) +{ + return (color * 1.3f); +} + +float4 apply_dawn(float4 color) +{ + return color; +} + +float4 ps_main(VS_Output input) +{ + float4 sampled_color = __PROPERTIES__input_tex.Sample(__PROPERTIES__tex_sampler, input.uv); + float t = 0.0f; + float4 a = float4(0, 0, 0, 0); + float4 b = float4(0, 0, 0, 0); + if (__PROPERTIES__hour_of_day > 16) + { + t = ((__PROPERTIES__hour_of_day - 16) / 6); + a = apply_twilight(sampled_color); + b = apply_night(sampled_color); + } + else if (__PROPERTIES__hour_of_day > 12) + { + t = ((__PROPERTIES__hour_of_day - 12) / 6); + a = sampled_color; + b = apply_twilight(sampled_color); + } + else if (__PROPERTIES__hour_of_day > 6) + { + t = ((__PROPERTIES__hour_of_day - 6) / 6); + a = apply_morning(sampled_color); + b = sampled_color; + } + else if (__PROPERTIES__hour_of_day >= 0) + { + t = (__PROPERTIES__hour_of_day / 6); + a = apply_night(sampled_color); + b = apply_morning(sampled_color); + } + + return lerp(a, b, t); +} + diff --git a/test/codegen/pass_and_access_struct_fields_in_functions.golden b/test/codegen/pass_and_access_struct_fields_in_functions.golden new file mode 100644 index 0000000..4f97657 --- /dev/null +++ b/test/codegen/pass_and_access_struct_fields_in_functions.golden @@ -0,0 +1,19 @@ +float foo(Foo f); + +struct Foo +{ + float some_data; +}; + +float foo(Foo f) +{ + return f.some_data * 2.0f; +} + +void vs_main() +{ + Foo f; + f.some_data = 4.0f; + float d = foo(f); +} + diff --git a/test/codegen/passthrough.golden b/test/codegen/passthrough.golden new file mode 100644 index 0000000..5a7589b --- /dev/null +++ b/test/codegen/passthrough.golden @@ -0,0 +1,10 @@ +float3 vs_main(float3 pos : POSITION) : SV_POSITION +{ + return pos; +} + +float4 ps_main() : SV_TARGET +{ + return float4(1.0f, 1.0f, 1.0f, 1.0f); +} + diff --git a/test/codegen/precedence_test.golden b/test/codegen/precedence_test.golden new file mode 100644 index 0000000..d127b05 --- /dev/null +++ b/test/codegen/precedence_test.golden @@ -0,0 +1,8 @@ +void vs_main() +{ + float x = 2; + float y = 5; + float z = 10; + float w = x * y + y * z - x / y * x; +} + diff --git a/test/codegen/property_rename.golden b/test/codegen/property_rename.golden new file mode 100644 index 0000000..85f47e3 --- /dev/null +++ b/test/codegen/property_rename.golden @@ -0,0 +1,16 @@ +cbuffer __PROPERTIES : register(b0) +{ + float4 __PROPERTIES__color; +} + + +float4 vs_main(float4 pos : POSITION) : SV_POSITION +{ + return pos; +} + +float4 ps_main() : SV_TARGET +{ + return __PROPERTIES__color; +} + diff --git a/test/codegen/rvalue_binary.golden b/test/codegen/rvalue_binary.golden new file mode 100644 index 0000000..65b101c --- /dev/null +++ b/test/codegen/rvalue_binary.golden @@ -0,0 +1,7 @@ +void vs_main() +{ + float2 a; + float2 b; + float x = (a + b).x; +} + diff --git a/test/codegen/simple_else_if.golden b/test/codegen/simple_else_if.golden new file mode 100644 index 0000000..3ef308c --- /dev/null +++ b/test/codegen/simple_else_if.golden @@ -0,0 +1,17 @@ +float4 vs_main(float3 pos : POSITION) : SV_POSITION +{ + if (pos.x > 100) + { + return float4(pos, 1.0f); + } + else if (pos.x > 50) + { + return float4(pos, 1.0f); + } + else + { + return float4(1.0f, 1.0f, 1.0f, 1.0f); + } + return float4(0.0f, 0.0f, 0.0f, 0.0f); +} + diff --git a/test/codegen/simple_if.golden b/test/codegen/simple_if.golden new file mode 100644 index 0000000..8c48635 --- /dev/null +++ b/test/codegen/simple_if.golden @@ -0,0 +1,10 @@ +float4 vs_main(float3 pos : POSITION) : SV_POSITION +{ + if (0 > 100) + { + return float4(pos, 1.0f); + } + + return float4(0.0f, 0.0f, 0.0f, 0.0f); +} + diff --git a/test/codegen/simple_if_else.golden b/test/codegen/simple_if_else.golden new file mode 100644 index 0000000..68d438a --- /dev/null +++ b/test/codegen/simple_if_else.golden @@ -0,0 +1,13 @@ +float4 vs_main(float3 pos : POSITION) : SV_POSITION +{ + if (0 > 100) + { + return float4(pos, 1.0f); + } + else + { + return float4(1.0f, 1.0f, 1.0f, 1.0f); + } + return float4(0.0f, 0.0f, 0.0f, 0.0f); +} + diff --git a/test/codegen/simple_struct_access.golden b/test/codegen/simple_struct_access.golden new file mode 100644 index 0000000..b32d99e --- /dev/null +++ b/test/codegen/simple_struct_access.golden @@ -0,0 +1,11 @@ +struct Data +{ + float4 color; +}; + +void vs_main() +{ + Data d; + float4 x = d.color; +} + diff --git a/test/codegen/struct_within_struct.golden b/test/codegen/struct_within_struct.golden new file mode 100644 index 0000000..8794381 --- /dev/null +++ b/test/codegen/struct_within_struct.golden @@ -0,0 +1,17 @@ +struct Foo +{ + float4 color; +}; + +struct Bar +{ + Foo t; +}; + +void vs_main() +{ + Foo f; + Bar b; + b.t = f; +} + diff --git a/test/codegen/texture_sample.golden b/test/codegen/texture_sample.golden new file mode 100644 index 0000000..ba7961b --- /dev/null +++ b/test/codegen/texture_sample.golden @@ -0,0 +1,29 @@ +struct PS_Input; + +cbuffer __PROPERTIES : register(b0) +{ +} + +Texture2D texture : register(t0); +Sampler sampler : register(s0); + +struct PS_Input +{ + float2 uv; + float4 pos : POSITION; +} + +PS_Input vs_main(float4 pos : POSITION, float2 uv) +{ + PS_Input result; + result.uv = uv; + result.pos = pos; + return result; +} + +float4 ps_main(PS_Input input) : SV_TARGET +{ + float4 color = texture.sample(input.uv, sampler); + return color; +} + diff --git a/test/codegen/unary.golden b/test/codegen/unary.golden new file mode 100644 index 0000000..9c73d21 --- /dev/null +++ b/test/codegen/unary.golden @@ -0,0 +1,10 @@ +float4 vs_vs_main(float3 position : POSITION) : SV_POSITION +{ + return float4(position.x, position.y, position.z, 1.0f); +} + +float4 ps_ps_main(float4 position : SV_POSITION) : SV_TARGET +{ + return float4(0.5f, -1, 0, 1); +} + diff --git a/test/codegen/use_builtin_functions.golden b/test/codegen/use_builtin_functions.golden new file mode 100644 index 0000000..fead5e5 --- /dev/null +++ b/test/codegen/use_builtin_functions.golden @@ -0,0 +1,5 @@ +void vs_main() +{ + float4 f = float4(1, 1, 1, 1); +} + diff --git a/test/codegen_all.suite b/test/codegen_all.suite new file mode 100644 index 0000000..d1e0be4 --- /dev/null +++ b/test/codegen_all.suite @@ -0,0 +1,30 @@ +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 +test/constant_buffer.ink codegen +test/empty_struct.ink codegen +test/empty_vertex_main.ink codegen +test/empty_vertex_main_with_position_parameter.ink codegen +test/field_assignment.ink codegen +test/function_call.ink codegen +test/function_call_out_of_order_declaration.ink codegen +test/function_call_return.ink codegen +test/ifdefs.ink codegen +test/if_def_block.ink codegen +test/if_def_expression.ink codegen +test/inferred_types.ink codegen +test/multiple_functions.ink codegen +test/multiple_semicolons_everywhere.ink codegen +test/nested_if.ink codegen +test/pass_and_access_struct_fields_in_functions.ink codegen +test/passthrough.ink codegen +test/rvalue_binary.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 +test/use_builtin_functions.ink codegen diff --git a/test/colorful_circle.ink b/test/colorful_circle.ink new file mode 100644 index 0000000..9ef9063 --- /dev/null +++ b/test/colorful_circle.ink @@ -0,0 +1,39 @@ +prop :: properties { + time : float @time; + resolution : float2 @resolution; +} + +vertex main :: (pos : float3 @position) -> float4 @position { + return float4(pos, 1.0); +} + +pixel main :: (pos : float4 @outposition) -> float4 @target { + p := float2(2.0 * pos.x - prop.resolution.x, 2.0 * pos.y - prop.resolution.y) / prop.resolution.y; + tau := 3.1415926535 * 2.0; + a := atan(p.x, p.y); + r := length(p) * 0.75; + + uv := float2(a / tau, r); + + x_col := (uv.x - (p.time / 3.0)) * 3.0; + x_col = mod(x_col, 3.0); + hor_colour := float3(0.25, 0.25, 0.25); + + if x_col < 1.0 { + horColour.r += 1.0 - xCol; + horColour.g += xCol; + } else if x_col < 2.0 { + xCol -= 1.0; + horColour.g += 1.0 - xCol; + horColour.b += xCol; + } else { + x_col -= 2.0; + hor_colour.b += 1.0 - x_col; + hor_colour.r += x_col; + } + + uv = (2.0 * uv) - 1.0; + beam_width = (0.7+0.5*cos(uv.x*10.0*tau*0.15*clamp(floor(5.0 + 10.0*cos(iTime)), 0.0, 10.0))) * abs(1.0 / (30.0 * uv.y)); + hor_beam = float3(beam_width); + result := float4(((hor_beam) * hor_colour), 1.0); +} diff --git a/test/compile_all.suite b/test/compile_all.suite new file mode 100644 index 0000000..075e834 --- /dev/null +++ b/test/compile_all.suite @@ -0,0 +1,30 @@ +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 +test/empty_struct.ink compile +test/empty_vertex_main.ink compile +test/empty_vertex_main_with_position_parameter.ink compile +test/field_assignment.ink compile +test/float_suffix.ink compile +test/function_call.ink compile +test/function_call_out_of_order_declaration.ink compile +test/function_call_return.ink compile +test/functions_with_same_name.ink compile +test/ifdefs.ink compile +test/if_def_block.ink compile +test/if_def_expression.ink compile +test/inferred_types.ink compile +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/rvalue_binary.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 +test/use_builtin_functions.ink compile \ No newline at end of file diff --git a/test/compiled/assign_arithmetic_expression.golden b/test/compiled/assign_arithmetic_expression.golden new file mode 100644 index 0000000..d8b18cc --- /dev/null +++ b/test/compiled/assign_arithmetic_expression.golden @@ -0,0 +1 @@ +[vertex entry point] - vs_main diff --git a/test/compiled/builtin_types.golden b/test/compiled/builtin_types.golden new file mode 100644 index 0000000..d8b18cc --- /dev/null +++ b/test/compiled/builtin_types.golden @@ -0,0 +1 @@ +[vertex entry point] - vs_main diff --git a/test/compiled/hinted_cbuffer.golden b/test/compiled/hinted_cbuffer.golden new file mode 100644 index 0000000..78d6a29 --- /dev/null +++ b/test/compiled/hinted_cbuffer.golden @@ -0,0 +1,13 @@ +[vertex entry point] - vs_main +[constant_buffer] - props - 0 (@properties) + [field] - projection : struct : float4x4 {m11 : float, + m12 : float, m13 : float, m14 : float, m21 : float, + m22 : float, m23 : float, m24 : float, m31 : float, + m32 : float, m33 : float, m34 : float, m41 : float, + m42 : float, m43 : float, m44 : float} (@projection) + [field] - view : struct : float4x4 {m11 : float, + m12 : float, m13 : float, m14 : float, m21 : float, + m22 : float, m23 : float, m24 : float, m31 : float, + m32 : float, m33 : float, m34 : float, m41 : float, + m42 : float, m43 : float, m44 : float} (@view) + \ No newline at end of file diff --git a/test/compiled/if_def_block.golden b/test/compiled/if_def_block.golden new file mode 100644 index 0000000..8b31b1a --- /dev/null +++ b/test/compiled/if_def_block.golden @@ -0,0 +1 @@ +[pixel entry point] - ps_main diff --git a/test/compiled/if_def_expression.golden b/test/compiled/if_def_expression.golden new file mode 100644 index 0000000..10b55ea --- /dev/null +++ b/test/compiled/if_def_expression.golden @@ -0,0 +1 @@ +[vertex entry point] - vs_console_main diff --git a/test/compiled/ifdefs.golden b/test/compiled/ifdefs.golden new file mode 100644 index 0000000..f2dc725 --- /dev/null +++ b/test/compiled/ifdefs.golden @@ -0,0 +1,2 @@ +[vertex entry point] - vs_skinning_main +[pixel entry point] - ps_main diff --git a/test/complicated_computation.ink b/test/complicated_computation.ink new file mode 100644 index 0000000..6869d0c --- /dev/null +++ b/test/complicated_computation.ink @@ -0,0 +1,6 @@ +vertex main :: () { + x : float = 5.0; + y : float = 3000.0; + + z : float = y * y + x; +} diff --git a/test/constant_buffer.ink b/test/constant_buffer.ink new file mode 100644 index 0000000..c243a69 --- /dev/null +++ b/test/constant_buffer.ink @@ -0,0 +1,14 @@ +camera :: Constant_Buffer { + projection : float4x4; + view : float4x4; +} + +vertex main :: (pos : float4 @position) -> float4 @position { + mv : float4 = mul(camera.view, pos); + mvp : float4 = mul(camera.projection, mv); + return mvp; +} + +pixel main :: () -> float4 @target { + return float4(0.5, 0.5, 0.5, 1.0); +} diff --git a/test/custom_hint.ink b/test/custom_hint.ink new file mode 100644 index 0000000..69772be --- /dev/null +++ b/test/custom_hint.ink @@ -0,0 +1,12 @@ +p :: properties { + time : float @time; +} + +vertex main :: (pos : float3 @position) -> float4 @position { + return float4(pos.x, pos.y, pos.z, 1.0); +} + +pixel main :: (pos : float4 @outposition) -> float4 @target { + t := p.time; + return float4(1, 1, 1, 1); +} diff --git a/test/double_access.ink b/test/double_access.ink new file mode 100644 index 0000000..80d4dfb --- /dev/null +++ b/test/double_access.ink @@ -0,0 +1,7 @@ +p :: Constant_Buffer { + v : float2; +} + +vertex main ::() { + x : float = p.v.x / p.v.y; +} diff --git a/test/else_if_after_else.ink b/test/else_if_after_else.ink new file mode 100644 index 0000000..be4360d --- /dev/null +++ b/test/else_if_after_else.ink @@ -0,0 +1,10 @@ +vertex main :: (pos : float3 @position) -> float4 @position { + if 0 > 100 { + + } else { + + } else if 0 > 200 { + + } + return float4(0.0); +} diff --git a/test/empty_struct.ink b/test/empty_struct.ink new file mode 100644 index 0000000..6f8cdf9 --- /dev/null +++ b/test/empty_struct.ink @@ -0,0 +1,3 @@ +Foo :: struct {} + + diff --git a/test/empty_vertex_main.ink b/test/empty_vertex_main.ink new file mode 100644 index 0000000..21695c3 --- /dev/null +++ b/test/empty_vertex_main.ink @@ -0,0 +1,3 @@ +vertex main :: () { + +} \ No newline at end of file diff --git a/test/empty_vertex_main_with_position_parameter.ink b/test/empty_vertex_main_with_position_parameter.ink new file mode 100644 index 0000000..863b215 --- /dev/null +++ b/test/empty_vertex_main_with_position_parameter.ink @@ -0,0 +1,3 @@ +vertex main :: (pos : float3 @position) -> float3 { + return pos; +} diff --git a/test/field_assignment.ink b/test/field_assignment.ink new file mode 100644 index 0000000..2e493ee --- /dev/null +++ b/test/field_assignment.ink @@ -0,0 +1,6 @@ +vertex main :: (pos : float4 @position) -> float4 @position { + x : float = 5.0; + x = 7.0; + + return pos; +} diff --git a/test/field_without_type_specifier.ink b/test/field_without_type_specifier.ink new file mode 100644 index 0000000..a025c7b --- /dev/null +++ b/test/field_without_type_specifier.ink @@ -0,0 +1,3 @@ +vertex main :: () { + x := 5.0; +} diff --git a/test/float_if_cond.ink b/test/float_if_cond.ink new file mode 100644 index 0000000..9ec6373 --- /dev/null +++ b/test/float_if_cond.ink @@ -0,0 +1,6 @@ +vertex main :: (pos : float3 @position) -> float4 @position { + if 1.0 { + return float4(pos, 1.0); + } + return float4(0.0); +} diff --git a/test/float_suffix.ink b/test/float_suffix.ink new file mode 100644 index 0000000..f7fee39 --- /dev/null +++ b/test/float_suffix.ink @@ -0,0 +1,3 @@ +vertex main :: () { + x : float = 2.0f; +} diff --git a/test/for_i_loop.ink b/test/for_i_loop.ink new file mode 100644 index 0000000..c5928ee --- /dev/null +++ b/test/for_i_loop.ink @@ -0,0 +1,6 @@ +vertex main :: () { + x := 0; + for i : 0..10 { + x += 1.0; + } +} diff --git a/test/for_i_one_liner.ink b/test/for_i_one_liner.ink new file mode 100644 index 0000000..75d0401 --- /dev/null +++ b/test/for_i_one_liner.ink @@ -0,0 +1,4 @@ +vertex main :: () { + x := 0.0; + for i : 0..10 x += 2.0; +} diff --git a/test/for_index_outside.ink b/test/for_index_outside.ink new file mode 100644 index 0000000..59edbef --- /dev/null +++ b/test/for_index_outside.ink @@ -0,0 +1,7 @@ +vertex main :: () { + for i : 0..10 { + x : float; + } + + i += 1; +} diff --git a/test/for_no_iter.ink b/test/for_no_iter.ink new file mode 100644 index 0000000..3c91504 --- /dev/null +++ b/test/for_no_iter.ink @@ -0,0 +1,6 @@ +vertex main :: () { + x := 0.0; + for i : 0.. { + x += 2.0; + } +} diff --git a/test/function_call.ink b/test/function_call.ink new file mode 100644 index 0000000..bed9e80 --- /dev/null +++ b/test/function_call.ink @@ -0,0 +1,7 @@ +foo :: () -> int { + return 4; +} + +vertex main :: () { + foo(); +} diff --git a/test/function_call_out_of_order_declaration.ink b/test/function_call_out_of_order_declaration.ink new file mode 100644 index 0000000..81237d2 --- /dev/null +++ b/test/function_call_out_of_order_declaration.ink @@ -0,0 +1,7 @@ +vertex main :: () { + foo(); +} + +foo :: () { + +} diff --git a/test/function_call_return.ink b/test/function_call_return.ink new file mode 100644 index 0000000..98ca8cb --- /dev/null +++ b/test/function_call_return.ink @@ -0,0 +1,7 @@ +vertex main :: () { + +} + +pixel main :: () -> float4 @target0 { + return float4(1, 1, 1, 1); +} diff --git a/test/function_with_int_return.ink b/test/function_with_int_return.ink new file mode 100644 index 0000000..f9d0a20 --- /dev/null +++ b/test/function_with_int_return.ink @@ -0,0 +1,3 @@ +vertex main :: (pos : float3) -> int { + return 0; +} diff --git a/test/functions_with_same_name.ink b/test/functions_with_same_name.ink new file mode 100644 index 0000000..716465b --- /dev/null +++ b/test/functions_with_same_name.ink @@ -0,0 +1,7 @@ +foo :: () {} +foo :: () {} +bar :: () {} + +vertex main :: () { + +} diff --git a/test/hinted_cbuffer.ink b/test/hinted_cbuffer.ink new file mode 100644 index 0000000..969bebe --- /dev/null +++ b/test/hinted_cbuffer.ink @@ -0,0 +1,10 @@ +props :: constant_buffer @properties { + projection : float4x4 @projection; + view : float4x4 @view; +} + +vertex main :: (pos : float4 @position) -> float4 @position { + mv : float4 = mul(props.view, pos); + mvp : float4 = mul(props.projection, mv); + return mvp; +} diff --git a/test/if_cond_assign.ink b/test/if_cond_assign.ink new file mode 100644 index 0000000..7baa0fa --- /dev/null +++ b/test/if_cond_assign.ink @@ -0,0 +1,6 @@ +vertex main :: (pos : float3 @position) -> float4 @position { + if 0 = 100 { + return float4(pos, 1.0); + } + return float4(0.0); +} diff --git a/test/if_def_block.ink b/test/if_def_block.ink new file mode 100644 index 0000000..730171e --- /dev/null +++ b/test/if_def_block.ink @@ -0,0 +1,11 @@ +#add_define Alpha + +pixel main :: () { +#if Env.Alpha { + alpha_color := float4(1, 0, 0, 1); + f := 2.0; +} else { + color := float3(0, 0, 0); + g := 5.0; +} +} diff --git a/test/if_def_expression.ink b/test/if_def_expression.ink new file mode 100644 index 0000000..83c1505 --- /dev/null +++ b/test/if_def_expression.ink @@ -0,0 +1,13 @@ +#add_define PS5 +#add_define XSX +#add_define Switch2 + +#if (Env.PS5 && Env.XSX) || Env.Switch2 { + vertex console_main :: () { + + } +} else { + vertex windows_main :: () { + + } +} diff --git a/test/if_if_if.ink b/test/if_if_if.ink new file mode 100644 index 0000000..71e196e --- /dev/null +++ b/test/if_if_if.ink @@ -0,0 +1,6 @@ +vertex main :: (pos : float3 @position) -> float4 @position { + if if if 0 > 100 { + return float4(pos, 1.0); + } + return float4(0.0); +} diff --git a/test/if_no_cond.ink b/test/if_no_cond.ink new file mode 100644 index 0000000..5ebeef7 --- /dev/null +++ b/test/if_no_cond.ink @@ -0,0 +1,5 @@ +vertex main :: () { + if { + + } +} diff --git a/test/ifdefs.ink b/test/ifdefs.ink new file mode 100644 index 0000000..6ffa919 --- /dev/null +++ b/test/ifdefs.ink @@ -0,0 +1,17 @@ +#add_define Skinning +#add_define UV + + +#if Env.Skinning { + vertex skinning_main :: () { + x : float = 5.0; + } +} else #if Env.UV { + vertex texture_mapping_main :: () { + x : float2 = float2(2.0, 2.0); + } +} + +pixel main :: () { + +} diff --git a/test/inferred_types.ink b/test/inferred_types.ink new file mode 100644 index 0000000..30f8ded --- /dev/null +++ b/test/inferred_types.ink @@ -0,0 +1,17 @@ +bar :: () -> float { + return 5.0; +} + +foo :: () -> float { + return bar(); +} + +vertex main :: (pos : float3 @position) -> float4 @position { + f := 2.0; + i := 10; + f = foo(); + v2 := float2(2, 2); + v3 := float3(2, 2, 3); + v4 := float4(4, 5, 6, 7); + return float4(1, 1, 1, 1); +} \ No newline at end of file diff --git a/test/large_block.ink b/test/large_block.ink new file mode 100644 index 0000000..fd7530f --- /dev/null +++ b/test/large_block.ink @@ -0,0 +1,42 @@ +p :: Constant_Buffer @properties { + color : float4; + rect_position : float2; + rect_scale : float2; + resolution : float2; + texture : Texture2D; + sampler : Sampler; +} + +PS_Input :: struct { + uv : float2 @uv; + pos : float4 @pos; +} + +vertex main :: (pos : float4 @position) -> PS_Input { + res : float2 = p.resolution; + scale : float2 = p.rect_scale; + rect_pos : float2 = p.rect_position;; + + center : float2 = rect_pos; + half_size : float2 = float2(scale.x / 2, scale.y / 2); + dst_pos : float4 = float4(pos.x * half_size.x + center.x, pos.y * half_size.y + center.y, 0.0, 1.0); + + result : PS_Input; + + src_p0 : float2 = float2(0.0, 1.0); + src_p1 : float2 = float2(1.0, 0.0); + + src_half_size : float2 = (src_p1 - src_p0) / 2; + src_center : float2 = (src_p1 + src_p0) / 2; + src_pos : float2 = float2(pos.x, pos.y) * src_half_size + src_center; + + result.uv = float2(1, 1); + result.pos = float4(2.0 * dst_pos.x / res.x - 1, 2.0 * dst_pos.y / res.y - 1, 0.0, 1.0); + + return result; +} + +pixel main :: (input : PS_Input) -> float4 @target0 { + color : float4 = p.color; + return color; +} 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/arrays.golden b/test/lex/arrays.golden new file mode 100644 index 0000000..2312b77 --- /dev/null +++ b/test/lex/arrays.golden @@ -0,0 +1,40 @@ +{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_ARROW; ; index = 18 ; length = 2 line = 1 ; column = 18 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 21 ; length = 6 line = 1 ; column = 21 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 28 ; length = 1 line = 1 ; column = 28 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 29 ; length = 8 line = 1 ; column = 29 ; value ='position'; } +{kind = TOKEN_LEFTBRACE; ; index = 38 ; length = 1 line = 1 ; column = 38 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 42 ; length = 3 line = 2 ; column = 0 ; value ='arr'; } +{kind = TOKEN_COLON; ; index = 46 ; length = 1 line = 2 ; column = 4 ; value =':'; } +{kind = TOKEN_LEFTBRACKET; ; index = 48 ; length = 1 line = 2 ; column = 6 ; value ='['; } +{kind = TOKEN_INTLITERAL; ; index = 49 ; length = 2 line = 2 ; column = 7 ; value ='16'; } +{kind = TOKEN_RIGHTBRACKET; ; index = 51 ; length = 1 line = 2 ; column = 9 ; value =']'; } +{kind = TOKEN_DOT; ; index = 52 ; length = 1 line = 2 ; column = 10 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 53 ; length = 6 line = 2 ; column = 11 ; value ='float4'; } +{kind = TOKEN_SEMICOLON; ; index = 59 ; length = 1 line = 2 ; column = 17 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 63 ; length = 3 line = 3 ; column = 0 ; value ='arr'; } +{kind = TOKEN_LEFTBRACKET; ; index = 66 ; length = 1 line = 3 ; column = 3 ; value ='['; } +{kind = TOKEN_INTLITERAL; ; index = 67 ; length = 1 line = 3 ; column = 4 ; value ='0'; } +{kind = TOKEN_RIGHTBRACKET; ; index = 68 ; length = 1 line = 3 ; column = 5 ; value =']'; } +{kind = TOKEN_ASSIGN; ; index = 70 ; length = 1 line = 3 ; column = 7 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 72 ; length = 6 line = 3 ; column = 9 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 78 ; length = 1 line = 3 ; column = 15 ; value ='('; } +{kind = TOKEN_INTLITERAL; ; index = 79 ; length = 1 line = 3 ; column = 16 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 80 ; length = 1 line = 3 ; column = 17 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 81 ; length = 1 line = 3 ; column = 18 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 82 ; length = 1 line = 3 ; column = 19 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 83 ; length = 1 line = 3 ; column = 20 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 84 ; length = 1 line = 3 ; column = 21 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 85 ; length = 1 line = 3 ; column = 22 ; value =';'; } +{kind = TOKEN_RETURN; ; index = 89 ; length = 6 line = 4 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 96 ; length = 3 line = 4 ; column = 7 ; value ='arr'; } +{kind = TOKEN_LEFTBRACKET; ; index = 99 ; length = 1 line = 4 ; column = 10 ; value ='['; } +{kind = TOKEN_INTLITERAL; ; index = 100 ; length = 1 line = 4 ; column = 11 ; value ='0'; } +{kind = TOKEN_RIGHTBRACKET; ; index = 101 ; length = 1 line = 4 ; column = 12 ; value =']'; } +{kind = TOKEN_SEMICOLON; ; index = 102 ; length = 1 line = 4 ; column = 13 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 105 ; length = 1 line = 5 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 108 ; length = 0 line = 6 ; column = 0 ; value =''; } diff --git a/test/lex/assign_arithmetic_expression.golden b/test/lex/assign_arithmetic_expression.golden new file mode 100644 index 0000000..d687b92 --- /dev/null +++ b/test/lex/assign_arithmetic_expression.golden @@ -0,0 +1,16 @@ +{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 ='x'; } +{kind = TOKEN_COLON; ; index = 24 ; length = 1 line = 2 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 26 ; length = 5 line = 2 ; column = 4 ; value ='float'; } +{kind = TOKEN_ASSIGN; ; index = 32 ; length = 1 line = 2 ; column = 10 ; value ='='; } +{kind = TOKEN_FLOATLITERAL; ; index = 34 ; length = 3 line = 2 ; column = 12 ; value ='2'; } +{kind = TOKEN_PLUS; ; index = 38 ; length = 1 line = 2 ; column = 16 ; value ='+'; } +{kind = TOKEN_FLOATLITERAL; ; index = 40 ; length = 3 line = 2 ; column = 18 ; value ='5'; } +{kind = TOKEN_SEMICOLON; ; index = 43 ; length = 1 line = 2 ; column = 21 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 46 ; length = 1 line = 3 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 49 ; length = 0 line = 4 ; 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/basic_property_and_return_value.golden b/test/lex/basic_property_and_return_value.golden new file mode 100644 index 0000000..a0cfb9f --- /dev/null +++ b/test/lex/basic_property_and_return_value.golden @@ -0,0 +1,47 @@ +{kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 10 line = 1 ; column = 0 ; value ='properties'; } +{kind = TOKEN_DOUBLECOLON; ; index = 11 ; length = 2 line = 1 ; column = 11 ; value ='::'; } +{kind = TOKEN_CONSTANT_BUFFER; ; index = 14 ; length = 15 line = 1 ; column = 14 ; value ='Constant_Buffer'; } +{kind = TOKEN_AT; ; index = 30 ; length = 1 line = 1 ; column = 30 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 31 ; length = 10 line = 1 ; column = 31 ; value ='properties'; } +{kind = TOKEN_LEFTBRACE; ; index = 42 ; length = 1 line = 1 ; column = 42 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 46 ; length = 5 line = 2 ; column = 0 ; value ='color'; } +{kind = TOKEN_COLON; ; index = 52 ; length = 1 line = 2 ; column = 6 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 54 ; length = 6 line = 2 ; column = 8 ; value ='float4'; } +{kind = TOKEN_SEMICOLON; ; index = 60 ; length = 1 line = 2 ; column = 14 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 63 ; length = 1 line = 3 ; column = 0 ; value ='}'; } +{kind = TOKEN_VERTEX; ; index = 68 ; length = 6 line = 5 ; column = 0 ; value ='vertex'; } +{kind = TOKEN_IDENTIFIER; ; index = 75 ; length = 4 line = 5 ; column = 7 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 80 ; length = 2 line = 5 ; column = 12 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 83 ; length = 1 line = 5 ; column = 15 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 84 ; length = 3 line = 5 ; column = 16 ; value ='pos'; } +{kind = TOKEN_COLON; ; index = 88 ; length = 1 line = 5 ; column = 20 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 90 ; length = 6 line = 5 ; column = 22 ; value ='float3'; } +{kind = TOKEN_AT; ; index = 97 ; length = 1 line = 5 ; column = 29 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 98 ; length = 8 line = 5 ; column = 30 ; value ='position'; } +{kind = TOKEN_RIGHTPAREN; ; index = 106 ; length = 1 line = 5 ; column = 38 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 108 ; length = 2 line = 5 ; column = 40 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 111 ; length = 6 line = 5 ; column = 43 ; value ='float3'; } +{kind = TOKEN_AT; ; index = 118 ; length = 1 line = 5 ; column = 50 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 119 ; length = 8 line = 5 ; column = 51 ; value ='position'; } +{kind = TOKEN_LEFTBRACE; ; index = 128 ; length = 1 line = 5 ; column = 60 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 134 ; length = 6 line = 6 ; column = 2 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 141 ; length = 3 line = 6 ; column = 9 ; value ='pos'; } +{kind = TOKEN_SEMICOLON; ; index = 144 ; length = 1 line = 6 ; column = 12 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 147 ; length = 1 line = 7 ; column = 0 ; value ='}'; } +{kind = TOKEN_PIXEL; ; index = 152 ; length = 5 line = 9 ; column = 0 ; value ='pixel'; } +{kind = TOKEN_IDENTIFIER; ; index = 158 ; length = 4 line = 9 ; column = 6 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 163 ; length = 2 line = 9 ; column = 11 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 166 ; length = 1 line = 9 ; column = 14 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 167 ; length = 1 line = 9 ; column = 15 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 169 ; length = 2 line = 9 ; column = 17 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 172 ; length = 6 line = 9 ; column = 20 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 179 ; length = 1 line = 9 ; column = 27 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 180 ; length = 7 line = 9 ; column = 28 ; value ='target0'; } +{kind = TOKEN_LEFTBRACE; ; index = 188 ; length = 1 line = 9 ; column = 36 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 194 ; length = 6 line = 10 ; column = 2 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 201 ; length = 10 line = 10 ; column = 9 ; value ='properties'; } +{kind = TOKEN_DOT; ; index = 211 ; length = 1 line = 10 ; column = 19 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 212 ; length = 5 line = 10 ; column = 20 ; value ='color'; } +{kind = TOKEN_SEMICOLON; ; index = 217 ; length = 1 line = 10 ; column = 25 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 220 ; length = 1 line = 11 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 223 ; length = 0 line = 12 ; column = 0 ; value =''; } diff --git a/test/lex/builtin_types.golden b/test/lex/builtin_types.golden new file mode 100644 index 0000000..27fece7 --- /dev/null +++ b/test/lex/builtin_types.golden @@ -0,0 +1,223 @@ +{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 = 2 line = 2 ; column = 0 ; value ='v2'; } +{kind = TOKEN_COLON; ; index = 25 ; length = 1 line = 2 ; column = 3 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 27 ; length = 6 line = 2 ; column = 5 ; value ='float2'; } +{kind = TOKEN_ASSIGN; ; index = 34 ; length = 1 line = 2 ; column = 12 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 36 ; length = 6 line = 2 ; column = 14 ; value ='float2'; } +{kind = TOKEN_LEFTPAREN; ; index = 42 ; length = 1 line = 2 ; column = 20 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 43 ; length = 3 line = 2 ; column = 21 ; value ='2'; } +{kind = TOKEN_COMMA; ; index = 46 ; length = 1 line = 2 ; column = 24 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 48 ; length = 3 line = 2 ; column = 26 ; value ='2'; } +{kind = TOKEN_RIGHTPAREN; ; index = 51 ; length = 1 line = 2 ; column = 29 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 52 ; length = 1 line = 2 ; column = 30 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 56 ; length = 2 line = 3 ; column = 0 ; value ='v2'; } +{kind = TOKEN_ASSIGN; ; index = 59 ; length = 1 line = 3 ; column = 3 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 61 ; length = 6 line = 3 ; column = 5 ; value ='float2'; } +{kind = TOKEN_LEFTPAREN; ; index = 67 ; length = 1 line = 3 ; column = 11 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 68 ; length = 3 line = 3 ; column = 12 ; value ='2'; } +{kind = TOKEN_RIGHTPAREN; ; index = 71 ; length = 1 line = 3 ; column = 15 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 72 ; length = 1 line = 3 ; column = 16 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 76 ; length = 2 line = 4 ; column = 0 ; value ='v2'; } +{kind = TOKEN_ASSIGN; ; index = 79 ; length = 1 line = 4 ; column = 3 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 81 ; length = 6 line = 4 ; column = 5 ; value ='float2'; } +{kind = TOKEN_LEFTPAREN; ; index = 87 ; length = 1 line = 4 ; column = 11 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 88 ; length = 2 line = 4 ; column = 12 ; value ='v2'; } +{kind = TOKEN_RIGHTPAREN; ; index = 90 ; length = 1 line = 4 ; column = 14 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 91 ; length = 1 line = 4 ; column = 15 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 97 ; length = 2 line = 6 ; column = 0 ; value ='v3'; } +{kind = TOKEN_COLON; ; index = 100 ; length = 1 line = 6 ; column = 3 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 102 ; length = 6 line = 6 ; column = 5 ; value ='float3'; } +{kind = TOKEN_ASSIGN; ; index = 109 ; length = 1 line = 6 ; column = 12 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 111 ; length = 6 line = 6 ; column = 14 ; value ='float3'; } +{kind = TOKEN_LEFTPAREN; ; index = 117 ; length = 1 line = 6 ; column = 20 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 118 ; length = 3 line = 6 ; column = 21 ; value ='2'; } +{kind = TOKEN_COMMA; ; index = 121 ; length = 1 line = 6 ; column = 24 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 123 ; length = 3 line = 6 ; column = 26 ; value ='2'; } +{kind = TOKEN_COMMA; ; index = 126 ; length = 1 line = 6 ; column = 29 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 128 ; length = 3 line = 6 ; column = 31 ; value ='2'; } +{kind = TOKEN_RIGHTPAREN; ; index = 131 ; length = 1 line = 6 ; column = 34 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 132 ; length = 1 line = 6 ; column = 35 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 136 ; length = 2 line = 7 ; column = 0 ; value ='v3'; } +{kind = TOKEN_ASSIGN; ; index = 139 ; length = 1 line = 7 ; column = 3 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 141 ; length = 6 line = 7 ; column = 5 ; value ='float3'; } +{kind = TOKEN_LEFTPAREN; ; index = 147 ; length = 1 line = 7 ; column = 11 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 148 ; length = 2 line = 7 ; column = 12 ; value ='v2'; } +{kind = TOKEN_COMMA; ; index = 150 ; length = 1 line = 7 ; column = 14 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 152 ; length = 3 line = 7 ; column = 16 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 155 ; length = 1 line = 7 ; column = 19 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 156 ; length = 1 line = 7 ; column = 20 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 160 ; length = 2 line = 8 ; column = 0 ; value ='v3'; } +{kind = TOKEN_ASSIGN; ; index = 163 ; length = 1 line = 8 ; column = 3 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 165 ; length = 6 line = 8 ; column = 5 ; value ='float3'; } +{kind = TOKEN_LEFTPAREN; ; index = 171 ; length = 1 line = 8 ; column = 11 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 172 ; length = 3 line = 8 ; column = 12 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 175 ; length = 1 line = 8 ; column = 15 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 177 ; length = 2 line = 8 ; column = 17 ; value ='v2'; } +{kind = TOKEN_RIGHTPAREN; ; index = 179 ; length = 1 line = 8 ; column = 19 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 180 ; length = 1 line = 8 ; column = 20 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 184 ; length = 2 line = 9 ; column = 0 ; value ='v3'; } +{kind = TOKEN_ASSIGN; ; index = 187 ; length = 1 line = 9 ; column = 3 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 189 ; length = 6 line = 9 ; column = 5 ; value ='float3'; } +{kind = TOKEN_LEFTPAREN; ; index = 195 ; length = 1 line = 9 ; column = 11 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 196 ; length = 3 line = 9 ; column = 12 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 199 ; length = 1 line = 9 ; column = 15 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 200 ; length = 1 line = 9 ; column = 16 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 204 ; length = 2 line = 10 ; column = 0 ; value ='v3'; } +{kind = TOKEN_ASSIGN; ; index = 207 ; length = 1 line = 10 ; column = 3 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 209 ; length = 6 line = 10 ; column = 5 ; value ='float3'; } +{kind = TOKEN_LEFTPAREN; ; index = 215 ; length = 1 line = 10 ; column = 11 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 216 ; length = 2 line = 10 ; column = 12 ; value ='v3'; } +{kind = TOKEN_RIGHTPAREN; ; index = 218 ; length = 1 line = 10 ; column = 14 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 219 ; length = 1 line = 10 ; column = 15 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 226 ; length = 2 line = 12 ; column = 0 ; value ='v4'; } +{kind = TOKEN_COLON; ; index = 229 ; length = 1 line = 12 ; column = 3 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 231 ; length = 6 line = 12 ; column = 5 ; value ='float4'; } +{kind = TOKEN_ASSIGN; ; index = 238 ; length = 1 line = 12 ; column = 12 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 240 ; length = 6 line = 12 ; column = 14 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 246 ; length = 1 line = 12 ; column = 20 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 247 ; length = 3 line = 12 ; column = 21 ; value ='2'; } +{kind = TOKEN_COMMA; ; index = 250 ; length = 1 line = 12 ; column = 24 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 252 ; length = 3 line = 12 ; column = 26 ; value ='2'; } +{kind = TOKEN_COMMA; ; index = 255 ; length = 1 line = 12 ; column = 29 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 257 ; length = 3 line = 12 ; column = 31 ; value ='2'; } +{kind = TOKEN_COMMA; ; index = 260 ; length = 1 line = 12 ; column = 34 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 262 ; length = 3 line = 12 ; column = 36 ; value ='2'; } +{kind = TOKEN_RIGHTPAREN; ; index = 265 ; length = 1 line = 12 ; column = 39 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 266 ; length = 1 line = 12 ; column = 40 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 270 ; length = 2 line = 13 ; column = 0 ; value ='v4'; } +{kind = TOKEN_ASSIGN; ; index = 273 ; length = 1 line = 13 ; column = 3 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 275 ; length = 6 line = 13 ; column = 5 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 281 ; length = 1 line = 13 ; column = 11 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 282 ; length = 2 line = 13 ; column = 12 ; value ='v4'; } +{kind = TOKEN_RIGHTPAREN; ; index = 284 ; length = 1 line = 13 ; column = 14 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 285 ; length = 1 line = 13 ; column = 15 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 289 ; length = 2 line = 14 ; column = 0 ; value ='v4'; } +{kind = TOKEN_ASSIGN; ; index = 292 ; length = 1 line = 14 ; column = 3 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 294 ; length = 6 line = 14 ; column = 5 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 300 ; length = 1 line = 14 ; column = 11 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 301 ; length = 2 line = 14 ; column = 12 ; value ='v2'; } +{kind = TOKEN_COMMA; ; index = 303 ; length = 1 line = 14 ; column = 14 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 305 ; length = 2 line = 14 ; column = 16 ; value ='v2'; } +{kind = TOKEN_RIGHTPAREN; ; index = 307 ; length = 1 line = 14 ; column = 18 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 308 ; length = 1 line = 14 ; column = 19 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 312 ; length = 2 line = 15 ; column = 0 ; value ='v4'; } +{kind = TOKEN_ASSIGN; ; index = 315 ; length = 1 line = 15 ; column = 3 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 317 ; length = 6 line = 15 ; column = 5 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 323 ; length = 1 line = 15 ; column = 11 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 324 ; length = 2 line = 15 ; column = 12 ; value ='v2'; } +{kind = TOKEN_COMMA; ; index = 326 ; length = 1 line = 15 ; column = 14 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 328 ; length = 3 line = 15 ; column = 16 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 331 ; length = 1 line = 15 ; column = 19 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 333 ; length = 3 line = 15 ; column = 21 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 336 ; length = 1 line = 15 ; column = 24 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 337 ; length = 1 line = 15 ; column = 25 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 341 ; length = 2 line = 16 ; column = 0 ; value ='v4'; } +{kind = TOKEN_ASSIGN; ; index = 344 ; length = 1 line = 16 ; column = 3 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 346 ; length = 6 line = 16 ; column = 5 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 352 ; length = 1 line = 16 ; column = 11 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 353 ; length = 3 line = 16 ; column = 12 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 356 ; length = 1 line = 16 ; column = 15 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 358 ; length = 2 line = 16 ; column = 17 ; value ='v2'; } +{kind = TOKEN_COMMA; ; index = 360 ; length = 1 line = 16 ; column = 19 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 362 ; length = 3 line = 16 ; column = 21 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 365 ; length = 1 line = 16 ; column = 24 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 366 ; length = 1 line = 16 ; column = 25 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 370 ; length = 2 line = 17 ; column = 0 ; value ='v4'; } +{kind = TOKEN_ASSIGN; ; index = 373 ; length = 1 line = 17 ; column = 3 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 375 ; length = 6 line = 17 ; column = 5 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 381 ; length = 1 line = 17 ; column = 11 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 382 ; length = 3 line = 17 ; column = 12 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 385 ; length = 1 line = 17 ; column = 15 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 387 ; length = 3 line = 17 ; column = 17 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 390 ; length = 1 line = 17 ; column = 20 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 392 ; length = 2 line = 17 ; column = 22 ; value ='v2'; } +{kind = TOKEN_RIGHTPAREN; ; index = 394 ; length = 1 line = 17 ; column = 24 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 395 ; length = 1 line = 17 ; column = 25 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 399 ; length = 2 line = 18 ; column = 0 ; value ='v4'; } +{kind = TOKEN_ASSIGN; ; index = 402 ; length = 1 line = 18 ; column = 3 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 404 ; length = 6 line = 18 ; column = 5 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 410 ; length = 1 line = 18 ; column = 11 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 411 ; length = 2 line = 18 ; column = 12 ; value ='v3'; } +{kind = TOKEN_COMMA; ; index = 413 ; length = 1 line = 18 ; column = 14 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 415 ; length = 3 line = 18 ; column = 16 ; value ='2'; } +{kind = TOKEN_RIGHTPAREN; ; index = 418 ; length = 1 line = 18 ; column = 19 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 419 ; length = 1 line = 18 ; column = 20 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 423 ; length = 2 line = 19 ; column = 0 ; value ='v4'; } +{kind = TOKEN_ASSIGN; ; index = 426 ; length = 1 line = 19 ; column = 3 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 428 ; length = 6 line = 19 ; column = 5 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 434 ; length = 1 line = 19 ; column = 11 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 435 ; length = 3 line = 19 ; column = 12 ; value ='2'; } +{kind = TOKEN_COMMA; ; index = 438 ; length = 1 line = 19 ; column = 15 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 440 ; length = 2 line = 19 ; column = 17 ; value ='v3'; } +{kind = TOKEN_RIGHTPAREN; ; index = 442 ; length = 1 line = 19 ; column = 19 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 443 ; length = 1 line = 19 ; column = 20 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 447 ; length = 2 line = 20 ; column = 0 ; value ='v4'; } +{kind = TOKEN_ASSIGN; ; index = 450 ; length = 1 line = 20 ; column = 3 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 452 ; length = 6 line = 20 ; column = 5 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 458 ; length = 1 line = 20 ; column = 11 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 459 ; length = 3 line = 20 ; column = 12 ; value ='2'; } +{kind = TOKEN_RIGHTPAREN; ; index = 462 ; length = 1 line = 20 ; column = 15 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 463 ; length = 1 line = 20 ; column = 16 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 472 ; length = 2 line = 23 ; column = 0 ; value ='v4'; } +{kind = TOKEN_ASSIGN; ; index = 475 ; length = 1 line = 23 ; column = 3 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 477 ; length = 6 line = 23 ; column = 5 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 483 ; length = 1 line = 23 ; column = 11 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 484 ; length = 3 line = 23 ; column = 12 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 487 ; length = 1 line = 23 ; column = 15 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 489 ; length = 3 line = 23 ; column = 17 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 492 ; length = 1 line = 23 ; column = 20 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 494 ; length = 2 line = 23 ; column = 22 ; value ='v2'; } +{kind = TOKEN_RIGHTPAREN; ; index = 496 ; length = 1 line = 23 ; column = 24 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 497 ; length = 1 line = 23 ; column = 25 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 501 ; length = 2 line = 24 ; column = 0 ; value ='v4'; } +{kind = TOKEN_ASSIGN; ; index = 504 ; length = 1 line = 24 ; column = 3 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 506 ; length = 6 line = 24 ; column = 5 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 512 ; length = 1 line = 24 ; column = 11 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 513 ; length = 3 line = 24 ; column = 12 ; value ='2'; } +{kind = TOKEN_RIGHTPAREN; ; index = 516 ; length = 1 line = 24 ; column = 15 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 517 ; length = 1 line = 24 ; column = 16 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 524 ; length = 2 line = 26 ; column = 0 ; value ='v2'; } +{kind = TOKEN_DOT; ; index = 526 ; length = 1 line = 26 ; column = 2 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 527 ; length = 1 line = 26 ; column = 3 ; value ='x'; } +{kind = TOKEN_ASSIGN; ; index = 529 ; length = 1 line = 26 ; column = 5 ; value ='='; } +{kind = TOKEN_FLOATLITERAL; ; index = 531 ; length = 3 line = 26 ; column = 7 ; value ='2'; } +{kind = TOKEN_SEMICOLON; ; index = 534 ; length = 1 line = 26 ; column = 10 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 538 ; length = 2 line = 27 ; column = 0 ; value ='v2'; } +{kind = TOKEN_DOT; ; index = 540 ; length = 1 line = 27 ; column = 2 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 541 ; length = 1 line = 27 ; column = 3 ; value ='y'; } +{kind = TOKEN_ASSIGN; ; index = 543 ; length = 1 line = 27 ; column = 5 ; value ='='; } +{kind = TOKEN_FLOATLITERAL; ; index = 545 ; length = 3 line = 27 ; column = 7 ; value ='2'; } +{kind = TOKEN_SEMICOLON; ; index = 548 ; length = 1 line = 27 ; column = 10 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 554 ; length = 1 line = 29 ; column = 0 ; value ='p'; } +{kind = TOKEN_COLON; ; index = 556 ; length = 1 line = 29 ; column = 2 ; value =':'; } +{kind = TOKEN_ASSIGN; ; index = 557 ; length = 1 line = 29 ; column = 3 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 559 ; length = 2 line = 29 ; column = 5 ; value ='v2'; } +{kind = TOKEN_DOT; ; index = 561 ; length = 1 line = 29 ; column = 7 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 562 ; length = 1 line = 29 ; column = 8 ; value ='x'; } +{kind = TOKEN_PLUS; ; index = 564 ; length = 1 line = 29 ; column = 10 ; value ='+'; } +{kind = TOKEN_IDENTIFIER; ; index = 566 ; length = 2 line = 29 ; column = 12 ; value ='v3'; } +{kind = TOKEN_DOT; ; index = 568 ; length = 1 line = 29 ; column = 14 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 569 ; length = 1 line = 29 ; column = 15 ; value ='z'; } +{kind = TOKEN_SEMICOLON; ; index = 570 ; length = 1 line = 29 ; column = 16 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 574 ; length = 1 line = 30 ; column = 0 ; value ='q'; } +{kind = TOKEN_COLON; ; index = 576 ; length = 1 line = 30 ; column = 2 ; value =':'; } +{kind = TOKEN_ASSIGN; ; index = 577 ; length = 1 line = 30 ; column = 3 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 579 ; length = 2 line = 30 ; column = 5 ; value ='v4'; } +{kind = TOKEN_DOT; ; index = 581 ; length = 1 line = 30 ; column = 7 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 582 ; length = 1 line = 30 ; column = 8 ; value ='w'; } +{kind = TOKEN_PLUS; ; index = 584 ; length = 1 line = 30 ; column = 10 ; value ='+'; } +{kind = TOKEN_IDENTIFIER; ; index = 586 ; length = 2 line = 30 ; column = 12 ; value ='v2'; } +{kind = TOKEN_DOT; ; index = 588 ; length = 1 line = 30 ; column = 14 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 589 ; length = 1 line = 30 ; column = 15 ; value ='x'; } +{kind = TOKEN_SEMICOLON; ; index = 590 ; length = 1 line = 30 ; column = 16 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 596 ; length = 1 line = 32 ; column = 0 ; value ='m'; } +{kind = TOKEN_COLON; ; index = 598 ; length = 1 line = 32 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 600 ; length = 8 line = 32 ; column = 4 ; value ='float4x4'; } +{kind = TOKEN_SEMICOLON; ; index = 608 ; length = 1 line = 32 ; column = 12 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 614 ; length = 1 line = 34 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 617 ; length = 0 line = 35 ; column = 0 ; value =''; } diff --git a/test/lex/colorful_circle.golden b/test/lex/colorful_circle.golden new file mode 100644 index 0000000..222b72a --- /dev/null +++ b/test/lex/colorful_circle.golden @@ -0,0 +1,297 @@ +{kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 4 line = 1 ; column = 0 ; value ='prop'; } +{kind = TOKEN_DOUBLECOLON; ; index = 5 ; length = 2 line = 1 ; column = 5 ; value ='::'; } +{kind = TOKEN_PROPERTIES; ; index = 8 ; length = 10 line = 1 ; column = 8 ; value ='properties'; } +{kind = TOKEN_LEFTBRACE; ; index = 19 ; length = 1 line = 1 ; column = 19 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 23 ; length = 4 line = 2 ; column = 0 ; value ='time'; } +{kind = TOKEN_COLON; ; index = 28 ; length = 1 line = 2 ; column = 5 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 30 ; length = 5 line = 2 ; column = 7 ; value ='float'; } +{kind = TOKEN_AT; ; index = 36 ; length = 1 line = 2 ; column = 13 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 37 ; length = 4 line = 2 ; column = 14 ; value ='time'; } +{kind = TOKEN_SEMICOLON; ; index = 41 ; length = 1 line = 2 ; column = 18 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 45 ; length = 10 line = 3 ; column = 0 ; value ='resolution'; } +{kind = TOKEN_COLON; ; index = 56 ; length = 1 line = 3 ; column = 11 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 58 ; length = 6 line = 3 ; column = 13 ; value ='float2'; } +{kind = TOKEN_AT; ; index = 65 ; length = 1 line = 3 ; column = 20 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 66 ; length = 10 line = 3 ; column = 21 ; value ='resolution'; } +{kind = TOKEN_SEMICOLON; ; index = 76 ; length = 1 line = 3 ; column = 31 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 79 ; length = 1 line = 4 ; column = 0 ; value ='}'; } +{kind = TOKEN_VERTEX; ; index = 84 ; length = 6 line = 6 ; column = 0 ; value ='vertex'; } +{kind = TOKEN_IDENTIFIER; ; index = 91 ; length = 4 line = 6 ; column = 7 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 96 ; length = 2 line = 6 ; column = 12 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 99 ; length = 1 line = 6 ; column = 15 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 100 ; length = 3 line = 6 ; column = 16 ; value ='pos'; } +{kind = TOKEN_COLON; ; index = 104 ; length = 1 line = 6 ; column = 20 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 106 ; length = 6 line = 6 ; column = 22 ; value ='float3'; } +{kind = TOKEN_AT; ; index = 113 ; length = 1 line = 6 ; column = 29 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 114 ; length = 8 line = 6 ; column = 30 ; value ='position'; } +{kind = TOKEN_RIGHTPAREN; ; index = 122 ; length = 1 line = 6 ; column = 38 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 124 ; length = 2 line = 6 ; column = 40 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 127 ; length = 6 line = 6 ; column = 43 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 134 ; length = 1 line = 6 ; column = 50 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 135 ; length = 8 line = 6 ; column = 51 ; value ='position'; } +{kind = TOKEN_LEFTBRACE; ; index = 144 ; length = 1 line = 6 ; column = 60 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 148 ; length = 6 line = 7 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 155 ; length = 6 line = 7 ; column = 7 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 161 ; length = 1 line = 7 ; column = 13 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 162 ; length = 3 line = 7 ; column = 14 ; value ='pos'; } +{kind = TOKEN_COMMA; ; index = 165 ; length = 1 line = 7 ; column = 17 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 167 ; length = 3 line = 7 ; column = 19 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 170 ; length = 1 line = 7 ; column = 22 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 171 ; length = 1 line = 7 ; column = 23 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 174 ; length = 1 line = 8 ; column = 0 ; value ='}'; } +{kind = TOKEN_PIXEL; ; index = 179 ; length = 5 line = 10 ; column = 0 ; value ='pixel'; } +{kind = TOKEN_IDENTIFIER; ; index = 185 ; length = 4 line = 10 ; column = 6 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 190 ; length = 2 line = 10 ; column = 11 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 193 ; length = 1 line = 10 ; column = 14 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 194 ; length = 3 line = 10 ; column = 15 ; value ='pos'; } +{kind = TOKEN_COLON; ; index = 198 ; length = 1 line = 10 ; column = 19 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 200 ; length = 6 line = 10 ; column = 21 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 207 ; length = 1 line = 10 ; column = 28 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 208 ; length = 11 line = 10 ; column = 29 ; value ='outposition'; } +{kind = TOKEN_RIGHTPAREN; ; index = 219 ; length = 1 line = 10 ; column = 40 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 221 ; length = 2 line = 10 ; column = 42 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 224 ; length = 6 line = 10 ; column = 45 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 231 ; length = 1 line = 10 ; column = 52 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 232 ; length = 6 line = 10 ; column = 53 ; value ='target'; } +{kind = TOKEN_LEFTBRACE; ; index = 239 ; length = 1 line = 10 ; column = 60 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 243 ; length = 1 line = 11 ; column = 0 ; value ='p'; } +{kind = TOKEN_COLON; ; index = 245 ; length = 1 line = 11 ; column = 2 ; value =':'; } +{kind = TOKEN_ASSIGN; ; index = 246 ; length = 1 line = 11 ; column = 3 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 248 ; length = 6 line = 11 ; column = 5 ; value ='float2'; } +{kind = TOKEN_LEFTPAREN; ; index = 254 ; length = 1 line = 11 ; column = 11 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 255 ; length = 3 line = 11 ; column = 12 ; value ='2'; } +{kind = TOKEN_STAR; ; index = 259 ; length = 1 line = 11 ; column = 16 ; value ='*'; } +{kind = TOKEN_IDENTIFIER; ; index = 261 ; length = 3 line = 11 ; column = 18 ; value ='pos'; } +{kind = TOKEN_DOT; ; index = 264 ; length = 1 line = 11 ; column = 21 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 265 ; length = 1 line = 11 ; column = 22 ; value ='x'; } +{kind = TOKEN_MINUS; ; index = 267 ; length = 1 line = 11 ; column = 24 ; value ='-'; } +{kind = TOKEN_IDENTIFIER; ; index = 269 ; length = 4 line = 11 ; column = 26 ; value ='prop'; } +{kind = TOKEN_DOT; ; index = 273 ; length = 1 line = 11 ; column = 30 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 274 ; length = 10 line = 11 ; column = 31 ; value ='resolution'; } +{kind = TOKEN_DOT; ; index = 284 ; length = 1 line = 11 ; column = 41 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 285 ; length = 1 line = 11 ; column = 42 ; value ='x'; } +{kind = TOKEN_COMMA; ; index = 286 ; length = 1 line = 11 ; column = 43 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 288 ; length = 3 line = 11 ; column = 45 ; value ='2'; } +{kind = TOKEN_STAR; ; index = 292 ; length = 1 line = 11 ; column = 49 ; value ='*'; } +{kind = TOKEN_IDENTIFIER; ; index = 294 ; length = 3 line = 11 ; column = 51 ; value ='pos'; } +{kind = TOKEN_DOT; ; index = 297 ; length = 1 line = 11 ; column = 54 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 298 ; length = 1 line = 11 ; column = 55 ; value ='y'; } +{kind = TOKEN_MINUS; ; index = 300 ; length = 1 line = 11 ; column = 57 ; value ='-'; } +{kind = TOKEN_IDENTIFIER; ; index = 302 ; length = 4 line = 11 ; column = 59 ; value ='prop'; } +{kind = TOKEN_DOT; ; index = 306 ; length = 1 line = 11 ; column = 63 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 307 ; length = 10 line = 11 ; column = 64 ; value ='resolution'; } +{kind = TOKEN_DOT; ; index = 317 ; length = 1 line = 11 ; column = 74 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 318 ; length = 1 line = 11 ; column = 75 ; value ='y'; } +{kind = TOKEN_RIGHTPAREN; ; index = 319 ; length = 1 line = 11 ; column = 76 ; value =')'; } +{kind = TOKEN_SLASH; ; index = 321 ; length = 1 line = 11 ; column = 78 ; value ='/'; } +{kind = TOKEN_IDENTIFIER; ; index = 323 ; length = 4 line = 11 ; column = 80 ; value ='prop'; } +{kind = TOKEN_DOT; ; index = 327 ; length = 1 line = 11 ; column = 84 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 328 ; length = 10 line = 11 ; column = 85 ; value ='resolution'; } +{kind = TOKEN_DOT; ; index = 338 ; length = 1 line = 11 ; column = 95 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 339 ; length = 1 line = 11 ; column = 96 ; value ='y'; } +{kind = TOKEN_SEMICOLON; ; index = 340 ; length = 1 line = 11 ; column = 97 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 344 ; length = 3 line = 12 ; column = 0 ; value ='tau'; } +{kind = TOKEN_COLON; ; index = 348 ; length = 1 line = 12 ; column = 4 ; value =':'; } +{kind = TOKEN_ASSIGN; ; index = 349 ; length = 1 line = 12 ; column = 5 ; value ='='; } +{kind = TOKEN_FLOATLITERAL; ; index = 351 ; length = 12 line = 12 ; column = 7 ; value ='3.141593'; } +{kind = TOKEN_STAR; ; index = 364 ; length = 1 line = 12 ; column = 20 ; value ='*'; } +{kind = TOKEN_FLOATLITERAL; ; index = 366 ; length = 3 line = 12 ; column = 22 ; value ='2'; } +{kind = TOKEN_SEMICOLON; ; index = 369 ; length = 1 line = 12 ; column = 25 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 373 ; length = 1 line = 13 ; column = 0 ; value ='a'; } +{kind = TOKEN_COLON; ; index = 375 ; length = 1 line = 13 ; column = 2 ; value =':'; } +{kind = TOKEN_ASSIGN; ; index = 376 ; length = 1 line = 13 ; column = 3 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 378 ; length = 4 line = 13 ; column = 5 ; value ='atan'; } +{kind = TOKEN_LEFTPAREN; ; index = 382 ; length = 1 line = 13 ; column = 9 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 383 ; length = 1 line = 13 ; column = 10 ; value ='p'; } +{kind = TOKEN_DOT; ; index = 384 ; length = 1 line = 13 ; column = 11 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 385 ; length = 1 line = 13 ; column = 12 ; value ='x'; } +{kind = TOKEN_COMMA; ; index = 386 ; length = 1 line = 13 ; column = 13 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 388 ; length = 1 line = 13 ; column = 15 ; value ='p'; } +{kind = TOKEN_DOT; ; index = 389 ; length = 1 line = 13 ; column = 16 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 390 ; length = 1 line = 13 ; column = 17 ; value ='y'; } +{kind = TOKEN_RIGHTPAREN; ; index = 391 ; length = 1 line = 13 ; column = 18 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 392 ; length = 1 line = 13 ; column = 19 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 396 ; length = 1 line = 14 ; column = 0 ; value ='r'; } +{kind = TOKEN_COLON; ; index = 398 ; length = 1 line = 14 ; column = 2 ; value =':'; } +{kind = TOKEN_ASSIGN; ; index = 399 ; length = 1 line = 14 ; column = 3 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 401 ; length = 6 line = 14 ; column = 5 ; value ='length'; } +{kind = TOKEN_LEFTPAREN; ; index = 407 ; length = 1 line = 14 ; column = 11 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 408 ; length = 1 line = 14 ; column = 12 ; value ='p'; } +{kind = TOKEN_RIGHTPAREN; ; index = 409 ; length = 1 line = 14 ; column = 13 ; value =')'; } +{kind = TOKEN_STAR; ; index = 411 ; length = 1 line = 14 ; column = 15 ; value ='*'; } +{kind = TOKEN_FLOATLITERAL; ; index = 413 ; length = 4 line = 14 ; column = 17 ; value ='0.75'; } +{kind = TOKEN_SEMICOLON; ; index = 417 ; length = 1 line = 14 ; column = 21 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 423 ; length = 2 line = 16 ; column = 0 ; value ='uv'; } +{kind = TOKEN_COLON; ; index = 426 ; length = 1 line = 16 ; column = 3 ; value =':'; } +{kind = TOKEN_ASSIGN; ; index = 427 ; length = 1 line = 16 ; column = 4 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 429 ; length = 6 line = 16 ; column = 6 ; value ='float2'; } +{kind = TOKEN_LEFTPAREN; ; index = 435 ; length = 1 line = 16 ; column = 12 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 436 ; length = 1 line = 16 ; column = 13 ; value ='a'; } +{kind = TOKEN_SLASH; ; index = 438 ; length = 1 line = 16 ; column = 15 ; value ='/'; } +{kind = TOKEN_IDENTIFIER; ; index = 440 ; length = 3 line = 16 ; column = 17 ; value ='tau'; } +{kind = TOKEN_COMMA; ; index = 443 ; length = 1 line = 16 ; column = 20 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 445 ; length = 1 line = 16 ; column = 22 ; value ='r'; } +{kind = TOKEN_RIGHTPAREN; ; index = 446 ; length = 1 line = 16 ; column = 23 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 447 ; length = 1 line = 16 ; column = 24 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 453 ; length = 5 line = 18 ; column = 0 ; value ='x_col'; } +{kind = TOKEN_COLON; ; index = 459 ; length = 1 line = 18 ; column = 6 ; value =':'; } +{kind = TOKEN_ASSIGN; ; index = 460 ; length = 1 line = 18 ; column = 7 ; value ='='; } +{kind = TOKEN_LEFTPAREN; ; index = 462 ; length = 1 line = 18 ; column = 9 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 463 ; length = 2 line = 18 ; column = 10 ; value ='uv'; } +{kind = TOKEN_DOT; ; index = 465 ; length = 1 line = 18 ; column = 12 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 466 ; length = 1 line = 18 ; column = 13 ; value ='x'; } +{kind = TOKEN_MINUS; ; index = 468 ; length = 1 line = 18 ; column = 15 ; value ='-'; } +{kind = TOKEN_LEFTPAREN; ; index = 470 ; length = 1 line = 18 ; column = 17 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 471 ; length = 1 line = 18 ; column = 18 ; value ='p'; } +{kind = TOKEN_DOT; ; index = 472 ; length = 1 line = 18 ; column = 19 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 473 ; length = 4 line = 18 ; column = 20 ; value ='time'; } +{kind = TOKEN_SLASH; ; index = 478 ; length = 1 line = 18 ; column = 25 ; value ='/'; } +{kind = TOKEN_FLOATLITERAL; ; index = 480 ; length = 3 line = 18 ; column = 27 ; value ='3'; } +{kind = TOKEN_RIGHTPAREN; ; index = 483 ; length = 1 line = 18 ; column = 30 ; value =')'; } +{kind = TOKEN_RIGHTPAREN; ; index = 484 ; length = 1 line = 18 ; column = 31 ; value =')'; } +{kind = TOKEN_STAR; ; index = 486 ; length = 1 line = 18 ; column = 33 ; value ='*'; } +{kind = TOKEN_FLOATLITERAL; ; index = 488 ; length = 3 line = 18 ; column = 35 ; value ='3'; } +{kind = TOKEN_SEMICOLON; ; index = 491 ; length = 1 line = 18 ; column = 38 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 495 ; length = 5 line = 19 ; column = 0 ; value ='x_col'; } +{kind = TOKEN_ASSIGN; ; index = 501 ; length = 1 line = 19 ; column = 6 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 503 ; length = 3 line = 19 ; column = 8 ; value ='mod'; } +{kind = TOKEN_LEFTPAREN; ; index = 506 ; length = 1 line = 19 ; column = 11 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 507 ; length = 5 line = 19 ; column = 12 ; value ='x_col'; } +{kind = TOKEN_COMMA; ; index = 512 ; length = 1 line = 19 ; column = 17 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 514 ; length = 3 line = 19 ; column = 19 ; value ='3'; } +{kind = TOKEN_RIGHTPAREN; ; index = 517 ; length = 1 line = 19 ; column = 22 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 518 ; length = 1 line = 19 ; column = 23 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 522 ; length = 10 line = 20 ; column = 0 ; value ='hor_colour'; } +{kind = TOKEN_COLON; ; index = 533 ; length = 1 line = 20 ; column = 11 ; value =':'; } +{kind = TOKEN_ASSIGN; ; index = 534 ; length = 1 line = 20 ; column = 12 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 536 ; length = 6 line = 20 ; column = 14 ; value ='float3'; } +{kind = TOKEN_LEFTPAREN; ; index = 542 ; length = 1 line = 20 ; column = 20 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 543 ; length = 4 line = 20 ; column = 21 ; value ='0.25'; } +{kind = TOKEN_COMMA; ; index = 547 ; length = 1 line = 20 ; column = 25 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 549 ; length = 4 line = 20 ; column = 27 ; value ='0.25'; } +{kind = TOKEN_COMMA; ; index = 553 ; length = 1 line = 20 ; column = 31 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 555 ; length = 4 line = 20 ; column = 33 ; value ='0.25'; } +{kind = TOKEN_RIGHTPAREN; ; index = 559 ; length = 1 line = 20 ; column = 37 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 560 ; length = 1 line = 20 ; column = 38 ; value =';'; } +{kind = TOKEN_IF; ; index = 567 ; length = 2 line = 22 ; column = 0 ; value ='if'; } +{kind = TOKEN_IDENTIFIER; ; index = 570 ; length = 5 line = 22 ; column = 3 ; value ='x_col'; } +{kind = TOKEN_LESS; ; index = 576 ; length = 1 line = 22 ; column = 9 ; value ='<'; } +{kind = TOKEN_FLOATLITERAL; ; index = 578 ; length = 3 line = 22 ; column = 11 ; value ='1'; } +{kind = TOKEN_LEFTBRACE; ; index = 582 ; length = 1 line = 22 ; column = 15 ; value ='{'; } +{kind = TOKEN_RIGHTBRACE; ; index = 587 ; length = 1 line = 24 ; column = 0 ; value ='}'; } +{kind = TOKEN_ELSE; ; index = 589 ; length = 4 line = 24 ; column = 2 ; value ='else'; } +{kind = TOKEN_IF; ; index = 594 ; length = 2 line = 24 ; column = 7 ; value ='if'; } +{kind = TOKEN_IDENTIFIER; ; index = 597 ; length = 5 line = 24 ; column = 10 ; value ='x_col'; } +{kind = TOKEN_LESS; ; index = 603 ; length = 1 line = 24 ; column = 16 ; value ='<'; } +{kind = TOKEN_FLOATLITERAL; ; index = 605 ; length = 3 line = 24 ; column = 18 ; value ='2'; } +{kind = TOKEN_LEFTBRACE; ; index = 609 ; length = 1 line = 24 ; column = 22 ; value ='{'; } +{kind = TOKEN_RIGHTBRACE; ; index = 615 ; length = 1 line = 26 ; column = 0 ; value ='}'; } +{kind = TOKEN_ELSE; ; index = 617 ; length = 4 line = 26 ; column = 2 ; value ='else'; } +{kind = TOKEN_LEFTBRACE; ; index = 622 ; length = 1 line = 26 ; column = 7 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 626 ; length = 5 line = 27 ; column = 0 ; value ='x_col'; } +{kind = TOKEN_MINUSEQUALS; ; index = 632 ; length = 2 line = 27 ; column = 6 ; value ='-='; } +{kind = TOKEN_FLOATLITERAL; ; index = 635 ; length = 3 line = 27 ; column = 9 ; value ='2'; } +{kind = TOKEN_SEMICOLON; ; index = 638 ; length = 1 line = 27 ; column = 12 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 642 ; length = 10 line = 28 ; column = 0 ; value ='hor_colour'; } +{kind = TOKEN_DOT; ; index = 652 ; length = 1 line = 28 ; column = 10 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 653 ; length = 1 line = 28 ; column = 11 ; value ='b'; } +{kind = TOKEN_PLUSEQUALS; ; index = 655 ; length = 2 line = 28 ; column = 13 ; value ='+='; } +{kind = TOKEN_FLOATLITERAL; ; index = 658 ; length = 3 line = 28 ; column = 16 ; value ='1'; } +{kind = TOKEN_MINUS; ; index = 662 ; length = 1 line = 28 ; column = 20 ; value ='-'; } +{kind = TOKEN_IDENTIFIER; ; index = 664 ; length = 5 line = 28 ; column = 22 ; value ='x_col'; } +{kind = TOKEN_SEMICOLON; ; index = 669 ; length = 1 line = 28 ; column = 27 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 673 ; length = 10 line = 29 ; column = 0 ; value ='hor_colour'; } +{kind = TOKEN_DOT; ; index = 683 ; length = 1 line = 29 ; column = 10 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 684 ; length = 1 line = 29 ; column = 11 ; value ='r'; } +{kind = TOKEN_PLUSEQUALS; ; index = 686 ; length = 2 line = 29 ; column = 13 ; value ='+='; } +{kind = TOKEN_IDENTIFIER; ; index = 689 ; length = 5 line = 29 ; column = 16 ; value ='x_col'; } +{kind = TOKEN_SEMICOLON; ; index = 694 ; length = 1 line = 29 ; column = 21 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 697 ; length = 1 line = 30 ; column = 0 ; value ='}'; } +{kind = TOKEN_IDENTIFIER; ; index = 702 ; length = 2 line = 32 ; column = 0 ; value ='uv'; } +{kind = TOKEN_ASSIGN; ; index = 705 ; length = 1 line = 32 ; column = 3 ; value ='='; } +{kind = TOKEN_LEFTPAREN; ; index = 707 ; length = 1 line = 32 ; column = 5 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 708 ; length = 3 line = 32 ; column = 6 ; value ='2'; } +{kind = TOKEN_STAR; ; index = 712 ; length = 1 line = 32 ; column = 10 ; value ='*'; } +{kind = TOKEN_IDENTIFIER; ; index = 714 ; length = 2 line = 32 ; column = 12 ; value ='uv'; } +{kind = TOKEN_RIGHTPAREN; ; index = 716 ; length = 1 line = 32 ; column = 14 ; value =')'; } +{kind = TOKEN_MINUS; ; index = 718 ; length = 1 line = 32 ; column = 16 ; value ='-'; } +{kind = TOKEN_FLOATLITERAL; ; index = 720 ; length = 3 line = 32 ; column = 18 ; value ='1'; } +{kind = TOKEN_SEMICOLON; ; index = 723 ; length = 1 line = 32 ; column = 21 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 726 ; length = 10 line = 33 ; column = 0 ; value ='beam_width'; } +{kind = TOKEN_ASSIGN; ; index = 737 ; length = 1 line = 33 ; column = 11 ; value ='='; } +{kind = TOKEN_LEFTPAREN; ; index = 739 ; length = 1 line = 33 ; column = 13 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 740 ; length = 3 line = 33 ; column = 14 ; value ='0.7'; } +{kind = TOKEN_PLUS; ; index = 743 ; length = 1 line = 33 ; column = 17 ; value ='+'; } +{kind = TOKEN_FLOATLITERAL; ; index = 744 ; length = 3 line = 33 ; column = 18 ; value ='0.5'; } +{kind = TOKEN_STAR; ; index = 747 ; length = 1 line = 33 ; column = 21 ; value ='*'; } +{kind = TOKEN_IDENTIFIER; ; index = 748 ; length = 3 line = 33 ; column = 22 ; value ='cos'; } +{kind = TOKEN_LEFTPAREN; ; index = 751 ; length = 1 line = 33 ; column = 25 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 752 ; length = 2 line = 33 ; column = 26 ; value ='uv'; } +{kind = TOKEN_DOT; ; index = 754 ; length = 1 line = 33 ; column = 28 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 755 ; length = 1 line = 33 ; column = 29 ; value ='x'; } +{kind = TOKEN_STAR; ; index = 756 ; length = 1 line = 33 ; column = 30 ; value ='*'; } +{kind = TOKEN_FLOATLITERAL; ; index = 757 ; length = 4 line = 33 ; column = 31 ; value ='10'; } +{kind = TOKEN_STAR; ; index = 761 ; length = 1 line = 33 ; column = 35 ; value ='*'; } +{kind = TOKEN_IDENTIFIER; ; index = 762 ; length = 3 line = 33 ; column = 36 ; value ='tau'; } +{kind = TOKEN_STAR; ; index = 765 ; length = 1 line = 33 ; column = 39 ; value ='*'; } +{kind = TOKEN_FLOATLITERAL; ; index = 766 ; length = 4 line = 33 ; column = 40 ; value ='0.15'; } +{kind = TOKEN_STAR; ; index = 770 ; length = 1 line = 33 ; column = 44 ; value ='*'; } +{kind = TOKEN_IDENTIFIER; ; index = 771 ; length = 5 line = 33 ; column = 45 ; value ='clamp'; } +{kind = TOKEN_LEFTPAREN; ; index = 776 ; length = 1 line = 33 ; column = 50 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 777 ; length = 5 line = 33 ; column = 51 ; value ='floor'; } +{kind = TOKEN_LEFTPAREN; ; index = 782 ; length = 1 line = 33 ; column = 56 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 783 ; length = 3 line = 33 ; column = 57 ; value ='5'; } +{kind = TOKEN_PLUS; ; index = 787 ; length = 1 line = 33 ; column = 61 ; value ='+'; } +{kind = TOKEN_FLOATLITERAL; ; index = 789 ; length = 4 line = 33 ; column = 63 ; value ='10'; } +{kind = TOKEN_STAR; ; index = 793 ; length = 1 line = 33 ; column = 67 ; value ='*'; } +{kind = TOKEN_IDENTIFIER; ; index = 794 ; length = 3 line = 33 ; column = 68 ; value ='cos'; } +{kind = TOKEN_LEFTPAREN; ; index = 797 ; length = 1 line = 33 ; column = 71 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 798 ; length = 5 line = 33 ; column = 72 ; value ='iTime'; } +{kind = TOKEN_RIGHTPAREN; ; index = 803 ; length = 1 line = 33 ; column = 77 ; value =')'; } +{kind = TOKEN_RIGHTPAREN; ; index = 804 ; length = 1 line = 33 ; column = 78 ; value =')'; } +{kind = TOKEN_COMMA; ; index = 805 ; length = 1 line = 33 ; column = 79 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 807 ; length = 3 line = 33 ; column = 81 ; value ='0'; } +{kind = TOKEN_COMMA; ; index = 810 ; length = 1 line = 33 ; column = 84 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 812 ; length = 4 line = 33 ; column = 86 ; value ='10'; } +{kind = TOKEN_RIGHTPAREN; ; index = 816 ; length = 1 line = 33 ; column = 90 ; value =')'; } +{kind = TOKEN_RIGHTPAREN; ; index = 817 ; length = 1 line = 33 ; column = 91 ; value =')'; } +{kind = TOKEN_RIGHTPAREN; ; index = 818 ; length = 1 line = 33 ; column = 92 ; value =')'; } +{kind = TOKEN_STAR; ; index = 820 ; length = 1 line = 33 ; column = 94 ; value ='*'; } +{kind = TOKEN_IDENTIFIER; ; index = 822 ; length = 3 line = 33 ; column = 96 ; value ='abs'; } +{kind = TOKEN_LEFTPAREN; ; index = 825 ; length = 1 line = 33 ; column = 99 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 826 ; length = 3 line = 33 ; column = 100 ; value ='1'; } +{kind = TOKEN_SLASH; ; index = 830 ; length = 1 line = 33 ; column = 104 ; value ='/'; } +{kind = TOKEN_LEFTPAREN; ; index = 832 ; length = 1 line = 33 ; column = 106 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 833 ; length = 4 line = 33 ; column = 107 ; value ='30'; } +{kind = TOKEN_STAR; ; index = 838 ; length = 1 line = 33 ; column = 112 ; value ='*'; } +{kind = TOKEN_IDENTIFIER; ; index = 840 ; length = 2 line = 33 ; column = 114 ; value ='uv'; } +{kind = TOKEN_DOT; ; index = 842 ; length = 1 line = 33 ; column = 116 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 843 ; length = 1 line = 33 ; column = 117 ; value ='y'; } +{kind = TOKEN_RIGHTPAREN; ; index = 844 ; length = 1 line = 33 ; column = 118 ; value =')'; } +{kind = TOKEN_RIGHTPAREN; ; index = 845 ; length = 1 line = 33 ; column = 119 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 846 ; length = 1 line = 33 ; column = 120 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 849 ; length = 8 line = 34 ; column = 0 ; value ='hor_beam'; } +{kind = TOKEN_ASSIGN; ; index = 858 ; length = 1 line = 34 ; column = 9 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 860 ; length = 6 line = 34 ; column = 11 ; value ='float3'; } +{kind = TOKEN_LEFTPAREN; ; index = 866 ; length = 1 line = 34 ; column = 17 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 867 ; length = 10 line = 34 ; column = 18 ; value ='beam_width'; } +{kind = TOKEN_RIGHTPAREN; ; index = 877 ; length = 1 line = 34 ; column = 28 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 878 ; length = 1 line = 34 ; column = 29 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 881 ; length = 6 line = 35 ; column = 0 ; value ='result'; } +{kind = TOKEN_COLON; ; index = 888 ; length = 1 line = 35 ; column = 7 ; value =':'; } +{kind = TOKEN_ASSIGN; ; index = 889 ; length = 1 line = 35 ; column = 8 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 891 ; length = 6 line = 35 ; column = 10 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 897 ; length = 1 line = 35 ; column = 16 ; value ='('; } +{kind = TOKEN_LEFTPAREN; ; index = 898 ; length = 1 line = 35 ; column = 17 ; value ='('; } +{kind = TOKEN_LEFTPAREN; ; index = 899 ; length = 1 line = 35 ; column = 18 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 900 ; length = 8 line = 35 ; column = 19 ; value ='hor_beam'; } +{kind = TOKEN_RIGHTPAREN; ; index = 908 ; length = 1 line = 35 ; column = 27 ; value =')'; } +{kind = TOKEN_STAR; ; index = 910 ; length = 1 line = 35 ; column = 29 ; value ='*'; } +{kind = TOKEN_IDENTIFIER; ; index = 912 ; length = 10 line = 35 ; column = 31 ; value ='hor_colour'; } +{kind = TOKEN_RIGHTPAREN; ; index = 922 ; length = 1 line = 35 ; column = 41 ; value =')'; } +{kind = TOKEN_COMMA; ; index = 923 ; length = 1 line = 35 ; column = 42 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 925 ; length = 3 line = 35 ; column = 44 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 928 ; length = 1 line = 35 ; column = 47 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 929 ; length = 1 line = 35 ; column = 48 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 932 ; length = 1 line = 36 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 935 ; length = 0 line = 37 ; column = 0 ; value =''; } diff --git a/test/lex/complicated_computation.golden b/test/lex/complicated_computation.golden new file mode 100644 index 0000000..10f7113 --- /dev/null +++ b/test/lex/complicated_computation.golden @@ -0,0 +1,30 @@ +{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 ='x'; } +{kind = TOKEN_COLON; ; index = 24 ; length = 1 line = 2 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 26 ; length = 5 line = 2 ; column = 4 ; value ='float'; } +{kind = TOKEN_ASSIGN; ; index = 32 ; length = 1 line = 2 ; column = 10 ; value ='='; } +{kind = TOKEN_FLOATLITERAL; ; index = 34 ; length = 3 line = 2 ; column = 12 ; value ='5'; } +{kind = TOKEN_SEMICOLON; ; index = 37 ; length = 1 line = 2 ; column = 15 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 41 ; length = 1 line = 3 ; column = 0 ; value ='y'; } +{kind = TOKEN_COLON; ; index = 43 ; length = 1 line = 3 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 45 ; length = 5 line = 3 ; column = 4 ; value ='float'; } +{kind = TOKEN_ASSIGN; ; index = 51 ; length = 1 line = 3 ; column = 10 ; value ='='; } +{kind = TOKEN_FLOATLITERAL; ; index = 53 ; length = 6 line = 3 ; column = 12 ; value ='3000'; } +{kind = TOKEN_SEMICOLON; ; index = 59 ; length = 1 line = 3 ; column = 18 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 65 ; length = 1 line = 5 ; column = 0 ; value ='z'; } +{kind = TOKEN_COLON; ; index = 67 ; length = 1 line = 5 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 69 ; length = 5 line = 5 ; column = 4 ; value ='float'; } +{kind = TOKEN_ASSIGN; ; index = 75 ; length = 1 line = 5 ; column = 10 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 77 ; length = 1 line = 5 ; column = 12 ; value ='y'; } +{kind = TOKEN_STAR; ; index = 79 ; length = 1 line = 5 ; column = 14 ; value ='*'; } +{kind = TOKEN_IDENTIFIER; ; index = 81 ; length = 1 line = 5 ; column = 16 ; value ='y'; } +{kind = TOKEN_PLUS; ; index = 83 ; length = 1 line = 5 ; column = 18 ; value ='+'; } +{kind = TOKEN_IDENTIFIER; ; index = 85 ; length = 1 line = 5 ; column = 20 ; value ='x'; } +{kind = TOKEN_SEMICOLON; ; index = 86 ; length = 1 line = 5 ; column = 21 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 89 ; length = 1 line = 6 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 92 ; length = 0 line = 7 ; column = 0 ; value =''; } diff --git a/test/lex/constant_buffer.golden b/test/lex/constant_buffer.golden new file mode 100644 index 0000000..52d6cd3 --- /dev/null +++ b/test/lex/constant_buffer.golden @@ -0,0 +1,82 @@ +{kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 6 line = 1 ; column = 0 ; value ='camera'; } +{kind = TOKEN_DOUBLECOLON; ; index = 7 ; length = 2 line = 1 ; column = 7 ; value ='::'; } +{kind = TOKEN_CONSTANT_BUFFER; ; index = 10 ; length = 15 line = 1 ; column = 10 ; value ='Constant_Buffer'; } +{kind = TOKEN_LEFTBRACE; ; index = 26 ; length = 1 line = 1 ; column = 26 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 30 ; length = 10 line = 2 ; column = 0 ; value ='projection'; } +{kind = TOKEN_COLON; ; index = 41 ; length = 1 line = 2 ; column = 11 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 43 ; length = 8 line = 2 ; column = 13 ; value ='float4x4'; } +{kind = TOKEN_SEMICOLON; ; index = 51 ; length = 1 line = 2 ; column = 21 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 55 ; length = 4 line = 3 ; column = 0 ; value ='view'; } +{kind = TOKEN_COLON; ; index = 66 ; length = 1 line = 3 ; column = 11 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 68 ; length = 8 line = 3 ; column = 13 ; value ='float4x4'; } +{kind = TOKEN_SEMICOLON; ; index = 76 ; length = 1 line = 3 ; column = 21 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 79 ; length = 1 line = 4 ; column = 0 ; value ='}'; } +{kind = TOKEN_VERTEX; ; index = 84 ; length = 6 line = 6 ; column = 0 ; value ='vertex'; } +{kind = TOKEN_IDENTIFIER; ; index = 91 ; length = 4 line = 6 ; column = 7 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 96 ; length = 2 line = 6 ; column = 12 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 99 ; length = 1 line = 6 ; column = 15 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 100 ; length = 3 line = 6 ; column = 16 ; value ='pos'; } +{kind = TOKEN_COLON; ; index = 104 ; length = 1 line = 6 ; column = 20 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 106 ; length = 6 line = 6 ; column = 22 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 113 ; length = 1 line = 6 ; column = 29 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 114 ; length = 8 line = 6 ; column = 30 ; value ='position'; } +{kind = TOKEN_RIGHTPAREN; ; index = 122 ; length = 1 line = 6 ; column = 38 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 124 ; length = 2 line = 6 ; column = 40 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 127 ; length = 6 line = 6 ; column = 43 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 134 ; length = 1 line = 6 ; column = 50 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 135 ; length = 8 line = 6 ; column = 51 ; value ='position'; } +{kind = TOKEN_LEFTBRACE; ; index = 144 ; length = 1 line = 6 ; column = 60 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 148 ; length = 2 line = 7 ; column = 0 ; value ='mv'; } +{kind = TOKEN_COLON; ; index = 151 ; length = 1 line = 7 ; column = 3 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 153 ; length = 6 line = 7 ; column = 5 ; value ='float4'; } +{kind = TOKEN_ASSIGN; ; index = 160 ; length = 1 line = 7 ; column = 12 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 162 ; length = 3 line = 7 ; column = 14 ; value ='mul'; } +{kind = TOKEN_LEFTPAREN; ; index = 165 ; length = 1 line = 7 ; column = 17 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 166 ; length = 6 line = 7 ; column = 18 ; value ='camera'; } +{kind = TOKEN_DOT; ; index = 172 ; length = 1 line = 7 ; column = 24 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 173 ; length = 4 line = 7 ; column = 25 ; value ='view'; } +{kind = TOKEN_COMMA; ; index = 177 ; length = 1 line = 7 ; column = 29 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 179 ; length = 3 line = 7 ; column = 31 ; value ='pos'; } +{kind = TOKEN_RIGHTPAREN; ; index = 182 ; length = 1 line = 7 ; column = 34 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 183 ; length = 1 line = 7 ; column = 35 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 187 ; length = 3 line = 8 ; column = 0 ; value ='mvp'; } +{kind = TOKEN_COLON; ; index = 191 ; length = 1 line = 8 ; column = 4 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 193 ; length = 6 line = 8 ; column = 6 ; value ='float4'; } +{kind = TOKEN_ASSIGN; ; index = 200 ; length = 1 line = 8 ; column = 13 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 202 ; length = 3 line = 8 ; column = 15 ; value ='mul'; } +{kind = TOKEN_LEFTPAREN; ; index = 205 ; length = 1 line = 8 ; column = 18 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 206 ; length = 6 line = 8 ; column = 19 ; value ='camera'; } +{kind = TOKEN_DOT; ; index = 212 ; length = 1 line = 8 ; column = 25 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 213 ; length = 10 line = 8 ; column = 26 ; value ='projection'; } +{kind = TOKEN_COMMA; ; index = 223 ; length = 1 line = 8 ; column = 36 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 225 ; length = 2 line = 8 ; column = 38 ; value ='mv'; } +{kind = TOKEN_RIGHTPAREN; ; index = 227 ; length = 1 line = 8 ; column = 40 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 228 ; length = 1 line = 8 ; column = 41 ; value =';'; } +{kind = TOKEN_RETURN; ; index = 232 ; length = 6 line = 9 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 239 ; length = 3 line = 9 ; column = 7 ; value ='mvp'; } +{kind = TOKEN_SEMICOLON; ; index = 242 ; length = 1 line = 9 ; column = 10 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 245 ; length = 1 line = 10 ; column = 0 ; value ='}'; } +{kind = TOKEN_PIXEL; ; index = 250 ; length = 5 line = 12 ; column = 0 ; value ='pixel'; } +{kind = TOKEN_IDENTIFIER; ; index = 256 ; length = 4 line = 12 ; column = 6 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 261 ; length = 2 line = 12 ; column = 11 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 264 ; length = 1 line = 12 ; column = 14 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 265 ; length = 1 line = 12 ; column = 15 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 267 ; length = 2 line = 12 ; column = 17 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 270 ; length = 6 line = 12 ; column = 20 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 277 ; length = 1 line = 12 ; column = 27 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 278 ; length = 6 line = 12 ; column = 28 ; value ='target'; } +{kind = TOKEN_LEFTBRACE; ; index = 285 ; length = 1 line = 12 ; column = 35 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 289 ; length = 6 line = 13 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 296 ; length = 6 line = 13 ; column = 7 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 302 ; length = 1 line = 13 ; column = 13 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 303 ; length = 3 line = 13 ; column = 14 ; value ='0.5'; } +{kind = TOKEN_COMMA; ; index = 306 ; length = 1 line = 13 ; column = 17 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 308 ; length = 3 line = 13 ; column = 19 ; value ='0.5'; } +{kind = TOKEN_COMMA; ; index = 311 ; length = 1 line = 13 ; column = 22 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 313 ; length = 3 line = 13 ; column = 24 ; value ='0.5'; } +{kind = TOKEN_COMMA; ; index = 316 ; length = 1 line = 13 ; column = 27 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 318 ; length = 3 line = 13 ; column = 29 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 321 ; length = 1 line = 13 ; column = 32 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 322 ; length = 1 line = 13 ; column = 33 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 325 ; length = 1 line = 14 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 328 ; length = 0 line = 15 ; column = 0 ; value =''; } diff --git a/test/lex/custom_hint.golden b/test/lex/custom_hint.golden new file mode 100644 index 0000000..3e224eb --- /dev/null +++ b/test/lex/custom_hint.golden @@ -0,0 +1,81 @@ +{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_PROPERTIES; ; index = 5 ; length = 10 line = 1 ; column = 5 ; value ='properties'; } +{kind = TOKEN_LEFTBRACE; ; index = 16 ; length = 1 line = 1 ; column = 16 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 20 ; length = 4 line = 2 ; column = 0 ; value ='time'; } +{kind = TOKEN_COLON; ; index = 25 ; length = 1 line = 2 ; column = 5 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 27 ; length = 5 line = 2 ; column = 7 ; value ='float'; } +{kind = TOKEN_AT; ; index = 33 ; length = 1 line = 2 ; column = 13 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 34 ; length = 4 line = 2 ; column = 14 ; value ='time'; } +{kind = TOKEN_SEMICOLON; ; index = 38 ; length = 1 line = 2 ; column = 18 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 41 ; length = 1 line = 3 ; column = 0 ; value ='}'; } +{kind = TOKEN_VERTEX; ; index = 46 ; length = 6 line = 5 ; column = 0 ; value ='vertex'; } +{kind = TOKEN_IDENTIFIER; ; index = 53 ; length = 4 line = 5 ; column = 7 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 58 ; length = 2 line = 5 ; column = 12 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 61 ; length = 1 line = 5 ; column = 15 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 62 ; length = 3 line = 5 ; column = 16 ; value ='pos'; } +{kind = TOKEN_COLON; ; index = 66 ; length = 1 line = 5 ; column = 20 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 68 ; length = 6 line = 5 ; column = 22 ; value ='float3'; } +{kind = TOKEN_AT; ; index = 75 ; length = 1 line = 5 ; column = 29 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 76 ; length = 8 line = 5 ; column = 30 ; value ='position'; } +{kind = TOKEN_RIGHTPAREN; ; index = 84 ; length = 1 line = 5 ; column = 38 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 86 ; length = 2 line = 5 ; column = 40 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 89 ; length = 6 line = 5 ; column = 43 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 96 ; length = 1 line = 5 ; column = 50 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 97 ; length = 8 line = 5 ; column = 51 ; value ='position'; } +{kind = TOKEN_LEFTBRACE; ; index = 106 ; length = 1 line = 5 ; column = 60 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 110 ; length = 6 line = 6 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 117 ; length = 6 line = 6 ; column = 7 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 123 ; length = 1 line = 6 ; column = 13 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 124 ; length = 3 line = 6 ; column = 14 ; value ='pos'; } +{kind = TOKEN_DOT; ; index = 127 ; length = 1 line = 6 ; column = 17 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 128 ; length = 1 line = 6 ; column = 18 ; value ='x'; } +{kind = TOKEN_COMMA; ; index = 129 ; length = 1 line = 6 ; column = 19 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 131 ; length = 3 line = 6 ; column = 21 ; value ='pos'; } +{kind = TOKEN_DOT; ; index = 134 ; length = 1 line = 6 ; column = 24 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 135 ; length = 1 line = 6 ; column = 25 ; value ='y'; } +{kind = TOKEN_COMMA; ; index = 136 ; length = 1 line = 6 ; column = 26 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 138 ; length = 3 line = 6 ; column = 28 ; value ='pos'; } +{kind = TOKEN_DOT; ; index = 141 ; length = 1 line = 6 ; column = 31 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 142 ; length = 1 line = 6 ; column = 32 ; value ='z'; } +{kind = TOKEN_COMMA; ; index = 143 ; length = 1 line = 6 ; column = 33 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 145 ; length = 3 line = 6 ; column = 35 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 148 ; length = 1 line = 6 ; column = 38 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 149 ; length = 1 line = 6 ; column = 39 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 152 ; length = 1 line = 7 ; column = 0 ; value ='}'; } +{kind = TOKEN_PIXEL; ; index = 157 ; length = 5 line = 9 ; column = 0 ; value ='pixel'; } +{kind = TOKEN_IDENTIFIER; ; index = 163 ; length = 4 line = 9 ; column = 6 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 168 ; length = 2 line = 9 ; column = 11 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 171 ; length = 1 line = 9 ; column = 14 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 172 ; length = 3 line = 9 ; column = 15 ; value ='pos'; } +{kind = TOKEN_COLON; ; index = 176 ; length = 1 line = 9 ; column = 19 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 178 ; length = 6 line = 9 ; column = 21 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 185 ; length = 1 line = 9 ; column = 28 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 186 ; length = 11 line = 9 ; column = 29 ; value ='outposition'; } +{kind = TOKEN_RIGHTPAREN; ; index = 197 ; length = 1 line = 9 ; column = 40 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 199 ; length = 2 line = 9 ; column = 42 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 202 ; length = 6 line = 9 ; column = 45 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 209 ; length = 1 line = 9 ; column = 52 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 210 ; length = 6 line = 9 ; column = 53 ; value ='target'; } +{kind = TOKEN_LEFTBRACE; ; index = 217 ; length = 1 line = 9 ; column = 60 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 221 ; length = 1 line = 10 ; column = 0 ; value ='t'; } +{kind = TOKEN_COLON; ; index = 223 ; length = 1 line = 10 ; column = 2 ; value =':'; } +{kind = TOKEN_ASSIGN; ; index = 224 ; length = 1 line = 10 ; column = 3 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 226 ; length = 1 line = 10 ; column = 5 ; value ='p'; } +{kind = TOKEN_DOT; ; index = 227 ; length = 1 line = 10 ; column = 6 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 228 ; length = 4 line = 10 ; column = 7 ; value ='time'; } +{kind = TOKEN_SEMICOLON; ; index = 232 ; length = 1 line = 10 ; column = 11 ; value =';'; } +{kind = TOKEN_RETURN; ; index = 236 ; length = 6 line = 11 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 243 ; length = 6 line = 11 ; column = 7 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 249 ; length = 1 line = 11 ; column = 13 ; value ='('; } +{kind = TOKEN_INTLITERAL; ; index = 250 ; length = 1 line = 11 ; column = 14 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 251 ; length = 1 line = 11 ; column = 15 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 253 ; length = 1 line = 11 ; column = 17 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 254 ; length = 1 line = 11 ; column = 18 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 256 ; length = 1 line = 11 ; column = 20 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 257 ; length = 1 line = 11 ; column = 21 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 259 ; length = 1 line = 11 ; column = 23 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 260 ; length = 1 line = 11 ; column = 24 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 261 ; length = 1 line = 11 ; column = 25 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 264 ; length = 1 line = 12 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 267 ; length = 0 line = 13 ; column = 0 ; value =''; } diff --git a/test/lex/double_access.golden b/test/lex/double_access.golden new file mode 100644 index 0000000..4a5cee4 --- /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/else_if_after_else.golden b/test/lex/else_if_after_else.golden new file mode 100644 index 0000000..8e04b09 --- /dev/null +++ b/test/lex/else_if_after_else.golden @@ -0,0 +1,39 @@ +{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_RIGHTBRACE; ; index = 83 ; length = 1 line = 4 ; column = 0 ; value ='}'; } +{kind = TOKEN_ELSE; ; index = 85 ; length = 4 line = 4 ; column = 2 ; value ='else'; } +{kind = TOKEN_LEFTBRACE; ; index = 90 ; length = 1 line = 4 ; column = 7 ; value ='{'; } +{kind = TOKEN_RIGHTBRACE; ; index = 99 ; length = 1 line = 6 ; column = 4 ; value ='}'; } +{kind = TOKEN_ELSE; ; index = 101 ; length = 4 line = 6 ; column = 6 ; value ='else'; } +{kind = TOKEN_IF; ; index = 106 ; length = 2 line = 6 ; column = 11 ; value ='if'; } +{kind = TOKEN_INTLITERAL; ; index = 109 ; length = 1 line = 6 ; column = 14 ; value ='0'; } +{kind = TOKEN_GREATER; ; index = 111 ; length = 1 line = 6 ; column = 16 ; value ='>'; } +{kind = TOKEN_INTLITERAL; ; index = 113 ; length = 3 line = 6 ; column = 18 ; value ='200'; } +{kind = TOKEN_LEFTBRACE; ; index = 117 ; length = 1 line = 6 ; column = 22 ; value ='{'; } +{kind = TOKEN_RIGHTBRACE; ; index = 123 ; length = 1 line = 8 ; column = 0 ; value ='}'; } +{kind = TOKEN_RETURN; ; index = 127 ; length = 6 line = 9 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 134 ; length = 6 line = 9 ; column = 7 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 140 ; length = 1 line = 9 ; column = 13 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 141 ; length = 3 line = 9 ; column = 14 ; value ='0'; } +{kind = TOKEN_RIGHTPAREN; ; index = 144 ; length = 1 line = 9 ; column = 17 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 145 ; length = 1 line = 9 ; column = 18 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 148 ; length = 1 line = 10 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 151 ; length = 0 line = 11 ; column = 0 ; value =''; } diff --git a/test/lex/empty_struct.golden b/test/lex/empty_struct.golden new file mode 100644 index 0000000..d792e47 --- /dev/null +++ b/test/lex/empty_struct.golden @@ -0,0 +1,6 @@ +{kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 3 line = 1 ; column = 0 ; value ='Foo'; } +{kind = TOKEN_DOUBLECOLON; ; index = 4 ; length = 2 line = 1 ; column = 4 ; value ='::'; } +{kind = TOKEN_STRUCT; ; index = 7 ; length = 6 line = 1 ; column = 7 ; value ='struct'; } +{kind = TOKEN_LEFTBRACE; ; index = 14 ; length = 1 line = 1 ; column = 14 ; value ='{'; } +{kind = TOKEN_RIGHTBRACE; ; index = 15 ; length = 1 line = 1 ; column = 15 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 22 ; length = 0 line = 4 ; column = 0 ; value =''; } diff --git a/test/lex/empty_vertex_main.golden b/test/lex/empty_vertex_main.golden new file mode 100644 index 0000000..514efae --- /dev/null +++ b/test/lex/empty_vertex_main.golden @@ -0,0 +1,8 @@ +{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_RIGHTBRACE; ; index = 23 ; length = 1 line = 3 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 24 ; length = 0 line = 3 ; column = 1 ; value =''; } diff --git a/test/lex/empty_vertex_main_with_position_parameter.golden b/test/lex/empty_vertex_main_with_position_parameter.golden new file mode 100644 index 0000000..6caf421 --- /dev/null +++ b/test/lex/empty_vertex_main_with_position_parameter.golden @@ -0,0 +1,18 @@ +{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 ='float3'; } +{kind = TOKEN_LEFTBRACE; ; index = 50 ; length = 1 line = 1 ; column = 50 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 54 ; length = 6 line = 2 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 61 ; length = 3 line = 2 ; column = 7 ; value ='pos'; } +{kind = TOKEN_SEMICOLON; ; index = 64 ; length = 1 line = 2 ; column = 10 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 67 ; length = 1 line = 3 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 70 ; length = 0 line = 4 ; column = 0 ; value =''; } diff --git a/test/lex/field_assignment.golden b/test/lex/field_assignment.golden new file mode 100644 index 0000000..541f78b --- /dev/null +++ b/test/lex/field_assignment.golden @@ -0,0 +1,30 @@ +{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 ='float4'; } +{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_IDENTIFIER; ; index = 64 ; length = 1 line = 2 ; column = 0 ; value ='x'; } +{kind = TOKEN_COLON; ; index = 66 ; length = 1 line = 2 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 68 ; length = 5 line = 2 ; column = 4 ; value ='float'; } +{kind = TOKEN_ASSIGN; ; index = 74 ; length = 1 line = 2 ; column = 10 ; value ='='; } +{kind = TOKEN_FLOATLITERAL; ; index = 76 ; length = 3 line = 2 ; column = 12 ; value ='5'; } +{kind = TOKEN_SEMICOLON; ; index = 79 ; length = 1 line = 2 ; column = 15 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 83 ; length = 1 line = 3 ; column = 0 ; value ='x'; } +{kind = TOKEN_ASSIGN; ; index = 85 ; length = 1 line = 3 ; column = 2 ; value ='='; } +{kind = TOKEN_FLOATLITERAL; ; index = 87 ; length = 3 line = 3 ; column = 4 ; value ='7'; } +{kind = TOKEN_SEMICOLON; ; index = 90 ; length = 1 line = 3 ; column = 7 ; value =';'; } +{kind = TOKEN_RETURN; ; index = 96 ; length = 6 line = 5 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 103 ; length = 3 line = 5 ; column = 7 ; value ='pos'; } +{kind = TOKEN_SEMICOLON; ; index = 106 ; length = 1 line = 5 ; column = 10 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 109 ; length = 1 line = 6 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 112 ; length = 0 line = 7 ; column = 0 ; value =''; } diff --git a/test/lex/field_without_type_specifier.golden b/test/lex/field_without_type_specifier.golden new file mode 100644 index 0000000..a7782f0 --- /dev/null +++ b/test/lex/field_without_type_specifier.golden @@ -0,0 +1,13 @@ +{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 ='x'; } +{kind = TOKEN_COLON; ; index = 24 ; length = 1 line = 2 ; column = 2 ; value =':'; } +{kind = TOKEN_ASSIGN; ; index = 25 ; length = 1 line = 2 ; column = 3 ; value ='='; } +{kind = TOKEN_FLOATLITERAL; ; index = 27 ; length = 3 line = 2 ; column = 5 ; value ='5'; } +{kind = TOKEN_SEMICOLON; ; index = 30 ; length = 1 line = 2 ; column = 8 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 33 ; length = 1 line = 3 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 36 ; length = 0 line = 4 ; column = 0 ; value =''; } diff --git a/test/lex/float_if_cond.golden b/test/lex/float_if_cond.golden new file mode 100644 index 0000000..38f1583 --- /dev/null +++ b/test/lex/float_if_cond.golden @@ -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 =''; } diff --git a/test/lex/float_suffix.golden b/test/lex/float_suffix.golden new file mode 100644 index 0000000..94acbd1 --- /dev/null +++ b/test/lex/float_suffix.golden @@ -0,0 +1,4 @@ +test/float_suffix.ink:2,12: error: We don't use 'f' suffixes for floating point values. + x : float = 2.0f + ^^^^ + \ No newline at end of file diff --git a/test/lex/for_i_loop.golden b/test/lex/for_i_loop.golden new file mode 100644 index 0000000..ed55324 --- /dev/null +++ b/test/lex/for_i_loop.golden @@ -0,0 +1,25 @@ +{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 ='x'; } +{kind = TOKEN_COLON; ; index = 24 ; length = 1 line = 2 ; column = 2 ; value =':'; } +{kind = TOKEN_ASSIGN; ; index = 25 ; length = 1 line = 2 ; column = 3 ; value ='='; } +{kind = TOKEN_INTLITERAL; ; index = 27 ; length = 1 line = 2 ; column = 5 ; value ='0'; } +{kind = TOKEN_SEMICOLON; ; index = 28 ; length = 1 line = 2 ; column = 6 ; value =';'; } +{kind = TOKEN_FOR; ; index = 32 ; length = 3 line = 3 ; column = 0 ; value ='for'; } +{kind = TOKEN_IDENTIFIER; ; index = 36 ; length = 1 line = 3 ; column = 4 ; value ='i'; } +{kind = TOKEN_COLON; ; index = 38 ; length = 1 line = 3 ; column = 6 ; value =':'; } +{kind = TOKEN_INTLITERAL; ; index = 40 ; length = 1 line = 3 ; column = 8 ; value ='0'; } +{kind = TOKEN_DOTDOT; ; index = 41 ; length = 2 line = 3 ; column = 9 ; value ='..'; } +{kind = TOKEN_INTLITERAL; ; index = 43 ; length = 2 line = 3 ; column = 11 ; value ='10'; } +{kind = TOKEN_LEFTBRACE; ; index = 46 ; length = 1 line = 3 ; column = 14 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 51 ; length = 1 line = 4 ; column = 0 ; value ='x'; } +{kind = TOKEN_PLUSEQUALS; ; index = 53 ; length = 2 line = 4 ; column = 2 ; value ='+='; } +{kind = TOKEN_FLOATLITERAL; ; index = 56 ; length = 3 line = 4 ; column = 5 ; value ='1'; } +{kind = TOKEN_SEMICOLON; ; index = 59 ; length = 1 line = 4 ; column = 8 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 63 ; length = 1 line = 5 ; column = 0 ; value ='}'; } +{kind = TOKEN_RIGHTBRACE; ; index = 66 ; length = 1 line = 6 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 69 ; length = 0 line = 7 ; column = 0 ; value =''; } diff --git a/test/lex/for_i_one_liner.golden b/test/lex/for_i_one_liner.golden new file mode 100644 index 0000000..d33d5c6 --- /dev/null +++ b/test/lex/for_i_one_liner.golden @@ -0,0 +1,23 @@ +{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 ='x'; } +{kind = TOKEN_COLON; ; index = 24 ; length = 1 line = 2 ; column = 2 ; value =':'; } +{kind = TOKEN_ASSIGN; ; index = 25 ; length = 1 line = 2 ; column = 3 ; value ='='; } +{kind = TOKEN_FLOATLITERAL; ; index = 27 ; length = 3 line = 2 ; column = 5 ; value ='0'; } +{kind = TOKEN_SEMICOLON; ; index = 30 ; length = 1 line = 2 ; column = 8 ; value =';'; } +{kind = TOKEN_FOR; ; index = 34 ; length = 3 line = 3 ; column = 0 ; value ='for'; } +{kind = TOKEN_IDENTIFIER; ; index = 38 ; length = 1 line = 3 ; column = 4 ; value ='i'; } +{kind = TOKEN_COLON; ; index = 40 ; length = 1 line = 3 ; column = 6 ; value =':'; } +{kind = TOKEN_INTLITERAL; ; index = 42 ; length = 1 line = 3 ; column = 8 ; value ='0'; } +{kind = TOKEN_DOTDOT; ; index = 43 ; length = 2 line = 3 ; column = 9 ; value ='..'; } +{kind = TOKEN_INTLITERAL; ; index = 45 ; length = 2 line = 3 ; column = 11 ; value ='10'; } +{kind = TOKEN_IDENTIFIER; ; index = 48 ; length = 1 line = 3 ; column = 14 ; value ='x'; } +{kind = TOKEN_PLUSEQUALS; ; index = 50 ; length = 2 line = 3 ; column = 16 ; value ='+='; } +{kind = TOKEN_FLOATLITERAL; ; index = 53 ; length = 3 line = 3 ; column = 19 ; value ='2'; } +{kind = TOKEN_SEMICOLON; ; index = 56 ; length = 1 line = 3 ; column = 22 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 59 ; length = 1 line = 4 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 62 ; length = 0 line = 5 ; column = 0 ; value =''; } diff --git a/test/lex/for_no_iter.golden b/test/lex/for_no_iter.golden new file mode 100644 index 0000000..eb59856 --- /dev/null +++ b/test/lex/for_no_iter.golden @@ -0,0 +1,24 @@ +{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 ='x'; } +{kind = TOKEN_COLON; ; index = 24 ; length = 1 line = 2 ; column = 2 ; value =':'; } +{kind = TOKEN_ASSIGN; ; index = 25 ; length = 1 line = 2 ; column = 3 ; value ='='; } +{kind = TOKEN_FLOATLITERAL; ; index = 27 ; length = 3 line = 2 ; column = 5 ; value ='0'; } +{kind = TOKEN_SEMICOLON; ; index = 30 ; length = 1 line = 2 ; column = 8 ; value =';'; } +{kind = TOKEN_FOR; ; index = 34 ; length = 3 line = 3 ; column = 0 ; value ='for'; } +{kind = TOKEN_IDENTIFIER; ; index = 38 ; length = 1 line = 3 ; column = 4 ; value ='i'; } +{kind = TOKEN_COLON; ; index = 40 ; length = 1 line = 3 ; column = 6 ; value =':'; } +{kind = TOKEN_INTLITERAL; ; index = 42 ; length = 1 line = 3 ; column = 8 ; value ='0'; } +{kind = TOKEN_DOTDOT; ; index = 43 ; length = 2 line = 3 ; column = 9 ; value ='..'; } +{kind = TOKEN_LEFTBRACE; ; index = 46 ; length = 1 line = 3 ; column = 12 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 51 ; length = 1 line = 4 ; column = 0 ; value ='x'; } +{kind = TOKEN_PLUSEQUALS; ; index = 53 ; length = 2 line = 4 ; column = 2 ; value ='+='; } +{kind = TOKEN_FLOATLITERAL; ; index = 56 ; length = 3 line = 4 ; column = 5 ; value ='2'; } +{kind = TOKEN_SEMICOLON; ; index = 59 ; length = 1 line = 4 ; column = 8 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 63 ; length = 1 line = 5 ; column = 0 ; value ='}'; } +{kind = TOKEN_RIGHTBRACE; ; index = 66 ; length = 1 line = 6 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 69 ; length = 0 line = 7 ; column = 0 ; value =''; } diff --git a/test/lex/foreign_function.golden b/test/lex/foreign_function.golden new file mode 100644 index 0000000..24bca42 --- /dev/null +++ b/test/lex/foreign_function.golden @@ -0,0 +1,40 @@ +{kind = TOKEN_DIRECTIVE; ; index = 1 ; length = 7 line = 1 ; column = 0 ; value ='foreign'; } +{kind = TOKEN_IDENTIFIER; ; index = 9 ; length = 6 line = 1 ; column = 8 ; value ='float2'; } +{kind = TOKEN_DOUBLECOLON; ; index = 16 ; length = 2 line = 1 ; column = 15 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 19 ; length = 1 line = 1 ; column = 18 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 20 ; length = 5 line = 1 ; column = 19 ; value ='float'; } +{kind = TOKEN_COMMA; ; index = 25 ; length = 1 line = 1 ; column = 24 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 27 ; length = 5 line = 1 ; column = 26 ; value ='float'; } +{kind = TOKEN_RIGHTPAREN; ; index = 32 ; length = 1 line = 1 ; column = 31 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 34 ; length = 2 line = 1 ; column = 33 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 37 ; length = 6 line = 1 ; column = 36 ; value ='float2'; } +{kind = TOKEN_SEMICOLON; ; index = 43 ; length = 1 line = 1 ; column = 42 ; value =';'; } +{kind = TOKEN_DIRECTIVE; ; index = 47 ; length = 7 line = 2 ; column = 0 ; value ='foreign'; } +{kind = TOKEN_IDENTIFIER; ; index = 55 ; length = 6 line = 2 ; column = 8 ; value ='float3'; } +{kind = TOKEN_DOUBLECOLON; ; index = 62 ; length = 2 line = 2 ; column = 15 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 65 ; length = 1 line = 2 ; column = 18 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 66 ; length = 5 line = 2 ; column = 19 ; value ='float'; } +{kind = TOKEN_COMMA; ; index = 71 ; length = 1 line = 2 ; column = 24 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 73 ; length = 5 line = 2 ; column = 26 ; value ='float'; } +{kind = TOKEN_COMMA; ; index = 78 ; length = 1 line = 2 ; column = 31 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 80 ; length = 5 line = 2 ; column = 33 ; value ='float'; } +{kind = TOKEN_RIGHTPAREN; ; index = 85 ; length = 1 line = 2 ; column = 38 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 87 ; length = 2 line = 2 ; column = 40 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 90 ; length = 6 line = 2 ; column = 43 ; value ='float3'; } +{kind = TOKEN_SEMICOLON; ; index = 96 ; length = 1 line = 2 ; column = 49 ; value =';'; } +{kind = TOKEN_DIRECTIVE; ; index = 100 ; length = 7 line = 3 ; column = 0 ; value ='foreign'; } +{kind = TOKEN_IDENTIFIER; ; index = 108 ; length = 6 line = 3 ; column = 8 ; value ='float4'; } +{kind = TOKEN_DOUBLECOLON; ; index = 115 ; length = 2 line = 3 ; column = 15 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 118 ; length = 1 line = 3 ; column = 18 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 119 ; length = 5 line = 3 ; column = 19 ; value ='float'; } +{kind = TOKEN_COMMA; ; index = 124 ; length = 1 line = 3 ; column = 24 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 126 ; length = 5 line = 3 ; column = 26 ; value ='float'; } +{kind = TOKEN_COMMA; ; index = 131 ; length = 1 line = 3 ; column = 31 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 133 ; length = 5 line = 3 ; column = 33 ; value ='float'; } +{kind = TOKEN_COMMA; ; index = 138 ; length = 1 line = 3 ; column = 38 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 140 ; length = 5 line = 3 ; column = 40 ; value ='float'; } +{kind = TOKEN_RIGHTPAREN; ; index = 145 ; length = 1 line = 3 ; column = 45 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 147 ; length = 2 line = 3 ; column = 47 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 150 ; length = 6 line = 3 ; column = 50 ; value ='float4'; } +{kind = TOKEN_SEMICOLON; ; index = 156 ; length = 1 line = 3 ; column = 56 ; value =';'; } +{kind = TOKEN_EOF; ; index = 159 ; length = 0 line = 4 ; column = 0 ; value =''; } diff --git a/test/lex/foreign_overload.golden b/test/lex/foreign_overload.golden new file mode 100644 index 0000000..b07661e --- /dev/null +++ b/test/lex/foreign_overload.golden @@ -0,0 +1,96 @@ +{kind = TOKEN_DIRECTIVE; ; index = 1 ; length = 7 line = 1 ; column = 0 ; value ='foreign'; } +{kind = TOKEN_IDENTIFIER; ; index = 9 ; length = 3 line = 1 ; column = 8 ; value ='mul'; } +{kind = TOKEN_DOUBLECOLON; ; index = 13 ; length = 2 line = 1 ; column = 12 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 16 ; length = 1 line = 1 ; column = 15 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 17 ; length = 6 line = 1 ; column = 16 ; value ='float2'; } +{kind = TOKEN_COMMA; ; index = 23 ; length = 1 line = 1 ; column = 22 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 25 ; length = 6 line = 1 ; column = 24 ; value ='float2'; } +{kind = TOKEN_RIGHTPAREN; ; index = 31 ; length = 1 line = 1 ; column = 30 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 33 ; length = 2 line = 1 ; column = 32 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 36 ; length = 6 line = 1 ; column = 35 ; value ='float2'; } +{kind = TOKEN_SEMICOLON; ; index = 42 ; length = 1 line = 1 ; column = 41 ; value =';'; } +{kind = TOKEN_DIRECTIVE; ; index = 46 ; length = 7 line = 2 ; column = 0 ; value ='foreign'; } +{kind = TOKEN_IDENTIFIER; ; index = 54 ; length = 3 line = 2 ; column = 8 ; value ='mul'; } +{kind = TOKEN_DOUBLECOLON; ; index = 58 ; length = 2 line = 2 ; column = 12 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 61 ; length = 1 line = 2 ; column = 15 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 62 ; length = 6 line = 2 ; column = 16 ; value ='float3'; } +{kind = TOKEN_COMMA; ; index = 68 ; length = 1 line = 2 ; column = 22 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 70 ; length = 6 line = 2 ; column = 24 ; value ='float3'; } +{kind = TOKEN_RIGHTPAREN; ; index = 76 ; length = 1 line = 2 ; column = 30 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 78 ; length = 2 line = 2 ; column = 32 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 81 ; length = 6 line = 2 ; column = 35 ; value ='float3'; } +{kind = TOKEN_SEMICOLON; ; index = 87 ; length = 1 line = 2 ; column = 41 ; value =';'; } +{kind = TOKEN_DIRECTIVE; ; index = 91 ; length = 7 line = 3 ; column = 0 ; value ='foreign'; } +{kind = TOKEN_IDENTIFIER; ; index = 99 ; length = 3 line = 3 ; column = 8 ; value ='mul'; } +{kind = TOKEN_DOUBLECOLON; ; index = 103 ; length = 2 line = 3 ; column = 12 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 106 ; length = 1 line = 3 ; column = 15 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 107 ; length = 6 line = 3 ; column = 16 ; value ='float4'; } +{kind = TOKEN_COMMA; ; index = 113 ; length = 1 line = 3 ; column = 22 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 115 ; length = 6 line = 3 ; column = 24 ; value ='float4'; } +{kind = TOKEN_RIGHTPAREN; ; index = 121 ; length = 1 line = 3 ; column = 30 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 123 ; length = 2 line = 3 ; column = 32 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 126 ; length = 6 line = 3 ; column = 35 ; value ='float4'; } +{kind = TOKEN_SEMICOLON; ; index = 132 ; length = 1 line = 3 ; column = 41 ; value =';'; } +{kind = TOKEN_DIRECTIVE; ; index = 136 ; length = 7 line = 4 ; column = 0 ; value ='foreign'; } +{kind = TOKEN_IDENTIFIER; ; index = 144 ; length = 3 line = 4 ; column = 8 ; value ='mul'; } +{kind = TOKEN_DOUBLECOLON; ; index = 148 ; length = 2 line = 4 ; column = 12 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 151 ; length = 1 line = 4 ; column = 15 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 152 ; length = 8 line = 4 ; column = 16 ; value ='float4x4'; } +{kind = TOKEN_COMMA; ; index = 160 ; length = 1 line = 4 ; column = 24 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 162 ; length = 8 line = 4 ; column = 26 ; value ='float4x4'; } +{kind = TOKEN_RIGHTPAREN; ; index = 170 ; length = 1 line = 4 ; column = 34 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 172 ; length = 2 line = 4 ; column = 36 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 175 ; length = 8 line = 4 ; column = 39 ; value ='float4x4'; } +{kind = TOKEN_SEMICOLON; ; index = 183 ; length = 1 line = 4 ; column = 47 ; value =';'; } +{kind = TOKEN_DIRECTIVE; ; index = 189 ; length = 7 line = 6 ; column = 0 ; value ='foreign'; } +{kind = TOKEN_IDENTIFIER; ; index = 197 ; length = 6 line = 6 ; column = 8 ; value ='float2'; } +{kind = TOKEN_DOUBLECOLON; ; index = 204 ; length = 2 line = 6 ; column = 15 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 207 ; length = 1 line = 6 ; column = 18 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 208 ; length = 5 line = 6 ; column = 19 ; value ='float'; } +{kind = TOKEN_COMMA; ; index = 213 ; length = 1 line = 6 ; column = 24 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 215 ; length = 5 line = 6 ; column = 26 ; value ='float'; } +{kind = TOKEN_RIGHTPAREN; ; index = 220 ; length = 1 line = 6 ; column = 31 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 222 ; length = 2 line = 6 ; column = 33 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 225 ; length = 6 line = 6 ; column = 36 ; value ='float2'; } +{kind = TOKEN_SEMICOLON; ; index = 231 ; length = 1 line = 6 ; column = 42 ; value =';'; } +{kind = TOKEN_VERTEX; ; index = 236 ; length = 6 line = 8 ; column = 0 ; value ='vertex'; } +{kind = TOKEN_IDENTIFIER; ; index = 243 ; length = 4 line = 8 ; column = 7 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 248 ; length = 2 line = 8 ; column = 12 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 251 ; length = 1 line = 8 ; column = 15 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 252 ; length = 1 line = 8 ; column = 16 ; value =')'; } +{kind = TOKEN_LEFTBRACE; ; index = 254 ; length = 1 line = 8 ; column = 18 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 258 ; length = 2 line = 9 ; column = 0 ; value ='v1'; } +{kind = TOKEN_COLON; ; index = 261 ; length = 1 line = 9 ; column = 3 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 263 ; length = 6 line = 9 ; column = 5 ; value ='float2'; } +{kind = TOKEN_ASSIGN; ; index = 270 ; length = 1 line = 9 ; column = 12 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 272 ; length = 6 line = 9 ; column = 14 ; value ='float2'; } +{kind = TOKEN_LEFTPAREN; ; index = 278 ; length = 1 line = 9 ; column = 20 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 279 ; length = 3 line = 9 ; column = 21 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 282 ; length = 1 line = 9 ; column = 24 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 284 ; length = 3 line = 9 ; column = 26 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 287 ; length = 1 line = 9 ; column = 29 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 288 ; length = 1 line = 9 ; column = 30 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 292 ; length = 2 line = 10 ; column = 0 ; value ='v2'; } +{kind = TOKEN_COLON; ; index = 295 ; length = 1 line = 10 ; column = 3 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 297 ; length = 6 line = 10 ; column = 5 ; value ='float2'; } +{kind = TOKEN_ASSIGN; ; index = 304 ; length = 1 line = 10 ; column = 12 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 306 ; length = 6 line = 10 ; column = 14 ; value ='float2'; } +{kind = TOKEN_LEFTPAREN; ; index = 312 ; length = 1 line = 10 ; column = 20 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 313 ; length = 3 line = 10 ; column = 21 ; value ='3'; } +{kind = TOKEN_COMMA; ; index = 316 ; length = 1 line = 10 ; column = 24 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 318 ; length = 3 line = 10 ; column = 26 ; value ='3'; } +{kind = TOKEN_RIGHTPAREN; ; index = 321 ; length = 1 line = 10 ; column = 29 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 322 ; length = 1 line = 10 ; column = 30 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 328 ; length = 2 line = 12 ; column = 0 ; value ='v3'; } +{kind = TOKEN_COLON; ; index = 331 ; length = 1 line = 12 ; column = 3 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 333 ; length = 6 line = 12 ; column = 5 ; value ='float2'; } +{kind = TOKEN_ASSIGN; ; index = 340 ; length = 1 line = 12 ; column = 12 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 342 ; length = 3 line = 12 ; column = 14 ; value ='mul'; } +{kind = TOKEN_LEFTPAREN; ; index = 345 ; length = 1 line = 12 ; column = 17 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 346 ; length = 2 line = 12 ; column = 18 ; value ='v1'; } +{kind = TOKEN_COMMA; ; index = 348 ; length = 1 line = 12 ; column = 20 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 350 ; length = 2 line = 12 ; column = 22 ; value ='v2'; } +{kind = TOKEN_RIGHTPAREN; ; index = 352 ; length = 1 line = 12 ; column = 24 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 353 ; length = 1 line = 12 ; column = 25 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 356 ; length = 1 line = 13 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 359 ; length = 0 line = 14 ; column = 0 ; value =''; } diff --git a/test/lex/function_call.golden b/test/lex/function_call.golden new file mode 100644 index 0000000..d5a51ea --- /dev/null +++ b/test/lex/function_call.golden @@ -0,0 +1,23 @@ +{kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 3 line = 1 ; column = 0 ; value ='foo'; } +{kind = TOKEN_DOUBLECOLON; ; index = 4 ; length = 2 line = 1 ; column = 4 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 7 ; length = 1 line = 1 ; column = 7 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 8 ; length = 1 line = 1 ; column = 8 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 10 ; length = 2 line = 1 ; column = 10 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 13 ; length = 3 line = 1 ; column = 13 ; value ='int'; } +{kind = TOKEN_LEFTBRACE; ; index = 17 ; length = 1 line = 1 ; column = 17 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 21 ; length = 6 line = 2 ; column = 0 ; value ='return'; } +{kind = TOKEN_INTLITERAL; ; index = 28 ; length = 1 line = 2 ; column = 7 ; value ='4'; } +{kind = TOKEN_SEMICOLON; ; index = 29 ; length = 1 line = 2 ; column = 8 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 32 ; length = 1 line = 3 ; column = 0 ; value ='}'; } +{kind = TOKEN_VERTEX; ; index = 37 ; length = 6 line = 5 ; column = 0 ; value ='vertex'; } +{kind = TOKEN_IDENTIFIER; ; index = 44 ; length = 4 line = 5 ; column = 7 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 49 ; length = 2 line = 5 ; column = 12 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 52 ; length = 1 line = 5 ; column = 15 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 53 ; length = 1 line = 5 ; column = 16 ; value =')'; } +{kind = TOKEN_LEFTBRACE; ; index = 55 ; length = 1 line = 5 ; column = 18 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 59 ; length = 3 line = 6 ; column = 0 ; value ='foo'; } +{kind = TOKEN_LEFTPAREN; ; index = 62 ; length = 1 line = 6 ; column = 3 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 63 ; length = 1 line = 6 ; column = 4 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 64 ; length = 1 line = 6 ; column = 5 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 67 ; length = 1 line = 7 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 70 ; length = 0 line = 8 ; column = 0 ; value =''; } diff --git a/test/lex/function_call_out_of_order_declaration.golden b/test/lex/function_call_out_of_order_declaration.golden new file mode 100644 index 0000000..959a584 --- /dev/null +++ b/test/lex/function_call_out_of_order_declaration.golden @@ -0,0 +1,18 @@ +{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 = 3 line = 2 ; column = 0 ; value ='foo'; } +{kind = TOKEN_LEFTPAREN; ; index = 25 ; length = 1 line = 2 ; column = 3 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 26 ; length = 1 line = 2 ; column = 4 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 27 ; length = 1 line = 2 ; column = 5 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 30 ; length = 1 line = 3 ; column = 0 ; value ='}'; } +{kind = TOKEN_IDENTIFIER; ; index = 35 ; length = 3 line = 5 ; column = 0 ; value ='foo'; } +{kind = TOKEN_DOUBLECOLON; ; index = 39 ; length = 2 line = 5 ; column = 4 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 42 ; length = 1 line = 5 ; column = 7 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 43 ; length = 1 line = 5 ; column = 8 ; value =')'; } +{kind = TOKEN_LEFTBRACE; ; index = 45 ; length = 1 line = 5 ; column = 10 ; value ='{'; } +{kind = TOKEN_RIGHTBRACE; ; index = 50 ; length = 1 line = 7 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 53 ; length = 0 line = 8 ; column = 0 ; value =''; } diff --git a/test/lex/function_call_return.golden b/test/lex/function_call_return.golden new file mode 100644 index 0000000..60d7683 --- /dev/null +++ b/test/lex/function_call_return.golden @@ -0,0 +1,31 @@ +{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_RIGHTBRACE; ; index = 23 ; length = 1 line = 3 ; column = 0 ; value ='}'; } +{kind = TOKEN_PIXEL; ; index = 28 ; length = 5 line = 5 ; column = 0 ; value ='pixel'; } +{kind = TOKEN_IDENTIFIER; ; index = 34 ; length = 4 line = 5 ; column = 6 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 39 ; length = 2 line = 5 ; column = 11 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 42 ; length = 1 line = 5 ; column = 14 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 43 ; length = 1 line = 5 ; column = 15 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 45 ; length = 2 line = 5 ; column = 17 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 48 ; length = 6 line = 5 ; column = 20 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 55 ; length = 1 line = 5 ; column = 27 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 56 ; length = 7 line = 5 ; column = 28 ; value ='target0'; } +{kind = TOKEN_LEFTBRACE; ; index = 64 ; length = 1 line = 5 ; column = 36 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 68 ; length = 6 line = 6 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 75 ; length = 6 line = 6 ; column = 7 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 81 ; length = 1 line = 6 ; column = 13 ; value ='('; } +{kind = TOKEN_INTLITERAL; ; index = 82 ; length = 1 line = 6 ; column = 14 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 83 ; length = 1 line = 6 ; column = 15 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 85 ; length = 1 line = 6 ; column = 17 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 86 ; length = 1 line = 6 ; column = 18 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 88 ; length = 1 line = 6 ; column = 20 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 89 ; length = 1 line = 6 ; column = 21 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 91 ; length = 1 line = 6 ; column = 23 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 92 ; length = 1 line = 6 ; column = 24 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 93 ; length = 1 line = 6 ; column = 25 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 96 ; length = 1 line = 7 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 99 ; length = 0 line = 8 ; column = 0 ; value =''; } diff --git a/test/lex/function_with_int_return.golden b/test/lex/function_with_int_return.golden new file mode 100644 index 0000000..5e5af1f --- /dev/null +++ b/test/lex/function_with_int_return.golden @@ -0,0 +1,16 @@ +{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_RIGHTPAREN; ; index = 28 ; length = 1 line = 1 ; column = 28 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 30 ; length = 2 line = 1 ; column = 30 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 33 ; length = 3 line = 1 ; column = 33 ; value ='int'; } +{kind = TOKEN_LEFTBRACE; ; index = 37 ; length = 1 line = 1 ; column = 37 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 41 ; length = 6 line = 2 ; column = 0 ; value ='return'; } +{kind = TOKEN_INTLITERAL; ; index = 48 ; length = 1 line = 2 ; column = 7 ; value ='0'; } +{kind = TOKEN_SEMICOLON; ; index = 49 ; length = 1 line = 2 ; column = 8 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 52 ; length = 1 line = 3 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 55 ; length = 0 line = 4 ; column = 0 ; value =''; } diff --git a/test/lex/functions_with_same_name.golden b/test/lex/functions_with_same_name.golden new file mode 100644 index 0000000..04986c1 --- /dev/null +++ b/test/lex/functions_with_same_name.golden @@ -0,0 +1,26 @@ +{kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 3 line = 1 ; column = 0 ; value ='foo'; } +{kind = TOKEN_DOUBLECOLON; ; index = 4 ; length = 2 line = 1 ; column = 4 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 7 ; length = 1 line = 1 ; column = 7 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 8 ; length = 1 line = 1 ; column = 8 ; value =')'; } +{kind = TOKEN_LEFTBRACE; ; index = 10 ; length = 1 line = 1 ; column = 10 ; value ='{'; } +{kind = TOKEN_RIGHTBRACE; ; index = 11 ; length = 1 line = 1 ; column = 11 ; value ='}'; } +{kind = TOKEN_IDENTIFIER; ; index = 14 ; length = 3 line = 2 ; column = 0 ; value ='foo'; } +{kind = TOKEN_DOUBLECOLON; ; index = 18 ; length = 2 line = 2 ; column = 4 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 21 ; length = 1 line = 2 ; column = 7 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 22 ; length = 1 line = 2 ; column = 8 ; value =')'; } +{kind = TOKEN_LEFTBRACE; ; index = 24 ; length = 1 line = 2 ; column = 10 ; value ='{'; } +{kind = TOKEN_RIGHTBRACE; ; index = 25 ; length = 1 line = 2 ; column = 11 ; value ='}'; } +{kind = TOKEN_IDENTIFIER; ; index = 28 ; length = 3 line = 3 ; column = 0 ; value ='bar'; } +{kind = TOKEN_DOUBLECOLON; ; index = 32 ; length = 2 line = 3 ; column = 4 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 35 ; length = 1 line = 3 ; column = 7 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 36 ; length = 1 line = 3 ; column = 8 ; value =')'; } +{kind = TOKEN_LEFTBRACE; ; index = 38 ; length = 1 line = 3 ; column = 10 ; value ='{'; } +{kind = TOKEN_RIGHTBRACE; ; index = 39 ; length = 1 line = 3 ; column = 11 ; value ='}'; } +{kind = TOKEN_VERTEX; ; index = 44 ; length = 6 line = 5 ; column = 0 ; value ='vertex'; } +{kind = TOKEN_IDENTIFIER; ; index = 51 ; length = 4 line = 5 ; column = 7 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 56 ; length = 2 line = 5 ; column = 12 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 59 ; length = 1 line = 5 ; column = 15 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 60 ; length = 1 line = 5 ; column = 16 ; value =')'; } +{kind = TOKEN_LEFTBRACE; ; index = 62 ; length = 1 line = 5 ; column = 18 ; value ='{'; } +{kind = TOKEN_RIGHTBRACE; ; index = 67 ; length = 1 line = 7 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 70 ; length = 0 line = 8 ; column = 0 ; value =''; } diff --git a/test/lex/hinted_cbuffer.golden b/test/lex/hinted_cbuffer.golden new file mode 100644 index 0000000..556953a --- /dev/null +++ b/test/lex/hinted_cbuffer.golden @@ -0,0 +1,65 @@ +{kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 5 line = 1 ; column = 0 ; value ='props'; } +{kind = TOKEN_DOUBLECOLON; ; index = 6 ; length = 2 line = 1 ; column = 6 ; value ='::'; } +{kind = TOKEN_CONSTANT_BUFFER; ; index = 9 ; length = 15 line = 1 ; column = 9 ; value ='constant_buffer'; } +{kind = TOKEN_AT; ; index = 25 ; length = 1 line = 1 ; column = 25 ; value ='@'; } +{kind = TOKEN_PROPERTIES; ; index = 26 ; length = 10 line = 1 ; column = 26 ; value ='properties'; } +{kind = TOKEN_LEFTBRACE; ; index = 37 ; length = 1 line = 1 ; column = 37 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 41 ; length = 10 line = 2 ; column = 0 ; value ='projection'; } +{kind = TOKEN_COLON; ; index = 52 ; length = 1 line = 2 ; column = 11 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 54 ; length = 8 line = 2 ; column = 13 ; value ='float4x4'; } +{kind = TOKEN_AT; ; index = 63 ; length = 1 line = 2 ; column = 22 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 64 ; length = 10 line = 2 ; column = 23 ; value ='projection'; } +{kind = TOKEN_SEMICOLON; ; index = 74 ; length = 1 line = 2 ; column = 33 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 78 ; length = 4 line = 3 ; column = 0 ; value ='view'; } +{kind = TOKEN_COLON; ; index = 89 ; length = 1 line = 3 ; column = 11 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 91 ; length = 8 line = 3 ; column = 13 ; value ='float4x4'; } +{kind = TOKEN_AT; ; index = 100 ; length = 1 line = 3 ; column = 22 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 101 ; length = 4 line = 3 ; column = 23 ; value ='view'; } +{kind = TOKEN_SEMICOLON; ; index = 105 ; length = 1 line = 3 ; column = 27 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 108 ; length = 1 line = 4 ; column = 0 ; value ='}'; } +{kind = TOKEN_VERTEX; ; index = 113 ; length = 6 line = 6 ; column = 0 ; value ='vertex'; } +{kind = TOKEN_IDENTIFIER; ; index = 120 ; length = 4 line = 6 ; column = 7 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 125 ; length = 2 line = 6 ; column = 12 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 128 ; length = 1 line = 6 ; column = 15 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 129 ; length = 3 line = 6 ; column = 16 ; value ='pos'; } +{kind = TOKEN_COLON; ; index = 133 ; length = 1 line = 6 ; column = 20 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 135 ; length = 6 line = 6 ; column = 22 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 142 ; length = 1 line = 6 ; column = 29 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 143 ; length = 8 line = 6 ; column = 30 ; value ='position'; } +{kind = TOKEN_RIGHTPAREN; ; index = 151 ; length = 1 line = 6 ; column = 38 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 153 ; length = 2 line = 6 ; column = 40 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 156 ; length = 6 line = 6 ; column = 43 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 163 ; length = 1 line = 6 ; column = 50 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 164 ; length = 8 line = 6 ; column = 51 ; value ='position'; } +{kind = TOKEN_LEFTBRACE; ; index = 173 ; length = 1 line = 6 ; column = 60 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 177 ; length = 2 line = 7 ; column = 0 ; value ='mv'; } +{kind = TOKEN_COLON; ; index = 180 ; length = 1 line = 7 ; column = 3 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 182 ; length = 6 line = 7 ; column = 5 ; value ='float4'; } +{kind = TOKEN_ASSIGN; ; index = 189 ; length = 1 line = 7 ; column = 12 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 191 ; length = 3 line = 7 ; column = 14 ; value ='mul'; } +{kind = TOKEN_LEFTPAREN; ; index = 194 ; length = 1 line = 7 ; column = 17 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 195 ; length = 5 line = 7 ; column = 18 ; value ='props'; } +{kind = TOKEN_DOT; ; index = 200 ; length = 1 line = 7 ; column = 23 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 201 ; length = 4 line = 7 ; column = 24 ; value ='view'; } +{kind = TOKEN_COMMA; ; index = 205 ; length = 1 line = 7 ; column = 28 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 207 ; length = 3 line = 7 ; column = 30 ; value ='pos'; } +{kind = TOKEN_RIGHTPAREN; ; index = 210 ; length = 1 line = 7 ; column = 33 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 211 ; length = 1 line = 7 ; column = 34 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 215 ; length = 3 line = 8 ; column = 0 ; value ='mvp'; } +{kind = TOKEN_COLON; ; index = 219 ; length = 1 line = 8 ; column = 4 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 221 ; length = 6 line = 8 ; column = 6 ; value ='float4'; } +{kind = TOKEN_ASSIGN; ; index = 228 ; length = 1 line = 8 ; column = 13 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 230 ; length = 3 line = 8 ; column = 15 ; value ='mul'; } +{kind = TOKEN_LEFTPAREN; ; index = 233 ; length = 1 line = 8 ; column = 18 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 234 ; length = 5 line = 8 ; column = 19 ; value ='props'; } +{kind = TOKEN_DOT; ; index = 239 ; length = 1 line = 8 ; column = 24 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 240 ; length = 10 line = 8 ; column = 25 ; value ='projection'; } +{kind = TOKEN_COMMA; ; index = 250 ; length = 1 line = 8 ; column = 35 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 252 ; length = 2 line = 8 ; column = 37 ; value ='mv'; } +{kind = TOKEN_RIGHTPAREN; ; index = 254 ; length = 1 line = 8 ; column = 39 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 255 ; length = 1 line = 8 ; column = 40 ; value =';'; } +{kind = TOKEN_RETURN; ; index = 259 ; length = 6 line = 9 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 266 ; length = 3 line = 9 ; column = 7 ; value ='mvp'; } +{kind = TOKEN_SEMICOLON; ; index = 269 ; length = 1 line = 9 ; column = 10 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 272 ; length = 1 line = 10 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 275 ; length = 0 line = 11 ; column = 0 ; value =''; } diff --git a/test/lex/if_cond_assign.golden b/test/lex/if_cond_assign.golden new file mode 100644 index 0000000..be22abf --- /dev/null +++ b/test/lex/if_cond_assign.golden @@ -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_ASSIGN; ; 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 =''; } diff --git a/test/lex/if_def_block.golden b/test/lex/if_def_block.golden new file mode 100644 index 0000000..df791c6 --- /dev/null +++ b/test/lex/if_def_block.golden @@ -0,0 +1,53 @@ +{kind = TOKEN_PIXEL; ; index = 21 ; length = 5 line = 3 ; column = 0 ; value ='pixel'; } +{kind = TOKEN_IDENTIFIER; ; index = 27 ; length = 4 line = 3 ; column = 6 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 32 ; length = 2 line = 3 ; column = 11 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 35 ; length = 1 line = 3 ; column = 14 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 36 ; length = 1 line = 3 ; column = 15 ; value =')'; } +{kind = TOKEN_LEFTBRACE; ; index = 38 ; length = 1 line = 3 ; column = 17 ; value ='{'; } +{kind = TOKEN_DIRECTIVE; ; index = 42 ; length = 2 line = 4 ; column = 0 ; value ='if'; } +{kind = TOKEN_IDENTIFIER; ; index = 45 ; length = 3 line = 4 ; column = 3 ; value ='Env'; } +{kind = TOKEN_DOT; ; index = 48 ; length = 1 line = 4 ; column = 6 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 49 ; length = 5 line = 4 ; column = 7 ; value ='Alpha'; } +{kind = TOKEN_LEFTBRACE; ; index = 55 ; length = 1 line = 4 ; column = 13 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 59 ; length = 11 line = 5 ; column = 0 ; value ='alpha_color'; } +{kind = TOKEN_COLON; ; index = 71 ; length = 1 line = 5 ; column = 12 ; value =':'; } +{kind = TOKEN_ASSIGN; ; index = 72 ; length = 1 line = 5 ; column = 13 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 74 ; length = 6 line = 5 ; column = 15 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 80 ; length = 1 line = 5 ; column = 21 ; value ='('; } +{kind = TOKEN_INTLITERAL; ; index = 81 ; length = 1 line = 5 ; column = 22 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 82 ; length = 1 line = 5 ; column = 23 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 84 ; length = 1 line = 5 ; column = 25 ; value ='0'; } +{kind = TOKEN_COMMA; ; index = 85 ; length = 1 line = 5 ; column = 26 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 87 ; length = 1 line = 5 ; column = 28 ; value ='0'; } +{kind = TOKEN_COMMA; ; index = 88 ; length = 1 line = 5 ; column = 29 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 90 ; length = 1 line = 5 ; column = 31 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 91 ; length = 1 line = 5 ; column = 32 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 92 ; length = 1 line = 5 ; column = 33 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 96 ; length = 1 line = 6 ; column = 0 ; value ='f'; } +{kind = TOKEN_COLON; ; index = 98 ; length = 1 line = 6 ; column = 2 ; value =':'; } +{kind = TOKEN_ASSIGN; ; index = 99 ; length = 1 line = 6 ; column = 3 ; value ='='; } +{kind = TOKEN_FLOATLITERAL; ; index = 101 ; length = 3 line = 6 ; column = 5 ; value ='2'; } +{kind = TOKEN_SEMICOLON; ; index = 104 ; length = 1 line = 6 ; column = 8 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 107 ; length = 1 line = 7 ; column = 0 ; value ='}'; } +{kind = TOKEN_ELSE; ; index = 109 ; length = 4 line = 7 ; column = 2 ; value ='else'; } +{kind = TOKEN_LEFTBRACE; ; index = 114 ; length = 1 line = 7 ; column = 7 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 118 ; length = 5 line = 8 ; column = 0 ; value ='color'; } +{kind = TOKEN_COLON; ; index = 124 ; length = 1 line = 8 ; column = 6 ; value =':'; } +{kind = TOKEN_ASSIGN; ; index = 125 ; length = 1 line = 8 ; column = 7 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 127 ; length = 6 line = 8 ; column = 9 ; value ='float3'; } +{kind = TOKEN_LEFTPAREN; ; index = 133 ; length = 1 line = 8 ; column = 15 ; value ='('; } +{kind = TOKEN_INTLITERAL; ; index = 134 ; length = 1 line = 8 ; column = 16 ; value ='0'; } +{kind = TOKEN_COMMA; ; index = 135 ; length = 1 line = 8 ; column = 17 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 137 ; length = 1 line = 8 ; column = 19 ; value ='0'; } +{kind = TOKEN_COMMA; ; index = 138 ; length = 1 line = 8 ; column = 20 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 140 ; length = 1 line = 8 ; column = 22 ; value ='0'; } +{kind = TOKEN_RIGHTPAREN; ; index = 141 ; length = 1 line = 8 ; column = 23 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 142 ; length = 1 line = 8 ; column = 24 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 146 ; length = 1 line = 9 ; column = 0 ; value ='g'; } +{kind = TOKEN_COLON; ; index = 148 ; length = 1 line = 9 ; column = 2 ; value =':'; } +{kind = TOKEN_ASSIGN; ; index = 149 ; length = 1 line = 9 ; column = 3 ; value ='='; } +{kind = TOKEN_FLOATLITERAL; ; index = 151 ; length = 3 line = 9 ; column = 5 ; value ='5'; } +{kind = TOKEN_SEMICOLON; ; index = 154 ; length = 1 line = 9 ; column = 8 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 157 ; length = 1 line = 10 ; column = 0 ; value ='}'; } +{kind = TOKEN_RIGHTBRACE; ; index = 160 ; length = 1 line = 11 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 163 ; length = 0 line = 12 ; column = 0 ; value =''; } diff --git a/test/lex/if_def_expression.golden b/test/lex/if_def_expression.golden new file mode 100644 index 0000000..a7be876 --- /dev/null +++ b/test/lex/if_def_expression.golden @@ -0,0 +1,34 @@ +{kind = TOKEN_DIRECTIVE; ; index = 58 ; length = 2 line = 5 ; column = 0 ; value ='if'; } +{kind = TOKEN_LEFTPAREN; ; index = 61 ; length = 1 line = 5 ; column = 3 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 62 ; length = 3 line = 5 ; column = 4 ; value ='Env'; } +{kind = TOKEN_DOT; ; index = 65 ; length = 1 line = 5 ; column = 7 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 66 ; length = 3 line = 5 ; column = 8 ; value ='PS5'; } +{kind = TOKEN_LOGICALAND; ; index = 70 ; length = 2 line = 5 ; column = 12 ; value ='&&'; } +{kind = TOKEN_IDENTIFIER; ; index = 73 ; length = 3 line = 5 ; column = 15 ; value ='Env'; } +{kind = TOKEN_DOT; ; index = 76 ; length = 1 line = 5 ; column = 18 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 77 ; length = 3 line = 5 ; column = 19 ; value ='XSX'; } +{kind = TOKEN_RIGHTPAREN; ; index = 80 ; length = 1 line = 5 ; column = 22 ; value =')'; } +{kind = TOKEN_LOGICALOR; ; index = 82 ; length = 2 line = 5 ; column = 24 ; value ='||'; } +{kind = TOKEN_IDENTIFIER; ; index = 85 ; length = 3 line = 5 ; column = 27 ; value ='Env'; } +{kind = TOKEN_DOT; ; index = 88 ; length = 1 line = 5 ; column = 30 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 89 ; length = 7 line = 5 ; column = 31 ; value ='Switch2'; } +{kind = TOKEN_LEFTBRACE; ; index = 97 ; length = 1 line = 5 ; column = 39 ; value ='{'; } +{kind = TOKEN_VERTEX; ; index = 101 ; length = 6 line = 6 ; column = 0 ; value ='vertex'; } +{kind = TOKEN_IDENTIFIER; ; index = 108 ; length = 12 line = 6 ; column = 7 ; value ='console_main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 121 ; length = 2 line = 6 ; column = 20 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 124 ; length = 1 line = 6 ; column = 23 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 125 ; length = 1 line = 6 ; column = 24 ; value =')'; } +{kind = TOKEN_LEFTBRACE; ; index = 127 ; length = 1 line = 6 ; column = 26 ; value ='{'; } +{kind = TOKEN_RIGHTBRACE; ; index = 133 ; length = 1 line = 8 ; column = 0 ; value ='}'; } +{kind = TOKEN_RIGHTBRACE; ; index = 136 ; length = 1 line = 9 ; column = 0 ; value ='}'; } +{kind = TOKEN_ELSE; ; index = 138 ; length = 4 line = 9 ; column = 2 ; value ='else'; } +{kind = TOKEN_LEFTBRACE; ; index = 143 ; length = 1 line = 9 ; column = 7 ; value ='{'; } +{kind = TOKEN_VERTEX; ; index = 147 ; length = 6 line = 10 ; column = 0 ; value ='vertex'; } +{kind = TOKEN_IDENTIFIER; ; index = 154 ; length = 12 line = 10 ; column = 7 ; value ='windows_main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 167 ; length = 2 line = 10 ; column = 20 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 170 ; length = 1 line = 10 ; column = 23 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 171 ; length = 1 line = 10 ; column = 24 ; value =')'; } +{kind = TOKEN_LEFTBRACE; ; index = 173 ; length = 1 line = 10 ; column = 26 ; value ='{'; } +{kind = TOKEN_RIGHTBRACE; ; index = 179 ; length = 1 line = 12 ; column = 0 ; value ='}'; } +{kind = TOKEN_RIGHTBRACE; ; index = 182 ; length = 1 line = 13 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 185 ; length = 0 line = 14 ; column = 0 ; value =''; } diff --git a/test/lex/if_if_if.golden b/test/lex/if_if_if.golden new file mode 100644 index 0000000..476a91c --- /dev/null +++ b/test/lex/if_if_if.golden @@ -0,0 +1,39 @@ +{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_IF; ; index = 67 ; length = 2 line = 2 ; column = 3 ; value ='if'; } +{kind = TOKEN_IF; ; index = 70 ; length = 2 line = 2 ; column = 6 ; value ='if'; } +{kind = TOKEN_INTLITERAL; ; index = 73 ; length = 1 line = 2 ; column = 9 ; value ='0'; } +{kind = TOKEN_GREATER; ; index = 75 ; length = 1 line = 2 ; column = 11 ; value ='>'; } +{kind = TOKEN_INTLITERAL; ; index = 77 ; length = 3 line = 2 ; column = 13 ; value ='100'; } +{kind = TOKEN_LEFTBRACE; ; index = 81 ; length = 1 line = 2 ; column = 17 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 86 ; length = 6 line = 3 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 93 ; length = 6 line = 3 ; column = 7 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 99 ; length = 1 line = 3 ; column = 13 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 100 ; length = 3 line = 3 ; column = 14 ; value ='pos'; } +{kind = TOKEN_COMMA; ; index = 103 ; length = 1 line = 3 ; column = 17 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 105 ; length = 3 line = 3 ; column = 19 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 108 ; length = 1 line = 3 ; column = 22 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 109 ; length = 1 line = 3 ; column = 23 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 113 ; length = 1 line = 4 ; column = 0 ; value ='}'; } +{kind = TOKEN_RETURN; ; index = 117 ; length = 6 line = 5 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 124 ; length = 6 line = 5 ; column = 7 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 130 ; length = 1 line = 5 ; column = 13 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 131 ; length = 3 line = 5 ; column = 14 ; value ='0'; } +{kind = TOKEN_RIGHTPAREN; ; index = 134 ; length = 1 line = 5 ; column = 17 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 135 ; length = 1 line = 5 ; column = 18 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 138 ; length = 1 line = 6 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 141 ; length = 0 line = 7 ; column = 0 ; value =''; } diff --git a/test/lex/ifdefs.golden b/test/lex/ifdefs.golden new file mode 100644 index 0000000..89e39ae --- /dev/null +++ b/test/lex/ifdefs.golden @@ -0,0 +1,52 @@ +{kind = TOKEN_DIRECTIVE; ; index = 43 ; length = 2 line = 5 ; column = 0 ; value ='if'; } +{kind = TOKEN_IDENTIFIER; ; index = 46 ; length = 3 line = 5 ; column = 3 ; value ='Env'; } +{kind = TOKEN_DOT; ; index = 49 ; length = 1 line = 5 ; column = 6 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 50 ; length = 8 line = 5 ; column = 7 ; value ='Skinning'; } +{kind = TOKEN_LEFTBRACE; ; index = 59 ; length = 1 line = 5 ; column = 16 ; value ='{'; } +{kind = TOKEN_VERTEX; ; index = 63 ; length = 6 line = 6 ; column = 0 ; value ='vertex'; } +{kind = TOKEN_IDENTIFIER; ; index = 70 ; length = 13 line = 6 ; column = 7 ; value ='skinning_main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 84 ; length = 2 line = 6 ; column = 21 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 87 ; length = 1 line = 6 ; column = 24 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 88 ; length = 1 line = 6 ; column = 25 ; value =')'; } +{kind = TOKEN_LEFTBRACE; ; index = 90 ; length = 1 line = 6 ; column = 27 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 95 ; length = 1 line = 7 ; column = 0 ; value ='x'; } +{kind = TOKEN_COLON; ; index = 97 ; length = 1 line = 7 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 99 ; length = 5 line = 7 ; column = 4 ; value ='float'; } +{kind = TOKEN_ASSIGN; ; index = 105 ; length = 1 line = 7 ; column = 10 ; value ='='; } +{kind = TOKEN_FLOATLITERAL; ; index = 107 ; length = 3 line = 7 ; column = 12 ; value ='5'; } +{kind = TOKEN_SEMICOLON; ; index = 110 ; length = 1 line = 7 ; column = 15 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 114 ; length = 1 line = 8 ; column = 0 ; value ='}'; } +{kind = TOKEN_RIGHTBRACE; ; index = 117 ; length = 1 line = 9 ; column = 0 ; value ='}'; } +{kind = TOKEN_ELSE; ; index = 119 ; length = 4 line = 9 ; column = 2 ; value ='else'; } +{kind = TOKEN_DIRECTIVE; ; index = 125 ; length = 2 line = 9 ; column = 7 ; value ='if'; } +{kind = TOKEN_IDENTIFIER; ; index = 128 ; length = 3 line = 9 ; column = 10 ; value ='Env'; } +{kind = TOKEN_DOT; ; index = 131 ; length = 1 line = 9 ; column = 13 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 132 ; length = 2 line = 9 ; column = 14 ; value ='UV'; } +{kind = TOKEN_LEFTBRACE; ; index = 135 ; length = 1 line = 9 ; column = 17 ; value ='{'; } +{kind = TOKEN_VERTEX; ; index = 139 ; length = 6 line = 10 ; column = 0 ; value ='vertex'; } +{kind = TOKEN_IDENTIFIER; ; index = 146 ; length = 20 line = 10 ; column = 7 ; value ='texture_mapping_main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 167 ; length = 2 line = 10 ; column = 28 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 170 ; length = 1 line = 10 ; column = 31 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 171 ; length = 1 line = 10 ; column = 32 ; value =')'; } +{kind = TOKEN_LEFTBRACE; ; index = 173 ; length = 1 line = 10 ; column = 34 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 178 ; length = 1 line = 11 ; column = 0 ; value ='x'; } +{kind = TOKEN_COLON; ; index = 180 ; length = 1 line = 11 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 182 ; length = 6 line = 11 ; column = 4 ; value ='float2'; } +{kind = TOKEN_ASSIGN; ; index = 189 ; length = 1 line = 11 ; column = 11 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 191 ; length = 6 line = 11 ; column = 13 ; value ='float2'; } +{kind = TOKEN_LEFTPAREN; ; index = 197 ; length = 1 line = 11 ; column = 19 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 198 ; length = 3 line = 11 ; column = 20 ; value ='2'; } +{kind = TOKEN_COMMA; ; index = 201 ; length = 1 line = 11 ; column = 23 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 203 ; length = 3 line = 11 ; column = 25 ; value ='2'; } +{kind = TOKEN_RIGHTPAREN; ; index = 206 ; length = 1 line = 11 ; column = 28 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 207 ; length = 1 line = 11 ; column = 29 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 211 ; length = 1 line = 12 ; column = 0 ; value ='}'; } +{kind = TOKEN_RIGHTBRACE; ; index = 214 ; length = 1 line = 13 ; column = 0 ; value ='}'; } +{kind = TOKEN_PIXEL; ; index = 219 ; length = 5 line = 15 ; column = 0 ; value ='pixel'; } +{kind = TOKEN_IDENTIFIER; ; index = 225 ; length = 4 line = 15 ; column = 6 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 230 ; length = 2 line = 15 ; column = 11 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 233 ; length = 1 line = 15 ; column = 14 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 234 ; length = 1 line = 15 ; column = 15 ; value =')'; } +{kind = TOKEN_LEFTBRACE; ; index = 236 ; length = 1 line = 15 ; column = 17 ; value ='{'; } +{kind = TOKEN_RIGHTBRACE; ; index = 241 ; length = 1 line = 17 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 244 ; length = 0 line = 18 ; column = 0 ; value =''; } diff --git a/test/lex/inferred_types.golden b/test/lex/inferred_types.golden new file mode 100644 index 0000000..146cb73 --- /dev/null +++ b/test/lex/inferred_types.golden @@ -0,0 +1,105 @@ +{kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 3 line = 1 ; column = 0 ; value ='bar'; } +{kind = TOKEN_DOUBLECOLON; ; index = 4 ; length = 2 line = 1 ; column = 4 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 7 ; length = 1 line = 1 ; column = 7 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 8 ; length = 1 line = 1 ; column = 8 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 10 ; length = 2 line = 1 ; column = 10 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 13 ; length = 5 line = 1 ; column = 13 ; value ='float'; } +{kind = TOKEN_LEFTBRACE; ; index = 19 ; length = 1 line = 1 ; column = 19 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 23 ; length = 6 line = 2 ; column = 0 ; value ='return'; } +{kind = TOKEN_FLOATLITERAL; ; index = 30 ; length = 3 line = 2 ; column = 7 ; value ='5'; } +{kind = TOKEN_SEMICOLON; ; index = 33 ; length = 1 line = 2 ; column = 10 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 36 ; length = 1 line = 3 ; column = 0 ; value ='}'; } +{kind = TOKEN_IDENTIFIER; ; index = 41 ; length = 3 line = 5 ; column = 0 ; value ='foo'; } +{kind = TOKEN_DOUBLECOLON; ; index = 45 ; length = 2 line = 5 ; column = 4 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 48 ; length = 1 line = 5 ; column = 7 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 49 ; length = 1 line = 5 ; column = 8 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 51 ; length = 2 line = 5 ; column = 10 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 54 ; length = 5 line = 5 ; column = 13 ; value ='float'; } +{kind = TOKEN_LEFTBRACE; ; index = 60 ; length = 1 line = 5 ; column = 19 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 64 ; length = 6 line = 6 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 71 ; length = 3 line = 6 ; column = 7 ; value ='bar'; } +{kind = TOKEN_LEFTPAREN; ; index = 74 ; length = 1 line = 6 ; column = 10 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 75 ; length = 1 line = 6 ; column = 11 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 76 ; length = 1 line = 6 ; column = 12 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 79 ; length = 1 line = 7 ; column = 0 ; value ='}'; } +{kind = TOKEN_VERTEX; ; index = 84 ; length = 6 line = 9 ; column = 0 ; value ='vertex'; } +{kind = TOKEN_IDENTIFIER; ; index = 91 ; length = 4 line = 9 ; column = 7 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 96 ; length = 2 line = 9 ; column = 12 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 99 ; length = 1 line = 9 ; column = 15 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 100 ; length = 3 line = 9 ; column = 16 ; value ='pos'; } +{kind = TOKEN_COLON; ; index = 104 ; length = 1 line = 9 ; column = 20 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 106 ; length = 6 line = 9 ; column = 22 ; value ='float3'; } +{kind = TOKEN_AT; ; index = 113 ; length = 1 line = 9 ; column = 29 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 114 ; length = 8 line = 9 ; column = 30 ; value ='position'; } +{kind = TOKEN_RIGHTPAREN; ; index = 122 ; length = 1 line = 9 ; column = 38 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 124 ; length = 2 line = 9 ; column = 40 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 127 ; length = 6 line = 9 ; column = 43 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 134 ; length = 1 line = 9 ; column = 50 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 135 ; length = 8 line = 9 ; column = 51 ; value ='position'; } +{kind = TOKEN_LEFTBRACE; ; index = 144 ; length = 1 line = 9 ; column = 60 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 151 ; length = 1 line = 10 ; column = 3 ; value ='f'; } +{kind = TOKEN_COLON; ; index = 153 ; length = 1 line = 10 ; column = 5 ; value =':'; } +{kind = TOKEN_ASSIGN; ; index = 154 ; length = 1 line = 10 ; column = 6 ; value ='='; } +{kind = TOKEN_FLOATLITERAL; ; index = 156 ; length = 3 line = 10 ; column = 8 ; value ='2'; } +{kind = TOKEN_SEMICOLON; ; index = 159 ; length = 1 line = 10 ; column = 11 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 166 ; length = 1 line = 11 ; column = 3 ; value ='i'; } +{kind = TOKEN_COLON; ; index = 168 ; length = 1 line = 11 ; column = 5 ; value =':'; } +{kind = TOKEN_ASSIGN; ; index = 169 ; length = 1 line = 11 ; column = 6 ; value ='='; } +{kind = TOKEN_INTLITERAL; ; index = 171 ; length = 2 line = 11 ; column = 8 ; value ='10'; } +{kind = TOKEN_SEMICOLON; ; index = 173 ; length = 1 line = 11 ; column = 10 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 180 ; length = 1 line = 12 ; column = 3 ; value ='f'; } +{kind = TOKEN_ASSIGN; ; index = 182 ; length = 1 line = 12 ; column = 5 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 184 ; length = 3 line = 12 ; column = 7 ; value ='foo'; } +{kind = TOKEN_LEFTPAREN; ; index = 187 ; length = 1 line = 12 ; column = 10 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 188 ; length = 1 line = 12 ; column = 11 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 189 ; length = 1 line = 12 ; column = 12 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 196 ; length = 2 line = 13 ; column = 3 ; value ='v2'; } +{kind = TOKEN_COLON; ; index = 199 ; length = 1 line = 13 ; column = 6 ; value =':'; } +{kind = TOKEN_ASSIGN; ; index = 200 ; length = 1 line = 13 ; column = 7 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 202 ; length = 6 line = 13 ; column = 9 ; value ='float2'; } +{kind = TOKEN_LEFTPAREN; ; index = 208 ; length = 1 line = 13 ; column = 15 ; value ='('; } +{kind = TOKEN_INTLITERAL; ; index = 209 ; length = 1 line = 13 ; column = 16 ; value ='2'; } +{kind = TOKEN_COMMA; ; index = 210 ; length = 1 line = 13 ; column = 17 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 212 ; length = 1 line = 13 ; column = 19 ; value ='2'; } +{kind = TOKEN_RIGHTPAREN; ; index = 213 ; length = 1 line = 13 ; column = 20 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 214 ; length = 1 line = 13 ; column = 21 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 221 ; length = 2 line = 14 ; column = 3 ; value ='v3'; } +{kind = TOKEN_COLON; ; index = 224 ; length = 1 line = 14 ; column = 6 ; value =':'; } +{kind = TOKEN_ASSIGN; ; index = 225 ; length = 1 line = 14 ; column = 7 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 227 ; length = 6 line = 14 ; column = 9 ; value ='float3'; } +{kind = TOKEN_LEFTPAREN; ; index = 233 ; length = 1 line = 14 ; column = 15 ; value ='('; } +{kind = TOKEN_INTLITERAL; ; index = 234 ; length = 1 line = 14 ; column = 16 ; value ='2'; } +{kind = TOKEN_COMMA; ; index = 235 ; length = 1 line = 14 ; column = 17 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 237 ; length = 1 line = 14 ; column = 19 ; value ='2'; } +{kind = TOKEN_COMMA; ; index = 238 ; length = 1 line = 14 ; column = 20 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 240 ; length = 1 line = 14 ; column = 22 ; value ='3'; } +{kind = TOKEN_RIGHTPAREN; ; index = 241 ; length = 1 line = 14 ; column = 23 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 242 ; length = 1 line = 14 ; column = 24 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 249 ; length = 2 line = 15 ; column = 3 ; value ='v4'; } +{kind = TOKEN_COLON; ; index = 252 ; length = 1 line = 15 ; column = 6 ; value =':'; } +{kind = TOKEN_ASSIGN; ; index = 253 ; length = 1 line = 15 ; column = 7 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 255 ; length = 6 line = 15 ; column = 9 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 261 ; length = 1 line = 15 ; column = 15 ; value ='('; } +{kind = TOKEN_INTLITERAL; ; index = 262 ; length = 1 line = 15 ; column = 16 ; value ='4'; } +{kind = TOKEN_COMMA; ; index = 263 ; length = 1 line = 15 ; column = 17 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 265 ; length = 1 line = 15 ; column = 19 ; value ='5'; } +{kind = TOKEN_COMMA; ; index = 266 ; length = 1 line = 15 ; column = 20 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 268 ; length = 1 line = 15 ; column = 22 ; value ='6'; } +{kind = TOKEN_COMMA; ; index = 269 ; length = 1 line = 15 ; column = 23 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 271 ; length = 1 line = 15 ; column = 25 ; value ='7'; } +{kind = TOKEN_RIGHTPAREN; ; index = 272 ; length = 1 line = 15 ; column = 26 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 273 ; length = 1 line = 15 ; column = 27 ; value =';'; } +{kind = TOKEN_RETURN; ; index = 280 ; length = 6 line = 16 ; column = 3 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 287 ; length = 6 line = 16 ; column = 10 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 293 ; length = 1 line = 16 ; column = 16 ; value ='('; } +{kind = TOKEN_INTLITERAL; ; index = 294 ; length = 1 line = 16 ; column = 17 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 295 ; length = 1 line = 16 ; column = 18 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 297 ; length = 1 line = 16 ; column = 20 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 298 ; length = 1 line = 16 ; column = 21 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 300 ; length = 1 line = 16 ; column = 23 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 301 ; length = 1 line = 16 ; column = 24 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 303 ; length = 1 line = 16 ; column = 26 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 304 ; length = 1 line = 16 ; column = 27 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 305 ; length = 1 line = 16 ; column = 28 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 308 ; length = 1 line = 17 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 309 ; length = 0 line = 17 ; column = 1 ; value =''; } diff --git a/test/lex/large_block.golden b/test/lex/large_block.golden new file mode 100644 index 0000000..978d90e --- /dev/null +++ b/test/lex/large_block.golden @@ -0,0 +1,291 @@ +{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_AT; ; index = 21 ; length = 1 line = 1 ; column = 21 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 22 ; length = 10 line = 1 ; column = 22 ; value ='properties'; } +{kind = TOKEN_LEFTBRACE; ; index = 33 ; length = 1 line = 1 ; column = 33 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 37 ; length = 5 line = 2 ; column = 0 ; value ='color'; } +{kind = TOKEN_COLON; ; index = 51 ; length = 1 line = 2 ; column = 14 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 53 ; length = 6 line = 2 ; column = 16 ; value ='float4'; } +{kind = TOKEN_SEMICOLON; ; index = 59 ; length = 1 line = 2 ; column = 22 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 63 ; length = 13 line = 3 ; column = 0 ; value ='rect_position'; } +{kind = TOKEN_COLON; ; index = 77 ; length = 1 line = 3 ; column = 14 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 79 ; length = 6 line = 3 ; column = 16 ; value ='float2'; } +{kind = TOKEN_SEMICOLON; ; index = 85 ; length = 1 line = 3 ; column = 22 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 89 ; length = 10 line = 4 ; column = 0 ; value ='rect_scale'; } +{kind = TOKEN_COLON; ; index = 103 ; length = 1 line = 4 ; column = 14 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 105 ; length = 6 line = 4 ; column = 16 ; value ='float2'; } +{kind = TOKEN_SEMICOLON; ; index = 111 ; length = 1 line = 4 ; column = 22 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 115 ; length = 10 line = 5 ; column = 0 ; value ='resolution'; } +{kind = TOKEN_COLON; ; index = 129 ; length = 1 line = 5 ; column = 14 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 131 ; length = 6 line = 5 ; column = 16 ; value ='float2'; } +{kind = TOKEN_SEMICOLON; ; index = 137 ; length = 1 line = 5 ; column = 22 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 141 ; length = 7 line = 6 ; column = 0 ; value ='texture'; } +{kind = TOKEN_COLON; ; index = 155 ; length = 1 line = 6 ; column = 14 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 157 ; length = 9 line = 6 ; column = 16 ; value ='Texture2D'; } +{kind = TOKEN_SEMICOLON; ; index = 166 ; length = 1 line = 6 ; column = 25 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 170 ; length = 7 line = 7 ; column = 0 ; value ='sampler'; } +{kind = TOKEN_COLON; ; index = 184 ; length = 1 line = 7 ; column = 14 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 186 ; length = 7 line = 7 ; column = 16 ; value ='Sampler'; } +{kind = TOKEN_SEMICOLON; ; index = 193 ; length = 1 line = 7 ; column = 23 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 196 ; length = 1 line = 8 ; column = 0 ; value ='}'; } +{kind = TOKEN_IDENTIFIER; ; index = 201 ; length = 8 line = 10 ; column = 0 ; value ='PS_Input'; } +{kind = TOKEN_DOUBLECOLON; ; index = 210 ; length = 2 line = 10 ; column = 9 ; value ='::'; } +{kind = TOKEN_STRUCT; ; index = 213 ; length = 6 line = 10 ; column = 12 ; value ='struct'; } +{kind = TOKEN_LEFTBRACE; ; index = 220 ; length = 1 line = 10 ; column = 19 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 224 ; length = 2 line = 11 ; column = 0 ; value ='uv'; } +{kind = TOKEN_COLON; ; index = 227 ; length = 1 line = 11 ; column = 3 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 229 ; length = 6 line = 11 ; column = 5 ; value ='float2'; } +{kind = TOKEN_AT; ; index = 236 ; length = 1 line = 11 ; column = 12 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 237 ; length = 2 line = 11 ; column = 13 ; value ='uv'; } +{kind = TOKEN_SEMICOLON; ; index = 239 ; length = 1 line = 11 ; column = 15 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 243 ; length = 3 line = 12 ; column = 0 ; value ='pos'; } +{kind = TOKEN_COLON; ; index = 247 ; length = 1 line = 12 ; column = 4 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 249 ; length = 6 line = 12 ; column = 6 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 256 ; length = 1 line = 12 ; column = 13 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 257 ; length = 3 line = 12 ; column = 14 ; value ='pos'; } +{kind = TOKEN_SEMICOLON; ; index = 260 ; length = 1 line = 12 ; column = 17 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 263 ; length = 1 line = 13 ; column = 0 ; value ='}'; } +{kind = TOKEN_VERTEX; ; index = 268 ; length = 6 line = 15 ; column = 0 ; value ='vertex'; } +{kind = TOKEN_IDENTIFIER; ; index = 275 ; length = 4 line = 15 ; column = 7 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 280 ; length = 2 line = 15 ; column = 12 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 283 ; length = 1 line = 15 ; column = 15 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 284 ; length = 3 line = 15 ; column = 16 ; value ='pos'; } +{kind = TOKEN_COLON; ; index = 288 ; length = 1 line = 15 ; column = 20 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 290 ; length = 6 line = 15 ; column = 22 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 297 ; length = 1 line = 15 ; column = 29 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 298 ; length = 8 line = 15 ; column = 30 ; value ='position'; } +{kind = TOKEN_RIGHTPAREN; ; index = 306 ; length = 1 line = 15 ; column = 38 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 308 ; length = 2 line = 15 ; column = 40 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 311 ; length = 8 line = 15 ; column = 43 ; value ='PS_Input'; } +{kind = TOKEN_LEFTBRACE; ; index = 320 ; length = 1 line = 15 ; column = 52 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 324 ; length = 3 line = 16 ; column = 0 ; value ='res'; } +{kind = TOKEN_COLON; ; index = 333 ; length = 1 line = 16 ; column = 9 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 335 ; length = 6 line = 16 ; column = 11 ; value ='float2'; } +{kind = TOKEN_ASSIGN; ; index = 342 ; length = 1 line = 16 ; column = 18 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 344 ; length = 1 line = 16 ; column = 20 ; value ='p'; } +{kind = TOKEN_DOT; ; index = 345 ; length = 1 line = 16 ; column = 21 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 346 ; length = 10 line = 16 ; column = 22 ; value ='resolution'; } +{kind = TOKEN_SEMICOLON; ; index = 356 ; length = 1 line = 16 ; column = 32 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 360 ; length = 5 line = 17 ; column = 0 ; value ='scale'; } +{kind = TOKEN_COLON; ; index = 369 ; length = 1 line = 17 ; column = 9 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 371 ; length = 6 line = 17 ; column = 11 ; value ='float2'; } +{kind = TOKEN_ASSIGN; ; index = 378 ; length = 1 line = 17 ; column = 18 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 380 ; length = 1 line = 17 ; column = 20 ; value ='p'; } +{kind = TOKEN_DOT; ; index = 381 ; length = 1 line = 17 ; column = 21 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 382 ; length = 10 line = 17 ; column = 22 ; value ='rect_scale'; } +{kind = TOKEN_SEMICOLON; ; index = 392 ; length = 1 line = 17 ; column = 32 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 396 ; length = 8 line = 18 ; column = 0 ; value ='rect_pos'; } +{kind = TOKEN_COLON; ; index = 405 ; length = 1 line = 18 ; column = 9 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 407 ; length = 6 line = 18 ; column = 11 ; value ='float2'; } +{kind = TOKEN_ASSIGN; ; index = 414 ; length = 1 line = 18 ; column = 18 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 416 ; length = 1 line = 18 ; column = 20 ; value ='p'; } +{kind = TOKEN_DOT; ; index = 417 ; length = 1 line = 18 ; column = 21 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 418 ; length = 13 line = 18 ; column = 22 ; value ='rect_position'; } +{kind = TOKEN_SEMICOLON; ; index = 431 ; length = 1 line = 18 ; column = 35 ; value =';'; } +{kind = TOKEN_SEMICOLON; ; index = 432 ; length = 1 line = 18 ; column = 36 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 438 ; length = 6 line = 20 ; column = 0 ; value ='center'; } +{kind = TOKEN_COLON; ; index = 445 ; length = 1 line = 20 ; column = 7 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 447 ; length = 6 line = 20 ; column = 9 ; value ='float2'; } +{kind = TOKEN_ASSIGN; ; index = 454 ; length = 1 line = 20 ; column = 16 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 456 ; length = 8 line = 20 ; column = 18 ; value ='rect_pos'; } +{kind = TOKEN_SEMICOLON; ; index = 464 ; length = 1 line = 20 ; column = 26 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 468 ; length = 9 line = 21 ; column = 0 ; value ='half_size'; } +{kind = TOKEN_COLON; ; index = 479 ; length = 1 line = 21 ; column = 11 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 481 ; length = 6 line = 21 ; column = 13 ; value ='float2'; } +{kind = TOKEN_ASSIGN; ; index = 488 ; length = 1 line = 21 ; column = 20 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 490 ; length = 6 line = 21 ; column = 22 ; value ='float2'; } +{kind = TOKEN_LEFTPAREN; ; index = 496 ; length = 1 line = 21 ; column = 28 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 497 ; length = 5 line = 21 ; column = 29 ; value ='scale'; } +{kind = TOKEN_DOT; ; index = 502 ; length = 1 line = 21 ; column = 34 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 503 ; length = 1 line = 21 ; column = 35 ; value ='x'; } +{kind = TOKEN_SLASH; ; index = 505 ; length = 1 line = 21 ; column = 37 ; value ='/'; } +{kind = TOKEN_INTLITERAL; ; index = 507 ; length = 1 line = 21 ; column = 39 ; value ='2'; } +{kind = TOKEN_COMMA; ; index = 508 ; length = 1 line = 21 ; column = 40 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 510 ; length = 5 line = 21 ; column = 42 ; value ='scale'; } +{kind = TOKEN_DOT; ; index = 515 ; length = 1 line = 21 ; column = 47 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 516 ; length = 1 line = 21 ; column = 48 ; value ='y'; } +{kind = TOKEN_SLASH; ; index = 518 ; length = 1 line = 21 ; column = 50 ; value ='/'; } +{kind = TOKEN_INTLITERAL; ; index = 520 ; length = 1 line = 21 ; column = 52 ; value ='2'; } +{kind = TOKEN_RIGHTPAREN; ; index = 521 ; length = 1 line = 21 ; column = 53 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 522 ; length = 1 line = 21 ; column = 54 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 526 ; length = 7 line = 22 ; column = 0 ; value ='dst_pos'; } +{kind = TOKEN_COLON; ; index = 537 ; length = 1 line = 22 ; column = 11 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 539 ; length = 6 line = 22 ; column = 13 ; value ='float4'; } +{kind = TOKEN_ASSIGN; ; index = 546 ; length = 1 line = 22 ; column = 20 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 548 ; length = 6 line = 22 ; column = 22 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 554 ; length = 1 line = 22 ; column = 28 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 555 ; length = 3 line = 22 ; column = 29 ; value ='pos'; } +{kind = TOKEN_DOT; ; index = 558 ; length = 1 line = 22 ; column = 32 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 559 ; length = 1 line = 22 ; column = 33 ; value ='x'; } +{kind = TOKEN_STAR; ; index = 561 ; length = 1 line = 22 ; column = 35 ; value ='*'; } +{kind = TOKEN_IDENTIFIER; ; index = 563 ; length = 9 line = 22 ; column = 37 ; value ='half_size'; } +{kind = TOKEN_DOT; ; index = 572 ; length = 1 line = 22 ; column = 46 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 573 ; length = 1 line = 22 ; column = 47 ; value ='x'; } +{kind = TOKEN_PLUS; ; index = 575 ; length = 1 line = 22 ; column = 49 ; value ='+'; } +{kind = TOKEN_IDENTIFIER; ; index = 577 ; length = 6 line = 22 ; column = 51 ; value ='center'; } +{kind = TOKEN_DOT; ; index = 583 ; length = 1 line = 22 ; column = 57 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 584 ; length = 1 line = 22 ; column = 58 ; value ='x'; } +{kind = TOKEN_COMMA; ; index = 585 ; length = 1 line = 22 ; column = 59 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 587 ; length = 3 line = 22 ; column = 61 ; value ='pos'; } +{kind = TOKEN_DOT; ; index = 590 ; length = 1 line = 22 ; column = 64 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 591 ; length = 1 line = 22 ; column = 65 ; value ='y'; } +{kind = TOKEN_STAR; ; index = 593 ; length = 1 line = 22 ; column = 67 ; value ='*'; } +{kind = TOKEN_IDENTIFIER; ; index = 595 ; length = 9 line = 22 ; column = 69 ; value ='half_size'; } +{kind = TOKEN_DOT; ; index = 604 ; length = 1 line = 22 ; column = 78 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 605 ; length = 1 line = 22 ; column = 79 ; value ='y'; } +{kind = TOKEN_PLUS; ; index = 607 ; length = 1 line = 22 ; column = 81 ; value ='+'; } +{kind = TOKEN_IDENTIFIER; ; index = 609 ; length = 6 line = 22 ; column = 83 ; value ='center'; } +{kind = TOKEN_DOT; ; index = 615 ; length = 1 line = 22 ; column = 89 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 616 ; length = 1 line = 22 ; column = 90 ; value ='y'; } +{kind = TOKEN_COMMA; ; index = 617 ; length = 1 line = 22 ; column = 91 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 619 ; length = 3 line = 22 ; column = 93 ; value ='0'; } +{kind = TOKEN_COMMA; ; index = 622 ; length = 1 line = 22 ; column = 96 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 624 ; length = 3 line = 22 ; column = 98 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 627 ; length = 1 line = 22 ; column = 101 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 628 ; length = 1 line = 22 ; column = 102 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 634 ; length = 6 line = 24 ; column = 0 ; value ='result'; } +{kind = TOKEN_COLON; ; index = 641 ; length = 1 line = 24 ; column = 7 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 643 ; length = 8 line = 24 ; column = 9 ; value ='PS_Input'; } +{kind = TOKEN_SEMICOLON; ; index = 651 ; length = 1 line = 24 ; column = 17 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 657 ; length = 6 line = 26 ; column = 0 ; value ='src_p0'; } +{kind = TOKEN_COLON; ; index = 664 ; length = 1 line = 26 ; column = 7 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 666 ; length = 6 line = 26 ; column = 9 ; value ='float2'; } +{kind = TOKEN_ASSIGN; ; index = 673 ; length = 1 line = 26 ; column = 16 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 675 ; length = 6 line = 26 ; column = 18 ; value ='float2'; } +{kind = TOKEN_LEFTPAREN; ; index = 681 ; length = 1 line = 26 ; column = 24 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 682 ; length = 3 line = 26 ; column = 25 ; value ='0'; } +{kind = TOKEN_COMMA; ; index = 685 ; length = 1 line = 26 ; column = 28 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 687 ; length = 3 line = 26 ; column = 30 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 690 ; length = 1 line = 26 ; column = 33 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 691 ; length = 1 line = 26 ; column = 34 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 695 ; length = 6 line = 27 ; column = 0 ; value ='src_p1'; } +{kind = TOKEN_COLON; ; index = 702 ; length = 1 line = 27 ; column = 7 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 704 ; length = 6 line = 27 ; column = 9 ; value ='float2'; } +{kind = TOKEN_ASSIGN; ; index = 711 ; length = 1 line = 27 ; column = 16 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 713 ; length = 6 line = 27 ; column = 18 ; value ='float2'; } +{kind = TOKEN_LEFTPAREN; ; index = 719 ; length = 1 line = 27 ; column = 24 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 720 ; length = 3 line = 27 ; column = 25 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 723 ; length = 1 line = 27 ; column = 28 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 725 ; length = 3 line = 27 ; column = 30 ; value ='0'; } +{kind = TOKEN_RIGHTPAREN; ; index = 728 ; length = 1 line = 27 ; column = 33 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 729 ; length = 1 line = 27 ; column = 34 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 735 ; length = 13 line = 29 ; column = 0 ; value ='src_half_size'; } +{kind = TOKEN_COLON; ; index = 749 ; length = 1 line = 29 ; column = 14 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 751 ; length = 6 line = 29 ; column = 16 ; value ='float2'; } +{kind = TOKEN_ASSIGN; ; index = 758 ; length = 1 line = 29 ; column = 23 ; value ='='; } +{kind = TOKEN_LEFTPAREN; ; index = 760 ; length = 1 line = 29 ; column = 25 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 761 ; length = 6 line = 29 ; column = 26 ; value ='src_p1'; } +{kind = TOKEN_MINUS; ; index = 768 ; length = 1 line = 29 ; column = 33 ; value ='-'; } +{kind = TOKEN_IDENTIFIER; ; index = 770 ; length = 6 line = 29 ; column = 35 ; value ='src_p0'; } +{kind = TOKEN_RIGHTPAREN; ; index = 776 ; length = 1 line = 29 ; column = 41 ; value =')'; } +{kind = TOKEN_SLASH; ; index = 778 ; length = 1 line = 29 ; column = 43 ; value ='/'; } +{kind = TOKEN_INTLITERAL; ; index = 780 ; length = 1 line = 29 ; column = 45 ; value ='2'; } +{kind = TOKEN_SEMICOLON; ; index = 781 ; length = 1 line = 29 ; column = 46 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 785 ; length = 10 line = 30 ; column = 0 ; value ='src_center'; } +{kind = TOKEN_COLON; ; index = 799 ; length = 1 line = 30 ; column = 14 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 801 ; length = 6 line = 30 ; column = 16 ; value ='float2'; } +{kind = TOKEN_ASSIGN; ; index = 808 ; length = 1 line = 30 ; column = 23 ; value ='='; } +{kind = TOKEN_LEFTPAREN; ; index = 810 ; length = 1 line = 30 ; column = 25 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 811 ; length = 6 line = 30 ; column = 26 ; value ='src_p1'; } +{kind = TOKEN_PLUS; ; index = 818 ; length = 1 line = 30 ; column = 33 ; value ='+'; } +{kind = TOKEN_IDENTIFIER; ; index = 820 ; length = 6 line = 30 ; column = 35 ; value ='src_p0'; } +{kind = TOKEN_RIGHTPAREN; ; index = 826 ; length = 1 line = 30 ; column = 41 ; value =')'; } +{kind = TOKEN_SLASH; ; index = 828 ; length = 1 line = 30 ; column = 43 ; value ='/'; } +{kind = TOKEN_INTLITERAL; ; index = 830 ; length = 1 line = 30 ; column = 45 ; value ='2'; } +{kind = TOKEN_SEMICOLON; ; index = 831 ; length = 1 line = 30 ; column = 46 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 835 ; length = 7 line = 31 ; column = 0 ; value ='src_pos'; } +{kind = TOKEN_COLON; ; index = 849 ; length = 1 line = 31 ; column = 14 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 851 ; length = 6 line = 31 ; column = 16 ; value ='float2'; } +{kind = TOKEN_ASSIGN; ; index = 858 ; length = 1 line = 31 ; column = 23 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 860 ; length = 6 line = 31 ; column = 25 ; value ='float2'; } +{kind = TOKEN_LEFTPAREN; ; index = 866 ; length = 1 line = 31 ; column = 31 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 867 ; length = 3 line = 31 ; column = 32 ; value ='pos'; } +{kind = TOKEN_DOT; ; index = 870 ; length = 1 line = 31 ; column = 35 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 871 ; length = 1 line = 31 ; column = 36 ; value ='x'; } +{kind = TOKEN_COMMA; ; index = 872 ; length = 1 line = 31 ; column = 37 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 874 ; length = 3 line = 31 ; column = 39 ; value ='pos'; } +{kind = TOKEN_DOT; ; index = 877 ; length = 1 line = 31 ; column = 42 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 878 ; length = 1 line = 31 ; column = 43 ; value ='y'; } +{kind = TOKEN_RIGHTPAREN; ; index = 879 ; length = 1 line = 31 ; column = 44 ; value =')'; } +{kind = TOKEN_STAR; ; index = 881 ; length = 1 line = 31 ; column = 46 ; value ='*'; } +{kind = TOKEN_IDENTIFIER; ; index = 883 ; length = 13 line = 31 ; column = 48 ; value ='src_half_size'; } +{kind = TOKEN_PLUS; ; index = 897 ; length = 1 line = 31 ; column = 62 ; value ='+'; } +{kind = TOKEN_IDENTIFIER; ; index = 899 ; length = 10 line = 31 ; column = 64 ; value ='src_center'; } +{kind = TOKEN_SEMICOLON; ; index = 909 ; length = 1 line = 31 ; column = 74 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 915 ; length = 6 line = 33 ; column = 0 ; value ='result'; } +{kind = TOKEN_DOT; ; index = 921 ; length = 1 line = 33 ; column = 6 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 922 ; length = 2 line = 33 ; column = 7 ; value ='uv'; } +{kind = TOKEN_ASSIGN; ; index = 925 ; length = 1 line = 33 ; column = 10 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 927 ; length = 6 line = 33 ; column = 12 ; value ='float2'; } +{kind = TOKEN_LEFTPAREN; ; index = 933 ; length = 1 line = 33 ; column = 18 ; value ='('; } +{kind = TOKEN_INTLITERAL; ; index = 934 ; length = 1 line = 33 ; column = 19 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 935 ; length = 1 line = 33 ; column = 20 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 937 ; length = 1 line = 33 ; column = 22 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 938 ; length = 1 line = 33 ; column = 23 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 939 ; length = 1 line = 33 ; column = 24 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 943 ; length = 6 line = 34 ; column = 0 ; value ='result'; } +{kind = TOKEN_DOT; ; index = 949 ; length = 1 line = 34 ; column = 6 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 950 ; length = 3 line = 34 ; column = 7 ; value ='pos'; } +{kind = TOKEN_ASSIGN; ; index = 954 ; length = 1 line = 34 ; column = 11 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 956 ; length = 6 line = 34 ; column = 13 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 962 ; length = 1 line = 34 ; column = 19 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 963 ; length = 3 line = 34 ; column = 20 ; value ='2'; } +{kind = TOKEN_STAR; ; index = 967 ; length = 1 line = 34 ; column = 24 ; value ='*'; } +{kind = TOKEN_IDENTIFIER; ; index = 969 ; length = 7 line = 34 ; column = 26 ; value ='dst_pos'; } +{kind = TOKEN_DOT; ; index = 976 ; length = 1 line = 34 ; column = 33 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 977 ; length = 1 line = 34 ; column = 34 ; value ='x'; } +{kind = TOKEN_SLASH; ; index = 979 ; length = 1 line = 34 ; column = 36 ; value ='/'; } +{kind = TOKEN_IDENTIFIER; ; index = 981 ; length = 3 line = 34 ; column = 38 ; value ='res'; } +{kind = TOKEN_DOT; ; index = 984 ; length = 1 line = 34 ; column = 41 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 985 ; length = 1 line = 34 ; column = 42 ; value ='x'; } +{kind = TOKEN_MINUS; ; index = 987 ; length = 1 line = 34 ; column = 44 ; value ='-'; } +{kind = TOKEN_INTLITERAL; ; index = 989 ; length = 1 line = 34 ; column = 46 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 990 ; length = 1 line = 34 ; column = 47 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 992 ; length = 3 line = 34 ; column = 49 ; value ='2'; } +{kind = TOKEN_STAR; ; index = 996 ; length = 1 line = 34 ; column = 53 ; value ='*'; } +{kind = TOKEN_IDENTIFIER; ; index = 998 ; length = 7 line = 34 ; column = 55 ; value ='dst_pos'; } +{kind = TOKEN_DOT; ; index = 1005 ; length = 1 line = 34 ; column = 62 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 1006 ; length = 1 line = 34 ; column = 63 ; value ='y'; } +{kind = TOKEN_SLASH; ; index = 1008 ; length = 1 line = 34 ; column = 65 ; value ='/'; } +{kind = TOKEN_IDENTIFIER; ; index = 1010 ; length = 3 line = 34 ; column = 67 ; value ='res'; } +{kind = TOKEN_DOT; ; index = 1013 ; length = 1 line = 34 ; column = 70 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 1014 ; length = 1 line = 34 ; column = 71 ; value ='y'; } +{kind = TOKEN_MINUS; ; index = 1016 ; length = 1 line = 34 ; column = 73 ; value ='-'; } +{kind = TOKEN_INTLITERAL; ; index = 1018 ; length = 1 line = 34 ; column = 75 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 1019 ; length = 1 line = 34 ; column = 76 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 1021 ; length = 3 line = 34 ; column = 78 ; value ='0'; } +{kind = TOKEN_COMMA; ; index = 1024 ; length = 1 line = 34 ; column = 81 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 1026 ; length = 3 line = 34 ; column = 83 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 1029 ; length = 1 line = 34 ; column = 86 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 1030 ; length = 1 line = 34 ; column = 87 ; value =';'; } +{kind = TOKEN_RETURN; ; index = 1036 ; length = 6 line = 36 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 1043 ; length = 6 line = 36 ; column = 7 ; value ='result'; } +{kind = TOKEN_SEMICOLON; ; index = 1049 ; length = 1 line = 36 ; column = 13 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 1052 ; length = 1 line = 37 ; column = 0 ; value ='}'; } +{kind = TOKEN_PIXEL; ; index = 1057 ; length = 5 line = 39 ; column = 0 ; value ='pixel'; } +{kind = TOKEN_IDENTIFIER; ; index = 1063 ; length = 4 line = 39 ; column = 6 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 1068 ; length = 2 line = 39 ; column = 11 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 1071 ; length = 1 line = 39 ; column = 14 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 1072 ; length = 5 line = 39 ; column = 15 ; value ='input'; } +{kind = TOKEN_COLON; ; index = 1078 ; length = 1 line = 39 ; column = 21 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 1080 ; length = 8 line = 39 ; column = 23 ; value ='PS_Input'; } +{kind = TOKEN_RIGHTPAREN; ; index = 1088 ; length = 1 line = 39 ; column = 31 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 1090 ; length = 2 line = 39 ; column = 33 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 1093 ; length = 6 line = 39 ; column = 36 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 1100 ; length = 1 line = 39 ; column = 43 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 1101 ; length = 7 line = 39 ; column = 44 ; value ='target0'; } +{kind = TOKEN_LEFTBRACE; ; index = 1109 ; length = 1 line = 39 ; column = 52 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 1113 ; length = 5 line = 40 ; column = 0 ; value ='color'; } +{kind = TOKEN_COLON; ; index = 1119 ; length = 1 line = 40 ; column = 6 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 1121 ; length = 6 line = 40 ; column = 8 ; value ='float4'; } +{kind = TOKEN_ASSIGN; ; index = 1128 ; length = 1 line = 40 ; column = 15 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 1130 ; length = 1 line = 40 ; column = 17 ; value ='p'; } +{kind = TOKEN_DOT; ; index = 1131 ; length = 1 line = 40 ; column = 18 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 1132 ; length = 5 line = 40 ; column = 19 ; value ='color'; } +{kind = TOKEN_SEMICOLON; ; index = 1137 ; length = 1 line = 40 ; column = 24 ; value =';'; } +{kind = TOKEN_RETURN; ; index = 1141 ; length = 6 line = 41 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 1148 ; length = 5 line = 41 ; column = 7 ; value ='color'; } +{kind = TOKEN_SEMICOLON; ; index = 1153 ; length = 1 line = 41 ; column = 12 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 1156 ; length = 1 line = 42 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 1159 ; length = 0 line = 43 ; column = 0 ; value =''; } diff --git a/test/lex/load_test.golden b/test/lex/load_test.golden new file mode 100644 index 0000000..cf71590 Binary files /dev/null and b/test/lex/load_test.golden differ diff --git a/test/lex/meta_block.golden b/test/lex/meta_block.golden new file mode 100644 index 0000000..5430249 --- /dev/null +++ b/test/lex/meta_block.golden @@ -0,0 +1,60 @@ +{kind = TOKEN_META; ; index = 0 ; length = 4 line = 1 ; column = 0 ; value ='meta'; } +{kind = TOKEN_LEFTBRACE; ; index = 5 ; length = 1 line = 1 ; column = 5 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 9 ; length = 4 line = 2 ; column = 0 ; value ='name'; } +{kind = TOKEN_COLON; ; index = 18 ; length = 1 line = 2 ; column = 9 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 20 ; length = 8 line = 2 ; column = 11 ; value ='LitBasic'; } +{kind = TOKEN_SEMICOLON; ; index = 28 ; length = 1 line = 2 ; column = 19 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 32 ; length = 8 line = 3 ; column = 0 ; value ='category'; } +{kind = TOKEN_COLON; ; index = 41 ; length = 1 line = 3 ; column = 9 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 43 ; length = 5 line = 3 ; column = 11 ; value ='Scene'; } +{kind = TOKEN_SEMICOLON; ; index = 48 ; length = 1 line = 3 ; column = 16 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 51 ; length = 1 line = 4 ; column = 0 ; value ='}'; } +{kind = TOKEN_PROPERTIES; ; index = 56 ; length = 10 line = 6 ; column = 0 ; value ='properties'; } +{kind = TOKEN_LEFTBRACE; ; index = 67 ; length = 1 line = 6 ; column = 11 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 71 ; length = 5 line = 7 ; column = 0 ; value ='color'; } +{kind = TOKEN_COLON; ; index = 77 ; length = 1 line = 7 ; column = 6 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 79 ; length = 6 line = 7 ; column = 8 ; value ='float4'; } +{kind = TOKEN_SEMICOLON; ; index = 85 ; length = 1 line = 7 ; column = 14 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 88 ; length = 1 line = 8 ; column = 0 ; value ='}'; } +{kind = TOKEN_VERTEX; ; index = 93 ; length = 6 line = 10 ; column = 0 ; value ='vertex'; } +{kind = TOKEN_IDENTIFIER; ; index = 100 ; length = 4 line = 10 ; column = 7 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 105 ; length = 2 line = 10 ; column = 12 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 108 ; length = 1 line = 10 ; column = 15 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 109 ; length = 3 line = 10 ; column = 16 ; value ='pos'; } +{kind = TOKEN_COLON; ; index = 113 ; length = 1 line = 10 ; column = 20 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 115 ; length = 6 line = 10 ; column = 22 ; value ='float3'; } +{kind = TOKEN_AT; ; index = 122 ; length = 1 line = 10 ; column = 29 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 123 ; length = 8 line = 10 ; column = 30 ; value ='position'; } +{kind = TOKEN_COMMA; ; index = 131 ; length = 1 line = 10 ; column = 38 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 133 ; length = 2 line = 10 ; column = 40 ; value ='uv'; } +{kind = TOKEN_COLON; ; index = 136 ; length = 1 line = 10 ; column = 43 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 138 ; length = 6 line = 10 ; column = 45 ; value ='float2'; } +{kind = TOKEN_AT; ; index = 145 ; length = 1 line = 10 ; column = 52 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 146 ; length = 2 line = 10 ; column = 53 ; value ='uv'; } +{kind = TOKEN_RIGHTPAREN; ; index = 148 ; length = 1 line = 10 ; column = 55 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 150 ; length = 2 line = 10 ; column = 57 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 153 ; length = 6 line = 10 ; column = 60 ; value ='float3'; } +{kind = TOKEN_AT; ; index = 160 ; length = 1 line = 10 ; column = 67 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 161 ; length = 8 line = 10 ; column = 68 ; value ='position'; } +{kind = TOKEN_LEFTBRACE; ; index = 170 ; length = 1 line = 10 ; column = 77 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 174 ; length = 6 line = 11 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 181 ; length = 3 line = 11 ; column = 7 ; value ='pos'; } +{kind = TOKEN_SEMICOLON; ; index = 184 ; length = 1 line = 11 ; column = 10 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 187 ; length = 1 line = 12 ; column = 0 ; value ='}'; } +{kind = TOKEN_PIXEL; ; index = 192 ; length = 5 line = 14 ; column = 0 ; value ='pixel'; } +{kind = TOKEN_IDENTIFIER; ; index = 198 ; length = 4 line = 14 ; column = 6 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 203 ; length = 2 line = 14 ; column = 11 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 206 ; length = 1 line = 14 ; column = 14 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 207 ; length = 1 line = 14 ; column = 15 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 209 ; length = 2 line = 14 ; column = 17 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 212 ; length = 6 line = 14 ; column = 20 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 219 ; length = 1 line = 14 ; column = 27 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 220 ; length = 7 line = 14 ; column = 28 ; value ='target0'; } +{kind = TOKEN_LEFTBRACE; ; index = 228 ; length = 1 line = 14 ; column = 36 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 232 ; length = 6 line = 15 ; column = 0 ; value ='return'; } +{kind = TOKEN_PROPERTIES; ; index = 239 ; length = 10 line = 15 ; column = 7 ; value ='properties'; } +{kind = TOKEN_DOT; ; index = 249 ; length = 1 line = 15 ; column = 17 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 250 ; length = 5 line = 15 ; column = 18 ; value ='color'; } +{kind = TOKEN_SEMICOLON; ; index = 255 ; length = 1 line = 15 ; column = 23 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 258 ; length = 1 line = 16 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 261 ; length = 0 line = 17 ; column = 0 ; value =''; } diff --git a/test/lex/multiple_functions.golden b/test/lex/multiple_functions.golden new file mode 100644 index 0000000..53b3d1e --- /dev/null +++ b/test/lex/multiple_functions.golden @@ -0,0 +1,48 @@ +{kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 3 line = 1 ; column = 0 ; value ='foo'; } +{kind = TOKEN_DOUBLECOLON; ; index = 4 ; length = 2 line = 1 ; column = 4 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 7 ; length = 1 line = 1 ; column = 7 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 8 ; length = 1 line = 1 ; column = 8 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 10 ; length = 2 line = 1 ; column = 10 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 13 ; length = 3 line = 1 ; column = 13 ; value ='int'; } +{kind = TOKEN_LEFTBRACE; ; index = 17 ; length = 1 line = 1 ; column = 17 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 21 ; length = 6 line = 2 ; column = 0 ; value ='return'; } +{kind = TOKEN_INTLITERAL; ; index = 28 ; length = 1 line = 2 ; column = 7 ; value ='5'; } +{kind = TOKEN_SEMICOLON; ; index = 29 ; length = 1 line = 2 ; column = 8 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 32 ; length = 1 line = 3 ; column = 0 ; value ='}'; } +{kind = TOKEN_IDENTIFIER; ; index = 37 ; length = 3 line = 5 ; column = 0 ; value ='bar'; } +{kind = TOKEN_DOUBLECOLON; ; index = 41 ; length = 2 line = 5 ; column = 4 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 44 ; length = 1 line = 5 ; column = 7 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 45 ; length = 1 line = 5 ; column = 8 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 47 ; length = 2 line = 5 ; column = 10 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 50 ; length = 5 line = 5 ; column = 13 ; value ='float'; } +{kind = TOKEN_LEFTBRACE; ; index = 56 ; length = 1 line = 5 ; column = 19 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 60 ; length = 6 line = 6 ; column = 0 ; value ='return'; } +{kind = TOKEN_FLOATLITERAL; ; index = 67 ; length = 6 line = 6 ; column = 7 ; value ='1235'; } +{kind = TOKEN_STAR; ; index = 74 ; length = 1 line = 6 ; column = 14 ; value ='*'; } +{kind = TOKEN_INTLITERAL; ; index = 76 ; length = 3 line = 6 ; column = 16 ; value ='500'; } +{kind = TOKEN_SEMICOLON; ; index = 79 ; length = 1 line = 6 ; column = 19 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 82 ; length = 1 line = 7 ; column = 0 ; value ='}'; } +{kind = TOKEN_VERTEX; ; index = 87 ; length = 6 line = 9 ; column = 0 ; value ='vertex'; } +{kind = TOKEN_IDENTIFIER; ; index = 94 ; length = 4 line = 9 ; column = 7 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 99 ; length = 2 line = 9 ; column = 12 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 102 ; length = 1 line = 9 ; column = 15 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 103 ; length = 1 line = 9 ; column = 16 ; value =')'; } +{kind = TOKEN_LEFTBRACE; ; index = 105 ; length = 1 line = 9 ; column = 18 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 109 ; length = 1 line = 10 ; column = 0 ; value ='x'; } +{kind = TOKEN_COLON; ; index = 111 ; length = 1 line = 10 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 113 ; length = 3 line = 10 ; column = 4 ; value ='int'; } +{kind = TOKEN_ASSIGN; ; index = 117 ; length = 1 line = 10 ; column = 8 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 119 ; length = 3 line = 10 ; column = 10 ; value ='foo'; } +{kind = TOKEN_LEFTPAREN; ; index = 122 ; length = 1 line = 10 ; column = 13 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 123 ; length = 1 line = 10 ; column = 14 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 124 ; length = 1 line = 10 ; column = 15 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 128 ; length = 1 line = 11 ; column = 0 ; value ='y'; } +{kind = TOKEN_COLON; ; index = 130 ; length = 1 line = 11 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 132 ; length = 5 line = 11 ; column = 4 ; value ='float'; } +{kind = TOKEN_ASSIGN; ; index = 138 ; length = 1 line = 11 ; column = 10 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 140 ; length = 3 line = 11 ; column = 12 ; value ='bar'; } +{kind = TOKEN_LEFTPAREN; ; index = 143 ; length = 1 line = 11 ; column = 15 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 144 ; length = 1 line = 11 ; column = 16 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 145 ; length = 1 line = 11 ; column = 17 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 148 ; length = 1 line = 12 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 151 ; length = 0 line = 13 ; column = 0 ; value =''; } diff --git a/test/lex/multiple_semicolons_everywhere.golden b/test/lex/multiple_semicolons_everywhere.golden new file mode 100644 index 0000000..00649a1 --- /dev/null +++ b/test/lex/multiple_semicolons_everywhere.golden @@ -0,0 +1,77 @@ +{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 ='float3'; } +{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_RETURN; ; index = 64 ; length = 6 line = 2 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 71 ; length = 3 line = 2 ; column = 7 ; value ='pos'; } +{kind = TOKEN_SEMICOLON; ; index = 74 ; length = 1 line = 2 ; column = 10 ; value =';'; } +{kind = TOKEN_SEMICOLON; ; index = 75 ; length = 1 line = 2 ; column = 11 ; value =';'; } +{kind = TOKEN_SEMICOLON; ; index = 76 ; length = 1 line = 2 ; column = 12 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 79 ; length = 1 line = 3 ; column = 0 ; value ='}'; } +{kind = TOKEN_IDENTIFIER; ; index = 84 ; length = 3 line = 5 ; column = 0 ; value ='foo'; } +{kind = TOKEN_DOUBLECOLON; ; index = 88 ; length = 2 line = 5 ; column = 4 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 91 ; length = 1 line = 5 ; column = 7 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 92 ; length = 1 line = 5 ; column = 8 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 94 ; length = 2 line = 5 ; column = 10 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 97 ; length = 6 line = 5 ; column = 13 ; value ='float4'; } +{kind = TOKEN_LEFTBRACE; ; index = 104 ; length = 1 line = 5 ; column = 20 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 108 ; length = 6 line = 6 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 115 ; length = 6 line = 6 ; column = 7 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 121 ; length = 1 line = 6 ; column = 13 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 122 ; length = 3 line = 6 ; column = 14 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 125 ; length = 1 line = 6 ; column = 17 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 127 ; length = 3 line = 6 ; column = 19 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 130 ; length = 1 line = 6 ; column = 22 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 132 ; length = 3 line = 6 ; column = 24 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 135 ; length = 1 line = 6 ; column = 27 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 137 ; length = 3 line = 6 ; column = 29 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 140 ; length = 1 line = 6 ; column = 32 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 141 ; length = 1 line = 6 ; column = 33 ; value =';'; } +{kind = TOKEN_SEMICOLON; ; index = 142 ; length = 1 line = 6 ; column = 34 ; value =';'; } +{kind = TOKEN_SEMICOLON; ; index = 143 ; length = 1 line = 6 ; column = 35 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 146 ; length = 1 line = 7 ; column = 0 ; value ='}'; } +{kind = TOKEN_PIXEL; ; index = 151 ; length = 5 line = 9 ; column = 0 ; value ='pixel'; } +{kind = TOKEN_IDENTIFIER; ; index = 157 ; length = 4 line = 9 ; column = 6 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 162 ; length = 2 line = 9 ; column = 11 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 165 ; length = 1 line = 9 ; column = 14 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 166 ; length = 1 line = 9 ; column = 15 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 168 ; length = 2 line = 9 ; column = 17 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 171 ; length = 6 line = 9 ; column = 20 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 178 ; length = 1 line = 9 ; column = 27 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 179 ; length = 7 line = 9 ; column = 28 ; value ='target0'; } +{kind = TOKEN_LEFTBRACE; ; index = 187 ; length = 1 line = 9 ; column = 36 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 191 ; length = 1 line = 10 ; column = 0 ; value ='y'; } +{kind = TOKEN_COLON; ; index = 193 ; length = 1 line = 10 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 195 ; length = 6 line = 10 ; column = 4 ; value ='float4'; } +{kind = TOKEN_ASSIGN; ; index = 202 ; length = 1 line = 10 ; column = 11 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 204 ; length = 3 line = 10 ; column = 13 ; value ='foo'; } +{kind = TOKEN_LEFTPAREN; ; index = 207 ; length = 1 line = 10 ; column = 16 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 208 ; length = 1 line = 10 ; column = 17 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 209 ; length = 1 line = 10 ; column = 18 ; value =';'; } +{kind = TOKEN_SEMICOLON; ; index = 210 ; length = 1 line = 10 ; column = 19 ; value =';'; } +{kind = TOKEN_SEMICOLON; ; index = 211 ; length = 1 line = 10 ; column = 20 ; value =';'; } +{kind = TOKEN_SEMICOLON; ; index = 212 ; length = 1 line = 10 ; column = 21 ; value =';'; } +{kind = TOKEN_SEMICOLON; ; index = 216 ; length = 1 line = 11 ; column = 0 ; value =';'; } +{kind = TOKEN_SEMICOLON; ; index = 217 ; length = 1 line = 11 ; column = 1 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 221 ; length = 5 line = 12 ; column = 0 ; value ='color'; } +{kind = TOKEN_COLON; ; index = 227 ; length = 1 line = 12 ; column = 6 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 229 ; length = 6 line = 12 ; column = 8 ; value ='float4'; } +{kind = TOKEN_ASSIGN; ; index = 236 ; length = 1 line = 12 ; column = 15 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 238 ; length = 1 line = 12 ; column = 17 ; value ='y'; } +{kind = TOKEN_SEMICOLON; ; index = 239 ; length = 1 line = 12 ; column = 18 ; value =';'; } +{kind = TOKEN_RETURN; ; index = 243 ; length = 6 line = 13 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 250 ; length = 5 line = 13 ; column = 7 ; value ='color'; } +{kind = TOKEN_SEMICOLON; ; index = 255 ; length = 1 line = 13 ; column = 12 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 258 ; length = 1 line = 14 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 261 ; length = 0 line = 15 ; column = 0 ; value =''; } diff --git a/test/lex/nested_if.golden b/test/lex/nested_if.golden new file mode 100644 index 0000000..8a8e101 --- /dev/null +++ b/test/lex/nested_if.golden @@ -0,0 +1,64 @@ +{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_IDENTIFIER; ; index = 67 ; length = 3 line = 2 ; column = 3 ; value ='pos'; } +{kind = TOKEN_DOT; ; index = 70 ; length = 1 line = 2 ; column = 6 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 71 ; length = 1 line = 2 ; column = 7 ; value ='x'; } +{kind = TOKEN_GREATER; ; index = 73 ; length = 1 line = 2 ; column = 9 ; value ='>'; } +{kind = TOKEN_INTLITERAL; ; index = 75 ; length = 3 line = 2 ; column = 11 ; value ='100'; } +{kind = TOKEN_LEFTBRACE; ; index = 79 ; length = 1 line = 2 ; column = 15 ; value ='{'; } +{kind = TOKEN_IF; ; index = 84 ; length = 2 line = 3 ; column = 0 ; value ='if'; } +{kind = TOKEN_IDENTIFIER; ; index = 87 ; length = 3 line = 3 ; column = 3 ; value ='pos'; } +{kind = TOKEN_DOT; ; index = 90 ; length = 1 line = 3 ; column = 6 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 91 ; length = 1 line = 3 ; column = 7 ; value ='x'; } +{kind = TOKEN_GREATER; ; index = 93 ; length = 1 line = 3 ; column = 9 ; value ='>'; } +{kind = TOKEN_INTLITERAL; ; index = 95 ; length = 2 line = 3 ; column = 11 ; value ='50'; } +{kind = TOKEN_LEFTBRACE; ; index = 98 ; length = 1 line = 3 ; column = 14 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 104 ; length = 6 line = 4 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 111 ; length = 6 line = 4 ; column = 7 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 117 ; length = 1 line = 4 ; column = 13 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 118 ; length = 3 line = 4 ; column = 14 ; value ='pos'; } +{kind = TOKEN_COMMA; ; index = 121 ; length = 1 line = 4 ; column = 17 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 123 ; length = 3 line = 4 ; column = 19 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 126 ; length = 1 line = 4 ; column = 22 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 127 ; length = 1 line = 4 ; column = 23 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 132 ; length = 1 line = 5 ; column = 0 ; value ='}'; } +{kind = TOKEN_ELSE; ; index = 134 ; length = 4 line = 5 ; column = 2 ; value ='else'; } +{kind = TOKEN_LEFTBRACE; ; index = 139 ; length = 1 line = 5 ; column = 7 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 145 ; length = 6 line = 6 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 152 ; length = 6 line = 6 ; column = 7 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 158 ; length = 1 line = 6 ; column = 13 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 159 ; length = 3 line = 6 ; column = 14 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 162 ; length = 1 line = 6 ; column = 17 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 163 ; length = 1 line = 6 ; column = 18 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 168 ; length = 1 line = 7 ; column = 0 ; value ='}'; } +{kind = TOKEN_RETURN; ; index = 173 ; length = 6 line = 8 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 180 ; length = 6 line = 8 ; column = 7 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 186 ; length = 1 line = 8 ; column = 13 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 187 ; length = 3 line = 8 ; column = 14 ; value ='pos'; } +{kind = TOKEN_COMMA; ; index = 190 ; length = 1 line = 8 ; column = 17 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 192 ; length = 3 line = 8 ; column = 19 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 195 ; length = 1 line = 8 ; column = 22 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 196 ; length = 1 line = 8 ; column = 23 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 200 ; length = 1 line = 9 ; column = 0 ; value ='}'; } +{kind = TOKEN_RETURN; ; index = 205 ; length = 6 line = 10 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 212 ; length = 6 line = 10 ; column = 7 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 218 ; length = 1 line = 10 ; column = 13 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 219 ; length = 3 line = 10 ; column = 14 ; value ='0'; } +{kind = TOKEN_RIGHTPAREN; ; index = 222 ; length = 1 line = 10 ; column = 17 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 223 ; length = 1 line = 10 ; column = 18 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 226 ; length = 1 line = 11 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 229 ; length = 0 line = 12 ; column = 0 ; value =''; } diff --git a/test/lex/non_bool_cond.golden b/test/lex/non_bool_cond.golden new file mode 100644 index 0000000..38f1583 --- /dev/null +++ b/test/lex/non_bool_cond.golden @@ -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 =''; } diff --git a/test/lex/pass_and_access_struct_fields_in_functions.golden b/test/lex/pass_and_access_struct_fields_in_functions.golden new file mode 100644 index 0000000..4f2a996 --- /dev/null +++ b/test/lex/pass_and_access_struct_fields_in_functions.golden @@ -0,0 +1,54 @@ +{kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 3 line = 1 ; column = 0 ; value ='Foo'; } +{kind = TOKEN_DOUBLECOLON; ; index = 4 ; length = 2 line = 1 ; column = 4 ; value ='::'; } +{kind = TOKEN_STRUCT; ; index = 7 ; length = 6 line = 1 ; column = 7 ; value ='struct'; } +{kind = TOKEN_LEFTBRACE; ; index = 14 ; length = 1 line = 1 ; column = 14 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 18 ; length = 9 line = 2 ; column = 0 ; value ='some_data'; } +{kind = TOKEN_COLON; ; index = 28 ; length = 1 line = 2 ; column = 10 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 30 ; length = 5 line = 2 ; column = 12 ; value ='float'; } +{kind = TOKEN_SEMICOLON; ; index = 35 ; length = 1 line = 2 ; column = 17 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 38 ; length = 1 line = 3 ; column = 0 ; value ='}'; } +{kind = TOKEN_IDENTIFIER; ; index = 43 ; length = 3 line = 5 ; column = 0 ; value ='foo'; } +{kind = TOKEN_DOUBLECOLON; ; index = 47 ; length = 2 line = 5 ; column = 4 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 50 ; length = 1 line = 5 ; column = 7 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 51 ; length = 1 line = 5 ; column = 8 ; value ='f'; } +{kind = TOKEN_COLON; ; index = 53 ; length = 1 line = 5 ; column = 10 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 55 ; length = 3 line = 5 ; column = 12 ; value ='Foo'; } +{kind = TOKEN_RIGHTPAREN; ; index = 58 ; length = 1 line = 5 ; column = 15 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 60 ; length = 2 line = 5 ; column = 17 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 63 ; length = 5 line = 5 ; column = 20 ; value ='float'; } +{kind = TOKEN_LEFTBRACE; ; index = 69 ; length = 1 line = 5 ; column = 26 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 73 ; length = 6 line = 6 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 80 ; length = 1 line = 6 ; column = 7 ; value ='f'; } +{kind = TOKEN_DOT; ; index = 81 ; length = 1 line = 6 ; column = 8 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 82 ; length = 9 line = 6 ; column = 9 ; value ='some_data'; } +{kind = TOKEN_STAR; ; index = 92 ; length = 1 line = 6 ; column = 19 ; value ='*'; } +{kind = TOKEN_FLOATLITERAL; ; index = 94 ; length = 3 line = 6 ; column = 21 ; value ='2'; } +{kind = TOKEN_SEMICOLON; ; index = 97 ; length = 1 line = 6 ; column = 24 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 100 ; length = 1 line = 7 ; column = 0 ; value ='}'; } +{kind = TOKEN_VERTEX; ; index = 105 ; length = 6 line = 9 ; column = 0 ; value ='vertex'; } +{kind = TOKEN_IDENTIFIER; ; index = 112 ; length = 4 line = 9 ; column = 7 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 117 ; length = 2 line = 9 ; column = 12 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 120 ; length = 1 line = 9 ; column = 15 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 121 ; length = 1 line = 9 ; column = 16 ; value =')'; } +{kind = TOKEN_LEFTBRACE; ; index = 123 ; length = 1 line = 9 ; column = 18 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 127 ; length = 1 line = 10 ; column = 0 ; value ='f'; } +{kind = TOKEN_COLON; ; index = 129 ; length = 1 line = 10 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 131 ; length = 3 line = 10 ; column = 4 ; value ='Foo'; } +{kind = TOKEN_SEMICOLON; ; index = 134 ; length = 1 line = 10 ; column = 7 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 138 ; length = 1 line = 11 ; column = 0 ; value ='f'; } +{kind = TOKEN_DOT; ; index = 139 ; length = 1 line = 11 ; column = 1 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 140 ; length = 9 line = 11 ; column = 2 ; value ='some_data'; } +{kind = TOKEN_ASSIGN; ; index = 150 ; length = 1 line = 11 ; column = 12 ; value ='='; } +{kind = TOKEN_FLOATLITERAL; ; index = 152 ; length = 3 line = 11 ; column = 14 ; value ='4'; } +{kind = TOKEN_SEMICOLON; ; index = 155 ; length = 1 line = 11 ; column = 17 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 159 ; length = 1 line = 12 ; column = 0 ; value ='d'; } +{kind = TOKEN_COLON; ; index = 161 ; length = 1 line = 12 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 163 ; length = 5 line = 12 ; column = 4 ; value ='float'; } +{kind = TOKEN_ASSIGN; ; index = 169 ; length = 1 line = 12 ; column = 10 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 171 ; length = 3 line = 12 ; column = 12 ; value ='foo'; } +{kind = TOKEN_LEFTPAREN; ; index = 174 ; length = 1 line = 12 ; column = 15 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 175 ; length = 1 line = 12 ; column = 16 ; value ='f'; } +{kind = TOKEN_RIGHTPAREN; ; index = 176 ; length = 1 line = 12 ; column = 17 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 177 ; length = 1 line = 12 ; column = 18 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 180 ; length = 1 line = 13 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 183 ; length = 0 line = 14 ; column = 0 ; value =''; } diff --git a/test/lex/passthrough.golden b/test/lex/passthrough.golden new file mode 100644 index 0000000..9807eba --- /dev/null +++ b/test/lex/passthrough.golden @@ -0,0 +1,43 @@ +{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 ='float3'; } +{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_RETURN; ; index = 64 ; length = 6 line = 2 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 71 ; length = 3 line = 2 ; column = 7 ; value ='pos'; } +{kind = TOKEN_SEMICOLON; ; index = 74 ; length = 1 line = 2 ; column = 10 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 77 ; length = 1 line = 3 ; column = 0 ; value ='}'; } +{kind = TOKEN_PIXEL; ; index = 82 ; length = 5 line = 5 ; column = 0 ; value ='pixel'; } +{kind = TOKEN_IDENTIFIER; ; index = 88 ; length = 4 line = 5 ; column = 6 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 93 ; length = 2 line = 5 ; column = 11 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 96 ; length = 1 line = 5 ; column = 14 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 97 ; length = 1 line = 5 ; column = 15 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 99 ; length = 2 line = 5 ; column = 17 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 102 ; length = 6 line = 5 ; column = 20 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 109 ; length = 1 line = 5 ; column = 27 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 110 ; length = 7 line = 5 ; column = 28 ; value ='target0'; } +{kind = TOKEN_LEFTBRACE; ; index = 118 ; length = 1 line = 5 ; column = 36 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 122 ; length = 6 line = 6 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 129 ; length = 6 line = 6 ; column = 7 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 135 ; length = 1 line = 6 ; column = 13 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 136 ; length = 3 line = 6 ; column = 14 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 139 ; length = 1 line = 6 ; column = 17 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 141 ; length = 3 line = 6 ; column = 19 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 144 ; length = 1 line = 6 ; column = 22 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 146 ; length = 3 line = 6 ; column = 24 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 149 ; length = 1 line = 6 ; column = 27 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 151 ; length = 3 line = 6 ; column = 29 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 154 ; length = 1 line = 6 ; column = 32 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 155 ; length = 1 line = 6 ; column = 33 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 158 ; length = 1 line = 7 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 161 ; length = 0 line = 8 ; column = 0 ; value =''; } diff --git a/test/lex/precedence_test.golden b/test/lex/precedence_test.golden new file mode 100644 index 0000000..7a8a783 --- /dev/null +++ b/test/lex/precedence_test.golden @@ -0,0 +1,50 @@ +{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 ='x'; } +{kind = TOKEN_COLON; ; index = 24 ; length = 1 line = 2 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 26 ; length = 5 line = 2 ; column = 4 ; value ='float'; } +{kind = TOKEN_ASSIGN; ; index = 32 ; length = 1 line = 2 ; column = 10 ; value ='='; } +{kind = TOKEN_FLOATLITERAL; ; index = 34 ; length = 3 line = 2 ; column = 12 ; value ='2'; } +{kind = TOKEN_SEMICOLON; ; index = 37 ; length = 1 line = 2 ; column = 15 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 41 ; length = 1 line = 3 ; column = 0 ; value ='y'; } +{kind = TOKEN_COLON; ; index = 43 ; length = 1 line = 3 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 45 ; length = 5 line = 3 ; column = 4 ; value ='float'; } +{kind = TOKEN_ASSIGN; ; index = 51 ; length = 1 line = 3 ; column = 10 ; value ='='; } +{kind = TOKEN_FLOATLITERAL; ; index = 53 ; length = 3 line = 3 ; column = 12 ; value ='5'; } +{kind = TOKEN_SEMICOLON; ; index = 56 ; length = 1 line = 3 ; column = 15 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 60 ; length = 1 line = 4 ; column = 0 ; value ='z'; } +{kind = TOKEN_COLON; ; index = 62 ; length = 1 line = 4 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 64 ; length = 5 line = 4 ; column = 4 ; value ='float'; } +{kind = TOKEN_ASSIGN; ; index = 70 ; length = 1 line = 4 ; column = 10 ; value ='='; } +{kind = TOKEN_FLOATLITERAL; ; index = 72 ; length = 4 line = 4 ; column = 12 ; value ='10'; } +{kind = TOKEN_SEMICOLON; ; index = 76 ; length = 1 line = 4 ; column = 16 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 82 ; length = 1 line = 6 ; column = 0 ; value ='w'; } +{kind = TOKEN_COLON; ; index = 84 ; length = 1 line = 6 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 86 ; length = 5 line = 6 ; column = 4 ; value ='float'; } +{kind = TOKEN_ASSIGN; ; index = 92 ; length = 1 line = 6 ; column = 10 ; value ='='; } +{kind = TOKEN_LEFTPAREN; ; index = 94 ; length = 1 line = 6 ; column = 12 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 95 ; length = 1 line = 6 ; column = 13 ; value ='x'; } +{kind = TOKEN_STAR; ; index = 97 ; length = 1 line = 6 ; column = 15 ; value ='*'; } +{kind = TOKEN_IDENTIFIER; ; index = 99 ; length = 1 line = 6 ; column = 17 ; value ='y'; } +{kind = TOKEN_RIGHTPAREN; ; index = 100 ; length = 1 line = 6 ; column = 18 ; value =')'; } +{kind = TOKEN_PLUS; ; index = 102 ; length = 1 line = 6 ; column = 20 ; value ='+'; } +{kind = TOKEN_IDENTIFIER; ; index = 104 ; length = 1 line = 6 ; column = 22 ; value ='y'; } +{kind = TOKEN_STAR; ; index = 106 ; length = 1 line = 6 ; column = 24 ; value ='*'; } +{kind = TOKEN_LEFTPAREN; ; index = 108 ; length = 1 line = 6 ; column = 26 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 109 ; length = 1 line = 6 ; column = 27 ; value ='z'; } +{kind = TOKEN_MINUS; ; index = 111 ; length = 1 line = 6 ; column = 29 ; value ='-'; } +{kind = TOKEN_IDENTIFIER; ; index = 113 ; length = 1 line = 6 ; column = 31 ; value ='x'; } +{kind = TOKEN_SLASH; ; index = 115 ; length = 1 line = 6 ; column = 33 ; value ='/'; } +{kind = TOKEN_LEFTPAREN; ; index = 117 ; length = 1 line = 6 ; column = 35 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 118 ; length = 1 line = 6 ; column = 36 ; value ='y'; } +{kind = TOKEN_STAR; ; index = 120 ; length = 1 line = 6 ; column = 38 ; value ='*'; } +{kind = TOKEN_IDENTIFIER; ; index = 122 ; length = 1 line = 6 ; column = 40 ; value ='x'; } +{kind = TOKEN_RIGHTPAREN; ; index = 123 ; length = 1 line = 6 ; column = 41 ; value =')'; } +{kind = TOKEN_RIGHTPAREN; ; index = 124 ; length = 1 line = 6 ; column = 42 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 125 ; length = 1 line = 6 ; column = 43 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 128 ; length = 1 line = 7 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 131 ; length = 0 line = 8 ; column = 0 ; value =''; } diff --git a/test/lex/property_rename.golden b/test/lex/property_rename.golden new file mode 100644 index 0000000..323fe95 --- /dev/null +++ b/test/lex/property_rename.golden @@ -0,0 +1,45 @@ +{kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 5 line = 1 ; column = 0 ; value ='props'; } +{kind = TOKEN_DOUBLECOLON; ; index = 6 ; length = 2 line = 1 ; column = 6 ; value ='::'; } +{kind = TOKEN_PROPERTIES; ; index = 9 ; length = 10 line = 1 ; column = 9 ; value ='properties'; } +{kind = TOKEN_LEFTBRACE; ; index = 20 ; length = 1 line = 1 ; column = 20 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 24 ; length = 5 line = 2 ; column = 0 ; value ='color'; } +{kind = TOKEN_COLON; ; index = 30 ; length = 1 line = 2 ; column = 6 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 32 ; length = 6 line = 2 ; column = 8 ; value ='float4'; } +{kind = TOKEN_SEMICOLON; ; index = 38 ; length = 1 line = 2 ; column = 14 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 41 ; length = 1 line = 3 ; column = 0 ; value ='}'; } +{kind = TOKEN_VERTEX; ; index = 46 ; length = 6 line = 5 ; column = 0 ; value ='vertex'; } +{kind = TOKEN_IDENTIFIER; ; index = 53 ; length = 4 line = 5 ; column = 7 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 58 ; length = 2 line = 5 ; column = 12 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 61 ; length = 1 line = 5 ; column = 15 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 62 ; length = 3 line = 5 ; column = 16 ; value ='pos'; } +{kind = TOKEN_COLON; ; index = 66 ; length = 1 line = 5 ; column = 20 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 68 ; length = 6 line = 5 ; column = 22 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 75 ; length = 1 line = 5 ; column = 29 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 76 ; length = 8 line = 5 ; column = 30 ; value ='position'; } +{kind = TOKEN_RIGHTPAREN; ; index = 84 ; length = 1 line = 5 ; column = 38 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 86 ; length = 2 line = 5 ; column = 40 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 89 ; length = 6 line = 5 ; column = 43 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 96 ; length = 1 line = 5 ; column = 50 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 97 ; length = 8 line = 5 ; column = 51 ; value ='position'; } +{kind = TOKEN_LEFTBRACE; ; index = 106 ; length = 1 line = 5 ; column = 60 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 110 ; length = 6 line = 6 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 117 ; length = 3 line = 6 ; column = 7 ; value ='pos'; } +{kind = TOKEN_SEMICOLON; ; index = 120 ; length = 1 line = 6 ; column = 10 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 123 ; length = 1 line = 7 ; column = 0 ; value ='}'; } +{kind = TOKEN_PIXEL; ; index = 128 ; length = 5 line = 9 ; column = 0 ; value ='pixel'; } +{kind = TOKEN_IDENTIFIER; ; index = 134 ; length = 4 line = 9 ; column = 6 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 139 ; length = 2 line = 9 ; column = 11 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 142 ; length = 1 line = 9 ; column = 14 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 143 ; length = 1 line = 9 ; column = 15 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 145 ; length = 2 line = 9 ; column = 17 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 148 ; length = 6 line = 9 ; column = 20 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 155 ; length = 1 line = 9 ; column = 27 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 156 ; length = 7 line = 9 ; column = 28 ; value ='target0'; } +{kind = TOKEN_LEFTBRACE; ; index = 164 ; length = 1 line = 9 ; column = 36 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 170 ; length = 6 line = 10 ; column = 2 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 177 ; length = 5 line = 10 ; column = 9 ; value ='props'; } +{kind = TOKEN_DOT; ; index = 182 ; length = 1 line = 10 ; column = 14 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 183 ; length = 5 line = 10 ; column = 15 ; value ='color'; } +{kind = TOKEN_SEMICOLON; ; index = 188 ; length = 1 line = 10 ; column = 20 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 191 ; length = 1 line = 11 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 194 ; length = 0 line = 12 ; column = 0 ; value =''; } diff --git a/test/lex/redeclared_variable.golden b/test/lex/redeclared_variable.golden new file mode 100644 index 0000000..aa67b1c --- /dev/null +++ b/test/lex/redeclared_variable.golden @@ -0,0 +1,20 @@ +{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 ='x'; } +{kind = TOKEN_COLON; ; index = 24 ; length = 1 line = 2 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 26 ; length = 5 line = 2 ; column = 4 ; value ='float'; } +{kind = TOKEN_ASSIGN; ; index = 32 ; length = 1 line = 2 ; column = 10 ; value ='='; } +{kind = TOKEN_FLOATLITERAL; ; index = 34 ; length = 3 line = 2 ; column = 12 ; value ='1'; } +{kind = TOKEN_SEMICOLON; ; index = 37 ; length = 1 line = 2 ; column = 15 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 41 ; length = 1 line = 3 ; column = 0 ; value ='x'; } +{kind = TOKEN_COLON; ; index = 43 ; length = 1 line = 3 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 45 ; length = 5 line = 3 ; column = 4 ; value ='float'; } +{kind = TOKEN_ASSIGN; ; index = 51 ; length = 1 line = 3 ; column = 10 ; value ='='; } +{kind = TOKEN_FLOATLITERAL; ; index = 53 ; length = 3 line = 3 ; column = 12 ; value ='5'; } +{kind = TOKEN_SEMICOLON; ; index = 56 ; length = 1 line = 3 ; column = 15 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 59 ; length = 1 line = 4 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 62 ; length = 0 line = 5 ; column = 0 ; value =''; } diff --git a/test/lex/rvalue_binary.golden b/test/lex/rvalue_binary.golden new file mode 100644 index 0000000..bd6d0eb --- /dev/null +++ b/test/lex/rvalue_binary.golden @@ -0,0 +1,27 @@ +{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 ='a'; } +{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 ='b'; } +{kind = TOKEN_COLON; ; index = 38 ; length = 1 line = 3 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 40 ; length = 6 line = 3 ; column = 4 ; value ='float2'; } +{kind = TOKEN_SEMICOLON; ; index = 46 ; length = 1 line = 3 ; column = 10 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 52 ; length = 1 line = 5 ; column = 0 ; value ='x'; } +{kind = TOKEN_COLON; ; index = 54 ; length = 1 line = 5 ; column = 2 ; value =':'; } +{kind = TOKEN_ASSIGN; ; index = 55 ; length = 1 line = 5 ; column = 3 ; value ='='; } +{kind = TOKEN_LEFTPAREN; ; index = 57 ; length = 1 line = 5 ; column = 5 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 58 ; length = 1 line = 5 ; column = 6 ; value ='a'; } +{kind = TOKEN_PLUS; ; index = 60 ; length = 1 line = 5 ; column = 8 ; value ='+'; } +{kind = TOKEN_IDENTIFIER; ; index = 62 ; length = 1 line = 5 ; column = 10 ; value ='b'; } +{kind = TOKEN_RIGHTPAREN; ; index = 63 ; length = 1 line = 5 ; column = 11 ; value =')'; } +{kind = TOKEN_DOT; ; index = 64 ; length = 1 line = 5 ; column = 12 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 65 ; length = 1 line = 5 ; column = 13 ; value ='x'; } +{kind = TOKEN_SEMICOLON; ; index = 66 ; length = 1 line = 5 ; column = 14 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 69 ; length = 1 line = 6 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 72 ; length = 0 line = 7 ; column = 0 ; value =''; } diff --git a/test/lex/simple_else_if.golden b/test/lex/simple_else_if.golden new file mode 100644 index 0000000..111002d --- /dev/null +++ b/test/lex/simple_else_if.golden @@ -0,0 +1,65 @@ +{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_IDENTIFIER; ; index = 67 ; length = 3 line = 2 ; column = 3 ; value ='pos'; } +{kind = TOKEN_DOT; ; index = 70 ; length = 1 line = 2 ; column = 6 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 71 ; length = 1 line = 2 ; column = 7 ; value ='x'; } +{kind = TOKEN_GREATER; ; index = 73 ; length = 1 line = 2 ; column = 9 ; value ='>'; } +{kind = TOKEN_INTLITERAL; ; index = 75 ; length = 3 line = 2 ; column = 11 ; value ='100'; } +{kind = TOKEN_LEFTBRACE; ; index = 79 ; length = 1 line = 2 ; column = 15 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 84 ; length = 6 line = 3 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 91 ; length = 6 line = 3 ; column = 7 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 97 ; length = 1 line = 3 ; column = 13 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 98 ; length = 3 line = 3 ; column = 14 ; value ='pos'; } +{kind = TOKEN_COMMA; ; index = 101 ; length = 1 line = 3 ; column = 17 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 103 ; length = 3 line = 3 ; column = 19 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 106 ; length = 1 line = 3 ; column = 22 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 107 ; length = 1 line = 3 ; column = 23 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 111 ; length = 1 line = 4 ; column = 0 ; value ='}'; } +{kind = TOKEN_ELSE; ; index = 113 ; length = 4 line = 4 ; column = 2 ; value ='else'; } +{kind = TOKEN_IF; ; index = 118 ; length = 2 line = 4 ; column = 7 ; value ='if'; } +{kind = TOKEN_IDENTIFIER; ; index = 121 ; length = 3 line = 4 ; column = 10 ; value ='pos'; } +{kind = TOKEN_DOT; ; index = 124 ; length = 1 line = 4 ; column = 13 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 125 ; length = 1 line = 4 ; column = 14 ; value ='x'; } +{kind = TOKEN_GREATER; ; index = 127 ; length = 1 line = 4 ; column = 16 ; value ='>'; } +{kind = TOKEN_INTLITERAL; ; index = 129 ; length = 2 line = 4 ; column = 18 ; value ='50'; } +{kind = TOKEN_LEFTBRACE; ; index = 132 ; length = 1 line = 4 ; column = 21 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 137 ; length = 6 line = 5 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 144 ; length = 6 line = 5 ; column = 7 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 150 ; length = 1 line = 5 ; column = 13 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 151 ; length = 3 line = 5 ; column = 14 ; value ='pos'; } +{kind = TOKEN_COMMA; ; index = 154 ; length = 1 line = 5 ; column = 17 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 156 ; length = 3 line = 5 ; column = 19 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 159 ; length = 1 line = 5 ; column = 22 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 160 ; length = 1 line = 5 ; column = 23 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 164 ; length = 1 line = 6 ; column = 0 ; value ='}'; } +{kind = TOKEN_ELSE; ; index = 166 ; length = 4 line = 6 ; column = 2 ; value ='else'; } +{kind = TOKEN_LEFTBRACE; ; index = 171 ; length = 1 line = 6 ; column = 7 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 176 ; length = 6 line = 7 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 183 ; length = 6 line = 7 ; column = 7 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 189 ; length = 1 line = 7 ; column = 13 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 190 ; length = 3 line = 7 ; column = 14 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 193 ; length = 1 line = 7 ; column = 17 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 194 ; length = 1 line = 7 ; column = 18 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 198 ; length = 1 line = 8 ; column = 0 ; value ='}'; } +{kind = TOKEN_RETURN; ; index = 202 ; length = 6 line = 9 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 209 ; length = 6 line = 9 ; column = 7 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 215 ; length = 1 line = 9 ; column = 13 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 216 ; length = 3 line = 9 ; column = 14 ; value ='0'; } +{kind = TOKEN_RIGHTPAREN; ; index = 219 ; length = 1 line = 9 ; column = 17 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 220 ; length = 1 line = 9 ; column = 18 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 223 ; length = 1 line = 10 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 228 ; length = 0 line = 12 ; column = 0 ; value =''; } diff --git a/test/lex/simple_if.golden b/test/lex/simple_if.golden new file mode 100644 index 0000000..9808533 --- /dev/null +++ b/test/lex/simple_if.golden @@ -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 =''; } diff --git a/test/lex/simple_if_else.golden b/test/lex/simple_if_else.golden new file mode 100644 index 0000000..2b0cc59 --- /dev/null +++ b/test/lex/simple_if_else.golden @@ -0,0 +1,46 @@ +{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_ELSE; ; index = 109 ; length = 4 line = 4 ; column = 2 ; value ='else'; } +{kind = TOKEN_LEFTBRACE; ; index = 114 ; length = 1 line = 4 ; column = 7 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 119 ; length = 6 line = 5 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 126 ; length = 6 line = 5 ; column = 7 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 132 ; length = 1 line = 5 ; column = 13 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 133 ; length = 3 line = 5 ; column = 14 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 136 ; length = 1 line = 5 ; column = 17 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 137 ; length = 1 line = 5 ; column = 18 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 141 ; length = 1 line = 6 ; column = 0 ; value ='}'; } +{kind = TOKEN_RETURN; ; index = 145 ; length = 6 line = 7 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 152 ; length = 6 line = 7 ; column = 7 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 158 ; length = 1 line = 7 ; column = 13 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 159 ; length = 3 line = 7 ; column = 14 ; value ='0'; } +{kind = TOKEN_RIGHTPAREN; ; index = 162 ; length = 1 line = 7 ; column = 17 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 163 ; length = 1 line = 7 ; column = 18 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 166 ; length = 1 line = 8 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 169 ; length = 0 line = 9 ; column = 0 ; value =''; } diff --git a/test/lex/simple_struct_access.golden b/test/lex/simple_struct_access.golden new file mode 100644 index 0000000..d9abb8b --- /dev/null +++ b/test/lex/simple_struct_access.golden @@ -0,0 +1,29 @@ +{kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 4 line = 1 ; column = 0 ; value ='Data'; } +{kind = TOKEN_DOUBLECOLON; ; index = 5 ; length = 2 line = 1 ; column = 5 ; value ='::'; } +{kind = TOKEN_STRUCT; ; index = 8 ; length = 6 line = 1 ; column = 8 ; value ='struct'; } +{kind = TOKEN_LEFTBRACE; ; index = 15 ; length = 1 line = 1 ; column = 15 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 19 ; length = 5 line = 2 ; column = 0 ; value ='color'; } +{kind = TOKEN_COLON; ; index = 25 ; length = 1 line = 2 ; column = 6 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 27 ; length = 6 line = 2 ; column = 8 ; value ='float4'; } +{kind = TOKEN_SEMICOLON; ; index = 33 ; length = 1 line = 2 ; column = 14 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 36 ; length = 1 line = 3 ; column = 0 ; value ='}'; } +{kind = TOKEN_VERTEX; ; index = 41 ; length = 6 line = 5 ; column = 0 ; value ='vertex'; } +{kind = TOKEN_IDENTIFIER; ; index = 48 ; length = 4 line = 5 ; column = 7 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 53 ; length = 2 line = 5 ; column = 12 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 56 ; length = 1 line = 5 ; column = 15 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 57 ; length = 1 line = 5 ; column = 16 ; value =')'; } +{kind = TOKEN_LEFTBRACE; ; index = 59 ; length = 1 line = 5 ; column = 18 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 63 ; length = 1 line = 6 ; column = 0 ; value ='d'; } +{kind = TOKEN_COLON; ; index = 65 ; length = 1 line = 6 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 67 ; length = 4 line = 6 ; column = 4 ; value ='Data'; } +{kind = TOKEN_SEMICOLON; ; index = 71 ; length = 1 line = 6 ; column = 8 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 75 ; length = 1 line = 7 ; column = 0 ; value ='x'; } +{kind = TOKEN_COLON; ; index = 77 ; length = 1 line = 7 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 79 ; length = 6 line = 7 ; column = 4 ; value ='float4'; } +{kind = TOKEN_ASSIGN; ; index = 86 ; length = 1 line = 7 ; column = 11 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 88 ; length = 1 line = 7 ; column = 13 ; value ='d'; } +{kind = TOKEN_DOT; ; index = 89 ; length = 1 line = 7 ; column = 14 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 90 ; length = 5 line = 7 ; column = 15 ; value ='color'; } +{kind = TOKEN_SEMICOLON; ; index = 95 ; length = 1 line = 7 ; column = 20 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 98 ; length = 1 line = 8 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 101 ; length = 0 line = 9 ; column = 0 ; value =''; } diff --git a/test/lex/struct_access_primitive_type.golden b/test/lex/struct_access_primitive_type.golden new file mode 100644 index 0000000..9064b7b --- /dev/null +++ b/test/lex/struct_access_primitive_type.golden @@ -0,0 +1,20 @@ +{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 ='x'; } +{kind = TOKEN_COLON; ; index = 24 ; length = 1 line = 2 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 26 ; length = 3 line = 2 ; column = 4 ; value ='int'; } +{kind = TOKEN_ASSIGN; ; index = 30 ; length = 1 line = 2 ; column = 8 ; value ='='; } +{kind = TOKEN_INTLITERAL; ; index = 32 ; length = 1 line = 2 ; column = 10 ; value ='5'; } +{kind = TOKEN_SEMICOLON; ; index = 33 ; length = 1 line = 2 ; column = 11 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 37 ; length = 1 line = 3 ; column = 0 ; value ='x'; } +{kind = TOKEN_DOT; ; index = 38 ; length = 1 line = 3 ; column = 1 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 39 ; length = 1 line = 3 ; column = 2 ; value ='d'; } +{kind = TOKEN_ASSIGN; ; index = 41 ; length = 1 line = 3 ; column = 4 ; value ='='; } +{kind = TOKEN_INTLITERAL; ; index = 43 ; length = 1 line = 3 ; column = 6 ; value ='4'; } +{kind = TOKEN_SEMICOLON; ; index = 44 ; length = 1 line = 3 ; column = 7 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 47 ; length = 1 line = 4 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 50 ; length = 0 line = 5 ; column = 0 ; value =''; } diff --git a/test/lex/struct_field_access_test.golden b/test/lex/struct_field_access_test.golden new file mode 100644 index 0000000..245f788 --- /dev/null +++ b/test/lex/struct_field_access_test.golden @@ -0,0 +1,167 @@ +{kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 10 line = 1 ; column = 0 ; value ='Vertex_Out'; } +{kind = TOKEN_DOUBLECOLON; ; index = 11 ; length = 2 line = 1 ; column = 11 ; value ='::'; } +{kind = TOKEN_STRUCT; ; index = 14 ; length = 6 line = 1 ; column = 14 ; value ='struct'; } +{kind = TOKEN_LEFTBRACE; ; index = 21 ; length = 1 line = 1 ; column = 21 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 25 ; length = 8 line = 2 ; column = 0 ; value ='position'; } +{kind = TOKEN_COLON; ; index = 34 ; length = 1 line = 2 ; column = 9 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 36 ; length = 6 line = 2 ; column = 11 ; value ='float3'; } +{kind = TOKEN_AT; ; index = 43 ; length = 1 line = 2 ; column = 18 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 44 ; length = 8 line = 2 ; column = 19 ; value ='position'; } +{kind = TOKEN_SEMICOLON; ; index = 52 ; length = 1 line = 2 ; column = 27 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 56 ; length = 6 line = 3 ; column = 0 ; value ='normal'; } +{kind = TOKEN_COLON; ; index = 65 ; length = 1 line = 3 ; column = 9 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 67 ; length = 6 line = 3 ; column = 11 ; value ='float3'; } +{kind = TOKEN_AT; ; index = 74 ; length = 1 line = 3 ; column = 18 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 75 ; length = 6 line = 3 ; column = 19 ; value ='normal'; } +{kind = TOKEN_SEMICOLON; ; index = 81 ; length = 1 line = 3 ; column = 25 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 85 ; length = 2 line = 4 ; column = 0 ; value ='uv'; } +{kind = TOKEN_COLON; ; index = 94 ; length = 1 line = 4 ; column = 9 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 96 ; length = 6 line = 4 ; column = 11 ; value ='float3'; } +{kind = TOKEN_AT; ; index = 103 ; length = 1 line = 4 ; column = 18 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 104 ; length = 2 line = 4 ; column = 19 ; value ='uv'; } +{kind = TOKEN_SEMICOLON; ; index = 106 ; length = 1 line = 4 ; column = 21 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 110 ; length = 8 line = 5 ; column = 0 ; value ='frag_pos'; } +{kind = TOKEN_COLON; ; index = 119 ; length = 1 line = 5 ; column = 9 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 121 ; length = 6 line = 5 ; column = 11 ; value ='float3'; } +{kind = TOKEN_AT; ; index = 128 ; length = 1 line = 5 ; column = 18 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 129 ; length = 6 line = 5 ; column = 19 ; value ='interp'; } +{kind = TOKEN_SEMICOLON; ; index = 135 ; length = 1 line = 5 ; column = 25 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 138 ; length = 1 line = 6 ; column = 0 ; value ='}'; } +{kind = TOKEN_INSTANCE; ; index = 143 ; length = 8 line = 8 ; column = 0 ; value ='instance'; } +{kind = TOKEN_LEFTBRACE; ; index = 152 ; length = 1 line = 8 ; column = 9 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 156 ; length = 5 line = 9 ; column = 0 ; value ='model'; } +{kind = TOKEN_COLON; ; index = 162 ; length = 1 line = 9 ; column = 6 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 164 ; length = 8 line = 9 ; column = 8 ; value ='float4x4'; } +{kind = TOKEN_AT; ; index = 173 ; length = 1 line = 9 ; column = 17 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 174 ; length = 5 line = 9 ; column = 18 ; value ='model'; } +{kind = TOKEN_SEMICOLON; ; index = 179 ; length = 1 line = 9 ; column = 23 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 182 ; length = 1 line = 10 ; column = 0 ; value ='}'; } +{kind = TOKEN_VERTEX; ; index = 187 ; length = 6 line = 12 ; column = 0 ; value ='vertex'; } +{kind = TOKEN_IDENTIFIER; ; index = 194 ; length = 4 line = 12 ; column = 7 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 199 ; length = 2 line = 12 ; column = 12 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 202 ; length = 1 line = 12 ; column = 15 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 203 ; length = 8 line = 12 ; column = 16 ; value ='position'; } +{kind = TOKEN_COLON; ; index = 212 ; length = 1 line = 12 ; column = 25 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 214 ; length = 6 line = 12 ; column = 27 ; value ='float3'; } +{kind = TOKEN_AT; ; index = 221 ; length = 1 line = 12 ; column = 34 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 222 ; length = 8 line = 12 ; column = 35 ; value ='position'; } +{kind = TOKEN_COMMA; ; index = 230 ; length = 1 line = 12 ; column = 43 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 232 ; length = 2 line = 12 ; column = 45 ; value ='uv'; } +{kind = TOKEN_COLON; ; index = 235 ; length = 1 line = 12 ; column = 48 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 237 ; length = 6 line = 12 ; column = 50 ; value ='float2'; } +{kind = TOKEN_AT; ; index = 244 ; length = 1 line = 12 ; column = 57 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 245 ; length = 2 line = 12 ; column = 58 ; value ='uv'; } +{kind = TOKEN_COMMA; ; index = 247 ; length = 1 line = 12 ; column = 60 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 249 ; length = 6 line = 12 ; column = 62 ; value ='normal'; } +{kind = TOKEN_COLON; ; index = 256 ; length = 1 line = 12 ; column = 69 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 258 ; length = 6 line = 12 ; column = 71 ; value ='float3'; } +{kind = TOKEN_AT; ; index = 265 ; length = 1 line = 12 ; column = 78 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 266 ; length = 6 line = 12 ; column = 79 ; value ='normal'; } +{kind = TOKEN_RIGHTPAREN; ; index = 272 ; length = 1 line = 12 ; column = 85 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 274 ; length = 2 line = 12 ; column = 87 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 277 ; length = 10 line = 12 ; column = 90 ; value ='Vertex_Out'; } +{kind = TOKEN_LEFTBRACE; ; index = 288 ; length = 1 line = 12 ; column = 101 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 292 ; length = 5 line = 13 ; column = 0 ; value ='v_out'; } +{kind = TOKEN_COLON; ; index = 298 ; length = 1 line = 13 ; column = 6 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 300 ; length = 10 line = 13 ; column = 8 ; value ='Vertex_Out'; } +{kind = TOKEN_SEMICOLON; ; index = 310 ; length = 1 line = 13 ; column = 18 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 316 ; length = 5 line = 15 ; column = 0 ; value ='v_out'; } +{kind = TOKEN_DOT; ; index = 321 ; length = 1 line = 15 ; column = 5 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 322 ; length = 8 line = 15 ; column = 6 ; value ='position'; } +{kind = TOKEN_ASSIGN; ; index = 331 ; length = 1 line = 15 ; column = 15 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 333 ; length = 3 line = 15 ; column = 17 ; value ='mul'; } +{kind = TOKEN_LEFTPAREN; ; index = 336 ; length = 1 line = 15 ; column = 20 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 337 ; length = 8 line = 15 ; column = 21 ; value ='position'; } +{kind = TOKEN_COMMA; ; index = 345 ; length = 1 line = 15 ; column = 29 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 347 ; length = 5 line = 15 ; column = 31 ; value ='model'; } +{kind = TOKEN_RIGHTPAREN; ; index = 352 ; length = 1 line = 15 ; column = 36 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 353 ; length = 1 line = 15 ; column = 37 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 357 ; length = 5 line = 16 ; column = 0 ; value ='v_out'; } +{kind = TOKEN_DOT; ; index = 362 ; length = 1 line = 16 ; column = 5 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 363 ; length = 6 line = 16 ; column = 6 ; value ='normal'; } +{kind = TOKEN_ASSIGN; ; index = 372 ; length = 1 line = 16 ; column = 15 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 374 ; length = 6 line = 16 ; column = 17 ; value ='normal'; } +{kind = TOKEN_SEMICOLON; ; index = 380 ; length = 1 line = 16 ; column = 23 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 384 ; length = 5 line = 17 ; column = 0 ; value ='v_out'; } +{kind = TOKEN_DOT; ; index = 389 ; length = 1 line = 17 ; column = 5 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 390 ; length = 2 line = 17 ; column = 6 ; value ='uv'; } +{kind = TOKEN_ASSIGN; ; index = 399 ; length = 1 line = 17 ; column = 15 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 401 ; length = 2 line = 17 ; column = 17 ; value ='uv'; } +{kind = TOKEN_SEMICOLON; ; index = 403 ; length = 1 line = 17 ; column = 19 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 407 ; length = 5 line = 18 ; column = 0 ; value ='v_out'; } +{kind = TOKEN_DOT; ; index = 412 ; length = 1 line = 18 ; column = 5 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 413 ; length = 8 line = 18 ; column = 6 ; value ='frag_pos'; } +{kind = TOKEN_ASSIGN; ; index = 422 ; length = 1 line = 18 ; column = 15 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 424 ; length = 8 line = 18 ; column = 17 ; value ='position'; } +{kind = TOKEN_SEMICOLON; ; index = 432 ; length = 1 line = 18 ; column = 25 ; value =';'; } +{kind = TOKEN_RETURN; ; index = 438 ; length = 6 line = 20 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 445 ; length = 5 line = 20 ; column = 7 ; value ='v_out'; } +{kind = TOKEN_SEMICOLON; ; index = 450 ; length = 1 line = 20 ; column = 12 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 453 ; length = 1 line = 21 ; column = 0 ; value ='}'; } +{kind = TOKEN_IDENTIFIER; ; index = 458 ; length = 9 line = 23 ; column = 0 ; value ='Pixel_Out'; } +{kind = TOKEN_DOUBLECOLON; ; index = 468 ; length = 2 line = 23 ; column = 10 ; value ='::'; } +{kind = TOKEN_STRUCT; ; index = 471 ; length = 6 line = 23 ; column = 13 ; value ='struct'; } +{kind = TOKEN_LEFTBRACE; ; index = 478 ; length = 1 line = 23 ; column = 20 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 482 ; length = 5 line = 24 ; column = 0 ; value ='color'; } +{kind = TOKEN_COLON; ; index = 491 ; length = 1 line = 24 ; column = 9 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 493 ; length = 6 line = 24 ; column = 11 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 500 ; length = 1 line = 24 ; column = 18 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 501 ; length = 7 line = 24 ; column = 19 ; value ='target0'; } +{kind = TOKEN_SEMICOLON; ; index = 508 ; length = 1 line = 24 ; column = 26 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 512 ; length = 8 line = 25 ; column = 0 ; value ='emission'; } +{kind = TOKEN_COLON; ; index = 521 ; length = 1 line = 25 ; column = 9 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 523 ; length = 6 line = 25 ; column = 11 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 530 ; length = 1 line = 25 ; column = 18 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 531 ; length = 7 line = 25 ; column = 19 ; value ='target1'; } +{kind = TOKEN_SEMICOLON; ; index = 538 ; length = 1 line = 25 ; column = 26 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 541 ; length = 1 line = 26 ; column = 0 ; value ='}'; } +{kind = TOKEN_PIXEL; ; index = 546 ; length = 5 line = 28 ; column = 0 ; value ='pixel'; } +{kind = TOKEN_IDENTIFIER; ; index = 552 ; length = 4 line = 28 ; column = 6 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 557 ; length = 2 line = 28 ; column = 11 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 560 ; length = 1 line = 28 ; column = 14 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 561 ; length = 4 line = 28 ; column = 15 ; value ='v_in'; } +{kind = TOKEN_COLON; ; index = 566 ; length = 1 line = 28 ; column = 20 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 568 ; length = 10 line = 28 ; column = 22 ; value ='Vertex_Out'; } +{kind = TOKEN_RIGHTPAREN; ; index = 578 ; length = 1 line = 28 ; column = 32 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 580 ; length = 2 line = 28 ; column = 34 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 583 ; length = 9 line = 28 ; column = 37 ; value ='Pixel_Out'; } +{kind = TOKEN_LEFTBRACE; ; index = 593 ; length = 1 line = 28 ; column = 47 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 597 ; length = 5 line = 29 ; column = 0 ; value ='p_out'; } +{kind = TOKEN_COLON; ; index = 603 ; length = 1 line = 29 ; column = 6 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 605 ; length = 9 line = 29 ; column = 8 ; value ='Pixel_Out'; } +{kind = TOKEN_SEMICOLON; ; index = 614 ; length = 1 line = 29 ; column = 17 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 620 ; length = 5 line = 31 ; column = 0 ; value ='p_out'; } +{kind = TOKEN_DOT; ; index = 625 ; length = 1 line = 31 ; column = 5 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 626 ; length = 5 line = 31 ; column = 6 ; value ='color'; } +{kind = TOKEN_ASSIGN; ; index = 635 ; length = 1 line = 31 ; column = 15 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 637 ; length = 6 line = 31 ; column = 17 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 643 ; length = 1 line = 31 ; column = 23 ; value ='('; } +{kind = TOKEN_INTLITERAL; ; index = 644 ; length = 1 line = 31 ; column = 24 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 645 ; length = 1 line = 31 ; column = 25 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 647 ; length = 3 line = 31 ; column = 27 ; value ='0.5'; } +{kind = TOKEN_COMMA; ; index = 650 ; length = 1 line = 31 ; column = 30 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 652 ; length = 1 line = 31 ; column = 32 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 653 ; length = 1 line = 31 ; column = 33 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 655 ; length = 1 line = 31 ; column = 35 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 656 ; length = 1 line = 31 ; column = 36 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 657 ; length = 1 line = 31 ; column = 37 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 661 ; length = 5 line = 32 ; column = 0 ; value ='p_out'; } +{kind = TOKEN_DOT; ; index = 666 ; length = 1 line = 32 ; column = 5 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 667 ; length = 8 line = 32 ; column = 6 ; value ='emission'; } +{kind = TOKEN_ASSIGN; ; index = 676 ; length = 1 line = 32 ; column = 15 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 678 ; length = 6 line = 32 ; column = 17 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 684 ; length = 1 line = 32 ; column = 23 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 685 ; length = 3 line = 32 ; column = 24 ; value ='2'; } +{kind = TOKEN_COMMA; ; index = 688 ; length = 1 line = 32 ; column = 27 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 690 ; length = 3 line = 32 ; column = 29 ; value ='2'; } +{kind = TOKEN_COMMA; ; index = 693 ; length = 1 line = 32 ; column = 32 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 695 ; length = 3 line = 32 ; column = 34 ; value ='2'; } +{kind = TOKEN_COMMA; ; index = 698 ; length = 1 line = 32 ; column = 37 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 700 ; length = 3 line = 32 ; column = 39 ; value ='2'; } +{kind = TOKEN_RIGHTPAREN; ; index = 703 ; length = 1 line = 32 ; column = 42 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 704 ; length = 1 line = 32 ; column = 43 ; value =';'; } +{kind = TOKEN_RETURN; ; index = 710 ; length = 6 line = 34 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 717 ; length = 5 line = 34 ; column = 7 ; value ='p_out'; } +{kind = TOKEN_SEMICOLON; ; index = 722 ; length = 1 line = 34 ; column = 12 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 725 ; length = 1 line = 35 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 728 ; length = 0 line = 36 ; column = 0 ; value =''; } diff --git a/test/lex/struct_within_struct.golden b/test/lex/struct_within_struct.golden new file mode 100644 index 0000000..dc4648c --- /dev/null +++ b/test/lex/struct_within_struct.golden @@ -0,0 +1,40 @@ +{kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 3 line = 1 ; column = 0 ; value ='Foo'; } +{kind = TOKEN_DOUBLECOLON; ; index = 4 ; length = 2 line = 1 ; column = 4 ; value ='::'; } +{kind = TOKEN_STRUCT; ; index = 7 ; length = 6 line = 1 ; column = 7 ; value ='struct'; } +{kind = TOKEN_LEFTBRACE; ; index = 14 ; length = 1 line = 1 ; column = 14 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 18 ; length = 5 line = 2 ; column = 0 ; value ='color'; } +{kind = TOKEN_COLON; ; index = 24 ; length = 1 line = 2 ; column = 6 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 26 ; length = 6 line = 2 ; column = 8 ; value ='float4'; } +{kind = TOKEN_SEMICOLON; ; index = 32 ; length = 1 line = 2 ; column = 14 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 35 ; length = 1 line = 3 ; column = 0 ; value ='}'; } +{kind = TOKEN_IDENTIFIER; ; index = 40 ; length = 3 line = 5 ; column = 0 ; value ='Bar'; } +{kind = TOKEN_DOUBLECOLON; ; index = 44 ; length = 2 line = 5 ; column = 4 ; value ='::'; } +{kind = TOKEN_STRUCT; ; index = 47 ; length = 6 line = 5 ; column = 7 ; value ='struct'; } +{kind = TOKEN_LEFTBRACE; ; index = 54 ; length = 1 line = 5 ; column = 14 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 61 ; length = 1 line = 6 ; column = 4 ; value ='t'; } +{kind = TOKEN_COLON; ; index = 63 ; length = 1 line = 6 ; column = 6 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 65 ; length = 3 line = 6 ; column = 8 ; value ='Foo'; } +{kind = TOKEN_SEMICOLON; ; index = 68 ; length = 1 line = 6 ; column = 11 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 71 ; length = 1 line = 7 ; column = 0 ; value ='}'; } +{kind = TOKEN_VERTEX; ; index = 76 ; length = 6 line = 9 ; column = 0 ; value ='vertex'; } +{kind = TOKEN_IDENTIFIER; ; index = 83 ; length = 4 line = 9 ; column = 7 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 88 ; length = 2 line = 9 ; column = 12 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 91 ; length = 1 line = 9 ; column = 15 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 92 ; length = 1 line = 9 ; column = 16 ; value =')'; } +{kind = TOKEN_LEFTBRACE; ; index = 94 ; length = 1 line = 9 ; column = 18 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 98 ; length = 1 line = 10 ; column = 0 ; value ='f'; } +{kind = TOKEN_COLON; ; index = 100 ; length = 1 line = 10 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 102 ; length = 3 line = 10 ; column = 4 ; value ='Foo'; } +{kind = TOKEN_SEMICOLON; ; index = 105 ; length = 1 line = 10 ; column = 7 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 109 ; length = 1 line = 11 ; column = 0 ; value ='b'; } +{kind = TOKEN_COLON; ; index = 111 ; length = 1 line = 11 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 113 ; length = 3 line = 11 ; column = 4 ; value ='Bar'; } +{kind = TOKEN_SEMICOLON; ; index = 116 ; length = 1 line = 11 ; column = 7 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 120 ; length = 1 line = 12 ; column = 0 ; value ='b'; } +{kind = TOKEN_DOT; ; index = 121 ; length = 1 line = 12 ; column = 1 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 122 ; length = 1 line = 12 ; column = 2 ; value ='t'; } +{kind = TOKEN_ASSIGN; ; index = 124 ; length = 1 line = 12 ; column = 4 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 126 ; length = 1 line = 12 ; column = 6 ; value ='f'; } +{kind = TOKEN_SEMICOLON; ; index = 127 ; length = 1 line = 12 ; column = 7 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 130 ; length = 1 line = 13 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 133 ; length = 0 line = 14 ; column = 0 ; value =''; } diff --git a/test/lex/temp_access.golden b/test/lex/temp_access.golden new file mode 100644 index 0000000..b8722ee --- /dev/null +++ b/test/lex/temp_access.golden @@ -0,0 +1,26 @@ +{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 ='a'; } +{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 ='b'; } +{kind = TOKEN_COLON; ; index = 38 ; length = 1 line = 3 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 40 ; length = 6 line = 3 ; column = 4 ; value ='float2'; } +{kind = TOKEN_SEMICOLON; ; index = 46 ; length = 1 line = 3 ; column = 10 ; value =';'; } +{kind = TOKEN_LEFTPAREN; ; index = 52 ; length = 1 line = 5 ; column = 0 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 53 ; length = 1 line = 5 ; column = 1 ; value ='a'; } +{kind = TOKEN_PLUS; ; index = 55 ; length = 1 line = 5 ; column = 3 ; value ='+'; } +{kind = TOKEN_IDENTIFIER; ; index = 57 ; length = 1 line = 5 ; column = 5 ; value ='b'; } +{kind = TOKEN_RIGHTPAREN; ; index = 58 ; length = 1 line = 5 ; column = 6 ; value =')'; } +{kind = TOKEN_DOT; ; index = 59 ; length = 1 line = 5 ; column = 7 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 60 ; length = 1 line = 5 ; column = 8 ; value ='x'; } +{kind = TOKEN_ASSIGN; ; index = 62 ; length = 1 line = 5 ; column = 10 ; value ='='; } +{kind = TOKEN_FLOATLITERAL; ; index = 64 ; length = 3 line = 5 ; column = 12 ; value ='2'; } +{kind = TOKEN_SEMICOLON; ; index = 67 ; length = 1 line = 5 ; column = 15 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 70 ; length = 1 line = 6 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 73 ; length = 0 line = 7 ; column = 0 ; value =''; } diff --git a/test/lex/texture_sample.golden b/test/lex/texture_sample.golden new file mode 100644 index 0000000..298e305 --- /dev/null +++ b/test/lex/texture_sample.golden @@ -0,0 +1,107 @@ +{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_PROPERTIES; ; index = 5 ; length = 10 line = 1 ; column = 5 ; value ='properties'; } +{kind = TOKEN_DOUBLECOLON; ; index = 16 ; length = 2 line = 1 ; column = 16 ; value ='::'; } +{kind = TOKEN_LEFTBRACE; ; index = 19 ; length = 1 line = 1 ; column = 19 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 23 ; length = 7 line = 2 ; column = 0 ; value ='texture'; } +{kind = TOKEN_COLON; ; index = 31 ; length = 1 line = 2 ; column = 8 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 33 ; length = 9 line = 2 ; column = 10 ; value ='texture2D'; } +{kind = TOKEN_SEMICOLON; ; index = 42 ; length = 1 line = 2 ; column = 19 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 46 ; length = 7 line = 3 ; column = 0 ; value ='sampler'; } +{kind = TOKEN_COLON; ; index = 54 ; length = 1 line = 3 ; column = 8 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 56 ; length = 7 line = 3 ; column = 10 ; value ='sampler'; } +{kind = TOKEN_SEMICOLON; ; index = 63 ; length = 1 line = 3 ; column = 17 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 66 ; length = 1 line = 4 ; column = 0 ; value ='}'; } +{kind = TOKEN_IDENTIFIER; ; index = 71 ; length = 8 line = 6 ; column = 0 ; value ='PS_Input'; } +{kind = TOKEN_DOUBLECOLON; ; index = 80 ; length = 2 line = 6 ; column = 9 ; value ='::'; } +{kind = TOKEN_STRUCT; ; index = 83 ; length = 6 line = 6 ; column = 12 ; value ='struct'; } +{kind = TOKEN_LEFTBRACE; ; index = 90 ; length = 1 line = 6 ; column = 19 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 94 ; length = 2 line = 7 ; column = 0 ; value ='uv'; } +{kind = TOKEN_COLON; ; index = 98 ; length = 1 line = 7 ; column = 4 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 100 ; length = 6 line = 7 ; column = 6 ; value ='float2'; } +{kind = TOKEN_AT; ; index = 107 ; length = 1 line = 7 ; column = 13 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 108 ; length = 2 line = 7 ; column = 14 ; value ='uv'; } +{kind = TOKEN_SEMICOLON; ; index = 110 ; length = 1 line = 7 ; column = 16 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 114 ; length = 3 line = 8 ; column = 0 ; value ='pos'; } +{kind = TOKEN_COLON; ; index = 118 ; length = 1 line = 8 ; column = 4 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 120 ; length = 6 line = 8 ; column = 6 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 127 ; length = 1 line = 8 ; column = 13 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 128 ; length = 8 line = 8 ; column = 14 ; value ='position'; } +{kind = TOKEN_SEMICOLON; ; index = 136 ; length = 1 line = 8 ; column = 22 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 139 ; length = 1 line = 9 ; column = 0 ; value ='}'; } +{kind = TOKEN_VERTEX; ; index = 144 ; length = 6 line = 11 ; column = 0 ; value ='vertex'; } +{kind = TOKEN_IDENTIFIER; ; index = 151 ; length = 4 line = 11 ; column = 7 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 156 ; length = 2 line = 11 ; column = 12 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 159 ; length = 1 line = 11 ; column = 15 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 160 ; length = 3 line = 11 ; column = 16 ; value ='pos'; } +{kind = TOKEN_COLON; ; index = 164 ; length = 1 line = 11 ; column = 20 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 166 ; length = 6 line = 11 ; column = 22 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 173 ; length = 1 line = 11 ; column = 29 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 174 ; length = 8 line = 11 ; column = 30 ; value ='position'; } +{kind = TOKEN_COMMA; ; index = 182 ; length = 1 line = 11 ; column = 38 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 184 ; length = 2 line = 11 ; column = 40 ; value ='uv'; } +{kind = TOKEN_COLON; ; index = 187 ; length = 1 line = 11 ; column = 43 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 189 ; length = 6 line = 11 ; column = 45 ; value ='float2'; } +{kind = TOKEN_AT; ; index = 196 ; length = 1 line = 11 ; column = 52 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 197 ; length = 2 line = 11 ; column = 53 ; value ='uv'; } +{kind = TOKEN_RIGHTPAREN; ; index = 199 ; length = 1 line = 11 ; column = 55 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 201 ; length = 2 line = 11 ; column = 57 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 204 ; length = 8 line = 11 ; column = 60 ; value ='PS_Input'; } +{kind = TOKEN_LEFTBRACE; ; index = 213 ; length = 1 line = 11 ; column = 69 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 217 ; length = 6 line = 12 ; column = 0 ; value ='result'; } +{kind = TOKEN_COLON; ; index = 224 ; length = 1 line = 12 ; column = 7 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 226 ; length = 8 line = 12 ; column = 9 ; value ='PS_Input'; } +{kind = TOKEN_SEMICOLON; ; index = 234 ; length = 1 line = 12 ; column = 17 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 240 ; length = 6 line = 14 ; column = 0 ; value ='result'; } +{kind = TOKEN_DOT; ; index = 246 ; length = 1 line = 14 ; column = 6 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 247 ; length = 2 line = 14 ; column = 7 ; value ='uv'; } +{kind = TOKEN_ASSIGN; ; index = 250 ; length = 1 line = 14 ; column = 10 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 252 ; length = 2 line = 14 ; column = 12 ; value ='uv'; } +{kind = TOKEN_SEMICOLON; ; index = 254 ; length = 1 line = 14 ; column = 14 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 258 ; length = 6 line = 15 ; column = 0 ; value ='result'; } +{kind = TOKEN_DOT; ; index = 264 ; length = 1 line = 15 ; column = 6 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 265 ; length = 3 line = 15 ; column = 7 ; value ='pos'; } +{kind = TOKEN_ASSIGN; ; index = 269 ; length = 1 line = 15 ; column = 11 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 271 ; length = 3 line = 15 ; column = 13 ; value ='pos'; } +{kind = TOKEN_SEMICOLON; ; index = 274 ; length = 1 line = 15 ; column = 16 ; value =';'; } +{kind = TOKEN_RETURN; ; index = 280 ; length = 6 line = 17 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 287 ; length = 6 line = 17 ; column = 7 ; value ='result'; } +{kind = TOKEN_SEMICOLON; ; index = 293 ; length = 1 line = 17 ; column = 13 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 296 ; length = 1 line = 18 ; column = 0 ; value ='}'; } +{kind = TOKEN_PIXEL; ; index = 301 ; length = 5 line = 20 ; column = 0 ; value ='pixel'; } +{kind = TOKEN_IDENTIFIER; ; index = 307 ; length = 4 line = 20 ; column = 6 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 312 ; length = 2 line = 20 ; column = 11 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 315 ; length = 1 line = 20 ; column = 14 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 316 ; length = 5 line = 20 ; column = 15 ; value ='input'; } +{kind = TOKEN_COLON; ; index = 322 ; length = 1 line = 20 ; column = 21 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 324 ; length = 8 line = 20 ; column = 23 ; value ='PS_Input'; } +{kind = TOKEN_RIGHTPAREN; ; index = 332 ; length = 1 line = 20 ; column = 31 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 334 ; length = 2 line = 20 ; column = 33 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 337 ; length = 6 line = 20 ; column = 36 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 344 ; length = 1 line = 20 ; column = 43 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 345 ; length = 6 line = 20 ; column = 44 ; value ='target'; } +{kind = TOKEN_LEFTBRACE; ; index = 352 ; length = 1 line = 20 ; column = 51 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 356 ; length = 5 line = 21 ; column = 0 ; value ='color'; } +{kind = TOKEN_COLON; ; index = 362 ; length = 1 line = 21 ; column = 6 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 364 ; length = 6 line = 21 ; column = 8 ; value ='float4'; } +{kind = TOKEN_ASSIGN; ; index = 371 ; length = 1 line = 21 ; column = 15 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 373 ; length = 6 line = 21 ; column = 17 ; value ='sample'; } +{kind = TOKEN_LEFTPAREN; ; index = 379 ; length = 1 line = 21 ; column = 23 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 380 ; length = 1 line = 21 ; column = 24 ; value ='p'; } +{kind = TOKEN_DOT; ; index = 381 ; length = 1 line = 21 ; column = 25 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 382 ; length = 7 line = 21 ; column = 26 ; value ='texture'; } +{kind = TOKEN_COMMA; ; index = 389 ; length = 1 line = 21 ; column = 33 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 391 ; length = 5 line = 21 ; column = 35 ; value ='input'; } +{kind = TOKEN_DOT; ; index = 396 ; length = 1 line = 21 ; column = 40 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 397 ; length = 2 line = 21 ; column = 41 ; value ='uv'; } +{kind = TOKEN_COMMA; ; index = 399 ; length = 1 line = 21 ; column = 43 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 401 ; length = 1 line = 21 ; column = 45 ; value ='p'; } +{kind = TOKEN_DOT; ; index = 402 ; length = 1 line = 21 ; column = 46 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 403 ; length = 7 line = 21 ; column = 47 ; value ='sampler'; } +{kind = TOKEN_RIGHTPAREN; ; index = 410 ; length = 1 line = 21 ; column = 54 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 411 ; length = 1 line = 21 ; column = 55 ; value =';'; } +{kind = TOKEN_RETURN; ; index = 415 ; length = 6 line = 22 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 422 ; length = 5 line = 22 ; column = 7 ; value ='color'; } +{kind = TOKEN_SEMICOLON; ; index = 427 ; length = 1 line = 22 ; column = 12 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 430 ; length = 1 line = 23 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 433 ; length = 0 line = 24 ; column = 0 ; value =''; } diff --git a/test/lex/type_as_function_name.golden b/test/lex/type_as_function_name.golden new file mode 100644 index 0000000..eb61f48 --- /dev/null +++ b/test/lex/type_as_function_name.golden @@ -0,0 +1,7 @@ +{kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 3 line = 1 ; column = 0 ; value ='int'; } +{kind = TOKEN_DOUBLECOLON; ; index = 4 ; length = 2 line = 1 ; column = 4 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 7 ; length = 1 line = 1 ; column = 7 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 8 ; length = 1 line = 1 ; column = 8 ; value =')'; } +{kind = TOKEN_LEFTBRACE; ; index = 10 ; length = 1 line = 1 ; column = 10 ; value ='{'; } +{kind = TOKEN_RIGHTBRACE; ; index = 11 ; length = 1 line = 1 ; column = 11 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 14 ; length = 0 line = 2 ; column = 0 ; value =''; } diff --git a/test/lex/type_as_variable_name.golden b/test/lex/type_as_variable_name.golden new file mode 100644 index 0000000..9e29614 --- /dev/null +++ b/test/lex/type_as_variable_name.golden @@ -0,0 +1,14 @@ +{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 = 3 line = 2 ; column = 0 ; value ='int'; } +{kind = TOKEN_COLON; ; index = 26 ; length = 1 line = 2 ; column = 4 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 28 ; length = 5 line = 2 ; column = 6 ; value ='float'; } +{kind = TOKEN_ASSIGN; ; index = 34 ; length = 1 line = 2 ; column = 12 ; value ='='; } +{kind = TOKEN_FLOATLITERAL; ; index = 36 ; length = 3 line = 2 ; column = 14 ; value ='4'; } +{kind = TOKEN_SEMICOLON; ; index = 39 ; length = 1 line = 2 ; column = 17 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 42 ; length = 1 line = 3 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 45 ; length = 0 line = 4 ; column = 0 ; value =''; } diff --git a/test/lex/unary.golden b/test/lex/unary.golden new file mode 100644 index 0000000..51d8753 --- /dev/null +++ b/test/lex/unary.golden @@ -0,0 +1,64 @@ +{kind = TOKEN_VERTEX; ; index = 0 ; length = 6 line = 1 ; column = 0 ; value ='vertex'; } +{kind = TOKEN_IDENTIFIER; ; index = 7 ; length = 7 line = 1 ; column = 7 ; value ='vs_main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 15 ; length = 2 line = 1 ; column = 15 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 18 ; length = 1 line = 1 ; column = 18 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 19 ; length = 8 line = 1 ; column = 19 ; value ='position'; } +{kind = TOKEN_COLON; ; index = 28 ; length = 1 line = 1 ; column = 28 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 30 ; length = 6 line = 1 ; column = 30 ; value ='float3'; } +{kind = TOKEN_AT; ; index = 37 ; length = 1 line = 1 ; column = 37 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 38 ; length = 8 line = 1 ; column = 38 ; value ='position'; } +{kind = TOKEN_RIGHTPAREN; ; index = 46 ; length = 1 line = 1 ; column = 46 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 48 ; length = 2 line = 1 ; column = 48 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 51 ; length = 6 line = 1 ; column = 51 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 58 ; length = 1 line = 1 ; column = 58 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 59 ; length = 8 line = 1 ; column = 59 ; value ='position'; } +{kind = TOKEN_LEFTBRACE; ; index = 68 ; length = 1 line = 1 ; column = 68 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 75 ; length = 6 line = 2 ; column = 3 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 82 ; length = 6 line = 2 ; column = 10 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 88 ; length = 1 line = 2 ; column = 16 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 89 ; length = 8 line = 2 ; column = 17 ; value ='position'; } +{kind = TOKEN_DOT; ; index = 97 ; length = 1 line = 2 ; column = 25 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 98 ; length = 1 line = 2 ; column = 26 ; value ='x'; } +{kind = TOKEN_COMMA; ; index = 99 ; length = 1 line = 2 ; column = 27 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 101 ; length = 8 line = 2 ; column = 29 ; value ='position'; } +{kind = TOKEN_DOT; ; index = 109 ; length = 1 line = 2 ; column = 37 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 110 ; length = 1 line = 2 ; column = 38 ; value ='y'; } +{kind = TOKEN_COMMA; ; index = 111 ; length = 1 line = 2 ; column = 39 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 113 ; length = 8 line = 2 ; column = 41 ; value ='position'; } +{kind = TOKEN_DOT; ; index = 121 ; length = 1 line = 2 ; column = 49 ; value ='.'; } +{kind = TOKEN_IDENTIFIER; ; index = 122 ; length = 1 line = 2 ; column = 50 ; value ='z'; } +{kind = TOKEN_COMMA; ; index = 123 ; length = 1 line = 2 ; column = 51 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 125 ; length = 3 line = 2 ; column = 53 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 128 ; length = 1 line = 2 ; column = 56 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 129 ; length = 1 line = 2 ; column = 57 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 132 ; length = 1 line = 3 ; column = 0 ; value ='}'; } +{kind = TOKEN_PIXEL; ; index = 137 ; length = 5 line = 5 ; column = 0 ; value ='pixel'; } +{kind = TOKEN_IDENTIFIER; ; index = 143 ; length = 7 line = 5 ; column = 6 ; value ='ps_main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 151 ; length = 2 line = 5 ; column = 14 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 154 ; length = 1 line = 5 ; column = 17 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 155 ; length = 8 line = 5 ; column = 18 ; value ='position'; } +{kind = TOKEN_COLON; ; index = 164 ; length = 1 line = 5 ; column = 27 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 166 ; length = 6 line = 5 ; column = 29 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 173 ; length = 1 line = 5 ; column = 36 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 174 ; length = 11 line = 5 ; column = 37 ; value ='outposition'; } +{kind = TOKEN_RIGHTPAREN; ; index = 185 ; length = 1 line = 5 ; column = 48 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 187 ; length = 2 line = 5 ; column = 50 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 190 ; length = 6 line = 5 ; column = 53 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 197 ; length = 1 line = 5 ; column = 60 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 198 ; length = 6 line = 5 ; column = 61 ; value ='target'; } +{kind = TOKEN_LEFTBRACE; ; index = 205 ; length = 1 line = 5 ; column = 68 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 211 ; length = 6 line = 6 ; column = 2 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 218 ; length = 6 line = 6 ; column = 9 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 224 ; length = 1 line = 6 ; column = 15 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 225 ; length = 3 line = 6 ; column = 16 ; value ='0.5'; } +{kind = TOKEN_COMMA; ; index = 228 ; length = 1 line = 6 ; column = 19 ; value =','; } +{kind = TOKEN_MINUS; ; index = 230 ; length = 1 line = 6 ; column = 21 ; value ='-'; } +{kind = TOKEN_INTLITERAL; ; index = 231 ; length = 1 line = 6 ; column = 22 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 232 ; length = 1 line = 6 ; column = 23 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 234 ; length = 1 line = 6 ; column = 25 ; value ='0'; } +{kind = TOKEN_COMMA; ; index = 235 ; length = 1 line = 6 ; column = 26 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 237 ; length = 1 line = 6 ; column = 28 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 238 ; length = 1 line = 6 ; column = 29 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 239 ; length = 1 line = 6 ; column = 30 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 242 ; length = 1 line = 7 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 243 ; length = 0 line = 7 ; column = 1 ; value =''; } diff --git a/test/lex/undeclared_function.golden b/test/lex/undeclared_function.golden new file mode 100644 index 0000000..23dc414 --- /dev/null +++ b/test/lex/undeclared_function.golden @@ -0,0 +1,12 @@ +{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 = 3 line = 2 ; column = 0 ; value ='foo'; } +{kind = TOKEN_LEFTPAREN; ; index = 25 ; length = 1 line = 2 ; column = 3 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 26 ; length = 1 line = 2 ; column = 4 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 27 ; length = 1 line = 2 ; column = 5 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 30 ; length = 1 line = 3 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 33 ; length = 0 line = 4 ; column = 0 ; value =''; } diff --git a/test/lex/undeclared_symbol.golden b/test/lex/undeclared_symbol.golden new file mode 100644 index 0000000..301f881 --- /dev/null +++ b/test/lex/undeclared_symbol.golden @@ -0,0 +1,14 @@ +{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 ='b'; } +{kind = TOKEN_COLON; ; index = 24 ; length = 1 line = 2 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 26 ; length = 3 line = 2 ; column = 4 ; value ='int'; } +{kind = TOKEN_ASSIGN; ; index = 30 ; length = 1 line = 2 ; column = 8 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 32 ; length = 1 line = 2 ; column = 10 ; value ='f'; } +{kind = TOKEN_SEMICOLON; ; index = 33 ; length = 1 line = 2 ; column = 11 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 36 ; length = 1 line = 3 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 39 ; length = 0 line = 4 ; column = 0 ; value =''; } diff --git a/test/lex/unknown_overload.golden b/test/lex/unknown_overload.golden new file mode 100644 index 0000000..a6e5d85 --- /dev/null +++ b/test/lex/unknown_overload.golden @@ -0,0 +1,51 @@ +{kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 3 line = 1 ; column = 0 ; value ='foo'; } +{kind = TOKEN_DOUBLECOLON; ; index = 4 ; length = 2 line = 1 ; column = 4 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 7 ; length = 1 line = 1 ; column = 7 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 8 ; length = 2 line = 1 ; column = 8 ; value ='v1'; } +{kind = TOKEN_COLON; ; index = 11 ; length = 1 line = 1 ; column = 11 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 13 ; length = 6 line = 1 ; column = 13 ; value ='float3'; } +{kind = TOKEN_COMMA; ; index = 19 ; length = 1 line = 1 ; column = 19 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 21 ; length = 2 line = 1 ; column = 21 ; value ='v2'; } +{kind = TOKEN_COLON; ; index = 24 ; length = 1 line = 1 ; column = 24 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 26 ; length = 6 line = 1 ; column = 26 ; value ='float3'; } +{kind = TOKEN_RIGHTPAREN; ; index = 32 ; length = 1 line = 1 ; column = 32 ; value =')'; } +{kind = TOKEN_LEFTBRACE; ; index = 34 ; length = 1 line = 1 ; column = 34 ; value ='{'; } +{kind = TOKEN_RIGHTBRACE; ; index = 35 ; length = 1 line = 1 ; column = 35 ; value ='}'; } +{kind = TOKEN_IDENTIFIER; ; index = 38 ; length = 3 line = 2 ; column = 0 ; value ='foo'; } +{kind = TOKEN_DOUBLECOLON; ; index = 42 ; length = 2 line = 2 ; column = 4 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 45 ; length = 1 line = 2 ; column = 7 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 46 ; length = 2 line = 2 ; column = 8 ; value ='v1'; } +{kind = TOKEN_COLON; ; index = 49 ; length = 1 line = 2 ; column = 11 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 51 ; length = 6 line = 2 ; column = 13 ; value ='float2'; } +{kind = TOKEN_COMMA; ; index = 57 ; length = 1 line = 2 ; column = 19 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 59 ; length = 2 line = 2 ; column = 21 ; value ='v2'; } +{kind = TOKEN_COLON; ; index = 62 ; length = 1 line = 2 ; column = 24 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 64 ; length = 6 line = 2 ; column = 26 ; value ='float2'; } +{kind = TOKEN_COMMA; ; index = 70 ; length = 1 line = 2 ; column = 32 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 72 ; length = 2 line = 2 ; column = 34 ; value ='v3'; } +{kind = TOKEN_COLON; ; index = 75 ; length = 1 line = 2 ; column = 37 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 77 ; length = 6 line = 2 ; column = 39 ; value ='float2'; } +{kind = TOKEN_RIGHTPAREN; ; index = 83 ; length = 1 line = 2 ; column = 45 ; value =')'; } +{kind = TOKEN_LEFTBRACE; ; index = 85 ; length = 1 line = 2 ; column = 47 ; value ='{'; } +{kind = TOKEN_RIGHTBRACE; ; index = 86 ; length = 1 line = 2 ; column = 48 ; value ='}'; } +{kind = TOKEN_VERTEX; ; index = 91 ; length = 6 line = 4 ; column = 0 ; value ='vertex'; } +{kind = TOKEN_IDENTIFIER; ; index = 98 ; length = 4 line = 4 ; column = 7 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 103 ; length = 2 line = 4 ; column = 12 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 106 ; length = 1 line = 4 ; column = 15 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 107 ; length = 1 line = 4 ; column = 16 ; value =')'; } +{kind = TOKEN_LEFTBRACE; ; index = 109 ; length = 1 line = 4 ; column = 18 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 113 ; length = 1 line = 5 ; column = 0 ; value ='v'; } +{kind = TOKEN_COLON; ; index = 115 ; length = 1 line = 5 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 117 ; length = 5 line = 5 ; column = 4 ; value ='float'; } +{kind = TOKEN_ASSIGN; ; index = 123 ; length = 1 line = 5 ; column = 10 ; value ='='; } +{kind = TOKEN_FLOATLITERAL; ; index = 125 ; length = 3 line = 5 ; column = 12 ; value ='2'; } +{kind = TOKEN_SEMICOLON; ; index = 128 ; length = 1 line = 5 ; column = 15 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 132 ; length = 3 line = 6 ; column = 0 ; value ='foo'; } +{kind = TOKEN_LEFTPAREN; ; index = 135 ; length = 1 line = 6 ; column = 3 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 136 ; length = 1 line = 6 ; column = 4 ; value ='v'; } +{kind = TOKEN_COMMA; ; index = 137 ; length = 1 line = 6 ; column = 5 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 139 ; length = 1 line = 6 ; column = 7 ; value ='v'; } +{kind = TOKEN_RIGHTPAREN; ; index = 140 ; length = 1 line = 6 ; column = 8 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 141 ; length = 1 line = 6 ; column = 9 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 144 ; length = 1 line = 7 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 147 ; length = 0 line = 8 ; column = 0 ; value =''; } diff --git a/test/lex/use_builtin_functions.golden b/test/lex/use_builtin_functions.golden new file mode 100644 index 0000000..245b04d --- /dev/null +++ b/test/lex/use_builtin_functions.golden @@ -0,0 +1,23 @@ +{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 ='f'; } +{kind = TOKEN_COLON; ; index = 24 ; length = 1 line = 2 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 26 ; length = 6 line = 2 ; column = 4 ; value ='float4'; } +{kind = TOKEN_ASSIGN; ; index = 33 ; length = 1 line = 2 ; column = 11 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 35 ; length = 6 line = 2 ; column = 13 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 41 ; length = 1 line = 2 ; column = 19 ; value ='('; } +{kind = TOKEN_INTLITERAL; ; index = 42 ; length = 1 line = 2 ; column = 20 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 43 ; length = 1 line = 2 ; column = 21 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 45 ; length = 1 line = 2 ; column = 23 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 46 ; length = 1 line = 2 ; column = 24 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 48 ; length = 1 line = 2 ; column = 26 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 49 ; length = 1 line = 2 ; column = 27 ; value =','; } +{kind = TOKEN_INTLITERAL; ; index = 51 ; length = 1 line = 2 ; column = 29 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 52 ; length = 1 line = 2 ; column = 30 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 53 ; length = 1 line = 2 ; column = 31 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 56 ; length = 1 line = 3 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 59 ; length = 0 line = 4 ; column = 0 ; value =''; } diff --git a/test/lex/wrong_argument_count.golden b/test/lex/wrong_argument_count.golden new file mode 100644 index 0000000..b9c8830 --- /dev/null +++ b/test/lex/wrong_argument_count.golden @@ -0,0 +1,73 @@ +{kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 3 line = 1 ; column = 0 ; value ='foo'; } +{kind = TOKEN_DOUBLECOLON; ; index = 4 ; length = 2 line = 1 ; column = 4 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 7 ; length = 1 line = 1 ; column = 7 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 8 ; length = 1 line = 1 ; column = 8 ; value ='x'; } +{kind = TOKEN_COLON; ; index = 10 ; length = 1 line = 1 ; column = 10 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 12 ; length = 5 line = 1 ; column = 12 ; value ='float'; } +{kind = TOKEN_COMMA; ; index = 17 ; length = 1 line = 1 ; column = 17 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 19 ; length = 1 line = 1 ; column = 19 ; value ='y'; } +{kind = TOKEN_COLON; ; index = 21 ; length = 1 line = 1 ; column = 21 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 23 ; length = 5 line = 1 ; column = 23 ; value ='float'; } +{kind = TOKEN_COMMA; ; index = 28 ; length = 1 line = 1 ; column = 28 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 30 ; length = 1 line = 1 ; column = 30 ; value ='z'; } +{kind = TOKEN_COLON; ; index = 32 ; length = 1 line = 1 ; column = 32 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 34 ; length = 5 line = 1 ; column = 34 ; value ='float'; } +{kind = TOKEN_RIGHTPAREN; ; index = 39 ; length = 1 line = 1 ; column = 39 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 41 ; length = 2 line = 1 ; column = 41 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 44 ; length = 5 line = 1 ; column = 44 ; value ='float'; } +{kind = TOKEN_LEFTBRACE; ; index = 50 ; length = 1 line = 1 ; column = 50 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 54 ; length = 6 line = 2 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 61 ; length = 1 line = 2 ; column = 7 ; value ='x'; } +{kind = TOKEN_STAR; ; index = 63 ; length = 1 line = 2 ; column = 9 ; value ='*'; } +{kind = TOKEN_IDENTIFIER; ; index = 65 ; length = 1 line = 2 ; column = 11 ; value ='y'; } +{kind = TOKEN_STAR; ; index = 67 ; length = 1 line = 2 ; column = 13 ; value ='*'; } +{kind = TOKEN_IDENTIFIER; ; index = 69 ; length = 1 line = 2 ; column = 15 ; value ='z'; } +{kind = TOKEN_SEMICOLON; ; index = 70 ; length = 1 line = 2 ; column = 16 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 73 ; length = 1 line = 3 ; column = 0 ; value ='}'; } +{kind = TOKEN_IDENTIFIER; ; index = 76 ; length = 3 line = 4 ; column = 0 ; value ='foo'; } +{kind = TOKEN_DOUBLECOLON; ; index = 80 ; length = 2 line = 4 ; column = 4 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 83 ; length = 1 line = 4 ; column = 7 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 84 ; length = 1 line = 4 ; column = 8 ; value ='x'; } +{kind = TOKEN_COLON; ; index = 86 ; length = 1 line = 4 ; column = 10 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 88 ; length = 5 line = 4 ; column = 12 ; value ='float'; } +{kind = TOKEN_COMMA; ; index = 93 ; length = 1 line = 4 ; column = 17 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 95 ; length = 1 line = 4 ; column = 19 ; value ='y'; } +{kind = TOKEN_COLON; ; index = 97 ; length = 1 line = 4 ; column = 21 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 99 ; length = 5 line = 4 ; column = 23 ; value ='float'; } +{kind = TOKEN_COMMA; ; index = 104 ; length = 1 line = 4 ; column = 28 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 106 ; length = 1 line = 4 ; column = 30 ; value ='z'; } +{kind = TOKEN_COLON; ; index = 108 ; length = 1 line = 4 ; column = 32 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 110 ; length = 5 line = 4 ; column = 34 ; value ='float'; } +{kind = TOKEN_COMMA; ; index = 115 ; length = 1 line = 4 ; column = 39 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 117 ; length = 1 line = 4 ; column = 41 ; value ='w'; } +{kind = TOKEN_COLON; ; index = 119 ; length = 1 line = 4 ; column = 43 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 121 ; length = 5 line = 4 ; column = 45 ; value ='float'; } +{kind = TOKEN_RIGHTPAREN; ; index = 126 ; length = 1 line = 4 ; column = 50 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 128 ; length = 2 line = 4 ; column = 52 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 131 ; length = 5 line = 4 ; column = 55 ; value ='float'; } +{kind = TOKEN_LEFTBRACE; ; index = 137 ; length = 1 line = 4 ; column = 61 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 141 ; length = 6 line = 5 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 148 ; length = 1 line = 5 ; column = 7 ; value ='x'; } +{kind = TOKEN_STAR; ; index = 150 ; length = 1 line = 5 ; column = 9 ; value ='*'; } +{kind = TOKEN_IDENTIFIER; ; index = 152 ; length = 1 line = 5 ; column = 11 ; value ='y'; } +{kind = TOKEN_STAR; ; index = 154 ; length = 1 line = 5 ; column = 13 ; value ='*'; } +{kind = TOKEN_IDENTIFIER; ; index = 156 ; length = 1 line = 5 ; column = 15 ; value ='z'; } +{kind = TOKEN_STAR; ; index = 158 ; length = 1 line = 5 ; column = 17 ; value ='*'; } +{kind = TOKEN_IDENTIFIER; ; index = 160 ; length = 1 line = 5 ; column = 19 ; value ='w'; } +{kind = TOKEN_SEMICOLON; ; index = 161 ; length = 1 line = 5 ; column = 20 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 164 ; length = 1 line = 6 ; column = 0 ; value ='}'; } +{kind = TOKEN_VERTEX; ; index = 169 ; length = 6 line = 8 ; column = 0 ; value ='vertex'; } +{kind = TOKEN_IDENTIFIER; ; index = 176 ; length = 4 line = 8 ; column = 7 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 181 ; length = 2 line = 8 ; column = 12 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 184 ; length = 1 line = 8 ; column = 15 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 185 ; length = 1 line = 8 ; column = 16 ; value =')'; } +{kind = TOKEN_LEFTBRACE; ; index = 187 ; length = 1 line = 8 ; column = 18 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 191 ; length = 3 line = 9 ; column = 0 ; value ='foo'; } +{kind = TOKEN_LEFTPAREN; ; index = 194 ; length = 1 line = 9 ; column = 3 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 195 ; length = 3 line = 9 ; column = 4 ; value ='2'; } +{kind = TOKEN_COMMA; ; index = 198 ; length = 1 line = 9 ; column = 7 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 200 ; length = 3 line = 9 ; column = 9 ; value ='3'; } +{kind = TOKEN_RIGHTPAREN; ; index = 203 ; length = 1 line = 9 ; column = 12 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 204 ; length = 1 line = 9 ; column = 13 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 207 ; length = 1 line = 10 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 212 ; length = 0 line = 12 ; column = 0 ; value =''; } diff --git a/test/lex/wrong_multiply.golden b/test/lex/wrong_multiply.golden new file mode 100644 index 0000000..f054098 --- /dev/null +++ b/test/lex/wrong_multiply.golden @@ -0,0 +1,54 @@ +{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 ='float4'; } +{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_IDENTIFIER; ; index = 64 ; length = 3 line = 2 ; column = 0 ; value ='res'; } +{kind = TOKEN_COLON; ; index = 68 ; length = 1 line = 2 ; column = 4 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 70 ; length = 6 line = 2 ; column = 6 ; value ='float2'; } +{kind = TOKEN_ASSIGN; ; index = 77 ; length = 1 line = 2 ; column = 13 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 79 ; length = 6 line = 2 ; column = 15 ; value ='float2'; } +{kind = TOKEN_LEFTPAREN; ; index = 85 ; length = 1 line = 2 ; column = 21 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 86 ; length = 3 line = 2 ; column = 22 ; value ='2'; } +{kind = TOKEN_COMMA; ; index = 89 ; length = 1 line = 2 ; column = 25 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 91 ; length = 3 line = 2 ; column = 27 ; value ='2'; } +{kind = TOKEN_RIGHTPAREN; ; index = 94 ; length = 1 line = 2 ; column = 30 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 95 ; length = 1 line = 2 ; column = 31 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 99 ; length = 3 line = 3 ; column = 0 ; value ='foo'; } +{kind = TOKEN_COLON; ; index = 103 ; length = 1 line = 3 ; column = 4 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 105 ; length = 5 line = 3 ; column = 6 ; value ='float'; } +{kind = TOKEN_ASSIGN; ; index = 111 ; length = 1 line = 3 ; column = 12 ; value ='='; } +{kind = TOKEN_FLOATLITERAL; ; index = 113 ; length = 3 line = 3 ; column = 14 ; value ='1'; } +{kind = TOKEN_SEMICOLON; ; index = 116 ; length = 1 line = 3 ; column = 17 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 120 ; length = 6 line = 4 ; column = 0 ; value ='result'; } +{kind = TOKEN_COLON; ; index = 127 ; length = 1 line = 4 ; column = 7 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 129 ; length = 6 line = 4 ; column = 9 ; value ='float4'; } +{kind = TOKEN_ASSIGN; ; index = 136 ; length = 1 line = 4 ; column = 16 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 138 ; length = 6 line = 4 ; column = 18 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 144 ; length = 1 line = 4 ; column = 24 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 145 ; length = 3 line = 4 ; column = 25 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 148 ; length = 1 line = 4 ; column = 28 ; value =','; } +{kind = TOKEN_IDENTIFIER; ; index = 150 ; length = 3 line = 4 ; column = 30 ; value ='foo'; } +{kind = TOKEN_STAR; ; index = 154 ; length = 1 line = 4 ; column = 34 ; value ='*'; } +{kind = TOKEN_IDENTIFIER; ; index = 156 ; length = 3 line = 4 ; column = 36 ; value ='res'; } +{kind = TOKEN_COMMA; ; index = 159 ; length = 1 line = 4 ; column = 39 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 161 ; length = 3 line = 4 ; column = 41 ; value ='0'; } +{kind = TOKEN_COMMA; ; index = 164 ; length = 1 line = 4 ; column = 44 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 166 ; length = 3 line = 4 ; column = 46 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 169 ; length = 1 line = 4 ; column = 49 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 170 ; length = 1 line = 4 ; column = 50 ; value =';'; } +{kind = TOKEN_RETURN; ; index = 174 ; length = 6 line = 5 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 181 ; length = 6 line = 5 ; column = 7 ; value ='result'; } +{kind = TOKEN_SEMICOLON; ; index = 187 ; length = 1 line = 5 ; column = 13 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 190 ; length = 1 line = 6 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 193 ; length = 0 line = 7 ; column = 0 ; value =''; } diff --git a/test/lex/wrong_type_for_function.golden b/test/lex/wrong_type_for_function.golden new file mode 100644 index 0000000..7f82c40 --- /dev/null +++ b/test/lex/wrong_type_for_function.golden @@ -0,0 +1,73 @@ +{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 ='float3'; } +{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_RETURN; ; index = 64 ; length = 6 line = 2 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 71 ; length = 3 line = 2 ; column = 7 ; value ='pos'; } +{kind = TOKEN_SEMICOLON; ; index = 74 ; length = 1 line = 2 ; column = 10 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 77 ; length = 1 line = 3 ; column = 0 ; value ='}'; } +{kind = TOKEN_IDENTIFIER; ; index = 82 ; length = 3 line = 5 ; column = 0 ; value ='foo'; } +{kind = TOKEN_DOUBLECOLON; ; index = 86 ; length = 2 line = 5 ; column = 4 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 89 ; length = 1 line = 5 ; column = 7 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 90 ; length = 1 line = 5 ; column = 8 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 92 ; length = 2 line = 5 ; column = 10 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 95 ; length = 6 line = 5 ; column = 13 ; value ='float2'; } +{kind = TOKEN_LEFTBRACE; ; index = 102 ; length = 1 line = 5 ; column = 20 ; value ='{'; } +{kind = TOKEN_RETURN; ; index = 106 ; length = 6 line = 6 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 113 ; length = 6 line = 6 ; column = 7 ; value ='float2'; } +{kind = TOKEN_LEFTPAREN; ; index = 119 ; length = 1 line = 6 ; column = 13 ; value ='('; } +{kind = TOKEN_FLOATLITERAL; ; index = 120 ; length = 3 line = 6 ; column = 14 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 123 ; length = 1 line = 6 ; column = 17 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 125 ; length = 3 line = 6 ; column = 19 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 128 ; length = 1 line = 6 ; column = 22 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 129 ; length = 1 line = 6 ; column = 23 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 132 ; length = 1 line = 7 ; column = 0 ; value ='}'; } +{kind = TOKEN_PIXEL; ; index = 137 ; length = 5 line = 9 ; column = 0 ; value ='pixel'; } +{kind = TOKEN_IDENTIFIER; ; index = 143 ; length = 4 line = 9 ; column = 6 ; value ='main'; } +{kind = TOKEN_DOUBLECOLON; ; index = 148 ; length = 2 line = 9 ; column = 11 ; value ='::'; } +{kind = TOKEN_LEFTPAREN; ; index = 151 ; length = 1 line = 9 ; column = 14 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 152 ; length = 1 line = 9 ; column = 15 ; value =')'; } +{kind = TOKEN_ARROW; ; index = 154 ; length = 2 line = 9 ; column = 17 ; value ='->'; } +{kind = TOKEN_IDENTIFIER; ; index = 157 ; length = 6 line = 9 ; column = 20 ; value ='float4'; } +{kind = TOKEN_AT; ; index = 164 ; length = 1 line = 9 ; column = 27 ; value ='@'; } +{kind = TOKEN_IDENTIFIER; ; index = 165 ; length = 7 line = 9 ; column = 28 ; value ='target0'; } +{kind = TOKEN_LEFTBRACE; ; index = 173 ; length = 1 line = 9 ; column = 36 ; value ='{'; } +{kind = TOKEN_IDENTIFIER; ; index = 177 ; length = 1 line = 10 ; column = 0 ; value ='y'; } +{kind = TOKEN_COLON; ; index = 179 ; length = 1 line = 10 ; column = 2 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 181 ; length = 6 line = 10 ; column = 4 ; value ='float2'; } +{kind = TOKEN_ASSIGN; ; index = 188 ; length = 1 line = 10 ; column = 11 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 190 ; length = 3 line = 10 ; column = 13 ; value ='foo'; } +{kind = TOKEN_LEFTPAREN; ; index = 193 ; length = 1 line = 10 ; column = 16 ; value ='('; } +{kind = TOKEN_RIGHTPAREN; ; index = 194 ; length = 1 line = 10 ; column = 17 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 195 ; length = 1 line = 10 ; column = 18 ; value =';'; } +{kind = TOKEN_IDENTIFIER; ; index = 199 ; length = 5 line = 11 ; column = 0 ; value ='color'; } +{kind = TOKEN_COLON; ; index = 205 ; length = 1 line = 11 ; column = 6 ; value =':'; } +{kind = TOKEN_IDENTIFIER; ; index = 207 ; length = 6 line = 11 ; column = 8 ; value ='float4'; } +{kind = TOKEN_ASSIGN; ; index = 214 ; length = 1 line = 11 ; column = 15 ; value ='='; } +{kind = TOKEN_IDENTIFIER; ; index = 216 ; length = 6 line = 11 ; column = 17 ; value ='float4'; } +{kind = TOKEN_LEFTPAREN; ; index = 222 ; length = 1 line = 11 ; column = 23 ; value ='('; } +{kind = TOKEN_IDENTIFIER; ; index = 223 ; length = 1 line = 11 ; column = 24 ; value ='y'; } +{kind = TOKEN_COMMA; ; index = 224 ; length = 1 line = 11 ; column = 25 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 226 ; length = 3 line = 11 ; column = 27 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 229 ; length = 1 line = 11 ; column = 30 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 231 ; length = 3 line = 11 ; column = 32 ; value ='1'; } +{kind = TOKEN_COMMA; ; index = 234 ; length = 1 line = 11 ; column = 35 ; value =','; } +{kind = TOKEN_FLOATLITERAL; ; index = 236 ; length = 3 line = 11 ; column = 37 ; value ='1'; } +{kind = TOKEN_RIGHTPAREN; ; index = 239 ; length = 1 line = 11 ; column = 40 ; value =')'; } +{kind = TOKEN_SEMICOLON; ; index = 240 ; length = 1 line = 11 ; column = 41 ; value =';'; } +{kind = TOKEN_RETURN; ; index = 244 ; length = 6 line = 12 ; column = 0 ; value ='return'; } +{kind = TOKEN_IDENTIFIER; ; index = 251 ; length = 5 line = 12 ; column = 7 ; value ='color'; } +{kind = TOKEN_SEMICOLON; ; index = 256 ; length = 1 line = 12 ; column = 12 ; value =';'; } +{kind = TOKEN_RIGHTBRACE; ; index = 259 ; length = 1 line = 13 ; column = 0 ; value ='}'; } +{kind = TOKEN_EOF; ; index = 262 ; length = 0 line = 14 ; column = 0 ; value =''; } diff --git a/test/lex_all.suite b/test/lex_all.suite new file mode 100644 index 0000000..70625bf --- /dev/null +++ b/test/lex_all.suite @@ -0,0 +1,55 @@ +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 +test/empty_vertex_main_with_position_parameter.ink lex +test/field_assignment.ink lex +test/field_without_type_specifier.ink lex +test/float_suffix.ink lex +test/float_if_cond.ink lex +test/for_i_loop.ink lex +test/for_i_one_liner.ink lex +test/for_no_iter.ink lex +test/function_call.ink lex +test/function_call_out_of_order_declaration.ink lex +test/function_call_return.ink lex +test/functions_with_same_name.ink lex +test/function_with_int_return.ink lex +test/if_cond_assign.ink lex +test/ifdefs.ink lex +test/if_def_block.ink lex +test/if_def_expression.ink lex +test/if_if_if.ink lex +test/inferred_types.ink lex +test/large_block.ink lex +test/multiple_functions.ink lex +test/multiple_semicolons_everywhere.ink lex +test/nested_if.ink lex +test/non_bool_cond.ink lex +test/pass_and_access_struct_fields_in_functions.ink lex +test/passthrough.ink lex +test/redeclared_variable.ink lex +test/rvalue_binary.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 +test/temp_access.ink lex +test/type_as_variable_name.ink lex +test/unary.ink lex +test/undeclared_function.ink lex +test/undeclared_symbol.ink lex +test/unknown_overload.ink lex +test/use_builtin_functions.ink lex +test/wrong_argument_count.ink lex +test/wrong_multiply.ink lex +test/wrong_type_for_function.ink lex diff --git a/test/load_test.ink b/test/load_test.ink new file mode 100644 index 0000000..d49b0c2 --- /dev/null +++ b/test/load_test.ink @@ -0,0 +1,5 @@ +#load "some_file.ink"; + +vertex main :: () { + v2 : float2 = float2(2.0, 2.0); +} diff --git a/test/multiple_functions.ink b/test/multiple_functions.ink new file mode 100644 index 0000000..6deaf30 --- /dev/null +++ b/test/multiple_functions.ink @@ -0,0 +1,12 @@ +foo :: () -> int { + return 5; +} + +bar :: () -> float { + return 1235.0 * 500; +} + +vertex main :: () { + x : int = foo(); + y : float = bar(); +} diff --git a/test/multiple_semicolons_everywhere.ink b/test/multiple_semicolons_everywhere.ink new file mode 100644 index 0000000..0db69de --- /dev/null +++ b/test/multiple_semicolons_everywhere.ink @@ -0,0 +1,14 @@ +vertex main :: (pos : float3 @position) -> float3 @position { + return pos;;; +} + +foo :: () -> float4 { + return float4(1.0, 1.0, 1.0, 1.0);;; +} + +pixel main :: () -> float4 @target0 { + y : float4 = foo();;;; + ;; + color : float4 = y; + return color; +} diff --git a/test/nested_if.ink b/test/nested_if.ink new file mode 100644 index 0000000..6ab592b --- /dev/null +++ b/test/nested_if.ink @@ -0,0 +1,11 @@ +vertex main :: (pos : float3 @position) -> float4 @position { + if pos.x > 100 { + if pos.x > 50 { + return float4(pos, 1.0); + } else { + return float4(1.0); + } + return float4(pos, 1.0); + } + return float4(0.0); +} diff --git a/test/night_time.ink b/test/night_time.ink new file mode 100644 index 0000000..b7dfdd6 --- /dev/null +++ b/test/night_time.ink @@ -0,0 +1,78 @@ +p :: properties { + input_tex : Texture2D; + tex_sampler : Sampler; + + hour_of_day : float; +} + +VS_Input :: struct { + pos : float3 @position; + uv : float2 @uv; +} + +VS_Output :: struct { + pos : float4 @outposition; + uv : float2 @uv; +} + +vertex main :: (input : VS_Input) -> VS_Output { + output : VS_Output; + output.pos = float4(input.pos, 1.0); + output.uv = input.uv; + return output; +} + +apply_night :: (color : float4) -> float4 { + result := color; + result -= float4(0.3, 0.2, 0.0, 0.0); + result *= 0.8; + + return result; +} + +apply_twilight :: (color : float4) -> float4 { + result := color; + result += float4(0.2, -0.1, 0.1, 0.0); + result *= 0.9; + + return result; +} + +apply_morning :: (color : float4) -> float4 { + return color * 1.3; +} + +apply_dawn :: (color : float4) -> float4 { + return color; +} + +pixel main :: (input : VS_Output) -> float4 @outposition { + sampled_color : float4 = sample(p.input_tex, p.tex_sampler, input.uv); + + t := 0.0; + a := float4(0, 0, 0, 0); + b := float4(0, 0, 0, 0); + + if p.hour_of_day > 16 { + t = (p.hour_of_day - 16) / 6; + a = apply_twilight(sampled_color); + b = apply_night(sampled_color); + } else if p.hour_of_day > 12 { + t = (p.hour_of_day - 12) / 6; + a = sampled_color; + b = apply_twilight(sampled_color); + } else if p.hour_of_day > 6 { + t = (p.hour_of_day - 6) / 6; + a = apply_morning(sampled_color); + b = sampled_color; + } else if p.hour_of_day >= 0 { + t = p.hour_of_day / 6; + a = apply_night(sampled_color); + b = apply_morning(sampled_color); + } + + return lerp(a, b, t); +} + + + diff --git a/test/non_bool_cond.ink b/test/non_bool_cond.ink new file mode 100644 index 0000000..9ec6373 --- /dev/null +++ b/test/non_bool_cond.ink @@ -0,0 +1,6 @@ +vertex main :: (pos : float3 @position) -> float4 @position { + if 1.0 { + return float4(pos, 1.0); + } + return float4(0.0); +} 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/arrays.golden b/test/parse/arrays.golden new file mode 100644 index 0000000..f518314 --- /dev/null +++ b/test/parse/arrays.golden @@ -0,0 +1,6 @@ +(program + (fun vertex vs_main -> float4 (@position) + [] + (:= arr [16].float4) + (= arr[0] (float4 1 1 1)) + (return arr[0]))) \ No newline at end of file diff --git a/test/parse/assign_arithmetic_expression.golden b/test/parse/assign_arithmetic_expression.golden new file mode 100644 index 0000000..75418c8 --- /dev/null +++ b/test/parse/assign_arithmetic_expression.golden @@ -0,0 +1,4 @@ +(program + (fun vertex vs_main + [] + (:= x float (+ 2 5)))) \ 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/basic_property_and_return_value.golden b/test/parse/basic_property_and_return_value.golden new file mode 100644 index 0000000..9b38159 --- /dev/null +++ b/test/parse/basic_property_and_return_value.golden @@ -0,0 +1,11 @@ +(program + (constant_buffer properties (@properties) + [(:= color float4)]) + + (fun vertex vs_main -> float3 (@position) + [(:= pos float3 (@position))] + (return pos)) + + (fun pixel ps_main -> float4 (@target0) + [] + (return properties.color))) \ 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/builtin_types.golden b/test/parse/builtin_types.golden new file mode 100644 index 0000000..520ba12 --- /dev/null +++ b/test/parse/builtin_types.golden @@ -0,0 +1,27 @@ +(program + (fun vertex vs_main + [] + (:= v2 float2 (float2 2 2)) + (= v2 (float2 2)) + (= v2 (float2 v2)) + (:= v3 float3 (float3 2 2 2)) + (= v3 (float3 v2 1)) + (= v3 (float3 1 v2)) + (= v3 (float3 1)) + (= v3 (float3 v3)) + (:= v4 float4 (float4 2 2 2 2)) + (= v4 (float4 v4)) + (= v4 (float4 v2 v2)) + (= v4 (float4 v2 1 1)) + (= v4 (float4 1 v2 1)) + (= v4 (float4 1 1 v2)) + (= v4 (float4 v3 2)) + (= v4 (float4 2 v3)) + (= v4 (float4 2)) + (= v4 (float4 1 1 v2)) + (= v4 (float4 2)) + (= v2.x 2) + (= v2.y 2) + (:= p (+ v2.x v3.z)) + (:= q (+ v4.w v2.x)) + (:= m float4x4))) \ No newline at end of file diff --git a/test/parse/complicated_computation.golden b/test/parse/complicated_computation.golden new file mode 100644 index 0000000..0b3f2a7 --- /dev/null +++ b/test/parse/complicated_computation.golden @@ -0,0 +1,6 @@ +(program + (fun vertex vs_main + [] + (:= x float 5) + (:= y float 3000) + (:= z float (+ (* y y) x)))) \ No newline at end of file diff --git a/test/parse/constant_buffer.golden b/test/parse/constant_buffer.golden new file mode 100644 index 0000000..ae2654f --- /dev/null +++ b/test/parse/constant_buffer.golden @@ -0,0 +1,14 @@ +(program + (constant_buffer camera + [(:= projection float4x4) + (:= view float4x4)]) + + (fun vertex vs_main -> float4 (@position) + [(:= pos float4 (@position))] + (:= mv float4 (mul camera.view pos)) + (:= mvp float4 (mul camera.projection mv)) + (return mvp)) + + (fun pixel ps_main -> float4 (@target) + [] + (return (float4 0.5 0.5 0.5 1)))) \ No newline at end of file diff --git a/test/parse/custom_hint.golden b/test/parse/custom_hint.golden new file mode 100644 index 0000000..cb0ee66 --- /dev/null +++ b/test/parse/custom_hint.golden @@ -0,0 +1,12 @@ +(program + (properties p + [(:= time float (@time))]) + + (fun vertex vs_main -> float4 (@position) + [(:= pos float3 (@position))] + (return (float4 pos.x pos.y pos.z 1))) + + (fun pixel ps_main -> float4 (@target) + [(:= pos float4 (@outposition))] + (:= t p.time) + (return (float4 1 1 1 1)))) \ 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/else_if_after_else.golden b/test/parse/else_if_after_else.golden new file mode 100644 index 0000000..e7796d4 --- /dev/null +++ b/test/parse/else_if_after_else.golden @@ -0,0 +1,4 @@ +test/else_if_after_else.ink:6,6: error: 'else if' without 'if' +  } else if 0 > 200 { + ^^^^ + \ No newline at end of file diff --git a/test/parse/empty_struct.golden b/test/parse/empty_struct.golden new file mode 100644 index 0000000..958643d --- /dev/null +++ b/test/parse/empty_struct.golden @@ -0,0 +1,3 @@ +(program + (struct Foo + [])) \ No newline at end of file diff --git a/test/parse/empty_vertex_main.golden b/test/parse/empty_vertex_main.golden new file mode 100644 index 0000000..05724ee --- /dev/null +++ b/test/parse/empty_vertex_main.golden @@ -0,0 +1,3 @@ +(program + (fun vertex vs_main + [])) \ No newline at end of file diff --git a/test/parse/empty_vertex_main_with_position_parameter.golden b/test/parse/empty_vertex_main_with_position_parameter.golden new file mode 100644 index 0000000..55ac1b1 --- /dev/null +++ b/test/parse/empty_vertex_main_with_position_parameter.golden @@ -0,0 +1,4 @@ +(program + (fun vertex vs_main -> float3 + [(:= pos float3 (@position))] + (return pos))) \ No newline at end of file diff --git a/test/parse/field_assignment.golden b/test/parse/field_assignment.golden new file mode 100644 index 0000000..266ed37 --- /dev/null +++ b/test/parse/field_assignment.golden @@ -0,0 +1,6 @@ +(program + (fun vertex vs_main -> float4 (@position) + [(:= pos float4 (@position))] + (:= x float 5) + (= x 7) + (return pos))) \ No newline at end of file diff --git a/test/parse/field_without_type_specifier.golden b/test/parse/field_without_type_specifier.golden new file mode 100644 index 0000000..f8800b3 --- /dev/null +++ b/test/parse/field_without_type_specifier.golden @@ -0,0 +1,4 @@ +(program + (fun vertex vs_main + [] + (:= x 5))) \ No newline at end of file diff --git a/test/parse/float_if_cond.golden b/test/parse/float_if_cond.golden new file mode 100644 index 0000000..19b9cad --- /dev/null +++ b/test/parse/float_if_cond.golden @@ -0,0 +1,6 @@ +(program + (fun vertex vs_main -> float4 (@position) + [(:= pos float3 (@position))] + (if 1 + (return (float4 pos 1))) + (return (float4 0)))) \ No newline at end of file diff --git a/test/parse/for_i_loop.golden b/test/parse/for_i_loop.golden new file mode 100644 index 0000000..9ad7f7a --- /dev/null +++ b/test/parse/for_i_loop.golden @@ -0,0 +1,6 @@ +(program + (fun vertex vs_main + [] + (:= x 0) + (for i : 0..10 + (+= x 1)))) \ No newline at end of file diff --git a/test/parse/for_i_one_liner.golden b/test/parse/for_i_one_liner.golden new file mode 100644 index 0000000..6a295fd --- /dev/null +++ b/test/parse/for_i_one_liner.golden @@ -0,0 +1,4 @@ +test/for_i_one_liner.ink:3,0: error: Unable to parse statement here. 'for' currently expects a brace-enclosed block as a body. + for i : 0..10 x += 2.0; + ^^^ + \ No newline at end of file diff --git a/test/parse/for_no_iter.golden b/test/parse/for_no_iter.golden new file mode 100644 index 0000000..8d74b82 --- /dev/null +++ b/test/parse/for_no_iter.golden @@ -0,0 +1,9 @@ +test/for_no_iter.ink:3,9: error: Expected expression after '..'. Expected end of iterator. + for i : 0.. { + x += 2.0; + ^^ +test/for_no_iter.ink:3,0: error: Unable to parse statement here. + for i : 0.. { + x += 2.0; + ^^^ + \ No newline at end of file diff --git a/test/parse/foreign_function.golden b/test/parse/foreign_function.golden new file mode 100644 index 0000000..d7c7968 --- /dev/null +++ b/test/parse/foreign_function.golden @@ -0,0 +1,15 @@ +(program + (foreign fun float2 -> float2 + [(:= float) + (:= float)]) + + (foreign fun float3 -> float3 + [(:= float) + (:= float) + (:= float)]) + + (foreign fun float4 -> float4 + [(:= float) + (:= float) + (:= float) + (:= float)])) \ No newline at end of file diff --git a/test/parse/foreign_overload.golden b/test/parse/foreign_overload.golden new file mode 100644 index 0000000..8cfe34b --- /dev/null +++ b/test/parse/foreign_overload.golden @@ -0,0 +1,26 @@ +(program + (foreign fun mul -> float2 + [(:= float2) + (:= float2)]) + + (foreign fun mul -> float3 + [(:= float3) + (:= float3)]) + + (foreign fun mul -> float4 + [(:= float4) + (:= float4)]) + + (foreign fun mul -> float4x4 + [(:= float4x4) + (:= float4x4)]) + + (foreign fun float2 -> float2 + [(:= float) + (:= float)]) + + (fun vertex vs_main + [] + (:= v1 float2 (float2 1 1)) + (:= v2 float2 (float2 3 3)) + (:= v3 float2 (mul v1 v2)))) \ No newline at end of file diff --git a/test/parse/function_call.golden b/test/parse/function_call.golden new file mode 100644 index 0000000..08645cd --- /dev/null +++ b/test/parse/function_call.golden @@ -0,0 +1,8 @@ +(program + (fun foo -> int + [] + (return 4)) + + (fun vertex vs_main + [] + (foo))) \ No newline at end of file diff --git a/test/parse/function_call_out_of_order_declaration.golden b/test/parse/function_call_out_of_order_declaration.golden new file mode 100644 index 0000000..37a74df --- /dev/null +++ b/test/parse/function_call_out_of_order_declaration.golden @@ -0,0 +1,7 @@ +(program + (fun vertex vs_main + [] + (foo)) + + (fun foo + [])) \ No newline at end of file diff --git a/test/parse/function_call_return.golden b/test/parse/function_call_return.golden new file mode 100644 index 0000000..991be8a --- /dev/null +++ b/test/parse/function_call_return.golden @@ -0,0 +1,7 @@ +(program + (fun vertex vs_main + []) + + (fun pixel ps_main -> float4 (@target0) + [] + (return (float4 1 1 1 1)))) \ No newline at end of file diff --git a/test/parse/function_with_int_return.golden b/test/parse/function_with_int_return.golden new file mode 100644 index 0000000..20e9d79 --- /dev/null +++ b/test/parse/function_with_int_return.golden @@ -0,0 +1,4 @@ +(program + (fun vertex vs_main -> int + [(:= pos float3)] + (return 0))) \ No newline at end of file diff --git a/test/parse/functions_with_same_name.golden b/test/parse/functions_with_same_name.golden new file mode 100644 index 0000000..99a19ed --- /dev/null +++ b/test/parse/functions_with_same_name.golden @@ -0,0 +1,12 @@ +(program + (fun foo + []) + + (fun foo + []) + + (fun bar + []) + + (fun vertex vs_main + [])) \ No newline at end of file diff --git a/test/parse/hinted_cbuffer.golden b/test/parse/hinted_cbuffer.golden new file mode 100644 index 0000000..10b3fb4 --- /dev/null +++ b/test/parse/hinted_cbuffer.golden @@ -0,0 +1,10 @@ +(program + (constant_buffer props (@properties) + [(:= projection float4x4 (@projection)) + (:= view float4x4 (@view))]) + + (fun vertex vs_main -> float4 (@position) + [(:= pos float4 (@position))] + (:= mv float4 (mul props.view pos)) + (:= mvp float4 (mul props.projection mv)) + (return mvp))) \ No newline at end of file diff --git a/test/parse/if_cond_assign.golden b/test/parse/if_cond_assign.golden new file mode 100644 index 0000000..508188f --- /dev/null +++ b/test/parse/if_cond_assign.golden @@ -0,0 +1,6 @@ +(program + (fun vertex vs_main -> float4 (@position) + [(:= pos float3 (@position))] + (if (= 0 100) + (return (float4 pos 1))) + (return (float4 0)))) \ No newline at end of file diff --git a/test/parse/if_def_block.golden b/test/parse/if_def_block.golden new file mode 100644 index 0000000..772ccd1 --- /dev/null +++ b/test/parse/if_def_block.golden @@ -0,0 +1,8 @@ +(program + (fun pixel ps_main + [] + (#if Env.Alpha + (:= alpha_color (float4 1 0 0 1)) + (:= f 2) + (:= color (float3 0 0 0)) + (:= g 5)))) \ No newline at end of file diff --git a/test/parse/if_def_expression.golden b/test/parse/if_def_expression.golden new file mode 100644 index 0000000..e5f5179 --- /dev/null +++ b/test/parse/if_def_expression.golden @@ -0,0 +1,6 @@ +(program + (#if (|| (&& Env.PS5 Env.XSX) Env.Switch2) + (fun vertex vs_console_main + []) + (fun vertex vs_windows_main + []))) \ No newline at end of file diff --git a/test/parse/if_if_if.golden b/test/parse/if_if_if.golden new file mode 100644 index 0000000..ab9d7b0 --- /dev/null +++ b/test/parse/if_if_if.golden @@ -0,0 +1,4 @@ +test/if_if_if.ink:2,0: error: Expected expression after 'if'. Expected if condition. + if if if 0 > 100 { + ^^ + \ No newline at end of file diff --git a/test/parse/ifdefs.golden b/test/parse/ifdefs.golden new file mode 100644 index 0000000..ff6aea5 --- /dev/null +++ b/test/parse/ifdefs.golden @@ -0,0 +1,12 @@ +(program + (#if Env.Skinning + (fun vertex vs_skinning_main + [] + (:= x float 5)) + (#if Env.UV + (fun vertex vs_texture_mapping_main + [] + (:= x float2 (float2 2 2))))) + + (fun pixel ps_main + [])) \ No newline at end of file diff --git a/test/parse/inferred_types.golden b/test/parse/inferred_types.golden new file mode 100644 index 0000000..530b95d --- /dev/null +++ b/test/parse/inferred_types.golden @@ -0,0 +1,18 @@ +(program + (fun bar -> float + [] + (return 5)) + + (fun foo -> float + [] + (return (bar))) + + (fun vertex vs_main -> float4 (@position) + [(:= pos float3 (@position))] + (:= f 2) + (:= i 10) + (= f (foo)) + (:= v2 (float2 2 2)) + (:= v3 (float3 2 2 3)) + (:= v4 (float4 4 5 6 7)) + (return (float4 1 1 1 1)))) \ No newline at end of file diff --git a/test/parse/large_block.golden b/test/parse/large_block.golden new file mode 100644 index 0000000..e76ad08 --- /dev/null +++ b/test/parse/large_block.golden @@ -0,0 +1,35 @@ +(program + (constant_buffer p (@properties) + [(:= color float4) + (:= rect_position float2) + (:= rect_scale float2) + (:= resolution float2) + (:= texture Texture2D) + (:= sampler Sampler)]) + + (struct PS_Input + [(:= uv float2 (@uv)) + (:= pos float4 (@pos))]) + + (fun vertex vs_main -> PS_Input + [(:= pos float4 (@position))] + (:= res float2 p.resolution) + (:= scale float2 p.rect_scale) + (:= rect_pos float2 p.rect_position) + (:= center float2 rect_pos) + (:= half_size float2 (float2 (/ scale.x 2) (/ scale.y 2))) + (:= dst_pos float4 (float4 (+ (* pos.x half_size.x) center.x) (+ (* pos.y half_size.y) center.y) 0 1)) + (:= result PS_Input) + (:= src_p0 float2 (float2 0 1)) + (:= src_p1 float2 (float2 1 0)) + (:= src_half_size float2 (/ (- src_p1 src_p0) 2)) + (:= src_center float2 (/ (+ src_p1 src_p0) 2)) + (:= src_pos float2 (+ (* (float2 pos.x pos.y) src_half_size) src_center)) + (= result.uv (float2 1 1)) + (= result.pos (float4 (- (/ (* 2 dst_pos.x) res.x) 1) (- (/ (* 2 dst_pos.y) res.y) 1) 0 1)) + (return result)) + + (fun pixel ps_main -> float4 (@target0) + [(:= input PS_Input)] + (:= color float4 p.color) + (return color))) \ No newline at end of file diff --git a/test/parse/meta_block.golden b/test/parse/meta_block.golden new file mode 100644 index 0000000..588da3d --- /dev/null +++ b/test/parse/meta_block.golden @@ -0,0 +1,16 @@ +(program + (meta + [(:= name LitBasic) + (:= category Scene)]) + + (properties + [(:= color float4)]) + + (fun vertex vs_main -> float3 (@position) + [(:= pos float3 (@position)) + (:= uv float2 (@uv))] + (return pos)) + + (fun pixel ps_main -> float4 (@target0) + [] + (return properties.color))) \ No newline at end of file diff --git a/test/parse/multiple_functions.golden b/test/parse/multiple_functions.golden new file mode 100644 index 0000000..ef863b9 --- /dev/null +++ b/test/parse/multiple_functions.golden @@ -0,0 +1,13 @@ +(program + (fun foo -> int + [] + (return 5)) + + (fun bar -> float + [] + (return (* 1235 500))) + + (fun vertex vs_main + [] + (:= x int (foo)) + (:= y float (bar)))) \ No newline at end of file diff --git a/test/parse/multiple_semicolons_everywhere.golden b/test/parse/multiple_semicolons_everywhere.golden new file mode 100644 index 0000000..98c8308 --- /dev/null +++ b/test/parse/multiple_semicolons_everywhere.golden @@ -0,0 +1,14 @@ +(program + (fun vertex vs_main -> float3 (@position) + [(:= pos float3 (@position))] + (return pos)) + + (fun foo -> float4 + [] + (return (float4 1 1 1 1))) + + (fun pixel ps_main -> float4 (@target0) + [] + (:= y float4 (foo)) + (:= color float4 y) + (return color))) \ No newline at end of file diff --git a/test/parse/nested_if.golden b/test/parse/nested_if.golden new file mode 100644 index 0000000..80608cf --- /dev/null +++ b/test/parse/nested_if.golden @@ -0,0 +1,9 @@ +(program + (fun vertex vs_main -> float4 (@position) + [(:= pos float3 (@position))] + (if (> pos.x 100) + (if (> pos.x 50) + (return (float4 pos 1)) + (return (float4 1))) + (return (float4 pos 1))) + (return (float4 0)))) \ No newline at end of file diff --git a/test/parse/non_bool_cond.golden b/test/parse/non_bool_cond.golden new file mode 100644 index 0000000..19b9cad --- /dev/null +++ b/test/parse/non_bool_cond.golden @@ -0,0 +1,6 @@ +(program + (fun vertex vs_main -> float4 (@position) + [(:= pos float3 (@position))] + (if 1 + (return (float4 pos 1))) + (return (float4 0)))) \ No newline at end of file diff --git a/test/parse/pass_and_access_struct_fields_in_functions.golden b/test/parse/pass_and_access_struct_fields_in_functions.golden new file mode 100644 index 0000000..e6f79e8 --- /dev/null +++ b/test/parse/pass_and_access_struct_fields_in_functions.golden @@ -0,0 +1,13 @@ +(program + (struct Foo + [(:= some_data float)]) + + (fun foo -> float + [(:= f Foo)] + (return (* f.some_data 2))) + + (fun vertex vs_main + [] + (:= f Foo) + (= f.some_data 4) + (:= d float (foo f)))) \ No newline at end of file diff --git a/test/parse/passthrough.golden b/test/parse/passthrough.golden new file mode 100644 index 0000000..03ae03e --- /dev/null +++ b/test/parse/passthrough.golden @@ -0,0 +1,8 @@ +(program + (fun vertex vs_main -> float3 (@position) + [(:= pos float3 (@position))] + (return pos)) + + (fun pixel ps_main -> float4 (@target0) + [] + (return (float4 1 1 1 1)))) \ No newline at end of file diff --git a/test/parse/precedence_test.golden b/test/parse/precedence_test.golden new file mode 100644 index 0000000..94c7827 --- /dev/null +++ b/test/parse/precedence_test.golden @@ -0,0 +1,7 @@ +(program + (fun vertex vs_main + [] + (:= x float 2) + (:= y float 5) + (:= z float 10) + (:= w float (+ (* x y) (* y (- z (/ x (* y x)))))))) \ No newline at end of file diff --git a/test/parse/property_rename.golden b/test/parse/property_rename.golden new file mode 100644 index 0000000..7506650 --- /dev/null +++ b/test/parse/property_rename.golden @@ -0,0 +1,11 @@ +(program + (properties props + [(:= color float4)]) + + (fun vertex vs_main -> float4 (@position) + [(:= pos float4 (@position))] + (return pos)) + + (fun pixel ps_main -> float4 (@target0) + [] + (return props.color))) \ No newline at end of file diff --git a/test/parse/redeclared_variable.golden b/test/parse/redeclared_variable.golden new file mode 100644 index 0000000..d147f29 --- /dev/null +++ b/test/parse/redeclared_variable.golden @@ -0,0 +1,5 @@ +(program + (fun vertex vs_main + [] + (:= x float 1) + (:= x float 5))) \ No newline at end of file diff --git a/test/parse/rvalue_binary.golden b/test/parse/rvalue_binary.golden new file mode 100644 index 0000000..9528bb6 --- /dev/null +++ b/test/parse/rvalue_binary.golden @@ -0,0 +1,6 @@ +(program + (fun vertex vs_main + [] + (:= a float2) + (:= b float2) + (:= x (+ a b).x))) \ No newline at end of file diff --git a/test/parse/simple_else_if.golden b/test/parse/simple_else_if.golden new file mode 100644 index 0000000..111f8a9 --- /dev/null +++ b/test/parse/simple_else_if.golden @@ -0,0 +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)))) \ No newline at end of file diff --git a/test/parse/simple_if.golden b/test/parse/simple_if.golden new file mode 100644 index 0000000..3473f24 --- /dev/null +++ b/test/parse/simple_if.golden @@ -0,0 +1,6 @@ +(program + (fun vertex vs_main -> float4 (@position) + [(:= pos float3 (@position))] + (if (> 0 100) + (return (float4 pos 1))) + (return (float4 0)))) \ No newline at end of file diff --git a/test/parse/simple_if_else.golden b/test/parse/simple_if_else.golden new file mode 100644 index 0000000..ab5dcdf --- /dev/null +++ b/test/parse/simple_if_else.golden @@ -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)))) \ No newline at end of file diff --git a/test/parse/simple_struct_access.golden b/test/parse/simple_struct_access.golden new file mode 100644 index 0000000..885933f --- /dev/null +++ b/test/parse/simple_struct_access.golden @@ -0,0 +1,8 @@ +(program + (struct Data + [(:= color float4)]) + + (fun vertex vs_main + [] + (:= d Data) + (:= x float4 d.color))) \ No newline at end of file diff --git a/test/parse/struct_access_primitive_type.golden b/test/parse/struct_access_primitive_type.golden new file mode 100644 index 0000000..3cf9f4a --- /dev/null +++ b/test/parse/struct_access_primitive_type.golden @@ -0,0 +1,5 @@ +(program + (fun vertex vs_main + [] + (:= x int 5) + (= x.d 4))) \ No newline at end of file diff --git a/test/parse/struct_field_access_test.golden b/test/parse/struct_field_access_test.golden new file mode 100644 index 0000000..1eac9b0 --- /dev/null +++ b/test/parse/struct_field_access_test.golden @@ -0,0 +1,31 @@ +(program + (struct Vertex_Out + [(:= position float3 (@position)) + (:= normal float3 (@normal)) + (:= uv float3 (@uv)) + (:= frag_pos float3 (@interp))]) + + (instance + [(:= model float4x4 (@model))]) + + (fun vertex main + [(:= position float3 (@position)) + (:= uv float2 (@uv)) + (:= normal float3 (@normal))] + (:= v_out Vertex_Out) + (= v_out.position (mul position model)) + (= v_out.normal normal) + (= v_out.uv uv) + (= v_out.frag_pos position) + (return v_out)) + + (struct Pixel_Out + [(:= color float4 (@target0)) + (:= emission float4 (@target1))]) + + (fun pixel main + [(:= v_in Vertex_Out)] + (:= p_out Pixel_Out) + (= p_out.color (float4 1 0.5 1 1)) + (= p_out.emission (float4 2 2 2 2)) + (return p_out))) \ No newline at end of file diff --git a/test/parse/struct_within_struct.golden b/test/parse/struct_within_struct.golden new file mode 100644 index 0000000..4a446fc --- /dev/null +++ b/test/parse/struct_within_struct.golden @@ -0,0 +1,12 @@ +(program + (struct Foo + [(:= color float4)]) + + (struct Bar + [(:= t Foo)]) + + (fun vertex vs_main + [] + (:= f Foo) + (:= b Bar) + (= b.t f))) \ No newline at end of file diff --git a/test/parse/temp_access.golden b/test/parse/temp_access.golden new file mode 100644 index 0000000..bbb84d3 --- /dev/null +++ b/test/parse/temp_access.golden @@ -0,0 +1,6 @@ +(program + (fun vertex vs_main + [] + (:= a float2) + (:= b float2) + (= (+ a b).x 2))) \ No newline at end of file diff --git a/test/parse/texture_sample.golden b/test/parse/texture_sample.golden new file mode 100644 index 0000000..2787800 --- /dev/null +++ b/test/parse/texture_sample.golden @@ -0,0 +1,21 @@ +(program + (properties p + [(:= texture texture2D) + (:= sampler sampler)]) + + (struct PS_Input + [(:= uv float2 (@uv)) + (:= pos float4 (@position))]) + + (fun vertex vs_main -> PS_Input + [(:= pos float4 (@position)) + (:= uv float2 (@uv))] + (:= result PS_Input) + (= result.uv uv) + (= result.pos pos) + (return result)) + + (fun pixel ps_main -> float4 (@target) + [(:= input PS_Input)] + (:= color float4 (sample p.texture input.uv p.sampler)) + (return color))) \ No newline at end of file diff --git a/test/parse/type_as_function_name.golden b/test/parse/type_as_function_name.golden new file mode 100644 index 0000000..a18c0e0 --- /dev/null +++ b/test/parse/type_as_function_name.golden @@ -0,0 +1,3 @@ +(program + (fun int + [])) \ No newline at end of file diff --git a/test/parse/type_as_variable_name.golden b/test/parse/type_as_variable_name.golden new file mode 100644 index 0000000..e9b253f --- /dev/null +++ b/test/parse/type_as_variable_name.golden @@ -0,0 +1,4 @@ +(program + (fun vertex vs_main + [] + (:= int float 4))) \ No newline at end of file diff --git a/test/parse/unary.golden b/test/parse/unary.golden new file mode 100644 index 0000000..e246f2a --- /dev/null +++ b/test/parse/unary.golden @@ -0,0 +1,8 @@ +(program + (fun vertex vs_vs_main -> float4 (@position) + [(:= position float3 (@position))] + (return (float4 position.x position.y position.z 1))) + + (fun pixel ps_ps_main -> float4 (@target) + [(:= position float4 (@outposition))] + (return (float4 0.5 -1 0 1)))) \ No newline at end of file diff --git a/test/parse/undeclared_function.golden b/test/parse/undeclared_function.golden new file mode 100644 index 0000000..3b8dc2c --- /dev/null +++ b/test/parse/undeclared_function.golden @@ -0,0 +1,4 @@ +(program + (fun vertex vs_main + [] + (foo))) \ No newline at end of file diff --git a/test/parse/undeclared_symbol.golden b/test/parse/undeclared_symbol.golden new file mode 100644 index 0000000..12f6b40 --- /dev/null +++ b/test/parse/undeclared_symbol.golden @@ -0,0 +1,4 @@ +(program + (fun vertex vs_main + [] + (:= b int f))) \ No newline at end of file diff --git a/test/parse/unknown_overload.golden b/test/parse/unknown_overload.golden new file mode 100644 index 0000000..0eacd96 --- /dev/null +++ b/test/parse/unknown_overload.golden @@ -0,0 +1,14 @@ +(program + (fun foo + [(:= v1 float3) + (:= v2 float3)]) + + (fun foo + [(:= v1 float2) + (:= v2 float2) + (:= v3 float2)]) + + (fun vertex vs_main + [] + (:= v float 2) + (foo v v))) \ No newline at end of file diff --git a/test/parse/use_builtin_functions.golden b/test/parse/use_builtin_functions.golden new file mode 100644 index 0000000..ce3f292 --- /dev/null +++ b/test/parse/use_builtin_functions.golden @@ -0,0 +1,4 @@ +(program + (fun vertex vs_main + [] + (:= f float4 (float4 1 1 1 1)))) \ No newline at end of file diff --git a/test/parse/wrong_argument_count.golden b/test/parse/wrong_argument_count.golden new file mode 100644 index 0000000..02bd703 --- /dev/null +++ b/test/parse/wrong_argument_count.golden @@ -0,0 +1,17 @@ +(program + (fun foo -> float + [(:= x float) + (:= y float) + (:= z float)] + (return (* (* x y) z))) + + (fun foo -> float + [(:= x float) + (:= y float) + (:= z float) + (:= w float)] + (return (* (* (* x y) z) w))) + + (fun vertex vs_main + [] + (foo 2 3))) \ No newline at end of file diff --git a/test/parse/wrong_multiply.golden b/test/parse/wrong_multiply.golden new file mode 100644 index 0000000..3dc2f46 --- /dev/null +++ b/test/parse/wrong_multiply.golden @@ -0,0 +1,7 @@ +(program + (fun vertex vs_main -> float4 (@position) + [(:= pos float4 (@position))] + (:= res float2 (float2 2 2)) + (:= foo float 1) + (:= result float4 (float4 1 (* foo res) 0 1)) + (return result))) \ No newline at end of file diff --git a/test/parse/wrong_type_for_function.golden b/test/parse/wrong_type_for_function.golden new file mode 100644 index 0000000..937494b --- /dev/null +++ b/test/parse/wrong_type_for_function.golden @@ -0,0 +1,14 @@ +(program + (fun vertex vs_main -> float3 (@position) + [(:= pos float3 (@position))] + (return pos)) + + (fun foo -> float2 + [] + (return (float2 1 1))) + + (fun pixel ps_main -> float4 (@target0) + [] + (:= y float2 (foo)) + (:= color float4 (float4 y 1 1 1)) + (return color))) \ No newline at end of file diff --git a/test/parse_all.suite b/test/parse_all.suite new file mode 100644 index 0000000..d273418 --- /dev/null +++ b/test/parse_all.suite @@ -0,0 +1,55 @@ +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 +test/empty_vertex_main_with_position_parameter.ink parse +test/field_assignment.ink parse +test/field_without_type_specifier.ink parse +test/float_if_cond.ink parse +test/float_suffix.ink parse +test/for_i_loop.ink parse +test/for_i_one_liner.ink parse +test/for_no_iter.ink parse +test/function_call.ink parse +test/function_call_out_of_order_declaration.ink parse +test/function_call_return.ink parse +test/functions_with_same_name.ink parse +test/function_with_int_return.ink parse +test/if_cond_assign.ink parse +test/ifdefs.ink parse +test/if_def_block.ink parse +test/if_def_expression.ink parse +test/if_if_if.ink parse +test/inferred_types.ink parse +test/large_block.ink parse +test/multiple_functions.ink parse +test/multiple_semicolons_everywhere.ink parse +test/nested_if.ink parse +test/non_bool_cond.ink parse +test/pass_and_access_struct_fields_in_functions.ink parse +test/passthrough.ink parse +test/redeclared_variable.ink parse +test/rvalue_binary.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 +test/temp_access.ink parse +test/type_as_variable_name.ink parse +test/unary.ink parse +test/undeclared_function.ink parse +test/undeclared_symbol.ink parse +test/unknown_overload.ink parse +test/use_builtin_functions.ink parse +test/wrong_argument_count.ink parse +test/wrong_multiply.ink parse +test/wrong_type_for_function.ink parse diff --git a/test/pass_and_access_struct_fields_in_functions.ink b/test/pass_and_access_struct_fields_in_functions.ink new file mode 100644 index 0000000..ab849c0 --- /dev/null +++ b/test/pass_and_access_struct_fields_in_functions.ink @@ -0,0 +1,13 @@ +Foo :: struct { + some_data : float; +} + +foo :: (f : Foo) -> float { + return f.some_data * 2.0; +} + +vertex main :: () { + f : Foo; + f.some_data = 4.0; + d : float = foo(f); +} diff --git a/test/passthrough.ink b/test/passthrough.ink new file mode 100644 index 0000000..98b8204 --- /dev/null +++ b/test/passthrough.ink @@ -0,0 +1,7 @@ +vertex main :: (pos : float3 @position) -> float3 @position { + return pos; +} + +pixel main :: () -> float4 @target0 { + return float4(1.0, 1.0, 1.0, 1.0); +} diff --git a/test/precedence_test.ink b/test/precedence_test.ink new file mode 100644 index 0000000..1cb0672 --- /dev/null +++ b/test/precedence_test.ink @@ -0,0 +1,7 @@ +vertex main :: () { + x : float = 2.0; + y : float = 5.0; + z : float = 10.0; + + w : float = (x * y) + y * (z - x / (y * x)); +} diff --git a/test/redeclared_variable.ink b/test/redeclared_variable.ink new file mode 100644 index 0000000..72181a8 --- /dev/null +++ b/test/redeclared_variable.ink @@ -0,0 +1,4 @@ +vertex main :: () { + x : float = 1.0; + x : float = 5.0; +} diff --git a/test/rvalue_binary.ink b/test/rvalue_binary.ink new file mode 100644 index 0000000..1812fb3 --- /dev/null +++ b/test/rvalue_binary.ink @@ -0,0 +1,6 @@ +vertex main :: () { + a : float2; + b : float2; + + x := (a + b).x; +} diff --git a/test/simple_else_if.ink b/test/simple_else_if.ink new file mode 100644 index 0000000..5a0e776 --- /dev/null +++ b/test/simple_else_if.ink @@ -0,0 +1,11 @@ +vertex main :: (pos : float3 @position) -> float4 @position { + if pos.x > 100 { + return float4(pos, 1.0); + } else if pos.x > 50 { + return float4(pos, 1.0); + } else { + return float4(1.0); + } + return float4(0.0); +} + diff --git a/test/simple_float2_expressions.ink b/test/simple_float2_expressions.ink new file mode 100644 index 0000000..89464db --- /dev/null +++ b/test/simple_float2_expressions.ink @@ -0,0 +1,14 @@ +vertex main :: (pos : float4 @position) -> float4 @position { + src_p0 : float2 = float2(0.0, 1.0); + src_p1 : float2 = float2(1.0, 0.0); + + src_half_size : float2 = (src_p1 - src_p0) / 2; + src_center : float2 = (src_p1 + src_p0) / 2; + src_pos : float2 = float2(pos.x, pos.y) * src_half_size + src_center; + + return float4(1, 1, 1, 1); +} + +pixel main :: () -> float4 @target0 { + return float4(1, 1, 1, 1); +} diff --git a/test/simple_if.ink b/test/simple_if.ink new file mode 100644 index 0000000..65e2a67 --- /dev/null +++ b/test/simple_if.ink @@ -0,0 +1,6 @@ +vertex main :: (pos : float3 @position) -> float4 @position { + if 0 > 100 { + return float4(pos, 1.0); + } + return float4(0.0); +} diff --git a/test/simple_if_else.ink b/test/simple_if_else.ink new file mode 100644 index 0000000..b80447e --- /dev/null +++ b/test/simple_if_else.ink @@ -0,0 +1,8 @@ +vertex main :: (pos : float3 @position) -> float4 @position { + if 0 > 100 { + return float4(pos, 1.0); + } else { + return float4(1.0); + } + return float4(0.0); +} diff --git a/test/simple_struct_access.ink b/test/simple_struct_access.ink new file mode 100644 index 0000000..72cac07 --- /dev/null +++ b/test/simple_struct_access.ink @@ -0,0 +1,8 @@ +Data :: struct { + color : float4; +} + +vertex main :: () { + d : Data; + x : float4 = d.color; +} diff --git a/test/struct_access_primitive_type.ink b/test/struct_access_primitive_type.ink new file mode 100644 index 0000000..9a720a5 --- /dev/null +++ b/test/struct_access_primitive_type.ink @@ -0,0 +1,4 @@ +vertex main :: () { + x : int = 5; + x.d = 4; +} diff --git a/test/struct_output_vertex.ink b/test/struct_output_vertex.ink new file mode 100644 index 0000000..7ebf857 --- /dev/null +++ b/test/struct_output_vertex.ink @@ -0,0 +1,15 @@ +VS_Out :: struct { + pos : float4 @outposition; +} + +vertex main :: (pos : float3 @position) -> VS_Out { + vs_out : VS_Out; + + vs_out.pos = float4(pos, 1.0); + + return vs_out; +} + +pixel main :: (ps_in : VS_Out) -> float4 @target { + return float4(1, 1, 1, 1); +} diff --git a/test/struct_with_multiple_members.ink b/test/struct_with_multiple_members.ink new file mode 100644 index 0000000..6617f01 --- /dev/null +++ b/test/struct_with_multiple_members.ink @@ -0,0 +1,5 @@ +Foo :: struct { + color : float4; + pos : float2; + uv : float2; +} diff --git a/test/struct_within_struct.ink b/test/struct_within_struct.ink new file mode 100644 index 0000000..cee1754 --- /dev/null +++ b/test/struct_within_struct.ink @@ -0,0 +1,13 @@ +Foo :: struct { + color : float4; +} + +Bar :: struct { + t : Foo; +} + +vertex main :: () { + f : Foo; + b : Bar; + b.t = f; +} diff --git a/test/temp_access.ink b/test/temp_access.ink new file mode 100644 index 0000000..d10ca44 --- /dev/null +++ b/test/temp_access.ink @@ -0,0 +1,6 @@ +vertex main :: () { + a : float2; + b : float2; + + (a + b).x = 2.0; +} diff --git a/test/texture_sample.ink b/test/texture_sample.ink new file mode 100644 index 0000000..63c89df --- /dev/null +++ b/test/texture_sample.ink @@ -0,0 +1,23 @@ +p :: properties { + texture : Texture2D; + sampler : Sampler; +} + +PS_Input :: struct { + uv : float2 @uv; + pos : float4 @position; +} + +vertex main :: (pos : float4 @position, uv : float2 @uv) -> PS_Input { + result : PS_Input; + + result.uv = uv; + result.pos = pos; + + return result; +} + +pixel main :: (input : PS_Input) -> float4 @target { + color : float4 = sample(p.texture, input.uv, p.sampler); + return color; +} diff --git a/test/type_as_function_name.ink b/test/type_as_function_name.ink new file mode 100644 index 0000000..0b1ca5f --- /dev/null +++ b/test/type_as_function_name.ink @@ -0,0 +1 @@ +int :: () {} diff --git a/test/type_as_variable_name.ink b/test/type_as_variable_name.ink new file mode 100644 index 0000000..8ad8f6c --- /dev/null +++ b/test/type_as_variable_name.ink @@ -0,0 +1,3 @@ +vertex main :: () { + int : float = 4.0; +} diff --git a/test/unary.ink b/test/unary.ink new file mode 100644 index 0000000..74c8857 --- /dev/null +++ b/test/unary.ink @@ -0,0 +1,7 @@ +vertex vs_main :: (position : float3 @position) -> float4 @position { + return float4(position.x, position.y, position.z, 1.0); +} + +pixel ps_main :: (position : float4 @outposition) -> float4 @target { + return float4(0.5, -1, 0, 1); +} \ No newline at end of file diff --git a/test/undeclared_function.ink b/test/undeclared_function.ink new file mode 100644 index 0000000..6ae1ae3 --- /dev/null +++ b/test/undeclared_function.ink @@ -0,0 +1,3 @@ +vertex main :: () { + foo(); +} diff --git a/test/undeclared_symbol.ink b/test/undeclared_symbol.ink new file mode 100644 index 0000000..75aa132 --- /dev/null +++ b/test/undeclared_symbol.ink @@ -0,0 +1,3 @@ +vertex main :: () { + b : int = f; +} diff --git a/test/unknown_overload.ink b/test/unknown_overload.ink new file mode 100644 index 0000000..96fd0f9 --- /dev/null +++ b/test/unknown_overload.ink @@ -0,0 +1,7 @@ +foo :: (v1 : float3, v2 : float3) {} +foo :: (v1 : float2, v2 : float2, v3 : float2) {} + +vertex main :: () { + v : float = 2.0; + foo(v, v); +} diff --git a/test/use_builtin_functions.ink b/test/use_builtin_functions.ink new file mode 100644 index 0000000..b8bd212 --- /dev/null +++ b/test/use_builtin_functions.ink @@ -0,0 +1,3 @@ +vertex main :: () { + f : float4 = float4(1, 1, 1, 1); +} diff --git a/test/wrong_argument_count.ink b/test/wrong_argument_count.ink new file mode 100644 index 0000000..6f3e788 --- /dev/null +++ b/test/wrong_argument_count.ink @@ -0,0 +1,11 @@ +foo :: (x : float, y : float, z : float) -> float { + return x * y * z; +} +foo :: (x : float, y : float, z : float, w : float) -> float { + return x * y * z * w; +} + +vertex main :: () { + foo(2.0, 3.0); +} + diff --git a/test/wrong_multiply.ink b/test/wrong_multiply.ink new file mode 100644 index 0000000..87cd93f --- /dev/null +++ b/test/wrong_multiply.ink @@ -0,0 +1,6 @@ +vertex main :: (pos : float4 @position) -> float4 @position { + res : float2 = float2(2.0, 2.0); + foo : float = 1.0; + result : float4 = float4(1.0, foo * res, 0.0, 1.0); + return result; +} diff --git a/test/wrong_type_for_function.ink b/test/wrong_type_for_function.ink new file mode 100644 index 0000000..cf4fa72 --- /dev/null +++ b/test/wrong_type_for_function.ink @@ -0,0 +1,13 @@ +vertex main :: (pos : float3 @position) -> float3 @position { + return pos; +} + +foo :: () -> float2 { + return float2(1.0, 1.0); +} + +pixel main :: () -> float4 @target0 { + y : float2 = foo(); + color : float4 = float4(y, 1.0, 1.0, 1.0); + return color; +}