From: Brendan Hansen Date: Sun, 9 May 2021 17:05:24 +0000 (-0500) Subject: bugfixes with unused locals X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=992245fe6a0ad9a9347d708681aae5b51e849420;p=onyx.git bugfixes with unused locals --- diff --git a/bin/onyx b/bin/onyx index f0437b20..8a4a22b5 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/docs/bugs b/docs/bugs index e46bbf5d..01468a4c 100644 --- a/docs/bugs +++ b/docs/bugs @@ -66,6 +66,11 @@ List of known bugs: [ ] :UnaryFieldAccessIsGross +[ ] Segfault when trying to immediately access type inferred array literal. + println( (.[ 1, 2, 3, 4, 5 ])[0] ); + +[ ] Why are character literals signed???? + List of things to change: [X] Currently, there is no way to use the initialized members of a structure without using a struct literal. There should be a initialize intrinsic procedure that takes a pointer to anything and initializes it. diff --git a/modules/immediate_mode/immediate_renderer.onyx b/modules/immediate_mode/immediate_renderer.onyx index 4d55eace..4fd88b2d 100644 --- a/modules/immediate_mode/immediate_renderer.onyx +++ b/modules/immediate_mode/immediate_renderer.onyx @@ -193,24 +193,34 @@ Immediate_Renderer :: struct { }, } - quad :: (use ir: ^Immediate_Renderer, position: Vector2, size: Vector2, color: Color4 = .{1,1,1}) { - push_vertex(ir, .{ position.x, position.y }, color); - push_vertex(ir, .{ position.x + size.x, position.y }); - push_vertex(ir, .{ position.x + size.x, position.y + size.y }); - - push_vertex(ir, .{ position.x, position.y }); - push_vertex(ir, .{ position.x + size.x, position.y + size.y }); - push_vertex(ir, .{ position.x, position.y + size.y }); + rect :: (use ir: ^Immediate_Renderer, position: Vector2, size: Vector2, color: Color4 = .{1,1,1}) { + if vertex_count >= verticies.count - 6 do ir->flush(); + + vertex_ptr := ^verticies[vertex_count]; + defer vertex_count += 6; + + vertex_ptr[0] = .{ .{ position.x, position.y }, color, .{ 0, 0 } }; + vertex_ptr[1] = .{ .{ position.x + size.x, position.y }, color, .{ 0, 0 } }; + vertex_ptr[2] = .{ .{ position.x + size.x, position.y + size.y }, color, .{ 0, 0 } }; + + vertex_ptr[3] = .{ .{ position.x, position.y }, color, .{ 0, 0 } }; + vertex_ptr[4] = .{ .{ position.x + size.x, position.y + size.y }, color, .{ 0, 0 } }; + vertex_ptr[5] = .{ .{ position.x, position.y + size.y }, color, .{ 0, 0 } }; } - textured_quad :: (use ir: ^Immediate_Renderer, position: Vector2, size: Vector2, texture_position: Vector2, texture_size: Vector2, color: Color4 = .{1,1,1}) { - push_vertex(ir, .{ position.x, position.y }, color, .{ texture_position.x, texture_position.y }); - push_vertex(ir, .{ position.x + size.x, position.y }, color, .{ texture_position.x + texture_size.x, texture_position.y }); - push_vertex(ir, .{ position.x + size.x, position.y + size.y }, color, .{ texture_position.x + texture_size.x, texture_position.y + texture_size.y }); + textured_rect :: (use ir: ^Immediate_Renderer, position: Vector2, size: Vector2, texture_position: Vector2, texture_size: Vector2, color: Color4 = .{1,1,1}) { + if vertex_count >= verticies.count - 6 do ir->flush(); + + vertex_ptr := ^verticies[vertex_count]; + defer vertex_count += 6; - push_vertex(ir, .{ position.x, position.y }, color, .{ texture_position.x, texture_position.y }); - push_vertex(ir, .{ position.x + size.x, position.y + size.y }, color, .{ texture_position.x + texture_size.x, texture_position.y + texture_size.y }); - push_vertex(ir, .{ position.x, position.y + size.y }, color, .{ texture_position.x, texture_position.y + texture_size.y }); + vertex_ptr[0] = .{ .{ position.x, position.y }, color, .{ texture_position.x, texture_position.y } }; + vertex_ptr[1] = .{ .{ position.x + size.x, position.y }, color, .{ texture_position.x + texture_size.x, texture_position.y } }; + vertex_ptr[2] = .{ .{ position.x + size.x, position.y + size.y }, color, .{ texture_position.x + texture_size.x, texture_position.y + texture_size.y } }; + + vertex_ptr[3] = .{ .{ position.x, position.y }, color, .{ texture_position.x, texture_position.y } }; + vertex_ptr[4] = .{ .{ position.x + size.x, position.y + size.y }, color, .{ texture_position.x + texture_size.x, texture_position.y + texture_size.y } }; + vertex_ptr[5] = .{ .{ position.x, position.y + size.y }, color, .{ texture_position.x, texture_position.y + texture_size.y } }; } // NOTE: Calling set_texture without a parameter will disable textured rendering. @@ -232,7 +242,12 @@ Immediate_Renderer :: struct { 0, 0, 0, 1 ]; - gl.uniformMatrix4(active_shader.view_uniform, true, projection_matrix); + gl.useProgram(simple_shader.program); + gl.uniformMatrix4(simple_shader.view_uniform, true, projection_matrix); + gl.useProgram(textured_shader.program); + gl.uniformMatrix4(textured_shader.view_uniform, true, projection_matrix); + + gl.useProgram(active_shader.program); } } @@ -259,12 +274,12 @@ vertex :: proc { (position: Vector2, color: Color4) { immediate_renderer->push_vertex(position, color); }, } -quad :: (position: Vector2, size: Vector2, color: Color4 = .{1,1,1}) { - immediate_renderer->quad(position, size, color); +rect :: (position: Vector2, size: Vector2, color: Color4 = .{1,1,1}) { + immediate_renderer->rect(position, size, color); } -textured_quad :: (position: Vector2, size: Vector2, texture_position: Vector2, texture_size: Vector2, color: Color4 = .{1,1,1}) { - immediate_renderer->textured_quad(position, size, texture_position, texture_size, color); +textured_rect :: (position: Vector2, size: Vector2, texture_position: Vector2, texture_size: Vector2, color: Color4 = .{1,1,1}) { + immediate_renderer->textured_rect(position, size, texture_position, texture_size, color); } flush :: () do immediate_renderer->flush(); diff --git a/src/onyxchecker.c b/src/onyxchecker.c index 6ec36c90..cbae99bd 100644 --- a/src/onyxchecker.c +++ b/src/onyxchecker.c @@ -962,6 +962,10 @@ CheckStatus check_unaryop(AstUnaryOp** punop) { CheckStatus check_struct_literal(AstStructLiteral* sl) { if (sl->type == NULL) { + // NOTE: This is used for automatically typed struct literals. If there is no provided + // type for the struct literal, assume that it is passes successfully. When it is used + // elsewhere, it will be added as an expression entity that will be processed once the + // stnode is filled out. if (sl->stnode == NULL) return Check_Success; if (!node_is_type((AstNode *) sl->stnode)) { @@ -1493,7 +1497,9 @@ CheckStatus check_statement(AstNode** pstmt) { // in a block in order to efficiently allocate enough space and registers // for them all. Now with LocalAllocator, this is no longer necessary. // Therefore, locals stay in the tree and need to be passed along. - case Ast_Kind_Local: return Check_Success; + case Ast_Kind_Local: + fill_in_type((AstTyped *) stmt); + return Check_Success; default: CHECK(expression, (AstTyped **) pstmt); diff --git a/src/onyxutils.c b/src/onyxutils.c index 92290fdd..49a10a9f 100644 --- a/src/onyxutils.c +++ b/src/onyxutils.c @@ -1341,6 +1341,21 @@ static AstNode* lookup_default_value_by_idx(AstNode* provider, i32 idx) { } } +static i32 maximum_argument_count(AstNode* provider) { + switch (provider->kind) { + case Ast_Kind_Struct_Literal: { + AstStructLiteral* sl = (AstStructLiteral *) provider; + assert(sl->type); + + return type_structlike_mem_count(sl->type); + } + } + + // NOTE: This returns int_max for anything other than struct literals because the + // bounds checking on the arguments will be done elsewhere. + return 0x7fffffff; +} + // NOTE: The values array can be partially filled out, and is the resulting array. // Returns if all the values were filled in. b32 fill_in_arguments(Arguments* args, AstNode* provider, char** err_msg) { @@ -1378,6 +1393,12 @@ b32 fill_in_arguments(Arguments* args, AstNode* provider, char** err_msg) { } } + i32 maximum_arguments = maximum_argument_count(provider); + if (bh_arr_length(args->values) > maximum_arguments) { + *err_msg = bh_aprintf(global_scratch_allocator, "Too many values provided. Expected at most %d.", maximum_arguments); + success = 0; + } + return success; }