Compare commits

..

24 Commits

Author SHA1 Message Date
d5476b54d7 Fix tests. 2025-09-13 22:02:44 +02:00
622ce388fa Actually fix which allocator we're using in the tests. 2025-09-13 22:01:29 +02:00
b0653b6563 Tracy 2025-09-11 17:29:45 +02:00
d6ea2e4c2f Memory optimization for the general case by reserving significantly fewer tokens in lexer. It was reserving 1 million always! 2025-09-11 12:27:44 +02:00
361a310ed1 Actually pass the allocator in so it's used instead of temp. 2025-09-11 11:33:16 +02:00
78e6d6146e Remove compiler ctx allocator 2025-09-11 11:23:07 +02:00
79ec6cc42f Added the rest of current builtins. Started properly implementing compile tests. 2025-09-11 11:03:02 +02:00
9461fe626f Change result to context for clarity. Fix a bunch of stuff in builtin functions and structs. 2025-09-10 23:21:34 +02:00
ceafd197f5 A bunch of new allocation related stuff. 2025-09-10 06:59:29 +02:00
f4a9592f26 Much better allocation strategy with new ncore arenas. Add more builtin node gen stuff. It's kind of wonky. 2025-09-06 23:30:45 +02:00
9cf51a1534 Broke builtins. 2025-09-06 19:58:46 +02:00
11c936ba7f Started load directive. 2025-09-03 22:31:18 +02:00
4924b01eac Added some initial directive code. Don't quite like the way it's done 2025-09-03 21:05:00 +02:00
603b625e21 Rename of files, improved for handling, add cb hints
- Rename Test to Ink as main file
- Support more errors for for loops.
- Add hints to cbs
2025-09-02 11:55:27 +02:00
9e0728f952 Fixed some error handling and weird consume logic. 2025-09-01 12:58:45 +02:00
94fc3a4dad Added basic for i loops. Missing some breaking tests and more tests. Also want to add for each at some point and it_index. 2025-08-30 22:58:51 +02:00
14f8b20d5f More small changes 2025-08-27 22:12:19 +02:00
4825623c73 Merge branch 'main' of git.nbross.com:nielsbross/Ink-Shader-Language 2025-08-27 21:55:08 +02:00
da87209690 Move compile result stuff out of specific stages. 2025-08-27 21:55:01 +02:00
e0908a67c0 Add hint parsing on constant buffers. Not yet used in output. 2025-08-25 22:08:58 +02:00
ab711b5610 Minor experiment 2025-08-25 21:56:08 +02:00
f6801e3eeb Fix type result on binary compuations. 2025-08-24 11:37:16 +02:00
4f37ed03c0 Remove unnecessary error check in compile_file 2025-08-24 11:22:13 +02:00
5b2e2e936b Add record error to add file. Change compile_file to take varargs 2025-08-24 11:19:59 +02:00
46 changed files with 2502 additions and 705 deletions

3
.gitmodules vendored
View File

@@ -1,3 +1,6 @@
[submodule "modules/nbrutil"]
path = modules/ncore
url = git@git.nbross.com:nielsbross/NCore.git
[submodule "modules/tracy"]
path = modules/tracy
url = https://github.com/rluba/jai-tracy.git

59
AST.jai
View File

@@ -14,6 +14,8 @@ AST_Kind :: enum {
Meta;
Instance;
//==
// Directives
If_Directive;
// Hint;
// Type;
@@ -21,6 +23,7 @@ AST_Kind :: enum {
Call;
Struct;
If;
For;
CBuffer;
FieldList;
ArgList;
@@ -190,7 +193,13 @@ pretty_print_children :: (parent : *AST_Node, indentation : int, builder : *Stri
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 {
@@ -309,6 +318,26 @@ pretty_print_if :: (node : *AST_Node, indentation : int, builder : *String_Build
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);
@@ -327,6 +356,9 @@ pretty_print_node :: (node : *AST_Node, indentation : int, builder : *String_Bui
case .If; {
pretty_print_if(node, indentation, builder, skip_indent);
}
case .For; {
pretty_print_for(node, indentation, builder, skip_indent);
}
case .Struct;
case .ArgList; {
pretty_print_arglist(node, indentation + 2, builder, skip_indent);
@@ -410,6 +442,10 @@ pretty_print_declaration :: (declaration : *AST_Node, indentation : int, builder
append(builder, "pixel ");
}
if declaration.kind == .If_Directive {
append(builder, "#if ");
}
if declaration.kind == .Properties {
append(builder, "properties");
if declaration.name.count > 0 {
@@ -439,26 +475,17 @@ pretty_print_declaration :: (declaration : *AST_Node, indentation : int, builder
}
if declaration.children.count > 0 {
// print_to_builder(builder, "\n");
// if declaration.kind == .Function {
// field_list := declaration.children[0];
// pretty_print_fieldlist(field_list, indentation + 1, builder);
// append(builder, "\n");
// if declaration.children.count > 1 {
// body := declaration.children[1];
// pretty_print_node(body, indentation + 1, builder, true);
// }
// } else if declaration.kind == .Struct {
// pretty_print_node(declaration.children[0], indentation + 1, builder);
// } else {
// pretty_print_node(declaration.children[0], indentation + 1, builder);
// }
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);
} else {
print_to_builder(builder, "\n");
pretty_print_children(declaration, indentation + 1, builder, flags = .NewLine);
}
}
append(builder, ")");
}

View File

@@ -16,26 +16,26 @@ Output_Language :: enum {
Codegen_State :: struct {
path : string;
scope_stack : Scope_Stack;
// scope_stack : Scope_Stack;
current_scope : Scope_Handle;
type_variables : []Type_Variable;
root : *AST_Node;
// type_variables : []Type_Variable;
// root : *AST_Node;
output_language : Output_Language;
builder : String_Builder;
result : Codegen_Result;
result : *Compiler_Context;
}
Codegen_Result :: struct {
messages : [..]Compiler_Message;
// Codegen_Result :: struct {
// messages : [..]Compiler_Message;
had_error : bool;
// had_error : bool;
result_text : string; // @Incomplete(nb): Result for now, should likely be far more sophisticated.
}
// result_text : string; // @Incomplete(nb): Result for now, should likely be far more sophisticated.
// }
Reserved_HLSL_Words :: string.[
"texture",
@@ -56,10 +56,7 @@ Reserved_GLSL_Words :: string.[
""
];
init_codegen_state :: (state : *Codegen_State, file : *Compiled_File, output_language : Output_Language) {
state.root = file.ast_root;
state.scope_stack = file.scope_stack;
state.type_variables = file.type_variables;
init_codegen_state :: (state : *Codegen_State, result : *Compiler_Context, output_language : Output_Language) {
state.current_scope = cast(Scope_Handle)1;
state.output_language = output_language;
init_string_builder(*state.builder);
@@ -105,16 +102,16 @@ hlsl_type_to_string :: (type_variable : Type_Variable) -> string {
}
emit_field :: (state : *Codegen_State, node : *AST_Node, indentation : int) {
find_result := find_symbol(state.scope_stack, node.name, state.current_scope);
find_result := find_symbol(state.result.scope_stack, node.name, state.current_scope);
field := from_handle(state.type_variables, find_result.type_variable);
field := from_handle(state.result.type_variables, find_result.type_variable);
indent(state, indentation);
print_to_builder(*state.builder, "% ", hlsl_type_to_string(field));
if field.struct_field_parent {
parent_tv := from_handle(state.type_variables, field.struct_field_parent.type_variable);
parent_tv := from_handle(state.result.type_variables, field.struct_field_parent.type_variable);
if parent_tv.typename == "properties" {
append(*state.builder, "__PROPERTIES__");
@@ -144,7 +141,7 @@ emit_field :: (state : *Codegen_State, node : *AST_Node, indentation : int) {
for i :0..field.children.count - 1 {
child := from_handle(state.type_variables, field.children[i]);
child := from_handle(state.result.type_variables, field.children[i]);
emit_node(state, child.source_node, 0);
}
@@ -230,7 +227,7 @@ emit_call :: (state : *Codegen_State, node : *AST_Node, indentation : int) {
}
emit_properties :: (state : *Codegen_State, node : *AST_Node, indentation : int) {
find_result := find_symbol(state.scope_stack, ifx node.name.count > 0 then node.name else "properties", state.current_scope);
find_result := find_symbol(state.result.scope_stack, ifx node.name.count > 0 then node.name else "properties", state.current_scope);
if !find_result {
message : Compiler_Message;
@@ -241,7 +238,7 @@ emit_properties :: (state : *Codegen_State, node : *AST_Node, indentation : int)
}
assert(find_result != null, "Attempting to generate undeclared properties buffer. This should never happen at this stage.");
variable := from_handle(state.type_variables, find_result.type_variable);
variable := from_handle(state.result.type_variables, find_result.type_variable);
print_to_builder(*state.builder, "cbuffer __PROPERTIES : register(b%) \n{\n", variable.resource_index);
@@ -253,7 +250,7 @@ emit_properties :: (state : *Codegen_State, node : *AST_Node, indentation : int)
for child : node.children {
if child.kind == .FieldList {
for field : child.children {
tv := from_handle(state.type_variables, field.type_variable);
tv := from_handle(state.result.type_variables, field.type_variable);
if tv.type == .Sampler || tv.type == .Texture2D {
array_add(*resources, field);
continue;
@@ -281,7 +278,7 @@ emit_properties :: (state : *Codegen_State, node : *AST_Node, indentation : int)
emit_function :: (state : *Codegen_State, node : *AST_Node, indentation : int, emit_body := true) {
name := get_actual_function_name(node);
find_result := find_symbol(state.scope_stack, name, state.current_scope);
find_result := find_symbol(state.result.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 {
@@ -293,12 +290,12 @@ emit_function :: (state : *Codegen_State, node : *AST_Node, indentation : int, e
}
for func : find_result.functions {
function_variable := from_handle(state.type_variables, func.type_variable);
function_variable := from_handle(state.result.type_variables, func.type_variable);
indent(state, indentation);
if function_variable.return_type_variable {
return_variable := from_handle(state.type_variables, function_variable.return_type_variable);
return_variable := from_handle(state.result.type_variables, function_variable.return_type_variable);
print_to_builder(*state.builder, "% ", hlsl_type_to_string(return_variable));
} else {
append(*state.builder, "void ");
@@ -438,12 +435,12 @@ emit_node :: (state : *Codegen_State, node : *AST_Node, indentation : int) {
case .Variable; {
indent(*state.builder, indentation);
type_var := from_handle(state.type_variables, node.type_variable);
type_var := from_handle(state.result.type_variables, node.type_variable);
is_properties := type_var.typename == "properties";
if !is_properties {
if type_var.struct_field_parent {
parent_tv := from_handle(state.type_variables, type_var.struct_field_parent.type_variable);
parent_tv := from_handle(state.result.type_variables, type_var.struct_field_parent.type_variable);
if parent_tv.typename == "properties" {
append(*state.builder, "__PROPERTIES__");
@@ -497,6 +494,26 @@ emit_node :: (state : *Codegen_State, node : *AST_Node, indentation : int) {
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);
@@ -556,7 +573,7 @@ emit_struct :: (state : *Codegen_State, node : *AST_Node, indentation : int) {
print_to_builder(*state.builder, "struct %", node.name);
current_scope := state.current_scope;
state.current_scope = from_handle(state.type_variables, node.type_variable).scope;
state.current_scope = from_handle(state.result.type_variables, node.type_variable).scope;
field_list := node.children[0];
@@ -573,11 +590,11 @@ emit_struct :: (state : *Codegen_State, node : *AST_Node, indentation : int) {
}
emit_cbuffer :: (state : *Codegen_State, node : *AST_Node, indentation : int) {
variable := from_handle(state.type_variables, node.type_variable);
variable := from_handle(state.result.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.type_variables, node.type_variable).scope;
state.current_scope = from_handle(state.result.type_variables, node.type_variable).scope;
field_list := node.children[0];
@@ -610,26 +627,37 @@ emit_declaration :: (state : *Codegen_State, node : *AST_Node) {
}
}
codegen :: (result : *Compile_Result) {
codegen :: (result : *Compiler_Context, allocator := temp) {
codegen(result, .HLSL);
}
codegen :: (result : *Compiler_Context, output_language : Output_Language, allocator := temp) {
if result.had_error {
return;
}
for *file : result.files {
new_context := context;
new_context.allocator = allocator;
push_context new_context {
init_context_allocators();
defer clear_context_allocators();
state : Codegen_State;
init_codegen_state(*state, file, .HLSL);
state.result = result;
state.current_scope = cast(Scope_Handle)1;
state.output_language = output_language;
init_string_builder(*state.builder);
codegen_result := codegen(*state);
file.codegen_result_text = copy_string(codegen_result.result_text);
codegen(*state);
}
}
codegen :: (state : *Codegen_State) -> Codegen_Result {
#scope_file
codegen :: (state : *Codegen_State) {
found_function : bool = false;
// found_struct : bool = false;
// for variable : state.type_variables {
// for variable : state.result.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;
@@ -642,7 +670,7 @@ codegen :: (state : *Codegen_State) -> Codegen_Result {
// append(*state.builder, "\n");
// }
for variable : state.type_variables {
for variable : state.result.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);
@@ -653,22 +681,14 @@ codegen :: (state : *Codegen_State) -> Codegen_Result {
append(*state.builder, "\n");
}
for declaration : state.root.children {
for declaration : state.result.root.children {
if declaration.foreign_declaration {
continue;
}
emit_declaration(state, declaration);
}
state.result.result_text = builder_to_string(*state.builder);
return state.result;
}
codegen :: (file : *Compiled_File, output_language : Output_Language) -> Codegen_Result {
codegen_state : Codegen_State;
init_codegen_state(*codegen_state, file, output_language);
return codegen(*codegen_state);
state.result.codegen_result_text = builder_to_string(*state.builder);
}
#scope_module

View File

@@ -1,10 +1,14 @@
/////////////////////////////////////
//~ nbr: General improvements
//
// [x] Print out all failed tests in a list at the end
// [ ] 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
/*~ 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";
@@ -68,9 +72,11 @@ Test_Suite :: struct {
results : [..]Result;
}
get_golden_path :: (file_path : string, stage : Stage_Flags, allocator := context.allocator) -> string {
path := parse_path(file_path);
file_without_extension := split(path.words[path.words.count - 1], ".");
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;
@@ -78,6 +84,7 @@ get_golden_path :: (file_path : string, stage : Stage_Flags, allocator := contex
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; {
@@ -108,10 +115,11 @@ get_golden_path :: (file_path : string, stage : Stage_Flags, allocator := contex
}
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);
golden_path := builder_to_string(*builder,, sc.allocator);
array_add(*path.words, golden_path);
final_path := path_to_string(path);
@@ -119,208 +127,234 @@ get_golden_path :: (file_path : string, stage : Stage_Flags, allocator := contex
return final_path;
}
do_golden_comparison :: (golden_path : string, comparison_text : string, result_data : *Result, output_type : Output_Type) {
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_data.golden_path = copy_string(golden_path);
result_data.type = .Golden_Output;
result.golden_path = copy_string(golden_path);
result.type = .Golden_Output;
return;
} else {
// Do the comparison
if !file_exists(golden_path) {
result_data.info_text = tprint("Golden file % does not exist. Please run with -output-as-golden at least once.\n", golden_path);
result_data.type = .Golden_File_Not_Found;
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);
golden_text, ok := read_entire_file(golden_path,, sc.allocator);
if !ok {
result_data.info_text = tprint("Unable to open golden file %\n", golden_path);
result_data.type = .Golden_File_Not_Found;
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");
gold := replace(golden_text, "\r\n", "\n");
result := compare(comp, gold) == 0;
if !result {
result_data.type = .Failed;
result_data.info_text = tprint("Golden file:\n%\n===============\n%", gold, comp);
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_data.type = .Passed;
result.type = .Passed;
}
}
}
run_codegen_test :: (file_path : string, result : *Compile_Result, output_type : Output_Type = 0) -> Result {
add_file(result, file_path);
run_codegen_test :: (file_path : string, ctx : *Compiler_Context, output_type : Output_Type = 0) -> Result {
result : Result;
result.path = file_path;
result_data : Result;
result_data.path = file_path;
lex(ctx, context.allocator);
parse(ctx, context.allocator);
check(ctx, context.allocator);
lex(result);
parse(result);
check(result);
if result.had_error {
result_data.type = .Failed;
return result_data;
if ctx.had_error {
result.type = .Failed;
return result;
}
result_data = run_codegen_test(result, output_type);
result = run_codegen_test(ctx, output_type);
return result_data;
return result;
}
run_codegen_test :: (result : *Compile_Result, output_type : Output_Type = 0) -> Result {
result_data : Result;
result_data.path = result.files[0].file.path;
run_codegen_test :: (ctx : *Compiler_Context, output_type : Output_Type = 0) -> Result {
result : Result;
result.path = ctx.file.path;
result_text : string;
codegen(result);
codegen(ctx, context.allocator);
if result.had_error {
result_data.type = .Failed;
result_text = report_messages(result.messages);
return result_data;
if ctx.had_error {
result.type = .Failed;
result_text = report_messages(ctx.messages);
return result;
}
result_text = result.files[0].codegen_result_text;
result_text = ctx.codegen_result_text;
if output_type & .StdOut {
result_data.info_text = result_text;
result_data.type = .StdOut;
return result_data;
result.info_text = result_text;
result.type = .StdOut;
return result;
}
golden_path := get_golden_path(result.files[0].file.path, .Codegen);
do_golden_comparison(golden_path, result_text, *result_data, output_type);
return result_data;
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, Compile_Result {
compiler : Shader_Compiler;
run_compile_test :: (path : string, output_type : Output_Type = 0) -> Result, Compiler_Context {
ctx : Compiler_Context;
result : Result;
compilation_result := compile_file(*compiler, .[path]);
print("\n");
result.path = path;
compile_file(*ctx, path, context.allocator);
if compilation_result.had_error {
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);
}
return result, compilation_result;
}
for cb : ctx.cbuffers {
print_to_builder(*sb, "[constant_buffer] - % - %\n", cb.name, cb.buffer_index);
run_lexer_test :: (file_path : string, result : *Compile_Result, output_type : Output_Type = 0) -> Result {
result_data : Result;
result_data.path = file_path;
result_data.stage = .Lexer;
indent(*sb, 1);
for field : cb.fields {
append(*sb, "[field] - ");
pretty_print_field(*sb, *field.base_field);
}
}
result_text : string;
add_file(result, file_path);
lex(result);
if result.had_error {
result_data.type = .Failed;
result_text = report_messages(result.messages);
} else {
result_text = pretty_print_tokens(result.files[0].tokens.tokens, *temp);
result.info_text = builder_to_string(*sb);
}
if output_type & .StdOut {
result_data.info_text = result_text;
result_data.type = .StdOut;
return result_data;
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.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_data, output_type);
return result_data;
do_golden_comparison(golden_path, result_text, *result, output_type);
return result;
}
run_parser_test :: (file_path : string, result : *Compile_Result, output_type : Output_Type = 0) -> Result {
result_data : Result;
result_data.path = file_path;
run_parser_test :: (file_path : string, ctx : *Compiler_Context, output_type : Output_Type = 0) -> Result {
result : Result;
result.path = file_path;
add_file(result, file_path);
lex(result);
if result.had_error {
result_data.type = .Passed;
return result_data;
lex(ctx);
if ctx.had_error {
result.type = .Passed;
return result;
}
result_data = run_parser_test(result, output_type);
result = run_parser_test(ctx, output_type);
return result_data;
return result;
}
run_parser_test :: (result : *Compile_Result, output_type : Output_Type = 0) -> Result {
parse(result);
result_data : Result;
result_data.path = result.files[0].file.path;
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 result.had_error {
result_data.type = .Failed;
result_text = report_messages(result.messages,, temp);
if ctx.had_error {
result.type = .Failed;
result_text = report_messages(ctx.messages);
} else {
result_text = pretty_print_ast(result.files[0].ast_root, *temp);
result_text = pretty_print_ast(ctx.root, context.allocator);
}
if output_type & .StdOut {
result_data.info_text = result_text;
result_data.type = .StdOut;
return result_data;
result.info_text = result_text;
result.type = .StdOut;
return result;
}
golden_path := get_golden_path(result.files[0].file.path, .Parser);
do_golden_comparison(golden_path, result_text, *result_data, output_type);
return result_data;
golden_path := get_golden_path(ctx.file.path, .Parser);
do_golden_comparison(golden_path, result_text, *result, output_type);
return result;
}
run_semantic_analysis_test :: (result : *Compile_Result, output_type : Output_Type = 0) -> Result {
result_data : Result;
result_data.path = result.files[0].file.path;
run_semantic_analysis_test :: (ctx : *Compiler_Context, output_type : Output_Type = 0) -> Result {
result : Result;
result.path = ctx.file.path;
result_text : string;
check(result);
check(ctx, context.allocator);
if result.had_error {
result_data.type = .Failed;
result_text = report_messages(result.messages);
if ctx.had_error {
result.type = .Failed;
result_text = report_messages(ctx.messages);
} else {
result_text = pretty_print_symbol_table(result, temp);
result_text = pretty_print_symbol_table(ctx, context.allocator);
}
if output_type & .StdOut {
result_data.info_text = result_text;
result_data.type = .StdOut;
return result_data;
result.info_text = result_text;
result.type = .StdOut;
return result;
}
golden_path := get_golden_path(result.files[0].file.path, .Semantic_Analysis);
do_golden_comparison(golden_path, result_text, *result_data, output_type);
return result_data;
golden_path := get_golden_path(ctx.file.path, .Semantic_Analysis);
do_golden_comparison(golden_path, result_text, *result, output_type);
return result;
}
run_semantic_analysis_test :: (file_path : string, result : *Compile_Result, output_type : Output_Type = 0) -> Result {
add_file(result, file_path);
run_semantic_analysis_test :: (file_path : string, ctx : *Compiler_Context, output_type : Output_Type = 0) -> Result {
result : Result;
result.path = file_path;
result_data : Result;
result_data.path = file_path;
lex(result);
parse(result);
if result.had_error {
result_data.type = .Failed;
return result_data;
lex(ctx, context.allocator);
parse(ctx, context.allocator);
if ctx.had_error {
result.type = .Failed;
return result;
}
result_data = run_semantic_analysis_test(result, output_type);;
result = run_semantic_analysis_test(ctx, output_type);
return result_data;
return result;
}
make_test_case :: (path : string, stage_flags : Stage_Flags, allocator := context.allocator) -> Test_Case {
@@ -332,47 +366,56 @@ make_test_case :: (path : string, stage_flags : Stage_Flags, allocator := contex
return test_case;
}
run_test_new :: (file_path : string, stage_flags : Stage_Flags, results : *[..]Result, output_type : Output_Type = 0) {
compile_result : Compile_Result;
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, *compile_result, output_type);
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(*compile_result, output_type);
result = run_parser_test(*ctx, output_type);
} else {
result = run_parser_test(file_path, *compile_result, output_type);
result = run_parser_test(file_path, *ctx, output_type);
}
record_result(results, result);
}
if stage_flags & .Semantic_Analysis {
if stage_flags & .Parser && (result.type == .Passed || result.type == .Golden_Output) {
result = run_semantic_analysis_test(*compile_result, output_type);
result = run_semantic_analysis_test(*ctx, output_type);
} else {
result = run_semantic_analysis_test(file_path, *compile_result, output_type);
result = run_semantic_analysis_test(file_path, *ctx, output_type);
}
record_result(results, result);
}
if stage_flags & .Codegen {
if stage_flags & .Semantic_Analysis && (result.type == .Passed || result.type == .Golden_Output) {
result = run_codegen_test(*compile_result, output_type);
result = run_codegen_test(*ctx, output_type);
} else {
result = run_codegen_test(file_path, *compile_result, output_type);
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) {
run_test :: (test_case : Test_Case, results : *[..]Result, output_type : Output_Type = 0, allocator := temp) {
print("%Running test: %......", cyan(), test_case.path);
// path 30
@@ -390,8 +433,7 @@ run_test :: (test_case : Test_Case, results : *[..]Result, output_type : Output_
print(" ");
}
run_test_new(test_case.path, test_case.stage_flags, results, output_type);
// run_test(test_case.path, test_case.stage_flags, results, output_type);
run_test_new(test_case.path, test_case.stage_flags, results, output_type, allocator);
}
record_result :: (results : *[..]Result, result : Result) {
@@ -409,14 +451,16 @@ run_test_suite :: (using suite : *Test_Suite, output_type : Output_Type = 0) {
stage : string;
}
test_arena : Allocator = make_arena(Gigabytes(1));
failed_test_paths : [..]Fail_Data;
failed_test_paths.allocator = temp;
failed_test_paths.allocator = test_arena;
builder : String_Builder;
init_string_builder(*builder,, temp);
init_string_builder(*builder,, test_arena);
for test_case : test_cases {
run_test(test_case, *suite.results, output_type);
run_test(test_case, *suite.results, output_type, allocator = test_arena);
for < suite.results {
result := suite.results[it_index];
@@ -440,7 +484,7 @@ run_test_suite :: (using suite : *Test_Suite, output_type : Output_Type = 0) {
// print("\n");
}
print("\n");
append(*builder, "\n");
if output_type == 0 {
if failed_test_paths.count == 0 {
@@ -459,23 +503,33 @@ run_test_suite :: (using suite : *Test_Suite, output_type : Output_Type = 0) {
}
}
print("%\n", builder_to_string(*builder));
print("%\n", builder_to_string(*builder,, test_arena));
}
read_suite :: (file_path : string, suite : *Test_Suite) -> bool {
bytes, ok := read_entire_file(file_path);
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);
file_without_extension := split(path.words[path.words.count - 1], ".");
suite.name = copy_string(file_without_extension[0]);
split_lines := split(bytes, "\n");
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 {
line := split(split_line, " ");
if split_line.count == 0 {
break;
}
if split_line[0] == #char "#" {
continue;
}
line := split(split_line, " ",, sc.allocator);
if line[0].count == 0 {
continue;
}
@@ -485,7 +539,7 @@ read_suite :: (file_path : string, suite : *Test_Suite) -> bool {
}
if line.count == 1 {
line = split(split_line, "\t");
line = split(split_line, "\t",, sc.allocator);
if line.count == 1 {
log_error("Invalid line - % - \n", it_index + 1);
continue;
@@ -508,7 +562,7 @@ read_suite :: (file_path : string, suite : *Test_Suite) -> bool {
stage_flags |= .Compile;
}
}
test_case := make_test_case(test_case_path, stage_flags);
test_case := make_test_case(test_case_path, stage_flags, allocator);
array_add(*suite.test_cases, test_case);
}
@@ -569,15 +623,19 @@ evaluate_result :: (result : Result) {
}
main :: () {
lexer : Lexer;
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;
}
@@ -620,12 +678,14 @@ main :: () {
} else if arg == "-compile" {
current_suite.test_cases[cases - 1].stage_flags |= .Compile;
} else if contains(arg, ".") {
path_split := split(arg, "\\");
split_path := split(path_split[path_split.count - 1], ".");
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);
test_case := make_test_case(path, 0);
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());
@@ -636,8 +696,10 @@ main :: () {
}
case .None; {
if contains(arg, ".") {
path_split := split(arg, "\\");
split_path := split(path_split[path_split.count - 1], ".");
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 {
@@ -648,12 +710,14 @@ main :: () {
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);
test_case := make_test_case(path, 0);
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 {
@@ -664,7 +728,9 @@ main :: () {
path := copy_string(arg);
suite : Test_Suite;
read_suite(path, *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 {
@@ -678,4 +744,6 @@ main :: () {
for suite : suites {
run_test_suite(*suite, output_type);
}
clear(local_temp);
}

View File

@@ -5,17 +5,11 @@ Lexer :: struct {
current_line : int;
current_column : int;
result : Lexing_Result;
ctx : *Compiler_Context;
path : string;
}
Lexing_Result :: struct {
tokens : [..]Token;
had_error : bool;
messages : [..]Compiler_Message;
}
Token_Kind :: enum {
TOKEN_FLOATLITERAL;
TOKEN_INTLITERAL;
@@ -54,6 +48,7 @@ Token_Kind :: enum {
TOKEN_SEMICOLON;
TOKEN_COMMA;
TOKEN_DOT;
TOKEN_DOTDOT;
TOKEN_IDENTIFIER;
@@ -100,6 +95,7 @@ Token_Kind :: enum {
TOKEN_RETURN;
TOKEN_REGISTER;
TOKEN_STRING;
TOKEN_STRUCT;
TOKEN_SWITCH;
@@ -137,6 +133,8 @@ Token :: struct {
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 {
@@ -264,12 +262,32 @@ identifier_kind :: (using lexer : *Lexer) -> Token_Kind {
error_token :: (lexer : *Lexer, message : string) -> *Token {
token : *Token = new_token(lexer, .TOKEN_ERROR);
lexer.result.had_error = true;
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;
@@ -291,8 +309,8 @@ record_error :: (lexer : *Lexer, message : string) {
array_add(*error.source_locations, source_location);
lexer.result.had_error = true;
array_add(*lexer.result.messages, error);
lexer.ctx.had_error = true;
array_add(*lexer.ctx.messages, error);
}
make_int :: (lexer : *Lexer) -> *Token {
@@ -322,10 +340,6 @@ make_float :: (lexer : *Lexer) -> *Token {
return token;
}
make_string :: () {
}
new_token :: (lexer : *Lexer, kind : Token_Kind) -> *Token {
length := lexer.cursor - lexer.start;
token : Token;
@@ -342,13 +356,49 @@ new_token :: (lexer : *Lexer, kind : Token_Kind) -> *Token {
}
lexer.current_column += length;
array_add(*lexer.result.tokens, token);
return *lexer.result.tokens[lexer.result.tokens.count - 1];
array_add(*lexer.ctx.tokens, token);
return *lexer.ctx.tokens[lexer.ctx.tokens.count - 1];
}
make_directive :: (lexer : *Lexer) -> *Token {
lexer.start += 1;
return make_identifier(lexer, .TOKEN_DIRECTIVE);
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);;
}
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 {
@@ -367,6 +417,7 @@ make_token :: (lexer : *Lexer, token_kind : Token_Kind) -> *Token {
skip_whitespace :: (lexer : *Lexer) {
while true {
if is_at_end(lexer) return;
c := peek_char(lexer);
if c == {
@@ -421,6 +472,17 @@ scan_next_token :: (lexer : *Lexer) -> *Token {
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);
@@ -490,7 +552,10 @@ scan_next_token :: (lexer : *Lexer) -> *Token {
}
case #char ";"; return make_token(lexer, .TOKEN_SEMICOLON);
case #char ","; return make_token(lexer, .TOKEN_COMMA);
case #char "."; return make_token(lexer, .TOKEN_DOT);
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 };
@@ -499,45 +564,35 @@ scan_next_token :: (lexer : *Lexer) -> *Token {
// return error_token(lexer, tprint("Invalid token: %", s));
}
lex :: (result : *Compile_Result) {
if result.had_error {
lex :: (ctx : *Compiler_Context, allocator := temp) {
if ctx.had_error {
return;
}
for *file : result.files {
new_context := context;
new_context.allocator = allocator;
push_context new_context {
init_context_allocators();
defer clear_context_allocators();
lexer : Lexer;
init_lexer_from_string(*lexer, file.file.source);
lexer.path = file.file.path;
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);
}
array_copy(*file.tokens.tokens, lexer.result.tokens);
result.had_error |= lexer.result.had_error;
// @Incomplete(nb): Temporary until we figure out a good way of passing this stuff around
copy_messages(lexer.result.messages, *result.messages);
}
}
lex :: (lexer : *Lexer, allocator : Allocator = context.allocator) -> Lexing_Result {
lexer.result.tokens.allocator = allocator;
token : *Token = scan_next_token(lexer);
while token && token.kind != .TOKEN_EOF {
token = scan_next_token(lexer);
}
return lexer.result;
}
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.result.had_error = true;
lexer.ctx.had_error = true;
}
}
@@ -545,7 +600,7 @@ 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.result.had_error = true;
lexer.ctx.had_error = true;
}
}
@@ -715,9 +770,11 @@ print_from_source_location :: (builder : *String_Builder, source_location : Sour
}
print_from_source_location :: (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,, allocator);
print_from_source_location(*builder, source_location);
init_string_builder(*builder,, sc.allocator);
print_from_source_location(*builder, source_location,, sc.allocator);
return builder_to_string(*builder,, allocator);
}

View File

@@ -1,5 +1,7 @@
#import "Flat_Pool";
// #load "qpwodkqopwkd.jai";
/**
* TODO:
* if parsing
@@ -11,34 +13,14 @@
Parse_State :: struct {
current : *Token;
previous : *Token;
tokens : [..]Token;
current_token_index : int;
node_allocator : Allocator;
node_arena : Arena;
child_allocator : Allocator;
child_arena : Arena;
// had_error : bool;
path : string;
result : Parse_Result;
ctx : *Compiler_Context;
}
////////////////////////////
//@nb - Result and error handling
Parse_Result :: struct {
root : *AST_Node;
nodes : [..]AST_Node;
had_error : bool;
messages : [..]Compiler_Message;
}
Parse_Error_Kind :: enum {
Parse_Error_Type_Missing;
Parse_Error_Expected_Expression;
@@ -129,16 +111,6 @@ parse_rules :: #run -> [(cast(int)Token_Kind.TOKEN_ERROR) + 1]Parse_Rule {
return rules;
}
init_parse_state :: (parse_state : *Parse_State, tokens : [..]Token, path : string) {
parse_state.tokens = tokens;
parse_state.path = path;
parse_state.node_allocator = make_arena(*parse_state.node_arena);
parse_state.child_allocator = make_arena(*parse_state.child_arena);
parse_state.result.nodes.allocator = parse_state.node_allocator;
array_reserve(*parse_state.result.nodes, 4096);
parse_state.current_token_index = 0;
}
////////////////////////////
//@nb - Error handling functions
@@ -147,7 +119,7 @@ record_error :: (parse_state : *Parse_State, token : Token, message : string, re
error : Compiler_Message;
error.message_kind = .Error;
error.message = message;
error.path = parse_state.path;
error.path = parse_state.ctx.file.path;
source_location : Source_Range;
source_location.begin = token;
@@ -155,14 +127,17 @@ record_error :: (parse_state : *Parse_State, token : Token, message : string, re
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.result.had_error = true;
array_add(*parse_state.result.messages, error);
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 {
@@ -190,8 +165,10 @@ unexpected_token :: (state : *Parse_State, token : Token, message : string) {
/*
*/
sc := get_scratch();
defer scratch_end(sc);
builder : String_Builder;
init_string_builder(*builder,, temp);
init_string_builder(*builder,, sc.allocator);
print_to_builder(*builder, "%\n\n", message);
@@ -214,7 +191,7 @@ unexpected_token :: (state : *Parse_State, token : Token, message : string) {
indent(*builder, 1);
print_token_pointer(*builder, token);
final_message := builder_to_string(*builder);
final_message := builder_to_string(*builder,, context.allocator);
record_error(state, token, final_message, false);
}
@@ -262,6 +239,26 @@ else_without_if :: (state : *Parse_State) {
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(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);
@@ -329,6 +326,26 @@ empty_block :: (state : *Parse_State, token : Token, message : string) {
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(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);
@@ -353,14 +370,217 @@ advance_to_sync_point :: (parse_state : *Parse_State) {
////////////////////////////
//@nb - Base parsing functions
make_node :: (parse_state : *Parse_State, kind : AST_Kind) -> *AST_Node {
make_node :: (nodes : *[..]AST_Node, kind : AST_Kind) -> *AST_Node {
node : AST_Node;
node.kind = kind;
node.children.allocator = parse_state.child_allocator;
array_add(*parse_state.result.nodes, node);
array_add(nodes, node);
return *parse_state.result.nodes[parse_state.result.nodes.count - 1];
return *(nodes.*[nodes.count - 1]);
}
make_node :: (parse_state : *Parse_State, kind : AST_Kind) -> *AST_Node {
return make_node(*parse_state.ctx.nodes, kind);
}
// new_builtin_node :: (nodes : *[..]AST_Node, kind : AST_Kind) -> *AST_Node {
// node := make_node(parse_state, kind);
// node.builtin = true;
// return node;
// }
make_builtin_token :: (tokens : *[..]Token, builder : *String_Builder, kind : Token_Kind, text : string, col : *int, line : *int) -> *Token {
tok : Token;
tok.kind = kind;
start := 0;
buffer := get_current_buffer(builder);
if buffer {
start := buffer.count;
}
tok.column = col.*;
print_to_builder(builder, "%", text);
buffer = get_current_buffer(builder);
end := buffer.count;
for c : text {
if c == #char "\n" {
line.* ++ 1;
col.* = 0;
} else {
col.* += 1;
}
}
tok.index = buffer.count - text.count;
tok.length = text.count;
tok.builtin = true;
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);
builder : String_Builder;
builder.allocator = sc.allocator; // I want to find a good way to use scratch here...
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, *builder, .TOKEN_IDENTIFIER, tprint("%", name), *col, *line);
ident_token.ident_value = name;
source_location.begin = ident_token;
append(*builder, " ");
make_builtin_token(*ctx.tokens, *builder, .TOKEN_DOUBLECOLON, "::", *col, *line);
append(*builder, " ");
make_builtin_token(*ctx.tokens, *builder, .TOKEN_STRUCT, "struct", *col, *line);
append(*builder, " ");
make_builtin_token(*ctx.tokens, *builder, .TOKEN_LEFTBRACE, "{", *col, *line);
append(*builder, "\n");
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;
indent(*builder, 1);
field_ident := make_builtin_token(*ctx.tokens, *builder, .TOKEN_IDENTIFIER, tprint("%", member.name), *col, *line);
field_source_loc.begin = field_ident;
field.token = field_ident;
field.name = member.name;
append(*builder, " ");
make_builtin_token(*ctx.tokens, *builder, .TOKEN_COLON, ":", *col, *line);
append(*builder, " ");
make_builtin_token(*ctx.tokens, *builder, .TOKEN_IDENTIFIER, tprint("%", member.typename), *col, *line);
semicolon_tok := make_builtin_token(*ctx.tokens, *builder, .TOKEN_SEMICOLON, ";", *col, *line);
append(*builder, "\n");
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, *builder, .TOKEN_RIGHTBRACE, "}", *col, *line);
append(*builder, "\n");
source_location.end = brace_token;
source := builder_to_string(*builder,, context.allocator);
source_location.begin.source = *source.data[source_location.begin.column];
source_location.end.source = *source.data[source_location.end.column];
for i : tok_index..ctx.tokens.count - 1 {
tok := ctx.tokens[i];
tok.source = *source.data[tok.column];
}
for field : field_list.children {
field.source_location.begin.source = *source.data[field.source_location.begin.column];
field.source_location.end.source = *source.data[field.source_location.end.column];
// field.source_location.main_token.source = *source.data[tok.column];
}
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);
builder : String_Builder;
builder.allocator = sc.allocator; // I want to find a good way to use scratch here...
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, *builder, .TOKEN_IDENTIFIER, tprint("%", name), *col, *line);
source_location.begin = ident_token;
append(*builder, " ");
make_builtin_token(*ctx.tokens, *builder, .TOKEN_DOUBLECOLON, "::", *col, *line);
append(*builder, " ");
make_builtin_token(*ctx.tokens, *builder, .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;
// field_ident := make_builtin_token(*ctx.tokens, *builder, .TOKEN_IDENTIFIER, tprint("%", member.name), *col, *line);
type_tok := make_builtin_token(*ctx.tokens, *builder, .TOKEN_IDENTIFIER, tprint("%", 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, *builder, .TOKEN_COMMA, ",", *col, *line);
append(*builder, " ");
}
field_source_loc.end = type_tok;
field.source_location = field_source_loc;
add_child(field_list, field);
}
make_builtin_token(*ctx.tokens, *builder, .TOKEN_RIGHTPAREN, ")", *col, *line);
semicolon_tok := make_builtin_token(*ctx.tokens, *builder, .TOKEN_SEMICOLON, ";", *col, *line);
source_location.end = semicolon_tok;
source := builder_to_string(*builder,, context.allocator);
source_location.begin.source = *source.data[source_location.begin.column];
source_location.end.source = *source.data[source_location.end.column];
for i : tok_index..ctx.tokens.count - 1 {
tok := ctx.tokens[i];
tok.source = *source.data[tok.column];
}
for field : field_list.children {
field.source_location.begin.source = *source.data[field.source_location.begin.column];
field.source_location.end.source = *source.data[field.source_location.end.column];
// field.source_location.main_token.source = *source.data[tok.column];
}
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 == .Properties);
return struct_or_func.children[0];
}
add_child :: (node : *AST_Node, child : *AST_Node) {
@@ -393,10 +613,10 @@ advance :: (parse_state : *Parse_State) {
parse_state.previous = parse_state.current;
while true {
if parse_state.current_token_index >= parse_state.tokens.count {
if parse_state.current_token_index >= parse_state.ctx.tokens.count {
break;
}
parse_state.current = *parse_state.tokens[parse_state.current_token_index];
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;
@@ -429,7 +649,7 @@ check_any :: (parse_state : *Parse_State, kinds : ..Token_Kind) -> bool {
//nb - Checks if the next token is of a certain kind
check_next :: (parse_state : *Parse_State, kind : Token_Kind) -> bool {
return parse_state.tokens[parse_state.current_token_index].kind == kind;
return parse_state.ctx.tokens[parse_state.current_token_index].kind == kind;
}
//nb - Consume a token if
@@ -440,9 +660,13 @@ consume :: (parse_state : *Parse_State, kind : Token_Kind, message : string) {
}
token := parse_state.previous;
advance(parse_state);
advance_to_sync_point(parse_state);
unexpected_token(parse_state, token, message);
consume(parse_state, kind, message);
if parse_state.current.kind == .TOKEN_EOF {
return;
}
}
////////////////////////////
@@ -451,16 +675,21 @@ get_rule :: (kind : Token_Kind) -> *Parse_Rule {
return *parse_rules[kind];
}
precedence :: (parse_state : *Parse_State, precedence : Precedence) -> *AST_Node {
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 = parse_state.previous.source;
tok_s.count = parse_state.previous.length;
expected_expression(parse_state, parse_state.previous, tprint("Expected expression after '%'.", tok_s));
// @Incomplete: Add error node here?
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.");
}
@@ -473,7 +702,6 @@ precedence :: (parse_state : *Parse_State, precedence : Precedence) -> *AST_Node
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));
// expected_expression(parse_state, parse_state.current, "Reached end of file. Expected expression.");
// @Incomplete: Add error node here?
return null;
}
@@ -540,8 +768,8 @@ binary :: (parse_state : *Parse_State, left : *AST_Node) -> *AST_Node {
}
array_access :: (parse_state : *Parse_State, left : *AST_Node) -> *AST_Node {
identifier := parse_state.tokens[parse_state.current_token_index - 3];
left_bracket := parse_state.tokens[parse_state.current_token_index - 2];
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, .Unary);
array_access.token = left_bracket;
@@ -606,6 +834,66 @@ directive :: (state : *Parse_State) -> *AST_Node {
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;
// source_location.begin = state.previous;
advance(state);
cond := expression(state);
add_child(if_directive, cond);
if_body := block(state);
add_child(if_directive, if_body);
if_directive.source_location = source_location;
return if_directive;
} else if state.current.ident_value == "load" {
advance(state);
if check(state, .TOKEN_STRING) {
// path_tok := state.current;
// path := path_tok.string_value;
// advance(state);
// result : Compiler_Context;
// ctx.allocator = state.ctx.allocator;
// ctx.environment = state.ctx.environment;
// ctx.file = make_file(*result, path);
// if ctx.file.source.count == 0 {
// unable_to_open_file(state, path, path_tok);
// advance_to_sync_point(state);
// advance(state);
// return null;
// }
// consume(state, .TOKEN_SEMICOLON, "Expected ';' after #load directive");
// lex(*result);
// count := state.ctx.tokens..count;
// current_idx := state.current_token_index;
// result_count := ctx.tokens..count;
// // state.ctx.tokens..count -= 1;
// array_resize(*state.ctx.tokens., count + result_count - 1);
// memcpy(*state.ctx.tokens[current_idx + result_count - 1], *state.ctx.tokens[current_idx], size_of(Token) * (count - current_idx));
// for *tok : ctx.tokens. {
// if tok.kind == .TOKEN_EOF {
// break;
// }
// tok.builtin = true;
// state.ctx.tokens[it_index] = tok.*;
// }
}
}
return null;
@@ -693,8 +981,8 @@ floating :: (parse_state : *Parse_State, left : *AST_Node) -> *AST_Node {
return node;
}
expression :: (parse_state : *Parse_State) -> *AST_Node {
expression := precedence(parse_state, .PREC_ASSIGNMENT);
expression :: (parse_state : *Parse_State, message : string = "") -> *AST_Node {
expression := precedence(parse_state, .PREC_ASSIGNMENT, message);
return expression;
}
@@ -749,7 +1037,7 @@ field_declaration :: (parse_state : *Parse_State, identifier_token : *Token) ->
node.array_field = true;
} else {
if !check(parse_state, .TOKEN_ASSIGN) {
internal_error_message(*parse_state.result.messages, "Unimplemented error message.", parse_state.path);
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.");
@@ -771,7 +1059,6 @@ field_declaration :: (parse_state : *Parse_State, identifier_token : *Token) ->
advance(parse_state);
}
}
} else if match(parse_state, .TOKEN_ASSIGN) {
add_child(node, expression(parse_state));
}
@@ -794,8 +1081,8 @@ argument_list :: (parse_state : *Parse_State) -> *AST_Node {
source_location.main_token = parse_state.current;
error_before := parse_state.result.had_error;
parse_state.result.had_error = false;
error_before := parse_state.ctx.had_error;
parse_state.ctx.had_error = false;
while !check(parse_state, .TOKEN_RIGHTPAREN) {
arg := expression(parse_state);
@@ -808,12 +1095,12 @@ argument_list :: (parse_state : *Parse_State) -> *AST_Node {
if check(parse_state, .TOKEN_RIGHTPAREN) break;
consume(parse_state, .TOKEN_COMMA, "Expect ',' after function argument.");
if parse_state.result.had_error {
if parse_state.ctx.had_error {
break;
}
}
parse_state.result.had_error = error_before || parse_state.result.had_error;
parse_state.ctx.had_error = error_before || parse_state.ctx.had_error;
consume(parse_state, .TOKEN_RIGHTPAREN, "Expect ')' after function call.");
@@ -873,9 +1160,10 @@ statement :: (parse_state : *Parse_State) -> *AST_Node {
source_location : Source_Range;
source_location.begin = parse_state.previous;
if_cond := expression(parse_state);
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);
@@ -905,6 +1193,59 @@ statement :: (parse_state : *Parse_State) -> *AST_Node {
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);
}
@@ -1108,6 +1449,18 @@ constant_buffer :: (parse_state : *Parse_State, identifier_token : *Token = null
node : *AST_Node;
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);
@@ -1162,6 +1515,7 @@ const_declaration :: (parse_state : *Parse_State, identifier_token : *Token) ->
}
declaration :: (parse_state : *Parse_State) -> *AST_Node {
skip_statement := false;
decl_node : *AST_Node;
if match(parse_state, .TOKEN_PROPERTIES) {
decl_node = property_block(parse_state);
@@ -1189,6 +1543,7 @@ declaration :: (parse_state : *Parse_State) -> *AST_Node {
decl_node = call(parse_state, null);
} 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;
@@ -1211,7 +1566,7 @@ declaration :: (parse_state : *Parse_State) -> *AST_Node {
decl_node = error;
}
if !decl_node {
if !decl_node && !skip_statement {
decl_node = statement(parse_state);
}
@@ -1222,20 +1577,28 @@ declaration :: (parse_state : *Parse_State) -> *AST_Node {
return decl_node;
}
parse :: (result : *Compile_Result) {
if result.had_error {
parse :: (ctx : *Compiler_Context, allocator := temp) {
if ctx.had_error {
return;
}
for *file : result.files {
new_context := context;
new_context.allocator = allocator;
push_context new_context {
init_context_allocators();
defer clear_context_allocators();
parse_state : Parse_State;
init_parse_state(*parse_state, file.tokens.tokens, file.file.path);
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.result.root = make_node(*parse_state, .Program);
array_reserve(*parse_state.result.root.children, 1024);
program := parse_state.result.root;
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);
@@ -1244,34 +1607,7 @@ parse :: (result : *Compile_Result) {
}
}
}
//@Incomplete(nb): will this straight copy just work?
// Might need to rething how we do this.
file.ast_root = parse_state.result.root;
file.ast_nodes = parse_state.result.nodes;
copy_messages(parse_state.result.messages, *result.messages);
result.had_error |= parse_state.result.had_error;
}
}
parse :: (parse_state : *Parse_State) -> Parse_Result {
advance(parse_state);
if !match(parse_state, .TOKEN_EOF) {
parse_state.result.root = make_node(parse_state, .Program);
array_reserve(*parse_state.result.root.children, 1024);
program := parse_state.result.root;
while !check(parse_state, .TOKEN_EOF) {
decl := declaration(parse_state);
if decl {
add_child(program, decl);
}
}
}
return parse_state.result;
}
#load "AST.jai";

View File

@@ -40,7 +40,7 @@ Type_Kind :: enum {
Array;
}
Type_Variable_Kind :: enum {
Source_Kind :: enum {
Expression;
Declaration; // struct, properties, function, etc.
}
@@ -55,9 +55,12 @@ Typenames :: string.[
"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;
kind : Type_Variable_Kind;
source_kind : Source_Kind;
builtin : bool;
name : string;
@@ -87,8 +90,6 @@ Type_Variable_Handle :: #type, distinct u32;
Scope_Stack :: struct {
allocator : Allocator;
arena : Arena;
stack : [..]Scope;
}
@@ -123,6 +124,8 @@ Scope :: struct {
builtin : bool;
kind : Scope_Kind;
allocator : Allocator;
}
Scope_Handle :: #type, distinct u32;
@@ -140,15 +143,12 @@ Semantic_Checker :: struct {
current_scope : Scope_Handle;
result_file : *Compiled_File;
ctx : *Compiler_Context;
current_buffer_index : u32 = 0;
current_sampler_index : u32 = 0;
current_texture_index : u32 = 0;
messages : [..]Compiler_Message;
message_arena : Arena;
message_allocator : Allocator;
had_error : bool;
}
@@ -451,7 +451,7 @@ Attempting to access a field on a primitive type '%'.
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.result_file.type_variables, variable));
print_to_builder(*builder, "Attempting to access a field on a primitive type '%'.\n", proper_type_to_string(checker.ctx.type_variables, variable));
indent(*builder, 1);
cyan(*builder);
@@ -512,7 +512,7 @@ if_condition_has_to_be_boolean_type :: (checker : *Semantic_Checker, usage_site
usage_child := usage_site.children[0];
usage_loc := usage_child.source_location;
print_to_builder(*builder, "% has type %\n", print_from_source_location(*usage_loc), proper_type_to_string(checker.result_file.type_variables, var));
print_to_builder(*builder, "% has type %\n", print_from_source_location(*usage_loc), proper_type_to_string(checker.ctx.type_variables, var));
message := builder_to_string(*builder,, temp);
record_error(checker, message, usage_site.source_location, false);
@@ -554,7 +554,7 @@ type_mismatch :: (checker : *Semantic_Checker, usage_site : *AST_Node, expect_no
indent(*builder, 1);
print_to_builder(*builder, "expected:\n");
indent(*builder, 2);
proper_type_to_string(*builder, checker.result_file.type_variables, expect_var);
proper_type_to_string(*builder, checker.ctx.type_variables, expect_var);
append(*builder, "\n");
// indent(*builder, 2);
@@ -592,7 +592,7 @@ record_error :: (checker : *Semantic_Checker, error_string : string, locations :
error.message = error_string;
checker.had_error = true;
array_add(*checker.messages, error);
array_add(*checker.ctx.messages, error);
}
is_proper :: (var : Type_Variable) -> bool {
@@ -617,10 +617,12 @@ use_scope :: (checker : *Semantic_Checker, handle : Scope_Handle) -> Scope_Handl
push_scope :: (checker : *Semantic_Checker, name := "", kind : Scope_Kind = .Global) -> *Scope, Scope_Handle {
new_scope : Scope;
array_add(*checker.result_file.scope_stack.stack, new_scope);
array_add(*checker.ctx.scope_stack.stack, new_scope);
count := checker.result_file.scope_stack.stack.count;
scope := *checker.result_file.scope_stack.stack[count - 1];
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;
@@ -628,7 +630,7 @@ push_scope :: (checker : *Semantic_Checker, name := "", kind : Scope_Kind = .Glo
scope.builtin = true;
}
scope.children.allocator = checker.result_file.scope_stack.allocator;
scope.children.allocator = checker.ctx.scope_stack.stack.allocator;
if checker.current_scope {
scope := get_current_scope(checker);
@@ -651,12 +653,12 @@ pop_scope :: (checker : *Semantic_Checker) -> Scope_Handle {
}
peek_scope :: (checker : *Semantic_Checker) -> *Scope, Scope_Handle {
if checker.result_file.scope_stack.stack.count == 0 {
if checker.ctx.scope_stack.stack.count == 0 {
return null, 0;
}
count := checker.result_file.scope_stack.stack.count;
scope := *checker.result_file.scope_stack.stack[count - 1];
count := checker.ctx.scope_stack.stack.count;
scope := *checker.ctx.scope_stack.stack[count - 1];
return scope, xx count;
}
@@ -673,7 +675,7 @@ get_scope :: (scope_stack : Scope_Stack, handle : Scope_Handle) -> *Scope {
}
get_scope :: (checker : *Semantic_Checker, handle : Scope_Handle) -> *Scope {
return get_scope(*checker.result_file.scope_stack, handle);
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 {
@@ -695,8 +697,120 @@ add_symbol_to_scope :: (state : Checker_State, scope_stack : *Scope_Stack, scope
new_type_variable :: (checker : *Semantic_Checker) -> *Type_Variable, Type_Variable_Handle {
variable : Type_Variable;
handle := cast(Type_Variable_Handle)checker.result_file.type_variables.count + 1;
array_add(*checker.result_file.type_variables, 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 : *Semantic_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 : *Semantic_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 : *Semantic_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;
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);
return_var.type = lookup_type(checker, checker.current_scope, return_arg.typename, *return_var.typename);
from_handle(checker, handle).return_type_variable = return_handle;
}
return from_handle(checker, handle), handle;
}
@@ -719,16 +833,13 @@ init_semantic_checker :: (checker : *Semantic_Checker, root : *AST_Node, path :
checker.current_sampler_index = 0;
checker.current_texture_index = 0;
array_reserve(*checker.messages, 16);
checker.program_root = root;
checker.path = path;
// @Incomplete(niels): Use other allocator and/or add static array with convenience functions
array_reserve(*checker.result_file.type_variables, 2048);
array_reserve(*checker.ctx.type_variables, 2048);
checker.result_file.scope_stack.allocator = make_arena(*checker.result_file.scope_stack.arena);
array_reserve(*checker.result_file.scope_stack.stack, 256);
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);
@@ -754,7 +865,7 @@ find_symbol :: (scope_stack : Scope_Stack, name : string, current_scope : Scope_
}
find_symbol :: (checker : *Semantic_Checker, name : string, current_scope : Scope_Handle, containing_scope : *Scope_Handle = null) -> *Defined_Symbol {
return find_symbol(checker.result_file.scope_stack, name, current_scope, containing_scope);
return find_symbol(checker.ctx.scope_stack, name, current_scope, containing_scope);
}
find_symbol :: (name : string, checker : *Semantic_Checker, containing_scope : *Scope_Handle = null) -> *Defined_Symbol {
@@ -762,12 +873,12 @@ find_symbol :: (name : string, checker : *Semantic_Checker, 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));
// assert(handle > 0 && xx handle <= variables.count, tprint("Invalid handle: %. Range is: 1-%", handle, variables.count - 1));
return *variables[handle - 1];
}
from_handle :: (checker : *Semantic_Checker, handle : Type_Variable_Handle) -> *Type_Variable {
return from_handle(checker.result_file.type_variables, handle);
return from_handle(checker.ctx.type_variables, handle);
}
proper_type_to_string :: (builder : *String_Builder, variables : []Type_Variable, var : Type_Variable) {
@@ -843,10 +954,7 @@ proper_type_to_string :: (variables : []Type_Variable, var : Type_Variable, allo
return "______not proper type______";
}
get_type_from_identifier :: (checker : *Semantic_Checker, scope : Scope_Handle, node : *AST_Node, typename : *string = null) -> Type_Kind {
type_string := node.token.ident_value;
lookup_type :: (checker : *Semantic_Checker, scope : Scope_Handle, type_string : string, typename : *string = null) -> Type_Kind {
if type_string == {
case Typenames[Type_Kind.Int]; return .Int;
case Typenames[Type_Kind.Half]; return .Half;
@@ -872,8 +980,9 @@ get_type_from_identifier :: (checker : *Semantic_Checker, scope : Scope_Handle,
return .Invalid;
}
check_expression :: (node : *AST_Node, checker : *Semantic_Checker) -> Type_Variable_Handle {
return 0;
lookup_type :: (checker : *Semantic_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 : *Semantic_Checker, node : *AST_Node) {
@@ -885,7 +994,7 @@ check_block :: (checker : *Semantic_Checker, node : *AST_Node) {
declare_struct :: (checker : *Semantic_Checker, node : *AST_Node, name : string) -> Type_Variable_Handle {
variable, handle := new_type_variable(checker);
variable.type = .Struct;
variable.kind = .Declaration;
variable.source_kind = .Declaration;
variable.name = name;
variable.source_node = node;
variable.typename = name;
@@ -898,7 +1007,7 @@ declare_struct :: (checker : *Semantic_Checker, node : *AST_Node, name : string)
symbol.name = name;
symbol.source_node = node;
symbol.type_variable = handle;
add_symbol_to_scope(checker.state, *checker.result_file.scope_stack, checker.current_scope, name, symbol);
add_symbol_to_scope(checker.state, *checker.ctx.scope_stack, checker.current_scope, name, symbol);
} else {
symbol_redeclaration(checker, node, find_result);
return 0;
@@ -933,7 +1042,7 @@ declare_properties :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Va
name := ifx node.name.count == 0 then "properties" else node.name;
if node.name.count > 0 {
checker.result_file.property_name = name;
checker.ctx.property_name = name;
}
type_var := declare_struct(checker, node, name);
var := from_handle(checker, type_var);
@@ -950,14 +1059,13 @@ declare_cbuffer :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Varia
var.type = .CBuffer;
var.resource_index = checker.current_buffer_index;
checker.current_buffer_index += 1;
array_add(*checker.result_file.constant_buffers, type_var);
array_add(*checker.ctx.constant_buffers, type_var);
return type_var;
}
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);
@@ -977,7 +1085,7 @@ declare_function :: (checker : *Semantic_Checker, node : *AST_Node, builtin : bo
variable, handle := new_type_variable(checker);
variable.type = .Function;
variable.kind = .Declaration;
variable.source_kind = .Declaration;
variable.name = node.name;
variable.source_node = node;
variable.builtin = builtin;
@@ -986,11 +1094,11 @@ declare_function :: (checker : *Semantic_Checker, node : *AST_Node, builtin : bo
name_to_check := get_actual_function_name(node);
if node.vertex_entry_point {
checker.result_file.vertex_entry_point.node = node;
checker.ctx.vertex_entry_point.node = node;
}
if node.pixel_entry_point {
checker.result_file.pixel_entry_point.node = node;
checker.ctx.pixel_entry_point.node = node;
}
find_result := find_symbol(checker, name_to_check, checker.current_scope);
@@ -1004,10 +1112,11 @@ declare_function :: (checker : *Semantic_Checker, node : *AST_Node, builtin : bo
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, 32);
array_add(*symbol.functions, function);
add_symbol_to_scope(checker.state, *checker.result_file.scope_stack, checker.current_scope, name_to_check, symbol);
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];
@@ -1024,7 +1133,7 @@ declare_function :: (checker : *Semantic_Checker, node : *AST_Node, builtin : bo
node_child := field_list.children[i];
typename : string;
arg_type := get_type_from_identifier(checker, checker.current_scope, node_child, *typename);
arg_type := lookup_type(checker, checker.current_scope, node_child, *typename);
other_arg := from_handle(checker, arg);
if arg_type != other_arg.type {
@@ -1084,7 +1193,7 @@ declare_function :: (checker : *Semantic_Checker, node : *AST_Node, builtin : bo
if builtin && node.token.ident_value.count > 0 {
return_var, return_handle := new_type_variable(checker);
return_var.type = get_type_from_identifier(checker, checker.current_scope, node, *return_var.typename);
return_var.type = lookup_type(checker, checker.current_scope, node, *return_var.typename);
from_handle(checker, handle).return_type_variable= return_handle;
}
@@ -1204,7 +1313,7 @@ check_field :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Variable_
variable, handle := new_type_variable(checker);
variable.name = node.name;
typename : string;
variable.type = get_type_from_identifier(checker, checker.current_scope, node, *typename);
variable.type = lookup_type(checker, checker.current_scope, node, *typename);
variable.is_array = node.array_field;
@@ -1216,12 +1325,12 @@ check_field :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Variable_
}
}
if variable.kind == .Declaration && variable.type == .Sampler {
if variable.source_kind == .Declaration && variable.type == .Sampler {
variable.resource_index = checker.current_sampler_index;
checker.current_sampler_index += 1;
}
if variable.kind == .Declaration && variable.type == .Texture2D {
if variable.source_kind == .Declaration && variable.type == .Texture2D {
variable.resource_index = checker.current_texture_index;
checker.current_texture_index += 1;
}
@@ -1244,7 +1353,7 @@ check_field :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Variable_
symbol.name = node.name;
symbol.source_node = node;
symbol.type_variable = handle;
add_symbol_to_scope(checker.state, *checker.result_file.scope_stack, checker.current_scope, node.name, symbol);
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;
@@ -1252,7 +1361,7 @@ check_field :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Variable_
}
if node.token.ident_value.count > 0 {
variable.type = get_type_from_identifier(checker, checker.current_scope, node);
variable.type = lookup_type(checker, checker.current_scope, node);
}
if node.children.count > 0 {
@@ -1435,6 +1544,8 @@ check_node :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Variable_H
variable, handle := new_type_variable(checker);
lhs_type := from_handle(checker, lhs_var);
rhs_type := from_handle(checker, rhs_var);
variable.type = lhs_type.type;
variable.typename = lhs_type.typename;
variable.scope = lhs_type.scope;
@@ -1452,6 +1563,16 @@ check_node :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Variable_H
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 !types_compatible(checker, lhs_var, rhs_var) {
@@ -1476,6 +1597,33 @@ check_node :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Variable_H
case .Return; {
return check_node(checker, node.children[0]);
}
case .For; {
loop_iterator := node.token;
symbol : Defined_Symbol;
symbol.name = loop_iterator.ident_value;
symbol.source_node = node;
variable, handle := new_type_variable(checker);
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]);
}
case .If; {
cond_var := check_node(checker, node.children[0]);
@@ -1496,6 +1644,10 @@ check_node :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Variable_H
}
}
}
case .If_Directive; {
cond_var := check_node(checker, node.children[0]);
assert(false, "Not implemented yet\n");
}
case .Variable; {
return check_variable(checker, node);
}
@@ -1642,11 +1794,278 @@ types_compatible :: (checker : *Semantic_Checker, lhs : Type_Variable_Handle, rh
return true;
}
}
return false;
}
add_hlsl_builtins :: (checker : *Semantic_Checker) {
add_builtins_new :: (checker : *Semantic_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 : *Semantic_Checker) {
source_location := #location().fully_pathed_filename;
path_array := split(source_location, "/");
@@ -1656,11 +2075,11 @@ add_hlsl_builtins :: (checker : *Semantic_Checker) {
append(*sb, "/");
}
append(*sb, "hlsl_builtin.ink");
append(*sb, "builtins.ink");
path := builder_to_string(*sb);
HLSL_BUILTIN, ok := read_entire_file(path);
BUILTIN, ok := read_entire_file(path);
if !ok {
messages : [..]Compiler_Message;
@@ -1672,70 +2091,71 @@ add_hlsl_builtins :: (checker : *Semantic_Checker) {
checker.state = .Adding_Builtins;
lexer : Lexer;
checker.ctx.file = make_file_from_string(BUILTIN);
init_lexer_from_string(*lexer, HLSL_BUILTIN);
if lexer.result.had_error {
print("%\n", report_messages(lexer.result.messages));
return;
}
prev_file := checker.ctx.file;
prev_root := checker.ctx.root;
prev_tokens := checker.ctx.tokens;
lex_result := lex(*lexer,, *temp);
if lex_result.had_error {
print("%\n", report_messages(lex_result.messages));
return;
}
checker.ctx.root = null;
parse_state : Parse_State;
init_parse_state(*parse_state, lex_result.tokens, lexer.path);
tokens : [..]Token;
scratch := get_scratch();
defer scratch_end(scratch);
tokens.allocator = scratch.allocator;
array_reserve(*tokens, 1024 * 1024);
checker.ctx.tokens = tokens;
parse_result := parse(*parse_state);
if parse_result.had_error {
print("%\n", report_messages(parse_result.messages));
return;
}
checker.ctx.tokens.count = 0;
type_check(checker, parse_result.root);
if checker.had_error {
print("%\n", report_messages(checker.messages));
return;
}
lex(checker.ctx);
parse(checker.ctx);
type_check(checker, checker.ctx.root);
for *type_var : checker.result_file.type_variables {
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 : *Semantic_Checker, root : *AST_Node) {
traverse(checker, root);
}
check :: (result : *Compile_Result) {
if result.had_error {
check :: (ctx : *Compiler_Context, allocator : Allocator = temp) {
if ctx.had_error {
return;
}
for *file : result.files {
new_context := context;
new_context.allocator = allocator;
push_context new_context {
init_context_allocators();
defer clear_context_allocators();
checker : Semantic_Checker;
checker.current_buffer_index = 0;
checker.current_sampler_index = 0;
checker.current_texture_index = 0;
checker.result_file = file;
array_reserve(*checker.messages, 32);
checker.ctx = ctx;
init_semantic_checker(*checker, file.ast_root, file.file.path);
init_semantic_checker(*checker, ctx.root, ctx.file.path);
// @Performance: Should have this built in stuff done earlier and only once
add_hlsl_builtins(*checker);
add_builtins_new(*checker);
// add_builtins(*checker);
type_check(*checker, file.ast_root);
type_check(*checker, ctx.root);
result.had_error |= checker.had_error;
copy_messages(checker.messages, *result.messages);
ctx.had_error |= checker.had_error;
}
}
// ===========================================================
@@ -1868,7 +2288,7 @@ pretty_print_scope :: (current_scope : Scope_Handle, scope_stack : Scope_Stack,
case .CBuffer; #through;
case .Properties; #through;
case .Struct; {
if type_variable.typename.count > 0 && type_variable.kind != .Declaration {
if type_variable.typename.count > 0 && type_variable.source_kind != .Declaration {
indent(builder, indentation + 1);
print_key(*scope_stack, current_scope, builder, key);
print_type_variable(builder, variables, type_variable);
@@ -1894,7 +2314,7 @@ pretty_print_scope :: (current_scope : Scope_Handle, scope_stack : Scope_Stack,
case .CBuffer; #through;
case .Properties; #through;
case .Struct; {
if type_variable.typename.count > 0 && type_variable.kind != .Declaration {
if type_variable.typename.count > 0 && type_variable.source_kind != .Declaration {
indent(builder, indentation + 1);
print_key(*scope_stack, current_scope, builder, key);
print_to_builder(builder, "%\n", type_variable.typename);
@@ -1971,7 +2391,7 @@ print_type_variable :: (builder : *String_Builder, variables : []Type_Variable,
source_location.end = right_most.source_location.main_token;
source_location.main_token = node.source_location.main_token;
print_from_source_location(builder, source_location);
print("%\n", print_from_source_location(builder, source_location,, temp));
}
case .Call; {
if variable.return_type_variable{
@@ -1998,7 +2418,7 @@ print_type_variable :: (builder : *String_Builder, variables : []Type_Variable,
append(builder, ")");
}
case; {
print_from_source_location(builder, node.source_location);
print("%\n", print_from_source_location(builder, node.source_location,, temp));
}
}
}
@@ -2014,21 +2434,17 @@ pretty_print_symbol_table :: (checker : *Semantic_Checker, allocator : Allocator
builder : String_Builder;
init_string_builder(*builder,, allocator);
pretty_print_scope(xx checker.current_scope, checker.result_file.scope_stack, checker.result_file.type_variables, *checker.result_file.scope_stack.stack[0], *builder);
pretty_print_scope(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 :: (result : *Compile_Result, allocator : Allocator) -> string {
pretty_print_symbol_table :: (ctx : *Compiler_Context, allocator : Allocator) -> string {
builder : String_Builder;
init_string_builder(*builder,, allocator);
for *file : result.files {
current_scope := cast(Scope_Handle)1;
pretty_print_scope(current_scope, file.scope_stack, file.type_variables, *file.scope_stack.stack[0], *builder);
}
pretty_print_scope(current_scope, ctx.scope_stack, ctx.type_variables, *ctx.scope_stack.stack[0], *builder);
return builder_to_string(*builder,, allocator);
}

View File

@@ -1,16 +1,19 @@
#import "Basic";
#import "File";
#import "Compiler";
#import "Metaprogram_Plugins";
plugins: [..] *Metaprogram_Plugin;
build :: () {
w := compiler_create_workspace("Shader Compiler Test Build");
w := compiler_create_workspace("Ink Build");
if !w {
print("Workspace creation failed.\n");
return;
}
EXECUTABLE_NAME :: "test";
MAIN_FILE :: "Test.jai";
EXECUTABLE_NAME :: "ink";
MAIN_FILE :: "Ink.jai";
options := get_build_options(w);
@@ -18,12 +21,43 @@ build :: () {
args := options.compile_time_command_line;
intercept_flags: Intercept_Flags;
plugin_start_index := -1;
for arg : args {
if arg == {
case "check"; {
options.output_type = .NO_OUTPUT;
}
}
it := args[it_index];
if !it continue;
if it[0] == #char "+" {
plugin_start_index = it_index;
}
}
plugins_to_create: [..] Plugin_To_Create;
tracy : Plugin_To_Create;
tracy.name = "tracy";
array_add(*plugins_to_create, tracy);
// got_error := false;
// if plugin_start_index >= 0 {
// success:, plugins_to_create = parse_plugin_arguments(args, plugin_start_index);
// if !success got_error = true;
// }
// if got_error {
// exit(1);
// }
success := init_plugins(plugins_to_create, *plugins, w);
if !success {
log_error("A plugin init() failed. Exiting.\n");
exit(0);
}
new_path: [..] string;
@@ -35,18 +69,41 @@ build :: () {
wd := get_working_directory();
set_build_options(options, w);
compiler_begin_intercept(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});
set_build_options_dc(.{do_output=false, write_added_strings=false});
}
#run build();
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();

View File

@@ -4,6 +4,8 @@
#load "Semantic_Analysis.jai";
#load "Codegen.jai";
#import "File_Utilities";
add_define :: (env : *Environment, key : string) {
for define : env.defines {
if define == key {
@@ -26,10 +28,6 @@ Environment :: struct {
defines : [..]string;
}
Shader_Compiler :: struct {
environment : Environment;
}
Field_Kind :: enum {
Int :: 0;
Half :: 1;
@@ -119,6 +117,9 @@ Constant_Buffer :: struct {
fields : Static_Array(Property_Field, 16);
// hints : Field_Hint; // optional hint...
hints : [..]Field_Hint;
buffer_index : u32;
}
@@ -136,15 +137,14 @@ Input_File :: struct {
path : string;
}
Token_Stream :: struct {
tokens : [..]Token;
}
Compiled_File :: struct {
Compiler_Context :: struct {
file : Input_File;
tokens : Token_Stream;
ast_root : *AST_Node;
ast_nodes : [..]AST_Node;
environment : Environment;
tokens : [..]Token;;
root : *AST_Node;
nodes : [..]AST_Node;
codegen_result_text : string;
@@ -170,68 +170,72 @@ Compiled_File :: struct {
properties : Properties;
max_constant_buffers :: 16;
cbuffers : Static_Array(Constant_Buffer, max_constant_buffers);
allocator : Allocator;
arena : Arena;
}
Compile_Result :: struct {
files : [..]Compiled_File;
had_error : bool;
messages : [..]Compiler_Message;
allocator : Allocator;
arena : Arena;
}
//@Incomplete(niels): need to consider allocation
add_file :: (result : *Compile_Result, path : string) {
#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(.File_Load_Failed, "Unable to load file: %", path);
return;
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 = file_string;
input_file.source = source;
input_file.path = path;
compiled_file : Compiled_File;
compiled_file.file = input_file;
compiled_file.allocator = make_arena(*compiled_file.arena);
array_add(*result.files, compiled_file);
return input_file;
}
// @Incomplete(nb): Will we ever even use this?
from_file :: (path : string) -> Compile_Result {
arr : [1]string;
arr[0] = path;
return from_files(arr);
}
from_files :: (paths : []string) -> Compile_Result {
result : Compile_Result;
for path : paths {
add_file(*result, path);
}
return result;
}
// Compilation_Result :: struct {
// messages : [..]Compiler_Message;
// had_error : bool;
// collection : Shader_Variant_Collection;
// }
pretty_print_field :: (field : *Field) -> string {
builder : String_Builder;
init_string_builder(*builder,, temp);
@@ -380,7 +384,7 @@ type_variable_to_field :: (type_variables : []Type_Variable, scope_stack : Scope
}
field_hint.kind = .Target;
} else {
field_hint.custom_hint_name = copy_string(hint.ident_value);
field_hint.custom_hint_name = hint.ident_value;
field_hint.kind = .Custom;
}
array_add(*field.hints, field_hint);
@@ -396,15 +400,18 @@ type_variable_to_field :: (type_variables : []Type_Variable, scope_stack : Scope
}
type_variable_to_field :: (checker : *Semantic_Checker, variable : *Type_Variable) -> Field {
return type_variable_to_field(checker.result_file.type_variables, checker.result_file.scope_stack, variable);
return type_variable_to_field(checker.ctx.type_variables, checker.ctx.scope_stack, variable);
}
generate_output_data :: (result : *Compile_Result) {
for *file : result.files {
if file.vertex_entry_point.node {
file.vertex_entry_point.name = file.vertex_entry_point.node.name;
generate_output_data :: (ctx : *Compiler_Context) {
if ctx.had_error {
return;
}
type_variable := from_handle(file.type_variables, file.vertex_entry_point.node.type_variable);
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;
@@ -412,50 +419,58 @@ generate_output_data :: (result : *Compile_Result) {
if node.children[0].kind == .FieldList {
field_list := node.children[0];
for child : field_list.children {
tv := from_handle(file.type_variables, child.type_variable);
field := type_variable_to_field(file.type_variables, file.scope_stack, tv);
array_add(*file.vertex_entry_point.input, field);
tv := from_handle(ctx.type_variables, child.type_variable);
field := type_variable_to_field(ctx.type_variables, ctx.scope_stack, tv);
array_add(*ctx.vertex_entry_point.input, field);
}
}
}
}
for buffer_variable : file.constant_buffers {
variable := from_handle(file.type_variables, buffer_variable);
for buffer_variable : ctx.constant_buffers {
variable := from_handle(ctx.type_variables, buffer_variable);
cb := array_add(*file.cbuffers);
cb := array_add(*ctx.cbuffers);
for i : 0..variable.children.count - 1 {
child := variable.children[i];
field : Property_Field;
field.base_field = type_variable_to_field(file.type_variables, file.scope_stack, from_handle(file.type_variables, child));
field.base_field = type_variable_to_field(ctx.type_variables, ctx.scope_stack, from_handle(ctx.type_variables, child));
array_add(*cb.fields, field);
}
cb.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(*cb.hints, field_hint);
}
}
find_result := find_symbol(*file.scope_stack, file.property_name, xx 1);
find_result := find_symbol(*ctx.scope_stack, ctx.property_name, xx 1);
if find_result {
property_variable := from_handle(file.type_variables, find_result.type_variable);
property_variable := from_handle(ctx.type_variables, find_result.type_variable);
for i : 0..property_variable.children.count - 1 {
child := property_variable.children[i];
field := type_variable_to_field(file.type_variables, file.scope_stack, from_handle(file.type_variables, child));
field := type_variable_to_field(ctx.type_variables, ctx.scope_stack, from_handle(ctx.type_variables, child));
prop_field : Property_Field;
prop_field.base_field = field;
array_add(*file.properties.fields, prop_field);
array_add(*ctx.properties.fields, prop_field);
}
file.properties.buffer_index = property_variable.resource_index;
ctx.properties.buffer_index = property_variable.resource_index;
}
if file.pixel_entry_point.node {
file.pixel_entry_point.name = file.pixel_entry_point.node.name;
type_variable := from_handle(file.type_variables, file.pixel_entry_point.node.type_variable);
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);
field := type_variable_to_field(file.type_variables, file.scope_stack, type_variable.return_type_variable);
field := type_variable_to_field(ctx.type_variables, ctx.scope_stack, type_variable.return_type_variable);
for hint : type_variable.source_node.hint_tokens {
field_hint : Field_Hint;
@@ -479,30 +494,23 @@ generate_output_data :: (result : *Compile_Result) {
array_add(*field.hints, field_hint);
}
file.pixel_entry_point.return_value = field;
}
ctx.pixel_entry_point.return_value = field;
}
}
compile_file :: (compiler : *Shader_Compiler, paths : []string) -> Compile_Result {
result : Compile_Result;
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();
for path : paths {
add_file(*result, path);
ctx.file = make_file(ctx, path);
lex(ctx, allocator);
parse(ctx, allocator);
check(ctx, allocator);
codegen(ctx, allocator);
generate_output_data(ctx);
}
lex(*result);
parse(*result);
check(*result);
codegen(*result);
if result.had_error {
return result;
}
generate_output_data(*result);
return result;
}

1
modules/tracy Submodule

Submodule modules/tracy added at 9668d7b8ab

BIN
output.tracy Normal file

Binary file not shown.

34
test/builtin_types.ink Normal file
View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -1,5 +1,6 @@
test/assign_arithmetic_expression.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

View File

@@ -1,5 +1,6 @@
test/assign_arithmetic_expression.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

View File

@@ -0,0 +1 @@
[vertex entry point] - vs_main

6
test/for_i_loop.ink Normal file
View File

@@ -0,0 +1,6 @@
vertex main :: () {
x := 0;
for i : 0..10 {
x += 1.0;
}
}

4
test/for_i_one_liner.ink Normal file
View File

@@ -0,0 +1,4 @@
vertex main :: () {
x := 0.0;
for i : 0..10 x += 2.0;
}

6
test/for_no_iter.ink Normal file
View File

@@ -0,0 +1,6 @@
vertex main :: () {
x := 0.0;
for i : 0.. {
x += 2.0;
}
}

5
test/if_no_cond.ink Normal file
View File

@@ -0,0 +1,5 @@
vertex main :: () {
if {
}
}

5
test/ifdefs.ink Normal file
View File

@@ -0,0 +1,5 @@
#if Defines.Skinning {
vertex main :: () {
// Stub
}
}

View File

@@ -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 =''; }

View File

@@ -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 =''; }

View File

@@ -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 =''; }

View File

@@ -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 =''; }

289
test/lex/large_block.golden Normal file
View File

@@ -0,0 +1,289 @@
{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 = 5 line = 2 ; column = 0 ; value ='color'; }
{kind = TOKEN_COLON; ; index = 34 ; length = 1 line = 2 ; column = 14 ; value =':'; }
{kind = TOKEN_IDENTIFIER; ; index = 36 ; length = 6 line = 2 ; column = 16 ; value ='float4'; }
{kind = TOKEN_SEMICOLON; ; index = 42 ; length = 1 line = 2 ; column = 22 ; value =';'; }
{kind = TOKEN_IDENTIFIER; ; index = 46 ; length = 13 line = 3 ; column = 0 ; value ='rect_position'; }
{kind = TOKEN_COLON; ; index = 60 ; length = 1 line = 3 ; column = 14 ; value =':'; }
{kind = TOKEN_IDENTIFIER; ; index = 62 ; length = 6 line = 3 ; column = 16 ; value ='float2'; }
{kind = TOKEN_SEMICOLON; ; index = 68 ; length = 1 line = 3 ; column = 22 ; value =';'; }
{kind = TOKEN_IDENTIFIER; ; index = 72 ; length = 10 line = 4 ; column = 0 ; value ='rect_scale'; }
{kind = TOKEN_COLON; ; index = 86 ; length = 1 line = 4 ; column = 14 ; value =':'; }
{kind = TOKEN_IDENTIFIER; ; index = 88 ; length = 6 line = 4 ; column = 16 ; value ='float2'; }
{kind = TOKEN_SEMICOLON; ; index = 94 ; length = 1 line = 4 ; column = 22 ; value =';'; }
{kind = TOKEN_IDENTIFIER; ; index = 98 ; length = 10 line = 5 ; column = 0 ; value ='resolution'; }
{kind = TOKEN_COLON; ; index = 112 ; length = 1 line = 5 ; column = 14 ; value =':'; }
{kind = TOKEN_IDENTIFIER; ; index = 114 ; length = 6 line = 5 ; column = 16 ; value ='float2'; }
{kind = TOKEN_SEMICOLON; ; index = 120 ; length = 1 line = 5 ; column = 22 ; value =';'; }
{kind = TOKEN_IDENTIFIER; ; index = 124 ; length = 7 line = 6 ; column = 0 ; value ='texture'; }
{kind = TOKEN_COLON; ; index = 138 ; length = 1 line = 6 ; column = 14 ; value =':'; }
{kind = TOKEN_IDENTIFIER; ; index = 140 ; length = 9 line = 6 ; column = 16 ; value ='Texture2D'; }
{kind = TOKEN_SEMICOLON; ; index = 149 ; length = 1 line = 6 ; column = 25 ; value =';'; }
{kind = TOKEN_IDENTIFIER; ; index = 153 ; length = 7 line = 7 ; column = 0 ; value ='sampler'; }
{kind = TOKEN_COLON; ; index = 167 ; length = 1 line = 7 ; column = 14 ; value =':'; }
{kind = TOKEN_IDENTIFIER; ; index = 169 ; length = 7 line = 7 ; column = 16 ; value ='Sampler'; }
{kind = TOKEN_SEMICOLON; ; index = 176 ; length = 1 line = 7 ; column = 23 ; value =';'; }
{kind = TOKEN_RIGHTBRACE; ; index = 179 ; length = 1 line = 8 ; column = 0 ; value ='}'; }
{kind = TOKEN_IDENTIFIER; ; index = 184 ; length = 8 line = 10 ; column = 0 ; value ='PS_Input'; }
{kind = TOKEN_DOUBLECOLON; ; index = 193 ; length = 2 line = 10 ; column = 9 ; value ='::'; }
{kind = TOKEN_STRUCT; ; index = 196 ; length = 6 line = 10 ; column = 12 ; value ='struct'; }
{kind = TOKEN_LEFTBRACE; ; index = 203 ; length = 1 line = 10 ; column = 19 ; value ='{'; }
{kind = TOKEN_IDENTIFIER; ; index = 207 ; length = 2 line = 11 ; column = 0 ; value ='uv'; }
{kind = TOKEN_COLON; ; index = 210 ; length = 1 line = 11 ; column = 3 ; value =':'; }
{kind = TOKEN_IDENTIFIER; ; index = 212 ; length = 6 line = 11 ; column = 5 ; value ='float2'; }
{kind = TOKEN_AT; ; index = 219 ; length = 1 line = 11 ; column = 12 ; value ='@'; }
{kind = TOKEN_IDENTIFIER; ; index = 220 ; length = 2 line = 11 ; column = 13 ; value ='uv'; }
{kind = TOKEN_SEMICOLON; ; index = 222 ; length = 1 line = 11 ; column = 15 ; value =';'; }
{kind = TOKEN_IDENTIFIER; ; index = 226 ; length = 3 line = 12 ; column = 0 ; value ='pos'; }
{kind = TOKEN_COLON; ; index = 230 ; length = 1 line = 12 ; column = 4 ; value =':'; }
{kind = TOKEN_IDENTIFIER; ; index = 232 ; length = 6 line = 12 ; column = 6 ; value ='float4'; }
{kind = TOKEN_AT; ; index = 239 ; length = 1 line = 12 ; column = 13 ; value ='@'; }
{kind = TOKEN_IDENTIFIER; ; index = 240 ; length = 3 line = 12 ; column = 14 ; value ='pos'; }
{kind = TOKEN_SEMICOLON; ; index = 243 ; length = 1 line = 12 ; column = 17 ; value =';'; }
{kind = TOKEN_RIGHTBRACE; ; index = 246 ; length = 1 line = 13 ; column = 0 ; value ='}'; }
{kind = TOKEN_VERTEX; ; index = 251 ; length = 6 line = 15 ; column = 0 ; value ='vertex'; }
{kind = TOKEN_IDENTIFIER; ; index = 258 ; length = 4 line = 15 ; column = 7 ; value ='main'; }
{kind = TOKEN_DOUBLECOLON; ; index = 263 ; length = 2 line = 15 ; column = 12 ; value ='::'; }
{kind = TOKEN_LEFTPAREN; ; index = 266 ; length = 1 line = 15 ; column = 15 ; value ='('; }
{kind = TOKEN_IDENTIFIER; ; index = 267 ; length = 3 line = 15 ; column = 16 ; value ='pos'; }
{kind = TOKEN_COLON; ; index = 271 ; length = 1 line = 15 ; column = 20 ; value =':'; }
{kind = TOKEN_IDENTIFIER; ; index = 273 ; length = 6 line = 15 ; column = 22 ; value ='float4'; }
{kind = TOKEN_AT; ; index = 280 ; length = 1 line = 15 ; column = 29 ; value ='@'; }
{kind = TOKEN_IDENTIFIER; ; index = 281 ; length = 8 line = 15 ; column = 30 ; value ='position'; }
{kind = TOKEN_RIGHTPAREN; ; index = 289 ; length = 1 line = 15 ; column = 38 ; value =')'; }
{kind = TOKEN_ARROW; ; index = 291 ; length = 2 line = 15 ; column = 40 ; value ='->'; }
{kind = TOKEN_IDENTIFIER; ; index = 294 ; length = 8 line = 15 ; column = 43 ; value ='PS_Input'; }
{kind = TOKEN_LEFTBRACE; ; index = 303 ; length = 1 line = 15 ; column = 52 ; value ='{'; }
{kind = TOKEN_IDENTIFIER; ; index = 307 ; length = 3 line = 16 ; column = 0 ; value ='res'; }
{kind = TOKEN_COLON; ; index = 316 ; length = 1 line = 16 ; column = 9 ; value =':'; }
{kind = TOKEN_IDENTIFIER; ; index = 318 ; length = 6 line = 16 ; column = 11 ; value ='float2'; }
{kind = TOKEN_ASSIGN; ; index = 325 ; length = 1 line = 16 ; column = 18 ; value ='='; }
{kind = TOKEN_IDENTIFIER; ; index = 327 ; length = 1 line = 16 ; column = 20 ; value ='p'; }
{kind = TOKEN_DOT; ; index = 328 ; length = 1 line = 16 ; column = 21 ; value ='.'; }
{kind = TOKEN_IDENTIFIER; ; index = 329 ; length = 10 line = 16 ; column = 22 ; value ='resolution'; }
{kind = TOKEN_SEMICOLON; ; index = 339 ; length = 1 line = 16 ; column = 32 ; value =';'; }
{kind = TOKEN_IDENTIFIER; ; index = 343 ; length = 5 line = 17 ; column = 0 ; value ='scale'; }
{kind = TOKEN_COLON; ; index = 352 ; length = 1 line = 17 ; column = 9 ; value =':'; }
{kind = TOKEN_IDENTIFIER; ; index = 354 ; length = 6 line = 17 ; column = 11 ; value ='float2'; }
{kind = TOKEN_ASSIGN; ; index = 361 ; length = 1 line = 17 ; column = 18 ; value ='='; }
{kind = TOKEN_IDENTIFIER; ; index = 363 ; length = 1 line = 17 ; column = 20 ; value ='p'; }
{kind = TOKEN_DOT; ; index = 364 ; length = 1 line = 17 ; column = 21 ; value ='.'; }
{kind = TOKEN_IDENTIFIER; ; index = 365 ; length = 10 line = 17 ; column = 22 ; value ='rect_scale'; }
{kind = TOKEN_SEMICOLON; ; index = 375 ; length = 1 line = 17 ; column = 32 ; value =';'; }
{kind = TOKEN_IDENTIFIER; ; index = 379 ; length = 8 line = 18 ; column = 0 ; value ='rect_pos'; }
{kind = TOKEN_COLON; ; index = 388 ; length = 1 line = 18 ; column = 9 ; value =':'; }
{kind = TOKEN_IDENTIFIER; ; index = 390 ; length = 6 line = 18 ; column = 11 ; value ='float2'; }
{kind = TOKEN_ASSIGN; ; index = 397 ; length = 1 line = 18 ; column = 18 ; value ='='; }
{kind = TOKEN_IDENTIFIER; ; index = 399 ; length = 1 line = 18 ; column = 20 ; value ='p'; }
{kind = TOKEN_DOT; ; index = 400 ; length = 1 line = 18 ; column = 21 ; value ='.'; }
{kind = TOKEN_IDENTIFIER; ; index = 401 ; length = 13 line = 18 ; column = 22 ; value ='rect_position'; }
{kind = TOKEN_SEMICOLON; ; index = 414 ; length = 1 line = 18 ; column = 35 ; value =';'; }
{kind = TOKEN_SEMICOLON; ; index = 415 ; length = 1 line = 18 ; column = 36 ; value =';'; }
{kind = TOKEN_IDENTIFIER; ; index = 421 ; length = 6 line = 20 ; column = 0 ; value ='center'; }
{kind = TOKEN_COLON; ; index = 428 ; length = 1 line = 20 ; column = 7 ; value =':'; }
{kind = TOKEN_IDENTIFIER; ; index = 430 ; length = 6 line = 20 ; column = 9 ; value ='float2'; }
{kind = TOKEN_ASSIGN; ; index = 437 ; length = 1 line = 20 ; column = 16 ; value ='='; }
{kind = TOKEN_IDENTIFIER; ; index = 439 ; length = 8 line = 20 ; column = 18 ; value ='rect_pos'; }
{kind = TOKEN_SEMICOLON; ; index = 447 ; length = 1 line = 20 ; column = 26 ; value =';'; }
{kind = TOKEN_IDENTIFIER; ; index = 451 ; length = 9 line = 21 ; column = 0 ; value ='half_size'; }
{kind = TOKEN_COLON; ; index = 462 ; length = 1 line = 21 ; column = 11 ; value =':'; }
{kind = TOKEN_IDENTIFIER; ; index = 464 ; length = 6 line = 21 ; column = 13 ; value ='float2'; }
{kind = TOKEN_ASSIGN; ; index = 471 ; length = 1 line = 21 ; column = 20 ; value ='='; }
{kind = TOKEN_IDENTIFIER; ; index = 473 ; length = 6 line = 21 ; column = 22 ; value ='float2'; }
{kind = TOKEN_LEFTPAREN; ; index = 479 ; length = 1 line = 21 ; column = 28 ; value ='('; }
{kind = TOKEN_IDENTIFIER; ; index = 480 ; length = 5 line = 21 ; column = 29 ; value ='scale'; }
{kind = TOKEN_DOT; ; index = 485 ; length = 1 line = 21 ; column = 34 ; value ='.'; }
{kind = TOKEN_IDENTIFIER; ; index = 486 ; length = 1 line = 21 ; column = 35 ; value ='x'; }
{kind = TOKEN_SLASH; ; index = 488 ; length = 1 line = 21 ; column = 37 ; value ='/'; }
{kind = TOKEN_INTLITERAL; ; index = 490 ; length = 1 line = 21 ; column = 39 ; value ='2'; }
{kind = TOKEN_COMMA; ; index = 491 ; length = 1 line = 21 ; column = 40 ; value =','; }
{kind = TOKEN_IDENTIFIER; ; index = 493 ; length = 5 line = 21 ; column = 42 ; value ='scale'; }
{kind = TOKEN_DOT; ; index = 498 ; length = 1 line = 21 ; column = 47 ; value ='.'; }
{kind = TOKEN_IDENTIFIER; ; index = 499 ; length = 1 line = 21 ; column = 48 ; value ='y'; }
{kind = TOKEN_SLASH; ; index = 501 ; length = 1 line = 21 ; column = 50 ; value ='/'; }
{kind = TOKEN_INTLITERAL; ; index = 503 ; length = 1 line = 21 ; column = 52 ; value ='2'; }
{kind = TOKEN_RIGHTPAREN; ; index = 504 ; length = 1 line = 21 ; column = 53 ; value =')'; }
{kind = TOKEN_SEMICOLON; ; index = 505 ; length = 1 line = 21 ; column = 54 ; value =';'; }
{kind = TOKEN_IDENTIFIER; ; index = 509 ; length = 7 line = 22 ; column = 0 ; value ='dst_pos'; }
{kind = TOKEN_COLON; ; index = 520 ; length = 1 line = 22 ; column = 11 ; value =':'; }
{kind = TOKEN_IDENTIFIER; ; index = 522 ; length = 6 line = 22 ; column = 13 ; value ='float4'; }
{kind = TOKEN_ASSIGN; ; index = 529 ; length = 1 line = 22 ; column = 20 ; value ='='; }
{kind = TOKEN_IDENTIFIER; ; index = 531 ; length = 6 line = 22 ; column = 22 ; value ='float4'; }
{kind = TOKEN_LEFTPAREN; ; index = 537 ; length = 1 line = 22 ; column = 28 ; value ='('; }
{kind = TOKEN_IDENTIFIER; ; index = 538 ; length = 3 line = 22 ; column = 29 ; value ='pos'; }
{kind = TOKEN_DOT; ; index = 541 ; length = 1 line = 22 ; column = 32 ; value ='.'; }
{kind = TOKEN_IDENTIFIER; ; index = 542 ; length = 1 line = 22 ; column = 33 ; value ='x'; }
{kind = TOKEN_STAR; ; index = 544 ; length = 1 line = 22 ; column = 35 ; value ='*'; }
{kind = TOKEN_IDENTIFIER; ; index = 546 ; length = 9 line = 22 ; column = 37 ; value ='half_size'; }
{kind = TOKEN_DOT; ; index = 555 ; length = 1 line = 22 ; column = 46 ; value ='.'; }
{kind = TOKEN_IDENTIFIER; ; index = 556 ; length = 1 line = 22 ; column = 47 ; value ='x'; }
{kind = TOKEN_PLUS; ; index = 558 ; length = 1 line = 22 ; column = 49 ; value ='+'; }
{kind = TOKEN_IDENTIFIER; ; index = 560 ; length = 6 line = 22 ; column = 51 ; value ='center'; }
{kind = TOKEN_DOT; ; index = 566 ; length = 1 line = 22 ; column = 57 ; value ='.'; }
{kind = TOKEN_IDENTIFIER; ; index = 567 ; length = 1 line = 22 ; column = 58 ; value ='x'; }
{kind = TOKEN_COMMA; ; index = 568 ; length = 1 line = 22 ; column = 59 ; value =','; }
{kind = TOKEN_IDENTIFIER; ; index = 570 ; length = 3 line = 22 ; column = 61 ; value ='pos'; }
{kind = TOKEN_DOT; ; index = 573 ; length = 1 line = 22 ; column = 64 ; value ='.'; }
{kind = TOKEN_IDENTIFIER; ; index = 574 ; length = 1 line = 22 ; column = 65 ; value ='y'; }
{kind = TOKEN_STAR; ; index = 576 ; length = 1 line = 22 ; column = 67 ; value ='*'; }
{kind = TOKEN_IDENTIFIER; ; index = 578 ; length = 9 line = 22 ; column = 69 ; value ='half_size'; }
{kind = TOKEN_DOT; ; index = 587 ; length = 1 line = 22 ; column = 78 ; value ='.'; }
{kind = TOKEN_IDENTIFIER; ; index = 588 ; length = 1 line = 22 ; column = 79 ; value ='y'; }
{kind = TOKEN_PLUS; ; index = 590 ; length = 1 line = 22 ; column = 81 ; value ='+'; }
{kind = TOKEN_IDENTIFIER; ; index = 592 ; length = 6 line = 22 ; column = 83 ; value ='center'; }
{kind = TOKEN_DOT; ; index = 598 ; length = 1 line = 22 ; column = 89 ; value ='.'; }
{kind = TOKEN_IDENTIFIER; ; index = 599 ; length = 1 line = 22 ; column = 90 ; value ='y'; }
{kind = TOKEN_COMMA; ; index = 600 ; length = 1 line = 22 ; column = 91 ; value =','; }
{kind = TOKEN_FLOATLITERAL; ; index = 602 ; length = 3 line = 22 ; column = 93 ; value ='0'; }
{kind = TOKEN_COMMA; ; index = 605 ; length = 1 line = 22 ; column = 96 ; value =','; }
{kind = TOKEN_FLOATLITERAL; ; index = 607 ; length = 3 line = 22 ; column = 98 ; value ='1'; }
{kind = TOKEN_RIGHTPAREN; ; index = 610 ; length = 1 line = 22 ; column = 101 ; value =')'; }
{kind = TOKEN_SEMICOLON; ; index = 611 ; length = 1 line = 22 ; column = 102 ; value =';'; }
{kind = TOKEN_IDENTIFIER; ; index = 617 ; length = 6 line = 24 ; column = 0 ; value ='result'; }
{kind = TOKEN_COLON; ; index = 624 ; length = 1 line = 24 ; column = 7 ; value =':'; }
{kind = TOKEN_IDENTIFIER; ; index = 626 ; length = 8 line = 24 ; column = 9 ; value ='PS_Input'; }
{kind = TOKEN_SEMICOLON; ; index = 634 ; length = 1 line = 24 ; column = 17 ; value =';'; }
{kind = TOKEN_IDENTIFIER; ; index = 640 ; length = 6 line = 26 ; column = 0 ; value ='src_p0'; }
{kind = TOKEN_COLON; ; index = 647 ; length = 1 line = 26 ; column = 7 ; value =':'; }
{kind = TOKEN_IDENTIFIER; ; index = 649 ; length = 6 line = 26 ; column = 9 ; value ='float2'; }
{kind = TOKEN_ASSIGN; ; index = 656 ; length = 1 line = 26 ; column = 16 ; value ='='; }
{kind = TOKEN_IDENTIFIER; ; index = 658 ; length = 6 line = 26 ; column = 18 ; value ='float2'; }
{kind = TOKEN_LEFTPAREN; ; index = 664 ; length = 1 line = 26 ; column = 24 ; value ='('; }
{kind = TOKEN_FLOATLITERAL; ; index = 665 ; length = 3 line = 26 ; column = 25 ; value ='0'; }
{kind = TOKEN_COMMA; ; index = 668 ; length = 1 line = 26 ; column = 28 ; value =','; }
{kind = TOKEN_FLOATLITERAL; ; index = 670 ; length = 3 line = 26 ; column = 30 ; value ='1'; }
{kind = TOKEN_RIGHTPAREN; ; index = 673 ; length = 1 line = 26 ; column = 33 ; value =')'; }
{kind = TOKEN_SEMICOLON; ; index = 674 ; length = 1 line = 26 ; column = 34 ; value =';'; }
{kind = TOKEN_IDENTIFIER; ; index = 678 ; length = 6 line = 27 ; column = 0 ; value ='src_p1'; }
{kind = TOKEN_COLON; ; index = 685 ; length = 1 line = 27 ; column = 7 ; value =':'; }
{kind = TOKEN_IDENTIFIER; ; index = 687 ; length = 6 line = 27 ; column = 9 ; value ='float2'; }
{kind = TOKEN_ASSIGN; ; index = 694 ; length = 1 line = 27 ; column = 16 ; value ='='; }
{kind = TOKEN_IDENTIFIER; ; index = 696 ; length = 6 line = 27 ; column = 18 ; value ='float2'; }
{kind = TOKEN_LEFTPAREN; ; index = 702 ; length = 1 line = 27 ; column = 24 ; value ='('; }
{kind = TOKEN_FLOATLITERAL; ; index = 703 ; length = 3 line = 27 ; column = 25 ; value ='1'; }
{kind = TOKEN_COMMA; ; index = 706 ; length = 1 line = 27 ; column = 28 ; value =','; }
{kind = TOKEN_FLOATLITERAL; ; index = 708 ; length = 3 line = 27 ; column = 30 ; value ='0'; }
{kind = TOKEN_RIGHTPAREN; ; index = 711 ; length = 1 line = 27 ; column = 33 ; value =')'; }
{kind = TOKEN_SEMICOLON; ; index = 712 ; length = 1 line = 27 ; column = 34 ; value =';'; }
{kind = TOKEN_IDENTIFIER; ; index = 718 ; length = 13 line = 29 ; column = 0 ; value ='src_half_size'; }
{kind = TOKEN_COLON; ; index = 732 ; length = 1 line = 29 ; column = 14 ; value =':'; }
{kind = TOKEN_IDENTIFIER; ; index = 734 ; length = 6 line = 29 ; column = 16 ; value ='float2'; }
{kind = TOKEN_ASSIGN; ; index = 741 ; length = 1 line = 29 ; column = 23 ; value ='='; }
{kind = TOKEN_LEFTPAREN; ; index = 743 ; length = 1 line = 29 ; column = 25 ; value ='('; }
{kind = TOKEN_IDENTIFIER; ; index = 744 ; length = 6 line = 29 ; column = 26 ; value ='src_p1'; }
{kind = TOKEN_MINUS; ; index = 751 ; length = 1 line = 29 ; column = 33 ; value ='-'; }
{kind = TOKEN_IDENTIFIER; ; index = 753 ; length = 6 line = 29 ; column = 35 ; value ='src_p0'; }
{kind = TOKEN_RIGHTPAREN; ; index = 759 ; length = 1 line = 29 ; column = 41 ; value =')'; }
{kind = TOKEN_SLASH; ; index = 761 ; length = 1 line = 29 ; column = 43 ; value ='/'; }
{kind = TOKEN_INTLITERAL; ; index = 763 ; length = 1 line = 29 ; column = 45 ; value ='2'; }
{kind = TOKEN_SEMICOLON; ; index = 764 ; length = 1 line = 29 ; column = 46 ; value =';'; }
{kind = TOKEN_IDENTIFIER; ; index = 768 ; length = 10 line = 30 ; column = 0 ; value ='src_center'; }
{kind = TOKEN_COLON; ; index = 782 ; length = 1 line = 30 ; column = 14 ; value =':'; }
{kind = TOKEN_IDENTIFIER; ; index = 784 ; length = 6 line = 30 ; column = 16 ; value ='float2'; }
{kind = TOKEN_ASSIGN; ; index = 791 ; length = 1 line = 30 ; column = 23 ; value ='='; }
{kind = TOKEN_LEFTPAREN; ; index = 793 ; length = 1 line = 30 ; column = 25 ; value ='('; }
{kind = TOKEN_IDENTIFIER; ; index = 794 ; length = 6 line = 30 ; column = 26 ; value ='src_p1'; }
{kind = TOKEN_PLUS; ; index = 801 ; length = 1 line = 30 ; column = 33 ; value ='+'; }
{kind = TOKEN_IDENTIFIER; ; index = 803 ; length = 6 line = 30 ; column = 35 ; value ='src_p0'; }
{kind = TOKEN_RIGHTPAREN; ; index = 809 ; length = 1 line = 30 ; column = 41 ; value =')'; }
{kind = TOKEN_SLASH; ; index = 811 ; length = 1 line = 30 ; column = 43 ; value ='/'; }
{kind = TOKEN_INTLITERAL; ; index = 813 ; length = 1 line = 30 ; column = 45 ; value ='2'; }
{kind = TOKEN_SEMICOLON; ; index = 814 ; length = 1 line = 30 ; column = 46 ; value =';'; }
{kind = TOKEN_IDENTIFIER; ; index = 818 ; length = 7 line = 31 ; column = 0 ; value ='src_pos'; }
{kind = TOKEN_COLON; ; index = 832 ; length = 1 line = 31 ; column = 14 ; value =':'; }
{kind = TOKEN_IDENTIFIER; ; index = 834 ; length = 6 line = 31 ; column = 16 ; value ='float2'; }
{kind = TOKEN_ASSIGN; ; index = 841 ; length = 1 line = 31 ; column = 23 ; value ='='; }
{kind = TOKEN_IDENTIFIER; ; index = 843 ; length = 6 line = 31 ; column = 25 ; value ='float2'; }
{kind = TOKEN_LEFTPAREN; ; index = 849 ; length = 1 line = 31 ; column = 31 ; value ='('; }
{kind = TOKEN_IDENTIFIER; ; index = 850 ; length = 3 line = 31 ; column = 32 ; value ='pos'; }
{kind = TOKEN_DOT; ; index = 853 ; length = 1 line = 31 ; column = 35 ; value ='.'; }
{kind = TOKEN_IDENTIFIER; ; index = 854 ; length = 1 line = 31 ; column = 36 ; value ='x'; }
{kind = TOKEN_COMMA; ; index = 855 ; length = 1 line = 31 ; column = 37 ; value =','; }
{kind = TOKEN_IDENTIFIER; ; index = 857 ; length = 3 line = 31 ; column = 39 ; value ='pos'; }
{kind = TOKEN_DOT; ; index = 860 ; length = 1 line = 31 ; column = 42 ; value ='.'; }
{kind = TOKEN_IDENTIFIER; ; index = 861 ; length = 1 line = 31 ; column = 43 ; value ='y'; }
{kind = TOKEN_RIGHTPAREN; ; index = 862 ; length = 1 line = 31 ; column = 44 ; value =')'; }
{kind = TOKEN_STAR; ; index = 864 ; length = 1 line = 31 ; column = 46 ; value ='*'; }
{kind = TOKEN_IDENTIFIER; ; index = 866 ; length = 13 line = 31 ; column = 48 ; value ='src_half_size'; }
{kind = TOKEN_PLUS; ; index = 880 ; length = 1 line = 31 ; column = 62 ; value ='+'; }
{kind = TOKEN_IDENTIFIER; ; index = 882 ; length = 10 line = 31 ; column = 64 ; value ='src_center'; }
{kind = TOKEN_SEMICOLON; ; index = 892 ; length = 1 line = 31 ; column = 74 ; value =';'; }
{kind = TOKEN_IDENTIFIER; ; index = 898 ; length = 6 line = 33 ; column = 0 ; value ='result'; }
{kind = TOKEN_DOT; ; index = 904 ; length = 1 line = 33 ; column = 6 ; value ='.'; }
{kind = TOKEN_IDENTIFIER; ; index = 905 ; length = 2 line = 33 ; column = 7 ; value ='uv'; }
{kind = TOKEN_ASSIGN; ; index = 908 ; length = 1 line = 33 ; column = 10 ; value ='='; }
{kind = TOKEN_IDENTIFIER; ; index = 910 ; length = 6 line = 33 ; column = 12 ; value ='float2'; }
{kind = TOKEN_LEFTPAREN; ; index = 916 ; length = 1 line = 33 ; column = 18 ; value ='('; }
{kind = TOKEN_INTLITERAL; ; index = 917 ; length = 1 line = 33 ; column = 19 ; value ='1'; }
{kind = TOKEN_COMMA; ; index = 918 ; length = 1 line = 33 ; column = 20 ; value =','; }
{kind = TOKEN_INTLITERAL; ; index = 920 ; length = 1 line = 33 ; column = 22 ; value ='1'; }
{kind = TOKEN_RIGHTPAREN; ; index = 921 ; length = 1 line = 33 ; column = 23 ; value =')'; }
{kind = TOKEN_SEMICOLON; ; index = 922 ; length = 1 line = 33 ; column = 24 ; value =';'; }
{kind = TOKEN_IDENTIFIER; ; index = 926 ; length = 6 line = 34 ; column = 0 ; value ='result'; }
{kind = TOKEN_DOT; ; index = 932 ; length = 1 line = 34 ; column = 6 ; value ='.'; }
{kind = TOKEN_IDENTIFIER; ; index = 933 ; length = 3 line = 34 ; column = 7 ; value ='pos'; }
{kind = TOKEN_ASSIGN; ; index = 937 ; length = 1 line = 34 ; column = 11 ; value ='='; }
{kind = TOKEN_IDENTIFIER; ; index = 939 ; length = 6 line = 34 ; column = 13 ; value ='float4'; }
{kind = TOKEN_LEFTPAREN; ; index = 945 ; length = 1 line = 34 ; column = 19 ; value ='('; }
{kind = TOKEN_FLOATLITERAL; ; index = 946 ; length = 3 line = 34 ; column = 20 ; value ='2'; }
{kind = TOKEN_STAR; ; index = 950 ; length = 1 line = 34 ; column = 24 ; value ='*'; }
{kind = TOKEN_IDENTIFIER; ; index = 952 ; length = 7 line = 34 ; column = 26 ; value ='dst_pos'; }
{kind = TOKEN_DOT; ; index = 959 ; length = 1 line = 34 ; column = 33 ; value ='.'; }
{kind = TOKEN_IDENTIFIER; ; index = 960 ; length = 1 line = 34 ; column = 34 ; value ='x'; }
{kind = TOKEN_SLASH; ; index = 962 ; length = 1 line = 34 ; column = 36 ; value ='/'; }
{kind = TOKEN_IDENTIFIER; ; index = 964 ; length = 3 line = 34 ; column = 38 ; value ='res'; }
{kind = TOKEN_DOT; ; index = 967 ; length = 1 line = 34 ; column = 41 ; value ='.'; }
{kind = TOKEN_IDENTIFIER; ; index = 968 ; length = 1 line = 34 ; column = 42 ; value ='x'; }
{kind = TOKEN_MINUS; ; index = 970 ; length = 1 line = 34 ; column = 44 ; value ='-'; }
{kind = TOKEN_INTLITERAL; ; index = 972 ; length = 1 line = 34 ; column = 46 ; value ='1'; }
{kind = TOKEN_COMMA; ; index = 973 ; length = 1 line = 34 ; column = 47 ; value =','; }
{kind = TOKEN_FLOATLITERAL; ; index = 975 ; length = 3 line = 34 ; column = 49 ; value ='2'; }
{kind = TOKEN_STAR; ; index = 979 ; length = 1 line = 34 ; column = 53 ; value ='*'; }
{kind = TOKEN_IDENTIFIER; ; index = 981 ; length = 7 line = 34 ; column = 55 ; value ='dst_pos'; }
{kind = TOKEN_DOT; ; index = 988 ; length = 1 line = 34 ; column = 62 ; value ='.'; }
{kind = TOKEN_IDENTIFIER; ; index = 989 ; length = 1 line = 34 ; column = 63 ; value ='y'; }
{kind = TOKEN_SLASH; ; index = 991 ; length = 1 line = 34 ; column = 65 ; value ='/'; }
{kind = TOKEN_IDENTIFIER; ; index = 993 ; length = 3 line = 34 ; column = 67 ; value ='res'; }
{kind = TOKEN_DOT; ; index = 996 ; length = 1 line = 34 ; column = 70 ; value ='.'; }
{kind = TOKEN_IDENTIFIER; ; index = 997 ; length = 1 line = 34 ; column = 71 ; value ='y'; }
{kind = TOKEN_MINUS; ; index = 999 ; length = 1 line = 34 ; column = 73 ; value ='-'; }
{kind = TOKEN_INTLITERAL; ; index = 1001 ; length = 1 line = 34 ; column = 75 ; value ='1'; }
{kind = TOKEN_COMMA; ; index = 1002 ; length = 1 line = 34 ; column = 76 ; value =','; }
{kind = TOKEN_FLOATLITERAL; ; index = 1004 ; length = 3 line = 34 ; column = 78 ; value ='0'; }
{kind = TOKEN_COMMA; ; index = 1007 ; length = 1 line = 34 ; column = 81 ; value =','; }
{kind = TOKEN_FLOATLITERAL; ; index = 1009 ; length = 3 line = 34 ; column = 83 ; value ='1'; }
{kind = TOKEN_RIGHTPAREN; ; index = 1012 ; length = 1 line = 34 ; column = 86 ; value =')'; }
{kind = TOKEN_SEMICOLON; ; index = 1013 ; length = 1 line = 34 ; column = 87 ; value =';'; }
{kind = TOKEN_RETURN; ; index = 1019 ; length = 6 line = 36 ; column = 0 ; value ='return'; }
{kind = TOKEN_IDENTIFIER; ; index = 1026 ; length = 6 line = 36 ; column = 7 ; value ='result'; }
{kind = TOKEN_SEMICOLON; ; index = 1032 ; length = 1 line = 36 ; column = 13 ; value =';'; }
{kind = TOKEN_RIGHTBRACE; ; index = 1035 ; length = 1 line = 37 ; column = 0 ; value ='}'; }
{kind = TOKEN_PIXEL; ; index = 1040 ; length = 5 line = 39 ; column = 0 ; value ='pixel'; }
{kind = TOKEN_IDENTIFIER; ; index = 1046 ; length = 4 line = 39 ; column = 6 ; value ='main'; }
{kind = TOKEN_DOUBLECOLON; ; index = 1051 ; length = 2 line = 39 ; column = 11 ; value ='::'; }
{kind = TOKEN_LEFTPAREN; ; index = 1054 ; length = 1 line = 39 ; column = 14 ; value ='('; }
{kind = TOKEN_IDENTIFIER; ; index = 1055 ; length = 5 line = 39 ; column = 15 ; value ='input'; }
{kind = TOKEN_COLON; ; index = 1061 ; length = 1 line = 39 ; column = 21 ; value =':'; }
{kind = TOKEN_IDENTIFIER; ; index = 1063 ; length = 8 line = 39 ; column = 23 ; value ='PS_Input'; }
{kind = TOKEN_RIGHTPAREN; ; index = 1071 ; length = 1 line = 39 ; column = 31 ; value =')'; }
{kind = TOKEN_ARROW; ; index = 1073 ; length = 2 line = 39 ; column = 33 ; value ='->'; }
{kind = TOKEN_IDENTIFIER; ; index = 1076 ; length = 6 line = 39 ; column = 36 ; value ='float4'; }
{kind = TOKEN_AT; ; index = 1083 ; length = 1 line = 39 ; column = 43 ; value ='@'; }
{kind = TOKEN_IDENTIFIER; ; index = 1084 ; length = 7 line = 39 ; column = 44 ; value ='target0'; }
{kind = TOKEN_LEFTBRACE; ; index = 1092 ; length = 1 line = 39 ; column = 52 ; value ='{'; }
{kind = TOKEN_IDENTIFIER; ; index = 1096 ; length = 5 line = 40 ; column = 0 ; value ='color'; }
{kind = TOKEN_COLON; ; index = 1102 ; length = 1 line = 40 ; column = 6 ; value =':'; }
{kind = TOKEN_IDENTIFIER; ; index = 1104 ; length = 6 line = 40 ; column = 8 ; value ='float4'; }
{kind = TOKEN_ASSIGN; ; index = 1111 ; length = 1 line = 40 ; column = 15 ; value ='='; }
{kind = TOKEN_IDENTIFIER; ; index = 1113 ; length = 1 line = 40 ; column = 17 ; value ='p'; }
{kind = TOKEN_DOT; ; index = 1114 ; length = 1 line = 40 ; column = 18 ; value ='.'; }
{kind = TOKEN_IDENTIFIER; ; index = 1115 ; length = 5 line = 40 ; column = 19 ; value ='color'; }
{kind = TOKEN_SEMICOLON; ; index = 1120 ; length = 1 line = 40 ; column = 24 ; value =';'; }
{kind = TOKEN_RETURN; ; index = 1124 ; length = 6 line = 41 ; column = 0 ; value ='return'; }
{kind = TOKEN_IDENTIFIER; ; index = 1131 ; length = 5 line = 41 ; column = 7 ; value ='color'; }
{kind = TOKEN_SEMICOLON; ; index = 1136 ; length = 1 line = 41 ; column = 12 ; value =';'; }
{kind = TOKEN_RIGHTBRACE; ; index = 1139 ; length = 1 line = 42 ; column = 0 ; value ='}'; }
{kind = TOKEN_EOF; ; index = 1142 ; length = 0 line = 43 ; column = 0 ; value =''; }

BIN
test/lex/load_test.golden Normal file

Binary file not shown.

View File

@@ -1,5 +1,6 @@
test/assign_arithmetic_expression.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/else_if_after_else.ink lex
@@ -10,6 +11,9 @@ 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
@@ -18,6 +22,7 @@ test/function_with_int_return.ink lex
test/if_cond_assign.ink lex
test/if_if_if.ink lex
test/inferred_types.ink lex
test/large_block.ink lex
test/meta_block.ink lex
test/multiple_functions.ink lex
test/multiple_semicolons_everywhere.ink lex

5
test/load_test.ink Normal file
View File

@@ -0,0 +1,5 @@
#load "some_file.ink";
vertex main :: () {
v2 : float2 = float2(2.0, 2.0);
}

View File

@@ -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)))

View File

@@ -0,0 +1,6 @@
(program
(fun vertex vs_main
[]
(:= x 0)
(for i : 0..10
(+= x 1))))

View File

@@ -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;
^^^


View File

@@ -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;
^^^


View File

@@ -1,4 +1,4 @@
test/if_if_if.ink:2,3: error: Expected expression after 'if'.
test/if_if_if.ink:2,0: error: Expected expression after 'if'. Expected if condition.
if if if 0 > 100 {
^^


View File

@@ -0,0 +1,35 @@
(program
(properties p
[(:= 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)))

View File

@@ -1,5 +1,6 @@
test/assign_arithmetic_expression.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/else_if_after_else.ink parse
@@ -10,6 +11,9 @@ 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
@@ -18,6 +22,7 @@ test/function_with_int_return.ink parse
test/if_cond_assign.ink parse
test/if_if_if.ink parse
test/inferred_types.ink parse
test/large_block.ink parse
test/meta_block.ink parse
test/multiple_functions.ink parse
test/multiple_semicolons_everywhere.ink parse

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,4 +1,23 @@
test/wrong_multiply.ink:4,34: error: Type mismatch. Expected float got float2
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); (test/wrong_multiply.ink:0)
 float4 :: (float2, float2); (test/wrong_multiply.ink:0)
 float4 :: (float2, float, float); (test/wrong_multiply.ink:0)
 float4 :: (float, float2, float); (test/wrong_multiply.ink:0)
 float4 :: (float, float, float2); (test/wrong_multiply.ink:0)
 float4 :: (float, float3); (test/wrong_multiply.ink:0)
 float4 :: (float3, float); (test/wrong_multiply.ink:0)
 float4 :: (float4); (test/wrong_multiply.ink:0)
 float4 :: (float); (test/wrong_multiply.ink:0)
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);
^
@@ -6,6 +25,6 @@
float
got:
res : float2 = float2(2.0, 2.0)
result : float4 = float4(1.0, foo * res, 0.0, 1.0);


View File

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

View File

@@ -1,12 +1,13 @@
test/assign_arithmetic_expression.ink semant
test/basic_property_and_return_value.ink semant
test/builtin_types.ink semant
test/complicated_computation.ink semant
test/constant_buffer.ink semant
test/empty_struct.ink semant
test/empty_vertex_main.ink semant
test/empty_vertex_main_with_position_parameter.ink semant
test/field_assignment.ink semant
test/for_i_loop.ink semant
test/function_call.ink semant
test/function_call_out_of_order_declaration.ink semant
test/function_call_return.ink semant