ScummVM API documentation
sqstate.h
1 /* see copyright notice in squirrel.h */
2 #ifndef _SQSTATE_H_
3 #define _SQSTATE_H_
4 
5 #include "squtils.h"
6 #include "sqobject.h"
7 struct SQString;
8 struct SQTable;
9 //max number of character for a printed number
10 #define NUMBER_MAX_CHAR 50
11 
13 {
15  ~SQStringTable();
16  SQString *Add(const SQChar *,SQInteger len);
17  void Remove(SQString *);
18 private:
19  void Resize(SQInteger size);
20  void AllocNodes(SQInteger size);
21  SQString **_strings;
22  SQUnsignedInteger _numofslots;
23  SQUnsignedInteger _slotused;
24  SQSharedState *_sharedstate;
25 };
26 
27 struct RefTable {
28  struct RefNode {
29  SQObjectPtr obj;
30  SQUnsignedInteger refs;
31  struct RefNode *next;
32  };
33  RefTable();
34  ~RefTable();
35  void AddRef(SQObject &obj);
36  SQBool Release(SQObject &obj);
37  SQUnsignedInteger GetRefCount(SQObject &obj);
38 #ifndef NO_GARBAGE_COLLECTOR
39  void Mark(SQCollectable **chain);
40 #endif
41  void Finalize();
42 private:
43  RefNode *Get(SQObject &obj,SQHash &mainpos,RefNode **prev,bool add);
44  RefNode *Add(SQHash mainpos,SQObject &obj);
45  void Resize(SQUnsignedInteger size);
46  void AllocNodes(SQUnsignedInteger size);
47  SQUnsignedInteger _numofslots;
48  SQUnsignedInteger _slotused;
49  RefNode *_nodes;
50  RefNode *_freelist;
51  RefNode **_buckets;
52 };
53 
54 #define ADD_STRING(ss,str,len) ss->_stringtable->Add(str,len)
55 #define REMOVE_STRING(ss,bstr) ss->_stringtable->Remove(bstr)
56 
57 struct SQObjectPtr;
58 
60 {
61  SQSharedState();
62  ~SQSharedState();
63  void Init();
64 public:
65  SQChar* GetScratchPad(SQInteger size);
66  SQInteger GetMetaMethodIdxByName(const SQObjectPtr &name);
67 #ifndef NO_GARBAGE_COLLECTOR
68  SQInteger CollectGarbage(SQVM *vm);
69  void RunMark(SQVM *vm,SQCollectable **tchain);
70  SQInteger ResurrectUnreachable(SQVM *vm);
71  static void MarkObject(SQObjectPtr &o,SQCollectable **chain);
72 #endif
73  SQObjectPtrVec *_metamethods;
74  SQObjectPtr _metamethodsmap;
75  SQObjectPtrVec *_systemstrings;
76  SQObjectPtrVec *_types;
77  SQStringTable *_stringtable;
78  RefTable _refs_table;
79  SQObjectPtr _registry;
80  SQObjectPtr _consts;
81  SQObjectPtr _constructoridx;
82 #ifndef NO_GARBAGE_COLLECTOR
83  SQCollectable *_gc_chain;
84 #endif
85  SQObjectPtr _root_vm;
86  SQObjectPtr _table_default_delegate;
87  static const SQRegFunction _table_default_delegate_funcz[];
88  SQObjectPtr _array_default_delegate;
89  static const SQRegFunction _array_default_delegate_funcz[];
90  SQObjectPtr _string_default_delegate;
91  static const SQRegFunction _string_default_delegate_funcz[];
92  SQObjectPtr _number_default_delegate;
93  static const SQRegFunction _number_default_delegate_funcz[];
94  SQObjectPtr _generator_default_delegate;
95  static const SQRegFunction _generator_default_delegate_funcz[];
96  SQObjectPtr _closure_default_delegate;
97  static const SQRegFunction _closure_default_delegate_funcz[];
98  SQObjectPtr _thread_default_delegate;
99  static const SQRegFunction _thread_default_delegate_funcz[];
100  SQObjectPtr _class_default_delegate;
101  static const SQRegFunction _class_default_delegate_funcz[];
102  SQObjectPtr _instance_default_delegate;
103  static const SQRegFunction _instance_default_delegate_funcz[];
104  SQObjectPtr _weakref_default_delegate;
105  static const SQRegFunction _weakref_default_delegate_funcz[];
106 
107  SQCOMPILERERROR _compilererrorhandler;
108  SQPRINTFUNCTION _printfunc;
109  SQPRINTFUNCTION _errorfunc;
110  bool _debuginfo;
111  bool _notifyallexceptions;
112  SQUserPointer _foreignptr;
113  SQRELEASEHOOK _releasehook;
114 private:
115  SQChar *_scratchpad;
116  SQInteger _scratchpadsize;
117 };
118 
119 #define _sp(s) (_sharedstate->GetScratchPad(s))
120 #define _spval (_sharedstate->GetScratchPad(-1))
121 
122 #define _table_ddel _table(_sharedstate->_table_default_delegate)
123 #define _array_ddel _table(_sharedstate->_array_default_delegate)
124 #define _string_ddel _table(_sharedstate->_string_default_delegate)
125 #define _number_ddel _table(_sharedstate->_number_default_delegate)
126 #define _generator_ddel _table(_sharedstate->_generator_default_delegate)
127 #define _closure_ddel _table(_sharedstate->_closure_default_delegate)
128 #define _thread_ddel _table(_sharedstate->_thread_default_delegate)
129 #define _class_ddel _table(_sharedstate->_class_default_delegate)
130 #define _instance_ddel _table(_sharedstate->_instance_default_delegate)
131 #define _weakref_ddel _table(_sharedstate->_weakref_default_delegate)
132 
133 bool CompileTypemask(SQIntVec &res,const SQChar *typemask);
134 
135 
136 #endif //_SQSTATE_H_
Definition: sqvm.h:33
Definition: sqtable.h:25
Definition: sqstate.h:28
Definition: sqstate.h:59
Definition: squirrel.h:153
Definition: sqstate.h:27
Definition: sqobject.h:205
Definition: squirrel.h:183
Definition: sqstring.h:14
Definition: sqobject.h:313
Definition: sqstate.h:12