1.1 --- a/generator.py Mon Nov 28 16:23:38 2016 +0100
1.2 +++ b/generator.py Mon Nov 28 17:04:43 2016 +0100
1.3 @@ -788,9 +788,16 @@
1.4
1.5 # Special cases.
1.6
1.7 - elif attrname in ("__fname__", "__name__"):
1.8 + elif attrname in ("__file__", "__fname__", "__mname__", "__name__"):
1.9 path = ref.get_origin()
1.10 - local_number = self.importer.all_constants[path][path]
1.11 +
1.12 + if attrname == "__file__":
1.13 + module = self.importer.get_module(path)
1.14 + value = module.filename
1.15 + else:
1.16 + value = path
1.17 +
1.18 + local_number = self.importer.all_constants[path][value]
1.19 constant_name = "$c%d" % local_number
1.20 attr_path = "%s.%s" % (path, constant_name)
1.21 constant_number = self.optimiser.constant_numbers[attr_path]
2.1 --- a/inspector.py Mon Nov 28 16:23:38 2016 +0100
2.2 +++ b/inspector.py Mon Nov 28 17:04:43 2016 +0100
2.3 @@ -70,14 +70,14 @@
2.4
2.5 # Detect and record imports and globals declared in the module.
2.6
2.7 - self.assign_general_local("__name__", self.get_constant("string", self.name))
2.8 - self.assign_general_local("__file__", self.get_constant("string", filename))
2.9 self.process_structure(self.astnode)
2.10
2.11 # Set the class of the module after the definition has occurred.
2.12
2.13 ref = self.get_builtin("module")
2.14 self.set_name("__class__", ref)
2.15 + self.set_name("__mname__", self.get_constant("string", self.name).reference())
2.16 + self.set_name("__file__", self.get_constant("string", filename).reference())
2.17
2.18 # Get module-level attribute usage details.
2.19
3.1 --- a/lib/__builtins__/core.py Mon Nov 28 16:23:38 2016 +0100
3.2 +++ b/lib/__builtins__/core.py Mon Nov 28 17:04:43 2016 +0100
3.3 @@ -49,11 +49,20 @@
3.4
3.5 "The class of module objects."
3.6
3.7 + def __init__(self):
3.8 +
3.9 + """
3.10 + Reserve special attributes for module instances.
3.11 + """
3.12 +
3.13 + self.__file__ = None
3.14 + self.__mname__ = None
3.15 +
3.16 def __str__(self):
3.17
3.18 "Return a string representation."
3.19
3.20 - return self.__name__
3.21 + return self.__mname__
3.22
3.23 __repr__ = __str__
3.24