Re: Win32Forth defect in (LOCAL)?
  Home FAQ Contact Sign in
comp.lang.forth only
 
Advanced search
POPULAR GROUPS

more...

 Up
Re: Win32Forth defect in (LOCAL)?         

Group: comp.lang.forth · Group Profile
Author: Alex McDonald
Date: Sep 1, 2008 13:57

On Aug 23, 3:52 pm, "Stephan Becher" online.de> wrote:
> While trying to validate my new ANS Forth implemention of StrongForth on
> Win32Forth, I stumbled over an issue with (LOCAL). The generated code didn't
> work, and I finally found out that even the sample definition of LOCALS|
> from appendix A15 of the ANS Forth spec doesn't work correctly:
>
> Win32Forth: a Forth for Windows 95/98/ME/NT/2K/XP
> Version: 6.12.00 Build: 2
> Compiled: Samstag, August 23 2008, 4:18
> Platform: Windows XP, 821k bytes free
>  2,885 Words in Application dictionary
>  2,332 Words in System dictionary
>  5,217 Words total in dictionaries
> 20,312 Windows Constants available
> Current directory: C:\Programme\Win32Forth\extsrc\wincon\winconcpp
> Loading Win32For.CFG
> Loading Win32ForUser.CFG
>
> Program path is:     C:\Programme\Win32Forth\Win32For.EXE
> Forth path is:       C:\Programme\Win32Forth\
> Application path is:
>
> System Editor is:    Win32Forth IDE
>
> WARNING OFF SYS-WARNING-OFF  ok
> : EXAMPLE  ( n -- n n**2 n**3 )
>     LOCALS| N |   N  DUP N *  DUP N * ;  ok
> 5 EXAMPLE . . . 125 25 5  ok
> : LOCALS|  ( "name...name |" -- )
>     BEGIN
>       BL WORD   COUNT OVER C@
>       [CHAR] | - OVER 1 - OR
>     WHILE
>       (LOCAL)
>     REPEAT 2DROP   0 0 (LOCAL)
> ;  ok
> IMMEDIATE  ok
> : EXAMPLE  ( n -- n n**2 n**3 )
>     LOCALS| N |   N  DUP N *  DUP N * ;  ok
> 5 EXAMPLE . . . 0 0 0
>               ^
> Error(-4): . stack underflow
> 4 5 EXAMPLE . . . 64 16 4  ok
> .S  empty  ok
>
> It seems the runtime code of this redefined version of LOCALS| swallows one
> cell from the stack. Is this a known defect?
>
> Regards,
> Stephan

Yes, it looks like a bug. However, it's probably not going to get
fixed for some time I suspect, as (LOCALS) isn't used in user code.

: LOCALS| ( -- ) \ ANS standard locals
LOCALS-INIT
FALSE TO LOCDIR \ reversed stack order
BEGIN BLNEXTWORD
2DUP S" |" STR= INVERT
WHILE
(LOCAL) \ declare a local
REPEAT 2DROP
PARMS, \ compile runtime code
(equiv of 0 0 (LOCAL))
; IMMEDIATE

There's a bit of jiggery pokery goes on in the standard definition of
LOCALS| as you can see.

--
Regards
Alex McDonald
no comments
diggit! del.icio.us! reddit!