--- gforth/cross.fs 2000/09/23 15:05:58 1.86 +++ gforth/cross.fs 2001/09/04 13:06:06 1.103 @@ -17,7 +17,7 @@ \ You should have received a copy of the GNU General Public License \ along with this program; if not, write to the Free Software -\ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +\ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. 0 [IF] @@ -628,100 +628,167 @@ stack-warn [IF] : defempty? ; immediate [THEN] -\ \ GhostNames Ghosts 9may93jaw +\ Ghost Builder 06oct92py -\ second name source to search trough list +hex +4711 Constant 4712 Constant +4713 Constant 4714 Constant +4715 Constant -VARIABLE GhostNames -0 GhostNames ! +1 Constant -: GhostName ( -- addr ) - align here GhostNames @ , GhostNames ! here 0 , - bl word count - \ 2dup type space - string, \ !! cfalign ? - align ; +Struct -\ Ghost Builder 06oct92py + \ link to next ghost (always the first element) + cell% field >next-ghost -\ new version with temp variable 10may93jaw + \ type of ghost + cell% field >magic + + \ pointer where ghost is in target, or if unresolved + \ points to the where we have to resolve (linked-list) + cell% field >link -VARIABLE VocTemp + \ execution symantics (while target compiling) of ghost + cell% field >exec -: previous VocTemp @ set-current ; + cell% field >exec-compile -hex -4711 Constant 4712 Constant -4713 Constant 4714 Constant -4715 Constant + cell% field >exec2 + + cell% field >created + + \ the xt of the created ghost word itself + cell% field >ghost-xt -\ iForth makes only immediate directly after create -\ make atonce trick! ? + \ pointer to the counted string of the assiciated + \ assembler label + cell% field >asm-name -Variable atonce atonce off + \ mapped primitives have a special address, so + \ we are able to detect them + cell% field >asm-dummyaddr + + \ for builder (create, variable...) words + \ the execution symantics of words built are placed here + \ this is a doer ghost or a dummy ghost + cell% field >do:ghost -: NoExec true ABORT" CROSS: Don't execute ghost, or immediate target word" ; + cell% field >ghost-flags -: GhostHeader , 0 , ['] NoExec , ; + cell% field >ghost-name -: >magic ; \ type of ghost -: >link cell+ ; \ pointer where ghost is in target, or if unresolved - \ points to the where we have to resolve (linked-list) -: >exec cell+ cell+ ; \ execution symantics (while target compiling) of ghost -: >end 3 cells + ; \ room for additional tags - \ for builder (create, variable...) words the - \ execution symantics of words built are placed here +End-Struct ghost-struct + +Variable ghost-list +0 ghost-list ! Variable executed-ghost \ last executed ghost, needed in tcreate and gdoes> -Variable last-ghost \ last ghost that is created +\ Variable last-ghost \ last ghost that is created Variable last-header-ghost \ last ghost definitions with header +\ space for ghosts resolve structure +\ we create ghosts in a sepearte space +\ and not to the current host dp, because this +\ gives trouble with instant while compiling and creating +\ a ghost for a forward reference +\ BTW: we cannot allocate another memory region +\ because allot will check the overflow!! +Variable cross-space-dp +Create cross-space 250000 allot here 100 allot align +Constant cross-space-end +cross-space cross-space-dp ! +Variable cross-space-dp-orig + +: cross-space-used cross-space-dp @ cross-space - ; + +: >space ( -- ) + dp @ cross-space-dp-orig ! + cross-space-dp @ dp ! ; + +: space> ( -- ) + dp @ dup cross-space-dp ! + cross-space-end u> ABORT" CROSS: cross-space overflow" + cross-space-dp-orig @ dp ! ; + +: execute-exec execute ; +: execute-exec2 execute ; +: execute-exec-compile execute ; + +: NoExec + executed-ghost @ >exec2 @ + ?dup + IF execute-exec2 + ELSE true ABORT" CROSS: Don't execute ghost, or immediate target word" + THEN ; + +: (ghostheader) ( -- ) + ghost-list linked , 0 , ['] NoExec , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , ; + +: ghostheader ( -- ) (ghostheader) 0 , ; + +' Ghosts >wordlist Constant ghosts-wordlist + +\ the current wordlist for ghost definitions in the host +ghosts-wordlist Value current-ghosts + : Make-Ghost ( "name" -- ghost ) - >in @ GhostName swap >in ! - - dup last-ghost ! - DOES> dup executed-ghost ! >exec @ execute ; + >space + \ save current and create in ghost vocabulary + get-current >r current-ghosts set-current + >in @ Create >in ! + \ some forth systems like iForth need the immediate directly + \ after the word is created + \ restore current + r> set-current + here (ghostheader) + bl word count string, align + space> + \ set ghost-xt field by doing a search + dup >ghost-name count + current-ghosts search-wordlist + 0= ABORT" CROSS: Just created, must be there!" + over >ghost-xt ! + DOES> + dup executed-ghost ! + >exec @ execute-exec ; \ ghost words 14oct92py \ changed: 10may93py/jaw -: gfind ( string -- ghost true/1 / string false ) +Defer search-ghosts + +: (search-ghosts) ( adr len -- cfa true | 0 ) + current-ghosts search-wordlist ; + + ' (search-ghosts) IS search-ghosts + +: gsearch ( addr len -- ghost true | 0 ) + search-ghosts + dup IF swap >body swap THEN ; + +: gfind ( string -- ghost true / string false ) \ searches for string in word-list ghosts - dup count [ ' ghosts >wordlist ] Literal search-wordlist - dup IF >r >body nip r> THEN ; + \ dup count type space + dup >r count gsearch + dup IF rdrop ELSE r> swap THEN ; : gdiscover ( xt -- ghost true | xt false ) - GhostNames + >r ghost-list BEGIN @ dup - WHILE 2dup - cell+ @ dup >magic @ <> - >r >link @ = r> and - IF cell+ @ nip true EXIT THEN + WHILE dup >magic @ <> + IF dup >link @ r@ = + IF rdrop true EXIT THEN + THEN REPEAT - drop false ; - -VARIABLE Already + drop r> false ; -: ghost ( "name" -- ghost ) - Already off - >in @ bl word gfind IF atonce off Already on nip EXIT THEN +: Ghost ( "name" -- ghost ) + >in @ bl word gfind IF nip EXIT THEN drop >in ! Make-Ghost ; : >ghostname ( ghost -- adr len ) - GhostNames - BEGIN @ dup - WHILE 2dup cell+ @ = - UNTIL nip 2 cells + count - ELSE 2drop - \ true abort" CROSS: Ghostnames inconsistent" - s" ?!?!?!" - THEN ; - -: .ghost ( ghost -- ) >ghostname type ; - -\ ' >ghostname ALIAS @name + >ghost-name count ; : forward? ( ghost -- flag ) >magic @ = ; @@ -729,51 +796,133 @@ VARIABLE Already : undefined? ( ghost -- flag ) >magic @ dup = swap = or ; +: immediate? ( ghost -- flag ) + >magic @ = ; + +Variable TWarnings +TWarnings on +Variable Exists-Warnings +Exists-Warnings on + +: exists-warning ( ghost -- ghost ) + TWarnings @ Exists-Warnings @ and + IF dup >ghostname warnhead type ." exists " THEN ; + +\ : HeaderGhost Ghost ; + +Variable reuse-ghosts reuse-ghosts off + +1 [IF] \ FIXME: define when vocs are ready +: HeaderGhost ( "name" -- ghost ) + >in @ + bl word count +\ 2dup type space + current-ghosts search-wordlist + IF >body dup undefined? reuse-ghosts @ or + IF nip EXIT + ELSE exists-warning + THEN + drop >in ! + ELSE >in ! + THEN + \ we keep the execution semantics of the prviously + \ defined words, this is a workaround + \ for the redefined \ until vocs work + Make-Ghost ; +[THEN] + + +: .ghost ( ghost -- ) >ghostname type ; + +\ ' >ghostname ALIAS @name + +: [G'] ( -- ghost : name ) +\G ticks a ghost and returns its address +\ bl word gfind 0= ABORT" CROSS: Ghost don't exists" + ghost state @ IF postpone literal THEN ; immediate + +: ghost>cfa ( ghost -- cfa ) + dup undefined? ABORT" CROSS: forward " >link @ ; + +1 Constant