SlideShare a Scribd company logo
1 of 38
Design and Implementation
of Tiby


 Presenter: Daisuke Watanabe
 Affiliation: System software lab.
Background(1)

Ruby
  – Object-Oriented script language  
  – Simple grammar             Ruby
  – Dynamic typing                        without types
                              Class A
                               def add (a, b)
  ・ programming
       without types              c=a+b
 easy programming                 return c
  ・ Needs type check
                               end
                            end            without types
 slow speed
Implementation of TRuby for making Ruby faster

                                                           2
Background(2)

Typeable Ruby (TRuby)
  – Static typing language like Ruby
     Doesn’t need type check
             fast speed

  – Uses Type inference
     programming without types
           easy programming




                                       3
Purpose

Execution of Typeable Ruby (TRuby)
                  Assembly
    TRuby         Language
                              Byte code


 Type inference       Translate


                         Subset of TRuby

                        Assembly
TRuby        Tiby       Language
                                     Byte code

                                                 4
Purpose

 Execution of Typeable Ruby (TRuby)
                   Assembly
     TRuby         Language
                               Byte code

Design and Implementation of Tiby
  Type inference       Translate


                          Subset of TRuby

                         Assembly
TRuby         Tiby       Language
                                      Byte code

                                                  5
Outline
 Dynamic   typing & Static typing
 TRuby
 Tiby
 Implementation
 Evaluation
 Conclusion




                                     6
Outline
 Dynamic   typing & Static typing
 TRuby
 Tiby
 Implementation
 Evaluation
 Conclusion




                                     7
Dynamic typing & Static typing
Ruby ( Dynamic typing )   Java ( Static typing )
                           int add (int a, int b){
 def add (a, b)
                              int c;
    c=a+b
                              c = a + b;
    return c
                              return c;
 end
                           }

   TRuby is without types •Programming with types
 •Programmingstatic typing language like Ruby
 •Needs type check          •Doesn’t need type check
     Slow speed               Fast speed
     Easy
     programming
                                                       8
Outline
 Dynamic   typing & Static typing
 TRuby
 Tiby
 Implementation
 Evaluation
 Conclusion




                                     9
TRuby

   Features
    – Static typing language
    – Grammar like Ruby
    – Uses type inference
   Goals
    – Makes execution time faster
    – Keeps easy programming


                                    10
Comparing Ruby with TRuby
                                           Ruby + type
Ruby                   TRuby
class Hoge             class Hoge
     def add(a , b )        def add(a:Int, b:Int):Int
         return a+b             return a+b
     end                    end
end                    end
var = Hoge.new         var:Hoge = Hoge.new
var.add(1,2)           var.add(1,2)




                                                         11
Type inference

     Infers the type from the context
TRuby
                         Var      Type
1: a :Int = 1             a       Int
2: b = 3
3: c = a + b              b       Int
                          c       Int


                                         12
TRuby with type inference
                                             Ruby + type
Ruby                     TRuby
class Hoge               class Hoge
     def add(a , b )          def add(a:Int, b:Int):Int
         return a+b               return a+b
     end                      end
end                      end
var = Hoge.new           var:Hoge = Hoge.new
var.add(1,2)             var.add(1,2)



                Type inference
                                                           13
Execution of TRuby
                                      Java
TRuby          Tiby        Jasmin   byte code


 Translates   TRuby into Tiby
  – Type inference
  – Erasing syntax sugar
        TRuby               Tiby
        1.+(2)
                           1.+(2)
         1+2
     Syntax sugar                               14
Outline
 Dynamic   typing & Static typing
 TRuby
 Tiby
 Implementation
 Evaluation
 Conclusion




                                     15
Tiby
 Features
  – Describes variables and define methods with types
  – Uses four arithmetic and comparison operations by
    method calls
  – Describes function calls by method calls
  – Only “if” and “else” (Does’t use “elsif”)




                                                        16
Tiby
 Features
  – Describes variables and define methods with types
  – Uses four arithmetic and comparison operations by
    method calls

       TRuby                               Tiby
      a = 100                       a :Int = 100

      def foo(a)                    def foo(a :Int) :Int
        a+1                           a.+( 1 )
      end                           end


                                                           17
Tiby
 Features
  – Describes function calls by method calls




        TRuby                               Tiby
      def foo(a)                     def foo(a :Int) :Int
        a+1                            a.+( 1 )
      end                            end
      foo( 2 )                       self.foo( 2 )


                                                            18
Tiby
 Features
  – Only “if” and “else” (Doesn’t use “elsif”)




         TRuby                                   Tiby
      if a < 3                           if a.<(3) then
         1                                  1
      elsif a >3                         else
         4                                  if a.>(3) then
      else                                     4
         3                                  else
      end                                      3
                                            end
                                         end
                                                             19
Outline
 Dynamic   typing & Static typing
 TRuby
 Tiby
 Implementation
 Evaluation
 Conclusion




                                     20
Implementation
                                Java
TRuby     Tiby       Jasmin   byte code




                                          21
Implementation
                                           Java
TRuby         Tiby           Jasmin      byte code

           Implementing compiler

                     Compiler

    Tiby              Tree            Jasmin




                                                     22
Compiler
              Converts Tiby to Tree

                               Tree
   Tiby
                             stmt
a :Int = 10
a.+(1)
                  assign:a    virtual_call:plus(Int)Int



                     10       Var a              1

                                                          23
Compiler
       Generates Jasmin codes by tracing the tree


                Tree                    Jasmin

             stmt



assign:a    virtual_call:plus(Int)Int


  10         Var a            1

                                                    24
Compiler
       Generates Jasmin codes by tracing the tree


                Tree                             Jasmin
                                        new Int
                                        dup       Generate Int object
             stmt
                                        bipush 10
                                        invokespecial Int/<init>(I)V



assign:a    virtual_call:plus(Int)Int


  10         Var a            1

                                                                   25
Compiler
       Generate Jasmin code by tracing the tree


                Tree                              Jasmin
                                        new Int
             stmt                       dup
                                        bipush 10
                                        invokespecial Int/<init>(I)V
                                        astore 1 Assignment

assign:a    virtual_call:plus(Int)Int


  10         Var a            1

                                                                       26
Compiler
       Generate Jasmin code by tracing the tree


                Tree                              Jasmin
                                        new Int
             stmt                       dup
                                        bipush 10
                                        invokespecial Int/<init>(I)V
                                        astore 1

assign:a    virtual_call:plus(Int)Int


  10         Var a            1

                                                                       27
Compiler
       Generates Jasmin codes by tracing the tree


                Tree                              Jasmin
                                        new Int
             stmt                       dup
                                        bipush 10
                                        invokespecial Int/<init>(I)V
                                        astore 1
                                        aload 1 Call operation
assign:a    virtual_call:plus(Int)Int


  10         Var a            1

                                                                       28
Compiler
       Generates Jasmin codes by tracing the tree


                Tree                              Jasmin
                                        new Int
             stmt                       dup
                                        bipush 10
                                        invokespecial Int/<init>(I)V
                                        astore 1
                                        aload 1
                                        new Int
assign:a    virtual_call:plus(Int)Int   dup
                                        bipush 1
                                        invokespecial Int/<init>(I)V

  10         Var a            1

                                                                       29
Compiler
       Generates Jasmin codes by tracing the tree


                Tree                               Jasmin
                                        new Int
             stmt                       dup
                                        bipush 10
                                        invokespecial Int/<init>(I)V
                                        astore 1
                                        aload 1
                                        new Int
assign:a    virtual_call:plus(Int)Int   dup
                                        bipush 1
                                        invokespecial Int/<init>(I)V
                                        invokevirtual Int/plus (Int) Int
  10         Var a            1                       Method call

                                                                           30
Progress in implementation
Implemented processing
  –   Four arithmetic and comparison operations
  –   Handling of the variable
  –   Definition & call classes
  –   Definition & call methods
  –   Array (bound type)
  –   If and while statements
  –   Mix-in
  –   Inheritance




                                                  31
Outline
 Dynamic   typing & Static typing
 TRuby
 Tiby
 Implementation
 Evaluation
 Conclusion




                                     32
Evaluation
 Method
  – Comparing with JRuby and Ruby1.9 , Java
     ( JRuby - Dynamic typing , Run on JVM )
  – micro benchmark :fib , tak , ack
  – medium-scale benchmark: AO benchmark
 Environment
   CPU       Core2duo 2.33GHz
   Memory    2GB
   OS        Linux Kernel 2.6.31-15-generic
   Java      version 1.6.0_0
   JavaVM    version 14.0-b16
   Ruby      version 1.9.1p378
   JRuby     version 1.4.0
                                               33
Result – micro benchmark
                                                  1 20%     JRuby average time: - 73%
                                                            Ruby average time : - 44%
Re la t ive ra t io o f e x e c u t io n t im e




                                                  1 00%


                                                   80%
                                                                                               J Ru by
                                                   60%                                         Ru by
                                                                                               Tiby
                                                   40%
                                                                                               J a va
                                                   20%


                                                    0%
                                                             tak          f ib          ac k


                                                                                                         34
Evaluation – AO benchmark

 Calculates floating points for rendering
 Outputs a picture as the result




        Ruby                       Tiby

                                             35
Result – AO benchmark

                                                  200%
Re la t ive ra t io o f e x e c u t io n t im e




                                                  1 80%
                                                  1 60%
                                                  1 40%
                                                  1 20%
                                                  1 00%
                                                   80%
                                                   60%
                                                   40%
                                                   20%
                                                    0%
                                                           J Ru b y   Ru b y   Tib y   J ava

                                                                                               36
Outline
 dynamic   typing & static typing
 TRuby
 Tiby
 Implementation
 Evaluation
 Conclusion




                                     37
Conclusion

 Purpose
  – Design and Implementation of Tiby
 Result
  – Executed Medium-scale benchmark
  – Improved execution time
 future   tasks
  – Further implementation
  – Implement optimizations



                                        38

More Related Content

What's hot

Lifting The Veil - Reading Java Bytecode During Lunchtime
Lifting The Veil - Reading Java Bytecode During LunchtimeLifting The Veil - Reading Java Bytecode During Lunchtime
Lifting The Veil - Reading Java Bytecode During LunchtimeAlexander Shopov
 
Lifting The Veil - Reading Java Bytecode
Lifting The Veil - Reading Java BytecodeLifting The Veil - Reading Java Bytecode
Lifting The Veil - Reading Java BytecodeAlexander Shopov
 
C interview question answer 1
C interview question answer 1C interview question answer 1
C interview question answer 1Amit Kapoor
 
New c sharp4_features_part_iv
New c sharp4_features_part_ivNew c sharp4_features_part_iv
New c sharp4_features_part_ivNico Ludwig
 
Does Java Have a Future After Version 8? (Belfast JUG April 2014)
Does Java Have a Future After Version 8? (Belfast JUG April 2014)Does Java Have a Future After Version 8? (Belfast JUG April 2014)
Does Java Have a Future After Version 8? (Belfast JUG April 2014)Garth Gilmour
 
I Know Kung Fu - Juggling Java Bytecode
I Know Kung Fu - Juggling Java BytecodeI Know Kung Fu - Juggling Java Bytecode
I Know Kung Fu - Juggling Java BytecodeAlexander Shopov
 
The Rise of Dynamic Languages
The Rise of Dynamic LanguagesThe Rise of Dynamic Languages
The Rise of Dynamic Languagesgreenwop
 
Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3Chariza Pladin
 
Formal methods 1 - introduction
Formal methods   1 - introductionFormal methods   1 - introduction
Formal methods 1 - introductionVlad Patryshev
 
Refactoring Edit History of Source Code
Refactoring Edit History of Source CodeRefactoring Edit History of Source Code
Refactoring Edit History of Source CodeShinpei Hayashi
 
JIT compilation for CPython
JIT compilation for CPythonJIT compilation for CPython
JIT compilation for CPythondelimitry
 

What's hot (15)

Lifting The Veil - Reading Java Bytecode During Lunchtime
Lifting The Veil - Reading Java Bytecode During LunchtimeLifting The Veil - Reading Java Bytecode During Lunchtime
Lifting The Veil - Reading Java Bytecode During Lunchtime
 
Lifting The Veil - Reading Java Bytecode
Lifting The Veil - Reading Java BytecodeLifting The Veil - Reading Java Bytecode
Lifting The Veil - Reading Java Bytecode
 
C interview question answer 1
C interview question answer 1C interview question answer 1
C interview question answer 1
 
Ruby Hell Yeah
Ruby Hell YeahRuby Hell Yeah
Ruby Hell Yeah
 
New c sharp4_features_part_iv
New c sharp4_features_part_ivNew c sharp4_features_part_iv
New c sharp4_features_part_iv
 
Does Java Have a Future After Version 8? (Belfast JUG April 2014)
Does Java Have a Future After Version 8? (Belfast JUG April 2014)Does Java Have a Future After Version 8? (Belfast JUG April 2014)
Does Java Have a Future After Version 8? (Belfast JUG April 2014)
 
I Know Kung Fu - Juggling Java Bytecode
I Know Kung Fu - Juggling Java BytecodeI Know Kung Fu - Juggling Java Bytecode
I Know Kung Fu - Juggling Java Bytecode
 
The Rise of Dynamic Languages
The Rise of Dynamic LanguagesThe Rise of Dynamic Languages
The Rise of Dynamic Languages
 
Intervies
InterviesIntervies
Intervies
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3
 
Formal methods 1 - introduction
Formal methods   1 - introductionFormal methods   1 - introduction
Formal methods 1 - introduction
 
Modular Pick and Place Simulator using ROS Framework
Modular Pick and Place Simulator using ROS FrameworkModular Pick and Place Simulator using ROS Framework
Modular Pick and Place Simulator using ROS Framework
 
Refactoring Edit History of Source Code
Refactoring Edit History of Source CodeRefactoring Edit History of Source Code
Refactoring Edit History of Source Code
 
JIT compilation for CPython
JIT compilation for CPythonJIT compilation for CPython
JIT compilation for CPython
 

Viewers also liked

Guidelines notetaking
Guidelines notetakingGuidelines notetaking
Guidelines notetakingligo178
 
Social Engineering: Frames and Frame Control
Social Engineering: Frames and Frame ControlSocial Engineering: Frames and Frame Control
Social Engineering: Frames and Frame ControlSocial Exploits
 
Using the dictionary
Using the dictionaryUsing the dictionary
Using the dictionaryligo178
 
iOS UX by iMakeit4U
iOS UX by iMakeit4UiOS UX by iMakeit4U
iOS UX by iMakeit4UiMakeit4U
 
Guidelines for Beginning Your Thesis Paper
Guidelines for Beginning Your Thesis PaperGuidelines for Beginning Your Thesis Paper
Guidelines for Beginning Your Thesis Paperligo178
 
STIHL Southeast Direct Mail
STIHL Southeast Direct MailSTIHL Southeast Direct Mail
STIHL Southeast Direct MailOJ Graczyk
 
Guidelines Note taking
Guidelines Note takingGuidelines Note taking
Guidelines Note takingligo178
 
Reducing Noisy Nagios Alerts
Reducing Noisy Nagios AlertsReducing Noisy Nagios Alerts
Reducing Noisy Nagios AlertsTakumi Sakamoto
 
Handleiding SNS Mobiel Bankieren app
Handleiding SNS Mobiel Bankieren appHandleiding SNS Mobiel Bankieren app
Handleiding SNS Mobiel Bankieren appSNS Bank
 
Demo SNS Saldochecker (voor iPhone)
Demo SNS Saldochecker (voor iPhone)Demo SNS Saldochecker (voor iPhone)
Demo SNS Saldochecker (voor iPhone)SNS Bank
 
Library orientation bayshore
Library orientation bayshoreLibrary orientation bayshore
Library orientation bayshoreligo178
 
Handleiding SNS Mobiel Bankieren app (juni 2014)
Handleiding SNS Mobiel Bankieren app (juni 2014)Handleiding SNS Mobiel Bankieren app (juni 2014)
Handleiding SNS Mobiel Bankieren app (juni 2014)SNS Bank
 
現場のコード意識を変えるために導入したリーダブルコードとガウディの思想 - DevLove甲子園2014技 -
現場のコード意識を変えるために導入したリーダブルコードとガウディの思想 - DevLove甲子園2014技 -現場のコード意識を変えるために導入したリーダブルコードとガウディの思想 - DevLove甲子園2014技 -
現場のコード意識を変えるために導入したリーダブルコードとガウディの思想 - DevLove甲子園2014技 -Daisuke Watanabe
 
презентация камерун
презентация камерунпрезентация камерун
презентация камерунheilssarmee
 
Demo SNS Mobiel Bankieren (website)
Demo SNS Mobiel Bankieren (website)Demo SNS Mobiel Bankieren (website)
Demo SNS Mobiel Bankieren (website)SNS Bank
 

Viewers also liked (17)

Presentazione musella non vi dice ver b
Presentazione musella non vi dice ver bPresentazione musella non vi dice ver b
Presentazione musella non vi dice ver b
 
Guidelines notetaking
Guidelines notetakingGuidelines notetaking
Guidelines notetaking
 
Social Engineering: Frames and Frame Control
Social Engineering: Frames and Frame ControlSocial Engineering: Frames and Frame Control
Social Engineering: Frames and Frame Control
 
Using the dictionary
Using the dictionaryUsing the dictionary
Using the dictionary
 
Juzu framework
Juzu frameworkJuzu framework
Juzu framework
 
iOS UX by iMakeit4U
iOS UX by iMakeit4UiOS UX by iMakeit4U
iOS UX by iMakeit4U
 
Guidelines for Beginning Your Thesis Paper
Guidelines for Beginning Your Thesis PaperGuidelines for Beginning Your Thesis Paper
Guidelines for Beginning Your Thesis Paper
 
STIHL Southeast Direct Mail
STIHL Southeast Direct MailSTIHL Southeast Direct Mail
STIHL Southeast Direct Mail
 
Guidelines Note taking
Guidelines Note takingGuidelines Note taking
Guidelines Note taking
 
Reducing Noisy Nagios Alerts
Reducing Noisy Nagios AlertsReducing Noisy Nagios Alerts
Reducing Noisy Nagios Alerts
 
Handleiding SNS Mobiel Bankieren app
Handleiding SNS Mobiel Bankieren appHandleiding SNS Mobiel Bankieren app
Handleiding SNS Mobiel Bankieren app
 
Demo SNS Saldochecker (voor iPhone)
Demo SNS Saldochecker (voor iPhone)Demo SNS Saldochecker (voor iPhone)
Demo SNS Saldochecker (voor iPhone)
 
Library orientation bayshore
Library orientation bayshoreLibrary orientation bayshore
Library orientation bayshore
 
Handleiding SNS Mobiel Bankieren app (juni 2014)
Handleiding SNS Mobiel Bankieren app (juni 2014)Handleiding SNS Mobiel Bankieren app (juni 2014)
Handleiding SNS Mobiel Bankieren app (juni 2014)
 
現場のコード意識を変えるために導入したリーダブルコードとガウディの思想 - DevLove甲子園2014技 -
現場のコード意識を変えるために導入したリーダブルコードとガウディの思想 - DevLove甲子園2014技 -現場のコード意識を変えるために導入したリーダブルコードとガウディの思想 - DevLove甲子園2014技 -
現場のコード意識を変えるために導入したリーダブルコードとガウディの思想 - DevLove甲子園2014技 -
 
презентация камерун
презентация камерунпрезентация камерун
презентация камерун
 
Demo SNS Mobiel Bankieren (website)
Demo SNS Mobiel Bankieren (website)Demo SNS Mobiel Bankieren (website)
Demo SNS Mobiel Bankieren (website)
 

Similar to Truby

DZone%20-%20Essential%20Ruby
DZone%20-%20Essential%20RubyDZone%20-%20Essential%20Ruby
DZone%20-%20Essential%20Rubytutorialsruby
 
DZone%20-%20Essential%20Ruby
DZone%20-%20Essential%20RubyDZone%20-%20Essential%20Ruby
DZone%20-%20Essential%20Rubytutorialsruby
 
DTS s03e04 Typing
DTS s03e04 TypingDTS s03e04 Typing
DTS s03e04 TypingTuenti
 
A Static Type Analyzer of Untyped Ruby Code for Ruby 3
A Static Type Analyzer of Untyped Ruby Code for Ruby 3A Static Type Analyzer of Untyped Ruby Code for Ruby 3
A Static Type Analyzer of Untyped Ruby Code for Ruby 3mametter
 
Ruby tutorial
Ruby tutorialRuby tutorial
Ruby tutorialknoppix
 
Mypy pycon-fi-2012
Mypy pycon-fi-2012Mypy pycon-fi-2012
Mypy pycon-fi-2012jukkaleh
 
TypeProf for IDE: Enrich Development Experience without Annotations
TypeProf for IDE: Enrich Development Experience without AnnotationsTypeProf for IDE: Enrich Development Experience without Annotations
TypeProf for IDE: Enrich Development Experience without Annotationsmametter
 
Intro To Ror
Intro To RorIntro To Ror
Intro To Rormyuser
 
20140626 red dotrubyconf2014
20140626 red dotrubyconf201420140626 red dotrubyconf2014
20140626 red dotrubyconf2014Hiroshi SHIBATA
 
Type Profiler: Ambitious Type Inference for Ruby 3
Type Profiler: Ambitious Type Inference for Ruby 3Type Profiler: Ambitious Type Inference for Ruby 3
Type Profiler: Ambitious Type Inference for Ruby 3mametter
 
Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Jimmy Schementi
 

Similar to Truby (16)

DZone%20-%20Essential%20Ruby
DZone%20-%20Essential%20RubyDZone%20-%20Essential%20Ruby
DZone%20-%20Essential%20Ruby
 
DZone%20-%20Essential%20Ruby
DZone%20-%20Essential%20RubyDZone%20-%20Essential%20Ruby
DZone%20-%20Essential%20Ruby
 
DTS s03e04 Typing
DTS s03e04 TypingDTS s03e04 Typing
DTS s03e04 Typing
 
A Static Type Analyzer of Untyped Ruby Code for Ruby 3
A Static Type Analyzer of Untyped Ruby Code for Ruby 3A Static Type Analyzer of Untyped Ruby Code for Ruby 3
A Static Type Analyzer of Untyped Ruby Code for Ruby 3
 
F#3.0
F#3.0 F#3.0
F#3.0
 
Ruby tutorial
Ruby tutorialRuby tutorial
Ruby tutorial
 
Mypy pycon-fi-2012
Mypy pycon-fi-2012Mypy pycon-fi-2012
Mypy pycon-fi-2012
 
TypeProf for IDE: Enrich Development Experience without Annotations
TypeProf for IDE: Enrich Development Experience without AnnotationsTypeProf for IDE: Enrich Development Experience without Annotations
TypeProf for IDE: Enrich Development Experience without Annotations
 
Intro To Ror
Intro To RorIntro To Ror
Intro To Ror
 
Ruby
RubyRuby
Ruby
 
Ruby FFI
Ruby FFIRuby FFI
Ruby FFI
 
20140626 red dotrubyconf2014
20140626 red dotrubyconf201420140626 red dotrubyconf2014
20140626 red dotrubyconf2014
 
Ruby Chapter 2
Ruby Chapter 2Ruby Chapter 2
Ruby Chapter 2
 
Metaprogramming in Ruby
Metaprogramming in RubyMetaprogramming in Ruby
Metaprogramming in Ruby
 
Type Profiler: Ambitious Type Inference for Ruby 3
Type Profiler: Ambitious Type Inference for Ruby 3Type Profiler: Ambitious Type Inference for Ruby 3
Type Profiler: Ambitious Type Inference for Ruby 3
 
Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011
 

Truby

  • 1. Design and Implementation of Tiby Presenter: Daisuke Watanabe Affiliation: System software lab.
  • 2. Background(1) Ruby – Object-Oriented script language   – Simple grammar   Ruby – Dynamic typing without types Class A def add (a, b) ・ programming without types c=a+b easy programming return c ・ Needs type check end end without types slow speed Implementation of TRuby for making Ruby faster 2
  • 3. Background(2) Typeable Ruby (TRuby) – Static typing language like Ruby Doesn’t need type check fast speed – Uses Type inference programming without types easy programming 3
  • 4. Purpose Execution of Typeable Ruby (TRuby) Assembly TRuby Language Byte code Type inference Translate Subset of TRuby Assembly TRuby Tiby Language Byte code 4
  • 5. Purpose Execution of Typeable Ruby (TRuby) Assembly TRuby Language Byte code Design and Implementation of Tiby Type inference Translate Subset of TRuby Assembly TRuby Tiby Language Byte code 5
  • 6. Outline  Dynamic typing & Static typing  TRuby  Tiby  Implementation  Evaluation  Conclusion 6
  • 7. Outline  Dynamic typing & Static typing  TRuby  Tiby  Implementation  Evaluation  Conclusion 7
  • 8. Dynamic typing & Static typing Ruby ( Dynamic typing ) Java ( Static typing ) int add (int a, int b){ def add (a, b) int c; c=a+b c = a + b; return c return c; end } TRuby is without types •Programming with types •Programmingstatic typing language like Ruby •Needs type check •Doesn’t need type check Slow speed Fast speed Easy programming 8
  • 9. Outline  Dynamic typing & Static typing  TRuby  Tiby  Implementation  Evaluation  Conclusion 9
  • 10. TRuby  Features – Static typing language – Grammar like Ruby – Uses type inference  Goals – Makes execution time faster – Keeps easy programming 10
  • 11. Comparing Ruby with TRuby Ruby + type Ruby TRuby class Hoge class Hoge def add(a , b ) def add(a:Int, b:Int):Int return a+b return a+b end end end end var = Hoge.new var:Hoge = Hoge.new var.add(1,2) var.add(1,2) 11
  • 12. Type inference Infers the type from the context TRuby Var Type 1: a :Int = 1 a Int 2: b = 3 3: c = a + b b Int c Int 12
  • 13. TRuby with type inference Ruby + type Ruby TRuby class Hoge class Hoge def add(a , b ) def add(a:Int, b:Int):Int return a+b return a+b end end end end var = Hoge.new var:Hoge = Hoge.new var.add(1,2) var.add(1,2) Type inference 13
  • 14. Execution of TRuby Java TRuby Tiby Jasmin byte code  Translates TRuby into Tiby – Type inference – Erasing syntax sugar TRuby Tiby 1.+(2) 1.+(2) 1+2 Syntax sugar 14
  • 15. Outline  Dynamic typing & Static typing  TRuby  Tiby  Implementation  Evaluation  Conclusion 15
  • 16. Tiby  Features – Describes variables and define methods with types – Uses four arithmetic and comparison operations by method calls – Describes function calls by method calls – Only “if” and “else” (Does’t use “elsif”) 16
  • 17. Tiby  Features – Describes variables and define methods with types – Uses four arithmetic and comparison operations by method calls TRuby Tiby a = 100 a :Int = 100 def foo(a) def foo(a :Int) :Int a+1 a.+( 1 ) end end 17
  • 18. Tiby  Features – Describes function calls by method calls TRuby Tiby def foo(a) def foo(a :Int) :Int a+1 a.+( 1 ) end end foo( 2 ) self.foo( 2 ) 18
  • 19. Tiby  Features – Only “if” and “else” (Doesn’t use “elsif”) TRuby Tiby if a < 3 if a.<(3) then 1 1 elsif a >3 else 4 if a.>(3) then else 4 3 else end 3 end end 19
  • 20. Outline  Dynamic typing & Static typing  TRuby  Tiby  Implementation  Evaluation  Conclusion 20
  • 21. Implementation Java TRuby Tiby Jasmin byte code 21
  • 22. Implementation Java TRuby Tiby Jasmin byte code Implementing compiler Compiler Tiby Tree Jasmin 22
  • 23. Compiler Converts Tiby to Tree Tree Tiby stmt a :Int = 10 a.+(1) assign:a virtual_call:plus(Int)Int 10 Var a 1 23
  • 24. Compiler Generates Jasmin codes by tracing the tree Tree Jasmin stmt assign:a virtual_call:plus(Int)Int 10 Var a 1 24
  • 25. Compiler Generates Jasmin codes by tracing the tree Tree Jasmin new Int dup Generate Int object stmt bipush 10 invokespecial Int/<init>(I)V assign:a virtual_call:plus(Int)Int 10 Var a 1 25
  • 26. Compiler Generate Jasmin code by tracing the tree Tree Jasmin new Int stmt dup bipush 10 invokespecial Int/<init>(I)V astore 1 Assignment assign:a virtual_call:plus(Int)Int 10 Var a 1 26
  • 27. Compiler Generate Jasmin code by tracing the tree Tree Jasmin new Int stmt dup bipush 10 invokespecial Int/<init>(I)V astore 1 assign:a virtual_call:plus(Int)Int 10 Var a 1 27
  • 28. Compiler Generates Jasmin codes by tracing the tree Tree Jasmin new Int stmt dup bipush 10 invokespecial Int/<init>(I)V astore 1 aload 1 Call operation assign:a virtual_call:plus(Int)Int 10 Var a 1 28
  • 29. Compiler Generates Jasmin codes by tracing the tree Tree Jasmin new Int stmt dup bipush 10 invokespecial Int/<init>(I)V astore 1 aload 1 new Int assign:a virtual_call:plus(Int)Int dup bipush 1 invokespecial Int/<init>(I)V 10 Var a 1 29
  • 30. Compiler Generates Jasmin codes by tracing the tree Tree Jasmin new Int stmt dup bipush 10 invokespecial Int/<init>(I)V astore 1 aload 1 new Int assign:a virtual_call:plus(Int)Int dup bipush 1 invokespecial Int/<init>(I)V invokevirtual Int/plus (Int) Int 10 Var a 1 Method call 30
  • 31. Progress in implementation Implemented processing – Four arithmetic and comparison operations – Handling of the variable – Definition & call classes – Definition & call methods – Array (bound type) – If and while statements – Mix-in – Inheritance 31
  • 32. Outline  Dynamic typing & Static typing  TRuby  Tiby  Implementation  Evaluation  Conclusion 32
  • 33. Evaluation  Method – Comparing with JRuby and Ruby1.9 , Java ( JRuby - Dynamic typing , Run on JVM ) – micro benchmark :fib , tak , ack – medium-scale benchmark: AO benchmark  Environment CPU Core2duo 2.33GHz Memory 2GB OS Linux Kernel 2.6.31-15-generic Java version 1.6.0_0 JavaVM version 14.0-b16 Ruby version 1.9.1p378 JRuby version 1.4.0 33
  • 34. Result – micro benchmark 1 20% JRuby average time: - 73% Ruby average time : - 44% Re la t ive ra t io o f e x e c u t io n t im e 1 00% 80% J Ru by 60% Ru by Tiby 40% J a va 20% 0% tak f ib ac k 34
  • 35. Evaluation – AO benchmark  Calculates floating points for rendering  Outputs a picture as the result Ruby Tiby 35
  • 36. Result – AO benchmark 200% Re la t ive ra t io o f e x e c u t io n t im e 1 80% 1 60% 1 40% 1 20% 1 00% 80% 60% 40% 20% 0% J Ru b y Ru b y Tib y J ava 36
  • 37. Outline  dynamic typing & static typing  TRuby  Tiby  Implementation  Evaluation  Conclusion 37
  • 38. Conclusion  Purpose – Design and Implementation of Tiby  Result – Executed Medium-scale benchmark – Improved execution time  future tasks – Further implementation – Implement optimizations 38

Editor's Notes

  1. 近年、プログラミング言語 Ruby が注目されています。 Ruby on Rails などの web アプリケーションフレームワークなどの Ruby を用いた開発も注目されています。 この Ruby の特徴は この動的型付けを用いているため以下のような特徴を持ちます
  2. Typeable Ruby と言うのですが、 其の名のとおり Ruby に型をつけることが可能な言語として開発しています。
  3. 以前、 TRuby の実行はこのような形でしていました。 Truby からアセンブリ言語への変換で型推論と変換の両方を 行う形を取っていました。 しかし、型推論の仕様がまだ決まっていません なので、現在の状況で直接のコンパイラの実装は困難です。 そこで間に中間言語 Tiby を導入します。 Tiby は型推論を行いすべてに型がついている状態として 実装されます。 1 型推論が定まっていない 言語仕様がどんどん変わる そんな中では実装ができない
  4. 以前、 TRuby の実行はこのような形でしていました。 Truby からアセンブリ言語へのコンパイルで型推論と変換の両方を 行う形を取っていました。 しかし、型推論の仕様がまだ決まっていません なので、現在の状況でコンパイラの実装は困難です。 そこで間に中間言語 Tiby を導入します。 型推論の仕様が決まっていなくても、 変換部を作成することができます。 1 型推論が定まっていない 言語仕様がどんどん変わる そんな中では実装ができない
  5. 左動的片付け 右静的片付け 動的片づけを説明 静的片づけを説明 Ruby に静的片付けのように実行速度を早くできないか? ということで Ruby の実行速度を改善するために TRuby を作っている。
  6. Ruby ライクな静的片付け言語です 型推論を用いています 型推論については後ほど説明します。 Ruby の実行速度を改善すること Ruby のプログラミングのしやすさを維持すること の二つですね
  7. 左 Ruby 右 TRuby Ruby のプログラムの説明 Truby のプログラムの説明 違いの説明 インスタンス化するときにクラス名を記述する。 とか、メソッドの引数、返り値 しかし、このままでは Ruby のプログラミングのしやすさが失われてしまいます。 そこで、 Truby では型推論を用いています。 そのため、実は、 Truby でも左のコードを通すことができます。 次は、型推論がなんなのかと言うものを説明します。
  8. 1 行目は型推論を用いることなく Int 型ということがわかります 2 行目は型を記述していません。そこで型推論を用います。 型推論は右辺を解析します。 右辺が Int 型の3であるとわかります。 なので、 b は Int 型であると推論します。 つぎに …
  9. 左 Ruby 右 TRuby Ruby のプログラムの説明 Truby のプログラムの説明 違いの説明 インスタンス化するときにクラス名を記述する。 とか、メソッドの引数、返り値 しかし、このままでは Ruby のプログラミングのしやすさが失われてしまいます。 そこで、 Truby では型推論を用いています。 そのため、実は、 Truby でも左のコードを通すことができます。 次は、型推論がなんなのかと言うものを説明します。
  10. 方の決定には、主に型推論を使います 次に、シンタックスシュガーの削除です Truby では加算の記述が二つあります。 この二つです。 Truby では加算もメソッドとして扱います。 なので、本来の記述は上です。 でも、これじゃあ、加算が書きにくいですよね。 そこで、読み書きのしやすさのためにシンタックスシュガーとして、下を記述をできるように定義しています。 このようなものをシンタックスシュガーと呼びます。 しかし、 Tiby では文法をシンプルにするために、本来の記述しか許してません。 なので、変換の際にシンタックスシュガーを本来の記述に変換します。
  11. Tiby は Truby のサブセットです。 Truby の機能と書き方を限定した中間言語になります。 そのため、プログラミングする人は気にしなくてよい言語になります。 以下のような特徴を持ちます。 変数定義、メソッド定義には必ず型を記述 四則演算、比較演算はメソッド呼び出しとして扱う 関数呼び出しもメソッド呼び出しとして扱う If 文では if と else のみを扱う
  12. 左 TRuby  右 Tiby Truby は型推論を用いているとして型を記述しないものとしてプログラムを示します。
  13. まず、 Tiby のコードから木構造に変換するやりかたから説明します。 次のように変換します 上は a に変数を代入するノードです。 そのコードのに引数10のノードを作ります 次 メソッドのノードを作ります そして、子ノードにレシーバの a つぎの子ノードに引数の 1 のノード
  14. 木構造をたどって Jasmin のコードを生成します まず、左側のノードです これは a に代入のノードです。 まずは子ノードを処理します 子ノードは10・・・
  15. 実装状況ですね 四則と比較 変数の扱い クラス定義呼び出し メソッド定義呼び出し 配列しかし型は固定 制御文は if と while です Mix-in (モジュールとインクルード) 継承
  16. Tiby と Jruby 及び Ruby1.9 と比較します。 Jruby は Tiby と同じように Ruby のコードを JVM 上で動作させます。 違うところは Jruby は動的片づけを用いているところです
  17. 浮動小数点を計算しレンダリングをするベンチマークです レンダリングの結果として、図を出力します。 左が Ruby の実行結果 右が Tiby での実行結果 中規模のベンチマークを動かせるくらい実装できました。