version 1.1, 1999/05/18 15:13:50
|
version 1.9, 2002/12/14 17:34:12
|
Line 1
|
Line 1
|
\ quote: S" and ." words |
\ quote: S" and ." words |
|
|
\ Copyright (C) 1996,1998 Free Software Foundation, Inc. |
\ Copyright (C) 1996,1998,1999 Free Software Foundation, Inc. |
|
|
\ This file is part of Gforth. |
\ This file is part of Gforth. |
|
|
Line 16
|
Line 16
|
|
|
\ You should have received a copy of the GNU General Public License |
\ You should have received a copy of the GNU General Public License |
\ along with this program; if not, write to the Free Software |
\ along with this program; if not, write to the Free Software |
\ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
\ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. |
|
|
\ this file comes last, because these words override cross' words. |
\ this file comes last, because these words override cross' words. |
|
|
require ./vars.fs |
require ./vars.fs |
|
|
create s"-buffer /line chars allot |
: CLiteral ( Compilation c-addr1 u ; run-time -- c-addr ) |
|
2>r postpone ahead here 2r> s, >r postpone then |
|
r> postpone literal ; immediate restrict |
|
|
|
: SLiteral ( Compilation c-addr1 u ; run-time -- c-addr2 u ) \ string |
|
\G Compilation: compile the string specified by @i{c-addr1}, |
|
\G @i{u} into the current definition. Run-time: return |
|
\G @i{c-addr2 u} describing the address and length of the |
|
\G string. |
|
tuck 2>r postpone ahead here 2r> chars mem, align >r postpone then |
|
r> postpone literal postpone literal ; immediate restrict |
|
|
|
\ \ abort" 22feb93py |
|
|
|
: abort" ( compilation 'ccc"' -- ; run-time f -- ) \ core,exception-ext abort-quote |
|
\G If any bit of @i{f} is non-zero, perform the function of @code{-2 throw}, |
|
\G displaying the string @i{ccc} if there is no exception frame on the |
|
\G exception stack. |
|
postpone if [char] " parse postpone cliteral postpone c(abort") |
|
postpone then ; immediate restrict |
|
|
|
\ create s"-buffer /line chars allot |
has? compiler 0= |
has? compiler 0= |
[IF] : s" [ELSE] :noname [THEN] |
[IF] : s" [ELSE] :noname [THEN] |
[char] " parse |
[char] " parse |
/line min >r s"-buffer r@ cmove |
[ has? OS [IF] ] |
s"-buffer r> ; |
save-mem |
|
[ [THEN] ] |
|
; |
|
\ /line min >r s"-buffer r@ cmove |
|
\ s"-buffer r> ; |
has? compiler [IF] |
has? compiler [IF] |
:noname [char] " parse postpone SLiteral ; |
:noname [char] " parse postpone SLiteral ; |
interpret/compile: S" ( compilation 'ccc"' -- ; run-time -- c-addr u ) \ core,file s-quote |
interpret/compile: S" ( compilation 'ccc"' -- ; run-time -- c-addr u ) \ core,file s-quote |
\G Compilation: Parse a string @i{ccc} delimited by a @code{"} |
\G Compilation: Parse a string @i{ccc} delimited by a @code{"} |
\G (double quote). At run-time, return the length, @i{u}, and the |
\G (double quote). At run-time, return the length, @i{u}, and the |
\G start address, @i{c-addr} of the string. Interpretation: parse |
\G start address, @i{c-addr} of the string. Interpretation: parse |
\G the string as before, and return @i{c-addr}, @i{u}. The |
\G the string as before, and return @i{c-addr}, @i{u}. Gforth |
\G string is stored in a temporary buffer which may be overwritten |
\G @code{allocate}s the string. The resulting memory leak is usually |
\G by subsequent uses of @code{S"}. |
\G not a problem; the exception is if you create strings containing |
|
\G @code{S"} and @code{evaluate} them; then the leak is not bounded |
|
\G by the size of the interpreted files and you may want to |
|
\G @code{free} the strings. ANS Forth only guarantees one buffer of |
|
\G 80 characters, so in standard programs you should assume that the |
|
\G string lives only until the next @code{s"}. |
[THEN] |
[THEN] |
|
|
:noname [char] " parse type ; |
:noname [char] " parse type ; |
:noname postpone (.") ," align ; |
:noname [char] " parse postpone sLiteral postpone type ; |
interpret/compile: ." ( compilation 'ccc"' -- ; run-time -- ) \ core dot-quote |
interpret/compile: ." ( compilation 'ccc"' -- ; run-time -- ) \ core dot-quote |
\G Compilation: Parse a string @i{ccc} delimited by a " (double |
\G Compilation: Parse a string @i{ccc} delimited by a " (double |
\G quote). At run-time, display the string. Interpretation semantics |
\G quote). At run-time, display the string. Interpretation semantics |