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