diff --git a/Check.jai b/Check.jai index a5ded95..4b1d90a 100644 --- a/Check.jai +++ b/Check.jai @@ -1094,16 +1094,16 @@ declare_buffer :: (checker : *Checker, node : *AST_Node) -> Type_Variable_Handle return 0; } - buffer_struct_name := sprint("%_buffer_substruct___%", random_get(), node.name); + 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; + variable.element_type = declare_struct(checker, node, buffer_struct_name); + variable.resource_index = checker.current_texture_index; element := from_handle(checker, variable.element_type); scope := get_scope(checker, element.scope); scope.builtin = true; variable.scope = element.scope; - checker.current_buffer_index += 1; + checker.current_texture_index += 1; node.type_variable = handle; diff --git a/Codegen.jai b/Codegen.jai index 6e9d867..6fa1060 100644 --- a/Codegen.jai +++ b/Codegen.jai @@ -526,8 +526,13 @@ emit_field_list :: (state : *Codegen_State, field_list : *AST_Node, indentation } } -emit_struct :: (state : *Codegen_State, node : *AST_Node, indentation : int) { - print_to_builder(*state.builder, "struct %", node.name); +emit_struct :: (state : *Codegen_State, node : *AST_Node, indentation : int, name : string = "") { + if name.count > 0 { + print_to_builder(*state.builder, "struct %", name); + } else { + print_to_builder(*state.builder, "struct %", node.name); + } + current_scope := state.current_scope; state.current_scope = from_handle(state.ctx.type_variables, node.type_variable).scope; @@ -571,10 +576,10 @@ 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); + emit_struct(state, node, indentation, element.typename); // print_to_builder(*state.builder, "struct %\n", element.name); - print_to_builder(*state.builder, "StructuredBuffer<%> %;\n\n", element.typename, variable.name); + print_to_builder(*state.builder, "StructuredBuffer<%> % : register(t%);\n\n", element.typename, variable.name, variable.resource_index); } diff --git a/Lexing.jai b/Lexing.jai index b4669e3..69c78cd 100644 --- a/Lexing.jai +++ b/Lexing.jai @@ -217,11 +217,11 @@ identifier_kind :: (using lexer : *Lexer) -> Token_Kind { identifier.count = length; if identifier == "bool" return .TOKEN_BOOL; - if identifier == "buffer" return .TOKEN_BUFFER; + if identifier == "Buffer" return .TOKEN_BUFFER; if identifier == "case" return .TOKEN_CASE; if identifier == "columnmajor" return .TOKEN_COLUMNMAJOR; if identifier == "const" return .TOKEN_CONST; - if identifier == "constant_buffer" return .TOKEN_CONSTANT_BUFFER; + if identifier == "Constant_Buffer" return .TOKEN_CONSTANT_BUFFER; if identifier == "continue" return .TOKEN_CONTINUE; if identifier == "default" return .TOKEN_DEFAULT; if identifier == "directive" return .TOKEN_DIRECTIVE; diff --git a/test/basic_property_and_return_value.ink b/test/basic_property_and_return_value.ink index bdafd0d..1473525 100644 --- a/test/basic_property_and_return_value.ink +++ b/test/basic_property_and_return_value.ink @@ -1,4 +1,4 @@ -properties :: constant_buffer @properties { +properties :: Constant_Buffer @properties { color : float4; } diff --git a/test/buffers.ink b/test/buffers.ink index 5686b6e..9cb608f 100644 --- a/test/buffers.ink +++ b/test/buffers.ink @@ -1,8 +1,8 @@ -property_buffer :: buffer { +property_buffer :: Buffer { color : float4; } -const_buffer :: constant_buffer { +const_buffer :: Constant_Buffer { color : float4; } diff --git a/test/constant_buffer.ink b/test/constant_buffer.ink index 20b2f0a..c243a69 100644 --- a/test/constant_buffer.ink +++ b/test/constant_buffer.ink @@ -1,4 +1,4 @@ -camera :: constant_buffer { +camera :: Constant_Buffer { projection : float4x4; view : float4x4; } diff --git a/test/double_access.ink b/test/double_access.ink index 13948cf..80d4dfb 100644 --- a/test/double_access.ink +++ b/test/double_access.ink @@ -1,4 +1,4 @@ -p :: constant_buffer { +p :: Constant_Buffer { v : float2; } diff --git a/test/large_block.ink b/test/large_block.ink index 98c0520..fd7530f 100644 --- a/test/large_block.ink +++ b/test/large_block.ink @@ -1,4 +1,4 @@ -p :: constant_buffer @properties { +p :: Constant_Buffer @properties { color : float4; rect_position : float2; rect_scale : float2; diff --git a/test/lex/basic_property_and_return_value.golden b/test/lex/basic_property_and_return_value.golden index f4e5d64..a0cfb9f 100644 --- a/test/lex/basic_property_and_return_value.golden +++ b/test/lex/basic_property_and_return_value.golden @@ -1,6 +1,6 @@ {kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 10 line = 1 ; column = 0 ; value ='properties'; } {kind = TOKEN_DOUBLECOLON; ; index = 11 ; length = 2 line = 1 ; column = 11 ; value ='::'; } -{kind = TOKEN_CONSTANT_BUFFER; ; index = 14 ; length = 15 line = 1 ; column = 14 ; value ='constant_buffer'; } +{kind = TOKEN_CONSTANT_BUFFER; ; index = 14 ; length = 15 line = 1 ; column = 14 ; value ='Constant_Buffer'; } {kind = TOKEN_AT; ; index = 30 ; length = 1 line = 1 ; column = 30 ; value ='@'; } {kind = TOKEN_IDENTIFIER; ; index = 31 ; length = 10 line = 1 ; column = 31 ; value ='properties'; } {kind = TOKEN_LEFTBRACE; ; index = 42 ; length = 1 line = 1 ; column = 42 ; value ='{'; } diff --git a/test/lex/constant_buffer.golden b/test/lex/constant_buffer.golden index 6be077a..52d6cd3 100644 --- a/test/lex/constant_buffer.golden +++ b/test/lex/constant_buffer.golden @@ -1,6 +1,6 @@ {kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 6 line = 1 ; column = 0 ; value ='camera'; } {kind = TOKEN_DOUBLECOLON; ; index = 7 ; length = 2 line = 1 ; column = 7 ; value ='::'; } -{kind = TOKEN_CONSTANT_BUFFER; ; index = 10 ; length = 15 line = 1 ; column = 10 ; value ='constant_buffer'; } +{kind = TOKEN_CONSTANT_BUFFER; ; index = 10 ; length = 15 line = 1 ; column = 10 ; value ='Constant_Buffer'; } {kind = TOKEN_LEFTBRACE; ; index = 26 ; length = 1 line = 1 ; column = 26 ; value ='{'; } {kind = TOKEN_IDENTIFIER; ; index = 30 ; length = 10 line = 2 ; column = 0 ; value ='projection'; } {kind = TOKEN_COLON; ; index = 41 ; length = 1 line = 2 ; column = 11 ; value =':'; } diff --git a/test/lex/double_access.golden b/test/lex/double_access.golden index 4e79e91..5be793d 100644 --- a/test/lex/double_access.golden +++ b/test/lex/double_access.golden @@ -1,6 +1,6 @@ {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_IDENTIFIER; ; 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 =':'; } diff --git a/test/lex/large_block.golden b/test/lex/large_block.golden index a9bfc7f..93bf2d8 100644 --- a/test/lex/large_block.golden +++ b/test/lex/large_block.golden @@ -1,6 +1,6 @@ {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_IDENTIFIER; ; index = 5 ; length = 15 line = 1 ; column = 5 ; value ='constant_buffer'; } {kind = TOKEN_AT; ; index = 21 ; length = 1 line = 1 ; column = 21 ; value ='@'; } {kind = TOKEN_IDENTIFIER; ; index = 22 ; length = 10 line = 1 ; column = 22 ; value ='properties'; } {kind = TOKEN_LEFTBRACE; ; index = 33 ; length = 1 line = 1 ; column = 33 ; value ='{'; }