00001 00002 00003 00004 00005 00006
00007
00008 #include "skParseNode.h"
00009 #include "skExecutableIterator.h"
00010 #include "skRValueTable.h"
00011
00015 class P_Interpreter
00016 {
00017 public:
00018 P_Interpreter();
00019 ~P_Interpreter();
00020
00021
00022
00023
00024 skRValue evaluate(skiExecutable * obj,skRValueTable& var,skExprNode * n);
00025 skRValue evalMethod(skiExecutable * obj,skRValueTable& var,skIdListNode * ids);
00026 void makeMethodCall(skiExecutable * obj,skRValueTable& var,skRValue& robject,const skString& method_name,skExprNode * array_index, const skString& attribute,skExprListNode * exprs,skRValue& ret);
00027
00028
00029
00030 void executeAssignStat(skiExecutable * obj,skRValueTable& var,skAssignNode * n);
00031
00032
00033
00034 bool executeStat(skiExecutable * obj,skRValueTable& var,skStatNode * pstat,skRValue& r);
00035 bool executeStats(skiExecutable * obj,skRValueTable& var,skStatListNode * n,skRValue& r);
00036 bool executeReturnStat(skiExecutable * obj,skRValueTable& var,skReturnNode * n,skRValue& r);
00037 bool executeIfStat(skiExecutable * obj,skRValueTable& var,skIfNode * n,skRValue& r);
00038 bool executeWhileStat(skiExecutable * obj,skRValueTable& var,skWhileNode * n,skRValue& r);
00039 bool executeSwitchStat(skiExecutable * obj,skRValueTable& var,skSwitchNode * n,skRValue& r);
00040 bool executeForEachStat(skiExecutable * obj,skRValueTable& var,skForEachNode * n,skRValue& r);
00041 bool executeForStat(skiExecutable * obj,skRValueTable& var,skForNode * n,skRValue& r);
00042
00043
00044
00045 void addLocalVariable(skRValueTable& var,const skString& name,skRValue value);
00046 skString checkIndirectId(skiExecutable * obj,skRValueTable& var,const skString& name);
00047
00048 skRValue findValue(skiExecutable * obj,skRValueTable& var,const skString& name,skExprNode * array_index,const skString& attribute);
00049 void runtimeError(const skString& s);
00050 void followIdList(skiExecutable * obj,skRValueTable& var,skIdListNode * idList,skRValue& object);
00051 void trace(const skString& s);
00052
00053
00054 bool extractFieldArrayValue(skiExecutable * obj,skRValueTable& var,skRValue& robject,const skString& field_name,skExprNode * array_index,const skString& attrib,skRValue& ret);
00055
00056 bool extractArrayValue(skiExecutable * obj,skRValueTable& var,skRValue& robject,skExprNode * array_index,const skString& attrib,skRValue& ret) ;
00057
00058 bool extractValue(skRValue& robject,const skString& name,const skString& attrib,skRValue& ret) ;
00059
00060
00061 bool insertArrayValue(skiExecutable * obj,skRValueTable& var,skRValue& robject, skExprNode * array_index,const skString& attr,const skRValue& value);
00062
00063 bool insertValue(skRValue& robject,const skString& name, const skString& attr,const skRValue& value);
00064
00065
00066 skRValueTable m_GlobalVars;
00067 unsigned int m_StackDepth;
00068 bool m_Tracing;
00069
00070 skTraceCallback * m_TraceCallback;
00071 skStatementStepper * m_StatementStepper;
00072 skString m_Location;
00073 int m_LineNum;
00074 THREAD static skInterpreter * g_GlobalInterpreter;
00075
00076 };
00077
00078
00079 inline skString P_Interpreter::checkIndirectId(skiExecutable * obj,skRValueTable& var,const skString& name)
00080
00081 {
00082
00083 skString ret=name;
00084 if (name.at(0)=='@'){
00085 ret=name.substr(1,name.length()-1);
00086 skRValue new_name=findValue(obj,var,ret,0,skString());
00087 ret=new_name.str();
00088 }
00089 return ret;
00090 }