Annotation of gforth/kernel/quotes.fs, revision 1.13

1.1       jwilke      1: \ quote: S" and ." words
                      2: 
1.13    ! anton       3: \ Copyright (C) 1996,1998,1999,2002,2003,2007 Free Software Foundation, Inc.
1.1       jwilke      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
1.12      anton       9: \ as published by the Free Software Foundation, either version 3
1.1       jwilke     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
1.12      anton      18: \ along with this program. If not, see http://www.gnu.org/licenses/.
1.1       jwilke     19: 
                     20: \ this file comes last, because these words override cross' words.
                     21: 
                     22: require ./vars.fs
                     23: 
1.6       anton      24: : CLiteral ( Compilation c-addr1 u ; run-time -- c-addr )
1.7       anton      25:     2>r postpone ahead here 2r> s, >r postpone then
                     26:     r> postpone literal ; immediate restrict
1.6       anton      27: 
                     28: : SLiteral ( Compilation c-addr1 u ; run-time -- c-addr2 u ) \ string
                     29: \G Compilation: compile the string specified by @i{c-addr1},
                     30: \G @i{u} into the current definition. Run-time: return
                     31: \G @i{c-addr2 u} describing the address and length of the
                     32: \G string.
1.7       anton      33:     tuck 2>r postpone ahead here 2r> chars mem, align >r postpone then
                     34:     r> postpone literal postpone literal ; immediate restrict
1.6       anton      35: 
                     36: \ \ abort"                                                     22feb93py
                     37: 
                     38: : abort" ( compilation 'ccc"' -- ; run-time f -- ) \ core,exception-ext        abort-quote
                     39: \G If any bit of @i{f} is non-zero, perform the function of @code{-2 throw},
                     40: \G displaying the string @i{ccc} if there is no exception frame on the
                     41: \G exception stack.
                     42:     postpone if [char] " parse postpone cliteral postpone c(abort")
                     43:     postpone then ; immediate restrict
                     44: 
1.4       anton      45: \ create s"-buffer /line chars allot
1.1       jwilke     46: has? compiler 0= 
                     47: [IF] : s" [ELSE] :noname [THEN]
1.5       pazsan     48:        [char] " parse
                     49: [ has? OS [IF] ]
                     50:     save-mem
                     51: [ [THEN] ]
                     52: ;
1.4       anton      53: \      /line min >r s"-buffer r@ cmove
                     54: \      s"-buffer r> ;
1.1       jwilke     55: has? compiler [IF]
                     56: :noname [char] " parse postpone SLiteral ;
                     57: interpret/compile: S" ( compilation 'ccc"' -- ; run-time -- c-addr u ) \ core,file     s-quote
                     58:   \G Compilation: Parse a string @i{ccc} delimited by a @code{"}
                     59:   \G (double quote). At run-time, return the length, @i{u}, and the
                     60:   \G start address, @i{c-addr} of the string. Interpretation: parse
1.4       anton      61:   \G the string as before, and return @i{c-addr}, @i{u}. Gforth
                     62:   \G @code{allocate}s the string. The resulting memory leak is usually
                     63:   \G not a problem; the exception is if you create strings containing
                     64:   \G @code{S"} and @code{evaluate} them; then the leak is not bounded
                     65:   \G by the size of the interpreted files and you may want to
                     66:   \G @code{free} the strings.  ANS Forth only guarantees one buffer of
                     67:   \G 80 characters, so in standard programs you should assume that the
                     68:   \G string lives only until the next @code{s"}.
1.1       jwilke     69: [THEN]
                     70: 
                     71: :noname    [char] " parse type ;
1.9       pazsan     72: :noname    [char] " parse postpone sLiteral postpone type ;
1.1       jwilke     73: interpret/compile: ." ( compilation 'ccc"' -- ; run-time -- )  \ core  dot-quote
                     74:   \G Compilation: Parse a string @i{ccc} delimited by a " (double
                     75:   \G quote). At run-time, display the string. Interpretation semantics
                     76:   \G for this word are undefined in ANS Forth. Gforth's interpretation
                     77:   \G semantics are to display the string. This is the simplest way to
                     78:   \G display a string from within a definition; see examples below.
                     79: 

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