\ An implementation of CREATE DOES> and >BODY overtop of Gforth's existing one,
\ for illustration. Tested under Gforth 0.6.2.
\ Neal Bridges, 2006. neal@quartus.net
variable latestcreate
: CREATE
:
here cell+ >r \ save this to backpatch the dataspace literal
0 postpone literal
here cell+ latestcreate ! \ save this for DOES> to backpatch the xt literal later
['] noop postpone literal postpone execute
postpone ;
here r> ! \ backpatch the dataspace pointer
;
: (does) ( xt -- ) latestcreate @ ! ;
: DOES>
here cell+ >r \ save this to backpatch the literal
['] noop postpone literal
postpone (does)
postpone ; \ terminate the current definition
here r> ! \ backpatch the literal with the xt of the subsequent code
(:noname) \ begin a new headerless word that doesn't leave an xt on the stack at ; time
; immediate
: >BODY
3 cells + @ \ this works in Gforth to retrieve the dataspace pointer from our CREATEs
;