X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=src%2Falloc.c;h=ad55630b7a0c8ddb75174c8d476a771b442c3ebe;hb=58a5ffdfec139a0c9d399f603b77a764ae8607f7;hp=24f102b2f7ca94585ea04154f81b015fcfcc74ad;hpb=6c1eef40f411ff4eec7a3f7599a81be7fae07e2a;p=muddle-interpreter.git diff --git a/src/alloc.c b/src/alloc.c index 24f102b..ad55630 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -1,5 +1,5 @@ /* -Copyright (C) 2017 Keziah Wesley +Copyright (C) 2017-2018 Keziah Wesley You can redistribute and/or modify this file under the terms of the GNU Affero General Public License as published by the Free Software @@ -22,6 +22,9 @@ License along with this file. If not, see extern pool_object *pool; extern pool_ptr ptop; +extern object *vhp_base; +extern heap_ptr vhp; + pool_ptr pool_alloc (uint32_t len) { @@ -55,13 +58,31 @@ pool_copy_array_rev (const pool_object * objs, uint32_t len) return p; } +object * +HEAP_OBJECT (heap_ptr p) +{ + assert (p > 0); + return &vhp_base[p]; +} + +heap_ptr +heap_alloc (uint32_t len) +{ + enum + { DOPE_LEN = 1 }; + heap_ptr p = vhp; + vhp += len + DOPE_LEN; + return p; +} + heap_ptr heap_copy_array_rev (const object * objs, uint32_t len) { - object *xs = heap_alloc (len); + heap_ptr p = heap_alloc (len); + object *xs = HEAP_OBJECT (p); for (int i = 0; i < (int) len; i++) { xs[i] = objs[len - 1 - (unsigned) i]; } - return HEAP_PTR_OF_OBJECT (xs); + return p; }