SlideShare a Scribd company logo
1 of 25
Download to read offline
UFFI
by Example
About me
Pharo architect since 2012

Owned a company to develop in
Pharo back in 2008

Java senior architect for 7 years (and
15 years overall Java experience)

Web, microprocessors, etc., etc., etc.

JavaScript, C++, ObjC, C#, Delphi,
ASM and lots of languages no longer
exist or have been long-time
forgotten

24 years (!) programming experience
(yes… I’m becoming old)
Why FFI*?
Why we want it or even need it?
*FFI: Foreign Function Interface
–Dan Ingalls
“an operating system is a collection of things that
don't fit inside a language; there shouldn't be one”
–John Lennon
“Life is what happens to you while you're busy
making other plans..”
FFI in Pharo
FFI Plugin

Alien FFI

NativeBoost FFI
FFI plugin
Compiler build (no extensions available).

Basic C types and structures

No callbacks

Not very easy to understand
void pango_cairo_update_layout (cairo_t *cr, PangoLayout *layout)
CairoCanvas >> pangoUpdateCairo: anAddress1 layout: anAddress2
<cdecl: void 'pango_cairo_update_layout' (void* void*) module: '/opt/
local/lib/libpangocairo-1.0.0.dylib'>
AlienFFI plugin
Object per method (“aliens”) 

Very low level

Callbacks!

Not very easy to understand
void pango_cairo_update_layout (cairo_t *cr, PangoLayout *layout)
CairoCanvas >> pangoUpdateCairo: anAlien1 layout: anAlien2
^ (Alien
lookup: 'pango_cairo_update_layout'
inLibrary: '/opt/local/lib/libpangocairo-1.0.0.dylib')
primFFICallResult: (result := Alien newGC: 4)
with: anAlien1
with: anAlien2
NativeBoost FFI
Runtime build

Easy to create OO models with it (look Athens)

Very easy to understand

Very low level and hard to modify
void pango_cairo_update_layout (cairo_t *cr, PangoLayout *layout)
CairoCanvas >> pangoUpdateLayout: layout
^ self
nbCall: #(void pango_cairo_update_layout (self, PangoLayout *layout))
module: '/opt/local/lib/libpangocairo-1.0.0.dylib'
Why we removed
NativeBoost?
It was not working on Spur (or in 64bit)

It was hard to maintain (and we need a different
implementation for each architecture)

Since we were using NB exclusively for FFI, we decided
to replace it with a different one, using the VM plugin
What is UFFI?
A front-end to express FFI calls in Pharo.

Uses ThreadedFFIPlugin, but should be able to plug
others in the future.

It shares same philosophy as NativeBoost:

‣ keep as much as possible in the image

‣ no need to modify VM to add functionality

But it is not ASM: Just plain Smalltalk.
Goals
Keep NativeBoost syntax 

‣ Because is cool :)

‣ Provide backward compatibility for most use-cases

Enhance documentation and self-documentation

Be the unified base for future FFI backends
implementations
Meta-goals
Expand the “universe of possible”: 

- Be able to use existing libraries our there instead
needing to reproduce them (run away of the “not
invented here” syndrome).

- Do not need plugins to expand functionality

Provide an easy and efficient way to interact with the
outside world.
How does a call looks like?
char *getenv(const char *)
getEnv: variable
^ self
ffiCall: #( String getenv( String variable ))
module: LibC
(People who know NativeBoost will find this very familiar….)
How does a call looks like?
char *getenv(const char *)
getEnv: variable
^ self
ffiCall: #( String getenv( String variable ))
module: LibC
A regular Pharo method with one argument
How does a call looks like?
char *getenv(const char *)
getEnv: variable
^ self
ffiCall: #( String getenv( String variable ))
module: LibC
A literal array to represent C function
How does a call looks like?
char *getenv(const char *)
getEnv: variable
^ self
ffiCall: #( String getenv( String variable ))
module: LibC
Types annotation used to generate marshalling code
How does a call looks like?
char *getenv(const char *)
getEnv: variable
^ self
ffiCall: #( String getenv( String variable ))
module: LibC
The value to be passed when calling out
How does a call looks like?
char *getenv(const char *)
getEnv: variable
^ self
ffiCall: #( String getenv( String variable ))
module: LibC
The library to lookup C function
FFILibrary
A very simple abstraction to define module names that
can be different each platform.

Can be used also as a place to store C function
definitions (like a real library :) ).
Insights to UnifiedFFI
getEnv: variable
^ self
ffiCall: #(void pango_cairo_update_layout (self, PangoLayout *layout))
module: PangoLibrary
1. Generate bytecodes for marshalling
2. Re-send the method execution
void pango_cairo_update_layout (cairo_t *cr, PangoLayout *layout)
How does a call looks like?
49 <20> pushConstant: <cdecl: void 'pango_cairo_update_layout' (void*
void*) module: '/opt/local/lib/libpangocairo-1.0.0.dylib'>
50 <05> pushRcvr: 5
51 <10> pushTemp: 0
52 <76> pushConstant: 1
53 <E1> send: instVarAt:
54 <8A 82> pop 2 into (Array new: 2)
56 <E2> send: invokeWithArguments:
57 <87> pop
58 <78> returnSelf
void pango_cairo_update_layout (cairo_t *cr, PangoLayout *layout)
Types
Support for standard C types: int, float, etc.

Support for type aliases (map a name to one of the defined types)

Complex types: 

- FFIExternalObject: External addresses (objects)

- FFIOpaqueObject: Opaque C types/structures 

- FFIExternalStructure

- FFIExternalArray, FFITypeArray

- FFIExternalEnumeration

- FFIExternalValueHolder: Buffers (to pass referenced data, e.g. “double *”)

- FFIConstantHandle: Windows HANDLE (constant addresses)
So… and the example?
Demo time :)
Thanks!
Smalltalk quitSession.

More Related Content

What's hot

ruby-ffiについてざっくり解説
ruby-ffiについてざっくり解説ruby-ffiについてざっくり解説
ruby-ffiについてざっくり解説ota42y
 
PharoJS: Hijack the JavaScript Ecosystem
PharoJS: Hijack the JavaScript EcosystemPharoJS: Hijack the JavaScript Ecosystem
PharoJS: Hijack the JavaScript EcosystemESUG
 
JIRA / Confluence の 必須プラグインはこれだ
JIRA / Confluence の必須プラグインはこれだJIRA / Confluence の必須プラグインはこれだ
JIRA / Confluence の 必須プラグインはこれだNarichika Kajihara
 
よくわかるHopscotch hashing
よくわかるHopscotch hashingよくわかるHopscotch hashing
よくわかるHopscotch hashingKumazaki Hiroki
 
runC概要と使い方
runC概要と使い方runC概要と使い方
runC概要と使い方Yuji Oshima
 
Pharo Networking by Example
Pharo Networking by ExamplePharo Networking by Example
Pharo Networking by ExampleNoury Bouraqadi
 
Functional Smalltalk
Functional SmalltalkFunctional Smalltalk
Functional SmalltalkESUG
 
導入から 10 年、PHP の trait は滅びるべきなのか その適切な使いどころと弱点、将来について
導入から 10 年、PHP の trait は滅びるべきなのか その適切な使いどころと弱点、将来について導入から 10 年、PHP の trait は滅びるべきなのか その適切な使いどころと弱点、将来について
導入から 10 年、PHP の trait は滅びるべきなのか その適切な使いどころと弱点、将来についてshinjiigarashi
 
goで末尾再帰最適化は使えるか?
goで末尾再帰最適化は使えるか?goで末尾再帰最適化は使えるか?
goで末尾再帰最適化は使えるか?mori takuma
 
Vivado hls勉強会5(axi4 stream)
Vivado hls勉強会5(axi4 stream)Vivado hls勉強会5(axi4 stream)
Vivado hls勉強会5(axi4 stream)marsee101
 
Oxygen Not Includedをやるべき4つの理由
Oxygen Not Includedをやるべき4つの理由Oxygen Not Includedをやるべき4つの理由
Oxygen Not Includedをやるべき4つの理由lestrrat
 
Music With Pharo
Music With PharoMusic With Pharo
Music With PharoESUG
 
ACRiウェビナー:小野様ご講演資料
ACRiウェビナー:小野様ご講演資料ACRiウェビナー:小野様ご講演資料
ACRiウェビナー:小野様ご講演資料直久 住川
 
Nervesが開拓する「ElixirでIoT」の新世界
Nervesが開拓する「ElixirでIoT」の新世界Nervesが開拓する「ElixirでIoT」の新世界
Nervesが開拓する「ElixirでIoT」の新世界Hideki Takase
 
Spring Boot の Web アプリケーションを Docker に載せて AWS ECS で動かしている話
Spring Boot の Web アプリケーションを Docker に載せて AWS ECS で動かしている話Spring Boot の Web アプリケーションを Docker に載せて AWS ECS で動かしている話
Spring Boot の Web アプリケーションを Docker に載せて AWS ECS で動かしている話JustSystems Corporation
 
eBPFは何が嬉しいのか
eBPFは何が嬉しいのかeBPFは何が嬉しいのか
eBPFは何が嬉しいのかYutaro Hayakawa
 
MySQLと組み合わせて始める全文検索プロダクト"elasticsearch"
MySQLと組み合わせて始める全文検索プロダクト"elasticsearch"MySQLと組み合わせて始める全文検索プロダクト"elasticsearch"
MySQLと組み合わせて始める全文検索プロダクト"elasticsearch"Kentaro Yoshida
 

What's hot (20)

ruby-ffiについてざっくり解説
ruby-ffiについてざっくり解説ruby-ffiについてざっくり解説
ruby-ffiについてざっくり解説
 
Go入門
Go入門Go入門
Go入門
 
PharoJS: Hijack the JavaScript Ecosystem
PharoJS: Hijack the JavaScript EcosystemPharoJS: Hijack the JavaScript Ecosystem
PharoJS: Hijack the JavaScript Ecosystem
 
JIRA / Confluence の 必須プラグインはこれだ
JIRA / Confluence の必須プラグインはこれだJIRA / Confluence の必須プラグインはこれだ
JIRA / Confluence の 必須プラグインはこれだ
 
よくわかるHopscotch hashing
よくわかるHopscotch hashingよくわかるHopscotch hashing
よくわかるHopscotch hashing
 
runC概要と使い方
runC概要と使い方runC概要と使い方
runC概要と使い方
 
Pharo Networking by Example
Pharo Networking by ExamplePharo Networking by Example
Pharo Networking by Example
 
Functional Smalltalk
Functional SmalltalkFunctional Smalltalk
Functional Smalltalk
 
導入から 10 年、PHP の trait は滅びるべきなのか その適切な使いどころと弱点、将来について
導入から 10 年、PHP の trait は滅びるべきなのか その適切な使いどころと弱点、将来について導入から 10 年、PHP の trait は滅びるべきなのか その適切な使いどころと弱点、将来について
導入から 10 年、PHP の trait は滅びるべきなのか その適切な使いどころと弱点、将来について
 
goで末尾再帰最適化は使えるか?
goで末尾再帰最適化は使えるか?goで末尾再帰最適化は使えるか?
goで末尾再帰最適化は使えるか?
 
Vivado hls勉強会5(axi4 stream)
Vivado hls勉強会5(axi4 stream)Vivado hls勉強会5(axi4 stream)
Vivado hls勉強会5(axi4 stream)
 
Oxygen Not Includedをやるべき4つの理由
Oxygen Not Includedをやるべき4つの理由Oxygen Not Includedをやるべき4つの理由
Oxygen Not Includedをやるべき4つの理由
 
Music With Pharo
Music With PharoMusic With Pharo
Music With Pharo
 
ACRiウェビナー:小野様ご講演資料
ACRiウェビナー:小野様ご講演資料ACRiウェビナー:小野様ご講演資料
ACRiウェビナー:小野様ご講演資料
 
Nervesが開拓する「ElixirでIoT」の新世界
Nervesが開拓する「ElixirでIoT」の新世界Nervesが開拓する「ElixirでIoT」の新世界
Nervesが開拓する「ElixirでIoT」の新世界
 
Unityと.NET
Unityと.NETUnityと.NET
Unityと.NET
 
Spring Boot の Web アプリケーションを Docker に載せて AWS ECS で動かしている話
Spring Boot の Web アプリケーションを Docker に載せて AWS ECS で動かしている話Spring Boot の Web アプリケーションを Docker に載せて AWS ECS で動かしている話
Spring Boot の Web アプリケーションを Docker に載せて AWS ECS で動かしている話
 
eBPFを用いたトレーシングについて
eBPFを用いたトレーシングについてeBPFを用いたトレーシングについて
eBPFを用いたトレーシングについて
 
eBPFは何が嬉しいのか
eBPFは何が嬉しいのかeBPFは何が嬉しいのか
eBPFは何が嬉しいのか
 
MySQLと組み合わせて始める全文検索プロダクト"elasticsearch"
MySQLと組み合わせて始める全文検索プロダクト"elasticsearch"MySQLと組み合わせて始める全文検索プロダクト"elasticsearch"
MySQLと組み合わせて始める全文検索プロダクト"elasticsearch"
 

Similar to Pharo foreign function interface (FFI) by example by Esteban Lorenzano

How Symfony changed my life (#SfPot, Paris, 19th November 2015)
How Symfony changed my life (#SfPot, Paris, 19th November 2015)How Symfony changed my life (#SfPot, Paris, 19th November 2015)
How Symfony changed my life (#SfPot, Paris, 19th November 2015)Matthias Noback
 
How Symfony Changed My Life
How Symfony Changed My LifeHow Symfony Changed My Life
How Symfony Changed My LifeMatthias Noback
 
PharoDAYS 2015: FFI - The good, the bad and the ugly by Esteban Lorenzano
PharoDAYS 2015: FFI - The good, the bad and the ugly by Esteban LorenzanoPharoDAYS 2015: FFI - The good, the bad and the ugly by Esteban Lorenzano
PharoDAYS 2015: FFI - The good, the bad and the ugly by Esteban LorenzanoPharo
 
Non-Blocking Strategies for FFI
 Non-Blocking Strategies for FFI Non-Blocking Strategies for FFI
Non-Blocking Strategies for FFIESUG
 
JNA - Let's C what it's worth
JNA - Let's C what it's worthJNA - Let's C what it's worth
JNA - Let's C what it's worthIdan Sheinberg
 
Improving the Pharo VM
Improving the Pharo VMImproving the Pharo VM
Improving the Pharo VMFAST
 
Francesco abeni joomla_extensions_best_practices
Francesco abeni joomla_extensions_best_practicesFrancesco abeni joomla_extensions_best_practices
Francesco abeni joomla_extensions_best_practicesFrancesco Abeni
 
Bay NET Aug 19 2009 presentation ppt
Bay  NET Aug 19 2009 presentation pptBay  NET Aug 19 2009 presentation ppt
Bay NET Aug 19 2009 presentation pptArt Scott
 
Introduction to MonoTouch and Monodroid/Mono for Android
Introduction to MonoTouch and Monodroid/Mono for AndroidIntroduction to MonoTouch and Monodroid/Mono for Android
Introduction to MonoTouch and Monodroid/Mono for AndroidChris Hardy
 
"The F# Path to Relaxation", Don Syme
"The F# Path to Relaxation", Don Syme"The F# Path to Relaxation", Don Syme
"The F# Path to Relaxation", Don SymeFwdays
 
Cape Cod Web Technology Meetup - 3
Cape Cod Web Technology Meetup - 3Cape Cod Web Technology Meetup - 3
Cape Cod Web Technology Meetup - 3Asher Martin
 
Hithhiker guide to eclipse presentation frameworks galaxy
Hithhiker guide to eclipse presentation frameworks galaxyHithhiker guide to eclipse presentation frameworks galaxy
Hithhiker guide to eclipse presentation frameworks galaxyglefur
 
Ny symfony meetup may 2015
Ny symfony meetup may 2015Ny symfony meetup may 2015
Ny symfony meetup may 2015Roland Benedetti
 
Domain Modeling & Full-Stack Web Development F#
Domain Modeling & Full-Stack Web Development F#Domain Modeling & Full-Stack Web Development F#
Domain Modeling & Full-Stack Web Development F#Kevin Avignon
 
Lowcode: Redoing NativeBoost Portably
Lowcode: Redoing NativeBoost PortablyLowcode: Redoing NativeBoost Portably
Lowcode: Redoing NativeBoost PortablyESUG
 
Php extensions workshop
Php extensions workshopPhp extensions workshop
Php extensions workshopjulien pauli
 
Php7 extensions workshop
Php7 extensions workshopPhp7 extensions workshop
Php7 extensions workshopjulien pauli
 
Pharo Consortium: A roadmap to solid evolution
Pharo Consortium: A roadmap to solid evolutionPharo Consortium: A roadmap to solid evolution
Pharo Consortium: A roadmap to solid evolutionESUG
 
Pharo: A roadmap to solid evolution.
Pharo: A roadmap to solid evolution.Pharo: A roadmap to solid evolution.
Pharo: A roadmap to solid evolution.Esteban Lorenzano
 

Similar to Pharo foreign function interface (FFI) by example by Esteban Lorenzano (20)

How Symfony changed my life (#SfPot, Paris, 19th November 2015)
How Symfony changed my life (#SfPot, Paris, 19th November 2015)How Symfony changed my life (#SfPot, Paris, 19th November 2015)
How Symfony changed my life (#SfPot, Paris, 19th November 2015)
 
How Symfony Changed My Life
How Symfony Changed My LifeHow Symfony Changed My Life
How Symfony Changed My Life
 
PharoDAYS 2015: FFI - The good, the bad and the ugly by Esteban Lorenzano
PharoDAYS 2015: FFI - The good, the bad and the ugly by Esteban LorenzanoPharoDAYS 2015: FFI - The good, the bad and the ugly by Esteban Lorenzano
PharoDAYS 2015: FFI - The good, the bad and the ugly by Esteban Lorenzano
 
Non-Blocking Strategies for FFI
 Non-Blocking Strategies for FFI Non-Blocking Strategies for FFI
Non-Blocking Strategies for FFI
 
JNA - Let's C what it's worth
JNA - Let's C what it's worthJNA - Let's C what it's worth
JNA - Let's C what it's worth
 
Improving the Pharo VM
Improving the Pharo VMImproving the Pharo VM
Improving the Pharo VM
 
Francesco abeni joomla_extensions_best_practices
Francesco abeni joomla_extensions_best_practicesFrancesco abeni joomla_extensions_best_practices
Francesco abeni joomla_extensions_best_practices
 
Bay NET Aug 19 2009 presentation ppt
Bay  NET Aug 19 2009 presentation pptBay  NET Aug 19 2009 presentation ppt
Bay NET Aug 19 2009 presentation ppt
 
Introduction to MonoTouch and Monodroid/Mono for Android
Introduction to MonoTouch and Monodroid/Mono for AndroidIntroduction to MonoTouch and Monodroid/Mono for Android
Introduction to MonoTouch and Monodroid/Mono for Android
 
"The F# Path to Relaxation", Don Syme
"The F# Path to Relaxation", Don Syme"The F# Path to Relaxation", Don Syme
"The F# Path to Relaxation", Don Syme
 
PHP Internals
PHP InternalsPHP Internals
PHP Internals
 
Cape Cod Web Technology Meetup - 3
Cape Cod Web Technology Meetup - 3Cape Cod Web Technology Meetup - 3
Cape Cod Web Technology Meetup - 3
 
Hithhiker guide to eclipse presentation frameworks galaxy
Hithhiker guide to eclipse presentation frameworks galaxyHithhiker guide to eclipse presentation frameworks galaxy
Hithhiker guide to eclipse presentation frameworks galaxy
 
Ny symfony meetup may 2015
Ny symfony meetup may 2015Ny symfony meetup may 2015
Ny symfony meetup may 2015
 
Domain Modeling & Full-Stack Web Development F#
Domain Modeling & Full-Stack Web Development F#Domain Modeling & Full-Stack Web Development F#
Domain Modeling & Full-Stack Web Development F#
 
Lowcode: Redoing NativeBoost Portably
Lowcode: Redoing NativeBoost PortablyLowcode: Redoing NativeBoost Portably
Lowcode: Redoing NativeBoost Portably
 
Php extensions workshop
Php extensions workshopPhp extensions workshop
Php extensions workshop
 
Php7 extensions workshop
Php7 extensions workshopPhp7 extensions workshop
Php7 extensions workshop
 
Pharo Consortium: A roadmap to solid evolution
Pharo Consortium: A roadmap to solid evolutionPharo Consortium: A roadmap to solid evolution
Pharo Consortium: A roadmap to solid evolution
 
Pharo: A roadmap to solid evolution.
Pharo: A roadmap to solid evolution.Pharo: A roadmap to solid evolution.
Pharo: A roadmap to solid evolution.
 

More from FAST

Threads, Critical Sections, and Termination
Threads, Critical Sections, and TerminationThreads, Critical Sections, and Termination
Threads, Critical Sections, and TerminationFAST
 
OOP with Smalltalk
OOP with SmalltalkOOP with Smalltalk
OOP with SmalltalkFAST
 
Powerlang: a Vehicle for Lively Implementing Programming Languages
Powerlang: a Vehicle for Lively Implementing Programming LanguagesPowerlang: a Vehicle for Lively Implementing Programming Languages
Powerlang: a Vehicle for Lively Implementing Programming LanguagesFAST
 
Constructing 3D scenes with Woden Engine
Constructing 3D scenes with Woden EngineConstructing 3D scenes with Woden Engine
Constructing 3D scenes with Woden EngineFAST
 
Demystifying the creation of coding tools
Demystifying the creation of coding toolsDemystifying the creation of coding tools
Demystifying the creation of coding toolsFAST
 
Application Starter: the entry point for your application
Application Starter: the entry point for your applicationApplication Starter: the entry point for your application
Application Starter: the entry point for your applicationFAST
 
What is (not) Pharo 8?
What is (not) Pharo 8?What is (not) Pharo 8?
What is (not) Pharo 8?FAST
 
Stargate: an interstellar journey to RESTful APIs
Stargate: an interstellar journey to RESTful APIsStargate: an interstellar journey to RESTful APIs
Stargate: an interstellar journey to RESTful APIsFAST
 
Opening Smalltalks 2019
Opening Smalltalks 2019Opening Smalltalks 2019
Opening Smalltalks 2019FAST
 
Smalltalk Computers, Past and Future by Jecel Mattos de Assumpção Jr
Smalltalk Computers, Past and Future by Jecel Mattos de Assumpção JrSmalltalk Computers, Past and Future by Jecel Mattos de Assumpção Jr
Smalltalk Computers, Past and Future by Jecel Mattos de Assumpção JrFAST
 
Adaptive Compilation by Jecel Mattos de Assumpção Jr
Adaptive Compilation by Jecel Mattos de Assumpção JrAdaptive Compilation by Jecel Mattos de Assumpção Jr
Adaptive Compilation by Jecel Mattos de Assumpção JrFAST
 
Choosing where to run our objects: the S8 Smalltalk approach by Description:F...
Choosing where to run our objects: the S8 Smalltalk approach by Description:F...Choosing where to run our objects: the S8 Smalltalk approach by Description:F...
Choosing where to run our objects: the S8 Smalltalk approach by Description:F...FAST
 
Using 128 GPU cores, Tensorflow and VASmalltalk to detect Kolsh beers with ES...
Using 128 GPU cores, Tensorflow and VASmalltalk to detect Kolsh beers with ES...Using 128 GPU cores, Tensorflow and VASmalltalk to detect Kolsh beers with ES...
Using 128 GPU cores, Tensorflow and VASmalltalk to detect Kolsh beers with ES...FAST
 
Improving VASmalltalk deployment, availability and scalability with Docker by...
Improving VASmalltalk deployment, availability and scalability with Docker by...Improving VASmalltalk deployment, availability and scalability with Docker by...
Improving VASmalltalk deployment, availability and scalability with Docker by...FAST
 
VASmalltalk and Raspberry Pi powering the largest MIDI instrument of the world
VASmalltalk and Raspberry Pi powering the largest MIDI instrument of the worldVASmalltalk and Raspberry Pi powering the largest MIDI instrument of the world
VASmalltalk and Raspberry Pi powering the largest MIDI instrument of the worldFAST
 
Hands-on Raspberry Pi and VA Smalltalk - Starting Workshop
Hands-on Raspberry Pi and VA Smalltalk - Starting WorkshopHands-on Raspberry Pi and VA Smalltalk - Starting Workshop
Hands-on Raspberry Pi and VA Smalltalk - Starting WorkshopFAST
 
Live typing: Update and what's next by Hernan Wilkinson
Live typing: Update and what's next by Hernan WilkinsonLive typing: Update and what's next by Hernan Wilkinson
Live typing: Update and what's next by Hernan WilkinsonFAST
 
Enhanced Email Protocol Framework for VAST by Seth Berman
Enhanced Email Protocol Framework for VAST by Seth BermanEnhanced Email Protocol Framework for VAST by Seth Berman
Enhanced Email Protocol Framework for VAST by Seth BermanFAST
 
VA Smalltalk Product Update by Seth Berman
VA Smalltalk Product Update by Seth BermanVA Smalltalk Product Update by Seth Berman
VA Smalltalk Product Update by Seth BermanFAST
 
Cuis Smalltalk: Past, present and future by By Hernán Wilkinson & Juan Vuletich
Cuis Smalltalk: Past, present and future by By Hernán Wilkinson & Juan VuletichCuis Smalltalk: Past, present and future by By Hernán Wilkinson & Juan Vuletich
Cuis Smalltalk: Past, present and future by By Hernán Wilkinson & Juan VuletichFAST
 

More from FAST (20)

Threads, Critical Sections, and Termination
Threads, Critical Sections, and TerminationThreads, Critical Sections, and Termination
Threads, Critical Sections, and Termination
 
OOP with Smalltalk
OOP with SmalltalkOOP with Smalltalk
OOP with Smalltalk
 
Powerlang: a Vehicle for Lively Implementing Programming Languages
Powerlang: a Vehicle for Lively Implementing Programming LanguagesPowerlang: a Vehicle for Lively Implementing Programming Languages
Powerlang: a Vehicle for Lively Implementing Programming Languages
 
Constructing 3D scenes with Woden Engine
Constructing 3D scenes with Woden EngineConstructing 3D scenes with Woden Engine
Constructing 3D scenes with Woden Engine
 
Demystifying the creation of coding tools
Demystifying the creation of coding toolsDemystifying the creation of coding tools
Demystifying the creation of coding tools
 
Application Starter: the entry point for your application
Application Starter: the entry point for your applicationApplication Starter: the entry point for your application
Application Starter: the entry point for your application
 
What is (not) Pharo 8?
What is (not) Pharo 8?What is (not) Pharo 8?
What is (not) Pharo 8?
 
Stargate: an interstellar journey to RESTful APIs
Stargate: an interstellar journey to RESTful APIsStargate: an interstellar journey to RESTful APIs
Stargate: an interstellar journey to RESTful APIs
 
Opening Smalltalks 2019
Opening Smalltalks 2019Opening Smalltalks 2019
Opening Smalltalks 2019
 
Smalltalk Computers, Past and Future by Jecel Mattos de Assumpção Jr
Smalltalk Computers, Past and Future by Jecel Mattos de Assumpção JrSmalltalk Computers, Past and Future by Jecel Mattos de Assumpção Jr
Smalltalk Computers, Past and Future by Jecel Mattos de Assumpção Jr
 
Adaptive Compilation by Jecel Mattos de Assumpção Jr
Adaptive Compilation by Jecel Mattos de Assumpção JrAdaptive Compilation by Jecel Mattos de Assumpção Jr
Adaptive Compilation by Jecel Mattos de Assumpção Jr
 
Choosing where to run our objects: the S8 Smalltalk approach by Description:F...
Choosing where to run our objects: the S8 Smalltalk approach by Description:F...Choosing where to run our objects: the S8 Smalltalk approach by Description:F...
Choosing where to run our objects: the S8 Smalltalk approach by Description:F...
 
Using 128 GPU cores, Tensorflow and VASmalltalk to detect Kolsh beers with ES...
Using 128 GPU cores, Tensorflow and VASmalltalk to detect Kolsh beers with ES...Using 128 GPU cores, Tensorflow and VASmalltalk to detect Kolsh beers with ES...
Using 128 GPU cores, Tensorflow and VASmalltalk to detect Kolsh beers with ES...
 
Improving VASmalltalk deployment, availability and scalability with Docker by...
Improving VASmalltalk deployment, availability and scalability with Docker by...Improving VASmalltalk deployment, availability and scalability with Docker by...
Improving VASmalltalk deployment, availability and scalability with Docker by...
 
VASmalltalk and Raspberry Pi powering the largest MIDI instrument of the world
VASmalltalk and Raspberry Pi powering the largest MIDI instrument of the worldVASmalltalk and Raspberry Pi powering the largest MIDI instrument of the world
VASmalltalk and Raspberry Pi powering the largest MIDI instrument of the world
 
Hands-on Raspberry Pi and VA Smalltalk - Starting Workshop
Hands-on Raspberry Pi and VA Smalltalk - Starting WorkshopHands-on Raspberry Pi and VA Smalltalk - Starting Workshop
Hands-on Raspberry Pi and VA Smalltalk - Starting Workshop
 
Live typing: Update and what's next by Hernan Wilkinson
Live typing: Update and what's next by Hernan WilkinsonLive typing: Update and what's next by Hernan Wilkinson
Live typing: Update and what's next by Hernan Wilkinson
 
Enhanced Email Protocol Framework for VAST by Seth Berman
Enhanced Email Protocol Framework for VAST by Seth BermanEnhanced Email Protocol Framework for VAST by Seth Berman
Enhanced Email Protocol Framework for VAST by Seth Berman
 
VA Smalltalk Product Update by Seth Berman
VA Smalltalk Product Update by Seth BermanVA Smalltalk Product Update by Seth Berman
VA Smalltalk Product Update by Seth Berman
 
Cuis Smalltalk: Past, present and future by By Hernán Wilkinson & Juan Vuletich
Cuis Smalltalk: Past, present and future by By Hernán Wilkinson & Juan VuletichCuis Smalltalk: Past, present and future by By Hernán Wilkinson & Juan Vuletich
Cuis Smalltalk: Past, present and future by By Hernán Wilkinson & Juan Vuletich
 

Recently uploaded

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 

Recently uploaded (20)

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 

Pharo foreign function interface (FFI) by example by Esteban Lorenzano

  • 2. About me Pharo architect since 2012 Owned a company to develop in Pharo back in 2008 Java senior architect for 7 years (and 15 years overall Java experience) Web, microprocessors, etc., etc., etc. JavaScript, C++, ObjC, C#, Delphi, ASM and lots of languages no longer exist or have been long-time forgotten 24 years (!) programming experience (yes… I’m becoming old)
  • 3. Why FFI*? Why we want it or even need it? *FFI: Foreign Function Interface
  • 4. –Dan Ingalls “an operating system is a collection of things that don't fit inside a language; there shouldn't be one”
  • 5. –John Lennon “Life is what happens to you while you're busy making other plans..”
  • 6. FFI in Pharo FFI Plugin Alien FFI NativeBoost FFI
  • 7. FFI plugin Compiler build (no extensions available). Basic C types and structures No callbacks Not very easy to understand void pango_cairo_update_layout (cairo_t *cr, PangoLayout *layout) CairoCanvas >> pangoUpdateCairo: anAddress1 layout: anAddress2 <cdecl: void 'pango_cairo_update_layout' (void* void*) module: '/opt/ local/lib/libpangocairo-1.0.0.dylib'>
  • 8. AlienFFI plugin Object per method (“aliens”) Very low level Callbacks! Not very easy to understand void pango_cairo_update_layout (cairo_t *cr, PangoLayout *layout) CairoCanvas >> pangoUpdateCairo: anAlien1 layout: anAlien2 ^ (Alien lookup: 'pango_cairo_update_layout' inLibrary: '/opt/local/lib/libpangocairo-1.0.0.dylib') primFFICallResult: (result := Alien newGC: 4) with: anAlien1 with: anAlien2
  • 9. NativeBoost FFI Runtime build Easy to create OO models with it (look Athens) Very easy to understand Very low level and hard to modify void pango_cairo_update_layout (cairo_t *cr, PangoLayout *layout) CairoCanvas >> pangoUpdateLayout: layout ^ self nbCall: #(void pango_cairo_update_layout (self, PangoLayout *layout)) module: '/opt/local/lib/libpangocairo-1.0.0.dylib'
  • 10. Why we removed NativeBoost? It was not working on Spur (or in 64bit) It was hard to maintain (and we need a different implementation for each architecture) Since we were using NB exclusively for FFI, we decided to replace it with a different one, using the VM plugin
  • 11. What is UFFI? A front-end to express FFI calls in Pharo. Uses ThreadedFFIPlugin, but should be able to plug others in the future. It shares same philosophy as NativeBoost: ‣ keep as much as possible in the image ‣ no need to modify VM to add functionality But it is not ASM: Just plain Smalltalk.
  • 12. Goals Keep NativeBoost syntax ‣ Because is cool :) ‣ Provide backward compatibility for most use-cases Enhance documentation and self-documentation Be the unified base for future FFI backends implementations
  • 13. Meta-goals Expand the “universe of possible”: - Be able to use existing libraries our there instead needing to reproduce them (run away of the “not invented here” syndrome). - Do not need plugins to expand functionality Provide an easy and efficient way to interact with the outside world.
  • 14. How does a call looks like? char *getenv(const char *) getEnv: variable ^ self ffiCall: #( String getenv( String variable )) module: LibC (People who know NativeBoost will find this very familiar….)
  • 15. How does a call looks like? char *getenv(const char *) getEnv: variable ^ self ffiCall: #( String getenv( String variable )) module: LibC A regular Pharo method with one argument
  • 16. How does a call looks like? char *getenv(const char *) getEnv: variable ^ self ffiCall: #( String getenv( String variable )) module: LibC A literal array to represent C function
  • 17. How does a call looks like? char *getenv(const char *) getEnv: variable ^ self ffiCall: #( String getenv( String variable )) module: LibC Types annotation used to generate marshalling code
  • 18. How does a call looks like? char *getenv(const char *) getEnv: variable ^ self ffiCall: #( String getenv( String variable )) module: LibC The value to be passed when calling out
  • 19. How does a call looks like? char *getenv(const char *) getEnv: variable ^ self ffiCall: #( String getenv( String variable )) module: LibC The library to lookup C function
  • 20. FFILibrary A very simple abstraction to define module names that can be different each platform. Can be used also as a place to store C function definitions (like a real library :) ).
  • 21. Insights to UnifiedFFI getEnv: variable ^ self ffiCall: #(void pango_cairo_update_layout (self, PangoLayout *layout)) module: PangoLibrary 1. Generate bytecodes for marshalling 2. Re-send the method execution void pango_cairo_update_layout (cairo_t *cr, PangoLayout *layout)
  • 22. How does a call looks like? 49 <20> pushConstant: <cdecl: void 'pango_cairo_update_layout' (void* void*) module: '/opt/local/lib/libpangocairo-1.0.0.dylib'> 50 <05> pushRcvr: 5 51 <10> pushTemp: 0 52 <76> pushConstant: 1 53 <E1> send: instVarAt: 54 <8A 82> pop 2 into (Array new: 2) 56 <E2> send: invokeWithArguments: 57 <87> pop 58 <78> returnSelf void pango_cairo_update_layout (cairo_t *cr, PangoLayout *layout)
  • 23. Types Support for standard C types: int, float, etc. Support for type aliases (map a name to one of the defined types) Complex types: - FFIExternalObject: External addresses (objects) - FFIOpaqueObject: Opaque C types/structures - FFIExternalStructure - FFIExternalArray, FFITypeArray - FFIExternalEnumeration - FFIExternalValueHolder: Buffers (to pass referenced data, e.g. “double *”) - FFIConstantHandle: Windows HANDLE (constant addresses)
  • 24. So… and the example? Demo time :)