23.10.2013 Views

FAST Forth Native-Language Embedded Computers

FAST Forth Native-Language Embedded Computers

FAST Forth Native-Language Embedded Computers

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Listing Ten-a. Zero-stack-effect line.<br />

TMBUF ARCTM [ YR MINUTES - I+ ]LIT CMOVE ( Copy time, date to arc buffer.)<br />

Listing Ten-b. A parameter calculated on each line.<br />

CALCULATE SOURCE ADDRESS AT RUN TIME ( comments comments comments )<br />

CALCULATE DESTINATION ADDRESS AT RUN TIME ( comments comments comments )<br />

[ CALCULATE COUNT AT COMPILE TIME ]LIT ( comments comments comments )<br />

CMOVE<br />

Listing Eleven. Comments that need comments.<br />

CODE CODE CODE CODE ( A max addr addr' addr" tok-len)<br />

eliminate all net stack effect; but it is important that we<br />

work toward that goal, nevertheless.<br />

A line with a CMOVE might simply be like Listing Ten-a.<br />

But if it takes a few operations to calculate the parameters,<br />

each of those operations will usually need its own line, as<br />

in Listing Ten-b.<br />

Now (in listing Ten-b) we have a code paragraph made<br />

up of four sentence lines. If this is only part of a colon<br />

definition, a blank line should be used to separate it from<br />

other code that may come above and below it.<br />

Stack-Effect Comments<br />

When code can be written in minimal-stack-effect<br />

lines, there will be little need for stack comments for each<br />

line. Sometimes, however, things will get a bit confusing,<br />

and there may not be any good way to get around it.<br />

If there is any question about what's left on the stack<br />

at the end of a line, that should be cleared up in the<br />

comments. In those cases, I like to start the comment line<br />

with a A as a stack symbol, followed by a description of<br />

what's on the stack after the line is finished executing.<br />

Listing Eleven shows the stack effect comment follow-<br />

ing a line of code in something we bought. It hardly<br />

qualifies as a description. Maximum what? Addresses of<br />

what? Granted, when there are five things on the stack to<br />

tell about, you don't have much room to tell what each one<br />

is. But since that was the case, they should have put a few<br />

lines of "glossary" above or below the code, telling you<br />

that when you come upon "addr," understand that it<br />

means such-and-such. The same would apply at the next<br />

step up, where there is truly a description, but accomplish-<br />

ing it required non-standard abbreviations beyond what is<br />

intuitive.<br />

Dropping down to use another line may initially seem<br />

like an obvious solution to the problem of insufficient<br />

comment room. However, if this requires putting com-<br />

ment space between lines of code that should not be<br />

separated, it may partially defeat the purpose.<br />

Comments<br />

Much has already been said about comments. I will<br />

only add that if there is not enough room to the right of<br />

the code to put in complete comments, by all means-put<br />

a paragraph or two (or whatever it takes) above the code<br />

to describe what it will be doing, and why. No abbrevia-<br />

tions are necessary here. Make a complete description.<br />

Leave nothing hidden! Expose everything! Typing it in<br />

while it is fresh in your mind will take a fraction of the time<br />

it would take to figure it out with inadequate comments a<br />

year or two later when you want to make an update. It will<br />

be even more valuable if someone else has to figure it out.<br />

In some cases, you may need to write about hardware<br />

or other limitations encountered that led up to the decision<br />

to do it the way you did. Sometimes when I didn't do this,<br />

those things have slipped my mind and I would think,<br />

"Hey, there's a much better way to do this!" After spending<br />

some time on it, I would start remembering that I had<br />

already tried my "better" idea and that there was a good<br />

reason for not doing it that way.<br />

Case<br />

Lower-case is generally only for internals, like branch,<br />

lit, litq, etc. For example, in the <strong>Forth</strong>s I've used, DO<br />

compiles do (a different word), and CREATE compiles the<br />

address of the run-time routine called create (also a<br />

different word). The programmer rarely accesses the<br />

internals directly. Because of this, some <strong>Forth</strong>s (LMl's<br />

UR/FORTH, for example) start out by putting the PC in<br />

"Caps Lock."<br />

The ascenders and descenders of lower-case letters are<br />

part of what our brain uses to recognize words quickly<br />

when we read prose, when our eyes stop once for every<br />

few words as we read quickly. Our process of reading<br />

code, however, is much different. When we read prose,<br />

the line divisions are mostly meaningless, existing prima-<br />

rily because an 8.5" x 11" book is much more manageable<br />

than a ribbon a mile long. However, the line breaks in<br />

(Continues onpage 31 .)<br />

March 1994 Aprjl 26 <strong>Forth</strong> Dimensions

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!