60#include "grammar.tab.hpp"
66#include "../utility/PEBLUtility.h"
67#include "../utility/PError.h"
68#include "../utility/rc_ptrs.h"
69#include "../utility/Defs.h"
71#include "../objects/PCustomObject.h"
72#include "../apps/Globals.h"
73#include "../devices/PEventLoop-es.h"
81#undef PEBL_DEBUG_PRINT
96#ifdef PEBL_DEBUG_PRINT
97 cout <<
"Creating Evaluator: " << mScope << endl;
112#ifdef PEBL_DEBUG_PRINT
113 cout <<
"Creating Evaluator: " << mScope << endl;
135#ifdef PEBL_DEBUG_PRINT
136 cout <<
"Deleting Evaluator: " << mScope << endl;
153#ifdef PEBL_EMSCRIPTEN
169#ifdef PEBL_DEBUG_PRINT
171 cout <<
"PDP::Type: " << node->
GetType() << endl;
184#ifdef PEBL_DEBUG_PRINT
185 cout <<
"ERROR IN GENERIC EVALUATOR::EVALUATE" << endl;
201 const PNode * node = mNodeStack.top();
203#ifdef PEBL_DEBUG_PRINT
204 cout <<
"---------------async--a--------\n";
226#ifdef PEBL_DEBUG_PRINT
227 cout <<
"---------------async--b--------Evaluating OpNode ["<< node->
GetOp() <<
"] of Type: " << node->
GetOpName() <<
"------------\n";
233 switch(node->
GetOp())
258 mNodeStack.push(variablenode);
259 mNodeStack.push(tail);
260 mNodeStack.push(node2);
266 case PEBL_ASSIGN_TAIL:
273 const PNode * node1 = mNodeStack.top();
280#ifdef PEBL_DEBUG_PRINT
281 cout <<
"Initial Variable Name: [" << v1.
GetVariableName() <<
"]" << endl;
338 mNodeStack.push(tail);
339 mNodeStack.push(node2);
340 mNodeStack.push(node1);
372 mNodeStack.push(tail);
373 mNodeStack.push(node2);
374 mNodeStack.push(node1);
379 case PEBL_DIVIDE_TAIL:
401 mNodeStack.push(tail);
402 mNodeStack.push(node2);
403 mNodeStack.push(node1);
406 case PEBL_MULTIPLY_TAIL:
427 mNodeStack.push(tail);
428 mNodeStack.push(node2);
429 mNodeStack.push(node1);
433 case PEBL_POWER_TAIL:
456 mNodeStack.push(tail);
457 mNodeStack.push(node2);
458 mNodeStack.push(node1);
462 case PEBL_SUBTRACT_TAIL:
484 mNodeStack.push(tail);
485 mNodeStack.push(node1);
505 mNodeStack.push(finish);
506 mNodeStack.push(node->
GetLeft());
530 mNodeStack.push(tail);
531 mNodeStack.push(node1);
551 mNodeStack.push(finish);
552 mNodeStack.push(node->
GetLeft());
577 mNodeStack.push(tail);
578 mNodeStack.push(node1);
611 mNodeStack.push(codeblock);
612 mNodeStack.push(tail);
613 mNodeStack.push(node1);
627 mNodeStack.push(tail2);
667 mNodeStack.push(node2);
668 mNodeStack.push(node1);
697 mNodeStack.push(tail);
698 mNodeStack.push(node1);
711 case PEBL_LAMBDAFUNCTION:
760 vector <Variant>::iterator p = tmp->
Begin();
772 bool hasdefault =
false;
773 if(((
OpNode*)(((
OpNode*)node1)->GetLeft()))->GetOp()==PEBL_VARPAIR)
788 mNodeStack.push(defaultNode);
789 while(mNodeStack.size() > 0)
798 vdef = ((
DataNode*)defaultNode)->GetValue();
835 string message =
"Too few arguments passed to function [" + mScope +
"].";
837 if(mScope ==
"Start")
838 message +=
" (Make sure Start function has only one variable).";
850 string message = string(
"Too many arguments passed to function [" + mScope +
"].");
852 if(mScope ==
"Start") message +=
" (Make sure Start function has a variable).";
861 mNodeStack.push(node2);
868 case PEBL_LIBRARYFUNCTION:
888 const unsigned int min = ((
DataNode*)(node0->
GetLeft()))->GetValue().GetInteger();
889 const unsigned int max = ((
DataNode*)(node0->
GetRight()))->GetValue().GetInteger();
925 cerr <<
"UNHANDLED ELSE CASE. NOT A LIST\n" ;
931 if(numargs < min || numargs > max)
936 Variant(
"Incorrect number of arguments.. Wanted between ")+
982 mNodeStack.push(tail);
983 mNodeStack.push(node1);
987 case PEBL_FUNCTION_TAIL1:
1011 if(plist && plist->
Length() > 0)
1044#ifdef PEBL_DEBUG_PRINT
1045 cout <<
"Calling a function with argument list. " << endl;
1055 mNodeStack.push(node2);
1064 mNodeStack.push(tail2);
1069 case PEBL_FUNCTION_TAIL2:
1079#ifdef PEBL_DEBUG_PRINT
1080 cout <<
"In function_tail2 OpNode ["<< node2->
GetOp() <<
"] of Type: " << node2->
GetOpName() <<
"------------\n";
1084 switch(((
OpNode*)node2)->GetOp())
1089 case PEBL_LIBRARYFUNCTION:
1092 mNodeStack.push(node2);
1098 case PEBL_LAMBDAFUNCTION:
1106 mVariableMapStack.push(mLocalVariableMap);
1110 mScopeStack.push(mScope);
1122 mNodeStack.push(tail);
1125 mNodeStack.push(node2);
1141 case PEBL_FUNCTION_TAIL_LIBFUNCTION:
1150 if(mScopeStack.size() == 0) {
1154 mScope = mScopeStack.top();
1157 if(mVariableMapStack.size() == 0) {
1161 mLocalVariableMap = mVariableMapStack.top();
1162 mVariableMapStack.pop();
1203 mNodeStack.push(node);
1204 mNodeStack.push(tail);
1205 mNodeStack.push(node1);
1210 case PEBL_WHILE_TAIL:
1240 mNodeStack.push(whiletail2);
1241 mNodeStack.push(node2);
1259 case PEBL_WHILE_TAIL2:
1296 mNodeStack.push(codeblock);
1297 mNodeStack.push(tail2);
1298 mNodeStack.push(codeblock);
1299 mNodeStack.push(tail);
1300 mNodeStack.push(node1);
1308 case PEBL_LOOP_TAIL1:
1314 const long unsigned int index = (
const long unsigned int)
Pop();
1382 case PEBL_LOOP_TAIL2:
1406 const PNode * codeblock = mNodeStack.top();
1417 mNodeStack.push(tail2);
1418 mNodeStack.push(codeblock);
1419 mNodeStack.push(tail1);
1430 case PEBL_VARIABLEDATUM:
1450 mNodeStack.push(node2);
1475 mNodeStack.push(node1);
1506 mNodeStack.push(node1);
1546 mNodeStack.push(node2);
1552 mNodeStack.push(tail);
1556 mNodeStack.push(node1);
1561 case PEBL_LISTITEM_TAIL:
1593 std::reverse(tmpList->
Begin(),tmpList->
End());
1611 mNodeStack.push(tail);
1612 mNodeStack.push(node2);
1613 mNodeStack.push(node1);
1639 mNodeStack.push(tail);
1640 mNodeStack.push(node2);
1641 mNodeStack.push(node1);
1665 mNodeStack.push(tail);
1666 mNodeStack.push(node2);
1667 mNodeStack.push(node1);
1694 mNodeStack.push(tail);
1695 mNodeStack.push(node2);
1696 mNodeStack.push(node1);
1721 mNodeStack.push(tail);
1722 mNodeStack.push(node2);
1723 mNodeStack.push(node1);
1746 mNodeStack.push(tail);
1747 mNodeStack.push(node2);
1748 mNodeStack.push(node1);
1764 case PEBL_STATEMENTS:
1776#ifdef PEBL_DEBUG_PRINT
1777 cout <<
"Checking a PEBL_STATEMENTS: " <<
GetStackDepth() << endl;
1807 mNodeStack.push(tail);
1808 mNodeStack.push(node->
GetLeft());
1815 case PEBL_STATEMENTS_TAIL1:
1852#ifdef PEBL_DEBUG_PRINT
1853 cout <<
"PEBL_BREAK: pushing break onto stack.\n";
1872 mNodeStack.push(node1);
1899#ifdef PEBL_DEBUG_PRINT
1900 cout <<
"-------------------------";
1901 cout <<
"Evaluating DataNode of Value: " << node->
GetValue() << endl;;
1955#ifdef PEBL_DEBUG_PRINT
1956 cout <<
"Evaluating a normal Variant: ";
2040#ifdef PEBL_DEBUG_PRINT
2041 cout <<
"Calling a function with argument list: " << endl;
2053 switch(((
OpNode*)node2)->GetOp())
2055 case PEBL_LAMBDAFUNCTION:
2084 cout <<
"Adding dummy value to end of null function\n";
2097 case PEBL_LIBRARYFUNCTION:
2117#ifdef PEBL_DEBUG_PRINT
2118 cout <<
"Pushing Stack: depth: "<< mStack.size() <<
"-->" <<
GetStackDepth() + 1;
2121 if (mStack.size() > mStackMax)
2126#ifdef PEBL_DEBUG_PRINT
2127 if(mStack.size())cout <<
" [" << mStack.top() <<
"] is on top.\n";
2136#ifdef PEBL_DEBUG_PRINT
2137 cout <<
"Popping Stack: depth: "<< mStack.size() <<
"-->" <<
GetStackDepth() - 1;
2139 if(mStack.size() <=0 )
2146#ifdef PEBL_DEBUG_PRINT
2147 if(mStack.size())cout <<
" [" << mStack.top() <<
"] is on top.\n";
2156#ifdef PEBL_DEBUG_PRINT
2157 cout <<
"Peeking at top of stack: "<< mStack.size() << endl;
2159 if(mStack.size() <=0 )
2178 mNodeStack.push(node);
const Variant & GetValue() const
This class has got everything you need to evaluate stuff.
static const PNode * gEvalNode
void NodeStackPush(const PNode *node)
static PCallStack gCallStack
static PEventLoop * mEventLoop
bool IsVariableName(Variant v)
static VariableMap gGlobalVariableMap
static FunctionMap mFunctionMap
Initiate some static member data.
void CallFunction(const OpNode *node)
PNode * GetFunction(const std::string &funcname)
std::string GetOpName() const
void Push(const PNode *node)
counted_ptr< PEBLObjectBase > GetObject() const
bool IsCustomObject() const
This class simply represent an abstract text-based object.
virtual ObjectValidationError ValidateProperty(std::string, Variant v) const
virtual Variant GetProperty(std::string) const
std::vector< Variant >::const_iterator End() const
std::vector< Variant >::const_iterator Begin() const
Variant Nth(unsigned int n)
unsigned long Length() const
void PushBack(const Variant &v)
int GetLineNumber() const
PNODE_TYPE GetType() const
Access mType data.
std::string GetFilename() const
std::string GetFunctionName() const
bool Exists(const std::string &varname)
void AddVariable(const std::string &varname, const Variant &val)
Variant RetrieveValue(const std::string &varname)
bool IsComplexData() const
bool IsGlobalVariable() const
std::string GetVariablePropertyName() const
pFunc GetFunctionPointer() const
bool IsStackSignal() const
std::string GetVariableName() const
std::string GetString() const
StackSignalType GetSignal() const
PComplexData * GetComplexData() const
bool IsLocalVariable() const
std::string GetVariableBaseName() const
std::string GetFunctionName() const
VariantDataType GetDataType() const
This returns the type as an enum.
Variant ResolvePropertyChain(Variant obj, const std::string &propertyChain)
void SetPropertyChain(Variant obj, const std::string &propertyChain, Variant value)
void ExitQuietly(const std::string &message, int exitCode=0)
void AssertType(Variant v, int type, const std::string &outsidemessage)
void SignalFatalError(const std::string &message)