1.1 --- a/micropython/data.py Tue Apr 01 00:19:03 2014 +0200
1.2 +++ b/micropython/data.py Thu May 01 23:03:06 2014 +0200
1.3 @@ -1607,6 +1607,47 @@
1.4 else:
1.5 self.importer.use_name(attrname, self.full_name(), value)
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 + self.value = value
1.15 + TypedInstance.__init__(self, get_constant_class(self.get_class_name()))
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 # Pre-made class instances.
1.49 # For each of these, their details will be filled in later.
1.50
1.51 @@ -1619,6 +1660,7 @@
1.52 "unicode" : Class("unicode"),
1.53 "type" : Class("type"),
1.54 "NoneType" : Class("NoneType"),
1.55 + "NotImplementedType" : Class("NotImplementedType"),
1.56 }
1.57
1.58 def get_constant_class(name):