Sunday, October 04, 2009

Development Support words for uForth

Support words shouldn't be in the core. As smaller as it could be to write in C, I am resisting the urge of making the core larger. Take for instance "words". It is very, very useful for debugging but not so useful in a "finished" system. Why should it eat precious RAM or Flash if you don't need it?

Here is a quick definition of words in uForth. You can place it in init.f (for BOOTSTRAP versions) or pass it to "uforth_interpret()". It depends on a few words I've already shipped in init.f:


( Implementation of words in pure uForth! )
create _ ( dummy "known length" entry )
variable last_word
variable ccnt ( keep track of # of characters on a line)


: words ( -- )
_ 6 - @ last_word ! ( We know where the prev word link is inside of _ )
0 ccnt !
last_word @ ( pointer to last word )
begin
dup ( keep it on the stack )
1+ count 63 and dup ccnt +! ( get length of word's name )
ccnt @ 70 > if cr 0 ccnt ! then ( 70 characters per line )
type 32 emit 32 emit ( print word's name )
2 ccnt +! ( add in spaces )
@ ( get prev link from last word )
dup -1 = ( -1 link means no more words! )
until
drop ;

No comments: