4 ms·
I'm surprised by the assertion that you can't use expression syntax because you would then be forced to implement common subexpression elimination. You don't: J
by tom_mellior 7y ago
I'm surprised by the assertion that you can't use expression syntax because you would then be forced to implement common subexpression elimination. You don't: Just run your C compiler with -O0 and you should get expressions without CSE.
What you do give up if you use expression syntax is control over register allocation, unless you specify that expressions are evaluated via the stack and a designated accumulator. Or you could annotate every single subexpression with the register to put it in. I'd agree that this might not be a good fit for the overall design of this language, but I don't think CSE is to blame.
Besides that, the description of the calling convention could use a few more details. Are all registers except the stack pointer and the return value(s) callee-saved? Can you return multiple values? Can each function choose where to return its results, or is eax fixed as the return register? The "may be just documentation" comment confuses me.
- akkartik 7y agoAs I reread that passage now, there's some redundancy in my prose. The first time I mention CSE I'm talking specifically about optimization and the need to avoid the temptation to build an optimizer over time. The second time I don't, but I'm still implicitly assuming the need to optimize. I should clean that up. Calling convention: yes, all registers are callee-saved. Multiple values can be returned. (Up to 6, I guess?) Since the callee saves registers, any returned registers are just not saved and restored. A function can return in any register, though I use `eax` by convention. Since miscommunication between caller and callee about what registers are clobbered can lead to subtle bugs, I require the caller to also show the correct register being written to. Does that help? I'll work this in. Thanks!
- tom_mellior 7y agoYes, that's great, thanks!