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

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

lisp: implement LObject::Eval.

  • Property svn:keywords set to Id
File size: 1.2 KB
RevLine 
[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
7 *  domain software, no warranty is made or implied by Crack dot Com or
8 *  Jonathan Clark.
9 */
10
[481]11#include "stack.h"
[2]12#ifndef __LISP_GC_HPP_
13#define __LISP_GC_HPP_
14
15extern grow_stack<void> l_user_stack;       // stack user progs can push data and have it GCed
16
17void collect_space(int which_space); // should be tmp or permenant
18
19void register_pointer(void *&addr);
20void unregister_pointer(void *&addr);
21
[491]22// This pointer reference stack lists all pointers to temporary lisp
23// objects. This allows the pointers to be automatically modified if an
24// object allocation triggers a garbage collection.
25class PtrRef
26{
27public:
28    template<typename T> inline PtrRef(T *&ref)
29    {
30        stack.push((void **)&ref);
31    }
[2]32
[496]33    template<typename T> inline PtrRef(T * const &ref)
34    {
35        stack.push((void **)&ref);
36    }
37
[491]38    inline ~PtrRef()
39    {
40        stack.pop(1);
41    }
[2]42
[491]43    // stack of user pointers, user pointers get remapped on GC
44    static grow_stack<void *>stack;
45};
46
[2]47#endif
[491]48
Note: See TracBrowser for help on using the repository browser.