▲ | vdupras 3 days ago | |||||||
The mapping to assembly of: 42 = if ."hey!" then is much more straightforward than if (n == 42) printf("hey!"); I understand that to the newcomer, it might not appear that way, but implementing a Forth is really eye-opening in that regard. If I might allow myself a bit of promotion, I wrote https://tumbleforth.hardcoded.net/ as such an eye-opening process. It's less "gentle" than Easy Forth here, but it digs deeper. | ||||||||
▲ | bxparks 2 days ago | parent [-] | |||||||
From the comments in this thread, it seems that to understand how Forth implements a simple IF-THEN-ELSE control-flow, I have to understand the difference between non-immediate and immediate words. I also have to understand the difference between outer and inner interpreter. And I have to understand how Forth generates snippets of machine code (where does that get stored? I thought Forth only has 2 stacks, does it also have a general heap?). Then understand how the THEN token goes back and patches the placeholder address generated by the IF token. And understand the difference between the parsing phase and the interpreted phase of the Forth interpreter/compiler. But you are saying that the Forth version is simpler than C version which will kinda look like this after it's compiled (Z80 assembly code, it's in my head right now):
I find that hard to believe, but I accept that you believe that. | ||||||||
|