aparrish@friend.camp
aparrish@friend.camp

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

vim screenshot with lots of game boy assembly instructions that interact with the call stack, like

|
Embed
Progress spinner
aparrish@friend.camp
aparrish@friend.camp

imagine society if the game boy's push and pop instructions took fewer than four m-cycles

|
Embed
Progress spinner
s_ol@merveilles.town
s_ol@merveilles.town

@aparrish
... somehow it feels wrong that i can extrapolate that this is probably Python from a screenshot with this little syntax?

|
Embed
Progress spinner
aparrish@friend.camp
aparrish@friend.camp

@s_ol yup python! my python program is generating rgbds assembly code

|
Embed
Progress spinner
jaykass@mastodon.online
jaykass@mastodon.online

@aparrish

|
Embed
Progress spinner
aparrish@friend.camp
aparrish@friend.camp

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!

|
Embed
Progress spinner
aparrish@friend.camp
aparrish@friend.camp

here's the source code if anyone wants to take a peek gist.github.com/aparrish/31b16 (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)

|
Embed
Progress spinner
In reply to
sod
sod

@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. 😊

|
Embed
Progress spinner
aparrish@friend.camp
aparrish@friend.camp

@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!

|
Embed
Progress spinner
drj@typo.social
drj@typo.social

@aparrish pipeline from Homebrew GB Cart Design to FORTH-like languages to 10 PRINT

:)

|
Embed
Progress spinner
aparrish@friend.camp
aparrish@friend.camp

@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

|
Embed
Progress spinner
drj@typo.social
drj@typo.social

@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).

|
Embed
Progress spinner
aparrish@friend.camp
aparrish@friend.camp

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. gist.github.com/aparrish/31b16 for new 10print implementation (clearer imo and runs faster!)

|
Embed
Progress spinner
aparrish@friend.camp
aparrish@friend.camp

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"

|
Embed
Progress spinner