Ejemplo n.º 1
0
def _return_from_function(config: Configuration) -> None:
    """
    Helper function for when the control flow for a frame exits.
    """
    valn = tuple(config.pop_operand() for _ in range(config.frame_arity))
    # discard all of the current labels before popping the frame.
    while config.has_active_label:
        config.pop_label()
    config.pop_frame()

    if config.has_active_frame:
        config.extend_operands(valn)
    else:
        config.extend_results(valn)
Ejemplo n.º 2
0
def _br(config: Configuration, label_idx: LabelIdx) -> None:
    """
    Helper function for the BR, BR_IF, and BR_TABLE opcodes.
    """
    label = config.get_label_by_idx(label_idx)
    # take any return values off of the stack before popping labels
    valn = tuple(config.pop_operand() for _ in range(label.arity))

    if label.is_loop:
        # For loops we keep the label which represents the loop on the stack
        # since the continuation of a loop is beginning back at the beginning
        # of the loop itself.
        for _ in range(label_idx):
            config.pop_label()
        config.seek_to_instruction_idx(0)
    else:
        for _ in range(label_idx + 1):
            config.pop_label()

    # put return values back on the stack.
    config.extend_operands(valn)
Ejemplo n.º 3
0
def _exit_block(config: Configuration) -> None:
    """
    Helper function for when the control flow for a label exits.
    """
    label = config.pop_label()
    config.extend_operands(label.operand_stack)