Spinel -- Ruby AOT Compiler
Spinel compiles Ruby source code into standalone native executables. It performs whole-program type inference and generates optimized C code, achieving significant speedups over CRuby.
Spinel is self-hosting: the compiler backend is written in Ruby and compiles itself into a native binary.
How It Works
Ruby (.rb) | v spinel_parse Parse with Prism (libprism), serialize AST | (C binary, or CRuby + Prism gem as fallback) v AST text file | v spinel_codegen Type inference + C code generation | (self-hosted native binary) v C source (.c) | v cc -O2 -Ilib -lm Standard C compiler + runtime header | v Native binary Standalone, no runtime dependencies
Quick Start
# Fetch libprism sources (from the prism gem on rubygems.org): make deps # Build everything: make # Write a Ruby program: cat > hello.rb << ' RUBY ' def fib ( n ) if n < 2 n else fib(n - 1 ) + fib(n - 2 ) end end puts fib( 34 ) RUBY # Compile and run: ./spinel hello.rb ./hello # prints 5702887 (instantly)
Options
./spinel app.rb # compiles to ./app ./spinel app.rb -o myapp # compiles to ./myapp ./spinel app.rb -c # generates app.c only ./spinel app.rb -S # prints C to stdout
Spinel compiles its own backend. The bootstrap chain:
... continue reading