Skip to content

divs1210/Impala

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Simple, extensible bytecode interpreter

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published