Smalltalk on rubinius

1,111 views
985 views

Published on

Programming languages must be implemented in Java or C, everybody knows this. Sure, a prototype in Ruby, but that would be unusable. After all, Ruby is made for web development, right? Hard tasks, like implementing a compiler, have to happen in far more manly languages. But wait, the Rubinius compiler is written completely in Ruby, and it seems to get pretty decent performance, maybe we can use that.

In this talk, we will explore the possibilities of using the Rubinius compiler tool chain to implement our own programming language targeting the Rubinius VM. We get all the hard work that went into Rubinius for free and above all, can do the heavy lifting in Ruby, everyone's favorite programming language.

As an example we'll use Reak, a Smalltalk implementation running on Rubinius.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,111
On SlideShare
0
From Embeds
0
Number of Embeds
173
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Smalltalk on rubinius

  1. 1. Smalltalk On Rubinius Konstantin Haase
  2. 2. Why implementSmalltalk on Rubinius?
  3. 3. Why create aprogramming language?
  4. 4. Why create?
  5. 5. "When you dont create things, you becomedefined by your tastes rather than ability. Your tastes only narrow and exclude people. So create." why the lucky stiff
  6. 6. Why a programming language?
  7. 7. About programming languages:"I don’t like any of them, and I don’t think any of them are suitable for the real programming problems of today, whether for systems or for end-users" Alan Kay
  8. 8. Problem OrientedProgramming LanguagesCairo (~120k SLOC in C) rewritten in less than 400 lines
  9. 9. Why Smalltalk?
  10. 10. Why Rubinius?
  11. 11. 1 + 11 + 1
  12. 12. this is itthis.is.it
  13. 13. GoGaRuCo rock: #hardGoGaRuCo.rock :hard
  14. 14. doc convertFrom: #xml to: #yamldoc.convert(:xml, :ruby)
  15. 15. doc convertFrom: #xml to: #yamldoc.convert from: :xml, to: :ruby
  16. 16. [ 42 ]proc { 42 }
  17. 17. anArray do: [ :each | each doSomething ]an_array.each do |element| element.do_somethingend
  18. 18. Textmate version = 2 ifTrue: [ no way ] ifFalse: [ thought so ]if Textmate.version == 2 "no way"else "thought so"end
  19. 19. Storage current store: #foo; store: #barstorage = Storage.currentstorage.store :foostorage.store :bar
  20. 20. Smalltalk claims to looklike: English.Judge yourself. Does it.Ruby.claims.to.look.like "English"Judge.yourself; Does.it?
  21. 21. Reak github.com/rkh/Reak Like Squeak but with RFile based (as opposed to image based)
  22. 22. The Rubinius Compiler Pure Ruby Modular and Flexible lib/compiler
  23. 23. Parsing with KPeg github.com/evanphx/kpeg
  24. 24. " from Reak.AST.Self "grammar: g [ ^ g str: self ]# from Reak::AST::Returndef bootstrap_grammar(g) g.seq "^", :sp, g.t(:expression)end
  25. 25. Rubinius Bytecode
  26. 26. $ rbx compile -B -e puts "Hello World"0000: push_self0001: push_literal "Hello World"0003: allow_private0004: send_stack :puts, 1
  27. 27. $ rbx compile -B -e puts "Hello World"0000: push_self0001: push_literal "Hello World"0003: allow_private0004: send_stack :puts, 1
  28. 28. $ rbx compile -B -e puts "Hello World"0000: push_self0001: push_literal "Hello World"0003: allow_private0004: send_stack :puts, 1
  29. 29. $ rbx compile -B -e puts "Hello World"0000: push_self0001: push_literal "Hello World"0003: allow_private0004: send_stack :puts, 1
  30. 30. $ rbx compile -B -e puts "Hello World"0000: push_self0001: push_literal "Hello World"0003: allow_private0004: send_stack :puts, 1
  31. 31. class Object dynamic_method(:display) do |g| g.push_self g.push_local(0) # first argument g.send(:puts, 1, true) g.ret endenddisplay "Hello World"
  32. 32. Reusing the Rubinius tool chain
  33. 33. class Reak::Compiler < Rubinius::Compiler class Parser < Stage stage :parser next_stage Generator endend
  34. 34. class CustomNode < Reak::AST::Base def self.bootstrap_grammar(g) # grammar definition end def bytecode(g) # bytecode definition endend
  35. 35. class ConstantAccess < Rubinius::AST::ConstantAccess include Reak::AST::Node Reak::AST::Primary.push self def self.bootstrap_grammar(g) g.t /[A-Z][a-zA-Z0-9_]*/ end # no bytecode definition necessaryend
  36. 36. Rubinius.AST.TrueLiteral subclass: #TrueLiteral [ Reak.AST.Primary push: self. self include: Reak.AST.Node. self class >> grammar: g [ ^ g str: true ].]
  37. 37. " Remember cascades? "g pushSelf; pushLocal: 0; send: #puts args: 1 private: true; ret.
  38. 38. Reak.AST.Base subclass: #Cascade [ Reak.AST.Expression push: self. bytecode: g [ g pushSelf. cascadedSends do: [:send | g dup. send bytecode: g. g pop ]. lastSend bytecode: g. ]]
  39. 39. Thanks!github.com / rkh / presentations

×