-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbranch-bug.pn
54 lines (46 loc) · 1.18 KB
/
branch-bug.pn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
say = (msg): msg string print, "\n" print.
say2 = (label, value): label print, ": " print, value print, "\n" print.
wrongness = (n):
if (n == 0):
say("In n == 0 branch")
1
.
else:
say("In n != 0 branch")
.
.
say2("wrongness(0)", wrongness(0))
fib = (n):
say("in fib")
say(n)
if (n < 2):
say("n < 2")
# I can't get this to work no matter what:
# return(1)
# Nor any of this:
# result = 1
# say2("result", result)
# say2("1", 1)
# This isn't working either:
# They all fail when trying to print the "1", lookup failed on 'print'.
1
.
else:
say("n >= 2")
x = self fib(n-2)
say("got x")
say2("x", x)
y = self fib(n-1)
say2("y", y)
say2("x + y + 1", x + y + 1)
return(x + y + 1)
# Doesn't work, returns nil.
# return self fib(n-2) + self fib(n-1) + 1
.
.
say2("fib(10)", fib(10))
# This fails, even in the bytecode interpreter, and the reason seems to be bad
# codegen for "else". Rather than ending the "if" branch with a jump past the
# "else" branch, the compiler starts the "else" branch with a "testjmp".
# Apparently it thinks it arrived here from the "if"'s test (a "notjmp"), but
# of course the "if" branch can clobber the value.