It seems to me that a few of us are implementing a Forth for 65xxCPUs, with different design goals in mind. I don't mean to hijack this thread, and I also don't know whether it's right to start a new thread for every design issue that comes up. But the ugly has to go somewhere, so here goes:
In my implementation (for 6502), the innermost DO LOOP counter and limit are stored in 4 bytes of zeropage. This is for the speed and size advantages of not having to twiddle the machine stack all day long. As I'm reimplementing NUMBER, it occurs to me that I can also use >R R@ R> pretty freely inside the body of an inner DO loop, without having to worry about the loop index I getting in the way. It's not 79, 83, ANS, or Fig to be able to write something where R@ and I are not synonymous, like this, but it would work! Would I still be able to include the word FORTH-83 in my dictionary, which doesn't seem to have a lot to say about this divergence between R@ and I ?
Code:
( There is a string that is probably a number stored from addrlow..addrhigh -- caveat -- this probably has some bugs )
: NUMBER ( addr -- d ; convert a counted string to a signed double, keeping track of the decimal )
0 0 ROT COUNT ( 0 0 addr+1 len )
OVER C@ [ ASCII - ] = ( leading minus? )
DUP >R IF 1- SWAP 1+ SWAP THEN
OVER + 1+ SWAP ( 0 0 addrhigh addrlow )
DPL ON
?DO
BASE @ >R
I C@ R@ DIGIT ( doublesubtotal (currdigit) flag )
IF
SWAP R@ UM*
DROP ROT
R@ UM* D+
DPL @ 1+ IF DPL 1+! THEN
ELSE
I C@ [ ASCII . ] =
DPL @ 0< AND
IF
DPL OFF
ELSE
3 FAIL ( performs "NOT FOUND" ABORT - do not pass go do not collect $200 )
THEN
THEN
R> DROP
LOOP
R> IF DNEGATE THEN ;
Another thing I'm considering is to dispense with VOCABULARY entirely, at least in the initial release of PETTIL. No CURRENT, no CONTEXT, no VOCABULARY, but there would be a LATEST. Otherwise doing FORGET CREATE FIND all becomes mind-boggling, at least for my easily boggled mind. This is an obvious dealbreaker for the standards committee who will no doubt judge me harshly and kick me out of their clubhouse until I fix it. While I'm at it, I'm probably going to be playing fast and loose with BLOCK, EMPTY-BUFFERS, SAVE-BUFFERS, and all of that too, because this is not 1970 and I am not Chuck Moore and there is already a nice filesystem available on my target hardware platform, so I plan to use it. I will say that I am enjoying this project more than I really ought to, particularly the code golf. It's just that doing these things that violate standards makes me feel so impure.
OB6502: Here's 1+! which I'm proud of, a word from the Forth79 Referrence wordset
Code:
;--------------------------------------------------------------
;
; 1+! ( n -- )
;
; increments the word addressed by n
;
oneplusstorelfa .byt $de,$ad ; link
.byt (oneplusstore-*-1)|bit7 ; length
.asc "1+","!"|bit7 ; name
; there is no CFA, there is only code
oneplusstore ldy #$ff
sec
oneplusstore01 iny
lda (tos),y
adc #0 ; add one the first time, add C the second time
sta (tos),y
tya ; to set the Z flag
beq oneplusstore01 ; loop exactly twice
jmp pops