building ruby in smalltalk

37
Building Ruby in Smalltalk Martin McClure ESUG 2009

Upload: esug

Post on 28-Jun-2015

623 views

Category:

Technology


3 download

DESCRIPTION

Martin McClure: Building Ruby in Smalltalk. ESUG 2010, Barcelona, Spain

TRANSCRIPT

Page 1: Building Ruby in Smalltalk

Building Ruby in

SmalltalkMartin McClureESUG 2009

Page 2: Building Ruby in Smalltalk
Page 3: Building Ruby in Smalltalk

Why?

Page 4: Building Ruby in Smalltalk

Page 5: Building Ruby in Smalltalk

...and more

Page 6: Building Ruby in Smalltalk

GemStonefor

Really Smart Dummies

Page 7: Building Ruby in Smalltalk

GemStone/S

● Smalltalk Implementation● Headless● Shared transactional persistence

– Shared “image”– Commit merges concurrent changes– Large

● Thousands of concurrent VMs● Terabyte scale

– Fast● 10K commits/sec

Page 8: Building Ruby in Smalltalk

GemStone/S

It'sJust

Smalltalk

Page 9: Building Ruby in Smalltalk
Page 10: Building Ruby in Smalltalk

The Big Choice

Page 11: Building Ruby in Smalltalk

Challenge 1:The Compiler

Page 12: Building Ruby in Smalltalk

Smalltalk Grammar

Page 13: Building Ruby in Smalltalk

Ruby Grammar

Page 14: Building Ruby in Smalltalk

Ruby 1.8.6 parse.y

Page 15: Building Ruby in Smalltalk

Ruby 1.8.6 parse.y

Page 16: Building Ruby in Smalltalk

Cheat

Page 17: Building Ruby in Smalltalk
Page 18: Building Ruby in Smalltalk
Page 19: Building Ruby in Smalltalk

Challenge 2:Arity

Page 20: Building Ruby in Smalltalk

Arity Challenges

● Number of message send arguments and method definition parameters may be different.

● '*' Argument and parameter – Array expansion for variable arity

● '&' block passing● Smalltalk VM expects sender and receiver arity

to always be fixed and to match

Page 21: Building Ruby in Smalltalk

Cheat

Page 22: Building Ruby in Smalltalk

Synthetic 'Bridge' Methods

● def foo(a,*b) …end

● Compiles: foo, foo*, foo&, foo*&, foo:, foo:*, foo:&, foo:*&foo::, foo::*, foo::&, foo::*&foo:::, foo:::*, foo:::&, foo:::*&

Page 23: Building Ruby in Smalltalk

Synthetic 'Bridge' Methods

● some_object.foo(a,b,*c)compiles a send to selector foo::*

● Bridge method foo::* adapts number of arguments and resends to actual foo variant

Page 24: Building Ruby in Smalltalk

Challenge 3:Coexistenceof Ruby and

Smalltalk

Page 25: Building Ruby in Smalltalk

ImmediateClasses

Page 26: Building Ruby in Smalltalk

NotCheat

Page 27: Building Ruby in Smalltalk

Environment-specific behavior

● Method dictionary per class per environment● Each send site specifies an environment● Complicates full method lookup● Does not affect send-site caches

Page 28: Building Ruby in Smalltalk

Challenge 4:Per-instance

Behavior

Page 29: Building Ruby in Smalltalk

Challenge 5:Per-instance

Variables

Page 30: Building Ruby in Smalltalk

In Ruby, an instance variable

is created by the act of assigning to it.

Page 31: Building Ruby in Smalltalk

Possible instvars are hard to find

class MyExampledef initialize(someValue)

@my_instvar = someValueend

end…class MyExample

def setAlpha(newAlpha)@alpha = newAlpha

endend

Page 32: Building Ruby in Smalltalk

Core Tests Passed Over Time

Page 33: Building Ruby in Smalltalk

Did we make the

right choice?

Page 34: Building Ruby in Smalltalk

YesWeDid

Page 35: Building Ruby in Smalltalk

Cheat

Page 36: Building Ruby in Smalltalk

Not cheating

at all,really

Page 37: Building Ruby in Smalltalk

ThankYou

Questions?