File:  [gforth] / gforth / cross.fs
Revision 1.13: download - view: text, annotated - select for diffs
Mon Sep 12 19:00:27 1994 UTC (25 years, 3 months ago) by pazsan
Branches: MAIN
CVS tags: HEAD
Added forth variants for primitives
Added a generator for forth primitives
Cleaned up some minor errors
Changed names of local access (was cell size dependent)
Where is "getopt.h"???!? Added tiny workaround. Where is getopt_long?

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

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