Bugfix with scratch allocator
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 20 Jun 2020 02:46:40 +0000 (21:46 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 20 Jun 2020 02:46:40 +0000 (21:46 -0500)
include/bh.h
onyx
src/onyx.c
src/onyxparser.c

index 85ad76997beb0ffcbfac36b1e8809dfc654f74dd..063989c8f5a516715696b741095396ae12ec53f1 100644 (file)
@@ -924,10 +924,24 @@ BH_ALLOCATOR_PROC(bh_scratch_allocator_proc) {
                }
        } break;
 
-       case bh_allocator_action_free:
-       case bh_allocator_action_resize:
-               // Do nothing
-               break;
+       case bh_allocator_action_free: break;
+
+       case bh_allocator_action_resize: {
+               if (size > scratch->end - scratch->memory) {
+                       return NULL;
+               }
+
+               retval = scratch->curr;
+               scratch->curr += size;
+
+               if (scratch->curr >= scratch->end) {
+                       scratch->curr = scratch->memory;
+                       retval = scratch->curr;
+               }
+
+        // HACK!!!!!: Using size instead of some kind of "old size"
+        memcpy(retval, prev_memory, size);
+       } break;
        }
 
        return retval;
diff --git a/onyx b/onyx
index 59fdd5b4cc20fbbebe03806ed8025a447c2791a6..ea67fa4bbb97ca42a50fc2e210a29caab902b2cb 100755 (executable)
Binary files a/onyx and b/onyx differ
index 816a38a778008652879f76baf8d275e49038b713..2a57a80e3c912279ffaa6625137049f7e58b6346 100644 (file)
@@ -55,7 +55,7 @@ int main(int argc, char *argv[]) {
                onyx_message_print(&msgs);
                goto main_exit;
        } else {
-               // onyx_ast_print(program, 0);
+               onyx_ast_print(program, 0);
            bh_printf("\nNo errors.\n");
     }
 
index 9cdbda4964828198cc1a5b41fe39d36bfde15812..07cbfd1b2ac74fcbb68e2fb9f477ac7010fd1545 100644 (file)
@@ -341,7 +341,7 @@ static inline i32 get_precedence(OnyxAstNodeKind kind) {
 
 static OnyxAstNode* parse_expression(OnyxParser* parser) {
     bh_arr(OnyxAstNode*) tree_stack = NULL;
-    bh_arr_new(global_scratch_allocator, tree_stack, 4);
+    bh_arr_new(global_scratch_allocator, tree_stack, 1);
     bh_arr_set_length(tree_stack, 0);
 
        OnyxAstNode* left = parse_factor(parser);