A bunch of allocator stuff
This commit is contained in:
14
Parsing.jai
14
Parsing.jai
@@ -14,8 +14,12 @@ Parse_State :: struct {
|
|||||||
tokens : [..]Token;
|
tokens : [..]Token;
|
||||||
|
|
||||||
current_token_index : int;
|
current_token_index : int;
|
||||||
allocator : Allocator;
|
|
||||||
arena : Arena;
|
node_allocator : Allocator;
|
||||||
|
node_arena : Arena;
|
||||||
|
|
||||||
|
child_allocator : Allocator;
|
||||||
|
child_arena : Arena;
|
||||||
|
|
||||||
had_error : bool;
|
had_error : bool;
|
||||||
|
|
||||||
@@ -123,8 +127,9 @@ parse_rules :: #run -> [(cast(int)Token_Kind.TOKEN_ERROR) + 1]Parse_Rule {
|
|||||||
init_parse_state :: (parse_state : *Parse_State, tokens : [..]Token, path : string) {
|
init_parse_state :: (parse_state : *Parse_State, tokens : [..]Token, path : string) {
|
||||||
parse_state.tokens = tokens;
|
parse_state.tokens = tokens;
|
||||||
parse_state.path = path;
|
parse_state.path = path;
|
||||||
parse_state.allocator = make_arena(*parse_state.arena);
|
parse_state.node_allocator = make_arena(*parse_state.node_arena);
|
||||||
parse_state.result.nodes.allocator = parse_state.allocator;
|
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);
|
array_reserve(*parse_state.result.nodes, 4096);
|
||||||
parse_state.current_token_index = 0;
|
parse_state.current_token_index = 0;
|
||||||
}
|
}
|
||||||
@@ -275,6 +280,7 @@ make_node :: (parse_state : *Parse_State, kind : AST_Kind) -> *AST_Node {
|
|||||||
node : AST_Node;
|
node : AST_Node;
|
||||||
|
|
||||||
node.kind = kind;
|
node.kind = kind;
|
||||||
|
node.children.allocator = parse_state.child_allocator;
|
||||||
array_add(*parse_state.result.nodes, node);
|
array_add(*parse_state.result.nodes, node);
|
||||||
|
|
||||||
return *parse_state.result.nodes[parse_state.result.nodes.count - 1];
|
return *parse_state.result.nodes[parse_state.result.nodes.count - 1];
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ Type_Constraint :: struct {
|
|||||||
|
|
||||||
Scope_Stack :: struct {
|
Scope_Stack :: struct {
|
||||||
allocator : Allocator;
|
allocator : Allocator;
|
||||||
|
arena : Arena;
|
||||||
|
|
||||||
stack : [..]Scope;
|
stack : [..]Scope;
|
||||||
}
|
}
|
||||||
@@ -166,8 +167,10 @@ Scope :: struct {
|
|||||||
Scope_Handle :: #type, distinct u32;
|
Scope_Handle :: #type, distinct u32;
|
||||||
|
|
||||||
Semantic_Check_Result :: struct {
|
Semantic_Check_Result :: struct {
|
||||||
messages : [..]Compiler_Message;
|
messages : [..]Compiler_Message;
|
||||||
had_error : bool;
|
message_arena : Arena;
|
||||||
|
message_allocator : Allocator;
|
||||||
|
had_error : bool;
|
||||||
|
|
||||||
vertex_entry_point : *AST_Node;
|
vertex_entry_point : *AST_Node;
|
||||||
pixel_entry_point : *AST_Node;
|
pixel_entry_point : *AST_Node;
|
||||||
@@ -176,6 +179,8 @@ Semantic_Check_Result :: struct {
|
|||||||
|
|
||||||
scope_stack : Scope_Stack;
|
scope_stack : Scope_Stack;
|
||||||
type_variables : [..]Type_Variable;
|
type_variables : [..]Type_Variable;
|
||||||
|
type_var_arena : Arena;
|
||||||
|
type_var_allocator : Allocator;
|
||||||
|
|
||||||
property_name : string;
|
property_name : string;
|
||||||
}
|
}
|
||||||
@@ -600,7 +605,7 @@ record_error :: (checker : *Semantic_Checker, error_string : string, locations :
|
|||||||
error.message = error_string;
|
error.message = error_string;
|
||||||
|
|
||||||
checker.result.had_error = true;
|
checker.result.had_error = true;
|
||||||
array_add(*checker.result.messages, error);
|
array_add(*checker.result.messages, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
is_proper :: (var : Type_Variable) -> bool {
|
is_proper :: (var : Type_Variable) -> bool {
|
||||||
@@ -636,6 +641,8 @@ push_scope :: (checker : *Semantic_Checker, name := "", kind : Scope_Kind = .Glo
|
|||||||
scope.builtin = true;
|
scope.builtin = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scope.children.allocator = checker.result.scope_stack.allocator;
|
||||||
|
|
||||||
if checker.current_scope {
|
if checker.current_scope {
|
||||||
scope := get_current_scope(checker);
|
scope := get_current_scope(checker);
|
||||||
array_add(*scope.children, xx count);
|
array_add(*scope.children, xx count);
|
||||||
@@ -726,7 +733,10 @@ init_semantic_checker :: (checker : *Semantic_Checker, root : *AST_Node, path :
|
|||||||
checker.path = path;
|
checker.path = path;
|
||||||
|
|
||||||
// @Incomplete(niels): Use other allocator and/or add static array with convenience functions
|
// @Incomplete(niels): Use other allocator and/or add static array with convenience functions
|
||||||
|
checker.result.type_var_allocator = make_arena(*checker.result.type_var_arena);
|
||||||
array_reserve(*checker.result.type_variables, 2048);
|
array_reserve(*checker.result.type_variables, 2048);
|
||||||
|
|
||||||
|
checker.result.scope_stack.allocator = make_arena(*checker.result.scope_stack.arena);
|
||||||
array_reserve(*checker.result.scope_stack.stack, 256);
|
array_reserve(*checker.result.scope_stack.stack, 256);
|
||||||
|
|
||||||
global_scope, global_handle := push_scope(checker, kind = .Global);
|
global_scope, global_handle := push_scope(checker, kind = .Global);
|
||||||
@@ -1605,7 +1615,9 @@ types_compatible :: (checker : *Semantic_Checker, lhs : Type_Variable_Handle, rh
|
|||||||
for i : 0..lhs_struct_var.child_count - 1 {
|
for i : 0..lhs_struct_var.child_count - 1 {
|
||||||
lhs_child := lhs_struct_var.children[i];
|
lhs_child := lhs_struct_var.children[i];
|
||||||
rhs_child := rhs_struct_var.children[i];
|
rhs_child := rhs_struct_var.children[i];
|
||||||
if !types_compatible(checker, lhs_child, rhs_child) return false;
|
if !types_compatible(checker, lhs_child, rhs_child) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -1625,6 +1637,7 @@ union_terms :: (checker : *Semantic_Checker, lhs_handle : Type_Variable_Handle,
|
|||||||
lhs_var := h2tv(checker, lhs_handle);
|
lhs_var := h2tv(checker, lhs_handle);
|
||||||
rhs_var := h2tv(checker, rhs_handle);
|
rhs_var := h2tv(checker, rhs_handle);
|
||||||
|
|
||||||
|
print("% %\n", type_to_string(h2tv(checker, lhs_handle)), type_to_string(h2tv(checker, rhs_handle)));
|
||||||
if usage_site {
|
if usage_site {
|
||||||
type_mismatch(checker, usage_site, rhs_var.source_node.parent, rhs_handle, lhs_handle);
|
type_mismatch(checker, usage_site, rhs_var.source_node.parent, rhs_handle, lhs_handle);
|
||||||
} else {
|
} else {
|
||||||
@@ -1818,11 +1831,14 @@ type_to_string :: (type_variable : Type_Variable) -> string {
|
|||||||
return Typenames[type_variable.type];
|
return Typenames[type_variable.type];
|
||||||
}
|
}
|
||||||
case .Function; #through;
|
case .Function; #through;
|
||||||
case .Struct;
|
case .Struct; {
|
||||||
return type_variable.typename;
|
print("%\n", type_variable);
|
||||||
|
return type_variable.typename;
|
||||||
|
}
|
||||||
case .Array;
|
case .Array;
|
||||||
return "array";
|
return "array";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
42
test/large_block.shd
Normal file
42
test/large_block.shd
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
p :: properties {
|
||||||
|
color : float4;
|
||||||
|
rect_position : float2;
|
||||||
|
rect_scale : float2;
|
||||||
|
resolution : float2;
|
||||||
|
texture : Texture2D;
|
||||||
|
sampler : Sampler;
|
||||||
|
}
|
||||||
|
|
||||||
|
PS_Input :: struct {
|
||||||
|
uv : float2 @uv;
|
||||||
|
pos : float2 @pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
vertex main :: (pos : float4 @position) -> PS_Input {
|
||||||
|
res : float2 = p.resolution;
|
||||||
|
scale : float2 = p.rect_scale;
|
||||||
|
rect_pos : float2 = p.rect_position;;
|
||||||
|
|
||||||
|
center : float2 = rect_pos;
|
||||||
|
half_size : float2 = float2(scale.x / 2, scale.y / 2);
|
||||||
|
dst_pos : float4 = float4(pos.x * half_size.x + center.x, pos.y * half_size.y + center.y, 0.0, 1.0);
|
||||||
|
|
||||||
|
result : PS_Input;
|
||||||
|
|
||||||
|
src_p0 : float2 = float2(0.0, 1.0);
|
||||||
|
src_p1 : float2 = float2(1.0, 0.0);
|
||||||
|
|
||||||
|
src_half_size : float2 = (src_p1 - src_p0) / 2;
|
||||||
|
src_center : float2 = (src_p1 + src_p0) / 2;
|
||||||
|
src_pos : float2 = pos * src_half_size + src_center;
|
||||||
|
|
||||||
|
result.uv = float2(1, 1);
|
||||||
|
result.pos = float4(2.0 * dst_pos.x / res.x - 1, 2.0 * dst_pos.y / res.y - 1, 0.0, 1.0);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
pixel main :: (input : PS_Input) -> float4 @target0 {
|
||||||
|
color : float4 = p.color;
|
||||||
|
return color;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user