[DEV] some patch
This commit is contained in:
parent
0b9cd5c735
commit
685dd2bca8
@ -257,7 +257,7 @@ int main(int argc, char* argv[])
|
||||
_CrtsetAllocHook(MemAllocHook);
|
||||
#endif
|
||||
|
||||
v=rabbit::sq_open(1024);
|
||||
v=rabbit::sq_open();
|
||||
sq_setprintfunc(v,printfunc,errorfunc);
|
||||
|
||||
sq_pushroottable(v);
|
||||
|
@ -141,7 +141,8 @@ bool rabbit::VirtualMachine::ARITH_OP(uint64_t op,rabbit::ObjectPtr &trg,const r
|
||||
|
||||
rabbit::VirtualMachine::VirtualMachine(rabbit::SharedState *ss)
|
||||
{
|
||||
_sharedstate=ss;
|
||||
_stack.resize(4096);
|
||||
_sharedstate = ss;
|
||||
_suspended = SQFalse;
|
||||
_suspended_target = -1;
|
||||
_suspended_root = SQFalse;
|
||||
@ -159,6 +160,27 @@ rabbit::VirtualMachine::VirtualMachine(rabbit::SharedState *ss)
|
||||
_releasehook = NULL;
|
||||
}
|
||||
|
||||
bool rabbit::VirtualMachine::init(rabbit::VirtualMachine *friendvm) {
|
||||
_alloccallsstacksize = 4;
|
||||
_callstackdata.resize(_alloccallsstacksize);
|
||||
_callsstacksize = 0;
|
||||
_callsstack = &_callstackdata[0];
|
||||
_stackbase = 0;
|
||||
_top = 0;
|
||||
if(!friendvm) {
|
||||
_roottable = rabbit::Table::create(_get_shared_state(this), 0);
|
||||
sq_base_register(this);
|
||||
}
|
||||
else {
|
||||
_roottable = friendvm->_roottable;
|
||||
_errorhandler = friendvm->_errorhandler;
|
||||
_debughook = friendvm->_debughook;
|
||||
_debughook_native = friendvm->_debughook_native;
|
||||
_debughook_closure = friendvm->_debughook_closure;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void rabbit::VirtualMachine::finalize()
|
||||
{
|
||||
if(_releasehook) { _releasehook(_foreignptr,0); _releasehook = NULL; }
|
||||
@ -185,12 +207,25 @@ bool rabbit::VirtualMachine::arithMetaMethod(int64_t op,const rabbit::ObjectPtr
|
||||
{
|
||||
rabbit::MetaMethod mm;
|
||||
switch(op){
|
||||
case '+': mm=MT_ADD; break;
|
||||
case '-': mm=MT_SUB; break;
|
||||
case '/': mm=MT_DIV; break;
|
||||
case '*': mm=MT_MUL; break;
|
||||
case '%': mm=MT_MODULO; break;
|
||||
default: mm = MT_ADD; assert(0); break; //shutup compiler
|
||||
case '+':
|
||||
mm=MT_ADD;
|
||||
break;
|
||||
case '-':
|
||||
mm=MT_SUB;
|
||||
break;
|
||||
case '/':
|
||||
mm=MT_DIV;
|
||||
break;
|
||||
case '*':
|
||||
mm=MT_MUL;
|
||||
break;
|
||||
case '%':
|
||||
mm=MT_MODULO;
|
||||
break;
|
||||
default:
|
||||
mm = MT_ADD;
|
||||
assert(0);
|
||||
break; //shutup compiler
|
||||
}
|
||||
if( o1.isDelegable() == true
|
||||
&& o1.toDelegable()->_delegate) {
|
||||
@ -382,31 +417,6 @@ bool rabbit::VirtualMachine::typeOf(const rabbit::ObjectPtr &obj1,rabbit::Object
|
||||
return true;
|
||||
}
|
||||
|
||||
bool rabbit::VirtualMachine::init(rabbit::VirtualMachine *friendvm, int64_t stacksize)
|
||||
{
|
||||
_stack.resize(stacksize);
|
||||
_alloccallsstacksize = 4;
|
||||
_callstackdata.resize(_alloccallsstacksize);
|
||||
_callsstacksize = 0;
|
||||
_callsstack = &_callstackdata[0];
|
||||
_stackbase = 0;
|
||||
_top = 0;
|
||||
if(!friendvm) {
|
||||
_roottable = rabbit::Table::create(_get_shared_state(this), 0);
|
||||
sq_base_register(this);
|
||||
}
|
||||
else {
|
||||
_roottable = friendvm->_roottable;
|
||||
_errorhandler = friendvm->_errorhandler;
|
||||
_debughook = friendvm->_debughook;
|
||||
_debughook_native = friendvm->_debughook_native;
|
||||
_debughook_closure = friendvm->_debughook_closure;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool rabbit::VirtualMachine::startcall(rabbit::Closure *closure,int64_t target,int64_t args,int64_t stackbase,bool tailcall)
|
||||
{
|
||||
|
@ -61,7 +61,7 @@ namespace rabbit {
|
||||
};
|
||||
VirtualMachine(rabbit::SharedState *ss);
|
||||
~VirtualMachine();
|
||||
bool init(VirtualMachine *friendvm, int64_t stacksize);
|
||||
bool init(VirtualMachine *friendvm);
|
||||
bool execute(rabbit::ObjectPtr &func, int64_t nargs, int64_t stackbase, rabbit::ObjectPtr &outres, rabbit::Bool raiseerror, ExecutionType et = ET_CALL);
|
||||
//starts a native call return when the NATIVE closure returns
|
||||
bool callNative(rabbit::NativeClosure *nclosure, int64_t nargs, int64_t newbase, rabbit::ObjectPtr &retval, int32_t target, bool &suspend,bool &tailcall);
|
||||
|
@ -43,8 +43,8 @@ typedef int64_t (*SQLEXREADFUNC)(rabbit::UserPointer);
|
||||
|
||||
namespace rabbit {
|
||||
/*vm*/
|
||||
rabbit::VirtualMachine* sq_open(int64_t initialstacksize);
|
||||
rabbit::VirtualMachine* sq_newthread(rabbit::VirtualMachine* friendvm, int64_t initialstacksize);
|
||||
rabbit::VirtualMachine* sq_open();
|
||||
rabbit::VirtualMachine* sq_newthread(rabbit::VirtualMachine* friendvm);
|
||||
void sq_seterrorhandler(rabbit::VirtualMachine* v);
|
||||
void sq_close(rabbit::VirtualMachine* v);
|
||||
void sq_setforeignptr(rabbit::VirtualMachine* v,rabbit::UserPointer p);
|
||||
|
@ -56,7 +56,7 @@ namespace rabbit {
|
||||
return sq_throwerror(v, _get_shared_state(v)->getScratchPad(-1));
|
||||
}
|
||||
}
|
||||
rabbit::VirtualMachine* rabbit::sq_open(int64_t initialstacksize)
|
||||
rabbit::VirtualMachine* rabbit::sq_open()
|
||||
{
|
||||
rabbit::SharedState *ss;
|
||||
sq_new(ss, rabbit::SharedState);
|
||||
@ -66,7 +66,7 @@ rabbit::VirtualMachine* rabbit::sq_open(int64_t initialstacksize)
|
||||
rabbit::VirtualMachine *v = new (allocatedData) rabbit::VirtualMachine(ss);
|
||||
ss->_root_vm = v;
|
||||
|
||||
if(v->init(NULL, initialstacksize)) {
|
||||
if(v->init(NULL)) {
|
||||
return v;
|
||||
} else {
|
||||
v->~VirtualMachine();
|
||||
@ -76,7 +76,7 @@ rabbit::VirtualMachine* rabbit::sq_open(int64_t initialstacksize)
|
||||
return v;
|
||||
}
|
||||
|
||||
rabbit::VirtualMachine* rabbit::sq_newthread(rabbit::VirtualMachine* friendvm, int64_t initialstacksize)
|
||||
rabbit::VirtualMachine* rabbit::sq_newthread(rabbit::VirtualMachine* friendvm)
|
||||
{
|
||||
rabbit::SharedState *ss;
|
||||
ss=_get_shared_state(friendvm);
|
||||
@ -85,7 +85,7 @@ rabbit::VirtualMachine* rabbit::sq_newthread(rabbit::VirtualMachine* friendvm, i
|
||||
rabbit::VirtualMachine *v = new (allocatedData) rabbit::VirtualMachine(ss);
|
||||
ss->_root_vm = v;
|
||||
|
||||
if(v->init(friendvm, initialstacksize)) {
|
||||
if(v->init(friendvm)) {
|
||||
friendvm->push(v);
|
||||
return v;
|
||||
} else {
|
||||
@ -151,15 +151,11 @@ int64_t rabbit::sq_getversion()
|
||||
rabbit::Result rabbit::sq_compile(rabbit::VirtualMachine* v,SQLEXREADFUNC read,rabbit::UserPointer p,const char *sourcename,rabbit::Bool raiseerror)
|
||||
{
|
||||
rabbit::ObjectPtr o;
|
||||
#ifndef NO_COMPILER
|
||||
if(compile(v, read, p, sourcename, o, raiseerror?true:false, _get_shared_state(v)->_debuginfo)) {
|
||||
v->push(rabbit::Closure::create(_get_shared_state(v), o.toFunctionProto(), v->_roottable.toTable()->getWeakRef(rabbit::OT_TABLE)));
|
||||
return SQ_OK;
|
||||
}
|
||||
return SQ_ERROR;
|
||||
#else
|
||||
return sq_throwerror(v,"this is a no compiler build");
|
||||
#endif
|
||||
}
|
||||
|
||||
void rabbit::sq_enabledebuginfo(rabbit::VirtualMachine* v, rabbit::Bool enable)
|
||||
|
@ -238,9 +238,8 @@ static int64_t base_compilestring(rabbit::VirtualMachine* v)
|
||||
static int64_t base_newthread(rabbit::VirtualMachine* v)
|
||||
{
|
||||
rabbit::ObjectPtr &func = stack_get(v,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);
|
||||
sq_move(newv,v,-2);
|
||||
rabbit::VirtualMachine* newv = sq_newthread(v);
|
||||
sq_move(newv, v, -2);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user