# HG changeset patch # User Paul Boddie # Date 1217283623 -7200 # Node ID c849c63e54522bb66ebbb1b918c734bf88055148 # Parent b198f939f7bb314c5d816fcd49e6ca1175afc010 Added frame size estimation based on the number of arguments used and parameter name information supporting any keyword arguments employed. Added some utility methods to the Table class. Made CheckFrame an immediate instruction. Added notes on checking frames and defaults at run-time. diff -r b198f939f7bb -r c849c63e5452 docs/invocation.txt --- a/docs/invocation.txt Mon Jul 28 00:26:29 2008 +0200 +++ b/docs/invocation.txt Tue Jul 29 00:20:23 2008 +0200 @@ -127,6 +127,12 @@ Then, check the number of arguments and the availability of defaults against the details provided by the callable's structure. +Checking defaults for unknown callables: + + Approach #1 - pre-fill defaults, add arguments, check frame + + Approach #2 - add arguments, add defaults while checking frame + Functions as methods: def f(x, y, z): ... diff -r b198f939f7bb -r c849c63e5452 micropython/ast.py --- a/micropython/ast.py Mon Jul 28 00:26:29 2008 +0200 +++ b/micropython/ast.py Tue Jul 29 00:20:23 2008 +0200 @@ -702,6 +702,7 @@ first = 1 frame_pos = ncontext + max_keyword_pos = 0 for arg in args: @@ -775,6 +776,10 @@ # checks embedded offset against (callable+0) # moves the current value to frame+position + # Record the highest possible frame position for this argument. + + max_keyword_pos = max(max_keyword_pos, max(self.paramtable.all_attribute_positions(arg.name))) + else: self.dispatch(arg) self.new_op(StoreFrame(frame_pos)) @@ -838,7 +843,7 @@ # NOTE: the context in use. else: - self.new_op(CheckFrame()) + self.new_op(CheckFrame(max(max(employed_positions), max_keyword_pos))) def _generateCallFuncDefaultArgs(self, target, temp, nargs_min, nargs_max, employed_positions): diff -r b198f939f7bb -r c849c63e5452 micropython/rsvp.py --- a/micropython/rsvp.py Mon Jul 28 00:26:29 2008 +0200 +++ b/micropython/rsvp.py Tue Jul 29 00:20:23 2008 +0200 @@ -180,7 +180,7 @@ class LoadCallable(Instruction): "Load the target of an invocation." class StoreCallable(Instruction): "Store the source value into the object referenced by the current value." class LoadContext(Instruction): "Load the context of an invocation." -class CheckFrame(Instruction): "Check the invocation frame and context for the target." +class CheckFrame(Immediate): "Check the invocation frame and context for the target." class CheckSelf(Instruction): "Check the first argument of an invocation against the target." # Invocation-related instructions, using a special result "register". diff -r b198f939f7bb -r c849c63e5452 micropython/table.py --- a/micropython/table.py Mon Jul 28 00:26:29 2008 +0200 +++ b/micropython/table.py Tue Jul 29 00:20:23 2008 +0200 @@ -206,6 +206,36 @@ row.append(attributes.get(name)) return row + def all_attribute_positions(self, name): + + """ + Return a list of positions for the attribute with the given 'name' from + all known objects. + """ + + all = set() + for attributes in self.table.values(): + if attributes.has_key(name): + all.add(attributes[name]) + return all + + def all_possible_objects(self, names): + + """ + Return a list of object names supporting the given attribute 'names'. + """ + + possible = [] + for objname, attributes in self.table.items(): + found = 1 + for name in names: + if not attributes.has_key(name): + found = 0 + break + if found: + possible.append(objname) + return possible + def as_list(self): """