56#include "grammar.tab.hpp"
63#include "../utility/PError.h"
64#include "../utility/rc_ptrs.h"
65#include "../utility/Defs.h"
67#include "../objects/PCustomObject.h"
68#include "../devices/PEventLoop.h"
71#include <emscripten.h>
74#undef PEBL_DEBUG_PRINT
88#ifdef PEBL_DEBUG_PRINT
89 cout <<
"Creating Evaluator: " << mScope << endl;
96 gCallStack.Push(gEvalNode);
106#ifdef PEBL_DEBUG_PRINT
107 cout <<
"Creating Evaluator: " << mScope << endl;
120 gCallStack.Push(gEvalNode);
132#ifdef PEBL_DEBUG_PRINT
133 cout <<
"Deleting Evaluator: " << mScope << endl;
159#ifdef PEBL_DEBUG_PRINT
161 cout <<
"PDP::Type: " << node->
GetType() << endl;
162 cout <<
"PDP::Type: " << node->
GetType() << endl;
175#ifdef PEBL_DEBUG_PRINT
176 cout <<
"ERROR IN GENERIC EVALUATOR::EVALUATE" << endl;
189 unsigned long int numargs = 0;
196#ifdef PEBL_DEBUG_PRINT
197 cout <<
"-------------------------Evaluating OpNode ["<< node->
GetOp() <<
"] of Type: " << node->
GetOpName() <<
"------------\n";
202 switch(node->
GetOp())
231#ifdef PEBL_DEBUG_PRINT
232 cout <<
"Initial Variable Name: [" << v1.
GetVariableName() <<
"]" << endl;
499 case PEBL_LAMBDAFUNCTION:
551 vector <Variant>::iterator p = arglist->
Begin();
563 bool hasdefault =
false;
564 if(((
OpNode*)(((
OpNode*)node1)->GetLeft()))->GetOp()==PEBL_VARPAIR)
602 if(p != arglist->
End())
628 string message =
"Too few arguments passed to function [" + mScope +
"].";
630 if(mScope ==
"Start")
631 message +=
" (Make sure Start function has only one variable).";
640 if(p != arglist->
End())
643 string message = string(
"");
645 if(mScope ==
"Start")
646 message +=
"Start() function must be Start(p)).";
648 message +=
"Too many arguments passed to function [" + mScope +
"].";
662 case PEBL_LIBRARYFUNCTION:
677 const unsigned int min = ((
DataNode*)(node0->
GetLeft()))->GetValue().GetInteger();
678 const unsigned int max = ((
DataNode*)(node0->
GetRight()))->GetValue().GetInteger();
721 cout <<
"UNHANDLED ELSE CASE. NOT A LIST\n" ;
729 if(numargs < min || numargs > max)
734 Variant(
"Incorrect number of arguments.. Wanted between ")+
738 cout << message << endl;
852 vector<Variant>::const_iterator p = tmp->
Begin();
853 vector<Variant>::const_iterator end = tmp->
End();
893 case PEBL_VARIABLEDATUM:
1048 std::reverse(tmpList->
Begin(),tmpList->
End());
1158 case PEBL_STATEMENTS:
1164#ifdef PEBL_DEBUG_PRINT
1165 cout <<
"Checking a PEBL_STATEMENTS: " <<
GetStackDepth() << endl;
1223#ifdef PEBL_DEBUG_PRINT
1224 cout <<
"PEBL_BREAK: pushing break onto stack.\n";
1279#ifdef PEBL_DEBUG_PRINT
1280 cout <<
"-------------------------";
1281 cout <<
"Evaluating DataNode of Value: " << node->
GetValue() << endl;;
1334#ifdef PEBL_DEBUG_PRINT
1335 cout <<
"Evaluating a normal Variant: ";
1415#ifdef PEBL_DEBUG_PRINT
1416 cout <<
"Calling a function with argument list: " << endl;
1428 switch(((
OpNode*)node2)->GetOp())
1430 case PEBL_LAMBDAFUNCTION:
1459 cout <<
"Adding dummy value to end of null function\n";
1472 case PEBL_LIBRARYFUNCTION:
1488#ifdef PEBL_DEBUG_PRINT
1489 cout <<
"Pushing Stack: depth: "<< mStack.size() <<
"-->" <<
GetStackDepth() + 1;
1492 if (mStack.size() > mStackMax)
1497#ifdef PEBL_DEBUG_PRINT
1498 if(mStack.size())cout <<
" [" << mStack.top() <<
"] is on top.\n";
1507#ifdef PEBL_DEBUG_PRINT
1508 cout <<
"Popping Stack: depth: "<< mStack.size() <<
"-->" <<
GetStackDepth() - 1;
1510 if(mStack.size() <=0 )
1517#ifdef PEBL_DEBUG_PRINT
1518 if(mStack.size())cout <<
" [" << mStack.top() <<
"] is on top.\n";
1527#ifdef PEBL_DEBUG_PRINT
1528 cout <<
"Peeking at top of stack: "<< mStack.size() << endl;
1530 if(mStack.size() <=0 )
1535 return mStack.top();
const Variant & GetValue() const
This class has got everything you need to evaluate stuff.
bool Evaluate(const PNode *node)
static const PNode * gEvalNode
static PCallStack gCallStack
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
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
unsigned long Length() const
void PushBack(const Variant &v)
int GetLineNumber() const
PNODE_TYPE GetType() const
Access mType data.
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 AssertType(Variant v, int type, const std::string &outsidemessage)
void SignalFatalError(const std::string &message)