sclass VStack implements Steppable { new L stack; bool justReturned; O latestResult; transient bool justReturned_new; *() {} *(Computable computation) { push(computation); } // A is what the function returns interface Computable { public void step(VStack stack, O subComputationResult); } void push(Computable computation) { stack.add(computation); } // perform a computation step. returns false iff done public bool step() { if (empty(stack)) false; O latestResult = this.latestResult; this.latestResult = null; last(stack).step(this, latestResult); justReturned = justReturned_new; justReturned_new = false; true; } // called from computation to return a value void _return(O value default null) { latestResult = value; set justReturned_new; removeLast(stack); } // called from computation to tail-call another routine void tailCall(Computable computation) { removeLast(stack); stack.add(computation); } A compute(Computable computation) { if (computation == null) null; push(computation); stepAll(this); ret (A) latestResult; } O result() { ret latestResult; } }