Factorial on SubX
Ok, I think I understand calling conventions now.
Also coming face to face with the pain of debugging machine code 😀
More adventures with machine code
SubX now has a test harness, and support for string literals.
Current (increasingly silly) factorial program to compare with the parent toot: http://akkartik.name/images/20180923-subx-factorial.html
Two new features:
a) Autogenerated `run_tests` (line 26) which calls all functions starting with 'test_'.
b) String literals (line 31). They get transparently moved to the data segment and replaced with their address.
That isn't much progress for a month. I've been trying a few different things and learning a lot:
a) I spent some time looking at the GREAT stage0/Mes bootstrap project.
b) I tried to design a type-safe low-level language that could be converted line by line to machine code, but it turned out to be a bust (thanks @email@example.com!). It's possible if you give up on freeing heap memory.
I'm now convinced there are no shortcuts. Gotta build a real compiler in machine code.
@akkartik @firstname.lastname@example.org @haitch @freakazoid Honestly, my advice here is to read two books: "Programming a Problem Oriented Language" teaches you how to write your own Forth compiler from scratch (bare metal on up). There are no assembly listings in the book, because it's pure guidance, but it was instrumental in me getting DX-Forth working at all.
@vertigo That being said, if performance is a primary goal, I'd suggest considering whether simpler heuristics are applicable
@haitch @akkartik @email@example.com @freakazoid Nice thing about not shying away from passes in compiler implementation is that passes are often plug-and-play relative to each other. That allows you to follow Butler Lampson's philosophy: "Make it work, make it right, make it fast."
A lot of what goes into making a compiler produce the fastest possible code is an act of diminishing returns, and frequently has to be redone every processor generation. Ergo, the more you can modularize it, the better.
@vertigo Anyway, routines that juggle more than 32 variables at amy given time are possibly not very well thought out. And routines that use more than that shou;d probably be penalised and split into other functions. This is less of a problem for processors with many registers, but ai ser how it can be a concern for @akkartik who's specifically targetting IA32.
@akkartik @firstname.lastname@example.org @freakazoid
Server run by the main developers of the project It is not focused on any particular niche interest - everyone is welcome as long as you follow our code of conduct!