File:  [gforth] / gforth / extend.fs
Revision 1.5: download - view: text, annotated - select for diffs
Thu Aug 25 15:25:22 1994 UTC (25 years, 9 months ago) by anton
Branches: MAIN
CVS tags: HEAD
make now generates both images
the image names were changed
added C-level support for deferred words (dodefer)
made 2>r 2r> 2r@ 2rdrop primitives
some tuning of the outer interpreter; eliminated many words based on
 counted strings
Replaced the hash function with one that works better for larger tables

    1: \ EXTEND.FS    CORE-EXT Word not fully tested!         12may93jaw
    2: 
    3: \ May be cross-compiled
    4: 
    5: decimal
    6: 
    7: \ .(                                                    12may93jaw
    8: 
    9: : .(    [char] ) parse type ;
   10: 
   11: \ VALUE 2>R 2R> 2R@                                     17may93jaw
   12: 
   13: : value ( n -- )
   14:   (constant) , ;
   15: \ !! 2value
   16: 
   17: : 2Literal  swap postpone Literal  postpone Literal ;
   18:   immediate restrict
   19: 
   20: : m*/    ( d1 n2 u3 -- dqout )    >r s>d >r abs -rot
   21:   s>d r> xor r> swap >r >r dabs rot tuck um* 2swap um*
   22:   swap >r 0 d+ r> -rot r@ um/mod -rot r> um/mod nip swap
   23:   r> IF dnegate THEN ;
   24: 
   25: \ CASE OF ENDOF ENDCASE                                 17may93jaw
   26: 
   27: \ just as described in dpANS5
   28: 
   29: 0 CONSTANT case immediate
   30: 
   31: : of
   32:         1+ >r
   33:         postpone over postpone = postpone if postpone drop
   34:         r> ; immediate
   35: 
   36: : endof
   37:         >r postpone else r> ; immediate
   38: 
   39: : endcase
   40:         postpone drop
   41:         0 ?do postpone then loop ; immediate
   42: 
   43: \ C"                                                    17may93jaw
   44: 
   45: : (c")     "lit ;
   46: 
   47: : CLiteral postpone (c") here over char+ allot  place align ;
   48:                                               immediate restrict
   49: : C"       [char] " parse postpone CLiteral ; immediate restrict
   50: 
   51: \ UNUSED                                                17may93jaw
   52: 
   53: : unused   s0 @ 512 -        \ for stack
   54:            here - ;
   55: 
   56: \ [COMPILE]                                             17may93jaw
   57: 
   58: : [compile] 
   59:  ' compile, ; immediate
   60: 
   61: \ MARKER                                                17may93jaw
   62: 
   63: \ : marker here last @ create , , DOES> dup @ last ! cell+ @ dp ! ;
   64: \ doesn't work now. vocabularies?
   65: 
   66: \ CONVERT                                               17may93jaw
   67: 
   68: : convert true >number drop ;
   69: 
   70: \ ERASE                                                 17may93jaw
   71: 
   72: : erase ( 0 1 chars um/mod nip )  0 fill ;
   73: : blank ( 0 1 chars um/mod nip ) bl fill ;
   74: 
   75: \ ROLL                                                  17may93jaw
   76: 
   77: : roll  dup 1+ pick >r
   78:         cells sp@ 2 cells + dup cell+ rot move drop r> ;
   79: 
   80: \ SOURCE-ID SAVE-INPUT RESTORE-INPUT                    11jun93jaw
   81: 
   82: : source-id ( -- 0 | -1 | fileid )
   83:   loadfile @ dup 0= IF  drop loadline @ 0 min  THEN ;
   84: 
   85: : save-input ( -- x1 .. xn n )
   86:   >in @
   87:   loadfile @ ?dup
   88:   IF    dup file-position throw loadline @ >tib @ 6
   89:         #tib @ >tib +!
   90:   ELSE  loadline @ blk @ linestart @ >tib @ 5 THEN
   91: ;
   92: 
   93: : restore-input ( x1 .. xn n -- flag )
   94:   swap >tib !
   95:   6 = IF   loadline ! rot dup loadfile !
   96:            reposition-file IF drop true EXIT THEN
   97:       ELSE linestart ! blk !
   98:            dup loadline @ <> IF 2drop true EXIT THEN
   99:            loadline !
  100:       THEN
  101:   >in ! false ;
  102: 
  103: 
  104: 
  105: \ This things we don't need, but for being complete... jaw
  106: 
  107: \ EXPECT SPAN                                           17may93jaw
  108: 
  109: variable span
  110: 
  111: : expect ( c-addr +len -- )
  112:   0 rot over
  113:   BEGIN  key decode >r 2over = r> or  UNTIL
  114:   2drop nip span ! ;
  115: 

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