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.
class Reak::Compiler < Rubinius::Compiler class Parser < Stage stage :parser next_stage Generator endend
class CustomNode < Reak::AST::Base def self.bootstrap_grammar(g) # grammar definition end def bytecode(g) # bytecode definition endend
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
Rubinius.AST.TrueLiteral subclass: #TrueLiteral [ Reak.AST.Primary push: self. self include: Reak.AST.Node. self class >> grammar: g [ ^ g str: true ].]