Annotation of gforth/cross.fs, revision 1.71

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

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