2 # This file is Copyright 2003, 2006, 2007, 2009, 2010 Dean Hall.
4 # This file is part of the PyMite VM.
5 # The PyMite VM is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU GENERAL PUBLIC LICENSE Version 2.
8 # The PyMite VM is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 # A copy of the GNU GENERAL PUBLIC LICENSE Version 2
12 # is seen in the file COPYING in this directory.
29 * The threshold of heap.avail under which the interpreter will run the GC
30 * just before starting a native session.
32 #define HEAP_GC_NF_THRESHOLD (512)
36 #define DEBUG_PRINT_HEAP_AVAIL(s) \
37 do { uint16_t n; heap_getAvail(&n); printf(s "heap avail = %d\n", n); } \
40 #define DEBUG_PRINT_HEAP_AVAIL(s)
45 * Initializes the heap for use.
49 PmReturn_t
heap_init(void);
52 * Returns a free chunk from the heap.
54 * The chunk will be at least the requested size.
55 * The actual size can be found in the return chunk's od.od_size.
57 * @param requestedsize Requested size of the chunk in bytes.
58 * @param r_pchunk Addr of ptr to chunk (return).
61 PmReturn_t
heap_getChunk(uint16_t requestedsize
, uint8_t **r_pchunk
);
64 * Places the chunk back in the heap.
66 * @param ptr Pointer to object to free.
68 PmReturn_t
heap_freeChunk(pPmObj_t ptr
);
70 /** @return Return number of bytes available in the heap */
71 #if PM_HEAP_SIZE > 65535
80 * Runs the mark-sweep garbage collector
84 PmReturn_t
heap_gcRun(void);
87 * Enables (if true) or disables automatic garbage collection
89 * @param bool Value to enable or disable auto GC
92 PmReturn_t
heap_gcSetAuto(uint8_t auto_gc
);
97 * Pushes an object onto the temporary roots stack if there is room
98 * to protect the objects from a potential garbage collection
100 * @param pobj Object to push onto the roots stack
101 * @param r_objid By reference; ID to use when popping the object from the stack
103 void heap_gcPushTempRoot(pPmObj_t pobj
, uint8_t *r_objid
);
106 * Pops from the temporary roots stack all objects upto and including the one
107 * denoted by the given ID
109 * @param objid ID of object to pop
111 void heap_gcPopTempRoot(uint8_t objid
);
113 #endif /* __HEAP_H__ */