00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef skINTERPRETER_H
00022 #define skINTERPRETER_H
00023
00024 #include "skRValueTable.h"
00025 #include "skiExecutable.h"
00026 #include "skNull.h"
00027 #include "skParseNode.h"
00028 #include "skExecutableIterator.h"
00029 #include "skRValueTable.h"
00030
00031 class CLASSEXPORT skRValueArray;
00032 class CLASSEXPORT skExprNode;
00033 class CLASSEXPORT skStringList;
00034 class CLASSEXPORT skMethodDefNode;
00035 class CLASSEXPORT skTraceCallback;
00036 class CLASSEXPORT skStatementStepper;
00037
00038 #ifndef EXCEPTIONS_DEFINED
00039 #include "skScriptError.h"
00040 #endif
00041
00042 class CLASSEXPORT skStackFrame;
00043
00051 class CLASSEXPORT skInterpreter : public skExecutable
00052 {
00053 public:
00054
00055
00056
00057
00069 IMPORT_C skMethodDefNode * parseString(const skString& location,const skString& code,skExecutableContext& ctxt);
00082 IMPORT_C skMethodDefNode * parseExternalParams(const skString& location,skStringList& paramNames,const skString& code,skExecutableContext& ctxt);
00097 IMPORT_C void executeString(const skString& location,skiExecutable * obj,const skString& code,skRValueArray& args,skRValue& return_value,skMethodDefNode ** parseTree,skExecutableContext& ctxt);
00098
00113 IMPORT_C void executeStringExternalParams(const skString& location,skiExecutable * obj,skStringList& paramNames,const skString& code,skRValueArray& args,skRValue& r,skMethodDefNode ** keepParseTree,skExecutableContext& ctxt);
00114
00126 IMPORT_C void executeParseTree(const skString& location,skiExecutable * obj,skMethodDefNode * parseTree,skRValueArray& args,skRValue& return_value,skExecutableContext& ctxt);
00127
00128
00141 IMPORT_C void evaluateExpression(const skString& location,skiExecutable * obj,
00142 const skString& expression,skRValueTable& vars,
00143 skRValue& return_value,skExecutableContext& ctxt);
00156 #ifdef EXECUTE_PARSENODES
00157 IMPORT_C void evaluateExpression(const skString& location,skiExecutable * obj,
00158 skExprNode * expression,skRValueTable& vars,
00159 skRValue& return_value,skExecutableContext& ctxt);
00160 #else
00161 IMPORT_C void evaluateExpression(const skString& location,skiExecutable * obj,
00162 skCompiledCode& code,skRValueTable& vars,
00163 skRValue& return_value,skExecutableContext& ctxt);
00164 #endif
00165
00166
00167
00168
00169
00176 IMPORT_C void addGlobalVariable(const skString& name,const skRValue& value);
00181 IMPORT_C void removeGlobalVariable(const skString& name);
00182 #ifdef __SYMBIAN32__
00183
00190 IMPORT_C void addGlobalVariable(const TDesC& name,const skRValue& value);
00196 IMPORT_C void removeGlobalVariable(const TDesC& name);
00197 #endif
00198
00205 IMPORT_C bool findGlobalVariable(const skString& name,skRValue& return_value);
00206
00211 IMPORT_C const skRValueTable& getGlobalVariables() const;
00212
00213
00214
00215
00216
00221 virtual IMPORT_C bool setValue(const skString& s,const skString& attribute,const skRValue& v);
00227 virtual IMPORT_C bool getValue(const skString& s,const skString& attribute,skRValue& v);
00237 virtual IMPORT_C bool method(const skString& method_name,skRValueArray& arguments,skRValue& return_value,skExecutableContext& ctxt);
00238
00244 virtual void getInstanceVariables(skRValueTable& table);
00245
00246
00247
00248
00249
00253 IMPORT_C void trace(const skString& msg);
00257 IMPORT_C void trace(const Char * msg);
00261 IMPORT_C void setTraceCallback(skTraceCallback * callback);
00262
00266 IMPORT_C void setStatementStepper(skStatementStepper * stepper);
00267
00274 IMPORT_C void runtimeError(skStackFrame& ctxt,const skString& msg);
00281 IMPORT_C void runtimeError(skStackFrame& ctxt,const Char * msg);
00282
00283
00284
00285
00286
00292 IMPORT_C skInterpreter();
00296 virtual IMPORT_C ~skInterpreter();
00302 IMPORT_C void init();
00303
00304 inline skNull& getNull();
00305
00306 private:
00307
00308
00309
00310
00311
00315 skInterpreter(const skInterpreter&);
00319 skInterpreter& operator=(const skInterpreter&);
00320
00321 #ifdef EXECUTE_PARSENODES
00322
00333 skExprNode * parseExpression(const skString& location,const skString& expression,skExecutableContext& ctxt);
00334 #else
00335
00346 skCompiledExprNode * parseExpression(const skString& location,const skString& expression,skExecutableContext& ctxt);
00347 #endif
00348
00349
00355 #ifdef EXECUTE_PARSENODES
00356 skRValue evaluate(skStackFrame& frame,skExprNode * n);
00357 #else
00358 skRValue evaluate(skStackFrame& frame,skCompiledCode& code,USize& pc);
00359 #endif
00360
00365 #ifdef EXECUTE_PARSENODES
00366 skRValue evalMethod(skStackFrame& frame,skIdListNode * ids);
00367 #else
00368 skRValue evalMethod(skStackFrame& frame,skCompiledCode& code,USize& pc);
00369 #endif
00370
00380 #ifdef EXECUTE_PARSENODES
00381 void makeMethodCall(skStackFrame& frame,skRValue& robject,const skString& method_name,skExprNode * array_index, const skString& attribute,skExprListNode * exprs,skRValue& ret);
00382 #else
00383 void makeMethodCall(skStackFrame& frame,skCompiledCode& code,USize& pc,skRValue& robject,const skString& method_name,bool has_array_index,const skString& attribute, skRValue& ret);
00384 #endif
00385
00386
00387
00393 #ifdef EXECUTE_PARSENODES
00394 void executeAssignStat(skStackFrame& frame,skAssignNode * n);
00395 #else
00396 void executeAssignStat(skStackFrame& frame,skCompiledCode& code,USize& pc,skRValue& r);
00397 #endif
00398
00399
00400
00408 #ifdef EXECUTE_PARSENODES
00409 bool executeStats(skStackFrame& frame,skStatListNode * n,skRValue& r);
00410 #else
00411
00421 bool executeStats(skStackFrame& frame,skCompiledCode& code,USize& pc,int& num_bytes,bool execute_bytes,skRValue& r);
00422 #endif
00423
00430 #ifdef EXECUTE_PARSENODES
00431 bool executeReturnStat(skStackFrame& frame,skReturnNode * n,skRValue& r);
00432 #else
00433 bool executeReturnStat(skStackFrame& frame,skCompiledCode& code,USize& pc,skRValue& r,bool has_expr);
00434 #endif
00435
00443 #ifdef EXECUTE_PARSENODES
00444 bool executeIfStat(skStackFrame& frame,skIfNode * n,skRValue& r);
00445 #else
00446 bool executeIfStat(skStackFrame& frame,skCompiledCode& code,USize& pc,skRValue& r,bool has_else);
00447 #endif
00448
00456 #ifdef EXECUTE_PARSENODES
00457 bool executeWhileStat(skStackFrame& frame,skWhileNode * n,skRValue& r);
00458 #else
00459 bool executeWhileStat(skStackFrame& frame,skCompiledCode& code,USize& pc,skRValue& r);
00460 #endif
00461
00469 #ifdef EXECUTE_PARSENODES
00470 bool executeSwitchStat(skStackFrame& frame,skSwitchNode * n,skRValue& r);
00471 #else
00472 bool executeSwitchStat(skStackFrame& frame,skCompiledCode& code,USize& pc,skRValue& r,bool has_default);
00473 #endif
00474
00482 #ifdef EXECUTE_PARSENODES
00483 bool executeForEachStat(skStackFrame& frame,skForEachNode * n,skRValue& r);
00484 #else
00485 bool executeForEachStat(skStackFrame& frame,skCompiledCode& code,USize& pc,skRValue& r,USize id_index);
00486 #endif
00487
00495 #ifdef EXECUTE_PARSENODES
00496 bool executeForStat(skStackFrame& frame,skForNode * n,skRValue& r);
00497 #else
00498 bool executeForStat(skStackFrame& frame,skCompiledCode& code,USize& pc,skRValue& r,bool has_step);
00499 #endif
00500
00501
00502
00509 void addLocalVariable(skRValueTable& var,const skString& name,skRValue value);
00517 inline skString checkIndirectId(skStackFrame& frame,const skString& name);
00526 #ifdef EXECUTE_PARSENODES
00527 skRValue findValue(skStackFrame& frame,const skString& name,skExprNode * array_index,const skString& attribute);
00528 #else
00529 skRValue findValue(skStackFrame& frame,const skString& name,const skRValue * array_index,const skString& attribute);
00530 #endif
00531
00537 #ifdef EXECUTE_PARSENODES
00538 void followIdList(skStackFrame& frame,skIdListNode * idList,skRValue& object);
00539 #else
00540 void followIdList(skStackFrame& frame,skCompiledCode& code,USize& pc,int num_ids,skRValue& object);
00541 #endif
00542
00543
00553 #ifdef EXECUTE_PARSENODES
00554 bool extractFieldArrayValue(skStackFrame& frame,skRValue& robject,const skString& field_name,skExprNode * array_index,const skString& attrib,skRValue& ret);
00555 #else
00556 bool extractFieldArrayValue(skStackFrame& frame,skRValue& robject,const skString& field_name,const skRValue& array_index,const skString& attrib,skRValue& ret);
00557 #endif
00558
00565 #ifdef EXECUTE_PARSENODES
00566 bool extractArrayValue(skStackFrame& frame,skRValue& robject,skExprNode * array_index,const skString& attrib,skRValue& ret) ;
00567 #else
00568 bool extractArrayValue(skStackFrame& frame,skRValue& robject,const skRValue& array_index,const skString& attrib,skRValue& ret) ;
00569 #endif
00570
00578 bool extractValue(skStackFrame& frame,skRValue& robject,const skString& name,const skString& attrib,skRValue& ret) ;
00579
00588 #ifdef EXECUTE_PARSENODES
00589 bool insertArrayValue(skStackFrame& frame,skRValue& robject, skExprNode * array_index,const skString& attr,const skRValue& value);
00590 #else
00591 bool insertArrayValue(skStackFrame& frame,skCompiledCode& code,USize& pc,skRValue& robject, const skString& attr,const skRValue& value);
00592 #endif
00593
00601 bool insertValue(skStackFrame& frame,skRValue& robject,const skString& name, const skString& attr,const skRValue& value);
00602
00603 #ifndef EXECUTE_PARSENODES
00604 void getIdNode(skCompiledCode& code,USize& pc,skString& id,bool& has_array,bool& is_method);
00605 void getIdNodes(skCompiledCode& code,USize& pc,int& num_ids,skString& attribute);
00606 #endif
00607
00608
00610 skRValueTable m_GlobalVars;
00612 bool m_Tracing;
00614 skTraceCallback * m_TraceCallback;
00616 skStatementStepper * m_StatementStepper;
00620 skNull m_Null;
00621 };
00622
00623 inline skString skInterpreter::checkIndirectId(skStackFrame& frame,const skString& name)
00624
00625 {
00626
00627 skString ret=name;
00628 if (name.at(0)=='@'){
00629 ret=name.substr(1,name.length()-1);
00630 skRValue new_name=findValue(frame,ret,0,skString());
00631 ret=new_name.str();
00632 }
00633 return ret;
00634 }
00635
00636 inline skNull& skInterpreter::getNull()
00637
00638 {
00639 return m_Null;
00640 }
00641
00642 xskNAMED_LITERAL(OnANonObject,skSTR(" on a non-object\n"));
00643
00644 #endif
00645
00646