SlideShare uma empresa Scribd logo
1 de 30
Abusing Erlang Compilation Pipeline
for Fun and Profit
Erlang UG - Cracow (13.03.2017)
~ # whoami (afronski)
➔ Software and Operations Engineer
at Appliscale
Erlang, Python, JS, AWS, Linux
➔ Co-organizer:
Functional Miners
Silesian BEAMers
http://learnyousomeerlang.com/designing-a-concurrent-application#hot-code-loving
Brainfuck?
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++
++++++++++.>.+++.------.--------.>+.>.
Brainfuck!
8 symbols
+ -
< >
[ ]
, .
Brainfuck!
Example:
,----------
[----------------------.
,----------]
a = 97 A = 65
n = 10 a - A = 32
github.com/afronski/bferl
+[,+[-[>+>+<<-]>[<+>-]+>>++++++++[<-------->-]<-[<[-]>>>+[<+<+>>-]<[>+<-]<[<++>>>+[<+<->>-]<[>+<-]]>[<]<]>>[-]<<<[[-]<[>>+>+<<<-]>>
[<<+>>-]>>++++++++[<-------->-]<->>++++[<++++++++>-]<-<[>>>+<<[>+>[-]<<-]>[<+>-]>[<<<<<+>>>>++++[<++++++++>-]>-]<<-<-]>[<<<<[-]>>>>
[<<<<->>>>-]]<<++++[<<++++++++>>-]<<-[>>+>+<<<-]>>[<<+>>-]+>>+++++[<----->-]<-[<[-]>>>+[<+<->>-]<[>+<-]<[<++>>>+[<+<+>>-]<[>+<-]]>[
<]<]>>[-]<<<[[-]<<[>>+>+<<<-]>>[<<+>>-]+>------------[<[-]>>>+[<+<->>-]<[>+<-]<[<++>>>+[<+<+>>-]<[>+<-]]>[<]<]>>[-]<<<<<-----------
-->>[[-]+++++[<<+++++>>-]<<+>>]<[>++++[<<++++++++>>-]<-]>]<[-]++++++++[<++++++++>-]<+>]<.[-]+>>+<]>[[-]<]<]
Demo
Source Code
% -*- coding: utf8 -*-
-module(main).
-export([main/0, a/0]).
-define(GUESS_WAT, ok).
a() -> ?GUESS_WAT.
main() ->
a(),
io:format("Hello, world!~n").
Preprocessor
-file("main.erl", 1).
-module(main).
-export([main/0,a/0]).
a() -> ok.
main() ->
a(),
io:format("Hello, world!~n").
sys_pre_expand
-file("main.erl", 1).
a() -> ok.
main() -> a(),
io:format("Hello, world!~n").
module_info() -> erlang:get_module_info(main).
module_info(X) -> erlang:get_module_info(main, X).
Core Erlang
Intermediate representation of Erlang, intended
to lie at a level between source code and the
intermediate code typically found in compilers.
Core Erlang
During its evolution, the syntax has become
complicated, making it difficult to develop
programs that operate on the source.
Core Erlang
module 'main' ['a'/0,'main'/0, ...]
attributes []
...
'main'/0 =
...
apply 'a'/0 ()
call 'io':'format' ([72|[101|[108|[...]]]])
...
end
Kernel Erlang
Source Code
module 'main'
export ['a'/0,'main'/0,...]
fdef 'main'/0() =
do
call (local 'a'/0)() >> <>
then
enter (remote 'io':'format'/1)("Hello,
world!~n")
BEAM assembler
{module, main}.
{exports, [{a,0},{main,0},...]}.
{function, main, 0, 4}.
{label,4}.
{allocate,0,0}.
{call,0,{f,2}}.
{move,{literal,"Hello, world!~n"},{x,0}}.
...
{call_ext_last,1,{extfunc,io,format,1},0}.
BEAM file
464f52310000023c4245414d41746f6d000000
3b00000008046d61696e0161026f6b02696f06
666f726d61740b6d6f64756c655f696e666f06
65726.................................
What did I miss?
Parse Transforms
Custom Parsers
github.com/afronski/bferl/Compiler
Lexer Parser CodeGen
+++++++++
+[>++++++
+>
Core
Erlang
Tools
- Leex and Yecc
- cerl:*, cerl_clauses:*
- c(example, to_core).
- Erlang playground
- It allows to compile source into different forms.
- Interactively!
Okay, we know how to “abuse” it. ;)
But why?
Community
Examples
Hot-Code Reloading
Configuration as a Code
Hardwiring Dependencies in Code
DSL
Templating Engines
Configuration Files
Elixir EEx
Different Languages
LFE
Elixir
Typed Erlang
Syntax Analysis and
Transformations
Mutation Testing
Code Analysis Tools
Syntax Sugar ;)
Low-level
Optimizations
Knowing how it works under the hood
helps you to write better code.
λ
Thank you!
Any questions?
References
1. Our company - Appliscale.
2. Me - afronski.pl and my talks.
3. Functional Miners (facebook, twitter, github, email).
4. Hot-Code Reload (Learn You Some Erlang For Great Good)
5. Implementing Languages on the Erlang VM (R. Virding)
6. Virtually Instructional (L. Fridén)
7. Hack your own Erlang VM (R. Studnicki)
8. Core Erlang - Specification
9. Core Erlang - Documentation
10. A Peek Inside the Erlang Compiler (J. Hague)
11. Notes on Erlang Compiler (bhuztez)

Mais conteúdo relacionado

Mais procurados

Python Developer's Daily Routine
Python Developer's Daily RoutinePython Developer's Daily Routine
Python Developer's Daily Routine
Maxim Avanov
 
Icsm2009 bettenburg presentation
Icsm2009 bettenburg presentationIcsm2009 bettenburg presentation
Icsm2009 bettenburg presentation
SAIL_QU
 
スマートフォン勉強会@関東 #11 LT 5分で語る SQLite暗号化
スマートフォン勉強会@関東 #11 LT 5分で語る SQLite暗号化スマートフォン勉強会@関東 #11 LT 5分で語る SQLite暗号化
スマートフォン勉強会@関東 #11 LT 5分で語る SQLite暗号化
Taro Matsuzawa
 
On secure application of PHP wrappers
On secure application  of PHP wrappersOn secure application  of PHP wrappers
On secure application of PHP wrappers
Positive Hack Days
 

Mais procurados (19)

Python Developer's Daily Routine
Python Developer's Daily RoutinePython Developer's Daily Routine
Python Developer's Daily Routine
 
Clojure + MongoDB on Heroku
Clojure + MongoDB on HerokuClojure + MongoDB on Heroku
Clojure + MongoDB on Heroku
 
Crunching data with go: Tips, tricks, use-cases
Crunching data with go: Tips, tricks, use-casesCrunching data with go: Tips, tricks, use-cases
Crunching data with go: Tips, tricks, use-cases
 
Hive integration
Hive integrationHive integration
Hive integration
 
How to add user in system without useradd command
How to add user in system without useradd commandHow to add user in system without useradd command
How to add user in system without useradd command
 
Some Pry Features
Some Pry FeaturesSome Pry Features
Some Pry Features
 
Crack.ba
Crack.baCrack.ba
Crack.ba
 
Word Play in the Digital Age: Building Text Bots with Tracery
Word Play in the Digital Age: Building Text Bots with TraceryWord Play in the Digital Age: Building Text Bots with Tracery
Word Play in the Digital Age: Building Text Bots with Tracery
 
Getting Started with Microsoft Bot Framework
Getting Started with Microsoft Bot FrameworkGetting Started with Microsoft Bot Framework
Getting Started with Microsoft Bot Framework
 
DOD 2016 - Tomasz Torcz - The Song of JBoss and Chef
DOD 2016 - Tomasz Torcz - The Song of JBoss and Chef DOD 2016 - Tomasz Torcz - The Song of JBoss and Chef
DOD 2016 - Tomasz Torcz - The Song of JBoss and Chef
 
clonehd01
clonehd01clonehd01
clonehd01
 
Taste of-haskell
Taste of-haskellTaste of-haskell
Taste of-haskell
 
01 linux basics
01 linux basics01 linux basics
01 linux basics
 
Icsm2009 bettenburg presentation
Icsm2009 bettenburg presentationIcsm2009 bettenburg presentation
Icsm2009 bettenburg presentation
 
スマートフォン勉強会@関東 #11 LT 5分で語る SQLite暗号化
スマートフォン勉強会@関東 #11 LT 5分で語る SQLite暗号化スマートフォン勉強会@関東 #11 LT 5分で語る SQLite暗号化
スマートフォン勉強会@関東 #11 LT 5分で語る SQLite暗号化
 
GedcomX SDK - Getting Started
GedcomX SDK - Getting StartedGedcomX SDK - Getting Started
GedcomX SDK - Getting Started
 
Scala and big data in ICM. Scoobie, Scalding, Spark, Stratosphere. Scalar 2014
Scala and big data in ICM. Scoobie, Scalding, Spark, Stratosphere. Scalar 2014Scala and big data in ICM. Scoobie, Scalding, Spark, Stratosphere. Scalar 2014
Scala and big data in ICM. Scoobie, Scalding, Spark, Stratosphere. Scalar 2014
 
Klug pgsql tut
Klug pgsql tutKlug pgsql tut
Klug pgsql tut
 
On secure application of PHP wrappers
On secure application  of PHP wrappersOn secure application  of PHP wrappers
On secure application of PHP wrappers
 

Semelhante a Abusing Erlang compilation pipeline for Fun and Profit

Logging with Elasticsearch, Logstash & Kibana
Logging with Elasticsearch, Logstash & KibanaLogging with Elasticsearch, Logstash & Kibana
Logging with Elasticsearch, Logstash & Kibana
Amazee Labs
 
ZFConf 2011: Что такое Sphinx, зачем он вообще нужен и как его использовать с...
ZFConf 2011: Что такое Sphinx, зачем он вообще нужен и как его использовать с...ZFConf 2011: Что такое Sphinx, зачем он вообще нужен и как его использовать с...
ZFConf 2011: Что такое Sphinx, зачем он вообще нужен и как его использовать с...
ZFConf Conference
 

Semelhante a Abusing Erlang compilation pipeline for Fun and Profit (20)

Happy Go Programming
Happy Go ProgrammingHappy Go Programming
Happy Go Programming
 
2015 555 kharchenko_ppt
2015 555 kharchenko_ppt2015 555 kharchenko_ppt
2015 555 kharchenko_ppt
 
Learn Python 3 for absolute beginners
Learn Python 3 for absolute beginnersLearn Python 3 for absolute beginners
Learn Python 3 for absolute beginners
 
Python in 30 minutes!
Python in 30 minutes!Python in 30 minutes!
Python in 30 minutes!
 
Golang Performance : microbenchmarks, profilers, and a war story
Golang Performance : microbenchmarks, profilers, and a war storyGolang Performance : microbenchmarks, profilers, and a war story
Golang Performance : microbenchmarks, profilers, and a war story
 
忙しい人のためのSphinx 入門 demo
忙しい人のためのSphinx 入門 demo忙しい人のためのSphinx 入門 demo
忙しい人のためのSphinx 入門 demo
 
Extreme APIs for a better tomorrow
Extreme APIs for a better tomorrowExtreme APIs for a better tomorrow
Extreme APIs for a better tomorrow
 
Bits and Pieces from the UPEI Experience
Bits and Pieces from the UPEI ExperienceBits and Pieces from the UPEI Experience
Bits and Pieces from the UPEI Experience
 
Logging with Elasticsearch, Logstash & Kibana
Logging with Elasticsearch, Logstash & KibanaLogging with Elasticsearch, Logstash & Kibana
Logging with Elasticsearch, Logstash & Kibana
 
CoffeeScript Design Patterns
CoffeeScript Design PatternsCoffeeScript Design Patterns
CoffeeScript Design Patterns
 
Apache Hadoop Shell Rewrite
Apache Hadoop Shell RewriteApache Hadoop Shell Rewrite
Apache Hadoop Shell Rewrite
 
ACM BPM and elasticsearch AMIS25
ACM BPM and elasticsearch AMIS25ACM BPM and elasticsearch AMIS25
ACM BPM and elasticsearch AMIS25
 
Scrapy workshop
Scrapy workshopScrapy workshop
Scrapy workshop
 
Kyiv.py #16 october 2015
Kyiv.py #16 october 2015Kyiv.py #16 october 2015
Kyiv.py #16 october 2015
 
The Present and Future of the Web Platform
The Present and Future of the Web PlatformThe Present and Future of the Web Platform
The Present and Future of the Web Platform
 
ECMAScript 6
ECMAScript 6ECMAScript 6
ECMAScript 6
 
Oracle 18c installation on Oracle Enterprise Linux 7.4
Oracle 18c installation on Oracle Enterprise Linux 7.4Oracle 18c installation on Oracle Enterprise Linux 7.4
Oracle 18c installation on Oracle Enterprise Linux 7.4
 
The ARK Identifier Scheme at Ten Years Old
The ARK Identifier Scheme at Ten Years OldThe ARK Identifier Scheme at Ten Years Old
The ARK Identifier Scheme at Ten Years Old
 
ZFConf 2011: Что такое Sphinx, зачем он вообще нужен и как его использовать с...
ZFConf 2011: Что такое Sphinx, зачем он вообще нужен и как его использовать с...ZFConf 2011: Что такое Sphinx, зачем он вообще нужен и как его использовать с...
ZFConf 2011: Что такое Sphinx, зачем он вообще нужен и как его использовать с...
 
Es.next
Es.nextEs.next
Es.next
 

Mais de Wojciech Gawroński

Mais de Wojciech Gawroński (9)

AWS CDK: Your Infrastructure is Code!
AWS CDK: Your Infrastructure is Code!AWS CDK: Your Infrastructure is Code!
AWS CDK: Your Infrastructure is Code!
 
Mashup! AWS Lambda, Elixir and IoT Button
Mashup! AWS Lambda, Elixir and IoT ButtonMashup! AWS Lambda, Elixir and IoT Button
Mashup! AWS Lambda, Elixir and IoT Button
 
Amazon SageMaker in Practice - Workshop at Big Data Moscow 2018 (10.10.2018)
Amazon SageMaker in Practice - Workshop at Big Data Moscow 2018 (10.10.2018)Amazon SageMaker in Practice - Workshop at Big Data Moscow 2018 (10.10.2018)
Amazon SageMaker in Practice - Workshop at Big Data Moscow 2018 (10.10.2018)
 
Serverless .NET on AWS
Serverless .NET on AWS Serverless .NET on AWS
Serverless .NET on AWS
 
Functional Programming in Serverless World
Functional Programming in Serverless WorldFunctional Programming in Serverless World
Functional Programming in Serverless World
 
Learn Elixir The Hard Way
Learn Elixir The Hard WayLearn Elixir The Hard Way
Learn Elixir The Hard Way
 
Functional Programming in the Wild
Functional Programming in the WildFunctional Programming in the Wild
Functional Programming in the Wild
 
Why docker@localhost is not even remotely near DevOps?
Why docker@localhost is not even remotely near DevOps?Why docker@localhost is not even remotely near DevOps?
Why docker@localhost is not even remotely near DevOps?
 
How to move a mission critical system to 4 AWS regions in one year?
How to move a mission critical system to 4 AWS regions in one year?How to move a mission critical system to 4 AWS regions in one year?
How to move a mission critical system to 4 AWS regions in one year?
 

Último

Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
FIDO Alliance
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
FIDO Alliance
 

Último (20)

Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
Vector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxVector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptx
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overview
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 

Abusing Erlang compilation pipeline for Fun and Profit