### Auxiliary functions for operand stack manipulation Source: https://www.w3.org/TR/wasm-core-1 Provides functions to push and pop operand types, including a version that checks against an expected type and handles unknown types. Includes accumulative functions for multiple operands. ```pseudocode func push_opd(type : val_type | Unknown) = opds.push(type) func pop_opd() : val_type | Unknown = if (opds.size() = ctrls[0].height && ctrls[0].unreachable) return Unknown error_if(opds.size() = ctrls[0].height) return opds.pop() func pop_opd(expect : val_type | Unknown) : val_type | Unknown = let actual = pop_opd() if (actual = Unknown) return expect if (expect = Unknown) return actual error_if(actual =/= expect) return actual func push_opds(types : list(val_type)) = foreach (t in types) push_opd(t) func pop_opds(types : list(val_type)) = foreach (t in reverse(types)) pop_opd(t) ``` -------------------------------- ### Auxiliary functions for control stack manipulation Source: https://www.w3.org/TR/wasm-core-1 Provides functions to push and pop control frames, and to mark the current frame as unreachable. Popping verifies the operand stack matches the expected end types and height. ```pseudocode func push_ctrl(label : list(val_type), out : list(val_type)) = let frame = ctrl_frame(label, out, opds.size(), false) ctrls.push(frame) func pop_ctrl() : list(val_type) = error_if(ctrls.is_empty()) let frame = ctrls[0] pop_opds(frame.end_types) error_if(opds.size() =/= frame.height) ctrls.pop() return frame.end_types func unreachable() = opds.resize(ctrls[0].height) ctrls[0].unreachable := true ```