diff --git a/BlitzBasicIDE/blitzide.vcxproj b/BlitzBasicIDE/blitzide.vcxproj index a6eb05b..8bcf503 100644 --- a/BlitzBasicIDE/blitzide.vcxproj +++ b/BlitzBasicIDE/blitzide.vcxproj @@ -67,7 +67,7 @@ Default false Level3 - Cdecl + StdCall Async @@ -104,7 +104,7 @@ _CRT_SECURE_NO_WARNINGS;WIN32;%(PreprocessorDefinitions) true false - Cdecl + StdCall Async diff --git a/BlitzBasicLauncher/bblaunch.vcxproj b/BlitzBasicLauncher/bblaunch.vcxproj index 0fdd396..d554d96 100644 --- a/BlitzBasicLauncher/bblaunch.vcxproj +++ b/BlitzBasicLauncher/bblaunch.vcxproj @@ -66,7 +66,7 @@ Default false Level3 - Cdecl + StdCall Async @@ -101,7 +101,7 @@ _CRT_SECURE_NO_WARNINGS;WIN32;%(PreprocessorDefinitions) true false - Cdecl + StdCall Async diff --git a/Linker/linker_dll.vcxproj b/Linker/linker_dll.vcxproj index d279c9e..85ade6b 100644 --- a/Linker/linker_dll.vcxproj +++ b/Linker/linker_dll.vcxproj @@ -66,7 +66,7 @@ Default false Level3 - Cdecl + StdCall Async @@ -89,7 +89,6 @@ true true Console - .\Debug\linker.lib /FIXED:NO odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -103,7 +102,7 @@ _CRT_SECURE_NO_WARNINGS;WIN32;%(PreprocessorDefinitions) true false - Cdecl + StdCall Async @@ -125,7 +124,6 @@ true true Console - .\Release\linker.lib odbc32.lib;odbccp32.lib;%(AdditionalDependencies) diff --git a/LinkerLib/linker.vcxproj b/LinkerLib/linker.vcxproj index 3768ea4..a80b588 100644 --- a/LinkerLib/linker.vcxproj +++ b/LinkerLib/linker.vcxproj @@ -67,7 +67,7 @@ false Level3 $(IntDir)vc$(PlatformToolsetVersion).pdb - Cdecl + StdCall Async @@ -93,7 +93,7 @@ true false $(IntDir)vc$(PlatformToolsetVersion).pdb - Cdecl + StdCall Async diff --git a/Runtime/bbruntime_dll.vcxproj b/Runtime/bbruntime_dll.vcxproj index b397207..81574ec 100644 --- a/Runtime/bbruntime_dll.vcxproj +++ b/Runtime/bbruntime_dll.vcxproj @@ -66,7 +66,7 @@ Default false Level3 - Cdecl + StdCall Async @@ -89,7 +89,6 @@ true true Console - .\Debug\runtime.lib /FIXED:NO dxguid.lib;d3dx9.lib;d3d9.lib;dsound.lib;dinput8.lib;ddraw.lib;wsock32.lib;winmm.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)#ThirdParty\;$(DXSDK_DIR)Lib\x86\;%(AdditionalLibraryDirectories) @@ -105,7 +104,7 @@ _CRT_SECURE_NO_WARNINGS;WIN32;%(PreprocessorDefinitions) true false - Cdecl + StdCall Async @@ -127,7 +126,6 @@ true true Console - .\Release\runtime.lib dxguid.lib;d3dx9.lib;d3d9.lib;dsound.lib;dinput8.lib;ddraw.lib;wsock32.lib;winmm.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)#ThirdParty\;$(DXSDK_DIR)Lib\x86\;%(AdditionalLibraryDirectories) false diff --git a/RuntimeLib/basic.cpp b/RuntimeLib/basic.cpp index 9985722..befcb7b 100644 --- a/RuntimeLib/basic.cpp +++ b/RuntimeLib/basic.cpp @@ -1,594 +1,593 @@ - -#include "std.h" -#include "bbsys.h" - -//how many strings allocated -static int stringCnt; - -//how many objects new'd but not deleted -static int objCnt; - -//how many objects deleted but not released -static int unrelObjCnt; - -//how many objects to alloc per block -static const int OBJ_NEW_INC=512; - -//how many strings to alloc per block -static const int STR_NEW_INC=512; - -//current data ptr -static BBData *dataPtr; - -//chunks of mem - WHAT THE FUCK WAS I ON?!?!?!? -//static list memBlks; - -//strings -static BBStr usedStrs,freeStrs; - -//object handle number -static int next_handle; - -//object<->handle maps -static map handle_map; -static map object_map; - -static BBType _bbIntType( BBTYPE_INT ); -static BBType _bbFltType( BBTYPE_FLT ); -static BBType _bbStrType( BBTYPE_STR ); -static BBType _bbCStrType( BBTYPE_CSTR ); - -static void *bbMalloc( int size ){ - return malloc(size); -/* - char *c=d_new char[ size ]; - memBlks.push_back( c ); - return c; -*/ -} - -static void bbFree( void *q ){ - free(q); -/* - if( !q ) return; - char *c=(char*)q; - memBlks.remove( c ); - delete [] c; -*/ -} - -static void removeStr( BBStr *str ){ - str->next->prev=str->prev; - str->prev->next=str->next; -} - -static void insertStr( BBStr *str,BBStr *next ){ - str->next=next; - str->prev=next->prev; - str->prev->next=str; - next->prev=str; -} - -void *BBStr::operator new( size_t size ){ - if( freeStrs.next==&freeStrs ){ - BBStr *t=(BBStr*)bbMalloc( sizeof(BBStr)*STR_NEW_INC ); - for( int k=0;kcompare( *rhs ); - delete lhs;delete rhs;return n; -} - -int _bbStrToInt( BBStr *s ){ - int n=atoi( *s ); - delete s;return n; -} - -BBStr *_bbStrFromInt( int n ){ - return d_new BBStr( itoa( n ) ); -} - -float _bbStrToFloat( BBStr *s ){ - float n=(float)atof( *s ); - delete s;return n; -} - -BBStr *_bbStrFromFloat( float n ){ - return d_new BBStr( ftoa( n ) ); -} - -BBStr *_bbStrConst( const char *s ){ - return d_new BBStr( s ); -} - -void * _bbVecAlloc( BBVecType *type ){ - void *vec=bbMalloc( type->size*4 ); - memset( vec,0,type->size*4 ); - return vec; -} - -void _bbVecFree( void *vec,BBVecType *type ){ - if( type->elementType->type==BBTYPE_STR ){ - BBStr **p=(BBStr**)vec; - for( int k=0;ksize;++p,++k ){ - if( *p ) _bbStrRelease( *p ); - } - }else if( type->elementType->type==BBTYPE_OBJ ){ - BBObj **p=(BBObj**)vec; - for( int k=0;ksize;++p,++k ){ - if( *p ) _bbObjRelease( *p ); - } - } - bbFree( vec ); -} - -void _bbVecBoundsEx(){ - ThrowRuntimeException( "Blitz array index out of bounds" ); -} - -void _bbUndimArray( BBArray *array ){ - if( void *t=array->data ){ - if( array->elementType==BBTYPE_STR ){ - BBStr **p=(BBStr**)t; - int size=array->scales[array->dims-1]; - for( int k=0;kelementType==BBTYPE_OBJ ){ - BBObj **p=(BBObj**)t; - int size=array->scales[array->dims-1]; - for( int k=0;kdata=0; - } -} - -void _bbDimArray( BBArray *array ){ - int k; - for( k=0;kdims;++k ) ++array->scales[k]; - for( k=1;kdims;++k ){ - array->scales[k]*=array->scales[k-1]; - } - int size=array->scales[array->dims-1]; - array->data=bbMalloc( size*4 ); - memset( array->data,0,size*4 ); -} - -void _bbArrayBoundsEx(){ - ThrowRuntimeException( "Array index out of bounds" ); -} - -static void unlinkObj( BBObj *obj ){ - obj->next->prev=obj->prev; - obj->prev->next=obj->next; -} - -static void insertObj( BBObj *obj,BBObj *next ){ - obj->next=next; - obj->prev=next->prev; - next->prev->next=obj; - next->prev=obj; -} - -BBObj *_bbObjNew( BBObjType *type ){ - if( type->free.next==&type->free ){ - int obj_size=sizeof(BBObj)+type->fieldCnt*4; - BBObj *o=(BBObj*)bbMalloc( obj_size*OBJ_NEW_INC ); - for( int k=0;kfree ); - o=(BBObj*)( (char*)o+obj_size ); - } - } - BBObj *o=type->free.next; - unlinkObj( o ); - o->type=type; - o->ref_cnt=1; - o->fields=(BBField*)(o+1); - for( int k=0;kfieldCnt;++k ){ - switch( type->fieldTypes[k]->type ){ - case BBTYPE_VEC: - o->fields[k].VEC=_bbVecAlloc( (BBVecType*)type->fieldTypes[k] ); - break; - default: - o->fields[k].INT=0; - } - } - insertObj( o,&type->used ); - ++unrelObjCnt; - ++objCnt; - return o; -} - -void _bbObjDelete( BBObj *obj ){ - if( !obj ) return; - BBField *fields=obj->fields; - if( !fields ) return; - BBObjType *type=obj->type; - for( int k=0;kfieldCnt;++k ){ - switch( type->fieldTypes[k]->type ){ - case BBTYPE_STR: - _bbStrRelease( fields[k].STR ); - break; - case BBTYPE_OBJ: - _bbObjRelease( fields[k].OBJ ); - break; - case BBTYPE_VEC: - _bbVecFree( fields[k].VEC,(BBVecType*)type->fieldTypes[k] ); - break; - } - } - map::iterator it=object_map.find( obj ); - if( it!=object_map.end() ){ - handle_map.erase( it->second ); - object_map.erase( it ); - } - obj->fields=0; - _bbObjRelease( obj ); - --objCnt; -} - -void _bbObjDeleteEach( BBObjType *type ){ - BBObj *obj=type->used.next; - while( obj->type ){ - BBObj *next=obj->next; - if( obj->fields ) _bbObjDelete( obj ); - obj=next; - } -} - -extern void bbDebugLog( BBStr *t ); -extern void bbStop( ); - -void _bbObjRelease( BBObj *obj ){ - if( !obj || --obj->ref_cnt ) return; - unlinkObj( obj ); - insertObj( obj,&obj->type->free ); - --unrelObjCnt; -} - -void _bbObjStore( BBObj **var,BBObj *obj ){ - if( obj ) ++obj->ref_cnt; //do this first incase of self-assignment - _bbObjRelease( *var ); - *var=obj; -} - -int _bbObjCompare( BBObj *o1,BBObj *o2 ){ - return (o1 ? o1->fields : 0)!=(o2 ? o2->fields : 0); -} - -BBObj *_bbObjNext( BBObj *obj ){ - do{ - obj=obj->next; - if( !obj->type ) return 0; - }while( !obj->fields ); - return obj; -} - -BBObj *_bbObjPrev( BBObj *obj ){ - do{ - obj=obj->prev; - if( !obj->type ) return 0; - }while( !obj->fields ); - return obj; -} - -BBObj *_bbObjFirst( BBObjType *type ){ - return _bbObjNext( &type->used ); -} - -BBObj *_bbObjLast( BBObjType *type ){ - return _bbObjPrev( &type->used ); -} - -void _bbObjInsBefore( BBObj *o1,BBObj *o2 ){ - if( o1==o2 ) return; - unlinkObj( o1 ); - insertObj( o1,o2 ); -} - -void _bbObjInsAfter( BBObj *o1,BBObj *o2 ){ - if( o1==o2 ) return; - unlinkObj( o1 ); - insertObj( o1,o2->next ); -} - -int _bbObjEachFirst( BBObj **var,BBObjType *type ){ - _bbObjStore( var,_bbObjFirst( type ) ); - return *var!=0; -} - -int _bbObjEachNext( BBObj **var ){ - _bbObjStore( var,_bbObjNext( *var ) ); - return *var!=0; -} - -int _bbObjEachFirst2( BBObj **var,BBObjType *type ){ - *var=_bbObjFirst( type ); - return *var!=0; -} - -int _bbObjEachNext2( BBObj **var ){ - *var=_bbObjNext( *var ); - return *var!=0; -} - -BBStr *_bbObjToStr( BBObj *obj ){ - if( !obj || !obj->fields ) return d_new BBStr( "[NULL]" ); - - static BBObj *root; - static int recurs_cnt; - - if( obj==root ) return d_new BBStr( "[ROOT]" ); - if( recurs_cnt==8 ) return d_new BBStr( "...." ); - - ++recurs_cnt; - BBObj *oldRoot=root; - if( !root ) root=obj; - - BBObjType *type=obj->type; - BBField *fields=obj->fields; - BBStr *s=d_new BBStr("["),*t; - for( int k=0;kfieldCnt;++k ){ - if( k ) *s+=','; - switch( type->fieldTypes[k]->type ){ - case BBTYPE_INT: - t=_bbStrFromInt( fields[k].INT );*s+=*t;delete t; - break; - case BBTYPE_FLT: - t=_bbStrFromFloat( fields[k].FLT );*s+=*t;delete t; - break; - case BBTYPE_STR: - if( fields[k].STR ) *s+='\"'+*fields[k].STR+'\"'; - else *s+="\"\""; - break; - case BBTYPE_OBJ: - t=_bbObjToStr( fields[k].OBJ );*s+=*t;delete t; - break; - default: - *s+="???"; - } - } - *s+=']'; - root=oldRoot; - --recurs_cnt; - return s; -} - -int _bbObjToHandle( BBObj *obj ){ - if( !obj || !obj->fields ) return 0; - map::const_iterator it=object_map.find( obj ); - if( it!=object_map.end() ) return it->second; - ++next_handle; - object_map[obj]=next_handle; - handle_map[next_handle]=obj; - return next_handle; -} - -BBObj *_bbObjFromHandle( int handle,BBObjType *type ){ - map::const_iterator it=handle_map.find( handle ); - if( it==handle_map.end() ) return 0; - BBObj *obj=it->second; - return obj->type==type ? obj : 0; -} - -void _bbNullObjEx(){ - ThrowRuntimeException( "Object does not exist" ); -} - -void _bbRestore( BBData *data ){ - dataPtr=data; -} - -int _bbReadInt(){ - switch( dataPtr->fieldType ){ - case BBTYPE_END:ThrowRuntimeException( "Out of data" );return 0; - case BBTYPE_INT:return dataPtr++->field.INT; - case BBTYPE_FLT:return dataPtr++->field.FLT; - case BBTYPE_CSTR:return atoi( dataPtr++->field.CSTR ); - default:ThrowRuntimeException( "Bad data type" );return 0; - } -} - -float _bbReadFloat(){ - switch( dataPtr->fieldType ){ - case BBTYPE_END:ThrowRuntimeException( "Out of data" );return 0; - case BBTYPE_INT:return dataPtr++->field.INT; - case BBTYPE_FLT:return dataPtr++->field.FLT; - case BBTYPE_CSTR:return atof( dataPtr++->field.CSTR ); - default:ThrowRuntimeException( "Bad data type" );return 0; - } -} - -BBStr *_bbReadStr(){ - switch( dataPtr->fieldType ){ - case BBTYPE_END:ThrowRuntimeException( "Out of data" );return 0; - case BBTYPE_INT:return d_new BBStr( itoa( dataPtr++->field.INT ) ); - case BBTYPE_FLT:return d_new BBStr( ftoa( dataPtr++->field.FLT ) ); - case BBTYPE_CSTR:return d_new BBStr( dataPtr++->field.CSTR ); - default:ThrowRuntimeException( "Bad data type" );return 0; - } -} - -int _bbAbs( int n ){ - return n>=0 ? n : -n; -} - -int _bbSgn( int n ){ - return n>0 ? 1 : (n<0 ? -1 : 0); -} - -int _bbMod( int x,int y ){ - return x%y; -} - -float _bbFAbs( float n ){ - return n>=0 ? n : -n; -} - -float _bbFSgn( float n ){ - return n>0 ? 1 : (n<0 ? -1 : 0); -} - -float _bbFMod( float x,float y ){ - return (float)fmod( x,y ); -} - -float _bbFPow( float x,float y ){ - return (float)pow( x,y ); -} - -void bbRuntimeStats(){ - gx_runtime->debugLog( ("Active strings :"+itoa(stringCnt)).c_str() ); - gx_runtime->debugLog( ("Active objects :"+itoa(objCnt)).c_str() ); - gx_runtime->debugLog( ("Unreleased objs:"+itoa(unrelObjCnt)).c_str() ); - /* - clog<<"Active strings:"<next ){ - clog<<"string@"<<(void*)t< memBlks; + +//strings +static BBStr usedStrs, freeStrs; + +//object handle number +static int next_handle; + +//object<->handle maps +static map handle_map; +static map object_map; + +static BBType _bbIntType(BBTYPE_INT); +static BBType _bbFltType(BBTYPE_FLT); +static BBType _bbStrType(BBTYPE_STR); +static BBType _bbCStrType(BBTYPE_CSTR); + +static void *bbMalloc(int size) { + return malloc(size); + /* + char *c=d_new char[ size ]; + memBlks.push_back( c ); + return c; + */ +} + +static void bbFree(void *q) { + free(q); + /* + if( !q ) return; + char *c=(char*)q; + memBlks.remove( c ); + delete [] c; + */ +} + +static void removeStr(BBStr *str) { + str->next->prev = str->prev; + str->prev->next = str->next; +} + +static void insertStr(BBStr *str, BBStr *next) { + str->next = next; + str->prev = next->prev; + str->prev->next = str; + next->prev = str; +} + +void *BBStr::operator new(size_t size) { + if (freeStrs.next == &freeStrs) { + BBStr *t = (BBStr*)bbMalloc(sizeof(BBStr)*STR_NEW_INC); + for (int k = 0; k < STR_NEW_INC; ++k) insertStr(t++, &freeStrs); + } + BBStr *t = freeStrs.next; + removeStr(t); insertStr(t, &usedStrs); + return t; +} + +void BBStr::operator delete(void *q) { + if (!q) return; + BBStr *t = (BBStr*)q; + removeStr(t); insertStr(t, &freeStrs); +} + +BBStr::BBStr() { + ++stringCnt; +} + +BBStr::BBStr(const char *s) :string(s) { + ++stringCnt; +} + +BBStr::BBStr(const char *s, int n) : string(s, n) { + ++stringCnt; +} + +BBStr::BBStr(const BBStr &s) : string(s) { + ++stringCnt; +} + +BBStr::BBStr(const string &s) : string(s) { + ++stringCnt; +} + +BBStr &BBStr::operator=(const char *s) { + string::operator=(s); return *this; +} + +BBStr &BBStr::operator=(const BBStr &s) { + string::operator=(s); return *this; +} + +BBStr &BBStr::operator=(const string &s) { + string::operator=(s); return *this; +} + +BBStr::~BBStr() { + --stringCnt; +} + +BBStr *_bbStrLoad(BBStr **var) { + return *var ? d_new BBStr(**var) : d_new BBStr(); +} + +void _bbStrRelease(BBStr *str) { + delete str; +} + +void _bbStrStore(BBStr **var, BBStr *str) { + _bbStrRelease(*var); *var = str; +} + +BBStr *_bbStrConcat(BBStr *s1, BBStr *s2) { + *s1 += *s2; delete s2; return s1; +} + +int _bbStrCompare(BBStr *lhs, BBStr *rhs) { + int n = lhs->compare(*rhs); + delete lhs; delete rhs; return n; +} + +int _bbStrToInt(BBStr *s) { + int n = atoi(*s); + delete s; return n; +} + +BBStr *_bbStrFromInt(int n) { + return d_new BBStr(itoa(n)); +} + +float _bbStrToFloat(BBStr *s) { + float n = (float)atof(*s); + delete s; return n; +} + +BBStr *_bbStrFromFloat(float n) { + return d_new BBStr(ftoa(n)); +} + +BBStr *_bbStrConst(const char *s) { + return d_new BBStr(s); +} + +void * _bbVecAlloc(BBVecType *type) { + void *vec = bbMalloc(type->size * 4); + memset(vec, 0, type->size * 4); + return vec; +} + +void _bbVecFree(void *vec, BBVecType *type) { + if (type->elementType->type == BBTYPE_STR) { + BBStr **p = (BBStr**)vec; + for (int k = 0; k < type->size; ++p, ++k) { + if (*p) _bbStrRelease(*p); + } + } else if (type->elementType->type == BBTYPE_OBJ) { + BBObj **p = (BBObj**)vec; + for (int k = 0; k < type->size; ++p, ++k) { + if (*p) _bbObjRelease(*p); + } + } + bbFree(vec); +} + +void _bbVecBoundsEx() { + ThrowRuntimeException("Blitz array index out of bounds"); +} + +void _bbUndimArray(BBArray *array) { + if (void *t = array->data) { + if (array->elementType == BBTYPE_STR) { + BBStr **p = (BBStr**)t; + int size = array->scales[array->dims - 1]; + for (int k = 0; k < size; ++p, ++k) { + if (*p) _bbStrRelease(*p); + } + } else if (array->elementType == BBTYPE_OBJ) { + BBObj **p = (BBObj**)t; + int size = array->scales[array->dims - 1]; + for (int k = 0; k < size; ++p, ++k) { + if (*p) _bbObjRelease(*p); + } + } + bbFree(t); + array->data = 0; + } +} + +void _bbDimArray(BBArray *array) { + int k; + for (k = 0; k < array->dims; ++k) ++array->scales[k]; + for (k = 1; k < array->dims; ++k) { + array->scales[k] *= array->scales[k - 1]; + } + int size = array->scales[array->dims - 1]; + array->data = bbMalloc(size * 4); + memset(array->data, 0, size * 4); +} + +void _bbArrayBoundsEx() { + ThrowRuntimeException("Array index out of bounds"); +} + +static void unlinkObj(BBObj *obj) { + obj->next->prev = obj->prev; + obj->prev->next = obj->next; +} + +static void insertObj(BBObj *obj, BBObj *next) { + obj->next = next; + obj->prev = next->prev; + next->prev->next = obj; + next->prev = obj; +} + +BBObj *_bbObjNew(BBObjType *type) { + if (type->free.next == &type->free) { + int obj_size = sizeof(BBObj) + type->fieldCnt * 4; + BBObj *o = (BBObj*)bbMalloc(obj_size*OBJ_NEW_INC); + for (int k = 0; k < OBJ_NEW_INC; ++k) { + insertObj(o, &type->free); + o = (BBObj*)((char*)o + obj_size); + } + } + BBObj *o = type->free.next; + unlinkObj(o); + o->type = type; + o->ref_cnt = 1; + o->fields = (BBField*)(o + 1); + for (int k = 0; k < type->fieldCnt; ++k) { + switch (type->fieldTypes[k]->type) { + case BBTYPE_VEC: + o->fields[k].VEC = _bbVecAlloc((BBVecType*)type->fieldTypes[k]); + break; + default: + o->fields[k].INT = 0; + } + } + insertObj(o, &type->used); + ++unrelObjCnt; + ++objCnt; + return o; +} + +void _bbObjDelete(BBObj *obj) { + if (!obj) return; + BBField *fields = obj->fields; + if (!fields) return; + BBObjType *type = obj->type; + for (int k = 0; k < type->fieldCnt; ++k) { + switch (type->fieldTypes[k]->type) { + case BBTYPE_STR: + _bbStrRelease(fields[k].STR); + break; + case BBTYPE_OBJ: + _bbObjRelease(fields[k].OBJ); + break; + case BBTYPE_VEC: + _bbVecFree(fields[k].VEC, (BBVecType*)type->fieldTypes[k]); + break; + } + } + map::iterator it = object_map.find(obj); + if (it != object_map.end()) { + handle_map.erase(it->second); + object_map.erase(it); + } + obj->fields = 0; + _bbObjRelease(obj); + --objCnt; +} + +void _bbObjDeleteEach(BBObjType *type) { + BBObj *obj = type->used.next; + while (obj->type) { + BBObj *next = obj->next; + if (obj->fields) _bbObjDelete(obj); + obj = next; + } +} + +extern void bbDebugLog(BBStr *t); +extern void bbStop(); + +void _bbObjRelease(BBObj *obj) { + if (!obj || --obj->ref_cnt) return; + unlinkObj(obj); + insertObj(obj, &obj->type->free); + --unrelObjCnt; +} + +void _bbObjStore(BBObj **var, BBObj *obj) { + if (obj) ++obj->ref_cnt; //do this first incase of self-assignment + _bbObjRelease(*var); + *var = obj; +} + +int _bbObjCompare(BBObj *o1, BBObj *o2) { + return (o1 ? o1->fields : 0) != (o2 ? o2->fields : 0); +} + +BBObj *_bbObjNext(BBObj *obj) { + do { + obj = obj->next; + if (!obj->type) return 0; + } while (!obj->fields); + return obj; +} + +BBObj *_bbObjPrev(BBObj *obj) { + do { + obj = obj->prev; + if (!obj->type) return 0; + } while (!obj->fields); + return obj; +} + +BBObj *_bbObjFirst(BBObjType *type) { + return _bbObjNext(&type->used); +} + +BBObj *_bbObjLast(BBObjType *type) { + return _bbObjPrev(&type->used); +} + +void _bbObjInsBefore(BBObj *o1, BBObj *o2) { + if (o1 == o2) return; + unlinkObj(o1); + insertObj(o1, o2); +} + +void _bbObjInsAfter(BBObj *o1, BBObj *o2) { + if (o1 == o2) return; + unlinkObj(o1); + insertObj(o1, o2->next); +} + +int _bbObjEachFirst(BBObj **var, BBObjType *type) { + _bbObjStore(var, _bbObjFirst(type)); + return *var != 0; +} + +int _bbObjEachNext(BBObj **var) { + _bbObjStore(var, _bbObjNext(*var)); + return *var != 0; +} + +int _bbObjEachFirst2(BBObj **var, BBObjType *type) { + *var = _bbObjFirst(type); + return *var != 0; +} + +int _bbObjEachNext2(BBObj **var) { + *var = _bbObjNext(*var); + return *var != 0; +} + +BBStr *_bbObjToStr(BBObj *obj) { + if (!obj || !obj->fields) return d_new BBStr("[NULL]"); + + static BBObj *root; + static int recurs_cnt; + + if (obj == root) return d_new BBStr("[ROOT]"); + if (recurs_cnt == 8) return d_new BBStr("...."); + + ++recurs_cnt; + BBObj *oldRoot = root; + if (!root) root = obj; + + BBObjType *type = obj->type; + BBField *fields = obj->fields; + BBStr *s = d_new BBStr("["), *t; + for (int k = 0; k < type->fieldCnt; ++k) { + if (k) *s += ','; + switch (type->fieldTypes[k]->type) { + case BBTYPE_INT: + t = _bbStrFromInt(fields[k].INT); *s += *t; delete t; + break; + case BBTYPE_FLT: + t = _bbStrFromFloat(fields[k].FLT); *s += *t; delete t; + break; + case BBTYPE_STR: + if (fields[k].STR) *s += '\"' + *fields[k].STR + '\"'; + else *s += "\"\""; + break; + case BBTYPE_OBJ: + t = _bbObjToStr(fields[k].OBJ); *s += *t; delete t; + break; + default: + *s += "???"; + } + } + *s += ']'; + root = oldRoot; + --recurs_cnt; + return s; +} + +int _bbObjToHandle(BBObj *obj) { + if (!obj || !obj->fields) return 0; + map::const_iterator it = object_map.find(obj); + if (it != object_map.end()) return it->second; + ++next_handle; + object_map[obj] = next_handle; + handle_map[next_handle] = obj; + return next_handle; +} + +BBObj *_bbObjFromHandle(int handle, BBObjType *type) { + map::const_iterator it = handle_map.find(handle); + if (it == handle_map.end()) return 0; + BBObj *obj = it->second; + return obj->type == type ? obj : 0; +} + +void _bbNullObjEx() { + ThrowRuntimeException("Object does not exist"); +} + +void _bbRestore(BBData *data) { + dataPtr = data; +} + +int _bbReadInt() { + switch (dataPtr->fieldType) { + case BBTYPE_END:ThrowRuntimeException("Out of data"); return 0; + case BBTYPE_INT:return dataPtr++->field.INT; + case BBTYPE_FLT:return dataPtr++->field.FLT; + case BBTYPE_CSTR:return atoi(dataPtr++->field.CSTR); + default:ThrowRuntimeException("Bad data type"); return 0; + } +} + +float _bbReadFloat() { + switch (dataPtr->fieldType) { + case BBTYPE_END:ThrowRuntimeException("Out of data"); return 0; + case BBTYPE_INT:return dataPtr++->field.INT; + case BBTYPE_FLT:return dataPtr++->field.FLT; + case BBTYPE_CSTR:return atof(dataPtr++->field.CSTR); + default:ThrowRuntimeException("Bad data type"); return 0; + } +} + +BBStr *_bbReadStr() { + switch (dataPtr->fieldType) { + case BBTYPE_END:ThrowRuntimeException("Out of data"); return 0; + case BBTYPE_INT:return d_new BBStr(itoa(dataPtr++->field.INT)); + case BBTYPE_FLT:return d_new BBStr(ftoa(dataPtr++->field.FLT)); + case BBTYPE_CSTR:return d_new BBStr(dataPtr++->field.CSTR); + default:ThrowRuntimeException("Bad data type"); return 0; + } +} + +int _bbAbs(int n) { + return n >= 0 ? n : -n; +} + +int _bbSgn(int n) { + return n > 0 ? 1 : (n < 0 ? -1 : 0); +} + +int _bbMod(int x, int y) { + return x%y; +} + +float _bbFAbs(float n) { + return n >= 0 ? n : -n; +} + +float _bbFSgn(float n) { + return n > 0 ? 1 : (n < 0 ? -1 : 0); +} + +float _bbFMod(float x, float y) { + return (float)fmod(x, y); +} + +float _bbFPow(float x, float y) { + return (float)pow(x, y); +} + +void bbRuntimeStats() { + gx_runtime->debugLog(("Active strings :" + itoa(stringCnt)).c_str()); + gx_runtime->debugLog(("Active objects :" + itoa(objCnt)).c_str()); + gx_runtime->debugLog(("Unreleased objs:" + itoa(unrelObjCnt)).c_str()); + /* + clog<<"Active strings:"<next ){ + clog<<"string@"<<(void*)t< - -enum{ - BBTYPE_END=0, - BBTYPE_INT=1,BBTYPE_FLT=2, - BBTYPE_STR=3,BBTYPE_CSTR=4, - BBTYPE_OBJ=5,BBTYPE_VEC=6 -}; - -#pragma pack( push,1 ) - -struct BBObj; -struct BBStr; -struct BBType; -struct BBObjType; -struct BBVecType; -union BBField; -struct BBArray; - -struct BBObj{ - BBField *fields; - BBObj *next,*prev; - BBObjType *type; - int ref_cnt; -}; - -struct BBType{ - int type; - BBType( int n ):type(n){} -}; - -struct BBObjType : public BBType{ - BBObj used,free; - int fieldCnt; - BBType *fieldTypes[1]; -}; - -struct BBVecType : public BBType{ - int size; - BBType *elementType; -}; - -union BBField{ - int INT; - float FLT; - BBStr *STR; - char *CSTR; - BBObj *OBJ; - void *VEC; -}; - -struct BBArray{ - void *data; - int elementType,dims,scales[1]; -}; - -struct BBStr : public std::string{ - BBStr *next,*prev; - - BBStr(); - BBStr( const char *s ); - BBStr( const char *s,int n ); - BBStr( const BBStr &s ); - BBStr( const std::string &s ); - BBStr &operator=( const char *s ); - BBStr &operator=( const BBStr &s ); - BBStr &operator=( const std::string &s ); - ~BBStr(); - - void *operator new( size_t size ); - void operator delete( void *q ); - - void *operator new( size_t size,const char *file,int line ){ return operator new( size ); } - void operator delete( void *q,const char *file,int line ){ operator delete( q ); } -}; - -struct BBData{ - int fieldType; - BBField field; -}; - -#pragma pack( pop ) - -void basic_link(); - -extern BBType _bbIntType; -extern BBType _bbFltType; -extern BBType _bbStrType; -extern BBType _bbCStrType; - -BBStr * _bbStrLoad( BBStr **var ); -void _bbStrRelease( BBStr *str ); -void _bbStrStore( BBStr **var,BBStr *str ); -int _bbStrCompare( BBStr *lhs,BBStr *rhs ); - -BBStr * _bbStrConcat( BBStr *s1,BBStr *s2 ); -int _bbStrToInt( BBStr *s ); -BBStr * _bbStrFromInt( int n ); -float _bbStrToFloat( BBStr *s ); -BBStr * _bbStrFromFloat( float n ); -BBStr * _bbStrConst( const char *s ); - -void _bbDimArray( BBArray *array ); -void _bbUndimArray( BBArray *array ); -void _bbArrayBoundsEx(); - -void * _bbVecAlloc( BBVecType *type ); -void _bbVecFree( void *vec,BBVecType *type ); -void _bbVecBoundsEx(); - -BBObj * _bbObjNew( BBObjType *t ); -void _bbObjDelete( BBObj *obj ); -void _bbObjDeleteEach( BBObjType *type ); -void _bbObjRelease( BBObj *obj ); -void _bbObjStore( BBObj **var,BBObj *obj ); -BBObj * _bbObjNext( BBObj *obj ); -BBObj * _bbObjPrev( BBObj *obj ); -BBObj * _bbObjFirst( BBObjType *t ); -BBObj * _bbObjLast( BBObjType *t ); -void _bbObjInsBefore( BBObj *o1,BBObj *o2 ); -void _bbObjInsAfter( BBObj *o1,BBObj *o2 ); -int _bbObjEachFirst( BBObj **var,BBObjType *type ); -int _bbObjEachNext( BBObj **var ); -int _bbObjCompare( BBObj *o1,BBObj *o2 ); -BBStr * _bbObjToStr( BBObj *obj ); -int _bbObjToHandle( BBObj *obj ); -BBObj * _bbObjFromHandle( int handle,BBObjType *type ); -void _bbNullObjEx(); - -void _bbRestore( BBData *data ); -int _bbReadInt(); -float _bbReadFloat(); -BBStr * _bbReadStr(); - -int _bbAbs( int n ); -int _bbSgn( int n ); -int _bbMod( int x,int y ); -float _bbFAbs( float n ); -float _bbFSgn( float n ); -float _bbFMod( float x,float y ); -float _bbFPow( float x,float y ); - -void bbRuntimeStats(); - + +#ifndef BASIC_H +#define BASIC_H + +#include +#include + +enum { + BBTYPE_END = 0, + BBTYPE_INT = 1, BBTYPE_FLT = 2, + BBTYPE_STR = 3, BBTYPE_CSTR = 4, + BBTYPE_OBJ = 5, BBTYPE_VEC = 6 +}; + +#pragma pack( push,1 ) + +struct BBObj; +struct BBStr; +struct BBType; +struct BBObjType; +struct BBVecType; +union BBField; +struct BBArray; + +struct BBObj { + BBField *fields; + BBObj *next, *prev; + BBObjType *type; + int ref_cnt; +}; + +struct BBType { + int type; + BBType(int n) :type(n) {} +}; + +struct BBObjType : public BBType { + BBObj used, free; + int fieldCnt; + BBType *fieldTypes[1]; +}; + +struct BBVecType : public BBType { + int size; + BBType *elementType; +}; + +union BBField { + int INT; + float FLT; + BBStr *STR; + char *CSTR; + BBObj *OBJ; + void *VEC; +}; + +struct BBArray { + void *data; + int elementType, dims, scales[1]; +}; + +struct BBStr : public std::string { + BBStr *next, *prev; + + BBStr(); + BBStr(const char *s); + BBStr(const char *s, int n); + BBStr(const BBStr &s); + BBStr(const std::string &s); + BBStr &operator=(const char *s); + BBStr &operator=(const BBStr &s); + BBStr &operator=(const std::string &s); + ~BBStr(); + + void *operator new(size_t size); + void operator delete(void *q); + + void *operator new(size_t size, const char *file, int line) { return operator new(size); } + void operator delete(void *q, const char *file, int line) { operator delete(q); } +}; + +struct BBData { + int fieldType; + BBField field; +}; + +#pragma pack( pop ) + +void basic_link(); + +extern BBType _bbIntType; +extern BBType _bbFltType; +extern BBType _bbStrType; +extern BBType _bbCStrType; + +BBStr * _bbStrLoad(BBStr **var); +void _bbStrRelease(BBStr *str); +void _bbStrStore(BBStr **var, BBStr *str); +int _bbStrCompare(BBStr *lhs, BBStr *rhs); + +BBStr * _bbStrConcat(BBStr *s1, BBStr *s2); +int _bbStrToInt(BBStr *s); +BBStr * _bbStrFromInt(int n); +float _bbStrToFloat(BBStr *s); +BBStr * _bbStrFromFloat(float n); +BBStr * _bbStrConst(const char *s); + +void _bbDimArray(BBArray *array); +void _bbUndimArray(BBArray *array); +void _bbArrayBoundsEx(); + +void * _bbVecAlloc(BBVecType *type); +void _bbVecFree(void *vec, BBVecType *type); +void _bbVecBoundsEx(); + +BBObj * _bbObjNew(BBObjType *t); +void _bbObjDelete(BBObj *obj); +void _bbObjDeleteEach(BBObjType *type); +void _bbObjRelease(BBObj *obj); +void _bbObjStore(BBObj **var, BBObj *obj); +BBObj * _bbObjNext(BBObj *obj); +BBObj * _bbObjPrev(BBObj *obj); +BBObj * _bbObjFirst(BBObjType *t); +BBObj * _bbObjLast(BBObjType *t); +void _bbObjInsBefore(BBObj *o1, BBObj *o2); +void _bbObjInsAfter(BBObj *o1, BBObj *o2); +int _bbObjEachFirst(BBObj **var, BBObjType *type); +int _bbObjEachNext(BBObj **var); +int _bbObjCompare(BBObj *o1, BBObj *o2); +BBStr * _bbObjToStr(BBObj *obj); +int _bbObjToHandle(BBObj *obj); +BBObj * _bbObjFromHandle(int handle, BBObjType *type); +void _bbNullObjEx(); + +void _bbRestore(BBData *data); +int _bbReadInt(); +float _bbReadFloat(); +BBStr * _bbReadStr(); + +int _bbAbs(int n); +int _bbSgn(int n); +int _bbMod(int x, int y); +float _bbFAbs(float n); +float _bbFSgn(float n); +float _bbFMod(float x, float y); +float _bbFPow(float x, float y); + +void bbRuntimeStats(); + #endif \ No newline at end of file diff --git a/RuntimeLib/bbruntime.vcxproj b/RuntimeLib/bbruntime.vcxproj index e69ed87..844bfe1 100644 --- a/RuntimeLib/bbruntime.vcxproj +++ b/RuntimeLib/bbruntime.vcxproj @@ -68,7 +68,7 @@ false Level3 $(IntDir)vc$(PlatformToolsetVersion).pdb - Cdecl + StdCall Async @@ -95,7 +95,7 @@ false $(IntDir)vc$(PlatformToolsetVersion).pdb - Cdecl + StdCall Async diff --git a/asm_makeinsts/asm_makeinsts.vcxproj b/asm_makeinsts/asm_makeinsts.vcxproj index db349d8..f76a3e2 100644 --- a/asm_makeinsts/asm_makeinsts.vcxproj +++ b/asm_makeinsts/asm_makeinsts.vcxproj @@ -64,7 +64,7 @@ _CRT_SECURE_NO_WARNINGS;WIN32;%(PreprocessorDefinitions) true false - Cdecl + StdCall Async @@ -94,7 +94,7 @@ Default false Level3 - Cdecl + StdCall Async diff --git a/blitz/blitz.vcxproj b/blitz/blitz.vcxproj index f086733..ac522ed 100644 --- a/blitz/blitz.vcxproj +++ b/blitz/blitz.vcxproj @@ -67,7 +67,7 @@ ProgramDatabase false Level3 - Cdecl + StdCall Async @@ -98,7 +98,7 @@ true ProgramDatabase false - Cdecl + StdCall Async diff --git a/blitz3d/blitz3d.vcxproj b/blitz3d/blitz3d.vcxproj index 0fa4bc1..4dffb63 100644 --- a/blitz3d/blitz3d.vcxproj +++ b/blitz3d/blitz3d.vcxproj @@ -65,7 +65,7 @@ true false $(IntDir)vc$(PlatformToolsetVersion).pdb - Cdecl + StdCall Async @@ -78,7 +78,7 @@ true - .\Release\blitz3d.lib + $(OutDir)$(TargetName)$(TargetExt) MachineX86 @@ -94,7 +94,7 @@ false Level3 $(IntDir)vc$(PlatformToolsetVersion).pdb - Cdecl + StdCall Async @@ -107,7 +107,7 @@ true - .\Debug\blitz3d.lib + $(OutDir)$(TargetName)$(TargetExt) MachineX86 diff --git a/compiler/compiler.vcxproj b/compiler/compiler.vcxproj index 4440fa6..6095184 100644 --- a/compiler/compiler.vcxproj +++ b/compiler/compiler.vcxproj @@ -67,7 +67,7 @@ false Level3 $(IntDir)vc$(PlatformToolsetVersion).pdb - Cdecl + StdCall Async @@ -92,7 +92,7 @@ true false $(IntDir)vc$(PlatformToolsetVersion).pdb - Cdecl + StdCall Async diff --git a/config/config.vcxproj b/config/config.vcxproj index 50b0a8d..e8a364c 100644 --- a/config/config.vcxproj +++ b/config/config.vcxproj @@ -66,7 +66,7 @@ true false $(IntDir)vc$(PlatformToolsetVersion).pdb - Cdecl + StdCall Async @@ -93,7 +93,7 @@ false Level3 $(IntDir)vc$(PlatformToolsetVersion).pdb - Cdecl + StdCall Async diff --git a/debugger/debugger.vcxproj b/debugger/debugger.vcxproj index 9be0f51..30362a5 100644 --- a/debugger/debugger.vcxproj +++ b/debugger/debugger.vcxproj @@ -63,10 +63,10 @@ false true Level3 - _CRT_SECURE_NO_WARNINGS;WIN32;%(PreprocessorDefinitions) + _AFXDLL;_CRT_SECURE_NO_WARNINGS;WIN32;%(PreprocessorDefinitions) true false - Cdecl + StdCall Async @@ -88,7 +88,6 @@ true true Windows - .\Release\debugger.lib @@ -97,11 +96,11 @@ false true true - _CRT_SECURE_NO_WARNINGS;WIN32;DEBUG;%(PreprocessorDefinitions) + _AFXDLL;_CRT_SECURE_NO_WARNINGS;WIN32;DEBUG;%(PreprocessorDefinitions) Default false Level3 - Cdecl + StdCall Async @@ -124,7 +123,6 @@ true true Console - .\Debug\debugger.lib /FIXED:NO diff --git a/gxruntime/gxruntime.vcxproj b/gxruntime/gxruntime.vcxproj index c81a7cc..87acdf4 100644 --- a/gxruntime/gxruntime.vcxproj +++ b/gxruntime/gxruntime.vcxproj @@ -67,7 +67,7 @@ Level3 false $(IntDir)vc$(PlatformToolsetVersion).pdb - Cdecl + StdCall Async @@ -94,7 +94,7 @@ false Level3 $(IntDir)vc$(PlatformToolsetVersion).pdb - Cdecl + StdCall Async diff --git a/stdutil/stdutil.vcxproj b/stdutil/stdutil.vcxproj index 631aa3c..d5f733c 100644 --- a/stdutil/stdutil.vcxproj +++ b/stdutil/stdutil.vcxproj @@ -65,7 +65,7 @@ true false $(IntDir)vc$(PlatformToolsetVersion).pdb - Cdecl + StdCall Async @@ -92,7 +92,7 @@ false Level3 $(IntDir)vc$(PlatformToolsetVersion).pdb - Cdecl + StdCall Async