export const MAX_SIMULATED_POPS = 1024;
export function createEntryStackState() {
return {
required: 0,
stack: [],
};
}
export function topLiteral(state) {
return state.stack.at(-1);
}
export function popCount(state, count) {
ensureAvailable(state, count);
for (let index = 0; index < count; index += 1) {
state.stack.pop();
}
}
export function ensureAvailable(state, count) {
const boundedCount = Math.min(count, MAX_SIMULATED_POPS);
while (state.stack.length < boundedCount) {
state.stack.unshift(null);
state.required += 1;
}
}