Three example Raven programs:
malloc.rv
, which is the memory allocator currently used in Raven's standard library and invoked by the compiler where needed.- It may well be the worst allocator ever written, but it gives an idea of what low-level pointer-programming looks like (bearing in mind this is not the language's design priority).
complex.rv
is also taken from the standard library and shows how you can define a new numeric type and various operations on it, using dispatch and pattern matching.- There's no
Number
type or any other abstract traits yet, interfaces are still informal, though tools for formal interfaces are planned.
- There's no
brainfuck.rv
is the most complete and realistic program to date, showing parsing to a recursive AST and the core interpreter loop.- In future I expect programs to mostly look a bit more Python- or Clojure-like, centred around generic dictionaries and lists rather than custom types, but those data structures don't yet exist. This gives an unfinished but reasonably representative idea of how compiler-like code looks.
- Don't expect good benchmark results yet. Although Raven has a high performance ceiling, I've focused on getting things like array operations working at all, with laughably naive implementations for some things.
To compile Raven code you need to run a Julia REPL in the Raven source code directory, then you can execute the compiled .js
file using Node.js. (Raven compiles to wasm, but a little JavaScript is needed to load and invoke the .wasm
file.)
➜ master git:(master) ✗ j --proj -q
julia> using Raven
julia> Raven.compile("brainfuck.rv")
"brainfuck.js"
julia>
➜ master git:(master) ✗ node --experimental-wasm-stack-switching test.js hello.bf
Hello World!
➜ master git:(master) ✗
The first compile is pretty slow (~60s) due to Julia warmup; subsequent compiles in the same REPL session will be faster (~1s). (Though even that's much slower than I'd prefer.)
The above assumes you've saved brainfuck.rv
to the same directory and also that you have a hello.bf
brainfuck file to interpret. Here's a "hello world":
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.