199 initialPC := initial |
199 initialPC := initial |
200 ! ! |
200 ! ! |
201 |
201 |
202 !Block methodsFor:'error handling'! |
202 !Block methodsFor:'error handling'! |
203 |
203 |
204 argumentCountError:numberGiven |
204 wrongNumberOfArguments:numberGiven |
205 "report that the number of arguments given does not match the number expected" |
205 "report that the number of arguments given does not match the number expected" |
206 |
206 |
207 self error:('Block got ' , numberGiven printString , |
207 ArgumentSignal |
208 ' args while ' , nargs printString , ' where expected') |
208 raiseRequestWith:self |
|
209 errorString:('block got ' , numberGiven printString , |
|
210 ' args while ' , nargs printString , ' where expected') |
209 ! |
211 ! |
210 |
212 |
211 invalidMethod |
213 invalidMethod |
212 "this error is triggered by the interpreter when a non-Block object |
214 "this error is triggered by the interpreter when a non-Block object |
213 is about to be executed. |
215 is about to be executed. |
214 In this case, the VM sends this to the bad method (the receiver). |
216 In this case, the VM sends this to the bad method (the receiver). |
215 Can only happen when the Compiler/runtime system is broken or |
217 Can only happen when the Compiler/runtime system is broken or |
216 someone played around." |
218 someone played around." |
217 |
219 |
218 self error:'invalid block - not executable' |
220 InvalidCodeSignal |
219 ! |
221 raiseRequestWith:self |
220 |
222 errorString:'invalid block - not executable' |
221 tooManySendArguments |
|
222 "this error is triggered, when a method tries to perform a send with |
|
223 more arguments than supported by the interpreter - this can only |
|
224 happen, if the compiler has been changed without updating the VM." |
|
225 |
|
226 self error:'too many send args - should not happen' |
|
227 ! |
|
228 |
|
229 tooManyArguments |
|
230 "this error is triggered, when a method is called with more arguments |
|
231 than supported by the interpreter - this can only happen, if the |
|
232 compiler has been changed without updating the VM." |
|
233 |
|
234 self error:'block has too many args - should not happen' |
|
235 ! ! |
223 ! ! |
236 |
224 |
237 !Block methodsFor:'evaluation'! |
225 !Block methodsFor:'evaluation'! |
238 |
226 |
239 value |
227 value |
268 RETURN ( interpret(self, 0, nil, home COMMA_SND, nil) ); |
256 RETURN ( interpret(self, 0, nil, home COMMA_SND, nil) ); |
269 #endif |
257 #endif |
270 } |
258 } |
271 %} |
259 %} |
272 . |
260 . |
273 ^ self argumentCountError:0 |
261 ^ self wrongNumberOfArguments:0 |
274 ! |
262 ! |
275 |
263 |
276 value:arg |
264 value:arg |
277 "evaluate the receiver with one argument. The receiver must be a 1-arg block." |
265 "evaluate the receiver with one argument. The receiver must be a 1-arg block." |
278 |
266 |
303 RETURN ( interpret(self, 1, nil, home COMMA_SND, nil, arg) ); |
291 RETURN ( interpret(self, 1, nil, home COMMA_SND, nil, arg) ); |
304 #endif |
292 #endif |
305 } |
293 } |
306 %} |
294 %} |
307 . |
295 . |
308 ^ self argumentCountError:1 |
296 ^ self wrongNumberOfArguments:1 |
309 ! |
297 ! |
310 |
298 |
311 value:arg1 value:arg2 |
299 value:arg1 value:arg2 |
312 "evaluate the receiver with two arguments. The receiver must be a 2-arg block." |
300 "evaluate the receiver with two arguments. The receiver must be a 2-arg block." |
313 |
301 |
336 RETURN ( interpret(self, 2, nil, home COMMA_SND, nil, arg1, arg2) ); |
324 RETURN ( interpret(self, 2, nil, home COMMA_SND, nil, arg1, arg2) ); |
337 #endif |
325 #endif |
338 } |
326 } |
339 %} |
327 %} |
340 . |
328 . |
341 ^ self argumentCountError:2 |
329 ^ self wrongNumberOfArguments:2 |
342 ! |
330 ! |
343 |
331 |
344 value:arg1 value:arg2 value:arg3 |
332 value:arg1 value:arg2 value:arg3 |
345 "evaluate the receiver with three arguments. The receiver must be a 3-arg block." |
333 "evaluate the receiver with three arguments. The receiver must be a 3-arg block." |
346 |
334 |
369 RETURN ( interpret(self, 3, nil, home COMMA_SND, nil, arg1, arg2, arg3) ); |
357 RETURN ( interpret(self, 3, nil, home COMMA_SND, nil, arg1, arg2, arg3) ); |
370 #endif |
358 #endif |
371 } |
359 } |
372 %} |
360 %} |
373 . |
361 . |
374 ^ self argumentCountError:3 |
362 ^ self wrongNumberOfArguments:3 |
375 ! |
363 ! |
376 |
364 |
377 value:arg1 value:arg2 value:arg3 value:arg4 |
365 value:arg1 value:arg2 value:arg3 value:arg4 |
378 "evaluate the receiver with four arguments. The receiver must be a 4-arg block." |
366 "evaluate the receiver with four arguments. The receiver must be a 4-arg block." |
379 |
367 |
402 RETURN ( interpret(self, 4, nil, home COMMA_SND, nil, arg1, arg2, arg3, arg4) ); |
390 RETURN ( interpret(self, 4, nil, home COMMA_SND, nil, arg1, arg2, arg3, arg4) ); |
403 #endif |
391 #endif |
404 } |
392 } |
405 %} |
393 %} |
406 . |
394 . |
407 ^ self argumentCountError:4 |
395 ^ self wrongNumberOfArguments:4 |
408 ! |
396 ! |
409 |
397 |
410 value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 |
398 value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 |
411 "evaluate the receiver with four arguments. The receiver must be a 5-arg block." |
399 "evaluate the receiver with four arguments. The receiver must be a 5-arg block." |
412 |
400 |
435 RETURN ( interpret(self, 5, nil, home COMMA_SND, nil, arg1, arg2, arg3, arg4, arg5) ); |
423 RETURN ( interpret(self, 5, nil, home COMMA_SND, nil, arg1, arg2, arg3, arg4, arg5) ); |
436 #endif |
424 #endif |
437 } |
425 } |
438 %} |
426 %} |
439 . |
427 . |
440 ^ self argumentCountError:5 |
428 ^ self wrongNumberOfArguments:5 |
441 ! |
429 ! |
442 |
430 |
443 value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 |
431 value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 |
444 "evaluate the receiver with four arguments. The receiver must be a 6-arg block." |
432 "evaluate the receiver with four arguments. The receiver must be a 6-arg block." |
445 |
433 |
468 RETURN ( interpret(self, 6, nil, home COMMA_SND, nil, arg1, arg2, arg3, arg4, arg5, arg6) ); |
456 RETURN ( interpret(self, 6, nil, home COMMA_SND, nil, arg1, arg2, arg3, arg4, arg5, arg6) ); |
469 #endif |
457 #endif |
470 } |
458 } |
471 %} |
459 %} |
472 . |
460 . |
473 ^ self argumentCountError:6 |
461 ^ self wrongNumberOfArguments:6 |
474 ! |
462 ! |
475 |
463 |
476 valueWithArguments:argArray |
464 valueWithArguments:argArray |
477 "evaluate the receiver with arguments taken from argArray. |
465 "evaluate the receiver with arguments taken from argArray. |
478 The size of the argArray must match the number of arguments the receiver expects." |
466 The size of the argArray must match the number of arguments the receiver expects." |
479 |
467 |
480 |a1 a2 a3 a4 a5 a6 a7| |
468 |a1 a2 a3 a4 a5 a6 a7| |
481 |
469 |
482 (argArray class == Array) ifFalse:[ |
470 (argArray class == Array) ifFalse:[ |
483 ^ self error:'argument must be an array' |
471 ^ self badArgumentArry |
484 ]. |
472 ]. |
485 (argArray size == nargs) ifFalse:[ |
473 (argArray size == nargs) ifFalse:[ |
486 ^ self argumentCountError:(argArray size) |
474 ^ self wrongNumberOfArguments:(argArray size) |
487 ]. |
475 ]. |
488 %{ |
476 %{ |
489 |
477 |
490 REGISTER OBJFUNC thecode; |
478 REGISTER OBJFUNC thecode; |
491 OBJ home; |
479 OBJ home; |
533 #endif |
521 #endif |
534 |
522 |
535 error: ; |
523 error: ; |
536 %} |
524 %} |
537 . |
525 . |
538 self error:'only blocks with up-to 7 arguments supported' |
526 ArgumentSignal |
|
527 raiseRequestWith:self |
|
528 errorString:'only blocks with up-to 7 arguments supported' |
539 ! |
529 ! |
540 |
530 |
541 valueNowOrOnUnwindDo:aBlock |
531 valueNowOrOnUnwindDo:aBlock |
542 "evaluate the receiver - after that, or when some method sent within unwinds (i.e. does |
532 "evaluate the receiver - after that, or when some method sent within unwinds (i.e. does |
543 a long return), evaluate the argument, aBlock. |
533 a long return), evaluate the argument, aBlock. |