sjack
2024-10-31 15:13:36 UTC
A while ago I reworked all my source to use many vocabularies to test
the FigForth vocabulary design. The many vocabularies were not so much
to deal with scoping but to break the dictionary search into many smaller
paths. I found it not to be much of a problem, but a little awearness of
what affects CONTEXT change is essential.
Vocabulary usage demo
..CURRENT and CONTEXT are WRK BASE: 10 Latest: FIO
-VOC \ save original CURRENT
FIO \ set CONTEXT to FIO
open pad/txt/rubyatLI to hdi \ data input handle
create /tmp/foo to hdo \ data output handle
--
-- CONTEXT must be set to FIO in following compile because
-- colon start will reset CONTEXT to CURRENT.
-- After compile, CONTEXT will still be FIO.
--
{ FIO begin mpad0 512 read dup while write repeat 2drop }
{} \ run anonymous
0 close \ close data input
1 close \ close data output
-- See the created file
sys cat /tmp/foo
LI.
The Moving Finger writes; and, having writ,
Moves on: nor all thy Piety nor Wit
Shall lure it back to cancel half a Line,
Nor all thy Tears wash out a Word of it.
--
-- -VOC and +VOC were made to restore CONTEXT to saved CURRENT
-- for the benefit of FORGET MARKER and ANEW which require
-- CURRENT and CONTEXT to be the same.
--
+VOC \ restsore CONTEXT to original CURRENT
{fin} \ release anonymous memory
..CURRENT and CONTEXT are WRK BASE: 10 Latest: FIO
--
-- -VOC saved original CURRENT
-- FIO set CONTEXT for open and create
-- FIO set CONTEXT in anonymous compile { ... }
-- CONTEXT is still FIO for close
-- +VOC restored CONTEXT to original CURRENT
-- ( CURRENT never changed in this example )
-fin-
the FigForth vocabulary design. The many vocabularies were not so much
to deal with scoping but to break the dictionary search into many smaller
paths. I found it not to be much of a problem, but a little awearness of
what affects CONTEXT change is essential.
Vocabulary usage demo
..CURRENT and CONTEXT are WRK BASE: 10 Latest: FIO
-VOC \ save original CURRENT
FIO \ set CONTEXT to FIO
open pad/txt/rubyatLI to hdi \ data input handle
create /tmp/foo to hdo \ data output handle
--
-- CONTEXT must be set to FIO in following compile because
-- colon start will reset CONTEXT to CURRENT.
-- After compile, CONTEXT will still be FIO.
--
{ FIO begin mpad0 512 read dup while write repeat 2drop }
{} \ run anonymous
0 close \ close data input
1 close \ close data output
-- See the created file
sys cat /tmp/foo
LI.
The Moving Finger writes; and, having writ,
Moves on: nor all thy Piety nor Wit
Shall lure it back to cancel half a Line,
Nor all thy Tears wash out a Word of it.
--
-- -VOC and +VOC were made to restore CONTEXT to saved CURRENT
-- for the benefit of FORGET MARKER and ANEW which require
-- CURRENT and CONTEXT to be the same.
--
+VOC \ restsore CONTEXT to original CURRENT
{fin} \ release anonymous memory
..CURRENT and CONTEXT are WRK BASE: 10 Latest: FIO
--
-- -VOC saved original CURRENT
-- FIO set CONTEXT for open and create
-- FIO set CONTEXT in anonymous compile { ... }
-- CONTEXT is still FIO for close
-- +VOC restored CONTEXT to original CURRENT
-- ( CURRENT never changed in this example )
-fin-