def _simulate_stack(code: list) -> int:
max_stack = <NUM_LIT:0><EOL>curr_stack = <NUM_LIT:0><EOL>def _check_stack(ins):<EOL><INDENT>if curr_stack < <NUM_LIT:0>:<EOL><INDENT>raise CompileError("<STR_LIT>".format(ins))<EOL><DEDENT>if curr_stack > max_stack:<EOL><INDENT>return curr_stack<EOL><DEDENT><DEDENT>for instruction in code:<EOL><INDENT>assert isinstance(instruction, dis.Instruction)<EOL>if instruction.arg is not None:<EOL><INDENT>try:<EOL><INDENT>effect = dis.stack_effect(instruction.opcode, instruction.arg)<EOL><DEDENT>except ValueError as e:<EOL><INDENT>raise CompileError("<STR_LIT>"<EOL>.format(instruction.opcode)) from e<EOL><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>effect = dis.stack_effect(instruction.opcode)<EOL><DEDENT>except ValueError as e:<EOL><INDENT>raise CompileError("<STR_LIT>"<EOL>.format(instruction.opcode)) from e<EOL><DEDENT><DEDENT>curr_stack += effect<EOL>_should_new_stack = _check_stack(instruction)<EOL>if _should_new_stack:<EOL><INDENT>max_stack = _should_new_stack<EOL><DEDENT><DEDENT>return max_stack<EOL>
Simulates the actions of the stack, to check safety.

This returns the maximum needed stack.