1.1 --- a/docs/concepts.txt Fri Jun 12 22:03:56 2009 +0200
1.2 +++ b/docs/concepts.txt Sun Jun 14 01:18:05 2009 +0200
1.3 @@ -26,6 +26,13 @@
1.4 permitting the use of tables (described below). Module and class attributes
1.5 can also be finalised in this way in order to permit certain optimisations.
1.6
1.7 +An additional restriction required for the current implementation of tables
1.8 +(as described below) applies to class definitions: each class must be defined
1.9 +using a unique name; repeated definition of classes having the same name is
1.10 +thus not permitted. This restriction arises from the use of the "full name" of
1.11 +a class as a key to the object table, where the full name is a qualified path
1.12 +via the module hierarchy ending with the name of the class.
1.13 +
1.14 See rejected.txt for complicating mechanisms which could be applied to
1.15 mitigate the effects of these restrictions on optimisations.
1.16
2.1 --- a/micropython/__init__.py Fri Jun 12 22:03:56 2009 +0200
2.2 +++ b/micropython/__init__.py Sun Jun 14 01:18:05 2009 +0200
2.3 @@ -343,10 +343,21 @@
2.4
2.5 for obj in module.all_objects:
2.6 if isinstance(obj, micropython.inspect.Class):
2.7 - attributes = {obj.full_name() : obj}
2.8 +
2.9 + # Prevent ambiguous classes.
2.10 +
2.11 + full_name = obj.full_name()
2.12 + name = obj.name
2.13 +
2.14 + if module.has_key(name) and module[name].defines_ambiguous_class():
2.15 + raise TableGenerationError, "Class %r in module %r is ambiguously defined." % (name, module.full_name())
2.16 +
2.17 + # Define a table entry for the class.
2.18 +
2.19 + attributes = {full_name : obj}
2.20 attributes.update(obj.all_attributes())
2.21 attributes.update(obj.all_descendants())
2.22 - t.add(obj.full_name(), attributes)
2.23 + t.add(full_name, attributes)
2.24
2.25 return self.objtable
2.26
3.1 --- a/micropython/common.py Fri Jun 12 22:03:56 2009 +0200
3.2 +++ b/micropython/common.py Sun Jun 14 01:18:05 2009 +0200
3.3 @@ -44,6 +44,12 @@
3.4
3.5 pass
3.6
3.7 +class TableGenerationError(ProcessingError):
3.8 +
3.9 + "An error occurring when generating a lookup table."
3.10 +
3.11 + pass
3.12 +
3.13 class NodeProcessingError(ProcessingError):
3.14
3.15 "A processing error associated with a particular program node."
4.1 --- a/micropython/data.py Fri Jun 12 22:03:56 2009 +0200
4.2 +++ b/micropython/data.py Sun Jun 14 01:18:05 2009 +0200
4.3 @@ -361,6 +361,20 @@
4.4
4.5 return isinstance(self.parent, (Class, Module))
4.6
4.7 + def defines_ambiguous_class(self):
4.8 +
4.9 + "Return whether this attribute defines more than one class."
4.10 +
4.11 + if self.assignments > 1:
4.12 + have_class = 0
4.13 + for obj in self.get_values():
4.14 + if isinstance(obj, Class):
4.15 + if have_class:
4.16 + return 1
4.17 + have_class = 1
4.18 +
4.19 + return 0
4.20 +
4.21 def defined_within_hierarchy(self):
4.22
4.23 """
5.1 --- a/micropython/opt.py Fri Jun 12 22:03:56 2009 +0200
5.2 +++ b/micropython/opt.py Sun Jun 14 01:18:05 2009 +0200
5.3 @@ -152,7 +152,8 @@
5.4
5.5 "Return whether 'instruction' provides a constant input."
5.6
5.7 - return isinstance(instruction, LoadAddress) and instruction.attr.assignments == 1 or \
5.8 + return isinstance(instruction, LoadAddress) and instruction.attr.assignments == 1 and \
5.9 + isinstance(instruction.attr.get_value(), Constant) or \
5.10 isinstance(instruction, (LoadConst, LoadClass, LoadFunction))
5.11
5.12 def is_constant_target(self, instruction):
6.1 --- a/micropython/program.py Fri Jun 12 22:03:56 2009 +0200
6.2 +++ b/micropython/program.py Sun Jun 14 01:18:05 2009 +0200
6.3 @@ -61,6 +61,8 @@
6.4 def __nonzero__(self):
6.5 return self.truth_value
6.6
6.7 + __shortrepr__ = __repr__
6.8 +
6.9 # A representation of a context that is replaced upon certain assignment
6.10 # operations.
6.11
7.1 --- a/rsvp.py Fri Jun 12 22:03:56 2009 +0200
7.2 +++ b/rsvp.py Sun Jun 14 01:18:05 2009 +0200
7.3 @@ -291,10 +291,14 @@
7.4
7.5 attr_location = module.location + 1 + attr.position
7.6 context, ref = self.load(attr_location)
7.7 - content = self.load(ref + 1)
7.8 - print label, expected, content
7.9
7.10 - success = success and (int(expected) == content)
7.11 + if ref is not None:
7.12 + content = self.load(ref + 1)
7.13 + print label, expected, content
7.14 + success = success and (int(expected) == content)
7.15 + else:
7.16 + print label, expected, "missing"
7.17 + success = 0
7.18
7.19 return success
7.20 else:
7.21 @@ -901,9 +905,10 @@
7.22 def builtins_list_new(self):
7.23 frame = self.local_sp_stack[-1]
7.24
7.25 + # The first parameter should be empty.
7.26 # NOTE: Specific copying of tuples/lists.
7.27
7.28 - args_context, args = self.frame_stack[frame]
7.29 + args_context, args = self.frame_stack[frame + 1]
7.30 header = self.load(args)
7.31
7.32 list = self._MakeObject(header.size, self.list_instance)
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/tests/failure/instance_multiple_classes.py Sun Jun 14 01:18:05 2009 +0200
8.3 @@ -0,0 +1,13 @@
8.4 +#!/usr/bin/env python
8.5 +
8.6 +class C:
8.7 + x = 111
8.8 +
8.9 +class C:
8.10 + def __init__(self):
8.11 + self.x = 222
8.12 +
8.13 +c = C()
8.14 +result_222 = c.x
8.15 +
8.16 +# vim: tabstop=4 expandtab shiftwidth=4
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/tests/instance_initialisation.py Sun Jun 14 01:18:05 2009 +0200
10.3 @@ -0,0 +1,10 @@
10.4 +#!/usr/bin/env python
10.5 +
10.6 +class D:
10.7 + def __init__(self):
10.8 + self.x = 222
10.9 +
10.10 +d = D()
10.11 +result_222 = d.x
10.12 +
10.13 +# vim: tabstop=4 expandtab shiftwidth=4
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/tests/instance_uncertain.py Sun Jun 14 01:18:05 2009 +0200
12.3 @@ -0,0 +1,12 @@
12.4 +#!/usr/bin/env python
12.5 +
12.6 +class C:
12.7 + x = 111
12.8 +
12.9 +X = 1
12.10 +X = C
12.11 +x = X()
12.12 +
12.13 +result_111 = x.x
12.14 +
12.15 +# vim: tabstop=4 expandtab shiftwidth=4
13.1 --- a/tests/list.py Fri Jun 12 22:03:56 2009 +0200
13.2 +++ b/tests/list.py Sun Jun 14 01:18:05 2009 +0200
13.3 @@ -1,8 +1,12 @@
13.4 #!/usr/bin/env python
13.5
13.6 -[1, 2, 3]
13.7 a = [1, 2, 3]
13.8 -[1, [2, 3], 4, 5]
13.9 -b = list((9, 8, 7))
13.10 +b = [1, [2, 3], 4, 5]
13.11 +c = list((9, 8, 7))
13.12 +
13.13 +result_3 = a[2]
13.14 +result_4 = b[2]
13.15 +result_2 = b[1][0]
13.16 +result_9 = c[0]
13.17
13.18 # vim: tabstop=4 expandtab shiftwidth=4
14.1 --- a/tests/list_assign.py Fri Jun 12 22:03:56 2009 +0200
14.2 +++ b/tests/list_assign.py Sun Jun 14 01:18:05 2009 +0200
14.3 @@ -1,6 +1,9 @@
14.4 #!/usr/bin/env python
14.5
14.6 [a, b, c] = [1, 2, 3]
14.7 -[x, y, z] = list((9, 8, 7))
14.8 +
14.9 +result_1 = a
14.10 +result_2 = b
14.11 +result_3 = c
14.12
14.13 # vim: tabstop=4 expandtab shiftwidth=4
15.1 --- a/tests/list_assign2.py Fri Jun 12 22:03:56 2009 +0200
15.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
15.3 @@ -1,5 +0,0 @@
15.4 -#!/usr/bin/env python
15.5 -
15.6 -[d, [e, f], g] = [4, [5, 6], 7]
15.7 -
15.8 -# vim: tabstop=4 expandtab shiftwidth=4
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
16.2 +++ b/tests/list_assign_constructor.py Sun Jun 14 01:18:05 2009 +0200
16.3 @@ -0,0 +1,9 @@
16.4 +#!/usr/bin/env python
16.5 +
16.6 +[x, y, z] = list((9, 8, 7))
16.7 +
16.8 +result_9 = x
16.9 +result_8 = y
16.10 +result_7 = z
16.11 +
16.12 +# vim: tabstop=4 expandtab shiftwidth=4
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
17.2 +++ b/tests/list_assign_nested.py Sun Jun 14 01:18:05 2009 +0200
17.3 @@ -0,0 +1,10 @@
17.4 +#!/usr/bin/env python
17.5 +
17.6 +[d, [e, f], g] = [4, [5, 6], 7]
17.7 +
17.8 +result_4 = d
17.9 +result_5 = e
17.10 +result_6 = f
17.11 +result_7 = g
17.12 +
17.13 +# vim: tabstop=4 expandtab shiftwidth=4
18.1 --- a/tests/logical.py Fri Jun 12 22:03:56 2009 +0200
18.2 +++ b/tests/logical.py Sun Jun 14 01:18:05 2009 +0200
18.3 @@ -2,7 +2,7 @@
18.4
18.5 a = 1
18.6 b = 0
18.7 -c = a and b
18.8 -d = a or b
18.9 +result_0 = a and b
18.10 +result_1 = a or b
18.11
18.12 # vim: tabstop=4 expandtab shiftwidth=4