~ubuntu-branches/ubuntu/hardy/codeblocks/hardy-backports

« back to all changes in this revision

Viewing changes to src/include/scripting/squirrel/sqclosure.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-07-17 04:39:23 UTC
  • Revision ID: james.westby@ubuntu.com-20080717043923-gmsy5cwkdjswghkm
Tags: upstream-8.02
ImportĀ upstreamĀ versionĀ 8.02

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*      see copyright notice in squirrel.h */
 
2
#ifndef _SQCLOSURE_H_
 
3
#define _SQCLOSURE_H_
 
4
 
 
5
struct SQFunctionProto;
 
6
 
 
7
struct SQClosure : public CHAINABLE_OBJ
 
8
{
 
9
private:
 
10
        SQClosure(SQSharedState *ss,SQFunctionProto *func){_function=func; INIT_CHAIN();ADD_TO_CHAIN(&_ss(this)->_gc_chain,this);}
 
11
public:
 
12
        static SQClosure *Create(SQSharedState *ss,SQFunctionProto *func){
 
13
                SQClosure *nc=(SQClosure*)SQ_MALLOC(sizeof(SQClosure));
 
14
                new (nc) SQClosure(ss,func);
 
15
                return nc;
 
16
        }
 
17
        void Release(){
 
18
                sq_delete(this,SQClosure);
 
19
        }
 
20
        SQClosure *Clone()
 
21
        {
 
22
                SQClosure * ret = SQClosure::Create(_opt_ss(this),_funcproto(_function));
 
23
                ret->_env = _env;
 
24
                ret->_outervalues.copy(_outervalues);
 
25
                return ret;
 
26
        }
 
27
        ~SQClosure()
 
28
        {
 
29
                REMOVE_FROM_CHAIN(&_ss(this)->_gc_chain,this);
 
30
        }
 
31
        bool Save(SQVM *v,SQUserPointer up,SQWRITEFUNC write);
 
32
        static bool Load(SQVM *v,SQUserPointer up,SQREADFUNC read,SQObjectPtr &ret);
 
33
#ifndef NO_GARBAGE_COLLECTOR
 
34
        void Mark(SQCollectable **chain);
 
35
        void Finalize(){_outervalues.resize(0); }
 
36
#endif
 
37
        SQObjectPtr _env;
 
38
        SQObjectPtr _function;
 
39
        SQObjectPtrVec _outervalues;
 
40
};
 
41
//////////////////////////////////////////////
 
42
struct SQGenerator : public CHAINABLE_OBJ 
 
43
{
 
44
        enum SQGeneratorState{eRunning,eSuspended,eDead};
 
45
private:
 
46
        SQGenerator(SQSharedState *ss,SQClosure *closure){_closure=closure;_state=eRunning;_ci._generator=_null_;INIT_CHAIN();ADD_TO_CHAIN(&_ss(this)->_gc_chain,this);}
 
47
public:
 
48
        static SQGenerator *Create(SQSharedState *ss,SQClosure *closure){
 
49
                SQGenerator *nc=(SQGenerator*)SQ_MALLOC(sizeof(SQGenerator));
 
50
                new (nc) SQGenerator(ss,closure);
 
51
                return nc;
 
52
        }
 
53
        ~SQGenerator()
 
54
        {
 
55
                REMOVE_FROM_CHAIN(&_ss(this)->_gc_chain,this);
 
56
        }
 
57
    void Kill(){
 
58
                _state=eDead;
 
59
                _stack.resize(0);
 
60
                _closure=_null_;}
 
61
        void Release(){
 
62
                sq_delete(this,SQGenerator);
 
63
        }
 
64
        bool Yield(SQVM *v);
 
65
        bool Resume(SQVM *v,SQInteger target);
 
66
#ifndef NO_GARBAGE_COLLECTOR
 
67
        void Mark(SQCollectable **chain);
 
68
        void Finalize(){_stack.resize(0);_closure=_null_;}
 
69
#endif
 
70
        SQObjectPtr _closure;
 
71
        SQObjectPtrVec _stack;
 
72
        SQObjectPtrVec _vargsstack;
 
73
        SQVM::CallInfo _ci;
 
74
        ExceptionsTraps _etraps;
 
75
        SQGeneratorState _state;
 
76
};
 
77
 
 
78
struct SQNativeClosure : public CHAINABLE_OBJ
 
79
{
 
80
private:
 
81
        SQNativeClosure(SQSharedState *ss,SQFUNCTION func){_function=func;INIT_CHAIN();ADD_TO_CHAIN(&_ss(this)->_gc_chain,this);        }
 
82
public:
 
83
        static SQNativeClosure *Create(SQSharedState *ss,SQFUNCTION func)
 
84
        {
 
85
                SQNativeClosure *nc=(SQNativeClosure*)SQ_MALLOC(sizeof(SQNativeClosure));
 
86
                new (nc) SQNativeClosure(ss,func);
 
87
                return nc;
 
88
        }
 
89
        SQNativeClosure *Clone()
 
90
        {
 
91
                SQNativeClosure * ret = SQNativeClosure::Create(_opt_ss(this),_function);
 
92
                ret->_env = _env;
 
93
                ret->_name = _name;
 
94
                ret->_outervalues.copy(_outervalues);
 
95
                ret->_typecheck = _typecheck;
 
96
                ret->_nparamscheck = _nparamscheck;
 
97
                return ret;
 
98
        }
 
99
        ~SQNativeClosure()
 
100
        {
 
101
                REMOVE_FROM_CHAIN(&_ss(this)->_gc_chain,this);
 
102
        }
 
103
        void Release(){
 
104
                sq_delete(this,SQNativeClosure);
 
105
        }
 
106
#ifndef NO_GARBAGE_COLLECTOR
 
107
        void Mark(SQCollectable **chain);
 
108
        void Finalize(){_outervalues.resize(0);}
 
109
#endif
 
110
        SQObjectPtr _env;
 
111
        SQFUNCTION _function;
 
112
        SQObjectPtr _name;
 
113
        SQObjectPtrVec _outervalues;
 
114
        SQIntVec _typecheck;
 
115
        SQInteger _nparamscheck;
 
116
};
 
117
 
 
118
 
 
119
 
 
120
#endif //_SQCLOSURE_H_