// Restore stack to match given machine state. Stack should currently be empty. public bool Restore(MachineState stateAfterRestore, int skip) { if (skip > stateAfterRestore.Depth) { return(Failed(false, "underflow in restore")); } if (Depth != 0) { return(Failed(false, "cannot restore into non-empty stack")); } for (var i = 0; i < stateAfterRestore.Depth - skip; i++) { var id = stateAfterRestore.PeekId(stateAfterRestore.Depth - skip - 1 - i, gensym); var cell = new VariableCell(id); // Ok if already added as temporary compEnv.AddVariable (id, ArgLocal.Local, false, true, compEnv.SubstituteType(stateAfterRestore.PeekType(stateAfterRestore.Depth - skip - 1 - i))); stack.Add(new ExpressionStackEntry(cell.Read(), bottom)); } return(true); }
private bool Dump(ISeq <Statement> statements, MachineState state, int skip, int i) { if (statements == null) { return(Failed(false, "eval in flush")); } var id = state.PeekId(stack.Count - (1 + skip) - i, gensym); var cell = new VariableCell(id); var read = stack[i].Expression as ReadExpression; if (read == null || !read.Address.Equals(cell.AddressOf())) { // Ok if id already added as temporary compEnv.AddVariable(id, ArgLocal.Local, false, true, compEnv.SubstituteType(state.PeekType(stack.Count - (1 + skip) - i))); statements.Add(new ExpressionStatement(cell.Write(stack[i].Expression.CloneIfStruct(compEnv)))); } // else: stack entry has not changed, so no need to save it return(true); }