def __getitem__(self, key): if not isinstance(key, tuple) and len(key) == 2 \ and isinstance(key[0], str) and isinstance(key[1], str): raise KeyError("Key should be a tuple of the form (str, str), " "not {}".format(key)) namespace = key[0] type_name = key[1] # TODO: Check existence of namespace and named type return Type( libcoreir_c.COREContextNamed(self.context.context, str.encode(namespace), str.encode(type_name)), self.context)
def Record(self, fields): keys = [] values = [] for key, value in fields.items(): keys.append(str.encode(key)) values.append(value.ptr) keys = (ct.c_char_p * len(fields))(*keys) values = (COREType_p * len(fields))(*values) record_params = libcoreir_c.CORENewMap( self.context, ct.cast(keys, ct.c_void_p), ct.cast(values, ct.c_void_p), len(fields), COREMapKind_STR2TYPE_ORDEREDMAP) return Type(libcoreir_c.CORERecord(self.context, record_params), self)
def type(self): return Type(libcoreir_c.COREWireableGetType(self.ptr), self.context)
def Flip(self, typ): return Type(libcoreir_c.COREContextFlip(self.context, typ.ptr), self)
def Array(self, length, typ): assert isinstance(typ, Type) assert isinstance(length, int) return Type(libcoreir_c.COREArray(self.context, length, typ.ptr), self)
def Bit(self): return Type(libcoreir_c.COREBit(self.context), self)
def Any(self): return Type(libcoreir_c.COREAny(self.context), self)
def get_named_type(self, namespace, type_name): return Type( libcoreir_c.COREContextNamed(self.context, str.encode(namespace), str.encode(type_name)), self)