private void saveStack() {
		int height = 0;

		for (int i = 0; i < stack.size(); i++) {
			final Expr expr = stack.get(i);

			if (Tree.USE_STACK) {
				// Save to a stack variable only if we'll create a new
				// variable there.
				if (!(expr instanceof StackExpr)
						|| (((StackExpr) expr).index() != height)) {

					final StackExpr target = new StackExpr(height, expr.type());

					// Make a new statement to store the expression that was
					// part of the stack into memory.
					final Stmt store = new ExprStmt(new StoreExpr(target, expr,
							expr.type()));

					appendStmt(store);

					final StackExpr copy = (StackExpr) target.clone();
					copy.setDef(null);
					stack.set(i, copy);
				}

			} else {
				if (!(expr instanceof LocalExpr)
						|| !((LocalExpr) expr).fromStack()
						|| (((LocalExpr) expr).index() != height)) {

					final LocalExpr target = newStackLocal(nextIndex++, expr
							.type());

					final Stmt store = new ExprStmt(new StoreExpr(target, expr,
							expr.type()));

					appendStmt(store);

					final LocalExpr copy = (LocalExpr) target.clone();
					copy.setDef(null);
					stack.set(i, copy);
				}
			}

			height += expr.type().stackHeight();
		}
	}