scotws wrote:
Now, the Forth specs say that 0 ROLL is a null operation (which isn't really true, because n is dropped), 1 ROLL is SWAP and 2 ROLL is ROT.
The specs do not say that
ROLL is a null operation when the top of the stack is 0 ( zero) but that
0 ROLL is a null operation. The stack before
0 ROLL is the same as after
0 ROLL. The
0 and
ROLL have to be considered together.
ROT is not a null operation but
ROT ROT ROT certainly is.
Oh and here is Fleet Forth's implementation of
ROLLCode:
SCR# 3B
// ROLL
HEX
CODE ROLL
0 ,X LDA, 3F # AND,
POP.JMP 0= BRAN,
XSAVE STX, .A ASL, TAY,
XSAVE ADC,
POP.JMP 0< BRAN,
TAX, INX, INX,
0 ,X LDA, PHA, 1 ,X LDA, PHA,
BEGIN,
0FF ,X LDA, 1 ,X STA,
DEX, DEY,
0= UNTIL,
PLA,
PUT JMP, END-CODE
The branch to
POP.JMP is a branch into
ONCode:
SCR# 3A
// ON OFF
HEX
CODE ON ( N -- )
DEY, TYA,
0 X) STA, 0 ,X INC,
0= IF, 1 ,X INC, THEN,
0 X) STA,
LABEL POP.JMP
POP JMP,
END-CODE
CODE OFF ( N -- )
-2 ALLOT
' ON @ 1+ ,
END-CODE
Since this source is for a metacompiler, as opposed to a regular Forth assembler, using a label does not increase the target size ( it only exists on the host.)
Cheers,
Jim