# HG changeset patch # User Paul Boddie # Date 1398978186 -7200 # Node ID 4c2ac7cb47f72169bddfe0a0d61108f3e2b99688 # Parent aaedb9c1a31810ce96afc578aae8bfe52d30e11b Populated Const instances with references to their values' classes. diff -r aaedb9c1a318 -r 4c2ac7cb47f7 micropython/basicdata.py --- a/micropython/basicdata.py Tue Apr 01 00:19:03 2014 +0200 +++ b/micropython/basicdata.py Thu May 01 23:03:06 2014 +0200 @@ -113,45 +113,4 @@ __shortrepr__ = __repr__ -# Data objects appearing in programs before run-time. - -class Const(Constant, TypedInstance): - - "A constant object with no context." - - def __init__(self, value): - Instance.__init__(self) - self.value = value - - def get_value(self): - return self.value - - def __repr__(self): - return "Const(%r)" % self.value - - __shortrepr__ = __repr__ - - # Support constants as dictionary keys in order to build constant tables. - - def __eq__(self, other): - return other is not None and isinstance(other, Const) and \ - self.value == other.value and self.value.__class__ is other.value.__class__ - - def __ne__(self, other): - return not self.__eq__(other) - - def __hash__(self): - return hash(self.value) - - # Constants are instances of various built-in types. - - def value_type_name(self): - return ".".join(self.value_type_name_parts()) - - def value_type_name_parts(self): - return "__builtins__", self.get_class_name() - - def get_class_name(self): - return self.value.__class__.__name__ - # vim: tabstop=4 expandtab shiftwidth=4 diff -r aaedb9c1a318 -r 4c2ac7cb47f7 micropython/data.py --- a/micropython/data.py Tue Apr 01 00:19:03 2014 +0200 +++ b/micropython/data.py Thu May 01 23:03:06 2014 +0200 @@ -1607,6 +1607,47 @@ else: self.importer.use_name(attrname, self.full_name(), value) +# Data objects appearing in programs before run-time. + +class Const(Constant, TypedInstance): + + "A constant object with no context." + + def __init__(self, value): + self.value = value + TypedInstance.__init__(self, get_constant_class(self.get_class_name())) + + def get_value(self): + return self.value + + def __repr__(self): + return "Const(%r)" % self.value + + __shortrepr__ = __repr__ + + # Support constants as dictionary keys in order to build constant tables. + + def __eq__(self, other): + return other is not None and isinstance(other, Const) and \ + self.value == other.value and self.value.__class__ is other.value.__class__ + + def __ne__(self, other): + return not self.__eq__(other) + + def __hash__(self): + return hash(self.value) + + # Constants are instances of various built-in types. + + def value_type_name(self): + return ".".join(self.value_type_name_parts()) + + def value_type_name_parts(self): + return "__builtins__", self.get_class_name() + + def get_class_name(self): + return self.value.__class__.__name__ + # Pre-made class instances. # For each of these, their details will be filled in later. @@ -1619,6 +1660,7 @@ "unicode" : Class("unicode"), "type" : Class("type"), "NoneType" : Class("NoneType"), + "NotImplementedType" : Class("NotImplementedType"), } def get_constant_class(name):