# HG changeset patch # User Paul Boddie # Date 1242944255 -7200 # Node ID b58aae0af656187bf2c220b683e466577ea26382 # Parent b8550c04e8074a1af6f3f487e0f42a76c0637409 Removed the codedetails attribute from DataObject instances and from the structure descriptions. Added notes about argument checking for CheckFrame since the context needs to be verified where it is required. Made sure that the bool class is available since True and False are always available and their methods must also be accessible via the object table. Split various tests into separate programs with improved labelling. diff -r b8550c04e807 -r b58aae0af656 docs/concepts.txt --- a/docs/concepts.txt Mon May 18 23:56:12 2009 +0200 +++ b/docs/concepts.txt Fri May 22 00:17:35 2009 +0200 @@ -243,7 +243,7 @@ Size ---- -Used to indicate the number of attributes associated with an object. +Used to indicate the size of an object including attributes. Attributes ---------- @@ -280,7 +280,7 @@ Module m: 0 1 2 3 4 5 6 7 - classcode attrcode (unused) module type attribute ... + classcode attrcode (unused) (unused) (unused) module type attribute ... for m for m reference (global) reference diff -r b8550c04e807 -r b58aae0af656 micropython/__init__.py --- a/micropython/__init__.py Mon May 18 23:56:12 2009 +0200 +++ b/micropython/__init__.py Fri May 22 00:17:35 2009 +0200 @@ -513,6 +513,16 @@ "Make and return a constant for the given 'value'." + # Ensure the presence of the constant's type. + + name = value.__class__.__name__ + if self.modules.has_key("__builtins__"): + attr = self.modules["__builtins__"].get(name) + if attr is not None: + attr.set_referenced() + + # Make a constant object and return it. + const = micropython.data.Const(value) if not self.constant_values.has_key(const): self.constant_values[const] = const diff -r b8550c04e807 -r b58aae0af656 micropython/ast.py --- a/micropython/ast.py Mon May 18 23:56:12 2009 +0200 +++ b/micropython/ast.py Fri May 22 00:17:35 2009 +0200 @@ -608,7 +608,8 @@ ndefaults = len(fn.defaults) self.new_op(CheckFrame((nparams, ndefaults, fn.has_star))) - self.new_op(FillDefaults((nparams, ndefaults, fn))) + if ndefaults > 0: + self.new_op(FillDefaults((nparams, ndefaults, fn))) # Produce the body. @@ -677,7 +678,8 @@ ndefaults = len(fn.defaults) self.new_op(CheckFrame((nparams, ndefaults, fn.has_star))) - self.new_op(FillDefaults((nparams, ndefaults, fn))) + if ndefaults > 0: + self.new_op(FillDefaults((nparams, ndefaults, fn))) # Produce the body. diff -r b8550c04e807 -r b58aae0af656 micropython/data.py --- a/micropython/data.py Mon May 18 23:56:12 2009 +0200 +++ b/micropython/data.py Fri May 22 00:17:35 2009 +0200 @@ -461,7 +461,6 @@ objtable.as_list().get_code(self.value_type_name()), objtable.get_index(self.value_type_name()), # is instance None, - None, self.value_type_name(), 1 # size ) @@ -578,11 +577,6 @@ classcode, attrcode, # is instance call_method_code_location, - ( - call_method_value and len(call_method_value.positional_names), - call_method_value and len(call_method_value.defaults) - # NOTE: Add * parameter availability. - ), self.full_name(), len(self.instance_attributes()) + 1, # size call_method_funccode # funccode @@ -594,11 +588,6 @@ classcode, None, # is not instance instantiator_code_location, - ( - len(self.get_instantiator().positional_names), - len(self.get_instantiator().defaults) - # NOTE: Add * parameter availability. - ), self.full_name(), len(self.class_attributes()) + 1, # size instantiator_funccode # funccode @@ -980,11 +969,6 @@ objtable.as_list().get_code("__builtins__.function"), objtable.get_index("__builtins__.function"), # is instance self.code_location, - ( - len(self.positional_names), - len(self.defaults) - # NOTE: Add * parameter availability. - ), "__builtins__.function", len(self.defaults) + 1, # size paramtable.as_list().get_code(self.full_name()) # funccode @@ -1195,7 +1179,6 @@ objtable.as_list().get_code(self.full_name()), None, # NOTE: module name not used as an attribute, but should be instance None, - None, self.full_name(), len(self.module_attributes()) + 1 # size ) diff -r b8550c04e807 -r b58aae0af656 micropython/inspect.py --- a/micropython/inspect.py Mon May 18 23:56:12 2009 +0200 +++ b/micropython/inspect.py Fri May 22 00:17:35 2009 +0200 @@ -516,13 +516,6 @@ def visitConst(self, node): - # Accounting. - - name = node.value.__class__.__name__ - if self.builtins is not None and self.builtins.has_key(name): - attr = self.builtins[name] - attr.set_referenced() - # Register the constant, if necessary, returning the resulting object. return self.importer.make_constant(node.value) diff -r b8550c04e807 -r b58aae0af656 micropython/program.py --- a/micropython/program.py Mon May 18 23:56:12 2009 +0200 +++ b/micropython/program.py Fri May 22 00:17:35 2009 +0200 @@ -25,21 +25,20 @@ "A representation of a raw program data object." - def __init__(self, classcode, attrcode, codeaddr, codedetails, name, size, funccode=None): + def __init__(self, classcode, attrcode, codeaddr, name, size, funccode=None): self.classcode = classcode self.attrcode = attrcode self.codeaddr = codeaddr - self.codedetails = codedetails self.name = name self.size = size self.funccode = funccode def with_size(self, size): - return DataObject(self.classcode, self.attrcode, self.codeaddr, self.codedetails, self.name, size, self.funccode) + return DataObject(self.classcode, self.attrcode, self.codeaddr, self.name, size, self.funccode) def __repr__(self): return "%r # %s" % ( - (self.classcode, self.attrcode, self.codeaddr, self.codedetails, self.funccode, self.size), self.name + (self.classcode, self.attrcode, self.codeaddr, self.funccode, self.size), self.name ) # vim: tabstop=4 expandtab shiftwidth=4 diff -r b8550c04e807 -r b58aae0af656 rsvp.py --- a/rsvp.py Mon May 18 23:56:12 2009 +0200 +++ b/rsvp.py Fri May 22 00:17:35 2009 +0200 @@ -474,7 +474,7 @@ def LoadCallable(self): context, ref = self.value data = self.load(ref) - self.callable = data.codeaddr, data.codedetails + self.callable = data.codeaddr def StoreCallable(self): context, ref = self.value @@ -499,6 +499,9 @@ nlocals = len(self.frame_stack[frame:]) # Support sliding of the frame to exclude any inappropriate context. + # Since a context will always be present when this instruction is being + # used (whether or not it is desired), we can always test the nature of + # the context. if context_ref is None: self.local_sp_stack[-1] += 1 @@ -509,6 +512,8 @@ self.local_sp_stack[-1] += 1 nlocals -= 1 + # NOTE: Should check the context here. + # Test the frame size. # NOTE: Raise a proper exception here. @@ -547,7 +552,7 @@ self.status = self._CheckInstance(ref, target_context) def JumpWithFrame(self): - codeaddr, codedetails = self.callable + codeaddr = self.callable self.local_sp_stack.append(self.invocation_sp_stack[-1]) # adopt the invocation frame return self.jump(codeaddr, self.pc + 1) # return to the instruction after this one diff -r b8550c04e807 -r b58aae0af656 tests/attributes.py --- a/tests/attributes.py Mon May 18 23:56:12 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -#!/usr/bin/env python - -class C: - clsattr = 123 - clsattr2 = 456 - - def __init__(self, value): - self.instattr = value - self.clsattr - - def update(self, value): - self.attr = value - C.clsattr - -a = C.clsattr -c = C(789) -c.update(987) - -# vim: tabstop=4 expandtab shiftwidth=4 diff -r b8550c04e807 -r b58aae0af656 tests/attributes1.py --- a/tests/attributes1.py Mon May 18 23:56:12 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -#!/usr/bin/env python - -class C: - clsattr = 123 - - def __init__(self, value): - self.instattr = value - self.clsattr - - def update(self, value): - self.attr = value - C.clsattr - -C -C.clsattr -C(456).update(789) - -# vim: tabstop=4 expandtab shiftwidth=4 diff -r b8550c04e807 -r b58aae0af656 tests/attributes_class.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/attributes_class.py Fri May 22 00:17:35 2009 +0200 @@ -0,0 +1,10 @@ +#!/usr/bin/env python + +class C: + clsattr = 123 + clsattr2 = 456 + +a = C.clsattr +b = C.clsattr2 + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r b8550c04e807 -r b58aae0af656 tests/attributes_class_bind_function.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/attributes_class_bind_function.py Fri May 22 00:17:35 2009 +0200 @@ -0,0 +1,13 @@ +#!/usr/bin/env python + +def e(self, x): + return x + +class C: + e = e + +c = C() +p = c.e # bound C.e +result = p(321) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r b8550c04e807 -r b58aae0af656 tests/attributes_class_bind_function_inherited.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/attributes_class_bind_function_inherited.py Fri May 22 00:17:35 2009 +0200 @@ -0,0 +1,17 @@ +#!/usr/bin/env python + +def e(self, x): + return x + +class C: + e = e + +class E(C): + # e = C.e (via inheritance) + pass + +e = E() +r = e.e # bound E.e +result = r(321) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r b8550c04e807 -r b58aae0af656 tests/attributes_class_bind_function_unbound.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/attributes_class_bind_function_unbound.py Fri May 22 00:17:35 2009 +0200 @@ -0,0 +1,16 @@ +#!/usr/bin/env python + +def e(self, x): + return x + +class C: + e = e + +class D: + e = C.e + +d = D() +q = d.e # unbound C.e +result = q(321) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r b8550c04e807 -r b58aae0af656 tests/attributes_class_in_method.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/attributes_class_in_method.py Fri May 22 00:17:35 2009 +0200 @@ -0,0 +1,17 @@ +#!/usr/bin/env python + +class C: + clsattr = 123 + clsattr2 = 456 + + def f(self): + return C.clsattr + + def g(self): + return self.clsattr2 + +c = C() +a = c.f() +b = c.g() + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r b8550c04e807 -r b58aae0af656 tests/attributes_instance.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/attributes_instance.py Fri May 22 00:17:35 2009 +0200 @@ -0,0 +1,15 @@ +#!/usr/bin/env python + +class C: + def __init__(self, value): + self.instattr = value + + def update(self, value): + self.attr = value + +c = C(789) +c.update(987) +a = c.instattr +b = c.attr + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r b8550c04e807 -r b58aae0af656 tests/attributes_shadowing.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/attributes_shadowing.py Fri May 22 00:17:35 2009 +0200 @@ -0,0 +1,12 @@ +#!/usr/bin/env python + +class C: + clsattr = 123 + + def __init__(self, value=None): + self.instattr = value is None and self.clsattr or value + +c1 = C(789) +c2 = C() + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r b8550c04e807 -r b58aae0af656 tests/failure/attributes.py --- a/tests/failure/attributes.py Mon May 18 23:56:12 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -#!/usr/bin/env python - -class C: - clsattr = 123 - - def __init__(self, value): - self.instattr = value - self.clsattr - - def update(self, value): - self.attr = value - self.clsattr = value - C.clsattr = value - -C -C.clsattr - -# vim: tabstop=4 expandtab shiftwidth=4 diff -r b8550c04e807 -r b58aae0af656 tests/failure/attributes_collision.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/failure/attributes_collision.py Fri May 22 00:17:35 2009 +0200 @@ -0,0 +1,13 @@ +#!/usr/bin/env python + +class C: + clsattr = 123 + + def update(self, value): + self.attr = value + self.clsattr = value + +c = C() +c.update(456) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r b8550c04e807 -r b58aae0af656 tests/failure/attributes_set_class.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/failure/attributes_set_class.py Fri May 22 00:17:35 2009 +0200 @@ -0,0 +1,13 @@ +#!/usr/bin/env python + +class C: + clsattr = 123 + + def update(self, value): + self.attr = value + C.clsattr = value + +c = C() +c.update(456) + +# vim: tabstop=4 expandtab shiftwidth=4