[Compiler-sig] Update to compiler for Python 2.0

Mark Hammond MarkH@ActiveState.com
Tue, 10 Oct 2000 23:14:32 +1100


Hi all,
	The following patch allows the nondist/src/Compiler package to pass its
test suite again.

Notes re transformer:
* The code was changed in such a way it will still work with Python 1.x.
Thus, I avoid using new 2.0 specific "symbol" module attributes.  The other
files are changed in a 2.0 specific way.

* The import changes seem hacky, but it appears the correct solution would
be to introduce a new node just for the import name.  Couldn't be bothered!

* There are no changes to implement "import as", but the current test suite
passes again...

If there are no objections over the next few days, I will check it in...

Mark.

Index: compiler/pyassem.py
===================================================================
RCS file:
/projects/cvsroot/python/nondist/src/Compiler/compiler/pyassem.py,v
retrieving revision 1.9
diff -r1.9 pyassem.py
516c516
<     # UNPACK_TUPLE, UNPACK_LIST, BUILD_TUPLE,
---
>     # UNPACK_SEQUENCE, BUILD_TUPLE,
518,520c518
<     def UNPACK_TUPLE(self, count):
<         return count
<     def UNPACK_LIST(self, count):
---
>     def UNPACK_SEQUENCE(self, count):
Index: compiler/pycodegen.py
===================================================================
RCS file:
/projects/cvsroot/python/nondist/src/Compiler/compiler/pycodegen.py,v
retrieving revision 1.20
diff -r1.20 pycodegen.py
459c459
<             self.emit('UNPACK_TUPLE', len(node.nodes))
---
>             self.emit('UNPACK_SEQUENCE', len(node.nodes))
709c709
<         self.emit('UNPACK_TUPLE', len(tup))
---
>         self.emit('UNPACK_SEQUENCE', len(tup))
Index: compiler/transformer.py
===================================================================
RCS file:
/projects/cvsroot/python/nondist/src/Compiler/compiler/transformer.py,v
retrieving revision 1.10
diff -r1.10 transformer.py
403c403,413
<         names.append(nodelist[i][1])
---
>         this_node = nodelist[i]
>         if type(this_node[1]) == type(''):
>           # Old 1.6 style
>           this_name = this_node[1]
>         else:
>           # import foo as spam
>           this_name = this_node[1][1]
>           if len(this_node) > 2:
>             as_name = this_node[3][1]
>             this_name = this_name, as_name
>         names.append(this_name)
409c419,430
<       names.append(self.com_dotted_name(nodelist[i]))
---
>       this_node = nodelist[i]
>       if this_node[0] == symbol.dotted_name:
>         # Old 1.6 style
>         this_name = self.com_dotted_name(this_node)
>       else: # symbol.dotted_as_name, but we can't use that in 1.6
>         # import foo as spam
>         this_name = self.com_dotted_name(this_node[1])
>         if len(this_node) > 2:
>           as_name = this_node[3][1]
>           this_name = this_name, as_name
>       names.append(this_name)
>