How to get the return value of a context?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to get the return value of a context?

NorbertHartl
I'm trying to interleave some behavior in the normal execution flow.

For this I do something like


   targetCtx := self findTargetContext.
   interleavedCtx := [ self doSomething ] asContext.
   interleavedCtx swapSender: (targetCtx swapSender: interleavedCtx).

Basically this works pretty fine. Now I have the case that targetCtx returns a value that was assigned to a variable in the original code

   bar := self methodOfTheTargetCtx

What is a good way to get the return value of targetCtx? I think there is an easy way but I didn't find it. Even my very hacky tries failed. I did a manual test by having

   interleavedCtx := [ | foo |
      foo := self dummySend
      …
   ]

and setting the pc of the context just after the "send: dummySend" which is "popIntoTemp: 1". I thought at least that should bring the return value to foo but it didn't work.

Maybe I'm doing just something stupid on the way. Some hints for enlightenment would be fine.

thanks,

Norbert
 

   
Reply | Threaded
Open this post in threaded view
|

Re: How to get the return value of a context?

NorbertHartl

Am 04.09.2013 um 14:19 schrieb Norbert Hartl <[hidden email]>:

 interleavedCtx := [ | foo |
     foo := self dummySend
     …
  ]

It doesn't work with a temp inside the block. Using a method temp does what I think it does. So the very hackish way of doing it is at the moment

   | foo |
   ...
   interleavedCtx := [  
      foo := self dummy.
      …
      foo ] asContext.
      interleavedCtx pc: intermediateCtx startpc + 2.
      interleavedCtx swapSender: (targetCtx swapSender: interleavedCtx) 

I hope there is a more elaborate way of doing this (beside calculating the byte code offset more reliable).

Norbert