bugfixes with unused locals
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 9 May 2021 17:05:24 +0000 (12:05 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 9 May 2021 17:05:24 +0000 (12:05 -0500)
bin/onyx
docs/bugs
modules/immediate_mode/immediate_renderer.onyx
src/onyxchecker.c
src/onyxutils.c

index f0437b204741cbb280418e68bc8cd3849a5e1527..8a4a22b5baa9e29efa78a617d8852f076d8da238 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index e46bbf5d793d1f089c63b5e7acbec19c2358bd99..01468a4c9b20b5239426e54d3f4aea6b0764dce5 100644 (file)
--- 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.
index 4d55eace300d8207d7f76e4a7ce0f87ed5fdc497..4fd88b2d3cb2b38033758d6d763139834af687a7 100644 (file)
@@ -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();
index 6ec36c90fa3fa4ec109991b81604822fe6b1ba98..cbae99bdea112d952617905108d06effe18b9da1 100644 (file)
@@ -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);
index 92290fdd79e4173ebc3494b11985fd6e83db2b52..49a10a9f96de8bc5c279cd9e2c4a11d88326b091 100644 (file)
@@ -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;
 }