1 |
/* |
/* |
2 |
* Copyright (c) 2014-2017 Christian Schoenebeck |
* Copyright (c) 2014-2019 Christian Schoenebeck |
3 |
* |
* |
4 |
* http://www.linuxsampler.org |
* http://www.linuxsampler.org |
5 |
* |
* |
15 |
#include <stdlib.h> |
#include <stdlib.h> |
16 |
#include "tree.h" |
#include "tree.h" |
17 |
#include "ScriptVM.h" |
#include "ScriptVM.h" |
18 |
|
#include "../common/RTMath.h" |
19 |
|
|
20 |
namespace LinuxSampler { |
namespace LinuxSampler { |
21 |
|
|
35 |
/////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////// |
36 |
// class VMIntResultFunction |
// class VMIntResultFunction |
37 |
|
|
38 |
VMFnResult* VMIntResultFunction::errorResult(int i) { |
VMFnResult* VMIntResultFunction::errorResult(vmint i) { |
39 |
result.flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
result.flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
40 |
result.value = i; |
result.value = i; |
41 |
return &result; |
return &result; |
42 |
} |
} |
43 |
|
|
44 |
VMFnResult* VMIntResultFunction::successResult(int i) { |
VMFnResult* VMIntResultFunction::successResult(vmint i) { |
45 |
result.flags = STMT_SUCCESS; |
result.flags = STMT_SUCCESS; |
46 |
result.value = i; |
result.value = i; |
47 |
return &result; |
return &result; |
65 |
/////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////// |
66 |
// built-in script function: message() |
// built-in script function: message() |
67 |
|
|
68 |
bool CoreVMFunction_message::acceptsArgType(int iArg, ExprType_t type) const { |
bool CoreVMFunction_message::acceptsArgType(vmint iArg, ExprType_t type) const { |
69 |
return type == INT_EXPR || type == STRING_EXPR; |
return type == INT_EXPR || type == STRING_EXPR; |
70 |
} |
} |
71 |
|
|
72 |
VMFnResult* CoreVMFunction_message::exec(VMFnArgs* args) { |
VMFnResult* CoreVMFunction_message::exec(VMFnArgs* args) { |
73 |
if (!args->argsCount()) return errorResult(); |
if (!args->argsCount()) return errorResult(); |
74 |
|
|
75 |
|
uint64_t usecs = RTMath::unsafeMicroSeconds(RTMath::real_clock); |
76 |
|
|
77 |
VMStringExpr* strExpr = dynamic_cast<VMStringExpr*>(args->arg(0)); |
VMStringExpr* strExpr = dynamic_cast<VMStringExpr*>(args->arg(0)); |
78 |
if (strExpr) { |
if (strExpr) { |
79 |
std::cout << "[ScriptVM] " << strExpr->evalStr() << "\n"; |
printf("[ScriptVM %.3f] %s\n", usecs/1000000.f, strExpr->evalStr().c_str()); |
80 |
return successResult(); |
return successResult(); |
81 |
} |
} |
82 |
|
|
83 |
VMIntExpr* intExpr = dynamic_cast<VMIntExpr*>(args->arg(0)); |
VMIntExpr* intExpr = dynamic_cast<VMIntExpr*>(args->arg(0)); |
84 |
if (intExpr) { |
if (intExpr) { |
85 |
std::cout << "[ScriptVM] " << intExpr->evalInt() << "\n"; |
printf("[ScriptVM %.3f] %lld\n", usecs/1000000.f, (int64_t)intExpr->evalInt()); |
86 |
return successResult(); |
return successResult(); |
87 |
} |
} |
88 |
|
|
92 |
/////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////// |
93 |
// built-in script function: exit() |
// built-in script function: exit() |
94 |
|
|
95 |
|
vmint CoreVMFunction_exit::maxAllowedArgs() const { |
96 |
|
return (vm->isExitResultEnabled()) ? 1 : 0; |
97 |
|
} |
98 |
|
|
99 |
|
bool CoreVMFunction_exit::acceptsArgType(vmint iArg, ExprType_t type) const { |
100 |
|
if (!vm->isExitResultEnabled()) return false; |
101 |
|
return type == INT_EXPR || type == STRING_EXPR; |
102 |
|
} |
103 |
|
|
104 |
VMFnResult* CoreVMFunction_exit::exec(VMFnArgs* args) { |
VMFnResult* CoreVMFunction_exit::exec(VMFnArgs* args) { |
105 |
this->result.flags = STMT_ABORT_SIGNALLED; |
this->result.flags = STMT_ABORT_SIGNALLED; |
106 |
|
if (vm->isExitResultEnabled() && args->argsCount()) { |
107 |
|
ExecContext* ctx = dynamic_cast<ExecContext*>(vm->currentVMExecContext()); |
108 |
|
switch (args->arg(0)->exprType()) { |
109 |
|
case INT_EXPR: |
110 |
|
ctx->exitRes.intLiteral.value = args->arg(0)->asInt()->evalInt(); |
111 |
|
ctx->exitRes.value = &ctx->exitRes.intLiteral; |
112 |
|
break; |
113 |
|
case STRING_EXPR: |
114 |
|
ctx->exitRes.stringLiteral.value = args->arg(0)->asString()->evalStr(); |
115 |
|
ctx->exitRes.value = &ctx->exitRes.stringLiteral; |
116 |
|
break; |
117 |
|
default: |
118 |
|
; // noop - just to shut up the compiler |
119 |
|
} |
120 |
|
} |
121 |
return &result; |
return &result; |
122 |
} |
} |
123 |
|
|
124 |
/////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////// |
125 |
// built-in script function: wait() |
// built-in script function: wait() |
126 |
|
|
127 |
|
bool CoreVMFunction_wait::acceptsArgUnitType(vmint iArg, StdUnit_t type) const { |
128 |
|
if (iArg == 0) |
129 |
|
return type == VM_NO_UNIT || type == VM_SECOND; |
130 |
|
else |
131 |
|
return type == VM_NO_UNIT; |
132 |
|
} |
133 |
|
|
134 |
|
bool CoreVMFunction_wait::acceptsArgUnitPrefix(vmint iArg) const { |
135 |
|
return iArg == 0; |
136 |
|
} |
137 |
|
|
138 |
VMFnResult* CoreVMFunction_wait::exec(VMFnArgs* args) { |
VMFnResult* CoreVMFunction_wait::exec(VMFnArgs* args) { |
139 |
ExecContext* ctx = dynamic_cast<ExecContext*>(vm->currentVMExecContext()); |
ExecContext* ctx = dynamic_cast<ExecContext*>(vm->currentVMExecContext()); |
140 |
VMIntExpr* expr = dynamic_cast<VMIntExpr*>(args->arg(0)); |
VMIntExpr* expr = dynamic_cast<VMIntExpr*>(args->arg(0)); |
141 |
int us = expr->evalInt(); |
vmint us = expr->evalInt(VM_MICRO); |
142 |
if (us < 0) { |
if (us < 0) { |
143 |
wrnMsg("wait(): argument may not be negative! Aborting script!"); |
wrnMsg("wait(): argument may not be negative! Aborting script!"); |
144 |
this->result.flags = STMT_ABORT_SIGNALLED; |
this->result.flags = STMT_ABORT_SIGNALLED; |
155 |
/////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////// |
156 |
// built-in script function: abs() |
// built-in script function: abs() |
157 |
|
|
158 |
bool CoreVMFunction_abs::acceptsArgType(int iArg, ExprType_t type) const { |
bool CoreVMFunction_abs::acceptsArgType(vmint iArg, ExprType_t type) const { |
159 |
return type == INT_EXPR; |
return type == INT_EXPR; |
160 |
} |
} |
161 |
|
|
166 |
/////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////// |
167 |
// built-in script function: random() |
// built-in script function: random() |
168 |
|
|
169 |
bool CoreVMFunction_random::acceptsArgType(int iArg, ExprType_t type) const { |
bool CoreVMFunction_random::acceptsArgType(vmint iArg, ExprType_t type) const { |
170 |
return type == INT_EXPR; |
return type == INT_EXPR; |
171 |
} |
} |
172 |
|
|
173 |
VMFnResult* CoreVMFunction_random::exec(VMFnArgs* args) { |
VMFnResult* CoreVMFunction_random::exec(VMFnArgs* args) { |
174 |
int iMin = args->arg(0)->asInt()->evalInt(); |
vmint iMin = args->arg(0)->asInt()->evalInt(); |
175 |
int iMax = args->arg(1)->asInt()->evalInt(); |
vmint iMax = args->arg(1)->asInt()->evalInt(); |
176 |
float f = float(::rand()) / float(RAND_MAX); |
float f = float(::rand()) / float(RAND_MAX); |
177 |
return successResult( |
return successResult( |
178 |
iMin + roundf( f * float(iMax - iMin) ) |
iMin + roundf( f * float(iMax - iMin) ) |
182 |
/////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////// |
183 |
// built-in script function: num_elements() |
// built-in script function: num_elements() |
184 |
|
|
185 |
bool CoreVMFunction_num_elements::acceptsArgType(int iArg, ExprType_t type) const { |
bool CoreVMFunction_num_elements::acceptsArgType(vmint iArg, ExprType_t type) const { |
186 |
return type == INT_ARR_EXPR; |
return type == INT_ARR_EXPR; |
187 |
} |
} |
188 |
|
|
198 |
VMIntExpr* in = dynamic_cast<VMIntExpr*>(arg); |
VMIntExpr* in = dynamic_cast<VMIntExpr*>(arg); |
199 |
VMVariable* out = dynamic_cast<VMVariable*>(arg); |
VMVariable* out = dynamic_cast<VMVariable*>(arg); |
200 |
if (!in || !out) successResult(0); |
if (!in || !out) successResult(0); |
201 |
int i = in->evalInt() + 1; |
vmint i = in->evalInt() + 1; |
202 |
IntLiteral tmp(i); |
IntLiteral tmp(i); |
203 |
out->assignExpr(&tmp); |
out->assignExpr(&tmp); |
204 |
return successResult(i); |
return successResult(i); |
212 |
VMIntExpr* in = dynamic_cast<VMIntExpr*>(arg); |
VMIntExpr* in = dynamic_cast<VMIntExpr*>(arg); |
213 |
VMVariable* out = dynamic_cast<VMVariable*>(arg); |
VMVariable* out = dynamic_cast<VMVariable*>(arg); |
214 |
if (!in || !out) successResult(0); |
if (!in || !out) successResult(0); |
215 |
int i = in->evalInt() - 1; |
vmint i = in->evalInt() - 1; |
216 |
IntLiteral tmp(i); |
IntLiteral tmp(i); |
217 |
out->assignExpr(&tmp); |
out->assignExpr(&tmp); |
218 |
return successResult(i); |
return successResult(i); |
222 |
// built-in script function: in_range() |
// built-in script function: in_range() |
223 |
|
|
224 |
VMFnResult* CoreVMFunction_in_range::exec(VMFnArgs* args) { |
VMFnResult* CoreVMFunction_in_range::exec(VMFnArgs* args) { |
225 |
int i = args->arg(0)->asInt()->evalInt(); |
vmint i = args->arg(0)->asInt()->evalInt(); |
226 |
int lo = args->arg(1)->asInt()->evalInt(); |
vmint lo = args->arg(1)->asInt()->evalInt(); |
227 |
int hi = args->arg(2)->asInt()->evalInt(); |
vmint hi = args->arg(2)->asInt()->evalInt(); |
228 |
if (lo > hi) { // swap lo and hi |
if (lo > hi) { // swap lo and hi |
229 |
int tmp = lo; |
vmint tmp = lo; |
230 |
lo = hi; |
lo = hi; |
231 |
hi = tmp; |
hi = tmp; |
232 |
} |
} |
237 |
// built-in script function: sh_left() |
// built-in script function: sh_left() |
238 |
|
|
239 |
VMFnResult* CoreVMFunction_sh_left::exec(VMFnArgs* args) { |
VMFnResult* CoreVMFunction_sh_left::exec(VMFnArgs* args) { |
240 |
int i = args->arg(0)->asInt()->evalInt(); |
vmint i = args->arg(0)->asInt()->evalInt(); |
241 |
int n = args->arg(1)->asInt()->evalInt(); |
vmint n = args->arg(1)->asInt()->evalInt(); |
242 |
return successResult(i << n); |
return successResult(i << n); |
243 |
} |
} |
244 |
|
|
246 |
// built-in script function: sh_right() |
// built-in script function: sh_right() |
247 |
|
|
248 |
VMFnResult* CoreVMFunction_sh_right::exec(VMFnArgs* args) { |
VMFnResult* CoreVMFunction_sh_right::exec(VMFnArgs* args) { |
249 |
int i = args->arg(0)->asInt()->evalInt(); |
vmint i = args->arg(0)->asInt()->evalInt(); |
250 |
int n = args->arg(1)->asInt()->evalInt(); |
vmint n = args->arg(1)->asInt()->evalInt(); |
251 |
return successResult(i >> n); |
return successResult(i >> n); |
252 |
} |
} |
253 |
|
|
255 |
// built-in script function: min() |
// built-in script function: min() |
256 |
|
|
257 |
VMFnResult* CoreVMFunction_min::exec(VMFnArgs* args) { |
VMFnResult* CoreVMFunction_min::exec(VMFnArgs* args) { |
258 |
int l = args->arg(0)->asInt()->evalInt(); |
vmint l = args->arg(0)->asInt()->evalInt(); |
259 |
int r = args->arg(1)->asInt()->evalInt(); |
vmint r = args->arg(1)->asInt()->evalInt(); |
260 |
return successResult(l < r ? l : r); |
return successResult(l < r ? l : r); |
261 |
} |
} |
262 |
|
|
264 |
// built-in script function: max() |
// built-in script function: max() |
265 |
|
|
266 |
VMFnResult* CoreVMFunction_max::exec(VMFnArgs* args) { |
VMFnResult* CoreVMFunction_max::exec(VMFnArgs* args) { |
267 |
int l = args->arg(0)->asInt()->evalInt(); |
vmint l = args->arg(0)->asInt()->evalInt(); |
268 |
int r = args->arg(1)->asInt()->evalInt(); |
vmint r = args->arg(1)->asInt()->evalInt(); |
269 |
return successResult(l > r ? l : r); |
return successResult(l > r ? l : r); |
270 |
} |
} |
271 |
|
|
279 |
wrnMsg("array_equal(): the two arrays differ in size"); |
wrnMsg("array_equal(): the two arrays differ in size"); |
280 |
return successResult(0); // false |
return successResult(0); // false |
281 |
} |
} |
282 |
const int n = l->arraySize(); |
const vmint n = l->arraySize(); |
283 |
for (int i = 0; i < n; ++i) |
for (vmint i = 0; i < n; ++i) |
284 |
if (l->evalIntElement(i) != r->evalIntElement(i)) |
if (l->evalIntElement(i) != r->evalIntElement(i)) |
285 |
return successResult(0); // false |
return successResult(0); // false |
286 |
return successResult(1); // true |
return successResult(1); // true |
289 |
/////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////// |
290 |
// built-in script function: search() |
// built-in script function: search() |
291 |
|
|
292 |
ExprType_t CoreVMFunction_search::argType(int iArg) const { |
ExprType_t CoreVMFunction_search::argType(vmint iArg) const { |
293 |
return (iArg == 0) ? INT_ARR_EXPR : INT_EXPR; |
return (iArg == 0) ? INT_ARR_EXPR : INT_EXPR; |
294 |
} |
} |
295 |
|
|
296 |
bool CoreVMFunction_search::acceptsArgType(int iArg, ExprType_t type) const { |
bool CoreVMFunction_search::acceptsArgType(vmint iArg, ExprType_t type) const { |
297 |
if (iArg == 0) |
if (iArg == 0) |
298 |
return type == INT_ARR_EXPR; |
return type == INT_ARR_EXPR; |
299 |
else |
else |
302 |
|
|
303 |
VMFnResult* CoreVMFunction_search::exec(VMFnArgs* args) { |
VMFnResult* CoreVMFunction_search::exec(VMFnArgs* args) { |
304 |
VMIntArrayExpr* a = args->arg(0)->asIntArray(); |
VMIntArrayExpr* a = args->arg(0)->asIntArray(); |
305 |
const int needle = args->arg(1)->asInt()->evalInt(); |
const vmint needle = args->arg(1)->asInt()->evalInt(); |
306 |
const int n = a->arraySize(); |
const vmint n = a->arraySize(); |
307 |
for (int i = 0; i < n; ++i) |
for (vmint i = 0; i < n; ++i) |
308 |
if (a->evalIntElement(i) == needle) |
if (a->evalIntElement(i) == needle) |
309 |
return successResult(i); |
return successResult(i); |
310 |
return successResult(-1); // not found |
return successResult(-1); // not found |
313 |
/////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////// |
314 |
// built-in script function: sort() |
// built-in script function: sort() |
315 |
|
|
316 |
ExprType_t CoreVMFunction_sort::argType(int iArg) const { |
ExprType_t CoreVMFunction_sort::argType(vmint iArg) const { |
317 |
return (iArg == 0) ? INT_ARR_EXPR : INT_EXPR; |
return (iArg == 0) ? INT_ARR_EXPR : INT_EXPR; |
318 |
} |
} |
319 |
|
|
320 |
bool CoreVMFunction_sort::acceptsArgType(int iArg, ExprType_t type) const { |
bool CoreVMFunction_sort::acceptsArgType(vmint iArg, ExprType_t type) const { |
321 |
if (iArg == 0) |
if (iArg == 0) |
322 |
return type == INT_ARR_EXPR; |
return type == INT_ARR_EXPR; |
323 |
else |
else |
326 |
|
|
327 |
struct ArrElemPOD { |
struct ArrElemPOD { |
328 |
VMIntArrayExpr* m_array; |
VMIntArrayExpr* m_array; |
329 |
int m_index; |
vmint m_index; |
330 |
}; |
}; |
331 |
|
|
332 |
static inline void swap(class ArrElemRef& a, class ArrElemRef& b); |
static inline void swap(class ArrElemRef a, class ArrElemRef b); |
333 |
|
|
334 |
class ArrElemRef : protected ArrElemPOD { |
class ArrElemRef : protected ArrElemPOD { |
335 |
public: |
public: |
337 |
m_array = NULL; |
m_array = NULL; |
338 |
m_index = 0; |
m_index = 0; |
339 |
} |
} |
340 |
ArrElemRef(VMIntArrayExpr* a, int index) { |
ArrElemRef(VMIntArrayExpr* a, vmint index) { |
341 |
m_array = a; |
m_array = a; |
342 |
m_index = index; |
m_index = index; |
343 |
} |
} |
345 |
setValue(e.getValue()); |
setValue(e.getValue()); |
346 |
return *this; |
return *this; |
347 |
} |
} |
348 |
inline ArrElemRef& operator=(int val) { |
inline ArrElemRef& operator=(vmint val) { |
349 |
setValue(val); |
setValue(val); |
350 |
return *this; |
return *this; |
351 |
} |
} |
354 |
return true; |
return true; |
355 |
return getValue() == e.getValue(); |
return getValue() == e.getValue(); |
356 |
} |
} |
357 |
inline bool operator==(int val) const { |
inline bool operator==(vmint val) const { |
358 |
return getValue() == val; |
return getValue() == val; |
359 |
} |
} |
360 |
inline bool operator!=(const ArrElemRef& e) const { |
inline bool operator!=(const ArrElemRef& e) const { |
361 |
return !(operator==(e)); |
return !(operator==(e)); |
362 |
} |
} |
363 |
inline bool operator!=(int val) const { |
inline bool operator!=(vmint val) const { |
364 |
return !(operator==(val)); |
return !(operator==(val)); |
365 |
} |
} |
366 |
inline bool operator<(const ArrElemRef& e) const { |
inline bool operator<(const ArrElemRef& e) const { |
368 |
return false; |
return false; |
369 |
return getValue() < e.getValue(); |
return getValue() < e.getValue(); |
370 |
} |
} |
371 |
inline bool operator<(int val) const { |
inline bool operator<(vmint val) const { |
372 |
return getValue() < val; |
return getValue() < val; |
373 |
} |
} |
374 |
inline bool operator>(const ArrElemRef& e) const { |
inline bool operator>(const ArrElemRef& e) const { |
376 |
return false; |
return false; |
377 |
return getValue() > e.getValue(); |
return getValue() > e.getValue(); |
378 |
} |
} |
379 |
inline bool operator>(int val) const { |
inline bool operator>(vmint val) const { |
380 |
return getValue() > val; |
return getValue() > val; |
381 |
} |
} |
382 |
inline bool operator<=(const ArrElemRef& e) const { |
inline bool operator<=(const ArrElemRef& e) const { |
384 |
return true; |
return true; |
385 |
return getValue() <= e.getValue(); |
return getValue() <= e.getValue(); |
386 |
} |
} |
387 |
inline bool operator<=(int val) const { |
inline bool operator<=(vmint val) const { |
388 |
return getValue() <= val; |
return getValue() <= val; |
389 |
} |
} |
390 |
inline bool operator>=(const ArrElemRef& e) const { |
inline bool operator>=(const ArrElemRef& e) const { |
392 |
return true; |
return true; |
393 |
return getValue() >= e.getValue(); |
return getValue() >= e.getValue(); |
394 |
} |
} |
395 |
inline bool operator>=(int val) const { |
inline bool operator>=(vmint val) const { |
396 |
return getValue() >= val; |
return getValue() >= val; |
397 |
} |
} |
398 |
inline operator int() const { |
inline operator vmint() const { |
399 |
return getValue(); |
return getValue(); |
400 |
} |
} |
401 |
protected: |
protected: |
402 |
inline int getValue() const { |
inline vmint getValue() const { |
403 |
return m_array->evalIntElement(m_index); |
return m_array->evalIntElement(m_index); |
404 |
} |
} |
405 |
inline void setValue(int value) { |
inline void setValue(vmint value) { |
406 |
m_array->assignIntElement(m_index, value); |
m_array->assignIntElement(m_index, value); |
407 |
} |
} |
408 |
|
|
409 |
friend void swap(class ArrElemRef& a, class ArrElemRef& b); |
friend void swap(class ArrElemRef a, class ArrElemRef b); |
410 |
}; |
}; |
411 |
|
|
412 |
class ArrElemPtr : protected ArrElemPOD { |
class ArrElemPtr : protected ArrElemPOD { |
415 |
m_array = NULL; |
m_array = NULL; |
416 |
m_index = 0; |
m_index = 0; |
417 |
} |
} |
418 |
ArrElemPtr(VMIntArrayExpr* a, int index) { |
ArrElemPtr(VMIntArrayExpr* a, vmint index) { |
419 |
m_array = a; |
m_array = a; |
420 |
m_index = index; |
m_index = index; |
421 |
} |
} |
424 |
} |
} |
425 |
}; |
}; |
426 |
|
|
427 |
static inline void swap(ArrElemRef& a, ArrElemRef& b) { |
static inline void swap(ArrElemRef a, ArrElemRef b) { |
428 |
int valueA = a.getValue(); |
vmint valueA = a.getValue(); |
429 |
int valueB = b.getValue(); |
vmint valueB = b.getValue(); |
430 |
a.setValue(valueB); |
a.setValue(valueB); |
431 |
b.setValue(valueA); |
b.setValue(valueA); |
432 |
} |
} |
434 |
class ArrExprIter : public ArrElemPOD { |
class ArrExprIter : public ArrElemPOD { |
435 |
public: |
public: |
436 |
typedef std::random_access_iterator_tag iterator_category; |
typedef std::random_access_iterator_tag iterator_category; |
437 |
typedef int value_type; |
typedef vmint value_type; |
438 |
typedef ssize_t difference_type; |
typedef ssize_t difference_type; |
439 |
typedef ArrElemPtr pointer; |
typedef ArrElemPtr pointer; |
440 |
typedef ArrElemRef reference; |
typedef ArrElemRef reference; |
441 |
|
|
442 |
ArrExprIter(VMIntArrayExpr* a, int index) { |
ArrExprIter(VMIntArrayExpr* a, vmint index) { |
443 |
m_array = a; |
m_array = a; |
444 |
m_index = index; |
m_index = index; |
445 |
} |
} |
464 |
--m_index; |
--m_index; |
465 |
return it; |
return it; |
466 |
} |
} |
467 |
|
inline ArrExprIter& operator+=(difference_type d) { |
468 |
|
m_index += d; |
469 |
|
return *this; |
470 |
|
} |
471 |
|
inline ArrExprIter& operator-=(difference_type d) { |
472 |
|
m_index -= d; |
473 |
|
return *this; |
474 |
|
} |
475 |
inline bool operator==(const ArrExprIter& other) const { |
inline bool operator==(const ArrExprIter& other) const { |
476 |
return m_index == other.m_index; |
return m_index == other.m_index; |
477 |
} |
} |
508 |
}; |
}; |
509 |
|
|
510 |
struct DescArrExprSorter { |
struct DescArrExprSorter { |
511 |
inline bool operator()(const int& a, const int& b) const { |
inline bool operator()(const vmint& a, const vmint& b) const { |
512 |
return a > b; |
return a > b; |
513 |
} |
} |
514 |
}; |
}; |
517 |
VMIntArrayExpr* a = args->arg(0)->asIntArray(); |
VMIntArrayExpr* a = args->arg(0)->asIntArray(); |
518 |
bool bAscending = |
bool bAscending = |
519 |
(args->argsCount() < 2) ? true : !args->arg(1)->asInt()->evalInt(); |
(args->argsCount() < 2) ? true : !args->arg(1)->asInt()->evalInt(); |
520 |
int n = a->arraySize(); |
vmint n = a->arraySize(); |
521 |
ArrExprIter itBegin(a, 0); |
ArrExprIter itBegin(a, 0); |
522 |
ArrExprIter itEnd(a, n); |
ArrExprIter itEnd(a, n); |
523 |
if (bAscending) { |
if (bAscending) { |