File:  [gforth] / gforth / extend.fs
Revision 1.16: download - view: text, annotated - select for diffs
Tue Feb 13 11:12:17 1996 UTC (24 years ago) by anton
Branches: MAIN
CVS tags: HEAD
completed double-cell support for machines without a corresponding C int type

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

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