MCPcopy Create free account
hub / github.com/crownengine/crown / default_compute_function

Function default_compute_function

src/resource/expression_language.cpp:77–102  ·  view source on GitHub ↗

Computes the function specified by @a op_code on the @a stack.

Source from the content-addressed store, hash-verified

75
76 /// Computes the function specified by @a op_code on the @a stack.
77 static inline void default_compute_function(int op_code, Stack &stack)
78 {
79#define POP() pop(stack)
80#define PUSH(f) push(stack, f)
81
82 float a, b, c, d;
83
84 switch (op_code) {
85 case OP_ADD: b = POP(); a = POP(); PUSH(a + b); break;
86 case OP_SUB: b = POP(); a = POP(); PUSH(a - b); break;
87 case OP_MUL: b = POP(); a = POP(); PUSH(a * b); break;
88 case OP_DIV: b = POP(); a = POP(); PUSH(a / b); break;
89 case OP_UNARY_MINUS: PUSH(-POP()); break;
90 case OP_SIN: PUSH(fsin(POP())); break;
91 case OP_COS: PUSH(fcos(POP())); break;
92 case OP_ABS: a = POP(); PUSH(fabs(a)); break;
93 case OP_MATCH: b = POP(); a = POP(); PUSH(match(a, b)); break;
94 case OP_MATCH_2D: d = POP(); c = POP(); b = POP(); a = POP(); PUSH(match2d(a, b, c, d)); break;
95 case OP_NOP: break;
96 default:
97 CE_FATAL("Unknown opcode");
98 }
99
100#undef POP
101#undef PUSH
102 }
103
104 /// Union to cast through to convert between float and unsigned.
105 union FloatAndUnsigned

Callers

nothing calls this directly

Calls 3

match2dFunction · 0.85
matchFunction · 0.70
fabsFunction · 0.50

Tested by

no test coverage detected