[DEV] remove store compiled file
This commit is contained in:
parent
6ec3f05c5d
commit
0b9cd5c735
@ -72,9 +72,6 @@ void PrintUsage()
|
|||||||
{
|
{
|
||||||
fprintf(stderr,"usage: sq <options> <scriptpath [args]>.\n"
|
fprintf(stderr,"usage: sq <options> <scriptpath [args]>.\n"
|
||||||
"Available options are:\n"
|
"Available options are:\n"
|
||||||
" -c compiles the file to bytecode(default output 'out.karrot')\n"
|
|
||||||
" -o specifies output file for the -c option\n"
|
|
||||||
" -c compiles only\n"
|
|
||||||
" -d generates debug infos\n"
|
" -d generates debug infos\n"
|
||||||
" -v displays version infos\n"
|
" -v displays version infos\n"
|
||||||
" -h prints help\n");
|
" -h prints help\n");
|
||||||
@ -87,8 +84,6 @@ void PrintUsage()
|
|||||||
int getargs(rabbit::VirtualMachine* v,int argc, char* argv[],int64_t *retval)
|
int getargs(rabbit::VirtualMachine* v,int argc, char* argv[],int64_t *retval)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int compiles_only = 0;
|
|
||||||
char * output = NULL;
|
|
||||||
*retval = 0;
|
*retval = 0;
|
||||||
if(argc>1)
|
if(argc>1)
|
||||||
{
|
{
|
||||||
@ -104,14 +99,6 @@ int getargs(rabbit::VirtualMachine* v,int argc, char* argv[],int64_t *retval)
|
|||||||
case 'd':
|
case 'd':
|
||||||
sq_enabledebuginfo(v,1);
|
sq_enabledebuginfo(v,1);
|
||||||
break;
|
break;
|
||||||
case 'c':
|
|
||||||
compiles_only = 1;
|
|
||||||
break;
|
|
||||||
case 'o':
|
|
||||||
if(arg < argc) {
|
|
||||||
arg++;
|
|
||||||
output = argv[arg];
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
PrintVersionInfos();
|
PrintVersionInfos();
|
||||||
@ -140,49 +127,28 @@ int getargs(rabbit::VirtualMachine* v,int argc, char* argv[],int64_t *retval)
|
|||||||
|
|
||||||
arg++;
|
arg++;
|
||||||
|
|
||||||
//sq_pushstring(v,"ARGS",-1);
|
if(SQ_SUCCEEDED(rabbit::std::loadfile(v,filename,SQTrue))) {
|
||||||
//sq_newarray(v,0);
|
int callargs = 1;
|
||||||
|
sq_pushroottable(v);
|
||||||
//sq_createslot(v,-3);
|
for(i=arg;i<argc;i++)
|
||||||
//sq_pop(v,1);
|
{
|
||||||
if(compiles_only) {
|
const char *a;
|
||||||
if(SQ_SUCCEEDED(rabbit::std::loadfile(v,filename,SQTrue))){
|
a=argv[i];
|
||||||
const char *outfile = "out.karrot";
|
sq_pushstring(v,a,-1);
|
||||||
if(output) {
|
callargs++;
|
||||||
outfile = output;
|
|
||||||
}
|
|
||||||
if(SQ_SUCCEEDED(rabbit::std::writeclosuretofile(v,outfile)))
|
|
||||||
return _DONE;
|
|
||||||
}
|
}
|
||||||
}
|
if(SQ_SUCCEEDED(sq_call(v,callargs,SQTrue,SQTrue))) {
|
||||||
else {
|
rabbit::ObjectType type = sq_gettype(v,-1);
|
||||||
//if(SQ_SUCCEEDED(rabbit::std::dofile(v,filename,SQFalse,SQTrue))) {
|
if(type == rabbit::OT_INTEGER) {
|
||||||
//return _DONE;
|
*retval = type;
|
||||||
//}
|
sq_getinteger(v,-1,retval);
|
||||||
if(SQ_SUCCEEDED(rabbit::std::loadfile(v,filename,SQTrue))) {
|
|
||||||
int callargs = 1;
|
|
||||||
sq_pushroottable(v);
|
|
||||||
for(i=arg;i<argc;i++)
|
|
||||||
{
|
|
||||||
const char *a;
|
|
||||||
a=argv[i];
|
|
||||||
sq_pushstring(v,a,-1);
|
|
||||||
callargs++;
|
|
||||||
//sq_arrayappend(v,-2);
|
|
||||||
}
|
}
|
||||||
if(SQ_SUCCEEDED(sq_call(v,callargs,SQTrue,SQTrue))) {
|
return _DONE;
|
||||||
rabbit::ObjectType type = sq_gettype(v,-1);
|
|
||||||
if(type == rabbit::OT_INTEGER) {
|
|
||||||
*retval = type;
|
|
||||||
sq_getinteger(v,-1,retval);
|
|
||||||
}
|
|
||||||
return _DONE;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return _ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
return _ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
//if this point is reached an error occurred
|
//if this point is reached an error occurred
|
||||||
{
|
{
|
||||||
|
@ -317,41 +317,38 @@ rabbit::Result rabbit::std::loadfile(rabbit::VirtualMachine* v,const char *filen
|
|||||||
//probably an empty file
|
//probably an empty file
|
||||||
us = 0;
|
us = 0;
|
||||||
}
|
}
|
||||||
if(us == SQ_BYTECODE_STREAM_TAG) { //BYTECODE
|
switch (us) {
|
||||||
rabbit::std::fseek(file,0,SQ_SEEK_SET);
|
//gotta swap the next 2 lines on BIG endian machines
|
||||||
if(SQ_SUCCEEDED(sq_readclosure(v,file_read,file))) {
|
case 0xFFFE:
|
||||||
rabbit::std::fclose(file);
|
func = _io_file_lexfeed_UCS2_BE;
|
||||||
return SQ_OK;
|
break; //UTF-16 little endian;
|
||||||
}
|
case 0xFEFF:
|
||||||
|
func = _io_file_lexfeed_UCS2_LE;
|
||||||
|
break; //UTF-16 big endian;
|
||||||
|
case 0xBBEF:
|
||||||
|
if(rabbit::std::fread(&uc,1,sizeof(uc),file) == 0) {
|
||||||
|
rabbit::std::fclose(file);
|
||||||
|
return sq_throwerror(v,"io error");
|
||||||
|
}
|
||||||
|
if(uc != 0xBF) {
|
||||||
|
rabbit::std::fclose(file);
|
||||||
|
return sq_throwerror(v,"Unrecognized encoding");
|
||||||
|
}
|
||||||
|
func = _io_file_lexfeed_PLAIN;
|
||||||
|
break;
|
||||||
|
//UTF-8 ;
|
||||||
|
default:
|
||||||
|
rabbit::std::fseek(file,0,SQ_SEEK_SET);
|
||||||
|
break;
|
||||||
|
// ascii
|
||||||
}
|
}
|
||||||
else { //SCRIPT
|
IOBuffer buffer;
|
||||||
|
buffer.ptr = 0;
|
||||||
switch(us)
|
buffer.size = 0;
|
||||||
{
|
buffer.file = file;
|
||||||
//gotta swap the next 2 lines on BIG endian machines
|
if(SQ_SUCCEEDED(sq_compile(v,func,&buffer,filename,printerror))){
|
||||||
case 0xFFFE: func = _io_file_lexfeed_UCS2_BE; break;//UTF-16 little endian;
|
rabbit::std::fclose(file);
|
||||||
case 0xFEFF: func = _io_file_lexfeed_UCS2_LE; break;//UTF-16 big endian;
|
return SQ_OK;
|
||||||
case 0xBBEF:
|
|
||||||
if(rabbit::std::fread(&uc,1,sizeof(uc),file) == 0) {
|
|
||||||
rabbit::std::fclose(file);
|
|
||||||
return sq_throwerror(v,"io error");
|
|
||||||
}
|
|
||||||
if(uc != 0xBF) {
|
|
||||||
rabbit::std::fclose(file);
|
|
||||||
return sq_throwerror(v,"Unrecognized encoding");
|
|
||||||
}
|
|
||||||
func = _io_file_lexfeed_PLAIN;
|
|
||||||
break;//UTF-8 ;
|
|
||||||
default: rabbit::std::fseek(file,0,SQ_SEEK_SET); break; // ascii
|
|
||||||
}
|
|
||||||
IOBuffer buffer;
|
|
||||||
buffer.ptr = 0;
|
|
||||||
buffer.size = 0;
|
|
||||||
buffer.file = file;
|
|
||||||
if(SQ_SUCCEEDED(sq_compile(v,func,&buffer,filename,printerror))){
|
|
||||||
rabbit::std::fclose(file);
|
|
||||||
return SQ_OK;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
rabbit::std::fclose(file);
|
rabbit::std::fclose(file);
|
||||||
return SQ_ERROR;
|
return SQ_ERROR;
|
||||||
@ -376,18 +373,6 @@ rabbit::Result rabbit::std::dofile(rabbit::VirtualMachine* v,const char *filenam
|
|||||||
return SQ_ERROR;
|
return SQ_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
rabbit::Result rabbit::std::writeclosuretofile(rabbit::VirtualMachine* v,const char *filename)
|
|
||||||
{
|
|
||||||
SQFILE file = rabbit::std::fopen(filename,"wb+");
|
|
||||||
if(!file) return sq_throwerror(v,"cannot open the file");
|
|
||||||
if(SQ_SUCCEEDED(sq_writeclosure(v,file_write,file))) {
|
|
||||||
rabbit::std::fclose(file);
|
|
||||||
return SQ_OK;
|
|
||||||
}
|
|
||||||
rabbit::std::fclose(file);
|
|
||||||
return SQ_ERROR; //forward the error
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t _g_io_loadfile(rabbit::VirtualMachine* v)
|
int64_t _g_io_loadfile(rabbit::VirtualMachine* v)
|
||||||
{
|
{
|
||||||
const char *filename;
|
const char *filename;
|
||||||
@ -401,15 +386,6 @@ int64_t _g_io_loadfile(rabbit::VirtualMachine* v)
|
|||||||
return SQ_ERROR; //propagates the error
|
return SQ_ERROR; //propagates the error
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t _g_io_writeclosuretofile(rabbit::VirtualMachine* v)
|
|
||||||
{
|
|
||||||
const char *filename;
|
|
||||||
sq_getstring(v,2,&filename);
|
|
||||||
if(SQ_SUCCEEDED(rabbit::std::writeclosuretofile(v,filename)))
|
|
||||||
return 1;
|
|
||||||
return SQ_ERROR; //propagates the error
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t _g_io_dofile(rabbit::VirtualMachine* v)
|
int64_t _g_io_dofile(rabbit::VirtualMachine* v)
|
||||||
{
|
{
|
||||||
const char *filename;
|
const char *filename;
|
||||||
@ -428,7 +404,6 @@ int64_t _g_io_dofile(rabbit::VirtualMachine* v)
|
|||||||
static const rabbit::RegFunction iolib_funcs[]={
|
static const rabbit::RegFunction iolib_funcs[]={
|
||||||
_DECL_GLOBALIO_FUNC(loadfile,-2,".sb"),
|
_DECL_GLOBALIO_FUNC(loadfile,-2,".sb"),
|
||||||
_DECL_GLOBALIO_FUNC(dofile,-2,".sb"),
|
_DECL_GLOBALIO_FUNC(dofile,-2,".sb"),
|
||||||
_DECL_GLOBALIO_FUNC(writeclosuretofile,3,".sc"),
|
|
||||||
{NULL,(SQFUNCTION)0,0,NULL}
|
{NULL,(SQFUNCTION)0,0,NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -44,7 +44,6 @@ rabbit::Result getfile(rabbit::VirtualMachine* v, int64_t idx, SQFILE *file);
|
|||||||
//compiler helpers
|
//compiler helpers
|
||||||
rabbit::Result loadfile(rabbit::VirtualMachine* v,const char *filename,rabbit::Bool printerror);
|
rabbit::Result loadfile(rabbit::VirtualMachine* v,const char *filename,rabbit::Bool printerror);
|
||||||
rabbit::Result dofile(rabbit::VirtualMachine* v,const char *filename,rabbit::Bool retval,rabbit::Bool printerror);
|
rabbit::Result dofile(rabbit::VirtualMachine* v,const char *filename,rabbit::Bool retval,rabbit::Bool printerror);
|
||||||
rabbit::Result writeclosuretofile(rabbit::VirtualMachine* v,const char *filename);
|
|
||||||
|
|
||||||
rabbit::Result register_iolib(rabbit::VirtualMachine* v);
|
rabbit::Result register_iolib(rabbit::VirtualMachine* v);
|
||||||
|
|
||||||
|
@ -23,125 +23,6 @@
|
|||||||
#include <rabbit/RefCounted.hpp>
|
#include <rabbit/RefCounted.hpp>
|
||||||
#include <rabbit/squtils.hpp>
|
#include <rabbit/squtils.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool rabbit::SafeWrite(rabbit::VirtualMachine* v,SQWRITEFUNC write,rabbit::UserPointer up,rabbit::UserPointer dest,int64_t size)
|
|
||||||
{
|
|
||||||
if(write(up,dest,size) != size) {
|
|
||||||
v->raise_error("io error (write function failure)");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool rabbit::SafeRead(rabbit::VirtualMachine* v,SQWRITEFUNC read,rabbit::UserPointer up,rabbit::UserPointer dest,int64_t size)
|
|
||||||
{
|
|
||||||
if(size && read(up,dest,size) != size) {
|
|
||||||
v->raise_error("io error, read function failure, the origin stream could be corrupted/trucated");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool rabbit::WriteTag(rabbit::VirtualMachine* v,SQWRITEFUNC write,rabbit::UserPointer up,uint32_t tag)
|
|
||||||
{
|
|
||||||
return SafeWrite(v,write,up,&tag,sizeof(tag));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool rabbit::CheckTag(rabbit::VirtualMachine* v,SQWRITEFUNC read,rabbit::UserPointer up,uint32_t tag)
|
|
||||||
{
|
|
||||||
uint32_t t;
|
|
||||||
_CHECK_IO(SafeRead(v,read,up,&t,sizeof(t)));
|
|
||||||
if(t != tag){
|
|
||||||
v->raise_error("invalid or corrupted closure stream");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool rabbit::WriteObject(rabbit::VirtualMachine* v,rabbit::UserPointer up,SQWRITEFUNC write,rabbit::ObjectPtr &o)
|
|
||||||
{
|
|
||||||
uint32_t _type = (uint32_t)o.getType();
|
|
||||||
_CHECK_IO(SafeWrite(v,write,up,&_type,sizeof(_type)));
|
|
||||||
switch(o.getType()){
|
|
||||||
case rabbit::OT_STRING:
|
|
||||||
_CHECK_IO(SafeWrite(v,write,up,&o.toString()->_len,sizeof(int64_t)));
|
|
||||||
_CHECK_IO(SafeWrite(v,write,up,o.getStringValue(),sq_rsl(o.toString()->_len)));
|
|
||||||
break;
|
|
||||||
case rabbit::OT_BOOL:
|
|
||||||
case rabbit::OT_INTEGER:
|
|
||||||
_CHECK_IO(SafeWrite(v,write,up,&o.toInteger(),sizeof(int64_t)));break;
|
|
||||||
case rabbit::OT_FLOAT:
|
|
||||||
_CHECK_IO(SafeWrite(v,write,up,&o.toFloat(),sizeof(float_t)));break;
|
|
||||||
case rabbit::OT_NULL:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
v->raise_error("cannot serialize a %s",getTypeName(o));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool rabbit::ReadObject(rabbit::VirtualMachine* v,rabbit::UserPointer up,SQREADFUNC read,rabbit::ObjectPtr &o)
|
|
||||||
{
|
|
||||||
uint32_t _type;
|
|
||||||
_CHECK_IO(SafeRead(v,read,up,&_type,sizeof(_type)));
|
|
||||||
rabbit::ObjectType t = (rabbit::ObjectType)_type;
|
|
||||||
switch(t){
|
|
||||||
case rabbit::OT_STRING:{
|
|
||||||
int64_t len;
|
|
||||||
_CHECK_IO(SafeRead(v,read,up,&len,sizeof(int64_t)));
|
|
||||||
_CHECK_IO(SafeRead(v,read,up,_get_shared_state(v)->getScratchPad(sq_rsl(len)),sq_rsl(len)));
|
|
||||||
o=rabbit::String::create(_get_shared_state(v),_get_shared_state(v)->getScratchPad(-1),len);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case rabbit::OT_INTEGER:{
|
|
||||||
int64_t i;
|
|
||||||
_CHECK_IO(SafeRead(v,read,up,&i,sizeof(int64_t))); o = i; break;
|
|
||||||
}
|
|
||||||
case rabbit::OT_BOOL:{
|
|
||||||
int64_t i;
|
|
||||||
_CHECK_IO(SafeRead(v,read,up,&i,sizeof(int64_t))); o._type = rabbit::OT_BOOL; o._unVal.nInteger = i; break;
|
|
||||||
}
|
|
||||||
case rabbit::OT_FLOAT:{
|
|
||||||
float_t f;
|
|
||||||
_CHECK_IO(SafeRead(v,read,up,&f,sizeof(float_t))); o = f; break;
|
|
||||||
}
|
|
||||||
case rabbit::OT_NULL:
|
|
||||||
o.Null();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
v->raise_error("cannot serialize a %s",IdType2Name(t));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool rabbit::Closure::save(rabbit::VirtualMachine *v,rabbit::UserPointer up,SQWRITEFUNC write)
|
|
||||||
{
|
|
||||||
_CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_HEAD));
|
|
||||||
_CHECK_IO(WriteTag(v,write,up,sizeof(char)));
|
|
||||||
_CHECK_IO(WriteTag(v,write,up,sizeof(int64_t)));
|
|
||||||
_CHECK_IO(WriteTag(v,write,up,sizeof(float_t)));
|
|
||||||
_CHECK_IO(_function->save(v,up,write));
|
|
||||||
_CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_TAIL));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool rabbit::Closure::load(rabbit::VirtualMachine *v,rabbit::UserPointer up,SQREADFUNC read,rabbit::ObjectPtr &ret)
|
|
||||||
{
|
|
||||||
_CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_HEAD));
|
|
||||||
_CHECK_IO(CheckTag(v,read,up,sizeof(char)));
|
|
||||||
_CHECK_IO(CheckTag(v,read,up,sizeof(int64_t)));
|
|
||||||
_CHECK_IO(CheckTag(v,read,up,sizeof(float_t)));
|
|
||||||
rabbit::ObjectPtr func;
|
|
||||||
_CHECK_IO(rabbit::FunctionProto::load(v,up,read,func));
|
|
||||||
_CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_TAIL));
|
|
||||||
ret = rabbit::Closure::create(_get_shared_state(v),func.toFunctionProto(),v->_roottable.toTable()->getWeakRef(rabbit::OT_TABLE));
|
|
||||||
//FIXME: load an root for this closure
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
rabbit::Closure::~Closure() {
|
rabbit::Closure::~Closure() {
|
||||||
__Objrelease(_root);
|
__Objrelease(_root);
|
||||||
__Objrelease(_env);
|
__Objrelease(_env);
|
||||||
|
@ -33,8 +33,6 @@ namespace rabbit {
|
|||||||
Closure *clone();
|
Closure *clone();
|
||||||
~Closure();
|
~Closure();
|
||||||
|
|
||||||
bool save(rabbit::VirtualMachine *v,rabbit::UserPointer up,SQWRITEFUNC write);
|
|
||||||
static bool load(rabbit::VirtualMachine *v,rabbit::UserPointer up,SQREADFUNC read,rabbit::ObjectPtr &ret);
|
|
||||||
rabbit::WeakRef *_env;
|
rabbit::WeakRef *_env;
|
||||||
rabbit::WeakRef *_root;
|
rabbit::WeakRef *_root;
|
||||||
rabbit::Class *_base;
|
rabbit::Class *_base;
|
||||||
@ -42,12 +40,6 @@ namespace rabbit {
|
|||||||
rabbit::ObjectPtr *_outervalues;
|
rabbit::ObjectPtr *_outervalues;
|
||||||
rabbit::ObjectPtr *_defaultparams;
|
rabbit::ObjectPtr *_defaultparams;
|
||||||
};
|
};
|
||||||
bool SafeWrite(rabbit::VirtualMachine* v,SQWRITEFUNC write,rabbit::UserPointer up,rabbit::UserPointer dest,int64_t size);
|
|
||||||
bool SafeRead(rabbit::VirtualMachine* v,SQWRITEFUNC read,rabbit::UserPointer up,rabbit::UserPointer dest,int64_t size);
|
|
||||||
bool WriteTag(rabbit::VirtualMachine* v,SQWRITEFUNC write,rabbit::UserPointer up,uint32_t tag);
|
|
||||||
bool CheckTag(rabbit::VirtualMachine* v,SQWRITEFUNC read,rabbit::UserPointer up,uint32_t tag);
|
|
||||||
bool WriteObject(rabbit::VirtualMachine* v,rabbit::UserPointer up,SQWRITEFUNC write,rabbit::ObjectPtr &o);
|
|
||||||
bool ReadObject(rabbit::VirtualMachine* v,rabbit::UserPointer up,SQREADFUNC read,rabbit::ObjectPtr &o);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
#define _CHECK_IO(exp) { if(!exp)return false; }
|
#define _CHECK_IO(exp) { if(!exp)return false; }
|
||||||
|
@ -131,151 +131,3 @@ rabbit::FunctionProto::FunctionProto(rabbit::SharedState *ss)
|
|||||||
rabbit::FunctionProto::~FunctionProto()
|
rabbit::FunctionProto::~FunctionProto()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool rabbit::FunctionProto::save(rabbit::VirtualMachine *v,rabbit::UserPointer up,SQWRITEFUNC write)
|
|
||||||
{
|
|
||||||
int64_t i,nliterals = _nliterals,nparameters = _nparameters;
|
|
||||||
int64_t noutervalues = _noutervalues,nlocalvarinfos = _nlocalvarinfos;
|
|
||||||
int64_t nlineinfos=_nlineinfos,ninstructions = _ninstructions,nfunctions=_nfunctions;
|
|
||||||
int64_t ndefaultparams = _ndefaultparams;
|
|
||||||
_CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_PART));
|
|
||||||
_CHECK_IO(WriteObject(v,up,write,_sourcename));
|
|
||||||
_CHECK_IO(WriteObject(v,up,write,_name));
|
|
||||||
_CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_PART));
|
|
||||||
_CHECK_IO(SafeWrite(v,write,up,&nliterals,sizeof(nliterals)));
|
|
||||||
_CHECK_IO(SafeWrite(v,write,up,&nparameters,sizeof(nparameters)));
|
|
||||||
_CHECK_IO(SafeWrite(v,write,up,&noutervalues,sizeof(noutervalues)));
|
|
||||||
_CHECK_IO(SafeWrite(v,write,up,&nlocalvarinfos,sizeof(nlocalvarinfos)));
|
|
||||||
_CHECK_IO(SafeWrite(v,write,up,&nlineinfos,sizeof(nlineinfos)));
|
|
||||||
_CHECK_IO(SafeWrite(v,write,up,&ndefaultparams,sizeof(ndefaultparams)));
|
|
||||||
_CHECK_IO(SafeWrite(v,write,up,&ninstructions,sizeof(ninstructions)));
|
|
||||||
_CHECK_IO(SafeWrite(v,write,up,&nfunctions,sizeof(nfunctions)));
|
|
||||||
_CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_PART));
|
|
||||||
for(i=0;i<nliterals;i++){
|
|
||||||
_CHECK_IO(WriteObject(v,up,write,_literals[i]));
|
|
||||||
}
|
|
||||||
|
|
||||||
_CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_PART));
|
|
||||||
for(i=0;i<nparameters;i++){
|
|
||||||
_CHECK_IO(WriteObject(v,up,write,_parameters[i]));
|
|
||||||
}
|
|
||||||
|
|
||||||
_CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_PART));
|
|
||||||
for(i=0;i<noutervalues;i++){
|
|
||||||
_CHECK_IO(SafeWrite(v,write,up,&_outervalues[i]._type,sizeof(uint64_t)));
|
|
||||||
_CHECK_IO(WriteObject(v,up,write,_outervalues[i]._src));
|
|
||||||
_CHECK_IO(WriteObject(v,up,write,_outervalues[i]._name));
|
|
||||||
}
|
|
||||||
|
|
||||||
_CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_PART));
|
|
||||||
for(i=0;i<nlocalvarinfos;i++){
|
|
||||||
rabbit::LocalVarInfo &lvi=_localvarinfos[i];
|
|
||||||
_CHECK_IO(WriteObject(v,up,write,lvi._name));
|
|
||||||
_CHECK_IO(SafeWrite(v,write,up,&lvi._pos,sizeof(uint64_t)));
|
|
||||||
_CHECK_IO(SafeWrite(v,write,up,&lvi._start_op,sizeof(uint64_t)));
|
|
||||||
_CHECK_IO(SafeWrite(v,write,up,&lvi._end_op,sizeof(uint64_t)));
|
|
||||||
}
|
|
||||||
|
|
||||||
_CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_PART));
|
|
||||||
_CHECK_IO(SafeWrite(v,write,up,_lineinfos,sizeof(rabbit::LineInfo)*nlineinfos));
|
|
||||||
|
|
||||||
_CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_PART));
|
|
||||||
_CHECK_IO(SafeWrite(v,write,up,_defaultparams,sizeof(int64_t)*ndefaultparams));
|
|
||||||
|
|
||||||
_CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_PART));
|
|
||||||
_CHECK_IO(SafeWrite(v,write,up,_instructions,sizeof(rabbit::Instruction)*ninstructions));
|
|
||||||
|
|
||||||
_CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_PART));
|
|
||||||
for(i=0;i<nfunctions;i++){
|
|
||||||
_CHECK_IO(_functions[i].toFunctionProto()->save(v,up,write));
|
|
||||||
}
|
|
||||||
_CHECK_IO(SafeWrite(v,write,up,&_stacksize,sizeof(_stacksize)));
|
|
||||||
_CHECK_IO(SafeWrite(v,write,up,&_bgenerator,sizeof(_bgenerator)));
|
|
||||||
_CHECK_IO(SafeWrite(v,write,up,&_varparams,sizeof(_varparams)));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool rabbit::FunctionProto::load(rabbit::VirtualMachine *v,rabbit::UserPointer up,SQREADFUNC read,rabbit::ObjectPtr &ret)
|
|
||||||
{
|
|
||||||
int64_t i, nliterals,nparameters;
|
|
||||||
int64_t noutervalues ,nlocalvarinfos ;
|
|
||||||
int64_t nlineinfos,ninstructions ,nfunctions,ndefaultparams ;
|
|
||||||
rabbit::ObjectPtr sourcename, name;
|
|
||||||
rabbit::ObjectPtr o;
|
|
||||||
_CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
|
|
||||||
_CHECK_IO(ReadObject(v, up, read, sourcename));
|
|
||||||
_CHECK_IO(ReadObject(v, up, read, name));
|
|
||||||
|
|
||||||
_CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
|
|
||||||
_CHECK_IO(SafeRead(v,read,up, &nliterals, sizeof(nliterals)));
|
|
||||||
_CHECK_IO(SafeRead(v,read,up, &nparameters, sizeof(nparameters)));
|
|
||||||
_CHECK_IO(SafeRead(v,read,up, &noutervalues, sizeof(noutervalues)));
|
|
||||||
_CHECK_IO(SafeRead(v,read,up, &nlocalvarinfos, sizeof(nlocalvarinfos)));
|
|
||||||
_CHECK_IO(SafeRead(v,read,up, &nlineinfos, sizeof(nlineinfos)));
|
|
||||||
_CHECK_IO(SafeRead(v,read,up, &ndefaultparams, sizeof(ndefaultparams)));
|
|
||||||
_CHECK_IO(SafeRead(v,read,up, &ninstructions, sizeof(ninstructions)));
|
|
||||||
_CHECK_IO(SafeRead(v,read,up, &nfunctions, sizeof(nfunctions)));
|
|
||||||
|
|
||||||
|
|
||||||
rabbit::FunctionProto *f = rabbit::FunctionProto::create(NULL,ninstructions,nliterals,nparameters,
|
|
||||||
nfunctions,noutervalues,nlineinfos,nlocalvarinfos,ndefaultparams);
|
|
||||||
rabbit::ObjectPtr proto = f; //gets a ref in case of failure
|
|
||||||
f->_sourcename = sourcename;
|
|
||||||
f->_name = name;
|
|
||||||
|
|
||||||
_CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
|
|
||||||
|
|
||||||
for(i = 0;i < nliterals; i++){
|
|
||||||
_CHECK_IO(ReadObject(v, up, read, o));
|
|
||||||
f->_literals[i] = o;
|
|
||||||
}
|
|
||||||
_CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
|
|
||||||
|
|
||||||
for(i = 0; i < nparameters; i++){
|
|
||||||
_CHECK_IO(ReadObject(v, up, read, o));
|
|
||||||
f->_parameters[i] = o;
|
|
||||||
}
|
|
||||||
_CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
|
|
||||||
|
|
||||||
for(i = 0; i < noutervalues; i++){
|
|
||||||
uint64_t type;
|
|
||||||
rabbit::ObjectPtr name;
|
|
||||||
_CHECK_IO(SafeRead(v,read,up, &type, sizeof(uint64_t)));
|
|
||||||
_CHECK_IO(ReadObject(v, up, read, o));
|
|
||||||
_CHECK_IO(ReadObject(v, up, read, name));
|
|
||||||
f->_outervalues[i] = rabbit::OuterVar(name,o, (rabbit::OuterType)type);
|
|
||||||
}
|
|
||||||
_CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
|
|
||||||
|
|
||||||
for(i = 0; i < nlocalvarinfos; i++){
|
|
||||||
rabbit::LocalVarInfo lvi;
|
|
||||||
_CHECK_IO(ReadObject(v, up, read, lvi._name));
|
|
||||||
_CHECK_IO(SafeRead(v,read,up, &lvi._pos, sizeof(uint64_t)));
|
|
||||||
_CHECK_IO(SafeRead(v,read,up, &lvi._start_op, sizeof(uint64_t)));
|
|
||||||
_CHECK_IO(SafeRead(v,read,up, &lvi._end_op, sizeof(uint64_t)));
|
|
||||||
f->_localvarinfos[i] = lvi;
|
|
||||||
}
|
|
||||||
_CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
|
|
||||||
_CHECK_IO(SafeRead(v,read,up, f->_lineinfos, sizeof(rabbit::LineInfo)*nlineinfos));
|
|
||||||
|
|
||||||
_CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
|
|
||||||
_CHECK_IO(SafeRead(v,read,up, f->_defaultparams, sizeof(int64_t)*ndefaultparams));
|
|
||||||
|
|
||||||
_CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
|
|
||||||
_CHECK_IO(SafeRead(v,read,up, f->_instructions, sizeof(rabbit::Instruction)*ninstructions));
|
|
||||||
|
|
||||||
_CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
|
|
||||||
for(i = 0; i < nfunctions; i++){
|
|
||||||
_CHECK_IO(o.toFunctionProto()->load(v, up, read, o));
|
|
||||||
f->_functions[i] = o;
|
|
||||||
}
|
|
||||||
_CHECK_IO(SafeRead(v,read,up, &f->_stacksize, sizeof(f->_stacksize)));
|
|
||||||
_CHECK_IO(SafeRead(v,read,up, &f->_bgenerator, sizeof(f->_bgenerator)));
|
|
||||||
_CHECK_IO(SafeRead(v,read,up, &f->_varparams, sizeof(f->_varparams)));
|
|
||||||
|
|
||||||
ret = f;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -37,8 +37,6 @@ namespace rabbit {
|
|||||||
|
|
||||||
const char* getLocal(rabbit::VirtualMachine *v,uint64_t stackbase,uint64_t nseq,uint64_t nop);
|
const char* getLocal(rabbit::VirtualMachine *v,uint64_t stackbase,uint64_t nseq,uint64_t nop);
|
||||||
int64_t getLine(rabbit::Instruction *curr);
|
int64_t getLine(rabbit::Instruction *curr);
|
||||||
bool save(rabbit::VirtualMachine *v,rabbit::UserPointer up,SQWRITEFUNC write);
|
|
||||||
static bool load(rabbit::VirtualMachine *v,rabbit::UserPointer up,SQREADFUNC read,rabbit::ObjectPtr &ret);
|
|
||||||
rabbit::ObjectPtr _sourcename;
|
rabbit::ObjectPtr _sourcename;
|
||||||
rabbit::ObjectPtr _name;
|
rabbit::ObjectPtr _name;
|
||||||
int64_t _stacksize;
|
int64_t _stacksize;
|
||||||
|
@ -198,10 +198,6 @@ uint64_t sq_getvmrefcount(rabbit::VirtualMachine* v, const rabbit::Object *po);
|
|||||||
int64_t sq_collectgarbage(rabbit::VirtualMachine* v);
|
int64_t sq_collectgarbage(rabbit::VirtualMachine* v);
|
||||||
rabbit::Result sq_resurrectunreachable(rabbit::VirtualMachine* v);
|
rabbit::Result sq_resurrectunreachable(rabbit::VirtualMachine* v);
|
||||||
|
|
||||||
/*serialization*/
|
|
||||||
rabbit::Result sq_writeclosure(rabbit::VirtualMachine* vm,SQWRITEFUNC writef,rabbit::UserPointer up);
|
|
||||||
rabbit::Result sq_readclosure(rabbit::VirtualMachine* vm,SQREADFUNC readf,rabbit::UserPointer up);
|
|
||||||
|
|
||||||
/*mem allocation*/
|
/*mem allocation*/
|
||||||
void *sq_malloc(uint64_t size);
|
void *sq_malloc(uint64_t size);
|
||||||
void *sq_realloc(void* p,uint64_t oldsize,uint64_t newsize);
|
void *sq_realloc(void* p,uint64_t oldsize,uint64_t newsize);
|
||||||
|
@ -1350,35 +1350,6 @@ void rabbit::sq_setcompilererrorhandler(rabbit::VirtualMachine* v,SQCOMPILERERRO
|
|||||||
_get_shared_state(v)->_compilererrorhandler = f;
|
_get_shared_state(v)->_compilererrorhandler = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
rabbit::Result rabbit::sq_writeclosure(rabbit::VirtualMachine* v,SQWRITEFUNC w,rabbit::UserPointer up)
|
|
||||||
{
|
|
||||||
rabbit::ObjectPtr *o = NULL;
|
|
||||||
_GETSAFE_OBJ(v, -1, rabbit::OT_CLOSURE,o);
|
|
||||||
unsigned short tag = SQ_BYTECODE_STREAM_TAG;
|
|
||||||
if(o->toClosure()->_function->_noutervalues)
|
|
||||||
return sq_throwerror(v,"a closure with free variables bound cannot be serialized");
|
|
||||||
if(w(up,&tag,2) != 2)
|
|
||||||
return sq_throwerror(v,"io error");
|
|
||||||
if(!o->toClosure()->save(v,up,w))
|
|
||||||
return SQ_ERROR;
|
|
||||||
return SQ_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
rabbit::Result rabbit::sq_readclosure(rabbit::VirtualMachine* v,SQREADFUNC r,rabbit::UserPointer up)
|
|
||||||
{
|
|
||||||
rabbit::ObjectPtr closure;
|
|
||||||
|
|
||||||
unsigned short tag;
|
|
||||||
if(r(up,&tag,2) != 2)
|
|
||||||
return sq_throwerror(v,"io error");
|
|
||||||
if(tag != SQ_BYTECODE_STREAM_TAG)
|
|
||||||
return sq_throwerror(v,"invalid stream");
|
|
||||||
if(!rabbit::Closure::load(v,up,r,closure))
|
|
||||||
return SQ_ERROR;
|
|
||||||
v->push(closure);
|
|
||||||
return SQ_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
char * rabbit::sq_getscratchpad(rabbit::VirtualMachine* v,int64_t minsize)
|
char * rabbit::sq_getscratchpad(rabbit::VirtualMachine* v,int64_t minsize)
|
||||||
{
|
{
|
||||||
return _get_shared_state(v)->getScratchPad(minsize);
|
return _get_shared_state(v)->getScratchPad(minsize);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user