retroforth/example/Marker.forth
crc f18ba7d573 add example of a Marker word to restore the dictionary and heap pointers
FossilOrigin-Name: 178319a0c34517aea1a03eca369e581b7266a9fc5ad65c998bc6a02dee6fe568
2019-01-23 01:50:05 +00:00

27 lines
486 B
Forth

Marker provides a way to quickly reset the dictionary and heap
to the state it was in prior to the creation of the marker.
## The Code
~~~
:class:marker (a-)
compiling? [ compile:lit &class:marker compile:call ]
[ fetch-next !Dictionary fetch !Heap ] choose ;
:marker (s-) [ @Heap @Dictionary ] dip d:create , , &class:marker reclass ;
~~~
## A Test Case
```
:a #1 #2 #3 ;
:b a + + ;
:c b n:put nl ;
c
'd marker
:a #4 #5 #6 ;
:b a + + ;
:c b n:put nl ;
c
d
c
```