Annotation of gforth/extend.fs, revision 1.19

1.1       anton       1: \ EXTEND.FS    CORE-EXT Word not fully tested!         12may93jaw
                      2: 
1.12      anton       3: \ Copyright (C) 1995 Free Software Foundation, Inc.
                      4: 
                      5: \ This file is part of Gforth.
                      6: 
                      7: \ Gforth is free software; you can redistribute it and/or
                      8: \ modify it under the terms of the GNU General Public License
                      9: \ as published by the Free Software Foundation; either version 2
                     10: \ of the License, or (at your option) any later version.
                     11: 
                     12: \ This program is distributed in the hope that it will be useful,
                     13: \ but WITHOUT ANY WARRANTY; without even the implied warranty of
                     14: \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     15: \ GNU General Public License for more details.
                     16: 
                     17: \ You should have received a copy of the GNU General Public License
                     18: \ along with this program; if not, write to the Free Software
                     19: \ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
                     20: 
                     21: 
1.1       anton      22: \ May be cross-compiled
                     23: 
                     24: decimal
                     25: 
                     26: \ .(                                                    12may93jaw
                     27: 
1.11      anton      28: : .(   ( compilation "...<paren>" -- ) \ core-ext dot-paren
1.8       anton      29:     [char] ) parse type ; immediate
1.1       anton      30: 
                     31: \ VALUE 2>R 2R> 2R@                                     17may93jaw
                     32: 
1.18      anton      33: : value ( w "name" -- ) \ core-ext
1.3       anton      34:   (constant) , ;
                     35: \ !! 2value
1.1       anton      36: 
1.11      anton      37: : 2Literal ( compilation w1 w2 -- ; run-time  -- w1 w2 ) \ double two-literal
                     38:     swap postpone Literal  postpone Literal ; immediate restrict
1.2       pazsan     39: 
1.16      anton      40: ' drop alias d>s ( d -- n ) \ double           d_to_s
                     41: 
1.11      anton      42: : m*/ ( d1 n2 u3 -- dqout ) \ double m-star-slash
                     43:     >r s>d >r abs -rot
                     44:     s>d r> xor r> swap >r >r dabs rot tuck um* 2swap um*
                     45:     swap >r 0 d+ r> -rot r@ um/mod -rot r> um/mod nip swap
                     46:     r> IF dnegate THEN ;
1.4       pazsan     47: 
1.1       anton      48: \ CASE OF ENDOF ENDCASE                                 17may93jaw
                     49: 
                     50: \ just as described in dpANS5
                     51: 
1.11      anton      52: 0 CONSTANT case ( compilation  -- case-sys ; run-time  -- ) \ core-ext
                     53:     immediate
1.1       anton      54: 
1.11      anton      55: : of ( compilation  -- of-sys ; run-time x1 x2 -- |x1 ) \ core-ext
                     56:     \ !! the implementation does not match the stack effect
                     57:     1+ >r
                     58:     postpone over postpone = postpone if postpone drop
                     59:     r> ; immediate
                     60: 
                     61: : endof ( compilation case-sys1 of-sys -- case-sys2 ; run-time  -- ) \ core-ext end-of
                     62:     >r postpone else r> ; immediate
                     63: 
                     64: : endcase ( compilation case-sys -- ; run-time x -- ) \ core-ext end-case
                     65:     postpone drop
                     66:     0 ?do postpone then loop ; immediate
1.1       anton      67: 
                     68: \ C"                                                    17may93jaw
                     69: 
                     70: : (c")     "lit ;
                     71: 
1.11      anton      72: : CLiteral
                     73:     postpone (c") here over char+ allot  place align ; immediate restrict
                     74: 
                     75: : C" ( compilation "...<quote>" -- ; run-time  -- c-addr ) \ core-ext c-quote
                     76:     [char] " parse postpone CLiteral ; immediate restrict
1.1       anton      77: 
                     78: \ UNUSED                                                17may93jaw
                     79: 
1.11      anton      80: : unused ( -- u ) \ core-ext
1.19    ! anton      81:     forthstart dup 3 cells + @ + here - ;
1.1       anton      82: 
                     83: \ [COMPILE]                                             17may93jaw
                     84: 
1.11      anton      85: : [compile] ( compilation "name" -- ; run-time ? -- ? ) \ core-ext bracket-compile
                     86:     ' compile, ; immediate
1.1       anton      87: 
                     88: \ MARKER                                                17may93jaw
                     89: 
                     90: \ : marker here last @ create , , DOES> dup @ last ! cell+ @ dp ! ;
                     91: \ doesn't work now. vocabularies?
                     92: 
                     93: \ CONVERT                                               17may93jaw
                     94: 
1.11      anton      95: : convert ( ud1 c-addr1 -- ud2 c-addr2 ) \ core-ext
1.19    ! anton      96:     \ obsolescent; superseded by @code{>number}.
1.11      anton      97:     true >number drop ;
1.1       anton      98: 
                     99: \ ERASE                                                 17may93jaw
                    100: 
1.11      anton     101: : erase ( addr len -- ) \ core-ext
                    102:     \ !! dependence on "1 chars 1 ="
                    103:     ( 0 1 chars um/mod nip )  0 fill ;
                    104: : blank ( addr len -- ) \ string
                    105:     bl fill ;
1.1       anton     106: 
1.7       pazsan    107: \ SEARCH                                                02sep94py
                    108: 
1.11      anton     109: : search   ( buf buflen text textlen -- restbuf restlen flag ) \ string
                    110:     2over  2 pick - 1+ 3 pick c@ >r
                    111:     BEGIN
                    112:        r@ scan dup
                    113:     WHILE
                    114:        >r >r  2dup r@ -text
                    115:        0=
                    116:        IF
                    117:            >r drop 2drop r> r> r> rot + 1- rdrop true
                    118:            EXIT
                    119:        THEN
                    120:        r> r>  1 /string
                    121:     REPEAT
                    122:     2drop 2drop  rdrop false ;
1.7       pazsan    123: 
1.1       anton     124: \ SOURCE-ID SAVE-INPUT RESTORE-INPUT                    11jun93jaw
                    125: 
1.11      anton     126: : source-id ( -- 0 | -1 | fileid ) \ core-ext source-i-d
1.13      anton     127:   loadfile @ dup 0= IF  drop sourceline# 0 min  THEN ;
1.1       anton     128: 
1.11      anton     129: : save-input ( -- x1 .. xn n ) \ core-ext
1.14      anton     130:     >in @
                    131:     loadfile @
                    132:     if
                    133:        loadfile @ file-position throw
                    134:     else
                    135:        blk @
                    136:        linestart @
                    137:     then
                    138:     sourceline#
                    139:     >tib @
                    140:     source-id
                    141:     6 ;
1.1       anton     142: 
1.11      anton     143: : restore-input ( x1 .. xn n -- flag ) \ core-ext
1.14      anton     144:     6 <> -12 and throw
                    145:     source-id <> -12 and throw
                    146:     >tib !
                    147:     >r ( line# )
                    148:     loadfile @ 0<>
                    149:     if
                    150:        loadfile @ reposition-file throw
                    151:     else
                    152:        linestart !
                    153:        blk !
                    154:        sourceline# r@ <> blk @ 0= and loadfile @ 0= and
                    155:        if
                    156:            drop rdrop true EXIT
                    157:        then
                    158:     then
                    159:     r> loadline !
                    160:     >in !
                    161:     false ;
                    162: 
                    163: \ : save-input ( -- x1 .. xn n ) \ core-ext
                    164: \   >in @
                    165: \   loadfile @ ?dup
                    166: \   IF    dup file-position throw sourceline# >tib @ 6
                    167: \         #tib @ >tib +!
                    168: \   ELSE  sourceline# blk @ linestart @ >tib @ 5 THEN
                    169: \ ;
                    170: 
                    171: \ : restore-input ( x1 .. xn n -- flag ) \ core-ext
                    172: \   swap >tib !
                    173: \   6 = IF   loadline ! rot dup loadfile !
                    174: \            reposition-file IF drop true EXIT THEN
                    175: \       ELSE linestart ! blk !
                    176: \            dup sourceline# <> IF 2drop true EXIT THEN
                    177: \            loadline !
                    178: \       THEN
                    179: \   >in ! false ;
1.1       anton     180: 
                    181: 
                    182: 
                    183: \ This things we don't need, but for being complete... jaw
                    184: 
                    185: \ EXPECT SPAN                                           17may93jaw
                    186: 
1.11      anton     187: variable span ( -- a-addr ) \ core-ext
                    188: \ obsolescent
1.1       anton     189: 
1.11      anton     190: : expect ( c-addr +len -- ) \ core-ext
                    191:     \ obsolescent; use accept
1.9       anton     192:     0 rot over
                    193:     BEGIN ( maxlen span c-addr pos1 )
                    194:        key decode ( maxlen span c-addr pos2 flag )
                    195:        >r 2over = r> or
                    196:     UNTIL
1.17      pazsan    197:     2 pick swap /string type
                    198:     nip span ! ;
1.1       anton     199: 

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