MiniPascal
For my sins… well, no, but because Pascal was the second programming language I learned (after Basic, and you can’t really count 6502 assembly as a programming language), because it was the first programming language I ever earned money writing, because I am challenging myself to write a medium sized C project, and because I am always eager to learn something new by just doing it, I decided to write a Pascal compiler.
Of course it will not in any way be able to compete with projects like Free Pascal or anything like that, and its output probably won’t be the best code in both elegance, runtime and performance, but it’ll be usable. Or at least that’s my goal.
Scope
So, what should this Pascal compiler be able to do? Well, obviously, it should be ultimately able to compile itself. Which means I have to write the compiler twice, oh joy…
Then I’d like it to be usable, so code generation for Linux on x86_64 is first (because I have to test somehow), then probably some old-school microprocessors like the 6502/65816 or Z80, both of which I may be able to build minimal systems for. Then of course, some microcontrollers (or not so microcontrollers) might be nice, like the ATMEGA 328, some PIC (eg. I have a PIC16F877 in my parts drawer), or even a Raspberry Pi Pico or the Milk-V (one implementation of the RISC-V architecture).
As for which software I’d really like to run on it, TurboVision (or rather the free derivative FreeVision) comes to mind. However, since it is written in object-oriented Pascal, and I’m not in the slightest interested in implementing object-orientation in any kind or form, I might be forced to either rewrite it or use this as a perfect opportunity to test C/C++ interfacing.
Progress
2024-03-04
Basic filehandling should be in place by now, haven’t really decided what to do with multiple input files.
For options I use getopt_long, this might be replaced with something else since the getopt likes to throw its own error messages, and I don’t like that.
nobuild has been a blessing and a curse - it’s a really easy build system, but error messages are a bit misleading as they tend to point to strange places in some preprocessor code when all that’s wrong is a missing comma or semicolon. I think Alexey has mentioned something along that lines in his videos where he coded bits and pieces of nobuild, and besides, it isn’t a finished product yet, so I might be forced to do a major rewrite or replace it altogether.
But since it works for this project right now I keep using it.