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