Author: Armin Rigo <[email protected]>
Branch: py3.5-fstring-pep498
Changeset: r89696:f23c6257063a
Date: 2017-01-22 21:47 +0100
http://bitbucket.org/pypy/pypy/changeset/f23c6257063a/

Log:    ast -> bytecode, minimal

diff --git a/lib-python/3/opcode.py b/lib-python/3/opcode.py
--- a/lib-python/3/opcode.py
+++ b/lib-python/3/opcode.py
@@ -214,6 +214,9 @@
 def_op('BUILD_TUPLE_UNPACK', 152)
 def_op('BUILD_SET_UNPACK', 153)
 
+def_op('FORMAT_VALUE', 155)
+def_op('BUILD_STRING', 157)
+
 # pypy modification, experimental bytecode
 def_op('LOOKUP_METHOD', 201)          # Index in name list
 hasname.append(201)
diff --git a/pypy/interpreter/astcompiler/astbuilder.py 
b/pypy/interpreter/astcompiler/astbuilder.py
--- a/pypy/interpreter/astcompiler/astbuilder.py
+++ b/pypy/interpreter/astcompiler/astbuilder.py
@@ -1232,6 +1232,7 @@
 
     def _f_string_expr(self, joined_pieces, u, start, atom_node):
         conversion = -1     # the conversion char.  -1 if not specified.
+        format_spec = None
         nested_depth = 0    # nesting level for braces/parens/brackets in exprs
         p = start
         while p < len(u):
@@ -1261,7 +1262,10 @@
         assert p >= start
         expr = self._f_string_compile(u[start:p], atom_node)
         assert isinstance(expr, ast.Expression)
-        joined_pieces.append(expr.body)
+        fval = ast.FormattedValue(expr.body, conversion, format_spec,
+                                  atom_node.get_lineno(),
+                                  atom_node.get_column())
+        joined_pieces.append(fval)
         return end_f_string
 
     def _parse_f_string(self, joined_pieces, w_string, atom_node):
diff --git a/pypy/interpreter/astcompiler/codegen.py 
b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -1491,6 +1491,16 @@
             sub.value.walkabout(self)
         self._compile_slice(sub.slice, sub.ctx)
 
+    def visit_JoinedStr(self, joinedstr):
+        self.update_position(joinedstr.lineno)
+        for node in joinedstr.values:
+            node.walkabout(self)
+        self.emit_op_arg(ops.BUILD_STRING, len(joinedstr.values))
+
+    def visit_FormattedValue(self, fmt):
+        fmt.value.walkabout(self)
+        self.emit_op_arg(ops.FORMAT_VALUE, 0)
+
 
 class TopLevelCodeGenerator(PythonCodeGenerator):
 
diff --git a/pypy/interpreter/astcompiler/validate.py 
b/pypy/interpreter/astcompiler/validate.py
--- a/pypy/interpreter/astcompiler/validate.py
+++ b/pypy/interpreter/astcompiler/validate.py
@@ -447,3 +447,11 @@
             node.single is not space.w_True and
             node.single is not space.w_False):
             raise ValidationError("singleton must be True, False, or None")
+
+    def visit_JoinedStr(self, node):
+        self._validate_exprs(node.values)
+
+    def visit_FormattedValue(self, node):
+        self._validate_expr(node.value)
+        if node.format_spec:
+            self._validate_expr(node.format_spec)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to