Makeshift Programming Language
2022-02-05
A dead-simple programming language.
Table of Contents
Backgrounds
I was working on the Ashet Home Computer back when it was to be made with the SPU Mark II, a small 16 bit cpu and figured I need a programming language to be compiled on that machine.
As the environment was heavily resource constrained, no modern programming language was an option. As usual, I decided to create a new language.
Constraints
The design constraints of this language were to be as simple as possible, with as little features as possible while still kinda counting as a modern imperative programming language.
Makeshift has only a single type called word
, an unsigned machine-wide integer. It can be indexed (and is used as a pointer then), it can be called (and is used as a function pointer), and
you can do arithmetic with it. This way, basically no type system has to implement. Functions implicitly return an integer, if you don’t do a return, 0 will be returned.
Syntax
Makeshift is a very C/Zig like syntax, with curly braces for both arrays and block delimiting. The operators are mostly what you’d expect, except for the <val>@(<offset>)
operator, which performs not word, but byte indexing
into memory. { ... }
is an operator that returns a pointer to the contained sequence of bytes with a lifetime of the current scope. Thus, making text
a NUL terminated string with three characters.
const text = { 48, 48, 55, 0 };
fn strlen(ptr) {
var len = 0;
while(ptr@(len)) {
len = len + 1;
}
return len;
}
fn main() {
return strlen(text);
}
So this program will just compute the length of text
and returns it from main
.
Status
I tried to implement a compiler in Zig, but I already got too excited about compile time evaluation and ran into complications. Right now, the project is in hiatus, but I want to revive it and fix some design flaws:
- You can only index
word
orbyte
, which isn’t sufficient for 32 bit systems. - It required a good amount of compile time execution, which must be removed. Reduce the number of legal operations at compile time.
- Externs were missing, so programs could always be just a single file.
I still think the language is a cool thing to implement and bootstrap, and was designed as a bootstrapping language that should still be relatively easily compiled. Optimizations are always a good thing, but they aren’t really necessary.