これからのPerlプロダクトのかたち(YAPC::Asia 2013)

G
A brand new way of
Perl product, and it‟s future
Masaaki Goshima (@goccy54)
mixi Inc.
Me
• Name : Masaaki Goshima (@goccy54)
• Job : mixi (Tanpopo Group)
– Development for Developers
– Developing a platform for refining legacy software
– Managing Jenkins
• Personally, interested in Perl and developing
yet another Perl, gperl
– (YAPC::Asia 2012) Perlと出会いPerlを作る
gperl
• Fastest perl-like language
– Aiming perl5 compatible syntax
– Written with C++
• The last commit for repository was 11 months
ago...
– “Is this already departed !?”
NO! ITS STILL ALIVE!!!
• However, gperl itself has departed
• Modules(lexical analyzer, parser, code
generator, interpreter) are useful
– Lexical analyzer: implementing perl5 syntax
highlighter
– Parser: static analysis tool (used as
refinement of legacy perl5 code)
Input ->Lexer -> Parser ->CodeGenerator -> VM (JIT) -> output
This presentation‟s Goal
• Today, we‟re going to present “Spinout
projects” for each modules
gperl
Compiler::Lexer Compiler::Parser
Compiler::CodeGenerator
::LLVM
Lexer
Parser CodeGenerator
???::???::??? ?????
Next Module
Agenda
• Section 1
– Introduction of Compiler::* Modules
• Section 2
– (Application1) Running on multi platforms
• Section 3
– (Application2) Static analysis tool
Section1
• Introduction of Compiler::* Modules
1. Compiler::Lexer
– Lexical Analyzer for Perl5
2. Compiler::Parser
– Create Abstract Syntax Tree for Perl5
3. Compiler::CodeGenerator::LLVM
– Create LLVM IR for Perl5
Compiler::Lexer
• Lexical Analyzer for Perl5
• Features
– Simple (return Array Reference of Token Object)
– Fast (faster 10 ~ 100 times than PPI::Tokenize)
• Wirtten with C++
• Perfect hashing for reserved keywords
• memory pool for token objects
– Readable Code
• Nothing use parser generator like yacc/bison
Example
1: my$v = sprintf(<<'TEMPLATE', 'yapc');
2: %s::Asia
3: TEMPLATE
4: $v =~ s#yapc#YAPC#;
%s::Asia : HereDocument
TEMPLATE : HereDocumentEnd
$v : Var
=~ : RegOK
s : RegReplace
# : RegDelim
yapc : RegReplaceFrom
# : RegMiddleDelim
YAPC : RegReplaceTo
# : RegDelim
; : SemiColon
my : VarDecl
$v : LocalVar
= : Assign
sprintf : BuiltinFunc
( : LeftParenthesis
<< : LeftShift
TEMPLATE : HereDocumentRawTag
, : Comma
yapc : RawString
) : RightParenthesis
; : SemiColon
tokenize
Tips
• Cannot tokenize pattern
1. func*v
• 「*」is Glob or Mul
2. func/ ..
• 「/」is RegexDelimiter or Div
3. func<<FLAG
• 「FLAG」is HereDocumentTag or Constant
It may make a mistake
Future plan
• Supporting recursively tokenizing
– More wide range of parsing application
– Recursive parsing will take time, optimizing
will be next future work
func*v =>func(*v) or func() * v
func/ … =>func(/../) or func() / v
func<<FLAG =>func(<<FLAG) or func() << FLAG
sub func($) {} or sub func() {}
Compiler::Parser
• Create Abstract Syntax Tree for Perl5
• Features
– Fast (faster than PPI)
– Readable Code
• Simple design
• Nothing use generator
Can generate Virtual Machine code
as walking tree by post order
->
$a->{b}->[0]->c(@args)
->
->
$a {}
b
[]
c
0
@args
left
left
left
right
argsright
right
data
data
Example
my$v= sin$v + $v * $v / $v - $v&&$v
my($v= (sin((($v+ (($v* $v) / $v)) - $v))&&$v))
=
$v &&
left right
rightleft
The most difficult part of
Perl5 parser:
hidden(optional)
parenthesis
Example2) Can parse BlackPerl
BEFOREHAND: close door, each window &exit;
waituntiltime;
open spell book; study;
read (spell, $scan, select); tell us;
write it, print(thehex) whileeach watches,
reverse length,write again;
kill spiders, pop them, chop,
split, kill them. unlink arms, shift,
waitand listen (listening, wait).
sort the flock (then,
warn"the goats", kill"the sheep");
kill them, dump qualms,
shift moralities, values aside, each one;
die sheep; die (to, reversethe => system
you accept (reject, respect));
next step, killnext sacrifice,
each sacrifice, wait, redo ritual
until"all the spirits are pleased";
do it ("as they say").
do it(*everyone***must***participate***in***forbidden**s*e*x*).
return last victim; package body;
exitcrypt
(time, times&“half a time”)
&close it.
select (quickly) and
warnnext victim;
AFTERWARDS: tell nobody.
wait, waituntiltime;
wait until next year, next decade;
sleep, sleep, die yourself,
die@last
BlackPerl for Perl5
Future plan
• Replace PPI !!!
– Supporting some expressions
• ThreeTermOperator, Glob, given/when, goto etc..
– Supporting compatible methods PPI provides
• PPI::Document::find
• PPI::Document::prune
Compiler::CodeGenerator::LLVM
• Create LLVM IR for Perl5
->
$a->{b}->[0]->c(@args)
->
->
$a {}
b
[]
c
0
@args
left
left
left
right
argsright
right
data
data
1 2
3
4 5
6
7 8
9
10
Compiler::Parser Compiler::CodeGenerator::LLVM
LLVM IR
Running
with JIT
Native Code
Other Language
LLVM(Low Level Virtual Machine)
• Compiler Infrastructure
• Better than GNU GCC
LLVM
X86
ARM
Power
C/C++/Object
ive-C
JavaScript
py2llvm
MacRuby
clang
How to use
• Dependency: clang/llvm version 3.2 or 3.3
useCompiler::Lexer;
useCompiler::Parser;
useCompiler::CodeGenerator::LLVM;
my$tokens = Compiler::Lexer->new('')->tokenize($code);
my $ast= Compiler::Parser->new->parse($tokens);
my$generator = Compiler::CodeGenerator::LLVM->new();
my$llvm_ir= $generator->generate($ast); # generate LLVM IR
$generator->debug_run($ast); # run with JIT
Benchmark(Fibonacci)
Language
time(real)[
sec]
X
gperl 0.10 X81.2
LuaJIT
(2.0.0-beta10)
0.12 X67.6
v8(0.8.0) 0.18 X45.1
Compiler::CodeGenerator::
LLVM
0.72 X11.2
Perl(5.16.0) 8.12 X1.0
Environment
MacOSX(10.8.4)
2.2GHz Intel Core i7
Memory: 8GB
N=35
Section 2
• Application1)
– Running on multi platforms
1. Running on Web Browser
• Recently, way of writing code that runs on web
browser is not onlyJavaScript
– e.g.) CoffeScript, JSX, TypeScript, Dart
• I wrote module for Perl5!
SEE ALSO :perl.js (@gfx)
Compiler::Tools::Transpiler
• Translate Perl5 codes to JavaScript codes
– (Step1) translate Perl5 codes to LLVM-IR with
Compiler::* modules
– (Step2) translate LLVM-IR to JavaScript codes with
emscripten
Perl5
LLVM emscripten
How to use
useCompiler::Tools::Transpiler;
my$transpiler= Compiler::Tools::Transpiler->new({
engine=>'JavaScript‟,
library_path=> [„lib‟]
});
openmy $fh, '<', 'target_application.pl';
my$perl5_code = do { local$/; <$fh> };
my$javascript_code= $transpiler->transpile($perl5_code);
open $fh, '>', 'target_application.js';
print$fh $javascript_code;
close$fh;
※ Needs clang-3.2 and LLVM-3.2 (Not ver. 3.3 or later) because emscripten has still not
support LLVM 3.3 or later
ROADMAP/Repository
• Fix some emscripten‟s bugs
• Supporting accessors for HTML objects
• Supporting Canvas API
• etc..
• Repository
– https://github.com/goccy/p5-Compiler-Tools-Transpiler.git
2. Running on iOS and OSX
• Recently, software that can develop iOS or OSX
applications using light weight language has
being released
– RubyMotion
– mocl
– Titanium
• I wrote module for Perl5!
PerlMotion
iOS and OS X development
using the Perl5 programming language
PerlMotion’s Architecture
UIKit
Cocoa Touch Frameworks
Core Animation Core Audio Core Data
Perl5 x Cocoa Touch Frameworks
Bindings Library
LLVM IR
(Links Perl5 codes and Cocoa Touch Frameworks)
Perl5 Codes
Compiler::Lexer
Compiler::Parser
Compiler::CodeGenerator::LLVM
iOS Simulator iOS DeviceMacOSX
Generates Native Code for each target Architecture
DEMO
• HelloWorldby PerlMotion
Current Status
Still not support functions
Symbol Management System : Glob
Garbage Collection
Regexp
Three Term Operator
etc..
Not support functions
Dynamic evaluation like eval, s/../../e,
require
Supported functions
Primitive Types : Int, double, String, Array,
Hash, ArrayRefence, HashReference,
IOHandler, BlessedObject …
Operators : binary operator, single term
operator …
BuiltinFunction : print, say, shift, push, sin,
open …
Variable Definition, Function Definition
OOP System : package, bless, @ISA
ROADMAP
• Supporting deployment on device
• Preparing debugging environment
– (stdout/stderr/gdb..etc)
• Supporting existing framework (e.g. UIKit)
• Supporting CPAN modules written by Pure Perl
2014/4
Will release at April, 2014!
Welcome your Contribution!
• I want discuss design or objective
– Especially, I need advice on “What Perl
community likes?” (Naming rule, etc…)
https://github.com/goccy/perl-motion.git
Conclusion at Section 1 and 2
• Perl5 codes Run Anywhere!!!
– iOS,OSX,Web Browser and others
• Welcome your Contribution
– Compiler::Lexer
• https://github.com/goccy/p5-Compiler-Lexer.git
– Compiler::Parser
• https://github.com/goccy/p5-Compiler-Parser.git
– Compiler::CodeGenerator::LLVM
• https://github.com/goccy/p5-Compiler-CodeGenerator.git
– Compiler::Tools::Transpiler
• https://github.com/goccy/p5-Compiler-Tools-Transpiler.git
– PerlMotion
• https://github.com/goccy/perl-motion.git
• Application2)
– Static analysis tool
Section3
Compiler::Tools::CopyPasteDetector
• Detect Copy and Paste for Perl5
• Features
– Fast (detecting Engine written by C++ with
POSIX Thread)
– Accuracy (based on Compiler::Lexer and
B::Deparse)
– High functionality Visualizer
(some metrics or scattergram etc…)
DEMO
• Detect Copy & Paste of Catalyst and Mojolicious
Another Modules
• Perl::MinimumVersion::Fast(@tokuhirom)
– Find a minimum required version of perl for Perl code
• Test::LocalFunctions::Fast(@papix)
– Detect unused local function
Compiler::Lexer or Compiler::Parser provide that
you can write faster modules than existing module that uses PPI
Future plan
• Perl::Metrics::Simple::Fast
– Will release faster module than
Perl::Metrics::Simple by using
Compiler::Lexer and Compiler::Parser
• Next future, I will CPANize of static alnalysis
module that has been used at mixi
– It includes rich Visualizer
Conclusion at Section 3
• Introduction of copy and paste detecting
tool for Perl5
– Compiler::Tools::CopyPasteDetector
• Compiler::Lexer or Compiler::Parser provide that
you can write faster modules than existing
module that uses PPI
Finally
Compiler::Lexer Compiler::Parser
Compiler::CodeGenerator
::LLVM
Type Inference
Engine
Static Typing
- Coming soon -
gperl will assemble these brand new modules...
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
1 of 40

Recommended

Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015) by
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)ngotogenome
11.9K views42 slides
JavaOne 2012 - JVM JIT for Dummies by
JavaOne 2012 - JVM JIT for DummiesJavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesCharles Nutter
11K views123 slides
JRuby 9000 - Taipei Ruby User's Group 2015 by
JRuby 9000 - Taipei Ruby User's Group 2015JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015Charles Nutter
1.2K views73 slides
Beyond JVM - YOW! Sydney 2013 by
Beyond JVM - YOW! Sydney 2013Beyond JVM - YOW! Sydney 2013
Beyond JVM - YOW! Sydney 2013Charles Nutter
3.2K views115 slides
JRuby and Invokedynamic - Japan JUG 2015 by
JRuby and Invokedynamic - Japan JUG 2015JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015Charles Nutter
1.6K views89 slides
JRuby 9000 - Optimizing Above the JVM by
JRuby 9000 - Optimizing Above the JVMJRuby 9000 - Optimizing Above the JVM
JRuby 9000 - Optimizing Above the JVMCharles Nutter
2.1K views65 slides

More Related Content

What's hot

2008 07-24 kwpm-threads_and_synchronization by
2008 07-24 kwpm-threads_and_synchronization2008 07-24 kwpm-threads_and_synchronization
2008 07-24 kwpm-threads_and_synchronizationfangjiafu
393 views55 slides
Memory Management In Python The Basics by
Memory Management In Python The BasicsMemory Management In Python The Basics
Memory Management In Python The BasicsNina Zakharenko
32.5K views77 slides
JVM for Dummies - OSCON 2011 by
JVM for Dummies - OSCON 2011JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011Charles Nutter
7.7K views209 slides
Down the Rabbit Hole: An Adventure in JVM Wonderland by
Down the Rabbit Hole: An Adventure in JVM WonderlandDown the Rabbit Hole: An Adventure in JVM Wonderland
Down the Rabbit Hole: An Adventure in JVM WonderlandCharles Nutter
2.6K views128 slides
Experiments in Sharing Java VM Technology with CRuby by
Experiments in Sharing Java VM Technology with CRubyExperiments in Sharing Java VM Technology with CRuby
Experiments in Sharing Java VM Technology with CRubyMatthew Gaudet
17.7K views60 slides
Inside the JVM - Follow the white rabbit! by
Inside the JVM - Follow the white rabbit!Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!Sylvain Wallez
1.5K views59 slides

What's hot(20)

2008 07-24 kwpm-threads_and_synchronization by fangjiafu
2008 07-24 kwpm-threads_and_synchronization2008 07-24 kwpm-threads_and_synchronization
2008 07-24 kwpm-threads_and_synchronization
fangjiafu393 views
Memory Management In Python The Basics by Nina Zakharenko
Memory Management In Python The BasicsMemory Management In Python The Basics
Memory Management In Python The Basics
Nina Zakharenko32.5K views
JVM for Dummies - OSCON 2011 by Charles Nutter
JVM for Dummies - OSCON 2011JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011
Charles Nutter7.7K views
Down the Rabbit Hole: An Adventure in JVM Wonderland by Charles Nutter
Down the Rabbit Hole: An Adventure in JVM WonderlandDown the Rabbit Hole: An Adventure in JVM Wonderland
Down the Rabbit Hole: An Adventure in JVM Wonderland
Charles Nutter2.6K views
Experiments in Sharing Java VM Technology with CRuby by Matthew Gaudet
Experiments in Sharing Java VM Technology with CRubyExperiments in Sharing Java VM Technology with CRuby
Experiments in Sharing Java VM Technology with CRuby
Matthew Gaudet17.7K views
Inside the JVM - Follow the white rabbit! by Sylvain Wallez
Inside the JVM - Follow the white rabbit!Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!
Sylvain Wallez1.5K views
Introduction to clojure by Abbas Raza
Introduction to clojureIntroduction to clojure
Introduction to clojure
Abbas Raza1.4K views
Seeking Clojure by chrisriceuk
Seeking ClojureSeeking Clojure
Seeking Clojure
chrisriceuk1.3K views
Java 7 Whats New(), Whats Next() from Oredev by Mattias Karlsson
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from Oredev
Mattias Karlsson2.2K views
Asynchronous I/O in Python 3 by Feihong Hsu
Asynchronous I/O in Python 3Asynchronous I/O in Python 3
Asynchronous I/O in Python 3
Feihong Hsu40.3K views
Know yourengines velocity2011 by Demis Bellot
Know yourengines velocity2011Know yourengines velocity2011
Know yourengines velocity2011
Demis Bellot116.1K views
あなたのScalaを爆速にする7つの方法 by x1 ichi
あなたのScalaを爆速にする7つの方法あなたのScalaを爆速にする7つの方法
あなたのScalaを爆速にする7つの方法
x1 ichi9.1K views
Why GC is eating all my CPU? by Roman Elizarov
Why GC is eating all my CPU?Why GC is eating all my CPU?
Why GC is eating all my CPU?
Roman Elizarov6.7K views
Doctrine 2.0 Enterprise Persistence Layer for PHP by Guilherme Blanco
Doctrine 2.0 Enterprise Persistence Layer for PHPDoctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHP
Guilherme Blanco4.8K views
Fighting API Compatibility On Fluentd Using "Black Magic" by SATOSHI TAGOMORI
Fighting API Compatibility On Fluentd Using "Black Magic"Fighting API Compatibility On Fluentd Using "Black Magic"
Fighting API Compatibility On Fluentd Using "Black Magic"
SATOSHI TAGOMORI7.4K views
JVM Mechanics: When Does the JVM JIT & Deoptimize? by Doug Hawkins
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
Doug Hawkins12.7K views

Viewers also liked

Use Carton by
Use CartonUse Carton
Use CartonYoshihiro Sasaki
1.9K views26 slides
"Ops Tools with Perl" 2012/05/12 Hokkaido.pm by
"Ops Tools with Perl" 2012/05/12 Hokkaido.pm"Ops Tools with Perl" 2012/05/12 Hokkaido.pm
"Ops Tools with Perl" 2012/05/12 Hokkaido.pmRyosuke IWANAGA
1.8K views38 slides
YAPCレポートの舞台裏 by
YAPCレポートの舞台裏YAPCレポートの舞台裏
YAPCレポートの舞台裏Masahiro Honma
1.6K views23 slides
テーマ「最適化」 by
テーマ「最適化」テーマ「最適化」
テーマ「最適化」technocat
918 views24 slides
PHPカンファレンス北海道_20160416 by
PHPカンファレンス北海道_20160416PHPカンファレンス北海道_20160416
PHPカンファレンス北海道_20160416Yoshihiro Sasaki
1.1K views21 slides
YAPC::AsiaとHokkaido.pm by
YAPC::AsiaとHokkaido.pmYAPC::AsiaとHokkaido.pm
YAPC::AsiaとHokkaido.pmYoshihiro Sasaki
1.5K views20 slides

Viewers also liked(20)

"Ops Tools with Perl" 2012/05/12 Hokkaido.pm by Ryosuke IWANAGA
"Ops Tools with Perl" 2012/05/12 Hokkaido.pm"Ops Tools with Perl" 2012/05/12 Hokkaido.pm
"Ops Tools with Perl" 2012/05/12 Hokkaido.pm
Ryosuke IWANAGA1.8K views
YAPCレポートの舞台裏 by Masahiro Honma
YAPCレポートの舞台裏YAPCレポートの舞台裏
YAPCレポートの舞台裏
Masahiro Honma1.6K views
テーマ「最適化」 by technocat
テーマ「最適化」テーマ「最適化」
テーマ「最適化」
technocat918 views
PHPカンファレンス北海道_20160416 by Yoshihiro Sasaki
PHPカンファレンス北海道_20160416PHPカンファレンス北海道_20160416
PHPカンファレンス北海道_20160416
Yoshihiro Sasaki1.1K views
Games::* - Perlで 「ゲーム」しよう #hokkaidopm by 鉄次 尾形
Games::* - Perlで 「ゲーム」しよう #hokkaidopmGames::* - Perlで 「ゲーム」しよう #hokkaidopm
Games::* - Perlで 「ゲーム」しよう #hokkaidopm
鉄次 尾形3K views
Google trends to_irc by rarere
Google trends to_ircGoogle trends to_irc
Google trends to_irc
rarere883 views
YAPC::Asia 2013 - CPAN Testers Reports の情報を上手に使う by moznion
YAPC::Asia 2013 - CPAN Testers Reports の情報を上手に使うYAPC::Asia 2013 - CPAN Testers Reports の情報を上手に使う
YAPC::Asia 2013 - CPAN Testers Reports の情報を上手に使う
moznion4.2K views
理解したつもりになるGit入門 by Yoshihiro Sasaki
理解したつもりになるGit入門理解したつもりになるGit入門
理解したつもりになるGit入門
Yoshihiro Sasaki995 views
Plack::Request with Encoding by moznion
Plack::Request with EncodingPlack::Request with Encoding
Plack::Request with Encoding
moznion1.5K views
テーマ「なんでもないようなこと」 by technocat
テーマ「なんでもないようなこと」テーマ「なんでもないようなこと」
テーマ「なんでもないようなこと」
technocat862 views
Takao.mt 2013 by moznion
Takao.mt 2013Takao.mt 2013
Takao.mt 2013
moznion690 views
Perl 非同期プログラミング by lestrrat
Perl 非同期プログラミングPerl 非同期プログラミング
Perl 非同期プログラミング
lestrrat7.3K views
変数、リファレンス by charsbar
変数、リファレンス変数、リファレンス
変数、リファレンス
charsbar1.8K views

Similar to これからのPerlプロダクトのかたち(YAPC::Asia 2013)

Packaging perl (LPW2010) by
Packaging perl (LPW2010)Packaging perl (LPW2010)
Packaging perl (LPW2010)p3castro
2.1K views32 slides
50 shades of PHP by
50 shades of PHP50 shades of PHP
50 shades of PHPMaksym Hopei
182 views67 slides
Golang by
GolangGolang
GolangSoftware Infrastructure
693 views48 slides
Golang by
GolangGolang
GolangFatih Şimşek
293 views48 slides
A brief to PHP 7.3 by
A brief to PHP 7.3A brief to PHP 7.3
A brief to PHP 7.3Xinchen Hui
815 views17 slides
PHP Development Tools by
PHP  Development ToolsPHP  Development Tools
PHP Development ToolsAntony Abramchenko
341 views39 slides

Similar to これからのPerlプロダクトのかたち(YAPC::Asia 2013)(20)

Packaging perl (LPW2010) by p3castro
Packaging perl (LPW2010)Packaging perl (LPW2010)
Packaging perl (LPW2010)
p3castro2.1K views
A brief to PHP 7.3 by Xinchen Hui
A brief to PHP 7.3A brief to PHP 7.3
A brief to PHP 7.3
Xinchen Hui815 views
Polyglot and Functional Programming (OSCON 2012) by Martijn Verburg
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)
Martijn Verburg2.7K views
Eugene PHP June 2015 - Let's Talk Laravel by anaxamaxan
Eugene PHP June 2015 - Let's Talk LaravelEugene PHP June 2015 - Let's Talk Laravel
Eugene PHP June 2015 - Let's Talk Laravel
anaxamaxan899 views
Introduction to Laravel Framework (5.2) by Viral Solani
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)
Viral Solani2.5K views
Getting Started with Go by Steven Francia
Getting Started with GoGetting Started with Go
Getting Started with Go
Steven Francia39.8K views
Functional Programming in Clojure by Troy Miles
Functional Programming in ClojureFunctional Programming in Clojure
Functional Programming in Clojure
Troy Miles623 views
Игорь Фесенко "Direction of C# as a High-Performance Language" by Fwdays
Игорь Фесенко "Direction of C# as a High-Performance Language"Игорь Фесенко "Direction of C# as a High-Performance Language"
Игорь Фесенко "Direction of C# as a High-Performance Language"
Fwdays1.1K views
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift by Diego Freniche Brito
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift

Recently uploaded

"Surviving highload with Node.js", Andrii Shumada by
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada Fwdays
49 views29 slides
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveNetwork Automation Forum
49 views35 slides
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ... by
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...ShapeBlue
97 views28 slides
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti... by
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...ShapeBlue
69 views29 slides
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...James Anderson
142 views32 slides
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue by
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlueMigrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlueShapeBlue
147 views20 slides

Recently uploaded(20)

"Surviving highload with Node.js", Andrii Shumada by Fwdays
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada
Fwdays49 views
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ... by ShapeBlue
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...
ShapeBlue97 views
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti... by ShapeBlue
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
ShapeBlue69 views
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson142 views
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue by ShapeBlue
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlueMigrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue
ShapeBlue147 views
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T by ShapeBlue
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&TCloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T
ShapeBlue81 views
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha... by ShapeBlue
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
ShapeBlue113 views
Future of AR - Facebook Presentation by Rob McCarty
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook Presentation
Rob McCarty54 views
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ... by ShapeBlue
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
ShapeBlue121 views
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading... by The Digital Insurer
Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading...
Confidence in CloudStack - Aron Wagner, Nathan Gleason - Americ by ShapeBlue
Confidence in CloudStack - Aron Wagner, Nathan Gleason - AmericConfidence in CloudStack - Aron Wagner, Nathan Gleason - Americ
Confidence in CloudStack - Aron Wagner, Nathan Gleason - Americ
ShapeBlue58 views
State of the Union - Rohit Yadav - Apache CloudStack by ShapeBlue
State of the Union - Rohit Yadav - Apache CloudStackState of the Union - Rohit Yadav - Apache CloudStack
State of the Union - Rohit Yadav - Apache CloudStack
ShapeBlue218 views
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue by ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlueCloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
ShapeBlue68 views
Business Analyst Series 2023 - Week 4 Session 7 by DianaGray10
Business Analyst Series 2023 -  Week 4 Session 7Business Analyst Series 2023 -  Week 4 Session 7
Business Analyst Series 2023 - Week 4 Session 7
DianaGray10110 views
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software373 views
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker50 views
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava... by ShapeBlue
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...
ShapeBlue74 views

これからのPerlプロダクトのかたち(YAPC::Asia 2013)

  • 1. A brand new way of Perl product, and it‟s future Masaaki Goshima (@goccy54) mixi Inc.
  • 2. Me • Name : Masaaki Goshima (@goccy54) • Job : mixi (Tanpopo Group) – Development for Developers – Developing a platform for refining legacy software – Managing Jenkins • Personally, interested in Perl and developing yet another Perl, gperl – (YAPC::Asia 2012) Perlと出会いPerlを作る
  • 3. gperl • Fastest perl-like language – Aiming perl5 compatible syntax – Written with C++ • The last commit for repository was 11 months ago... – “Is this already departed !?”
  • 4. NO! ITS STILL ALIVE!!! • However, gperl itself has departed • Modules(lexical analyzer, parser, code generator, interpreter) are useful – Lexical analyzer: implementing perl5 syntax highlighter – Parser: static analysis tool (used as refinement of legacy perl5 code) Input ->Lexer -> Parser ->CodeGenerator -> VM (JIT) -> output
  • 5. This presentation‟s Goal • Today, we‟re going to present “Spinout projects” for each modules gperl Compiler::Lexer Compiler::Parser Compiler::CodeGenerator ::LLVM Lexer Parser CodeGenerator ???::???::??? ????? Next Module
  • 6. Agenda • Section 1 – Introduction of Compiler::* Modules • Section 2 – (Application1) Running on multi platforms • Section 3 – (Application2) Static analysis tool
  • 7. Section1 • Introduction of Compiler::* Modules 1. Compiler::Lexer – Lexical Analyzer for Perl5 2. Compiler::Parser – Create Abstract Syntax Tree for Perl5 3. Compiler::CodeGenerator::LLVM – Create LLVM IR for Perl5
  • 8. Compiler::Lexer • Lexical Analyzer for Perl5 • Features – Simple (return Array Reference of Token Object) – Fast (faster 10 ~ 100 times than PPI::Tokenize) • Wirtten with C++ • Perfect hashing for reserved keywords • memory pool for token objects – Readable Code • Nothing use parser generator like yacc/bison
  • 9. Example 1: my$v = sprintf(<<'TEMPLATE', 'yapc'); 2: %s::Asia 3: TEMPLATE 4: $v =~ s#yapc#YAPC#; %s::Asia : HereDocument TEMPLATE : HereDocumentEnd $v : Var =~ : RegOK s : RegReplace # : RegDelim yapc : RegReplaceFrom # : RegMiddleDelim YAPC : RegReplaceTo # : RegDelim ; : SemiColon my : VarDecl $v : LocalVar = : Assign sprintf : BuiltinFunc ( : LeftParenthesis << : LeftShift TEMPLATE : HereDocumentRawTag , : Comma yapc : RawString ) : RightParenthesis ; : SemiColon tokenize
  • 10. Tips • Cannot tokenize pattern 1. func*v • 「*」is Glob or Mul 2. func/ .. • 「/」is RegexDelimiter or Div 3. func<<FLAG • 「FLAG」is HereDocumentTag or Constant It may make a mistake
  • 11. Future plan • Supporting recursively tokenizing – More wide range of parsing application – Recursive parsing will take time, optimizing will be next future work func*v =>func(*v) or func() * v func/ … =>func(/../) or func() / v func<<FLAG =>func(<<FLAG) or func() << FLAG sub func($) {} or sub func() {}
  • 12. Compiler::Parser • Create Abstract Syntax Tree for Perl5 • Features – Fast (faster than PPI) – Readable Code • Simple design • Nothing use generator Can generate Virtual Machine code as walking tree by post order -> $a->{b}->[0]->c(@args) -> -> $a {} b [] c 0 @args left left left right argsright right data data
  • 13. Example my$v= sin$v + $v * $v / $v - $v&&$v my($v= (sin((($v+ (($v* $v) / $v)) - $v))&&$v)) = $v && left right rightleft The most difficult part of Perl5 parser: hidden(optional) parenthesis
  • 14. Example2) Can parse BlackPerl BEFOREHAND: close door, each window &exit; waituntiltime; open spell book; study; read (spell, $scan, select); tell us; write it, print(thehex) whileeach watches, reverse length,write again; kill spiders, pop them, chop, split, kill them. unlink arms, shift, waitand listen (listening, wait). sort the flock (then, warn"the goats", kill"the sheep"); kill them, dump qualms, shift moralities, values aside, each one; die sheep; die (to, reversethe => system you accept (reject, respect)); next step, killnext sacrifice, each sacrifice, wait, redo ritual until"all the spirits are pleased"; do it ("as they say"). do it(*everyone***must***participate***in***forbidden**s*e*x*). return last victim; package body; exitcrypt (time, times&“half a time”) &close it. select (quickly) and warnnext victim; AFTERWARDS: tell nobody. wait, waituntiltime; wait until next year, next decade; sleep, sleep, die yourself, die@last BlackPerl for Perl5
  • 15. Future plan • Replace PPI !!! – Supporting some expressions • ThreeTermOperator, Glob, given/when, goto etc.. – Supporting compatible methods PPI provides • PPI::Document::find • PPI::Document::prune
  • 16. Compiler::CodeGenerator::LLVM • Create LLVM IR for Perl5 -> $a->{b}->[0]->c(@args) -> -> $a {} b [] c 0 @args left left left right argsright right data data 1 2 3 4 5 6 7 8 9 10 Compiler::Parser Compiler::CodeGenerator::LLVM LLVM IR Running with JIT
  • 17. Native Code Other Language LLVM(Low Level Virtual Machine) • Compiler Infrastructure • Better than GNU GCC LLVM X86 ARM Power C/C++/Object ive-C JavaScript py2llvm MacRuby clang
  • 18. How to use • Dependency: clang/llvm version 3.2 or 3.3 useCompiler::Lexer; useCompiler::Parser; useCompiler::CodeGenerator::LLVM; my$tokens = Compiler::Lexer->new('')->tokenize($code); my $ast= Compiler::Parser->new->parse($tokens); my$generator = Compiler::CodeGenerator::LLVM->new(); my$llvm_ir= $generator->generate($ast); # generate LLVM IR $generator->debug_run($ast); # run with JIT
  • 19. Benchmark(Fibonacci) Language time(real)[ sec] X gperl 0.10 X81.2 LuaJIT (2.0.0-beta10) 0.12 X67.6 v8(0.8.0) 0.18 X45.1 Compiler::CodeGenerator:: LLVM 0.72 X11.2 Perl(5.16.0) 8.12 X1.0 Environment MacOSX(10.8.4) 2.2GHz Intel Core i7 Memory: 8GB N=35
  • 20. Section 2 • Application1) – Running on multi platforms
  • 21. 1. Running on Web Browser • Recently, way of writing code that runs on web browser is not onlyJavaScript – e.g.) CoffeScript, JSX, TypeScript, Dart • I wrote module for Perl5! SEE ALSO :perl.js (@gfx)
  • 22. Compiler::Tools::Transpiler • Translate Perl5 codes to JavaScript codes – (Step1) translate Perl5 codes to LLVM-IR with Compiler::* modules – (Step2) translate LLVM-IR to JavaScript codes with emscripten Perl5 LLVM emscripten
  • 23. How to use useCompiler::Tools::Transpiler; my$transpiler= Compiler::Tools::Transpiler->new({ engine=>'JavaScript‟, library_path=> [„lib‟] }); openmy $fh, '<', 'target_application.pl'; my$perl5_code = do { local$/; <$fh> }; my$javascript_code= $transpiler->transpile($perl5_code); open $fh, '>', 'target_application.js'; print$fh $javascript_code; close$fh; ※ Needs clang-3.2 and LLVM-3.2 (Not ver. 3.3 or later) because emscripten has still not support LLVM 3.3 or later
  • 24. ROADMAP/Repository • Fix some emscripten‟s bugs • Supporting accessors for HTML objects • Supporting Canvas API • etc.. • Repository – https://github.com/goccy/p5-Compiler-Tools-Transpiler.git
  • 25. 2. Running on iOS and OSX • Recently, software that can develop iOS or OSX applications using light weight language has being released – RubyMotion – mocl – Titanium • I wrote module for Perl5!
  • 26. PerlMotion iOS and OS X development using the Perl5 programming language
  • 27. PerlMotion’s Architecture UIKit Cocoa Touch Frameworks Core Animation Core Audio Core Data Perl5 x Cocoa Touch Frameworks Bindings Library LLVM IR (Links Perl5 codes and Cocoa Touch Frameworks) Perl5 Codes Compiler::Lexer Compiler::Parser Compiler::CodeGenerator::LLVM iOS Simulator iOS DeviceMacOSX Generates Native Code for each target Architecture
  • 29. Current Status Still not support functions Symbol Management System : Glob Garbage Collection Regexp Three Term Operator etc.. Not support functions Dynamic evaluation like eval, s/../../e, require Supported functions Primitive Types : Int, double, String, Array, Hash, ArrayRefence, HashReference, IOHandler, BlessedObject … Operators : binary operator, single term operator … BuiltinFunction : print, say, shift, push, sin, open … Variable Definition, Function Definition OOP System : package, bless, @ISA
  • 30. ROADMAP • Supporting deployment on device • Preparing debugging environment – (stdout/stderr/gdb..etc) • Supporting existing framework (e.g. UIKit) • Supporting CPAN modules written by Pure Perl 2014/4 Will release at April, 2014!
  • 31. Welcome your Contribution! • I want discuss design or objective – Especially, I need advice on “What Perl community likes?” (Naming rule, etc…) https://github.com/goccy/perl-motion.git
  • 32. Conclusion at Section 1 and 2 • Perl5 codes Run Anywhere!!! – iOS,OSX,Web Browser and others • Welcome your Contribution – Compiler::Lexer • https://github.com/goccy/p5-Compiler-Lexer.git – Compiler::Parser • https://github.com/goccy/p5-Compiler-Parser.git – Compiler::CodeGenerator::LLVM • https://github.com/goccy/p5-Compiler-CodeGenerator.git – Compiler::Tools::Transpiler • https://github.com/goccy/p5-Compiler-Tools-Transpiler.git – PerlMotion • https://github.com/goccy/perl-motion.git
  • 33. • Application2) – Static analysis tool Section3
  • 34. Compiler::Tools::CopyPasteDetector • Detect Copy and Paste for Perl5 • Features – Fast (detecting Engine written by C++ with POSIX Thread) – Accuracy (based on Compiler::Lexer and B::Deparse) – High functionality Visualizer (some metrics or scattergram etc…)
  • 35. DEMO • Detect Copy & Paste of Catalyst and Mojolicious
  • 36. Another Modules • Perl::MinimumVersion::Fast(@tokuhirom) – Find a minimum required version of perl for Perl code • Test::LocalFunctions::Fast(@papix) – Detect unused local function Compiler::Lexer or Compiler::Parser provide that you can write faster modules than existing module that uses PPI
  • 37. Future plan • Perl::Metrics::Simple::Fast – Will release faster module than Perl::Metrics::Simple by using Compiler::Lexer and Compiler::Parser • Next future, I will CPANize of static alnalysis module that has been used at mixi – It includes rich Visualizer
  • 38. Conclusion at Section 3 • Introduction of copy and paste detecting tool for Perl5 – Compiler::Tools::CopyPasteDetector • Compiler::Lexer or Compiler::Parser provide that you can write faster modules than existing module that uses PPI
  • 39. Finally Compiler::Lexer Compiler::Parser Compiler::CodeGenerator ::LLVM Type Inference Engine Static Typing - Coming soon - gperl will assemble these brand new modules...