[squeak-dev] Building a linux/Pi library to call via FFI

Chris Cunnington brasspen at gmail.com
Thu Sep 10 02:20:15 UTC 2015


http://sdmeta.gforge.inria.fr/FreeBooks/CollectiveNBlueBook/greenberg.pdf

Write it in Smalltalk:

#reverseInPlaceFrom:to:

| temp |
0 to: to - from // 2 do:
     [:index | temp ← self at: from + index.
     self at: from + index put: (self at: to-index).
     self at: to-index put: temp]

Re-write it as Slang:

#primReverseFromto

self export: true.
self var: #rcvr declareC: 'int *rcvr'.
to ← interpreterProxy stackIntegerValue: 0. from ← interpreterProxy 
stackIntegerValue: 1.
rcvrOop ← interpreterProxy stackObjectValue: 2.
rcvr ← self cCoerce: (interpreterProxy firstIndexableField: rcvrOop) to: 
'int *'.
interpreterProxy success: (from >= 1 and: [from+1 <= to]). 
interpreterProxy success: (to <= (interpreterProxy stSizeOf: rcvrOop)).
interpreterProxy failed ifTrue: [^nil].
rcvr ← rcvr - 1. "adjust for 1-based indexing."
0 to: to-from/2 do:
     [:index | t ← rcvr at: from + index.
     rcvr at: from + index put: (rcvr at: to-index).
     rcvr at: to-index put: t].
interpreterProxy pop: 3 thenPush: rcvrOop

Or subclass the long lost TestCodeGenerator to do it for you!

Chris

For those of you watching at home, the article above has the HelloWorld 
of plugins. Igor changed is slightly for a lecture in 2011 to make a 
plugin called TheUniversalAnswer. It returns 42.

#answerSeventeen

self export: true.
interpreterProxy
      pop: 1
      thenPush: (interpreterProxy integerObjectOf: 17)

All you need now is a compiling rig with two VMs and two images.
The VM you start your VMMaker image with. The VM you compile from the 
VMMaker source you just generated.
And the pristine target image you start with the VM you just compiled to 
prove it works.

Your spiral into plugin compiling madness starts with this handy script:

http://lists.squeakfoundation.org/pipermail/squeak-dev/2012-October/166038.html





On 2015-09-09 9:53 PM, David T. Lewis wrote:
> On Wed, Sep 09, 2015 at 11:17:08AM -0700, tim Rowledge wrote:
>> I?m trying - and so far failing - to do what should surely be a very simple
>> thing. This isn?t a new situation?  especially on unix.
>>
>> I have a single C file with just two functions. I have a matching H file.
>> I want to make them into a dynamic library that I can call via FFI. This
>> really shouldn?t be rocket science stuff!
> <OT>
> I assume there is some good reason that you would not do an end run
> around all that rocket science and just write a plugin? After all, you
> are the person who wrote the excellent early papers on how to extend the
> VM with plugins, and most of what little I know of VMs came from reading
> your early work on the topic.
>
> I would hate to be the one to deny a masochist his private pleasures, but
> really, why not not just do it the easy way?
> </OT>
>
> Dave
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20150909/4576e953/attachment.htm


More information about the Squeak-dev mailing list