Skip to content

Commit c17917f

Browse files
committed
fix applyOp got ReturnValue
1 parent deaecf1 commit c17917f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

evaluator.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ func (e *Evaluator) evaluate(exp *Expr, env *Environment) interface{} {
137137
case Binary:
138138
a := e.evaluate(exp.Left, env)
139139
b := e.evaluate(exp.Right, env)
140+
if a_, ok := a.(ReturnValue); ok {
141+
a = a_.Value
142+
}
143+
if b_, ok := b.(ReturnValue); ok {
144+
b = b_.Value
145+
}
140146
result := applyBinaryOp(exp.Operator, a, b, exp)
141147
return result
142148

example/test.rune

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
fibonacci = fun(n) {
2+
if n <= 0 then return = 0
3+
elif n == 1 then return = 1
4+
else
5+
fibonacci(n - 1) + fibonacci(n - 2)
6+
}
7+
8+
timeBefore = millis()
9+
result = fibonacci(30)
10+
timeAfter = millis()
11+
time = timeAfter - timeBefore
12+
println("Result: ", result)
13+
println("Milliseconds: ", time)
14+
return
15+
116
factorial = fun(n) {
217
if n == 0 then return = 1
318
n * factorial(n - 1)

0 commit comments

Comments
 (0)