Re: RfD - Enhanced local variable syntax, v4 (long)
- From: "David N. Williams" <williams@xxxxxxxxx>
- Date: Thu, 28 Aug 2008 20:36:11 -0400
David N. Williams wrote:
[...]
But I would really, really prefer that standard locals use stack
comment order.* :-)
Josh Grams sent me a private email wondering why, since I yearn
for standard locals with stack comment order, I don't just use
the gforth standard implementation:
http://www.complang.tuwien.ac.at/forth/anslocal.fs
That inspired me to revisit an old modification which worked
across lines. FWIW, a new version is posted below.
It uses NEXT-INSTREAM-NAME, which is the parsing.fs library name
for Wil Baden's across line word NEXT-WORD, and
|S|-SEEK-INSTREAM, the parsing.fs word for seeking past a
whitespace delimited string across lines.
It also uses the dynamic string (dstring) word >$S-COPY, which
copies an ANS Forth string (fstring) into string space and
pushes it onto the string stack, as well as $S>, which pops a
dstring from the string stack and pushes it onto the data stack
as an fstring.
This works with gforth. It fails with pfe, as does anslocal.fs.
It's suspicious to me that pfe's (LOCAL) is immediate, but
changing only the immediacy doesn't help.
-- David
( Title: Stack-comment ordered locals across lines
File: aelocals-xl.fs
Author: David N. Williams
License: Public Domain
Version: 0.5.0
Revised: August 28, 2008
)
s" parsing.fs" required
s" dstrings.fs" required
(*
http://www-personal.umich.edu/~williams/archive/forth/strings/parsing.fs
http://www-personal.umich.edu/~williams/archive/forth/strings/dstrings.fs
This code modifies Anton Ertl's anslocal.fs to work across lines.
Notation:
<ws> whitespace characters or line ends
<ws0> optional <ws>
<_--_text0> optional whitespace delimited "--" and text across lines
_}_ whitespace delimited "}"
*)
: get-locals ( "<ws0><name_1><ws>...<name_n><_--_text0>_}_" -- )
next-instream-name 2dup s" --" compare 0=
IF
2drop s" }" |s|-seek-instream
0= ABORT" ***locals } terminator not found" EXIT
ELSE
2dup s" }" compare 0= IF 2drop EXIT THEN
THEN
>$s-copy RECURSE $s> (LOCAL)
;
: { ( "<ws0><name_1><ws>...<name_n><_--_text0>_}_" -- ) \ compile
( p_1 ... p_n -- ) \ run
get-locals 0 0 (LOCAL)
; immediate
0 [IF]
\ broken-line version of Anton Ertl's test word
: test1-swap {
a
b
-- b a
}
.." xxx" b a ;
cr 1 2 test1-swap . . .s cr
\ version without "--"
: test2-swap { a
b }
.." xxx" b a ;
1 2 test2-swap . . .s cr
[THEN]
.
- Follow-Ups:
- Re: RfD - Enhanced local variable syntax, v4 (long)
- From: Anton Ertl
- Re: RfD - Enhanced local variable syntax, v4 (long)
- References:
- Re: RfD - Enhanced local variable syntax, v4 (long)
- From: Celime
- Re: RfD - Enhanced local variable syntax, v4 (long)
- From: Marcel Hendrix
- Re: RfD - Enhanced local variable syntax, v4 (long)
- From: Celime
- Re: RfD - Enhanced local variable syntax, v4 (long)
- From: Ed
- Re: RfD - Enhanced local variable syntax, v4 (long)
- From: Doug Hoffman
- Re: RfD - Enhanced local variable syntax, v4 (long)
- From: Ed
- Re: RfD - Enhanced local variable syntax, v4 (long)
- From: Doug Hoffman
- Re: RfD - Enhanced local variable syntax, v4 (long)
- From: Ed
- Re: RfD - Enhanced local variable syntax, v4 (long)
- From: Anton Ertl
- Re: RfD - Enhanced local variable syntax, v4 (long)
- From: Ed
- Re: RfD - Enhanced local variable syntax, v4 (long)
- Prev by Date: Re: Advanced Forth app techniques
- Next by Date: Re: FORTH on Cell/PS-3
- Previous by thread: Re: RfD - Enhanced local variable syntax, v4 (long)
- Next by thread: Re: RfD - Enhanced local variable syntax, v4 (long)
- Index(es):
Relevant Pages
|