

























<p>My compiler spoke only an approximation to standard Forth. The structure of my input programs probably wouldn't have been approved by the language standard, in particular. Source files were required to begin with all the function and variable definitions, and then the main program would follow them.</p><p>So the compiler noticed when the first thing appeared in the source file that was not a function or variable definition, or nested inside one. And when it saw it, that was where it set the entry-point address of the output executable.</p><p>But the check for the first top-level thing in the source file happened before, rather than after, discarding comments. So if you wrote a comment before a function definition, the program's entry point address would point at the start of that function, instead of the start of the main program.</p><p>I'd never noticed at school, because although I did write comments in my function definitions, I wrote them just _inside_ the function, where they didn't trigger this bug. But 20 years later, I dug out this compiler for nostalgia's sake, ran it in BeebEm, and tried writing a program in it (world's slowest MD5 implementation!) to demonstrate that it still worked.</p><p>And since my schooldays, I had switched to the habit that most people seem to have (and that tools like rustdoc outright enforce), of putting a function's comment _outside_ the function definition. Bang! Bad output code.</p><p>(The worst of it was that then of course pride required me to fix it, and unlike my Forth _programs_, the Forth _compiler_ was in dense uncommented 6502 assembler. Got there in the end, but ugh, the things we had to do to fit useful amounts of stuff into such small machines.)</p><p>(2/2)</p>
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。