1.1 --- a/docs/concepts.txt Mon May 18 23:56:12 2009 +0200 1.2 +++ b/docs/concepts.txt Fri May 22 00:17:35 2009 +0200 1.3 @@ -243,7 +243,7 @@ 1.4 Size 1.5 ---- 1.6 1.7 -Used to indicate the number of attributes associated with an object. 1.8 +Used to indicate the size of an object including attributes. 1.9 1.10 Attributes 1.11 ---------- 1.12 @@ -280,7 +280,7 @@ 1.13 Module m: 1.14 1.15 0 1 2 3 4 5 6 7 1.16 - classcode attrcode (unused) module type attribute ... 1.17 + classcode attrcode (unused) (unused) (unused) module type attribute ... 1.18 for m for m reference (global) 1.19 reference 1.20
2.1 --- a/micropython/__init__.py Mon May 18 23:56:12 2009 +0200 2.2 +++ b/micropython/__init__.py Fri May 22 00:17:35 2009 +0200 2.3 @@ -513,6 +513,16 @@ 2.4 2.5 "Make and return a constant for the given 'value'." 2.6 2.7 + # Ensure the presence of the constant's type. 2.8 + 2.9 + name = value.__class__.__name__ 2.10 + if self.modules.has_key("__builtins__"): 2.11 + attr = self.modules["__builtins__"].get(name) 2.12 + if attr is not None: 2.13 + attr.set_referenced() 2.14 + 2.15 + # Make a constant object and return it. 2.16 + 2.17 const = micropython.data.Const(value) 2.18 if not self.constant_values.has_key(const): 2.19 self.constant_values[const] = const
3.1 --- a/micropython/ast.py Mon May 18 23:56:12 2009 +0200 3.2 +++ b/micropython/ast.py Fri May 22 00:17:35 2009 +0200 3.3 @@ -608,7 +608,8 @@ 3.4 ndefaults = len(fn.defaults) 3.5 3.6 self.new_op(CheckFrame((nparams, ndefaults, fn.has_star))) 3.7 - self.new_op(FillDefaults((nparams, ndefaults, fn))) 3.8 + if ndefaults > 0: 3.9 + self.new_op(FillDefaults((nparams, ndefaults, fn))) 3.10 3.11 # Produce the body. 3.12 3.13 @@ -677,7 +678,8 @@ 3.14 ndefaults = len(fn.defaults) 3.15 3.16 self.new_op(CheckFrame((nparams, ndefaults, fn.has_star))) 3.17 - self.new_op(FillDefaults((nparams, ndefaults, fn))) 3.18 + if ndefaults > 0: 3.19 + self.new_op(FillDefaults((nparams, ndefaults, fn))) 3.20 3.21 # Produce the body. 3.22
4.1 --- a/micropython/data.py Mon May 18 23:56:12 2009 +0200 4.2 +++ b/micropython/data.py Fri May 22 00:17:35 2009 +0200 4.3 @@ -461,7 +461,6 @@ 4.4 objtable.as_list().get_code(self.value_type_name()), 4.5 objtable.get_index(self.value_type_name()), # is instance 4.6 None, 4.7 - None, 4.8 self.value_type_name(), 4.9 1 # size 4.10 ) 4.11 @@ -578,11 +577,6 @@ 4.12 classcode, 4.13 attrcode, # is instance 4.14 call_method_code_location, 4.15 - ( 4.16 - call_method_value and len(call_method_value.positional_names), 4.17 - call_method_value and len(call_method_value.defaults) 4.18 - # NOTE: Add * parameter availability. 4.19 - ), 4.20 self.full_name(), 4.21 len(self.instance_attributes()) + 1, # size 4.22 call_method_funccode # funccode 4.23 @@ -594,11 +588,6 @@ 4.24 classcode, 4.25 None, # is not instance 4.26 instantiator_code_location, 4.27 - ( 4.28 - len(self.get_instantiator().positional_names), 4.29 - len(self.get_instantiator().defaults) 4.30 - # NOTE: Add * parameter availability. 4.31 - ), 4.32 self.full_name(), 4.33 len(self.class_attributes()) + 1, # size 4.34 instantiator_funccode # funccode 4.35 @@ -980,11 +969,6 @@ 4.36 objtable.as_list().get_code("__builtins__.function"), 4.37 objtable.get_index("__builtins__.function"), # is instance 4.38 self.code_location, 4.39 - ( 4.40 - len(self.positional_names), 4.41 - len(self.defaults) 4.42 - # NOTE: Add * parameter availability. 4.43 - ), 4.44 "__builtins__.function", 4.45 len(self.defaults) + 1, # size 4.46 paramtable.as_list().get_code(self.full_name()) # funccode 4.47 @@ -1195,7 +1179,6 @@ 4.48 objtable.as_list().get_code(self.full_name()), 4.49 None, # NOTE: module name not used as an attribute, but should be instance 4.50 None, 4.51 - None, 4.52 self.full_name(), 4.53 len(self.module_attributes()) + 1 # size 4.54 )
5.1 --- a/micropython/inspect.py Mon May 18 23:56:12 2009 +0200 5.2 +++ b/micropython/inspect.py Fri May 22 00:17:35 2009 +0200 5.3 @@ -516,13 +516,6 @@ 5.4 5.5 def visitConst(self, node): 5.6 5.7 - # Accounting. 5.8 - 5.9 - name = node.value.__class__.__name__ 5.10 - if self.builtins is not None and self.builtins.has_key(name): 5.11 - attr = self.builtins[name] 5.12 - attr.set_referenced() 5.13 - 5.14 # Register the constant, if necessary, returning the resulting object. 5.15 5.16 return self.importer.make_constant(node.value)
6.1 --- a/micropython/program.py Mon May 18 23:56:12 2009 +0200 6.2 +++ b/micropython/program.py Fri May 22 00:17:35 2009 +0200 6.3 @@ -25,21 +25,20 @@ 6.4 6.5 "A representation of a raw program data object." 6.6 6.7 - def __init__(self, classcode, attrcode, codeaddr, codedetails, name, size, funccode=None): 6.8 + def __init__(self, classcode, attrcode, codeaddr, name, size, funccode=None): 6.9 self.classcode = classcode 6.10 self.attrcode = attrcode 6.11 self.codeaddr = codeaddr 6.12 - self.codedetails = codedetails 6.13 self.name = name 6.14 self.size = size 6.15 self.funccode = funccode 6.16 6.17 def with_size(self, size): 6.18 - return DataObject(self.classcode, self.attrcode, self.codeaddr, self.codedetails, self.name, size, self.funccode) 6.19 + return DataObject(self.classcode, self.attrcode, self.codeaddr, self.name, size, self.funccode) 6.20 6.21 def __repr__(self): 6.22 return "%r # %s" % ( 6.23 - (self.classcode, self.attrcode, self.codeaddr, self.codedetails, self.funccode, self.size), self.name 6.24 + (self.classcode, self.attrcode, self.codeaddr, self.funccode, self.size), self.name 6.25 ) 6.26 6.27 # vim: tabstop=4 expandtab shiftwidth=4
7.1 --- a/rsvp.py Mon May 18 23:56:12 2009 +0200 7.2 +++ b/rsvp.py Fri May 22 00:17:35 2009 +0200 7.3 @@ -474,7 +474,7 @@ 7.4 def LoadCallable(self): 7.5 context, ref = self.value 7.6 data = self.load(ref) 7.7 - self.callable = data.codeaddr, data.codedetails 7.8 + self.callable = data.codeaddr 7.9 7.10 def StoreCallable(self): 7.11 context, ref = self.value 7.12 @@ -499,6 +499,9 @@ 7.13 nlocals = len(self.frame_stack[frame:]) 7.14 7.15 # Support sliding of the frame to exclude any inappropriate context. 7.16 + # Since a context will always be present when this instruction is being 7.17 + # used (whether or not it is desired), we can always test the nature of 7.18 + # the context. 7.19 7.20 if context_ref is None: 7.21 self.local_sp_stack[-1] += 1 7.22 @@ -509,6 +512,8 @@ 7.23 self.local_sp_stack[-1] += 1 7.24 nlocals -= 1 7.25 7.26 + # NOTE: Should check the context here. 7.27 + 7.28 # Test the frame size. 7.29 # NOTE: Raise a proper exception here. 7.30 7.31 @@ -547,7 +552,7 @@ 7.32 self.status = self._CheckInstance(ref, target_context) 7.33 7.34 def JumpWithFrame(self): 7.35 - codeaddr, codedetails = self.callable 7.36 + codeaddr = self.callable 7.37 self.local_sp_stack.append(self.invocation_sp_stack[-1]) # adopt the invocation frame 7.38 return self.jump(codeaddr, self.pc + 1) # return to the instruction after this one 7.39
8.1 --- a/tests/attributes.py Mon May 18 23:56:12 2009 +0200 8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 8.3 @@ -1,19 +0,0 @@ 8.4 -#!/usr/bin/env python 8.5 - 8.6 -class C: 8.7 - clsattr = 123 8.8 - clsattr2 = 456 8.9 - 8.10 - def __init__(self, value): 8.11 - self.instattr = value 8.12 - self.clsattr 8.13 - 8.14 - def update(self, value): 8.15 - self.attr = value 8.16 - C.clsattr 8.17 - 8.18 -a = C.clsattr 8.19 -c = C(789) 8.20 -c.update(987) 8.21 - 8.22 -# vim: tabstop=4 expandtab shiftwidth=4
9.1 --- a/tests/attributes1.py Mon May 18 23:56:12 2009 +0200 9.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 9.3 @@ -1,18 +0,0 @@ 9.4 -#!/usr/bin/env python 9.5 - 9.6 -class C: 9.7 - clsattr = 123 9.8 - 9.9 - def __init__(self, value): 9.10 - self.instattr = value 9.11 - self.clsattr 9.12 - 9.13 - def update(self, value): 9.14 - self.attr = value 9.15 - C.clsattr 9.16 - 9.17 -C 9.18 -C.clsattr 9.19 -C(456).update(789) 9.20 - 9.21 -# vim: tabstop=4 expandtab shiftwidth=4
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/tests/attributes_class.py Fri May 22 00:17:35 2009 +0200 10.3 @@ -0,0 +1,10 @@ 10.4 +#!/usr/bin/env python 10.5 + 10.6 +class C: 10.7 + clsattr = 123 10.8 + clsattr2 = 456 10.9 + 10.10 +a = C.clsattr 10.11 +b = C.clsattr2 10.12 + 10.13 +# 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.py Fri May 22 00:17:35 2009 +0200 11.3 @@ -0,0 +1,13 @@ 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 +c = C() 11.13 +p = c.e # bound C.e 11.14 +result = p(321) 11.15 + 11.16 +# vim: tabstop=4 expandtab shiftwidth=4
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/tests/attributes_class_bind_function_inherited.py Fri May 22 00:17:35 2009 +0200 12.3 @@ -0,0 +1,17 @@ 12.4 +#!/usr/bin/env python 12.5 + 12.6 +def e(self, x): 12.7 + return x 12.8 + 12.9 +class C: 12.10 + e = e 12.11 + 12.12 +class E(C): 12.13 + # e = C.e (via inheritance) 12.14 + pass 12.15 + 12.16 +e = E() 12.17 +r = e.e # bound E.e 12.18 +result = r(321) 12.19 + 12.20 +# vim: tabstop=4 expandtab shiftwidth=4
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/tests/attributes_class_bind_function_unbound.py Fri May 22 00:17:35 2009 +0200 13.3 @@ -0,0 +1,16 @@ 13.4 +#!/usr/bin/env python 13.5 + 13.6 +def e(self, x): 13.7 + return x 13.8 + 13.9 +class C: 13.10 + e = e 13.11 + 13.12 +class D: 13.13 + e = C.e 13.14 + 13.15 +d = D() 13.16 +q = d.e # unbound C.e 13.17 +result = q(321) 13.18 + 13.19 +# vim: tabstop=4 expandtab shiftwidth=4
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/tests/attributes_class_in_method.py Fri May 22 00:17:35 2009 +0200 14.3 @@ -0,0 +1,17 @@ 14.4 +#!/usr/bin/env python 14.5 + 14.6 +class C: 14.7 + clsattr = 123 14.8 + clsattr2 = 456 14.9 + 14.10 + def f(self): 14.11 + return C.clsattr 14.12 + 14.13 + def g(self): 14.14 + return self.clsattr2 14.15 + 14.16 +c = C() 14.17 +a = c.f() 14.18 +b = c.g() 14.19 + 14.20 +# vim: tabstop=4 expandtab shiftwidth=4
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/tests/attributes_instance.py Fri May 22 00:17:35 2009 +0200 15.3 @@ -0,0 +1,15 @@ 15.4 +#!/usr/bin/env python 15.5 + 15.6 +class C: 15.7 + def __init__(self, value): 15.8 + self.instattr = value 15.9 + 15.10 + def update(self, value): 15.11 + self.attr = value 15.12 + 15.13 +c = C(789) 15.14 +c.update(987) 15.15 +a = c.instattr 15.16 +b = c.attr 15.17 + 15.18 +# vim: tabstop=4 expandtab shiftwidth=4
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/tests/attributes_shadowing.py Fri May 22 00:17:35 2009 +0200 16.3 @@ -0,0 +1,12 @@ 16.4 +#!/usr/bin/env python 16.5 + 16.6 +class C: 16.7 + clsattr = 123 16.8 + 16.9 + def __init__(self, value=None): 16.10 + self.instattr = value is None and self.clsattr or value 16.11 + 16.12 +c1 = C(789) 16.13 +c2 = C() 16.14 + 16.15 +# vim: tabstop=4 expandtab shiftwidth=4
17.1 --- a/tests/failure/attributes.py Mon May 18 23:56:12 2009 +0200 17.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 17.3 @@ -1,18 +0,0 @@ 17.4 -#!/usr/bin/env python 17.5 - 17.6 -class C: 17.7 - clsattr = 123 17.8 - 17.9 - def __init__(self, value): 17.10 - self.instattr = value 17.11 - self.clsattr 17.12 - 17.13 - def update(self, value): 17.14 - self.attr = value 17.15 - self.clsattr = value 17.16 - C.clsattr = value 17.17 - 17.18 -C 17.19 -C.clsattr 17.20 - 17.21 -# vim: tabstop=4 expandtab shiftwidth=4
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 18.2 +++ b/tests/failure/attributes_collision.py Fri May 22 00:17:35 2009 +0200 18.3 @@ -0,0 +1,13 @@ 18.4 +#!/usr/bin/env python 18.5 + 18.6 +class C: 18.7 + clsattr = 123 18.8 + 18.9 + def update(self, value): 18.10 + self.attr = value 18.11 + self.clsattr = value 18.12 + 18.13 +c = C() 18.14 +c.update(456) 18.15 + 18.16 +# vim: tabstop=4 expandtab shiftwidth=4
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 19.2 +++ b/tests/failure/attributes_set_class.py Fri May 22 00:17:35 2009 +0200 19.3 @@ -0,0 +1,13 @@ 19.4 +#!/usr/bin/env python 19.5 + 19.6 +class C: 19.7 + clsattr = 123 19.8 + 19.9 + def update(self, value): 19.10 + self.attr = value 19.11 + C.clsattr = value 19.12 + 19.13 +c = C() 19.14 +c.update(456) 19.15 + 19.16 +# vim: tabstop=4 expandtab shiftwidth=4