on df5bf81 help sign in
Idris-dev/java/org/idris/rts/TailCallClosure.java
26 lines 532 B history raw
1package org.idris.rts;
3public class TailCallClosure extends Closure {
4 private final Closure function;
6 public TailCallClosure(Closure function) {
7 super();
8 this.function = function;
9 }
11 public final Object call() {
12 Closure function = this.function;
13 Object result = null;
14 while (function != null) {
15 result = function.call();
16 function = null;
17 if (result instanceof TailCallClosure) {
18 function = ((TailCallClosure)result).function;
19 } else {
20 return result;
21 }
22 }
23 return result;
24 }