File:  [gforth] / gforth / cross.fs
Revision 1.2: download - view: text, annotated - select for diffs
Tue May 3 15:24:11 1994 UTC (29 years, 11 months ago) by pazsan
Branches: MAIN
CVS tags: HEAD
Added fsincos, corrected fsin.
Added fexpm1, flog1p.
Changed EXIT to ;S
Created immediate EXIT in kernal.fs and cross.fs for locals.

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

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