Example #1
0
 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)
Example #2
0
 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)
Example #3
0
 def type(self):
     return Type(libcoreir_c.COREWireableGetType(self.ptr), self.context)
Example #4
0
 def Flip(self, typ):
     return Type(libcoreir_c.COREContextFlip(self.context, typ.ptr), self)
Example #5
0
 def Array(self, length, typ):
     assert isinstance(typ, Type)
     assert isinstance(length, int)
     return Type(libcoreir_c.COREArray(self.context, length, typ.ptr), self)
Example #6
0
 def Bit(self):
     return Type(libcoreir_c.COREBit(self.context), self)
Example #7
0
 def Any(self):
     return Type(libcoreir_c.COREAny(self.context), self)
Example #8
0
 def get_named_type(self, namespace, type_name):
     return Type(
         libcoreir_c.COREContextNamed(self.context, str.encode(namespace),
                                      str.encode(type_name)), self)