Compiler for a simple programming language designed to run on my CPU made with Logisim evolution.
Implementation of the insertion sort algorithm:
var arr:5;
arr[0] = 4;
arr[1] = 23;
arr[2] = 1;
arr[3] = 7;
arr[4] = 12;
var len;
len = 5;
var r;
var j;
var i;
var x;
i = 1;
while i < len {
x = arr[i];
j = i - 1;
r = 0;
if j > -1 {
if arr[j] > x {
r = 1;
}
}
while r == 1 {
arr[j + 1] = arr[j];
j = j - 1;
r = 0;
if j > -1 {
if arr[j] > x {
r = 1;
}
}
}
arr[j + 1] = x;
i = i + 1;
}
i = 0;
while i < len {
show arr[i];
i = i + 1;
}
demo.mp4
The code generator can be retargetted by modifying CompilerVisitor.hx. It implements the visitor pattern.