aosabook/500lines · error · VirtualMachineError

unsupported bytecode type: %s

Error message

unsupported bytecode type: %s

What it means

Error "unsupported bytecode type: %s" thrown in aosabook/500lines.

Source

Thrown at interpreter/code/byterun/pyvm2.py:211

        return byte_name, argument

    def dispatch(self, byte_name, argument):
        """ Dispatch by bytename to the corresponding methods.
        Exceptions are caught and set on the virtual machine."""

        # When later unwinding the block stack,
        # we need to keep track of why we are doing it.
        why = None
        try:
            bytecode_fn = getattr(self, 'byte_%s' % byte_name, None)
            if bytecode_fn is None:
                if byte_name.startswith('UNARY_'):
                    self.unaryOperator(byte_name[6:])
                elif byte_name.startswith('BINARY_'):
                    self.binaryOperator(byte_name[7:])
                else:
                    raise VirtualMachineError(
                        "unsupported bytecode type: %s" % byte_name
                    )
            else:
                why = bytecode_fn(*argument)
        except:
            # deal with exceptions encountered while executing the op.
            self.last_exception = sys.exc_info()[:2] + (None,)
            why = 'exception'

        return why

    def manage_block_stack(self, why):
        block = self.frame.block_stack[-1]

        if block.type == 'loop' and why == 'continue':
            self.jump(self.return_value)
            why = None
            return why

View on GitHub (pinned to fba689d101)

Solutions

  1. Implement a byte_<NAME> method on VirtualMachine for the missing bytecode.
  2. If it is a unary or binary operator, add the operator to UNARY_OPERATORS/BINARY_OPERATORS so the dispatch handles it.
  3. Confirm the Python version whose bytecode you are executing matches the version the VM supports.

Example fix

def byte_PRINT_ITEM(self):
    item = self.frame.pop()
    print(item, end=' ')  # add the missing handler to VirtualMachine

When it happens

Trigger: Thrown at interpreter/code/byterun/pyvm2.py:211 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of aosabook/500lines@fba689d101 (2026-08-13). Data as JSON: /api/errors/dd3226385b343751. Report an issue: GitHub.