[squeak-dev] Villainous superpowers (Re: How to do logging)
Bert Freudenberg
bert at freudenbergs.de
Thu Nov 27 22:55:37 UTC 2008
On 27.11.2008, at 21:52, Michael van der Gulik wrote:
>> On Fri, Nov 28, 2008 at 8:52 AM, Bert Freudenberg <bert at freudenbergs.de
>> > wrote:
>>
>>> On 27.11.2008, at 18:44, Keith Hodges wrote:
>>>
>>> Hello All,
>>>
>>> I need a villainous superpower that I haven't needed before, can
>>> anyone
>>> tell me how to achieve this.
>>>
>>> I have some code like this:
>>>
>>> self send a message to me.
>>> self nextThing.
>>>
>>> or
>>>
>>> self send a message to me.
>>> A := self nextThing.
>>>
>>> What naughty superpower code can I put in to #send that will jump
>>> execution to self nextThing directly?
>>
>>
>> send
>> ...
>> thisContext sender jump: 4
>>
>> This skips 4 bytecodes in the calling method before returning, so
>> instead of pc=31 it continues at pc=35:
>>
>
> In terms of code smells, this is chemical warfare!! :-D.
No doubt about this. Kids, don't try this at home.
It still tremendous fun that you can do it. Keith, I have no idea what
you need this for but I think the following is pretty complete - it
skips until the next pop bytecode which marks the end of the current
statement. It should get confused only if there was a block in that
line that had a pop in itself:
send
Transcript show: 'send '.
self returnToPop.
self neverReached
returnToPop
| ctxt |
ctxt := thisContext sender sender.
[ctxt nextByte = 135]
whileFalse: [ctxt jump: 1].
ctxt resume
Try filing in attachment and eval "Evil new test"
- Bert -
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Evil.st
Type: application/octet-stream
Size: 937 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20081127/5ba4ae8c/Evil.obj
More information about the Squeak-dev
mailing list
|