[DEV] remote _closure()
This commit is contained in:
parent
04cdeeac1a
commit
440bc87551
@ -113,8 +113,8 @@ bool rabbit::Class::newSlot(rabbit::SharedState *ss,const rabbit::ObjectPtr &key
|
|||||||
} else {
|
} else {
|
||||||
rabbit::ObjectPtr theval = val;
|
rabbit::ObjectPtr theval = val;
|
||||||
if(_base && sq_type(val) == rabbit::OT_CLOSURE) {
|
if(_base && sq_type(val) == rabbit::OT_CLOSURE) {
|
||||||
theval = _closure(val)->clone();
|
theval = const_cast<rabbit::Closure*>(val.toClosure())->clone();
|
||||||
_closure(theval)->_base = _base;
|
theval.toClosure()->_base = _base;
|
||||||
__ObjaddRef(_base); //ref for the closure
|
__ObjaddRef(_base); //ref for the closure
|
||||||
}
|
}
|
||||||
if(sq_type(temp) == rabbit::OT_NULL) {
|
if(sq_type(temp) == rabbit::OT_NULL) {
|
||||||
|
@ -149,7 +149,6 @@ namespace rabbit {
|
|||||||
#define is_delegable(t) (sq_type(t)&SQOBJECT_DELEGABLE)
|
#define is_delegable(t) (sq_type(t)&SQOBJECT_DELEGABLE)
|
||||||
#define raw_type(obj) _RAW_TYPE((obj)._type)
|
#define raw_type(obj) _RAW_TYPE((obj)._type)
|
||||||
|
|
||||||
#define _closure(obj) ((obj)._unVal.pClosure)
|
|
||||||
#define _generator(obj) ((obj)._unVal.pGenerator)
|
#define _generator(obj) ((obj)._unVal.pGenerator)
|
||||||
#define _nativeclosure(obj) ((obj)._unVal.pNativeClosure)
|
#define _nativeclosure(obj) ((obj)._unVal.pNativeClosure)
|
||||||
#define _userdata(obj) ((obj)._unVal.pUserData)
|
#define _userdata(obj) ((obj)._unVal.pUserData)
|
||||||
|
@ -612,7 +612,7 @@ bool rabbit::VirtualMachine::CLOSURE_OP(rabbit::ObjectPtr &target, rabbit::Funct
|
|||||||
findOuter(closure->_outervalues[i], &STK(v._src.toInteger()));
|
findOuter(closure->_outervalues[i], &STK(v._src.toInteger()));
|
||||||
break;
|
break;
|
||||||
case otOUTER:
|
case otOUTER:
|
||||||
closure->_outervalues[i] = _closure(ci->_closure)->_outervalues[v._src.toInteger()];
|
closure->_outervalues[i] = ci->_closure.toClosure()->_outervalues[v._src.toInteger()];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -694,7 +694,7 @@ bool rabbit::VirtualMachine::execute(rabbit::ObjectPtr &closure, int64_t nargs,
|
|||||||
switch(et) {
|
switch(et) {
|
||||||
case ET_CALL: {
|
case ET_CALL: {
|
||||||
temp_reg = closure;
|
temp_reg = closure;
|
||||||
if(!startcall(_closure(temp_reg), _top - nargs, nargs, stackbase, false)) {
|
if(!startcall(temp_reg.toClosure(), _top - nargs, nargs, stackbase, false)) {
|
||||||
//call the handler if there are no calls in the stack, if not relies on the previous node
|
//call the handler if there are no calls in the stack, if not relies on the previous node
|
||||||
if(ci == NULL) callerrorHandler(_lasterror);
|
if(ci == NULL) callerrorHandler(_lasterror);
|
||||||
return false;
|
return false;
|
||||||
@ -723,7 +723,7 @@ exception_restore:
|
|||||||
{
|
{
|
||||||
const rabbit::Instruction &_i_ = *ci->_ip++;
|
const rabbit::Instruction &_i_ = *ci->_ip++;
|
||||||
//dumpstack(_stackbase);
|
//dumpstack(_stackbase);
|
||||||
//printf("\n[%d] %s %d %d %d %d\n",ci->_ip-_closure(ci->_closure)->_function->_instructions,g_InstrDesc[_i_.op].name,arg0,arg1,arg2,arg3);
|
//printf("\n[%d] %s %d %d %d %d\n",ci->_ip-ci->_closure.toClosure()->_function->_instructions,g_InstrDesc[_i_.op].name,arg0,arg1,arg2,arg3);
|
||||||
switch(_i_.op)
|
switch(_i_.op)
|
||||||
{
|
{
|
||||||
case _OP_LINE: if (_debughook) callDebugHook('l',arg1); continue;
|
case _OP_LINE: if (_debughook) callDebugHook('l',arg1); continue;
|
||||||
@ -735,12 +735,12 @@ exception_restore:
|
|||||||
case _OP_TAILCALL:{
|
case _OP_TAILCALL:{
|
||||||
rabbit::ObjectPtr &t = STK(arg1);
|
rabbit::ObjectPtr &t = STK(arg1);
|
||||||
if (sq_type(t) == rabbit::OT_CLOSURE
|
if (sq_type(t) == rabbit::OT_CLOSURE
|
||||||
&& (!_closure(t)->_function->_bgenerator)){
|
&& (!t.toClosure()->_function->_bgenerator)){
|
||||||
rabbit::ObjectPtr clo = t;
|
rabbit::ObjectPtr clo = t;
|
||||||
int64_t last_top = _top;
|
int64_t last_top = _top;
|
||||||
if(_openouters) closeOuters(&(_stack[_stackbase]));
|
if(_openouters) closeOuters(&(_stack[_stackbase]));
|
||||||
for (int64_t i = 0; i < arg3; i++) STK(i) = STK(arg2 + i);
|
for (int64_t i = 0; i < arg3; i++) STK(i) = STK(arg2 + i);
|
||||||
_GUARD(startcall(_closure(clo), ci->_target, arg3, _stackbase, true));
|
_GUARD(startcall(clo.toClosure(), ci->_target, arg3, _stackbase, true));
|
||||||
if (last_top >= _top) {
|
if (last_top >= _top) {
|
||||||
_top = last_top;
|
_top = last_top;
|
||||||
}
|
}
|
||||||
@ -751,7 +751,7 @@ exception_restore:
|
|||||||
rabbit::ObjectPtr clo = STK(arg1);
|
rabbit::ObjectPtr clo = STK(arg1);
|
||||||
switch (sq_type(clo)) {
|
switch (sq_type(clo)) {
|
||||||
case rabbit::OT_CLOSURE:
|
case rabbit::OT_CLOSURE:
|
||||||
_GUARD(startcall(_closure(clo), sarg0, arg3, _stackbase+arg2, false));
|
_GUARD(startcall(clo.toClosure(), sarg0, arg3, _stackbase+arg2, false));
|
||||||
continue;
|
continue;
|
||||||
case rabbit::OT_NATIVECLOSURE: {
|
case rabbit::OT_NATIVECLOSURE: {
|
||||||
bool suspend;
|
bool suspend;
|
||||||
@ -781,7 +781,7 @@ exception_restore:
|
|||||||
case rabbit::OT_CLOSURE:
|
case rabbit::OT_CLOSURE:
|
||||||
stkbase = _stackbase+arg2;
|
stkbase = _stackbase+arg2;
|
||||||
_stack[stkbase] = inst;
|
_stack[stkbase] = inst;
|
||||||
_GUARD(startcall(_closure(clo), -1, arg3, stkbase, false));
|
_GUARD(startcall(clo.toClosure(), -1, arg3, stkbase, false));
|
||||||
break;
|
break;
|
||||||
case rabbit::OT_NATIVECLOSURE:
|
case rabbit::OT_NATIVECLOSURE:
|
||||||
bool dummy;
|
bool dummy;
|
||||||
@ -874,7 +874,7 @@ exception_restore:
|
|||||||
continue;
|
continue;
|
||||||
case _OP_LOADNULLS:{ for(int32_t n=0; n < arg1; n++) STK(arg0+n).Null(); }continue;
|
case _OP_LOADNULLS:{ for(int32_t n=0; n < arg1; n++) STK(arg0+n).Null(); }continue;
|
||||||
case _OP_LOADROOT: {
|
case _OP_LOADROOT: {
|
||||||
rabbit::WeakRef *w = _closure(ci->_closure)->_root;
|
rabbit::WeakRef *w = ci->_closure.toClosure()->_root;
|
||||||
if(sq_type(w->_obj) != rabbit::OT_NULL) {
|
if(sq_type(w->_obj) != rabbit::OT_NULL) {
|
||||||
TARGET = w->_obj;
|
TARGET = w->_obj;
|
||||||
} else {
|
} else {
|
||||||
@ -892,13 +892,13 @@ exception_restore:
|
|||||||
continue;
|
continue;
|
||||||
case _OP_JZ: if(IsFalse(STK(arg0))) ci->_ip+=(sarg1); continue;
|
case _OP_JZ: if(IsFalse(STK(arg0))) ci->_ip+=(sarg1); continue;
|
||||||
case _OP_GETOUTER: {
|
case _OP_GETOUTER: {
|
||||||
rabbit::Closure *cur_cls = _closure(ci->_closure);
|
rabbit::Closure *cur_cls = ci->_closure.toClosure();
|
||||||
rabbit::Outer *otr = _outer(cur_cls->_outervalues[arg1]);
|
rabbit::Outer *otr = _outer(cur_cls->_outervalues[arg1]);
|
||||||
TARGET = *(otr->_valptr);
|
TARGET = *(otr->_valptr);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
case _OP_SETOUTER: {
|
case _OP_SETOUTER: {
|
||||||
rabbit::Closure *cur_cls = _closure(ci->_closure);
|
rabbit::Closure *cur_cls = ci->_closure.toClosure();
|
||||||
rabbit::Outer *otr = _outer(cur_cls->_outervalues[arg1]);
|
rabbit::Outer *otr = _outer(cur_cls->_outervalues[arg1]);
|
||||||
*(otr->_valptr) = STK(arg2);
|
*(otr->_valptr) = STK(arg2);
|
||||||
if(arg0 != 0xFF) {
|
if(arg0 != 0xFF) {
|
||||||
@ -1035,7 +1035,7 @@ exception_restore:
|
|||||||
case _OP_CLONE: _GUARD(clone(STK(arg1), TARGET)); continue;
|
case _OP_CLONE: _GUARD(clone(STK(arg1), TARGET)); continue;
|
||||||
case _OP_TYPEOF: _GUARD(typeOf(STK(arg1), TARGET)) continue;
|
case _OP_TYPEOF: _GUARD(typeOf(STK(arg1), TARGET)) continue;
|
||||||
case _OP_PUSHTRAP:{
|
case _OP_PUSHTRAP:{
|
||||||
rabbit::Instruction *_iv = _closure(ci->_closure)->_function->_instructions;
|
rabbit::Instruction *_iv = ci->_closure.toClosure()->_function->_instructions;
|
||||||
_etraps.pushBack(rabbit::ExceptionTrap(_top,_stackbase, &_iv[(ci->_ip-_iv)+arg1], arg0)); traps++;
|
_etraps.pushBack(rabbit::ExceptionTrap(_top,_stackbase, &_iv[(ci->_ip-_iv)+arg1], arg0)); traps++;
|
||||||
ci->_etraps++;
|
ci->_etraps++;
|
||||||
}
|
}
|
||||||
@ -1052,7 +1052,7 @@ exception_restore:
|
|||||||
_GUARD(newSlotA(STK(arg1),STK(arg2),STK(arg3),(arg0&NEW_SLOT_ATTRIBUTES_FLAG) ? STK(arg2-1) : rabbit::ObjectPtr(),(arg0&NEW_SLOT_STATIC_FLAG)?true:false,false));
|
_GUARD(newSlotA(STK(arg1),STK(arg2),STK(arg3),(arg0&NEW_SLOT_ATTRIBUTES_FLAG) ? STK(arg2-1) : rabbit::ObjectPtr(),(arg0&NEW_SLOT_STATIC_FLAG)?true:false,false));
|
||||||
continue;
|
continue;
|
||||||
case _OP_GETBASE:{
|
case _OP_GETBASE:{
|
||||||
rabbit::Closure *clo = _closure(ci->_closure);
|
rabbit::Closure *clo = ci->_closure.toClosure();
|
||||||
if(clo->_base) {
|
if(clo->_base) {
|
||||||
TARGET = clo->_base;
|
TARGET = clo->_base;
|
||||||
}
|
}
|
||||||
@ -1130,7 +1130,7 @@ void rabbit::VirtualMachine::callerrorHandler(rabbit::ObjectPtr &error)
|
|||||||
void rabbit::VirtualMachine::callDebugHook(int64_t type,int64_t forcedline)
|
void rabbit::VirtualMachine::callDebugHook(int64_t type,int64_t forcedline)
|
||||||
{
|
{
|
||||||
_debughook = false;
|
_debughook = false;
|
||||||
rabbit::FunctionProto *func=_closure(ci->_closure)->_function;
|
rabbit::FunctionProto *func=ci->_closure.toClosure()->_function;
|
||||||
if(_debughook_native) {
|
if(_debughook_native) {
|
||||||
const char *src = sq_type(func->_sourcename) == rabbit::OT_STRING?_stringval(func->_sourcename):NULL;
|
const char *src = sq_type(func->_sourcename) == rabbit::OT_STRING?_stringval(func->_sourcename):NULL;
|
||||||
const char *fname = sq_type(func->_name) == rabbit::OT_STRING?_stringval(func->_name):NULL;
|
const char *fname = sq_type(func->_name) == rabbit::OT_STRING?_stringval(func->_name):NULL;
|
||||||
@ -1300,7 +1300,7 @@ bool rabbit::VirtualMachine::get(const rabbit::ObjectPtr &self, const rabbit::Ob
|
|||||||
}
|
}
|
||||||
//#ifdef ROrabbit::OT_FALLBACK
|
//#ifdef ROrabbit::OT_FALLBACK
|
||||||
if(selfidx == 0) {
|
if(selfidx == 0) {
|
||||||
rabbit::WeakRef *w = _closure(ci->_closure)->_root;
|
rabbit::WeakRef *w = ci->_closure.toClosure()->_root;
|
||||||
if(sq_type(w->_obj) != rabbit::OT_NULL)
|
if(sq_type(w->_obj) != rabbit::OT_NULL)
|
||||||
{
|
{
|
||||||
if(get(*((const rabbit::ObjectPtr *)&w->_obj),key,dest,0,DONT_FALL_BACK)) return true;
|
if(get(*((const rabbit::ObjectPtr *)&w->_obj),key,dest,0,DONT_FALL_BACK)) return true;
|
||||||
@ -1791,7 +1791,7 @@ void rabbit::VirtualMachine::dumpstack(int64_t stackbase,bool dumpall)
|
|||||||
case rabbit::OT_NULL: printf("NULL"); break;
|
case rabbit::OT_NULL: printf("NULL"); break;
|
||||||
case rabbit::OT_TABLE: printf("TABLE %p[%p]",obj.toTable(),obj.toTable()->_delegate);break;
|
case rabbit::OT_TABLE: printf("TABLE %p[%p]",obj.toTable(),obj.toTable()->_delegate);break;
|
||||||
case rabbit::OT_ARRAY: printf("ARRAY %p",obj.toArray());break;
|
case rabbit::OT_ARRAY: printf("ARRAY %p",obj.toArray());break;
|
||||||
case rabbit::OT_CLOSURE: printf("CLOSURE [%p]",_closure(obj));break;
|
case rabbit::OT_CLOSURE: printf("CLOSURE [%p]",obj.toClosure());break;
|
||||||
case rabbit::OT_NATIVECLOSURE: printf("NATIVECLOSURE");break;
|
case rabbit::OT_NATIVECLOSURE: printf("NATIVECLOSURE");break;
|
||||||
case rabbit::OT_USERDATA: printf("USERDATA %p[%p]",_userdataval(obj),_userdata(obj)->_delegate);break;
|
case rabbit::OT_USERDATA: printf("USERDATA %p[%p]",_userdataval(obj),_userdata(obj)->_delegate);break;
|
||||||
case rabbit::OT_GENERATOR: printf("GENERATOR %p",_generator(obj));break;
|
case rabbit::OT_GENERATOR: printf("GENERATOR %p",_generator(obj));break;
|
||||||
|
@ -410,7 +410,7 @@ rabbit::Result rabbit::sq_getclosureinfo(rabbit::VirtualMachine* v,int64_t idx,u
|
|||||||
{
|
{
|
||||||
rabbit::Object o = stack_get(v, idx);
|
rabbit::Object o = stack_get(v, idx);
|
||||||
if(sq_type(o) == rabbit::OT_CLOSURE) {
|
if(sq_type(o) == rabbit::OT_CLOSURE) {
|
||||||
rabbit::Closure *c = _closure(o);
|
rabbit::Closure *c = o.toClosure();
|
||||||
rabbit::FunctionProto *proto = c->_function;
|
rabbit::FunctionProto *proto = c->_function;
|
||||||
*nparams = (uint64_t)proto->_nparameters;
|
*nparams = (uint64_t)proto->_nparameters;
|
||||||
*nfreevars = (uint64_t)proto->_noutervalues;
|
*nfreevars = (uint64_t)proto->_noutervalues;
|
||||||
@ -474,12 +474,12 @@ rabbit::Result rabbit::sq_bindenv(rabbit::VirtualMachine* v,int64_t idx)
|
|||||||
rabbit::WeakRef *w = _refcounted(env)->getWeakRef(sq_type(env));
|
rabbit::WeakRef *w = _refcounted(env)->getWeakRef(sq_type(env));
|
||||||
rabbit::ObjectPtr ret;
|
rabbit::ObjectPtr ret;
|
||||||
if(sq_isclosure(o)) {
|
if(sq_isclosure(o)) {
|
||||||
rabbit::Closure *c = _closure(o)->clone();
|
rabbit::Closure *c = o.toClosure()->clone();
|
||||||
__Objrelease(c->_env);
|
__Objrelease(c->_env);
|
||||||
c->_env = w;
|
c->_env = w;
|
||||||
__ObjaddRef(c->_env);
|
__ObjaddRef(c->_env);
|
||||||
if(_closure(o)->_base) {
|
if(o.toClosure()->_base) {
|
||||||
c->_base = _closure(o)->_base;
|
c->_base = o.toClosure()->_base;
|
||||||
__ObjaddRef(c->_base);
|
__ObjaddRef(c->_base);
|
||||||
}
|
}
|
||||||
ret = c;
|
ret = c;
|
||||||
@ -507,7 +507,7 @@ rabbit::Result rabbit::sq_getclosurename(rabbit::VirtualMachine* v,int64_t idx)
|
|||||||
v->push(_nativeclosure(o)->_name);
|
v->push(_nativeclosure(o)->_name);
|
||||||
}
|
}
|
||||||
else { //closure
|
else { //closure
|
||||||
v->push(_closure(o)->_function->_name);
|
v->push(o.toClosure()->_function->_name);
|
||||||
}
|
}
|
||||||
return SQ_OK;
|
return SQ_OK;
|
||||||
}
|
}
|
||||||
@ -518,7 +518,7 @@ rabbit::Result rabbit::sq_setclosureroot(rabbit::VirtualMachine* v,int64_t idx)
|
|||||||
rabbit::Object o = stack_get(v, -1);
|
rabbit::Object o = stack_get(v, -1);
|
||||||
if(!sq_isclosure(c)) return sq_throwerror(v, "closure expected");
|
if(!sq_isclosure(c)) return sq_throwerror(v, "closure expected");
|
||||||
if(sq_istable(o)) {
|
if(sq_istable(o)) {
|
||||||
_closure(c)->setRoot(o.toTable()->getWeakRef(rabbit::OT_TABLE));
|
c.toClosure()->setRoot(o.toTable()->getWeakRef(rabbit::OT_TABLE));
|
||||||
v->pop();
|
v->pop();
|
||||||
return SQ_OK;
|
return SQ_OK;
|
||||||
}
|
}
|
||||||
@ -529,7 +529,7 @@ rabbit::Result rabbit::sq_getclosureroot(rabbit::VirtualMachine* v,int64_t idx)
|
|||||||
{
|
{
|
||||||
rabbit::ObjectPtr &c = stack_get(v,idx);
|
rabbit::ObjectPtr &c = stack_get(v,idx);
|
||||||
if(!sq_isclosure(c)) return sq_throwerror(v, "closure expected");
|
if(!sq_isclosure(c)) return sq_throwerror(v, "closure expected");
|
||||||
v->push(_closure(c)->_root->_obj);
|
v->push(c.toClosure()->_root->_obj);
|
||||||
return SQ_OK;
|
return SQ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1120,7 +1120,7 @@ const char * rabbit::sq_getlocal(rabbit::VirtualMachine* v,uint64_t level,uint64
|
|||||||
rabbit::VirtualMachine::callInfo &ci=v->_callsstack[lvl];
|
rabbit::VirtualMachine::callInfo &ci=v->_callsstack[lvl];
|
||||||
if(sq_type(ci._closure)!=rabbit::OT_CLOSURE)
|
if(sq_type(ci._closure)!=rabbit::OT_CLOSURE)
|
||||||
return NULL;
|
return NULL;
|
||||||
rabbit::Closure *c=_closure(ci._closure);
|
rabbit::Closure *c=ci._closure.toClosure();
|
||||||
rabbit::FunctionProto *func=c->_function;
|
rabbit::FunctionProto *func=c->_function;
|
||||||
if(func->_noutervalues > (int64_t)idx) {
|
if(func->_noutervalues > (int64_t)idx) {
|
||||||
v->push(*_outer(c->_outervalues[idx])->_valptr);
|
v->push(*_outer(c->_outervalues[idx])->_valptr);
|
||||||
@ -1219,7 +1219,7 @@ rabbit::Result rabbit::sq_tailcall(rabbit::VirtualMachine* v, int64_t nparams)
|
|||||||
if (sq_type(res) != rabbit::OT_CLOSURE) {
|
if (sq_type(res) != rabbit::OT_CLOSURE) {
|
||||||
return sq_throwerror(v, "only closure can be tail called");
|
return sq_throwerror(v, "only closure can be tail called");
|
||||||
}
|
}
|
||||||
rabbit::Closure *clo = _closure(res);
|
rabbit::Closure *clo = res.toClosure();
|
||||||
if (clo->_function->_bgenerator)
|
if (clo->_function->_bgenerator)
|
||||||
{
|
{
|
||||||
return sq_throwerror(v, "generators cannot be tail called");
|
return sq_throwerror(v, "generators cannot be tail called");
|
||||||
@ -1305,11 +1305,11 @@ rabbit::Result rabbit::sq_writeclosure(rabbit::VirtualMachine* v,SQWRITEFUNC w,r
|
|||||||
rabbit::ObjectPtr *o = NULL;
|
rabbit::ObjectPtr *o = NULL;
|
||||||
_GETSAFE_OBJ(v, -1, rabbit::OT_CLOSURE,o);
|
_GETSAFE_OBJ(v, -1, rabbit::OT_CLOSURE,o);
|
||||||
unsigned short tag = SQ_BYTECODE_STREAM_TAG;
|
unsigned short tag = SQ_BYTECODE_STREAM_TAG;
|
||||||
if(_closure(*o)->_function->_noutervalues)
|
if(o->toClosure()->_function->_noutervalues)
|
||||||
return sq_throwerror(v,"a closure with free variables bound cannot be serialized");
|
return sq_throwerror(v,"a closure with free variables bound cannot be serialized");
|
||||||
if(w(up,&tag,2) != 2)
|
if(w(up,&tag,2) != 2)
|
||||||
return sq_throwerror(v,"io error");
|
return sq_throwerror(v,"io error");
|
||||||
if(!_closure(*o)->save(v,up,w))
|
if(!o->toClosure()->save(v,up,w))
|
||||||
return SQ_ERROR;
|
return SQ_ERROR;
|
||||||
return SQ_OK;
|
return SQ_OK;
|
||||||
}
|
}
|
||||||
@ -1362,7 +1362,7 @@ const char * rabbit::sq_getfreevariable(rabbit::VirtualMachine* v,int64_t idx,ui
|
|||||||
switch(sq_type(self))
|
switch(sq_type(self))
|
||||||
{
|
{
|
||||||
case rabbit::OT_CLOSURE:{
|
case rabbit::OT_CLOSURE:{
|
||||||
rabbit::Closure *clo = _closure(self);
|
rabbit::Closure *clo = self.toClosure();
|
||||||
rabbit::FunctionProto *fp = clo->_function;
|
rabbit::FunctionProto *fp = clo->_function;
|
||||||
if(((uint64_t)fp->_noutervalues) > nval) {
|
if(((uint64_t)fp->_noutervalues) > nval) {
|
||||||
v->push(*(_outer(clo->_outervalues[nval])->_valptr));
|
v->push(*(_outer(clo->_outervalues[nval])->_valptr));
|
||||||
@ -1390,9 +1390,9 @@ rabbit::Result rabbit::sq_setfreevariable(rabbit::VirtualMachine* v,int64_t idx,
|
|||||||
switch(sq_type(self))
|
switch(sq_type(self))
|
||||||
{
|
{
|
||||||
case rabbit::OT_CLOSURE:{
|
case rabbit::OT_CLOSURE:{
|
||||||
rabbit::FunctionProto *fp = _closure(self)->_function;
|
rabbit::FunctionProto *fp = self.toClosure()->_function;
|
||||||
if(((uint64_t)fp->_noutervalues) > nval){
|
if(((uint64_t)fp->_noutervalues) > nval){
|
||||||
*(_outer(_closure(self)->_outervalues[nval])->_valptr) = stack_get(v,-1);
|
*(_outer(self.toClosure()->_outervalues[nval])->_valptr) = stack_get(v,-1);
|
||||||
}
|
}
|
||||||
else return sq_throwerror(v,"invalid free var index");
|
else return sq_throwerror(v,"invalid free var index");
|
||||||
}
|
}
|
||||||
|
@ -237,7 +237,7 @@ static int64_t base_compilestring(rabbit::VirtualMachine* v)
|
|||||||
static int64_t base_newthread(rabbit::VirtualMachine* v)
|
static int64_t base_newthread(rabbit::VirtualMachine* v)
|
||||||
{
|
{
|
||||||
rabbit::ObjectPtr &func = stack_get(v,2);
|
rabbit::ObjectPtr &func = stack_get(v,2);
|
||||||
int64_t stksize = (_closure(func)->_function->_stacksize << 1) +2;
|
int64_t stksize = (func.toClosure()->_function->_stacksize << 1) +2;
|
||||||
rabbit::VirtualMachine* newv = sq_newthread(v, (stksize < MIN_STACK_OVERHEAD + 2)? MIN_STACK_OVERHEAD + 2 : stksize);
|
rabbit::VirtualMachine* newv = sq_newthread(v, (stksize < MIN_STACK_OVERHEAD + 2)? MIN_STACK_OVERHEAD + 2 : stksize);
|
||||||
sq_move(newv,v,-2);
|
sq_move(newv,v,-2);
|
||||||
return 1;
|
return 1;
|
||||||
@ -929,7 +929,7 @@ static int64_t closure_pcall(rabbit::VirtualMachine* v)
|
|||||||
static int64_t closure_call(rabbit::VirtualMachine* v)
|
static int64_t closure_call(rabbit::VirtualMachine* v)
|
||||||
{
|
{
|
||||||
rabbit::ObjectPtr &c = stack_get(v, -1);
|
rabbit::ObjectPtr &c = stack_get(v, -1);
|
||||||
if (sq_type(c) == rabbit::OT_CLOSURE && (_closure(c)->_function->_bgenerator == false))
|
if (sq_type(c) == rabbit::OT_CLOSURE && (c.toClosure()->_function->_bgenerator == false))
|
||||||
{
|
{
|
||||||
return sq_tailcall(v, sq_gettop(v) - 1);
|
return sq_tailcall(v, sq_gettop(v) - 1);
|
||||||
}
|
}
|
||||||
@ -980,7 +980,7 @@ static int64_t closure_getinfos(rabbit::VirtualMachine* v) {
|
|||||||
rabbit::Object o = stack_get(v,1);
|
rabbit::Object o = stack_get(v,1);
|
||||||
rabbit::Table *res = rabbit::Table::create(_get_shared_state(v),4);
|
rabbit::Table *res = rabbit::Table::create(_get_shared_state(v),4);
|
||||||
if(sq_type(o) == rabbit::OT_CLOSURE) {
|
if(sq_type(o) == rabbit::OT_CLOSURE) {
|
||||||
rabbit::FunctionProto *f = _closure(o)->_function;
|
rabbit::FunctionProto *f = o.toClosure()->_function;
|
||||||
int64_t nparams = f->_nparameters + (f->_varparams?1:0);
|
int64_t nparams = f->_nparameters + (f->_varparams?1:0);
|
||||||
rabbit::ObjectPtr params = rabbit::Array::create(_get_shared_state(v),nparams);
|
rabbit::ObjectPtr params = rabbit::Array::create(_get_shared_state(v),nparams);
|
||||||
rabbit::ObjectPtr defparams = rabbit::Array::create(_get_shared_state(v),f->_ndefaultparams);
|
rabbit::ObjectPtr defparams = rabbit::Array::create(_get_shared_state(v),f->_ndefaultparams);
|
||||||
@ -988,7 +988,7 @@ static int64_t closure_getinfos(rabbit::VirtualMachine* v) {
|
|||||||
params.toArray()->set((int64_t)n,f->_parameters[n]);
|
params.toArray()->set((int64_t)n,f->_parameters[n]);
|
||||||
}
|
}
|
||||||
for(int64_t j = 0; j<f->_ndefaultparams; j++) {
|
for(int64_t j = 0; j<f->_ndefaultparams; j++) {
|
||||||
defparams.toArray()->set((int64_t)j,_closure(o)->_defaultparams[j]);
|
defparams.toArray()->set((int64_t)j,o.toClosure()->_defaultparams[j]);
|
||||||
}
|
}
|
||||||
if(f->_varparams) {
|
if(f->_varparams) {
|
||||||
params.toArray()->set(nparams-1,rabbit::String::create(_get_shared_state(v),"...",-1));
|
params.toArray()->set(nparams-1,rabbit::String::create(_get_shared_state(v),"...",-1));
|
||||||
|
@ -28,7 +28,7 @@ rabbit::Result rabbit::sq_getfunctioninfo(rabbit::VirtualMachine* v,int64_t leve
|
|||||||
if (cssize > level) {
|
if (cssize > level) {
|
||||||
rabbit::VirtualMachine::callInfo &ci = v->_callsstack[cssize-level-1];
|
rabbit::VirtualMachine::callInfo &ci = v->_callsstack[cssize-level-1];
|
||||||
if(sq_isclosure(ci._closure)) {
|
if(sq_isclosure(ci._closure)) {
|
||||||
rabbit::Closure *c = _closure(ci._closure);
|
rabbit::Closure *c = ci._closure.toClosure();
|
||||||
rabbit::FunctionProto *proto = c->_function;
|
rabbit::FunctionProto *proto = c->_function;
|
||||||
fi->funcid = proto;
|
fi->funcid = proto;
|
||||||
fi->name = sq_type(proto->_name) == rabbit::OT_STRING?_stringval(proto->_name):"unknown";
|
fi->name = sq_type(proto->_name) == rabbit::OT_STRING?_stringval(proto->_name):"unknown";
|
||||||
@ -48,7 +48,7 @@ rabbit::Result rabbit::sq_stackinfos(rabbit::VirtualMachine* v, int64_t level, r
|
|||||||
rabbit::VirtualMachine::callInfo &ci = v->_callsstack[cssize-level-1];
|
rabbit::VirtualMachine::callInfo &ci = v->_callsstack[cssize-level-1];
|
||||||
switch (sq_type(ci._closure)) {
|
switch (sq_type(ci._closure)) {
|
||||||
case rabbit::OT_CLOSURE:{
|
case rabbit::OT_CLOSURE:{
|
||||||
rabbit::FunctionProto *func = _closure(ci._closure)->_function;
|
rabbit::FunctionProto *func = ci._closure.toClosure()->_function;
|
||||||
if (sq_type(func->_name) == rabbit::OT_STRING)
|
if (sq_type(func->_name) == rabbit::OT_STRING)
|
||||||
si->funcname = _stringval(func->_name);
|
si->funcname = _stringval(func->_name);
|
||||||
if (sq_type(func->_sourcename) == rabbit::OT_STRING)
|
if (sq_type(func->_sourcename) == rabbit::OT_STRING)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user