From 93fe66fb8ef5c731b46a30a804f74b4bf3b133d7 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 4 Aug 2023 23:05:22 +0100 Subject: give M extra param for tracking alloc size; macros for allocation --- vm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'vm.c') diff --git a/vm.c b/vm.c index a9610d2..4933614 100644 --- a/vm.c +++ b/vm.c @@ -16,10 +16,12 @@ Chunk chunk_new() { .clen = 0, .ccap = 0, .c = NULL, }; } + + size_t chunk_wbc(Chunk *ch, uint8_t byte) { if (ch->blen == ch->bcap) { size_t newsz = (ch->bcap == 0 ? 8 : ch->bcap * 2); - ch->b = M(ch->b, newsz * sizeof(uint8_t)); + ch->b = RENEW_ARR(ch->b, uint8_t, ch->bcap, newsz); ch->bcap = newsz; } size_t ix = ch->blen; @@ -30,7 +32,7 @@ size_t chunk_wbc(Chunk *ch, uint8_t byte) { size_t chunk_wconst(Chunk *ch, Val v) { if (ch->clen == ch->ccap) { size_t newsz = (ch->ccap == 0 ? 8 : ch->ccap *2); - ch->c = M(ch->c, newsz * sizeof(Val)); + ch->c = RENEW_ARR(ch->c, Val, ch->ccap, newsz); ch->ccap = newsz; } size_t ix = ch->clen; -- cgit v1.2.3