X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=src%2Falloc.h;h=89e1dab7c83e5a04385589b4f3539201d9681a14;hb=refs%2Fheads%2Fmaster;hp=4cab1d0313a5d44eb74306c4bb6fabd4c2956a7b;hpb=dc5745e090dab30f3aa606f3c2ab0b566046e4b9;p=muddle-interpreter.git diff --git a/src/alloc.h b/src/alloc.h index 4cab1d0..89e1dab 100644 --- a/src/alloc.h +++ b/src/alloc.h @@ -23,53 +23,31 @@ License along with this file. If not, see #include #include -/// 0, or a "pointer" to an object allocated in the pool typedef uint32_t pool_ptr; -/// 0, or a "pointer" to an object allocated in the heap typedef int32_t heap_ptr; typedef union pool_object pool_object; typedef union object object; - -extern char *vhp_base; // object -extern char *vhp; // object +typedef union uv_val uv_val; pool_object *POOL_OBJECT (pool_ptr p); - -// TODO make (heap_ptr)0 nullish -static inline object * -OBJECT_OF_HEAP_PTR (heap_ptr p) -{ - assert (p >= 0); - return (object *) (vhp_base + (p << 4)); -} +object *HEAP_OBJECT (heap_ptr p); +uv_val *UV_VAL (heap_ptr p); pool_ptr pool_alloc (uint32_t len); - -static inline heap_ptr -HEAP_PTR_OF_OBJECT (object * p) +heap_ptr heap_alloc (uint32_t len); +inline static heap_ptr +heap_alloc_uv (uint32_t len) { - assert ((uintptr_t) p >= (uintptr_t) vhp_base); - heap_ptr h = (heap_ptr) ((uintptr_t) p - (uintptr_t) vhp_base); - return h; -} - -static inline object * -heap_alloc (uint32_t len) -{ - enum - { DOPE_LEN = 1 }; - char *p = vhp; - vhp += (len + DOPE_LEN) << 4; - return (object *) p; + // divide by 2 (rounding up), then add one for dope + return heap_alloc (((len + 1) >> 1) + 1); } // given a headerless array of objects of known size, -// copy it backwards into newly-allocated pool space +// copy it into newly-allocated pool space +pool_ptr pool_copy_array (const pool_object * objs, uint32_t len); +// same as above, but backwards pool_ptr pool_copy_array_rev (const pool_object * objs, uint32_t len); - -// given a headerless array of objects of known size, -// copy it backwards into a newly-allocated vector body heap_ptr heap_copy_array_rev (const object * objs, uint32_t len); #endif // ALLOC_H