BIPLAN CR.1 (Bytecoded Interpreted Programming Language) is an experimental interpreted language designed for microcontrollers and real-time operating systems. Both the interpreter and the compiler fit in less than 48KB of program memory and are implemented in less than 2,000 lines of code; it is significantly more compact than Wasm3, MicroPython, or Lua. BIPLAN is simple, portable, modern, efficient, yet small enough to run on micro-controllers and vintage computers.
| Programming language | Compiler | Interpreter | Minimum requirements |
|---|---|---|---|
| TinyBasicPlus | ❌ (interprets source) | ✔️ | 11KB ROM, 1KB RAM |
| BIPLAN | ✔️ | ✔️ | 48KB ROM, 5KB RAM |
| Wasm3 | ❌ (interprets bytecode) | ✔️ | 64kB ROM, 10KB RAM |
| Wren | ✔️ | ✔️ | 160KB ROM, 16KB RAM |
| Lua 5.2 | ✔️ | ✔️ | 175KB ROM, 64kB RAM |
| MicroPython | ✔️ | ✔️ | 256KB ROM, 16KB RAM |
BIPLAN implements a compact virtual architecture (BIP CR.1) that uses ASCII bytecode. It includes a serial interface, input-output ports, analog-to-digital and digital-to-analog converters, mono sound, text mode graphics, file handling and inter-process communication pipes.
The version name CR.1 was chosen to honour the Italian Fiat CR.1 biplane fighter aircraft designed by Celestino Rosatelli, from whom it gained the 'CR' designation. The CR.1 was a sesquiplane of wood-and-fabric construction.
In 2017 I built a couple of standalone programmable computers with a screen and a keyboard using Arduino boards to run software I could understand. I was forced to use TinyBasicPlus because it was the only interpreted language that could fit into such tight memory constraints. The result was a machine with features comparable to an IBM 5150 booted into BASIC. Looking at it I asked myself: "How can BASIC, the first attempt to popularize programming, now 57 years old, still be the only viable option?" I just needed a simple interpreted programming language implemented in C, with very few dependencies and layers of abstraction. After some experiments I decided to design and implement that myself.
The development of BIPLAN started in 2017. I wrote both the compiler and the interpreter from scratch avoiding external libraries, frameworks and the influence of compiler and interpreter design studies, learning by doing and evaluating results. In 9 years of experiments I wrote BCC, a pre-processor and a multi-pass compiler capable of syntax and lexical analysis (701 lines of code), and BIPLAN, a register-based virtual machine implemented with a recursive descent parser (874 lines of code).
Fibonacci sequence computation in 149 bytes of BIPLAN code:
print fibonacci(40)
stop
function fibonacci($a, locals: $b, $c)
$b = 1
for #r = 0 to $a
$a = $b
$b = $c
$c = $a + $b
next
return $c
doneWith the command biplan fib.biplan the program is compiled in 45 bytes of BIP bytecode:
p~$40)xf$}j}k}l)}k1@$0,}j}j}k}k}l}l}j+}k;r}ld
And then interpreted:
102334155
On my linux computer biplan interprets the program in around 34 microseconds.
The table below contains the results of the benchmarks developed to compare 20 different programs implemented in BIPLAN and Python:
| Language | Bytecode size | Compilation | Interpretation | Startup |
|---|---|---|---|---|
| BIPLAN | 1.12KB | 431.58ms | 2366.70ms | 7ms |
| Python | 8.17KB | 1631.59ms | 3172.99ms | 48ms |
BIPLAN is more efficient than Python and it is well suited for applications that require fast startup time, minimal bytecode size and low power consumption.
- Bytecode
- Configuration
- Performance
- Comments
// - Conditions
ifelseend - Constants
truefalseHIGHLOWINPUTOUTPUT - Cycles
forwhilenextbreakcontinue - Functions
functionlocalsreturn - Macros
macro - Numeric variables
$$[] - Operators
+-*/%==!=>>=<<=&&||&|^>><<++--~not - Strings
::[] - System functions
adc readargscharcursordelayfile closefile openfile readfile writeincludeindexinputio openio readio writememmillisnumbernumericprintrandomrestartserial openserial readserial writesizestopstring - Unary operators
++--
To build BIPLAN you only need g++, the standard library requires also curl and jq:
sudo apt-get update && sudo apt-get install -y g++ jq curl
Once done see:
The following commands clone this repository, compile biplan, and execute the fib.biplan example to verify everything is working as expected:
git clone https://github.com/gioblu/BIPLAN.git
cd BIPLAN/examples/LINUX
make fast
sudo make install
biplan ../fibonacci/fib.biplan # Prints 102334155Feel free to send a pull request sharing something you have made that could help, if you want to support this project you can also try to solve an issue. AI-generated slop will not be reviewed: contributions to this project are evaluated only if well detailed, thoroughly designed, minimalistic and efficient. Thanks to support, expertise, kindness and talent of the following contributors, BIPLAN has been strongly tested, enhanced and verified:
BIPLAN CR.1 is licensed under the GNU Affero General Public License v3 (AGPLv3), and commercial or closed-source licenses are available on request. AGPLv3 permits commercial use if you comply with its copyleft terms (including source disclosure for network use).
When testing BIPLAN, take extreme care to avoid any danger. The implementation is experimental and may not behave as expected; use it at your own risk.