docs: def to_code(self):
          """Assemble a Python code object from a Code object."""
          co_argcount = len(self.args) - self.varargs - self.varkwargs
          co_stacksize = self._compute_stacksize()
          co_flags = self._compute_flags()
  
          co_consts = [self.docstring]
          co_names = []
          co_varnames = list(self.args)
  
          co_freevars = tuple(self.freevars)
  
          # We find all cellvars beforehand, for two reasons:
          # 1. We need the number of them to construct the numeric argument
          #    for ops in "hasfree".
          # 2. We need to put arguments which are cell vars in the beginning
          #    of co_cellvars
          cellvars = set(arg for op, arg in self.code
                         if isopcode(op) and op in hasfree
                         and arg not in co_freevars)
          co_cellvars = [x for x in self.args if x in cellvars]
  
          def index(seq, item, eq=operator.eq, can_append=True):
              """Find the index of item in a sequence and return it.
              If it is not found in the sequence, and can_append is True,
              it is appended to the sequence.
  
              eq is the equality operator to use.
              """
              for i, x in enumerate(seq):
                  if eq(x, item):
                      return i
              else:
                  if can_append:
                      seq.append(item)
                      return len(seq) - 1
                  else:
                      raise IndexError("Item not found")
  
          # List of tuples (pos, label) to be filled later
          jumps = []
          # A mapping from a label to its position
          label_pos = {}
          # Last SetLineno
          lastlineno = self.firstlineno
          lastlinepos = 0
  
          co_code = array('B')
          co_lnotab = array('B')
          for i, (op, arg) in enumerate(self.code):
              if isinstance(op, Label):
                  label_pos[op] = len(co_code)
  
              elif op is SetLineno:
                  incr_lineno = arg - lastlineno
                  incr_pos = len(co_code) - lastlinepos
                  lastlineno = arg
                  lastlinepos = len(co_code)
  
                  if incr_lineno == 0 and incr_pos == 0:
                      co_lnotab.append(0)
                      co_lnotab.append(0)
                  else:
                      while incr_pos > 255:
                          co_lnotab.append(255)
                          co_lnotab.append(0)
                          incr_pos -= 255
                      while incr_lineno > 255:
                          co_lnotab.append(incr_pos)
                          co_lnotab.append(255)
                          incr_pos = 0
                          incr_lineno -= 255
                      if incr_pos or incr_lineno:
                          co_lnotab.append(incr_pos)
                          co_lnotab.append(incr_lineno)
  
              elif op == opcode.EXTENDED_ARG:
                  raise ValueError("EXTENDED_ARG not supported in Code objects")
  
              elif not op in hasarg:
                  co_code.append(op)
  
              else:
                  if op in hasconst:
                      if isinstance(arg, Code) and i < len(self.code)-1 and \
                         self.code[i+1][0] in hascode:
                          arg = arg.to_code()
                      arg = index(co_consts, arg, operator.is_)
                  elif op in hasname:
                      arg = index(co_names, arg)
                  elif op in hasjump:
                      # arg will be filled later
                      jumps.append((len(co_code), arg))
                      arg = 0
                  elif op in haslocal:
                      arg = index(co_varnames, arg)
                  elif op in hascompare:
                      arg = index(cmp_op, arg, can_append=False)
                  elif op in hasfree:
                      try:
                          arg = index(co_freevars, arg, can_append=False) \
                                + len(cellvars)
                      except IndexError:
                          arg = index(co_cellvars, arg)
                  else:
                      # arg is ok
                      pass
  
                  if arg > 0xFFFF:
                      co_code.append(opcode.EXTENDED_ARG)
                      co_code.append((arg >> 16) & 0xFF)
                      co_code.append((arg >> 24) & 0xFF)
                  co_code.append(op)
                  co_code.append(arg & 0xFF)
                  co_code.append((arg >> 8) & 0xFF)
  
          for pos, label in jumps:
              jump = label_pos[label]
              if co_code[pos] in hasjrel:
                  jump -= pos+3
              if jump > 0xFFFF:
                  raise NotImplementedError("Extended jumps not implemented")
              co_code[pos+1] = jump & 0xFF
              co_code[pos+2] = (jump >> 8) & 0xFF
  
          co_code = co_code.tostring()
          co_lnotab = co_lnotab.tostring()
  
          co_consts = tuple(co_consts)
          co_names = tuple(co_names)
          co_varnames = tuple(co_varnames)
          co_nlocals = len(co_varnames)
          co_cellvars = tuple(co_cellvars)
  
          return types.CodeType(co_argcount, co_nlocals, co_stacksize, co_flags,
                                co_code, co_consts, co_names, co_varnames,
                                self.filename, self.name, self.firstlineno, co_lnotab,
                                co_freevars, co_cellvars)