1.1 --- a/docs/invocation.txt Mon Jul 28 00:26:29 2008 +0200
1.2 +++ b/docs/invocation.txt Tue Jul 29 00:20:23 2008 +0200
1.3 @@ -127,6 +127,12 @@
1.4 Then, check the number of arguments and the availability of defaults against
1.5 the details provided by the callable's structure.
1.6
1.7 +Checking defaults for unknown callables:
1.8 +
1.9 + Approach #1 - pre-fill defaults, add arguments, check frame
1.10 +
1.11 + Approach #2 - add arguments, add defaults while checking frame
1.12 +
1.13 Functions as methods:
1.14
1.15 def f(x, y, z): ...
2.1 --- a/micropython/ast.py Mon Jul 28 00:26:29 2008 +0200
2.2 +++ b/micropython/ast.py Tue Jul 29 00:20:23 2008 +0200
2.3 @@ -702,6 +702,7 @@
2.4
2.5 first = 1
2.6 frame_pos = ncontext
2.7 + max_keyword_pos = 0
2.8
2.9 for arg in args:
2.10
2.11 @@ -775,6 +776,10 @@
2.12 # checks embedded offset against (callable+0)
2.13 # moves the current value to frame+position
2.14
2.15 + # Record the highest possible frame position for this argument.
2.16 +
2.17 + max_keyword_pos = max(max_keyword_pos, max(self.paramtable.all_attribute_positions(arg.name)))
2.18 +
2.19 else:
2.20 self.dispatch(arg)
2.21 self.new_op(StoreFrame(frame_pos))
2.22 @@ -838,7 +843,7 @@
2.23 # NOTE: the context in use.
2.24
2.25 else:
2.26 - self.new_op(CheckFrame())
2.27 + self.new_op(CheckFrame(max(max(employed_positions), max_keyword_pos)))
2.28
2.29 def _generateCallFuncDefaultArgs(self, target, temp, nargs_min, nargs_max, employed_positions):
2.30
3.1 --- a/micropython/rsvp.py Mon Jul 28 00:26:29 2008 +0200
3.2 +++ b/micropython/rsvp.py Tue Jul 29 00:20:23 2008 +0200
3.3 @@ -180,7 +180,7 @@
3.4 class LoadCallable(Instruction): "Load the target of an invocation."
3.5 class StoreCallable(Instruction): "Store the source value into the object referenced by the current value."
3.6 class LoadContext(Instruction): "Load the context of an invocation."
3.7 -class CheckFrame(Instruction): "Check the invocation frame and context for the target."
3.8 +class CheckFrame(Immediate): "Check the invocation frame and context for the target."
3.9 class CheckSelf(Instruction): "Check the first argument of an invocation against the target."
3.10
3.11 # Invocation-related instructions, using a special result "register".
4.1 --- a/micropython/table.py Mon Jul 28 00:26:29 2008 +0200
4.2 +++ b/micropython/table.py Tue Jul 29 00:20:23 2008 +0200
4.3 @@ -206,6 +206,36 @@
4.4 row.append(attributes.get(name))
4.5 return row
4.6
4.7 + def all_attribute_positions(self, name):
4.8 +
4.9 + """
4.10 + Return a list of positions for the attribute with the given 'name' from
4.11 + all known objects.
4.12 + """
4.13 +
4.14 + all = set()
4.15 + for attributes in self.table.values():
4.16 + if attributes.has_key(name):
4.17 + all.add(attributes[name])
4.18 + return all
4.19 +
4.20 + def all_possible_objects(self, names):
4.21 +
4.22 + """
4.23 + Return a list of object names supporting the given attribute 'names'.
4.24 + """
4.25 +
4.26 + possible = []
4.27 + for objname, attributes in self.table.items():
4.28 + found = 1
4.29 + for name in names:
4.30 + if not attributes.has_key(name):
4.31 + found = 0
4.32 + break
4.33 + if found:
4.34 + possible.append(objname)
4.35 + return possible
4.36 +
4.37 def as_list(self):
4.38
4.39 """