10 |
#include "CoreVMFunctions.h" |
#include "CoreVMFunctions.h" |
11 |
|
|
12 |
#include <iostream> |
#include <iostream> |
13 |
|
#include <math.h> |
14 |
|
#include <stdlib.h> |
15 |
#include "tree.h" |
#include "tree.h" |
16 |
#include "ScriptVM.h" |
#include "ScriptVM.h" |
17 |
|
|
27 |
return &result; |
return &result; |
28 |
} |
} |
29 |
|
|
30 |
|
VMFnResult* VMIntResultFunction::errorResult(int i) { |
31 |
|
result.flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
32 |
|
result.value = i; |
33 |
|
return &result; |
34 |
|
} |
35 |
|
|
36 |
|
VMFnResult* VMIntResultFunction::successResult(int i) { |
37 |
|
result.flags = STMT_SUCCESS; |
38 |
|
result.value = i; |
39 |
|
return &result; |
40 |
|
} |
41 |
|
|
42 |
VMFnResult* VMStringResultFunction::errorResult(const String& s) { |
VMFnResult* VMStringResultFunction::errorResult(const String& s) { |
43 |
result.flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
result.flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
44 |
result.value = s; |
result.value = s; |
86 |
return &result; |
return &result; |
87 |
} |
} |
88 |
|
|
89 |
|
bool CoreVMFunction_abs::acceptsArgType(int iArg, ExprType_t type) const { |
90 |
|
return type == INT_EXPR; |
91 |
|
} |
92 |
|
|
93 |
|
VMFnResult* CoreVMFunction_abs::exec(VMFnArgs* args) { |
94 |
|
return successResult( ::abs(args->arg(0)->asInt()->evalInt()) ); |
95 |
|
} |
96 |
|
|
97 |
|
bool CoreVMFunction_random::acceptsArgType(int iArg, ExprType_t type) const { |
98 |
|
return type == INT_EXPR; |
99 |
|
} |
100 |
|
|
101 |
|
VMFnResult* CoreVMFunction_random::exec(VMFnArgs* args) { |
102 |
|
int iMin = args->arg(0)->asInt()->evalInt(); |
103 |
|
int iMax = args->arg(1)->asInt()->evalInt(); |
104 |
|
float f = float(::rand()) / float(RAND_MAX); |
105 |
|
return successResult( |
106 |
|
iMin + roundf( f * float(iMax - iMin) ) |
107 |
|
); |
108 |
|
} |
109 |
|
|
110 |
|
bool CoreVMFunction_num_elements::acceptsArgType(int iArg, ExprType_t type) const { |
111 |
|
return type == INT_ARR_EXPR; |
112 |
|
} |
113 |
|
|
114 |
|
VMFnResult* CoreVMFunction_num_elements::exec(VMFnArgs* args) { |
115 |
|
return successResult( args->arg(0)->asIntArray()->arraySize() ); |
116 |
|
} |
117 |
|
|
118 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |