15#include "ExprConfig.h"
33 std::cerr <<
"KSeExpr Debug Mode Enabled " <<
41#if defined(SEEXPR_ENABLE_LLVM)
42 if (
char* env = getenv(
"SE_EXPR_EVAL")) {
43 if (
Expression::debugging) std::cerr <<
"Overriding SeExpr Evaluation Default to be " << env << std::endl;
79 std::cerr <<
"return slot " <<
_returnSlot << std::endl;
162 int tempStartPos, tempEndPos;
171#ifdef SEEXPR_PERFORMANCE
178 std::string _parseError;
196 std::cerr <<
"Eval strategy is interpreter" << std::endl;
204 if (dimWanted > dimHave) {
216 std::cerr <<
"Eval strategy is llvm" << std::endl;
233 std::vector<int> lines;
237 if (*
p ==
'\n') lines.push_back(
static_cast<int>(
p - start));
240 lines.push_back(
static_cast<int>(
p - start));
242 std::stringstream sstream;
243 for (
unsigned int i = 0; i <
_errors.size(); i++) {
244 int* bound = std::lower_bound(&*lines.begin(), &*lines.end(),
_errors[i].startPos);
245 int line =
static_cast<int>(bound - &*lines.begin() + 1);
246 int lineStart = line == 1 ? 0 : lines[line - 1];
247 int col =
_errors[i].startPos - lineStart;
248 sstream <<
" Line " << line <<
" Col " << col <<
" - " <<
_errors[i].error << std::endl;
250 _parseError = std::string(sstream.str());
254 std::cerr <<
"ending with isValid " <<
_isValid << std::endl;
255 std::cerr <<
"parse error \n" << _parseError << std::endl;
279 static double noCrash[16] = {};
290 double* destBase =
reinterpret_cast<double**
>(varBlock->
data())[outputVarBlockOffset];
291 for (
size_t i = rangeStart; i < rangeEnd; i++) {
293 const double* f =
evalFP(varBlock);
294 for (
int k = 0; k < dim; k++) {
295 destBase[dim * i + k] = f[k];
299 _llvmEvaluator->evalMultiple(varBlock, outputVarBlockOffset, rangeStart, rangeEnd);
static constexpr std::array< int, 514 > p
static void init()
call to define built-in funcs
bool isLifetimeConstant() const
validity check: type is not an error
ExprType & Error()
Mutate this into an error type.
static bool valuesCompatible(const ExprType &a, const ExprType &b)
Checks if value types are compatible.
const VarBlockCreator * _varBlockCreator
void evalMultiple(VarBlock *varBlock, int outputVarBlockOffset, size_t rangeStart, size_t rangeEnd) const
Evaluate multiple blocks.
ErrorCode _parseErrorCode
void setExpr(const std::string &e)
static bool debugging
Whether to debug expressions.
std::set< std::string > _vars
bool usesFunc(const std::string &name) const
void parseIfNeeded() const
EvaluationStrategy _evaluationStrategy
Expression(EvaluationStrategy be=Expression::defaultEvaluationStrategy)
void addError(const ErrorCode error, const std::vector< std::string > ids, const int startPos, const int endPos) const
std::set< std::string > _funcs
bool usesVar(const std::string &name) const
Interpreter * _interpreter
std::vector< std::string > _parseErrorIds
const double * evalFP(VarBlock *varBlock=nullptr) const
void prepIfNeeded() const
EvaluationStrategy
Types of evaluation strategies that are available.
void debugPrintParseTree() const
void setContext(const Context &context)
ExprVarEnvBuilder _envBuilder
void debugPrintInterpreter() const
const ExprType & returnType() const
std::vector< std::pair< int, int > > _comments
const Context & context() const
const char * evalStr(VarBlock *varBlock=nullptr) const
std::vector< Error > _errors
void setVarBlockCreator(const VarBlockCreator *varBlockCreator)
ExprType _desiredReturnType
std::vector< std::string > _threadUnsafeFunctionCalls
void setDesiredReturnType(const ExprType &type)
static EvaluationStrategy defaultEvaluationStrategy
What evaluation strategy to use by default.
void debugPrintLLVM() const
LLVMEvaluator * _llvmEvaluator
A class that lets you register for the variables used by one or more expressions.
A thread local evaluation context. Just allocate and fill in with data.
char ** data()
Raw data of the data block pointer (used by compiler)
int indirectIndex
indirect index to add to pointer based data
std::vector< char * > s
copy of Interpreter's str data
std::vector< double > d
copy of Interpreter's double data
bool threadSafe
if true, interpreter's data will be copied to this instance before evaluation.
void walk(T_NODE *examinee)
Preorder walk.
static Expression::EvaluationStrategy chooseDefaultEvaluationStrategy()
Walker< true > ConstWalker
bool ExprParse(KSeExpr::ExprNode *&parseTree, KSeExpr::ErrorCode &errorCode, std::vector< std::string > &errorIds, int &errorStart, int &errorEnd, std::vector< std::pair< int, int > > &_comments, const KSeExpr::Expression *expr, const char *str, bool wantVec=true)
T_FUNCTYPE getTemplatizedOp(int i)
Return the function f encapsulated in class T for the dynamic i converted to a static d.
@ ExpressionIncompatibleTypes
"Expression generated type " << _parseTree->type() << " incompatible with desired type " << _desiredR...