Truby
-
Upload
daisuke-watanabe -
Category
Documents
-
view
272 -
download
8
Transcript of Truby
Design and Implementation of Tiby
Presenter: Daisuke Watanabe
Affiliation: System software lab.
2
Background(1)
Ruby– Object-Oriented script language – Simple grammar – Dynamic typing
slow speed
easy programming
Class A def add (a, b) c = a + b return c endend
Rubywithout types
without types ・ Needs type check
Implementation of TRuby for making Ruby faster
・ programming without types
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
4
TRuby Assembly Language Byte code
Purpose
Execution of Typeable Ruby (TRuby)
TRuby Tiby
Subset of TRuby
Assembly Language Byte code
Type inference Translate
5
TRuby Assembly Language Byte code
Purpose
Execution of Typeable Ruby (TRuby)
TRuby Tiby
Subset of TRuby
Assembly Language Byte code
Type inference TranslateDesign and Implementation of Tiby
6
Outline
Dynamic typing & Static typing TRuby Tiby Implementation Evaluation Conclusion
7
Outline
Dynamic typing & Static typing TRuby Tiby Implementation Evaluation Conclusion
8
Dynamic typing & Static typing
int add (int a, int b){ int c; c = a + b; return c;}
def add (a, b) c = a + b return cend
Ruby ( Dynamic typing ) Java ( Static typing )
•Programming without types
•Needs type check
•Programming with types
•Doesn’t need type check Slow speed
Easy programming
Fast speed
TRuby is static typing language like Ruby
9
Outline
Dynamic typing & Static typing TRuby Tiby Implementation Evaluation Conclusion
10
TRuby
Features – Static typing language – Grammar like Ruby – Uses type inference
Goals – Makes execution time faster – Keeps easy programming
11
Comparing Ruby with TRuby
class Hoge def add(a , b ) return a+b end end var = Hoge.new var.add(1,2)
class Hoge def add(a:Int, b:Int):Int return a+b end end var:Hoge = Hoge.new var.add(1,2)
Ruby + type Ruby TRuby
12
Type inference
Infers the type from the context
1: a :Int = 1 2: b = 3 3: c = a + b
TRubyVar Type
a b c
Int
Int
Int
13
TRuby with type inference
class Hoge def add(a , b ) return a+b end end var = Hoge.new var.add(1,2)
class Hoge def add(a:Int, b:Int):Int return a+b end end var:Hoge = Hoge.new var.add(1,2)
Ruby + type Ruby TRuby
Type inference
14
Execution of TRuby
TRuby Tiby Jasmin Java byte code
Translates TRuby into Tiby – Type inference – Erasing syntax sugar
1 + 2 1.+(2)
Syntax sugar
TRuby
1.+(2)
Tiby
15
Outline
Dynamic typing & Static typing TRuby Tiby Implementation Evaluation Conclusion
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”)
17
Tiby Features
– Describes variables and define methods with types
– Uses four arithmetic and comparison operations by method calls
a = 100
def foo(a) a + 1
end
a :Int = 100
def foo(a :Int) :Int
a.+( 1 )end
TRuby
Tiby
18
Tiby Features
– Describes function calls by method calls
def foo(a) a + 1
end
def foo(a :Int) :Int
a.+( 1 )end
foo( 2 ) self.foo( 2 )
TRuby
Tiby
19
Tiby Features
– Only “if” and “else” (Doesn’t use “elsif”)
TRuby
Tibyif a < 3
1elsif a >3
4else
3 end
if a.<(3) then1
else
4else
3 end
if a.>(3) then
end
20
Outline
Dynamic typing & Static typing TRuby Tiby Implementation Evaluation Conclusion
21
Implementation
TRuby Tiby Jasmin Java byte code
22
Implementation
TRuby Tiby Jasmin Java byte code
Jasmin Tiby
Implementing compiler
Compiler
Tree
23
Compiler
Converts Tiby to Tree
Tiby
a :Int = 10
a.+(1)
stmt
assign:a
10
virtual_call:plus(Int)Int
Var a 1
Tree
24
CompilerGenerates Jasmin codes by tracing the tree
stmt
assign:a
10
virtual_call:plus(Int)Int
Var a 1
Tree Jasmin
25
Compiler
stmt
assign:a
10 Var a 1
new Intdupbipush 10invokespecial Int/<init>(I)V
virtual_call:plus(Int)Int
Generate Int object
Generates Jasmin codes by tracing the tree
Tree Jasmin
26
Compiler
stmt
assign:a
10 Var a 1
new Intdupbipush 10invokespecial Int/<init>(I)Vastore 1
virtual_call:plus(Int)Int
Assignment
Generate Jasmin code by tracing the tree
Tree Jasmin
27
Compiler
stmt
assign:a
10 Var a 1
new Intdupbipush 10invokespecial Int/<init>(I)Vastore 1
virtual_call:plus(Int)Int
Generate Jasmin code by tracing the tree
Tree Jasmin
28
Compiler
stmt
assign:a
10 Var a 1
new Intdupbipush 10invokespecial Int/<init>(I)Vastore 1aload 1
virtual_call:plus(Int)Int
Call operation
Generates Jasmin codes by tracing the tree
Tree Jasmin
29
Compiler
stmt
assign:a
10 Var a 1
new Intdupbipush 10invokespecial Int/<init>(I)Vastore 1aload 1new Intdupbipush 1invokespecial Int/<init>(I)V
virtual_call:plus(Int)Int
Generates Jasmin codes by tracing the tree
Tree Jasmin
30
Compiler
stmt
assign:a
10 Var a 1
new Intdupbipush 10invokespecial Int/<init>(I)Vastore 1aload 1new Intdupbipush 1invokespecial Int/<init>(I)V
invokevirtual Int/plus (Int) Int
virtual_call:plus(Int)Int
Method call
Generates Jasmin codes by tracing the tree
Tree Jasmin
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
32
Outline
Dynamic typing & Static typing TRuby Tiby Implementation Evaluation Conclusion
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
OS
Core2duo 2.33GHz
Linux Kernel 2.6.31-15-generic
Memory 2GB
Java
JavaVM
version 1.6.0_0
version 14.0-b16
JRuby version 1.4.0Ruby version 1.9.1p378
34
Result – micro benchmark
0%
20%
40%
60%
80%
100%
120%
tak fib ack
Rel
ativ
e ra
tio
of e
xecu
tion
tim
e
J RubyRubyTibyJ ava
JRuby average time: - 73%
Ruby average time : - 44%
35
Evaluation – AO benchmark
Calculates floating points for rendering Outputs a picture as the result
TibyRuby
36
Result – AO benchmark
0%
20%
40%
60%
80%
100%
120%
140%
160%
180%
200%
J Ruby Ruby Tiby J ava
Rel
ativ
e ra
tio
of e
xecu
tion
tim
e
37
Outline
dynamic typing & static typing TRuby Tiby Implementation Evaluation Conclusion
38
Conclusion
Purpose – Design and Implementation of Tiby
Result– Executed Medium-scale benchmark – Improved execution time
future tasks – Further implementation– Implement optimizations