source: abuse/trunk/src/lisp/lisp_gc.h @ 635

Last change on this file since 635 was 635, checked in by Sam Hocevar, 10 years ago

lisp: refactor Lisp spaces so that they are real objects, and get rid
of the unused USER_SPACE.

  • Property svn:keywords set to Id
File size: 1.4 KB
Line 
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
16extern GrowStack<void> l_user_stack;
17
18class LispGC
19{
20public:
21    // Collect temporary or permanent spaces
22    static void CollectSpace(LSpace *which_space, int grow);
23
24private:
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.
35class PtrRef
36{
37public:
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
Note: See TracBrowser for help on using the repository browser.