bobbimanners / EightBall

The Eight Bit Algorithmic Language for Apple II, Commodore 64 and VIC20
GNU General Public License v3.0
19 stars 3 forks source link

recurse3() test case is failing when compiled #9

Closed bobbimanners closed 6 years ago

bobbimanners commented 6 years ago
sub recurse3(word x)
  if x==0
    return 1;
  else
    return x*recurse2(x-1)
  endif
endsub

This works okay in the interpreter but the compiled code does not run. Swapping the order of the arguments to the multiplication resolves the issue!

bobbimanners commented 6 years ago

Code above should read:

sub recurse3(word x)
  if x==0
    return 1;
  else
    return x*recurse3(x-1)
  endif
endsub

Even with this silly issue fixed however, the issue remains the same. Works fine when interpreted but not when compiled for x>1. Always returns 1 when compiled. If the code is changed to return recurse3(x-1) * x then it works. Not clear why.

bobbimanners commented 6 years ago

It seems the problem here is that the parser muddles up the outer (x function_call) and the inner (x-1) expressions somehow. The code emitted seems to try to calculate xx-1. This is probably a bug in the function call logic (which is a hack anyhow).

bobbimanners commented 6 years ago

Fixed in v0.62. The problem was that the compiler was omitting to push SENTINEL to the operator stack before evaluating the function's operand, and pop it afterwards. As a result the parsing was getting confused.