home *** CD-ROM | disk | FTP | other *** search
Null Bytes Alternating | 1995-05-19 | 6.3 KB | 86 lines |
- \ defer.utf
- \ Modifiable execution vectors
- \ ANS Forth compliant source code is Copyright (c)1994 by
- \ Jack J. Woehr, P.O. Box 51, Golden, Colorado 80402-0051
- \ jax@well.sf.ca.us 72203.1320@compuserve.com
- \ SYSOP RCFB (303) 278-0364 2400/9600/14400
- \ All Rights Reserved
- \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- \ This is free software and can be modified and redistributed under
- \ certain conditions described in the file COPYING.TXT. The
- \ Disclaimer of Warranty and License for this free software are also
- \ contained in the file COPYING.TXT.
- \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- \ Dependencies:
- \ CORE EXT
- \ <> TRUE
- \ A Standard System still exists after this code is loaded.
- \
- \ $Revision: 1.2 $
- \
-
- S" UTILS\UTILS.UTF" PROVIDES .(
-
- .( Loading DEFER ) CR
-
- MARKER defer.utf
-
- \ A default vector for DEFERred words
- : CRASH ( --) TRUE ABORT" Unitialized execution vector." ;
-
- \ A "guard word" to help identify words CREATEd by DEFER
- 0 CONSTANT DEFERRED
-
- \ Create a revectorable Forth word for a ROMmable system.
- \ This works in Vesta Forth Standard Edition for the SBC332.
- \ : ROM-DEFER ( "name" --)
- \ MODE? >R ROM ( Save RAM or ROM data space mode)
- \ CREATE ( CREATE ROM-style)
- \ RAM HERE ( Save this RAM address as pointer to xt)
- \ ['] CRASH , ( Default init, must re-init if ROMmed)
- \ ROM , ( Save RAM execution vector pointer from HERE)
- \ ['] DEFERRED , ( Tagged as a DEFERred word by xt of DEFERRED)
- \ R> ?MODE ( Restore previous mode)
- \ DOES> ( self-addr --)
- \ @ ( ram addr) @ ( xt) EXECUTE ( Runtime action: Fetch vector & execute)
- \ ;
-
- \ DEFER for RAM-only systems.
- \ This works in Jax4th and ZENForth.
- \ Yes, it would be simpler just to comma in the xt at the base of
- \ the CREATEd object. Using the "pointer-to" style is to illustrate
- \ how this construct doesn't port easily between RAM and ROM systems.
- : DEFER ( "name" --)
- CREATE HERE 2 CELLS + ,
- ['] DEFERRED ,
- ['] CRASH ,
- DOES> ( self-addr --)
- @ ( ptr to xt) @ ( xt) EXECUTE
- ;
-
- \ Hilevel state-smart revectorer IS.
- \ "name" is ostensibly DEFERred word
- \ Verifies that word was created by DEFER
- \ A clever application would avoid ABORT" and use CATCH .. THROW
- \ Not bulletproof, since the behaviour of >BODY if passed
- \ the execution token for a non-CREATE word is "ambiguous",
- \ which could mean anything from "who cares" to ABORT.
- : IS ( xt "name" | "name" --)
- ' >BODY DUP
- CELL+ @ ['] DEFERRED <>
- ABORT" IS on word not created by defer."
- STATE @ ( Compiling or interpreting?)
- IF ( Compiling .. at runtime, xt will be on stack)
- @
- POSTPONE LITERAL ( Compile vector holder address)
- POSTPONE ! ( At runtime, will store new vector)
- ELSE ( Interpreting, xt is on stack right now)
- @ ! ( Right now store new vector)
- THEN
- ; IMMEDIATE
-
- \ ~~~~~~~~~~~~~~~~
- \ End of DEFER.UTF
- \ ~~~~~~~~~~~~~~~~
-
-