diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2000-05-02 22:32:59 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2000-05-02 22:32:59 (GMT) |
commit | be317e615e9c25f3f38062266b9b8a7ad86a1c90 (patch) | |
tree | cbf3aed890a6896aa92505adcd6f89304edefd79 /Lib/compiler/transformer.py | |
parent | 0a4f1ff64eeb50cdf0b81bd4cff5b2e1d159daa5 (diff) | |
download | cpython-be317e615e9c25f3f38062266b9b8a7ad86a1c90.zip cpython-be317e615e9c25f3f38062266b9b8a7ad86a1c90.tar.gz cpython-be317e615e9c25f3f38062266b9b8a7ad86a1c90.tar.bz2 |
patches from Mark Hammond
Attached is a set of diffs for the .py compiler that adds support
for the new extended call syntax.
compiler/ast.py:
CallFunc node gets 2 new children to support extended call syntax -
"star_args" (for "*args") and "dstar_args" (for "**args")
compiler/pyassem.py
It appear that self.lnotab is supposed to be responsible for
tracking line numbers, but self.firstlineno was still hanging
around. Removed self.firstlineno completely. NOTE - I didnt
actually test that the generated code has the correct line numbers!!
Stack depth tracking appeared a little broken - the checks never
made it beyond the "self.patterns" check - thus, the custom methods
were never called! Fixed this.
(XXX Jeremy notes: I think this code is still broken because it
doesn't track stack effects across block bounaries.)
Added support for the new extended call syntax opcodes for depth
calculations.
compiler/pycodegen.py
Added support for the new extended call syntax opcodes.
compiler/transformer.py
Added support for the new extended call syntax.
Diffstat (limited to 'Lib/compiler/transformer.py')
-rw-r--r-- | Lib/compiler/transformer.py | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/Lib/compiler/transformer.py b/Lib/compiler/transformer.py index 1531ec3..d23fdb8 100644 --- a/Lib/compiler/transformer.py +++ b/Lib/compiler/transformer.py @@ -984,10 +984,32 @@ class Transformer: return Node('call_func', primaryNode, [ ]) args = [ ] kw = 0 - for i in range(1, len(nodelist), 2): - kw, result = self.com_argument(nodelist[i], kw) + len_nodelist = len(nodelist) + for i in range(1, len_nodelist, 2): + node = nodelist[i] + if node[0] == token.STAR or node[0] == token.DOUBLESTAR: + break + kw, result = self.com_argument(node, kw) args.append(result) - return Node('call_func', primaryNode, args) + else: + i = i + 1 # No broken by star arg, so skip the last one we processed. + star_node = dstar_node = None + while i < len_nodelist: + tok = nodelist[i] + ch = nodelist[i+1] + i = i + 3 + if tok[0]==token.STAR: + if star_node is not None: + raise SyntaxError, 'already have the varargs indentifier' + star_node = self.com_node(ch) + elif tok[0]==token.DOUBLESTAR: + if dstar_node is not None: + raise SyntaxError, 'already have the kwargs indentifier' + dstar_node = self.com_node(ch) + else: + raise SyntaxError, 'unknown node type: %s' % tok + + return Node('call_func', primaryNode, args, star_node, dstar_node) def com_argument(self, nodelist, kw): if len(nodelist) == 2: |