[PicForth] Code generation bug with infinite loops, dead code,
and 'else only' if constructs
Alex Holden
alex at linuxhacker.org
Mon Nov 29 21:23:15 CET 2004
OK, this is a bit of an obscure one. I had many lines of code in an
infinite loop in my main, and I wanted to quickly test something out
without commenting out every line of the loop, so I added something like
this at the beginning of main before the loop: dosomething begin again
The code picforth generated caused it to execute the 'dosomething' as
expected but then it entered the main loop as normal as if the 'begin
again' wasn't there. After a bit of messing about I seem to have
discovered that the code generation bug is only triggered when there is
an 'else only' if construct (ie. sometest if else dosomething then)
inside the main loop. Here is some example code:
: fred ;
: barney ;
: sometest 0 ;
main : test
fred begin again
begin sometest if else barney then again
;
barney shouldn't get called but it does. Here's the generated code:
0x0000 018A clrf 0x0A
0x0001 2809 goto 0x009 ; (init-picforth)
; name: fred
; max return-stack depth: 0
0x0004 0008 return
; name: barney
; max return-stack depth: 0
0x0005 0008 return
; name: sometest
; max return-stack depth: 0
0x0006 0384 decf 0x04,f
0x0007 0180 clrf 0x00
0x0008 0008 return
; name: (init-picforth)
; max return-stack depth: 0
0x0009 3032 movlw 0x32
0x000A 0084 movwf 0x04
; name: test
; max return-stack depth: 1
0x000B 2004 call 0x004 ; fred
0x000C 280E goto 0x00E ; test + 0x003
0x000D 2005 call 0x005 ; barney
0x000E 280D goto 0x00D ; test + 0x002
--
------------ 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