48 |
/////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////// |
49 |
// class VMEmptyResultFunction |
// class VMEmptyResultFunction |
50 |
|
|
51 |
|
void VMEmptyResultFunction::bindResult(VMFnResult* res) { |
52 |
|
result = dynamic_cast<VMEmptyResult*>(res); |
53 |
|
} |
54 |
|
|
55 |
|
VMFnResult* VMEmptyResultFunction::boundResult() const { |
56 |
|
return result; |
57 |
|
} |
58 |
|
|
59 |
VMFnResult* VMEmptyResultFunction::errorResult() { |
VMFnResult* VMEmptyResultFunction::errorResult() { |
60 |
result.flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
result->flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
61 |
return &result; |
return result; |
62 |
} |
} |
63 |
|
|
64 |
VMFnResult* VMEmptyResultFunction::successResult() { |
VMFnResult* VMEmptyResultFunction::successResult() { |
65 |
result.flags = STMT_SUCCESS; |
result->flags = STMT_SUCCESS; |
66 |
return &result; |
return result; |
67 |
} |
} |
68 |
|
|
69 |
/////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////// |
70 |
// class VMIntResultFunction |
// class VMIntResultFunction |
71 |
|
|
72 |
|
void VMIntResultFunction::bindResult(VMFnResult* res) { |
73 |
|
result = dynamic_cast<VMIntResult*>(res); |
74 |
|
} |
75 |
|
|
76 |
|
VMFnResult* VMIntResultFunction::boundResult() const { |
77 |
|
return result; |
78 |
|
} |
79 |
|
|
80 |
VMFnResult* VMIntResultFunction::errorResult(vmint i) { |
VMFnResult* VMIntResultFunction::errorResult(vmint i) { |
81 |
result.flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
result->flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
82 |
result.value = i; |
result->value = i; |
83 |
result.unitPrefixFactor = VM_NO_FACTOR; |
result->unitPrefixFactor = VM_NO_FACTOR; |
84 |
result.unitBaseType = VM_NO_UNIT; |
result->unitBaseType = VM_NO_UNIT; |
85 |
return &result; |
return result; |
86 |
} |
} |
87 |
|
|
88 |
VMFnResult* VMIntResultFunction::successResult(vmint i) { |
VMFnResult* VMIntResultFunction::successResult(vmint i) { |
89 |
result.flags = STMT_SUCCESS; |
result->flags = STMT_SUCCESS; |
90 |
result.value = i; |
result->value = i; |
91 |
result.unitPrefixFactor = VM_NO_FACTOR; |
result->unitPrefixFactor = VM_NO_FACTOR; |
92 |
result.unitBaseType = VM_NO_UNIT; |
result->unitBaseType = VM_NO_UNIT; |
93 |
return &result; |
return result; |
94 |
} |
} |
95 |
|
|
96 |
VMFnResult* VMIntResultFunction::errorResult(VMIntFnResDef res) { |
VMFnResult* VMIntResultFunction::errorResult(VMIntFnResDef res) { |
97 |
result.flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
result->flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
98 |
result.value = res.value; |
result->value = res.value; |
99 |
result.unitPrefixFactor = res.unitFactor; |
result->unitPrefixFactor = res.unitFactor; |
100 |
result.unitBaseType = VM_NO_UNIT; |
result->unitBaseType = VM_NO_UNIT; |
101 |
return &result; |
return result; |
102 |
} |
} |
103 |
|
|
104 |
VMFnResult* VMIntResultFunction::successResult(VMIntFnResDef res) { |
VMFnResult* VMIntResultFunction::successResult(VMIntFnResDef res) { |
105 |
result.flags = STMT_SUCCESS; |
result->flags = STMT_SUCCESS; |
106 |
result.value = res.value; |
result->value = res.value; |
107 |
result.unitPrefixFactor = res.unitFactor; |
result->unitPrefixFactor = res.unitFactor; |
108 |
result.unitBaseType = VM_NO_UNIT; |
result->unitBaseType = VM_NO_UNIT; |
109 |
return &result; |
return result; |
110 |
} |
} |
111 |
|
|
112 |
/////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////// |
113 |
// class VMRealResultFunction |
// class VMRealResultFunction |
114 |
|
|
115 |
|
void VMRealResultFunction::bindResult(VMFnResult* res) { |
116 |
|
result = dynamic_cast<VMRealResult*>(res); |
117 |
|
} |
118 |
|
|
119 |
|
VMFnResult* VMRealResultFunction::boundResult() const { |
120 |
|
return result; |
121 |
|
} |
122 |
|
|
123 |
VMFnResult* VMRealResultFunction::errorResult(vmfloat f) { |
VMFnResult* VMRealResultFunction::errorResult(vmfloat f) { |
124 |
result.flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
result->flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
125 |
result.value = f; |
result->value = f; |
126 |
result.unitPrefixFactor = VM_NO_FACTOR; |
result->unitPrefixFactor = VM_NO_FACTOR; |
127 |
result.unitBaseType = VM_NO_UNIT; |
result->unitBaseType = VM_NO_UNIT; |
128 |
return &result; |
return result; |
129 |
} |
} |
130 |
|
|
131 |
VMFnResult* VMRealResultFunction::errorResult(VMRealFnResDef res) { |
VMFnResult* VMRealResultFunction::errorResult(VMRealFnResDef res) { |
132 |
result.flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
result->flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
133 |
result.value = res.value; |
result->value = res.value; |
134 |
result.unitPrefixFactor = res.unitFactor; |
result->unitPrefixFactor = res.unitFactor; |
135 |
result.unitBaseType = VM_NO_UNIT; |
result->unitBaseType = VM_NO_UNIT; |
136 |
return &result; |
return result; |
137 |
} |
} |
138 |
|
|
139 |
VMFnResult* VMRealResultFunction::successResult(vmfloat f) { |
VMFnResult* VMRealResultFunction::successResult(vmfloat f) { |
140 |
result.flags = STMT_SUCCESS; |
result->flags = STMT_SUCCESS; |
141 |
result.value = f; |
result->value = f; |
142 |
result.unitPrefixFactor = VM_NO_FACTOR; |
result->unitPrefixFactor = VM_NO_FACTOR; |
143 |
result.unitBaseType = VM_NO_UNIT; |
result->unitBaseType = VM_NO_UNIT; |
144 |
return &result; |
return result; |
145 |
} |
} |
146 |
|
|
147 |
VMFnResult* VMRealResultFunction::successResult(VMRealFnResDef res) { |
VMFnResult* VMRealResultFunction::successResult(VMRealFnResDef res) { |
148 |
result.flags = STMT_SUCCESS; |
result->flags = STMT_SUCCESS; |
149 |
result.value = res.value; |
result->value = res.value; |
150 |
result.unitPrefixFactor = res.unitFactor; |
result->unitPrefixFactor = res.unitFactor; |
151 |
result.unitBaseType = VM_NO_UNIT; |
result->unitBaseType = VM_NO_UNIT; |
152 |
return &result; |
return result; |
153 |
} |
} |
154 |
|
|
155 |
/////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////// |
156 |
// class VMStringResultFunction |
// class VMStringResultFunction |
157 |
|
|
158 |
|
void VMStringResultFunction::bindResult(VMFnResult* res) { |
159 |
|
result = dynamic_cast<VMStringResult*>(res); |
160 |
|
} |
161 |
|
|
162 |
|
VMFnResult* VMStringResultFunction::boundResult() const { |
163 |
|
return result; |
164 |
|
} |
165 |
|
|
166 |
VMFnResult* VMStringResultFunction::errorResult(const String& s) { |
VMFnResult* VMStringResultFunction::errorResult(const String& s) { |
167 |
result.flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
result->flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
168 |
result.value = s; |
result->value = s; |
169 |
return &result; |
return result; |
170 |
} |
} |
171 |
|
|
172 |
VMFnResult* VMStringResultFunction::successResult(const String& s) { |
VMFnResult* VMStringResultFunction::successResult(const String& s) { |
173 |
result.flags = STMT_SUCCESS; |
result->flags = STMT_SUCCESS; |
174 |
result.value = s; |
result->value = s; |
175 |
return &result; |
return result; |
176 |
} |
} |
177 |
|
|
178 |
/////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////// |
179 |
// class VMNumberResultFunction |
// class VMNumberResultFunction |
180 |
|
|
181 |
|
VMFnResult* VMNumberResultFunction::allocResult(VMFnArgs* args) { |
182 |
|
ExprType_t type = returnType(args); |
183 |
|
if (type == INT_EXPR) |
184 |
|
return new VMIntResult(); |
185 |
|
if (type == REAL_EXPR) |
186 |
|
return new VMRealResult(); |
187 |
|
assert(false); |
188 |
|
return NULL; // just to avoid compiler error, we actually never get here |
189 |
|
} |
190 |
|
|
191 |
|
VMFnResult* VMNumberResultFunction::boundResult() const { |
192 |
|
if (intResult) return intResult; |
193 |
|
return realResult; |
194 |
|
} |
195 |
|
|
196 |
|
void VMNumberResultFunction::bindResult(VMFnResult* res) { |
197 |
|
intResult = dynamic_cast<VMIntResult*>(res); |
198 |
|
if (intResult) { |
199 |
|
realResult = NULL; |
200 |
|
return; |
201 |
|
} |
202 |
|
realResult = dynamic_cast<VMRealResult*>(res); |
203 |
|
} |
204 |
|
|
205 |
VMFnResult* VMNumberResultFunction::errorResult(vmint i) { |
VMFnResult* VMNumberResultFunction::errorResult(vmint i) { |
206 |
intResult.flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
intResult->flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
207 |
intResult.value = i; |
intResult->value = i; |
208 |
intResult.unitPrefixFactor = VM_NO_FACTOR; |
intResult->unitPrefixFactor = VM_NO_FACTOR; |
209 |
intResult.unitBaseType = VM_NO_UNIT; |
intResult->unitBaseType = VM_NO_UNIT; |
210 |
return &intResult; |
return intResult; |
211 |
} |
} |
212 |
|
|
213 |
VMFnResult* VMNumberResultFunction::errorResult(vmfloat f) { |
VMFnResult* VMNumberResultFunction::errorResult(vmfloat f) { |
214 |
realResult.flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
realResult->flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
215 |
realResult.value = f; |
realResult->value = f; |
216 |
realResult.unitPrefixFactor = VM_NO_FACTOR; |
realResult->unitPrefixFactor = VM_NO_FACTOR; |
217 |
intResult.unitBaseType = VM_NO_UNIT; |
intResult->unitBaseType = VM_NO_UNIT; |
218 |
return &realResult; |
return realResult; |
219 |
} |
} |
220 |
|
|
221 |
VMFnResult* VMNumberResultFunction::successResult(vmint i) { |
VMFnResult* VMNumberResultFunction::successResult(vmint i) { |
222 |
intResult.flags = STMT_SUCCESS; |
intResult->flags = STMT_SUCCESS; |
223 |
intResult.value = i; |
intResult->value = i; |
224 |
intResult.unitPrefixFactor = VM_NO_FACTOR; |
intResult->unitPrefixFactor = VM_NO_FACTOR; |
225 |
intResult.unitBaseType = VM_NO_UNIT; |
intResult->unitBaseType = VM_NO_UNIT; |
226 |
return &intResult; |
return intResult; |
227 |
} |
} |
228 |
|
|
229 |
VMFnResult* VMNumberResultFunction::successResult(vmfloat f) { |
VMFnResult* VMNumberResultFunction::successResult(vmfloat f) { |
230 |
realResult.flags = STMT_SUCCESS; |
realResult->flags = STMT_SUCCESS; |
231 |
realResult.value = f; |
realResult->value = f; |
232 |
realResult.unitPrefixFactor = VM_NO_FACTOR; |
realResult->unitPrefixFactor = VM_NO_FACTOR; |
233 |
realResult.unitBaseType = VM_NO_UNIT; |
realResult->unitBaseType = VM_NO_UNIT; |
234 |
return &realResult; |
return realResult; |
235 |
} |
} |
236 |
|
|
237 |
VMFnResult* VMNumberResultFunction::errorIntResult(VMIntFnResDef res) { |
VMFnResult* VMNumberResultFunction::errorIntResult(VMIntFnResDef res) { |
238 |
intResult.flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
intResult->flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
239 |
intResult.value = res.value; |
intResult->value = res.value; |
240 |
intResult.unitPrefixFactor = res.unitFactor; |
intResult->unitPrefixFactor = res.unitFactor; |
241 |
intResult.unitBaseType = VM_NO_UNIT; |
intResult->unitBaseType = VM_NO_UNIT; |
242 |
return &intResult; |
return intResult; |
243 |
} |
} |
244 |
|
|
245 |
VMFnResult* VMNumberResultFunction::errorRealResult(VMRealFnResDef res) { |
VMFnResult* VMNumberResultFunction::errorRealResult(VMRealFnResDef res) { |
246 |
realResult.flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
realResult->flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
247 |
realResult.value = res.value; |
realResult->value = res.value; |
248 |
realResult.unitPrefixFactor = res.unitFactor; |
realResult->unitPrefixFactor = res.unitFactor; |
249 |
realResult.unitBaseType = VM_NO_UNIT; |
realResult->unitBaseType = VM_NO_UNIT; |
250 |
return &realResult; |
return realResult; |
251 |
} |
} |
252 |
|
|
253 |
VMFnResult* VMNumberResultFunction::successIntResult(VMIntFnResDef res) { |
VMFnResult* VMNumberResultFunction::successIntResult(VMIntFnResDef res) { |
254 |
intResult.flags = STMT_SUCCESS; |
intResult->flags = STMT_SUCCESS; |
255 |
intResult.value = res.value; |
intResult->value = res.value; |
256 |
intResult.unitPrefixFactor = res.unitFactor; |
intResult->unitPrefixFactor = res.unitFactor; |
257 |
intResult.unitBaseType = VM_NO_UNIT; |
intResult->unitBaseType = VM_NO_UNIT; |
258 |
return &intResult; |
return intResult; |
259 |
} |
} |
260 |
|
|
261 |
VMFnResult* VMNumberResultFunction::successRealResult(VMRealFnResDef res) { |
VMFnResult* VMNumberResultFunction::successRealResult(VMRealFnResDef res) { |
262 |
realResult.flags = STMT_SUCCESS; |
realResult->flags = STMT_SUCCESS; |
263 |
realResult.value = res.value; |
realResult->value = res.value; |
264 |
realResult.unitPrefixFactor = res.unitFactor; |
realResult->unitPrefixFactor = res.unitFactor; |
265 |
realResult.unitBaseType = VM_NO_UNIT; |
realResult->unitBaseType = VM_NO_UNIT; |
266 |
return &realResult; |
return realResult; |
267 |
} |
} |
268 |
|
|
269 |
/////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////// |
326 |
} |
} |
327 |
|
|
328 |
VMFnResult* CoreVMFunction_exit::exec(VMFnArgs* args) { |
VMFnResult* CoreVMFunction_exit::exec(VMFnArgs* args) { |
329 |
this->result.flags = STMT_ABORT_SIGNALLED; |
this->result->flags = STMT_ABORT_SIGNALLED; |
330 |
if (vm->isExitResultEnabled() && args->argsCount()) { |
if (vm->isExitResultEnabled() && args->argsCount()) { |
331 |
ExecContext* ctx = dynamic_cast<ExecContext*>(vm->currentVMExecContext()); |
ExecContext* ctx = dynamic_cast<ExecContext*>(vm->currentVMExecContext()); |
332 |
switch (args->arg(0)->exprType()) { |
switch (args->arg(0)->exprType()) { |
362 |
; // noop - just to shut up the compiler |
; // noop - just to shut up the compiler |
363 |
} |
} |
364 |
} |
} |
365 |
return &result; |
return result; |
366 |
} |
} |
367 |
|
|
368 |
/////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////// |
386 |
StdUnit_t unit = expr->unitType(); |
StdUnit_t unit = expr->unitType(); |
387 |
vmint us = (unit) ? expr->evalCastInt(VM_MICRO) : expr->evalCastInt(); |
vmint us = (unit) ? expr->evalCastInt(VM_MICRO) : expr->evalCastInt(); |
388 |
if (us < 0) { |
if (us < 0) { |
389 |
wrnMsg("wait(): argument may not be negative! Aborting script!"); |
wrnMsg("wait(): argument may not be negative! Aborting handler!"); |
390 |
this->result.flags = STMT_ABORT_SIGNALLED; |
this->result->flags = STMT_ABORT_SIGNALLED; |
391 |
} else if (us == 0) { |
} else if (us == 0) { |
392 |
wrnMsg("wait(): argument may not be zero! Aborting script!"); |
wrnMsg("wait(): argument may not be zero! Aborting handler!"); |
393 |
this->result.flags = STMT_ABORT_SIGNALLED; |
this->result->flags = STMT_ABORT_SIGNALLED; |
394 |
} else { |
} else { |
395 |
ctx->suspendMicroseconds = us; |
ctx->suspendMicroseconds = us; |
396 |
this->result.flags = STMT_SUSPEND_SIGNALLED; |
this->result->flags = STMT_SUSPEND_SIGNALLED; |
397 |
} |
} |
398 |
return &result; |
return result; |
399 |
} |
} |
400 |
|
|
401 |
/////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////// |