def __call__( self, *args, **kwargs ):
    #print( "- Meta CALL", args )   # DEBUG

    # Instantiate the user-created BitStructDefinition class
    def_inst = super( MetaBitStruct, self ).__call__( *args, **kwargs )

    # Get all the members of type BitField from the BitStructDefinition
    # instance. Sort them by order of declaration (stored by the
    # BitField objects). TODO: sort objects in dictionary..
    fields = [(name, obj) for name, obj in
              def_inst.__dict__.items() if isinstance( obj, BitField )]
    fields.sort( lambda (n1, o1), (n2, o2) : cmp(o2.id, o1.id) )

    # Get the total size of the BitStruct
    nbits = sum( [ f.nbits for name, f in fields ] )

    # Create the new BitStruct class, then instantiate it
    name_prfx       = def_inst.__class__.__name__
    name_sufx       = '_'.join(str(x) for x in args)
    class_name      = "{}_{}".format( name_prfx, name_sufx )
    bitstruct_class = type( class_name, ( BitStruct, ), self._classdict )

    # Keep track of bit positions for each bitfield
    start_pos = 0
    bitstruct_class._bitfields = {}

    # Transform attributes containing BitField objects into properties,
    # when accessed they return slices of the underlying value
    for attr_name, bitfield in fields:

      # Calculate address range, update start_pos
      end_pos   = start_pos + bitfield.nbits
      addr      = slice( start_pos, end_pos )
      start_pos = end_pos

      # Add slice to bitfields
      bitstruct_class._bitfields[ attr_name ] = addr

      # Create a getter to assign to the property
      def create_getter( addr ):
        return lambda self : self.__getitem__( addr )

      # Create a setter to assign to the property
      # TODO: not needed when returning ConnectionSlice and accessing .value
      def create_setter( addr ):
        return lambda self, value: self.__setitem__( addr, value )

      # Add the property to the class
      setattr( bitstruct_class, attr_name,
               property( create_getter( addr ),
                         create_setter( addr )
                       )
             )

    if def_inst.__class__.__dict__ in '__str__':
      bitstruct_class.__str__ = def_inst.__class__.__dict__['__str__']

    # Return an instance of the new BitStruct class
    bitstruct_inst = bitstruct_class( nbits )

    # TODO: hack for verilog translation!
    bitstruct_inst._module    = def_inst.__class__.__module__
    bitstruct_inst._classname = def_inst.__class__.__name__
    bitstruct_inst._instantiate = '{class_name}{args}'.format(
        class_name = def_inst.__class__.__name__,
        args       = args,
    )
    assert not kwargs

    return bitstruct_inst

#=======================================================================
# BitStructDefinition
#=======================================================================
# Users wishing to define a new BitStruct type should create a new class
# which subclasses BitStructDefinition, then define fields using the
# BitField type (below). The parameterizable BitStructDefinition defined
# by the user is then used to create new classes of type BitStruct.
#
dataset/ETHPy150Open cornell-brg/pymtl/pymtl/datatypes/BitStruct.py/MetaBitStruct.__call__/swapped operands of `in`