Annotation of gforth/cross.fs, revision 1.70

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

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