Annotation of gforth/cross.fs, revision 1.19

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

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