Hi I am working with the InterpreterSimulator and I would like to send a message to an object inside the simulated environment. For example, I have the oop for true and I want to send it the message printString. My question is if this is possible. I don't know if there is a way to send a message to an object inside the simulation. I have thought about tinkering with the stack and calling an interpreter method. But I am not sure if this will work. Any hint will be much appreciated. Thanks in advance. Gabriel |
On 6 January 2011 16:41, Gabriel Hernán Barbuto <[hidden email]> wrote: > > Hi > > I am working with the InterpreterSimulator and I would like to send a > message to an object inside the simulated environment. For example, I > have the oop for true and I want to send it the message printString. > > My question is if this is possible. I don't know if there is a way to > send a message to an object inside the simulation. I have thought > about tinkering with the stack and calling an interpreter method. But > I am not sure if this will work. > Hi, Gabriel. The problem is, that even if you prepare a context and all arguments for message send, you should start interpreting the code and then leave the interpret loop once you received the answer. But if you look at #interpret method, there is an infinite loop, and no way how to escape it. I don't know if there is a way to tell simulator to leave the loop at certain point. P.S. In general, it would be cool to have something like: sqInt interpreter_call( sqInt receiver , sqInt selector , sqInt * arguments ) means: send message to receiver and return the answer. Unfortunately, Squeak VM does not provides such things, in contrast to languages like Lua, which providing C interoperability layer by default from very beginning of it existence. > Any hint will be much appreciated. Thanks in advance. > > Gabriel > -- Best regards, Igor Stasenko AKA sig. |
All you need to support this is in the Android VM. The Android VM calls interpret() in response to every input event and interpret() returns when the event is handled[*]. If you add an event that gets a selector (or some source code to be evaluated) you have just what you were looking for. [*] For a certain definition of "handled", involving aspects such as whether delays are involved, or other processes are being scheduled. In effect, the VM runs as long as there are active processes, and returns when there is no more work to do. Whether or not that corresponds with the result of the input expression is a different question. Cheers, - Andreas On 1/6/2011 5:00 PM, Igor Stasenko wrote: > > On 6 January 2011 16:41, Gabriel Hernán Barbuto<[hidden email]> wrote: >> >> Hi >> >> I am working with the InterpreterSimulator and I would like to send a >> message to an object inside the simulated environment. For example, I >> have the oop for true and I want to send it the message printString. >> >> My question is if this is possible. I don't know if there is a way to >> send a message to an object inside the simulation. I have thought >> about tinkering with the stack and calling an interpreter method. But >> I am not sure if this will work. >> > > Hi, Gabriel. > The problem is, that even if you prepare a context and all arguments > for message send, > you should start interpreting the code and then leave the interpret > loop once you received the answer. > But if you look at #interpret method, there is an infinite loop, > and no way how to escape it. > > I don't know if there is a way to tell simulator to leave the loop at > certain point. > > > P.S. In general, it would be cool to have something like: > > sqInt interpreter_call( sqInt receiver , sqInt selector , sqInt * arguments ) > > means: send message to receiver and return the answer. > > Unfortunately, Squeak VM does not provides such things, in contrast to > languages like Lua, > which providing C interoperability layer by default from very > beginning of it existence. > >> Any hint will be much appreciated. Thanks in advance. >> >> Gabriel >> > > |
In reply to this post by Igor Stasenko
Igor Thanks for your reply. But my idea was not to call interpret. I am aware of the infinite loop. I would like to push the selector and the receiver onto the stack and then call something like Interpreter>>#commonSend and then clean the stack. Maybe I cannot call Interpreter>>#commonSend because it fetches the next byte code and I don't want to modify the execution state. But at least perform the rest of the calls. I don't know if this makes any sense. >From what I have learned so far. Besides that this approach might not work. The problem seems to be creating the selector. If I can create the selector I will try it anyway. Thanks again. Gabriel On Thu, Jan 6, 2011 at 5:00 PM, Igor Stasenko <[hidden email]> wrote: > > On 6 January 2011 16:41, Gabriel Hernán Barbuto <[hidden email]> wrote: >> >> Hi >> >> I am working with the InterpreterSimulator and I would like to send a >> message to an object inside the simulated environment. For example, I >> have the oop for true and I want to send it the message printString. >> >> My question is if this is possible. I don't know if there is a way to >> send a message to an object inside the simulation. I have thought >> about tinkering with the stack and calling an interpreter method. But >> I am not sure if this will work. >> > > Hi, Gabriel. > The problem is, that even if you prepare a context and all arguments > for message send, > you should start interpreting the code and then leave the interpret > loop once you received the answer. > But if you look at #interpret method, there is an infinite loop, > and no way how to escape it. > > I don't know if there is a way to tell simulator to leave the loop at > certain point. > > > P.S. In general, it would be cool to have something like: > > sqInt interpreter_call( sqInt receiver , sqInt selector , sqInt * arguments ) > > means: send message to receiver and return the answer. > > Unfortunately, Squeak VM does not provides such things, in contrast to > languages like Lua, > which providing C interoperability layer by default from very > beginning of it existence. > >> Any hint will be much appreciated. Thanks in advance. >> >> Gabriel >> > > > -- > Best regards, > Igor Stasenko AKA sig. > |
In reply to this post by Gabriel Hernán Barbuto
Hi Gabriel, On Thu, Jan 6, 2011 at 7:41 AM, Gabriel Hernán Barbuto <[hidden email]> wrote:
I'm sure you could get it to work. To send printString to true simply push true, set messageSelector to printString (there are methods to search for strings to track down the selector) and argumentCount to 0 and send commonSend. There are all sorts of issues. Is the VM at a suspension point? Will the stack be balanced? What if a process switch happens during your message? How can you collect the result? But these al have answers.
What are you actually trying to do?
|
In reply to this post by Andreas.Raab
Andreas Thanks for your reply. I think I should've given more information. I am running the simulator, and while debugging I found that following oops is too hard. Maybe there is another way that I am not aware of. I am trying to implement a wrapper around the oops. I can get at the structure of an object and see its class and if it has any instance variables. The problem is when I want to see the object in an inspector. For example, for oop = 4. I can see its class is as expected UndefinedObject. But I want to get nil to display. Maybe for nil is not that important but for example, for true and false I think it's important. I have tried with InterpreterSimulator>>#stringOf: but it does not work. I have no idea about the Android VM. But I will take a look at it. I don't want to change the Interpreter. This object is meant to work with the simulator. I thought it would be possible to make the interpreter to interpret a method call that does not really exist in the byte code stream. Thanks again, and I hope this clarifies what I am trying to achieve and how I thought it would be possible. Cheers Gabriel On Thu, Jan 6, 2011 at 5:27 PM, Andreas Raab <[hidden email]> wrote: > > All you need to support this is in the Android VM. The Android VM calls > interpret() in response to every input event and interpret() returns when > the event is handled[*]. If you add an event that gets a selector (or some > source code to be evaluated) you have just what you were looking for. > > [*] For a certain definition of "handled", involving aspects such as whether > delays are involved, or other processes are being scheduled. In effect, the > VM runs as long as there are active processes, and returns when there is no > more work to do. Whether or not that corresponds with the result of the > input expression is a different question. > > Cheers, > - Andreas > > On 1/6/2011 5:00 PM, Igor Stasenko wrote: >> >> On 6 January 2011 16:41, Gabriel Hernán Barbuto<[hidden email]> >> wrote: >>> >>> Hi >>> >>> I am working with the InterpreterSimulator and I would like to send a >>> message to an object inside the simulated environment. For example, I >>> have the oop for true and I want to send it the message printString. >>> >>> My question is if this is possible. I don't know if there is a way to >>> send a message to an object inside the simulation. I have thought >>> about tinkering with the stack and calling an interpreter method. But >>> I am not sure if this will work. >>> >> >> Hi, Gabriel. >> The problem is, that even if you prepare a context and all arguments >> for message send, >> you should start interpreting the code and then leave the interpret >> loop once you received the answer. >> But if you look at #interpret method, there is an infinite loop, >> and no way how to escape it. >> >> I don't know if there is a way to tell simulator to leave the loop at >> certain point. >> >> >> P.S. In general, it would be cool to have something like: >> >> sqInt interpreter_call( sqInt receiver , sqInt selector , sqInt * >> arguments ) >> >> means: send message to receiver and return the answer. >> >> Unfortunately, Squeak VM does not provides such things, in contrast to >> languages like Lua, >> which providing C interoperability layer by default from very >> beginning of it existence. >> >>> Any hint will be much appreciated. Thanks in advance. >>> >>> Gabriel >>> >> >> > |
In reply to this post by Eliot Miranda-2
On Jan 6, 2011, at 6:23 PM, Eliot Miranda wrote: > Hi Gabriel, > > On Thu, Jan 6, 2011 at 7:41 AM, Gabriel Hernán Barbuto <[hidden email]> wrote: > > Hi > > I am working with the InterpreterSimulator and I would like to send a > message to an object inside the simulated environment. For example, I > have the oop for true and I want to send it the message printString. > > My question is if this is possible. I don't know if there is a way to > send a message to an object inside the simulation. I have thought > about tinkering with the stack and calling an interpreter method. But > I am not sure if this will work. > > I'm sure you could get it to work. To send printString to true simply push true, set messageSelector to printString (there are methods to search for strings to track down the selector) and argumentCount to 0 and send commonSend. There are all sorts of issues. Is the VM at a suspension point? Will the stack be balanced? What if a process switch happens during your message? How can you collect the result? But these al have answers. > > What are you actually trying to do? improving the interface of Simulator so that we can get a bit more out of the numbers :) Igor suggested to gabriel to implement a proxy so that we accessed faster iv and other structural information. > > > Any hint will be much appreciated. Thanks in advance. > > Gabriel > |
In reply to this post by Eliot Miranda-2
Eliot Thanks for your reply. I have just clarified what I am trying to achieve in the response to Andreas mail and Stef already answered your question. I was sure that a lot of issues will pop up and that I would have to find answers to them. For know I have loaded an image, and I want to inspect the objects. This seems to be the easy case. Because the VM is not really running so I think I won't get into any of the situations that you mentioned. But I think that to be able to provide a general wrapper for oops I will have to work on the things you mentioned. It's good to hear that it's doable and that there are answers for all the issues. I will try to implement the simple case and see how it works. I still need to find how to get at the printString selector but the information you provided will set me on the right track. Thanks again. Cheers Gabriel On Thu, Jan 6, 2011 at 6:23 PM, Eliot Miranda <[hidden email]> wrote: > > Hi Gabriel, > On Thu, Jan 6, 2011 at 7:41 AM, Gabriel Hernán Barbuto <[hidden email]> wrote: >> >> Hi >> >> I am working with the InterpreterSimulator and I would like to send a >> message to an object inside the simulated environment. For example, I >> have the oop for true and I want to send it the message printString. >> >> My question is if this is possible. I don't know if there is a way to >> send a message to an object inside the simulation. I have thought >> about tinkering with the stack and calling an interpreter method. But >> I am not sure if this will work. > > I'm sure you could get it to work. To send printString to true simply push true, set messageSelector to printString (there are methods to search for strings to track down the selector) and argumentCount to 0 and send commonSend. There are all sorts of issues. Is the VM at a suspension point? Will the stack be balanced? What if a process switch happens during your message? How can you collect the result? But these al have answers. > What are you actually trying to do? >> >> Any hint will be much appreciated. Thanks in advance. >> >> Gabriel > > > |
In reply to this post by Gabriel Hernán Barbuto
On 1/6/2011 6:09 PM, Gabriel Hernán Barbuto wrote: > I would like to push the selector and the receiver onto the stack and > then call something like Interpreter>>#commonSend and then clean the > stack. The 'correct' way to do that would be by: a) Creating a process for the message b) Setting up the context c) Pushing rcvr, selector, args d) Run the process until it completes e) Return the result Cheers, - Andreas > Maybe I cannot call Interpreter>>#commonSend because it fetches the > next byte code and I don't want to modify the execution state. But at > least perform the rest of the calls. I don't know if this makes any > sense. > >> From what I have learned so far. Besides that this approach might not > work. The problem seems to be creating the selector. If I can create > the selector I will try it anyway. > > Thanks again. > > Gabriel > > > On Thu, Jan 6, 2011 at 5:00 PM, Igor Stasenko<[hidden email]> wrote: >> >> On 6 January 2011 16:41, Gabriel Hernán Barbuto<[hidden email]> wrote: >>> >>> Hi >>> >>> I am working with the InterpreterSimulator and I would like to send a >>> message to an object inside the simulated environment. For example, I >>> have the oop for true and I want to send it the message printString. >>> >>> My question is if this is possible. I don't know if there is a way to >>> send a message to an object inside the simulation. I have thought >>> about tinkering with the stack and calling an interpreter method. But >>> I am not sure if this will work. >>> >> >> Hi, Gabriel. >> The problem is, that even if you prepare a context and all arguments >> for message send, >> you should start interpreting the code and then leave the interpret >> loop once you received the answer. >> But if you look at #interpret method, there is an infinite loop, >> and no way how to escape it. >> >> I don't know if there is a way to tell simulator to leave the loop at >> certain point. >> >> >> P.S. In general, it would be cool to have something like: >> >> sqInt interpreter_call( sqInt receiver , sqInt selector , sqInt * arguments ) >> >> means: send message to receiver and return the answer. >> >> Unfortunately, Squeak VM does not provides such things, in contrast to >> languages like Lua, >> which providing C interoperability layer by default from very >> beginning of it existence. >> >>> Any hint will be much appreciated. Thanks in advance. >>> >>> Gabriel >>> >> >> >> -- >> Best regards, >> Igor Stasenko AKA sig. >> > |
On 6 January 2011 19:10, Andreas Raab <[hidden email]> wrote: > > On 1/6/2011 6:09 PM, Gabriel Hernán Barbuto wrote: >> >> I would like to push the selector and the receiver onto the stack and >> then call something like Interpreter>>#commonSend and then clean the >> stack. > > The 'correct' way to do that would be by: > a) Creating a process for the message > b) Setting up the context > c) Pushing rcvr, selector, args > d) Run the process until it completes > e) Return the result > (a) can be done once, and then reused for subsequent calls. (if to move scheduling logic to image side, then its not necessary). A signal to leave interpreter loop could be that context have nowhere to return to. Alas.. the current VM semantics is to signal exception when this happens. But for, an interpreter simulator one could do the trick by overriding the: internalCannotReturn: resultObj <inline: true> self internalPush: activeContext. self internalPush: resultObj. messageSelector := self splObj: SelectorCannotReturn. argumentCount := 1. ^ self normalSend and check if its in 'waiting for call to return', and so, do the proper interpreter state cleanup, and return value to caller (to one who sent something like: simulator send: #foo to: barOop args: { a . b . c . } ) > Cheers, > - Andreas > >> Maybe I cannot call Interpreter>>#commonSend because it fetches the >> next byte code and I don't want to modify the execution state. But at >> least perform the rest of the calls. I don't know if this makes any >> sense. >> >>> From what I have learned so far. Besides that this approach might not >> >> work. The problem seems to be creating the selector. If I can create >> the selector I will try it anyway. >> >> Thanks again. >> >> Gabriel >> >> >> On Thu, Jan 6, 2011 at 5:00 PM, Igor Stasenko<[hidden email]> wrote: >>> >>> On 6 January 2011 16:41, Gabriel Hernán Barbuto<[hidden email]> >>> wrote: >>>> >>>> Hi >>>> >>>> I am working with the InterpreterSimulator and I would like to send a >>>> message to an object inside the simulated environment. For example, I >>>> have the oop for true and I want to send it the message printString. >>>> >>>> My question is if this is possible. I don't know if there is a way to >>>> send a message to an object inside the simulation. I have thought >>>> about tinkering with the stack and calling an interpreter method. But >>>> I am not sure if this will work. >>>> >>> >>> Hi, Gabriel. >>> The problem is, that even if you prepare a context and all arguments >>> for message send, >>> you should start interpreting the code and then leave the interpret >>> loop once you received the answer. >>> But if you look at #interpret method, there is an infinite loop, >>> and no way how to escape it. >>> >>> I don't know if there is a way to tell simulator to leave the loop at >>> certain point. >>> >>> >>> P.S. In general, it would be cool to have something like: >>> >>> sqInt interpreter_call( sqInt receiver , sqInt selector , sqInt * >>> arguments ) >>> >>> means: send message to receiver and return the answer. >>> >>> Unfortunately, Squeak VM does not provides such things, in contrast to >>> languages like Lua, >>> which providing C interoperability layer by default from very >>> beginning of it existence. >>> >>>> Any hint will be much appreciated. Thanks in advance. >>>> >>>> Gabriel >>>> >>> >>> >>> -- >>> Best regards, >>> Igor Stasenko AKA sig. >>> >> > -- Best regards, Igor Stasenko AKA sig. |
In reply to this post by Gabriel Hernán Barbuto
Hi Gabriel-- If you just want a description of an oop, use InterpreterSimulator>>shortPrint: and longPrint:. When I actually do want to send arbitrary messages to an object in simulation, I send remote messages from another object memory. This works because I wrote simulator support for the networking primitives in Flow. good luck, -C -- Craig Latta www.netjam.org/resume + 31 020 894 6247 + 1 415 287 3547 |
In reply to this post by Andreas.Raab
Andreas Thank you very much for the correct way to implement this. I don't know how to carry all these steps but I will learn how to do them. I am trying now to get the list of the instance variables, this seems to be easier. But the next step will be to display the value of these variables so I will need to do this anyway. Cheers Gabriel On Thu, Jan 6, 2011 at 7:10 PM, Andreas Raab <[hidden email]> wrote: > > On 1/6/2011 6:09 PM, Gabriel Hernán Barbuto wrote: >> >> I would like to push the selector and the receiver onto the stack and >> then call something like Interpreter>>#commonSend and then clean the >> stack. > > The 'correct' way to do that would be by: > a) Creating a process for the message > b) Setting up the context > c) Pushing rcvr, selector, args > d) Run the process until it completes > e) Return the result > > Cheers, > - Andreas > >> Maybe I cannot call Interpreter>>#commonSend because it fetches the >> next byte code and I don't want to modify the execution state. But at >> least perform the rest of the calls. I don't know if this makes any >> sense. >> >>> From what I have learned so far. Besides that this approach might not >> >> work. The problem seems to be creating the selector. If I can create >> the selector I will try it anyway. >> >> Thanks again. >> >> Gabriel >> >> >> On Thu, Jan 6, 2011 at 5:00 PM, Igor Stasenko<[hidden email]> wrote: >>> >>> On 6 January 2011 16:41, Gabriel Hernán Barbuto<[hidden email]> >>> wrote: >>>> >>>> Hi >>>> >>>> I am working with the InterpreterSimulator and I would like to send a >>>> message to an object inside the simulated environment. For example, I >>>> have the oop for true and I want to send it the message printString. >>>> >>>> My question is if this is possible. I don't know if there is a way to >>>> send a message to an object inside the simulation. I have thought >>>> about tinkering with the stack and calling an interpreter method. But >>>> I am not sure if this will work. >>>> >>> >>> Hi, Gabriel. >>> The problem is, that even if you prepare a context and all arguments >>> for message send, >>> you should start interpreting the code and then leave the interpret >>> loop once you received the answer. >>> But if you look at #interpret method, there is an infinite loop, >>> and no way how to escape it. >>> >>> I don't know if there is a way to tell simulator to leave the loop at >>> certain point. >>> >>> >>> P.S. In general, it would be cool to have something like: >>> >>> sqInt interpreter_call( sqInt receiver , sqInt selector , sqInt * >>> arguments ) >>> >>> means: send message to receiver and return the answer. >>> >>> Unfortunately, Squeak VM does not provides such things, in contrast to >>> languages like Lua, >>> which providing C interoperability layer by default from very >>> beginning of it existence. >>> >>>> Any hint will be much appreciated. Thanks in advance. >>>> >>>> Gabriel >>>> >>> >>> >>> -- >>> Best regards, >>> Igor Stasenko AKA sig. >>> >> > |
In reply to this post by ccrraaiigg
Craig Thank you for the pointer. I am going to take a look at it. Cheers Gabriel On Fri, Jan 7, 2011 at 5:37 AM, Craig Latta <[hidden email]> wrote: > > > Hi Gabriel-- > > If you just want a description of an oop, use > InterpreterSimulator>>shortPrint: and longPrint:. > > When I actually do want to send arbitrary messages to an object in > simulation, I send remote messages from another object memory. This > works because I wrote simulator support for the networking primitives in > Flow. > > > good luck, > > -C > > -- > Craig Latta > www.netjam.org/resume > + 31 020 894 6247 > + 1 415 287 3547 > > > |
Free forum by Nabble | Edit this page |