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
Boxiang Sun
cython
Commits
c14da739
Commit
c14da739
authored
Mar 14, 2009
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Templating utility code
parent
65abcc7f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
0 deletions
+25
-0
Cython/Utils.py
Cython/Utils.py
+25
-0
No files found.
Cython/Utils.py
View file @
c14da739
...
...
@@ -89,6 +89,12 @@ def long_literal(value):
value
=
int
(
value
)
return
not
-
2
**
31
<=
value
<
2
**
31
def
none_or_sub
(
s
,
data
):
if
s
is
None
:
return
s
else
:
return
s
%
data
# a simple class that simplifies the usage of utility code
class
UtilityCode
(
object
):
...
...
@@ -98,6 +104,7 @@ class UtilityCode(object):
self
.
init
=
init
self
.
cleanup
=
cleanup
self
.
requires
=
requires
self
.
_cache
=
{}
def
write_init_code
(
self
,
writer
,
pos
):
if
not
self
.
init
:
...
...
@@ -114,3 +121,21 @@ class UtilityCode(object):
self
.
cleanup
(
writer
,
pos
)
else
:
writer
.
put
(
self
.
cleanup
)
def
specialize
(
self
,
**
data
):
# Dicts aren't hashable...
key
=
data
.
items
();
key
.
sort
();
key
=
tuple
(
key
)
try
:
return
self
.
_cache
[
key
]
except
KeyError
:
if
self
.
requires
is
None
:
requires
=
None
else
:
requires
=
[
r
.
specialize
(
data
)
for
r
in
self
.
requires
]
s
=
self
.
_cache
[
key
]
=
UtilityCode
(
none_or_sub
(
self
.
proto
,
data
),
none_or_sub
(
self
.
impl
,
data
),
none_or_sub
(
self
.
init
,
data
),
none_or_sub
(
self
.
cleanup
,
data
),
requires
)
return
s
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