Impala is a simple bytecode interpreter written in Clojure. Written to learn from and to teach making use of.
Load everything into namespace.
(use '[impala core lib])
Write a simple program in impala bytecode and execute it,
printing the whole lifecycle to stdout
.
(let [prog [[SET :a 5]
[SET :b 3]
[ADD :a :b]]]
(run prog true))
We can even extend the instruction set by defining our own opcodes
- in Clojure
(defn ADD
"b := b + a"
[env a b]
(swap! env update-in [:vars b] + (-> @env :vars a)))
or
- in Impala byte code!
;; from impala.lib
(defop ADD
"b := b + a"
[a b] [Z]
(SUB a Z)
(SUB Z b))
At the heart of this capability is the SUBLEQ primitive, which is Turing Equivalent.
In this example, Z
is a temporary register created (and set to 0) every time ADD
is called, and deleted once it's done executing.
An opcode may use multiple temporary registers.
At the terminal, run
lein uberjar
./impala test/impala/test.imp
Impala is licensed under wtfpl and is effectively in the public domain.