Subleq, like many of the esoteric languages is not the fastest language, nor is it easiest to program in.
(Two glaringly obvious massive understatements of the Century).
However, a Subleq interpreter can be written in a few lines of C, or, at most a couple of hundred bytes of assembly language.
Once you have your interpreter in place, you have created a very minimal VM, regardless of what CPU you are coding for.
So provided you have coded your interpreter, a Subleq program for a Z80, will run exactly the same on a 6502, 6809, RCA 1802, PIC, MSP 430, x86 or whatever you might have available.
My friend Richard J. Howe, has coded up eForth into a Subleq image. It’s about 6500 16-bit words.*
I have adapted his interpreter code so that it can be hosted on any of the larger memory dev-boards supported by the Arduino IDE,
So far candidates have been a Pi Pico (RP2040), an STM32H743 Nucleo and a Teensy 4.1.
I am currently writing a subleq interpreter in Z80 assembly for my RC2014 and my Agon Light 2.
With a Subleq interpreter installed, plus the subleq image, which defines eForth, you will have a self-hosting Forth system.
No other tools required.
So, despite it’s minimalism, Subleq can get you up and running in Forth, regardless of your CPU.
- With the slightly modified Muxleq instruction, eForth will compile down to approximately 5K words of Muxleq code - and be significantly faster than Subleq.
It will even run on a CPU composed of fewer than 180 transistors and some parallel memory.
My interest in this was stimulated by this article in Nature, (Sept 2013) which describes an experimental CPU made from carbon nanotube FETs (CN-FETs), at Stanford University.
Remarkably they made a functional cpu from just 178 CN-FETs, plus conventional external RAM devices.
They used a variant of subleq, called subneg, which has the advantage of not requiring a program counter. This is a major saving in transistors.
They also proved that the MIPS instruction set could be compliled from the subneg instruction, so the experimental cpu could execute MIPS code - albeit extremely slowly.