1.1 --- a/micropython/basicdata.py Tue Apr 01 00:19:03 2014 +0200
1.2 +++ b/micropython/basicdata.py Thu May 01 23:03:06 2014 +0200
1.3 @@ -113,45 +113,4 @@
1.4
1.5 __shortrepr__ = __repr__
1.6
1.7 -# Data objects appearing in programs before run-time.
1.8 -
1.9 -class Const(Constant, TypedInstance):
1.10 -
1.11 - "A constant object with no context."
1.12 -
1.13 - def __init__(self, value):
1.14 - Instance.__init__(self)
1.15 - self.value = value
1.16 -
1.17 - def get_value(self):
1.18 - return self.value
1.19 -
1.20 - def __repr__(self):
1.21 - return "Const(%r)" % self.value
1.22 -
1.23 - __shortrepr__ = __repr__
1.24 -
1.25 - # Support constants as dictionary keys in order to build constant tables.
1.26 -
1.27 - def __eq__(self, other):
1.28 - return other is not None and isinstance(other, Const) and \
1.29 - self.value == other.value and self.value.__class__ is other.value.__class__
1.30 -
1.31 - def __ne__(self, other):
1.32 - return not self.__eq__(other)
1.33 -
1.34 - def __hash__(self):
1.35 - return hash(self.value)
1.36 -
1.37 - # Constants are instances of various built-in types.
1.38 -
1.39 - def value_type_name(self):
1.40 - return ".".join(self.value_type_name_parts())
1.41 -
1.42 - def value_type_name_parts(self):
1.43 - return "__builtins__", self.get_class_name()
1.44 -
1.45 - def get_class_name(self):
1.46 - return self.value.__class__.__name__
1.47 -
1.48 # vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/micropython/data.py Tue Apr 01 00:19:03 2014 +0200
2.2 +++ b/micropython/data.py Thu May 01 23:03:06 2014 +0200
2.3 @@ -1607,6 +1607,47 @@
2.4 else:
2.5 self.importer.use_name(attrname, self.full_name(), value)
2.6
2.7 +# Data objects appearing in programs before run-time.
2.8 +
2.9 +class Const(Constant, TypedInstance):
2.10 +
2.11 + "A constant object with no context."
2.12 +
2.13 + def __init__(self, value):
2.14 + self.value = value
2.15 + TypedInstance.__init__(self, get_constant_class(self.get_class_name()))
2.16 +
2.17 + def get_value(self):
2.18 + return self.value
2.19 +
2.20 + def __repr__(self):
2.21 + return "Const(%r)" % self.value
2.22 +
2.23 + __shortrepr__ = __repr__
2.24 +
2.25 + # Support constants as dictionary keys in order to build constant tables.
2.26 +
2.27 + def __eq__(self, other):
2.28 + return other is not None and isinstance(other, Const) and \
2.29 + self.value == other.value and self.value.__class__ is other.value.__class__
2.30 +
2.31 + def __ne__(self, other):
2.32 + return not self.__eq__(other)
2.33 +
2.34 + def __hash__(self):
2.35 + return hash(self.value)
2.36 +
2.37 + # Constants are instances of various built-in types.
2.38 +
2.39 + def value_type_name(self):
2.40 + return ".".join(self.value_type_name_parts())
2.41 +
2.42 + def value_type_name_parts(self):
2.43 + return "__builtins__", self.get_class_name()
2.44 +
2.45 + def get_class_name(self):
2.46 + return self.value.__class__.__name__
2.47 +
2.48 # Pre-made class instances.
2.49 # For each of these, their details will be filled in later.
2.50
2.51 @@ -1619,6 +1660,7 @@
2.52 "unicode" : Class("unicode"),
2.53 "type" : Class("type"),
2.54 "NoneType" : Class("NoneType"),
2.55 + "NotImplementedType" : Class("NotImplementedType"),
2.56 }
2.57
2.58 def get_constant_class(name):