Truby

38
Design and Implementation of Tiby Presenter: Daisuke Watanabe Affiliation: System software lab.

Transcript of Truby

Page 1: Truby

Design and Implementation of Tiby

Presenter: Daisuke Watanabe

Affiliation: System software lab.

Page 2: Truby

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

Page 3: Truby

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

Page 4: Truby

4

TRuby Assembly Language Byte code

Purpose

Execution of Typeable Ruby (TRuby)

TRuby Tiby

Subset of TRuby

Assembly Language Byte code

Type inference Translate

Page 5: Truby

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

Page 6: Truby

6

Outline

Dynamic typing & Static typing TRuby Tiby Implementation Evaluation Conclusion

Page 7: Truby

7

Outline

Dynamic typing & Static typing TRuby Tiby Implementation Evaluation Conclusion

Page 8: Truby

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

Page 9: Truby

9

Outline

Dynamic typing & Static typing TRuby Tiby Implementation Evaluation Conclusion

Page 10: Truby

10

TRuby

Features – Static typing language – Grammar like Ruby – Uses type inference

Goals – Makes execution time faster – Keeps easy programming

Page 11: Truby

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

Page 12: 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

Page 13: Truby

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

Page 14: Truby

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

Page 15: Truby

15

Outline

Dynamic typing & Static typing TRuby Tiby Implementation Evaluation Conclusion

Page 16: Truby

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

Page 17: Truby

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

Page 18: Truby

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

Page 19: Truby

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

Page 20: Truby

20

Outline

Dynamic typing & Static typing TRuby Tiby Implementation Evaluation Conclusion

Page 21: Truby

21

Implementation

TRuby Tiby Jasmin Java byte code

Page 22: Truby

22

Implementation

TRuby Tiby Jasmin Java byte code

Jasmin Tiby

Implementing compiler

Compiler

Tree

Page 23: Truby

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

Page 24: Truby

24

CompilerGenerates Jasmin codes by tracing the tree

stmt

assign:a

10

virtual_call:plus(Int)Int

Var a 1

Tree Jasmin

Page 25: Truby

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

Page 26: Truby

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

Page 27: Truby

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

Page 28: Truby

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

Page 29: Truby

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

Page 30: Truby

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

Page 31: Truby

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

Page 32: Truby

32

Outline

Dynamic typing & Static typing TRuby Tiby Implementation Evaluation Conclusion

Page 33: Truby

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

Page 34: Truby

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%

Page 35: Truby

35

Evaluation – AO benchmark

Calculates floating points for rendering Outputs a picture as the result

TibyRuby

Page 36: Truby

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

Page 37: Truby

37

Outline

dynamic typing & static typing TRuby Tiby Implementation Evaluation Conclusion

Page 38: Truby

38

Conclusion

Purpose – Design and Implementation of Tiby

Result– Executed Medium-scale benchmark – Improved execution time

future tasks – Further implementation– Implement optimizations