Runt is a small and quirky stack-based virtual machine built to work with Polysporth. Runt can be used as a thin layer for other C layers, effecitvely making it an ideal glue language.
Here are some features:
- Stack-based: heavily inspired by Forth
- Memory-pool allocation system: only one call to malloc/free needed!
- built-in parser and interpreter, with a stack-based syntax
- written in ANSI C
- simple API for defining new words
- Can be run inside of Polysporth plugin as a scheme-extension
The source code for Runt can be found here.
To do a full compile of Runt and the Runt Polysporth extension run:
This assumes that Sporth is installed.
If you want to just compile the runt interpreter (and implicitly compile librunt):
sudo make install
Starting up irunt will get you to a prompt, where you can try things out.
"Hello world" in runt looks like this:
> "hello world!" say hello world!
To make procedures, record mode must be turned on, which allows you to record to the cell pool. To return to interactive mode, you must stop:
> rec Recording. > : foo "runt is cool!" say ; > stop Stopping. > foo runt is cool!
Runt currently has supported for basic floating-point arithmetic. The "p" command pops the value from the stack and prints it.
> 1 3 + p 4 > 3 2 - p 1 > 10 3 / p 3.3333 > 12345 54321 * p 6.70593e+08
Some forth-like stack operations like swap and dup are also supported currently:
> rec : pow dup * ; stop Recording. Stopping. > 5 pow p 25
Plugins are procedures written in C that can be dynamically loaded at runtime. They are an ideal way to "glue" other C-libraries together.
Example code for a plugin exists in plugin.c. To compile it, run:
Once it is compiled, you can start up irunt in the directory it is in, and load it into the runt cell pool:
> "./plugin.so" dynload > test this is a plugin!