Annotation of gforth/cross.fs, revision 1.67

1.1       anton       1: \ CROSS.FS     The Cross-Compiler                      06oct92py
                      2: \ Idea and implementation: Bernd Paysan (py)
1.30      anton       3: 
1.58      anton       4: \ Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
1.30      anton       5: 
                      6: \ This file is part of Gforth.
                      7: 
                      8: \ Gforth is free software; you can redistribute it and/or
                      9: \ modify it under the terms of the GNU General Public License
                     10: \ as published by the Free Software Foundation; either version 2
                     11: \ of the License, or (at your option) any later version.
                     12: 
                     13: \ This program is distributed in the hope that it will be useful,
                     14: \ but WITHOUT ANY WARRANTY; without even the implied warranty of
                     15: \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     16: \ GNU General Public License for more details.
                     17: 
                     18: \ You should have received a copy of the GNU General Public License
                     19: \ along with this program; if not, write to the Free Software
                     20: \ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1.1       anton      21: 
1.67    ! jwilke     22: 0 
        !            23: [IF]
        !            24: 
        !            25: ToDo:
        !            26: Crossdoc destination ./doc/crossdoc.fd makes no sense when
        !            27: cross.fs is uses seperately. jaw
        !            28: Do we need this char translation with >address and in branchoffset? 
        !            29: (>body also affected) jaw
        !            30: Clean up mark> and >resolve stuff jaw
        !            31: 
        !            32: [THEN]
1.48      anton      33: 
                     34: 
1.52      jwilke     35: hex     \ the defualt base for the cross-compiler is hex !!
                     36: Warnings off
                     37: 
                     38: \ words that are generaly useful
                     39: 
1.59      pazsan     40: : KB  400 * ;
1.52      jwilke     41: : >wordlist ( vocabulary-xt -- wordlist-struct )
                     42:   also execute get-order swap >r 1- set-order r> ;
                     43: 
                     44: : umax 2dup u< IF swap THEN drop ;
                     45: : umin 2dup u> IF swap THEN drop ;
1.1       anton      46: 
1.23      pazsan     47: : string, ( c-addr u -- )
                     48:     \ puts down string as cstring
                     49:     dup c, here swap chars dup allot move ;
1.5       pazsan     50: 
1.52      jwilke     51: : SetValue ( n -- <name> )
1.54      pazsan     52: \G Same behaviour as "Value" if the <name> is not defined
                     53: \G Same behaviour as "to" if <name> is defined
1.52      jwilke     54: \G SetValue searches in the current vocabulary
                     55:  save-input bl word >r restore-input throw r> count
                     56:  get-current search-wordlist
1.56      pazsan     57:  IF ['] to execute ELSE Value THEN ;
1.52      jwilke     58: 
                     59: : DefaultValue ( n -- <name> )
1.54      pazsan     60: \G Same behaviour as "Value" if the <name> is not defined
                     61: \G DefaultValue searches in the current vocabulary
1.52      jwilke     62:  save-input bl word >r restore-input throw r> count
                     63:  get-current search-wordlist
1.56      pazsan     64:  IF bl word drop 2drop ELSE Value THEN ;
1.1       anton      65: 
                     66: hex
                     67: 
                     68: Vocabulary Cross
                     69: Vocabulary Target
                     70: Vocabulary Ghosts
                     71: VOCABULARY Minimal
                     72: only Forth also Target also also
                     73: definitions Forth
                     74: 
                     75: : T  previous Cross also Target ; immediate
                     76: : G  Ghosts ; immediate
                     77: : H  previous Forth also Cross ; immediate
                     78: 
                     79: forth definitions
                     80: 
                     81: : T  previous Cross also Target ; immediate
                     82: : G  Ghosts ; immediate
                     83: 
                     84: : >cross  also Cross definitions previous ;
                     85: : >target also Target definitions previous ;
                     86: : >minimal also Minimal definitions previous ;
                     87: 
                     88: H
                     89: 
                     90: >CROSS
                     91: 
1.52      jwilke     92: \ 1 Constant Cross-Flag        \ to check whether assembler compiler plug-ins are
                     93:                        \ for cross-compiling
                     94: \ No! we use "[IFUNDEF]" there to find out whether we are target compiling!!!
                     95: 
                     96: : comment? ( c-addr u -- c-addr u )
                     97:         2dup s" (" compare 0=
                     98:         IF    postpone (
                     99:         ELSE  2dup s" \" compare 0= IF postpone \ THEN
                    100:         THEN ;
                    101: 
                    102: \ Begin CROSS COMPILER:
                    103: 
                    104: 
                    105: 
                    106: \ \ --------------------        Error Handling                  05aug97jaw
                    107: 
                    108: \ Flags
                    109: 
                    110: also forth definitions  \ these values may be predefined before
                    111:                         \ the cross-compiler is loaded
                    112: 
                    113: false DefaultValue stack-warn           \ check on empty stack at any definition
                    114: false DefaultValue create-forward-warn   \ warn on forward declaration of created words
                    115: 
                    116: [IFUNDEF] DebugMaskSrouce Variable DebugMaskSource 0 DebugMaskSource ! [THEN]
                    117: [IFUNDEF] DebugMaskCross  Variable DebugMaskCross  0 DebugMaskCross  ! [THEN]
                    118: 
                    119: previous >CROSS
                    120: 
1.53      jwilke    121: : .dec
                    122:   base @ decimal swap . base ! ;
                    123: 
1.52      jwilke    124: : .sourcepos
                    125:   cr sourcefilename type ." :"
1.53      jwilke    126:   sourceline# .dec ;
1.52      jwilke    127: 
                    128: : warnhead
                    129: \G display error-message head
                    130: \G perhaps with linenumber and filename
                    131:   .sourcepos ." Warning: " ;
                    132: 
                    133: : empty? depth IF .sourcepos ." Stack not empty!"  THEN ;
                    134: 
                    135: stack-warn [IF]
                    136: : defempty? empty? ;
                    137: [ELSE]
                    138: : defempty? ; immediate
                    139: [THEN]
                    140: 
                    141: 
1.54      pazsan    142: 
1.52      jwilke    143: \ \ GhostNames Ghosts                                  9may93jaw
                    144: 
                    145: \ second name source to search trough list
                    146: 
                    147: VARIABLE GhostNames
                    148: 0 GhostNames !
                    149: 
                    150: : GhostName ( -- addr )
                    151:     here GhostNames @ , GhostNames ! here 0 ,
                    152:     bl word count
                    153:     \ 2dup type space
                    154:     string, \ !! cfalign ?
                    155:     align ;
                    156: 
                    157: \ Ghost Builder                                        06oct92py
                    158: 
                    159: \ <T T> new version with temp variable                 10may93jaw
                    160: 
                    161: VARIABLE VocTemp
                    162: 
                    163: : <T  get-current VocTemp ! also Ghosts definitions ;
                    164: : T>  previous VocTemp @ set-current ;
                    165: 
                    166: hex
                    167: 4711 Constant <fwd>             4712 Constant <res>
                    168: 4713 Constant <imm>             4714 Constant <do:>
                    169: 
                    170: \ iForth makes only immediate directly after create
                    171: \ make atonce trick! ?
                    172: 
                    173: Variable atonce atonce off
                    174: 
                    175: : NoExec true ABORT" CROSS: Don't execute ghost" ;
                    176: 
                    177: : GhostHeader <fwd> , 0 , ['] NoExec , ;
                    178: 
                    179: : >magic ;             \ type of ghost
                    180: : >link cell+ ;                \ pointer where ghost is in target, or if unresolved
                    181:                        \ points to the where we have to resolve (linked-list)
                    182: : >exec cell+ cell+ ;  \ execution symantics (while target compiling) of ghost
                    183: : >end 3 cells + ;     \ room for additional tags
                    184:                        \ for builder (create, variable...) words the
                    185:                        \ execution symantics of words built are placed here
                    186: 
                    187: Variable executed-ghost \ last executed ghost, needed in tcreate and gdoes>
                    188: Variable last-ghost    \ last ghost that is created
                    189: Variable last-header-ghost \ last ghost definitions with header
                    190: 
                    191: : Make-Ghost ( "name" -- ghost )
                    192:   >in @ GhostName swap >in !
                    193:   <T Create atonce @ IF immediate atonce off THEN
                    194:   here tuck swap ! ghostheader T>
                    195:   dup last-ghost !
                    196:   DOES> dup executed-ghost ! >exec @ execute ;
                    197: 
                    198: \ ghost words                                          14oct92py
                    199: \                                          changed:    10may93py/jaw
                    200: 
                    201: : gfind   ( string -- ghost true/1 / string false )
                    202: \ searches for string in word-list ghosts
                    203:   dup count [ ' ghosts >wordlist ] ALiteral search-wordlist
                    204:   dup IF >r >body nip r>  THEN ;
                    205: 
                    206: : gdiscover ( xt -- ghost true | xt false )
                    207:   GhostNames
                    208:   BEGIN @ dup
                    209:   WHILE 2dup
                    210:         cell+ @ dup >magic @ <fwd> <>
                    211:         >r >link @ = r> and
                    212:         IF cell+ @ nip true EXIT THEN
                    213:   REPEAT
                    214:   drop false ;
                    215: 
                    216: VARIABLE Already
                    217: 
                    218: : ghost   ( "name" -- ghost )
                    219:   Already off
                    220:   >in @  bl word gfind   IF  Already on nip EXIT  THEN
                    221:   drop  >in !  Make-Ghost ;
                    222: 
                    223: : >ghostname ( ghost -- adr len )
                    224:   GhostNames
                    225:   BEGIN @ dup
                    226:   WHILE 2dup cell+ @ =
                    227:   UNTIL nip 2 cells + count
1.54      pazsan    228:   ELSE  2drop 
                    229:        \ true abort" CROSS: Ghostnames inconsistent"
                    230:        s" ?!?!?!"
1.52      jwilke    231:   THEN ;
                    232: 
                    233: ' >ghostname ALIAS @name
                    234: 
                    235: : forward? ( ghost -- flag )
                    236:   >magic @ <fwd> = ;
                    237: 
                    238: \ Predefined ghosts                                    12dec92py
                    239: 
                    240: ghost 0=                                        drop
                    241: ghost branch    ghost ?branch                   2drop
                    242: ghost (do)      ghost (?do)                     2drop
                    243: ghost (for)                                     drop
                    244: ghost (loop)    ghost (+loop)                   2drop
                    245: ghost (next)                                    drop
                    246: ghost unloop    ghost ;S                        2drop
                    247: ghost lit       ghost (compile) ghost !         2drop drop
                    248: ghost (does>)   ghost noop                      2drop
                    249: ghost (.")      ghost (S")      ghost (ABORT")  2drop drop
                    250: ghost '                                         drop
                    251: ghost :docol    ghost :doesjump ghost :dodoes   2drop drop
1.54      pazsan    252: ghost :dovar                                   drop
1.52      jwilke    253: ghost over      ghost =         ghost drop      2drop drop
                    254: ghost - drop
1.54      pazsan    255: ghost 2drop drop
                    256: ghost 2dup drop
1.52      jwilke    257: 
                    258: \ \ Parameter for target systems                         06oct92py
                    259: 
                    260: \ we define it ans like...
                    261: wordlist Constant target-environment
                    262: 
                    263: VARIABLE env-current \ save information of current dictionary to restore with environ>
                    264: 
                    265: : >ENVIRON get-current env-current ! target-environment set-current ;
                    266: : ENVIRON> env-current @ set-current ; 
1.43      pazsan    267: 
1.48      anton     268: >TARGET
1.43      pazsan    269: 
1.67    ! jwilke    270: : environment? ( adr len -- [ x ] true | false )
1.52      jwilke    271:   target-environment search-wordlist 
                    272:   IF execute true ELSE false THEN ;
                    273: 
1.67    ! jwilke    274: : e? bl word count T environment? H 0= ABORT" environment variable not defined!" ;
1.52      jwilke    275: 
1.67    ! jwilke    276: : has?         bl word count T environment? H 
1.53      jwilke    277:        IF      \ environment variable is present, return its value
                    278:        ELSE    \ environment variable is not present, return false
                    279:                \ !! JAW abort is just for testing
                    280:                false true ABORT" arg" 
                    281:        THEN ;
1.52      jwilke    282: 
                    283: : $has? T environment? H IF ELSE false THEN ;
1.48      anton     284: 
1.54      pazsan    285: >ENVIRON get-order get-current swap 1+ set-order
                    286: true SetValue compiler
1.53      jwilke    287: true  SetValue cross
1.54      pazsan    288: true SetValue standard-threading
                    289: >TARGET previous
1.52      jwilke    290: 
1.59      pazsan    291: 
1.52      jwilke    292: mach-file count included hex
1.43      pazsan    293: 
1.53      jwilke    294: >ENVIRON
                    295: 
1.54      pazsan    296: T has? ec H
                    297: [IF]
                    298: false DefaultValue relocate
                    299: false DefaultValue file
                    300: false DefaultValue OS
                    301: false DefaultValue prims
                    302: false DefaultValue floating
                    303: false DefaultValue glocals
                    304: false DefaultValue dcomps
                    305: false DefaultValue hash
                    306: false DefaultValue xconds
                    307: false DefaultValue header
                    308: [THEN]
                    309: 
                    310: true DefaultValue interpreter
                    311: true DefaultValue ITC
                    312: false DefaultValue rom
1.53      jwilke    313: 
1.52      jwilke    314: >TARGET
1.53      jwilke    315: s" relocate" T environment? H 
                    316: [IF]   SetValue NIL
                    317: [ELSE] >ENVIRON T NIL H SetValue relocate
                    318: [THEN]
1.43      pazsan    319: 
                    320: >CROSS
                    321: 
1.52      jwilke    322: \ \ Create additional parameters                         19jan95py
1.19      pazsan    323: 
1.67    ! jwilke    324: 1 8 lshift Constant maxbyte 
        !           325: \ this sets byte size for the target machine, an (probably right guess) jaw
        !           326: 
1.19      pazsan    327: T
1.48      anton     328: NIL               Constant TNIL
1.19      pazsan    329: cell               Constant tcell
                    330: cell<<             Constant tcell<<
                    331: cell>bit           Constant tcell>bit
                    332: bits/byte          Constant tbits/byte
1.57      pazsan    333: bits/byte 8 /      Constant tchar
1.19      pazsan    334: float              Constant tfloat
1.57      pazsan    335: 1 bits/byte lshift Constant tmaxbyte
1.19      pazsan    336: H
                    337: 
1.48      anton     338: \ Variables                                            06oct92py
                    339: 
                    340: Variable image
                    341: Variable tlast    TNIL tlast !  \ Last name field
                    342: Variable tlastcfa \ Last code field
                    343: Variable tdoes    \ Resolve does> calls
                    344: Variable bit$
1.52      jwilke    345: 
                    346: \ statistics                                           10jun97jaw
                    347: 
                    348: Variable headers-named 0 headers-named !
                    349: Variable user-vars 0 user-vars !
                    350: 
                    351: \ Memory initialisation                                05dec92py
                    352: 
                    353: [IFDEF] Memory \ Memory is a bigFORTH feature
                    354:    also Memory
                    355:    : initmem ( var len -- )
                    356:      2dup swap handle! >r @ r> erase ;
                    357:    toss
                    358: [ELSE]
                    359:    : initmem ( var len -- )
                    360:      tuck allocate abort" CROSS: No memory for target"
                    361:      ( len var adr ) dup rot !
                    362:      ( len adr ) swap erase ;
                    363: [THEN]
                    364: 
                    365: \ MakeKernal                                           12dec92py
                    366: 
                    367: : makekernel ( targetsize -- targetsize )
                    368:   bit$  over 1- tcell>bit rshift 1+ initmem
                    369:   image over initmem ;
                    370: 
                    371: >MINIMAL
                    372: : makekernel makekernel ;
1.67    ! jwilke    373: >CROSS
        !           374: 
        !           375: : target>bitmask-size ( u1 -- u2 )
        !           376:   1- tcell>bit rshift 1+ ;
        !           377: 
        !           378: : allocatetarget ( size --- adr )
        !           379:   dup allocate ABORT" CROSS: No memory for target"
        !           380:   swap over swap erase ;
1.52      jwilke    381: 
                    382: 
                    383: 
1.54      pazsan    384: \ \ memregion.fs
1.52      jwilke    385: 
                    386: 
                    387: Variable last-defined-region    \ pointer to last defined region
                    388: Variable region-link            \ linked list with all regions
                    389: Variable mirrored-link          \ linked list for mirrored regions
                    390: 0 dup mirrored-link ! region-link !
                    391: 
                    392: 
1.67    ! jwilke    393: : >rname 6 cells + ;
        !           394: : >rbm   5 cells + ;
        !           395: : >rmem  4 cells + ;
        !           396: : >rlink 3 cells + ;
1.52      jwilke    397: : >rdp 2 cells + ;
                    398: : >rlen cell+ ;
                    399: : >rstart ;
                    400: 
                    401: 
                    402: : region ( addr len -- )                \G create a new region
                    403:   \ check whether predefined region exists 
                    404:   save-input bl word find >r >r restore-input throw r> r> 0= 
                    405:   IF   \ make region
                    406:        drop
                    407:        save-input create restore-input throw
                    408:        here last-defined-region !
                    409:        over ( startaddr ) , ( length ) , ( dp ) ,
1.67    ! jwilke    410:        region-link linked 0 , 0 , bl word count string,
1.52      jwilke    411:   ELSE \ store new parameters in region
                    412:         bl word drop
                    413:        >body >r r@ last-defined-region !
1.67    ! jwilke    414:        r@ >rlen ! dup r@ >rstart ! r> >rdp !
1.52      jwilke    415:   THEN ;
                    416: 
                    417: : borders ( region -- startaddr endaddr ) \G returns lower and upper region border
1.67    ! jwilke    418:   dup >rstart @ swap >rlen @ over + ;
1.52      jwilke    419: 
                    420: : extent  ( region -- startaddr len )   \G returns the really used area
1.67    ! jwilke    421:   dup >rstart @ swap >rdp @ over - ;
1.52      jwilke    422: 
                    423: : area ( region -- startaddr totallen ) \G returns the total area
1.67    ! jwilke    424:   dup >rstart swap >rlen @ ;
1.52      jwilke    425: 
                    426: : mirrored                              \G mark a region as mirrored
                    427:   mirrored-link
                    428:   linked last-defined-region @ , ;
                    429: 
1.67    ! jwilke    430: : .addr ( u -- )
        !           431: \G prints a 16 or 32 Bit nice hex value
1.52      jwilke    432:   base @ >r hex
                    433:   tcell 2 u>
                    434:   IF s>d <# # # # # '. hold # # # # #> type
                    435:   ELSE s>d <# # # # # # #> type
                    436:   THEN r> base ! ;
                    437: 
                    438: : .regions                      \G display region statistic
                    439: 
                    440:   \ we want to list the regions in the right order
                    441:   \ so first collect all regions on stack
                    442:   0 region-link @
                    443:   BEGIN dup WHILE dup @ REPEAT drop
                    444:   BEGIN dup
1.67    ! jwilke    445:   WHILE cr
        !           446:         0 >rlink - >r
        !           447:         r@ >rname count tuck type
1.52      jwilke    448:         12 swap - 0 max spaces space
1.67    ! jwilke    449:         ." Start: " r@ >rstart @ dup .addr space
        !           450:         ." End: " r@ >rlen @ + .addr space
        !           451:         ." DP: " r> >rdp @ .addr
1.52      jwilke    452:   REPEAT drop
1.53      jwilke    453:   s" rom" T $has? H 0= ?EXIT
1.52      jwilke    454:   cr ." Mirrored:"
                    455:   mirrored-link @
                    456:   BEGIN dup
1.67    ! jwilke    457:   WHILE space dup cell+ @ >rname count type @
1.52      jwilke    458:   REPEAT drop cr
                    459:   ;
                    460: 
                    461: \ -------- predefined regions
                    462: 
                    463: 0 0 region address-space
                    464: \ total memory addressed and used by the target system
                    465: 
                    466: 0 0 region dictionary
                    467: \ rom area for the compiler
                    468: 
1.53      jwilke    469: T has? rom H
1.52      jwilke    470: [IF]
                    471: 0 0 region ram-dictionary mirrored
                    472: \ ram area for the compiler
                    473: [ELSE]
                    474: ' dictionary ALIAS ram-dictionary
                    475: [THEN]
                    476: 
                    477: 0 0 region return-stack
                    478: 
                    479: 0 0 region data-stack
                    480: 
                    481: 0 0 region tib-region
                    482: 
                    483: ' dictionary ALIAS rom-dictionary
                    484: 
                    485: 
                    486: : setup-target ( -- )   \G initialize targets memory space
1.53      jwilke    487:   s" rom" T $has? H
1.52      jwilke    488:   IF  \ check for ram and rom...
1.67    ! jwilke    489:       address-space area nip 0<>
        !           490:       ram-dictionary area nip 0<>
        !           491:       rom-dictionary area nip 0<>
1.52      jwilke    492:       and and 0=
                    493:       ABORT" CROSS: define address-space, rom- , ram-dictionary, with rom-support!"
                    494:   THEN
                    495:   address-space area nip
                    496:   IF
                    497:       address-space area
                    498:   ELSE
                    499:       dictionary area
                    500:   THEN
1.67    ! jwilke    501:   nip 0=
1.52      jwilke    502:   ABORT" CROSS: define at least address-space or dictionary!!"
1.67    ! jwilke    503: 
        !           504:   \ allocate target for each region
        !           505:   region-link
        !           506:   BEGIN @ dup
        !           507:   WHILE dup
        !           508:         0 >rlink - >r
        !           509:         r@ >rlen @
        !           510:         IF      \ allocate mem
        !           511:                 r@ >rlen @ dup
        !           512: 
        !           513:                 allocatetarget dup image !
        !           514:                 r@ >rmem !
        !           515: 
        !           516:                 target>bitmask-size allocatetarget
        !           517:                 dup
        !           518:                 bit$ !
        !           519:                 r> >rbm !
        !           520: 
        !           521:         ELSE    r> drop THEN
        !           522:    REPEAT ;
1.52      jwilke    523: 
1.54      pazsan    524: \ \ switched tdp for rom support                               03jun97jaw
1.52      jwilke    525: 
                    526: \ second value is here to store some maximal value for statistics
                    527: \ tempdp is also embedded here but has nothing to do with rom support
                    528: \ (needs switched dp)
                    529: 
                    530: variable tempdp        0 ,     \ temporary dp for resolving
                    531: variable tempdp-save
                    532: 
                    533: 0 [IF]
                    534: variable romdp 0 ,      \ Dictionary-Pointer for ramarea
                    535: variable ramdp 0 ,      \ Dictionary-Pointer for romarea
                    536: 
                    537: \
                    538: variable sramdp                \ start of ram-area for forth
                    539: variable sromdp                \ start of rom-area for forth
                    540: 
                    541: [THEN]
                    542: 
                    543: 
                    544: 0 value tdp
                    545: variable fixed         \ flag: true: no automatic switching
                    546:                        \       false: switching is done automatically
                    547: 
                    548: \ Switch-Policy:
                    549: \
                    550: \ a header is always compiled into rom
                    551: \ after a created word (create and variable) compilation goes to ram
                    552: \
                    553: \ Be careful: If you want to make the data behind create into rom
                    554: \ you have to put >rom before create!
                    555: 
                    556: variable constflag constflag off
                    557: 
1.67    ! jwilke    558: : activate ( region -- )
        !           559: \G next code goes to this region
        !           560:   >rdp to tdp ;
        !           561: 
1.52      jwilke    562: : (switchram)
1.53      jwilke    563:   fixed @ ?EXIT s" rom" T $has? H 0= ?EXIT
1.67    ! jwilke    564:   ram-dictionary activate ;
1.52      jwilke    565: 
                    566: : switchram
                    567:   constflag @
                    568:   IF constflag off ELSE (switchram) THEN ;
                    569: 
                    570: : switchrom
1.67    ! jwilke    571:   fixed @ ?EXIT rom-dictionary activate ;
1.52      jwilke    572: 
                    573: : >tempdp ( addr -- ) 
                    574:   tdp tempdp-save ! tempdp to tdp tdp ! ;
                    575: : tempdp> ( -- )
                    576:   tempdp-save @ to tdp ;
                    577: 
                    578: : >ram  fixed off (switchram) fixed on ;
                    579: : >rom  fixed off switchrom fixed on ;
                    580: : >auto fixed off switchrom ;
                    581: 
                    582: 
                    583: 
                    584: \ : romstart dup sromdp ! romdp ! ;
                    585: \ : ramstart dup sramdp ! ramdp ! ;
                    586: 
1.67    ! jwilke    587: \ default compilation goes to rom
1.52      jwilke    588: \ when romable support is off, only the rom switch is used (!!)
                    589: >auto
                    590: 
1.48      anton     591: : there  tdp @ ;
                    592: 
1.52      jwilke    593: >TARGET
1.48      anton     594: 
1.52      jwilke    595: \ \ Target Memory Handling
1.1       anton     596: 
                    597: \ Byte ordering and cell size                          06oct92py
                    598: 
1.19      pazsan    599: : cell+         tcell + ;
                    600: : cells         tcell<< lshift ;
1.1       anton     601: : chars         ;
1.48      anton     602: : char+                1 + ;
1.19      pazsan    603: : floats       tfloat * ;
1.6       anton     604:     
1.1       anton     605: >CROSS
1.19      pazsan    606: : cell/         tcell<< rshift ;
1.1       anton     607: >TARGET
                    608: 20 CONSTANT bl
1.52      jwilke    609: \ TNIL Constant NIL
1.1       anton     610: 
                    611: >CROSS
                    612: 
1.20      pazsan    613: bigendian
                    614: [IF]
1.52      jwilke    615:    : S!  ( n addr -- )  >r s>d r> tcell bounds swap 1-
1.20      pazsan    616:      DO  maxbyte ud/mod rot I c!  -1 +LOOP  2drop ;
1.52      jwilke    617:    : S@  ( addr -- n )  >r 0 0 r> tcell bounds
1.20      pazsan    618:      DO  maxbyte * swap maxbyte um* rot + swap I c@ + swap  LOOP d>s ;
1.57      pazsan    619:    : Sc!  ( n addr -- )  >r s>d r> tchar bounds swap 1-
                    620:      DO  maxbyte ud/mod rot I c!  -1 +LOOP  2drop ;
                    621:    : Sc@  ( addr -- n )  >r 0 0 r> tchar bounds
                    622:      DO  maxbyte * swap maxbyte um* rot + swap I c@ + swap  LOOP d>s ;
1.19      pazsan    623: [ELSE]
1.52      jwilke    624:    : S!  ( n addr -- )  >r s>d r> tcell bounds
1.20      pazsan    625:      DO  maxbyte ud/mod rot I c!  LOOP  2drop ;
1.52      jwilke    626:    : S@  ( addr -- n )  >r 0 0 r> tcell bounds swap 1-
1.20      pazsan    627:      DO  maxbyte * swap maxbyte um* rot + swap I c@ + swap  -1 +LOOP d>s ;
1.57      pazsan    628:    : Sc!  ( n addr -- )  >r s>d r> tchar bounds
                    629:      DO  maxbyte ud/mod rot I c!  LOOP  2drop ;
                    630:    : Sc@  ( addr -- n )  >r 0 0 r> tchar bounds swap 1-
                    631:      DO  maxbyte * swap maxbyte um* rot + swap I c@ + swap  -1 +LOOP d>s ;
1.1       anton     632: [THEN]
                    633: 
1.67    ! jwilke    634: : taddr>region ( taddr -- region | 0 )
        !           635: \G finds for a target-address the correct region
        !           636: \G returns 0 if taddr is not in range of a target memory region
        !           637:   region-link
        !           638:   BEGIN @ dup
        !           639:   WHILE dup >r
        !           640:         0 >rlink - >r
        !           641:         r@ >rlen @
        !           642:         IF      dup r@ borders within
        !           643:                 IF r> r> drop nip EXIT THEN
        !           644:         THEN
        !           645:         r> drop
        !           646:         r>
        !           647:   REPEAT
        !           648:   2drop 0 ;
        !           649: 
        !           650: : (>regionimage) ( taddr -- 'taddr )
        !           651:   dup
        !           652:   \ find region we want to address
        !           653:   taddr>region dup 0= ABORT" Address out of range!"
        !           654:   >r
        !           655:   \ calculate offset in region
        !           656:   r@ >rstart @ -
        !           657:   \ add regions real address in our memory
        !           658:   r> >rmem @ + ;
        !           659: 
1.1       anton     660: \ Bit string manipulation                               06oct92py
                    661: \                                                       9may93jaw
                    662: CREATE Bittable 80 c, 40 c, 20 c, 10 c, 8 c, 4 c, 2 c, 1 c,
                    663: : bits ( n -- n ) chars Bittable + c@ ;
                    664: 
                    665: : >bit ( addr n -- c-addr mask ) 8 /mod rot + swap bits ;
                    666: : +bit ( addr n -- )  >bit over c@ or swap c! ;
1.4       pazsan    667: : -bit ( addr n -- )  >bit invert over c@ and swap c! ;
1.67    ! jwilke    668: 
        !           669: : (relon) ( taddr -- )  bit$ @ swap cell/ +bit ;
        !           670: : (reloff) ( taddr -- ) bit$ @ swap cell/ -bit ;
        !           671: 
        !           672: : (>image) ( taddr -- absaddr ) image @ + ;
        !           673: 
        !           674: DEFER >image
        !           675: DEFER relon
        !           676: DEFER reloff
        !           677: DEFER correcter
        !           678: 
        !           679: T has? relocate H
        !           680: [IF]
        !           681: ' (relon) IS relon
        !           682: ' (reloff) IS reloff
        !           683: ' (>image) IS >image
        !           684: [ELSE]
        !           685: ' drop IS relon
        !           686: ' drop IS reloff
        !           687: ' (correcter) IS >image
        !           688: [THEN]
1.1       anton     689: 
                    690: \ Target memory access                                 06oct92py
                    691: 
                    692: : align+  ( taddr -- rest )
1.48      anton     693:     tcell tuck 1- and - [ tcell 1- ] Literal and ;
1.22      anton     694: : cfalign+  ( taddr -- rest )
1.39      pazsan    695:     \ see kernel.fs:cfaligned
1.43      pazsan    696:     /maxalign tuck 1- and - [ /maxalign 1- ] Literal and ;
1.1       anton     697: 
                    698: >TARGET
                    699: : aligned ( taddr -- ta-addr )  dup align+ + ;
                    700: \ assumes cell alignment granularity (as GNU C)
                    701: 
1.22      anton     702: : cfaligned ( taddr1 -- taddr2 )
1.39      pazsan    703:     \ see kernel.fs
1.22      anton     704:     dup cfalign+ + ;
                    705: 
1.52      jwilke    706: : @  ( taddr -- w )     >image S@ ;
                    707: : !  ( w taddr -- )     >image S! ;
1.57      pazsan    708: : c@ ( taddr -- char )  >image Sc@ ;
                    709: : c! ( char taddr -- )  >image Sc! ;
1.7       anton     710: : 2@ ( taddr -- x1 x2 ) T dup cell+ @ swap @ H ;
                    711: : 2! ( x1 x2 taddr -- ) T swap over ! cell+ ! H ;
1.1       anton     712: 
                    713: \ Target compilation primitives                        06oct92py
                    714: \ included A!                                          16may93jaw
                    715: 
                    716: : here  ( -- there )    there ;
                    717: : allot ( n -- )        tdp +! ;
1.52      jwilke    718: : ,     ( w -- )        T here H tcell T allot  ! H T here drop H ;
1.57      pazsan    719: : c,    ( char -- )     T here    tchar allot c! H ;
1.67    ! jwilke    720: : align ( -- )          T here H align+ 0 ?DO  bl T c, tchar H +LOOP ;
1.22      anton     721: : cfalign ( -- )
1.59      pazsan    722:     T here H cfalign+ 0 ?DO  bl T c, tchar H +LOOP ;
1.1       anton     723: 
1.67    ! jwilke    724: : >address             dup 0>= IF tchar / THEN ; \ ?? jaw 
1.59      pazsan    725: : A!                    swap >address swap dup relon T ! H ;
                    726: : A,    ( w -- )        >address T here H relon T , H ;
1.1       anton     727: 
                    728: >CROSS
                    729: 
1.52      jwilke    730: : tcmove ( source dest len -- )
                    731: \G cmove in target memory
1.57      pazsan    732:   tchar * bounds
1.52      jwilke    733:   ?DO  dup T c@ H I T c! H 1+
1.57      pazsan    734:   tchar +LOOP  drop ;
1.1       anton     735: 
1.67    ! jwilke    736: \ \ Load Assembler
        !           737: 
1.1       anton     738: >TARGET
1.52      jwilke    739: H also Forth definitions \ ." asm: " order
1.1       anton     740: 
1.52      jwilke    741: : X    also target bl word find
                    742:        IF      state @ IF compile,
                    743:                ELSE execute THEN
                    744:        ELSE    previous ABORT" Cross: access method not supported!"
                    745:        THEN 
                    746:        previous ; immediate
1.1       anton     747: 
1.52      jwilke    748: [IFDEF] asm-include asm-include [THEN] hex
1.1       anton     749: 
1.52      jwilke    750: previous
                    751: >CROSS H
1.1       anton     752: 
1.52      jwilke    753: \ \ --------------------        Compiler Plug Ins               01aug97jaw
1.1       anton     754: 
1.54      pazsan    755: \  Compiler States
                    756: 
                    757: Variable comp-state
                    758: 0 Constant interpreting
                    759: 1 Constant compiling
                    760: 2 Constant resolving
                    761: 3 Constant assembling
                    762: 
1.52      jwilke    763: Defer lit, ( n -- )
                    764: Defer alit, ( n -- )
1.54      pazsan    765: 
                    766: Defer branch, ( target-addr -- )       \ compiles a branch
                    767: Defer ?branch, ( target-addr -- )      \ compiles a ?branch
                    768: Defer branchmark, ( -- branch-addr )   \ reserves room for a branch
                    769: Defer ?branchmark, ( -- branch-addr )  \ reserves room for a ?branch
                    770: Defer ?domark, ( -- branch-addr )      \ reserves room for a ?do branch
                    771: Defer branchto, ( -- )                 \ actual program position is target of a branch (do e.g. alignment)
                    772: Defer branchtoresolve, ( branch-addr -- ) \ resolves a forward reference from branchmark
                    773: Defer branchfrom, ( -- )               \ ?!
                    774: Defer branchtomark, ( -- target-addr ) \ marks a branch destination
                    775: 
1.52      jwilke    776: Defer colon, ( tcfa -- )               \ compiles call to tcfa at current position
1.54      pazsan    777: Defer colonmark, ( -- addr )           \ marks a colon call
1.52      jwilke    778: Defer colon-resolve ( tcfa addr -- )
1.54      pazsan    779: 
1.52      jwilke    780: Defer addr-resolve ( target-addr addr -- )
1.54      pazsan    781: Defer doer-resolve ( ghost res-pnt target-addr addr -- ghost res-pnt )
                    782: 
                    783: Defer do,      ( -- do-token )
                    784: Defer ?do,     ( -- ?do-token )
                    785: Defer for,     ( -- for-token )
                    786: Defer loop,    ( do-token / ?do-token -- )
                    787: Defer +loop,   ( do-token / ?do-token -- )
                    788: Defer next,    ( for-token )
1.1       anton     789: 
1.52      jwilke    790: [IFUNDEF] ca>native
                    791: defer ca>native        
                    792: [THEN]
1.1       anton     793: 
1.52      jwilke    794: >TARGET
                    795: DEFER >body             \ we need the system >body
                    796:                        \ and the target >body
                    797: >CROSS
                    798: T 2 cells H VALUE xt>body
1.54      pazsan    799: DEFER doprim,  \ compiles start of a primitive
                    800: DEFER docol,           \ compiles start of a colon definition
1.52      jwilke    801: DEFER doer,            
                    802: DEFER fini,      \ compiles end of definition ;s
                    803: DEFER doeshandler,
                    804: DEFER dodoes,
                    805: 
                    806: DEFER ]comp     \ starts compilation
                    807: DEFER comp[     \ ends compilation
                    808: 
1.54      pazsan    809: : (cc) T a, H ;                                        ' (cc) IS colon,
                    810: 
                    811: : (cr) >tempdp ]comp colon, comp[ tempdp> ;    ' (cr) IS colon-resolve
                    812: : (ar) T ! H ;                                 ' (ar) IS addr-resolve
                    813: : (dr)  ( ghost res-pnt target-addr addr )
                    814:        >tempdp drop over 
                    815:        dup >magic @ <do:> =
                    816:        IF      doer,
                    817:        ELSE    dodoes,
                    818:        THEN 
                    819:        tempdp> ;                               ' (dr) IS doer-resolve
                    820: 
                    821: : (cm) ( -- addr )
                    822:     T here align H
                    823:     -1 colon, ;                                        ' (cm) IS colonmark,
1.1       anton     824: 
1.52      jwilke    825: >TARGET
                    826: : compile, colon, ;
                    827: >CROSS
1.1       anton     828: 
1.53      jwilke    829: \ file loading
                    830: 
1.54      pazsan    831: : >fl-id   1 cells + ;
                    832: : >fl-name 2 cells + ;
                    833: 
1.53      jwilke    834: Variable filelist 0 filelist !
1.67    ! jwilke    835: Create NoFile ," #load-file#"
1.54      pazsan    836: 0 Value         filemem
1.67    ! jwilke    837: : loadfile  FileMem ?dup IF >fl-name ELSE NoFile THEN ;
1.53      jwilke    838: 
1.54      pazsan    839: 1 [IF] \ !! JAW WIP
1.1       anton     840: 
1.53      jwilke    841: : add-included-file ( adr len -- )
1.54      pazsan    842:        dup char+ >fl-name allocate throw >r
                    843:        r@ >fl-name place
1.53      jwilke    844:        filelist @ r@ !
1.54      pazsan    845:        r> dup filelist ! to FileMem
                    846:        ;
1.53      jwilke    847: 
                    848: : included? ( c-addr u -- f )
                    849:        filelist
                    850:        BEGIN   @ dup
                    851:        WHILE   >r r@ 1 cells + count compare 0=
                    852:                IF rdrop 2drop true EXIT THEN
                    853:                r>
                    854:        REPEAT
                    855:        2drop drop false ;      
                    856: 
                    857: : included 
1.54      pazsan    858: \      cr ." Including: " 2dup type ." ..."
                    859:        FileMem >r
                    860:        2dup add-included-file included 
                    861:        r> to FileMem ;
1.53      jwilke    862: 
                    863: : include bl word count included ;
                    864: 
                    865: : require bl word count included ;
                    866: 
                    867: [THEN]
1.1       anton     868: 
1.52      jwilke    869: \ resolve structure
1.1       anton     870: 
1.52      jwilke    871: : >next ;              \ link to next field
1.54      pazsan    872: : >tag cell+ ;         \ indecates type of reference: 0: call, 1: address, 2: doer
1.53      jwilke    873: : >taddr cell+ cell+ ; 
1.52      jwilke    874: : >ghost 3 cells + ;
1.53      jwilke    875: : >file 4 cells + ;
                    876: : >line 5 cells + ;
1.48      anton     877: 
1.54      pazsan    878: : (refered) ( ghost addr tag -- )
                    879: \G creates a reference to ghost at address taddr
                    880:     rot >r here r@ >link @ , r> >link ! 
                    881:     ( taddr tag ) ,
                    882:     ( taddr ) , 
                    883:     last-header-ghost @ , 
                    884:     loadfile , 
                    885:     sourceline# , 
                    886:   ;
                    887: 
1.52      jwilke    888: : refered ( ghost tag -- )
1.53      jwilke    889: \G creates a resolve structure
1.54      pazsan    890:     T here aligned H swap (refered)
                    891:   ;
                    892: 
                    893: : killref ( addr ghost -- )
                    894: \G kills a forward reference to ghost at position addr
                    895: \G this is used to eleminate a :dovar refence after making a DOES>
                    896:     dup >magic @ <fwd> <> IF 2drop EXIT THEN
                    897:     swap >r >link
                    898:     BEGIN dup @ dup  ( addr last this )
                    899:     WHILE dup >taddr @ r@ =
                    900:         IF   @ over !
                    901:         ELSE nip THEN
                    902:     REPEAT rdrop 2drop 
1.53      jwilke    903:   ;
1.48      anton     904: 
1.52      jwilke    905: Defer resolve-warning
1.1       anton     906: 
1.52      jwilke    907: : reswarn-test ( ghost res-struct -- ghost res-struct )
                    908:   over cr ." Resolving " >ghostname type dup ."  in " >ghost @ >ghostname type ;
1.1       anton     909: 
1.52      jwilke    910: : reswarn-forward ( ghost res-struct -- ghost res-struct )
                    911:   over warnhead >ghostname type dup ."  is referenced in " 
                    912:   >ghost @ >ghostname type ;
1.1       anton     913: 
1.52      jwilke    914: \ ' reswarn-test IS resolve-warning
                    915:  
1.1       anton     916: \ resolve                                              14oct92py
                    917: 
1.54      pazsan    918:  : resolve-loop ( ghost resolve-list tcfa -- )
                    919:     >r
                    920:     BEGIN dup WHILE 
                    921: \        dup >tag @ 2 = IF reswarn-forward THEN
                    922:          resolve-warning 
                    923:          r@ over >taddr @ 
                    924:          2 pick >tag @
                    925:          CASE  0 OF colon-resolve ENDOF
                    926:                1 OF addr-resolve ENDOF
                    927:                2 OF doer-resolve ENDOF
                    928:          ENDCASE
                    929:          @ \ next list element
                    930:     REPEAT 2drop rdrop 
                    931:   ;
1.52      jwilke    932: 
                    933: \ : resolve-loop ( ghost tcfa -- ghost tcfa )
                    934: \  >r dup >link @
                    935: \  BEGIN  dup  WHILE  dup T @ H r@ rot T ! H REPEAT  drop r> ;
1.1       anton     936: 
                    937: \ exists                                                9may93jaw
                    938: 
1.52      jwilke    939: Variable TWarnings
                    940: TWarnings on
                    941: Variable Exists-Warnings
                    942: Exists-Warnings on
                    943: 
1.1       anton     944: : exists ( ghost tcfa -- )
                    945:   over GhostNames
                    946:   BEGIN @ dup
                    947:   WHILE 2dup cell+ @ =
                    948:   UNTIL
1.52      jwilke    949:         2 cells + count
                    950:         TWarnings @ Exists-Warnings @ and
                    951:         IF warnhead type ."  exists"
                    952:         ELSE 2drop THEN
                    953:         drop swap >link !
1.24      pazsan    954:   ELSE  true abort" CROSS: Ghostnames inconsistent "
1.1       anton     955:   THEN ;
                    956: 
                    957: : resolve  ( ghost tcfa -- )
1.54      pazsan    958: \G resolve referencies to ghost with tcfa
                    959:     \ is ghost resolved?, second resolve means another definition with the
                    960:     \ same name
                    961:     over forward? 0= IF  exists EXIT THEN
                    962:     \ get linked-list
                    963:     swap >r r@ >link @ swap \ ( list tcfa R: ghost )
                    964:     \ mark ghost as resolved
                    965:     dup r@ >link ! <res> r@ >magic !
                    966:     \ loop through forward referencies
                    967:     r> -rot 
                    968:     comp-state @ >r Resolving comp-state !
                    969:     resolve-loop 
                    970:     r> comp-state !
                    971: 
                    972:     ['] noop IS resolve-warning 
1.52      jwilke    973:   ;
1.1       anton     974: 
                    975: \ gexecute ghost,                                      01nov92py
                    976: 
1.52      jwilke    977: : is-forward   ( ghost -- )
1.54      pazsan    978:   colonmark, 0 (refered) ; \ compile space for call
1.52      jwilke    979: 
                    980: : is-resolved   ( ghost -- )
                    981:   >link @ colon, ; \ compile-call
                    982: 
                    983: : gexecute   ( ghost -- )
                    984:   dup @ <fwd> = IF  is-forward  ELSE  is-resolved  THEN ;
                    985: 
                    986: : addr,  ( ghost -- )
                    987:   dup @ <fwd> = IF  1 refered 0 T a, H ELSE >link @ T a, H THEN ;
                    988: 
                    989: \ !! : ghost,     ghost  gexecute ;
1.1       anton     990: 
                    991: \ .unresolved                                          11may93jaw
                    992: 
                    993: variable ResolveFlag
                    994: 
                    995: \ ?touched                                             11may93jaw
                    996: 
1.52      jwilke    997: : ?touched ( ghost -- flag ) dup forward? swap >link @
1.1       anton     998:                                0 <> and ;
                    999: 
1.53      jwilke   1000: : .forwarddefs ( ghost -- )
                   1001:        ."  appeared in:"
                   1002:        >link
                   1003:        BEGIN   @ dup
                   1004:        WHILE   cr 5 spaces
                   1005:                dup >ghost @ >ghostname type
                   1006:                ."  file " dup >file @ ?dup IF count type ELSE ." CON" THEN
                   1007:                ."  line " dup >line @ .dec
                   1008:        REPEAT 
                   1009:        drop ;
                   1010: 
1.1       anton    1011: : ?resolved  ( ghostname -- )
                   1012:   dup cell+ @ ?touched
1.53      jwilke   1013:   IF   dup 
                   1014:        cell+ cell+ count cr type ResolveFlag on 
                   1015:        cell+ @ .forwarddefs
                   1016:   ELSE         drop 
                   1017:   THEN ;
1.1       anton    1018: 
                   1019: >MINIMAL
                   1020: : .unresolved  ( -- )
                   1021:   ResolveFlag off cr ." Unresolved: "
                   1022:   Ghostnames
                   1023:   BEGIN @ dup
                   1024:   WHILE dup ?resolved
1.10      anton    1025:   REPEAT drop ResolveFlag @
                   1026:   IF
1.48      anton    1027:       -1 abort" Unresolved words!"
1.10      anton    1028:   ELSE
                   1029:       ." Nothing!"
                   1030:   THEN
                   1031:   cr ;
1.1       anton    1032: 
1.52      jwilke   1033: : .stats
                   1034:   base @ >r decimal
                   1035:   cr ." named Headers: " headers-named @ . 
                   1036:   r> base ! ;
                   1037: 
1.1       anton    1038: >CROSS
                   1039: \ Header states                                        12dec92py
                   1040: 
                   1041: : flag! ( 8b -- )   tlast @ dup >r T c@ xor r> c! H ;
                   1042: 
                   1043: VARIABLE ^imm
                   1044: 
                   1045: >TARGET
1.36      anton    1046: : immediate     40 flag!
1.18      pazsan   1047:                 ^imm @ @ dup <imm> = IF  drop  EXIT  THEN
1.1       anton    1048:                 <res> <> ABORT" CROSS: Cannot immediate a unresolved word"
                   1049:                 <imm> ^imm @ ! ;
1.36      anton    1050: : restrict      20 flag! ;
1.52      jwilke   1051: 
1.54      pazsan   1052: : isdoer       
                   1053: \G define a forth word as doer, this makes obviously only sence on
                   1054: \G forth processors such as the PSC1000
                   1055:                <do:> last-header-ghost @ >magic ! ;
1.1       anton    1056: >CROSS
                   1057: 
                   1058: \ ALIAS2 ansforth conform alias                          9may93jaw
                   1059: 
                   1060: : ALIAS2 create here 0 , DOES> @ execute ;
                   1061: \ usage:
1.18      pazsan   1062: \ ' <name> alias2 bla !
1.1       anton    1063: 
                   1064: \ Target Header Creation                               01nov92py
                   1065: 
1.52      jwilke   1066: >TARGET
1.1       anton    1067: : string,  ( addr count -- )
1.28      pazsan   1068:   dup T c, H bounds  ?DO  I c@ T c, H  LOOP ; 
1.52      jwilke   1069: : name,  ( "name" -- )  bl word count T string, cfalign H ;
1.1       anton    1070: : view,   ( -- ) ( dummy ) ;
1.52      jwilke   1071: >CROSS
1.1       anton    1072: 
1.25      pazsan   1073: \ Target Document Creation (goes to crossdoc.fd)       05jul95py
                   1074: 
1.55      pazsan   1075: s" ./doc/crossdoc.fd" r/w create-file throw value doc-file-id
1.25      pazsan   1076: \ contains the file-id of the documentation file
                   1077: 
1.40      pazsan   1078: : T-\G ( -- )
1.25      pazsan   1079:     source >in @ /string doc-file-id write-line throw
1.40      pazsan   1080:     postpone \ ;
1.25      pazsan   1081: 
1.39      pazsan   1082: Variable to-doc  to-doc on
1.25      pazsan   1083: 
                   1084: : cross-doc-entry  ( -- )
                   1085:     to-doc @ tlast @ 0<> and   \ not an anonymous (i.e. noname) header
                   1086:     IF
                   1087:        s" " doc-file-id write-line throw
                   1088:        s" make-doc " doc-file-id write-file throw
                   1089:        tlast @ >image count $1F and doc-file-id write-file throw
                   1090:        >in @
                   1091:        [char] ( parse 2drop
                   1092:        [char] ) parse doc-file-id write-file throw
                   1093:        s"  )" doc-file-id write-file throw
                   1094:        [char] \ parse 2drop                                    
1.40      pazsan   1095:        T-\G
1.25      pazsan   1096:        >in !
1.39      pazsan   1097:     THEN ;
1.25      pazsan   1098: 
1.28      pazsan   1099: \ Target TAGS creation
                   1100: 
1.39      pazsan   1101: s" kernel.TAGS" r/w create-file throw value tag-file-id
1.28      pazsan   1102: \ contains the file-id of the tags file
                   1103: 
                   1104: Create tag-beg 2 c,  7F c, bl c,
                   1105: Create tag-end 2 c,  bl c, 01 c,
                   1106: Create tag-bof 1 c,  0C c,
                   1107: 
                   1108: 2variable last-loadfilename 0 0 last-loadfilename 2!
                   1109:            
                   1110: : put-load-file-name ( -- )
                   1111:     loadfilename 2@ last-loadfilename 2@ d<>
                   1112:     IF
                   1113:        tag-bof count tag-file-id write-line throw
1.31      anton    1114:        sourcefilename 2dup
1.28      pazsan   1115:        tag-file-id write-file throw
                   1116:        last-loadfilename 2!
                   1117:        s" ,0" tag-file-id write-line throw
                   1118:     THEN ;
                   1119: 
                   1120: : cross-tag-entry  ( -- )
                   1121:     tlast @ 0<>        \ not an anonymous (i.e. noname) header
                   1122:     IF
                   1123:        put-load-file-name
                   1124:        source >in @ min tag-file-id write-file throw
                   1125:        tag-beg count tag-file-id write-file throw
                   1126:        tlast @ >image count $1F and tag-file-id write-file throw
                   1127:        tag-end count tag-file-id write-file throw
1.31      anton    1128:        base @ decimal sourceline# 0 <# #s #> tag-file-id write-file throw
1.28      pazsan   1129: \      >in @ 0 <# #s [char] , hold #> tag-file-id write-line throw
                   1130:        s" ,0" tag-file-id write-line throw
                   1131:        base !
                   1132:     THEN ;
                   1133: 
1.43      pazsan   1134: \ Check for words
                   1135: 
                   1136: Defer skip? ' false IS skip?
                   1137: 
                   1138: : defined? ( -- flag ) \ name
1.52      jwilke   1139:     ghost forward? 0= ;
1.43      pazsan   1140: 
                   1141: : needed? ( -- flag ) \ name
1.48      anton    1142: \G returns a false flag when
                   1143: \G a word is not defined
                   1144: \G a forward reference exists
                   1145: \G so the definition is not skipped!
                   1146:     bl word gfind
1.52      jwilke   1147:     IF dup forward?
1.48      anton    1148:        nip
                   1149:        0=
                   1150:     ELSE  drop true  THEN ;
1.43      pazsan   1151: 
1.44      pazsan   1152: : doer? ( -- flag ) \ name
                   1153:     ghost >magic @ <do:> = ;
                   1154: 
1.43      pazsan   1155: : skip-defs ( -- )
                   1156:     BEGIN  refill  WHILE  source -trailing nip 0= UNTIL  THEN ;
                   1157: 
1.28      pazsan   1158: \ Target header creation
                   1159: 
1.54      pazsan   1160: Variable CreateFlag
                   1161: CreateFlag off
1.52      jwilke   1162: 
1.54      pazsan   1163: Variable NoHeaderFlag
                   1164: NoHeaderFlag off
1.1       anton    1165: 
1.54      pazsan   1166: : 0.r ( n1 n2 -- ) 
                   1167:     base @ >r hex 
                   1168:     0 swap <# 0 ?DO # LOOP #> type 
                   1169:     r> base ! ;
1.52      jwilke   1170: : .sym
                   1171:   bounds 
                   1172:   DO I c@ dup
                   1173:        CASE    '/ OF drop ." \/" ENDOF
                   1174:                '\ OF drop ." \\" ENDOF
                   1175:                dup OF emit ENDOF
                   1176:        ENDCASE
1.54      pazsan   1177:     LOOP ;
1.52      jwilke   1178: 
1.43      pazsan   1179: : (Theader ( "name" -- ghost )
1.54      pazsan   1180:     \  >in @ bl word count type 2 spaces >in !
                   1181:     \ wordheaders will always be compiled to rom
                   1182:     switchrom
                   1183:     \ build header in target
                   1184:     NoHeaderFlag @
                   1185:     IF  NoHeaderFlag off
                   1186:     ELSE
                   1187:        T align H view,
1.59      pazsan   1188:        tlast @ dup 0> IF  T 1 cells - H THEN T A, H  there tlast !
1.54      pazsan   1189:        1 headers-named +!      \ Statistic
                   1190:        >in @ T name, H >in !
                   1191:     THEN
                   1192:     T cfalign here H tlastcfa !
                   1193:     \ Symbol table
                   1194: \    >in @ cr ." sym:s/CFA=" there 4 0.r ." /"  bl word count .sym ." /g" cr >in !
                   1195:     CreateFlag @
                   1196:     IF
                   1197:        >in @ alias2 swap >in !         \ create alias in target
                   1198:        >in @ ghost swap >in !
                   1199:        swap also ghosts ' previous swap !     \ tick ghost and store in alias
                   1200:        CreateFlag off
                   1201:     ELSE ghost
                   1202:     THEN
                   1203:     dup Last-Header-Ghost !
                   1204:     dup >magic ^imm !     \ a pointer for immediate
                   1205:     Already @
                   1206:     IF  dup >end tdoes !
                   1207:     ELSE 0 tdoes !
                   1208:     THEN
                   1209:     80 flag!
                   1210:     cross-doc-entry cross-tag-entry ;
1.1       anton    1211: 
                   1212: VARIABLE ;Resolve 1 cells allot
1.52      jwilke   1213: \ this is the resolver information from ":"
                   1214: \ resolving is done by ";"
1.1       anton    1215: 
1.11      pazsan   1216: : Theader  ( "name" -- ghost )
                   1217:   (THeader dup there resolve 0 ;Resolve ! ;
1.1       anton    1218: 
                   1219: >TARGET
                   1220: : Alias    ( cfa -- ) \ name
1.43      pazsan   1221:     >in @ skip? IF  2drop  EXIT  THEN  >in !
1.53      jwilke   1222:     dup 0< s" prims" T $has? H 0= and
1.43      pazsan   1223:     IF
1.53      jwilke   1224:        .sourcepos ." needs prim: " >in @ bl word count type >in ! cr
1.43      pazsan   1225:     THEN
                   1226:     (THeader over resolve T A, H 80 flag! ;
1.42      pazsan   1227: : Alias:   ( cfa -- ) \ name
1.43      pazsan   1228:     >in @ skip? IF  2drop  EXIT  THEN  >in !
1.53      jwilke   1229:     dup 0< s" prims" T $has? H 0= and
1.43      pazsan   1230:     IF
1.53      jwilke   1231:        .sourcepos ." needs doer: " >in @ bl word count type >in ! cr
1.43      pazsan   1232:     THEN
                   1233:     ghost tuck swap resolve <do:> swap >magic ! ;
1.64      pazsan   1234: 
                   1235: Variable prim#
                   1236: : first-primitive ( n -- )  prim# ! ;
                   1237: : Primitive  ( -- ) \ name
                   1238:     prim# @ T Alias H  -1 prim# +! ;
1.1       anton    1239: >CROSS
                   1240: 
                   1241: \ Conditionals and Comments                            11may93jaw
                   1242: 
                   1243: : ;Cond
                   1244:   postpone ;
                   1245:   swap ! ;  immediate
                   1246: 
                   1247: : Cond: ( -- ) \ name {code } ;
                   1248:   atonce on
                   1249:   ghost
                   1250:   >exec
                   1251:   :NONAME ;
                   1252: 
                   1253: : restrict? ( -- )
                   1254: \ aborts on interprete state - ae
                   1255:   state @ 0= ABORT" CROSS: Restricted" ;
                   1256: 
                   1257: : Comment ( -- )
                   1258:   >in @ atonce on ghost swap >in ! ' swap >exec ! ;
                   1259: 
                   1260: Comment (       Comment \
                   1261: 
                   1262: \ compile                                              10may93jaw
                   1263: 
                   1264: : compile  ( -- ) \ name
                   1265:   restrict?
1.13      pazsan   1266:   bl word gfind dup 0= ABORT" CROSS: Can't compile "
1.1       anton    1267:   0> ( immediate? )
                   1268:   IF    >exec @ compile,
                   1269:   ELSE  postpone literal postpone gexecute  THEN ;
                   1270:                                         immediate
                   1271: 
1.52      jwilke   1272: : [G'] 
                   1273: \G ticks a ghost and returns its address
                   1274:   bl word gfind 0= ABORT" CROSS: Ghost don't exists"
                   1275:   state @
                   1276:   IF   postpone literal
                   1277:   THEN ; immediate
                   1278: 
                   1279: : ghost>cfa
                   1280:   dup forward? ABORT" CROSS: forward " >link @ ;
                   1281:                
                   1282: >TARGET
                   1283: 
                   1284: : '  ( -- cfa ) 
                   1285: \ returns the target-cfa of a ghost
                   1286:   bl word gfind 0= ABORT" CROSS: Ghost don't exists"
                   1287:   ghost>cfa ;
                   1288: 
                   1289: Cond: [']  T ' H alit, ;Cond
                   1290: 
                   1291: >CROSS
                   1292: 
                   1293: : [T']
                   1294: \ returns the target-cfa of a ghost, or compiles it as literal
                   1295:   postpone [G'] state @ IF postpone ghost>cfa ELSE ghost>cfa THEN ; immediate
1.42      pazsan   1296: 
1.52      jwilke   1297: \ \ threading modell                                   13dec92py
                   1298: \ modularized                                          14jun97jaw
                   1299: 
                   1300: : fillcfa   ( usedcells -- )
1.59      pazsan   1301:   T cells H xt>body swap - 0 ?DO 0 T c, tchar H +LOOP ;
1.52      jwilke   1302: 
                   1303: : (>body)   ( cfa -- pfa ) xt>body + ;         ' (>body) T IS >body H
                   1304: 
                   1305: : (doer,)   ( ghost -- ) ]comp gexecute comp[ 1 fillcfa ;   ' (doer,) IS doer,
                   1306: 
                   1307: : (docol,)  ( -- ) [G'] :docol doer, ;         ' (docol,) IS docol,
                   1308: 
                   1309: : (doprim,) ( -- )
                   1310:   there xt>body + ca>native T a, H 1 fillcfa ; ' (doprim,) IS doprim,
                   1311: 
                   1312: : (doeshandler,) ( -- ) 
                   1313:   T cfalign H compile :doesjump T 0 , H ;      ' (doeshandler,) IS doeshandler,
                   1314: 
                   1315: : (dodoes,) ( does-action-ghost -- )
                   1316:   ]comp [G'] :dodoes gexecute comp[
                   1317:   addr,
                   1318:   T here H tcell - reloff 2 fillcfa ;          ' (dodoes,) IS dodoes,
                   1319: 
                   1320: : (lit,) ( n -- )   compile lit T  ,  H ;      ' (lit,) IS lit,
                   1321: 
1.67    ! jwilke   1322: \ if we dont produce relocatable code alit, defaults to lit, jaw
        !          1323: has? relocate
        !          1324: [IF]
1.66      pazsan   1325: : (alit,) ( n -- )  compile lit T  a, H ;      ' (alit,) IS alit,
1.67    ! jwilke   1326: [ELSE]
        !          1327: : (alit,) ( n -- )  lit, ;                     ' (alit,) IS alit,
        !          1328: [THEN]
1.52      jwilke   1329: 
                   1330: : (fini,)         compile ;s ;                ' (fini,) IS fini,
1.42      pazsan   1331: 
1.43      pazsan   1332: [IFUNDEF] (code) 
                   1333: Defer (code)
                   1334: Defer (end-code)
                   1335: [THEN]
                   1336: 
1.1       anton    1337: >TARGET
1.43      pazsan   1338: : Code
1.52      jwilke   1339:   defempty?
1.48      anton    1340:   (THeader there resolve
1.53      jwilke   1341:   [ T e? prims H 0= [IF] T e? ITC H [ELSE] true [THEN] ] [IF]
1.52      jwilke   1342:   doprim, 
1.48      anton    1343:   [THEN]
                   1344:   depth (code) ;
1.43      pazsan   1345: 
                   1346: : Code:
1.52      jwilke   1347:   defempty?
1.48      anton    1348:     ghost dup there ca>native resolve  <do:> swap >magic !
1.43      pazsan   1349:     depth (code) ;
                   1350: 
                   1351: : end-code
1.52      jwilke   1352:     (end-code)
1.43      pazsan   1353:     depth ?dup IF   1- <> ABORT" CROSS: Stack changed"
                   1354:     ELSE true ABORT" CROSS: Stack empty" THEN
1.52      jwilke   1355:     ;
1.14      anton    1356: 
1.57      pazsan   1357: ( Cond ) : chars tchar * ; ( Cond )
1.1       anton    1358: 
                   1359: >CROSS
1.52      jwilke   1360: 
1.1       anton    1361: \ tLiteral                                             12dec92py
                   1362: 
                   1363: >TARGET
1.40      pazsan   1364: Cond: \G  T-\G ;Cond
                   1365: 
1.1       anton    1366: Cond:  Literal ( n -- )   restrict? lit, ;Cond
                   1367: Cond: ALiteral ( n -- )   restrict? alit, ;Cond
                   1368: 
                   1369: : Char ( "<char>" -- )  bl word char+ c@ ;
                   1370: Cond: [Char]   ( "<char>" -- )  restrict? Char  lit, ;Cond
                   1371: 
1.43      pazsan   1372: \ some special literals                                        27jan97jaw
                   1373: 
1.52      jwilke   1374: \ !! Known Bug: Special Literals and plug-ins work only correct
                   1375: \ on 16 and 32 Bit Targets and 32 Bit Hosts!
                   1376: 
1.43      pazsan   1377: Cond: MAXU
1.52      jwilke   1378:   restrict? 
                   1379:   tcell 1 cells u> 
                   1380:   IF   compile lit tcell 0 ?DO FF T c, H LOOP 
                   1381:   ELSE $ffffffff lit, THEN
                   1382:   ;Cond
1.43      pazsan   1383: 
                   1384: Cond: MINI
1.52      jwilke   1385:   restrict?
                   1386:   tcell 1 cells u>
                   1387:   IF   compile lit bigendian 
                   1388:        IF      80 T c, H tcell 1 ?DO 0 T c, H LOOP 
                   1389:        ELSE    tcell 1 ?DO 0 T c, H LOOP 80 T c, H
                   1390:        THEN
                   1391:   ELSE tcell 2 = IF $8000 ELSE $80000000 THEN lit, THEN
                   1392:   ;Cond
1.43      pazsan   1393:  
                   1394: Cond: MAXI
1.52      jwilke   1395:  restrict?
                   1396:  tcell 1 cells u>
                   1397:  IF    compile lit bigendian 
                   1398:        IF      7F T c, H tcell 1 ?DO FF T c, H LOOP
                   1399:        ELSE    tcell 1 ?DO FF T c, H LOOP 7F T c, H
                   1400:        THEN
                   1401:  ELSE  tcell 2 = IF $7fff ELSE $7fffffff THEN lit, THEN
1.43      pazsan   1402:  ;Cond
                   1403: 
1.1       anton    1404: >CROSS
                   1405: \ Target compiling loop                                12dec92py
                   1406: \ ">tib trick thrown out                               10may93jaw
                   1407: \ number? defined at the top                           11may93jaw
                   1408: 
                   1409: \ compiled word might leave items on stack!
                   1410: : tcom ( in name -- )
                   1411:   gfind  ?dup  IF    0> IF    nip >exec @ execute
                   1412:                         ELSE  nip gexecute  THEN EXIT THEN
                   1413:   number? dup  IF    0> IF swap lit,  THEN  lit,  drop
                   1414:                ELSE  2drop >in !
                   1415:                ghost gexecute THEN  ;
                   1416: 
                   1417: >TARGET
                   1418: \ : ; DOES>                                            13dec92py
                   1419: \ ]                                                     9may93py/jaw
                   1420: 
                   1421: : ] state on
1.54      pazsan   1422:     Compiling comp-state !
1.1       anton    1423:     BEGIN
1.13      pazsan   1424:         BEGIN >in @ bl word
1.1       anton    1425:               dup c@ 0= WHILE 2drop refill 0=
                   1426:               ABORT" CROSS: End of file while target compiling"
                   1427:         REPEAT
                   1428:         tcom
                   1429:         state @
                   1430:         0=
                   1431:     UNTIL ;
                   1432: 
                   1433: \ by the way: defining a second interpreter (a compiler-)loop
                   1434: \             is not allowed if a system should be ans conform
                   1435: 
                   1436: : : ( -- colon-sys ) \ Name
1.52      jwilke   1437:   defempty?
                   1438:   constflag off \ don't let this flag work over colon defs
                   1439:                \ just to go sure nothing unwanted happens
1.43      pazsan   1440:   >in @ skip? IF  drop skip-defs  EXIT  THEN  >in !
1.1       anton    1441:   (THeader ;Resolve ! there ;Resolve cell+ !
1.52      jwilke   1442:   docol, ]comp depth T ] H ;
1.1       anton    1443: 
1.37      pazsan   1444: : :noname ( -- colon-sys )
1.52      jwilke   1445:   T cfalign H there docol, 0 ;Resolve ! depth T ] H ;
1.37      pazsan   1446: 
1.2       pazsan   1447: Cond: EXIT ( -- )  restrict?  compile ;S  ;Cond
1.6       anton    1448: 
                   1449: Cond: ?EXIT ( -- ) 1 abort" CROSS: using ?exit" ;Cond
1.2       pazsan   1450: 
1.52      jwilke   1451: >CROSS
                   1452: : LastXT ;Resolve @ 0= abort" CROSS: no definition for LastXT"
                   1453:          ;Resolve cell+ @ ;
                   1454: 
                   1455: >TARGET
                   1456: 
                   1457: Cond: recurse ( -- ) Last-Ghost @ gexecute ;Cond
                   1458: 
1.1       anton    1459: Cond: ; ( -- ) restrict?
                   1460:                depth ?dup IF   1- <> ABORT" CROSS: Stack changed"
                   1461:                           ELSE true ABORT" CROSS: Stack empty" THEN
1.52      jwilke   1462:                fini,
                   1463:                comp[
                   1464:                state off
1.1       anton    1465:                ;Resolve @
                   1466:                IF ;Resolve @ ;Resolve cell+ @ resolve THEN
1.54      pazsan   1467:                Interpreting comp-state !
1.1       anton    1468:                ;Cond
1.54      pazsan   1469: Cond: [  restrict? state off Interpreting comp-state ! ;Cond
1.1       anton    1470: 
                   1471: >CROSS
1.54      pazsan   1472: 
                   1473: Create GhostDummy ghostheader
                   1474: <res> GhostDummy >magic !
                   1475: 
1.52      jwilke   1476: : !does ( does-action -- )
                   1477: \ !! zusammenziehen und dodoes, machen!
1.54      pazsan   1478:     tlastcfa @ [G'] :dovar killref
                   1479: \    tlastcfa @ dup there >r tdp ! compile :dodoes r> tdp ! T cell+ ! H ;
1.52      jwilke   1480: \ !! geht so nicht, da dodoes, ghost will!
1.54      pazsan   1481:     GhostDummy >link ! GhostDummy 
                   1482:     tlastcfa @ >tempdp dodoes, tempdp> ;
1.1       anton    1483: 
                   1484: >TARGET
                   1485: Cond: DOES> restrict?
1.52      jwilke   1486:         compile (does>) doeshandler, 
                   1487:        \ resolve words made by builders
                   1488:        tdoes @ ?dup IF  @ T here H resolve THEN
1.1       anton    1489:         ;Cond
1.52      jwilke   1490: : DOES> switchrom doeshandler, T here H !does depth T ] H ;
1.1       anton    1491: 
                   1492: >CROSS
                   1493: \ Creation                                             01nov92py
                   1494: 
                   1495: \ Builder                                               11may93jaw
                   1496: 
1.52      jwilke   1497: : Builder    ( Create-xt do:-xt "name" -- )
                   1498: \ builds up a builder in current vocabulary
                   1499: \ create-xt is executed when word is interpreted
                   1500: \ do:-xt is executet when the created word from builder is executed
                   1501: \ for do:-xt an additional entry after the normal ghost-enrys is used
                   1502: 
1.1       anton    1503:   >in @ alias2 swap dup >in ! >r >r
1.54      pazsan   1504:   Make-Ghost 
                   1505:   rot swap >exec dup @ ['] NoExec <>
                   1506:   IF 2drop ELSE ! THEN
                   1507:   ,
1.1       anton    1508:   r> r> >in !
1.11      pazsan   1509:   also ghosts ' previous swap ! ;
                   1510: \  DOES>  dup >exec @ execute ;
1.1       anton    1511: 
1.52      jwilke   1512: : gdoes,  ( ghost -- )
                   1513: \ makes the codefield for a word that is built
                   1514:   >end @ dup forward? 0=
                   1515:   IF
1.42      pazsan   1516:        dup >magic @ <do:> =
1.54      pazsan   1517:        IF       doer, 
                   1518:        ELSE    dodoes,
                   1519:        THEN
                   1520:        EXIT
1.52      jwilke   1521:   THEN
                   1522: \  compile :dodoes gexecute
                   1523: \  T here H tcell - reloff 
1.54      pazsan   1524:   2 refered 
                   1525:   0 fillcfa
                   1526:   ;
1.1       anton    1527: 
1.52      jwilke   1528: : TCreate ( <name> -- )
                   1529:   executed-ghost @
1.1       anton    1530:   CreateFlag on
1.52      jwilke   1531:   create-forward-warn
                   1532:   IF ['] reswarn-forward IS resolve-warning THEN
1.11      pazsan   1533:   Theader >r dup gdoes,
1.52      jwilke   1534: \ stores execution symantic in the built word
                   1535:   >end @ >exec @ r> >exec ! ;
                   1536: 
                   1537: : RTCreate ( <name> -- )
                   1538: \ creates a new word with code-field in ram
                   1539:   executed-ghost @
                   1540:   CreateFlag on
                   1541:   create-forward-warn
                   1542:   IF ['] reswarn-forward IS resolve-warning THEN
                   1543:   \ make Alias
                   1544:   (THeader there 0 T a, H 80 flag! ( S executed-ghost new-ghost )
                   1545:   \ store  poiter to code-field
                   1546:   switchram T cfalign H
                   1547:   there swap T ! H
                   1548:   there tlastcfa ! 
                   1549:   dup there resolve 0 ;Resolve !
                   1550:   >r dup gdoes,
1.11      pazsan   1551:   >end @ >exec @ r> >exec ! ;
1.1       anton    1552: 
                   1553: : Build:  ( -- [xt] [colon-sys] )
1.52      jwilke   1554:   :noname postpone TCreate ;
                   1555: 
                   1556: : BuildSmart:  ( -- [xt] [colon-sys] )
                   1557:   :noname
1.53      jwilke   1558:   [ T has? rom H [IF] ]
1.52      jwilke   1559:   postpone RTCreate
                   1560:   [ [ELSE] ]
                   1561:   postpone TCreate 
                   1562:   [ [THEN] ] ;
1.1       anton    1563: 
                   1564: : gdoes>  ( ghost -- addr flag )
1.52      jwilke   1565:   executed-ghost @
1.1       anton    1566:   state @ IF  gexecute true EXIT  THEN
1.52      jwilke   1567:   >link @ T >body H false ;
1.1       anton    1568: 
                   1569: \ DO: ;DO                                               11may93jaw
                   1570: \ changed to ?EXIT                                      10may93jaw
                   1571: 
                   1572: : DO:     ( -- addr [xt] [colon-sys] )
                   1573:   here ghostheader
1.11      pazsan   1574:   :noname postpone gdoes> postpone ?EXIT ;
1.1       anton    1575: 
1.42      pazsan   1576: : by:     ( -- addr [xt] [colon-sys] ) \ name
                   1577:   ghost
                   1578:   :noname postpone gdoes> postpone ?EXIT ;
                   1579: 
1.52      jwilke   1580: : ;DO ( addr [xt] [colon-sys] -- addr )
1.1       anton    1581:   postpone ;    ( S addr xt )
                   1582:   over >exec ! ; immediate
                   1583: 
                   1584: : by      ( -- addr ) \ Name
                   1585:   ghost >end @ ;
                   1586: 
                   1587: >TARGET
                   1588: \ Variables and Constants                              05dec92py
                   1589: 
1.52      jwilke   1590: Build:  ( n -- ) ;
                   1591: by: :docon ( ghost -- n ) T @ H ;DO
                   1592: Builder (Constant)
                   1593: 
                   1594: Build:  ( n -- ) T , H ;
                   1595: by (Constant)
                   1596: Builder Constant
                   1597: 
                   1598: Build:  ( n -- ) T A, H ;
                   1599: by (Constant)
                   1600: Builder AConstant
                   1601: 
                   1602: Build:  ( d -- ) T , , H ;
                   1603: DO: ( ghost -- d ) T dup cell+ @ swap @ H ;DO
                   1604: Builder 2Constant
                   1605: 
                   1606: BuildSmart: ;
1.42      pazsan   1607: by: :dovar ( ghost -- addr ) ;DO
1.1       anton    1608: Builder Create
                   1609: 
1.53      jwilke   1610: T has? rom H [IF]
1.54      pazsan   1611: Build: ( -- ) T here 0 , H switchram T align here swap ! 0 , H ( switchrom ) ;
1.52      jwilke   1612: by (Constant)
                   1613: Builder Variable
                   1614: [ELSE]
1.1       anton    1615: Build: T 0 , H ;
                   1616: by Create
                   1617: Builder Variable
1.52      jwilke   1618: [THEN]
1.1       anton    1619: 
1.53      jwilke   1620: T has? rom H [IF]
1.54      pazsan   1621: Build: ( -- ) T here 0 , H switchram T align here swap ! 0 , 0 , H ( switchrom ) ;
                   1622: by (Constant)
                   1623: Builder 2Variable
                   1624: [ELSE]
                   1625: Build: T 0 , 0 , H ;
                   1626: by Create
                   1627: Builder 2Variable
                   1628: [THEN]
                   1629: 
                   1630: T has? rom H [IF]
                   1631: Build: ( -- ) T here 0 , H switchram T align here swap ! 0 , H ( switchrom ) ;
1.52      jwilke   1632: by (Constant)
                   1633: Builder AVariable
                   1634: [ELSE]
1.1       anton    1635: Build: T 0 A, H ;
                   1636: by Create
                   1637: Builder AVariable
1.52      jwilke   1638: [THEN]
1.1       anton    1639: 
1.3       pazsan   1640: \ User variables                                       04may94py
                   1641: 
                   1642: >CROSS
                   1643: Variable tup  0 tup !
                   1644: Variable tudp 0 tudp !
                   1645: : u,  ( n -- udp )
                   1646:   tup @ tudp @ + T  ! H
1.19      pazsan   1647:   tudp @ dup T cell+ H tudp ! ;
1.3       pazsan   1648: : au, ( n -- udp )
                   1649:   tup @ tudp @ + T A! H
1.19      pazsan   1650:   tudp @ dup T cell+ H tudp ! ;
1.3       pazsan   1651: >TARGET
                   1652: 
                   1653: Build: T 0 u, , H ;
1.42      pazsan   1654: by: :douser ( ghost -- up-addr )  T @ H tup @ + ;DO
1.1       anton    1655: Builder User
                   1656: 
1.3       pazsan   1657: Build: T 0 u, , 0 u, drop H ;
                   1658: by User
1.1       anton    1659: Builder 2User
                   1660: 
1.3       pazsan   1661: Build: T 0 au, , H ;
                   1662: by User
1.1       anton    1663: Builder AUser
                   1664: 
1.52      jwilke   1665: BuildSmart: T , H ;
1.44      pazsan   1666: by (Constant)
1.1       anton    1667: Builder Value
                   1668: 
1.52      jwilke   1669: BuildSmart: T A, H ;
1.44      pazsan   1670: by (Constant)
1.32      pazsan   1671: Builder AValue
                   1672: 
1.52      jwilke   1673: BuildSmart:  ( -- ) [T'] noop T A, H ;
1.42      pazsan   1674: by: :dodefer ( ghost -- ) ABORT" CROSS: Don't execute" ;DO
1.1       anton    1675: Builder Defer
1.37      pazsan   1676: 
1.52      jwilke   1677: BuildSmart:  ( inter comp -- ) swap T immediate A, A, H ;
1.37      pazsan   1678: DO: ( ghost -- ) ABORT" CROSS: Don't execute" ;DO
1.38      anton    1679: Builder interpret/compile:
1.24      pazsan   1680: 
                   1681: \ Sturctures                                           23feb95py
                   1682: 
                   1683: >CROSS
                   1684: : nalign ( addr1 n -- addr2 )
                   1685: \ addr2 is the aligned version of addr1 wrt the alignment size n
                   1686:  1- tuck +  swap invert and ;
                   1687: >TARGET
                   1688: 
1.44      pazsan   1689: Build: ;
                   1690: by: :dofield T @ H + ;DO
                   1691: Builder (Field)
                   1692: 
1.51      anton    1693: Build: ( align1 offset1 align size "name" --  align2 offset2 )
                   1694:     rot dup T , H ( align1 align size offset1 )
                   1695:     + >r nalign r> ;
1.44      pazsan   1696: by (Field)
1.24      pazsan   1697: Builder Field
                   1698: 
1.51      anton    1699: : struct  T 1 chars 0 H ;
1.24      pazsan   1700: : end-struct  T 2Constant H ;
                   1701: 
1.52      jwilke   1702: : cell% ( n -- size align )
1.51      anton    1703:     T 1 cells H dup ;
1.24      pazsan   1704: 
                   1705: \ ' 2Constant Alias2 end-struct
                   1706: \ 0 1 T Chars H 2Constant struct
1.1       anton    1707: 
1.52      jwilke   1708: \ structural conditionals                              17dec92py
                   1709: 
                   1710: >CROSS
                   1711: : ?struc      ( flag -- )       ABORT" CROSS: unstructured " ;
                   1712: : sys?        ( sys -- sys )    dup 0= ?struc ;
                   1713: : >mark       ( -- sys )        T here  ( dup ." M" hex. ) 0 , H ;
                   1714: 
1.67    ! jwilke   1715: : branchoffset ( src dest -- ) - tchar / ; \ ?? jaw
1.52      jwilke   1716: 
                   1717: : >resolve    ( sys -- )        T here ( dup ." >" hex. ) over branchoffset swap ! H ;
                   1718: 
                   1719: : <resolve    ( sys -- )        T here ( dup ." <" hex. ) branchoffset , H ;
                   1720: 
1.54      pazsan   1721: :noname compile branch T here branchoffset , H ;
                   1722:   IS branch, ( target-addr -- )
                   1723: :noname compile ?branch T here branchoffset , H ;
                   1724:   IS ?branch, ( target-addr -- )
                   1725: :noname compile branch T here 0 , H ;
                   1726:   IS branchmark, ( -- branchtoken )
                   1727: :noname compile ?branch T here 0 , H ;
                   1728:   IS ?branchmark, ( -- branchtoken )
                   1729: :noname T here 0 , H ;
                   1730:   IS ?domark, ( -- branchtoken )
                   1731: :noname dup T @ H ?struc T here over branchoffset swap ! H ;
                   1732:   IS branchtoresolve, ( branchtoken -- )
                   1733: :noname branchto, T here H ;
                   1734:   IS branchtomark, ( -- target-addr )
1.52      jwilke   1735: 
                   1736: >TARGET
                   1737: 
                   1738: \ Structural Conditionals                              12dec92py
                   1739: 
                   1740: Cond: BUT       restrict? sys? swap ;Cond
                   1741: Cond: YET       restrict? sys? dup ;Cond
                   1742: 
1.54      pazsan   1743: 0 [IF]
1.52      jwilke   1744: >CROSS
                   1745: Variable tleavings
                   1746: >TARGET
                   1747: 
                   1748: Cond: DONE   ( addr -- )  restrict? tleavings @
                   1749:       BEGIN  2dup u> 0=  WHILE  dup T @ H swap >resolve REPEAT
                   1750:       tleavings ! drop ;Cond
                   1751: 
                   1752: >CROSS
1.54      pazsan   1753: : (leave)  T here H tleavings @ T , H  tleavings ! ;
1.52      jwilke   1754: >TARGET
                   1755: 
1.54      pazsan   1756: Cond: LEAVE     restrict? compile branch (leave) ;Cond
                   1757: Cond: ?LEAVE    restrict? compile 0=  compile ?branch (leave)  ;Cond
1.52      jwilke   1758: 
1.53      jwilke   1759: [ELSE]
                   1760:     \ !! This is WIP
                   1761:     \ The problem is (?DO)!
                   1762:     \ perhaps we need a plug-in for (?DO)
                   1763:     
                   1764: >CROSS
                   1765: Variable tleavings 0 tleavings !
1.54      pazsan   1766: : (done) ( addr -- )
                   1767:     tleavings @
                   1768:     BEGIN  dup
                   1769:     WHILE
                   1770:        >r dup r@ cell+ @ \ address of branch
                   1771:        u> 0=      \ lower than DO?     
                   1772:     WHILE
                   1773:        r@ 2 cells + @ \ branch token
                   1774:        branchtoresolve,
                   1775:        r@ @ r> free throw
                   1776:     REPEAT  r>  THEN
                   1777:     tleavings ! drop ;
                   1778: 
1.53      jwilke   1779: >TARGET
                   1780: 
1.54      pazsan   1781: Cond: DONE   ( addr -- )  restrict? (done) ;Cond
1.53      jwilke   1782: 
                   1783: >CROSS
1.54      pazsan   1784: : (leave) ( branchtoken -- )
1.53      jwilke   1785:     3 cells allocate throw >r
                   1786:     T here H r@ cell+ !
                   1787:     r@ 2 cells + !
                   1788:     tleavings @ r@ !
                   1789:     r> tleavings ! ;
                   1790: >TARGET
                   1791: 
1.54      pazsan   1792: Cond: LEAVE     restrict? branchmark, (leave) ;Cond
                   1793: Cond: ?LEAVE    restrict? compile 0=  ?branchmark, (leave)  ;Cond
1.53      jwilke   1794: 
                   1795: [THEN]
                   1796: 
1.54      pazsan   1797: >CROSS
                   1798: \ !!JW ToDo : Move to general tools section
                   1799: 
                   1800: : to1 ( x1 x2 xn n -- addr )
                   1801: \G packs n stack elements in a allocated memory region
                   1802:    dup dup 1+ cells allocate throw dup >r swap 1+
                   1803:    0 DO tuck ! cell+ LOOP
                   1804:    drop r> ;
                   1805: : 1to ( addr -- x1 x2 xn )
                   1806: \G unpacks the elements saved by to1
                   1807:     dup @ swap over cells + swap
                   1808:     0 DO  dup @ swap 1 cells -  LOOP
                   1809:     free throw ;
                   1810: 
                   1811: : loop]     branchto, dup <resolve tcell - (done) ;
                   1812: 
                   1813: : skiploop] ?dup IF branchto, branchtoresolve, THEN ;
                   1814: 
                   1815: >TARGET
                   1816: 
1.52      jwilke   1817: \ Structural Conditionals                              12dec92py
                   1818: 
1.53      jwilke   1819: >TARGET
1.52      jwilke   1820: Cond: AHEAD     restrict? branchmark, ;Cond
                   1821: Cond: IF        restrict? ?branchmark, ;Cond
                   1822: Cond: THEN      restrict? sys? branchto, branchtoresolve, ;Cond
                   1823: Cond: ELSE      restrict? sys? compile AHEAD swap compile THEN ;Cond
                   1824: 
                   1825: Cond: BEGIN     restrict? branchtomark, ;Cond
                   1826: Cond: WHILE     restrict? sys? compile IF swap ;Cond
                   1827: Cond: AGAIN     restrict? sys? branch, ;Cond
                   1828: Cond: UNTIL     restrict? sys? ?branch, ;Cond
                   1829: Cond: REPEAT    restrict? over 0= ?struc compile AGAIN compile THEN ;Cond
                   1830: 
                   1831: Cond: CASE      restrict? 0 ;Cond
                   1832: Cond: OF        restrict? 1+ >r compile over compile =
                   1833:                 compile IF compile drop r> ;Cond
1.45      pazsan   1834: Cond: ENDOF     restrict? >r compile ELSE r> ;Cond
                   1835: Cond: ENDCASE   restrict? compile drop 0 ?DO  compile THEN  LOOP ;Cond
1.1       anton    1836: 
                   1837: \ Structural Conditionals                              12dec92py
                   1838: 
1.67    ! jwilke   1839: :noname \ ?? i think 0 is too much! jaw
1.54      pazsan   1840:     0 compile (do)
                   1841:     branchtomark,  2 to1 ;
                   1842:   IS do, ( -- target-addr )
                   1843: 
                   1844: \ :noname
                   1845: \     compile 2dup compile = compile IF
                   1846: \     compile 2drop compile ELSE
                   1847: \     compile (do) branchtomark, 2 to1 ;
                   1848: \   IS ?do,
                   1849:     
                   1850: :noname
                   1851:     0 compile (?do)  ?domark, (leave)
                   1852:     branchtomark,  2 to1 ;
                   1853:   IS ?do, ( -- target-addr )
                   1854: :noname compile (for) branchtomark, ;
                   1855:   IS for, ( -- target-addr )
                   1856: :noname 1to compile (loop)  loop] compile unloop skiploop] ;
                   1857:   IS loop, ( target-addr -- )
                   1858: :noname 1to compile (+loop)  loop] compile unloop skiploop] ;
                   1859:   IS +loop, ( target-addr -- )
                   1860: :noname compile (next)  loop] compile unloop ;
                   1861:   IS next, ( target-addr -- )
                   1862: 
                   1863: Cond: DO       restrict? do, ;Cond
                   1864: Cond: ?DO      restrict? ?do, ;Cond
                   1865: Cond: FOR      restrict? for, ;Cond
                   1866: 
                   1867: Cond: LOOP     restrict? sys? loop, ;Cond
                   1868: Cond: +LOOP    restrict? sys? +loop, ;Cond
                   1869: Cond: NEXT     restrict? sys? next, ;Cond
1.52      jwilke   1870: 
1.1       anton    1871: \ String words                                         23feb93py
                   1872: 
1.52      jwilke   1873: : ,"            [char] " parse T string, align H ;
1.1       anton    1874: 
                   1875: Cond: ."        restrict? compile (.")     T ," H ;Cond
                   1876: Cond: S"        restrict? compile (S")     T ," H ;Cond
                   1877: Cond: ABORT"    restrict? compile (ABORT") T ," H ;Cond
                   1878: 
                   1879: Cond: IS        T ' >body H compile ALiteral compile ! ;Cond
1.66      pazsan   1880: : IS            T >address ' >body ! H ;
1.9       pazsan   1881: Cond: TO        T ' >body H compile ALiteral compile ! ;Cond
                   1882: : TO            T ' >body ! H ;
1.1       anton    1883: 
1.52      jwilke   1884: Cond: defers   T ' >body @ compile, H ;Cond
                   1885: : on           T -1 swap ! H ; 
                   1886: : off          T 0 swap ! H ;
                   1887: 
1.1       anton    1888: \ LINKED ERR" ENV" 2ENV"                                18may93jaw
                   1889: 
                   1890: \ linked list primitive
                   1891: : linked        T here over @ A, swap ! H ;
1.52      jwilke   1892: : chained      T linked A, H ;
1.1       anton    1893: 
                   1894: : err"   s" ErrLink linked" evaluate T , H
1.52      jwilke   1895:          [char] " parse T string, align H ;
1.1       anton    1896: 
                   1897: : env"  [char] " parse s" EnvLink linked" evaluate
1.52      jwilke   1898:         T string, align , H ;
1.1       anton    1899: 
                   1900: : 2env" [char] " parse s" EnvLink linked" evaluate
1.52      jwilke   1901:         here >r T string, align , , H
1.1       anton    1902:         r> dup T c@ H 80 and swap T c! H ;
                   1903: 
                   1904: \ compile must be last                                 22feb93py
                   1905: 
                   1906: Cond: compile ( -- ) restrict? \ name
1.13      pazsan   1907:       bl word gfind dup 0= ABORT" CROSS: Can't compile"
1.1       anton    1908:       0> IF    gexecute
                   1909:          ELSE  dup >magic @ <imm> =
                   1910:                IF   gexecute
1.54      pazsan   1911:                ELSE compile (compile) addr, THEN THEN ;Cond
1.1       anton    1912: 
                   1913: Cond: postpone ( -- ) restrict? \ name
1.13      pazsan   1914:       bl word gfind dup 0= ABORT" CROSS: Can't compile"
1.1       anton    1915:       0> IF    gexecute
                   1916:          ELSE  dup >magic @ <imm> =
                   1917:                IF   gexecute
1.54      pazsan   1918:               ELSE compile (compile) addr, THEN THEN ;Cond
                   1919:           
                   1920: \ \ minimal definitions
                   1921:           
1.1       anton    1922: >MINIMAL
                   1923: also minimal
                   1924: \ Usefull words                                        13feb93py
                   1925: 
                   1926: : KB  400 * ;
                   1927: 
1.54      pazsan   1928: \ \ [IF] [ELSE] [THEN] ...                             14sep97jaw
                   1929: 
                   1930: \ it is useful to define our own structures and not to rely
                   1931: \ on the words in the compiler
                   1932: \ The words in the compiler might be defined with vocabularies
                   1933: \ this doesn't work with our self-made compile-loop
                   1934: 
                   1935: Create parsed 20 chars allot   \ store word we parsed
                   1936: 
                   1937: : upcase
                   1938:     parsed count bounds
                   1939:     ?DO I c@ toupper I c! LOOP ;
                   1940: 
                   1941: : [ELSE]
                   1942:     1 BEGIN
                   1943:        BEGIN bl word count dup WHILE
                   1944:            comment? parsed place upcase parsed count
                   1945:            2dup s" [IF]" compare 0= >r 
                   1946:            2dup s" [IFUNDEF]" compare 0= >r
                   1947:            2dup s" [IFDEF]" compare 0= r> or r> or
                   1948:            IF   2drop 1+
                   1949:            ELSE 2dup s" [ELSE]" compare 0=
                   1950:                IF   2drop 1- dup
                   1951:                    IF 1+
                   1952:                    THEN
                   1953:                ELSE
                   1954:                    2dup s" [ENDIF]" compare 0= >r
                   1955:                    s" [THEN]" compare 0= r> or
                   1956:                    IF 1- THEN
                   1957:                THEN
                   1958:            THEN
                   1959:            ?dup 0= ?EXIT
                   1960:        REPEAT
                   1961:        2drop refill 0=
                   1962:     UNTIL drop ; immediate
                   1963:   
                   1964: : [THEN] ( -- ) ; immediate
                   1965: 
                   1966: : [ENDIF] ( -- ) ; immediate
                   1967: 
                   1968: : [IF] ( flag -- )
                   1969:     0= IF postpone [ELSE] THEN ; immediate 
                   1970: 
                   1971: Cond: [IF]      postpone [IF] ;Cond
                   1972: Cond: [THEN]    postpone [THEN] ;Cond
                   1973: Cond: [ELSE]    postpone [ELSE] ;Cond
                   1974: 
1.1       anton    1975: \ define new [IFDEF] and [IFUNDEF]                      20may93jaw
                   1976: 
1.43      pazsan   1977: : defined? defined? ;
1.44      pazsan   1978: : needed? needed? ;
                   1979: : doer? doer? ;
1.1       anton    1980: 
1.52      jwilke   1981: \ we want to use IFDEF on compiler directives (e.g. E?) in the source, too
                   1982: 
                   1983: : directive? 
                   1984:   bl word count [ ' target >wordlist ] aliteral search-wordlist 
                   1985:   dup IF nip THEN ;
                   1986: 
                   1987: : [IFDEF]  >in @ directive? swap >in !
                   1988:           0= IF defined? ELSE name 2drop true THEN
                   1989:           postpone [IF] ;
                   1990: 
1.43      pazsan   1991: : [IFUNDEF] defined? 0= postpone [IF] ;
1.1       anton    1992: 
1.54      pazsan   1993: Cond: [IFDEF]   postpone [IFDEF] ;Cond
                   1994: 
                   1995: Cond: [IFUNDEF] postpone [IFUNDEF] ;Cond
                   1996: 
1.1       anton    1997: \ C: \- \+ Conditional Compiling                         09jun93jaw
                   1998: 
1.43      pazsan   1999: : C: >in @ defined? 0=
1.1       anton    2000:      IF    >in ! T : H
                   2001:      ELSE drop
                   2002:         BEGIN bl word dup c@
                   2003:               IF   count comment? s" ;" compare 0= ?EXIT
                   2004:               ELSE refill 0= ABORT" CROSS: Out of Input while C:"
                   2005:               THEN
                   2006:         AGAIN
                   2007:      THEN ;
                   2008: 
                   2009: also minimal
                   2010: 
1.52      jwilke   2011: \G doesn't skip line when bit is set in debugmask
                   2012: : \D name evaluate debugmasksource @ and 0= IF postpone \ THEN ;
                   2013: 
1.48      anton    2014: \G interprets the line if word is not defined
1.43      pazsan   2015: : \- defined? IF postpone \ THEN ;
1.48      anton    2016: 
                   2017: \G interprets the line if word is defined
1.43      pazsan   2018: : \+ defined? 0= IF postpone \ THEN ;
1.1       anton    2019: 
1.48      anton    2020: Cond: \- \- ;Cond
                   2021: Cond: \+ \+ ;Cond
1.52      jwilke   2022: Cond: \D \D ;Cond
1.48      anton    2023: 
                   2024: : ?? bl word find IF execute ELSE drop 0 THEN ;
                   2025: 
                   2026: : needed:
                   2027: \G defines ghost for words that we want to be compiled
                   2028:   BEGIN >in @ bl word c@ WHILE >in ! ghost drop REPEAT drop ;
                   2029: 
                   2030: previous
                   2031: 
1.1       anton    2032: \ save-cross                                           17mar93py
                   2033: 
1.48      anton    2034: >CROSS
1.62      pazsan   2035: Create magic  s" Gforth2x" here over allot swap move
1.26      pazsan   2036: 
1.63      anton    2037: bigendian 1+ \ strangely, in magic big=0, little=1
                   2038: tcell 1 = 0 and or
1.62      pazsan   2039: tcell 2 = 2 and or
                   2040: tcell 4 = 4 and or
                   2041: tcell 8 = 6 and or
1.65      pazsan   2042: tchar 1 = $00 and or
                   2043: tchar 2 = $28 and or
                   2044: tchar 4 = $50 and or
                   2045: tchar 8 = $78 and or
1.62      pazsan   2046: magic 7 + c!
1.26      pazsan   2047: 
1.34      anton    2048: : save-cross ( "image-name" "binary-name" -- )
                   2049:   bl parse ." Saving to " 2dup type cr
1.1       anton    2050:   w/o bin create-file throw >r
1.48      anton    2051:   TNIL IF
1.43      pazsan   2052:       s" #! "   r@ write-file throw
                   2053:       bl parse  r@ write-file throw
                   2054:       s"  -i"   r@ write-file throw
                   2055:       #lf       r@ emit-file throw
                   2056:       r@ dup file-position throw drop 8 mod 8 swap ( file-id limit index )
                   2057:       ?do
                   2058:          bl over emit-file throw
                   2059:       loop
                   2060:       drop
                   2061:       magic 8       r@ write-file throw \ write magic
                   2062:   ELSE
                   2063:       bl parse 2drop
                   2064:   THEN
1.52      jwilke   2065:   image @ there 
                   2066:   r@ write-file throw \ write image
1.48      anton    2067:   TNIL IF
                   2068:       bit$  @ there 1- tcell>bit rshift 1+
1.16      pazsan   2069:                 r@ write-file throw \ write tags
1.43      pazsan   2070:   THEN
1.1       anton    2071:   r> close-file throw ;
                   2072: 
1.52      jwilke   2073: : save-region ( addr len -- )
                   2074:   bl parse w/o bin create-file throw >r
1.67    ! jwilke   2075:   swap >image swap r@ write-file throw
1.52      jwilke   2076:   r> close-file throw ;
                   2077: 
1.1       anton    2078: \ words that should be in minimal
1.52      jwilke   2079: 
                   2080: create s-buffer 50 chars allot
                   2081: 
1.48      anton    2082: >MINIMAL
                   2083: also minimal
1.1       anton    2084: 
1.48      anton    2085: bigendian Constant bigendian
1.52      jwilke   2086: : here there ;
1.67    ! jwilke   2087: : equ constant ;
        !          2088: : mark there constant ;
1.54      pazsan   2089: 
                   2090: \ compiler directives
1.52      jwilke   2091: : >ram >ram ;
                   2092: : >rom >rom ;
                   2093: : >auto >auto ;
                   2094: : >tempdp >tempdp ;
                   2095: : tempdp> tempdp> ;
                   2096: : const constflag on ;
                   2097: : warnings name 3 = 0= twarnings ! drop ;
1.60      anton    2098: : | ;
                   2099: \ : | NoHeaderFlag on ; \ This is broken (damages the last word)
1.52      jwilke   2100: 
1.48      anton    2101: : save-cross save-cross ;
1.52      jwilke   2102: : save-region save-region ;
                   2103: : tdump swap >image swap dump ;
                   2104: 
1.48      anton    2105: also forth 
1.52      jwilke   2106: [IFDEF] Label           : Label defempty? Label ; [THEN] 
                   2107: [IFDEF] start-macros    : start-macros defempty? start-macros ; [THEN]
                   2108: [IFDEF] builttag       : builttag builttag ;   [THEN]
1.48      anton    2109: previous
                   2110: 
1.52      jwilke   2111: : s" [char] " parse s-buffer place s-buffer count ; \ for environment?
1.43      pazsan   2112: : + + ;
1.52      jwilke   2113: : 1+ 1 + ;
                   2114: : 2+ 2 + ;
1.43      pazsan   2115: : or or ;
                   2116: : 1- 1- ;
                   2117: : - - ;
1.52      jwilke   2118: : and and ;
                   2119: : or or ;
1.43      pazsan   2120: : 2* 2* ;
                   2121: : * * ;
                   2122: : / / ;
                   2123: : dup dup ;
                   2124: : over over ;
                   2125: : swap swap ;
                   2126: : rot rot ;
                   2127: : drop drop ;
                   2128: : =   = ;
                   2129: : 0=   0= ;
                   2130: : lshift lshift ;
                   2131: : 2/ 2/ ;
1.19      pazsan   2132: : . . ;
1.1       anton    2133: 
1.43      pazsan   2134: : all-words    ['] false    IS skip? ;
                   2135: : needed-words ['] needed?  IS skip? ;
                   2136: : undef-words  ['] defined? IS skip? ;
1.1       anton    2137: 
1.40      pazsan   2138: : \  postpone \ ;  immediate
1.47      pazsan   2139: : \G T-\G ; immediate
1.40      pazsan   2140: : (  postpone ( ;  immediate
1.1       anton    2141: : include bl word count included ;
1.52      jwilke   2142: : require require ;
1.1       anton    2143: : .( [char] ) parse type ;
1.52      jwilke   2144: : ." [char] " parse type ;
1.1       anton    2145: : cr cr ;
                   2146: 
                   2147: : times 0 ?DO dup T c, H LOOP drop ; \ used for space table creation
                   2148: only forth also minimal definitions
                   2149: 
                   2150: \ cross-compiler words
                   2151: 
                   2152: : decimal       decimal ;
                   2153: : hex           hex ;
                   2154: 
1.3       pazsan   2155: : tudp          T tudp H ;
1.39      pazsan   2156: : tup           T tup H ;
                   2157: 
                   2158: : doc-off       false T to-doc H ! ;
                   2159: : doc-on        true  T to-doc H ! ;
1.52      jwilke   2160: [IFDEF] dbg : dbg dbg ; [THEN]
1.39      pazsan   2161: 
                   2162: minimal
1.1       anton    2163: 
                   2164: \ for debugging...
                   2165: : order         order ;
1.52      jwilke   2166: : hwords         words ;
                   2167: : words        also ghosts words previous ;
1.1       anton    2168: : .s            .s ;
                   2169: : bye           bye ;
                   2170: 
                   2171: \ turnkey direction
                   2172: : H forth ; immediate
                   2173: : T minimal ; immediate
                   2174: : G ghosts ; immediate
                   2175: 
                   2176: : turnkey  0 set-order also Target definitions
                   2177:            also Minimal also ;
                   2178: 
                   2179: \ these ones are pefered:
                   2180: 
                   2181: : lock   turnkey ;
                   2182: : unlock forth also cross ;
1.52      jwilke   2183: 
                   2184: : [[ also unlock ;
                   2185: : ]] previous previous ;
1.1       anton    2186: 
                   2187: unlock definitions also minimal
                   2188: : lock   lock ;
                   2189: lock

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