[PicForth] Possible 'if' code generation bug
Alex Holden
alex at linuxhacker.org
Sat Nov 13 12:42:56 CET 2004
Picforth seems to generate incorrect code when you have an 'if' with no
action following it. Is it not legal Forth to use a construct like that
if you want to only perform an action when a test fails? It works when I
try it in gforth and pforth but picforth doesn't seem to like it.
Here's a rather contrived example:
: sometest 0 ;
: doaction ;
main : sometest if else doaction then ;
Compiles to:
0x0000 018A clrf 0x0A
0x0001 2807 goto 0x007 ; (init-picforth)
; name: sometest
; max return-stack depth: 0
0x0003 0384 decf 0x04,f
0x0004 0180 clrf 0x00
0x0005 0008 return
; name: doaction
; max return-stack depth: 0
0x0006 0008 return
; name: (init-picforth)
; max return-stack depth: 0
0x0007 3032 movlw 0x32
0x0008 0084 movwf 0x04
; name: sometest
; max return-stack depth: 0
0x0009 0800 movf 0x00,w
0x000A 0A84 incf 0x04,f
0x000B 3800 iorlw 0x00
0x000C 1D03 btfss 0x03,2
0x000D 2800 goto 0x000 ; sometest + 0x005
0x000E 280F goto 0x00F ; sometest + 0x006
0x000F 0008 return
Which seems to me to be badly messed up. I stumbled across this when I
had a similar construct in my 'main' word and the goto 0x000 instruction
was making it continually reset itself.
Here's what happens if I do something similar with gforth (which behaves
as expected):
: sometest 0 ; ok
: doaction ." Hello" ; ok
: test sometest if else doaction then ; ok
test Hello ok
--
------------ Alex Holden - http://www.linuxhacker.org ------------
If it doesn't work, you're not hitting it with a big enough hammer
More information about the PicForth
mailing list