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

re:mobidyc the overview
re:mobidyc the overviewre:mobidyc the overview
re:mobidyc the overviewESUG
 
Pharo 10 and beyond
 Pharo 10 and beyond Pharo 10 and beyond
Pharo 10 and beyondESUG
 
Towards Object-centric Time-traveling Debuggers
 Towards Object-centric Time-traveling Debuggers Towards Object-centric Time-traveling Debuggers
Towards Object-centric Time-traveling DebuggersESUG
 
GemStone Update
GemStone Update GemStone Update
GemStone Update ESUG
 
【Unity道場 2月】シェーダを書けるプログラマになろう
【Unity道場 2月】シェーダを書けるプログラマになろう【Unity道場 2月】シェーダを書けるプログラマになろう
【Unity道場 2月】シェーダを書けるプログラマになろうUnity Technologies Japan K.K.
 
【Unite 2017 Tokyo】最適化をする前に覚えておきたい技術
【Unite 2017 Tokyo】最適化をする前に覚えておきたい技術【Unite 2017 Tokyo】最適化をする前に覚えておきたい技術
【Unite 2017 Tokyo】最適化をする前に覚えておきたい技術Unity Technologies Japan K.K.
 
Polyphony: Python ではじめる FPGA
Polyphony: Python ではじめる FPGAPolyphony: Python ではじめる FPGA
Polyphony: Python ではじめる FPGAryos36
 
UE4におけるキャラクタークラス設計
UE4におけるキャラクタークラス設計UE4におけるキャラクタークラス設計
UE4におけるキャラクタークラス設計Masahiko Nakamura
 
そう、UE4ならね。あなたのモバイルゲームをより快適にする沢山の冴えたやり方について Part 1 <Shader Compile, PSO Cache編>
  そう、UE4ならね。あなたのモバイルゲームをより快適にする沢山の冴えたやり方について Part 1 <Shader Compile, PSO Cache編>  そう、UE4ならね。あなたのモバイルゲームをより快適にする沢山の冴えたやり方について Part 1 <Shader Compile, PSO Cache編>
そう、UE4ならね。あなたのモバイルゲームをより快適にする沢山の冴えたやり方について Part 1 <Shader Compile, PSO Cache編>エピック・ゲームズ・ジャパン Epic Games Japan
 
UE4 Garbage Collection
UE4 Garbage CollectionUE4 Garbage Collection
UE4 Garbage CollectionQooJuice
 

What's hot (20)

re:mobidyc the overview
re:mobidyc the overviewre:mobidyc the overview
re:mobidyc the overview
 
Pharo 10 and beyond
 Pharo 10 and beyond Pharo 10 and beyond
Pharo 10 and beyond
 
Towards Object-centric Time-traveling Debuggers
 Towards Object-centric Time-traveling Debuggers Towards Object-centric Time-traveling Debuggers
Towards Object-centric Time-traveling Debuggers
 
【UE4.25 新機能】ロードの高速化機能「IOStore」について
【UE4.25 新機能】ロードの高速化機能「IOStore」について【UE4.25 新機能】ロードの高速化機能「IOStore」について
【UE4.25 新機能】ロードの高速化機能「IOStore」について
 
Unreal Studioのご紹介
Unreal Studioのご紹介Unreal Studioのご紹介
Unreal Studioのご紹介
 
GemStone Update
GemStone Update GemStone Update
GemStone Update
 
【Unity道場 2月】シェーダを書けるプログラマになろう
【Unity道場 2月】シェーダを書けるプログラマになろう【Unity道場 2月】シェーダを書けるプログラマになろう
【Unity道場 2月】シェーダを書けるプログラマになろう
 
Clang: More than just a C/C++ Compiler
Clang: More than just a C/C++ CompilerClang: More than just a C/C++ Compiler
Clang: More than just a C/C++ Compiler
 
【Unite 2017 Tokyo】最適化をする前に覚えておきたい技術
【Unite 2017 Tokyo】最適化をする前に覚えておきたい技術【Unite 2017 Tokyo】最適化をする前に覚えておきたい技術
【Unite 2017 Tokyo】最適化をする前に覚えておきたい技術
 
はじめてアンリアルエンジンで海戦をつくってみたときのお話
はじめてアンリアルエンジンで海戦をつくってみたときのお話はじめてアンリアルエンジンで海戦をつくってみたときのお話
はじめてアンリアルエンジンで海戦をつくってみたときのお話
 
聖剣伝説3でのUE4利用事例の紹介~Making of Mana | UNREAL FEST EXTREME 2020 WINTER
聖剣伝説3でのUE4利用事例の紹介~Making of Mana | UNREAL FEST EXTREME 2020 WINTER聖剣伝説3でのUE4利用事例の紹介~Making of Mana | UNREAL FEST EXTREME 2020 WINTER
聖剣伝説3でのUE4利用事例の紹介~Making of Mana | UNREAL FEST EXTREME 2020 WINTER
 
アーティストの為のプロファイル入門!~楽しいRenderDocの使い方~
アーティストの為のプロファイル入門!~楽しいRenderDocの使い方~アーティストの為のプロファイル入門!~楽しいRenderDocの使い方~
アーティストの為のプロファイル入門!~楽しいRenderDocの使い方~
 
Polyphony: Python ではじめる FPGA
Polyphony: Python ではじめる FPGAPolyphony: Python ではじめる FPGA
Polyphony: Python ではじめる FPGA
 
UE4におけるキャラクタークラス設計
UE4におけるキャラクタークラス設計UE4におけるキャラクタークラス設計
UE4におけるキャラクタークラス設計
 
なぜなにFProperty - 対応方法と改善点 -
なぜなにFProperty - 対応方法と改善点 -なぜなにFProperty - 対応方法と改善点 -
なぜなにFProperty - 対応方法と改善点 -
 
Fortniteを支える技術
Fortniteを支える技術Fortniteを支える技術
Fortniteを支える技術
 
UE4のローカライズ機能紹介 (UE4 Localization Deep Dive)
UE4のローカライズ機能紹介 (UE4 Localization Deep Dive)UE4のローカライズ機能紹介 (UE4 Localization Deep Dive)
UE4のローカライズ機能紹介 (UE4 Localization Deep Dive)
 
Unreal Engine 5 早期アクセスの注目機能総おさらい Part 2
Unreal Engine 5 早期アクセスの注目機能総おさらい Part 2Unreal Engine 5 早期アクセスの注目機能総おさらい Part 2
Unreal Engine 5 早期アクセスの注目機能総おさらい Part 2
 
そう、UE4ならね。あなたのモバイルゲームをより快適にする沢山の冴えたやり方について Part 1 <Shader Compile, PSO Cache編>
  そう、UE4ならね。あなたのモバイルゲームをより快適にする沢山の冴えたやり方について Part 1 <Shader Compile, PSO Cache編>  そう、UE4ならね。あなたのモバイルゲームをより快適にする沢山の冴えたやり方について Part 1 <Shader Compile, PSO Cache編>
そう、UE4ならね。あなたのモバイルゲームをより快適にする沢山の冴えたやり方について Part 1 <Shader Compile, PSO Cache編>
 
UE4 Garbage Collection
UE4 Garbage CollectionUE4 Garbage Collection
UE4 Garbage Collection
 

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
 
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
 
NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)Ron Munitz
 

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
 
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.
 
NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)
 

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

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
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
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 

Recently uploaded (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
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
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 

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 :)