this shouldn't be in svn
[supertux.git] / src / squirrel / squirrel / sqvm.h
index 7ba178c..569bd43 100644 (file)
@@ -13,14 +13,15 @@ void sq_base_register(HSQUIRRELVM v);
 \r
 struct SQExceptionTrap{\r
        SQExceptionTrap() {}\r
-       SQExceptionTrap(int ss, int stackbase,SQInstruction *ip, int ex_target){ _stacksize = ss; _stackbase = stackbase; _ip = ip; _extarget = ex_target;}\r
+       SQExceptionTrap(SQInteger ss, SQInteger stackbase,SQInstruction *ip, SQInteger ex_target){ _stacksize = ss; _stackbase = stackbase; _ip = ip; _extarget = ex_target;}\r
        SQExceptionTrap(const SQExceptionTrap &et) { (*this) = et;      }\r
-       int _stackbase;\r
-       int _stacksize;\r
+       SQInteger _stackbase;\r
+       SQInteger _stacksize;\r
        SQInstruction *_ip;\r
-       int _extarget;\r
+       SQInteger _extarget;\r
 };\r
 \r
+#define _INLINE \r
 \r
 #define STK(a) _stack._vals[_stackbase+(a)]\r
 #define TARGET _stack._vals[_stackbase+arg0]\r
@@ -31,55 +32,55 @@ struct SQVM : public CHAINABLE_OBJ
 {\r
        struct VarArgs {\r
                VarArgs() { size = 0; base = 0; }\r
-               int size;\r
-               int base;\r
+               SQInteger size;\r
+               SQInteger base;\r
        };\r
 \r
        struct CallInfo{\r
-               //CallInfo() {}\r
+               CallInfo() { _generator._type = OT_NULL;}\r
                //CallInfo(const CallInfo& ci) {  }\r
                SQInstructionVec *_iv;\r
                SQObjectPtrVec *_literals;\r
                SQObject _closure;\r
                SQObject _generator;\r
-               int _etraps;\r
-               int _prevstkbase;\r
-               int _prevtop;\r
-               int _target;\r
+               SQInteger _etraps;\r
+               SQInteger _prevstkbase;\r
+               SQInteger _prevtop;\r
+               SQInteger _target;\r
                SQInstruction *_ip;\r
-               int _ncalls;\r
-               bool _root;\r
+               SQInteger _ncalls;\r
+               SQBool _root;\r
                VarArgs _vargs;\r
        };\r
-\r
+       \r
 typedef sqvector<CallInfo> CallInfoVec;\r
 public:\r
        enum ExecutionType { ET_CALL, ET_RESUME_GENERATOR, ET_RESUME_VM };\r
        SQVM(SQSharedState *ss);\r
        ~SQVM();\r
-       bool Init(SQVM *friendvm, int stacksize);\r
-       bool Execute(SQObjectPtr &func, int target, int nargs, int stackbase, SQObjectPtr &outres, ExecutionType et = ET_CALL);\r
-       //start a native call return when the NATIVE closure returns(returns true if the vm has been suspended)\r
-       bool CallNative(SQNativeClosure *nclosure, int nargs, int stackbase, bool tailcall, SQObjectPtr &retval,bool &suspend);\r
-       //start a SQUIRREL call in the same "Execution loop"\r
-       bool StartCall(SQClosure *closure, int target, int nargs, int stackbase, bool tailcall);\r
-       bool CreateClassInstance(SQClass *theclass, int nargs, int stackbase, SQObjectPtr &retval);\r
+       bool Init(SQVM *friendvm, SQInteger stacksize);\r
+       bool Execute(SQObjectPtr &func, SQInteger target, SQInteger nargs, SQInteger stackbase, SQObjectPtr &outres, SQBool raiseerror, ExecutionType et = ET_CALL);\r
+       //starts a native call return when the NATIVE closure returns\r
+       bool CallNative(SQNativeClosure *nclosure, SQInteger nargs, SQInteger stackbase, bool tailcall, SQObjectPtr &retval,bool &suspend);\r
+       //starts a SQUIRREL call in the same "Execution loop"\r
+       bool StartCall(SQClosure *closure, SQInteger target, SQInteger nargs, SQInteger stackbase, bool tailcall);\r
+       bool CreateClassInstance(SQClass *theclass, SQObjectPtr &inst, SQObjectPtr &constructor);\r
        //call a generic closure pure SQUIRREL or NATIVE\r
-       bool Call(SQObjectPtr &closure, int nparams, int stackbase, SQObjectPtr &outres);\r
+       bool Call(SQObjectPtr &closure, SQInteger nparams, SQInteger stackbase, SQObjectPtr &outres,SQBool raiseerror);\r
        SQRESULT Suspend();\r
 \r
-       void CallDebugHook(int type,int forcedline=0);\r
+       void CallDebugHook(SQInteger type,SQInteger forcedline=0);\r
        void CallErrorHandler(SQObjectPtr &e);\r
        bool Get(const SQObjectPtr &self, const SQObjectPtr &key, SQObjectPtr &dest, bool raw, bool fetchroot);\r
        bool FallBackGet(const SQObjectPtr &self,const SQObjectPtr &key,SQObjectPtr &dest,bool raw);\r
        bool Set(const SQObjectPtr &self, const SQObjectPtr &key, const SQObjectPtr &val, bool fetchroot);\r
-       bool NewSlot(const SQObjectPtr &self, const SQObjectPtr &key, const SQObjectPtr &val);\r
+       bool NewSlot(const SQObjectPtr &self, const SQObjectPtr &key, const SQObjectPtr &val,bool bstatic);\r
        bool DeleteSlot(const SQObjectPtr &self, const SQObjectPtr &key, SQObjectPtr &res);\r
        bool Clone(const SQObjectPtr &self, SQObjectPtr &target);\r
-       bool ObjCmp(const SQObjectPtr &o1, const SQObjectPtr &o2,int &res);\r
+       bool ObjCmp(const SQObjectPtr &o1, const SQObjectPtr &o2,SQInteger &res);\r
        bool StringCat(const SQObjectPtr &str, const SQObjectPtr &obj, SQObjectPtr &dest);\r
        bool IsEqual(SQObjectPtr &o1,SQObjectPtr &o2,bool &res);\r
-       bool IsFalse(SQObjectPtr &o);\r
+       void ToString(const SQObjectPtr &o,SQObjectPtr &res);\r
        SQString *PrintObjVal(const SQObject &o);\r
 \r
  \r
@@ -87,30 +88,30 @@ public:
        void Raise_Error(SQObjectPtr &desc);\r
        void Raise_IdxError(SQObject &o);\r
        void Raise_CompareError(const SQObject &o1, const SQObject &o2);\r
-       void Raise_ParamTypeError(int nparam,int typemask,int type);\r
+       void Raise_ParamTypeError(SQInteger nparam,SQInteger typemask,SQInteger type);\r
 \r
        void TypeOf(const SQObjectPtr &obj1, SQObjectPtr &dest);\r
-       bool CallMetaMethod(SQDelegable *del, SQMetaMethod mm, int nparams, SQObjectPtr &outres);\r
-       bool ArithMetaMethod(int op, const SQObjectPtr &o1, const SQObjectPtr &o2, SQObjectPtr &dest);\r
-       //void Modulo(const SQObjectPtr &o1, const SQObjectPtr &o2, SQObjectPtr &dest);\r
-       bool Return(int _arg0, int _arg1, SQObjectPtr &retval);\r
+       bool CallMetaMethod(SQDelegable *del, SQMetaMethod mm, SQInteger nparams, SQObjectPtr &outres);\r
+       bool ArithMetaMethod(SQInteger op, const SQObjectPtr &o1, const SQObjectPtr &o2, SQObjectPtr &dest);\r
+       bool Return(SQInteger _arg0, SQInteger _arg1, SQObjectPtr &retval);\r
        //new stuff\r
-       bool ARITH_OP(unsigned int op,SQObjectPtr &trg,const SQObjectPtr &o1,const SQObjectPtr &o2);\r
-       bool BW_OP(unsigned int op,SQObjectPtr &trg,const SQObjectPtr &o1,const SQObjectPtr &o2);\r
-       bool NEG_OP(SQObjectPtr &trg,const SQObjectPtr &o1);\r
-       bool CMP_OP(CmpOP op, const SQObjectPtr &o1,const SQObjectPtr &o2,SQObjectPtr &res);\r
+       _INLINE bool ARITH_OP(SQUnsignedInteger op,SQObjectPtr &trg,const SQObjectPtr &o1,const SQObjectPtr &o2);\r
+       _INLINE bool BW_OP(SQUnsignedInteger op,SQObjectPtr &trg,const SQObjectPtr &o1,const SQObjectPtr &o2);\r
+       _INLINE bool NEG_OP(SQObjectPtr &trg,const SQObjectPtr &o1);\r
+       _INLINE bool CMP_OP(CmpOP op, const SQObjectPtr &o1,const SQObjectPtr &o2,SQObjectPtr &res);\r
        bool CLOSURE_OP(SQObjectPtr &target, SQFunctionProto *func);\r
        bool GETVARGV_OP(SQObjectPtr &target,SQObjectPtr &idx,CallInfo *ci);\r
-       bool CLASS_OP(SQObjectPtr &target,int base,int attrs);\r
+       bool CLASS_OP(SQObjectPtr &target,SQInteger base,SQInteger attrs);\r
+       bool GETPARENT_OP(SQObjectPtr &o,SQObjectPtr &target);\r
        //return true if the loop is finished\r
-       bool FOREACH_OP(SQObjectPtr &o1,SQObjectPtr &o2,SQObjectPtr &o3,SQObjectPtr &o4,int arg_2,bool &finished);\r
+       bool FOREACH_OP(SQObjectPtr &o1,SQObjectPtr &o2,SQObjectPtr &o3,SQObjectPtr &o4,SQInteger arg_2,bool &finished);\r
        bool DELEGATE_OP(SQObjectPtr &trg,SQObjectPtr &o1,SQObjectPtr &o2);\r
-       bool LOCAL_INC(int op,SQObjectPtr &target, SQObjectPtr &a, SQObjectPtr &incr);\r
-       bool PLOCAL_INC(int op,SQObjectPtr &target, SQObjectPtr &a, SQObjectPtr &incr);\r
-       bool DerefInc(int op,SQObjectPtr &target, SQObjectPtr &self, SQObjectPtr &key, SQObjectPtr &incr, bool postfix);\r
+       _INLINE bool LOCAL_INC(SQInteger op,SQObjectPtr &target, SQObjectPtr &a, SQObjectPtr &incr);\r
+       _INLINE bool PLOCAL_INC(SQInteger op,SQObjectPtr &target, SQObjectPtr &a, SQObjectPtr &incr);\r
+       _INLINE bool DerefInc(SQInteger op,SQObjectPtr &target, SQObjectPtr &self, SQObjectPtr &key, SQObjectPtr &incr, bool postfix);\r
        void PopVarArgs(VarArgs &vargs);\r
 #ifdef _DEBUG_DUMP\r
-       void dumpstack(int stackbase=-1, bool dumpall = false);\r
+       void dumpstack(SQInteger stackbase=-1, bool dumpall = false);\r
 #endif\r
 \r
 #ifndef NO_GARBAGE_COLLECTOR\r
@@ -121,22 +122,23 @@ public:
        void Release(){ sq_delete(this,SQVM); } //does nothing\r
 ////////////////////////////////////////////////////////////////////////////\r
        //stack functions for the api\r
-       void Pop();\r
-       void Pop(int n);\r
-       void Remove(int n);\r
+       void Remove(SQInteger n);\r
 \r
+       bool IsFalse(SQObjectPtr &o);\r
+       \r
+       void Pop();\r
+       void Pop(SQInteger n);\r
        void Push(const SQObjectPtr &o);\r
        SQObjectPtr &Top();\r
        SQObjectPtr &PopGet();\r
-       SQObjectPtr &GetUp(int n);\r
-       SQObjectPtr &GetAt(int n);\r
+       SQObjectPtr &GetUp(SQInteger n);\r
+       SQObjectPtr &GetAt(SQInteger n);\r
 \r
        SQObjectPtrVec _stack;\r
        SQObjectPtrVec _vargsstack;\r
-       int _top;\r
-       int _stackbase;\r
+       SQInteger _top;\r
+       SQInteger _stackbase;\r
        SQObjectPtr _roottable;\r
-       //SQObjectPtr _thrownerror;\r
        SQObjectPtr _lasterror;\r
        SQObjectPtr _errorhandler;\r
        SQObjectPtr _debughook;\r
@@ -148,21 +150,21 @@ public:
        void *_foreignptr;\r
        //VMs sharing the same state\r
        SQSharedState *_sharedstate;\r
-       int _nnativecalls;\r
+       SQInteger _nnativecalls;\r
        //suspend infos\r
-       bool _suspended;\r
-       bool _suspended_root;\r
-       int _suspended_target;\r
-       int _suspended_traps;\r
+       SQBool _suspended;\r
+       SQBool _suspended_root;\r
+       SQInteger _suspended_target;\r
+       SQInteger _suspended_traps;\r
 };\r
 \r
 struct AutoDec{\r
-       AutoDec(int *n) { _n = n; }\r
+       AutoDec(SQInteger *n) { _n = n; }\r
        ~AutoDec() { (*_n)--; }\r
-       int *_n;\r
+       SQInteger *_n;\r
 };\r
 \r
-SQObjectPtr &stack_get(HSQUIRRELVM v, int idx);\r
+inline SQObjectPtr &stack_get(HSQUIRRELVM v,SQInteger idx){return ((idx>=0)?(v->GetAt(idx+v->_stackbase-1)):(v->GetUp(idx)));}\r
 const SQChar *GetTypeName(const SQObjectPtr &obj1);\r
 const SQChar *IdType2Name(SQObjectType type);\r
 \r
@@ -175,8 +177,7 @@ const SQChar *IdType2Name(SQObjectType type);
 #endif\r
 \r
 #define PUSH_CALLINFO(v,nci){ \\r
-       v->_callsstack.push_back(nci); \\r
-       v->ci = &v->_callsstack.back(); \\r
+       v->ci = &v->_callsstack.push_back(nci); \\r
 }\r
 \r
 #define POP_CALLINFO(v){ \\r