Divs1210 Impala Save

Simple, extensible bytecode interpreter

Project README

Impala

Simple, extensible bytecode interpreter

Impala is a simple bytecode interpreter written in Clojure. Written to learn from and to teach making use of.

Usage

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.

Standalone Interpreter

At the terminal, run

lein uberjar

./impala test/impala/test.imp

License

Impala is licensed under wtfpl and is effectively in the public domain.

Open Source Agenda is not affiliated with "Divs1210 Impala" Project. README Source: divs1210/Impala
Stars
26
Open Issues
0
Last Commit
8 years ago
Repository

Open Source Agenda Badge

Open Source Agenda Rating