
A JIT Compiler in 380 Lines of Ruby - fogus
http://chris.wailes.name/?page_id=97
======
rbxbx
Caches of the original article and each associated chapter:

Original Post
[http://webcache.googleusercontent.com/search?q=cache:http://...](http://webcache.googleusercontent.com/search?q=cache:http://chris.wailes.name/?page_id=97)

Chapter 1: The Lexer
[http://webcache.googleusercontent.com/search?q=cache:http://...](http://webcache.googleusercontent.com/search?q=cache:http://chris.wailes.name/?page_id=105)

Chapter 2: The AST Nodes
[http://webcache.googleusercontent.com/search?q=cache:http://...](http://webcache.googleusercontent.com/search?q=cache:http://chris.wailes.name/?page_id=144)

Chapter 3: The Parser
[http://webcache.googleusercontent.com/search?q=cache:http://...](http://webcache.googleusercontent.com/search?q=cache:http://chris.wailes.name/?page_id=150)

Chapter 4: AST Translation
[http://webcache.googleusercontent.com/search?q=cache:http://...](http://webcache.googleusercontent.com/search?q=cache:http://chris.wailes.name/?page_id=173)

Chapter 5: JIT Compilation
[http://webcache.googleusercontent.com/search?q=cache:http://...](http://webcache.googleusercontent.com/search?q=cache:http://chris.wailes.name/?page_id=195)

Chapter 6: Adding Control Flow
[http://webcache.googleusercontent.com/search?q=cache:http://...](http://webcache.googleusercontent.com/search?q=cache:http://chris.wailes.name/?page_id=218)

Chapter 7: Playtime
[http://webcache.googleusercontent.com/search?q=cache:http://...](http://webcache.googleusercontent.com/search?q=cache:http://chris.wailes.name/?page_id=230)

Chapter 8: Mutable Variables
[http://webcache.googleusercontent.com/search?q=cache:http://...](http://webcache.googleusercontent.com/search?q=cache:http://chris.wailes.name/?page_id=248)

~~~
username3
Text-only loads faster.

------
wbhart
Unless I am mistaken, I think the title could do with being changed. It looks
to me like the Jit compiler is written in C++. LLVM is not written in Ruby.
What is implemented in Ruby here is a version of the toy Kaleidoscope language
which is given as an example of how to use the LLVM Jit on the LLVM website.

Are the LLVM bindings for Ruby up-to-date? I thought about using them last
night for a while, but ended up deciding to use peg to create a recursive
descent parser for my language and am going to write some pretty generic code
to do the AST myself. That way I can keep everything in C/C++.

~~~
wolfgangK
You might be interested by the first steps that I have taken to generate llvm
IR from boost::spirit (for the peg parser) even if the languages where too
simple to warrant an ast. <https://github.com/scientific-coder/Computer-
Languages>

~~~
wbhart
Thanks, though I already have a small language working with the LLVM Jit that
accepts the language described by this grammar:
<http://selmer.warwick.ac.uk/c.grm>

I'm in the process of rewriting it to use peg though, as I was using a parser
generator that is not open source, and it started to bug me that it wasn't.

------
cygwin98
The Kaleidoscope language reminds me of the hoc language. In Chapter 8 of the
book "The Unix Programming Environment", Brian Kernighan and Rob Pike used hoc
as an example to demonstrate how to use yacc, lex, and make to develop a
compiler.

In hoc, you have control flows and can define your own functions.
Unfortunately, hoc lost the battle to bc, that's why it's rarely known in the
Unix community.

