The Squirrel interpreter. See http://www.squirrel-lang.org/

Dependents:   Squirrel

Committer:
jhnwkmn
Date:
Tue Dec 16 11:39:42 2014 +0000
Revision:
3:7268a3ceaffc
Parent:
0:97a4f8cc534c
Accepts \r as line terminator as well.

Who changed what in which revision?

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