SIMPL - a Tiny Interactive Language for Microcontrollers or Experimental CPUs.
SIMPL is a symbolic language for programming microcontrollers based on printable ascii characters.
The idea of using single printable characters to represent instructions, commands, functions or even complete programs is not new:
MOUSE - a language for Microcomputers, Peter Grogono 1969
Txtzyme - a Nano Interpreter for Domain Specific Languages, Ward Cunningham 2010
Stable - An Extremely Small and Fast Forth VM, Sandor Schneider, 2016
SIMPL is derived from Txtzyme and development began in May 2013
The advantage of using a single character to represent an instruction or function is that it only takes up a single byte of storage, whilst function calls in other languages are often expressed as 16-bit addresses.
Secondly, we are taught to read, recognise and manipulate alphanumerical characters and symbols from an early age. This makes it easier to express a function or program symbolically rather than a series of numerical commands or lists of addresses. This may seem obvious to anyone who began their interests in computing programming by hand in assembly language and converting each instruction to hexadecimal characters to enter into the machine.
This leads to further compactness of the source code, for example a typical line of assembly language might be written:
ADD R0,R1
With SIMPL this is reduced to just the single "+" character, and the source and destination registers are defined implicitly in the design of the virtual machine.
SIMPL is not a large language. It's kernel can be defined in less than 200 lines of C++ code, which makes it suitable for small microcontrollers such as any of the Arduino compatible boards.
Neither is it a complicated language, it is confined by the limitations of the printable ascii characters meaning that you are restricted to a core of just 32 symbolic instructions. Variables and functions must be selected from the uppercase A-Z and the lowercase a-z characters which imposes a further restriction on the scope of the language.
SIMPL - A Brief Description
Each character, read in turn from RAM is interpreted and forms either an instruction, or a jump to an executable block of code, running on a virtual machine. The virtual machine is assumed to have a 16-bit wordsize and a 64Kbyte address space.
For example + will perform a 16-bit addition on the top two elements of the stack, whereas p will take the top element of the stack and print it to the terminal as a 16-bit decimal number.
In each case, the character is used in a look-up table or switch-case structure, to generate a unique jump to a block of code in ROM, which performs the command action.
Characters can be chosen by the programmer to have a strong mnemonic value, such as + for ADD and p for PRINT. Reducing these instructions to single characters makes the language very concise.
Thus SIMPL provides a shorthand means to communicate with a microcontroller or other computing device using an interactive command shell. This allows control the microcontroller and its harware peripherals using short snippets of code, or "microscripts" typed at the keyboard, or sent as a text file from a terminal emulator.
The interpreter can be pointed to any location in memory to begin parsing SIMPL code from there. Any location in memory containing a valid, printable ascii character (ascii $20 to $7E) will result in a jump to a legitimate code block, or trapped as an unused command.
In the case of commands typed from the keyboard, this memory will be an array in RAM that forms the Text Input Buffer (TIB). The code in the TIB will be executed immediately when the parser receives a carriage return character. This is called Immediate Mode.
The interpreter may also be pointed to a location in RAM containing the User's program. It will begin execution there and will continue until it finds a non-printable ascii character. This could be...
Owen,
SIMPL has been highly influenced by Forth, and it is evolving into a subset of Forth. Forth is typically 6 to 8k bytes if written in assembly language, perhaps double this if written in C. I hope that SIMPL will be under 4k bytes when written in C.
I wanted something quick and dirty that could easily be ported between microcontrollers. Once you get past "Hello World" or flashing a LED with a new microcontroller, you want something that allows you to quickly try out ideas, without the tedious Edit-Compile-Flash work flow.
SIMPL hopefully provides the means to accelerate you quickly past the LED flashing breakthrough.
It's been a work in progress since May of 2013, when I first stumbled across Ward Cunningham's Txtzyme. I hope to use this latest phase of lockdown to explore some more ideas and to formalise the language.
For the first few project logs, I am going to use a standard Arduino Uno as a target board. Everybody has some sort of access to an Arduino - and it allows new code to be tested out quickly.
Unfortunately the Arduino built in language functions are fairly verbose, setup(), loop(), digital read/write and the serial library add hundreds of unnecessary bytes to the interpreter code. This can be addressed later, as SIMPL is currently just a proof of concept.