committing call stack crimes so my little gameboy stack language can have while loops π

committing call stack crimes so my little gameboy stack language can have while loops π

imagine society if the game boy's push and pop instructions took fewer than four m-cycles
@aparrish
... somehow it feels wrong that i can extrapolate that this is probably Python from a screenshot with this little syntax?
i made a version of the famous 10 PRINT program with my gameboy stack-based language, and it runs great on real hardware! the language is very much still a work in progress, and neither this program nor the compiler are very efficient (bc i am a newcomer to both compilers *and* stack-based programming languages). but i am having a blast and learning a lot!
here's the source code if anyone wants to take a peek https://gist.github.com/aparrish/31b1639e876e162cf24ddcf7bf10a7fb (i think i'm calling the language "inchl" after the gameboy's "inc hl" instruction, which appears all over the place in the compiled code)
@aparrish Yay, I love this! Also, we should start a we-who-implemented-10-print-for-game-boy-webring or something. Mineβs here, yours is way more impressive. π
@sven this is great! the annotated version of your asm is very lucid and useful. wish i'd seen it when i was first learning!
@aparrish pipeline from Homebrew GB Cart Design to FORTH-like languages to 10 PRINT
:)
@drj yeah, now i just need to remember to pop the stack every once in a while so i actually finish some of these projects haha
@aparrish i think it is in the nature of FORTH-like languages that they are never finished (they are self-extending, after all). They just become standards (ANSI FORTH, and Open Firmware; probably others).
updates: I added some code generation optimizations for constant values in the source, and added "keep" versions of words where it makes sense ("keep" = pushes result to stack without consuming operands). I changed the "while" structure to only have one "block" (it keeps looping until there's a zero on the top of the stack at the end of the block). also added an "ifte" word to do if-then-else. https://gist.github.com/aparrish/31b1639e876e162cf24ddcf7bf10a7fb for new 10print implementation (clearer imo and runs faster!)
still on the to-do list: debug mode (inserts a check for stack overflow/underflow after every word); "aligned" mode that uses "inc l" instead of "inc hl" if the stack is guaranteed to begin at a $xx00 offset and never exceed 256 bytes (thereby saving a cycle every time something is added/removed from the stack); compile-time expressions; some way to represent strings and other static data inline. but even without all that, it's starting to feel "usable"