File:  [gforth] / gforth / extend.fs
Revision 1.12: download - view: text, annotated - select for diffs
Tue Nov 7 18:06:39 1995 UTC (24 years, 1 month ago) by anton
Branches: MAIN
CVS tags: HEAD
added copyright headers
changes to loadfilename & co. to make savesystem transparent to
 assertions and ~~

    1: \ EXTEND.FS    CORE-EXT Word not fully tested!         12may93jaw
    2: 
    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: 
   22: \ May be cross-compiled
   23: 
   24: decimal
   25: 
   26: \ .(                                                    12may93jaw
   27: 
   28: : .(   ( compilation "...<paren>" -- ) \ core-ext dot-paren
   29:     [char] ) parse type ; immediate
   30: 
   31: \ VALUE 2>R 2R> 2R@                                     17may93jaw
   32: 
   33: : value ( w -- ) \ core-ext
   34:   (constant) , ;
   35: \ !! 2value
   36: 
   37: : 2Literal ( compilation w1 w2 -- ; run-time  -- w1 w2 ) \ double two-literal
   38:     swap postpone Literal  postpone Literal ; immediate restrict
   39: 
   40: : m*/ ( d1 n2 u3 -- dqout ) \ double m-star-slash
   41:     >r s>d >r abs -rot
   42:     s>d r> xor r> swap >r >r dabs rot tuck um* 2swap um*
   43:     swap >r 0 d+ r> -rot r@ um/mod -rot r> um/mod nip swap
   44:     r> IF dnegate THEN ;
   45: 
   46: \ CASE OF ENDOF ENDCASE                                 17may93jaw
   47: 
   48: \ just as described in dpANS5
   49: 
   50: 0 CONSTANT case ( compilation  -- case-sys ; run-time  -- ) \ core-ext
   51:     immediate
   52: 
   53: : of ( compilation  -- of-sys ; run-time x1 x2 -- |x1 ) \ core-ext
   54:     \ !! the implementation does not match the stack effect
   55:     1+ >r
   56:     postpone over postpone = postpone if postpone drop
   57:     r> ; immediate
   58: 
   59: : endof ( compilation case-sys1 of-sys -- case-sys2 ; run-time  -- ) \ core-ext end-of
   60:     >r postpone else r> ; immediate
   61: 
   62: : endcase ( compilation case-sys -- ; run-time x -- ) \ core-ext end-case
   63:     postpone drop
   64:     0 ?do postpone then loop ; immediate
   65: 
   66: \ C"                                                    17may93jaw
   67: 
   68: : (c")     "lit ;
   69: 
   70: : CLiteral
   71:     postpone (c") here over char+ allot  place align ; immediate restrict
   72: 
   73: : C" ( compilation "...<quote>" -- ; run-time  -- c-addr ) \ core-ext c-quote
   74:     [char] " parse postpone CLiteral ; immediate restrict
   75: 
   76: \ UNUSED                                                17may93jaw
   77: 
   78: : unused ( -- u ) \ core-ext
   79:     s0 @ 512 -        \ for stack
   80:     here - ;
   81: 
   82: \ [COMPILE]                                             17may93jaw
   83: 
   84: : [compile] ( compilation "name" -- ; run-time ? -- ? ) \ core-ext bracket-compile
   85:     ' compile, ; immediate
   86: 
   87: \ MARKER                                                17may93jaw
   88: 
   89: \ : marker here last @ create , , DOES> dup @ last ! cell+ @ dp ! ;
   90: \ doesn't work now. vocabularies?
   91: 
   92: \ CONVERT                                               17may93jaw
   93: 
   94: : convert ( ud1 c-addr1 -- ud2 c-addr2 ) \ core-ext
   95:     \ obsolescent; supersedet by @code{>number}.
   96:     true >number drop ;
   97: 
   98: \ ERASE                                                 17may93jaw
   99: 
  100: : erase ( addr len -- ) \ core-ext
  101:     \ !! dependence on "1 chars 1 ="
  102:     ( 0 1 chars um/mod nip )  0 fill ;
  103: : blank ( addr len -- ) \ string
  104:     bl fill ;
  105: 
  106: \ SEARCH                                                02sep94py
  107: 
  108: : search   ( buf buflen text textlen -- restbuf restlen flag ) \ string
  109:     2over  2 pick - 1+ 3 pick c@ >r
  110:     BEGIN
  111: 	r@ scan dup
  112:     WHILE
  113: 	>r >r  2dup r@ -text
  114: 	0=
  115: 	IF
  116: 	    >r drop 2drop r> r> r> rot + 1- rdrop true
  117: 	    EXIT
  118: 	THEN
  119: 	r> r>  1 /string
  120:     REPEAT
  121:     2drop 2drop  rdrop false ;
  122: 
  123: \ ROLL                                                  17may93jaw
  124: 
  125: : roll  ( x0 x1 .. xn n -- x1 .. xn x0 ) \ core-ext
  126:   dup 1+ pick >r
  127:   cells sp@ cell+ dup cell+ rot move drop r> ;
  128: 
  129: \ SOURCE-ID SAVE-INPUT RESTORE-INPUT                    11jun93jaw
  130: 
  131: : source-id ( -- 0 | -1 | fileid ) \ core-ext source-i-d
  132:   loadfile @ dup 0= IF  drop loadline @ 0 min  THEN ;
  133: 
  134: : save-input ( -- x1 .. xn n ) \ core-ext
  135:   >in @
  136:   loadfile @ ?dup
  137:   IF    dup file-position throw loadline @ >tib @ 6
  138:         #tib @ >tib +!
  139:   ELSE  loadline @ blk @ linestart @ >tib @ 5 THEN
  140: ;
  141: 
  142: : restore-input ( x1 .. xn n -- flag ) \ core-ext
  143:   swap >tib !
  144:   6 = IF   loadline ! rot dup loadfile !
  145:            reposition-file IF drop true EXIT THEN
  146:       ELSE linestart ! blk !
  147:            dup loadline @ <> IF 2drop true EXIT THEN
  148:            loadline !
  149:       THEN
  150:   >in ! false ;
  151: 
  152: 
  153: 
  154: \ This things we don't need, but for being complete... jaw
  155: 
  156: \ EXPECT SPAN                                           17may93jaw
  157: 
  158: variable span ( -- a-addr ) \ core-ext
  159: \ obsolescent
  160: 
  161: : expect ( c-addr +len -- ) \ core-ext
  162:     \ obsolescent; use accept
  163:     0 rot over
  164:     BEGIN ( maxlen span c-addr pos1 )
  165: 	key decode ( maxlen span c-addr pos2 flag )
  166: 	>r 2over = r> or
  167:     UNTIL
  168:     type-rest drop
  169:     2drop nip span ! ;
  170: 

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