Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
04bfbb49
Commit
04bfbb49
authored
9 years ago
by
Jelle Zijlstra
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
f-strings: first attempt at code generation
parent
e2a245cb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
0 deletions
+33
-0
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+33
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
04bfbb49
...
@@ -2878,8 +2878,20 @@ class JoinedStrNode(ExprNode):
...
@@ -2878,8 +2878,20 @@ class JoinedStrNode(ExprNode):
#
#
# values [UnicodeNode|FormattedValueNode] Substrings of the f-string
# values [UnicodeNode|FormattedValueNode] Substrings of the f-string
#
#
type
=
py_object_type
subexprs
=
[
'values'
]
subexprs
=
[
'values'
]
def
analyse_types
(
self
,
env
):
self
.
values
=
[
v
.
analyse_types
(
env
)
for
v
in
self
.
values
]
self
.
values
=
[
v
.
coerce_to_pyobject
(
env
)
for
v
in
self
.
values
]
self
.
is_temp
=
1
return
self
def
generate_result_code
(
self
,
code
):
# TODO this just returns the first value
code
.
putln
(
'%s = %s;'
%
(
self
.
result
(),
self
.
values
[
0
].
py_result
()))
class
FormattedValueNode
(
ExprNode
):
class
FormattedValueNode
(
ExprNode
):
# {}-delimited portions of an f-string
# {}-delimited portions of an f-string
...
@@ -2890,6 +2902,27 @@ class FormattedValueNode(ExprNode):
...
@@ -2890,6 +2902,27 @@ class FormattedValueNode(ExprNode):
subexprs
=
[
'value'
,
'format_spec'
]
subexprs
=
[
'value'
,
'format_spec'
]
conversion_chars
=
'sra'
conversion_chars
=
'sra'
type
=
py_object_type
def
analyse_types
(
self
,
env
):
value
=
self
.
value
.
analyse_types
(
env
)
format_spec
=
self
.
format_spec
.
analyse_types
(
env
)
self
.
value
=
value
.
coerce_to_pyobject
(
env
)
self
.
format_spec
=
format_spec
.
coerce_to_pyobject
(
env
)
self
.
is_temp
=
True
return
self
def
generate_result_code
(
self
,
code
):
value_result
=
self
.
value
.
py_result
()
format_spec_result
=
self
.
format_spec
.
py_result
()
# TODO conversion chars
code
.
putln
(
"%s = PyObject_Format(%s, %s); %s"
%
(
self
.
result
(),
value_result
,
format_spec_result
,
code
.
error_goto_if_null
(
self
.
result
(),
self
.
pos
)))
code
.
put_gotref
(
self
.
result
())
#-------------------------------------------------------------------
#-------------------------------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment