18 bool multiInvoke = !scalarWanted;
22 int childDim = childType.
dim();
26 if (nonOneDim != 1 && childDim != nonOneDim) multiInvoke =
false;
31 return retType.
Error();
32 else if (multiInvoke && nonOneDim != 1)
33 return retType.
FP(nonOneDim);
41 int childDim = childType.
dim();
47 return retType.
Error();
55 int Func0Op(
int* opData,
double* fp,
char** c, std::vector<int>& ) {
59 int Func1Op(
int* opData,
double* fp,
char** c, std::vector<int>&) {
63 int Func2Op(
int* opData,
double* fp,
char** c, std::vector<int>&) {
67 int Func3Op(
int* opData,
double* fp,
char** c, std::vector<int>&) {
71 int Func4Op(
int* opData,
double* fp,
char** c, std::vector<int>&) {
76 int Func5Op(
int* opData,
double* fp,
char** c, std::vector<int>&) {
78 fp[opData[1]], fp[opData[2]], fp[opData[3]], fp[opData[4]], fp[opData[5]]);
81 int Func6Op(
int* opData,
double* fp,
char** c, std::vector<int>&) {
83 fp[opData[1]], fp[opData[2]], fp[opData[3]], fp[opData[4]], fp[opData[5]], fp[opData[6]]);
86 int FuncNOp(
int* opData,
double* fp,
char** c, std::vector<int>&) {
88 double* vals =
static_cast<double*
>(alloca(n *
sizeof(
double)));
89 for (
int k = 0; k < n; k++) vals[k] = fp[opData[k + 2]];
90 double* out = &fp[opData[n + 2]];
94 int Func1VOp(
int* opData,
double* fp,
char** c, std::vector<int>&) {
98 int Func2VOp(
int* opData,
double* fp,
char** c, std::vector<int>&) {
103 int Func1VVOp(
int* opData,
double* fp,
char** c, std::vector<int>&) {
105 double* out = &fp[opData[2]];
106 for (
int k = 0; k < 3; k++) out[k] = v[k];
109 int Func2VVOp(
int* opData,
double* fp,
char** c, std::vector<int>&) {
111 double* out = &fp[opData[3]];
112 for (
int k = 0; k < 3; k++) out[k] = v[k];
115 int FuncNVOp(
int* opData,
double* fp,
char** c, std::vector<int>&) {
118 for (
int k = 0; k < n; k++)
new (vals + k)
Vec3d(
Vec3dRef(&fp[opData[k + 2]]));
119 double* out = &fp[opData[n + 2]];
123 int FuncNVVOp(
int* opData,
double* fp,
char** c, std::vector<int>&) {
126 for (
int k = 0; k < n; k++)
new (vals + k)
Vec3d(
Vec3dRef(&fp[opData[k + 2]]));
127 double* out = &fp[opData[n + 2]];
129 for (
int k = 0; k < 3; k++) out[k] = val[k];
134 std::vector<int> argOps;
137 argOps.push_back(op);
141 int funcPtrLoc = interpreter->
allocPtr();
142 interpreter->
s[funcPtrLoc] = (
char*)
_func;
194 for (
int k = 0; k < node->
type().dim(); k++) {
195 interpreter->
addOp(op);
198 for (
size_t c = 0; c < argOps.size(); c++) {
205 interpreter->
endOp();
209 for (
size_t c = 0; c < argOps.size(); c++) {
211 int promotedArgOp = interpreter->
allocFP(3);
215 interpreter->
endOp();
216 argOps[c] = promotedArgOp;
221 interpreter->
addOp(op);
224 for (
int argOp : argOps) {
228 interpreter->
endOp();
231 std::cerr <<
"Interpreter dump" << std::endl;
232 interpreter->
print();
Node that calls a function.
double(double, double, double, double) Func4
Vec3d(int, const Vec3d *) Funcnvv
double(int, double *) Funcn
ExprType prep(ExprFuncNode *node, bool scalarWanted, ExprVarEnvBuilder &envBuilder) const override
int buildInterpreter(const ExprFuncNode *node, Interpreter *interpreter) const override
Build an interpreter to evaluate the expression.
double(const Vec3d &) Func1v
double(const Vec3d &, const Vec3d &) Func2v
double(double, double, double, double, double, double) Func6
double(double, double, double) Func3
Vec3d(const Vec3d &) Func1vv
double(int, const Vec3d *) Funcnv
double(double, double, double, double, double) Func5
Vec3d(const Vec3d &, const Vec3d &) Func2vv
double(double, double) Func2
virtual ExprType prep(bool dontNeedScalar, ExprVarEnvBuilder &envBuilder)
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
bool checkIsFP(const ExprType &type, bool &error) const
Checks if the type is a float[d] for any d.
int numChildren() const
Number of children.
bool checkCondition(bool check, const ErrorCode message, const std::vector< std::string > &ids, bool &error) const
Checks the boolean value and records an error string with node if it is false.
const ExprType & type() const
The type of the node.
const ExprNode * child(size_t i) const
Get 0 indexed child.
ExprType & FP(int d)
Mutate this into a floating point type of dimension d.
ExprType & setLifetime(const ExprType &a)
Assign the lifetime from type a to be my type.
bool isFP() const
Direct is predicate checks.
ExprType & Error()
Mutate this into an error type.
Variable scope builder is used by the type checking and code gen to track visiblity of variables and ...
static bool debugging
Whether to debug expressions.
int addOp(OpF op)
! adds an operator to the program (pointing to the data at the current location)
void endOp(bool execute=true)
std::vector< char * > s
constant and evaluated pointer data
int allocFP(int n)
! Allocate a floating point set of data of dimension n
int(*)(int *, double *, char **, std::vector< int > &) OpF
Op function pointer arguments are (int* currOpData,double* currD,char** c,std::stack<int>& callStacku...
int allocPtr()
Allocate a pointer location (can be anything, but typically space for char*)
int addOperand(int param)
! Adds an operand. Note this should be done after doing the addOp!
void print(int pc=-1) const
Debug by printing program.
static Vec< double, d, false > copy(T2 *raw)
Initialize vector value using raw memory.
int FuncNOp(int *opData, double *fp, char **c, std::vector< int > &)
int Func3Op(int *opData, double *fp, char **c, std::vector< int > &)
int Func1VOp(int *opData, double *fp, char **c, std::vector< int > &)
int Func1VVOp(int *opData, double *fp, char **c, std::vector< int > &)
int FuncNVVOp(int *opData, double *fp, char **c, std::vector< int > &)
int Func1Op(int *opData, double *fp, char **c, std::vector< int > &)
int Func2Op(int *opData, double *fp, char **c, std::vector< int > &)
@ ExpectedFloatOrFloat3
"Expected float or FP[3]"
int Func5Op(int *opData, double *fp, char **c, std::vector< int > &)
int Func2VOp(int *opData, double *fp, char **c, std::vector< int > &)
int Func4Op(int *opData, double *fp, char **c, std::vector< int > &)
int Func0Op(int *opData, double *fp, char **c, std::vector< int > &)
int Func6Op(int *opData, double *fp, char **c, std::vector< int > &)
Vec< double, 3, false > Vec3d
int Func2VVOp(int *opData, double *fp, char **c, std::vector< int > &)
int FuncNVOp(int *opData, double *fp, char **c, std::vector< int > &)
Vec< double, 3, true > Vec3dRef