5 ms·
A JIT Compiler in 380 Lines of Ruby
- rbxbx 15y agoCaches of the original article and each associated chapter: Original Post http://webcache.googleusercontent.com/search?q=cache:http://chris.wailes.name/?page_id=97 http://webcache.googleusercontent.com/search?q=cache:http://... Chapter 1: The Lexer http://webcache.googleusercontent.com/search?q=cache:http://chris.wailes.name/?page_id=105 http://webcache.googleusercontent.com/search?q=cache:http://... Chapter 2: The AST Nodes http://webcache.googleusercontent.com/search?q=cache:http://chris.wailes.name/?page_id=144 http://webcache.googleusercontent.com/search?q=cache:http://... Chapter 3: The Parser http://webcache.googleusercontent.com/search?q=cache:http://chris.wailes.name/?page_id=150 http://webcache.googleusercontent.com/search?q=cache:http://... Chapter 4: AST Translation http://webcache.googleusercontent.com/search?q=cache:http://chris.wailes.name/?page_id=173 http://webcache.googleusercontent.com/search?q=cache:http://... Chapter 5: JIT Compilation http://webcache.googleusercontent.com/search?q=cache:http://chris.wailes.name/?page_id=195 http://webcache.googleusercontent.com/search?q=cache:http://... Chapter 6: Adding Control Flow http://webcache.googleusercontent.com/search?q=cache:http://chris.wailes.name/?page_id=218 http://webcache.googleusercontent.com/search?q=cache:http://... Chapter 7: Playtime http://webcache.googleusercontent.com/search?q=cache:http://chris.wailes.name/?page_id=230 http://webcache.googleusercontent.com/search?q=cache:http://... Chapter 8: Mutable Variables http://webcache.googleusercontent.com/search?q=cache:http://chris.wailes.name/?page_id=248 http://webcache.googleusercontent.com/search?q=cache:http://...
- username3 15y agoText-only loads faster.
- wbhart 15y agoUnless 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++.
- bbatsell 15y ago> Are the LLVM bindings for Ruby up-to-date? I believe so; MacRuby is under pretty serious development by a team within Apple.
- wolfgangK 15y agoYou 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 https://github.com/scientific-coder/Computer-Languages
- wbhart 15y agoThanks, 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 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 15y agoThe 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.