[gforth] / gforth / kernel / int.fs  

gforth: gforth/kernel/int.fs

Diff for /gforth/kernel/int.fs between version 1.106 and 1.112

version 1.106, Mon Aug 23 14:03:53 2004 UTC version 1.112, Tue Dec 28 21:09:47 2004 UTC
Line 104 
Line 104 
 \ number? number                                       23feb93py  \ number? number                                       23feb93py
   
 hex  hex
 const Create bases   10 ,   2 ,   A , 100 ,  const Create bases   0A , 10 ,   2 ,   0A ,
 \                     16     2    10   character  \                    10   16     2     10
   
 \ !! protect BASE saving wrapper against exceptions  \ !! protect BASE saving wrapper against exceptions
 : getbase ( addr u -- addr' u' )  : getbase ( addr u -- addr' u' )
     over c@ [char] $ - dup 4 u<      2dup s" 0x" string-prefix? >r
       2dup s" 0X" string-prefix? r> or
       base @ #34 < and if
           hex 2 /string
       endif
       over c@ [char] # - dup 4 u<
     IF      IF
         cells bases + @ base ! 1 /string          cells bases + @ base ! 1 /string
     ELSE      ELSE
Line 123 
Line 128 
     THEN      THEN
     r> ;      r> ;
   
   : s'>unumber? ( addr u -- ud flag )
       \ convert string "C" or "C'" to character code
       dup 0= if
           false exit
       endif
       over c@ >r
       1 /string s" '" 2swap string-prefix?
       r> 0 rot ;
   
 : s>unumber? ( addr u -- ud flag )  : s>unumber? ( addr u -- ud flag )
       over c@ '' = if
           1 /string s'>unumber? exit
       endif
     base @ >r  dpl on  getbase      base @ >r  dpl on  getbase
     0. 2swap      0. 2swap
     BEGIN ( d addr len )      BEGIN ( d addr len )
Line 773 
Line 790 
 \ \ DOERROR (DOERROR)                                   13jun93jaw  \ \ DOERROR (DOERROR)                                   13jun93jaw
   
 8 Constant max-errors  8 Constant max-errors
   4 has? file 2 and + Constant /error
 Variable error-stack  0 error-stack !  Variable error-stack  0 error-stack !
 max-errors has? file [IF] 6 [ELSE] 4 [THEN] * cells allot  max-errors /error * cells allot
 \ format of one cell:  \ format of one cell:
 \ source ( addr u )  \ source ( addr u )
 \ >in  \ >in
Line 784 
Line 802 
 : error> ( -- addr u >in line# [addr u] )  : error> ( -- addr u >in line# [addr u] )
     -1 error-stack +!      -1 error-stack +!
     error-stack dup @      error-stack dup @
     [ has? file [IF] 6 [ELSE] 4 [THEN] ] Literal * cells + cell+      /error * cells + cell+
     [ has? file [IF] 6 [ELSE] 4 [THEN] ] Literal cells bounds DO      /error cells bounds DO
         I @          I @
         cell +LOOP ;          cell +LOOP ;
 : >error ( addr u >in line# [addr u] -- )  : >error ( addr u >in line# [addr u] -- )
     error-stack dup @ dup 1+      error-stack dup @ dup 1+
     max-errors 1- min error-stack !      max-errors 1- min error-stack !
     [ has? file [IF] 6 [ELSE] 4 [THEN] ] Literal * cells + cell+      /error * cells + cell+
     [ has? file [IF] 6 [ELSE] 4 [THEN] 1- ] Literal cells bounds swap DO      /error 1- cells bounds swap DO
         I !          I !
         -1 cells +LOOP ;          -1 cells +LOOP ;
   
Line 801 
Line 819 
     \ !! not used...      \ !! not used...
     base @ decimal swap . base ! ;      base @ decimal swap . base ! ;
   
 : dec.r ( u -- ) \ gforth  : dec.r ( u n -- ) \ gforth
     \G Display @i{u} as a unsigned decimal number      \G Display @i{u} as a unsigned decimal number in a field @i{n}
     base @ decimal swap 0 .r base ! ;      \G characters wide.
       base @ >r decimal .r r> base ! ;
   
 : hex. ( u -- ) \ gforth  : hex. ( u -- ) \ gforth
     \G Display @i{u} as an unsigned hex number, prefixed with a "$" and      \G Display @i{u} as an unsigned hex number, prefixed with a "$" and
Line 845 
Line 864 
   ELSE  .error    ELSE  .error
   THEN ;    THEN ;
   
   : umin ( u1 u2 -- u )
       2dup u>
       if
           swap
       then
       drop ;
   
   Defer mark-start
   Defer mark-end
   
   :noname ." >>>" ; IS mark-start
   :noname ." <<<" ; IS mark-end
   
   : .error-line ( addr1 u1 n1 -- )
       \ print error ending at char n1 in line addr1 u1
       \ should work with UTF-8 (whitespace check looks ok)
       over umin \ protect against wrong n1
       swap >r ( addr1 n1 R: u1 )
       -trailing 1- \ last non-space
       0 >r  BEGIN \ search for the first non-space
           2dup + c@ bl >  WHILE
           r> 1+ >r  1- dup 0<  UNTIL  THEN  1+
       ( addr1 n2 r: u1 namelen )
       2dup type mark-start
       r> -rot r> swap /string ( namelen addr2 u2 )
       >r swap 2dup type mark-end ( addr2 namelen r: u2 )
       r> swap /string type ;
   
 : .error-frame ( throwcode addr1 u1 n1 n2 [addr2 u2] -- throwcode )  : .error-frame ( throwcode addr1 u1 n1 n2 [addr2 u2] -- throwcode )
 \ addr2 u2:     filename of included file - optional  \ addr2 u2:     filename of included file - optional
 \ n2:           line number  \ n2:           line number
 \ n1:           error position in input line  \ n1:           error position in input line
 \ addr1 u1:     input line  \ addr1 u1:     input line
   cr error-stack @    cr error-stack @
   IF    IF ( throwcode addr1 u1 n1 n2 [addr2 u2] )
 [ has? file [IF] ]  [ has? file [IF] ] \ !! unbalanced stack effect
     ." in file included from "      ." in file included from "
     type ." :"      type ." :"
 [ [THEN] ]  [ [THEN] ] ( throwcode addr1 u1 n1 n2 )
     dec.r  drop 2drop      0 dec.r  drop 2drop
   ELSE    ELSE ( throwcode addr1 u1 n1 n2 [addr2 u2] )
 [ has? file [IF] ]  [ has? file [IF] ]
       type ." :"        type ." :"
 [ [THEN] ]  [ [THEN] ] ( throwcode addr1 u1 n1 n2 )
       dup >r dec.r ." : " 3 pick .error-string        dup 0 dec.r ." : " 4 pick .error-string
       r> IF \ if line# non-zero, there is a line        IF \ if line# non-zero, there is a line
           cr dup 2over type cr drop            cr .error-line
           nip -trailing 1- ( line-start index2 )  
           0 >r  BEGIN  
               2dup + c@ bl >  WHILE  
               r> 1+ >r  1- dup 0<  UNTIL  THEN  1+  
           ( line-start index1 )  
           typewhite  
           r> 1 max 0 ?do \ we want at least one "^", even if the length is 0  
               [char] ^ emit  
           loop  
       ELSE        ELSE
           2drop drop            2drop drop
       THEN        THEN
Line 882 
Line 920 
   [ has? os [IF] ]    [ has? os [IF] ]
       >stderr        >stderr
   [ [THEN] ]    [ [THEN] ]
   source >in @ sourceline# [ has? file [IF] ]    source >in @ sourceline# [ has? file [IF] ] \ !! unbalanced stack effect
       sourcefilename        sourcefilename
   [ [THEN] ] .error-frame    [ [THEN] ] .error-frame
   error-stack @ 0 ?DO    error-stack @ 0 ?DO


Generate output suitable for use with a patch program
Legend:
Removed from v.1.106  
changed lines
  Added in v.1.112

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help