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

Last change on this file was 636, checked in by Sam Hocevar, 11 years ago

lisp: merge the Lisp and LispGC classes and improve coding style.

  • Property svn:keywords set to Id
File size: 1.1 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
18// This pointer reference stack lists all pointers to temporary lisp
19// objects. This allows the pointers to be automatically modified if an
20// object allocation triggers a garbage collection.
21class PtrRef
22{
23public:
24    template<typename T> inline PtrRef(T *&ref)
25    {
26        stack.push((void **)&ref);
27    }
28
29    template<typename T> inline PtrRef(T * const &ref)
30    {
31        stack.push((void **)&ref);
32    }
33
34    inline ~PtrRef()
35    {
36        stack.pop(1);
37    }
38
39    // Stack of user pointers, user pointers get remapped on GC
40    static GrowStack<void *> stack;
41};
42
43#endif
44
Note: See TracBrowser for help on using the repository browser.