summaryrefslogtreecommitdiffstats
path: root/Lib/compiler
diff options
context:
space:
mode:
authorThomas Wouters <thomas@python.org>2007-02-23 19:56:57 (GMT)
committerThomas Wouters <thomas@python.org>2007-02-23 19:56:57 (GMT)
commit00e41defe8801ef37548fb60abacb3be13156d2a (patch)
tree863d072e568fee2b8f4959016b5954de457c7f4c /Lib/compiler
parentcf297e46b85257396560774e5492e9d71a40f32e (diff)
downloadcpython-00e41defe8801ef37548fb60abacb3be13156d2a.zip
cpython-00e41defe8801ef37548fb60abacb3be13156d2a.tar.gz
cpython-00e41defe8801ef37548fb60abacb3be13156d2a.tar.bz2
Bytes literal.
Diffstat (limited to 'Lib/compiler')
-rw-r--r--Lib/compiler/ast.py14
-rw-r--r--Lib/compiler/pyassem.py1
-rw-r--r--Lib/compiler/pycodegen.py4
-rw-r--r--Lib/compiler/transformer.py6
4 files changed, 23 insertions, 2 deletions
diff --git a/Lib/compiler/ast.py b/Lib/compiler/ast.py
index bc283c0..4794d66 100644
--- a/Lib/compiler/ast.py
+++ b/Lib/compiler/ast.py
@@ -267,6 +267,20 @@ class Break(Node):
def __repr__(self):
return "Break()"
+class Bytes(Node):
+ def __init__(self, value, lineno=None):
+ self.value = value
+ self.lineno = lineno
+
+ def getChildren(self):
+ return self.value,
+
+ def getChildNodes(self):
+ return ()
+
+ def __repr__(self):
+ return "Bytes(%s)" % (repr(self.value),)
+
class CallFunc(Node):
def __init__(self, node, args, star_args = None, dstar_args = None, lineno=None):
self.node = node
diff --git a/Lib/compiler/pyassem.py b/Lib/compiler/pyassem.py
index cac899d..f665c54 100644
--- a/Lib/compiler/pyassem.py
+++ b/Lib/compiler/pyassem.py
@@ -792,6 +792,7 @@ class StackDepthTracker:
'DELETE_ATTR': -1,
'STORE_GLOBAL': -1,
'BUILD_MAP': 1,
+ 'MAKE_BYTES': 0,
'COMPARE_OP': -1,
'STORE_FAST': -1,
'IMPORT_STAR': -1,
diff --git a/Lib/compiler/pycodegen.py b/Lib/compiler/pycodegen.py
index 8db4e0d..83fbc17 100644
--- a/Lib/compiler/pycodegen.py
+++ b/Lib/compiler/pycodegen.py
@@ -930,6 +930,10 @@ class CodeGenerator:
def visitConst(self, node):
self.emit('LOAD_CONST', node.value)
+
+ def visitBytes(self, node):
+ self.emit('LOAD_CONST', node.value)
+ self.emit('MAKE_BYTES')
def visitKeyword(self, node):
self.emit('LOAD_CONST', node.name)
diff --git a/Lib/compiler/transformer.py b/Lib/compiler/transformer.py
index 5f2face..79b702c 100644
--- a/Lib/compiler/transformer.py
+++ b/Lib/compiler/transformer.py
@@ -745,9 +745,11 @@ class Transformer:
return eval(lit)
def atom_string(self, nodelist):
- k = ''
- for node in nodelist:
+ k = self.decode_literal(nodelist[0][1])
+ for node in nodelist[1:]:
k += self.decode_literal(node[1])
+ if isinstance(k, bytes):
+ return Bytes(str(k), lineno=nodelist[0][2])
return Const(k, lineno=nodelist[0][2])
def atom_ellipsis(self, nodelist):