Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #26766

Re: Forth200x enhanced locals implementation

From "Alex McDonald" <blog@rivadpm.com>
Newsgroups comp.lang.forth
Subject Re: Forth200x enhanced locals implementation
Date 2013-10-30 22:23 +0000
Organization A noiseless patient Spider
Message-ID <l4s0sb$mti$1@dont-email.me> (permalink)
References <2013Oct30.180302@mips.complang.tuwien.ac.at>

Show all headers | View raw


on 30/10/2013 17:02:58,  wrote:
> The proposal for the Forth200x enhanced locals proposal does not
> contain a portable implementation, even though implementing the syntax
> is possible portably (increasing the number of locals, also contained
> in that proposal, requires carnal knowledge).
> 
> So I implemented the X:locals syntax portably, and you can find the
> result in compat/xlocals.fs in
> <http://www.complang.tuwien.ac.at/forth/compat.zip>.
> 
> There is an interesting insight in this implementation: I started out
> with the <http://www.complang.tuwien.ac.at/forth/anslocal.fs> code
> inspired by John Hayes' paper on implementing the { ... } syntax and
> added the "|" option and some error checking.
> 
> The interesting change is that I switched from BL WORD COUNT to using
> PARSE-NAME.  This significantly simplified the implementation, as I
> did not need to save and restore >IN, and reparse each local, but
> could just keep the parsed string descriptors around.

From wf32 locals implementation;

: nextword     ( -- addr len ) \ get next word in input stream
    begin parse-name dup 0=
    while 
      drop refill dup 0= if exit then
      2drop
    repeat ;

: definite-word ( -- addr len ) \ find definite word in stream
    nextword dup 0= throw_earlyeof ?throw ;

nextword supports {: across multiple lines; definite-word ensure that the
input stream isn't exhausted until we expect it to be. They are not good
names, I admit. Then;

: {: ( -- )  \ {: :} locals
   compile-only>
     0 to localdcl          \ zero dcl counter, new set of locals
     begin definite-word                    \ get next word
       2dup s" |" str= >r               \ as in {: [...] | ...
       2dup s" --" str= >r              \ as in {: [...] -- ...
       2dup s" :}"  str= 2r> or or not    \ as in {: [...] :} ...
     while (local) repeat                   \ if none, then not done
     0 0 (local)                          \ done all locals
     begin
       2dup s" :}" str= >r          \ here at ... -- or ... :}
            s" |" str= r> or not
     while definite-word repeat ;  \ skip until finish

Back to comp.lang.forth | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Forth200x enhanced locals implementation anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-10-30 17:03 +0000
  Re: Forth200x enhanced locals implementation "Alex McDonald" <blog@rivadpm.com> - 2013-10-30 22:23 +0000
    Re: Forth200x enhanced locals implementation anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-10-31 12:06 +0000
      Re: Forth200x enhanced locals implementation "Alex McDonald" <blog@rivadpm.com> - 2013-10-31 18:01 +0000
        Re: Forth200x enhanced locals implementation anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-11-01 08:46 +0000
          Re: Forth200x enhanced locals implementation "Alex McDonald" <blog@rivadpm.com> - 2013-11-01 10:36 +0000
  Re: Forth200x enhanced locals implementation albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-10-31 14:21 +0000
  Re: Forth200x enhanced locals implementation anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-11-03 14:22 +0000

csiph-web