Warning: session_start(): open(/var/lib/php/sessions/sess_iaf8hjn1macvvgl57c97hmno0i, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
sclass VStack implements Steppable {
new L stack;
O latestResult;
// was last instruction a return?
// can be used by computations to switch without a label
transient bool justReturned;
transient O subComputationResult;
// the null sentinel replaces a null function result
// when stored in latestResult
sclass NullSentinel {}
static new NullSentinel nullSentinel;
*() {}
*(Computable computation) { push(computation); }
// A is what the function returns
interface Computable {
public void step(VStack stack, O subComputationResult);
}
private O deSentinel(O o) {
ret o instanceof NullSentinel ? null : o;
}
private O sentinel(O o) {
ret o == null ? nullSentinel : o;
}
// called by computations or users to start a subroutine
void push(Computable computation) {
stack.add(computation);
}
// perform a computation step. returns false iff done
public bool step() {
if (empty(stack)) false;
justReturned = latestResult != null;
subComputationResult = deSentinel(latestResult);
latestResult = null;
last(stack).step(this, subComputationResult);
subComputationResult = null;
true;
}
// called from a computation to return a value
void _return(O value default null) {
latestResult = sentinel(value);
removeLast(stack);
}
// called from a computation to tail-call another routine
void tailCall(Computable computation) {
removeLast(stack);
stack.add(computation);
}
// all-in-one evaluation function - call on an empty stack
A compute(Computable computation) {
if (computation == null) null;
push(computation);
stepAll(this);
ret (A) latestResult;
}
// return result of just completed computation
O result() {
ret deSentinel(latestResult);
}
bool hasSubResult() { ret justReturned; }
}