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 |
|
|
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] %d\n", usecs/1000000.f, intExpr->evalInt()); |
86 |
return successResult(); |
return successResult(); |
87 |
} |
} |
88 |
|
|
92 |
/////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////// |
93 |
// built-in script function: exit() |
// built-in script function: exit() |
94 |
|
|
95 |
|
int CoreVMFunction_exit::maxAllowedArgs() const { |
96 |
|
return (vm->isExitResultEnabled()) ? 1 : 0; |
97 |
|
} |
98 |
|
|
99 |
|
bool CoreVMFunction_exit::acceptsArgType(int 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 |
|
|
453 |
--m_index; |
--m_index; |
454 |
return it; |
return it; |
455 |
} |
} |
456 |
|
inline ArrExprIter& operator+=(difference_type d) { |
457 |
|
m_index += d; |
458 |
|
return *this; |
459 |
|
} |
460 |
|
inline ArrExprIter& operator-=(difference_type d) { |
461 |
|
m_index -= d; |
462 |
|
return *this; |
463 |
|
} |
464 |
inline bool operator==(const ArrExprIter& other) const { |
inline bool operator==(const ArrExprIter& other) const { |
465 |
return m_index == other.m_index; |
return m_index == other.m_index; |
466 |
} |
} |