1.1 --- a/micropython/ast.py Sun May 24 18:12:07 2009 +0200
1.2 +++ b/micropython/ast.py Sun May 24 19:03:03 2009 +0200
1.3 @@ -37,11 +37,11 @@
1.4
1.5 attribute_load_instructions = (
1.6 LoadAddress, LoadAddressContext, LoadAddressContextCond,
1.7 - LoadAttr, LoadAttrIndex, LoadAttrIndexContext, LoadAttrIndexContextCond
1.8 + LoadAttr, LoadAttrIndex, LoadAttrIndexContextCond
1.9 )
1.10 attribute_store_instructions = (
1.11 None, None, None,
1.12 - StoreAttr, StoreAttrIndex, None, None
1.13 + StoreAttr, StoreAttrIndex, None
1.14 )
1.15
1.16 # Name access instructions, for use with the appropriate handlers.
2.1 --- a/micropython/opt.py Sun May 24 18:12:07 2009 +0200
2.2 +++ b/micropython/opt.py Sun May 24 19:03:03 2009 +0200
2.3 @@ -149,7 +149,7 @@
2.4 "Return whether 'instruction' provides a constant input."
2.5
2.6 return isinstance(instruction, LoadAddress) and instruction.attr.assignments == 1 or \
2.7 - isinstance(instruction, LoadConst)
2.8 + isinstance(instruction, (LoadConst, LoadFunction))
2.9
2.10 def is_constant_target(self, instruction):
2.11
2.12 @@ -169,7 +169,7 @@
2.13 a load operation from a CPU register or special memory location.
2.14 """
2.15
2.16 - return isinstance(instruction, (LoadConst, LoadName, LoadTemp, LoadResult, LoadException, LoadAddress))
2.17 + return isinstance(instruction, (LoadConst, LoadFunction, LoadName, LoadTemp, LoadResult, LoadException, LoadAddress))
2.18
2.19 def is_simple_input_user(self, instruction):
2.20
2.21 @@ -182,7 +182,7 @@
2.22 return isinstance(instruction, (
2.23 StoreTemp, StoreFrame, StoreResult, StoreException, # as the value being stored
2.24 LoadAddressContext, LoadAddressContextCond, # as the object being referenced
2.25 - LoadAttr, LoadAttrIndex, LoadAttrIndexContext, # as the object being referenced
2.26 + LoadAttr, LoadAttrIndex, # LoadAttrIndexContext, # as the object being referenced
2.27 LoadAttrIndexContextCond, # as the object being referenced
2.28 StoreAttr, StoreAttrIndex, StoreCallable, # as the object being referenced
2.29 StoreFrameIndex, # as the object being referenced
2.30 @@ -270,7 +270,7 @@
2.31 # LoadResult cannot be relied upon in general since the result register
2.32 # could be updated since first being referenced.
2.33
2.34 - return isinstance(self.active_value, (LoadName, LoadTemp, LoadAddress, LoadConst)) or \
2.35 + return isinstance(self.active_value, (LoadName, LoadTemp, LoadAddress, LoadConst, LoadFunction)) or \
2.36 isinstance(self.active_value, LoadResult) and self.active_value is self.active or \
2.37 isinstance(self.active_value, LoadException) and self.active_value is self.active
2.38
3.1 --- a/micropython/rsvp.py Sun May 24 18:12:07 2009 +0200
3.2 +++ b/micropython/rsvp.py Sun May 24 19:03:03 2009 +0200
3.3 @@ -181,9 +181,7 @@
3.4 class StoreAttr(AR): "Store the source value into the given attribute of the object referenced by the current value."
3.5 class LoadAttrIndex(Immediate): "Load into the current value the attribute of the current value with the given index."
3.6 class StoreAttrIndex(Immediate): "Store the source value into the attribute of the current value with the given index."
3.7 -class LoadAttrIndexContext(Immediate):
3.8 - """Load into the current value the attribute of the current value with the given index, making the
3.9 - current value the context."""
3.10 +##### LoadAttrIndexContext not defined.
3.11 class LoadAttrIndexContextCond(Immediate):
3.12 """Load into the current value the attribute of the current value with the given index, only making the
3.13 current value the context if the attribute is compatible."""
3.14 @@ -243,11 +241,12 @@
3.15 class InvertBoolean(Instruction): "Invert the boolean status."
3.16
3.17 # Instructions which affect the current value.
3.18 +# LoadAttrIndexContext not defined.
3.19
3.20 current_value_instructions = (
3.21 - LoadConst, LoadName, LoadTemp,
3.22 + LoadConst, LoadFunction, LoadName, LoadTemp,
3.23 LoadAddress, LoadAddressContext, LoadAddressContextCond,
3.24 - LoadAttr, LoadAttrIndex, LoadAttrIndexContext, LoadAttrIndexContextCond,
3.25 + LoadAttr, LoadAttrIndex, LoadAttrIndexContextCond,
3.26 LoadCallable, LoadContext, LoadResult,
3.27 LoadException, MakeObject
3.28 )
4.1 --- a/micropython/trans.py Sun May 24 18:12:07 2009 +0200
4.2 +++ b/micropython/trans.py Sun May 24 19:03:03 2009 +0200
4.3 @@ -318,8 +318,7 @@
4.4 """
4.5
4.6 AddressInstruction, AddressContextInstruction, AddressContextCondInstruction, \
4.7 - AttrInstruction, AttrIndexInstruction, AttrIndexContextInstruction, \
4.8 - AttrIndexContextCondInstruction = classes
4.9 + AttrInstruction, AttrIndexInstruction, AttrIndexContextCondInstruction = classes
4.10
4.11 # Where the last operation (defining the attribute owner) yields a
4.12 # constant...
5.1 --- a/rsvp.py Sun May 24 18:12:07 2009 +0200
5.2 +++ b/rsvp.py Sun May 24 19:03:03 2009 +0200
5.3 @@ -429,17 +429,7 @@
5.4 self.exception = self._MakeObject(2, self.attr_error_instance)
5.5 return self.RaiseException()
5.6
5.7 - def LoadAttrIndexContext(self):
5.8 - context, ref = self.value
5.9 - data = self.load(ref)
5.10 - element = self.objlist[data.classcode + self.operand]
5.11 - attr_index, class_attr, offset = element
5.12 - if attr_index == self.operand:
5.13 - loaded_context, loaded_ref = self.load(offset) # offset is address of class attribute
5.14 - self.value = ref, loaded_ref
5.15 - else:
5.16 - self.exception = self._MakeObject(2, self.attr_error_instance)
5.17 - return self.RaiseException()
5.18 + # LoadAttrIndexContext not defined.
5.19
5.20 def LoadAttrIndexContextCond(self):
5.21 context, ref = self.value
6.1 --- a/tests/attributes2.py Sun May 24 18:12:07 2009 +0200
6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
6.3 @@ -1,31 +0,0 @@
6.4 -#!/usr/bin/env python
6.5 -
6.6 -def e(x): pass
6.7 -
6.8 -class C:
6.9 - e = e
6.10 -
6.11 - def test(self):
6.12 - self.e()
6.13 -
6.14 -class D:
6.15 - e = C.e
6.16 -
6.17 - def test(self):
6.18 - self.e(1) # TypeError: unbound C.e needs C instance, not int
6.19 -
6.20 -class E(C):
6.21 - # e = C.e (via inheritance)
6.22 -
6.23 - def test(self):
6.24 - self.e()
6.25 -
6.26 -c = C()
6.27 -d = D()
6.28 -e = E()
6.29 -
6.30 -p = c.e # bound C.e
6.31 -q = d.e # unbound C.e
6.32 -r = e.e # bound E.e
6.33 -
6.34 -# vim: tabstop=4 expandtab shiftwidth=4
7.1 --- a/tests/attributes3.py Sun May 24 18:12:07 2009 +0200
7.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
7.3 @@ -1,41 +0,0 @@
7.4 -#!/usr/bin/env python
7.5 -
7.6 -class C:
7.7 - def g(self):
7.8 - return self.f # C.f with context self
7.9 - def f(self): pass
7.10 -
7.11 - def test(self):
7.12 - self.f()
7.13 - self.g()
7.14 -
7.15 -class D:
7.16 - f = C.f
7.17 - def g(self):
7.18 - return self.f # D.f with context preserved
7.19 -
7.20 - def test(self):
7.21 - self.f(2)
7.22 - self.g()
7.23 -
7.24 -class E(C):
7.25 - def g(self):
7.26 - return self.f # C.f with context self
7.27 -
7.28 - def test(self):
7.29 - self.f()
7.30 - self.g()
7.31 -
7.32 -C.f
7.33 -D.f
7.34 -E.f
7.35 -
7.36 -c = C()
7.37 -d = D()
7.38 -e = E()
7.39 -
7.40 -x = c.f # bound C.f == c.g()
7.41 -y = d.f # unbound C.f == d.g()
7.42 -z = e.f # bound E.f == e.g()
7.43 -
7.44 -# vim: tabstop=4 expandtab shiftwidth=4
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/tests/attributes_class_bind_function_inherited_internal.py Sun May 24 19:03:03 2009 +0200
8.3 @@ -0,0 +1,18 @@
8.4 +#!/usr/bin/env python
8.5 +
8.6 +def e(self, x):
8.7 + return x
8.8 +
8.9 +class C:
8.10 + e = e
8.11 +
8.12 +class E(C):
8.13 + # e = C.e (via inheritance)
8.14 +
8.15 + def test(self, x):
8.16 + return self.e(x)
8.17 +
8.18 +e = E()
8.19 +result = e.e(321)
8.20 +
8.21 +# vim: tabstop=4 expandtab shiftwidth=4
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/tests/attributes_class_bind_function_inherited_via_self.py Sun May 24 19:03:03 2009 +0200
9.3 @@ -0,0 +1,19 @@
9.4 +#!/usr/bin/env python
9.5 +
9.6 +def e(self, x):
9.7 + return x
9.8 +
9.9 +class C:
9.10 + e = e
9.11 +
9.12 +class E(C):
9.13 + # e = C.e (via inheritance)
9.14 +
9.15 + def f(self):
9.16 + return self.e
9.17 +
9.18 +e = E()
9.19 +r = e.f() # bound E.e
9.20 +result = r(321)
9.21 +
9.22 +# vim: tabstop=4 expandtab shiftwidth=4
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/tests/attributes_class_bind_function_internal.py Sun May 24 19:03:03 2009 +0200
10.3 @@ -0,0 +1,15 @@
10.4 +#!/usr/bin/env python
10.5 +
10.6 +def e(self, x):
10.7 + return x
10.8 +
10.9 +class C:
10.10 + e = e
10.11 +
10.12 + def test(self, x):
10.13 + return self.e(x)
10.14 +
10.15 +c = C()
10.16 +result = c.test(321)
10.17 +
10.18 +# vim: tabstop=4 expandtab shiftwidth=4
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/tests/attributes_class_bind_function_via_self.py Sun May 24 19:03:03 2009 +0200
11.3 @@ -0,0 +1,16 @@
11.4 +#!/usr/bin/env python
11.5 +
11.6 +def e(self, x):
11.7 + return x
11.8 +
11.9 +class C:
11.10 + e = e
11.11 +
11.12 + def f(self):
11.13 + return self.e
11.14 +
11.15 +c = C()
11.16 +p = c.f() # bound C.e
11.17 +result = p(321)
11.18 +
11.19 +# vim: tabstop=4 expandtab shiftwidth=4