File:  [gforth] / gforth / extend.fs
Revision 1.33: download - view: text, annotated - select for diffs
Tue Mar 23 20:24:18 1999 UTC (20 years, 8 months ago) by crook
Branches: MAIN
CVS tags: HEAD
Makefile.in

-- changes to make documentation build with moofglos.fs
   rather than with mini-oof.fs (since the former contains glossary
   entries and the latter does not)

assert.fs blocks.fs debug.fs environ.fs errors.fs extend.fs float.fs
glocals.fs moofglos.fs prim search.fs struct.fs stuff.fs vt100.fs
kernel/args.fs kernel/basics.fs kernel/comp.fs kernel/cond.fs
kernel/files.fs kernel/getdoers.fs kernel/int.fs kernel/io.fs
kernel/nio.fs kernel/paths.fs kernel/require.fs kernel/special.fs
kernel/tools.fs kernel/toolsext.fs kernel/vars.fs

-- many small changes to glossary entries.. I think most are done
   now, so I hope to change far fewer files next time!

doc/gforth.ds

-- many, many small changes and a few large ones. Moved some sections
   around, fixed typos and formatting errors, added new section on
   exception handling, rearranged 'files' section.

    1: \ EXTEND.FS    CORE-EXT Word not fully tested!         12may93jaw
    2: 
    3: \ Copyright (C) 1995,1998 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: : .(   ( "ccc<paren>" -- ) \ core-ext dot-paren
   29:   \G Parse a string @var{ccc} delimited by a @code{)} (right
   30:   \G parenthesis). Display the string. This is often used to display
   31:   \G progress information during compilation; see examples below.
   32:   [char] ) parse type ; immediate
   33: 
   34: \ VALUE 2>R 2R> 2R@                                     17may93jaw
   35: 
   36: \ !! 2value
   37: 
   38: : 2Literal ( compilation w1 w2 -- ; run-time  -- w1 w2 ) \ double two-literal
   39:     \G Compile appropriate code such that, at run-time, cell pair @var{w1, w2} are
   40:     \G placed on the stack. Interpretation semantics are undefined.
   41:     swap postpone Literal  postpone Literal ; immediate restrict
   42: 
   43: ' drop alias d>s ( d -- n ) \ double		d_to_s
   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 "ccc<quote>" -- ; run-time  -- c-addr ) \ core-ext c-quote
   79:     \G Compilation: parse a string @var{ccc} delimited by a @code{"}
   80:     \G (double quote). At run-time, return @var{c-addr} which
   81:     \G specifies the counted string @var{ccc}.  Interpretation
   82:     \G semantics are undefined.
   83:     [char] " parse postpone CLiteral ; immediate restrict
   84: 
   85: \ [COMPILE]                                             17may93jaw
   86: 
   87: : [compile] ( compilation "name" -- ; run-time ? -- ? ) \ core-ext bracket-compile
   88:     comp' drop compile, ; immediate
   89: 
   90: \ CONVERT                                               17may93jaw
   91: 
   92: : convert ( ud1 c-addr1 -- ud2 c-addr2 ) \ core-ext
   93:     \G OBSOLESCENT; superseded by @code{>number}.
   94:     char+ true >number drop ;
   95: 
   96: \ ERASE                                                 17may93jaw
   97: 
   98: : erase ( addr len -- ) \ core-ext
   99:     \G If @var{len}>0, clear all bits in each location of a memory region
  100:     \G of @var{len} address units starting at address @var{addr}.
  101:     \ !! dependence on "1 chars 1 ="
  102:     ( 0 1 chars um/mod nip )  0 fill ;
  103: : blank ( addr len -- ) \ string
  104:     \G If @var{len}>0, store the character value for a space in each
  105:     \G location of a memory region
  106:     \G of @var{len} character units starting at address @var{addr}.
  107:     bl fill ;
  108: 
  109: \ SEARCH                                                02sep94py
  110: 
  111: : search ( c-addr1 u1 c-addr2 u2 -- c-addr3 u3 flag ) \ string
  112:     \G Search the string specified by @var{c-addr1, u1} for the string
  113:     \G specified by @var{c-addr2, u2}. If @var{flag} is true: match was found
  114:     \G at @var{c-addr3} with @var{u3} characters remaining. If @var{flag} is false:
  115:     \G no match was found; @var{c-addr3, u3} are equal to @var{c-addr1, u1}.
  116:     \ not very efficient; but if we want efficiency, we'll do it as primitive
  117:     2>r 2dup
  118:     begin
  119: 	dup r@ >=
  120:     while
  121: 	over 2r@ swap -text 0= if
  122: 	    2swap 2drop 2r> 2drop true exit
  123: 	endif
  124: 	1 /string
  125:     repeat
  126:     2drop 2r> 2drop false ;
  127: 
  128: \ SOURCE-ID SAVE-INPUT RESTORE-INPUT                    11jun93jaw
  129: 
  130: : source-id ( -- 0 | -1 | fileid ) \ core-ext,file source-i-d
  131:   loadfile @ dup 0= IF  drop sourceline# 0 min  THEN ;
  132: 
  133: : save-input ( -- x1 .. xn n ) \ core-ext
  134:     >in @
  135:     loadfile @
  136:     if
  137: 	loadfile @ file-position throw
  138:     else
  139: 	blk @
  140: 	linestart @
  141:     then
  142:     sourceline#
  143:     >tib @
  144:     source-id
  145:     6 ;
  146: 
  147: : restore-input ( x1 .. xn n -- flag ) \ core-ext
  148:     6 <> -12 and throw
  149:     source-id <> -12 and throw
  150:     >tib !
  151:     >r ( line# )
  152:     loadfile @ 0<>
  153:     if
  154: 	loadfile @ reposition-file throw
  155:     else
  156: 	linestart !
  157: 	blk !
  158: 	sourceline# r@ <> blk @ 0= and loadfile @ 0= and
  159: 	if
  160: 	    drop rdrop true EXIT
  161: 	then
  162:     then
  163:     r> loadline !
  164:     >in !
  165:     false ;
  166: 
  167: \ This things we don't need, but for being complete... jaw
  168: 
  169: \ EXPECT SPAN                                           17may93jaw
  170: 
  171: variable span ( -- a-addr ) \ core-ext
  172: \ obsolescent
  173: 
  174: : expect ( c-addr +len -- ) \ core-ext
  175:     \ obsolescent; use accept
  176:     0 rot over
  177:     BEGIN ( maxlen span c-addr pos1 )
  178: 	key decode ( maxlen span c-addr pos2 flag )
  179: 	>r 2over = r> or
  180:     UNTIL
  181:     2 pick swap /string type
  182:     nip span ! ;
  183: 
  184: \ marker                                               18dec94py
  185: 
  186: \ Marker creates a mark that is removed (including everything 
  187: \ defined afterwards) when executing the mark.
  188: 
  189: : included-files-mark ( -- u )
  190:     included-files 2@ nip
  191:     blk @ 0=
  192:     if \ not input from blocks
  193: 	source-id 1 -1 within
  194: 	if \ input from file
  195: 	    1- \ do not include the last file (hopefully this is the
  196: 	       \ currently included file)
  197: 	then
  198:     then ;  
  199: 
  200: \ hmm, most of the saving appears to be pretty unnecessary: we could
  201: \ derive the wordlists and the words that have to be kept from the
  202: \ saved value of dp value. - anton
  203: 
  204: : marker, ( -- mark )
  205:     here
  206:     included-files-mark ,
  207:     dup A, \ here
  208:     voclink @ A, \ vocabulary list start
  209:     \ for all wordlists, remember wordlist-id (the linked list)
  210:     voclink
  211:     BEGIN
  212: 	@ dup
  213:     WHILE
  214: 	dup 0 wordlist-link - wordlist-id @ A,
  215:     REPEAT
  216:     drop
  217:     \ remember udp
  218:     udp @ , ;
  219: 
  220: : marker! ( mark -- )
  221:     \ reset included files count; resize will happen on next add-included-file
  222:     included-files 2@ drop over @ included-files 2! cell+
  223:     \ rest of marker!
  224:     dup @ swap cell+ ( here rest-of-marker )
  225:     dup @ voclink ! cell+
  226:     \ restore wordlists to former words
  227:     voclink
  228:     BEGIN
  229: 	@ dup 
  230:     WHILE
  231: 	over @ over 0 wordlist-link - wordlist-id !
  232: 	swap cell+ swap
  233:     REPEAT
  234:     drop
  235:     \ rehash wordlists to remove forgotten words
  236:     \ why don't we do this in a single step? - anton
  237:     voclink
  238:     BEGIN
  239: 	@ dup
  240:     WHILE
  241: 	dup 0 wordlist-link - rehash
  242:     REPEAT
  243:     drop
  244:     \ restore udp and dp
  245:     @ udp !  dp !
  246:     \ clean up vocabulary stack
  247:     0 vp @ 0
  248:     ?DO
  249: 	vp cell+ I cells + @ dup here >
  250: 	IF  drop  ELSE  swap 1+  THEN
  251:     LOOP
  252:     dup 0= or set-order \ -1 set-order if order is empty
  253:     get-current here > IF
  254: 	forth-wordlist set-current
  255:     THEN ;
  256: 
  257: : marker ( "<spaces> name" -- ) \ core-ext
  258:     \G Create a definition, @var{name} (called a @var{mark}) whose
  259:     \G execution semantics are to remove itself and everything 
  260:     \G defined after it.
  261:     marker, Create A,
  262: DOES> ( -- )
  263:     @ marker! ;
  264: 

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