File:  [gforth] / gforth / cross.fs
Revision 1.5: download - view: text, annotated - select for diffs
Wed Jun 1 10:05:14 1994 UTC (29 years, 9 months ago) by pazsan
Branches: MAIN
CVS tags: HEAD
added an experimental hash table (search/order.fs)
allowed the user to select caps-stored names or even case-
sensitive search.
Made gforth.texi compilable.

    1: \ CROSS.FS     The Cross-Compiler                      06oct92py
    2: \ $Id: cross.fs,v 1.5 1994/06/01 10:05:14 pazsan Exp $
    3: \ Idea and implementation: Bernd Paysan (py)
    4: \ Copyright 1992 by the ANSI figForth Development Group
    5: 
    6: \ Log:
    7: \       changed in ; [ to state off           12may93jaw
    8: \       included place +place                 12may93jaw
    9: \       for a created word (variable, constant...)
   10: \       is now an alias in the target voabulary.
   11: \       this means it is no longer necessary to
   12: \       switch between vocabularies for variable
   13: \       initialization                        12may93jaw
   14: \       discovered error in DOES>
   15: \       replaced !does with (;code)           16may93jaw
   16: \       made complete redesign and
   17: \       introduced two vocs method
   18: \       to be asure that the right words
   19: \       are found                             08jun93jaw
   20: \       btw:  ! works not with 16 bit
   21: \             targets                         09jun93jaw
   22: \       added: 2user and value                11jun93jaw
   23: 
   24: include other.fs       \ ansforth extentions for cross
   25: 
   26: : comment? ( c-addr u -- c-addr u )
   27:         2dup s" (" compare 0=
   28:         IF    postpone (
   29:         ELSE  2dup s" \" compare 0= IF postpone \ THEN
   30:         THEN ;
   31: 
   32: decimal
   33: 
   34: \ number?                                               11may93jaw
   35: 
   36: \ checks for +, -, $, & ...
   37: : leading? ( c-addr u -- c-addr u doubleflag negflag base )
   38:         2dup 1- chars + c@ [char] . =   \ process double
   39:         IF dup 1 chars = IF over 1 swap c! false ELSE 1 chars - true THEN
   40:         \ only if more than only . ( may be number output! )
   41:         \ if only . => store garbage
   42:         ELSE false THEN >r      \ numbers
   43:         false -rot base @ -rot
   44:         BEGIN over c@
   45:                 dup [char] - =
   46:                         IF drop >r >r >r
   47:                            drop true r> r> r> 0 THEN
   48:                 dup [char] + =
   49:                         IF drop 0 THEN
   50:                 dup [char] $ =
   51:                         IF drop >r >r drop 16 r> r> 0 THEN
   52:                 dup [char] & =
   53:                         IF drop >r >r drop 10 r> r> 0 THEN
   54:               0= IF 1 chars - swap char+ swap false ELSE true THEN
   55:               over 0= or
   56:         UNTIL
   57:               rot >r rot r> r> -rot ;
   58: 
   59: : number? ( c-addr -- n/d flag )
   60: \ return -1 if cell 1 if double 0 if garbage
   61:                 0 swap 0 swap           \ create double number
   62:                 count leading?
   63:                 base @ >r base !
   64:                 >r >r
   65:                 >number IF 2drop false r> r> 2drop
   66:                            r> base ! EXIT THEN
   67:                 drop r> r>
   68:                 IF IF dnegate 1
   69:                    ELSE drop negate -1 THEN
   70:                 ELSE IF 1 ELSE drop -1 THEN
   71:                 THEN r> base ! ;
   72: 
   73: 
   74: 
   75: \ Begin CROSS COMPILER:
   76: 
   77: \ GhostNames                                            9may93jaw
   78: \ second name source to search trough list
   79: 
   80: VARIABLE GhostNames
   81: 0 GhostNames !
   82: : GhostName ( -- addr )
   83:         here GhostNames @ , GhostNames ! here 0 ,
   84:         name count
   85: \        2dup type space
   86:         dup c, here over chars allot swap move align ;
   87: 
   88: hex
   89: 
   90: 
   91: Vocabulary Cross
   92: Vocabulary Target
   93: Vocabulary Ghosts
   94: VOCABULARY Minimal
   95: only Forth also Target also also
   96: definitions Forth
   97: 
   98: : T  previous Cross also Target ; immediate
   99: : G  Ghosts ; immediate
  100: : H  previous Forth also Cross ; immediate
  101: 
  102: forth definitions
  103: 
  104: : T  previous Cross also Target ; immediate
  105: : G  Ghosts ; immediate
  106: 
  107: : >cross  also Cross definitions previous ;
  108: : >target also Target definitions previous ;
  109: : >minimal also Minimal definitions previous ;
  110: 
  111: H
  112: 
  113: >CROSS
  114: 
  115: \ Variables                                            06oct92py
  116: 
  117: -1 Constant NIL
  118: Variable image
  119: Variable tlast    NIL tlast !  \ Last name field
  120: Variable tlastcfa \ Last code field
  121: Variable tdoes    \ Resolve does> calls
  122: Variable bit$
  123: Variable tdp
  124: : there  tdp @ ;
  125: 
  126: \ Parameter for target systems                         06oct92py
  127: 
  128: include machine.fs
  129: 
  130: >TARGET
  131: 
  132: \ Byte ordering and cell size                          06oct92py
  133: 
  134: : cell+         cell + ;
  135: : cells         cell<< lshift ;
  136: : chars         ;
  137: 
  138: >CROSS
  139: : cell/         cell<< rshift ;
  140: >TARGET
  141: 20 CONSTANT bl
  142: -1 Constant NIL
  143: -2 Constant :docol
  144: -3 Constant :docon
  145: -4 Constant :dovar
  146: -5 Constant :douser
  147: -6 Constant :dodoes
  148: -7 Constant :doesjump
  149: 
  150: >CROSS
  151: 
  152: endian  0 pad ! -1 pad c! pad @ 0<
  153: = [IF]   : bswap ; immediate 
  154: [ELSE]   : bswap ( big / little -- little / big )  0
  155:            cell 1- FOR  bits/byte lshift over
  156:                         [ 1 bits/byte lshift 1- ] Literal and or
  157:                         swap bits/byte rshift swap  NEXT  nip ;
  158: [THEN]
  159: 
  160: \ Memory initialisation                                05dec92py
  161: \ Fixed bug in else part                               11may93jaw
  162: 
  163: [IFDEF] Memory \ Memory is a bigFORTH feature
  164:    also Memory
  165:    : initmem ( var len -- )
  166:      2dup swap handle! >r @ r> erase ;
  167:    toss
  168: [ELSE]
  169:    : initmem ( var len -- )
  170:      tuck allocate abort" CROSS: No memory for target"
  171:      ( len var adr ) dup rot !
  172:      ( len adr ) swap erase ;
  173: [THEN]
  174: 
  175: \ MakeKernal                                           12dec92py
  176: 
  177: >MINIMAL
  178: : makekernal ( targetsize -- targetsize )
  179:   bit$  over 1- cell>bit rshift 1+ initmem
  180:   image over initmem tdp off ;
  181: 
  182: >CROSS
  183: \ Bit string manipulation                               06oct92py
  184: \                                                       9may93jaw
  185: CREATE Bittable 80 c, 40 c, 20 c, 10 c, 8 c, 4 c, 2 c, 1 c,
  186: : bits ( n -- n ) chars Bittable + c@ ;
  187: 
  188: : >bit ( addr n -- c-addr mask ) 8 /mod rot + swap bits ;
  189: : +bit ( addr n -- )  >bit over c@ or swap c! ;
  190: : -bit ( addr n -- )  >bit invert over c@ and swap c! ;
  191: : relon ( taddr -- )  bit$ @ swap cell/ +bit ;
  192: : reloff ( taddr -- )  bit$ @ swap cell/ -bit ;
  193: 
  194: \ Target memory access                                 06oct92py
  195: 
  196: : align+  ( taddr -- rest )
  197:     cell tuck 1- and - [ cell 1- ] Literal and ;
  198: 
  199: >TARGET
  200: : aligned ( taddr -- ta-addr )  dup align+ + ;
  201: \ assumes cell alignment granularity (as GNU C)
  202: 
  203: >CROSS
  204: : >image ( taddr -- absaddr )  image @ + ;
  205: >TARGET
  206: : @  ( taddr -- w )     >image @ bswap ;
  207: : !  ( w taddr -- )     >r bswap r> >image ! ;
  208: : c@ ( taddr -- char )  >image c@ ;
  209: : c! ( char taddr -- )  >image c! ;
  210: 
  211: \ Target compilation primitives                        06oct92py
  212: \ included A!                                          16may93jaw
  213: 
  214: : here  ( -- there )    there ;
  215: : allot ( n -- )        tdp +! ;
  216: : ,     ( w -- )        T here H cell T allot  ! H ;
  217: : c,    ( char -- )     T here    1 allot c! H ;
  218: : align ( -- )          T here H align+ 0 ?DO  bl T c, H LOOP ;
  219: 
  220: : A!                    dup relon T ! H ;
  221: : A,    ( w -- )        T here H relon T , H ;
  222: 
  223: >CROSS
  224: 
  225: \ threading modell                                     13dec92py
  226: 
  227: \ generic threading modell
  228: : docol,  ( -- ) :docol T A, 0 , H ;
  229: 
  230: >TARGET
  231: : >body   ( cfa -- pfa ) T cell+ cell+ H ;
  232: >CROSS
  233: 
  234: : dodoes, ( -- ) T :doesjump A, 0 , H ;
  235: 
  236: \ Ghost Builder                                        06oct92py
  237: 
  238: \ <T T> new version with temp variable                 10may93jaw
  239: 
  240: VARIABLE VocTemp
  241: 
  242: : <T  get-current VocTemp ! also Ghosts definitions ;
  243: : T>  previous VocTemp @ set-current ;
  244: 
  245: 4711 Constant <fwd>             4712 Constant <res>
  246: 4713 Constant <imm>
  247: 
  248: \ iForth makes only immediate directly after create
  249: \ make atonce trick! ?
  250: 
  251: Variable atonce atonce off
  252: 
  253: : NoExec true ABORT" CROSS: Don't execute ghost" ;
  254: 
  255: : GhostHeader <fwd> , 0 , ['] NoExec , ;
  256: 
  257: : >magic ; : >link cell+ ; : >exec cell+ cell+ ;
  258: : >end 3 cells + ;
  259: 
  260: : Make-Ghost ( "name" -- ghost )
  261:   >in @ GhostName swap >in !
  262:   <T Create atonce @ IF immediate atonce off THEN
  263:   here tuck swap ! ghostheader T>
  264:   DOES>  >exec @ execute ;
  265: 
  266: \ ghost words                                          14oct92py
  267: \                                          changed:    10may93py/jaw
  268: 
  269: : gfind   ( string -- ghost true/1 / string false )
  270: \ searches for string in word-list ghosts
  271: \ !! wouldn't it be simpler to just use search-wordlist ? ae
  272:   dup count [ ' ghosts >body ] ALiteral search-wordlist
  273: \ >r get-order  0 set-order also ghosts  r> find >r >r
  274:   >r r@ IF  >body nip  THEN  r> ;
  275: \ set-order  r> r@  IF  >body  THEN  r> ;
  276: 
  277: VARIABLE Already
  278: 
  279: : ghost   ( "name" -- ghost )
  280:   Already off
  281:   >in @  name gfind   IF  Already on nip EXIT  THEN
  282:   drop  >in !  Make-Ghost ;
  283: 
  284: \ resolve                                              14oct92py
  285: 
  286: : resolve-loop ( ghost tcfa -- ghost tcfa )
  287:   >r dup >link @
  288:   BEGIN  dup  WHILE  dup T @ H r@ rot T ! H REPEAT  drop r> ;
  289: 
  290: \ exists                                                9may93jaw
  291: 
  292: : exists ( ghost tcfa -- )
  293:   over GhostNames
  294:   BEGIN @ dup
  295:   WHILE 2dup cell+ @ =
  296:   UNTIL
  297:         nip 2 cells + count cr ." CROSS: Exists: " type 4 spaces
  298:         swap cell+ !
  299:   ELSE true ABORT" CROSS: Ghostnames inconsistent"
  300:   THEN ;
  301: 
  302: : resolve  ( ghost tcfa -- )
  303:   over >magic @ <fwd> <>  IF  exists EXIT THEN
  304:   resolve-loop  over >link ! <res> swap >magic ! ;
  305: 
  306: \ gexecute ghost,                                      01nov92py
  307: 
  308: : do-forward   ( ghost -- )
  309:   >link dup @  there rot !  T  A,  H ;
  310: : do-resolve   ( ghost -- )
  311:   >link @                   T  A,  H ;
  312: 
  313: : gexecute   ( ghost -- )   dup @
  314:              <fwd> = IF  do-forward  ELSE  do-resolve  THEN ;
  315: : ghost,     ghost  gexecute ;
  316: 
  317: \ .unresolved                                          11may93jaw
  318: 
  319: variable ResolveFlag
  320: 
  321: \ ?touched                                             11may93jaw
  322: 
  323: : ?touched ( ghost -- flag ) dup >magic @ <fwd> = swap >link @
  324:                                0 <> and ;
  325: 
  326: : ?resolved  ( ghostname -- )
  327:   dup cell+ @ ?touched
  328:   IF  cell+ cell+ count cr type ResolveFlag on ELSE drop THEN ;
  329: 
  330: >MINIMAL
  331: : .unresolved  ( -- )
  332:   ResolveFlag off cr ." Unresolved: "
  333:   Ghostnames
  334:   BEGIN @ dup
  335:   WHILE dup ?resolved
  336:   REPEAT drop ResolveFlag @ 0= IF ." Nothing!" THEN cr ;
  337: 
  338: >CROSS
  339: \ Header states                                        12dec92py
  340: 
  341: : flag! ( 8b -- )   tlast @ dup >r T c@ xor r> c! H ;
  342: 
  343: VARIABLE ^imm
  344: 
  345: >TARGET
  346: : immediate     20 flag!
  347:                 ^imm @ @ dup <imm> = ?EXIT
  348:                 <res> <> ABORT" CROSS: Cannot immediate a unresolved word"
  349:                 <imm> ^imm @ ! ;
  350: : restrict      ;
  351: >CROSS
  352: 
  353: \ ALIAS2 ansforth conform alias                          9may93jaw
  354: 
  355: : ALIAS2 create here 0 , DOES> @ execute ;
  356: \ usage:
  357: \ ' alias2 bla !
  358: 
  359: \ Target Header Creation                               01nov92py
  360: 
  361: : string,  ( addr count -- )
  362:   dup T c, H bounds  DO  I c@ T c, H  LOOP ; 
  363: : name,  ( "name" -- )  name count string, T align H ;
  364: : view,   ( -- ) ( dummy ) ;
  365: 
  366: VARIABLE CreateFlag CreateFlag off
  367: 
  368: : (Theader ( "name" -- ghost ) T align H view,
  369:   tlast @ dup 0> IF  T 1 cells - THEN  A, H  there tlast !
  370:   >in @ name, >in ! T here H tlastcfa !
  371:   CreateFlag @ IF
  372:   >in @ alias2 swap >in !         \ create alias in target
  373:   >in @ ghost swap >in !
  374:   swap also ghosts ' previous swap !        \ tick ghost and store in alias
  375:   CreateFlag off
  376:   ELSE ghost THEN
  377:   dup >magic ^imm !     \ a pointer for immediate
  378:   Already @ IF  dup >end tdoes !
  379:   ELSE 0 tdoes ! THEN
  380:   80 flag! ;
  381: 
  382: VARIABLE ;Resolve 1 cells allot
  383: 
  384: : Theader  ( "name" -- )     (THeader there resolve 0 ;Resolve ! ;
  385: 
  386: >TARGET
  387: : Alias    ( cfa -- ) \ name
  388:   (THeader over resolve T A, H 80 flag! ;
  389: >CROSS
  390: 
  391: \ Conditionals and Comments                            11may93jaw
  392: 
  393: : ;Cond
  394:   postpone ;
  395:   swap ! ;  immediate
  396: 
  397: : Cond: ( -- ) \ name {code } ;
  398:   atonce on
  399:   ghost
  400:   >exec
  401:   :NONAME ;
  402: 
  403: : restrict? ( -- )
  404: \ aborts on interprete state - ae
  405:   state @ 0= ABORT" CROSS: Restricted" ;
  406: 
  407: : Comment ( -- )
  408:   >in @ atonce on ghost swap >in ! ' swap >exec ! ;
  409: 
  410: Comment (       Comment \
  411: 
  412: \ Predefined ghosts                                    12dec92py
  413: 
  414: ghost 0=                                        drop
  415: ghost branch    ghost ?branch                   2drop
  416: ghost (do)      ghost (?do)                     2drop
  417: ghost (for)                                     drop
  418: ghost (loop)    ghost (+loop)                   2drop
  419: ghost (next)                                    drop
  420: ghost unloop    ghost ;S                        2drop
  421: ghost lit       ghost (compile) ghost !         2drop drop
  422: ghost (;code)   ghost noop                      2drop
  423: ghost (.")      ghost (S")      ghost (ABORT")  2drop drop
  424: 
  425: \ compile                                              10may93jaw
  426: 
  427: : compile  ( -- ) \ name
  428:   restrict?
  429:   name gfind dup 0= ABORT" CROSS: Can't compile "
  430:   0> ( immediate? )
  431:   IF    >exec @ compile,
  432:   ELSE  postpone literal postpone gexecute  THEN ;
  433:                                         immediate
  434: 
  435: >TARGET
  436: : '  ( -- cfa ) name gfind 0= ABORT" CROSS: undefined "
  437:   dup >magic @ <fwd> = ABORT" CROSS: forward " >link @ ;
  438: 
  439: Cond: [']  compile lit ghost gexecute ;Cond
  440: 
  441: >CROSS
  442: \ tLiteral                                             12dec92py
  443: 
  444: : lit, ( n -- )   compile lit T  ,  H ;
  445: : alit, ( n -- )  compile lit T A,  H ;
  446: 
  447: >TARGET
  448: Cond:  Literal ( n -- )   restrict? lit, ;Cond
  449: Cond: ALiteral ( n -- )   restrict? alit, ;Cond
  450: 
  451: : Char ( "<char>" -- )  bl word char+ c@ ;
  452: Cond: [Char]   ( "<char>" -- )  restrict? Char  lit, ;Cond
  453: 
  454: >CROSS
  455: \ Target compiling loop                                12dec92py
  456: \ ">tib trick thrown out                               10may93jaw
  457: \ number? defined at the top                           11may93jaw
  458: 
  459: \ compiled word might leave items on stack!
  460: : tcom ( in name -- )
  461:   gfind  ?dup  IF    0> IF    nip >exec @ execute
  462:                         ELSE  nip gexecute  THEN EXIT THEN
  463:   number? dup  IF    0> IF swap lit,  THEN  lit,  drop
  464:                ELSE  2drop >in !
  465:                ghost gexecute THEN  ;
  466: 
  467: >TARGET
  468: \ : ; DOES>                                            13dec92py
  469: \ ]                                                     9may93py/jaw
  470: 
  471: : ] state on
  472:     BEGIN
  473:         BEGIN >in @ name
  474:               dup c@ 0= WHILE 2drop refill 0=
  475:               ABORT" CROSS: End of file while target compiling"
  476:         REPEAT
  477:         tcom
  478:         state @
  479:         0=
  480:     UNTIL ;
  481: 
  482: \ by the way: defining a second interpreter (a compiler-)loop
  483: \             is not allowed if a system should be ans conform
  484: 
  485: : : ( -- colon-sys ) \ Name
  486:   (THeader ;Resolve ! there ;Resolve cell+ !
  487:   docol, depth T ] H ;
  488: 
  489: Cond: EXIT ( -- )  restrict?  compile ;S  ;Cond
  490: 
  491: Cond: ; ( -- ) restrict?
  492:                depth ?dup IF   1- <> ABORT" CROSS: Stack changed"
  493:                           ELSE true ABORT" CROSS: Stack empty" THEN
  494:                compile ;S state off
  495:                ;Resolve @
  496:                IF ;Resolve @ ;Resolve cell+ @ resolve THEN
  497:                ;Cond
  498: Cond: [  restrict? state off ;Cond
  499: 
  500: >CROSS
  501: : !does  :dodoes tlastcfa @ tuck T ! cell+ ! H ;
  502: 
  503: >TARGET
  504: Cond: DOES> restrict?
  505:         compile (;code) dodoes, tdoes @ ?dup IF  @ T here H resolve THEN
  506:         ;Cond
  507: : DOES> dodoes, T here H !does depth T ] H ;
  508: 
  509: >CROSS
  510: \ Creation                                             01nov92py
  511: 
  512: \ Builder                                               11may93jaw
  513: 
  514: : Builder    ( Create do: "name" -- )
  515:   >in @ alias2 swap dup >in ! >r >r
  516:   Make-Ghost rot swap >exec ! ,
  517:   r> r> >in !
  518:   also ghosts ' previous swap !
  519:   DOES> dup >exec @ execute ;
  520: 
  521: : gdoes,  ( ghost -- )  >end @ dup >magic @ <fwd> <>
  522:   IF dup >link @ dup 0< IF T A, 0 , H drop EXIT THEN drop THEN
  523:   :dodoes T A, H gexecute T here H cell - reloff ;
  524: 
  525: : TCreate ( ghost -- )
  526:   CreateFlag on
  527:   Theader dup gdoes,
  528:   >end @ >exec @ execute ;
  529: 
  530: : Build:  ( -- [xt] [colon-sys] )
  531:   :noname  postpone TCreate ;
  532: 
  533: : gdoes>  ( ghost -- addr flag )
  534:   state @ IF  gexecute true EXIT  THEN
  535:   cell+ @ T >body H false ;
  536: 
  537: \ DO: ;DO                                               11may93jaw
  538: \ changed to ?EXIT                                      10may93jaw
  539: 
  540: : (does>)        postpone does> ; immediate \ second level does>
  541: 
  542: : DO:     ( -- addr [xt] [colon-sys] )
  543:   here ghostheader
  544:   :noname
  545:   postpone (does>) postpone gdoes> postpone ?EXIT ;
  546: 
  547: : ;DO ( addr [xt] [colon-sys] -- )
  548:   postpone ;    ( S addr xt )
  549:   over >exec ! ; immediate
  550: 
  551: : by      ( -- addr ) \ Name
  552:   ghost >end @ ;
  553: 
  554: >TARGET
  555: \ Variables and Constants                              05dec92py
  556: 
  557: Build:  ;
  558: DO: ( ghost -- addr ) ;DO
  559: Builder Create
  560: by Create :dovar resolve
  561: 
  562: Build: T 0 , H ;
  563: by Create
  564: Builder Variable
  565: 
  566: Build: T 0 A, H ;
  567: by Create
  568: Builder AVariable
  569: 
  570: \ User variables                                       04may94py
  571: 
  572: >CROSS
  573: Variable tup  0 tup !
  574: Variable tudp 0 tudp !
  575: : u,  ( n -- udp )
  576:   tup @ tudp @ + T  ! H
  577:   tudp @ dup cell+ tudp ! ;
  578: : au, ( n -- udp )
  579:   tup @ tudp @ + T A! H
  580:   tudp @ dup cell+ tudp ! ;
  581: >TARGET
  582: 
  583: Build: T 0 u, , H ;
  584: DO: ( ghost -- up-addr )  T @ H tup @ + ;DO
  585: Builder User
  586: by User :douser resolve
  587: 
  588: Build: T 0 u, , 0 u, drop H ;
  589: by User
  590: Builder 2User
  591: 
  592: Build: T 0 au, , H ;
  593: by User
  594: Builder AUser
  595: 
  596: Build:  ( n -- ) T , H ;
  597: DO: ( ghost -- n ) T @ H ;DO
  598: Builder Constant
  599: by Constant :docon resolve
  600: 
  601: Build:  ( n -- ) T A, H ;
  602: by Constant
  603: Builder AConstant
  604: 
  605: Build: T 0 , H ;
  606: by Constant
  607: Builder Value
  608: 
  609: Build:  ( -- ) compile noop ;
  610: DO: ( ghost -- ) ABORT" CROSS: Don't execute" ;DO
  611: Builder Defer
  612: 
  613: \ structural conditionals                              17dec92py
  614: 
  615: >CROSS
  616: : ?struc      ( flag -- )       ABORT" CROSS: unstructured " ;
  617: : sys?        ( sys -- sys )    dup 0= ?struc ;
  618: : >mark       ( -- sys )        T here  0 , H ;
  619: : >resolve    ( sys -- )        T here over - swap ! H ;
  620: : <resolve    ( sys -- )        T here - , H ;
  621: >TARGET
  622: 
  623: \ Structural Conditionals                              12dec92py
  624: 
  625: Cond: BUT       restrict? sys? swap ;Cond
  626: Cond: YET       restrict? sys? dup ;Cond
  627: 
  628: >CROSS
  629: Variable tleavings
  630: >TARGET
  631: 
  632: Cond: DONE   ( addr -- )  restrict? tleavings @
  633:       BEGIN  2dup u> 0=  WHILE  dup T @ H swap >resolve REPEAT
  634:       tleavings ! drop ;Cond
  635: 
  636: >CROSS
  637: : (leave  T here H tleavings @ T , H  tleavings ! ;
  638: >TARGET
  639: 
  640: Cond: LEAVE     restrict? compile branch (leave ;Cond
  641: Cond: ?LEAVE    restrict? compile 0=  compile ?branch (leave  ;Cond
  642: 
  643: \ Structural Conditionals                              12dec92py
  644: 
  645: Cond: AHEAD     restrict? compile branch >mark ;Cond
  646: Cond: IF        restrict? compile ?branch >mark ;Cond
  647: Cond: THEN      restrict? sys? dup T @ H ?struc >resolve ;Cond
  648: Cond: ELSE      restrict? sys? compile AHEAD swap compile THEN ;Cond
  649: 
  650: Cond: BEGIN     restrict? T here H ;Cond
  651: Cond: WHILE     restrict? sys? compile IF swap ;Cond
  652: Cond: AGAIN     restrict? sys? compile branch <resolve ;Cond
  653: Cond: UNTIL     restrict? sys? compile ?branch <resolve ;Cond
  654: Cond: REPEAT    restrict? over 0= ?struc compile AGAIN compile THEN ;Cond
  655: 
  656: \ Structural Conditionals                              12dec92py
  657: 
  658: Cond: DO        restrict? compile (do)   T here H ;Cond
  659: Cond: ?DO       restrict? compile (?do)  (leave T here H ;Cond
  660: Cond: FOR       restrict? compile (for)  T here H ;Cond
  661: 
  662: >CROSS
  663: : loop]   dup <resolve cell - compile DONE compile unloop ;
  664: >TARGET
  665: 
  666: Cond: LOOP      restrict? sys? compile (loop)  loop] ;Cond
  667: Cond: +LOOP     restrict? sys? compile (+loop) loop] ;Cond
  668: Cond: NEXT      restrict? sys? compile (next)  loop] ;Cond
  669: 
  670: \ String words                                         23feb93py
  671: 
  672: : ,"            [char] " parse string, T align H ;
  673: 
  674: Cond: ."        restrict? compile (.")     T ," H ;Cond
  675: Cond: S"        restrict? compile (S")     T ," H ;Cond
  676: Cond: ABORT"    restrict? compile (ABORT") T ," H ;Cond
  677: 
  678: Cond: IS        T ' >body H compile ALiteral compile ! ;Cond
  679: : IS            T ' >body ! H ;
  680: 
  681: \ LINKED ERR" ENV" 2ENV"                                18may93jaw
  682: 
  683: \ linked list primitive
  684: : linked        T here over @ A, swap ! H ;
  685: 
  686: : err"   s" ErrLink linked" evaluate T , H
  687:          [char] " parse string, T align H ;
  688: 
  689: : env"  [char] " parse s" EnvLink linked" evaluate
  690:         string, T align , H ;
  691: 
  692: : 2env" [char] " parse s" EnvLink linked" evaluate
  693:         here >r string, T align , , H
  694:         r> dup T c@ H 80 and swap T c! H ;
  695: 
  696: \ compile must be last                                 22feb93py
  697: 
  698: Cond: compile ( -- ) restrict? \ name
  699:       name gfind dup 0= ABORT" CROSS: Can't compile"
  700:       0> IF    gexecute
  701:          ELSE  dup >magic @ <imm> =
  702:                IF   gexecute
  703:                ELSE compile (compile) gexecute THEN THEN ;Cond
  704: 
  705: Cond: postpone ( -- ) restrict? \ name
  706:       name gfind dup 0= ABORT" CROSS: Can't compile"
  707:       0> IF    gexecute
  708:          ELSE  dup >magic @ <imm> =
  709:                IF   gexecute
  710:                ELSE compile (compile) gexecute THEN THEN ;Cond
  711: 
  712: >MINIMAL
  713: also minimal
  714: \ Usefull words                                        13feb93py
  715: 
  716: : KB  400 * ;
  717: 
  718: \ define new [IFDEF] and [IFUNDEF]                      20may93jaw
  719: 
  720: : there? name gfind IF >magic @ <fwd> <> ELSE drop false THEN ;
  721: 
  722: : [IFDEF] there? postpone [IF] ;
  723: : [IFUNDEF] there? 0= postpone [IF] ;
  724: 
  725: \ C: \- \+ Conditional Compiling                         09jun93jaw
  726: 
  727: : C: >in @ there? 0=
  728:      IF    >in ! T : H
  729:      ELSE drop
  730:         BEGIN bl word dup c@
  731:               IF   count comment? s" ;" compare 0= ?EXIT
  732:               ELSE refill 0= ABORT" CROSS: Out of Input while C:"
  733:               THEN
  734:         AGAIN
  735:      THEN ;
  736: 
  737: also minimal
  738: 
  739: : \- there? IF postpone \ THEN ;
  740: : \+ there? 0= IF postpone \ THEN ;
  741: 
  742: : [IF]   postpone [IF] ;
  743: : [THEN] postpone [THEN] ;
  744: : [ELSE] postpone [ELSE] ;
  745: 
  746: Cond: [IF]      [IF] ;Cond
  747: Cond: [IFDEF]   [IFDEF] ;Cond
  748: Cond: [IFUNDEF] [IFUNDEF] ;Cond
  749: Cond: [THEN]    [THEN] ;Cond
  750: Cond: [ELSE]    [ELSE] ;Cond
  751: 
  752: \ save-cross                                           17mar93py
  753: 
  754: \ i'm not interested in bigforth features this time    10may93jaw
  755: \ [IFDEF] file
  756: \ also file
  757: \ [THEN]
  758: \ included throw after create-file                     11may93jaw
  759: 
  760: endian Constant endian
  761: 
  762: : save-cross ( "name" -- )
  763:   bl parse ." Saving to " 2dup type
  764:   w/o bin create-file throw >r
  765:   image @ there r@ write-file throw
  766:   bit$  @ there 1- cell>bit rshift 1+ r@ write-file throw
  767:   r> close-file throw ;
  768: 
  769: \ words that should be in minimal
  770: 
  771: : + + ;         : 1- 1- ;
  772: : - - ;         : 2* 2* ;
  773: : dup dup ;     : over over ;
  774: : swap swap ;   : rot rot ;
  775: 
  776: \ include bug5.fs
  777: \ only forth also minimal definitions
  778: 
  779: : \ postpone \ ;
  780: : ( postpone ( ;
  781: : include bl word count included ;
  782: : .( [char] ) parse type ;
  783: : cr cr ;
  784: 
  785: : times 0 ?DO dup T c, H LOOP drop ; \ used for space table creation
  786: only forth also minimal definitions
  787: 
  788: \ cross-compiler words
  789: 
  790: : decimal       decimal ;
  791: : hex           hex ;
  792: 
  793: : tudp          T tudp H ;
  794: : tup           T tup H ;  minimal
  795: 
  796: \ for debugging...
  797: : order         order ;
  798: : words         words ;
  799: : .s            .s ;
  800: 
  801: : bye           bye ;
  802: 
  803: \ turnkey direction
  804: : H forth ; immediate
  805: : T minimal ; immediate
  806: : G ghosts ; immediate
  807: 
  808: : turnkey  0 set-order also Target definitions
  809:            also Minimal also ;
  810: 
  811: \ these ones are pefered:
  812: 
  813: : lock   turnkey ;
  814: : unlock forth also cross ;
  815: 
  816: unlock definitions also minimal
  817: : lock   lock ;
  818: lock

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>