17#ifndef _Interpreter_h_
18#define _Interpreter_h_
30 static int f(
int* opData,
double* fp,
char** c, std::vector<int>& callStack) {
31 int posIn = opData[0];
32 int posOut = opData[1];
33 for (
int k = posOut; k < posOut + d; k++) fp[k] = fp[posIn];
43 std::vector<double>
d;
50 typedef std::map<const ExprLocalVar*, int>
VarToLoc;
54 typedef int (*
OpF)(
int*,
double*,
char**, std::vector<int>&);
56 std::vector<std::pair<OpF, int> >
ops;
70 int nextPC() {
return static_cast<int>(
ops.size()); }
75 assert(
false &&
"addOp called within another addOp");
78 int pc =
static_cast<int>(
ops.size());
79 ops.push_back(std::make_pair(op,
static_cast<int>(
opData.size())));
83 void endOp(
bool execute =
true) {
88 int pc =
static_cast<int>(
ops.size()) - 1;
89 const std::pair<OpF, int>& op =
ops[pc];
90 int* opCurr = &
opData[0] + op.second;
91 pc += op.first(opCurr, fp, str,
callStack);
98 int ret =
static_cast<int>(
opData.size());
105 int ret =
static_cast<int>(
d.size());
106 for (
int k = 0; k < n; k++)
d.push_back(0);
112 int ret =
static_cast<int>(
s.size());
120 void print(
int pc = -1)
const;
162 assert(
false &&
"Invalid dynamic parameter (not supported template)");
void setPCStart(int pcStart)
int allocFP(int n)
! Allocate a floating point set of data of dimension n
int addOp(OpF op)
! adds an operator to the program (pointing to the data at the current location)
int(* OpF)(int *, double *, char **, std::vector< int > &)
Op function pointer arguments are (int* currOpData,double* currD,char** c,std::stack<int>& callStacku...
std::vector< std::pair< OpF, int > > ops
void eval(VarBlock *varBlock, bool debug=false)
Evaluate program.
int addOperand(int param)
! Adds an operand. Note this should be done after doing the addOp!
int allocPtr()
Allocate a pointer location (can be anything, but typically space for char*)
int nextPC()
Return the position that the next instruction will be placed at.
std::map< const ExprLocalVar *, int > VarToLoc
Not needed for eval only building.
void endOp(bool execute=true)
std::vector< int > opData
Ooperands to op.
std::vector< double > d
Double data (constants and evaluated)
std::vector< char * > s
constant and evaluated pointer data
void print(int pc=-1) const
Debug by printing program.
std::vector< int > callStack
A thread local evaluation context. Just allocate and fill in with data.
T_FUNCTYPE getTemplatizedOp(int i)
Return the function f encapsulated in class T for the dynamic i converted to a static d.