X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=src%2Falloc.c;h=ccd96913fbff18e8b8bbd2ee673086a9f692595f;hb=refs%2Fheads%2Fmaster;hp=24f102b2f7ca94585ea04154f81b015fcfcc74ad;hpb=6c1eef40f411ff4eec7a3f7599a81be7fae07e2a;p=muddle-interpreter.git diff --git a/src/alloc.c b/src/alloc.c index 24f102b..ccd9691 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 @@ -17,11 +17,15 @@ License along with this file. If not, see */ #include "alloc.h" +#include "atom.h" #include "object.h" extern pool_object *pool; extern pool_ptr ptop; +extern object *vhp_base; +extern heap_ptr vhp; + pool_ptr pool_alloc (uint32_t len) { @@ -38,6 +42,22 @@ POOL_OBJECT (pool_ptr p) return &pool[p]; } +pool_ptr +pool_copy_array (const pool_object * objs, uint32_t len) +{ + if (!len) + return 0; + pool_ptr p = pool_alloc (len); + for (int i = 0; i < len; i++) + { + pool[p + i] = (pool_object) + { + .type = objs[i].type,.rest = p + i + 1,.val = objs[i].val}; + } + pool[p + len - 1].rest = 0; + return p; +} + pool_ptr pool_copy_array_rev (const pool_object * objs, uint32_t len) { @@ -55,13 +75,45 @@ 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; +} + +uv_val * +UV_VAL (heap_ptr p) +{ + assert (p > 0); + return (uv_val *) & vhp_base[p]; +} + +atom_body * +ATOM_BODY (heap_ptr p) +{ + assert (p); + return (atom_body *) (&vhp_base[p]); }