Howto invoke plugin primitive from Interpreter?

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

Howto invoke plugin primitive from Interpreter?

André Wendt-3
 
Hi,

I'm trying to invoke the primitiveFileOpen primitive from the FilePlugin
from within the Interpreter:

<primitive: 'primitiveFileOpen' module: 'FilePlugin'>

obviously does not work: It doesn't get translated to C. How do I invoke
a primitive of an (internal/external) plugin from within the Interpreter
class?

Thanks,
André
Reply | Threaded
Open this post in threaded view
|

Re: Howto invoke plugin primitive from Interpreter?

Bert Freudenberg


On Jun 14, 2007, at 11:28 , André Wendt wrote:

>
> Hi,
>
> I'm trying to invoke the primitiveFileOpen primitive from the  
> FilePlugin
> from within the Interpreter:
>
> <primitive: 'primitiveFileOpen' module: 'FilePlugin'>
>
> obviously does not work: It doesn't get translated to C. How do I  
> invoke
> a primitive of an (internal/external) plugin from within the  
> Interpreter
> class?

This is generally a bad idea, because you would have to pass  
parameters on the smalltalk stack.

What are you actually trying to achieve?

- Bert -


Reply | Threaded
Open this post in threaded view
|

Re: Howto invoke plugin primitive from Interpreter?

André Wendt-3
In reply to this post by André Wendt-3
 
Bert Freudenberg schrieb:

>  
>
> On Jun 14, 2007, at 11:28 , André Wendt wrote:
>
>> Hi,
>>
>> I'm trying to invoke the primitiveFileOpen primitive from the  
>> FilePlugin
>> from within the Interpreter:
>>
>> <primitive: 'primitiveFileOpen' module: 'FilePlugin'>
>>
>> obviously does not work: It doesn't get translated to C. How do I  
>> invoke
>> a primitive of an (internal/external) plugin from within the  
>> Interpreter
>> class?
>
> This is generally a bad idea, because you would have to pass  
> parameters on the smalltalk stack.
>
> What are you actually trying to achieve?

Hi Bert,

I'm trying to write a logging facility for send (sample work for Prof.
Hirschfeld, actually): Each time a message is sent, the target class,
message and a couple of other properties should be logged.

That means I have to open a file upon initialization and write the file
at each send. There's no other way than to do that in the Interpreter,
as far as I can see.

André
Reply | Threaded
Open this post in threaded view
|

Re: Howto invoke plugin primitive from Interpreter?

Bert Freudenberg

On Jun 14, 2007, at 14:31 , André Wendt wrote:

>
> Bert Freudenberg schrieb:
>>
>>
>> On Jun 14, 2007, at 11:28 , André Wendt wrote:
>>
>>> Hi,
>>>
>>> I'm trying to invoke the primitiveFileOpen primitive from the
>>> FilePlugin
>>> from within the Interpreter:
>>>
>>> <primitive: 'primitiveFileOpen' module: 'FilePlugin'>
>>>
>>> obviously does not work: It doesn't get translated to C. How do I
>>> invoke
>>> a primitive of an (internal/external) plugin from within the
>>> Interpreter
>>> class?
>>
>> This is generally a bad idea, because you would have to pass
>> parameters on the smalltalk stack.
>>
>> What are you actually trying to achieve?
>
> Hi Bert,
>
> I'm trying to write a logging facility for send (sample work for Prof.
> Hirschfeld, actually): Each time a message is sent, the target class,
> message and a couple of other properties should be logged.

I'm pretty sure John McIntosh did that before.

> That means I have to open a file upon initialization and write the  
> file
> at each send. There's no other way than to do that in the Interpreter,
> as far as I can see.

What about fopen()?

- Bert -


Reply | Threaded
Open this post in threaded view
|

Re: Howto invoke plugin primitive from Interpreter?

Marcus Denker
In reply to this post by André Wendt-3
 

On 14.06.2007, at 14:31, André Wendt wrote:

>
> Hi Bert,
>
> I'm trying to write a logging facility for send (sample work for Prof.
> Hirschfeld, actually): Each time a message is sent, the target class,
> message and a couple of other properties should be logged.
>
> That means I have to open a file upon initialization and write the  
> file
> at each send. There's no other way than to do that in the Interpreter,
> as far as I can see.
>
Hacking the interpreter is one solution... but you can do it from inside
the image, with no VM changes, too. It might be a bit slower, though.
(and maybe not what you need at all, nevertheless, it is good to now
all the options).

One way to achieve this with no VM change is to manipulate the
bytecode of the methods.

So for logging sends, you would add bytecode in front of each send
that does the logging. This bytecode can access all sorts of  
information,
e.g. the sender or the arguments of the sends.

We did a library that makes this kind of manipulation relatively easy to
do:

        http://www.iam.unibe.ch/~scg/Research/ByteSurgeon/

The ByteSurgeon framework has been used for a "Log everything" Back-
in-Time
Debugger.

We now have an even better system (called "Reflectivity") for this  
kind of meta
programming things (not based on bytecode manipulation).
If you decide to play with logging sends from "inside" the image,  
this should
be quite interesting. The resulting code is faster then doing  
bytecode manipulation,
and it allows for far better control (it implements the model of  
Partial Behavioral
Reflection found in Reflex for Java).

This is not yet released, but if you want to play with it, please  
send me a mail (I am
happy about any users ;-)).

        Marcus


smime.p7s (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Howto invoke plugin primitive from Interpreter?

André Wendt-3
In reply to this post by André Wendt-3
 
Bert Freudenberg schrieb:

>  
> On Jun 14, 2007, at 14:31 , André Wendt wrote:
>
>> Bert Freudenberg schrieb:
>>>
>>> On Jun 14, 2007, at 11:28 , André Wendt wrote:
>>>
>>>> Hi,
>>>>
>>>> I'm trying to invoke the primitiveFileOpen primitive from the
>>>> FilePlugin
>>>> from within the Interpreter:
>>>>
>>>> <primitive: 'primitiveFileOpen' module: 'FilePlugin'>
>>>>
>>>> obviously does not work: It doesn't get translated to C. How do I
>>>> invoke
>>>> a primitive of an (internal/external) plugin from within the
>>>> Interpreter
>>>> class?
>>> This is generally a bad idea, because you would have to pass
>>> parameters on the smalltalk stack.
>>>
>>> What are you actually trying to achieve?
>> Hi Bert,
>>
>> I'm trying to write a logging facility for send (sample work for Prof.
>> Hirschfeld, actually): Each time a message is sent, the target class,
>> message and a couple of other properties should be logged.
>
> I'm pretty sure John McIntosh did that before.
>
>> That means I have to open a file upon initialization and write the  
>> file
>> at each send. There's no other way than to do that in the Interpreter,
>> as far as I can see.
>
> What about fopen()?

Do you mean something like

f := self cCode: 'fopen(logFile, "a")'. ??

André
Reply | Threaded
Open this post in threaded view
|

Re: Howto invoke plugin primitive from Interpreter?

Bert Freudenberg

On Jun 14, 2007, at 16:08 , André Wendt wrote:

> Bert Freudenberg schrieb:
>>
>> On Jun 14, 2007, at 14:31 , André Wendt wrote:
>>
>>> That means I have to open a file upon initialization and write the
>>> file
>>> at each send. There's no other way than to do that in the  
>>> Interpreter,
>>> as far as I can see.
>>
>> What about fopen()?
>
> Do you mean something like
>
> f := self cCode: 'fopen(logFile, "a")'. ??

sure

- Bert -


Reply | Threaded
Open this post in threaded view
|

Re: Howto invoke plugin primitive from Interpreter?

André Wendt-3
In reply to this post by André Wendt-3
 
Bert Freudenberg schrieb:

>  
> On Jun 14, 2007, at 16:08 , André Wendt wrote:
>
>> Bert Freudenberg schrieb:
>>> On Jun 14, 2007, at 14:31 , André Wendt wrote:
>>>
>>>> That means I have to open a file upon initialization and write the
>>>> file
>>>> at each send. There's no other way than to do that in the  
>>>> Interpreter,
>>>> as far as I can see.
>>> What about fopen()?
>> Do you mean something like
>>
>> f := self cCode: 'fopen(logFile, "a")'. ??
>
> sure

I could do that (and it works), but only until I encounter the
corresponding fwrite() call. Something along the lines of

self cCode: 'fwrite("asdf", 4, 1, self sendProfile)'.

of course won't work, and then I'd still have to somehow mix my
variables into the C code. That's where it starts getting nasty again.

Any suggestions?

Thanks,
André
Reply | Threaded
Open this post in threaded view
|

Re: Howto invoke plugin primitive from Interpreter?

johnmci

Well as already noted I've code that does what you want if you want  
to do it in the vm.

via http://www.smalltalkconsulting.com/squeak.html

look on my idisk, or ftp site (I think) in the experimental folder,  
then the MessageLoggingVM folder.

David T Lewis also gave me code to enable the use of SIGNALS via  
OSProcess plugin to let you use the unix signal
logic to turn on/off tracing and modify what it was doing.


On Jun 14, 2007, at 9:06 AM, André Wendt wrote:

>
> Bert Freudenberg schrieb:
>>
>> On Jun 14, 2007, at 16:08 , André Wendt wrote:
>>
>>> Bert Freudenberg schrieb:
>>>> On Jun 14, 2007, at 14:31 , André Wendt wrote:
>>>>
>>>>> That means I have to open a file upon initialization and write the
>>>>> file
>>>>> at each send. There's no other way than to do that in the
>>>>> Interpreter,
>>>>> as far as I can see.
>>>> What about fopen()?
>>> Do you mean something like
>>>
>>> f := self cCode: 'fopen(logFile, "a")'. ??
>>
>> sure
>
> I could do that (and it works), but only until I encounter the
> corresponding fwrite() call. Something along the lines of
>
> self cCode: 'fwrite("asdf", 4, 1, self sendProfile)'.
>
> of course won't work, and then I'd still have to somehow mix my
> variables into the C code. That's where it starts getting nasty again.
>
> Any suggestions?
>
> Thanks,
> André

--
========================================================================
===
John M. McIntosh <[hidden email]>
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
========================================================================
===


Reply | Threaded
Open this post in threaded view
|

Re: Howto invoke plugin primitive from Interpreter?

André Wendt-3
In reply to this post by André Wendt-3
 
John M McIntosh schrieb:

>  
> Well as already noted I've code that does what you want if you want  
> to do it in the vm.
>
> via http://www.smalltalkconsulting.com/squeak.html
>
> look on my idisk, or ftp site (I think) in the experimental folder,  
> then the MessageLoggingVM folder.
>
> David T Lewis also gave me code to enable the use of SIGNALS via  
> OSProcess plugin to let you use the unix signal
> logic to turn on/off tracing and modify what it was doing.

I just realized it was quite rude of me to not thank for this help. I
really appreciated all the hints!

Thanks,
André