I noticed on the Forth standard website when testing
DOES>, there were no tests of nested
CREATE DOES>. Something similar might be useful in an object oriented package for Forth. Here is a test I came up with for nested
CREATE DOES>.
Code:
SCR# 3
// TEST CREATE DOES>
HEX
: LEVEL0 ( N -- )
CREATE , DOES> ( N2 -- )
CREATE @ , , DOES> ( N3 -- )
CREATE 2@ , , , DOES> ( N4 -- )
CREATE DUP 2+ 2@ ROT @ , , , ,
DOES> ( -- )
DUP 4 + 2@ ROT 2@ 4 0
DO U. LOOP ;
2 LEVEL0 LEVEL1
3 LEVEL1 LEVEL2
5 LEVEL2 LEVEL3
7 LEVEL3 LEVEL4
LEVEL4
And here is the result
Code:
3 LOAD 2 3 5 7 OK
And an examination of the parameter fields.
Code:
' LEVEL1 >BODY 10 DUMP
5A11 2 0 6 5A 86 4C 45 56 45 4C B2 BD 59 2 0 3 ...Z.LEVEL..Y...
OK
' LEVEL2 >BODY 10 DUMP
5A1E 2 0 3 0 13 5A 86 4C 45 56 45 4C B3 CC 59 2 .....Z.LEVEL..Y.
OK
' LEVEL3 >BODY 10 DUMP
5A2D 2 0 3 0 5 0 22 5A 86 4C 45 56 45 4C B4 E5 ......"Z.LEVEL..
OK
' LEVEL4 >BODY 10 DUMP
5A3E 2 0 3 0 5 0 7 0 4 44 55 4D 50 20 20 20 .........DUMP
OK
I'd like to hear about difficulties implementing
CREATE DOES> , what situation caused it to fail, so those of us writing our own Forths can more thoroughly test our implementations of
CREATE DOES>.
Cheers,
Jim