Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/divs1210/impala
Simple, extensible bytecode interpreter
https://github.com/divs1210/impala
bytecode-interpreter clojure vm
Last synced: about 5 hours ago
JSON representation
Simple, extensible bytecode interpreter
- Host: GitHub
- URL: https://github.com/divs1210/impala
- Owner: divs1210
- License: wtfpl
- Created: 2015-10-10T09:38:03.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-10-19T17:14:16.000Z (about 9 years ago)
- Last Synced: 2023-05-12T03:05:16.291Z (over 1 year ago)
- Topics: bytecode-interpreter, clojure, vm
- Language: Clojure
- Size: 160 KB
- Stars: 26
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Impala
## Simple, extensible bytecode interpreterImpala is a simple bytecode interpreter written in Clojure.
Written to learn from and to teach making use of.## Usage
Load everything into namespace.
```clojure
(use '[impala core lib])
```Write a simple program in impala bytecode and execute it,
printing the whole lifecycle to `stdout`.```clojure
(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
```clojure
(defn ADD
"b := b + a"
[env a b]
(swap! env update-in [:vars b] + (-> @env :vars a)))
```or
* __in Impala byte code__!
```clojure
;; 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](https://en.wikipedia.org/wiki/One_instruction_set_computer#Subtract_and_branch_if_less_than_or_equal_to_zero) 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
```bash
lein uberjar./impala test/impala/test.imp
```## License
Impala is licensed under [wtfpl](http://www.wtfpl.net/) and is effectively in the public domain.