61 # pragma fenv_access(on)
176 const double *param_values,
177 int param_values_len,
186 #define FAIL_IF(condition) \
188 return EXPR_PYLIKE_FATAL_ERROR; \
201 feclearexcept(FE_ALL_EXCEPT);
203 for (pc = 0; pc >= 0 && pc < expr->
ops_count; pc++) {
204 switch (ops[pc].opcode) {
208 stack[sp++] = ops[pc].
arg.
dval;
212 stack[sp++] = param_values[ops[pc].
arg.
ival];
216 stack[sp - 1] = ops[pc].arg.func1(stack[sp - 1]);
220 stack[sp - 2] = ops[pc].arg.func2(stack[sp - 2], stack[sp - 1]);
225 stack[sp - 3] = ops[pc].arg.func3(stack[sp - 3], stack[sp - 2], stack[sp - 1]);
229 FAIL_IF(sp < ops[pc].arg.ival);
230 for (
int j = 1; j < ops[pc].arg.ival; j++, sp--) {
235 FAIL_IF(sp < ops[pc].arg.ival);
236 for (
int j = 1; j < ops[pc].arg.ival; j++, sp--) {
243 pc += ops[pc].jmp_offset;
248 pc += ops[pc].jmp_offset;
255 pc += ops[pc].jmp_offset;
266 if (!ops[pc].arg.func2(stack[sp - 2], stack[sp - 1])) {
268 pc += ops[pc].jmp_offset;
272 stack[sp - 2] = stack[sp - 1];
286 *r_result = stack[0];
289 int flags = fetestexcept(FE_DIVBYZERO | FE_INVALID);
330 return arg *
M_PI / 180.0;
335 return arg * 180.0 /
M_PI;
345 return a * (1.0 -
x) + b *
x;
350 CLAMP(arg, 0.0, 1.0);
354 static double op_clamp3(
double arg,
double minv,
double maxv)
356 CLAMP(arg, minv, maxv);
362 double t = (
x -
a) / (b -
a);
364 return t *
t * (3.0 - 2.0 *
t);
369 return a ? 0.0 : 1.0;
374 return a == b ? 1.0 : 0.0;
379 return a != b ? 1.0 : 0.0;
384 return a < b ? 1.0 : 0.0;
389 return a <= b ? 1.0 : 0.0;
394 return a > b ? 1.0 : 0.0;
399 return a >= b ? 1.0 : 0.0;
408 {
"pi",
M_PI}, {
"True", 1.0}, {
"False", 0.0}, {
NULL, 0.0}};
419 # pragma function(ceil)
420 # pragma function(floor)
459 #define MAKE_CHAR2(a, b) (((a) << 8) | (b))
461 #define CHECK_ERROR(condition) \
462 if (!(condition)) { \
469 #define TOKEN_ID MAKE_CHAR2('I', 'D')
470 #define TOKEN_NUMBER MAKE_CHAR2('0', '0')
471 #define TOKEN_GE MAKE_CHAR2('>', '=')
472 #define TOKEN_LE MAKE_CHAR2('<', '=')
473 #define TOKEN_NE MAKE_CHAR2('!', '=')
474 #define TOKEN_EQ MAKE_CHAR2('=', '=')
475 #define TOKEN_AND MAKE_CHAR2('A', 'N')
476 #define TOKEN_OR MAKE_CHAR2('O', 'R')
477 #define TOKEN_NOT MAKE_CHAR2('N', 'O')
478 #define TOKEN_IF MAKE_CHAR2('I', 'F')
479 #define TOKEN_ELSE MAKE_CHAR2('E', 'L')
536 state->stack_ptr += stack_delta;
542 memset(op, 0,
sizeof(
ExprOp));
581 int jmp_gap =
state->ops_count -
state->last_jmp;
583 feclearexcept(FE_ALL_EXCEPT);
589 if (jmp_gap >= 1 && prev_ops[-1].opcode ==
OPCODE_CONST) {
594 volatile double result = func(prev_ops[-1].arg.
dval);
596 if (fetestexcept(FE_DIVBYZERO | FE_INVALID) == 0) {
606 if (jmp_gap >= 2 && prev_ops[-2].opcode ==
OPCODE_CONST &&
614 if (fetestexcept(FE_DIVBYZERO | FE_INVALID) == 0) {
626 if (jmp_gap >= 3 && prev_ops[-3].opcode ==
OPCODE_CONST &&
632 volatile double result = func(
635 if (fetestexcept(FE_DIVBYZERO | FE_INVALID) == 0) {
637 state->ops_count -= 2;
638 state->stack_ptr -= 2;
657 while (isspace(*
state->cur)) {
662 if (*
state->cur == 0) {
668 if (isdigit(*
state->cur) || (
state->cur[0] ==
'.' && isdigit(
state->cur[1]))) {
669 char *end, *out =
state->tokenbuf;
670 bool is_float =
false;
672 while (isdigit(*
state->cur)) {
673 *out++ = *
state->cur++;
676 if (*
state->cur ==
'.') {
678 *out++ = *
state->cur++;
680 while (isdigit(*
state->cur)) {
681 *out++ = *
state->cur++;
687 *out++ = *
state->cur++;
690 *out++ = *
state->cur++;
695 while (isdigit(*
state->cur)) {
696 *out++ = *
state->cur++;
703 if (!is_float &&
state->tokenbuf[0] ==
'0') {
704 for (
char *p =
state->tokenbuf + 1; *p; p++) {
712 state->tokenval = strtod(
state->tokenbuf, &end);
731 char *out =
state->tokenbuf;
734 *out++ = *
state->cur++;
776 switch (
state->token) {
799 switch (
state->token) {
819 for (i =
state->param_names_len - 1; i >= 0; i--) {
883 switch (
state->token) {
905 switch (
state->token) {
1021 int prev_last_jmp =
state->last_jmp;
1022 int start =
state->last_jmp =
state->ops_count;
1033 memcpy(body,
state->ops + start, bytes);
1063 else if (
state->last_jmp == start) {
1064 state->last_jmp = prev_last_jmp;
1083 const char **param_names,
1084 int param_names_len)
1092 state.param_names_len = param_names_len;
1093 state.param_names = param_names;
1108 expr =
MEM_mallocN(bytesize,
"ExprPyLike_Parsed");
#define BLI_array_alloca(arr, realsize)
@ EXPR_PYLIKE_FATAL_ERROR
@ EXPR_PYLIKE_DIV_BY_ZERO
struct ExprPyLike_Parsed ExprPyLike_Parsed
MINLINE int power_of_2_max_i(int n)
typedef double(DMatrix)[4][4]
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
Read Guarded memory(de)allocation.
#define MEM_reallocN(vmemh, len)
Group RGB to Bright Vector Camera CLAMP
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
void jump(const btVector3 &v=btVector3(0, 0, 0))
static double op_negate(double arg)
static bool parse_next_token(ExprParseState *state)
static double op_clamp3(double arg, double minv, double maxv)
struct KeywordTokenDef KeywordTokenDef
static int parse_add_jump(ExprParseState *state, eOpCode code)
double(* TernaryOpFunc)(double, double, double)
static double op_lt(double a, double b)
static int parse_function_args(ExprParseState *state)
static BinaryOpFunc parse_get_cmp_func(short token)
static bool parse_mul(ExprParseState *state)
static double op_smoothstep(double a, double b, double x)
static double op_mul(double a, double b)
static BuiltinOpDef builtin_ops[]
static bool parse_and(ExprParseState *state)
void BLI_expr_pylike_free(ExprPyLike_Parsed *expr)
static bool parse_expr(ExprParseState *state)
static const char * token_characters
eExprPyLike_EvalStatus BLI_expr_pylike_eval(ExprPyLike_Parsed *expr, const double *param_values, int param_values_len, double *r_result)
static bool parse_add(ExprParseState *state)
static double op_gt(double a, double b)
#define FAIL_IF(condition)
struct ExprParseState ExprParseState
struct BuiltinOpDef BuiltinOpDef
bool BLI_expr_pylike_is_valid(ExprPyLike_Parsed *expr)
static double op_ne(double a, double b)
#define CHECK_ERROR(condition)
ExprPyLike_Parsed * BLI_expr_pylike_parse(const char *expression, const char **param_names, int param_names_len)
static BuiltinConstDef builtin_consts[]
static ExprOp * parse_alloc_ops(ExprParseState *state, int count)
static double op_div(double a, double b)
static double op_eq(double a, double b)
static void parse_set_jump(ExprParseState *state, int jump)
static double op_lerp(double a, double b, double x)
static bool parse_add_func(ExprParseState *state, eOpCode code, int args, void *funcptr)
static bool parse_unary(ExprParseState *state)
static bool parse_not(ExprParseState *state)
static double op_le(double a, double b)
static const char * token_eq_characters
double(* BinaryOpFunc)(double, double)
bool BLI_expr_pylike_is_constant(ExprPyLike_Parsed *expr)
double(* UnaryOpFunc)(double)
static double op_ge(double a, double b)
static double op_add(double a, double b)
static double op_not(double a)
struct BuiltinConstDef BuiltinConstDef
static double op_sub(double a, double b)
static double op_degrees(double arg)
static double op_log2(double a, double b)
static bool parse_cmp_chain(ExprParseState *state, BinaryOpFunc cur_func)
static KeywordTokenDef keyword_list[]
static double op_clamp(double arg)
static ExprOp * parse_add_op(ExprParseState *state, eOpCode code, int stack_delta)
static double op_radians(double arg)
static bool parse_cmp(ExprParseState *state)
static bool parse_or(ExprParseState *state)
bool BLI_expr_pylike_is_using_param(ExprPyLike_Parsed *expr, int index)
static int opcode_arg_count(eOpCode code)
void(* MEM_freeN)(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)
void *(* MEM_mallocN)(size_t len, const char *str)
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
INLINE Rall1d< T, V, S > pow(const Rall1d< T, V, S > &arg, double m)
INLINE Rall1d< T, V, S > log(const Rall1d< T, V, S > &arg)
INLINE Rall1d< T, V, S > asin(const Rall1d< T, V, S > &x)
INLINE Rall1d< T, V, S > atan(const Rall1d< T, V, S > &x)
INLINE Rall1d< T, V, S > acos(const Rall1d< T, V, S > &x)
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
INLINE Rall1d< T, V, S > tan(const Rall1d< T, V, S > &arg)
INLINE Rall1d< T, V, S > atan2(const Rall1d< T, V, S > &y, const Rall1d< T, V, S > &x)
INLINE Rall1d< T, V, S > exp(const Rall1d< T, V, S > &arg)
const char ** param_names
ccl_device_inline float2 floor(const float2 &a)
ccl_device_inline float2 fabs(const float2 &a)
ccl_device_inline float3 ceil(const float3 &a)