Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pystencils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stephan Seitz
pystencils
Commits
2fe6cd6d
Commit
2fe6cd6d
authored
5 years ago
by
Stephan Seitz
Browse files
Options
Downloads
Patches
Plain Diff
Implement astnodes {SourceCodeComment,EmptyLine}
parent
01b8032e
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pystencils/astnodes.py
+45
-2
45 additions, 2 deletions
pystencils/astnodes.py
pystencils/backends/cbackend.py
+6
-0
6 additions, 0 deletions
pystencils/backends/cbackend.py
pystencils_tests/test_source_code_comment.py
+38
-0
38 additions, 0 deletions
pystencils_tests/test_source_code_comment.py
with
89 additions
and
2 deletions
pystencils/astnodes.py
+
45
−
2
View file @
2fe6cd6d
...
@@ -718,5 +718,48 @@ class DestructuringBindingsForFieldClass(Node):
...
@@ -718,5 +718,48 @@ class DestructuringBindingsForFieldClass(Node):
return
self
.
body
.
atoms
(
arg_type
)
|
{
s
for
s
in
self
.
symbols_defined
if
isinstance
(
s
,
arg_type
)}
return
self
.
body
.
atoms
(
arg_type
)
|
{
s
for
s
in
self
.
symbols_defined
if
isinstance
(
s
,
arg_type
)}
def
get_dummy_symbol
(
dtype
=
'
bool
'
):
class
SourceCodeComment
(
Node
):
return
TypedSymbol
(
'
dummy%s
'
%
uuid
.
uuid4
().
hex
,
create_type
(
dtype
))
def
__init__
(
self
,
text
):
self
.
text
=
text
@property
def
args
(
self
):
return
[]
@property
def
symbols_defined
(
self
):
return
set
()
@property
def
undefined_symbols
(
self
):
return
set
()
def
__str__
(
self
):
return
"
/*
"
+
self
.
text
+
"
*/
"
def
__repr__
(
self
):
return
self
.
__str__
()
class
EmptyLine
(
Node
):
def
__init__
(
self
):
pass
@property
def
args
(
self
):
return
[]
@property
def
symbols_defined
(
self
):
return
set
()
@property
def
undefined_symbols
(
self
):
return
set
()
def
__str__
(
self
):
return
""
def
__repr__
(
self
):
return
self
.
__str__
()
This diff is collapsed.
Click to expand it.
pystencils/backends/cbackend.py
+
6
−
0
View file @
2fe6cd6d
...
@@ -251,6 +251,12 @@ class CBackend:
...
@@ -251,6 +251,12 @@ class CBackend:
def
_print_CustomCodeNode
(
self
,
node
):
def
_print_CustomCodeNode
(
self
,
node
):
return
node
.
get_code
(
self
.
_dialect
,
self
.
_vector_instruction_set
)
return
node
.
get_code
(
self
.
_dialect
,
self
.
_vector_instruction_set
)
def
_print_SourceCodeComment
(
self
,
node
):
return
"
/*
"
+
node
.
text
+
"
*/
"
def
_print_EmptyLine
(
self
,
node
):
return
""
def
_print_Conditional
(
self
,
node
):
def
_print_Conditional
(
self
,
node
):
cond_type
=
get_type_of_expression
(
node
.
condition_expr
)
cond_type
=
get_type_of_expression
(
node
.
condition_expr
)
if
isinstance
(
cond_type
,
VectorType
):
if
isinstance
(
cond_type
,
VectorType
):
...
...
This diff is collapsed.
Click to expand it.
pystencils_tests/test_source_code_comment.py
0 → 100644
+
38
−
0
View file @
2fe6cd6d
# -*- coding: utf-8 -*-
#
# Copyright © 2019 Stephan Seitz <stephan.seitz@fau.de>
#
# Distributed under terms of the GPLv3 license.
"""
"""
import
pystencils
import
pystencils.astnodes
def
test_source_code_comment
():
a
,
b
=
pystencils
.
fields
(
'
a,b: float[2D]
'
)
assignments
=
pystencils
.
AssignmentCollection
(
{
a
.
center
():
b
[
0
,
2
]
+
b
[
0
,
0
]},
{}
)
ast
=
pystencils
.
create_kernel
(
assignments
,
target
=
'
cpu
'
)
ast
.
body
.
append
(
pystencils
.
astnodes
.
SourceCodeComment
(
"
Hallo
"
))
ast
.
body
.
append
(
pystencils
.
astnodes
.
EmptyLine
())
ast
.
body
.
append
(
pystencils
.
astnodes
.
SourceCodeComment
(
"
World!
"
))
print
(
ast
)
compiled
=
ast
.
compile
()
assert
compiled
is
not
None
print
(
pystencils
.
show_code
(
ast
))
def
main
():
test_source_code_comment
()
if
__name__
==
'
__main__
'
:
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment