#include "sqopcodes.h"\r
#include "sqobject.h"\r
#define MAX_NATIVE_CALLS 100\r
-#define MIN_STACK_OVERHEAD 15\r
+#define MIN_STACK_OVERHEAD 10\r
\r
#define SQ_SUSPEND_FLAG -666\r
-#define DONT_FALL_BACK 666\r
//base lib\r
void sq_base_register(HSQUIRRELVM v);\r
\r
\r
struct SQVM : public CHAINABLE_OBJ\r
{\r
+ struct VarArgs {\r
+ VarArgs() { size = 0; base = 0; }\r
+ unsigned short size;\r
+ unsigned short base;\r
+ };\r
+\r
struct CallInfo{\r
- //CallInfo() { _generator = NULL;}\r
+ //CallInfo() { _generator._type = OT_NULL;}\r
SQInstruction *_ip;\r
SQObjectPtr *_literals;\r
SQObjectPtr _closure;\r
SQInt32 _target;\r
SQInt32 _ncalls;\r
SQBool _root;\r
+ VarArgs _vargs;\r
};\r
\r
typedef sqvector<CallInfo> CallInfoVec;\r
public:\r
- void DebugHookProxy(SQInteger type, const SQChar * sourcename, SQInteger line, const SQChar * funcname);\r
- static void _DebugHookProxy(HSQUIRRELVM v, SQInteger type, const SQChar * sourcename, SQInteger line, const SQChar * funcname);\r
- enum ExecutionType { ET_CALL, ET_RESUME_GENERATOR, ET_RESUME_VM,ET_RESUME_THROW_VM };\r
+ enum ExecutionType { ET_CALL, ET_RESUME_GENERATOR, ET_RESUME_VM, ET_RESUME_THROW_VM };\r
SQVM(SQSharedState *ss);\r
~SQVM();\r
bool Init(SQVM *friendvm, SQInteger stacksize);\r
- bool Execute(SQObjectPtr &func, SQInteger nargs, SQInteger stackbase, SQObjectPtr &outres, SQBool raiseerror, ExecutionType et = ET_CALL);\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 newbase, SQObjectPtr &retval,bool &suspend);\r
+ bool CallNative(SQNativeClosure *nclosure, SQInteger nargs, SQInteger stackbase, 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
\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, SQInteger selfidx);\r
- SQInteger FallBackGet(const SQObjectPtr &self,const SQObjectPtr &key,SQObjectPtr &dest);\r
- bool InvokeDefaultDelegate(const SQObjectPtr &self,const SQObjectPtr &key,SQObjectPtr &dest);\r
- bool Set(const SQObjectPtr &self, const SQObjectPtr &key, const SQObjectPtr &val, SQInteger selfidx);\r
- SQInteger FallBackSet(const SQObjectPtr &self,const SQObjectPtr &key,const SQObjectPtr &val);\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,bool bstatic);\r
- bool NewSlotA(const SQObjectPtr &self,const SQObjectPtr &key,const SQObjectPtr &val,const SQObjectPtr &attrs,bool bstatic,bool raw);\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,SQInteger &res);\r
bool StringCat(const SQObjectPtr &str, const SQObjectPtr &obj, SQObjectPtr &dest);\r
- static bool IsEqual(const SQObjectPtr &o1,const SQObjectPtr &o2,bool &res);\r
- bool ToString(const SQObjectPtr &o,SQObjectPtr &res);\r
- SQString *PrintObjVal(const SQObjectPtr &o);\r
+ bool IsEqual(SQObjectPtr &o1,SQObjectPtr &o2,bool &res);\r
+ void ToString(const SQObjectPtr &o,SQObjectPtr &res);\r
+ SQString *PrintObjVal(const SQObject &o);\r
\r
\r
void Raise_Error(const SQChar *s, ...);\r
- void Raise_Error(const SQObjectPtr &desc);\r
- void Raise_IdxError(const SQObjectPtr &o);\r
+ 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(SQInteger nparam,SQInteger typemask,SQInteger type);\r
\r
- void FindOuter(SQObjectPtr &target, SQObjectPtr *stackindex);\r
- void RelocateOuters();\r
- void CloseOuters(SQObjectPtr *stackindex);\r
-\r
- bool TypeOf(const SQObjectPtr &obj1, SQObjectPtr &dest);\r
- bool CallMetaMethod(SQObjectPtr &closure, SQMetaMethod mm, SQInteger nparams, SQObjectPtr &outres);\r
+ void TypeOf(const SQObjectPtr &obj1, SQObjectPtr &dest);\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
_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,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,SQInteger arg_2,int exitpos,int &jump);\r
- //_INLINE bool LOCAL_INC(SQInteger op,SQObjectPtr &target, SQObjectPtr &a, SQObjectPtr &incr);\r
+ bool DELEGATE_OP(SQObjectPtr &trg,SQObjectPtr &o1,SQObjectPtr &o2);\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,SQInteger arg0);\r
+ _INLINE bool DerefInc(SQInteger op,SQObjectPtr &target, SQObjectPtr &self, SQObjectPtr &key, SQObjectPtr &incr, bool postfix);\r
+ void PopVarArgs(VarArgs &vargs);\r
+ void ClearStack(SQInteger last_top);\r
#ifdef _DEBUG_DUMP\r
void dumpstack(SQInteger stackbase=-1, bool dumpall = false);\r
#endif\r
\r
#ifndef NO_GARBAGE_COLLECTOR\r
void Mark(SQCollectable **chain);\r
- SQObjectType GetType() {return OT_THREAD;}\r
#endif\r
void Finalize();\r
void GrowCallStack() {\r
_callsstack = &_callstackdata[0];\r
_alloccallsstacksize = newsize;\r
}\r
- bool EnterFrame(SQInteger newbase, SQInteger newtop, bool tailcall);\r
- void LeaveFrame();\r
- void Release(){ sq_delete(this,SQVM); }\r
+ void Release(){ sq_delete(this,SQVM); } //does nothing\r
////////////////////////////////////////////////////////////////////////////\r
//stack functions for the api\r
void Remove(SQInteger n);\r
\r
- static bool IsFalse(SQObjectPtr &o);\r
+ bool IsFalse(SQObjectPtr &o);\r
\r
void Pop();\r
void Pop(SQInteger n);\r
void Push(const SQObjectPtr &o);\r
- void PushNull();\r
SQObjectPtr &Top();\r
SQObjectPtr &PopGet();\r
SQObjectPtr &GetUp(SQInteger n);\r
SQObjectPtr &GetAt(SQInteger n);\r
\r
SQObjectPtrVec _stack;\r
-\r
+ SQObjectPtrVec _vargsstack;\r
SQInteger _top;\r
SQInteger _stackbase;\r
- SQOuter *_openouters;\r
SQObjectPtr _roottable;\r
SQObjectPtr _lasterror;\r
SQObjectPtr _errorhandler;\r
-\r
- bool _debughook;\r
- SQDEBUGHOOK _debughook_native;\r
- SQObjectPtr _debughook_closure;\r
+ SQObjectPtr _debughook;\r
\r
SQObjectPtr temp_reg;\r
\r
//VMs sharing the same state\r
SQSharedState *_sharedstate;\r
SQInteger _nnativecalls;\r
- SQInteger _nmetamethodscall;\r
//suspend infos\r
SQBool _suspended;\r
SQBool _suspended_root;\r
SQInteger _suspended_target;\r
SQInteger _suspended_traps;\r
+ VarArgs _suspend_varargs;\r
};\r
\r
struct AutoDec{\r
#endif\r
\r
#define PUSH_CALLINFO(v,nci){ \\r
- SQInteger css = v->_callsstacksize; \\r
- if(css == v->_alloccallsstacksize) { \\r
+ if(v->_callsstacksize == v->_alloccallsstacksize) { \\r
v->GrowCallStack(); \\r
} \\r
- v->ci = &v->_callsstack[css]; \\r
+ v->ci = &v->_callsstack[v->_callsstacksize]; \\r
*(v->ci) = nci; \\r
v->_callsstacksize++; \\r
}\r
\r
#define POP_CALLINFO(v){ \\r
- SQInteger css = --v->_callsstacksize; \\r
+ v->_callsstacksize--; \\r
v->ci->_closure.Null(); \\r
- v->ci = css?&v->_callsstack[css-1]:NULL; \\r
+ if(v->_callsstacksize) \\r
+ v->ci = &v->_callsstack[v->_callsstacksize-1] ; \\r
+ else \\r
+ v->ci = NULL; \\r
}\r
#endif //_SQVM_H_\r