home *** CD-ROM | disk | FTP | other *** search
- \ BEHEAD - Headerless words for F-PC by George T. Hawkins
-
- \ Updated 24nov89, Gene Czarcinski
- \ . Merge some of George Hawkins' enhancements to BEHEADing
- \ into a version for F-PC 3.50
- \ . Fix bug: when the PASM386 was being processed in
- \ beheading mode, the space for regular defs was
- \ insufficient and overlapped the headerless headers.
- \ Change YDP-SHIFT so there is more space.
-
- comment:
-
- The words "headerless", "headers", and "behead" can be
- used together to provide a headerless word capability in
- F-PC.
-
- Although the use of headerless words can save you head
- space, their main advantage is in the software
- engineering they provide. That is, the definitions/
- names are *completely lost* not just stashed away in
- some obscure vocabulary.
-
- In general, during testing, you should set up your
- {headerless/headers}/ behead definitions as described
- above, but proceed it with a single "hwords-". The
- hwords- word will cause headerless, headers, and behead
- to be treated as noops. Once you've finished debugging
- and are ready to go production, then change the
- "hwords-" to "hwords+" (or, better still, simply remove
- the "hwords-" word). This will give the headerless,
- headers, and behead words their standard meaning.
- (Note: If you ever need to debug the code again, and
- want to see the names, then change hwords+ to hwords-
- (or re-insert a preliminary hwords-). Also note that
- the hwords-/+ word is global during a compilation
- session and extends across colon definitions and
- FLOAD's.)
-
- comment;
-
- only forth also hidden also
-
- forth definitions
-
- FALSE value haudit
- \
- \ A boolean variable which, if TRUE, automatically audits
- \ for beheading violations. That is, you will receive
- \ error notifiction if:
- \
- \ 1) The search order (after CONTEXT) is modified
- \ on any subsequent invocation of
- \ "headerless", any invocation of "headers",
- \ or the final invocation of "behead";
- \
- \ 2) You attempt to behead words across multiple
- \ FLOAD's.
- \
- \ If either type error above occurs, you are given the
- \ appropriate diagnostic information and allowed the
- \ choice of either continuing the compilation session or
- \ aborting it.
- \
- \ Although "haudit" initially defaults to FALSE, I
- \ recommend that you set it to TRUE via:
- \
- \ HAUDIT+
-
- : haudit+ ( -- )
- \ Enables automatic audit for beheading violations.
- TRUE !> haudit ;
-
- : haudit- ( -- )
- \ Disables automatic audit for beheading violations.
- FALSE !> haudit ;
-
- hidden definitions
-
- create h-pvoc \ the headerless pseudo vocabulary
-
- #threads 2* allot \ thread area
-
- : hv-insert ( -- )
- \ Initializes and inserts the headerless pseudo vocabulary
- \ into the search order.
- h-pvoc [ #threads 2* literal ] erase
- context @ \ save context on stack
- h-pvoc context !
- also \ insert headerless pseudo voc
- context ! ; \ restore current context
-
- 0 value sv-context \ saved context
- 0 value sv-current \ saved current
-
- : cc-save ( -- )
- \ saves context & current
- context @ !> sv-context
- current @ !> sv-current ;
-
- : cc-rest ( -- )
- \ restores context & current
- sv-context context !
- sv-current current ! ;
-
-
- 0 value ydp-reg \ the "regular" ydp
-
- 0 value ydp-hw \ the "headerless" ydp
-
- 0 value h-state \ keeps track of the "state" of the headerless
- \ word definitions. It has the following
- \ values and interpretations:
- \
- \ h-state meaning:
- \
- \ 0 in start or behead state
- \ 1 in initial headerless state
- \ 2 in headers state
- \ 3 in subsequent headerless state
-
- : ydp-shift ( -- )
- \ sets offset for headerless words
- #headsegs 16 * yhere - u2/
- 7000 \ sufficient space for PASM386
- 2dup u> IF swap THEN drop \ pick smaller of the two
- yhere + !> ydp-hw ;
-
- create init-fl b/hcb allot \ Stores the name of the currently loaded file
-
- create init-order #vocs 1- 2* allot \ stores vocab order
-
- 0 value init-ll \ initial load line
-
- : save-flo ( -- )
- \ save file status: name of file, line and search order
- seqhandle count init-fl place
- loadline @ !> init-ll
- context 2+ init-order [ #vocs 1- 2* literal ] cmove ;
-
- : sorder. ( addr -- )
- \ Prints search order (not including context) from address:
- cr ." Search order (after context):" cr
- [ #vocs 1- literal ] 0 DO
- dup @ ?dup IF
- body> >name .id
- THEN
- 2+
- LOOP
- drop ;
-
- : any-key ( -- )
- \ pause
- cr ." Press <ESC> to abort or any other key to continue"
- key $1B = IF abort THEN ;
-
- 0 value order-off
-
- \ Defines the initial context array offset to begin comparing
- \ the search order. The initial context array is saved with
- \ the vocabulary after CONTEXT in the search order. When in a
- \ "headers" state, the context array search should be started
- \ at offset 2. When in a "headerless" state, the context
- \ array search should be started at offset 3. After final
- \ beheading (and the initial order is restored), the context
- \ array search should be started at offset 1.
- \
- \ Note that this value is not absolutely necessary. That is,
- \ by judicious placement of "same-order?" and "horder-err" a
- \ constant offset can be assumed. This seems not to be worth
- \ the effort considering the loss of generality involved along
- \ with the insignificnat time/overhead considerations.
-
- : same-order? ( -- f )
- \ Compares the current search order with init-order. The
- \ initial context array offset is specified by "order-off".
- \ Returns TRUE if they are different.
- haudit not IF
- FALSE exit
- THEN
- FALSE ( assume the same )
- #vocs order-off DO
- I 2* context + @
- I order-off - 2* init-order + @
- 2dup <> IF
- 3drop TRUE leave
- THEN
- + 0= ?leave
- LOOP ;
-
- : ifi. ( -- )
- \ Prints initial file info.
- cr ." Initial load file: " init-fl count type
- cr ." Initial load line: " init-ll . ;
-
- : cfi. ( -- )
- \ Prints current file info.
- cr ." Current load file: " seqhandle count type
- cr ." Current load line: " loadline @ . ;
-
- : horder-err ( -- )
- \ Informs user that a search order modification has occurred
- \ between the initial invocation of "headerless" and the final
- \ "behead". Prints out diagnostic information and
- \ conditionally aborts.
- cr ." Beheading error: search order modified"
- ifi.
- init-order sorder.
- cfi.
- context order-off 2* + sorder. any-key ;
-
- : same-file? ( -- f )
- \ Compares the current load file with the initial headerless
- \ call load file. Returns TRUE if they are different.
- haudit not IF
- FALSE exit
- THEN
- init-fl c@ seqhandle c@ <> IF TRUE exit THEN
- init-fl 1+ seqhandle 1+ seqhandle c@ caps-comp ;
-
- : hfile-err ( -- )
- \ Informs user that a multiple file behead has occurred
- \ between the initial invocation of "headerless" and the final
- \ "behead". Prints out diagnostic information and
- \ conditionally aborts.
- cr ." Multiple file beheading"
- ifi. cfi. any-key ;
-
-
- forth definitions
-
- defer headerless ( -- )
- \ initiates/continues headerless word definitions
-
- defer headers ( -- )
- \ continues headers from a prior headerless word state
- \ NOTE: HEADERLESS must be used first.
-
- defer behead ( -- )
- \ beheads all headerless words
- \ NOTE: must be in a "headers" state
-
- hidden definitions
-
- : _headerless ( -- )
- \ initiates headerless words
- h-state 1 and IF
- cr ." *** Currently in headerless state ***"
- ELSE
- yhere !> ydp-reg \ save regular ydp
- cc-save \ save context & current
- h-state IF \ return to headerless state
- \ NOTE: current state is headers
- 2 !> order-off \ set context offset
- same-order? IF \
- horder-err \ inform user of order error
- THEN \
- 3 !> h-state \ set state
- ELSE \ initial headerless state
- save-flo \ save relevant state data
- hv-insert \ insert headerless pvoc
- ydp-shift \ shift ydp
- 1 !> h-state \ set state
- THEN
- also \ put context in search order
- h-pvoc current ! \ defs to pseudo voc
- h-pvoc context ! \ also as context
- ydp-hw ydp ! \ set/restore headerless ydp
- THEN ;
-
- : _headers ( -- )
- \ restores regular words
- h-state 1 and IF
- \ NOTE: current state is headerless
- 3 !> order-off \ set context offset
- same-order? IF \
- horder-err \ inform user of order error
- THEN
- yhere !> ydp-hw \ save headerless ydp
- ydp-reg ydp ! \ restore regular ydp
- 2 !> h-state \ set state
- previous \ remove context from search order
- cc-rest \ restore context & current
- ELSE
- cr ." *** Must use headerless first ***"
- THEN ;
-
- : _behead ( -- )
- \ beheads headerless words
- h-state 1 and IF
- cr ." *** Must use headers first ***"
- ELSE
- h-state IF
- 0 !> h-state \ set state
- cc-save \ save context & current
- previous \ remove headerless pvoc
- cc-rest \ restore context & current
- \ NOTE: search order restored
- same-file? IF \
- hfile-err \ inform user of file error
- THEN \
- 1 !> order-off \ set context offset
- same-order? IF \
- horder-err \ inform user of order error
- THEN \
- ELSE
- cr ." *** Nothing to behead ***"
- THEN
- THEN ;
-
- forth definitions
-
- 0 value beheadable \ allow the meta compiler to know that we are either
- \ beheading or we are NOT beheading.
- \ Tom Zimmer 12/06/88 15:26:12.57
-
- : hwords+ ( -- )
- \ enables headerless words capability
- ['] _headerless is headerless
- ['] _headers is headers
- ['] _behead is behead
- 0 !> h-state
- on> beheadable ;
-
- hwords+
-
- : hwords- ( -- )
- \ disables headerless words capability
- ['] noop is headerless
- ['] noop is headers
- ['] noop is behead
- off> beheadable ;
-
-
- only forth also definitions
-
-
-