moved back to old acc
[vox.git] / src / core / state.hpp
bloba9d0be3832d7945dfd6b53eb40991025dfc9c6ec
2 #ifndef _VXSTATE_H_
3 #define _VXSTATE_H_
5 #include "utils.hpp"
6 #include "object.hpp"
8 struct VXStringObj;
9 struct VXTableObj;
10 //max number of character for a printed number
11 #define NUMBER_MAX_CHAR 50
13 struct VXStringObjTable
15 VXStringObjTable(VXSharedState*ss);
16 ~VXStringObjTable();
17 VXStringObj *Add(const char *,VXInteger len);
18 void Remove(VXStringObj *);
19 private:
20 void Resize(VXInteger size);
21 void AllocNodes(VXInteger size);
22 VXStringObj **_strings;
23 VXUnsignedInteger _numofslots;
24 VXUnsignedInteger _slotused;
25 VXSharedState *_sharedstate;
28 struct RefTable
30 struct RefNode
32 VXObject obj;
33 VXUnsignedInteger refs;
34 struct RefNode *next;
36 RefTable();
37 ~RefTable();
38 void AddRef(VXRawObj &obj);
39 bool Release(VXRawObj &obj);
40 VXUnsignedInteger GetRefCount(VXRawObj &obj);
41 #ifndef NO_GARBAGE_COLLECTOR
42 void Mark(VXCollectable **chain);
43 #endif
44 void Finalize();
45 private:
46 RefNode *Get(VXRawObj &obj,VXHash &mainpos,RefNode **prev,bool add);
47 RefNode *Add(VXHash mainpos,VXRawObj &obj);
48 void Resize(VXUnsignedInteger size);
49 void AllocNodes(VXUnsignedInteger size);
50 VXUnsignedInteger _numofslots;
51 VXUnsignedInteger _slotused;
52 RefNode *_nodes;
53 RefNode *_freelist;
54 RefNode **_buckets;
57 #define ADD_STRING(ss,str,len) ss->_stringtable->Add(str,len)
58 #define REMOVE_STRING(ss,bstr) ss->_stringtable->Remove(bstr)
60 struct VXObject;
62 struct VXSharedState
64 VXSharedState();
65 ~VXSharedState();
66 void Init();
67 public:
68 char* GetScratchPad(VXInteger size);
69 VXInteger GetMetaMethodIdxByName(const VXObject &name);
70 #ifndef NO_GARBAGE_COLLECTOR
71 VXInteger CollectGarbage(VXState *vm);
72 void RunMark(VXState *vm,VXCollectable **tchain);
73 VXInteger ResurrectUnreachable(VXState *vm);
74 static void MarkObject(VXObject &o,VXCollectable **chain);
75 #endif
76 VXObjectVec *_metamethods;
77 VXObject _metamethodsmap;
78 VXObjectVec *_systemstrings;
79 VXObjectVec *_types;
80 VXStringObjTable *_stringtable;
81 RefTable _refs_table;
82 VXObject _registry;
83 VXObject _consts;
84 VXObject _constructoridx;
85 #ifndef NO_GARBAGE_COLLECTOR
86 VXCollectable *_gc_chain;
87 #endif
88 VXObject _root_vm;
89 VXObject _table_default_delegate;
90 static VXRegFunction _table_default_delegate_funcz[];
91 VXObject _array_default_delegate;
92 static VXRegFunction _array_default_delegate_funcz[];
93 VXObject _string_default_delegate;
94 static VXRegFunction _string_default_delegate_funcz[];
95 VXObject _number_default_delegate;
96 static VXRegFunction _number_default_delegate_funcz[];
97 VXObject _generator_default_delegate;
98 static VXRegFunction _generator_default_delegate_funcz[];
99 VXObject _closure_default_delegate;
100 static VXRegFunction _closure_default_delegate_funcz[];
101 VXObject _thread_default_delegate;
102 static VXRegFunction _thread_default_delegate_funcz[];
103 VXObject _class_default_delegate;
104 static VXRegFunction _class_default_delegate_funcz[];
105 VXObject _instance_default_delegate;
106 static VXRegFunction _instance_default_delegate_funcz[];
107 VXObject _weakref_default_delegate;
108 static VXRegFunction _weakref_default_delegate_funcz[];
110 VXCompileError _compilererrorhandler;
111 VXPrintFunction _printfunc;
112 VXPrintFunction _errorfunc;
113 bool _debuginfo;
114 bool _notifyallexceptions;
115 private:
116 char *_scratchpad;
117 VXInteger _scratchpadsize;
120 #define _table_ddel _table(_sharedstate->_table_default_delegate)
121 #define _array_ddel _table(_sharedstate->_array_default_delegate)
122 #define _string_ddel _table(_sharedstate->_string_default_delegate)
123 #define _number_ddel _table(_sharedstate->_number_default_delegate)
124 #define _generator_ddel _table(_sharedstate->_generator_default_delegate)
125 #define _closure_ddel _table(_sharedstate->_closure_default_delegate)
126 #define _thread_ddel _table(_sharedstate->_thread_default_delegate)
127 #define _class_ddel _table(_sharedstate->_class_default_delegate)
128 #define _instance_ddel _table(_sharedstate->_instance_default_delegate)
129 #define _weakref_ddel _table(_sharedstate->_weakref_default_delegate)
131 #define rsl(l) (l)
133 //extern VXObject _null_;
135 bool CompileTypemask(VXIntVec &res,const char *typemask);
136 #endif //_VXSTATE_H_