//--------------------------------------------------------------------------- void tTJSScriptBlock::Parse(const tjs_char *script, bool isexpr, bool resultneeded) { TJS_F_TRACE("tTJSScriptBlock::Parse"); if(!script) return; CompileErrorCount = 0; LexicalAnalyzer = new tTJSLexicalAnalyzer(this, script, isexpr, resultneeded); try { yyparse(this); } catch(...) { delete LexicalAnalyzer; LexicalAnalyzer=NULL; throw; } delete LexicalAnalyzer; LexicalAnalyzer=NULL; if(CompileErrorCount) { TJS_eTJSScriptError(FirstError, this, FirstErrorPos); } }
//--------------------------------------------------------------------------- // for Bytecode void tTJS::LoadByteCode( const tjs_uint8* buff, size_t len, tTJSVariant *result, iTJSDispatch2 *context, const tjs_char *name ) { TJS_F_TRACE("tTJS::LoadByteCode"); TJSSetFPUE(); if(Cache) Cache->LoadByteCode(buff, len, result, context, name); }
//--------------------------------------------------------------------------- void tTJS::ExecScript(const tjs_char *script, tTJSVariant *result, iTJSDispatch2 *context, const tjs_char *name, tjs_int lineofs) { TJS_F_TRACE("tTJS::ExecScript"); TJSSetFPUE(); if(Cache) Cache->ExecScript(script, result, context, name, lineofs); }
void tTJSScriptBlock::SetText(tTJSVariant *result, const tjs_char *text, iTJSDispatch2 * context, bool isexpression) { TJS_F_TRACE("tTJSScriptBlock::SetText"); // compiles text and executes its global level scripts. // the script will be compiled as an expression if isexpressn is true. if(!text) return; if(!text[0]) return; TJS_D((TJS_W("Counting lines ...\n"))) Script = new tjs_char[TJS_strlen(text)+1]; TJS_strcpy(Script, text); // calculation of line-count tjs_char *ls = Script; tjs_char *p = Script; while(*p) { if(*p == TJS_W('\r') || *p == TJS_W('\n')) { LineVector.push_back(int(ls - Script)); LineLengthVector.push_back(int(p - ls)); if(*p == TJS_W('\r') && p[1] == TJS_W('\n')) p++; p++; ls = p; } else { p++; } } if(p!=ls) { LineVector.push_back(int(ls - Script)); LineLengthVector.push_back(int(p - ls)); } try { // parse and execute #ifdef TJS_DEBUG_PROFILE_TIME { tTJSTimeProfiler p(parsetime); #endif Parse(text, isexpression, result != NULL); #ifdef TJS_DEBUG_PROFILE_TIME } { char buf[256]; sprintf(buf, "parsing : %d", parsetime); OutputDebugString(buf); if(parsetime) { sprintf(buf, "Commit : %d (%d%%)", time_Commit, time_Commit*100/parsetime); OutputDebugString(buf); sprintf(buf, "yylex : %d (%d%%)", time_yylex, time_yylex*100/parsetime); OutputDebugString(buf); sprintf(buf, "MakeNP : %d (%d%%)", time_make_np, time_make_np*100/parsetime); OutputDebugString(buf); sprintf(buf, "GenNodeCode : %d (%d%%)", time_GenNodeCode, time_GenNodeCode*100/parsetime); OutputDebugString(buf); sprintf(buf, " PutCode : %d (%d%%)", time_PutCode, time_PutCode*100/parsetime); OutputDebugString(buf); sprintf(buf, " PutData : %d (%d%%)", time_PutData, time_PutData*100/parsetime); OutputDebugString(buf); sprintf(buf, " this_proxy : %d (%d%%)", time_this_proxy, time_this_proxy*100/parsetime); OutputDebugString(buf); sprintf(buf, "ns::Push : %d (%d%%)", time_ns_Push, time_ns_Push*100/parsetime); OutputDebugString(buf); sprintf(buf, "ns::Pop : %d (%d%%)", time_ns_Pop, time_ns_Pop*100/parsetime); OutputDebugString(buf); sprintf(buf, "ns::Find : %d (%d%%)", time_ns_Find, time_ns_Find*100/parsetime); OutputDebugString(buf); sprintf(buf, "ns::Remove : %d (%d%%)", time_ns_Remove, time_ns_Remove*100/parsetime); OutputDebugString(buf); sprintf(buf, "ns::Commit : %d (%d%%)", time_ns_Commit, time_ns_Commit*100/parsetime); OutputDebugString(buf); } } #endif #ifdef TJS_DEBUG_DISASM std::list<tTJSInterCodeContext *>::iterator i = InterCodeContextList.begin(); while(i != InterCodeContextList.end()) { ConsoleOutput(TJS_W(""), (void*)this); ConsoleOutput((*i)->GetName(), (void*)this); (*i)->Disassemble(ConsoleOutput, (void*)this); i++; } #endif // execute global level script ExecuteTopLevelScript(result, context); } catch(...) { if(InterCodeContextList.size() != 1) { if(TopLevelContext) TopLevelContext->Release(), TopLevelContext = NULL; while(ContextStack.size()) { ContextStack.top()->Release(); ContextStack.pop(); } } throw; } if(InterCodeContextList.size() != 1) { // this is not a single-context script block // (may hook itself) // release all contexts and global at this time if(TopLevelContext) TopLevelContext->Release(), TopLevelContext = NULL; while(ContextStack.size()) { ContextStack.top()->Release(); ContextStack.pop(); } } }