Added spec:commit task to commit changes to spec/ruby sources.
[rbx.git] / shotgun / lib / heap.h
blob5e85bb81744d5fc8e5034c5583c3cbca79ee8ae8
1 #ifndef RBS_HEAP_H
2 #define RBS_HEAP_H
4 typedef void* address;
6 /*
7 address : lower heap bound address
8 curret : current tip of the heap
9 last : upper heap bound address
10 scan : GC scanner position
12 struct heap {
13 size_t size;
14 address address;
15 address current;
16 address last;
17 address scan;
20 typedef struct heap* rheap;
22 rheap heap_new(size_t size);
23 int heap_deallocate(rheap h);
24 int heap_allocate_memory(rheap h);
25 int heap_allocate_extended(rheap h);
26 int heap_reset(rheap h);
27 int heap_enough_fields_p(rheap h, int fields);
28 int heap_allocated_p(rheap h);
29 int heap_using_extended_p(rheap h);
30 OBJECT heap_copy_object(rheap h, OBJECT obj);
31 OBJECT heap_next_object(rheap h);
32 int heap_fully_scanned_p(rheap h);
33 OBJECT heap_next_unscanned(rheap h);
34 int heap_enough_fields_p(rheap h, int fields);
36 /* controls fast heap allocation using inline functions on and off */
37 #define FAST_HEAP 1
39 #ifdef FAST_HEAP
41 #include <string.h>
43 static inline address heap_allocate(rheap h, unsigned int size) {
44 address addr;
45 addr = (address)h->current;
46 memset((void*)addr, 0, size);
47 h->current = (address)((uintptr_t)h->current + size);
49 return addr;
52 #define heap_allocate_dirty(h, size) ({ \
53 address _a; _a = (address)h->current; h->current = (address)((uintptr_t)h->current + size); _a; })
55 #define heap_putback(h, size) (h->current = (address)((uintptr_t)h->current - size))
57 static inline unsigned int heap_enough_space_p(rheap h, unsigned int size) {
58 if((uintptr_t)h->current + size > (uintptr_t)h->last + 1) return FALSE;
59 return TRUE;
62 static inline unsigned int heap_contains_p(rheap h, address addr) {
64 if(addr < h->address) return FALSE;
65 if(addr >= (address)((uintptr_t)h->last)) return FALSE;
66 return TRUE;
70 #else
72 address heap_allocate(rheap h, unsigned int size);
73 unsigned int heap_enough_space_p(rheap h, unsigned int size);
75 #endif
77 #endif