45 # pragma fenv_access(on)
152 const double *param_values,
153 int param_values_len,
162 #define FAIL_IF(condition) \
164 return EXPR_PYLIKE_FATAL_ERROR; \
177 feclearexcept(FE_ALL_EXCEPT);
179 for (pc = 0; pc >= 0 && pc < expr->
ops_count; pc++) {
180 switch (ops[pc].opcode) {
184 stack[sp++] = ops[pc].
arg.
dval;
188 stack[sp++] = param_values[ops[pc].
arg.
ival];
192 stack[sp - 1] = ops[pc].arg.func1(stack[sp - 1]);
196 stack[sp - 2] = ops[pc].arg.func2(stack[sp - 2], stack[sp - 1]);
201 stack[sp - 3] = ops[pc].arg.func3(stack[sp - 3], stack[sp - 2], stack[sp - 1]);
205 FAIL_IF(sp < ops[pc].arg.ival);
206 for (
int j = 1; j < ops[pc].arg.ival; j++, sp--) {
211 FAIL_IF(sp < ops[pc].arg.ival);
212 for (
int j = 1; j < ops[pc].arg.ival; j++, sp--) {
219 pc += ops[pc].jmp_offset;
224 pc += ops[pc].jmp_offset;
231 pc += ops[pc].jmp_offset;
242 if (!ops[pc].arg.func2(stack[sp - 2], stack[sp - 1])) {
244 pc += ops[pc].jmp_offset;
248 stack[sp - 2] = stack[sp - 1];
262 *r_result = stack[0];
265 int flags = fetestexcept(FE_DIVBYZERO | FE_INVALID);
306 return arg *
M_PI / 180.0;
311 return arg * 180.0 /
M_PI;
321 return a * (1.0 -
x) +
b *
x;
326 CLAMP(arg, 0.0, 1.0);
330 static double op_clamp3(
double arg,
double minv,
double maxv)
332 CLAMP(arg, minv, maxv);
338 double t = (
x -
a) / (
b -
a);
340 return t *
t * (3.0 - 2.0 *
t);
345 return a ? 0.0 : 1.0;
350 return a ==
b ? 1.0 : 0.0;
355 return a !=
b ? 1.0 : 0.0;
360 return a <
b ? 1.0 : 0.0;
365 return a <=
b ? 1.0 : 0.0;
370 return a >
b ? 1.0 : 0.0;
375 return a >=
b ? 1.0 : 0.0;
384 {
"pi",
M_PI}, {
"True", 1.0}, {
"False", 0.0}, {
NULL, 0.0}};
395 # pragma function(ceil)
396 # pragma function(floor)
435 #define MAKE_CHAR2(a, b) (((a) << 8) | (b))
437 #define CHECK_ERROR(condition) \
438 if (!(condition)) { \
445 #define TOKEN_ID MAKE_CHAR2('I', 'D')
446 #define TOKEN_NUMBER MAKE_CHAR2('0', '0')
447 #define TOKEN_GE MAKE_CHAR2('>', '=')
448 #define TOKEN_LE MAKE_CHAR2('<', '=')
449 #define TOKEN_NE MAKE_CHAR2('!', '=')
450 #define TOKEN_EQ MAKE_CHAR2('=', '=')
451 #define TOKEN_AND MAKE_CHAR2('A', 'N')
452 #define TOKEN_OR MAKE_CHAR2('O', 'R')
453 #define TOKEN_NOT MAKE_CHAR2('N', 'O')
454 #define TOKEN_IF MAKE_CHAR2('I', 'F')
455 #define TOKEN_ELSE MAKE_CHAR2('E', 'L')
512 state->stack_ptr += stack_delta;
518 memset(op, 0,
sizeof(
ExprOp));
557 int jmp_gap =
state->ops_count -
state->last_jmp;
559 feclearexcept(FE_ALL_EXCEPT);
565 if (jmp_gap >= 1 && prev_ops[-1].opcode ==
OPCODE_CONST) {
570 volatile double result = func(prev_ops[-1].arg.
dval);
572 if (fetestexcept(FE_DIVBYZERO | FE_INVALID) == 0) {
582 if (jmp_gap >= 2 && prev_ops[-2].opcode ==
OPCODE_CONST &&
590 if (fetestexcept(FE_DIVBYZERO | FE_INVALID) == 0) {
602 if (jmp_gap >= 3 && prev_ops[-3].opcode ==
OPCODE_CONST &&
608 volatile double result = func(
611 if (fetestexcept(FE_DIVBYZERO | FE_INVALID) == 0) {
613 state->ops_count -= 2;
614 state->stack_ptr -= 2;
633 while (isspace(*
state->cur)) {
638 if (*
state->cur == 0) {
644 if (isdigit(*
state->cur) || (
state->cur[0] ==
'.' && isdigit(
state->cur[1]))) {
646 bool is_float =
false;
648 while (isdigit(*
state->cur)) {
652 if (*
state->cur ==
'.') {
656 while (isdigit(*
state->cur)) {
671 while (isdigit(*
state->cur)) {
679 if (!is_float &&
state->tokenbuf[0] ==
'0') {
680 for (
char *p =
state->tokenbuf + 1; *p; p++) {
688 state->tokenval = strtod(
state->tokenbuf, &end);
752 switch (
state->token) {
775 switch (
state->token) {
795 for (i =
state->param_names_len - 1; i >= 0; i--) {
859 switch (
state->token) {
881 switch (
state->token) {
997 int prev_last_jmp =
state->last_jmp;
998 int start =
state->last_jmp =
state->ops_count;
1009 memcpy(body,
state->ops + start, bytes);
1039 else if (
state->last_jmp == start) {
1040 state->last_jmp = prev_last_jmp;
1053 const char **param_names,
1054 int param_names_len)
1062 state.param_names_len = param_names_len;
1063 state.param_names = param_names;
1078 expr =
MEM_mallocN(bytesize,
"ExprPyLike_Parsed");
#define BLI_array_alloca(arr, realsize)
#define BLI_assert_msg(a, msg)
@ 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 Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position 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)
ccl_device_inline float2 fabs(const float2 &a)
ccl_device_inline float3 exp(float3 v)
ccl_device_inline float3 ceil(const float3 &a)
ccl_device_inline float3 pow(float3 v, float e)
ccl_device_inline float3 log(float3 v)
INLINE Rall1d< T, V, S > cos(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)
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
const char ** param_names