2 Copyright (C) 2017 Keziah Wesley
4 You can redistribute and/or modify this file under the terms of the
5 GNU Affero General Public License as published by the Free Software
6 Foundation, either version 3 of the License, or (at your option) any
9 This file is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Affero General Public License for more details.
14 You should have received a copy of the GNU Affero General Public
15 License along with this file. If not, see
16 <http://www.gnu.org/licenses/>.
26 /// 0, or a "pointer" to an object allocated in the pool
27 typedef uint32_t pool_ptr;
28 /// 0, or a "pointer" to an object allocated in the heap
29 typedef int32_t heap_ptr;
31 typedef union pool_object pool_object;
32 typedef union object object;
34 extern char *vhp_base; // object
35 extern char *vhp; // object
37 pool_object *POOL_OBJECT (pool_ptr p);
39 // TODO make (heap_ptr)0 nullish
40 static inline object *
41 OBJECT_OF_HEAP_PTR (heap_ptr p)
44 return (object *) (vhp_base + (p << 4));
47 pool_ptr pool_alloc (uint32_t len);
49 static inline heap_ptr
50 HEAP_PTR_OF_OBJECT (object * p)
52 assert ((uintptr_t) p >= (uintptr_t) vhp_base);
53 heap_ptr h = (heap_ptr) ((uintptr_t) p - (uintptr_t) vhp_base);
57 static inline object *
58 heap_alloc (uint32_t len)
63 vhp += (len + DOPE_LEN) << 4;
67 // given a headerless array of objects of known size,
68 // copy it backwards into newly-allocated pool space
69 pool_ptr pool_copy_array_rev (const pool_object * objs, uint32_t len);
71 // given a headerless array of objects of known size,
72 // copy it backwards into a newly-allocated vector body
73 heap_ptr heap_copy_array_rev (const object * objs, uint32_t len);