[56] | 1 | /* |
---|
| 2 | * Abuse - dark 2D side-scrolling platform game |
---|
| 3 | * Copyright (c) 1995 Crack dot Com |
---|
[494] | 4 | * Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net> |
---|
[56] | 5 | * |
---|
| 6 | * This software was released into the Public Domain. As with most public |
---|
[555] | 7 | * domain software, no warranty is made or implied by Crack dot Com, by |
---|
| 8 | * Jonathan Clark, or by Sam Hocevar. |
---|
[56] | 9 | */ |
---|
| 10 | |
---|
[481] | 11 | #include "stack.h" |
---|
[2] | 12 | #ifndef __LISP_GC_HPP_ |
---|
| 13 | #define __LISP_GC_HPP_ |
---|
| 14 | |
---|
[558] | 15 | // Stack user progs can push data and have it GCed |
---|
[561] | 16 | extern GrowStack<void> l_user_stack; |
---|
[2] | 17 | |
---|
[558] | 18 | class LispGC |
---|
| 19 | { |
---|
| 20 | public: |
---|
| 21 | // Collect temporary or permanent spaces |
---|
| 22 | static void CollectSpace(int which_space, int grow); |
---|
[2] | 23 | |
---|
[558] | 24 | private: |
---|
| 25 | static LArray *CollectArray(LArray *x); |
---|
| 26 | static LList *CollectList(LList *x); |
---|
| 27 | static LObject *CollectObject(LObject *x); |
---|
| 28 | static void CollectSymbols(LSymbol *root); |
---|
| 29 | static void CollectStacks(); |
---|
| 30 | }; |
---|
[2] | 31 | |
---|
[491] | 32 | // This pointer reference stack lists all pointers to temporary lisp |
---|
| 33 | // objects. This allows the pointers to be automatically modified if an |
---|
| 34 | // object allocation triggers a garbage collection. |
---|
| 35 | class PtrRef |
---|
| 36 | { |
---|
| 37 | public: |
---|
| 38 | template<typename T> inline PtrRef(T *&ref) |
---|
| 39 | { |
---|
| 40 | stack.push((void **)&ref); |
---|
| 41 | } |
---|
[2] | 42 | |
---|
[496] | 43 | template<typename T> inline PtrRef(T * const &ref) |
---|
| 44 | { |
---|
| 45 | stack.push((void **)&ref); |
---|
| 46 | } |
---|
| 47 | |
---|
[491] | 48 | inline ~PtrRef() |
---|
| 49 | { |
---|
| 50 | stack.pop(1); |
---|
| 51 | } |
---|
[2] | 52 | |
---|
[558] | 53 | // Stack of user pointers, user pointers get remapped on GC |
---|
[561] | 54 | static GrowStack<void *> stack; |
---|
[491] | 55 | }; |
---|
| 56 | |
---|
[2] | 57 | #endif |
---|
[491] | 58 | |
---|