Project: MojoBASIC (Patreon)
Content
Let me take you back to high school; back when Nirvana was obsoleting Guns 'n' Roses, back when OJ Simpson was that football player in the Naked Gun movies, and back when I was in love with QuickBASIC.
Having outgrown QBasic, I harassed my friend Steven Francesconi until he pirated me a copy of QuickBASIC 4.5 against his will (sorry, Steven!). I wanted to mod VBBS, a BBS written in BASIC that was totally amazeballs back in the day.
I would have long debates with my friends about how BASIC was better than C (case insensitive variables mean you never access the wrong one by a typo! Humans think about the first item in a list as #1, not #0! I was young, everyone) and write pages and pages of code--probably nothing useful--on loose leaf in the back of class. I spent time modding VBBS and writing fun little ASCII art trinkets and things that don't even make sense to modern humans, like BBS tagline selector programs.
I wrote _so much_ code in QuickBASIC in 1993, not even knowing that Microsoft had abandoned the product a full five years earlier. They were working on this little thing called "Visual Basic" now.
I spent some time revisiting 16-year-old Ryan this month.
MojoBASIC started out as a little toy language I was building to learn about LLVM (more on this in a later post, hopefully!), and then an idea took over my brain and I put away the original project to spend a week trying to parse QuickBASIC syntax. I ended up wandering away because I was missing deadlines by focusing on these sort of projects--as I do--but I thought I might revisit it now and see how far I can run with it.
At the moment, it parses (most of) QuickBASIC's syntax into an Abstract Syntax Tree, and walks that tree to print out basically the same BASIC program. There's a ton of LLVM integration code that's #if 0'd out that was inherited from the other project, which I'll be reenabling soon. Once that's in place, you'll be able to dump out LLVM bitcode trivially, meaning you can do fun things like:
- Compile a BASIC program into a native executable on Linux, Mac, Windows, and other platforms LLVM supports.
- Write a subroutine in BASIC and call it from your Clang-compiled C code.
- Run BASIC code on the web with Emscripten.
- Use BASIC as a scripting language embedded in a game, with LLVM's JIT functionality.
- Install apps written in BASIC on an iPhone.
I'm not saying we'll get there, or we even _should_ get there. A more practical goal is that we can compile GORILLA.BAS, high-five about this and then never speak of it again. Sometimes you just have to build something so you can stop thinking about building something.
Maybe we get it to the point where it can handle all those pre-.NET Visual Basic programs that are being lost to time. Did you know Visual Basic 6.0 won't even _install_ on Windows 10 without a massive fight?
The source code to MojoBASIC is here.