18 #include "../clib/clib.h" 19 #include "../clib/compilerspecifics.h" 20 #include "../clib/logfacility.h" 21 #include "../clib/passert.h" 22 #include "../clib/strutil.h" 35 #include "../clib/mlog.h" 42 #ifdef ESCRIPT_PROFILE 44 #define WIN32_LEAN_AND_MEAN 57 #ifdef ESCRIPT_PROFILE 58 escript_profile_map EscriptProfileMap;
63 for (
const auto& ex : executor_instances )
66 if ( !ex->empty_scriptname() )
82 current_module_function( NULL ),
85 runs_to_completion_( false ),
87 debug_state_( DEBUG_STATE_NONE ),
94 executor_instances.insert(
this );
108 executor_instances.erase(
this );
125 for (
auto& fm :
prog_->modules )
128 if ( fm->functions.empty() )
139 << fm->modulename.get() <<
"\n";
143 if ( !fm->have_indexes )
150 for (
unsigned fidx = 0; fidx < fm->functions.size(); fidx++ )
154 if ( !func->
name.get().empty() )
159 ERROR_PRINT <<
"Unable to find " << fm->modulename.get() <<
"::" << func->
name.get()
165 fm->have_indexes =
true;
176 for (
int i = howMany - 1; i >= 0; --i )
180 POLLOG_ERROR.Format(
"Fatal error: Value Stack Empty! ({},PC={})\n" ) <<
prog_->name <<
PC;
215 return str ? str->
data() :
"";
237 return dbl ? dbl->
value() : 0.0;
245 return ( (
BLong*)objimp )->value();
249 return static_cast<int>( ( (
Double*)objimp )->value() );
259 ": Less Parameter than expected. " +
260 "You should use *.em-files shipped with this Core and " 261 "recompile ALL of your Scripts _now_! RTFM" );
269 ": Less Parameter than expected. " +
270 "You should use *.em-files shipped with this Core and " 271 "recompile ALL of your Scripts _now_! RTFM" );
273 return fparams[param].get()->impptr();
291 ": Less Parameter than expected. " +
292 "You should use *.em-files shipped with this Core and " 293 "recompile ALL of your Scripts _now_! RTFM" );
299 if ( imp->isa( type ) )
308 tmp <<
"Script Error in '" <<
scriptname() <<
"' PC=" <<
PC <<
": \n";
312 tmp <<
"\tCall to an object method.\n";
324 ": Less Parameter than expected. " +
325 "You should use *.em-files shipped with this Core and " 326 "recompile ALL of your Scripts _now_! RTFM" );
332 if ( imp->isa( type ) )
338 std::string report =
"Invalid parameter type. Expected param " +
Clib::decint( param ) +
360 return ( pstr != NULL );
370 value = plong->
value();
386 value = plong->
value();
387 if ( value >= 0 && value <= maxval )
393 std::string report =
"Parameter " +
Clib::decint( param ) +
" value " +
394 Clib::decint( value ) +
" out of expected range of [0.." +
413 value = plong->
value();
414 if ( value >= minval && value <= maxval )
420 std::string report =
"Parameter " +
Clib::decint( param ) +
" value " +
438 value =
static_cast<Double*
>( imp )->value();
443 value =
static_cast<BLong*
>( imp )->value();
450 <<
"\tParameter " << param <<
": Expected Integer or Real" 461 return ( pobjarr != NULL );
479 <<
"\tParameter " << param
480 <<
": Expected datatype " 503 <<
"\tParameter " << param
504 <<
": Expected datatype " 519 int longvalue = plong->
value();
520 if ( longvalue >= 0 && longvalue <= maxval )
522 value =
static_cast<unsigned short>( longvalue );
527 std::string report =
"Parameter " +
Clib::decint( param ) +
" value " +
528 Clib::decint( longvalue ) +
" out of expected range of [0.." +
541 unsigned short maxval )
548 int longvalue = plong->
value();
549 if ( longvalue >= minval && longvalue <= maxval )
551 value =
static_cast<unsigned short>( longvalue );
556 std::string report =
"Parameter " +
Clib::decint( param ) +
" value " +
557 Clib::decint( longvalue ) +
" out of expected range of [" +
575 int longvalue = plong->
value();
576 if ( longvalue >= 0 && longvalue <= USHRT_MAX )
578 value =
static_cast<unsigned short>( longvalue );
583 std::string report =
"Parameter " +
Clib::decint( param ) +
" value " +
584 Clib::decint( longvalue ) +
" out of expected range of [0.." +
602 int longvalue = plong->
value();
603 if ( longvalue >= 0 )
605 value =
static_cast<unsigned>( longvalue );
610 std::string report =
"Parameter " +
Clib::decint( param ) +
" value " +
611 Clib::decint( longvalue ) +
" out of expected range of [0.." +
630 int longvalue = plong->
value();
631 if ( longvalue >= (
int)SHRT_MIN && longvalue <= (
int)SHRT_MAX )
633 value =
static_cast<short>( longvalue );
638 std::string report =
"Parameter " +
Clib::decint( param ) +
" value " +
639 Clib::decint( longvalue ) +
" out of expected range of [" +
658 int longvalue = plong->
value();
659 if ( longvalue >= (
int)SHRT_MIN && longvalue <= maxval )
661 value =
static_cast<short>( longvalue );
666 std::string report =
"Parameter " +
Clib::decint( param ) +
" value " +
667 Clib::decint( longvalue ) +
" out of expected range of [" +
686 int longvalue = plong->
value();
687 if ( longvalue >= minval && longvalue <= maxval )
689 value =
static_cast<short>( longvalue );
694 std::string report =
"Parameter " +
Clib::decint( param ) +
" value " +
695 Clib::decint( longvalue ) +
" out of expected range of [" +
711 passert( varnum < Locals2->size() );
726 token =
prog_->instr[position].token;
742 nLines =
static_cast<unsigned int>(
prog_->instr.size() );
745 for (
unsigned i = 0; i <
prog_->nglobals; ++i )
753 ++
prog_->invocations;
762 return new BObject(
new BError(
"Please recompile this script!" ) );
786 POLLOG_ERROR.Format(
"Fatal error: Value Stack Empty! ({},PC={})\n" ) <<
prog_->name <<
PC;
804 DEBUGLOG <<
"Error in script '" <<
prog_->name.get() <<
"':\n" 805 <<
"\tModule Function " << modfunc->
name.get() <<
" was not found.\n";
807 throw std::runtime_error(
"No implementation for function found." );
813 #ifdef ESCRIPT_PROFILE 814 std::stringstream strm;
817 strm <<
" [" <<
fparams[0].
get()->impptr()->typeOf() <<
"]";
818 std::string
name( strm.str() );
819 unsigned long profile_start = GetTimeUs();
822 #ifdef ESCRIPT_PROFILE 823 profile_escript(
name, profile_start );
867 ERROR_PRINT <<
"variable is already initialized..\n";
873 objref->setimp( arr );
982 m_IterVal( pIterVal ),
983 m_pIterVal( new
BLong( 0 ) )
1028 Locals2->back().set( objref.
get() );
1039 unsigned locsize =
static_cast<unsigned int>( Locals2->size() );
1040 ObjArray* arr =
static_cast<ObjArray*
>( ( *Locals2 )[locsize - 2]->impptr() );
1043 BLong* blong =
static_cast<BLong*
>( ( *Locals2 )[locsize - 1]->impptr() );
1055 ( *Locals2 )[locsize - 3].set( elem );
1069 ContIterator* pIter = objref->impptr()->createIterator( pIterVal );
1073 Locals2->back().set( pIterVal );
1081 size_t locsize = Locals2->size();
1087 ( *Locals2 )[locsize - 3].set( next );
1105 if ( *startref.
get() > *endref.
get() )
1111 Locals2->push_back(
BObjectRef( startref->clone() ) );
1112 Locals2->push_back(
BObjectRef( endref->clone() ) );
1117 size_t locsize = Locals2->size();
1120 BObjectImp* itr = ( *Locals2 )[locsize - 2]->impptr();
1121 BObjectImp* end = ( *Locals2 )[locsize - 1]->impptr();
1143 const unsigned char* dataptr = token.
dataptr;
1146 unsigned short offset;
1147 std::memcpy( &offset, dataptr,
sizeof(
unsigned short ) );
1149 unsigned char type = *dataptr;
1153 int v = blong->
value();
1154 if ( std::memcmp( &v, dataptr,
sizeof(
int ) ) == 0 )
1171 const std::string& bstring = bstringimp->
value();
1172 const unsigned char* dataptr = token.
dataptr;
1175 unsigned short offset;
1176 std::memcpy( &offset, dataptr,
sizeof(
unsigned short ) );
1178 unsigned char type = *dataptr;
1190 if ( bstring.size() == type && memcmp( bstring.data(), dataptr,
type ) == 0 )
1201 const unsigned char* dataptr = token.
dataptr;
1204 unsigned short offset;
1205 std::memcpy( &offset, dataptr,
sizeof(
unsigned short ) );
1207 unsigned char type = *dataptr;
1230 PC = ins_casejmp_findlong( ins.
token, static_cast<BLong*>( objimp ) );
1234 PC = ins_casejmp_findstring( ins.
token, static_cast<String*>( objimp ) );
1238 PC = ins_casejmp_finddefault( ins.
token );
1240 ValueStack.pop_back();
1248 if ( objref->impptr()->isTrue() )
1251 ValueStack.pop_back();
1258 if ( !objref->impptr()->isTrue() )
1261 ValueStack.pop_back();
1268 ValueStack.push_back( ( *Locals2 )[ins.
token.
lval] );
1275 ValueStack.push_back( Globals2[ins.
token.
lval] );
1287 ValueStack.pop_back();
1293 ValueStack.pop_back();
1301 !( right.
count() == 1 && rightimpref.
count() == 1 ) );
1307 ValueStack.pop_back();
1315 !( right.
count() == 1 && rightimpref.
count() == 1 ) );
1321 ValueStack.pop_back();
1329 !( right.
count() == 1 && rightimpref.
count() == 1 ) );
1330 ValueStack.pop_back();
1336 ValueStack.pop_back();
1345 !( right.
count() == 1 && rightimpref.
count() == 1 ) );
1346 ValueStack.pop_back();
1352 ValueStack.pop_back();
1366 tmp->impref().operPlusEqual( obj, right.
impref() );
1369 ValueStack.pop_back();
1375 ValueStack.pop_back();
1389 tmp->impref().operMinusEqual( obj, right.
impref() );
1392 ValueStack.pop_back();
1398 ValueStack.pop_back();
1412 tmp->impref().operTimesEqual( obj, right.
impref() );
1415 ValueStack.pop_back();
1421 ValueStack.pop_back();
1435 tmp->impref().operDivideEqual( obj, right.
impref() );
1438 ValueStack.pop_back();
1444 ValueStack.pop_back();
1458 tmp->impref().operModulusEqual( obj, right.
impref() );
1461 ValueStack.pop_back();
1470 #ifdef ESCRIPT_PROFILE 1471 std::stringstream strm;
1472 strm <<
"MBR_" << leftref->impptr()->typeOf() <<
" ." << ins.
token.
tokval();
1473 if ( !fparams.empty() )
1474 strm <<
" [" << fparams[0].
get()->impptr()->typeOf() <<
"]";
1475 std::string
name( strm.str() );
1476 unsigned long profile_start = GetTimeUs();
1479 #ifdef ESCRIPT_PROFILE 1480 profile_escript(
name, profile_start );
1490 #ifdef ESCRIPT_PROFILE 1491 std::stringstream strm;
1492 strm <<
"MBR_" << leftref->impptr()->typeOf() <<
" ." << ins.
token.
lval;
1493 if ( !fparams.empty() )
1494 strm <<
" [" << fparams[0].
get()->impptr()->typeOf() <<
"]";
1495 std::string
name( strm.str() );
1496 unsigned long profile_start = GetTimeUs();
1499 #ifdef ESCRIPT_PROFILE 1500 profile_escript(
name, profile_start );
1514 if ( right.
count() == 1 && rightimpref.
count() == 1 )
1516 lvar->setimp( &rightimpref );
1520 lvar->setimp( rightimpref.
copy() );
1522 ValueStack.pop_back();
1534 if ( right.
count() == 1 && rightimpref.
count() == 1 )
1536 gvar->setimp( &rightimpref );
1540 gvar->setimp( rightimpref.
copy() );
1542 ValueStack.pop_back();
1549 ValueStack.pop_back();
1557 if ( right.
count() == 1 && rightimpref.
count() == 1 )
1559 left.
setimp( &rightimpref );
1565 ValueStack.pop_back();
1576 ValueStack.pop_back();
1584 if ( right.
count() == 1 && rightimpref.
count() == 1 )
1586 left.
setimp( &rightimpref );
1607 ValueStack.pop_back();
1609 ValueStack.pop_back();
1634 ValueStack.pop_back();
1636 ValueStack.pop_back();
1647 ValueStack.pop_back();
1659 ValueStack.pop_back();
1677 ValueStack.pop_back();
1695 ValueStack.pop_back();
1712 ValueStack.pop_back();
1729 ValueStack.pop_back();
1746 ValueStack.pop_back();
1763 ValueStack.pop_back();
1780 ValueStack.pop_back();
1797 ValueStack.pop_back();
1814 ValueStack.pop_back();
1831 ValueStack.pop_back();
1848 ValueStack.pop_back();
1866 ValueStack.pop_back();
1872 int _true = ( left != right );
1884 ValueStack.pop_back();
1890 int _true = ( left == right );
1902 ValueStack.pop_back();
1908 int _true = ( left < right );
1920 ValueStack.pop_back();
1925 int _true = ( left <= right );
1936 ValueStack.pop_back();
1942 int _true = ( left > right );
1953 ValueStack.pop_back();
1959 int _true = ( left >= right );
1972 ValueStack.pop_back();
1975 leftref = ( *leftref )->OperSubscript( *rightref );
1981 std::stack<BObjectRef> indices;
1982 for (
int i = 0; i < ins.
token.
lval; ++i )
1984 indices.push( ValueStack.back() );
1985 ValueStack.pop_back();
1989 leftref = ( *leftref )->OperMultiSubscript( indices );
1994 ValueStack.pop_back();
1996 std::stack<BObjectRef> indices;
1997 for (
int i = 0; i < ins.
token.
lval; ++i )
1999 indices.push( ValueStack.back() );
2000 ValueStack.pop_back();
2004 leftref = ( *leftref )->OperMultiSubscriptAssign( indices, target_ref->impptr() );
2015 ValueStack.pop_back();
2021 leftref = addmember( left, right );
2032 ValueStack.pop_back();
2038 leftref = removemember( left, right );
2049 ValueStack.pop_back();
2055 leftref = checkmember( left, right );
2073 ValueStack.pop_back();
2081 if ( valob.
count() == 1 && valimp->
count() == 1 )
2106 ValueStack.pop_back();
2111 ValueStack.pop_back();
2119 if ( keyob.
count() != 1 || keyimp->
count() != 1 )
2121 keyimp = keyimp->
copy();
2123 if ( valob.
count() != 1 || valimp->
count() != 1 )
2125 valimp = valimp->
copy();
2140 ValueStack.pop_back();
2152 ValueStack.pop_back();
2169 ValueStack.pop_back();
2186 ValueStack.pop_back();
2203 ValueStack.pop_back();
2220 ValueStack.pop_back();
2237 ValueStack.pop_back();
2256 getParams( nparams );
2257 execFunc( ins.
token );
2265 getParams( nparams );
2270 auto funcr =
static_cast<BFunctionRef*
>( objref->impptr() );
2272 if ( funcr->validCall( ins.
token.
lval, *
this, &jmp ) )
2275 ValueStack.pop_back();
2276 for (
auto& p : fparams )
2277 ValueStack.push_back( p );
2279 ins_jsr_userfunc( jmp );
2282 ins_makelocal( jmp );
2287 #ifdef ESCRIPT_PROFILE 2288 std::stringstream strm;
2289 strm <<
"MTHID_" << objref->impptr()->typeOf() <<
" ." << ins.
token.
lval;
2290 if ( !fparams.empty() )
2291 strm <<
" [" << fparams[0].
get()->impptr()->typeOf() <<
"]";
2292 std::string
name( strm.str() );
2293 unsigned long profile_start = GetTimeUs();
2296 #ifdef ESCRIPT_PROFILE 2297 profile_escript(
name, profile_start );
2307 func_result_ = NULL;
2325 getParams( nparams );
2330 auto funcr =
static_cast<BFunctionRef*
>( objref->impptr() );
2332 if ( funcr->validCall( ins.
token.
tokval(), *
this, &jmp ) )
2335 ValueStack.pop_back();
2336 for (
auto& p : fparams )
2337 ValueStack.push_back( p );
2339 ins_jsr_userfunc( jmp );
2342 ins_makelocal( jmp );
2348 #ifdef ESCRIPT_PROFILE 2349 std::stringstream strm;
2350 strm <<
"MTH_" << objref->impptr()->typeOf() <<
" ." << ins.
token.
tokval();
2351 if ( !fparams.empty() )
2352 strm <<
" [" << fparams[0].
get()->impptr()->typeOf() <<
"]";
2353 std::string
name( strm.str() );
2354 unsigned long profile_start = GetTimeUs();
2357 #ifdef ESCRIPT_PROFILE 2358 profile_escript(
name, profile_start );
2369 func_result_ = NULL;
2387 if ( debug_level >= SOURCELINES && ins.
token.
tokval() )
2404 upperLocals2.push_back( Locals2 );
2414 ControlStack.push_back( rc );
2420 tmp <<
"Script " << scriptname() <<
" exceeded maximum call depth\n" 2421 <<
"Return path PCs: ";
2422 while ( !ControlStack.empty() )
2424 rc = ControlStack.back();
2425 ControlStack.pop_back();
2426 tmp << rc.
PC <<
" ";
2428 POLLOG << tmp.str() <<
"\n";
2435 popParam( ins.
token );
2440 popParamByRef( ins.
token );
2445 getArg( ins.
token );
2453 for (
int i = 0; i < ins.
token.
lval; i++ )
2454 Locals2->pop_back();
2458 for (
int i = 0; i < ins.
token.
lval; i++ )
2459 Globals2.pop_back();
2468 ControlStack.push_back( rc );
2470 upperLocals2.push_back( Locals2 );
2479 if ( ControlStack.empty() )
2489 ControlStack.pop_back();
2496 if ( !upperLocals2.empty() )
2498 Locals2 = upperLocals2.back();
2499 upperLocals2.pop_back();
2547 newobj = ref->impref().inverse();
2775 throw std::runtime_error(
"Undefined execution token " +
Clib::tostring( token.
id ) );
2794 if ( debug_level >= INSTRUCTIONS )
2799 if ( debug_state_ == DEBUG_STATE_ATTACHING )
2801 debug_state_ = DEBUG_STATE_ATTACHED;
2805 else if ( debug_state_ == DEBUG_STATE_INS_TRACE )
2808 debug_state_ = DEBUG_STATE_ATTACHED;
2812 else if ( debug_state_ == DEBUG_STATE_STEP_INTO )
2814 debug_state_ = DEBUG_STATE_STEPPING_INTO;
2817 else if ( debug_state_ == DEBUG_STATE_STEPPING_INTO )
2819 if ( prog_->dbg_ins_statementbegin.size() > PC && prog_->dbg_ins_statementbegin[PC] )
2821 tmpbreakpoints_.insert( PC );
2825 else if ( debug_state_ == DEBUG_STATE_STEP_OVER )
2827 unsigned breakPC = PC + 1;
2828 while ( prog_->dbg_ins_statementbegin.size() > breakPC )
2830 if ( prog_->dbg_ins_statementbegin[breakPC] )
2832 tmpbreakpoints_.insert( breakPC );
2833 debug_state_ = DEBUG_STATE_RUN;
2842 else if ( debug_state_ == DEBUG_STATE_RUN )
2846 else if ( debug_state_ == DEBUG_STATE_BREAK_INTO )
2848 debug_state_ = DEBUG_STATE_ATTACHED;
2854 if ( ( breakpoints_.count( PC ) || tmpbreakpoints_.count( PC ) ) && bp_skip_ != PC &&
2857 tmpbreakpoints_.erase( PC );
2859 debug_state_ = DEBUG_STATE_ATTACHED;
2867 ++prog_->instr_cycles;
2872 ( this->*( ins.
func ) )( ins );
2874 catch ( std::exception& ex )
2877 tmp <<
"Exception in: " << prog_->name.get() <<
" PC=" << onPC <<
": " << ex.what() <<
"\n";
2879 tmp <<
"run_ok_ = false\n";
2882 tmp <<
" PC < nLines: (" << PC <<
" < " << nLines <<
") \n";
2885 tmp <<
"error_ = true\n";
2887 tmp <<
"done = true\n";
2892 show_context( onPC );
2898 POLLOG_ERROR <<
"Exception in " << prog_->name.get() <<
", PC=" << onPC <<
": unclassified\n";
2900 show_context( onPC );
2908 os << ( ( atPC == PC ) ?
">" :
" " ) << atPC
2909 << ( breakpoints_.count( static_cast<unsigned>( atPC ) ) ?
"*" :
":" ) <<
" " 2910 << prog_->instr[atPC].token;
2916 unsigned start, end;
2924 if ( end >= nLines )
2927 for (
unsigned i = start; i <= end; ++i )
2929 POLLOG.Format(
"{}: {}\n" ) << i << dbg_get_instruction( i );
2934 unsigned start, end;
2942 if ( end >= nLines )
2945 for (
unsigned i = start; i <= end; ++i )
2947 os << dbg_get_instruction( i ) <<
'\n';
2958 set_running_to_completion(
true );
2959 while ( runnable() )
2974 while ( !ValueStack.empty() )
2975 ValueStack.pop_back();
2989 bool data_shown =
false;
2997 while ( !ValueStack.empty() )
2999 if ( Clib::memoryleak_debug )
3007 LEAKLOG << ValueStack.back()->impptr()->pack();
3008 LEAKLOG <<
" [" << ValueStack.back()->impptr()->sizeEstimate() <<
"] ";
3010 ValueStack.pop_back();
3012 if ( Clib::memoryleak_debug )
3029 ValueStack.push_back( arg );
3034 availmodules.push_back( module );
3041 for ( idx = 0; idx < availmodules.size(); idx++ )
3044 if ( stricmp( module->
moduleName.get().c_str(), name.c_str() ) == 0 )
3052 setdebugging(
true );
3053 debug_state_ = DEBUG_STATE_ATTACHING;
3057 setdebugging(
false );
3058 debug_state_ = DEBUG_STATE_NONE;
3063 debug_state_ = DEBUG_STATE_INS_TRACE;
3068 debug_state_ = DEBUG_STATE_STEP_INTO;
3073 debug_state_ = DEBUG_STATE_STEP_OVER;
3078 debug_state_ = DEBUG_STATE_RUN;
3083 debug_state_ = DEBUG_STATE_BREAK_INTO;
3088 breakpoints_.insert( atPC );
3092 breakpoints_.erase( atPC );
3096 breakpoints_.clear();
3101 size_t size =
sizeof( *this );
3103 for (
const auto& bojectrefvec : upperLocals2 )
3106 for (
const auto& bojectref : *bojectrefvec )
3108 if ( bojectref !=
nullptr )
3109 size += bojectref->sizeEstimate();
3115 for (
const auto& bojectref : *Locals2 )
3117 if ( bojectref !=
nullptr )
3118 size += bojectref->sizeEstimate();
3121 for (
const auto& bojectref : Globals2 )
3123 if ( bojectref !=
nullptr )
3124 size += bojectref->sizeEstimate();
3127 for (
const auto& bojectref : ValueStack )
3129 if ( bojectref !=
nullptr )
3130 size += bojectref->sizeEstimate();
3133 for (
const auto& bojectref : fparams )
3135 if ( bojectref !=
nullptr )
3136 size += bojectref->sizeEstimate();
3140 size += 3 *
sizeof(
unsigned* ) + breakpoints_.size() *
sizeof( unsigned );
3141 size += 3 *
sizeof(
unsigned* ) + tmpbreakpoints_.size() *
sizeof( unsigned );
3142 size += func_result_ !=
nullptr ? func_result_->sizeEstimate() : 0;
3147 #ifdef ESCRIPT_PROFILE 3148 void Executor::profile_escript( std::string
name,
unsigned long profile_start )
3150 unsigned long profile_end = GetTimeUs() - profile_start;
3151 escript_profile_map::iterator itr = EscriptProfileMap.find( name );
3152 if ( itr != EscriptProfileMap.end() )
3154 itr->second.count++;
3155 itr->second.sum += profile_end;
3156 if ( itr->second.max < profile_end )
3157 itr->second.max = profile_end;
3158 else if ( itr->second.min > profile_end )
3159 itr->second.min = profile_end;
3163 profile_instr profInstr;
3164 profInstr.count = 1;
3165 profInstr.max = profile_end;
3166 profInstr.min = profile_end;
3167 profInstr.sum = profile_end;
3168 EscriptProfileMap[
name] = profInstr;
3173 unsigned long Executor::GetTimeUs()
3175 static bool bInitialized =
false;
3176 static LARGE_INTEGER lFreq, lStart;
3177 static LARGE_INTEGER lDivisor;
3178 if ( !bInitialized )
3180 bInitialized =
true;
3181 QueryPerformanceFrequency( &lFreq );
3182 QueryPerformanceCounter( &lStart );
3183 lDivisor.QuadPart = lFreq.QuadPart / 1000000;
3187 QueryPerformanceCounter( &lEnd );
3188 double duration = double( lEnd.QuadPart - lStart.QuadPart ) / lFreq.QuadPart;
3189 duration *= 1000000;
3190 LONGLONG llDuration =
static_cast<LONGLONG
>( duration );
3191 return llDuration & 0xffffffff;
3194 unsigned long Executor::GetTimeUs()
3196 static bool bInitialized =
false;
3198 if ( !bInitialized )
3200 bInitialized =
true;
3201 gettimeofday( &t1, NULL );
3205 gettimeofday( &t2, NULL );
3208 elapsedTime = ( t2.tv_sec - t1.tv_sec ) * 1000000.0;
3209 elapsedTime += ( t2.tv_usec - t1.tv_usec );
3211 long long llDuration =
static_cast<long long>( elapsedTime );
3212 return llDuration & 0xffffffff;
virtual BObjectImp * selfBitShiftRightObjImp(const BObjectImp &objimp) const
BObjectRef getObjRef(void)
void ins_modulusequal(const Instruction &ins)
void ins_exit(const Instruction &ins)
void setFunctionResult(BObjectImp *imp)
void ins_globalvar(const Instruction &ins)
void ins_in(const Instruction &ins)
virtual BObjectRef get_member(const char *membername)
void ins_set_member(const Instruction &ins)
void ins_error(const Instruction &ins)
void ins_logical_not(const Instruction &ins)
void ins_dictionary(const Instruction &ins)
int makeDouble(unsigned param)
BObjectImp * func_result_
const std::string & value() const
void ins_multisubscript_assign(const Instruction &ins)
virtual ContIterator * createIterator(BObject *pIterVal) POL_OVERRIDE
void ins_string(const Instruction &ins)
void ins_unminus(const Instruction &ins)
BObjectImp * copy(void) const
void ins_jsr_userfunc(const Instruction &ins)
void ins_set_member_id_consume_modulusequal(const Instruction &ins)
void ins_divideequal(const Instruction &ins)
ValueStackCont ValueStack
virtual BObjectImp * selfBitAndObjImp(const BObjectImp &objimp) const
BObjectImp * getParamImp2(unsigned param, BObjectImp::BObjectType type)
void ins_progend(const Instruction &ins)
size_t sizeEstimate() const
void ins_uninit(const Instruction &ins)
std::string scripts_thread_script
bool isa(BObjectType type) const
virtual BObjectImp * selfBitOrObjImp(const BObjectImp &objimp) const
void ins_nop(const Instruction &ins)
void ins_get_member(const Instruction &ins)
void ins_array_assign_consume(const Instruction &ins)
void ins_initforeach(const Instruction &ins)
int getToken(Token &token, unsigned position)
void ins_jmpiffalse(const Instruction &ins)
const char * tokval() const
virtual long contains(const BObjectImp &objimp) const
void ins_equal(const Instruction &ins)
void addModule(ExecutorModule *module)
void ins_notequal(const Instruction &ins)
void ins_set_member_id_consume_timesequal(const Instruction &ins)
virtual int functionIndex(const std::string &funcname)=0
void execFunc(const Token &token)
void ins_modulus(const Instruction &ins)
void ins_lessequal(const Instruction &ins)
std::string decint(unsigned short v)
#define IS_DEBUGLOG_DISABLED
void ins_add(const Instruction &ins)
std::vector< BObjectRef > BObjectRefVec
void ins_set_member_id_consume_divideequal(const Instruction &ins)
void ins_pop_param(const Instruction &ins)
void ins_addmember_assign(const Instruction &ins)
static int ins_casejmp_finddefault(const Token &token)
EScriptConfig escript_config
int makeString(unsigned param)
void ins_bitshift_right(const Instruction &ins)
void ins_func(const Instruction &ins)
void ins_set_member_id_consume_minusequal(const Instruction &ins)
void ins_div(const Instruction &ins)
virtual BObjectImp * copy() const =0
BObjectRef & GlobalVar(unsigned int varnum)
void ins_return(const Instruction &ins)
virtual void operInsertInto(BObject &obj, const BObjectImp &objimp)
const BLong * getLongParam(unsigned param)
bool isa(BObjectImp::BObjectType type) const
std::vector< ExecutorModule * > execmodules
ArrayIterator(ObjArray *pArr, BObject *pIterVal)
void ins_logical_and(const Instruction &ins)
int paramAsLong(unsigned param)
void ins_lessthan(const Instruction &ins)
virtual void operModulusEqual(BObject &obj, BObjectImp &objimp)
void ins_initfor(const Instruction &ins)
const char * paramAsString(unsigned param)
void(Executor::* ExecInstrFunc)(const Instruction &)
static int ins_casejmp_findlong(const Token &token, BLong *blong)
#define EXPLICIT_CAST(totype, fromtype)
std::string getStringRep() const
virtual BObjectRef operDotPlus(const char *name)
void ins_checkmember(const Instruction &ins)
void ins_call_method(const Instruction &ins)
#define passert_r(exp, reason)
void ins_goto(const Instruction &ins)
void ins_initforeach2(const Instruction &ins)
void ins_assign_localvar(const Instruction &ins)
const BApplicObjType * object_type() const
virtual void operDivideEqual(BObject &obj, BObjectImp &objimp)
BObject * getParamObj(unsigned param)
boost_utils::function_name_flystring name
void ins_ident(const Instruction &ins)
std::string dbg_get_instruction(size_t atPC) const
void ins_funcref(const Instruction &ins)
virtual BObjectImp * selfBitShiftLeftObjImp(const BObjectImp &objimp) const
void pushArg(BObjectImp *arg)
virtual BObject * step() POL_OVERRIDE
void ins_dictionary_addmember(const Instruction &ins)
void ins_bitwise_xor(const Instruction &ins)
static BObjectRef addmember(BObject &left, const BObject &right)
void setimp(BObjectImp *imp)
void ins_greaterthan(const Instruction &ins)
void ins_arraysubscript(const Instruction &ins)
void ins_pop_param_byref(const Instruction &ins)
virtual BObjectRef get_member_id(const int id)
virtual BObjectRef set_member(const char *membername, BObjectImp *valueimp, bool copy)
virtual BObjectImp * execFunc(unsigned idx)=0
static BObjectRef checkmember(BObject &left, const BObject &right)
const BApplicObjType * pointer_type() const
void ins_get_arg(const Instruction &ins)
void ins_bitshift_left(const Instruction &ins)
virtual void operPlusEqual(BObject &obj, BObjectImp &objimp)
ExecutorModule * findModule(const std::string &name)
std::vector< BObjectRef > fparams
std::vector< BObjectRefVec * > upperLocals2
virtual ContIterator * createIterator(BObject *pIterVal)
std::string tostring(const Bscript::BTokenType &v)
bool AttachFunctionalityModules()
static BObjectRef removemember(BObject &left, const BObject &right)
bool setProgram(EScriptProgram *prog)
static UninitObject * create()
void ins_minusequal(const Instruction &ins)
void ins_bitwise_and(const Instruction &ins)
void ins_set_member_id(const Instruction &ins)
void ins_logical_or(const Instruction &ins)
virtual void operMinusEqual(BObject &obj, BObjectImp &objimp)
boost_utils::function_name_flystring moduleName
bool getRealParam(unsigned param, double &value)
void ins_timesequal(const Instruction &ins)
void ins_stepforeach(const Instruction &ins)
virtual BObjectRef set_member_id(const int id, BObjectImp *valueimp, bool copy)
int getParams(unsigned howMany)
ref_ptr< EScriptProgram > prog_
void addMember(const char *name, BObjectRef val)
void popParamByRef(const Token &token)
void ins_localvar(const Instruction &ins)
void ins_addmember(const Instruction &ins)
void ins_array(const Instruction &ins)
static int ins_casejmp_findstring(const Token &token, String *bstringimp)
void ins_struct(const Instruction &ins)
void ins_subtract(const Instruction &ins)
std::vector< ModuleFunction * > functions
unsigned int max_call_depth
virtual std::string functionName(unsigned idx)=0
void ins_stepforeach2(const Instruction &ins)
void ins_mult(const Instruction &ins)
void ins_declareArray(const Instruction &ins)
void ins_double(const Instruction &ins)
unsigned int count() const
const unsigned char * dataptr
std::set< Executor * > executor_instances
void ins_leave_block(const Instruction &ins)
virtual BObjectImp * selfMinusObjImp(const BObjectImp &objimp) const
void dbg_setbp(unsigned atPC)
virtual BObjectRef operDotQMark(const char *name)
void ins_nextfor(const Instruction &ins)
void * getApplicPtrParam(unsigned param, const BApplicObjType *pointer_type)
void ins_assign(const Instruction &ins)
void popParam(const Token &token)
BApplicObjBase * getApplicObjParam(unsigned param, const BApplicObjType *object_type)
const std::string & scriptname() const
const String * getStringParam(unsigned param)
virtual BObjectImp * selfTimesObjImp(const BObjectImp &objimp) const
void dbg_clrbp(unsigned atPC)
D explicit_cast(const S &s)
void ins_assign_globalvar(const Instruction &ins)
void ins_set_member_id_consume(const Instruction &ins)
void ins_bitwise_or(const Instruction &ins)
void ins_makelocal(const Instruction &ins)
void ins_removemember(const Instruction &ins)
static ref_ptr< BObjectImp > SharedInstanceOwner
void ins_set_member_id_consume_plusequal(const Instruction &ins)
void ins_makeLocal(const Instruction &ins)
virtual BObjectImp * selfModulusObjImp(const BObjectImp &objimp) const
void ins_get_member_id(const Instruction &ins)
void ins_call_method_id(const Instruction &ins)
double paramAsDouble(unsigned param)
virtual std::string getStringRep() const POL_OVERRIDE
virtual BObjectImp * selfBitXorObjImp(const BObjectImp &objimp) const
BObject * makeObj(const Token &token)
void ins_jmpiftrue(const Instruction &ins)
void ins_bitwise_not(const Instruction &ins)
void ins_plusequal(const Instruction &ins)
void getArg(const Token &token)
void ins_greaterequal(const Instruction &ins)
#define passert_always(exp)
void show_context(unsigned atPC)
void ins_statementbegin(const Instruction &ins)
void ins_insert_into(const Instruction &ins)
void ins_gosub(const Instruction &ins)
void ins_addmember2(const Instruction &ins)
static Clib::SpinLock _executor_lock
std::lock_guard< SpinLock > SpinLockGuard
void initForFnCall(unsigned in_PC)
virtual BObjectRef operDotMinus(const char *name)
virtual size_t sizeEstimate() const
void ins_array_assign(const Instruction &ins)
virtual BObjectImp * array_assign(BObjectImp *idx, BObjectImp *target, bool copy)
bool getObjArrayParam(unsigned param, ObjArray *&pobjarr)
virtual BObjectImp * selfDividedByObjImp(const BObjectImp &objimp) const
void ins_multisubscript(const Instruction &ins)
void ins_long(const Instruction &ins)
const char * data() const
void ins_set_member_consume(const Instruction &ins)
BObjectRef & LocalVar(unsigned int varnum)
void ins_casejmp(const Instruction &ins)
static ExecInstrFunc GetInstrFunc(const Token &token)
void ins_consume(const Instruction &ins)
void ins_assign_consume(const Instruction &ins)
static const char * typestr(BObjectType typ)
static UninitObject * SharedInstance
virtual void operTimesEqual(BObject &obj, BObjectImp &objimp)
BObjectImp * getParamImp(unsigned param)
virtual BObjectImp * selfPlusObjImp(const BObjectImp &objimp) const
ModuleFunction * current_module_function
unsigned scripts_thread_scriptPC
bool getParam(unsigned param, int &value)
void display_executor_instances()
std::vector< ExecutorModule * > availmodules