Re: [Pharo-users] FFI beginner question

2019-09-24 Thread Guillermo Polito


> El 24 sept 2019, a las 4:35, Richard O'Keefe  escribió:
> 
> What I want to do is to create a binding for the SoftPosit library.
> A typical function has an interface like
>quire16_t q16_fdp_add(quire16_t, posit16_t, posit16_t);
> where
>typedef struct { uint16_t v; } posit16_t;
>typedef struct { uint64_t v[2]; } quire16_t;
> A "quire" is a dot product accumulator.
> A "posit" is a number.
> {quire,posit}{8,16,32} are defined, and a number of other types.

Ok, so IIUC, what you need is:

1) define type aliases (e.g., typedef posit16_t uint_t)
2) define a couple of structs based on those types

I see in the booklet no documentation about type aliases so far, but in the 
latest pharo version there are a couple of examples you can look at.
Type aliases can be defined as class variables in the class using the type, or 
in a shared pool, if you mean to use those types in several places.
Take a look at FT2Types class side for an example, where the type FT_Error is 
defined

FT2Types class>>initialize
... 
FT_Error := 'long’.
…

and then used in a callout like this

FT2Face >> ffiGetKerningLeft: left_glyph right: right_glyph result: akerning
self ffiCall: #(FT_Error FT_Get_Kerning(self, FT_UInt left_glyph, 
FT_UInt right_glyph, 2, FT_Vector  *akerning ))

Then, to use those defined types in a struct definition, you only need to make 
those type aliases (class vars) available in your struct, and use them in the 
struct field definition
See for example FTMatrix

FTMatrix class >> fieldsDesc
^ #(
FT_Fixedxx
FT_Fixedxy
FT_Fixedyx 
FT_Fixedyy
)

Hope this helps,
Guille


Re: [Pharo-users] FFI beginner question

2019-09-23 Thread Richard O'Keefe
What I want to do is to create a binding for the SoftPosit library.
A typical function has an interface like
quire16_t q16_fdp_add(quire16_t, posit16_t, posit16_t);
where
typedef struct { uint16_t v; } posit16_t;
typedef struct { uint64_t v[2]; } quire16_t;
A "quire" is a dot product accumulator.
A "posit" is a number.
{quire,posit}{8,16,32} are defined, and a number of other types.



Re: [Pharo-users] FFI beginner question

2019-09-23 Thread Brainstorms
Guillermo,

I'm interested in helping, but at this point, I think I'd be most helpful
working at improving documentation (mainly editing) rather than working on
Pharo code itself.  (I'd like to work toward that, though.)  

I'm still a newbie with Pharo, but I am a good writer/editor.  And I expect
that working with Pharo documentation would be another means of increasing
my knowledge of the Pharo ecosystem -- so that's additional incentive for
me.

I gather that the PDF books are written using Pillar, which I know nothing
about.  Are there resources & guides for this tool/format that would help me
learn how to make & edit these kinds of documents?

Also, I've never contributed to an open source project; Pharo seems to be a
good place to start doing so.  I see that most of the documentation, web
pages, booklets, etc. are in English so there's the advantage that English
is my first language (and I actually paid attention in school  :^).  I'm
also aware, from experience, that Documentation is rarely the first choice
for developers to apply their time & enthusiasm...

-Ted




--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html



Re: [Pharo-users] FFI beginner question

2019-09-23 Thread Guillermo Polito
See

https://github.com/pharo-project/pharo/issues/4693 

https://github.com/pharo-project/pharo/issues/4694 

https://github.com/pharo-project/pharo/issues/4695 


Of course, if somebody wants to help, you’re welcome to :)

Guille

> El 23 sept 2019, a las 13:59, Guillermo Polito  
> escribió:
> 
> Just more detail into it:
> 
>  - the source code of the booklet, written in Pillar, resides in here:
>https://github.com/SquareBracketAssociates/Booklet-uFFI 
> 
> 
>  - I’ve been in the last weeks doing a pass on it (see branch version2 
> https://github.com/SquareBracketAssociates/Booklet-uFFI/tree/version2 
> )
>I started adding examples, and enhancing the explanations.
>I got particularly blocked when explaining marshalling where I saw several 
> issues to address / features to add before continuing documenting
> 
> I have some issues written down to fix in FFI soon:
>   1 - unify vocabulary: module and library in the API (see #ffiCall:module: 
> #macModuleName #ffiLibraryName, #ffiLibrary…)
>   2 - some of the names above are misleading (#ffiLibraryName returning a 
> library object and not a name for example)
>   3 - extend literal object support to floats
>   4 - add a strict (but safe) mode where types for literals are mandatory 
> (otherwise marshalling can go wrong :))
> 
> I’ll create issues for these in the next hours ^^.
> 
>> El 23 sept 2019, a las 13:38, Richard O'Keefe > > escribió:
>> 
>> how do I
>> connect C numeric
>> types introduced by the library to FFI?
> 
> Hi Richard, what do you mean? Do you have an example? What’s the signature of 
> your C function look like?
> 
> Guille



Re: [Pharo-users] FFI beginner question

2019-09-23 Thread Guillermo Polito
Just more detail into it:

 - the source code of the booklet, written in Pillar, resides in here:
   https://github.com/SquareBracketAssociates/Booklet-uFFI 


 - I’ve been in the last weeks doing a pass on it (see branch version2 
https://github.com/SquareBracketAssociates/Booklet-uFFI/tree/version2 
)
   I started adding examples, and enhancing the explanations.
   I got particularly blocked when explaining marshalling where I saw several 
issues to address / features to add before continuing documenting

I have some issues written down to fix in FFI soon:
  1 - unify vocabulary: module and library in the API (see #ffiCall:module: 
#macModuleName #ffiLibraryName, #ffiLibrary…)
  2 - some of the names above are misleading (#ffiLibraryName returning a 
library object and not a name for example)
  3 - extend literal object support to floats
  4 - add a strict (but safe) mode where types for literals are mandatory 
(otherwise marshalling can go wrong :))

I’ll create issues for these in the next hours ^^.

> El 23 sept 2019, a las 13:38, Richard O'Keefe  escribió:
> 
> how do I
> connect C numeric
> types introduced by the library to FFI?

Hi Richard, what do you mean? Do you have an example? What’s the signature of 
your C function look like?

Guille

Re: [Pharo-users] FFI beginner question

2019-09-23 Thread Richard O'Keefe
Thank you for that.  I note that some sections have nothing in them.
Now that I have
read that, what is the next thing to read?  In particular, how do I
connect C numeric
types introduced by the library to FFI?

On Mon, 23 Sep 2019 at 16:45, Tomaž Turk  wrote:
>
> Hi,
>
> The book draft is here: 
> https://files.pharo.org/books-pdfs/booklet-uFFI/UFFIDRAFT.pdf.
>
> Best wishes,
> Tomaz
>
>
>
> Any plans to draft a Pharo booklet on this subject?
>
> -Ted
>



Re: [Pharo-users] FFI beginner question

2019-09-22 Thread Tomaž Turk

Hi,

The book draft is here: 
https://files.pharo.org/books-pdfs/booklet-uFFI/UFFIDRAFT.pdf.


Best wishes,
Tomaz




Any plans to draft a Pharo booklet on this subject?

-Ted


Re: [Pharo-users] FFI beginner question

2019-09-22 Thread Brainstorms
I'm also interested in this...  

Any plans to draft a Pharo booklet on this subject?

-Ted




--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html



[Pharo-users] FFI beginner question

2019-09-22 Thread Richard O'Keefe
I am developing a Smalltalk interface to an existing C library which I
intend to make generally available.  Naturally I am doing this in my own
Smalltalk system first, where it's unsurprisingly easy for me.  But when
I have it working, I'd like to make a Pharo port available.

I have never used the Foreign Function Interface in Pharo before and
don't even know where to start.

What should I read first?
Is there a model project to imitate?