From: Brendan Hansen Date: Sat, 20 Jun 2020 02:46:40 +0000 (-0500) Subject: Bugfix with scratch allocator X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=817333381dfca63564f9cd66083fe0badfe872e2;p=onyx.git Bugfix with scratch allocator --- diff --git a/include/bh.h b/include/bh.h index 85ad7699..063989c8 100644 --- a/include/bh.h +++ b/include/bh.h @@ -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 59fdd5b4..ea67fa4b 100755 Binary files a/onyx and b/onyx differ diff --git a/src/onyx.c b/src/onyx.c index 816a38a7..2a57a80e 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -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"); } diff --git a/src/onyxparser.c b/src/onyxparser.c index 9cdbda49..07cbfd1b 100644 --- a/src/onyxparser.c +++ b/src/onyxparser.c @@ -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);