1 | /* |
---|
2 | * Abuse - dark 2D side-scrolling platform game |
---|
3 | * Copyright (c) 1995 Crack dot Com |
---|
4 | * Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net> |
---|
5 | * |
---|
6 | * This software was released into the Public Domain. As with most public |
---|
7 | * domain software, no warranty is made or implied by Crack dot Com, by |
---|
8 | * Jonathan Clark, or by Sam Hocevar. |
---|
9 | */ |
---|
10 | |
---|
11 | #include "stack.h" |
---|
12 | #ifndef __LISP_GC_HPP_ |
---|
13 | #define __LISP_GC_HPP_ |
---|
14 | |
---|
15 | // Stack user progs can push data and have it GCed |
---|
16 | extern GrowStack<void> l_user_stack; |
---|
17 | |
---|
18 | class LispGC |
---|
19 | { |
---|
20 | public: |
---|
21 | // Collect temporary or permanent spaces |
---|
22 | static void CollectSpace(int which_space, int grow); |
---|
23 | |
---|
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 | }; |
---|
31 | |
---|
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 | } |
---|
42 | |
---|
43 | template<typename T> inline PtrRef(T * const &ref) |
---|
44 | { |
---|
45 | stack.push((void **)&ref); |
---|
46 | } |
---|
47 | |
---|
48 | inline ~PtrRef() |
---|
49 | { |
---|
50 | stack.pop(1); |
---|
51 | } |
---|
52 | |
---|
53 | // Stack of user pointers, user pointers get remapped on GC |
---|
54 | static GrowStack<void *> stack; |
---|
55 | }; |
---|
56 | |
---|
57 | #endif |
---|
58 | |
---|