I have been slowly working on getting a MUSL compiler that targets the MU5 emulator, with the ultimate goal of compiling the MUSS source code to run on it. The first step is to build a cross compiler that works on Windows. A while back I switched tactic from building my own Flex/Bison compiler, to hand translating the MUSL compiler into C. I completed that translation a few months ago.
I then started testing the translated compiler, parsing some sample MUSL code. I found a lot of mistranslations, of course. I also found a couple of spots where I could not reconcile the code with the way it was supposed to work. A couple of the IF statements had to be inverted, I have marked these in the translated code with “/**/” and an explanatory comment.
I translated the MUBL module too, so that it would output a form of intermediate binary code, however I think I should not have bothered. This is because, more recently, I switched to parsing very simple programs and building an actual implementation of MUTL that targets the emulator.
Today I succeeded in compiling the following program which runs on the MU5 emulator and outputs a simple “hello world” message.
*TLSEG 0 %FFFF %00010000 0 6; *TLSEG 1 %FFFF 0 0 6; *TLLOAD 1 0; *GLOBAL 0; *CODE 1; *VTYPE LOGICAL64; MODULE; VSTORE CONSOLE.INTERRUPT %300; VSTORE TELETYPE.DATA %306; VSTORE TELETYPE.CONTROL %307; $PS PRINT.STRING(ADDR[LOGICAL8]); PRINT.STRING(%"HELLO MU5 WORLD$L"); HALT: -> HALT; PROC PRINT.STRING(STRING); $IN I; FOR I < 16 DO %F => CONSOLE.INTERRUPT; :: Reset console interrupt bits 0 => TELETYPE.CONTROL; :: TTY output mode STRING^[I] => TELETYPE.DATA; WHILE CONSOLE.INTERRUPT = 0 DO OD; OD END *END
The code is naïve and relies on a tweak to the emulator not to generate an interrupt when the teletype character has been written. Note also that the built-in SIZE function does not work, I have not been able to work out how it is supposed to work yet.