mirror of
https://github.com/nillerusr/source-engine.git
synced 2026-08-30 22:19:19 +00:00
WIP: port alien swarm and extend engine for asw
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
SQUIRREL= ..
|
||||
|
||||
|
||||
OUT= $(SQUIRREL)/lib/libsquirrel.a
|
||||
INCZ= -I$(SQUIRREL)/include -I. -Iinclude
|
||||
DEFS=
|
||||
LIB=
|
||||
|
||||
OBJS= \
|
||||
sqapi.o \
|
||||
sqbaselib.o \
|
||||
sqcompiler.o \
|
||||
sqdebug.o \
|
||||
sqlexer.o \
|
||||
sqobject.o \
|
||||
sqparser.o \
|
||||
sqstate.o \
|
||||
sqtable.o \
|
||||
sqvm.o \
|
||||
sqmem.o \
|
||||
sqclass.o
|
||||
|
||||
SRCS= \
|
||||
sqapi.cpp \
|
||||
sqbaselib.cpp \
|
||||
sqfuncstate.cpp \
|
||||
sqdebug.cpp \
|
||||
sqlexer.cpp \
|
||||
sqobject.cpp \
|
||||
sqcompiler.cpp \
|
||||
sqstate.cpp \
|
||||
sqtable.cpp \
|
||||
sqmem.cpp \
|
||||
sqvm.cpp \
|
||||
sqclass.cpp
|
||||
|
||||
|
||||
|
||||
sq32:
|
||||
gcc -O2 -fno-rtti -Wall -c $(SRCS) $(INCZ) $(DEFS)
|
||||
ar rc $(OUT) *.o
|
||||
rm *.o
|
||||
|
||||
sqprof:
|
||||
gcc -O2 -pg -fno-rtti -pie -gstabs -g3 -Wall -c $(SRCS) $(INCZ) $(DEFS)
|
||||
ar rc $(OUT) *.o
|
||||
rm *.o
|
||||
|
||||
sq64:
|
||||
gcc -O2 -D_SQ64 -fno-rtti -Wall -c $(SRCS) $(INCZ) $(DEFS)
|
||||
ar rc $(OUT) *.o
|
||||
rm *.o
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,98 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#ifndef _SQARRAY_H_
|
||||
#define _SQARRAY_H_
|
||||
|
||||
#if defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST)
|
||||
#include "memdbgon.h"
|
||||
#undef new // allow placement new
|
||||
#endif
|
||||
|
||||
struct SQArray : public CHAINABLE_OBJ
|
||||
{
|
||||
private:
|
||||
SQArray(SQSharedState *ss,SQInteger nsize){_values.resize(nsize); INIT_CHAIN();ADD_TO_CHAIN(&_ss(this)->_gc_chain,this);}
|
||||
~SQArray()
|
||||
{
|
||||
REMOVE_FROM_CHAIN(&_ss(this)->_gc_chain,this);
|
||||
}
|
||||
public:
|
||||
static SQArray* Create(SQSharedState *ss,SQInteger nInitialSize){
|
||||
SQArray *newarray=(SQArray*)SQ_MALLOC(sizeof(SQArray));
|
||||
new (newarray) SQArray(ss,nInitialSize);
|
||||
return newarray;
|
||||
}
|
||||
#ifndef NO_GARBAGE_COLLECTOR
|
||||
void Mark(SQCollectable **chain);
|
||||
#endif
|
||||
void Iterate( CSQStateIterator *pIterator );
|
||||
|
||||
void Finalize(){
|
||||
_values.resize(0);
|
||||
}
|
||||
bool Get(const SQInteger nidx,SQObjectPtr &val)
|
||||
{
|
||||
if(nidx>=0 && nidx<(SQInteger)_values.size()){
|
||||
SQObjectPtr &o = _values[nidx];
|
||||
val = _realval(o);
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
bool Set(const SQInteger nidx,const SQObjectPtr &val)
|
||||
{
|
||||
if(nidx>=0 && nidx<(SQInteger)_values.size()){
|
||||
_values[nidx]=val;
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
SQInteger Next(const SQObjectPtr &refpos,SQObjectPtr &outkey,SQObjectPtr &outval)
|
||||
{
|
||||
SQUnsignedInteger idx=TranslateIndex(refpos);
|
||||
while(idx<_values.size()){
|
||||
//first found
|
||||
outkey=(SQInteger)idx;
|
||||
SQObjectPtr &o = _values[idx];
|
||||
outval = _realval(o);
|
||||
//return idx for the next iteration
|
||||
return ++idx;
|
||||
}
|
||||
//nothing to iterate anymore
|
||||
return -1;
|
||||
}
|
||||
SQArray *Clone(){SQArray *anew=Create(_opt_ss(this),Size()); anew->_values.copy(_values); return anew; }
|
||||
SQInteger Size() const {return _values.size();}
|
||||
void Resize(SQInteger size,SQObjectPtr &fill = _null_) { _values.resize(size,fill); ShrinkIfNeeded(); }
|
||||
void Reserve(SQInteger size) { _values.reserve(size); }
|
||||
void Append(const SQObject &o){_values.push_back(o);}
|
||||
void Extend(const SQArray *a);
|
||||
SQObjectPtr &Top(){return _values.top();}
|
||||
void Pop(){_values.pop_back(); ShrinkIfNeeded(); }
|
||||
bool Insert(SQInteger idx,const SQObject &val){
|
||||
if(idx < 0 || idx > (SQInteger)_values.size())
|
||||
return false;
|
||||
_values.insert(idx,val);
|
||||
return true;
|
||||
}
|
||||
void ShrinkIfNeeded() {
|
||||
if(_values.size() <= _values.capacity()>>2) //shrink the array
|
||||
_values.shrinktofit();
|
||||
}
|
||||
bool Remove(SQInteger idx){
|
||||
if(idx < 0 || idx >= (SQInteger)_values.size())
|
||||
return false;
|
||||
_values.remove(idx);
|
||||
ShrinkIfNeeded();
|
||||
return true;
|
||||
}
|
||||
void Release()
|
||||
{
|
||||
sq_delete(this,SQArray);
|
||||
}
|
||||
SQObjectPtrVec _values;
|
||||
};
|
||||
|
||||
#if defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST)
|
||||
#include "memdbgoff.h"
|
||||
#endif
|
||||
#endif //_SQARRAY_H_
|
||||
@@ -0,0 +1,917 @@
|
||||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
#include "sqpcheader.h"
|
||||
#include "sqvm.h"
|
||||
#include "sqstring.h"
|
||||
#include "sqtable.h"
|
||||
#include "sqarray.h"
|
||||
#include "sqfuncproto.h"
|
||||
#include "sqclosure.h"
|
||||
#include "sqclass.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <ctype.h>
|
||||
#if defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST)
|
||||
#include "memdbgon.h"
|
||||
#endif
|
||||
|
||||
bool str2num(const SQChar *s,SQObjectPtr &res)
|
||||
{
|
||||
SQChar *end;
|
||||
if(scstrstr(s,_SC("."))){
|
||||
SQFloat r = SQFloat(scstrtod(s,&end));
|
||||
if(s == end) return false;
|
||||
res = r;
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
SQInteger r = SQInteger(scstrtol(s,&end,10));
|
||||
if(s == end) return false;
|
||||
res = r;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
static SQInteger base_dummy(HSQUIRRELVM v)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef NO_GARBAGE_COLLECTOR
|
||||
static SQInteger base_collectgarbage(HSQUIRRELVM v)
|
||||
{
|
||||
sq_pushinteger(v, sq_collectgarbage(v));
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
static SQInteger base_getroottable(HSQUIRRELVM v)
|
||||
{
|
||||
v->Push(v->_roottable);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger base_getconsttable(HSQUIRRELVM v)
|
||||
{
|
||||
v->Push(_ss(v)->_consts);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static SQInteger base_setroottable(HSQUIRRELVM v)
|
||||
{
|
||||
SQObjectPtr &o=stack_get(v,2);
|
||||
if(SQ_FAILED(sq_setroottable(v))) return SQ_ERROR;
|
||||
v->Push(o);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger base_setconsttable(HSQUIRRELVM v)
|
||||
{
|
||||
SQObjectPtr &o=stack_get(v,2);
|
||||
if(SQ_FAILED(sq_setconsttable(v))) return SQ_ERROR;
|
||||
v->Push(o);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger base_seterrorhandler(HSQUIRRELVM v)
|
||||
{
|
||||
sq_seterrorhandler(v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SQInteger base_setdebughook(HSQUIRRELVM v)
|
||||
{
|
||||
sq_setdebughook(v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SQInteger base_enabledebuginfo(HSQUIRRELVM v)
|
||||
{
|
||||
SQObjectPtr &o=stack_get(v,2);
|
||||
sq_enabledebuginfo(v,(type(o) != OT_NULL)?1:0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SQInteger base_getstackinfos(HSQUIRRELVM v)
|
||||
{
|
||||
SQInteger level;
|
||||
SQStackInfos si;
|
||||
SQInteger seq = 0;
|
||||
const SQChar *name = NULL;
|
||||
sq_getinteger(v, -1, &level);
|
||||
if (SQ_SUCCEEDED(sq_stackinfos(v, level, &si)))
|
||||
{
|
||||
const SQChar *fn = _SC("unknown");
|
||||
const SQChar *src = _SC("unknown");
|
||||
if(si.funcname)fn = si.funcname;
|
||||
if(si.source)src = si.source;
|
||||
sq_newtable(v);
|
||||
sq_pushstring(v, _SC("func"), -1);
|
||||
sq_pushstring(v, fn, -1);
|
||||
sq_createslot(v, -3);
|
||||
sq_pushstring(v, _SC("src"), -1);
|
||||
sq_pushstring(v, src, -1);
|
||||
sq_createslot(v, -3);
|
||||
sq_pushstring(v, _SC("line"), -1);
|
||||
sq_pushinteger(v, si.line);
|
||||
sq_createslot(v, -3);
|
||||
sq_pushstring(v, _SC("locals"), -1);
|
||||
sq_newtable(v);
|
||||
seq=0;
|
||||
while ((name = sq_getlocal(v, level, seq))) {
|
||||
sq_pushstring(v, name, -1);
|
||||
sq_push(v, -2);
|
||||
sq_createslot(v, -4);
|
||||
sq_pop(v, 1);
|
||||
seq++;
|
||||
}
|
||||
sq_createslot(v, -3);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SQInteger base_assert(HSQUIRRELVM v)
|
||||
{
|
||||
if(v->IsFalse(stack_get(v,2))){
|
||||
return sq_throwerror(v,_SC("assertion failed"));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SQInteger get_slice_params(HSQUIRRELVM v,SQInteger &sidx,SQInteger &eidx,SQObjectPtr &o)
|
||||
{
|
||||
SQInteger top = sq_gettop(v);
|
||||
sidx=0;
|
||||
eidx=0;
|
||||
o=stack_get(v,1);
|
||||
SQObjectPtr &start=stack_get(v,2);
|
||||
if(type(start)!=OT_NULL && sq_isnumeric(start)){
|
||||
sidx=tointeger(start);
|
||||
}
|
||||
if(top>2){
|
||||
SQObjectPtr &end=stack_get(v,3);
|
||||
if(sq_isnumeric(end)){
|
||||
eidx=tointeger(end);
|
||||
}
|
||||
}
|
||||
else {
|
||||
eidx = sq_getsize(v,1);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger base_print(HSQUIRRELVM v)
|
||||
{
|
||||
const SQChar *str;
|
||||
sq_tostring(v,2);
|
||||
sq_getstring(v,-1,&str);
|
||||
if(_ss(v)->_printfunc) _ss(v)->_printfunc(v,_SC("%s"),str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SQInteger base_compilestring(HSQUIRRELVM v)
|
||||
{
|
||||
SQInteger nargs=sq_gettop(v);
|
||||
const SQChar *src=NULL,*name=_SC("unnamedbuffer");
|
||||
SQInteger size;
|
||||
sq_getstring(v,2,&src);
|
||||
size=sq_getsize(v,2);
|
||||
if(nargs>2){
|
||||
sq_getstring(v,3,&name);
|
||||
}
|
||||
if(SQ_SUCCEEDED(sq_compilebuffer(v,src,size,name,SQFalse)))
|
||||
return 1;
|
||||
else
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
static SQInteger base_newthread(HSQUIRRELVM v)
|
||||
{
|
||||
SQObjectPtr &func = stack_get(v,2);
|
||||
SQInteger stksize = (_funcproto(_closure(func)->_function)->_stacksize << 1) +2;
|
||||
HSQUIRRELVM newv = sq_newthread(v, (stksize < MIN_STACK_OVERHEAD + 2)? MIN_STACK_OVERHEAD + 2 : stksize);
|
||||
sq_move(newv,v,-2);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger base_suspend(HSQUIRRELVM v)
|
||||
{
|
||||
return sq_suspendvm(v);
|
||||
}
|
||||
|
||||
static SQInteger base_array(HSQUIRRELVM v)
|
||||
{
|
||||
SQArray *a;
|
||||
SQObject &size = stack_get(v,2);
|
||||
if(sq_gettop(v) > 2) {
|
||||
a = SQArray::Create(_ss(v),0);
|
||||
a->Resize(tointeger(size),stack_get(v,3));
|
||||
}
|
||||
else {
|
||||
a = SQArray::Create(_ss(v),tointeger(size));
|
||||
}
|
||||
v->Push(a);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger base_type(HSQUIRRELVM v)
|
||||
{
|
||||
SQObjectPtr &o = stack_get(v,2);
|
||||
v->Push(SQString::Create(_ss(v),GetTypeName(o),-1));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQRegFunction base_funcs[]={
|
||||
//generic
|
||||
{_SC("seterrorhandler"),base_seterrorhandler,2, NULL},
|
||||
{_SC("setdebughook"),base_setdebughook,2, NULL},
|
||||
{_SC("enabledebuginfo"),base_enabledebuginfo,2, NULL},
|
||||
{_SC("getstackinfos"),base_getstackinfos,2, _SC(".n")},
|
||||
{_SC("getroottable"),base_getroottable,1, NULL},
|
||||
{_SC("setroottable"),base_setroottable,2, NULL},
|
||||
{_SC("getconsttable"),base_getconsttable,1, NULL},
|
||||
{_SC("setconsttable"),base_setconsttable,2, NULL},
|
||||
{_SC("assert"),base_assert,2, NULL},
|
||||
{_SC("print"),base_print,2, NULL},
|
||||
{_SC("compilestring"),base_compilestring,-2, _SC(".ss")},
|
||||
{_SC("newthread"),base_newthread,2, _SC(".c")},
|
||||
{_SC("suspend"),base_suspend,-1, NULL},
|
||||
{_SC("array"),base_array,-2, _SC(".n")},
|
||||
{_SC("type"),base_type,2, NULL},
|
||||
{_SC("dummy"),base_dummy,0,NULL},
|
||||
#ifndef NO_GARBAGE_COLLECTOR
|
||||
{_SC("collectgarbage"),base_collectgarbage,1, _SC("t")},
|
||||
#endif
|
||||
{0,0}
|
||||
};
|
||||
|
||||
void sq_base_register(HSQUIRRELVM v)
|
||||
{
|
||||
SQInteger i=0;
|
||||
sq_pushroottable(v);
|
||||
while(base_funcs[i].name!=0) {
|
||||
sq_pushstring(v,base_funcs[i].name,-1);
|
||||
sq_newclosure(v,base_funcs[i].f,0);
|
||||
sq_setnativeclosurename(v,-1,base_funcs[i].name);
|
||||
sq_setparamscheck(v,base_funcs[i].nparamscheck,base_funcs[i].typemask);
|
||||
sq_createslot(v,-3);
|
||||
i++;
|
||||
}
|
||||
sq_pushstring(v,_SC("_version_"),-1);
|
||||
sq_pushstring(v,SQUIRREL_VERSION,-1);
|
||||
sq_createslot(v,-3);
|
||||
sq_pushstring(v,_SC("_charsize_"),-1);
|
||||
sq_pushinteger(v,sizeof(SQChar));
|
||||
sq_createslot(v,-3);
|
||||
sq_pushstring(v,_SC("_intsize_"),-1);
|
||||
sq_pushinteger(v,sizeof(SQInteger));
|
||||
sq_createslot(v,-3);
|
||||
sq_pushstring(v,_SC("_floatsize_"),-1);
|
||||
sq_pushinteger(v,sizeof(SQFloat));
|
||||
sq_createslot(v,-3);
|
||||
sq_pop(v,1);
|
||||
}
|
||||
|
||||
static SQInteger default_delegate_len(HSQUIRRELVM v)
|
||||
{
|
||||
v->Push(SQInteger(sq_getsize(v,1)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger default_delegate_tofloat(HSQUIRRELVM v)
|
||||
{
|
||||
SQObjectPtr &o=stack_get(v,1);
|
||||
switch(type(o)){
|
||||
case OT_STRING:{
|
||||
SQObjectPtr res;
|
||||
if(str2num(_stringval(o),res)){
|
||||
v->Push(SQObjectPtr(tofloat(res)));
|
||||
break;
|
||||
}}
|
||||
return sq_throwerror(v, _SC("cannot convert the string"));
|
||||
break;
|
||||
case OT_INTEGER:case OT_FLOAT:
|
||||
v->Push(SQObjectPtr(tofloat(o)));
|
||||
break;
|
||||
case OT_BOOL:
|
||||
v->Push(SQObjectPtr((SQFloat)(_integer(o)?1:0)));
|
||||
break;
|
||||
default:
|
||||
v->Push(_null_);
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger default_delegate_tointeger(HSQUIRRELVM v)
|
||||
{
|
||||
SQObjectPtr &o=stack_get(v,1);
|
||||
switch(type(o)){
|
||||
case OT_STRING:{
|
||||
SQObjectPtr res;
|
||||
if(str2num(_stringval(o),res)){
|
||||
v->Push(SQObjectPtr(tointeger(res)));
|
||||
break;
|
||||
}}
|
||||
return sq_throwerror(v, _SC("cannot convert the string"));
|
||||
break;
|
||||
case OT_INTEGER:case OT_FLOAT:
|
||||
v->Push(SQObjectPtr(tointeger(o)));
|
||||
break;
|
||||
case OT_BOOL:
|
||||
v->Push(SQObjectPtr(_integer(o)?(SQInteger)1:(SQInteger)0));
|
||||
break;
|
||||
default:
|
||||
v->Push(_null_);
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger default_delegate_tostring(HSQUIRRELVM v)
|
||||
{
|
||||
sq_tostring(v,1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger obj_delegate_weakref(HSQUIRRELVM v)
|
||||
{
|
||||
sq_weakref(v,1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger obj_clear(HSQUIRRELVM v)
|
||||
{
|
||||
return sq_clear(v,-1);
|
||||
}
|
||||
|
||||
|
||||
static SQInteger number_delegate_tochar(HSQUIRRELVM v)
|
||||
{
|
||||
SQObject &o=stack_get(v,1);
|
||||
SQChar c = (SQChar)tointeger(o);
|
||||
v->Push(SQString::Create(_ss(v),(const SQChar *)&c,1));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
//TABLE DEFAULT DELEGATE
|
||||
|
||||
static SQInteger table_rawdelete(HSQUIRRELVM v)
|
||||
{
|
||||
if(SQ_FAILED(sq_rawdeleteslot(v,1,SQTrue)))
|
||||
return SQ_ERROR;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static SQInteger container_rawexists(HSQUIRRELVM v)
|
||||
{
|
||||
if(SQ_SUCCEEDED(sq_rawget(v,-2))) {
|
||||
sq_pushbool(v,SQTrue);
|
||||
return 1;
|
||||
}
|
||||
sq_pushbool(v,SQFalse);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger table_rawset(HSQUIRRELVM v)
|
||||
{
|
||||
return sq_rawset(v,-3);
|
||||
}
|
||||
|
||||
|
||||
static SQInteger table_rawget(HSQUIRRELVM v)
|
||||
{
|
||||
return SQ_SUCCEEDED(sq_rawget(v,-2))?1:SQ_ERROR;
|
||||
}
|
||||
|
||||
|
||||
SQRegFunction SQSharedState::_table_default_delegate_funcz[]={
|
||||
{_SC("len"),default_delegate_len,1, _SC("t")},
|
||||
{_SC("rawget"),table_rawget,2, _SC("t")},
|
||||
{_SC("rawset"),table_rawset,3, _SC("t")},
|
||||
{_SC("rawdelete"),table_rawdelete,2, _SC("t")},
|
||||
{_SC("rawin"),container_rawexists,2, _SC("t")},
|
||||
{_SC("weakref"),obj_delegate_weakref,1, NULL },
|
||||
{_SC("tostring"),default_delegate_tostring,1, _SC(".")},
|
||||
{_SC("clear"),obj_clear,1, _SC(".")},
|
||||
{0,0}
|
||||
};
|
||||
|
||||
//ARRAY DEFAULT DELEGATE///////////////////////////////////////
|
||||
|
||||
static SQInteger array_append(HSQUIRRELVM v)
|
||||
{
|
||||
return sq_arrayappend(v,-2);
|
||||
}
|
||||
|
||||
static SQInteger array_extend(HSQUIRRELVM v)
|
||||
{
|
||||
_array(stack_get(v,1))->Extend(_array(stack_get(v,2)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SQInteger array_reverse(HSQUIRRELVM v)
|
||||
{
|
||||
return sq_arrayreverse(v,-1);
|
||||
}
|
||||
|
||||
static SQInteger array_pop(HSQUIRRELVM v)
|
||||
{
|
||||
return SQ_SUCCEEDED(sq_arraypop(v,1,SQTrue))?1:SQ_ERROR;
|
||||
}
|
||||
|
||||
static SQInteger array_top(HSQUIRRELVM v)
|
||||
{
|
||||
SQObject &o=stack_get(v,1);
|
||||
if(_array(o)->Size()>0){
|
||||
v->Push(_array(o)->Top());
|
||||
return 1;
|
||||
}
|
||||
else return sq_throwerror(v,_SC("top() on a empty array"));
|
||||
}
|
||||
|
||||
static SQInteger array_insert(HSQUIRRELVM v)
|
||||
{
|
||||
SQObject &o=stack_get(v,1);
|
||||
SQObject &idx=stack_get(v,2);
|
||||
SQObject &val=stack_get(v,3);
|
||||
if(!_array(o)->Insert(tointeger(idx),val))
|
||||
return sq_throwerror(v,_SC("index out of range"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SQInteger array_remove(HSQUIRRELVM v)
|
||||
{
|
||||
SQObject &o = stack_get(v, 1);
|
||||
SQObject &idx = stack_get(v, 2);
|
||||
if(!sq_isnumeric(idx)) return sq_throwerror(v, _SC("wrong type"));
|
||||
SQObjectPtr val;
|
||||
if(_array(o)->Get(tointeger(idx), val)) {
|
||||
_array(o)->Remove(tointeger(idx));
|
||||
v->Push(val);
|
||||
return 1;
|
||||
}
|
||||
return sq_throwerror(v, _SC("idx out of range"));
|
||||
}
|
||||
|
||||
static SQInteger array_resize(HSQUIRRELVM v)
|
||||
{
|
||||
SQObject &o = stack_get(v, 1);
|
||||
SQObject &nsize = stack_get(v, 2);
|
||||
SQObjectPtr fill;
|
||||
if(sq_isnumeric(nsize)) {
|
||||
if(sq_gettop(v) > 2)
|
||||
fill = stack_get(v, 3);
|
||||
_array(o)->Resize(tointeger(nsize),fill);
|
||||
return 0;
|
||||
}
|
||||
return sq_throwerror(v, _SC("size must be a number"));
|
||||
}
|
||||
|
||||
|
||||
//QSORT ala Sedgewick
|
||||
bool _qsort_compare(HSQUIRRELVM v,SQObjectPtr &arr,SQObjectPtr &a,SQObjectPtr &b,SQInteger func,SQInteger &ret)
|
||||
{
|
||||
if(func < 0) {
|
||||
if(!v->ObjCmp(a,b,ret)) return false;
|
||||
}
|
||||
else {
|
||||
SQInteger top = sq_gettop(v);
|
||||
sq_push(v, func);
|
||||
sq_pushroottable(v);
|
||||
v->Push(a);
|
||||
v->Push(b);
|
||||
if(SQ_FAILED(sq_call(v, 3, SQTrue, SQFalse))) {
|
||||
if(!sq_isstring( v->_lasterror))
|
||||
v->Raise_Error(_SC("compare func failed"));
|
||||
return false;
|
||||
}
|
||||
sq_getinteger(v, -1, &ret);
|
||||
sq_settop(v, top);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//QSORT ala Sedgewick
|
||||
bool _qsort(HSQUIRRELVM v,SQObjectPtr &arr, SQInteger l, SQInteger r,SQInteger func)
|
||||
{
|
||||
SQInteger i, j;
|
||||
SQArray *a=_array(arr);
|
||||
SQObjectPtr pivot,t;
|
||||
if( l < r ){
|
||||
pivot = a->_values[l];
|
||||
i = l; j = r+1;
|
||||
while(1){
|
||||
SQInteger ret;
|
||||
do {
|
||||
++i;
|
||||
if(i > r) break;
|
||||
if(!_qsort_compare(v,arr,a->_values[i],pivot,func,ret))
|
||||
return false;
|
||||
} while( ret <= 0);
|
||||
do {
|
||||
--j;
|
||||
if ( j < 0 ) {
|
||||
v->Raise_Error( _SC("Invalid qsort, probably compare function defect") );
|
||||
return false;
|
||||
}
|
||||
if(!_qsort_compare(v,arr,a->_values[j],pivot,func,ret))
|
||||
return false;
|
||||
}
|
||||
while( ret > 0 );
|
||||
if( i >= j ) break;
|
||||
t = a->_values[i]; a->_values[i] = a->_values[j]; a->_values[j] = t;
|
||||
}
|
||||
t = a->_values[l]; a->_values[l] = a->_values[j]; a->_values[j] = t;
|
||||
if(!_qsort( v, arr, l, j-1,func)) return false;
|
||||
if(!_qsort( v, arr, j+1, r,func)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static SQInteger array_sort(HSQUIRRELVM v)
|
||||
{
|
||||
SQInteger func = -1;
|
||||
SQObjectPtr &o = stack_get(v,1);
|
||||
SQObject &funcobj = stack_get(v,2);
|
||||
if(_array(o)->Size() > 1) {
|
||||
if(type(funcobj) == OT_CLOSURE || type(funcobj) == OT_NATIVECLOSURE) func = 2;
|
||||
if(!_qsort(v, o, 0, _array(o)->Size()-1, func))
|
||||
return SQ_ERROR;
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static SQInteger array_slice(HSQUIRRELVM v)
|
||||
{
|
||||
SQInteger sidx,eidx;
|
||||
SQObjectPtr o;
|
||||
if(get_slice_params(v,sidx,eidx,o)==-1)return -1;
|
||||
SQInteger alen = _array(o)->Size();
|
||||
if(sidx < 0)sidx = alen + sidx;
|
||||
if(eidx < 0)eidx = alen + eidx;
|
||||
if(eidx < sidx)return sq_throwerror(v,_SC("wrong indexes"));
|
||||
if(eidx > alen)return sq_throwerror(v,_SC("slice out of range"));
|
||||
SQArray *arr=SQArray::Create(_ss(v),eidx-sidx);
|
||||
SQObjectPtr t;
|
||||
SQInteger count=0;
|
||||
for(SQInteger i=sidx;i<eidx;i++){
|
||||
_array(o)->Get(i,t);
|
||||
arr->Set(count++,t);
|
||||
}
|
||||
v->Push(arr);
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
SQRegFunction SQSharedState::_array_default_delegate_funcz[]={
|
||||
{_SC("len"),default_delegate_len,1, _SC("a")},
|
||||
{_SC("append"),array_append,2, _SC("a")},
|
||||
{_SC("extend"),array_extend,2, _SC("aa")},
|
||||
{_SC("push"),array_append,2, _SC("a")},
|
||||
{_SC("pop"),array_pop,1, _SC("a")},
|
||||
{_SC("top"),array_top,1, _SC("a")},
|
||||
{_SC("insert"),array_insert,3, _SC("an")},
|
||||
{_SC("remove"),array_remove,2, _SC("an")},
|
||||
{_SC("resize"),array_resize,-2, _SC("an")},
|
||||
{_SC("reverse"),array_reverse,1, _SC("a")},
|
||||
{_SC("sort"),array_sort,-1, _SC("ac")},
|
||||
{_SC("slice"),array_slice,-1, _SC("ann")},
|
||||
{_SC("weakref"),obj_delegate_weakref,1, NULL },
|
||||
{_SC("tostring"),default_delegate_tostring,1, _SC(".")},
|
||||
{_SC("clear"),obj_clear,1, _SC(".")},
|
||||
{0,0}
|
||||
};
|
||||
|
||||
//STRING DEFAULT DELEGATE//////////////////////////
|
||||
static SQInteger string_slice(HSQUIRRELVM v)
|
||||
{
|
||||
SQInteger sidx,eidx;
|
||||
SQObjectPtr o;
|
||||
if(SQ_FAILED(get_slice_params(v,sidx,eidx,o)))return -1;
|
||||
SQInteger slen = _string(o)->_len;
|
||||
if(sidx < 0)sidx = slen + sidx;
|
||||
if(eidx < 0)eidx = slen + eidx;
|
||||
if(eidx < sidx) return sq_throwerror(v,_SC("wrong indexes"));
|
||||
if(eidx > slen) return sq_throwerror(v,_SC("slice out of range"));
|
||||
v->Push(SQString::Create(_ss(v),&_stringval(o)[sidx],eidx-sidx));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger string_find(HSQUIRRELVM v)
|
||||
{
|
||||
SQInteger top,start_idx=0;
|
||||
const SQChar *str,*substr,*ret;
|
||||
if(((top=sq_gettop(v))>1) && SQ_SUCCEEDED(sq_getstring(v,1,&str)) && SQ_SUCCEEDED(sq_getstring(v,2,&substr))){
|
||||
if(top>2)sq_getinteger(v,3,&start_idx);
|
||||
if((sq_getsize(v,1)>start_idx) && (start_idx>=0)){
|
||||
ret=scstrstr(&str[start_idx],substr);
|
||||
if(ret){
|
||||
sq_pushinteger(v,(SQInteger)(ret-str));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return sq_throwerror(v,_SC("invalid param"));
|
||||
}
|
||||
|
||||
#define STRING_TOFUNCZ(func) static SQInteger string_##func(HSQUIRRELVM v) \
|
||||
{ \
|
||||
SQObject str=stack_get(v,1); \
|
||||
SQInteger len=_string(str)->_len; \
|
||||
const SQChar *sThis=_stringval(str); \
|
||||
SQChar *sNew=(_ss(v)->GetScratchPad(rsl(len))); \
|
||||
for(SQInteger i=0;i<len;i++) sNew[i]=func(sThis[i]); \
|
||||
v->Push(SQString::Create(_ss(v),sNew,len)); \
|
||||
return 1; \
|
||||
}
|
||||
|
||||
|
||||
STRING_TOFUNCZ(tolower)
|
||||
STRING_TOFUNCZ(toupper)
|
||||
|
||||
SQRegFunction SQSharedState::_string_default_delegate_funcz[]={
|
||||
{_SC("len"),default_delegate_len,1, _SC("s")},
|
||||
{_SC("tointeger"),default_delegate_tointeger,1, _SC("s")},
|
||||
{_SC("tofloat"),default_delegate_tofloat,1, _SC("s")},
|
||||
{_SC("tostring"),default_delegate_tostring,1, _SC(".")},
|
||||
{_SC("slice"),string_slice,-1, _SC(" s n n")},
|
||||
{_SC("find"),string_find,-2, _SC("s s n ")},
|
||||
{_SC("tolower"),string_tolower,1, _SC("s")},
|
||||
{_SC("toupper"),string_toupper,1, _SC("s")},
|
||||
{_SC("weakref"),obj_delegate_weakref,1, NULL },
|
||||
{0,0}
|
||||
};
|
||||
|
||||
//INTEGER DEFAULT DELEGATE//////////////////////////
|
||||
SQRegFunction SQSharedState::_number_default_delegate_funcz[]={
|
||||
{_SC("tointeger"),default_delegate_tointeger,1, _SC("n|b")},
|
||||
{_SC("tofloat"),default_delegate_tofloat,1, _SC("n|b")},
|
||||
{_SC("tostring"),default_delegate_tostring,1, _SC(".")},
|
||||
{_SC("tochar"),number_delegate_tochar,1, _SC("n|b")},
|
||||
{_SC("weakref"),obj_delegate_weakref,1, NULL },
|
||||
{0,0}
|
||||
};
|
||||
|
||||
//CLOSURE DEFAULT DELEGATE//////////////////////////
|
||||
static SQInteger closure_pcall(HSQUIRRELVM v)
|
||||
{
|
||||
return SQ_SUCCEEDED(sq_call(v,sq_gettop(v)-1,SQTrue,SQFalse))?1:SQ_ERROR;
|
||||
}
|
||||
|
||||
static SQInteger closure_call(HSQUIRRELVM v)
|
||||
{
|
||||
return SQ_SUCCEEDED(sq_call(v,sq_gettop(v)-1,SQTrue,SQTrue))?1:SQ_ERROR;
|
||||
}
|
||||
|
||||
static SQInteger _closure_acall(HSQUIRRELVM v,SQBool raiseerror)
|
||||
{
|
||||
SQArray *aparams=_array(stack_get(v,2));
|
||||
SQInteger nparams=aparams->Size();
|
||||
v->Push(stack_get(v,1));
|
||||
for(SQInteger i=0;i<nparams;i++)v->Push(aparams->_values[i]);
|
||||
return SQ_SUCCEEDED(sq_call(v,nparams,SQTrue,raiseerror))?1:SQ_ERROR;
|
||||
}
|
||||
|
||||
static SQInteger closure_acall(HSQUIRRELVM v)
|
||||
{
|
||||
return _closure_acall(v,SQTrue);
|
||||
}
|
||||
|
||||
static SQInteger closure_pacall(HSQUIRRELVM v)
|
||||
{
|
||||
return _closure_acall(v,SQFalse);
|
||||
}
|
||||
|
||||
static SQInteger closure_bindenv(HSQUIRRELVM v)
|
||||
{
|
||||
if(SQ_FAILED(sq_bindenv(v,1)))
|
||||
return SQ_ERROR;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger closure_getinfos(HSQUIRRELVM v) {
|
||||
SQObject o = stack_get(v,1);
|
||||
SQTable *res = SQTable::Create(_ss(v),4);
|
||||
if(type(o) == OT_CLOSURE) {
|
||||
SQFunctionProto *f = _funcproto(_closure(o)->_function);
|
||||
SQInteger nparams = f->_nparameters + (f->_varparams?1:0);
|
||||
SQObjectPtr params = SQArray::Create(_ss(v),nparams);
|
||||
for(SQInteger n = 0; n<f->_nparameters; n++) {
|
||||
_array(params)->Set((SQInteger)n,f->_parameters[n]);
|
||||
}
|
||||
if(f->_varparams) {
|
||||
_array(params)->Set(nparams-1,SQString::Create(_ss(v),_SC("..."),-1));
|
||||
}
|
||||
res->NewSlot(SQString::Create(_ss(v),_SC("native"),-1),false);
|
||||
res->NewSlot(SQString::Create(_ss(v),_SC("name"),-1),f->_name);
|
||||
res->NewSlot(SQString::Create(_ss(v),_SC("src"),-1),f->_sourcename);
|
||||
res->NewSlot(SQString::Create(_ss(v),_SC("parameters"),-1),params);
|
||||
res->NewSlot(SQString::Create(_ss(v),_SC("varargs"),-1),f->_varparams);
|
||||
}
|
||||
else { //OT_NATIVECLOSURE
|
||||
SQNativeClosure *nc = _nativeclosure(o);
|
||||
res->NewSlot(SQString::Create(_ss(v),_SC("native"),-1),true);
|
||||
res->NewSlot(SQString::Create(_ss(v),_SC("name"),-1),nc->_name);
|
||||
res->NewSlot(SQString::Create(_ss(v),_SC("paramscheck"),-1),nc->_nparamscheck);
|
||||
SQObjectPtr typecheck;
|
||||
if(nc->_typecheck.size() > 0) {
|
||||
typecheck =
|
||||
SQArray::Create(_ss(v), nc->_typecheck.size());
|
||||
for(SQUnsignedInteger n = 0; n<nc->_typecheck.size(); n++) {
|
||||
_array(typecheck)->Set((SQInteger)n,nc->_typecheck[n]);
|
||||
}
|
||||
}
|
||||
res->NewSlot(SQString::Create(_ss(v),_SC("typecheck"),-1),typecheck);
|
||||
}
|
||||
v->Push(res);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
SQRegFunction SQSharedState::_closure_default_delegate_funcz[]={
|
||||
{_SC("call"),closure_call,-1, _SC("c")},
|
||||
{_SC("pcall"),closure_pcall,-1, _SC("c")},
|
||||
{_SC("acall"),closure_acall,2, _SC("ca")},
|
||||
{_SC("pacall"),closure_pacall,2, _SC("ca")},
|
||||
{_SC("weakref"),obj_delegate_weakref,1, NULL },
|
||||
{_SC("tostring"),default_delegate_tostring,1, _SC(".")},
|
||||
{_SC("bindenv"),closure_bindenv,2, _SC("c x|y|t")},
|
||||
{_SC("getinfos"),closure_getinfos,1, _SC("c")},
|
||||
{0,0}
|
||||
};
|
||||
|
||||
//GENERATOR DEFAULT DELEGATE
|
||||
static SQInteger generator_getstatus(HSQUIRRELVM v)
|
||||
{
|
||||
SQObject &o=stack_get(v,1);
|
||||
switch(_generator(o)->_state){
|
||||
case SQGenerator::eSuspended:v->Push(SQString::Create(_ss(v),_SC("suspended")));break;
|
||||
case SQGenerator::eRunning:v->Push(SQString::Create(_ss(v),_SC("running")));break;
|
||||
case SQGenerator::eDead:v->Push(SQString::Create(_ss(v),_SC("dead")));break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
SQRegFunction SQSharedState::_generator_default_delegate_funcz[]={
|
||||
{_SC("getstatus"),generator_getstatus,1, _SC("g")},
|
||||
{_SC("weakref"),obj_delegate_weakref,1, NULL },
|
||||
{_SC("tostring"),default_delegate_tostring,1, _SC(".")},
|
||||
{0,0}
|
||||
};
|
||||
|
||||
//THREAD DEFAULT DELEGATE
|
||||
|
||||
static SQInteger thread_call(HSQUIRRELVM v)
|
||||
{
|
||||
|
||||
SQObjectPtr o = stack_get(v,1);
|
||||
if(type(o) == OT_THREAD) {
|
||||
SQInteger nparams = sq_gettop(v);
|
||||
_thread(o)->Push(_thread(o)->_roottable);
|
||||
for(SQInteger i = 2; i<(nparams+1); i++)
|
||||
sq_move(_thread(o),v,i);
|
||||
if(SQ_SUCCEEDED(sq_call(_thread(o),nparams,SQTrue,SQFalse))) {
|
||||
sq_move(v,_thread(o),-1);
|
||||
sq_pop(_thread(o),1);
|
||||
return 1;
|
||||
}
|
||||
v->_lasterror = _thread(o)->_lasterror;
|
||||
return SQ_ERROR;
|
||||
}
|
||||
return sq_throwerror(v,_SC("wrong parameter"));
|
||||
}
|
||||
|
||||
static SQInteger thread_wakeup(HSQUIRRELVM v)
|
||||
{
|
||||
SQObjectPtr o = stack_get(v,1);
|
||||
if(type(o) == OT_THREAD) {
|
||||
SQVM *thread = _thread(o);
|
||||
SQInteger state = sq_getvmstate(thread);
|
||||
if(state != SQ_VMSTATE_SUSPENDED) {
|
||||
switch(state) {
|
||||
case SQ_VMSTATE_IDLE:
|
||||
return sq_throwerror(v,_SC("cannot wakeup a idle thread"));
|
||||
break;
|
||||
case SQ_VMSTATE_RUNNING:
|
||||
return sq_throwerror(v,_SC("cannot wakeup a running thread"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SQInteger wakeupret = sq_gettop(v)>1?1:0;
|
||||
if(wakeupret) {
|
||||
sq_move(thread,v,2);
|
||||
}
|
||||
if(SQ_SUCCEEDED(sq_wakeupvm(thread,wakeupret,SQTrue,SQTrue,SQFalse))) {
|
||||
sq_move(v,thread,-1);
|
||||
sq_pop(thread,1); //pop retval
|
||||
if(sq_getvmstate(thread) == SQ_VMSTATE_IDLE) {
|
||||
sq_settop(thread,1); //pop roottable
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
sq_settop(thread,1);
|
||||
v->_lasterror = thread->_lasterror;
|
||||
return SQ_ERROR;
|
||||
}
|
||||
return sq_throwerror(v,_SC("wrong parameter"));
|
||||
}
|
||||
|
||||
static SQInteger thread_getstatus(HSQUIRRELVM v)
|
||||
{
|
||||
SQObjectPtr &o = stack_get(v,1);
|
||||
switch(sq_getvmstate(_thread(o))) {
|
||||
case SQ_VMSTATE_IDLE:
|
||||
sq_pushstring(v,_SC("idle"),-1);
|
||||
break;
|
||||
case SQ_VMSTATE_RUNNING:
|
||||
sq_pushstring(v,_SC("running"),-1);
|
||||
break;
|
||||
case SQ_VMSTATE_SUSPENDED:
|
||||
sq_pushstring(v,_SC("suspended"),-1);
|
||||
break;
|
||||
default:
|
||||
return sq_throwerror(v,_SC("internal VM error"));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
SQRegFunction SQSharedState::_thread_default_delegate_funcz[] = {
|
||||
{_SC("call"), thread_call, -1, _SC("v")},
|
||||
{_SC("wakeup"), thread_wakeup, -1, _SC("v")},
|
||||
{_SC("getstatus"), thread_getstatus, 1, _SC("v")},
|
||||
{_SC("weakref"),obj_delegate_weakref,1, NULL },
|
||||
{_SC("tostring"),default_delegate_tostring,1, _SC(".")},
|
||||
{0,0},
|
||||
};
|
||||
|
||||
static SQInteger class_getattributes(HSQUIRRELVM v)
|
||||
{
|
||||
if(SQ_SUCCEEDED(sq_getattributes(v,-2)))
|
||||
return 1;
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
static SQInteger class_setattributes(HSQUIRRELVM v)
|
||||
{
|
||||
if(SQ_SUCCEEDED(sq_setattributes(v,-3)))
|
||||
return 1;
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
static SQInteger class_instance(HSQUIRRELVM v)
|
||||
{
|
||||
if(SQ_SUCCEEDED(sq_createinstance(v,-1)))
|
||||
return 1;
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
SQRegFunction SQSharedState::_class_default_delegate_funcz[] = {
|
||||
{_SC("getattributes"), class_getattributes, 2, _SC("y.")},
|
||||
{_SC("setattributes"), class_setattributes, 3, _SC("y..")},
|
||||
{_SC("rawin"),container_rawexists,2, _SC("y")},
|
||||
{_SC("weakref"),obj_delegate_weakref,1, NULL },
|
||||
{_SC("tostring"),default_delegate_tostring,1, _SC(".")},
|
||||
{_SC("instance"),class_instance,1, _SC("y")},
|
||||
{0,0}
|
||||
};
|
||||
|
||||
static SQInteger instance_getclass(HSQUIRRELVM v)
|
||||
{
|
||||
if(SQ_SUCCEEDED(sq_getclass(v,1)))
|
||||
return 1;
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
SQRegFunction SQSharedState::_instance_default_delegate_funcz[] = {
|
||||
{_SC("getclass"), instance_getclass, 1, _SC("x")},
|
||||
{_SC("rawin"),container_rawexists,2, _SC("x")},
|
||||
{_SC("weakref"),obj_delegate_weakref,1, NULL },
|
||||
{_SC("tostring"),default_delegate_tostring,1, _SC(".")},
|
||||
{0,0}
|
||||
};
|
||||
|
||||
static SQInteger weakref_ref(HSQUIRRELVM v)
|
||||
{
|
||||
if(SQ_FAILED(sq_getweakrefval(v,1)))
|
||||
return SQ_ERROR;
|
||||
return 1;
|
||||
}
|
||||
|
||||
SQRegFunction SQSharedState::_weakref_default_delegate_funcz[] = {
|
||||
{_SC("ref"),weakref_ref,1, _SC("r")},
|
||||
{_SC("weakref"),obj_delegate_weakref,1, NULL },
|
||||
{_SC("tostring"),default_delegate_tostring,1, _SC(".")},
|
||||
{0,0}
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
#include "sqpcheader.h"
|
||||
#include "sqvm.h"
|
||||
#include "sqtable.h"
|
||||
#include "sqclass.h"
|
||||
#include "sqclosure.h"
|
||||
#if defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST)
|
||||
#include "memdbgon.h"
|
||||
#undef new // allow placement new
|
||||
#endif
|
||||
|
||||
SQClass::SQClass(SQSharedState *ss,SQClass *base)
|
||||
{
|
||||
_base = base;
|
||||
_typetag = 0;
|
||||
_hook = NULL;
|
||||
_udsize = 0;
|
||||
_metamethods.resize(MT_LAST); //size it to max size
|
||||
if(_base) {
|
||||
_defaultvalues.copy(base->_defaultvalues);
|
||||
_methods.copy(base->_methods);
|
||||
_metamethods.copy(base->_metamethods);
|
||||
__ObjAddRef(_base);
|
||||
}
|
||||
_members = base?base->_members->Clone() : SQTable::Create(ss,0);
|
||||
__ObjAddRef(_members);
|
||||
_locked = false;
|
||||
INIT_CHAIN();
|
||||
ADD_TO_CHAIN(&_sharedstate->_gc_chain, this);
|
||||
}
|
||||
|
||||
void SQClass::Finalize() {
|
||||
_attributes = _null_;
|
||||
_defaultvalues.resize(0);
|
||||
_methods.resize(0);
|
||||
_metamethods.resize(0);
|
||||
__ObjRelease(_members);
|
||||
if(_base) {
|
||||
__ObjRelease(_base);
|
||||
}
|
||||
}
|
||||
|
||||
SQClass::~SQClass()
|
||||
{
|
||||
REMOVE_FROM_CHAIN(&_sharedstate->_gc_chain, this);
|
||||
Finalize();
|
||||
}
|
||||
|
||||
bool SQClass::NewSlot(SQSharedState *ss,const SQObjectPtr &key,const SQObjectPtr &val,bool bstatic)
|
||||
{
|
||||
SQObjectPtr temp;
|
||||
if(_locked)
|
||||
return false; //the class already has an instance so cannot be modified
|
||||
if(_members->Get(key,temp) && _isfield(temp)) //overrides the default value
|
||||
{
|
||||
_defaultvalues[_member_idx(temp)].val = val;
|
||||
return true;
|
||||
}
|
||||
if(type(val) == OT_CLOSURE || type(val) == OT_NATIVECLOSURE || bstatic) {
|
||||
SQInteger mmidx;
|
||||
if((type(val) == OT_CLOSURE || type(val) == OT_NATIVECLOSURE) &&
|
||||
(mmidx = ss->GetMetaMethodIdxByName(key)) != -1) {
|
||||
_metamethods[mmidx] = val;
|
||||
}
|
||||
else {
|
||||
if(type(temp) == OT_NULL) {
|
||||
SQClassMember m;
|
||||
m.val = val;
|
||||
_members->NewSlot(key,SQObjectPtr(_make_method_idx(_methods.size())));
|
||||
_methods.push_back(m);
|
||||
}
|
||||
else {
|
||||
_methods[_member_idx(temp)].val = val;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
SQClassMember m;
|
||||
m.val = val;
|
||||
_members->NewSlot(key,SQObjectPtr(_make_field_idx(_defaultvalues.size())));
|
||||
_defaultvalues.push_back(m);
|
||||
return true;
|
||||
}
|
||||
|
||||
SQInstance *SQClass::CreateInstance()
|
||||
{
|
||||
if(!_locked) Lock();
|
||||
return SQInstance::Create(_opt_ss(this),this);
|
||||
}
|
||||
|
||||
SQInteger SQClass::Next(const SQObjectPtr &refpos, SQObjectPtr &outkey, SQObjectPtr &outval)
|
||||
{
|
||||
SQObjectPtr oval;
|
||||
SQInteger idx = _members->Next(false,refpos,outkey,oval);
|
||||
if(idx != -1) {
|
||||
if(_ismethod(oval)) {
|
||||
outval = _methods[_member_idx(oval)].val;
|
||||
}
|
||||
else {
|
||||
SQObjectPtr &o = _defaultvalues[_member_idx(oval)].val;
|
||||
outval = _realval(o);
|
||||
}
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
|
||||
bool SQClass::SetAttributes(const SQObjectPtr &key,const SQObjectPtr &val)
|
||||
{
|
||||
SQObjectPtr idx;
|
||||
if(_members->Get(key,idx)) {
|
||||
if(_isfield(idx))
|
||||
_defaultvalues[_member_idx(idx)].attrs = val;
|
||||
else
|
||||
_methods[_member_idx(idx)].attrs = val;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SQClass::GetAttributes(const SQObjectPtr &key,SQObjectPtr &outval)
|
||||
{
|
||||
SQObjectPtr idx;
|
||||
if(_members->Get(key,idx)) {
|
||||
outval = (_isfield(idx)?_defaultvalues[_member_idx(idx)].attrs:_methods[_member_idx(idx)].attrs);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
void SQInstance::Init(SQSharedState *ss)
|
||||
{
|
||||
_userpointer = NULL;
|
||||
_hook = NULL;
|
||||
__ObjAddRef(_class);
|
||||
_delegate = _class->_members;
|
||||
INIT_CHAIN();
|
||||
ADD_TO_CHAIN(&_sharedstate->_gc_chain, this);
|
||||
}
|
||||
|
||||
SQInstance::SQInstance(SQSharedState *ss, SQClass *c, SQInteger memsize)
|
||||
{
|
||||
_memsize = memsize;
|
||||
_class = c;
|
||||
SQUnsignedInteger nvalues = _class->_defaultvalues.size();
|
||||
for(SQUnsignedInteger n = 0; n < nvalues; n++) {
|
||||
new (&_values[n]) SQObjectPtr(_class->_defaultvalues[n].val);
|
||||
}
|
||||
Init(ss);
|
||||
}
|
||||
|
||||
SQInstance::SQInstance(SQSharedState *ss, SQInstance *i, SQInteger memsize)
|
||||
{
|
||||
_memsize = memsize;
|
||||
_class = i->_class;
|
||||
SQUnsignedInteger nvalues = _class->_defaultvalues.size();
|
||||
for(SQUnsignedInteger n = 0; n < nvalues; n++) {
|
||||
new (&_values[n]) SQObjectPtr(i->_values[n]);
|
||||
}
|
||||
Init(ss);
|
||||
}
|
||||
|
||||
void SQInstance::Finalize()
|
||||
{
|
||||
SQUnsignedInteger nvalues = _class->_defaultvalues.size();
|
||||
__ObjRelease(_class);
|
||||
for(SQUnsignedInteger i = 0; i < nvalues; i++) {
|
||||
_values[i] = _null_;
|
||||
}
|
||||
}
|
||||
|
||||
SQInstance::~SQInstance()
|
||||
{
|
||||
REMOVE_FROM_CHAIN(&_sharedstate->_gc_chain, this);
|
||||
if(_class){ Finalize(); } //if _class is null it was already finalized by the GC
|
||||
}
|
||||
|
||||
bool SQInstance::GetMetaMethod(SQVM *v,SQMetaMethod mm,SQObjectPtr &res)
|
||||
{
|
||||
if(type(_class->_metamethods[mm]) != OT_NULL) {
|
||||
res = _class->_metamethods[mm];
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SQInstance::InstanceOf(SQClass *trg)
|
||||
{
|
||||
SQClass *parent = _class;
|
||||
while(parent != NULL) {
|
||||
if(parent == trg)
|
||||
return true;
|
||||
parent = parent->_base;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#ifndef _SQCLASS_H_
|
||||
#define _SQCLASS_H_
|
||||
#if defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST)
|
||||
#include "memdbgon.h"
|
||||
#undef new // allow placement new
|
||||
#endif
|
||||
|
||||
struct SQInstance;
|
||||
|
||||
struct SQClassMember {
|
||||
SQClassMember(){}
|
||||
SQClassMember(const SQClassMember &o) {
|
||||
val = o.val;
|
||||
attrs = o.attrs;
|
||||
}
|
||||
SQObjectPtr val;
|
||||
SQObjectPtr attrs;
|
||||
};
|
||||
|
||||
typedef sqvector<SQClassMember> SQClassMemberVec;
|
||||
|
||||
#define MEMBER_TYPE_METHOD 0x01000000
|
||||
#define MEMBER_TYPE_FIELD 0x02000000
|
||||
|
||||
#define _ismethod(o) (_integer(o)&MEMBER_TYPE_METHOD)
|
||||
#define _isfield(o) (_integer(o)&MEMBER_TYPE_FIELD)
|
||||
#define _make_method_idx(i) ((SQInteger)(MEMBER_TYPE_METHOD|i))
|
||||
#define _make_field_idx(i) ((SQInteger)(MEMBER_TYPE_FIELD|i))
|
||||
#define _member_type(o) (_integer(o)&0xFF000000)
|
||||
#define _member_idx(o) (_integer(o)&0x00FFFFFF)
|
||||
|
||||
struct SQClass : public CHAINABLE_OBJ
|
||||
{
|
||||
SQClass(SQSharedState *ss,SQClass *base);
|
||||
public:
|
||||
static SQClass* Create(SQSharedState *ss,SQClass *base) {
|
||||
SQClass *newclass = (SQClass *)SQ_MALLOC(sizeof(SQClass));
|
||||
new (newclass) SQClass(ss, base);
|
||||
return newclass;
|
||||
}
|
||||
~SQClass();
|
||||
bool NewSlot(SQSharedState *ss, const SQObjectPtr &key,const SQObjectPtr &val,bool bstatic);
|
||||
bool Get(const SQObjectPtr &key,SQObjectPtr &val) {
|
||||
if(_members->Get(key,val)) {
|
||||
if(_isfield(val)) {
|
||||
SQObjectPtr &o = _defaultvalues[_member_idx(val)].val;
|
||||
val = _realval(o);
|
||||
}
|
||||
else {
|
||||
val = _methods[_member_idx(val)].val;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool SetAttributes(const SQObjectPtr &key,const SQObjectPtr &val);
|
||||
bool GetAttributes(const SQObjectPtr &key,SQObjectPtr &outval);
|
||||
void Lock() { _locked = true; if(_base) _base->Lock(); }
|
||||
void Release() {
|
||||
if (_hook) { _hook(_typetag,0);}
|
||||
sq_delete(this, SQClass);
|
||||
}
|
||||
void Finalize();
|
||||
#ifndef NO_GARBAGE_COLLECTOR
|
||||
void Mark(SQCollectable ** );
|
||||
#endif
|
||||
void Iterate( CSQStateIterator *pIterator );
|
||||
|
||||
SQInteger Next(const SQObjectPtr &refpos, SQObjectPtr &outkey, SQObjectPtr &outval);
|
||||
SQInstance *CreateInstance();
|
||||
SQTable *_members;
|
||||
SQClass *_base;
|
||||
SQClassMemberVec _defaultvalues;
|
||||
SQClassMemberVec _methods;
|
||||
SQObjectPtrVec _metamethods;
|
||||
SQObjectPtr _attributes;
|
||||
SQUserPointer _typetag;
|
||||
SQRELEASEHOOK _hook;
|
||||
bool _locked;
|
||||
SQInteger _udsize;
|
||||
};
|
||||
|
||||
#define calcinstancesize(_theclass_) \
|
||||
(_theclass_->_udsize + sizeof(SQInstance) + (sizeof(SQObjectPtr)*(_theclass_->_defaultvalues.size()>0?_theclass_->_defaultvalues.size()-1:0)))
|
||||
|
||||
struct SQInstance : public SQDelegable
|
||||
{
|
||||
void Init(SQSharedState *ss);
|
||||
SQInstance(SQSharedState *ss, SQClass *c, SQInteger memsize);
|
||||
SQInstance(SQSharedState *ss, SQInstance *c, SQInteger memsize);
|
||||
public:
|
||||
static SQInstance* Create(SQSharedState *ss,SQClass *theclass) {
|
||||
|
||||
SQInteger size = calcinstancesize(theclass);
|
||||
SQInstance *newinst = (SQInstance *)SQ_MALLOC(size);
|
||||
new (newinst) SQInstance(ss, theclass,size);
|
||||
if(theclass->_udsize) {
|
||||
newinst->_userpointer = ((unsigned char *)newinst) + (size - theclass->_udsize);
|
||||
}
|
||||
return newinst;
|
||||
}
|
||||
SQInstance *Clone(SQSharedState *ss)
|
||||
{
|
||||
SQInteger size = calcinstancesize(_class);
|
||||
SQInstance *newinst = (SQInstance *)SQ_MALLOC(size);
|
||||
new (newinst) SQInstance(ss, this,size);
|
||||
if(_class->_udsize) {
|
||||
newinst->_userpointer = ((unsigned char *)newinst) + (size - _class->_udsize);
|
||||
}
|
||||
return newinst;
|
||||
}
|
||||
~SQInstance();
|
||||
bool Get(const SQObjectPtr &key,SQObjectPtr &val) {
|
||||
if(_class->_members->Get(key,val)) {
|
||||
if(_isfield(val)) {
|
||||
SQObjectPtr &o = _values[_member_idx(val)];
|
||||
val = _realval(o);
|
||||
}
|
||||
else {
|
||||
val = _class->_methods[_member_idx(val)].val;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool Set(const SQObjectPtr &key,const SQObjectPtr &val) {
|
||||
SQObjectPtr idx;
|
||||
if(_class->_members->Get(key,idx) && _isfield(idx)) {
|
||||
_values[_member_idx(idx)] = val;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void Release() {
|
||||
SQ_VALIDATE_REF_COUNT( this );
|
||||
_uiRef++;
|
||||
if (_hook) { _hook(_userpointer,0);}
|
||||
_uiRef--;
|
||||
SQ_VALIDATE_REF_COUNT( this );
|
||||
if(_uiRef > 0) return;
|
||||
SQInteger size = _memsize;
|
||||
this->~SQInstance();
|
||||
SQ_FREE(this, size);
|
||||
}
|
||||
void Finalize();
|
||||
#ifndef NO_GARBAGE_COLLECTOR
|
||||
void Mark(SQCollectable ** );
|
||||
#endif
|
||||
void Iterate( CSQStateIterator *pIterator );
|
||||
|
||||
bool InstanceOf(SQClass *trg);
|
||||
bool GetMetaMethod(SQVM *v,SQMetaMethod mm,SQObjectPtr &res);
|
||||
|
||||
SQClass *_class;
|
||||
SQUserPointer _userpointer;
|
||||
SQRELEASEHOOK _hook;
|
||||
SQInteger _memsize;
|
||||
SQObjectPtr _values[1];
|
||||
};
|
||||
|
||||
#if defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST)
|
||||
#include "memdbgoff.h"
|
||||
#endif
|
||||
#endif //_SQCLASS_H_
|
||||
@@ -0,0 +1,139 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#ifndef _SQCLOSURE_H_
|
||||
#define _SQCLOSURE_H_
|
||||
#if defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST)
|
||||
#include "memdbgon.h"
|
||||
#undef new // allow placement new
|
||||
#endif
|
||||
|
||||
#ifdef _X360
|
||||
#if defined Yield
|
||||
#undef Yield
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct SQFunctionProto;
|
||||
|
||||
struct SQClosure : public CHAINABLE_OBJ
|
||||
{
|
||||
private:
|
||||
SQClosure(SQSharedState *ss,SQFunctionProto *func){_function=func; INIT_CHAIN();ADD_TO_CHAIN(&_ss(this)->_gc_chain,this);}
|
||||
public:
|
||||
static SQClosure *Create(SQSharedState *ss,SQFunctionProto *func){
|
||||
SQClosure *nc=(SQClosure*)SQ_MALLOC(sizeof(SQClosure));
|
||||
new (nc) SQClosure(ss,func);
|
||||
return nc;
|
||||
}
|
||||
void Release(){
|
||||
sq_delete(this,SQClosure);
|
||||
}
|
||||
SQClosure *Clone()
|
||||
{
|
||||
SQClosure * ret = SQClosure::Create(_opt_ss(this),_funcproto(_function));
|
||||
ret->_env = _env;
|
||||
ret->_outervalues.copy(_outervalues);
|
||||
ret->_defaultparams.copy(_defaultparams);
|
||||
return ret;
|
||||
}
|
||||
~SQClosure()
|
||||
{
|
||||
REMOVE_FROM_CHAIN(&_ss(this)->_gc_chain,this);
|
||||
}
|
||||
bool Save(SQVM *v,SQUserPointer up,SQWRITEFUNC write);
|
||||
static bool Load(SQVM *v,SQUserPointer up,SQREADFUNC read,SQObjectPtr &ret);
|
||||
#ifndef NO_GARBAGE_COLLECTOR
|
||||
void Mark(SQCollectable **chain);
|
||||
void Finalize(){_outervalues.resize(0); }
|
||||
#endif
|
||||
void Iterate( CSQStateIterator *pIterator );
|
||||
|
||||
SQObjectPtr _env;
|
||||
SQObjectPtr _function;
|
||||
SQObjectPtrVec _outervalues;
|
||||
SQObjectPtrVec _defaultparams;
|
||||
};
|
||||
//////////////////////////////////////////////
|
||||
struct SQGenerator : public CHAINABLE_OBJ
|
||||
{
|
||||
enum SQGeneratorState{eRunning,eSuspended,eDead};
|
||||
private:
|
||||
SQGenerator(SQSharedState *ss,SQClosure *closure){_closure=closure;_state=eRunning;_ci._generator=NULL;INIT_CHAIN();ADD_TO_CHAIN(&_ss(this)->_gc_chain,this);}
|
||||
public:
|
||||
static SQGenerator *Create(SQSharedState *ss,SQClosure *closure){
|
||||
SQGenerator *nc=(SQGenerator*)SQ_MALLOC(sizeof(SQGenerator));
|
||||
new (nc) SQGenerator(ss,closure);
|
||||
return nc;
|
||||
}
|
||||
~SQGenerator()
|
||||
{
|
||||
REMOVE_FROM_CHAIN(&_ss(this)->_gc_chain,this);
|
||||
}
|
||||
void Kill(){
|
||||
_state=eDead;
|
||||
_stack.resize(0);
|
||||
_closure=_null_;}
|
||||
void Release(){
|
||||
sq_delete(this,SQGenerator);
|
||||
}
|
||||
bool Yield(SQVM *v);
|
||||
bool Resume(SQVM *v,SQInteger target);
|
||||
#ifndef NO_GARBAGE_COLLECTOR
|
||||
void Mark(SQCollectable **chain);
|
||||
void Finalize(){_stack.resize(0);_closure=_null_;}
|
||||
#endif
|
||||
void Iterate( CSQStateIterator *pIterator );
|
||||
|
||||
SQObjectPtr _closure;
|
||||
SQObjectPtrVec _stack;
|
||||
SQObjectPtrVec _vargsstack;
|
||||
SQVM::CallInfo _ci;
|
||||
ExceptionsTraps _etraps;
|
||||
SQGeneratorState _state;
|
||||
};
|
||||
|
||||
struct SQNativeClosure : public CHAINABLE_OBJ
|
||||
{
|
||||
private:
|
||||
SQNativeClosure(SQSharedState *ss,SQFUNCTION func){_function=func;INIT_CHAIN();ADD_TO_CHAIN(&_ss(this)->_gc_chain,this); }
|
||||
public:
|
||||
static SQNativeClosure *Create(SQSharedState *ss,SQFUNCTION func)
|
||||
{
|
||||
SQNativeClosure *nc=(SQNativeClosure*)SQ_MALLOC(sizeof(SQNativeClosure));
|
||||
new (nc) SQNativeClosure(ss,func);
|
||||
return nc;
|
||||
}
|
||||
SQNativeClosure *Clone()
|
||||
{
|
||||
SQNativeClosure * ret = SQNativeClosure::Create(_opt_ss(this),_function);
|
||||
ret->_env = _env;
|
||||
ret->_name = _name;
|
||||
ret->_outervalues.copy(_outervalues);
|
||||
ret->_typecheck.copy(_typecheck);
|
||||
ret->_nparamscheck = _nparamscheck;
|
||||
return ret;
|
||||
}
|
||||
~SQNativeClosure()
|
||||
{
|
||||
REMOVE_FROM_CHAIN(&_ss(this)->_gc_chain,this);
|
||||
}
|
||||
void Release(){
|
||||
sq_delete(this,SQNativeClosure);
|
||||
}
|
||||
#ifndef NO_GARBAGE_COLLECTOR
|
||||
void Mark(SQCollectable **chain);
|
||||
void Finalize(){_outervalues.resize(0);}
|
||||
#endif
|
||||
void Iterate( CSQStateIterator *pIterator );
|
||||
|
||||
SQInteger _nparamscheck;
|
||||
SQIntVec _typecheck;
|
||||
SQObjectPtrVec _outervalues;
|
||||
SQObjectPtr _env;
|
||||
SQFUNCTION _function;
|
||||
SQObjectPtr _name;
|
||||
};
|
||||
|
||||
#if defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST)
|
||||
#include "memdbgoff.h"
|
||||
#endif
|
||||
#endif //_SQCLOSURE_H_
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,77 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#ifndef _SQCOMPILER_H_
|
||||
#define _SQCOMPILER_H_
|
||||
|
||||
struct SQVM;
|
||||
|
||||
#define TK_IDENTIFIER 258
|
||||
#define TK_STRING_LITERAL 259
|
||||
#define TK_INTEGER 260
|
||||
#define TK_FLOAT 261
|
||||
#define TK_DELEGATE 262
|
||||
#define TK_DELETE 263
|
||||
#define TK_EQ 264
|
||||
#define TK_NE 265
|
||||
#define TK_LE 266
|
||||
#define TK_GE 267
|
||||
#define TK_SWITCH 268
|
||||
#define TK_ARROW 269
|
||||
#define TK_AND 270
|
||||
#define TK_OR 271
|
||||
#define TK_IF 272
|
||||
#define TK_ELSE 273
|
||||
#define TK_WHILE 274
|
||||
#define TK_BREAK 275
|
||||
#define TK_FOR 276
|
||||
#define TK_DO 277
|
||||
#define TK_NULL 278
|
||||
#define TK_FOREACH 279
|
||||
#define TK_IN 280
|
||||
#define TK_NEWSLOT 281
|
||||
#define TK_MODULO 282
|
||||
#define TK_LOCAL 283
|
||||
#define TK_CLONE 284
|
||||
#define TK_FUNCTION 285
|
||||
#define TK_RETURN 286
|
||||
#define TK_TYPEOF 287
|
||||
#define TK_UMINUS 288
|
||||
#define TK_PLUSEQ 289
|
||||
#define TK_MINUSEQ 290
|
||||
#define TK_CONTINUE 291
|
||||
#define TK_YIELD 292
|
||||
#define TK_TRY 293
|
||||
#define TK_CATCH 294
|
||||
#define TK_THROW 295
|
||||
#define TK_SHIFTL 296
|
||||
#define TK_SHIFTR 297
|
||||
#define TK_RESUME 298
|
||||
#define TK_DOUBLE_COLON 299
|
||||
#define TK_CASE 300
|
||||
#define TK_DEFAULT 301
|
||||
#define TK_THIS 302
|
||||
#define TK_PLUSPLUS 303
|
||||
#define TK_MINUSMINUS 304
|
||||
#define TK_PARENT 305
|
||||
#define TK_USHIFTR 306
|
||||
#define TK_CLASS 307
|
||||
#define TK_EXTENDS 308
|
||||
#define TK_CONSTRUCTOR 310
|
||||
#define TK_INSTANCEOF 311
|
||||
#define TK_VARPARAMS 312
|
||||
#define TK_VARGC 313
|
||||
#define TK_VARGV 314
|
||||
#define TK_TRUE 315
|
||||
#define TK_FALSE 316
|
||||
#define TK_MULEQ 317
|
||||
#define TK_DIVEQ 318
|
||||
#define TK_MODEQ 319
|
||||
#define TK_ATTR_OPEN 320
|
||||
#define TK_ATTR_CLOSE 321
|
||||
#define TK_STATIC 322
|
||||
#define TK_ENUM 323
|
||||
#define TK_CONST 324
|
||||
|
||||
|
||||
typedef void(*CompilerErrorFunc)(void *ud, const SQChar *s);
|
||||
bool Compile(SQVM *vm, SQLEXREADFUNC rg, SQUserPointer up, const SQChar *sourcename, SQObjectPtr &out, bool raiseerror, bool lineinfo);
|
||||
#endif //_SQCOMPILER_H_
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
#include "sqpcheader.h"
|
||||
#include <stdarg.h>
|
||||
#include "sqvm.h"
|
||||
#include "sqfuncproto.h"
|
||||
#include "sqclosure.h"
|
||||
#include "sqstring.h"
|
||||
#if defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST)
|
||||
#include "memdbgon.h"
|
||||
#endif
|
||||
|
||||
SQRESULT sq_getfunctioninfo(HSQUIRRELVM v,SQInteger level,SQFunctionInfo *fi)
|
||||
{
|
||||
SQInteger cssize = v->_callsstacksize;
|
||||
if (cssize > level) {
|
||||
SQVM::CallInfo &ci = v->_callsstack[cssize-level-1];
|
||||
if(sq_isclosure(ci._closure)) {
|
||||
SQClosure *c = _closure(ci._closure);
|
||||
SQFunctionProto *proto = _funcproto(c->_function);
|
||||
fi->funcid = proto;
|
||||
fi->name = type(proto->_name) == OT_STRING?_stringval(proto->_name):_SC("unknown");
|
||||
fi->source = type(proto->_name) == OT_STRING?_stringval(proto->_sourcename):_SC("unknown");
|
||||
return SQ_OK;
|
||||
}
|
||||
}
|
||||
return sq_throwerror(v,_SC("the object is not a closure"));
|
||||
}
|
||||
|
||||
SQRESULT sq_stackinfos(HSQUIRRELVM v, SQInteger level, SQStackInfos *si)
|
||||
{
|
||||
SQInteger cssize = v->_callsstacksize;
|
||||
if (cssize > level) {
|
||||
memset(si, 0, sizeof(SQStackInfos));
|
||||
SQVM::CallInfo &ci = v->_callsstack[cssize-level-1];
|
||||
switch (type(ci._closure)) {
|
||||
case OT_CLOSURE:{
|
||||
SQFunctionProto *func = _funcproto(_closure(ci._closure)->_function);
|
||||
if (type(func->_name) == OT_STRING)
|
||||
si->funcname = _stringval(func->_name);
|
||||
if (type(func->_sourcename) == OT_STRING)
|
||||
si->source = _stringval(func->_sourcename);
|
||||
si->line = func->GetLine(ci._ip);
|
||||
}
|
||||
break;
|
||||
case OT_NATIVECLOSURE:
|
||||
si->source = _SC("NATIVE");
|
||||
si->funcname = _SC("unknown");
|
||||
if(type(_nativeclosure(ci._closure)->_name) == OT_STRING)
|
||||
si->funcname = _stringval(_nativeclosure(ci._closure)->_name);
|
||||
si->line = -1;
|
||||
break;
|
||||
default: break; //shutup compiler
|
||||
}
|
||||
return SQ_OK;
|
||||
}
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
void SQVM::Raise_Error(const SQChar *s, ...)
|
||||
{
|
||||
va_list vl;
|
||||
va_start(vl, s);
|
||||
scvsprintf(_sp(rsl((SQInteger)scstrlen(s)+(NUMBER_MAX_CHAR*2))), s, vl);
|
||||
va_end(vl);
|
||||
_lasterror = SQString::Create(_ss(this),_spval,-1);
|
||||
}
|
||||
|
||||
void SQVM::Raise_Error(SQObjectPtr &desc)
|
||||
{
|
||||
_lasterror = desc;
|
||||
}
|
||||
|
||||
SQString *SQVM::PrintObjVal(const SQObject &o)
|
||||
{
|
||||
switch(type(o)) {
|
||||
case OT_STRING: return _string(o);
|
||||
case OT_INTEGER:
|
||||
scsprintf(_sp(rsl(NUMBER_MAX_CHAR+1)), _SC("%d"), _integer(o));
|
||||
return SQString::Create(_ss(this), _spval);
|
||||
break;
|
||||
case OT_FLOAT:
|
||||
scsprintf(_sp(rsl(NUMBER_MAX_CHAR+1)), _SC("%.14g"), _float(o));
|
||||
return SQString::Create(_ss(this), _spval);
|
||||
break;
|
||||
default:
|
||||
return SQString::Create(_ss(this), GetTypeName(o));
|
||||
}
|
||||
}
|
||||
|
||||
void SQVM::Raise_IdxError(SQObject &o)
|
||||
{
|
||||
SQObjectPtr oval = PrintObjVal(o);
|
||||
Raise_Error(_SC("the index '%.50s' does not exist"), _stringval(oval));
|
||||
}
|
||||
|
||||
void SQVM::Raise_CompareError(const SQObject &o1, const SQObject &o2)
|
||||
{
|
||||
SQObjectPtr oval1 = PrintObjVal(o1), oval2 = PrintObjVal(o2);
|
||||
Raise_Error(_SC("comparsion between '%.50s' and '%.50s'"), _stringval(oval1), _stringval(oval2));
|
||||
}
|
||||
|
||||
|
||||
void SQVM::Raise_ParamTypeError(SQInteger nparam,SQInteger typemask,SQInteger type)
|
||||
{
|
||||
SQObjectPtr exptypes = SQString::Create(_ss(this), _SC(""), -1);
|
||||
SQInteger found = 0;
|
||||
for(SQInteger i=0; i<16; i++)
|
||||
{
|
||||
SQInteger mask = 0x00000001 << i;
|
||||
if(typemask & (mask)) {
|
||||
if(found>0) StringCat(exptypes,SQString::Create(_ss(this), _SC("|"), -1), exptypes);
|
||||
found ++;
|
||||
StringCat(exptypes,SQString::Create(_ss(this), IdType2Name((SQObjectType)mask), -1), exptypes);
|
||||
}
|
||||
}
|
||||
Raise_Error(_SC("parameter %d has an invalid type '%s' ; expected: '%s'"), nparam, IdType2Name((SQObjectType)type), _stringval(exptypes));
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#ifndef _SQFUNCTION_H_
|
||||
#define _SQFUNCTION_H_
|
||||
|
||||
#include "sqopcodes.h"
|
||||
|
||||
#if defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST)
|
||||
#include "memdbgon.h"
|
||||
#undef new // allow placement new
|
||||
#endif
|
||||
|
||||
enum SQOuterType {
|
||||
otLOCAL = 0,
|
||||
otSYMBOL = 1,
|
||||
otOUTER = 2
|
||||
};
|
||||
|
||||
struct SQOuterVar
|
||||
{
|
||||
|
||||
SQOuterVar(){}
|
||||
SQOuterVar(const SQObjectPtr &name,const SQObjectPtr &src,SQOuterType t)
|
||||
{
|
||||
_name = name;
|
||||
_src=src;
|
||||
_type=t;
|
||||
}
|
||||
SQOuterVar(const SQOuterVar &ov)
|
||||
{
|
||||
_type=ov._type;
|
||||
_src=ov._src;
|
||||
_name=ov._name;
|
||||
}
|
||||
SQOuterType _type;
|
||||
SQObjectPtr _name;
|
||||
SQObjectPtr _src;
|
||||
};
|
||||
|
||||
struct SQLocalVarInfo
|
||||
{
|
||||
SQLocalVarInfo():_start_op(0),_end_op(0){}
|
||||
SQLocalVarInfo(const SQLocalVarInfo &lvi)
|
||||
{
|
||||
_name=lvi._name;
|
||||
_start_op=lvi._start_op;
|
||||
_end_op=lvi._end_op;
|
||||
_pos=lvi._pos;
|
||||
}
|
||||
SQObjectPtr _name;
|
||||
SQUnsignedInteger _start_op;
|
||||
SQUnsignedInteger _end_op;
|
||||
SQUnsignedInteger _pos;
|
||||
};
|
||||
|
||||
struct SQLineInfo { SQInteger _line;SQInteger _op; };
|
||||
|
||||
typedef sqvector<SQOuterVar> SQOuterVarVec;
|
||||
typedef sqvector<SQLocalVarInfo> SQLocalVarInfoVec;
|
||||
typedef sqvector<SQLineInfo> SQLineInfoVec;
|
||||
|
||||
#define _FUNC_SIZE(ni,nl,nparams,nfuncs,nouters,nlineinf,localinf,defparams) (sizeof(SQFunctionProto) \
|
||||
+((ni-1)*sizeof(SQInstruction))+(nl*sizeof(SQObjectPtr)) \
|
||||
+(nparams*sizeof(SQObjectPtr))+(nfuncs*sizeof(SQObjectPtr)) \
|
||||
+(nouters*sizeof(SQOuterVar))+(nlineinf*sizeof(SQLineInfo)) \
|
||||
+(localinf*sizeof(SQLocalVarInfo))+(defparams*sizeof(SQInteger)))
|
||||
|
||||
#define _CONSTRUCT_VECTOR(type,size,ptr) { \
|
||||
for(SQInteger n = 0; n < size; n++) { \
|
||||
new (&ptr[n]) type(); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define _DESTRUCT_VECTOR(type,size,ptr) { \
|
||||
for(SQInteger nl = 0; nl < size; nl++) { \
|
||||
ptr[nl].~type(); \
|
||||
} \
|
||||
}
|
||||
struct SQFunctionProto : public SQRefCounted
|
||||
{
|
||||
private:
|
||||
SQFunctionProto(){
|
||||
_stacksize=0;
|
||||
_bgenerator=false;}
|
||||
public:
|
||||
static SQFunctionProto *Create(SQInteger ninstructions,
|
||||
SQInteger nliterals,SQInteger nparameters,
|
||||
SQInteger nfunctions,SQInteger noutervalues,
|
||||
SQInteger nlineinfos,SQInteger nlocalvarinfos,SQInteger ndefaultparams)
|
||||
{
|
||||
SQFunctionProto *f;
|
||||
//I compact the whole class and members in a single memory allocation
|
||||
f = (SQFunctionProto *)sq_vm_malloc(_FUNC_SIZE(ninstructions,nliterals,nparameters,nfunctions,noutervalues,nlineinfos,nlocalvarinfos,ndefaultparams));
|
||||
new (f) SQFunctionProto;
|
||||
f->_ninstructions = ninstructions;
|
||||
f->_literals = (SQObjectPtr*)&f->_instructions[ninstructions];
|
||||
f->_nliterals = nliterals;
|
||||
f->_parameters = (SQObjectPtr*)&f->_literals[nliterals];
|
||||
f->_nparameters = nparameters;
|
||||
f->_functions = (SQObjectPtr*)&f->_parameters[nparameters];
|
||||
f->_nfunctions = nfunctions;
|
||||
f->_outervalues = (SQOuterVar*)&f->_functions[nfunctions];
|
||||
f->_noutervalues = noutervalues;
|
||||
f->_lineinfos = (SQLineInfo *)&f->_outervalues[noutervalues];
|
||||
f->_nlineinfos = nlineinfos;
|
||||
f->_localvarinfos = (SQLocalVarInfo *)&f->_lineinfos[nlineinfos];
|
||||
f->_nlocalvarinfos = nlocalvarinfos;
|
||||
f->_defaultparams = (SQInteger *)&f->_localvarinfos[nlocalvarinfos];
|
||||
f->_ndefaultparams = ndefaultparams;
|
||||
|
||||
_CONSTRUCT_VECTOR(SQObjectPtr,f->_nliterals,f->_literals);
|
||||
_CONSTRUCT_VECTOR(SQObjectPtr,f->_nparameters,f->_parameters);
|
||||
_CONSTRUCT_VECTOR(SQObjectPtr,f->_nfunctions,f->_functions);
|
||||
_CONSTRUCT_VECTOR(SQOuterVar,f->_noutervalues,f->_outervalues);
|
||||
//_CONSTRUCT_VECTOR(SQLineInfo,f->_nlineinfos,f->_lineinfos); //not required are 2 integers
|
||||
_CONSTRUCT_VECTOR(SQLocalVarInfo,f->_nlocalvarinfos,f->_localvarinfos);
|
||||
return f;
|
||||
}
|
||||
void Release(){
|
||||
_DESTRUCT_VECTOR(SQObjectPtr,_nliterals,_literals);
|
||||
_DESTRUCT_VECTOR(SQObjectPtr,_nparameters,_parameters);
|
||||
_DESTRUCT_VECTOR(SQObjectPtr,_nfunctions,_functions);
|
||||
_DESTRUCT_VECTOR(SQOuterVar,_noutervalues,_outervalues);
|
||||
//_DESTRUCT_VECTOR(SQLineInfo,_nlineinfos,_lineinfos); //not required are 2 integers
|
||||
_DESTRUCT_VECTOR(SQLocalVarInfo,_nlocalvarinfos,_localvarinfos);
|
||||
SQInteger size = _FUNC_SIZE(_ninstructions,_nliterals,_nparameters,_nfunctions,_noutervalues,_nlineinfos,_nlocalvarinfos,_ndefaultparams);
|
||||
this->~SQFunctionProto();
|
||||
sq_vm_free(this,size);
|
||||
}
|
||||
const SQChar* GetLocal(SQVM *v,SQUnsignedInteger stackbase,SQUnsignedInteger nseq,SQUnsignedInteger nop);
|
||||
SQInteger GetLine(SQInstruction *curr);
|
||||
bool Save(SQVM *v,SQUserPointer up,SQWRITEFUNC write);
|
||||
static bool Load(SQVM *v,SQUserPointer up,SQREADFUNC read,SQObjectPtr &ret);
|
||||
|
||||
SQObjectPtr _sourcename;
|
||||
SQObjectPtr _name;
|
||||
SQInteger _stacksize;
|
||||
bool _bgenerator;
|
||||
bool _varparams;
|
||||
|
||||
SQInteger _nlocalvarinfos;
|
||||
SQLocalVarInfo *_localvarinfos;
|
||||
|
||||
SQInteger _nlineinfos;
|
||||
SQLineInfo *_lineinfos;
|
||||
|
||||
SQInteger _nliterals;
|
||||
SQObjectPtr *_literals;
|
||||
|
||||
SQInteger _nparameters;
|
||||
SQObjectPtr *_parameters;
|
||||
|
||||
SQInteger _nfunctions;
|
||||
SQObjectPtr *_functions;
|
||||
|
||||
SQInteger _noutervalues;
|
||||
SQOuterVar *_outervalues;
|
||||
|
||||
SQInteger _ndefaultparams;
|
||||
SQInteger *_defaultparams;
|
||||
|
||||
SQInteger _ninstructions;
|
||||
SQInstruction _instructions[1];
|
||||
};
|
||||
|
||||
#if defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST)
|
||||
#include "memdbgoff.h"
|
||||
#endif
|
||||
|
||||
#endif //_SQFUNCTION_H_
|
||||
@@ -0,0 +1,571 @@
|
||||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
#include "sqpcheader.h"
|
||||
#include "sqcompiler.h"
|
||||
#include "sqfuncproto.h"
|
||||
#include "sqstring.h"
|
||||
#include "sqtable.h"
|
||||
#include "sqopcodes.h"
|
||||
#include "sqfuncstate.h"
|
||||
#if defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST)
|
||||
#include "memdbgon.h"
|
||||
#undef new // allow placement new
|
||||
#endif
|
||||
|
||||
#ifdef _DEBUG_DUMP
|
||||
SQInstructionDesc g_InstrDesc[]={
|
||||
{_SC("_OP_LINE")},
|
||||
{_SC("_OP_LOAD")},
|
||||
{_SC("_OP_LOADINT")},
|
||||
{_SC("_OP_LOADFLOAT")},
|
||||
{_SC("_OP_DLOAD")},
|
||||
{_SC("_OP_TAILCALL")},
|
||||
{_SC("_OP_CALL")},
|
||||
{_SC("_OP_PREPCALL")},
|
||||
{_SC("_OP_PREPCALLK")},
|
||||
{_SC("_OP_GETK")},
|
||||
{_SC("_OP_MOVE")},
|
||||
{_SC("_OP_NEWSLOT")},
|
||||
{_SC("_OP_DELETE")},
|
||||
{_SC("_OP_SET")},
|
||||
{_SC("_OP_GET")},
|
||||
{_SC("_OP_EQ")},
|
||||
{_SC("_OP_NE")},
|
||||
{_SC("_OP_ARITH")},
|
||||
{_SC("_OP_BITW")},
|
||||
{_SC("_OP_RETURN")},
|
||||
{_SC("_OP_LOADNULLS")},
|
||||
{_SC("_OP_LOADROOTTABLE")},
|
||||
{_SC("_OP_LOADBOOL")},
|
||||
{_SC("_OP_DMOVE")},
|
||||
{_SC("_OP_JMP")},
|
||||
{_SC("_OP_JNZ")},
|
||||
{_SC("_OP_JZ")},
|
||||
{_SC("_OP_LOADFREEVAR")},
|
||||
{_SC("_OP_VARGC")},
|
||||
{_SC("_OP_GETVARGV")},
|
||||
{_SC("_OP_NEWTABLE")},
|
||||
{_SC("_OP_NEWARRAY")},
|
||||
{_SC("_OP_APPENDARRAY")},
|
||||
{_SC("_OP_GETPARENT")},
|
||||
{_SC("_OP_COMPARITH")},
|
||||
{_SC("_OP_COMPARITHL")},
|
||||
{_SC("_OP_INC")},
|
||||
{_SC("_OP_INCL")},
|
||||
{_SC("_OP_PINC")},
|
||||
{_SC("_OP_PINCL")},
|
||||
{_SC("_OP_CMP")},
|
||||
{_SC("_OP_EXISTS")},
|
||||
{_SC("_OP_INSTANCEOF")},
|
||||
{_SC("_OP_AND")},
|
||||
{_SC("_OP_OR")},
|
||||
{_SC("_OP_NEG")},
|
||||
{_SC("_OP_NOT")},
|
||||
{_SC("_OP_BWNOT")},
|
||||
{_SC("_OP_CLOSURE")},
|
||||
{_SC("_OP_YIELD")},
|
||||
{_SC("_OP_RESUME")},
|
||||
{_SC("_OP_FOREACH")},
|
||||
{_SC("_OP_POSTFOREACH")},
|
||||
{_SC("_OP_DELEGATE")},
|
||||
{_SC("_OP_CLONE")},
|
||||
{_SC("_OP_TYPEOF")},
|
||||
{_SC("_OP_PUSHTRAP")},
|
||||
{_SC("_OP_POPTRAP")},
|
||||
{_SC("_OP_THROW")},
|
||||
{_SC("_OP_CLASS")},
|
||||
{_SC("_OP_NEWSLOTA")}
|
||||
};
|
||||
#endif
|
||||
void DumpLiteral(SQObjectPtr &o)
|
||||
{
|
||||
switch(type(o)){
|
||||
case OT_STRING: scprintf(_SC("\"%s\""),_stringval(o));break;
|
||||
case OT_FLOAT: scprintf(_SC("{%f}"),_float(o));break;
|
||||
case OT_INTEGER: scprintf(_SC("{%d}"),_integer(o));break;
|
||||
case OT_BOOL: scprintf(_SC("%s"),_integer(o)?_SC("true"):_SC("false"));break;
|
||||
default: scprintf(_SC("(%s %p)"),GetTypeName(o),(void*)_rawval(o));break; break; //shut up compiler
|
||||
}
|
||||
}
|
||||
|
||||
SQFuncState::SQFuncState(SQSharedState *ss,SQFuncState *parent,CompilerErrorFunc efunc,void *ed)
|
||||
{
|
||||
_nliterals = 0;
|
||||
_literals = SQTable::Create(ss,0);
|
||||
_strings = SQTable::Create(ss,0);
|
||||
_sharedstate = ss;
|
||||
_lastline = 0;
|
||||
_optimization = true;
|
||||
_parent = parent;
|
||||
_stacksize = 0;
|
||||
_traps = 0;
|
||||
_returnexp = 0;
|
||||
_varparams = false;
|
||||
_errfunc = efunc;
|
||||
_errtarget = ed;
|
||||
_bgenerator = false;
|
||||
|
||||
}
|
||||
|
||||
void SQFuncState::Error(const SQChar *err)
|
||||
{
|
||||
_errfunc(_errtarget,err);
|
||||
}
|
||||
|
||||
#ifdef _DEBUG_DUMP
|
||||
void SQFuncState::Dump(SQFunctionProto *func)
|
||||
{
|
||||
SQUnsignedInteger n=0,i;
|
||||
SQInteger si;
|
||||
scprintf(_SC("SQInstruction sizeof %d\n"),sizeof(SQInstruction));
|
||||
scprintf(_SC("SQObject sizeof %d\n"),sizeof(SQObject));
|
||||
scprintf(_SC("--------------------------------------------------------------------\n"));
|
||||
scprintf(_SC("*****FUNCTION [%s]\n"),type(func->_name)==OT_STRING?_stringval(func->_name):_SC("unknown"));
|
||||
scprintf(_SC("-----LITERALS\n"));
|
||||
SQObjectPtr refidx,key,val;
|
||||
SQInteger idx;
|
||||
SQObjectPtrVec templiterals;
|
||||
templiterals.resize(_nliterals);
|
||||
while((idx=_table(_literals)->Next(false,refidx,key,val))!=-1) {
|
||||
refidx=idx;
|
||||
templiterals[_integer(val)]=key;
|
||||
}
|
||||
for(i=0;i<templiterals.size();i++){
|
||||
scprintf(_SC("[%d] "),n);
|
||||
DumpLiteral(templiterals[i]);
|
||||
scprintf(_SC("\n"));
|
||||
n++;
|
||||
}
|
||||
scprintf(_SC("-----PARAMS\n"));
|
||||
if(_varparams)
|
||||
scprintf(_SC("<<VARPARAMS>>\n"));
|
||||
n=0;
|
||||
for(i=0;i<_parameters.size();i++){
|
||||
scprintf(_SC("[%d] "),n);
|
||||
DumpLiteral(_parameters[i]);
|
||||
scprintf(_SC("\n"));
|
||||
n++;
|
||||
}
|
||||
scprintf(_SC("-----LOCALS\n"));
|
||||
for(si=0;si<func->_nlocalvarinfos;si++){
|
||||
SQLocalVarInfo lvi=func->_localvarinfos[si];
|
||||
scprintf(_SC("[%d] %s \t%d %d\n"),lvi._pos,_stringval(lvi._name),lvi._start_op,lvi._end_op);
|
||||
n++;
|
||||
}
|
||||
scprintf(_SC("-----LINE INFO\n"));
|
||||
for(i=0;i<_lineinfos.size();i++){
|
||||
SQLineInfo li=_lineinfos[i];
|
||||
scprintf(_SC("op [%d] line [%d] \n"),li._op,li._line);
|
||||
n++;
|
||||
}
|
||||
scprintf(_SC("-----dump\n"));
|
||||
n=0;
|
||||
for(i=0;i<_instructions.size();i++){
|
||||
SQInstruction &inst=_instructions[i];
|
||||
if(inst.op==_OP_LOAD || inst.op==_OP_DLOAD || inst.op==_OP_PREPCALLK || inst.op==_OP_GETK ){
|
||||
|
||||
SQInteger lidx = inst._arg1;
|
||||
scprintf(_SC("[%03d] %15s %d "),n,g_InstrDesc[inst.op].name,inst._arg0);
|
||||
if(lidx >= 0xFFFFFFFF)
|
||||
scprintf(_SC("null"));
|
||||
else {
|
||||
SQInteger refidx;
|
||||
SQObjectPtr val,key,refo;
|
||||
while(((refidx=_table(_literals)->Next(false,refo,key,val))!= -1) && (_integer(val) != lidx)) {
|
||||
refo = refidx;
|
||||
}
|
||||
DumpLiteral(key);
|
||||
}
|
||||
if(inst.op != _OP_DLOAD) {
|
||||
scprintf(_SC(" %d %d \n"),inst._arg2,inst._arg3);
|
||||
}
|
||||
else {
|
||||
scprintf(_SC(" %d "),inst._arg2);
|
||||
lidx = inst._arg3;
|
||||
if(lidx >= 0xFFFFFFFF)
|
||||
scprintf(_SC("null"));
|
||||
else {
|
||||
SQInteger refidx;
|
||||
SQObjectPtr val,key,refo;
|
||||
while(((refidx=_table(_literals)->Next(false,refo,key,val))!= -1) && (_integer(val) != lidx)) {
|
||||
refo = refidx;
|
||||
}
|
||||
DumpLiteral(key);
|
||||
scprintf(_SC("\n"));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(inst.op==_OP_LOADFLOAT) {
|
||||
scprintf(_SC("[%03d] %15s %d %f %d %d\n"),n,g_InstrDesc[inst.op].name,inst._arg0,*((SQFloat*)&inst._arg1),inst._arg2,inst._arg3);
|
||||
}
|
||||
else if(inst.op==_OP_ARITH){
|
||||
scprintf(_SC("[%03d] %15s %d %d %d %c\n"),n,g_InstrDesc[inst.op].name,inst._arg0,inst._arg1,inst._arg2,inst._arg3);
|
||||
}
|
||||
else
|
||||
scprintf(_SC("[%03d] %15s %d %d %d %d\n"),n,g_InstrDesc[inst.op].name,inst._arg0,inst._arg1,inst._arg2,inst._arg3);
|
||||
n++;
|
||||
}
|
||||
scprintf(_SC("-----\n"));
|
||||
scprintf(_SC("stack size[%d]\n"),func->_stacksize);
|
||||
scprintf(_SC("--------------------------------------------------------------------\n\n"));
|
||||
}
|
||||
#endif
|
||||
|
||||
SQInteger SQFuncState::GetNumericConstant(const SQInteger cons)
|
||||
{
|
||||
return GetConstant(SQObjectPtr(cons));
|
||||
}
|
||||
|
||||
SQInteger SQFuncState::GetNumericConstant(const SQFloat cons)
|
||||
{
|
||||
return GetConstant(SQObjectPtr(cons));
|
||||
}
|
||||
|
||||
SQInteger SQFuncState::GetConstant(const SQObject &cons)
|
||||
{
|
||||
SQObjectPtr val;
|
||||
if(!_table(_literals)->Get(cons,val))
|
||||
{
|
||||
val = _nliterals;
|
||||
_table(_literals)->NewSlot(cons,val);
|
||||
_nliterals++;
|
||||
if(_nliterals > MAX_LITERALS) {
|
||||
val.Null();
|
||||
Error(_SC("internal compiler error: too many literals"));
|
||||
}
|
||||
}
|
||||
return _integer(val);
|
||||
}
|
||||
|
||||
void SQFuncState::SetIntructionParams(SQInteger pos,SQInteger arg0,SQInteger arg1,SQInteger arg2,SQInteger arg3)
|
||||
{
|
||||
_instructions[pos]._arg0=(unsigned char)*((SQUnsignedInteger *)&arg0);
|
||||
_instructions[pos]._arg1=(SQInt32)*((SQUnsignedInteger *)&arg1);
|
||||
_instructions[pos]._arg2=(unsigned char)*((SQUnsignedInteger *)&arg2);
|
||||
_instructions[pos]._arg3=(unsigned char)*((SQUnsignedInteger *)&arg3);
|
||||
}
|
||||
|
||||
void SQFuncState::SetIntructionParam(SQInteger pos,SQInteger arg,SQInteger val)
|
||||
{
|
||||
switch(arg){
|
||||
case 0:_instructions[pos]._arg0=(unsigned char)*((SQUnsignedInteger *)&val);break;
|
||||
case 1:case 4:_instructions[pos]._arg1=(SQInt32)*((SQUnsignedInteger *)&val);break;
|
||||
case 2:_instructions[pos]._arg2=(unsigned char)*((SQUnsignedInteger *)&val);break;
|
||||
case 3:_instructions[pos]._arg3=(unsigned char)*((SQUnsignedInteger *)&val);break;
|
||||
};
|
||||
}
|
||||
|
||||
SQInteger SQFuncState::AllocStackPos()
|
||||
{
|
||||
SQInteger npos=_vlocals.size();
|
||||
_vlocals.push_back(SQLocalVarInfo());
|
||||
if(_vlocals.size()>((SQUnsignedInteger)_stacksize)) {
|
||||
if(_stacksize>MAX_FUNC_STACKSIZE) Error(_SC("internal compiler error: too many locals"));
|
||||
_stacksize=_vlocals.size();
|
||||
}
|
||||
return npos;
|
||||
}
|
||||
|
||||
SQInteger SQFuncState::PushTarget(SQInteger n)
|
||||
{
|
||||
if(n!=-1){
|
||||
_targetstack.push_back(n);
|
||||
return n;
|
||||
}
|
||||
n=AllocStackPos();
|
||||
_targetstack.push_back(n);
|
||||
return n;
|
||||
}
|
||||
|
||||
SQInteger SQFuncState::GetUpTarget(SQInteger n){
|
||||
return _targetstack[((_targetstack.size()-1)-n)];
|
||||
}
|
||||
|
||||
SQInteger SQFuncState::TopTarget(){
|
||||
return _targetstack.back();
|
||||
}
|
||||
SQInteger SQFuncState::PopTarget()
|
||||
{
|
||||
SQInteger npos=_targetstack.back();
|
||||
SQLocalVarInfo t=_vlocals[_targetstack.back()];
|
||||
if(type(t._name)==OT_NULL){
|
||||
_vlocals.pop_back();
|
||||
}
|
||||
_targetstack.pop_back();
|
||||
return npos;
|
||||
}
|
||||
|
||||
SQInteger SQFuncState::GetStackSize()
|
||||
{
|
||||
return _vlocals.size();
|
||||
}
|
||||
|
||||
void SQFuncState::SetStackSize(SQInteger n)
|
||||
{
|
||||
SQInteger size=_vlocals.size();
|
||||
while(size>n){
|
||||
size--;
|
||||
SQLocalVarInfo lvi=_vlocals.back();
|
||||
if(type(lvi._name)!=OT_NULL){
|
||||
lvi._end_op=GetCurrentPos();
|
||||
_localvarinfos.push_back(lvi);
|
||||
}
|
||||
_vlocals.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
bool SQFuncState::IsConstant(const SQObject &name,SQObject &e)
|
||||
{
|
||||
SQObjectPtr val;
|
||||
if(_table(_sharedstate->_consts)->Get(name,val)) {
|
||||
e = val;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SQFuncState::IsLocal(SQUnsignedInteger stkpos)
|
||||
{
|
||||
if(stkpos>=_vlocals.size())return false;
|
||||
else if(type(_vlocals[stkpos]._name)!=OT_NULL)return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
SQInteger SQFuncState::PushLocalVariable(const SQObject &name)
|
||||
{
|
||||
SQInteger pos=_vlocals.size();
|
||||
SQLocalVarInfo lvi;
|
||||
lvi._name=name;
|
||||
lvi._start_op=GetCurrentPos()+1;
|
||||
lvi._pos=_vlocals.size();
|
||||
_vlocals.push_back(lvi);
|
||||
if(_vlocals.size()>((SQUnsignedInteger)_stacksize))_stacksize=_vlocals.size();
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
SQInteger SQFuncState::GetLocalVariable(const SQObject &name)
|
||||
{
|
||||
SQInteger locals=_vlocals.size();
|
||||
while(locals>=1){
|
||||
if(type(_vlocals[locals-1]._name)==OT_STRING && _string(_vlocals[locals-1]._name)==_string(name)){
|
||||
return locals-1;
|
||||
}
|
||||
locals--;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
SQInteger SQFuncState::GetOuterVariable(const SQObject &name)
|
||||
{
|
||||
SQInteger outers = _outervalues.size();
|
||||
for(SQInteger i = 0; i<outers; i++) {
|
||||
if(_string(_outervalues[i]._name) == _string(name))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void SQFuncState::AddOuterValue(const SQObject &name)
|
||||
{
|
||||
SQInteger pos=-1;
|
||||
if(_parent) {
|
||||
pos = _parent->GetLocalVariable(name);
|
||||
if(pos == -1) {
|
||||
pos = _parent->GetOuterVariable(name);
|
||||
if(pos != -1) {
|
||||
_outervalues.push_back(SQOuterVar(name,SQObjectPtr(SQInteger(pos)),otOUTER)); //local
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
_outervalues.push_back(SQOuterVar(name,SQObjectPtr(SQInteger(pos)),otLOCAL)); //local
|
||||
return;
|
||||
}
|
||||
}
|
||||
_outervalues.push_back(SQOuterVar(name,name,otSYMBOL)); //global
|
||||
}
|
||||
|
||||
void SQFuncState::AddParameter(const SQObject &name)
|
||||
{
|
||||
PushLocalVariable(name);
|
||||
_parameters.push_back(name);
|
||||
}
|
||||
|
||||
void SQFuncState::AddLineInfos(SQInteger line,bool lineop,bool force)
|
||||
{
|
||||
if(_lastline!=line || force){
|
||||
SQLineInfo li;
|
||||
li._line=line;li._op=(GetCurrentPos()+1);
|
||||
if(lineop)AddInstruction(_OP_LINE,0,line);
|
||||
_lineinfos.push_back(li);
|
||||
_lastline=line;
|
||||
}
|
||||
}
|
||||
|
||||
void SQFuncState::AddInstruction(SQInstruction &i)
|
||||
{
|
||||
SQInteger size = _instructions.size();
|
||||
if(size > 0 && _optimization){ //simple optimizer
|
||||
SQInstruction &pi = _instructions[size-1];//previous instruction
|
||||
switch(i.op) {
|
||||
case _OP_RETURN:
|
||||
if( _parent && i._arg0 != MAX_FUNC_STACKSIZE && pi.op == _OP_CALL && _returnexp < size-1) {
|
||||
pi.op = _OP_TAILCALL;
|
||||
}
|
||||
break;
|
||||
case _OP_GET:
|
||||
if( pi.op == _OP_LOAD && pi._arg0 == i._arg2 && (!IsLocal(pi._arg0))){
|
||||
pi._arg1 = pi._arg1;
|
||||
pi._arg2 = (unsigned char)i._arg1;
|
||||
pi.op = _OP_GETK;
|
||||
pi._arg0 = i._arg0;
|
||||
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case _OP_PREPCALL:
|
||||
if( pi.op == _OP_LOAD && pi._arg0 == i._arg1 && (!IsLocal(pi._arg0))){
|
||||
pi.op = _OP_PREPCALLK;
|
||||
pi._arg0 = i._arg0;
|
||||
pi._arg1 = pi._arg1;
|
||||
pi._arg2 = i._arg2;
|
||||
pi._arg3 = i._arg3;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case _OP_APPENDARRAY:
|
||||
if(pi.op == _OP_LOAD && pi._arg0 == i._arg1 && (!IsLocal(pi._arg0))){
|
||||
pi.op = _OP_APPENDARRAY;
|
||||
pi._arg0 = i._arg0;
|
||||
pi._arg1 = pi._arg1;
|
||||
pi._arg2 = MAX_FUNC_STACKSIZE;
|
||||
pi._arg3 = MAX_FUNC_STACKSIZE;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case _OP_MOVE:
|
||||
if((pi.op == _OP_GET || pi.op == _OP_ARITH || pi.op == _OP_BITW) && (pi._arg0 == i._arg1))
|
||||
{
|
||||
pi._arg0 = i._arg0;
|
||||
_optimization = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if(pi.op == _OP_MOVE)
|
||||
{
|
||||
pi.op = _OP_DMOVE;
|
||||
pi._arg2 = i._arg0;
|
||||
pi._arg3 = (unsigned char)i._arg1;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case _OP_LOAD:
|
||||
if(pi.op == _OP_LOAD && i._arg1 < 256) {
|
||||
pi.op = _OP_DLOAD;
|
||||
pi._arg2 = i._arg0;
|
||||
pi._arg3 = (unsigned char)i._arg1;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case _OP_EQ:case _OP_NE:
|
||||
if(pi.op == _OP_LOAD && pi._arg0 == i._arg1 && (!IsLocal(pi._arg0) ))
|
||||
{
|
||||
pi.op = i.op;
|
||||
pi._arg0 = i._arg0;
|
||||
pi._arg1 = pi._arg1;
|
||||
pi._arg2 = i._arg2;
|
||||
pi._arg3 = MAX_FUNC_STACKSIZE;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case _OP_LOADNULLS:
|
||||
if((pi.op == _OP_LOADNULLS && pi._arg0+pi._arg1 == i._arg0)) {
|
||||
|
||||
pi._arg1 = pi._arg1 + 1;
|
||||
pi.op = _OP_LOADNULLS;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case _OP_LINE:
|
||||
if(pi.op == _OP_LINE) {
|
||||
_instructions.pop_back();
|
||||
_lineinfos.pop_back();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
_optimization = true;
|
||||
_instructions.push_back(i);
|
||||
}
|
||||
|
||||
SQObject SQFuncState::CreateString(const SQChar *s,SQInteger len)
|
||||
{
|
||||
SQObjectPtr ns(SQString::Create(_sharedstate,s,len));
|
||||
_table(_strings)->NewSlot(ns,(SQInteger)1);
|
||||
return ns;
|
||||
}
|
||||
|
||||
SQObject SQFuncState::CreateTable()
|
||||
{
|
||||
SQObjectPtr nt(SQTable::Create(_sharedstate,0));
|
||||
_table(_strings)->NewSlot(nt,(SQInteger)1);
|
||||
return nt;
|
||||
}
|
||||
|
||||
SQFunctionProto *SQFuncState::BuildProto()
|
||||
{
|
||||
SQFunctionProto *f=SQFunctionProto::Create(_instructions.size(),
|
||||
_nliterals,_parameters.size(),_functions.size(),_outervalues.size(),
|
||||
_lineinfos.size(),_localvarinfos.size(),_defaultparams.size());
|
||||
|
||||
SQObjectPtr refidx,key,val;
|
||||
SQInteger idx;
|
||||
|
||||
f->_stacksize = _stacksize;
|
||||
f->_sourcename = _sourcename;
|
||||
f->_bgenerator = _bgenerator;
|
||||
f->_name = _name;
|
||||
|
||||
while((idx=_table(_literals)->Next(false,refidx,key,val))!=-1) {
|
||||
f->_literals[_integer(val)]=key;
|
||||
refidx=idx;
|
||||
}
|
||||
|
||||
for(SQUnsignedInteger nf = 0; nf < _functions.size(); nf++) f->_functions[nf] = _functions[nf];
|
||||
for(SQUnsignedInteger np = 0; np < _parameters.size(); np++) f->_parameters[np] = _parameters[np];
|
||||
for(SQUnsignedInteger no = 0; no < _outervalues.size(); no++) f->_outervalues[no] = _outervalues[no];
|
||||
for(SQUnsignedInteger no = 0; no < _localvarinfos.size(); no++) f->_localvarinfos[no] = _localvarinfos[no];
|
||||
for(SQUnsignedInteger no = 0; no < _lineinfos.size(); no++) f->_lineinfos[no] = _lineinfos[no];
|
||||
for(SQUnsignedInteger no = 0; no < _defaultparams.size(); no++) f->_defaultparams[no] = _defaultparams[no];
|
||||
|
||||
memcpy(f->_instructions,&_instructions[0],_instructions.size()*sizeof(SQInstruction));
|
||||
|
||||
f->_varparams = _varparams;
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
SQFuncState *SQFuncState::PushChildState(SQSharedState *ss)
|
||||
{
|
||||
SQFuncState *child = (SQFuncState *)sq_malloc(sizeof(SQFuncState));
|
||||
new (child) SQFuncState(ss,this,_errfunc,_errtarget);
|
||||
_childstates.push_back(child);
|
||||
return child;
|
||||
}
|
||||
|
||||
void SQFuncState::PopChildState()
|
||||
{
|
||||
SQFuncState *child = _childstates.back();
|
||||
sq_delete(child,SQFuncState);
|
||||
_childstates.pop_back();
|
||||
}
|
||||
|
||||
SQFuncState::~SQFuncState()
|
||||
{
|
||||
while(_childstates.size() > 0)
|
||||
{
|
||||
PopChildState();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#ifndef _SQFUNCSTATE_H_
|
||||
#define _SQFUNCSTATE_H_
|
||||
///////////////////////////////////
|
||||
#include "squtils.h"
|
||||
|
||||
struct SQFuncState
|
||||
{
|
||||
SQFuncState(SQSharedState *ss,SQFuncState *parent,CompilerErrorFunc efunc,void *ed);
|
||||
~SQFuncState();
|
||||
#ifdef _DEBUG_DUMP
|
||||
void Dump(SQFunctionProto *func);
|
||||
#endif
|
||||
void Error(const SQChar *err);
|
||||
SQFuncState *PushChildState(SQSharedState *ss);
|
||||
void PopChildState();
|
||||
void AddInstruction(SQOpcode _op,SQInteger arg0=0,SQInteger arg1=0,SQInteger arg2=0,SQInteger arg3=0){SQInstruction i(_op,arg0,arg1,arg2,arg3);AddInstruction(i);}
|
||||
void AddInstruction(SQInstruction &i);
|
||||
void SetIntructionParams(SQInteger pos,SQInteger arg0,SQInteger arg1,SQInteger arg2=0,SQInteger arg3=0);
|
||||
void SetIntructionParam(SQInteger pos,SQInteger arg,SQInteger val);
|
||||
SQInstruction &GetInstruction(SQInteger pos){return _instructions[pos];}
|
||||
void PopInstructions(SQInteger size){for(SQInteger i=0;i<size;i++)_instructions.pop_back();}
|
||||
void SetStackSize(SQInteger n);
|
||||
void SnoozeOpt(){_optimization=false;}
|
||||
void AddDefaultParam(SQInteger trg) { _defaultparams.push_back(trg); }
|
||||
SQInteger GetDefaultParamCount() { return _defaultparams.size(); }
|
||||
SQInteger GetCurrentPos(){return _instructions.size()-1;}
|
||||
SQInteger GetNumericConstant(const SQInteger cons);
|
||||
SQInteger GetNumericConstant(const SQFloat cons);
|
||||
SQInteger PushLocalVariable(const SQObject &name);
|
||||
void AddParameter(const SQObject &name);
|
||||
void AddOuterValue(const SQObject &name);
|
||||
SQInteger GetLocalVariable(const SQObject &name);
|
||||
SQInteger GetOuterVariable(const SQObject &name);
|
||||
SQInteger GenerateCode();
|
||||
SQInteger GetStackSize();
|
||||
SQInteger CalcStackFrameSize();
|
||||
void AddLineInfos(SQInteger line,bool lineop,bool force=false);
|
||||
SQFunctionProto *BuildProto();
|
||||
SQInteger AllocStackPos();
|
||||
SQInteger PushTarget(SQInteger n=-1);
|
||||
SQInteger PopTarget();
|
||||
SQInteger TopTarget();
|
||||
SQInteger GetUpTarget(SQInteger n);
|
||||
bool IsLocal(SQUnsignedInteger stkpos);
|
||||
SQObject CreateString(const SQChar *s,SQInteger len = -1);
|
||||
SQObject CreateTable();
|
||||
bool IsConstant(const SQObject &name,SQObject &e);
|
||||
SQInteger _returnexp;
|
||||
SQLocalVarInfoVec _vlocals;
|
||||
SQIntVec _targetstack;
|
||||
SQInteger _stacksize;
|
||||
bool _varparams;
|
||||
bool _bgenerator;
|
||||
SQIntVec _unresolvedbreaks;
|
||||
SQIntVec _unresolvedcontinues;
|
||||
SQObjectPtrVec _functions;
|
||||
SQObjectPtrVec _parameters;
|
||||
SQOuterVarVec _outervalues;
|
||||
SQInstructionVec _instructions;
|
||||
SQLocalVarInfoVec _localvarinfos;
|
||||
SQObjectPtr _literals;
|
||||
SQObjectPtr _strings;
|
||||
SQObjectPtr _name;
|
||||
SQObjectPtr _sourcename;
|
||||
SQInteger _nliterals;
|
||||
SQLineInfoVec _lineinfos;
|
||||
SQFuncState *_parent;
|
||||
SQIntVec _breaktargets;
|
||||
SQIntVec _continuetargets;
|
||||
SQIntVec _defaultparams;
|
||||
SQInteger _lastline;
|
||||
SQInteger _traps; //contains number of nested exception traps
|
||||
bool _optimization;
|
||||
SQSharedState *_sharedstate;
|
||||
sqvector<SQFuncState*> _childstates;
|
||||
SQInteger GetConstant(const SQObject &cons);
|
||||
private:
|
||||
CompilerErrorFunc _errfunc;
|
||||
void *_errtarget;
|
||||
};
|
||||
|
||||
|
||||
#endif //_SQFUNCSTATE_H_
|
||||
|
||||
@@ -0,0 +1,479 @@
|
||||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
#include "sqpcheader.h"
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include "sqtable.h"
|
||||
#include "sqstring.h"
|
||||
#include "sqcompiler.h"
|
||||
#include "sqlexer.h"
|
||||
#if defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST)
|
||||
#include "memdbgon.h"
|
||||
#endif
|
||||
|
||||
#define CUR_CHAR (_currdata)
|
||||
#define RETURN_TOKEN(t) { _prevtoken = _curtoken; _curtoken = t; return t;}
|
||||
#define IS_EOB() (CUR_CHAR <= SQUIRREL_EOB)
|
||||
#define NEXT() {Next();_currentcolumn++;}
|
||||
#define INIT_TEMP_STRING() { _longstr.resize(0);}
|
||||
#define APPEND_CHAR(c) { _longstr.push_back(c);}
|
||||
#define TERMINATE_BUFFER() {_longstr.push_back(_SC('\0'));}
|
||||
#define ADD_KEYWORD(key,id) _keywords->NewSlot( SQString::Create(ss, _SC(#key)) ,SQInteger(id))
|
||||
|
||||
SQLexer::SQLexer(){}
|
||||
SQLexer::~SQLexer()
|
||||
{
|
||||
_keywords->Release();
|
||||
}
|
||||
|
||||
void SQLexer::Init(SQSharedState *ss, SQLEXREADFUNC rg, SQUserPointer up,CompilerErrorFunc efunc,void *ed)
|
||||
{
|
||||
_errfunc = efunc;
|
||||
_errtarget = ed;
|
||||
_sharedstate = ss;
|
||||
_keywords = SQTable::Create(ss, 26);
|
||||
ADD_KEYWORD(while, TK_WHILE);
|
||||
ADD_KEYWORD(do, TK_DO);
|
||||
ADD_KEYWORD(if, TK_IF);
|
||||
ADD_KEYWORD(else, TK_ELSE);
|
||||
ADD_KEYWORD(break, TK_BREAK);
|
||||
ADD_KEYWORD(continue, TK_CONTINUE);
|
||||
ADD_KEYWORD(return, TK_RETURN);
|
||||
ADD_KEYWORD(null, TK_NULL);
|
||||
ADD_KEYWORD(function, TK_FUNCTION);
|
||||
ADD_KEYWORD(local, TK_LOCAL);
|
||||
ADD_KEYWORD(for, TK_FOR);
|
||||
ADD_KEYWORD(foreach, TK_FOREACH);
|
||||
ADD_KEYWORD(in, TK_IN);
|
||||
ADD_KEYWORD(typeof, TK_TYPEOF);
|
||||
ADD_KEYWORD(delegate, TK_DELEGATE);
|
||||
ADD_KEYWORD(delete, TK_DELETE);
|
||||
ADD_KEYWORD(try, TK_TRY);
|
||||
ADD_KEYWORD(catch, TK_CATCH);
|
||||
ADD_KEYWORD(throw, TK_THROW);
|
||||
ADD_KEYWORD(clone, TK_CLONE);
|
||||
ADD_KEYWORD(yield, TK_YIELD);
|
||||
ADD_KEYWORD(resume, TK_RESUME);
|
||||
ADD_KEYWORD(switch, TK_SWITCH);
|
||||
ADD_KEYWORD(case, TK_CASE);
|
||||
ADD_KEYWORD(default, TK_DEFAULT);
|
||||
ADD_KEYWORD(this, TK_THIS);
|
||||
ADD_KEYWORD(parent,TK_PARENT);
|
||||
ADD_KEYWORD(class,TK_CLASS);
|
||||
ADD_KEYWORD(extends,TK_EXTENDS);
|
||||
ADD_KEYWORD(constructor,TK_CONSTRUCTOR);
|
||||
ADD_KEYWORD(instanceof,TK_INSTANCEOF);
|
||||
ADD_KEYWORD(vargc,TK_VARGC);
|
||||
ADD_KEYWORD(vargv,TK_VARGV);
|
||||
ADD_KEYWORD(true,TK_TRUE);
|
||||
ADD_KEYWORD(false,TK_FALSE);
|
||||
ADD_KEYWORD(static,TK_STATIC);
|
||||
ADD_KEYWORD(enum,TK_ENUM);
|
||||
ADD_KEYWORD(const,TK_CONST);
|
||||
|
||||
_readf = rg;
|
||||
_up = up;
|
||||
_lasttokenline = _currentline = 1;
|
||||
_currentcolumn = 0;
|
||||
_prevtoken = -1;
|
||||
Next();
|
||||
}
|
||||
|
||||
void SQLexer::Error(const SQChar *err)
|
||||
{
|
||||
_errfunc(_errtarget,err);
|
||||
}
|
||||
|
||||
void SQLexer::Next()
|
||||
{
|
||||
SQInteger t = _readf(_up);
|
||||
if(t > MAX_CHAR) Error(_SC("Invalid character"));
|
||||
if(t != 0) {
|
||||
_currdata = (LexChar)t;
|
||||
return;
|
||||
}
|
||||
_currdata = SQUIRREL_EOB;
|
||||
}
|
||||
|
||||
const SQChar *SQLexer::Tok2Str(SQInteger tok)
|
||||
{
|
||||
SQObjectPtr itr, key, val;
|
||||
SQInteger nitr;
|
||||
while((nitr = _keywords->Next(false,itr, key, val)) != -1) {
|
||||
itr = (SQInteger)nitr;
|
||||
if(((SQInteger)_integer(val)) == tok)
|
||||
return _stringval(key);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void SQLexer::LexBlockComment()
|
||||
{
|
||||
bool done = false;
|
||||
while(!done) {
|
||||
switch(CUR_CHAR) {
|
||||
case _SC('*'): { NEXT(); if(CUR_CHAR == _SC('/')) { done = true; NEXT(); }}; continue;
|
||||
case _SC('\n'): _currentline++; NEXT(); continue;
|
||||
case SQUIRREL_EOB: Error(_SC("missing \"*/\" in comment"));
|
||||
default: NEXT();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SQInteger SQLexer::Lex()
|
||||
{
|
||||
_lasttokenline = _currentline;
|
||||
while(CUR_CHAR != SQUIRREL_EOB) {
|
||||
switch(CUR_CHAR){
|
||||
case _SC('\t'): case _SC('\r'): case _SC(' '): NEXT(); continue;
|
||||
case _SC('\n'):
|
||||
_currentline++;
|
||||
_prevtoken=_curtoken;
|
||||
_curtoken=_SC('\n');
|
||||
NEXT();
|
||||
_currentcolumn=1;
|
||||
continue;
|
||||
case _SC('/'):
|
||||
NEXT();
|
||||
switch(CUR_CHAR){
|
||||
case _SC('*'):
|
||||
NEXT();
|
||||
LexBlockComment();
|
||||
continue;
|
||||
case _SC('/'):
|
||||
do { NEXT(); } while (CUR_CHAR != _SC('\n') && (!IS_EOB()));
|
||||
continue;
|
||||
case _SC('='):
|
||||
NEXT();
|
||||
RETURN_TOKEN(TK_DIVEQ);
|
||||
continue;
|
||||
case _SC('>'):
|
||||
NEXT();
|
||||
RETURN_TOKEN(TK_ATTR_CLOSE);
|
||||
continue;
|
||||
default:
|
||||
RETURN_TOKEN('/');
|
||||
}
|
||||
case _SC('='):
|
||||
NEXT();
|
||||
if (CUR_CHAR != _SC('=')){ RETURN_TOKEN('=') }
|
||||
else { NEXT(); RETURN_TOKEN(TK_EQ); }
|
||||
case _SC('<'):
|
||||
NEXT();
|
||||
if ( CUR_CHAR == _SC('=') ) { NEXT(); RETURN_TOKEN(TK_LE) }
|
||||
else if ( CUR_CHAR == _SC('-') ) { NEXT(); RETURN_TOKEN(TK_NEWSLOT); }
|
||||
else if ( CUR_CHAR == _SC('<') ) { NEXT(); RETURN_TOKEN(TK_SHIFTL); }
|
||||
else if ( CUR_CHAR == _SC('/') ) { NEXT(); RETURN_TOKEN(TK_ATTR_OPEN); }
|
||||
//else if ( CUR_CHAR == _SC('[') ) { NEXT(); ReadMultilineString(); RETURN_TOKEN(TK_STRING_LITERAL); }
|
||||
else { RETURN_TOKEN('<') }
|
||||
case _SC('>'):
|
||||
NEXT();
|
||||
if (CUR_CHAR == _SC('=')){ NEXT(); RETURN_TOKEN(TK_GE);}
|
||||
else if(CUR_CHAR == _SC('>')){
|
||||
NEXT();
|
||||
if(CUR_CHAR == _SC('>')){
|
||||
NEXT();
|
||||
RETURN_TOKEN(TK_USHIFTR);
|
||||
}
|
||||
RETURN_TOKEN(TK_SHIFTR);
|
||||
}
|
||||
else { RETURN_TOKEN('>') }
|
||||
case _SC('!'):
|
||||
NEXT();
|
||||
if (CUR_CHAR != _SC('=')){ RETURN_TOKEN('!')}
|
||||
else { NEXT(); RETURN_TOKEN(TK_NE); }
|
||||
case _SC('@'): {
|
||||
SQInteger stype;
|
||||
NEXT();
|
||||
if(CUR_CHAR != _SC('"'))
|
||||
Error(_SC("string expected"));
|
||||
if((stype=ReadString('"',true))!=-1) {
|
||||
RETURN_TOKEN(stype);
|
||||
}
|
||||
Error(_SC("error parsing the string"));
|
||||
}
|
||||
case _SC('"'):
|
||||
case _SC('\''): {
|
||||
SQInteger stype;
|
||||
if((stype=ReadString(CUR_CHAR,false))!=-1){
|
||||
RETURN_TOKEN(stype);
|
||||
}
|
||||
Error(_SC("error parsing the string"));
|
||||
}
|
||||
case _SC('{'): case _SC('}'): case _SC('('): case _SC(')'): case _SC('['): case _SC(']'):
|
||||
case _SC(';'): case _SC(','): case _SC('?'): case _SC('^'): case _SC('~'):
|
||||
{SQInteger ret = CUR_CHAR;
|
||||
NEXT(); RETURN_TOKEN(ret); }
|
||||
case _SC('.'):
|
||||
NEXT();
|
||||
if (CUR_CHAR != _SC('.')){ RETURN_TOKEN('.') }
|
||||
NEXT();
|
||||
if (CUR_CHAR != _SC('.')){ Error(_SC("invalid token '..'")); }
|
||||
NEXT();
|
||||
RETURN_TOKEN(TK_VARPARAMS);
|
||||
case _SC('&'):
|
||||
NEXT();
|
||||
if (CUR_CHAR != _SC('&')){ RETURN_TOKEN('&') }
|
||||
else { NEXT(); RETURN_TOKEN(TK_AND); }
|
||||
case _SC('|'):
|
||||
NEXT();
|
||||
if (CUR_CHAR != _SC('|')){ RETURN_TOKEN('|') }
|
||||
else { NEXT(); RETURN_TOKEN(TK_OR); }
|
||||
case _SC(':'):
|
||||
NEXT();
|
||||
if (CUR_CHAR != _SC(':')){ RETURN_TOKEN(':') }
|
||||
else { NEXT(); RETURN_TOKEN(TK_DOUBLE_COLON); }
|
||||
case _SC('*'):
|
||||
NEXT();
|
||||
if (CUR_CHAR == _SC('=')){ NEXT(); RETURN_TOKEN(TK_MULEQ);}
|
||||
else RETURN_TOKEN('*');
|
||||
case _SC('%'):
|
||||
NEXT();
|
||||
if (CUR_CHAR == _SC('=')){ NEXT(); RETURN_TOKEN(TK_MODEQ);}
|
||||
else RETURN_TOKEN('%');
|
||||
case _SC('-'):
|
||||
NEXT();
|
||||
if (CUR_CHAR == _SC('=')){ NEXT(); RETURN_TOKEN(TK_MINUSEQ);}
|
||||
else if (CUR_CHAR == _SC('-')){ NEXT(); RETURN_TOKEN(TK_MINUSMINUS);}
|
||||
else RETURN_TOKEN('-');
|
||||
case _SC('+'):
|
||||
NEXT();
|
||||
if (CUR_CHAR == _SC('=')){ NEXT(); RETURN_TOKEN(TK_PLUSEQ);}
|
||||
else if (CUR_CHAR == _SC('+')){ NEXT(); RETURN_TOKEN(TK_PLUSPLUS);}
|
||||
else RETURN_TOKEN('+');
|
||||
case SQUIRREL_EOB:
|
||||
return 0;
|
||||
default:{
|
||||
if (scisdigit(CUR_CHAR)) {
|
||||
SQInteger ret = ReadNumber();
|
||||
RETURN_TOKEN(ret);
|
||||
}
|
||||
else if (scisalpha(CUR_CHAR) || CUR_CHAR == _SC('_')) {
|
||||
SQInteger t = ReadID();
|
||||
RETURN_TOKEN(t);
|
||||
}
|
||||
else {
|
||||
SQInteger c = CUR_CHAR;
|
||||
if (sciscntrl((int)c)) Error(_SC("unexpected character(control)"));
|
||||
NEXT();
|
||||
RETURN_TOKEN(c);
|
||||
}
|
||||
RETURN_TOKEN(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
SQInteger SQLexer::GetIDType(SQChar *s)
|
||||
{
|
||||
SQObjectPtr t;
|
||||
if(_keywords->Get(SQString::Create(_sharedstate, s), t)) {
|
||||
return SQInteger(_integer(t));
|
||||
}
|
||||
return TK_IDENTIFIER;
|
||||
}
|
||||
|
||||
|
||||
SQInteger SQLexer::ReadString(SQInteger ndelim,bool verbatim)
|
||||
{
|
||||
INIT_TEMP_STRING();
|
||||
NEXT();
|
||||
if(IS_EOB()) return -1;
|
||||
for(;;) {
|
||||
while(CUR_CHAR != ndelim) {
|
||||
switch(CUR_CHAR) {
|
||||
case SQUIRREL_EOB:
|
||||
Error(_SC("unfinished string"));
|
||||
return -1;
|
||||
case _SC('\n'):
|
||||
if(!verbatim) Error(_SC("newline in a constant"));
|
||||
APPEND_CHAR(CUR_CHAR); NEXT();
|
||||
_currentline++;
|
||||
break;
|
||||
case _SC('\\'):
|
||||
if(verbatim) {
|
||||
APPEND_CHAR('\\'); NEXT();
|
||||
}
|
||||
else {
|
||||
NEXT();
|
||||
switch(CUR_CHAR) {
|
||||
case _SC('x'): NEXT(); {
|
||||
if(!isxdigit(CUR_CHAR)) Error(_SC("hexadecimal number expected"));
|
||||
const SQInteger maxdigits = 4;
|
||||
SQChar temp[maxdigits+1];
|
||||
SQInteger n = 0;
|
||||
while(isxdigit(CUR_CHAR) && n < maxdigits) {
|
||||
temp[n] = CUR_CHAR;
|
||||
n++;
|
||||
NEXT();
|
||||
}
|
||||
temp[n] = 0;
|
||||
SQChar *sTemp;
|
||||
APPEND_CHAR((SQChar)scstrtoul(temp,&sTemp,16));
|
||||
}
|
||||
break;
|
||||
case _SC('t'): APPEND_CHAR(_SC('\t')); NEXT(); break;
|
||||
case _SC('a'): APPEND_CHAR(_SC('\a')); NEXT(); break;
|
||||
case _SC('b'): APPEND_CHAR(_SC('\b')); NEXT(); break;
|
||||
case _SC('n'): APPEND_CHAR(_SC('\n')); NEXT(); break;
|
||||
case _SC('r'): APPEND_CHAR(_SC('\r')); NEXT(); break;
|
||||
case _SC('v'): APPEND_CHAR(_SC('\v')); NEXT(); break;
|
||||
case _SC('f'): APPEND_CHAR(_SC('\f')); NEXT(); break;
|
||||
case _SC('0'): APPEND_CHAR(_SC('\0')); NEXT(); break;
|
||||
case _SC('\\'): APPEND_CHAR(_SC('\\')); NEXT(); break;
|
||||
case _SC('"'): APPEND_CHAR(_SC('"')); NEXT(); break;
|
||||
case _SC('\''): APPEND_CHAR(_SC('\'')); NEXT(); break;
|
||||
default:
|
||||
Error(_SC("unrecognised escaper char"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
APPEND_CHAR(CUR_CHAR);
|
||||
NEXT();
|
||||
}
|
||||
}
|
||||
NEXT();
|
||||
if(verbatim && CUR_CHAR == '"') { //double quotation
|
||||
APPEND_CHAR(CUR_CHAR);
|
||||
NEXT();
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
TERMINATE_BUFFER();
|
||||
SQInteger len = _longstr.size()-1;
|
||||
if(ndelim == _SC('\'')) {
|
||||
if(len == 0) Error(_SC("empty constant"));
|
||||
if(len > 1) Error(_SC("constant too long"));
|
||||
_nvalue = _longstr[0];
|
||||
return TK_INTEGER;
|
||||
}
|
||||
_svalue = &_longstr[0];
|
||||
return TK_STRING_LITERAL;
|
||||
}
|
||||
|
||||
void LexHexadecimal(const SQChar *s,SQUnsignedInteger *res)
|
||||
{
|
||||
*res = 0;
|
||||
while(*s != 0)
|
||||
{
|
||||
if(scisdigit(*s)) *res = (*res)*16+((*s++)-'0');
|
||||
else if(scisxdigit(*s)) *res = (*res)*16+(toupper(*s++)-'A'+10);
|
||||
else { Assert(0); }
|
||||
}
|
||||
}
|
||||
|
||||
void LexInteger(const SQChar *s,SQUnsignedInteger *res)
|
||||
{
|
||||
*res = 0;
|
||||
while(*s != 0)
|
||||
{
|
||||
*res = (*res)*10+((*s++)-'0');
|
||||
}
|
||||
}
|
||||
|
||||
SQInteger scisodigit(SQInteger c) { return c >= _SC('0') && c <= _SC('7'); }
|
||||
|
||||
void LexOctal(const SQChar *s,SQUnsignedInteger *res)
|
||||
{
|
||||
*res = 0;
|
||||
while(*s != 0)
|
||||
{
|
||||
if(scisodigit(*s)) *res = (*res)*8+((*s++)-'0');
|
||||
else { assert(0); }
|
||||
}
|
||||
}
|
||||
|
||||
SQInteger isexponent(SQInteger c) { return c == 'e' || c=='E'; }
|
||||
|
||||
|
||||
#define MAX_HEX_DIGITS (sizeof(SQInteger)*2)
|
||||
SQInteger SQLexer::ReadNumber()
|
||||
{
|
||||
#define TINT 1
|
||||
#define TFLOAT 2
|
||||
#define THEX 3
|
||||
#define TSCIENTIFIC 4
|
||||
#define TOCTAL 5
|
||||
SQInteger type = TINT, firstchar = CUR_CHAR;
|
||||
SQChar *sTemp;
|
||||
INIT_TEMP_STRING();
|
||||
NEXT();
|
||||
if(firstchar == _SC('0') && (toupper(CUR_CHAR) == _SC('X') || scisodigit(CUR_CHAR)) ) {
|
||||
if(scisodigit(CUR_CHAR)) {
|
||||
type = TOCTAL;
|
||||
while(scisodigit(CUR_CHAR)) {
|
||||
APPEND_CHAR(CUR_CHAR);
|
||||
NEXT();
|
||||
}
|
||||
if(scisdigit(CUR_CHAR)) Error(_SC("invalid octal number"));
|
||||
}
|
||||
else {
|
||||
NEXT();
|
||||
type = THEX;
|
||||
while(isxdigit(CUR_CHAR)) {
|
||||
APPEND_CHAR(CUR_CHAR);
|
||||
NEXT();
|
||||
}
|
||||
if(_longstr.size() > MAX_HEX_DIGITS) Error(_SC("too many digits for an Hex number"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
APPEND_CHAR((int)firstchar);
|
||||
while (CUR_CHAR == _SC('.') || scisdigit(CUR_CHAR) || isexponent(CUR_CHAR)) {
|
||||
if(CUR_CHAR == _SC('.')) type = TFLOAT;
|
||||
if(isexponent(CUR_CHAR)) {
|
||||
if(type != TFLOAT) Error(_SC("invalid numeric format"));
|
||||
type = TSCIENTIFIC;
|
||||
APPEND_CHAR(CUR_CHAR);
|
||||
NEXT();
|
||||
if(CUR_CHAR == '+' || CUR_CHAR == '-'){
|
||||
APPEND_CHAR(CUR_CHAR);
|
||||
NEXT();
|
||||
}
|
||||
if(!scisdigit(CUR_CHAR)) Error(_SC("exponent expected"));
|
||||
}
|
||||
|
||||
APPEND_CHAR(CUR_CHAR);
|
||||
NEXT();
|
||||
}
|
||||
}
|
||||
TERMINATE_BUFFER();
|
||||
switch(type) {
|
||||
case TSCIENTIFIC:
|
||||
case TFLOAT:
|
||||
_fvalue = (SQFloat)scstrtod(&_longstr[0],&sTemp);
|
||||
return TK_FLOAT;
|
||||
case TINT:
|
||||
LexInteger(&_longstr[0],(SQUnsignedInteger *)&_nvalue);
|
||||
return TK_INTEGER;
|
||||
case THEX:
|
||||
LexHexadecimal(&_longstr[0],(SQUnsignedInteger *)&_nvalue);
|
||||
return TK_INTEGER;
|
||||
case TOCTAL:
|
||||
LexOctal(&_longstr[0],(SQUnsignedInteger *)&_nvalue);
|
||||
return TK_INTEGER;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
SQInteger SQLexer::ReadID()
|
||||
{
|
||||
SQInteger res;
|
||||
INIT_TEMP_STRING();
|
||||
do {
|
||||
APPEND_CHAR(CUR_CHAR);
|
||||
NEXT();
|
||||
} while(scisalnum(CUR_CHAR) || CUR_CHAR == _SC('_'));
|
||||
TERMINATE_BUFFER();
|
||||
res = GetIDType(&_longstr[0]);
|
||||
if(res == TK_IDENTIFIER || res == TK_CONSTRUCTOR) {
|
||||
_svalue = &_longstr[0];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#ifndef _SQLEXER_H_
|
||||
#define _SQLEXER_H_
|
||||
|
||||
#ifdef SQUNICODE
|
||||
typedef SQChar LexChar;
|
||||
#else
|
||||
typedef unsigned char LexChar;
|
||||
#endif
|
||||
|
||||
struct SQLexer
|
||||
{
|
||||
SQLexer();
|
||||
~SQLexer();
|
||||
void Init(SQSharedState *ss,SQLEXREADFUNC rg,SQUserPointer up,CompilerErrorFunc efunc,void *ed);
|
||||
void Error(const SQChar *err);
|
||||
SQInteger Lex();
|
||||
const SQChar *Tok2Str(SQInteger tok);
|
||||
private:
|
||||
SQInteger GetIDType(SQChar *s);
|
||||
SQInteger ReadString(SQInteger ndelim,bool verbatim);
|
||||
SQInteger ReadNumber();
|
||||
void LexBlockComment();
|
||||
SQInteger ReadID();
|
||||
void Next();
|
||||
SQInteger _curtoken;
|
||||
SQTable *_keywords;
|
||||
public:
|
||||
SQInteger _prevtoken;
|
||||
SQInteger _currentline;
|
||||
SQInteger _lasttokenline;
|
||||
SQInteger _currentcolumn;
|
||||
const SQChar *_svalue;
|
||||
SQInteger _nvalue;
|
||||
SQFloat _fvalue;
|
||||
SQLEXREADFUNC _readf;
|
||||
SQUserPointer _up;
|
||||
LexChar _currdata;
|
||||
SQSharedState *_sharedstate;
|
||||
sqvector<SQChar> _longstr;
|
||||
CompilerErrorFunc _errfunc;
|
||||
void *_errtarget;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
#include "sqpcheader.h"
|
||||
#if !(defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST))
|
||||
void *sq_vm_malloc(SQUnsignedInteger size){ return malloc(size); }
|
||||
|
||||
void *sq_vm_realloc(void *p, SQUnsignedInteger oldsize, SQUnsignedInteger size){ return realloc(p, size); }
|
||||
|
||||
void sq_vm_free(void *p, SQUnsignedInteger size){ free(p); }
|
||||
#endif
|
||||
@@ -0,0 +1,712 @@
|
||||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
#include "sqpcheader.h"
|
||||
#include "sqvm.h"
|
||||
#include "sqstring.h"
|
||||
#include "sqarray.h"
|
||||
#include "sqtable.h"
|
||||
#include "squserdata.h"
|
||||
#include "sqfuncproto.h"
|
||||
#include "sqclass.h"
|
||||
#include "sqclosure.h"
|
||||
#if defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST)
|
||||
#include "memdbgon.h"
|
||||
#undef new // allow placement new
|
||||
#endif
|
||||
|
||||
|
||||
const SQChar *IdType2Name(SQObjectType type)
|
||||
{
|
||||
switch(_RAW_TYPE(type))
|
||||
{
|
||||
case _RT_NULL:return _SC("null");
|
||||
case _RT_INTEGER:return _SC("integer");
|
||||
case _RT_FLOAT:return _SC("float");
|
||||
case _RT_BOOL:return _SC("bool");
|
||||
case _RT_STRING:return _SC("string");
|
||||
case _RT_TABLE:return _SC("table");
|
||||
case _RT_ARRAY:return _SC("array");
|
||||
case _RT_GENERATOR:return _SC("generator");
|
||||
case _RT_CLOSURE:
|
||||
return _SC("function");
|
||||
case _RT_NATIVECLOSURE:
|
||||
return _SC("native function");
|
||||
case _RT_USERDATA:
|
||||
case _RT_USERPOINTER:
|
||||
return _SC("userdata");
|
||||
case _RT_THREAD: return _SC("thread");
|
||||
case _RT_FUNCPROTO: return _SC("function");
|
||||
case _RT_CLASS: return _SC("class");
|
||||
case _RT_INSTANCE: return _SC("instance");
|
||||
case _RT_WEAKREF: return _SC("weakref");
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
const SQChar *GetTypeName(const SQObjectPtr &obj1)
|
||||
{
|
||||
return IdType2Name(type(obj1));
|
||||
}
|
||||
|
||||
SQString *SQString::Create(SQSharedState *ss,const SQChar *s,SQInteger len)
|
||||
{
|
||||
SQString *str=ADD_STRING(ss,s,len);
|
||||
str->_sharedstate=ss;
|
||||
return str;
|
||||
}
|
||||
|
||||
void SQString::Release()
|
||||
{
|
||||
REMOVE_STRING(_sharedstate,this);
|
||||
}
|
||||
|
||||
SQInteger SQString::Next(const SQObjectPtr &refpos, SQObjectPtr &outkey, SQObjectPtr &outval)
|
||||
{
|
||||
SQInteger idx = (SQInteger)TranslateIndex(refpos);
|
||||
while(idx < _len){
|
||||
outkey = (SQInteger)idx;
|
||||
outval = SQInteger(_val[idx]);
|
||||
//return idx for the next iteration
|
||||
return ++idx;
|
||||
}
|
||||
//nothing to iterate anymore
|
||||
return -1;
|
||||
}
|
||||
|
||||
SQUnsignedInteger TranslateIndex(const SQObjectPtr &idx)
|
||||
{
|
||||
switch(type(idx)){
|
||||
case OT_NULL:
|
||||
return 0;
|
||||
case OT_INTEGER:
|
||||
return (SQUnsignedInteger)_integer(idx);
|
||||
default: Assert(0); break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
SQWeakRef *SQRefCounted::GetWeakRef(SQObjectType type)
|
||||
{
|
||||
if(!_weakref) {
|
||||
sq_new(_weakref,SQWeakRef);
|
||||
_weakref->_obj._type = type;
|
||||
_weakref->_obj._unVal.pRefCounted = this;
|
||||
}
|
||||
return _weakref;
|
||||
}
|
||||
|
||||
SQRefCounted::~SQRefCounted()
|
||||
{
|
||||
if(_weakref) {
|
||||
_weakref->_obj._type = OT_NULL;
|
||||
_weakref->_obj._unVal.pRefCounted = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void SQWeakRef::Release() {
|
||||
if(ISREFCOUNTED(_obj._type)) {
|
||||
_obj._unVal.pRefCounted->_weakref = NULL;
|
||||
}
|
||||
sq_delete(this,SQWeakRef);
|
||||
}
|
||||
|
||||
bool SQDelegable::GetMetaMethod(SQVM *v,SQMetaMethod mm,SQObjectPtr &res) {
|
||||
if(_delegate) {
|
||||
return _delegate->Get((*_ss(v)->_metamethods)[mm],res);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SQDelegable::SetDelegate(SQTable *mt)
|
||||
{
|
||||
SQTable *temp = mt;
|
||||
if(temp == this) return false;
|
||||
while (temp) {
|
||||
if (temp->_delegate == this) return false; //cycle detected
|
||||
temp = temp->_delegate;
|
||||
}
|
||||
if (mt) __ObjAddRef(mt);
|
||||
__ObjRelease(_delegate);
|
||||
_delegate = mt;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SQGenerator::Yield(SQVM *v)
|
||||
{
|
||||
if(_state==eSuspended) { v->Raise_Error(_SC("internal vm error, yielding dead generator")); return false;}
|
||||
if(_state==eDead) { v->Raise_Error(_SC("internal vm error, yielding a dead generator")); return false; }
|
||||
SQInteger size = v->_top-v->_stackbase;
|
||||
_ci=*v->ci;
|
||||
_stack.resize(size);
|
||||
for(SQInteger n =0; n<size; n++) {
|
||||
_stack._vals[n] = v->_stack[v->_stackbase+n];
|
||||
v->_stack[v->_stackbase+n] = _null_;
|
||||
}
|
||||
SQInteger nvargs = v->ci->_vargs.size;
|
||||
SQInteger vargsbase = v->ci->_vargs.base;
|
||||
for(SQInteger j = nvargs - 1; j >= 0; j--) {
|
||||
_vargsstack.push_back(v->_vargsstack[vargsbase+j]);
|
||||
}
|
||||
_ci._generator=NULL;
|
||||
for(SQInteger i=0;i<_ci._etraps;i++) {
|
||||
_etraps.push_back(v->_etraps.top());
|
||||
v->_etraps.pop_back();
|
||||
}
|
||||
_state=eSuspended;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SQGenerator::Resume(SQVM *v,SQInteger target)
|
||||
{
|
||||
SQInteger size=_stack.size();
|
||||
if(_state==eDead){ v->Raise_Error(_SC("resuming dead generator")); return false; }
|
||||
if(_state==eRunning){ v->Raise_Error(_SC("resuming active generator")); return false; }
|
||||
SQInteger prevtop=v->_top-v->_stackbase;
|
||||
PUSH_CALLINFO(v,_ci);
|
||||
SQInteger oldstackbase=v->_stackbase;
|
||||
v->_stackbase = v->_top;
|
||||
v->ci->_target = (SQInt32)target;
|
||||
v->ci->_generator = this;
|
||||
v->ci->_vargs.size = (unsigned short)_vargsstack.size();
|
||||
|
||||
for(SQInteger i=0;i<_ci._etraps;i++) {
|
||||
v->_etraps.push_back(_etraps.top());
|
||||
_etraps.pop_back();
|
||||
}
|
||||
for(SQInteger n =0; n<size; n++) {
|
||||
v->_stack[v->_stackbase+n] = _stack._vals[n];
|
||||
_stack._vals[0] = _null_;
|
||||
}
|
||||
while(_vargsstack.size()) {
|
||||
v->_vargsstack.push_back(_vargsstack.back());
|
||||
_vargsstack.pop_back();
|
||||
}
|
||||
v->ci->_vargs.base = (unsigned short)(v->_vargsstack.size() - v->ci->_vargs.size);
|
||||
v->_top=v->_stackbase+size;
|
||||
v->ci->_prevtop = (SQInt32)prevtop;
|
||||
v->ci->_prevstkbase = (SQInt32)(v->_stackbase - oldstackbase);
|
||||
_state=eRunning;
|
||||
if (type(v->_debughook) != OT_NULL && _rawval(v->_debughook) != _rawval(v->ci->_closure))
|
||||
v->CallDebugHook(_SC('c'));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SQArray::Extend(const SQArray *a){
|
||||
SQInteger xlen;
|
||||
if((xlen=a->Size()))
|
||||
for(SQInteger i=0;i<xlen;i++)
|
||||
Append(a->_values[i]);
|
||||
}
|
||||
|
||||
const SQChar* SQFunctionProto::GetLocal(SQVM *vm,SQUnsignedInteger stackbase,SQUnsignedInteger nseq,SQUnsignedInteger nop)
|
||||
{
|
||||
SQUnsignedInteger nvars=_nlocalvarinfos;
|
||||
const SQChar *res=NULL;
|
||||
if(nvars>=nseq){
|
||||
for(SQUnsignedInteger i=0;i<nvars;i++){
|
||||
if(_localvarinfos[i]._start_op<=nop && _localvarinfos[i]._end_op>=nop)
|
||||
{
|
||||
if(nseq==0){
|
||||
vm->Push(vm->_stack[stackbase+_localvarinfos[i]._pos]);
|
||||
res=_stringval(_localvarinfos[i]._name);
|
||||
break;
|
||||
}
|
||||
nseq--;
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
SQInteger SQFunctionProto::GetLine(SQInstruction *curr)
|
||||
{
|
||||
SQInteger op = (SQInteger)(curr-_instructions);
|
||||
SQInteger line=_lineinfos[0]._line;
|
||||
for(SQInteger i=1;i<_nlineinfos;i++){
|
||||
if(_lineinfos[i]._op>=op)
|
||||
return line;
|
||||
line=_lineinfos[i]._line;
|
||||
}
|
||||
return line;
|
||||
}
|
||||
|
||||
#define _CHECK_IO(exp) { if(!exp)return false; }
|
||||
bool SafeWrite(HSQUIRRELVM v,SQWRITEFUNC write,SQUserPointer up,SQUserPointer dest,SQInteger size)
|
||||
{
|
||||
if(write(up,dest,size) != size) {
|
||||
v->Raise_Error(_SC("io error (write function failure)"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SafeRead(HSQUIRRELVM v,SQWRITEFUNC read,SQUserPointer up,SQUserPointer dest,SQInteger size)
|
||||
{
|
||||
if(size && read(up,dest,size) != size) {
|
||||
v->Raise_Error(_SC("io error, read function failure, the origin stream could be corrupted/trucated"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WriteTag(HSQUIRRELVM v,SQWRITEFUNC write,SQUserPointer up,SQInteger tag)
|
||||
{
|
||||
return SafeWrite(v,write,up,&tag,sizeof(tag));
|
||||
}
|
||||
|
||||
bool CheckTag(HSQUIRRELVM v,SQWRITEFUNC read,SQUserPointer up,SQInteger tag)
|
||||
{
|
||||
SQInteger t;
|
||||
_CHECK_IO(SafeRead(v,read,up,&t,sizeof(t)));
|
||||
if(t != tag){
|
||||
v->Raise_Error(_SC("invalid or corrupted closure stream"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WriteObject(HSQUIRRELVM v,SQUserPointer up,SQWRITEFUNC write,SQObjectPtr &o)
|
||||
{
|
||||
_CHECK_IO(SafeWrite(v,write,up,&type(o),sizeof(SQObjectType)));
|
||||
switch(type(o)){
|
||||
case OT_STRING:
|
||||
_CHECK_IO(SafeWrite(v,write,up,&_string(o)->_len,sizeof(SQInteger)));
|
||||
_CHECK_IO(SafeWrite(v,write,up,_stringval(o),rsl(_string(o)->_len)));
|
||||
break;
|
||||
case OT_INTEGER:
|
||||
_CHECK_IO(SafeWrite(v,write,up,&_integer(o),sizeof(SQInteger)));break;
|
||||
case OT_FLOAT:
|
||||
_CHECK_IO(SafeWrite(v,write,up,&_float(o),sizeof(SQFloat)));break;
|
||||
case OT_NULL:
|
||||
break;
|
||||
default:
|
||||
v->Raise_Error(_SC("cannot serialize a %s"),GetTypeName(o));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ReadObject(HSQUIRRELVM v,SQUserPointer up,SQREADFUNC read,SQObjectPtr &o)
|
||||
{
|
||||
SQObjectType t;
|
||||
_CHECK_IO(SafeRead(v,read,up,&t,sizeof(SQObjectType)));
|
||||
switch(t){
|
||||
case OT_STRING:{
|
||||
SQInteger len;
|
||||
_CHECK_IO(SafeRead(v,read,up,&len,sizeof(SQInteger)));
|
||||
_CHECK_IO(SafeRead(v,read,up,_ss(v)->GetScratchPad(rsl(len)),rsl(len)));
|
||||
o=SQString::Create(_ss(v),_ss(v)->GetScratchPad(-1),len);
|
||||
}
|
||||
break;
|
||||
case OT_INTEGER:{
|
||||
SQInteger i;
|
||||
_CHECK_IO(SafeRead(v,read,up,&i,sizeof(SQInteger))); o = i; break;
|
||||
}
|
||||
case OT_FLOAT:{
|
||||
SQFloat f;
|
||||
_CHECK_IO(SafeRead(v,read,up,&f,sizeof(SQFloat))); o = f; break;
|
||||
}
|
||||
case OT_NULL:
|
||||
o=_null_;
|
||||
break;
|
||||
default:
|
||||
v->Raise_Error(_SC("cannot serialize a %s"),IdType2Name(t));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SQClosure::Save(SQVM *v,SQUserPointer up,SQWRITEFUNC write)
|
||||
{
|
||||
_CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_HEAD));
|
||||
_CHECK_IO(WriteTag(v,write,up,sizeof(SQChar)));
|
||||
_CHECK_IO(_funcproto(_function)->Save(v,up,write));
|
||||
_CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_TAIL));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SQClosure::Load(SQVM *v,SQUserPointer up,SQREADFUNC read,SQObjectPtr &ret)
|
||||
{
|
||||
_CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_HEAD));
|
||||
_CHECK_IO(CheckTag(v,read,up,sizeof(SQChar)));
|
||||
SQObjectPtr func;
|
||||
_CHECK_IO(SQFunctionProto::Load(v,up,read,func));
|
||||
_CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_TAIL));
|
||||
ret = SQClosure::Create(_ss(v),_funcproto(func));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SQFunctionProto::Save(SQVM *v,SQUserPointer up,SQWRITEFUNC write)
|
||||
{
|
||||
SQInteger i,nliterals = _nliterals,nparameters = _nparameters;
|
||||
SQInteger noutervalues = _noutervalues,nlocalvarinfos = _nlocalvarinfos;
|
||||
SQInteger nlineinfos=_nlineinfos,ninstructions = _ninstructions,nfunctions=_nfunctions;
|
||||
SQInteger 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(SQUnsignedInteger)));
|
||||
_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++){
|
||||
SQLocalVarInfo &lvi=_localvarinfos[i];
|
||||
_CHECK_IO(WriteObject(v,up,write,lvi._name));
|
||||
_CHECK_IO(SafeWrite(v,write,up,&lvi._pos,sizeof(SQUnsignedInteger)));
|
||||
_CHECK_IO(SafeWrite(v,write,up,&lvi._start_op,sizeof(SQUnsignedInteger)));
|
||||
_CHECK_IO(SafeWrite(v,write,up,&lvi._end_op,sizeof(SQUnsignedInteger)));
|
||||
}
|
||||
|
||||
_CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_PART));
|
||||
_CHECK_IO(SafeWrite(v,write,up,_lineinfos,sizeof(SQLineInfo)*nlineinfos));
|
||||
|
||||
_CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_PART));
|
||||
_CHECK_IO(SafeWrite(v,write,up,_defaultparams,sizeof(SQInteger)*ndefaultparams));
|
||||
|
||||
_CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_PART));
|
||||
_CHECK_IO(SafeWrite(v,write,up,_instructions,sizeof(SQInstruction)*ninstructions));
|
||||
|
||||
_CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_PART));
|
||||
for(i=0;i<nfunctions;i++){
|
||||
_CHECK_IO(_funcproto(_functions[i])->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 SQFunctionProto::Load(SQVM *v,SQUserPointer up,SQREADFUNC read,SQObjectPtr &ret)
|
||||
{
|
||||
SQInteger i, nliterals,nparameters;
|
||||
SQInteger noutervalues ,nlocalvarinfos ;
|
||||
SQInteger nlineinfos,ninstructions ,nfunctions,ndefaultparams ;
|
||||
SQObjectPtr sourcename, name;
|
||||
SQObjectPtr 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)));
|
||||
|
||||
|
||||
SQFunctionProto *f = SQFunctionProto::Create(ninstructions,nliterals,nparameters,
|
||||
nfunctions,noutervalues,nlineinfos,nlocalvarinfos,ndefaultparams);
|
||||
SQObjectPtr 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++){
|
||||
SQUnsignedInteger type;
|
||||
SQObjectPtr name;
|
||||
_CHECK_IO(SafeRead(v,read,up, &type, sizeof(SQUnsignedInteger)));
|
||||
_CHECK_IO(ReadObject(v, up, read, o));
|
||||
_CHECK_IO(ReadObject(v, up, read, name));
|
||||
f->_outervalues[i] = SQOuterVar(name,o, (SQOuterType)type);
|
||||
}
|
||||
_CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
|
||||
|
||||
for(i = 0; i < nlocalvarinfos; i++){
|
||||
SQLocalVarInfo lvi;
|
||||
_CHECK_IO(ReadObject(v, up, read, lvi._name));
|
||||
_CHECK_IO(SafeRead(v,read,up, &lvi._pos, sizeof(SQUnsignedInteger)));
|
||||
_CHECK_IO(SafeRead(v,read,up, &lvi._start_op, sizeof(SQUnsignedInteger)));
|
||||
_CHECK_IO(SafeRead(v,read,up, &lvi._end_op, sizeof(SQUnsignedInteger)));
|
||||
f->_localvarinfos[i] = lvi;
|
||||
}
|
||||
_CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
|
||||
_CHECK_IO(SafeRead(v,read,up, f->_lineinfos, sizeof(SQLineInfo)*nlineinfos));
|
||||
|
||||
_CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
|
||||
_CHECK_IO(SafeRead(v,read,up, f->_defaultparams, sizeof(SQInteger)*ndefaultparams));
|
||||
|
||||
_CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
|
||||
_CHECK_IO(SafeRead(v,read,up, f->_instructions, sizeof(SQInstruction)*ninstructions));
|
||||
|
||||
_CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
|
||||
for(i = 0; i < nfunctions; i++){
|
||||
_CHECK_IO(_funcproto(o)->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;
|
||||
}
|
||||
|
||||
#ifndef NO_GARBAGE_COLLECTOR
|
||||
|
||||
#define START_MARK() if(!(_uiRef&MARK_FLAG)){ \
|
||||
_uiRef|=MARK_FLAG;
|
||||
|
||||
#define END_MARK() RemoveFromChain(&_sharedstate->_gc_chain, this); \
|
||||
AddToChain(chain, this); }
|
||||
|
||||
void SQVM::Mark(SQCollectable **chain)
|
||||
{
|
||||
START_MARK()
|
||||
SQSharedState::MarkObject(_lasterror,chain);
|
||||
SQSharedState::MarkObject(_errorhandler,chain);
|
||||
SQSharedState::MarkObject(_debughook,chain);
|
||||
SQSharedState::MarkObject(_roottable, chain);
|
||||
SQSharedState::MarkObject(temp_reg, chain);
|
||||
for(SQUnsignedInteger i = 0; i < _stack.size(); i++) SQSharedState::MarkObject(_stack[i], chain);
|
||||
for(SQUnsignedInteger j = 0; j < _vargsstack.size(); j++) SQSharedState::MarkObject(_vargsstack[j], chain);
|
||||
for(SQInteger k = 0; k < _callsstacksize; k++) SQSharedState::MarkObject(_callsstack[k]._closure, chain);
|
||||
END_MARK()
|
||||
}
|
||||
|
||||
void SQArray::Mark(SQCollectable **chain)
|
||||
{
|
||||
START_MARK()
|
||||
SQInteger len = _values.size();
|
||||
for(SQInteger i = 0;i < len; i++) SQSharedState::MarkObject(_values[i], chain);
|
||||
END_MARK()
|
||||
}
|
||||
void SQTable::Mark(SQCollectable **chain)
|
||||
{
|
||||
START_MARK()
|
||||
if(_delegate) _delegate->Mark(chain);
|
||||
SQInteger len = _numofnodes;
|
||||
for(SQInteger i = 0; i < len; i++){
|
||||
SQSharedState::MarkObject(_nodes[i].key, chain);
|
||||
SQSharedState::MarkObject(_nodes[i].val, chain);
|
||||
}
|
||||
END_MARK()
|
||||
}
|
||||
|
||||
void SQClass::Mark(SQCollectable **chain)
|
||||
{
|
||||
START_MARK()
|
||||
_members->Mark(chain);
|
||||
if(_base) _base->Mark(chain);
|
||||
SQSharedState::MarkObject(_attributes, chain);
|
||||
for(SQUnsignedInteger i =0; i< _defaultvalues.size(); i++) {
|
||||
SQSharedState::MarkObject(_defaultvalues[i].val, chain);
|
||||
SQSharedState::MarkObject(_defaultvalues[i].attrs, chain);
|
||||
}
|
||||
for(SQUnsignedInteger j =0; j< _methods.size(); j++) {
|
||||
SQSharedState::MarkObject(_methods[j].val, chain);
|
||||
SQSharedState::MarkObject(_methods[j].attrs, chain);
|
||||
}
|
||||
for(SQUnsignedInteger k =0; k< _metamethods.size(); k++) {
|
||||
SQSharedState::MarkObject(_metamethods[k], chain);
|
||||
}
|
||||
END_MARK()
|
||||
}
|
||||
|
||||
void SQInstance::Mark(SQCollectable **chain)
|
||||
{
|
||||
START_MARK()
|
||||
_class->Mark(chain);
|
||||
SQUnsignedInteger nvalues = _class->_defaultvalues.size();
|
||||
for(SQUnsignedInteger i =0; i< nvalues; i++) {
|
||||
SQSharedState::MarkObject(_values[i], chain);
|
||||
}
|
||||
END_MARK()
|
||||
}
|
||||
|
||||
void SQGenerator::Mark(SQCollectable **chain)
|
||||
{
|
||||
START_MARK()
|
||||
for(SQUnsignedInteger i = 0; i < _stack.size(); i++) SQSharedState::MarkObject(_stack[i], chain);
|
||||
for(SQUnsignedInteger j = 0; j < _vargsstack.size(); j++) SQSharedState::MarkObject(_vargsstack[j], chain);
|
||||
SQSharedState::MarkObject(_closure, chain);
|
||||
END_MARK()
|
||||
}
|
||||
|
||||
void SQClosure::Mark(SQCollectable **chain)
|
||||
{
|
||||
START_MARK()
|
||||
for(SQUnsignedInteger i = 0; i < _outervalues.size(); i++) SQSharedState::MarkObject(_outervalues[i], chain);
|
||||
for(SQUnsignedInteger i = 0; i < _defaultparams.size(); i++) SQSharedState::MarkObject(_defaultparams[i], chain);
|
||||
END_MARK()
|
||||
}
|
||||
|
||||
void SQNativeClosure::Mark(SQCollectable **chain)
|
||||
{
|
||||
START_MARK()
|
||||
for(SQUnsignedInteger i = 0; i < _outervalues.size(); i++) SQSharedState::MarkObject(_outervalues[i], chain);
|
||||
END_MARK()
|
||||
}
|
||||
|
||||
void SQUserData::Mark(SQCollectable **chain){
|
||||
START_MARK()
|
||||
if(_delegate) _delegate->Mark(chain);
|
||||
END_MARK()
|
||||
}
|
||||
|
||||
void SQCollectable::UnMark() { _uiRef&=~MARK_FLAG; }
|
||||
|
||||
#endif
|
||||
|
||||
void SQVM::Iterate( CSQStateIterator *pIterator )
|
||||
{
|
||||
SQSharedState::IterateObject(pIterator,_lasterror,"_lasterror");
|
||||
SQSharedState::IterateObject(pIterator,_errorhandler,"_errorhandler");
|
||||
SQSharedState::IterateObject(pIterator,_debughook,"_debughook");
|
||||
SQSharedState::IterateObject(pIterator,_roottable,"_roottable");
|
||||
SQSharedState::IterateObject(pIterator,temp_reg,"temp_reg");
|
||||
pIterator->PsuedoKey( "_stack" );
|
||||
if ( pIterator->BeginContained() )
|
||||
{
|
||||
for(SQUnsignedInteger i = 0; i < _stack.size(); i++) SQSharedState::IterateObject(pIterator,_stack[i]);
|
||||
pIterator->EndContained();
|
||||
}
|
||||
pIterator->PsuedoKey( "_vargsstack" );
|
||||
if ( pIterator->BeginContained() )
|
||||
{
|
||||
for(SQUnsignedInteger j = 0; j < _vargsstack.size(); j++) SQSharedState::IterateObject(pIterator,_vargsstack[j]);
|
||||
pIterator->EndContained();
|
||||
}
|
||||
}
|
||||
|
||||
void SQArray::Iterate( CSQStateIterator *pIterator )
|
||||
{
|
||||
SQInteger len = _values.size();
|
||||
for(SQInteger i = 0;i < len; i++) SQSharedState::IterateObject(pIterator,_values[i]);
|
||||
}
|
||||
|
||||
void SQTable::Iterate( CSQStateIterator *pIterator )
|
||||
{
|
||||
if(_delegate)
|
||||
{
|
||||
SQObject d = { OT_TABLE, _delegate };
|
||||
pIterator->PsuedoKey( "_delegate " );
|
||||
SQObjectPtr tmp(d);
|
||||
pIterator->Value( tmp );
|
||||
}
|
||||
SQInteger len = _numofnodes;
|
||||
for(SQInteger i = 0; i < len; i++){
|
||||
pIterator->Key(_nodes[i].key);
|
||||
SQSharedState::IterateObject(pIterator,_nodes[i].val);
|
||||
}
|
||||
}
|
||||
|
||||
void SQClass::Iterate( CSQStateIterator *pIterator )
|
||||
{
|
||||
SQObject m = { OT_TABLE, _members };
|
||||
SQObjectPtr tmpObjectPtr_m( m );
|
||||
SQSharedState::IterateObject(pIterator, tmpObjectPtr_m, "_members" );
|
||||
if(_base)
|
||||
{
|
||||
SQObject b = { OT_CLASS, (SQTable *)_base };
|
||||
pIterator->PsuedoKey( "_base " );
|
||||
SQObjectPtr tmpObjectPtr_b(b);
|
||||
pIterator->Value( tmpObjectPtr_b );
|
||||
}
|
||||
SQSharedState::IterateObject(pIterator,_attributes, "_attributes");
|
||||
pIterator->PsuedoKey( "_defaultvalues" );
|
||||
pIterator->BeginContained();
|
||||
for(SQUnsignedInteger i =0; i< _defaultvalues.size(); i++) {
|
||||
SQSharedState::IterateObject(pIterator,_defaultvalues[i].val);
|
||||
SQSharedState::IterateObject(pIterator,_defaultvalues[i].attrs);
|
||||
}
|
||||
pIterator->EndContained();
|
||||
pIterator->PsuedoKey( "_methods" );
|
||||
pIterator->BeginContained();
|
||||
for(SQUnsignedInteger j =0; j< _methods.size(); j++) {
|
||||
SQSharedState::IterateObject(pIterator,_methods[j].val);
|
||||
SQSharedState::IterateObject(pIterator,_methods[j].attrs);
|
||||
}
|
||||
pIterator->EndContained();
|
||||
pIterator->PsuedoKey( "_metamethods" );
|
||||
pIterator->BeginContained();
|
||||
for(SQUnsignedInteger k =0; k< _metamethods.size(); k++) {
|
||||
SQSharedState::IterateObject(pIterator,_metamethods[k]);
|
||||
}
|
||||
pIterator->EndContained();
|
||||
}
|
||||
|
||||
void SQInstance::Iterate( CSQStateIterator *pIterator )
|
||||
{
|
||||
SQObject c = { OT_CLASS, (SQTable *)_class };
|
||||
pIterator->PsuedoKey( "_class " );
|
||||
SQObjectPtr tmpObjectPtr_c( c );
|
||||
pIterator->Value( tmpObjectPtr_c );
|
||||
|
||||
SQUnsignedInteger nvalues = _class->_defaultvalues.size();
|
||||
for(SQUnsignedInteger i =0; i< nvalues; i++) {
|
||||
SQSharedState::IterateObject(pIterator,_values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void SQGenerator::Iterate( CSQStateIterator *pIterator )
|
||||
{
|
||||
for(SQUnsignedInteger i = 0; i < _stack.size(); i++) SQSharedState::IterateObject(pIterator,_stack[i]);
|
||||
for(SQUnsignedInteger j = 0; j < _vargsstack.size(); j++) SQSharedState::IterateObject(pIterator,_vargsstack[j]);
|
||||
SQSharedState::IterateObject(pIterator,_closure);
|
||||
}
|
||||
|
||||
void SQClosure::Iterate( CSQStateIterator *pIterator )
|
||||
{
|
||||
for(SQUnsignedInteger i = 0; i < _outervalues.size(); i++) SQSharedState::IterateObject(pIterator,_outervalues[i]);
|
||||
for(SQUnsignedInteger i = 0; i < _defaultparams.size(); i++) SQSharedState::IterateObject(pIterator,_defaultparams[i]);
|
||||
}
|
||||
|
||||
void SQNativeClosure::Iterate( CSQStateIterator *pIterator )
|
||||
{
|
||||
for(SQUnsignedInteger i = 0; i < _outervalues.size(); i++) SQSharedState::IterateObject(pIterator,_outervalues[i]);
|
||||
}
|
||||
|
||||
void SQUserData::Iterate( CSQStateIterator *pIterator )
|
||||
{
|
||||
if(_delegate)
|
||||
{
|
||||
SQObject d = { OT_TABLE, _delegate };
|
||||
pIterator->PsuedoKey( "_delegate " );
|
||||
SQObjectPtr tmpObjectPtr_d(d);
|
||||
pIterator->Value( tmpObjectPtr_d );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,384 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#ifndef _SQOBJECT_H_
|
||||
#define _SQOBJECT_H_
|
||||
|
||||
#include "squtils.h"
|
||||
|
||||
#define SQ_CLOSURESTREAM_HEAD (('S'<<24)|('Q'<<16)|('I'<<8)|('R'))
|
||||
#define SQ_CLOSURESTREAM_PART (('P'<<24)|('A'<<16)|('R'<<8)|('T'))
|
||||
#define SQ_CLOSURESTREAM_TAIL (('T'<<24)|('A'<<16)|('I'<<8)|('L'))
|
||||
|
||||
struct SQSharedState;
|
||||
class CSQStateIterator;
|
||||
|
||||
enum SQMetaMethod{
|
||||
MT_ADD=0,
|
||||
MT_SUB=1,
|
||||
MT_MUL=2,
|
||||
MT_DIV=3,
|
||||
MT_UNM=4,
|
||||
MT_MODULO=5,
|
||||
MT_SET=6,
|
||||
MT_GET=7,
|
||||
MT_TYPEOF=8,
|
||||
MT_NEXTI=9,
|
||||
MT_CMP=10,
|
||||
MT_CALL=11,
|
||||
MT_CLONED=12,
|
||||
MT_NEWSLOT=13,
|
||||
MT_DELSLOT=14,
|
||||
MT_TOSTRING=15,
|
||||
MT_NEWMEMBER=16,
|
||||
MT_INHERITED=17,
|
||||
MT_LAST = 18
|
||||
};
|
||||
|
||||
#define MM_ADD _SC("_add")
|
||||
#define MM_SUB _SC("_sub")
|
||||
#define MM_MUL _SC("_mul")
|
||||
#define MM_DIV _SC("_div")
|
||||
#define MM_UNM _SC("_unm")
|
||||
#define MM_MODULO _SC("_modulo")
|
||||
#define MM_SET _SC("_set")
|
||||
#define MM_GET _SC("_get")
|
||||
#define MM_TYPEOF _SC("_typeof")
|
||||
#define MM_NEXTI _SC("_nexti")
|
||||
#define MM_CMP _SC("_cmp")
|
||||
#define MM_CALL _SC("_call")
|
||||
#define MM_CLONED _SC("_cloned")
|
||||
#define MM_NEWSLOT _SC("_newslot")
|
||||
#define MM_DELSLOT _SC("_delslot")
|
||||
#define MM_TOSTRING _SC("_tostring")
|
||||
#define MM_NEWMEMBER _SC("_newmember")
|
||||
#define MM_INHERITED _SC("_inherited")
|
||||
|
||||
#define MINPOWER2 4
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define SQ_VALIDATE_REF_COUNT( pObj ) if ( (pObj)->_uiRef < 0 ) { DebuggerBreak(); }
|
||||
#else
|
||||
#define SQ_VALIDATE_REF_COUNT( pObj )
|
||||
#endif
|
||||
|
||||
struct SQRefCounted
|
||||
{
|
||||
SQRefCounted() { _uiRef = 0; _weakref = NULL; }
|
||||
virtual ~SQRefCounted();
|
||||
virtual void Iterate( CSQStateIterator *pIterator ) {};
|
||||
SQWeakRef *GetWeakRef(SQObjectType type);
|
||||
SQInteger _uiRef; // this should be signed to catch bugs
|
||||
struct SQWeakRef *_weakref;
|
||||
virtual void Release()=0;
|
||||
};
|
||||
|
||||
struct SQWeakRef : SQRefCounted
|
||||
{
|
||||
void Release();
|
||||
SQObject _obj;
|
||||
};
|
||||
|
||||
#define _realval(o) (type((o)) != OT_WEAKREF?(SQObject)o:_weakref(o)->_obj)
|
||||
|
||||
struct SQObjectPtr;
|
||||
|
||||
#define __AddRef(type,unval) if(ISREFCOUNTED(type)) \
|
||||
{ \
|
||||
SQ_VALIDATE_REF_COUNT( unval.pRefCounted ); \
|
||||
unval.pRefCounted->_uiRef++; \
|
||||
}
|
||||
|
||||
#define __Release(type,unval) if(ISREFCOUNTED(type) && ((--unval.pRefCounted->_uiRef)<=0)) \
|
||||
{ \
|
||||
SQ_VALIDATE_REF_COUNT( unval.pRefCounted ); \
|
||||
unval.pRefCounted->Release(); \
|
||||
}
|
||||
|
||||
#define __ObjRelease(obj) { \
|
||||
if((obj)) { \
|
||||
if( ( -- ((obj)->_uiRef) ) <= 0 ) \
|
||||
{ \
|
||||
SQ_VALIDATE_REF_COUNT( obj ); \
|
||||
(obj)->Release(); \
|
||||
} \
|
||||
(obj) = NULL; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define __ObjAddRef(obj) { \
|
||||
SQ_VALIDATE_REF_COUNT( obj ); \
|
||||
(obj)->_uiRef++; \
|
||||
}
|
||||
|
||||
#define type(obj) ((obj)._type)
|
||||
// VALVE_BUILD -- define a version of 'type' that is less name-space polluting so that we can #undef
|
||||
// and redef type around VS 2013 STL header files.
|
||||
#define SQ_TYPE(obj) ((obj)._type)
|
||||
#define is_delegable(t) (type(t)&SQOBJECT_DELEGABLE)
|
||||
#define raw_type(obj) _RAW_TYPE((obj)._type)
|
||||
|
||||
#define _integer(obj) ((obj)._unVal.nInteger)
|
||||
#define _float(obj) ((obj)._unVal.fFloat)
|
||||
#define _string(obj) ((obj)._unVal.pString)
|
||||
#define _table(obj) ((obj)._unVal.pTable)
|
||||
#define _array(obj) ((obj)._unVal.pArray)
|
||||
#define _closure(obj) ((obj)._unVal.pClosure)
|
||||
#define _generator(obj) ((obj)._unVal.pGenerator)
|
||||
#define _nativeclosure(obj) ((obj)._unVal.pNativeClosure)
|
||||
#define _userdata(obj) ((obj)._unVal.pUserData)
|
||||
#define _userpointer(obj) ((obj)._unVal.pUserPointer)
|
||||
#define _thread(obj) ((obj)._unVal.pThread)
|
||||
#define _funcproto(obj) ((obj)._unVal.pFunctionProto)
|
||||
#define _class(obj) ((obj)._unVal.pClass)
|
||||
#define _instance(obj) ((obj)._unVal.pInstance)
|
||||
#define _delegable(obj) ((SQDelegable *)(obj)._unVal.pDelegable)
|
||||
#define _weakref(obj) ((obj)._unVal.pWeakRef)
|
||||
#define _refcounted(obj) ((obj)._unVal.pRefCounted)
|
||||
#define _rawval(obj) ((obj)._unVal.raw)
|
||||
|
||||
#define _stringval(obj) (obj)._unVal.pString->_val
|
||||
#define _userdataval(obj) (obj)._unVal.pUserData->_val
|
||||
|
||||
#define tofloat(num) ((type(num)==OT_INTEGER)?(SQFloat)_integer(num):_float(num))
|
||||
#define tointeger(num) ((type(num)==OT_FLOAT)?(SQInteger)_float(num):_integer(num))
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
struct SQObjectPtr : public SQObject
|
||||
{
|
||||
SQObjectPtr()
|
||||
{
|
||||
SQ_OBJECT_RAWINIT()
|
||||
_type=OT_NULL;
|
||||
_unVal.pUserPointer=NULL;
|
||||
}
|
||||
SQObjectPtr(const SQObjectPtr &o)
|
||||
{
|
||||
SQ_OBJECT_RAWINIT()
|
||||
_type=o._type;
|
||||
_unVal=o._unVal;
|
||||
__AddRef(_type,_unVal);
|
||||
}
|
||||
SQObjectPtr(const SQObject &o)
|
||||
{
|
||||
SQ_OBJECT_RAWINIT()
|
||||
_type=o._type;
|
||||
_unVal=o._unVal;
|
||||
__AddRef(_type,_unVal);
|
||||
}
|
||||
SQObjectPtr(SQTable *pTable)
|
||||
{
|
||||
SQ_OBJECT_RAWINIT()
|
||||
_type=OT_TABLE;
|
||||
_unVal.pTable=pTable;
|
||||
Assert(_unVal.pTable);
|
||||
__AddRef(_type,_unVal);
|
||||
}
|
||||
SQObjectPtr(SQClass *pClass)
|
||||
{
|
||||
SQ_OBJECT_RAWINIT()
|
||||
_type=OT_CLASS;
|
||||
_unVal.pClass=pClass;
|
||||
Assert(_unVal.pClass);
|
||||
__AddRef(_type,_unVal);
|
||||
}
|
||||
SQObjectPtr(SQInstance *pInstance)
|
||||
{
|
||||
SQ_OBJECT_RAWINIT()
|
||||
_type=OT_INSTANCE;
|
||||
_unVal.pInstance=pInstance;
|
||||
Assert(_unVal.pInstance);
|
||||
__AddRef(_type,_unVal);
|
||||
}
|
||||
SQObjectPtr(SQArray *pArray)
|
||||
{
|
||||
SQ_OBJECT_RAWINIT()
|
||||
_type=OT_ARRAY;
|
||||
_unVal.pArray=pArray;
|
||||
Assert(_unVal.pArray);
|
||||
__AddRef(_type,_unVal);
|
||||
}
|
||||
SQObjectPtr(SQClosure *pClosure)
|
||||
{
|
||||
SQ_OBJECT_RAWINIT()
|
||||
_type=OT_CLOSURE;
|
||||
_unVal.pClosure=pClosure;
|
||||
Assert(_unVal.pClosure);
|
||||
__AddRef(_type,_unVal);
|
||||
}
|
||||
SQObjectPtr(SQGenerator *pGenerator)
|
||||
{
|
||||
SQ_OBJECT_RAWINIT()
|
||||
_type=OT_GENERATOR;
|
||||
_unVal.pGenerator=pGenerator;
|
||||
Assert(_unVal.pGenerator);
|
||||
__AddRef(_type,_unVal);
|
||||
}
|
||||
SQObjectPtr(SQNativeClosure *pNativeClosure)
|
||||
{
|
||||
SQ_OBJECT_RAWINIT()
|
||||
_type=OT_NATIVECLOSURE;
|
||||
_unVal.pNativeClosure=pNativeClosure;
|
||||
Assert(_unVal.pNativeClosure);
|
||||
__AddRef(_type,_unVal);
|
||||
}
|
||||
SQObjectPtr(SQString *pString)
|
||||
{
|
||||
SQ_OBJECT_RAWINIT()
|
||||
_type=OT_STRING;
|
||||
_unVal.pString=pString;
|
||||
Assert(_unVal.pString);
|
||||
__AddRef(_type,_unVal);
|
||||
}
|
||||
SQObjectPtr(SQUserData *pUserData)
|
||||
{
|
||||
SQ_OBJECT_RAWINIT()
|
||||
_type=OT_USERDATA;
|
||||
_unVal.pUserData=pUserData;
|
||||
Assert(_unVal.pUserData);
|
||||
__AddRef(_type,_unVal);
|
||||
}
|
||||
SQObjectPtr(SQVM *pThread)
|
||||
{
|
||||
SQ_OBJECT_RAWINIT()
|
||||
_type=OT_THREAD;
|
||||
_unVal.pThread=pThread;
|
||||
Assert(_unVal.pThread);
|
||||
__AddRef(_type,_unVal);
|
||||
}
|
||||
SQObjectPtr(SQWeakRef *pWeakRef)
|
||||
{
|
||||
SQ_OBJECT_RAWINIT()
|
||||
_type=OT_WEAKREF;
|
||||
_unVal.pWeakRef=pWeakRef;
|
||||
Assert(_unVal.pWeakRef);
|
||||
__AddRef(_type,_unVal);
|
||||
}
|
||||
SQObjectPtr(SQFunctionProto *pFunctionProto)
|
||||
{
|
||||
SQ_OBJECT_RAWINIT()
|
||||
_type=OT_FUNCPROTO;
|
||||
_unVal.pFunctionProto=pFunctionProto;
|
||||
Assert(_unVal.pFunctionProto);
|
||||
__AddRef(_type,_unVal);
|
||||
}
|
||||
SQObjectPtr(SQInteger nInteger)
|
||||
{
|
||||
SQ_OBJECT_RAWINIT()
|
||||
_type=OT_INTEGER;
|
||||
_unVal.nInteger=nInteger;
|
||||
}
|
||||
SQObjectPtr(SQFloat fFloat)
|
||||
{
|
||||
SQ_OBJECT_RAWINIT()
|
||||
_type=OT_FLOAT;
|
||||
_unVal.fFloat=fFloat;
|
||||
}
|
||||
SQObjectPtr(bool bBool)
|
||||
{
|
||||
SQ_OBJECT_RAWINIT()
|
||||
_type = OT_BOOL;
|
||||
_unVal.nInteger = bBool?1:0;
|
||||
}
|
||||
SQObjectPtr(SQUserPointer pUserPointer)
|
||||
{
|
||||
SQ_OBJECT_RAWINIT()
|
||||
_type=OT_USERPOINTER;
|
||||
_unVal.pUserPointer=pUserPointer;
|
||||
}
|
||||
~SQObjectPtr()
|
||||
{
|
||||
__Release(_type,_unVal);
|
||||
}
|
||||
inline void Null()
|
||||
{
|
||||
SQObjectType tOldType;
|
||||
SQObjectValue unOldVal;
|
||||
tOldType = _type;
|
||||
unOldVal = _unVal;
|
||||
_type = OT_NULL;
|
||||
_unVal.pUserPointer = NULL;
|
||||
__Release(tOldType,unOldVal);
|
||||
}
|
||||
inline SQObjectPtr& operator=(SQInteger i)
|
||||
{
|
||||
__Release(_type,_unVal);
|
||||
_unVal.nInteger = i;
|
||||
_type = OT_INTEGER;
|
||||
return *this;
|
||||
}
|
||||
inline SQObjectPtr& operator=(SQFloat f)
|
||||
{
|
||||
__Release(_type,_unVal);
|
||||
_unVal.fFloat = f;
|
||||
_type = OT_FLOAT;
|
||||
return *this;
|
||||
}
|
||||
inline SQObjectPtr& operator=(const SQObjectPtr& obj)
|
||||
{
|
||||
SQObjectType tOldType;
|
||||
SQObjectValue unOldVal;
|
||||
tOldType=_type;
|
||||
unOldVal=_unVal;
|
||||
_unVal = obj._unVal;
|
||||
_type = obj._type;
|
||||
__AddRef(_type,_unVal);
|
||||
__Release(tOldType,unOldVal);
|
||||
return *this;
|
||||
}
|
||||
inline SQObjectPtr& operator=(const SQObject& obj)
|
||||
{
|
||||
SQObjectType tOldType;
|
||||
SQObjectValue unOldVal;
|
||||
tOldType=_type;
|
||||
unOldVal=_unVal;
|
||||
_unVal = obj._unVal;
|
||||
_type = obj._type;
|
||||
__AddRef(_type,_unVal);
|
||||
__Release(tOldType,unOldVal);
|
||||
return *this;
|
||||
}
|
||||
private:
|
||||
SQObjectPtr(const SQChar *){} //safety
|
||||
};
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef NO_GARBAGE_COLLECTOR
|
||||
#define MARK_FLAG 0x40000000
|
||||
struct SQCollectable : public SQRefCounted {
|
||||
SQCollectable *_next;
|
||||
SQCollectable *_prev;
|
||||
SQSharedState *_sharedstate;
|
||||
virtual void Release()=0;
|
||||
virtual void Mark(SQCollectable **chain)=0;
|
||||
void UnMark();
|
||||
virtual void Finalize()=0;
|
||||
static void AddToChain(SQCollectable **chain,SQCollectable *c);
|
||||
static void RemoveFromChain(SQCollectable **chain,SQCollectable *c);
|
||||
};
|
||||
|
||||
|
||||
#define ADD_TO_CHAIN(chain,obj) AddToChain(chain,obj)
|
||||
#define REMOVE_FROM_CHAIN(chain,obj) {if(!(_uiRef&MARK_FLAG))RemoveFromChain(chain,obj);}
|
||||
#define CHAINABLE_OBJ SQCollectable
|
||||
#define INIT_CHAIN() {_next=NULL;_prev=NULL;_sharedstate=ss;}
|
||||
#else
|
||||
|
||||
#define ADD_TO_CHAIN(chain,obj) ((void)0)
|
||||
#define REMOVE_FROM_CHAIN(chain,obj) ((void)0)
|
||||
#define CHAINABLE_OBJ SQRefCounted
|
||||
#define INIT_CHAIN() ((void)0)
|
||||
#endif
|
||||
|
||||
struct SQDelegable : public CHAINABLE_OBJ {
|
||||
bool SetDelegate(SQTable *m);
|
||||
virtual bool GetMetaMethod(SQVM *v,SQMetaMethod mm,SQObjectPtr &res);
|
||||
SQTable *_delegate;
|
||||
};
|
||||
|
||||
SQUnsignedInteger TranslateIndex(const SQObjectPtr &idx);
|
||||
typedef sqvector<SQObjectPtr> SQObjectPtrVec;
|
||||
typedef sqvector<SQInteger> SQIntVec;
|
||||
const SQChar *GetTypeName(const SQObjectPtr &obj1);
|
||||
const SQChar *IdType2Name(SQObjectType type);
|
||||
|
||||
|
||||
|
||||
#endif //_SQOBJECT_H_
|
||||
@@ -0,0 +1,115 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#ifndef _SQOPCODES_H_
|
||||
#define _SQOPCODES_H_
|
||||
|
||||
#define MAX_FUNC_STACKSIZE 0xFF
|
||||
#define MAX_LITERALS ((SQInteger)0x7FFFFFFF)
|
||||
|
||||
enum BitWiseOP {
|
||||
BW_AND = 0,
|
||||
BW_OR = 2,
|
||||
BW_XOR = 3,
|
||||
BW_SHIFTL = 4,
|
||||
BW_SHIFTR = 5,
|
||||
BW_USHIFTR = 6
|
||||
};
|
||||
|
||||
enum CmpOP {
|
||||
CMP_G = 0,
|
||||
CMP_GE = 2,
|
||||
CMP_L = 3,
|
||||
CMP_LE = 4
|
||||
};
|
||||
enum SQOpcode
|
||||
{
|
||||
_OP_LINE= 0x00,
|
||||
_OP_LOAD= 0x01,
|
||||
_OP_LOADINT= 0x02,
|
||||
_OP_LOADFLOAT= 0x03,
|
||||
_OP_DLOAD= 0x04,
|
||||
_OP_TAILCALL= 0x05,
|
||||
_OP_CALL= 0x06,
|
||||
_OP_PREPCALL= 0x07,
|
||||
_OP_PREPCALLK= 0x08,
|
||||
_OP_GETK= 0x09,
|
||||
_OP_MOVE= 0x0A,
|
||||
_OP_NEWSLOT= 0x0B,
|
||||
_OP_DELETE= 0x0C,
|
||||
_OP_SET= 0x0D,
|
||||
_OP_GET= 0x0E,
|
||||
_OP_EQ= 0x0F,
|
||||
_OP_NE= 0x10,
|
||||
_OP_ARITH= 0x11,
|
||||
_OP_BITW= 0x12,
|
||||
_OP_RETURN= 0x13,
|
||||
_OP_LOADNULLS= 0x14,
|
||||
_OP_LOADROOTTABLE= 0x15,
|
||||
_OP_LOADBOOL= 0x16,
|
||||
_OP_DMOVE= 0x17,
|
||||
_OP_JMP= 0x18,
|
||||
_OP_JNZ= 0x19,
|
||||
_OP_JZ= 0x1A,
|
||||
_OP_LOADFREEVAR= 0x1B,
|
||||
_OP_VARGC= 0x1C,
|
||||
_OP_GETVARGV= 0x1D,
|
||||
_OP_NEWTABLE= 0x1E,
|
||||
_OP_NEWARRAY= 0x1F,
|
||||
_OP_APPENDARRAY= 0x20,
|
||||
_OP_GETPARENT= 0x21,
|
||||
_OP_COMPARITH= 0x22,
|
||||
_OP_COMPARITHL= 0x23,
|
||||
_OP_INC= 0x24,
|
||||
_OP_INCL= 0x25,
|
||||
_OP_PINC= 0x26,
|
||||
_OP_PINCL= 0x27,
|
||||
_OP_CMP= 0x28,
|
||||
_OP_EXISTS= 0x29,
|
||||
_OP_INSTANCEOF= 0x2A,
|
||||
_OP_AND= 0x2B,
|
||||
_OP_OR= 0x2C,
|
||||
_OP_NEG= 0x2D,
|
||||
_OP_NOT= 0x2E,
|
||||
_OP_BWNOT= 0x2F,
|
||||
_OP_CLOSURE= 0x30,
|
||||
_OP_YIELD= 0x31,
|
||||
_OP_RESUME= 0x32,
|
||||
_OP_FOREACH= 0x33,
|
||||
_OP_POSTFOREACH= 0x34,
|
||||
_OP_DELEGATE= 0x35,
|
||||
_OP_CLONE= 0x36,
|
||||
_OP_TYPEOF= 0x37,
|
||||
_OP_PUSHTRAP= 0x38,
|
||||
_OP_POPTRAP= 0x39,
|
||||
_OP_THROW= 0x3A,
|
||||
_OP_CLASS= 0x3B,
|
||||
_OP_NEWSLOTA= 0x3C,
|
||||
};
|
||||
|
||||
struct SQInstructionDesc {
|
||||
const SQChar *name;
|
||||
};
|
||||
|
||||
struct SQInstruction
|
||||
{
|
||||
SQInstruction(){};
|
||||
SQInstruction(SQOpcode _op,SQInteger a0=0,SQInteger a1=0,SQInteger a2=0,SQInteger a3=0)
|
||||
{ op = _op;
|
||||
_arg0 = (unsigned char)a0;_arg1 = (SQInt32)a1;
|
||||
_arg2 = (unsigned char)a2;_arg3 = (unsigned char)a3;
|
||||
}
|
||||
|
||||
|
||||
SQInt32 _arg1;
|
||||
unsigned char op;
|
||||
unsigned char _arg0;
|
||||
unsigned char _arg2;
|
||||
unsigned char _arg3;
|
||||
};
|
||||
|
||||
#include "squtils.h"
|
||||
typedef sqvector<SQInstruction> SQInstructionVec;
|
||||
|
||||
#define NEW_SLOT_ATTRIBUTES_FLAG 0x01
|
||||
#define NEW_SLOT_STATIC_FLAG 0x02
|
||||
|
||||
#endif // _SQOPCODES_H_
|
||||
@@ -0,0 +1,19 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#ifndef _SQPCHEADER_H_
|
||||
#define _SQPCHEADER_H_
|
||||
|
||||
#if defined(_MSC_VER) && defined(_DEBUG)
|
||||
#include <crtdbg.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <new>
|
||||
//squirrel stuff
|
||||
#include <squirrel.h>
|
||||
#include "sqobject.h"
|
||||
#include "sqstate.h"
|
||||
|
||||
#endif //_SQPCHEADER_H_
|
||||
@@ -0,0 +1,725 @@
|
||||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
#include "sqpcheader.h"
|
||||
#include "sqopcodes.h"
|
||||
#include "sqvm.h"
|
||||
#include "sqfuncproto.h"
|
||||
#include "sqclosure.h"
|
||||
#include "sqstring.h"
|
||||
#include "sqtable.h"
|
||||
#include "sqarray.h"
|
||||
#include "squserdata.h"
|
||||
#include "sqclass.h"
|
||||
|
||||
#ifdef DEBUG_SQSTRING_LEAKS
|
||||
#include "tier1/utldict.h"
|
||||
#endif
|
||||
|
||||
#if defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST)
|
||||
#include "memdbgon.h"
|
||||
#undef new // allow placement new
|
||||
#endif
|
||||
|
||||
SQObjectPtr _null_;
|
||||
SQObjectPtr _true_(true);
|
||||
SQObjectPtr _false_(false);
|
||||
SQObjectPtr _one_((SQInteger)1);
|
||||
SQObjectPtr _minusone_((SQInteger)-1);
|
||||
|
||||
SQSharedState::SQSharedState()
|
||||
{
|
||||
_compilererrorhandler = NULL;
|
||||
_printfunc = NULL;
|
||||
_debuginfo = false;
|
||||
_notifyallexceptions = false;
|
||||
m_pOwnerData = NULL;
|
||||
_gc_disableDepth = 0;
|
||||
}
|
||||
|
||||
#define newsysstring(s) { \
|
||||
_systemstrings->push_back(SQString::Create(this,s)); \
|
||||
}
|
||||
|
||||
#define newmetamethod(s) { \
|
||||
_metamethods->push_back(SQString::Create(this,s)); \
|
||||
_table(_metamethodsmap)->NewSlot(_metamethods->back(),(SQInteger)(_metamethods->size()-1)); \
|
||||
}
|
||||
|
||||
bool CompileTypemask(SQIntVec &res,const SQChar *typemask)
|
||||
{
|
||||
SQInteger i = 0;
|
||||
|
||||
SQInteger mask = 0;
|
||||
while(typemask[i] != 0) {
|
||||
|
||||
switch(typemask[i]){
|
||||
case 'o': mask |= _RT_NULL; break;
|
||||
case 'i': mask |= _RT_INTEGER; break;
|
||||
case 'f': mask |= _RT_FLOAT; break;
|
||||
case 'n': mask |= (_RT_FLOAT | _RT_INTEGER); break;
|
||||
case 's': mask |= _RT_STRING; break;
|
||||
case 't': mask |= _RT_TABLE; break;
|
||||
case 'a': mask |= _RT_ARRAY; break;
|
||||
case 'u': mask |= _RT_USERDATA; break;
|
||||
case 'c': mask |= (_RT_CLOSURE | _RT_NATIVECLOSURE); break;
|
||||
case 'b': mask |= _RT_BOOL; break;
|
||||
case 'g': mask |= _RT_GENERATOR; break;
|
||||
case 'p': mask |= _RT_USERPOINTER; break;
|
||||
case 'v': mask |= _RT_THREAD; break;
|
||||
case 'x': mask |= _RT_INSTANCE; break;
|
||||
case 'y': mask |= _RT_CLASS; break;
|
||||
case 'r': mask |= _RT_WEAKREF; break;
|
||||
case '.': mask = -1; res.push_back(mask); i++; mask = 0; continue;
|
||||
case ' ': i++; continue; //ignores spaces
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
i++;
|
||||
if(typemask[i] == '|') {
|
||||
i++;
|
||||
if(typemask[i] == 0)
|
||||
return false;
|
||||
continue;
|
||||
}
|
||||
res.push_back(mask);
|
||||
mask = 0;
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
SQTable *CreateDefaultDelegate(SQSharedState *ss,SQRegFunction *funcz)
|
||||
{
|
||||
SQInteger i=0;
|
||||
SQTable *t=SQTable::Create(ss,0);
|
||||
while(funcz[i].name!=0){
|
||||
SQNativeClosure *nc = SQNativeClosure::Create(ss,funcz[i].f);
|
||||
nc->_nparamscheck = funcz[i].nparamscheck;
|
||||
nc->_name = SQString::Create(ss,funcz[i].name);
|
||||
if(funcz[i].typemask && !CompileTypemask(nc->_typecheck,funcz[i].typemask))
|
||||
return NULL;
|
||||
t->NewSlot(SQString::Create(ss,funcz[i].name),nc);
|
||||
i++;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
void SQSharedState::Init()
|
||||
{
|
||||
_scratchpad=NULL;
|
||||
_scratchpadsize=0;
|
||||
#ifndef NO_GARBAGE_COLLECTOR
|
||||
_gc_chain=NULL;
|
||||
#endif
|
||||
sq_new(_stringtable,StringTable);
|
||||
sq_new(_metamethods,SQObjectPtrVec);
|
||||
sq_new(_systemstrings,SQObjectPtrVec);
|
||||
sq_new(_types,SQObjectPtrVec);
|
||||
_metamethodsmap = SQTable::Create(this,MT_LAST-1);
|
||||
//adding type strings to avoid memory trashing
|
||||
//types names
|
||||
newsysstring(_SC("null"));
|
||||
newsysstring(_SC("table"));
|
||||
newsysstring(_SC("array"));
|
||||
newsysstring(_SC("closure"));
|
||||
newsysstring(_SC("string"));
|
||||
newsysstring(_SC("userdata"));
|
||||
newsysstring(_SC("integer"));
|
||||
newsysstring(_SC("float"));
|
||||
newsysstring(_SC("userpointer"));
|
||||
newsysstring(_SC("function"));
|
||||
newsysstring(_SC("generator"));
|
||||
newsysstring(_SC("thread"));
|
||||
newsysstring(_SC("class"));
|
||||
newsysstring(_SC("instance"));
|
||||
newsysstring(_SC("bool"));
|
||||
//meta methods
|
||||
newmetamethod(MM_ADD);
|
||||
newmetamethod(MM_SUB);
|
||||
newmetamethod(MM_MUL);
|
||||
newmetamethod(MM_DIV);
|
||||
newmetamethod(MM_UNM);
|
||||
newmetamethod(MM_MODULO);
|
||||
newmetamethod(MM_SET);
|
||||
newmetamethod(MM_GET);
|
||||
newmetamethod(MM_TYPEOF);
|
||||
newmetamethod(MM_NEXTI);
|
||||
newmetamethod(MM_CMP);
|
||||
newmetamethod(MM_CALL);
|
||||
newmetamethod(MM_CLONED);
|
||||
newmetamethod(MM_NEWSLOT);
|
||||
newmetamethod(MM_DELSLOT);
|
||||
newmetamethod(MM_TOSTRING);
|
||||
newmetamethod(MM_NEWMEMBER);
|
||||
newmetamethod(MM_INHERITED);
|
||||
|
||||
_constructoridx = SQString::Create(this,_SC("constructor"));
|
||||
_registry = SQTable::Create(this,0);
|
||||
_consts = SQTable::Create(this,0);
|
||||
_table_default_delegate = CreateDefaultDelegate(this,_table_default_delegate_funcz);
|
||||
_array_default_delegate = CreateDefaultDelegate(this,_array_default_delegate_funcz);
|
||||
_string_default_delegate = CreateDefaultDelegate(this,_string_default_delegate_funcz);
|
||||
_number_default_delegate = CreateDefaultDelegate(this,_number_default_delegate_funcz);
|
||||
_closure_default_delegate = CreateDefaultDelegate(this,_closure_default_delegate_funcz);
|
||||
_generator_default_delegate = CreateDefaultDelegate(this,_generator_default_delegate_funcz);
|
||||
_thread_default_delegate = CreateDefaultDelegate(this,_thread_default_delegate_funcz);
|
||||
_class_default_delegate = CreateDefaultDelegate(this,_class_default_delegate_funcz);
|
||||
_instance_default_delegate = CreateDefaultDelegate(this,_instance_default_delegate_funcz);
|
||||
_weakref_default_delegate = CreateDefaultDelegate(this,_weakref_default_delegate_funcz);
|
||||
|
||||
}
|
||||
|
||||
SQSharedState::~SQSharedState()
|
||||
{
|
||||
_constructoridx = _null_;
|
||||
_table(_registry)->Finalize();
|
||||
_table(_consts)->Finalize();
|
||||
_table(_metamethodsmap)->Finalize();
|
||||
_registry = _null_;
|
||||
_consts = _null_;
|
||||
_metamethodsmap = _null_;
|
||||
while(!_systemstrings->empty()) {
|
||||
_systemstrings->back()=_null_;
|
||||
_systemstrings->pop_back();
|
||||
}
|
||||
_thread(_root_vm)->Finalize();
|
||||
_root_vm = _null_;
|
||||
_table_default_delegate = _null_;
|
||||
_array_default_delegate = _null_;
|
||||
_string_default_delegate = _null_;
|
||||
_number_default_delegate = _null_;
|
||||
_closure_default_delegate = _null_;
|
||||
_generator_default_delegate = _null_;
|
||||
_thread_default_delegate = _null_;
|
||||
_class_default_delegate = _null_;
|
||||
_instance_default_delegate = _null_;
|
||||
_weakref_default_delegate = _null_;
|
||||
_refs_table.Finalize();
|
||||
#ifndef NO_GARBAGE_COLLECTOR
|
||||
SQCollectable *t = _gc_chain;
|
||||
SQCollectable *nx = NULL;
|
||||
while(t) {
|
||||
SQ_VALIDATE_REF_COUNT( t );
|
||||
t->_uiRef++;
|
||||
t->Finalize();
|
||||
nx = t->_next;
|
||||
if(--t->_uiRef <= 0)
|
||||
{
|
||||
SQ_VALIDATE_REF_COUNT( t );
|
||||
t->Release();
|
||||
}
|
||||
t=nx;
|
||||
}
|
||||
Assert(_gc_chain==NULL); //just to prove a theory
|
||||
while(_gc_chain){
|
||||
_gc_chain->_uiRef++;
|
||||
SQ_VALIDATE_REF_COUNT( _gc_chain );
|
||||
_gc_chain->Release();
|
||||
}
|
||||
#endif
|
||||
|
||||
sq_delete(_types,SQObjectPtrVec);
|
||||
sq_delete(_systemstrings,SQObjectPtrVec);
|
||||
sq_delete(_metamethods,SQObjectPtrVec);
|
||||
sq_delete(_stringtable,StringTable);
|
||||
if(_scratchpad)SQ_FREE(_scratchpad,_scratchpadsize);
|
||||
}
|
||||
|
||||
|
||||
SQInteger SQSharedState::GetMetaMethodIdxByName(const SQObjectPtr &name)
|
||||
{
|
||||
if(type(name) != OT_STRING)
|
||||
return -1;
|
||||
SQObjectPtr ret;
|
||||
if(_table(_metamethodsmap)->Get(name,ret)) {
|
||||
return _integer(ret);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline bool IsContainer( SQObjectType type )
|
||||
{
|
||||
switch(type){
|
||||
case OT_TABLE:
|
||||
case OT_ARRAY:
|
||||
case OT_USERDATA:
|
||||
case OT_CLOSURE:
|
||||
case OT_NATIVECLOSURE:
|
||||
case OT_GENERATOR:
|
||||
case OT_THREAD:
|
||||
case OT_CLASS:
|
||||
case OT_INSTANCE:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void SQSharedState::Iterate( SQVM *vm, CSQStateIterator *pIterator )
|
||||
{
|
||||
#ifndef NO_GARBAGE_COLLECTOR
|
||||
CollectGarbage( vm );
|
||||
SQInteger n=0;
|
||||
SQCollectable *tchain=NULL;
|
||||
SQVM *vms = _thread(_root_vm);
|
||||
|
||||
vms->Iterate( pIterator );
|
||||
SQInteger x = _table(_thread(_root_vm)->_roottable)->CountUsed();
|
||||
// _refs_table.Mark(&tchain);
|
||||
IterateObject(pIterator,_registry,"_registry");
|
||||
IterateObject(pIterator,_consts,"_consts");
|
||||
IterateObject(pIterator,_metamethodsmap,"_metamethodsmap");
|
||||
IterateObject(pIterator,_table_default_delegate,"_table_default_delegate");
|
||||
IterateObject(pIterator,_array_default_delegate,"_array_default_delegate");
|
||||
IterateObject(pIterator,_string_default_delegate,"_string_default_delegate");
|
||||
IterateObject(pIterator,_number_default_delegate,"_number_default_delegate");
|
||||
IterateObject(pIterator,_generator_default_delegate,"_generator_default_delegate");
|
||||
IterateObject(pIterator,_thread_default_delegate,"_thread_default_delegate");
|
||||
IterateObject(pIterator,_closure_default_delegate,"_closure_default_delegate");
|
||||
IterateObject(pIterator,_class_default_delegate,"_class_default_delegate");
|
||||
IterateObject(pIterator,_instance_default_delegate,"_instance_default_delegate");
|
||||
IterateObject(pIterator,_weakref_default_delegate,"_weakref_default_delegate");
|
||||
|
||||
_refcounted(_registry)->_uiRef &= ~MARK_FLAG;
|
||||
_refcounted(_consts)->_uiRef &= ~MARK_FLAG;
|
||||
_refcounted(_metamethodsmap)->_uiRef &= ~MARK_FLAG;
|
||||
_refcounted(_table_default_delegate)->_uiRef &= ~MARK_FLAG;
|
||||
_refcounted(_array_default_delegate)->_uiRef &= ~MARK_FLAG;
|
||||
_refcounted(_string_default_delegate)->_uiRef &= ~MARK_FLAG;
|
||||
_refcounted(_number_default_delegate)->_uiRef &= ~MARK_FLAG;
|
||||
_refcounted(_generator_default_delegate)->_uiRef &= ~MARK_FLAG;
|
||||
_refcounted(_thread_default_delegate)->_uiRef &= ~MARK_FLAG;
|
||||
_refcounted(_closure_default_delegate)->_uiRef &= ~MARK_FLAG;
|
||||
_refcounted(_class_default_delegate)->_uiRef &= ~MARK_FLAG;
|
||||
_refcounted(_instance_default_delegate)->_uiRef &= ~MARK_FLAG;
|
||||
_refcounted(_weakref_default_delegate)->_uiRef &= ~MARK_FLAG;
|
||||
|
||||
SQCollectable *t = _gc_chain;
|
||||
while(t)
|
||||
{
|
||||
t->UnMark();
|
||||
t = t->_next;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void SQSharedState::IterateObject( CSQStateIterator *pIterator, SQObjectPtr &value, const char *pszName )
|
||||
{
|
||||
#ifndef NO_GARBAGE_COLLECTOR
|
||||
if ( pszName )
|
||||
{
|
||||
pIterator->PsuedoKey( pszName );
|
||||
}
|
||||
|
||||
pIterator->Value( value );
|
||||
if ( IsContainer( type(value) ) )
|
||||
{
|
||||
if ( !( value._unVal.pRefCounted->_uiRef & MARK_FLAG ) )
|
||||
{
|
||||
if ( pIterator->BeginContained() )
|
||||
{
|
||||
value._unVal.pRefCounted->_uiRef |= MARK_FLAG;
|
||||
value._unVal.pRefCounted->Iterate( pIterator );
|
||||
pIterator->EndContained();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#ifndef NO_GARBAGE_COLLECTOR
|
||||
|
||||
void SQSharedState::MarkObject(SQObjectPtr &o,SQCollectable **chain)
|
||||
{
|
||||
switch(type(o)){
|
||||
case OT_TABLE:_table(o)->Mark(chain);break;
|
||||
case OT_ARRAY:_array(o)->Mark(chain);break;
|
||||
case OT_USERDATA:_userdata(o)->Mark(chain);break;
|
||||
case OT_CLOSURE:_closure(o)->Mark(chain);break;
|
||||
case OT_NATIVECLOSURE:_nativeclosure(o)->Mark(chain);break;
|
||||
case OT_GENERATOR:_generator(o)->Mark(chain);break;
|
||||
case OT_THREAD:_thread(o)->Mark(chain);break;
|
||||
case OT_CLASS:_class(o)->Mark(chain);break;
|
||||
case OT_INSTANCE:_instance(o)->Mark(chain);break;
|
||||
default: break; //shutup compiler
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SQInteger SQSharedState::CollectGarbage(SQVM *vm)
|
||||
{
|
||||
Assert( _gc_disableDepth >=0 );
|
||||
if ( _gc_disableDepth > 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
SQInteger n=0;
|
||||
SQCollectable *tchain=NULL;
|
||||
SQVM *vms = _thread(_root_vm);
|
||||
|
||||
vms->Mark(&tchain);
|
||||
SQInteger x = _table(_thread(_root_vm)->_roottable)->CountUsed();
|
||||
_refs_table.Mark(&tchain);
|
||||
MarkObject(_registry,&tchain);
|
||||
MarkObject(_consts,&tchain);
|
||||
MarkObject(_metamethodsmap,&tchain);
|
||||
MarkObject(_table_default_delegate,&tchain);
|
||||
MarkObject(_array_default_delegate,&tchain);
|
||||
MarkObject(_string_default_delegate,&tchain);
|
||||
MarkObject(_number_default_delegate,&tchain);
|
||||
MarkObject(_generator_default_delegate,&tchain);
|
||||
MarkObject(_thread_default_delegate,&tchain);
|
||||
MarkObject(_closure_default_delegate,&tchain);
|
||||
MarkObject(_class_default_delegate,&tchain);
|
||||
MarkObject(_instance_default_delegate,&tchain);
|
||||
MarkObject(_weakref_default_delegate,&tchain);
|
||||
|
||||
SQCollectable *t = _gc_chain;
|
||||
SQCollectable *nx = NULL;
|
||||
while(t) {
|
||||
SQ_VALIDATE_REF_COUNT( t );
|
||||
t->_uiRef++;
|
||||
t->Finalize();
|
||||
nx = t->_next;
|
||||
if(--t->_uiRef <= 0)
|
||||
{
|
||||
SQ_VALIDATE_REF_COUNT( t );
|
||||
t->Release();
|
||||
}
|
||||
t = nx;
|
||||
n++;
|
||||
}
|
||||
|
||||
t = tchain;
|
||||
while(t) {
|
||||
t->UnMark();
|
||||
t = t->_next;
|
||||
}
|
||||
_gc_chain = tchain;
|
||||
SQInteger z = _table(_thread(_root_vm)->_roottable)->CountUsed();
|
||||
Assert(z == x);
|
||||
return n;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef NO_GARBAGE_COLLECTOR
|
||||
void SQCollectable::AddToChain(SQCollectable **chain,SQCollectable *c)
|
||||
{
|
||||
c->_prev = NULL;
|
||||
c->_next = *chain;
|
||||
if(*chain) (*chain)->_prev = c;
|
||||
*chain = c;
|
||||
}
|
||||
|
||||
void SQCollectable::RemoveFromChain(SQCollectable **chain,SQCollectable *c)
|
||||
{
|
||||
if(c->_prev) c->_prev->_next = c->_next;
|
||||
else *chain = c->_next;
|
||||
if(c->_next)
|
||||
c->_next->_prev = c->_prev;
|
||||
c->_next = NULL;
|
||||
c->_prev = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
SQChar* SQSharedState::GetScratchPad(SQInteger size)
|
||||
{
|
||||
SQInteger newsize;
|
||||
if(size>0) {
|
||||
if(_scratchpadsize < size) {
|
||||
newsize = size + (size>>1);
|
||||
_scratchpad = (SQChar *)SQ_REALLOC(_scratchpad,_scratchpadsize,newsize);
|
||||
_scratchpadsize = newsize;
|
||||
|
||||
}else if(_scratchpadsize >= (size<<5)) {
|
||||
newsize = _scratchpadsize >> 1;
|
||||
_scratchpad = (SQChar *)SQ_REALLOC(_scratchpad,_scratchpadsize,newsize);
|
||||
_scratchpadsize = newsize;
|
||||
}
|
||||
}
|
||||
return _scratchpad;
|
||||
}
|
||||
|
||||
RefTable::RefTable()
|
||||
{
|
||||
AllocNodes(4);
|
||||
}
|
||||
|
||||
void RefTable::Finalize()
|
||||
{
|
||||
RefNode *nodes = _nodes;
|
||||
for(SQUnsignedInteger n = 0; n < _numofslots; n++) {
|
||||
nodes->obj = _null_;
|
||||
nodes++;
|
||||
}
|
||||
}
|
||||
|
||||
RefTable::~RefTable()
|
||||
{
|
||||
SQ_FREE(_buckets,(_numofslots * sizeof(RefNode *)) + (_numofslots * sizeof(RefNode)));
|
||||
}
|
||||
|
||||
#ifndef NO_GARBAGE_COLLECTOR
|
||||
void RefTable::Mark(SQCollectable **chain)
|
||||
{
|
||||
RefNode *nodes = (RefNode *)_nodes;
|
||||
for(SQUnsignedInteger n = 0; n < _numofslots; n++) {
|
||||
if(type(nodes->obj) != OT_NULL) {
|
||||
SQSharedState::MarkObject(nodes->obj,chain);
|
||||
}
|
||||
nodes++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void RefTable::AddRef(SQObject &obj)
|
||||
{
|
||||
SQHash mainpos;
|
||||
RefNode *prev;
|
||||
RefNode *ref = Get(obj,mainpos,&prev,true);
|
||||
ref->refs++;
|
||||
}
|
||||
|
||||
SQBool RefTable::Release(SQObject &obj)
|
||||
{
|
||||
SQHash mainpos;
|
||||
RefNode *prev;
|
||||
RefNode *ref = Get(obj,mainpos,&prev,false);
|
||||
if(ref) {
|
||||
if(--ref->refs == 0) {
|
||||
SQObjectPtr o = ref->obj;
|
||||
if(prev) {
|
||||
prev->next = ref->next;
|
||||
}
|
||||
else {
|
||||
_buckets[mainpos] = ref->next;
|
||||
}
|
||||
ref->next = _freelist;
|
||||
_freelist = ref;
|
||||
_slotused--;
|
||||
ref->obj = _null_;
|
||||
//<<FIXME>>test for shrink?
|
||||
return SQTrue;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Assert(0);
|
||||
}
|
||||
return SQFalse;
|
||||
}
|
||||
|
||||
void RefTable::Resize(SQUnsignedInteger size)
|
||||
{
|
||||
RefNode **oldbucks = _buckets;
|
||||
RefNode *t = _nodes;
|
||||
SQUnsignedInteger oldnumofslots = _numofslots;
|
||||
AllocNodes(size);
|
||||
//rehash
|
||||
SQUnsignedInteger nfound = 0;
|
||||
for(SQUnsignedInteger n = 0; n < oldnumofslots; n++) {
|
||||
if(type(t->obj) != OT_NULL) {
|
||||
//add back;
|
||||
Assert(t->refs != 0);
|
||||
RefNode *nn = Add(::HashObj(t->obj)&(_numofslots-1),t->obj);
|
||||
nn->refs = t->refs;
|
||||
t->obj = _null_;
|
||||
nfound++;
|
||||
}
|
||||
t++;
|
||||
}
|
||||
Assert(nfound == oldnumofslots);
|
||||
SQ_FREE(oldbucks,(oldnumofslots * sizeof(RefNode *)) + (oldnumofslots * sizeof(RefNode)));
|
||||
}
|
||||
|
||||
RefTable::RefNode *RefTable::Add(SQHash mainpos,SQObject &obj)
|
||||
{
|
||||
RefNode *t = _buckets[mainpos];
|
||||
RefNode *newnode = _freelist;
|
||||
newnode->obj = obj;
|
||||
_buckets[mainpos] = newnode;
|
||||
_freelist = _freelist->next;
|
||||
newnode->next = t;
|
||||
Assert(newnode->refs == 0);
|
||||
_slotused++;
|
||||
return newnode;
|
||||
}
|
||||
|
||||
RefTable::RefNode *RefTable::Get(SQObject &obj,SQHash &mainpos,RefNode **prev,bool add)
|
||||
{
|
||||
RefNode *ref;
|
||||
mainpos = ::HashObj(obj)&(_numofslots-1);
|
||||
*prev = NULL;
|
||||
for (ref = _buckets[mainpos]; ref; ) {
|
||||
if(_rawval(ref->obj) == _rawval(obj) && type(ref->obj) == type(obj))
|
||||
break;
|
||||
*prev = ref;
|
||||
ref = ref->next;
|
||||
}
|
||||
if(ref == NULL && add) {
|
||||
if(_numofslots == _slotused) {
|
||||
Assert(_freelist == 0);
|
||||
Resize(_numofslots*2);
|
||||
mainpos = ::HashObj(obj)&(_numofslots-1);
|
||||
}
|
||||
ref = Add(mainpos,obj);
|
||||
}
|
||||
return ref;
|
||||
}
|
||||
|
||||
void RefTable::AllocNodes(SQUnsignedInteger size)
|
||||
{
|
||||
RefNode **bucks;
|
||||
RefNode *nodes;
|
||||
bucks = (RefNode **)SQ_MALLOC((size * sizeof(RefNode *)) + (size * sizeof(RefNode)));
|
||||
nodes = (RefNode *)&bucks[size];
|
||||
RefNode *temp = nodes;
|
||||
SQUnsignedInteger n;
|
||||
for(n = 0; n < size - 1; n++) {
|
||||
bucks[n] = NULL;
|
||||
temp->refs = 0;
|
||||
new (&temp->obj) SQObjectPtr;
|
||||
temp->next = temp+1;
|
||||
temp++;
|
||||
}
|
||||
bucks[n] = NULL;
|
||||
temp->refs = 0;
|
||||
new (&temp->obj) SQObjectPtr;
|
||||
temp->next = NULL;
|
||||
_freelist = nodes;
|
||||
_nodes = nodes;
|
||||
_buckets = bucks;
|
||||
_slotused = 0;
|
||||
_numofslots = size;
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//StringTable
|
||||
/*
|
||||
* The following code is based on Lua 4.0 (Copyright 1994-2002 Tecgraf, PUC-Rio.)
|
||||
* http://www.lua.org/copyright.html#4
|
||||
* http://www.lua.org/source/4.0.1/src_lstring.c.html
|
||||
*/
|
||||
|
||||
StringTable::StringTable()
|
||||
{
|
||||
AllocNodes(4);
|
||||
_slotused = 0;
|
||||
}
|
||||
|
||||
StringTable::~StringTable()
|
||||
{
|
||||
SQ_FREE(_strings,sizeof(SQString*)*_numofslots);
|
||||
_strings = NULL;
|
||||
}
|
||||
|
||||
void StringTable::AllocNodes(SQInteger size)
|
||||
{
|
||||
_numofslots = size;
|
||||
_strings = (SQString**)SQ_MALLOC(sizeof(SQString*)*_numofslots);
|
||||
memset(_strings,0,sizeof(SQString*)*_numofslots);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_SQSTRING_LEAKS
|
||||
bool g_bDumpSQStrings;
|
||||
#endif
|
||||
|
||||
SQString *StringTable::Add(const SQChar *news,SQInteger len)
|
||||
{
|
||||
if(len<0)
|
||||
len = (SQInteger)scstrlen(news);
|
||||
SQHash h = ::_hashstr(news,len)&(_numofslots-1);
|
||||
SQString *s;
|
||||
for (s = _strings[h]; s; s = s->_next){
|
||||
if(s->_len == len && (!memcmp(news,s->_val,rsl(len))))
|
||||
return s; //found
|
||||
}
|
||||
|
||||
SQString *t=(SQString *)SQ_MALLOC(rsl(len)+sizeof(SQString));
|
||||
new (t) SQString;
|
||||
memcpy(t->_val,news,rsl(len));
|
||||
t->_val[len] = _SC('\0');
|
||||
t->_len = len;
|
||||
t->_hash = ::_hashstr(news,len);
|
||||
t->_next = _strings[h];
|
||||
_strings[h] = t;
|
||||
_slotused++;
|
||||
if (_slotused > _numofslots) /* too crowded? */
|
||||
Resize(_numofslots*2);
|
||||
|
||||
#ifdef DEBUG_SQSTRING_LEAKS
|
||||
if ( g_bDumpSQStrings )
|
||||
{
|
||||
g_bDumpSQStrings = false;
|
||||
CUtlDict< CCopyableUtlVector<SQString *>, int > sorter;
|
||||
Msg( "{\n");
|
||||
for (SQInteger i=0; i<(int)_numofslots; i++){
|
||||
SQString *p = _strings[i];
|
||||
while(p){
|
||||
int i = sorter.Find( p->_val );
|
||||
if ( i == -1 )
|
||||
{
|
||||
i = sorter.Insert( p->_val );
|
||||
}
|
||||
sorter[i].AddToTail( p );
|
||||
SQString *next = p->_next;
|
||||
p = next;
|
||||
}
|
||||
}
|
||||
int ii = sorter.First();
|
||||
while ( ii != -1 )
|
||||
{
|
||||
for ( int j = 0; j < sorter[ii].Count(); j++ )
|
||||
{
|
||||
Msg( "0x%x/%2d: %s\n", sorter[ii][j], sorter[ii][j]->_uiRef, sorter[ii][j]->_val );
|
||||
}
|
||||
ii = sorter.Next( ii );
|
||||
}
|
||||
Msg( "}\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
void StringTable::Resize(SQInteger size)
|
||||
{
|
||||
SQInteger oldsize=_numofslots;
|
||||
SQString **oldtable=_strings;
|
||||
AllocNodes(size);
|
||||
for (SQInteger i=0; i<oldsize; i++){
|
||||
SQString *p = oldtable[i];
|
||||
while(p){
|
||||
SQString *next = p->_next;
|
||||
SQHash h = p->_hash&(_numofslots-1);
|
||||
p->_next = _strings[h];
|
||||
_strings[h] = p;
|
||||
p = next;
|
||||
}
|
||||
}
|
||||
SQ_FREE(oldtable,oldsize*sizeof(SQString*));
|
||||
}
|
||||
|
||||
void StringTable::Remove(SQString *bs)
|
||||
{
|
||||
SQString *s;
|
||||
SQString *prev=NULL;
|
||||
SQHash h = bs->_hash&(_numofslots - 1);
|
||||
|
||||
for (s = _strings[h]; s; ){
|
||||
if(s == bs){
|
||||
if(prev)
|
||||
prev->_next = s->_next;
|
||||
else
|
||||
_strings[h] = s->_next;
|
||||
_slotused--;
|
||||
SQInteger slen = s->_len;
|
||||
s->~SQString();
|
||||
SQ_FREE(s,sizeof(SQString) + rsl(slen));
|
||||
return;
|
||||
}
|
||||
prev = s;
|
||||
s = s->_next;
|
||||
}
|
||||
Assert(0);//if this fail something is wrong
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#ifndef _SQSTATE_H_
|
||||
#define _SQSTATE_H_
|
||||
|
||||
#include "squtils.h"
|
||||
#include "sqobject.h"
|
||||
struct SQString;
|
||||
struct SQTable;
|
||||
//max number of character for a printed number
|
||||
#define NUMBER_MAX_CHAR 50
|
||||
|
||||
struct StringTable
|
||||
{
|
||||
StringTable();
|
||||
~StringTable();
|
||||
SQString *Add(const SQChar *,SQInteger len);
|
||||
void Remove(SQString *);
|
||||
private:
|
||||
void Resize(SQInteger size);
|
||||
void AllocNodes(SQInteger size);
|
||||
SQString **_strings;
|
||||
SQUnsignedInteger _numofslots;
|
||||
SQUnsignedInteger _slotused;
|
||||
};
|
||||
|
||||
struct RefTable {
|
||||
struct RefNode {
|
||||
SQObjectPtr obj;
|
||||
SQUnsignedInteger refs;
|
||||
struct RefNode *next;
|
||||
};
|
||||
RefTable();
|
||||
~RefTable();
|
||||
void AddRef(SQObject &obj);
|
||||
SQBool Release(SQObject &obj);
|
||||
#ifndef NO_GARBAGE_COLLECTOR
|
||||
void Mark(SQCollectable **chain);
|
||||
#endif
|
||||
void Iterate( CSQStateIterator *pIterator );
|
||||
|
||||
void Finalize();
|
||||
private:
|
||||
RefNode *Get(SQObject &obj,SQHash &mainpos,RefNode **prev,bool add);
|
||||
RefNode *Add(SQHash mainpos,SQObject &obj);
|
||||
void Resize(SQUnsignedInteger size);
|
||||
void AllocNodes(SQUnsignedInteger size);
|
||||
SQUnsignedInteger _numofslots;
|
||||
SQUnsignedInteger _slotused;
|
||||
RefNode *_nodes;
|
||||
RefNode *_freelist;
|
||||
RefNode **_buckets;
|
||||
};
|
||||
|
||||
#define ADD_STRING(ss,str,len) ss->_stringtable->Add(str,len)
|
||||
#define REMOVE_STRING(ss,bstr) ss->_stringtable->Remove(bstr)
|
||||
|
||||
struct SQObjectPtr;
|
||||
|
||||
class CSQStateIterator
|
||||
{
|
||||
public:
|
||||
// Simple objects
|
||||
virtual void PsuedoKey( const char *pszPsuedoKey ) = 0;
|
||||
virtual void Key( SQObjectPtr &key ) = 0;
|
||||
virtual void Value( SQObjectPtr &value ) = 0;
|
||||
|
||||
virtual bool BeginContained() = 0;
|
||||
virtual void EndContained() = 0;
|
||||
};
|
||||
|
||||
struct SQSharedState
|
||||
{
|
||||
SQSharedState();
|
||||
~SQSharedState();
|
||||
void Init();
|
||||
public:
|
||||
SQChar* GetScratchPad(SQInteger size);
|
||||
SQInteger GetMetaMethodIdxByName(const SQObjectPtr &name);
|
||||
#ifndef NO_GARBAGE_COLLECTOR
|
||||
SQInteger CollectGarbage(SQVM *vm);
|
||||
static void MarkObject(SQObjectPtr &o,SQCollectable **chain);
|
||||
#endif
|
||||
|
||||
void Iterate( SQVM *vm, CSQStateIterator *pIterator );
|
||||
static void IterateObject( CSQStateIterator *pIterator, SQObjectPtr &value, const char *pszName = NULL );
|
||||
|
||||
SQObjectPtrVec *_metamethods;
|
||||
SQObjectPtr _metamethodsmap;
|
||||
SQObjectPtrVec *_systemstrings;
|
||||
SQObjectPtrVec *_types;
|
||||
StringTable *_stringtable;
|
||||
RefTable _refs_table;
|
||||
SQObjectPtr _registry;
|
||||
SQObjectPtr _consts;
|
||||
SQObjectPtr _constructoridx;
|
||||
#ifndef NO_GARBAGE_COLLECTOR
|
||||
SQCollectable *_gc_chain;
|
||||
#endif
|
||||
SQObjectPtr _root_vm;
|
||||
SQObjectPtr _table_default_delegate;
|
||||
static SQRegFunction _table_default_delegate_funcz[];
|
||||
SQObjectPtr _array_default_delegate;
|
||||
static SQRegFunction _array_default_delegate_funcz[];
|
||||
SQObjectPtr _string_default_delegate;
|
||||
static SQRegFunction _string_default_delegate_funcz[];
|
||||
SQObjectPtr _number_default_delegate;
|
||||
static SQRegFunction _number_default_delegate_funcz[];
|
||||
SQObjectPtr _generator_default_delegate;
|
||||
static SQRegFunction _generator_default_delegate_funcz[];
|
||||
SQObjectPtr _closure_default_delegate;
|
||||
static SQRegFunction _closure_default_delegate_funcz[];
|
||||
SQObjectPtr _thread_default_delegate;
|
||||
static SQRegFunction _thread_default_delegate_funcz[];
|
||||
SQObjectPtr _class_default_delegate;
|
||||
static SQRegFunction _class_default_delegate_funcz[];
|
||||
SQObjectPtr _instance_default_delegate;
|
||||
static SQRegFunction _instance_default_delegate_funcz[];
|
||||
SQObjectPtr _weakref_default_delegate;
|
||||
static SQRegFunction _weakref_default_delegate_funcz[];
|
||||
|
||||
SQCOMPILERERROR _compilererrorhandler;
|
||||
SQPRINTFUNCTION _printfunc;
|
||||
bool _debuginfo;
|
||||
bool _notifyallexceptions;
|
||||
void *m_pOwnerData;
|
||||
|
||||
int _gc_disableDepth;
|
||||
private:
|
||||
SQChar *_scratchpad;
|
||||
SQInteger _scratchpadsize;
|
||||
};
|
||||
|
||||
#define _sp(s) (_sharedstate->GetScratchPad(s))
|
||||
#define _spval (_sharedstate->GetScratchPad(-1))
|
||||
|
||||
#define _table_ddel _table(_sharedstate->_table_default_delegate)
|
||||
#define _array_ddel _table(_sharedstate->_array_default_delegate)
|
||||
#define _string_ddel _table(_sharedstate->_string_default_delegate)
|
||||
#define _number_ddel _table(_sharedstate->_number_default_delegate)
|
||||
#define _generator_ddel _table(_sharedstate->_generator_default_delegate)
|
||||
#define _closure_ddel _table(_sharedstate->_closure_default_delegate)
|
||||
#define _thread_ddel _table(_sharedstate->_thread_default_delegate)
|
||||
#define _class_ddel _table(_sharedstate->_class_default_delegate)
|
||||
#define _instance_ddel _table(_sharedstate->_instance_default_delegate)
|
||||
#define _weakref_ddel _table(_sharedstate->_weakref_default_delegate)
|
||||
|
||||
#ifdef SQUNICODE //rsl REAL STRING LEN
|
||||
#define rsl(l) ((l)<<1)
|
||||
#else
|
||||
#define rsl(l) (l)
|
||||
#endif
|
||||
|
||||
extern SQObjectPtr _null_;
|
||||
extern SQObjectPtr _true_;
|
||||
extern SQObjectPtr _false_;
|
||||
extern SQObjectPtr _one_;
|
||||
extern SQObjectPtr _minusone_;
|
||||
|
||||
bool CompileTypemask(SQIntVec &res,const SQChar *typemask);
|
||||
|
||||
#if defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST)
|
||||
#ifndef sq_vm_malloc
|
||||
#define sq_vm_malloc malloc
|
||||
#define sq_vm_realloc(p,oldsize,size) realloc(p, size)
|
||||
#define sq_vm_free(p,size) free(p)
|
||||
#endif
|
||||
#else
|
||||
void *sq_vm_malloc(SQUnsignedInteger size);
|
||||
void *sq_vm_realloc(void *p,SQUnsignedInteger oldsize,SQUnsignedInteger size);
|
||||
void sq_vm_free(void *p,SQUnsignedInteger size);
|
||||
#endif
|
||||
#endif //_SQSTATE_H_
|
||||
@@ -0,0 +1,31 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#ifndef _SQSTRING_H_
|
||||
#define _SQSTRING_H_
|
||||
|
||||
inline SQHash _hashstr (const SQChar *s, size_t l)
|
||||
{
|
||||
SQHash h = (SQHash)l; /* seed */
|
||||
size_t step = (l>>5)|1; /* if string is too long, don't hash all its chars */
|
||||
for (; l>=step; l-=step)
|
||||
h = h ^ ((h<<5)+(h>>2)+(unsigned short)*(s++));
|
||||
return h;
|
||||
}
|
||||
|
||||
struct SQString : public SQRefCounted
|
||||
{
|
||||
SQString(){}
|
||||
~SQString(){}
|
||||
public:
|
||||
static SQString *Create(SQSharedState *ss, const SQChar *, SQInteger len = -1 );
|
||||
SQInteger Next(const SQObjectPtr &refpos, SQObjectPtr &outkey, SQObjectPtr &outval);
|
||||
void Release();
|
||||
SQSharedState *_sharedstate;
|
||||
SQString *_next; //chain for the string table
|
||||
SQInteger _len;
|
||||
SQHash _hash;
|
||||
SQChar _val[1];
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //_SQSTRING_H_
|
||||
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
#include "sqpcheader.h"
|
||||
#include "sqvm.h"
|
||||
#include "sqtable.h"
|
||||
#include "sqfuncproto.h"
|
||||
#include "sqclosure.h"
|
||||
#if defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST)
|
||||
#include "memdbgon.h"
|
||||
#undef new // allow placement new
|
||||
#endif
|
||||
|
||||
SQTable::SQTable(SQSharedState *ss,SQInteger nInitialSize)
|
||||
{
|
||||
SQInteger pow2size=MINPOWER2;
|
||||
while(nInitialSize>pow2size)pow2size=pow2size<<1;
|
||||
AllocNodes(pow2size);
|
||||
_usednodes = 0;
|
||||
_delegate = NULL;
|
||||
INIT_CHAIN();
|
||||
ADD_TO_CHAIN(&_sharedstate->_gc_chain,this);
|
||||
}
|
||||
|
||||
void SQTable::Remove(const SQObjectPtr &key)
|
||||
{
|
||||
|
||||
_HashNode *n = _Get(key, HashObj(key) & (_numofnodes - 1));
|
||||
if (n) {
|
||||
n->val = n->key = _null_;
|
||||
_usednodes--;
|
||||
Rehash(false);
|
||||
}
|
||||
}
|
||||
|
||||
void SQTable::AllocNodes(SQInteger nSize)
|
||||
{
|
||||
_HashNode *nodes=(_HashNode *)SQ_MALLOC(sizeof(_HashNode)*nSize);
|
||||
for(SQInteger i=0;i<nSize;i++){
|
||||
new (&nodes[i]) _HashNode;
|
||||
nodes[i].next=NULL;
|
||||
}
|
||||
_numofnodes=nSize;
|
||||
_nodes=nodes;
|
||||
_firstfree=&_nodes[_numofnodes-1];
|
||||
}
|
||||
|
||||
void SQTable::Rehash(bool force)
|
||||
{
|
||||
SQInteger realoldsize=_numofnodes;
|
||||
SQInteger oldsize=(realoldsize<4)?4:realoldsize;
|
||||
//prevent problems with the integer division
|
||||
if(oldsize<4)oldsize=4;
|
||||
_HashNode *nold=_nodes;
|
||||
SQInteger nelems=CountUsed();
|
||||
if (nelems >= oldsize-oldsize/4) /* using more than 3/4? */
|
||||
AllocNodes(oldsize*2);
|
||||
else if (nelems <= oldsize/4 && /* less than 1/4? */
|
||||
oldsize > MINPOWER2)
|
||||
AllocNodes(oldsize/2);
|
||||
else if(force)
|
||||
AllocNodes(oldsize);
|
||||
else
|
||||
return;
|
||||
_usednodes = 0;
|
||||
for (SQInteger i=0; i<realoldsize; i++) {
|
||||
_HashNode *old = nold+i;
|
||||
if (type(old->key) != OT_NULL)
|
||||
NewSlot(old->key,old->val);
|
||||
}
|
||||
for(SQInteger k=0;k<realoldsize;k++)
|
||||
nold[k].~_HashNode();
|
||||
SQ_FREE(nold,realoldsize*sizeof(_HashNode));
|
||||
}
|
||||
|
||||
SQTable *SQTable::Clone()
|
||||
{
|
||||
SQTable *nt=Create(_opt_ss(this),_numofnodes);
|
||||
SQInteger ridx=0;
|
||||
SQObjectPtr key,val;
|
||||
while((ridx=Next(true,ridx,key,val))!=-1){
|
||||
nt->NewSlot(key,val);
|
||||
}
|
||||
nt->SetDelegate(_delegate);
|
||||
return nt;
|
||||
}
|
||||
|
||||
bool SQTable::Get(const SQObjectPtr &key,SQObjectPtr &val)
|
||||
{
|
||||
if(type(key) == OT_NULL)
|
||||
return false;
|
||||
_HashNode *n = _Get(key, HashObj(key) & (_numofnodes - 1));
|
||||
if (n) {
|
||||
val = _realval(n->val);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool SQTable::NewSlot(const SQObjectPtr &key,const SQObjectPtr &val)
|
||||
{
|
||||
Assert(type(key) != OT_NULL);
|
||||
SQHash h = HashObj(key) & (_numofnodes - 1);
|
||||
_HashNode *n = _Get(key, h);
|
||||
if (n) {
|
||||
n->val = val;
|
||||
return false;
|
||||
}
|
||||
_HashNode *mp = &_nodes[h];
|
||||
n = mp;
|
||||
|
||||
|
||||
//key not found I'll insert it
|
||||
//main pos is not free
|
||||
|
||||
if(type(mp->key) != OT_NULL) {
|
||||
n = _firstfree; /* get a free place */
|
||||
SQHash mph = HashObj(mp->key) & (_numofnodes - 1);
|
||||
_HashNode *othern; /* main position of colliding node */
|
||||
|
||||
if (mp > n && (othern = &_nodes[mph]) != mp){
|
||||
/* yes; move colliding node into free position */
|
||||
while (othern->next != mp){
|
||||
Assert(othern->next != NULL);
|
||||
othern = othern->next; /* find previous */
|
||||
}
|
||||
othern->next = n; /* redo the chain with `n' in place of `mp' */
|
||||
n->key = mp->key;
|
||||
n->val = mp->val;/* copy colliding node into free pos. (mp->next also goes) */
|
||||
n->next = mp->next;
|
||||
mp->key = _null_;
|
||||
mp->val = _null_;
|
||||
mp->next = NULL; /* now `mp' is free */
|
||||
}
|
||||
else{
|
||||
/* new node will go into free position */
|
||||
n->next = mp->next; /* chain new position */
|
||||
mp->next = n;
|
||||
mp = n;
|
||||
}
|
||||
}
|
||||
mp->key = key;
|
||||
|
||||
for (;;) { /* correct `firstfree' */
|
||||
if (type(_firstfree->key) == OT_NULL && _firstfree->next == NULL) {
|
||||
mp->val = val;
|
||||
_usednodes++;
|
||||
return true; /* OK; table still has a free place */
|
||||
}
|
||||
else if (_firstfree == _nodes) break; /* cannot decrement from here */
|
||||
else (_firstfree)--;
|
||||
}
|
||||
Rehash(true);
|
||||
return NewSlot(key, val);
|
||||
}
|
||||
|
||||
SQInteger SQTable::Next(bool getweakrefs,const SQObjectPtr &refpos, SQObjectPtr &outkey, SQObjectPtr &outval)
|
||||
{
|
||||
SQInteger idx = (SQInteger)TranslateIndex(refpos);
|
||||
while (idx < _numofnodes) {
|
||||
if(type(_nodes[idx].key) != OT_NULL) {
|
||||
//first found
|
||||
_HashNode &n = _nodes[idx];
|
||||
outkey = n.key;
|
||||
outval = getweakrefs?(SQObject)n.val:_realval(n.val);
|
||||
//return idx for the next iteration
|
||||
return ++idx;
|
||||
}
|
||||
++idx;
|
||||
}
|
||||
//nothing to iterate anymore
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
bool SQTable::Set(const SQObjectPtr &key, const SQObjectPtr &val)
|
||||
{
|
||||
_HashNode *n = _Get(key, HashObj(key) & (_numofnodes - 1));
|
||||
if (n) {
|
||||
n->val = val;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void SQTable::_ClearNodes()
|
||||
{
|
||||
for(SQInteger i = 0;i < _numofnodes; i++) { _nodes[i].key = _null_; _nodes[i].val = _null_; }
|
||||
}
|
||||
|
||||
void SQTable::Finalize()
|
||||
{
|
||||
_ClearNodes();
|
||||
SetDelegate(NULL);
|
||||
}
|
||||
|
||||
void SQTable::Clear()
|
||||
{
|
||||
_ClearNodes();
|
||||
_usednodes = 0;
|
||||
Rehash(true);
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#ifndef _SQTABLE_H_
|
||||
#define _SQTABLE_H_
|
||||
/*
|
||||
* The following code is based on Lua 4.0 (Copyright 1994-2002 Tecgraf, PUC-Rio.)
|
||||
* http://www.lua.org/copyright.html#4
|
||||
* http://www.lua.org/source/4.0.1/src_ltable.c.html
|
||||
*/
|
||||
|
||||
#include "sqstring.h"
|
||||
|
||||
#if defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST)
|
||||
#include "memdbgon.h"
|
||||
#undef new // allow placement new
|
||||
#endif
|
||||
|
||||
#define hashptr(p) ((SQHash)(((SQInteger)((intp)p)) >> 3))
|
||||
|
||||
inline SQHash HashObj(const SQObjectPtr &key)
|
||||
{
|
||||
switch(type(key)) {
|
||||
case OT_STRING: return _string(key)->_hash;
|
||||
case OT_FLOAT: return (SQHash)((SQInteger)_float(key));
|
||||
case OT_BOOL: case OT_INTEGER: return (SQHash)((SQInteger)_integer(key));
|
||||
default: return hashptr(key._unVal.pRefCounted);
|
||||
}
|
||||
}
|
||||
|
||||
struct SQTable : public SQDelegable
|
||||
{
|
||||
friend class CSquirrelVM;
|
||||
private:
|
||||
struct _HashNode
|
||||
{
|
||||
_HashNode() { next = NULL; }
|
||||
SQObjectPtr val;
|
||||
SQObjectPtr key;
|
||||
_HashNode *next;
|
||||
};
|
||||
_HashNode *_firstfree;
|
||||
_HashNode *_nodes;
|
||||
SQInteger _numofnodes;
|
||||
SQInteger _usednodes;
|
||||
|
||||
///////////////////////////
|
||||
void AllocNodes(SQInteger nSize);
|
||||
void Rehash(bool force);
|
||||
SQTable(SQSharedState *ss, SQInteger nInitialSize);
|
||||
void _ClearNodes();
|
||||
public:
|
||||
static SQTable* Create(SQSharedState *ss,SQInteger nInitialSize)
|
||||
{
|
||||
SQTable *newtable = (SQTable*)SQ_MALLOC(sizeof(SQTable));
|
||||
new (newtable) SQTable(ss, nInitialSize);
|
||||
newtable->_delegate = NULL;
|
||||
return newtable;
|
||||
}
|
||||
void Finalize();
|
||||
SQTable *Clone();
|
||||
~SQTable()
|
||||
{
|
||||
SetDelegate(NULL);
|
||||
REMOVE_FROM_CHAIN(&_sharedstate->_gc_chain, this);
|
||||
for (SQInteger i = 0; i < _numofnodes; i++) _nodes[i].~_HashNode();
|
||||
SQ_FREE(_nodes, _numofnodes * sizeof(_HashNode));
|
||||
}
|
||||
#ifndef NO_GARBAGE_COLLECTOR
|
||||
void Mark(SQCollectable **chain);
|
||||
#endif
|
||||
void Iterate( CSQStateIterator *pIterator );
|
||||
|
||||
inline _HashNode *_Get(const SQObjectPtr &key,SQHash hash)
|
||||
{
|
||||
_HashNode *n = &_nodes[hash];
|
||||
do{
|
||||
if(_rawval(n->key) == _rawval(key) && type(n->key) == type(key)){
|
||||
return n;
|
||||
}
|
||||
}while((n = n->next));
|
||||
return NULL;
|
||||
}
|
||||
bool Get(const SQObjectPtr &key,SQObjectPtr &val);
|
||||
void Remove(const SQObjectPtr &key);
|
||||
bool Set(const SQObjectPtr &key, const SQObjectPtr &val);
|
||||
//returns true if a new slot has been created false if it was already present
|
||||
bool NewSlot(const SQObjectPtr &key,const SQObjectPtr &val);
|
||||
SQInteger Next(bool getweakrefs,const SQObjectPtr &refpos, SQObjectPtr &outkey, SQObjectPtr &outval);
|
||||
|
||||
SQInteger CountUsed(){ return _usednodes;}
|
||||
void Clear();
|
||||
void Release()
|
||||
{
|
||||
sq_delete(this, SQTable);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#if defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST)
|
||||
#include "memdbgoff.h"
|
||||
#endif
|
||||
|
||||
#endif //_SQTABLE_H_
|
||||
@@ -0,0 +1,324 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE CodeBlocks_project_file>
|
||||
<CodeBlocks_project_file>
|
||||
<FileVersion major="1" minor="1"/>
|
||||
<Project>
|
||||
<Option title="squirrel"/>
|
||||
<Option makefile="Makefile"/>
|
||||
<Option makefile_is_custom="0"/>
|
||||
<Option default_target="-1"/>
|
||||
<Option compiler="0"/>
|
||||
<Build>
|
||||
<Target title="Debug">
|
||||
<Option output="..\lib\libsquirrelD.a"/>
|
||||
<Option working_dir=""/>
|
||||
<Option object_output="Debug"/>
|
||||
<Option deps_output=".deps"/>
|
||||
<Option type="2"/>
|
||||
<Option compiler="0"/>
|
||||
<Option createDefFile="1"/>
|
||||
<Option projectResourceIncludeDirsRelation="2"/>
|
||||
<Compiler>
|
||||
<Add option="-DWIN32"/>
|
||||
<Add option="-D_DEBUG"/>
|
||||
<Add option="-D_LIB"/>
|
||||
<Add option="-DGARBAGE_COLLECTOR"/>
|
||||
<Add option="-D_CRT_SECURE_NO_DEPRECATE"/>
|
||||
<Add option="-W"/>
|
||||
<Add option="-O0"/>
|
||||
<Add directory="..\include"/>
|
||||
</Compiler>
|
||||
</Target>
|
||||
<Target title="Release">
|
||||
<Option output="..\lib\libsquirrel.a"/>
|
||||
<Option working_dir=""/>
|
||||
<Option object_output="Release"/>
|
||||
<Option deps_output=".deps"/>
|
||||
<Option type="2"/>
|
||||
<Option compiler="0"/>
|
||||
<Option createDefFile="1"/>
|
||||
<Option projectResourceIncludeDirsRelation="2"/>
|
||||
<Compiler>
|
||||
<Add option="-DWIN32"/>
|
||||
<Add option="-DNDEBUG"/>
|
||||
<Add option="-D_LIB"/>
|
||||
<Add option="-DGARBAGE_COLLECTOR"/>
|
||||
<Add option="-D_CRT_SECURE_NO_DEPRECATE"/>
|
||||
<Add option="-W"/>
|
||||
<Add option="-O2"/>
|
||||
<Add directory="..\include"/>
|
||||
</Compiler>
|
||||
</Target>
|
||||
<Target title="Debug - Unicode">
|
||||
<Option output="..\lib\libsquirrelDU.a"/>
|
||||
<Option working_dir=""/>
|
||||
<Option object_output="Debug - Unicode"/>
|
||||
<Option deps_output=".deps"/>
|
||||
<Option type="2"/>
|
||||
<Option compiler="0"/>
|
||||
<Option createDefFile="1"/>
|
||||
<Option projectResourceIncludeDirsRelation="2"/>
|
||||
<Compiler>
|
||||
<Add option="-DWIN32"/>
|
||||
<Add option="-D_DEBUG"/>
|
||||
<Add option="-D_LIB"/>
|
||||
<Add option="-DGARBAGE_COLLECTOR"/>
|
||||
<Add option="-D_CRT_SECURE_NO_DEPRECATE"/>
|
||||
<Add option="-D_CRT_NON_CONFORMING_SWPRINTFS"/>
|
||||
<Add option="-W"/>
|
||||
<Add option="-O0"/>
|
||||
<Add directory="..\include"/>
|
||||
</Compiler>
|
||||
</Target>
|
||||
<Target title="Release - Unicode">
|
||||
<Option output="..\lib\libsquirrelU.a"/>
|
||||
<Option working_dir=""/>
|
||||
<Option object_output="Release - Unicode"/>
|
||||
<Option deps_output=".deps"/>
|
||||
<Option type="2"/>
|
||||
<Option compiler="0"/>
|
||||
<Option createDefFile="1"/>
|
||||
<Option projectResourceIncludeDirsRelation="2"/>
|
||||
<Compiler>
|
||||
<Add option="-DWIN32"/>
|
||||
<Add option="-DNDEBUG"/>
|
||||
<Add option="-D_LIB"/>
|
||||
<Add option="-DGARBAGE_COLLECTOR"/>
|
||||
<Add option="-D_CRT_SECURE_NO_DEPRECATE"/>
|
||||
<Add option="-D_CRT_NON_CONFORMING_SWPRINTFS"/>
|
||||
<Add option="-W"/>
|
||||
<Add option="-O2"/>
|
||||
<Add directory="..\include"/>
|
||||
</Compiler>
|
||||
</Target>
|
||||
</Build>
|
||||
<Unit filename="sqapi.cpp">
|
||||
<Option compilerVar="CPP"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
<Unit filename="sqarray.h">
|
||||
<Option compilerVar=""/>
|
||||
<Option compile="0"/>
|
||||
<Option link="0"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
<Unit filename="sqbaselib.cpp">
|
||||
<Option compilerVar="CPP"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
<Unit filename="sqclass.cpp">
|
||||
<Option compilerVar="CPP"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
<Unit filename="sqclass.h">
|
||||
<Option compilerVar=""/>
|
||||
<Option compile="0"/>
|
||||
<Option link="0"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
<Unit filename="sqclosure.h">
|
||||
<Option compilerVar=""/>
|
||||
<Option compile="0"/>
|
||||
<Option link="0"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
<Unit filename="sqcompiler.cpp">
|
||||
<Option compilerVar="CPP"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
<Unit filename="sqcompiler.h">
|
||||
<Option compilerVar=""/>
|
||||
<Option compile="0"/>
|
||||
<Option link="0"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
<Unit filename="sqdebug.cpp">
|
||||
<Option compilerVar="CPP"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
<Unit filename="sqfuncproto.h">
|
||||
<Option compilerVar=""/>
|
||||
<Option compile="0"/>
|
||||
<Option link="0"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
<Unit filename="sqfuncstate.cpp">
|
||||
<Option compilerVar="CPP"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
<Unit filename="sqfuncstate.h">
|
||||
<Option compilerVar=""/>
|
||||
<Option compile="0"/>
|
||||
<Option link="0"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
<Unit filename="sqlexer.cpp">
|
||||
<Option compilerVar="CPP"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
<Unit filename="sqlexer.h">
|
||||
<Option compilerVar=""/>
|
||||
<Option compile="0"/>
|
||||
<Option link="0"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
<Unit filename="sqmem.cpp">
|
||||
<Option compilerVar="CPP"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
<Unit filename="sqobject.cpp">
|
||||
<Option compilerVar="CPP"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
<Unit filename="sqobject.h">
|
||||
<Option compilerVar=""/>
|
||||
<Option compile="0"/>
|
||||
<Option link="0"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
<Unit filename="sqopcodes.h">
|
||||
<Option compilerVar=""/>
|
||||
<Option compile="0"/>
|
||||
<Option link="0"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
<Unit filename="sqpcheader.h">
|
||||
<Option compilerVar=""/>
|
||||
<Option compile="0"/>
|
||||
<Option link="0"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
<Unit filename="sqstate.cpp">
|
||||
<Option compilerVar="CPP"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
<Unit filename="sqstate.h">
|
||||
<Option compilerVar=""/>
|
||||
<Option compile="0"/>
|
||||
<Option link="0"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
<Unit filename="sqstring.h">
|
||||
<Option compilerVar=""/>
|
||||
<Option compile="0"/>
|
||||
<Option link="0"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
<Unit filename="sqtable.cpp">
|
||||
<Option compilerVar="CPP"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
<Unit filename="sqtable.h">
|
||||
<Option compilerVar=""/>
|
||||
<Option compile="0"/>
|
||||
<Option link="0"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
<Unit filename="squserdata.h">
|
||||
<Option compilerVar=""/>
|
||||
<Option compile="0"/>
|
||||
<Option link="0"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
<Unit filename="squtils.h">
|
||||
<Option compilerVar=""/>
|
||||
<Option compile="0"/>
|
||||
<Option link="0"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
<Unit filename="sqvm.cpp">
|
||||
<Option compilerVar="CPP"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
<Unit filename="sqvm.h">
|
||||
<Option compilerVar=""/>
|
||||
<Option compile="0"/>
|
||||
<Option link="0"/>
|
||||
<Option target="Debug"/>
|
||||
<Option target="Release"/>
|
||||
<Option target="Debug - Unicode"/>
|
||||
<Option target="Release - Unicode"/>
|
||||
</Unit>
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
||||
@@ -0,0 +1,971 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Name="squirrel"
|
||||
ProjectGUID="{A79653F2-73F4-4F57-AE86-4AEBDE795232}"
|
||||
RootNamespace="squirrel"
|
||||
SccLocalPath=".."
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="false"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;GARBAGE_COLLECTOR;_CRT_SECURE_NO_DEPRECATE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
UsePrecompiledHeader="0"
|
||||
PrecompiledHeaderFile=".\Debug/squirrel.pch"
|
||||
AssemblerListingLocation="$(IntDir)/"
|
||||
ObjectFile="$(IntDir)/"
|
||||
ProgramDataBaseFileName="$(IntDir)/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="true"
|
||||
DebugInformationFormat="4"
|
||||
CompileAs="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1040"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
OutputFile="..\lib\squirrelD.lib"
|
||||
SuppressStartupBanner="true"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="false"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="..\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;GARBAGE_COLLECTOR;_CRT_SECURE_NO_DEPRECATE"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="0"
|
||||
EnableFunctionLevelLinking="true"
|
||||
UsePrecompiledHeader="0"
|
||||
PrecompiledHeaderFile=".\Release/squirrel.pch"
|
||||
AssemblerListingLocation="$(IntDir)/"
|
||||
ObjectFile="$(IntDir)/"
|
||||
ProgramDataBaseFileName="$(IntDir)/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="true"
|
||||
CompileAs="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1040"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
OutputFile="..\lib\squirrel.lib"
|
||||
SuppressStartupBanner="true"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Debug - Unicode|Win32"
|
||||
OutputDirectory="$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="false"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;GARBAGE_COLLECTOR;_CRT_SECURE_NO_DEPRECATE;_CRT_NON_CONFORMING_SWPRINTFS"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
UsePrecompiledHeader="0"
|
||||
PrecompiledHeaderFile=".\DebugU/squirrel.pch"
|
||||
AssemblerListingLocation="$(IntDir)/"
|
||||
ObjectFile="$(IntDir)/"
|
||||
ProgramDataBaseFileName="$(IntDir)/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="true"
|
||||
DebugInformationFormat="4"
|
||||
CompileAs="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1040"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
OutputFile="..\lib\squirrelDU.lib"
|
||||
SuppressStartupBanner="true"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release - Unicode|Win32"
|
||||
OutputDirectory="$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="false"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="..\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;GARBAGE_COLLECTOR;_CRT_SECURE_NO_DEPRECATE;_CRT_NON_CONFORMING_SWPRINTFS"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="0"
|
||||
EnableFunctionLevelLinking="true"
|
||||
UsePrecompiledHeader="0"
|
||||
PrecompiledHeaderFile=".\Release/squirrel.pch"
|
||||
AssemblerListingLocation="$(IntDir)/"
|
||||
ObjectFile="$(IntDir)/"
|
||||
ProgramDataBaseFileName="$(IntDir)/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="true"
|
||||
CompileAs="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1040"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
OutputFile="..\lib\squirrelU.lib"
|
||||
SuppressStartupBanner="true"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
>
|
||||
<File
|
||||
RelativePath="sqapi.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug - Unicode|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release - Unicode|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqbaselib.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug - Unicode|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release - Unicode|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqclass.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug - Unicode|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release - Unicode|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqcompiler.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug - Unicode|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release - Unicode|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqdebug.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug - Unicode|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release - Unicode|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqfuncstate.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug - Unicode|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release - Unicode|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqlexer.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug - Unicode|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release - Unicode|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqmem.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug - Unicode|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release - Unicode|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqobject.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug - Unicode|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release - Unicode|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqstate.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug - Unicode|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release - Unicode|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqtable.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug - Unicode|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release - Unicode|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqvm.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug - Unicode|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release - Unicode|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl"
|
||||
>
|
||||
<File
|
||||
RelativePath="sqarray.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqclass.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqclosure.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqcompiler.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqfuncproto.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqfuncstate.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqlexer.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqobject.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqopcodes.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqpcheader.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqstate.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqstring.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqtable.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="squserdata.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="squtils.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqvm.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
@@ -0,0 +1,750 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="squirrel"
|
||||
ProjectGUID="{D2EB28F5-6B67-4823-8051-B564EF852CED}"
|
||||
RootNamespace="squirrel"
|
||||
SccProjectName=""
|
||||
SccLocalPath="..">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;GARBAGE_COLLECTOR"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
UsePrecompiledHeader="0"
|
||||
PrecompiledHeaderFile=".\Debug/squirrel.pch"
|
||||
AssemblerListingLocation="$(IntDir)/"
|
||||
ObjectFile="$(IntDir)/"
|
||||
ProgramDataBaseFileName="$(IntDir)/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
DebugInformationFormat="4"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
OutputFile="..\lib\squirrelD.lib"
|
||||
SuppressStartupBanner="TRUE"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1040"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="..\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;GARBAGE_COLLECTOR"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="0"
|
||||
EnableFunctionLevelLinking="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
PrecompiledHeaderFile=".\Release/squirrel.pch"
|
||||
AssemblerListingLocation="$(IntDir)/"
|
||||
ObjectFile="$(IntDir)/"
|
||||
ProgramDataBaseFileName="$(IntDir)/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
OutputFile="..\lib\squirrel.lib"
|
||||
SuppressStartupBanner="TRUE"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1040"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Debug - Unicode|Win32"
|
||||
OutputDirectory="$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="1">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;GARBAGE_COLLECTOR"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
UsePrecompiledHeader="0"
|
||||
PrecompiledHeaderFile=".\DebugU/squirrel.pch"
|
||||
AssemblerListingLocation="$(IntDir)/"
|
||||
ObjectFile="$(IntDir)/"
|
||||
ProgramDataBaseFileName="$(IntDir)/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
DebugInformationFormat="4"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
OutputFile="..\lib\squirrelDU.lib"
|
||||
SuppressStartupBanner="TRUE"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1040"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release - Unicode|Win32"
|
||||
OutputDirectory="$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="1">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="..\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;GARBAGE_COLLECTOR"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="0"
|
||||
EnableFunctionLevelLinking="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
PrecompiledHeaderFile=".\Release/squirrel.pch"
|
||||
AssemblerListingLocation="$(IntDir)/"
|
||||
ObjectFile="$(IntDir)/"
|
||||
ProgramDataBaseFileName="$(IntDir)/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
OutputFile="..\lib\squirrelU.lib"
|
||||
SuppressStartupBanner="TRUE"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1040"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
|
||||
<File
|
||||
RelativePath="sqapi.cpp">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug - Unicode|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release - Unicode|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqbaselib.cpp">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug - Unicode|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release - Unicode|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqclass.cpp">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug - Unicode|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release - Unicode|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqcompiler.cpp">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug - Unicode|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release - Unicode|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqdebug.cpp">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug - Unicode|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release - Unicode|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqfuncstate.cpp">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug - Unicode|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release - Unicode|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqlexer.cpp">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug - Unicode|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release - Unicode|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqmem.cpp">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug - Unicode|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release - Unicode|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqobject.cpp">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug - Unicode|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release - Unicode|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqstate.cpp">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug - Unicode|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release - Unicode|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqtable.cpp">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug - Unicode|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release - Unicode|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqvm.cpp">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug - Unicode|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"
|
||||
PrecompiledHeaderThrough="stdafx.h"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release - Unicode|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl">
|
||||
<File
|
||||
RelativePath="sqarray.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqclass.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqclosure.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqcompiler.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqfuncproto.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqfuncstate.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqlexer.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqobject.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqopcodes.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqpcheader.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqstate.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqstring.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqtable.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="squserdata.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="squtils.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="sqvm.h">
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE CodeBlocks_project_file>
|
||||
<CodeBlocks_project_file>
|
||||
<FileVersion major="1" minor="1"/>
|
||||
<Project>
|
||||
<Option title="Static library"/>
|
||||
<Option makefile="Makefile"/>
|
||||
<Build>
|
||||
<Target title="default">
|
||||
<Option type="2"/>
|
||||
<Option parameters=""/>
|
||||
<Option includeInTargetAll="1"/>
|
||||
<Option projectCompilerOptionsRelation="3"/>
|
||||
<Option projectLinkerOptionsRelation="3"/>
|
||||
<Option projectIncludeDirsRelation="3"/>
|
||||
<Option projectLibDirsRelation="3"/>
|
||||
</Target>
|
||||
</Build>
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
||||
@@ -0,0 +1,47 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#ifndef _SQUSERDATA_H_
|
||||
#define _SQUSERDATA_H_
|
||||
|
||||
#if defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST)
|
||||
#include "memdbgon.h"
|
||||
#undef new // allow placement new
|
||||
#endif
|
||||
struct SQUserData : SQDelegable
|
||||
{
|
||||
SQUserData(SQSharedState *ss){ _delegate = 0; _hook = NULL; INIT_CHAIN(); ADD_TO_CHAIN(&_ss(this)->_gc_chain, this); }
|
||||
~SQUserData()
|
||||
{
|
||||
REMOVE_FROM_CHAIN(&_ss(this)->_gc_chain, this);
|
||||
SetDelegate(NULL);
|
||||
}
|
||||
static SQUserData* Create(SQSharedState *ss, SQInteger size)
|
||||
{
|
||||
SQUserData* ud = (SQUserData*)SQ_MALLOC(sizeof(SQUserData)+(size-1));
|
||||
new (ud) SQUserData(ss);
|
||||
ud->_size = size;
|
||||
ud->_typetag = 0;
|
||||
return ud;
|
||||
}
|
||||
#ifndef NO_GARBAGE_COLLECTOR
|
||||
void Mark(SQCollectable **chain);
|
||||
void Finalize(){SetDelegate(NULL);}
|
||||
#endif
|
||||
void Iterate( CSQStateIterator *pIterator );
|
||||
|
||||
void Release() {
|
||||
if (_hook) _hook(_val,_size);
|
||||
SQInteger tsize = _size - 1;
|
||||
this->~SQUserData();
|
||||
SQ_FREE(this, sizeof(SQUserData) + tsize);
|
||||
}
|
||||
|
||||
SQInteger _size;
|
||||
SQRELEASEHOOK _hook;
|
||||
SQUserPointer _typetag;
|
||||
SQChar _val[1];
|
||||
};
|
||||
|
||||
#if defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST)
|
||||
#include "memdbgoff.h"
|
||||
#endif
|
||||
#endif //_SQUSERDATA_H_
|
||||
@@ -0,0 +1,122 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#ifndef _SQUTILS_H_
|
||||
#define _SQUTILS_H_
|
||||
|
||||
#if defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST)
|
||||
#ifndef sq_vm_malloc
|
||||
#define sq_vm_malloc malloc
|
||||
#define sq_vm_realloc(p,oldsize,size) realloc(p, size)
|
||||
#define sq_vm_free(p,size) do { ((void)size); free(p); } while (0)
|
||||
#endif
|
||||
#define SQ_MALLOC(__size) sq_vm_malloc((__size));
|
||||
#define SQ_FREE(__ptr,__size) sq_vm_free((__ptr),(__size));
|
||||
#define SQ_REALLOC(__ptr,__oldsize,__size) sq_vm_realloc((__ptr),(__oldsize),(__size));
|
||||
#else
|
||||
#define SQ_MALLOC(__size) sq_vm_malloc((__size));
|
||||
#define SQ_FREE(__ptr,__size) sq_vm_free((__ptr),(__size));
|
||||
#define SQ_REALLOC(__ptr,__oldsize,__size) sq_vm_realloc((__ptr),(__oldsize),(__size));
|
||||
#endif
|
||||
#define sq_new(__ptr,__type) {__ptr=(__type *)sq_vm_malloc(sizeof(__type));new (__ptr) __type;}
|
||||
#define sq_delete(__ptr,__type) {__ptr->~__type();sq_vm_free(__ptr,sizeof(__type));}
|
||||
|
||||
#if defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST)
|
||||
#include "memdbgon.h"
|
||||
#undef new // allow placement new
|
||||
#endif
|
||||
//sqvector mini vector class, supports objects by value
|
||||
template<typename T> class sqvector
|
||||
{
|
||||
public:
|
||||
sqvector()
|
||||
{
|
||||
_vals = NULL;
|
||||
_size = 0;
|
||||
_allocated = 0;
|
||||
}
|
||||
sqvector(const sqvector<T>& v)
|
||||
{
|
||||
copy(v);
|
||||
}
|
||||
void copy(const sqvector<T>& v)
|
||||
{
|
||||
resize(v._size);
|
||||
for(SQUnsignedInteger i = 0; i < v._size; i++) {
|
||||
new ((void *)&_vals[i]) T(v._vals[i]);
|
||||
}
|
||||
_size = v._size;
|
||||
}
|
||||
~sqvector()
|
||||
{
|
||||
if(_allocated) {
|
||||
for(SQUnsignedInteger i = 0; i < _size; i++)
|
||||
_vals[i].~T();
|
||||
SQ_FREE(_vals, (_allocated * sizeof(T)));
|
||||
}
|
||||
}
|
||||
void reserve(SQUnsignedInteger newsize) { _realloc(newsize); }
|
||||
void resize(SQUnsignedInteger newsize, const T& fill = T())
|
||||
{
|
||||
if(newsize > _allocated)
|
||||
_realloc(newsize);
|
||||
if(newsize > _size) {
|
||||
while(_size < newsize) {
|
||||
new ((void *)&_vals[_size]) T(fill);
|
||||
_size++;
|
||||
}
|
||||
}
|
||||
else{
|
||||
for(SQUnsignedInteger i = newsize; i < _size; i++) {
|
||||
_vals[i].~T();
|
||||
}
|
||||
_size = newsize;
|
||||
}
|
||||
}
|
||||
void shrinktofit() { if(_size > 4) { _realloc(_size); } }
|
||||
T& top() const { return _vals[_size - 1]; }
|
||||
inline SQUnsignedInteger size() const { return _size; }
|
||||
bool empty() const { return (_size <= 0); }
|
||||
inline T &push_back(const T& val = T())
|
||||
{
|
||||
if(_allocated <= _size)
|
||||
_realloc(_size * 2);
|
||||
return *(new ((void *)&_vals[_size++]) T(val));
|
||||
}
|
||||
inline void pop_back()
|
||||
{
|
||||
_size--; _vals[_size].~T();
|
||||
}
|
||||
void insert(SQUnsignedInteger idx, const T& val)
|
||||
{
|
||||
resize(_size + 1);
|
||||
for(SQUnsignedInteger i = _size - 1; i > idx; i--) {
|
||||
_vals[i] = _vals[i - 1];
|
||||
}
|
||||
_vals[idx] = val;
|
||||
}
|
||||
void remove(SQUnsignedInteger idx)
|
||||
{
|
||||
_vals[idx].~T();
|
||||
if(idx < (_size - 1)) {
|
||||
memmove(&_vals[idx], &_vals[idx+1], sizeof(T) * (_size - idx - 1));
|
||||
}
|
||||
_size--;
|
||||
}
|
||||
SQUnsignedInteger capacity() { return _allocated; }
|
||||
inline T &back() const { return _vals[_size - 1]; }
|
||||
inline T& operator[](SQUnsignedInteger pos) const{ return _vals[pos]; }
|
||||
T* _vals;
|
||||
private:
|
||||
void _realloc(SQUnsignedInteger newsize)
|
||||
{
|
||||
newsize = (newsize > 0)?newsize:4;
|
||||
_vals = (T*)SQ_REALLOC(_vals, _allocated * sizeof(T), newsize * sizeof(T));
|
||||
_allocated = newsize;
|
||||
}
|
||||
SQUnsignedInteger _size;
|
||||
SQUnsignedInteger _allocated;
|
||||
};
|
||||
|
||||
#if defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST)
|
||||
#include "memdbgoff.h"
|
||||
#endif
|
||||
#endif //_SQUTILS_H_
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,223 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#ifndef _SQVM_H_
|
||||
#define _SQVM_H_
|
||||
|
||||
#include "sqopcodes.h"
|
||||
#include "sqobject.h"
|
||||
#define MAX_NATIVE_CALLS 100
|
||||
#define MIN_STACK_OVERHEAD 10
|
||||
|
||||
#define SQ_SUSPEND_FLAG -666
|
||||
//base lib
|
||||
void sq_base_register(HSQUIRRELVM v);
|
||||
|
||||
struct SQExceptionTrap{
|
||||
SQExceptionTrap() {}
|
||||
SQExceptionTrap(SQInteger ss, SQInteger stackbase,SQInstruction *ip, SQInteger ex_target){ _stacksize = ss; _stackbase = stackbase; _ip = ip; _extarget = ex_target;}
|
||||
SQExceptionTrap(const SQExceptionTrap &et) { (*this) = et; }
|
||||
SQInteger _stackbase;
|
||||
SQInteger _stacksize;
|
||||
SQInstruction *_ip;
|
||||
SQInteger _extarget;
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Feature to suspend / break script that runs a long time
|
||||
// Right now SQ_QUERY_COUNT_START tuned for runaway scripts, not preemption
|
||||
#define SQ_QUERY_COUNT_START 100000 // Number of skipped query times
|
||||
#define SQ_QUERY_CONTINUE 0
|
||||
#define SQ_QUERY_BREAK 1
|
||||
#define SQ_QUERY_SUSPEND 2
|
||||
|
||||
typedef int (*SQQuerySuspendFn)( HSQUIRRELVM );
|
||||
|
||||
|
||||
#define _INLINE
|
||||
|
||||
#define STK(a) _stack._vals[_stackbase+(a)]
|
||||
#define TARGET _stack._vals[_stackbase+arg0]
|
||||
|
||||
typedef sqvector<SQExceptionTrap> ExceptionsTraps;
|
||||
|
||||
struct SQVM : public CHAINABLE_OBJ
|
||||
{
|
||||
struct VarArgs {
|
||||
VarArgs() { size = 0; base = 0; }
|
||||
unsigned short size;
|
||||
unsigned short base;
|
||||
};
|
||||
|
||||
struct CallInfo{
|
||||
//CallInfo() { _generator._type = OT_NULL;}
|
||||
SQInstruction *_ip;
|
||||
SQObjectPtr *_literals;
|
||||
SQObjectPtr _closure;
|
||||
SQGenerator *_generator;
|
||||
SQInt32 _etraps;
|
||||
SQInt32 _prevstkbase;
|
||||
SQInt32 _prevtop;
|
||||
SQInt32 _target;
|
||||
SQInt32 _ncalls;
|
||||
SQBool _root;
|
||||
VarArgs _vargs;
|
||||
};
|
||||
|
||||
typedef sqvector<CallInfo> CallInfoVec;
|
||||
public:
|
||||
enum ExecutionType { ET_CALL, ET_RESUME_GENERATOR, ET_RESUME_VM, ET_RESUME_THROW_VM };
|
||||
SQVM(SQSharedState *ss);
|
||||
~SQVM();
|
||||
bool Init(SQVM *friendvm, SQInteger stacksize);
|
||||
bool Execute(SQObjectPtr &func, SQInteger target, SQInteger nargs, SQInteger stackbase, SQObjectPtr &outres, SQBool raiseerror, ExecutionType et = ET_CALL);
|
||||
//starts a native call return when the NATIVE closure returns
|
||||
bool CallNative(SQNativeClosure *nclosure, SQInteger nargs, SQInteger stackbase, SQObjectPtr &retval,bool &suspend);
|
||||
//starts a SQUIRREL call in the same "Execution loop"
|
||||
bool StartCall(SQClosure *closure, SQInteger target, SQInteger nargs, SQInteger stackbase, bool tailcall);
|
||||
bool CreateClassInstance(SQClass *theclass, SQObjectPtr &inst, SQObjectPtr &constructor);
|
||||
//call a generic closure pure SQUIRREL or NATIVE
|
||||
bool Call(SQObjectPtr &closure, SQInteger nparams, SQInteger stackbase, SQObjectPtr &outres,SQBool raiseerror);
|
||||
SQRESULT Suspend();
|
||||
|
||||
void CallDebugHook(SQInteger type,SQInteger forcedline=0);
|
||||
void CallErrorHandler(SQObjectPtr &e);
|
||||
bool Get(const SQObjectPtr &self, const SQObjectPtr &key, SQObjectPtr &dest, bool raw, bool fetchroot);
|
||||
bool FallBackGet(const SQObjectPtr &self,const SQObjectPtr &key,SQObjectPtr &dest,bool raw);
|
||||
bool Set(const SQObjectPtr &self, const SQObjectPtr &key, const SQObjectPtr &val, bool fetchroot);
|
||||
bool NewSlot(const SQObjectPtr &self, const SQObjectPtr &key, const SQObjectPtr &val,bool bstatic);
|
||||
bool DeleteSlot(const SQObjectPtr &self, const SQObjectPtr &key, SQObjectPtr &res);
|
||||
bool Clone(const SQObjectPtr &self, SQObjectPtr &target);
|
||||
bool ObjCmp(const SQObjectPtr &o1, const SQObjectPtr &o2,SQInteger &res);
|
||||
bool StringCat(const SQObjectPtr &str, const SQObjectPtr &obj, SQObjectPtr &dest);
|
||||
bool IsEqual(SQObjectPtr &o1,SQObjectPtr &o2,bool &res);
|
||||
void ToString(const SQObjectPtr &o,SQObjectPtr &res);
|
||||
SQString *PrintObjVal(const SQObject &o);
|
||||
|
||||
|
||||
void Raise_Error(const SQChar *s, ...);
|
||||
void Raise_Error(SQObjectPtr &desc);
|
||||
void Raise_IdxError(SQObject &o);
|
||||
void Raise_CompareError(const SQObject &o1, const SQObject &o2);
|
||||
void Raise_ParamTypeError(SQInteger nparam,SQInteger typemask,SQInteger type);
|
||||
|
||||
void TypeOf(const SQObjectPtr &obj1, SQObjectPtr &dest);
|
||||
bool CallMetaMethod(SQDelegable *del, SQMetaMethod mm, SQInteger nparams, SQObjectPtr &outres);
|
||||
bool ArithMetaMethod(SQInteger op, const SQObjectPtr &o1, const SQObjectPtr &o2, SQObjectPtr &dest);
|
||||
bool Return(SQInteger _arg0, SQInteger _arg1, SQObjectPtr &retval);
|
||||
//new stuff
|
||||
_INLINE bool ARITH_OP(SQUnsignedInteger op,SQObjectPtr &trg,const SQObjectPtr &o1,const SQObjectPtr &o2);
|
||||
_INLINE bool BW_OP(SQUnsignedInteger op,SQObjectPtr &trg,const SQObjectPtr &o1,const SQObjectPtr &o2);
|
||||
_INLINE bool NEG_OP(SQObjectPtr &trg,const SQObjectPtr &o1);
|
||||
_INLINE bool CMP_OP(CmpOP op, const SQObjectPtr &o1,const SQObjectPtr &o2,SQObjectPtr &res);
|
||||
bool CLOSURE_OP(SQObjectPtr &target, SQFunctionProto *func);
|
||||
bool GETVARGV_OP(SQObjectPtr &target,SQObjectPtr &idx,CallInfo *ci);
|
||||
bool CLASS_OP(SQObjectPtr &target,SQInteger base,SQInteger attrs);
|
||||
bool GETPARENT_OP(SQObjectPtr &o,SQObjectPtr &target);
|
||||
//return true if the loop is finished
|
||||
bool FOREACH_OP(SQObjectPtr &o1,SQObjectPtr &o2,SQObjectPtr &o3,SQObjectPtr &o4,SQInteger arg_2,int exitpos,int &jump);
|
||||
bool DELEGATE_OP(SQObjectPtr &trg,SQObjectPtr &o1,SQObjectPtr &o2);
|
||||
_INLINE bool LOCAL_INC(SQInteger op,SQObjectPtr &target, SQObjectPtr &a, SQObjectPtr &incr);
|
||||
_INLINE bool PLOCAL_INC(SQInteger op,SQObjectPtr &target, SQObjectPtr &a, SQObjectPtr &incr);
|
||||
_INLINE bool DerefInc(SQInteger op,SQObjectPtr &target, SQObjectPtr &self, SQObjectPtr &key, SQObjectPtr &incr, bool postfix);
|
||||
void PopVarArgs(VarArgs &vargs);
|
||||
void ClearStack(SQInteger last_top);
|
||||
#ifdef _DEBUG_DUMP
|
||||
void dumpstack(SQInteger stackbase=-1, bool dumpall = false);
|
||||
#endif
|
||||
|
||||
#ifndef NO_GARBAGE_COLLECTOR
|
||||
void Mark(SQCollectable **chain);
|
||||
#endif
|
||||
void Iterate( CSQStateIterator *pIterator );
|
||||
|
||||
void Finalize();
|
||||
void GrowCallStack() {
|
||||
SQInteger newsize = _alloccallsstacksize*2;
|
||||
_callstackdata.resize(newsize);
|
||||
_callsstack = &_callstackdata[0];
|
||||
_alloccallsstacksize = newsize;
|
||||
}
|
||||
void Release(){ sq_delete(this,SQVM); } //does nothing
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//stack functions for the api
|
||||
void Remove(SQInteger n);
|
||||
|
||||
bool IsFalse(SQObjectPtr &o);
|
||||
|
||||
void Pop();
|
||||
void Pop(SQInteger n);
|
||||
void Push(const SQObjectPtr &o);
|
||||
SQObjectPtr &Top();
|
||||
SQObjectPtr &PopGet();
|
||||
SQObjectPtr &GetUp(SQInteger n);
|
||||
SQObjectPtr &GetAt(SQInteger n);
|
||||
|
||||
void SetQuerySuspendFn( SQQuerySuspendFn qs_fn ){ _qs_fn=qs_fn; }
|
||||
int _qs_cnt;
|
||||
SQQuerySuspendFn _qs_fn;
|
||||
|
||||
SQObjectPtrVec _stack;
|
||||
SQObjectPtrVec _vargsstack;
|
||||
SQInteger _top;
|
||||
SQInteger _stackbase;
|
||||
SQObjectPtr _roottable;
|
||||
SQObjectPtr _lasterror;
|
||||
SQObjectPtr _errorhandler;
|
||||
SQObjectPtr _debughook;
|
||||
|
||||
SQObjectPtr temp_reg;
|
||||
|
||||
|
||||
CallInfo* _callsstack;
|
||||
SQInteger _callsstacksize;
|
||||
SQInteger _alloccallsstacksize;
|
||||
sqvector<CallInfo> _callstackdata;
|
||||
|
||||
ExceptionsTraps _etraps;
|
||||
CallInfo *ci;
|
||||
void *_foreignptr;
|
||||
//VMs sharing the same state
|
||||
SQSharedState *_sharedstate;
|
||||
SQInteger _nnativecalls;
|
||||
//suspend infos
|
||||
SQBool _suspended;
|
||||
SQBool _suspended_root;
|
||||
SQInteger _suspended_target;
|
||||
SQInteger _suspended_traps;
|
||||
VarArgs _suspend_varargs;
|
||||
};
|
||||
|
||||
struct AutoDec{
|
||||
AutoDec(SQInteger *n) { _n = n; }
|
||||
~AutoDec() { (*_n)--; }
|
||||
SQInteger *_n;
|
||||
};
|
||||
|
||||
inline SQObjectPtr &stack_get(HSQUIRRELVM v,SQInteger idx){return ((idx>=0)?(v->GetAt(idx+v->_stackbase-1)):(v->GetUp(idx)));}
|
||||
|
||||
#define _ss(_vm_) (_vm_)->_sharedstate
|
||||
|
||||
#ifndef NO_GARBAGE_COLLECTOR
|
||||
#define _opt_ss(_vm_) (_vm_)->_sharedstate
|
||||
#else
|
||||
#define _opt_ss(_vm_) NULL
|
||||
#endif
|
||||
|
||||
#define PUSH_CALLINFO(v,nci){ \
|
||||
if(v->_callsstacksize == v->_alloccallsstacksize) { \
|
||||
v->GrowCallStack(); \
|
||||
} \
|
||||
v->ci = &v->_callsstack[v->_callsstacksize]; \
|
||||
*(v->ci) = nci; \
|
||||
v->_callsstacksize++; \
|
||||
}
|
||||
|
||||
#define POP_CALLINFO(v){ \
|
||||
v->_callsstacksize--; \
|
||||
v->ci->_closure.Null(); \
|
||||
if(v->_callsstacksize) \
|
||||
v->ci = &v->_callsstack[v->_callsstacksize-1] ; \
|
||||
else \
|
||||
v->ci = NULL; \
|
||||
}
|
||||
#endif //_SQVM_H_
|
||||
Reference in New Issue
Block a user