Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
a8163914
Commit
a8163914
authored
Jun 17, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add rewriting for 'a in b' expressions
parent
a3477848
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
6 deletions
+42
-6
src/codegen/unwinding.cpp
src/codegen/unwinding.cpp
+1
-1
src/codegen/unwinding.h
src/codegen/unwinding.h
+1
-1
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+39
-3
src/runtime/set.cpp
src/runtime/set.cpp
+1
-1
No files found.
src/codegen/unwinding.cpp
View file @
a8163914
...
...
@@ -1007,7 +1007,7 @@ std::string getCurrentPythonLine() {
return
"unknown:-1"
;
}
void
logByCurrentPythonLine
(
std
::
string
&
stat_name
)
{
void
logByCurrentPythonLine
(
const
std
::
string
&
stat_name
)
{
std
::
string
stat
=
stat_name
+
"<"
+
getCurrentPythonLine
()
+
">"
;
Stats
::
log
(
Stats
::
getStatCounter
(
stat
));
}
...
...
src/codegen/unwinding.h
View file @
a8163914
...
...
@@ -46,7 +46,7 @@ ExecutionPoint getExecutionPoint();
std
::
string
getCurrentPythonLine
();
// doesn't really belong in unwinding.h, since it's stats related, but it needs to unwind to get the current line...
void
logByCurrentPythonLine
(
std
::
string
&
stat_name
);
void
logByCurrentPythonLine
(
const
std
::
string
&
stat_name
);
// Adds stack locals and closure locals into the locals dict, and returns it.
Box
*
fastLocalsToBoxedLocals
();
...
...
src/runtime/objmodel.cpp
View file @
a8163914
...
...
@@ -3727,6 +3727,19 @@ static bool convert3wayCompareResultToBool(Box* v, int op_type) {
};
}
Box
*
nonzeroAndBox
(
Box
*
b
,
bool
negate
)
{
if
(
likely
(
b
->
cls
==
bool_cls
))
{
if
(
negate
)
return
boxBool
(
b
!=
True
);
return
b
;
}
bool
t
=
b
->
nonzeroIC
();
if
(
negate
)
t
=
!
t
;
return
boxBool
(
t
);
}
Box
*
compareInternal
(
Box
*
lhs
,
Box
*
rhs
,
int
op_type
,
CompareRewriteArgs
*
rewrite_args
)
{
if
(
op_type
==
AST_TYPE
::
Is
||
op_type
==
AST_TYPE
::
IsNot
)
{
bool
neg
=
(
op_type
==
AST_TYPE
::
IsNot
);
...
...
@@ -3742,11 +3755,26 @@ Box* compareInternal(Box* lhs, Box* rhs, int op_type, CompareRewriteArgs* rewrit
}
if
(
op_type
==
AST_TYPE
::
In
||
op_type
==
AST_TYPE
::
NotIn
)
{
// TODO do rewrite
static
BoxedString
*
contains_str
=
static_cast
<
BoxedString
*>
(
PyString_InternFromString
(
"__contains__"
));
Box
*
contained
=
callattrInternal1
(
rhs
,
contains_str
,
CLASS_ONLY
,
NULL
,
ArgPassSpec
(
1
),
lhs
);
Box
*
contained
;
RewriterVar
*
r_contained
;
if
(
rewrite_args
)
{
CallRewriteArgs
crewrite_args
(
rewrite_args
->
rewriter
,
rewrite_args
->
rhs
,
rewrite_args
->
destination
);
crewrite_args
.
arg1
=
rewrite_args
->
lhs
;
contained
=
callattrInternal1
(
rhs
,
contains_str
,
CLASS_ONLY
,
&
crewrite_args
,
ArgPassSpec
(
1
),
lhs
);
if
(
!
crewrite_args
.
out_success
)
rewrite_args
=
NULL
;
else
if
(
contained
)
r_contained
=
crewrite_args
.
out_rtn
;
}
else
{
contained
=
callattrInternal1
(
rhs
,
contains_str
,
CLASS_ONLY
,
NULL
,
ArgPassSpec
(
1
),
lhs
);
}
if
(
contained
==
NULL
)
{
rewrite_args
=
NULL
;
int
result
=
_PySequence_IterSearch
(
rhs
,
lhs
,
PY_ITERSEARCH_CONTAINS
);
if
(
result
<
0
)
throwCAPIException
();
...
...
@@ -3754,6 +3782,14 @@ Box* compareInternal(Box* lhs, Box* rhs, int op_type, CompareRewriteArgs* rewrit
return
boxBool
(
result
);
}
if
(
rewrite_args
)
{
auto
r_negate
=
rewrite_args
->
rewriter
->
loadConst
((
int
)(
op_type
==
AST_TYPE
::
NotIn
));
RewriterVar
*
r_contained_box
=
rewrite_args
->
rewriter
->
call
(
true
,
(
void
*
)
nonzeroAndBox
,
r_contained
,
r_negate
);
rewrite_args
->
out_rtn
=
r_contained_box
;
rewrite_args
->
out_success
=
true
;
}
bool
b
;
if
(
contained
->
cls
==
bool_cls
)
b
=
contained
==
True
;
...
...
src/runtime/set.cpp
View file @
a8163914
...
...
@@ -410,7 +410,7 @@ Box* setPop(BoxedSet* self) {
Box
*
setContains
(
BoxedSet
*
self
,
Box
*
v
)
{
RELEASE_ASSERT
(
PyAnySet_Check
(
self
),
""
);
return
boxBool
(
self
->
s
.
count
(
v
)
!=
0
);
return
boxBool
(
self
->
s
.
find
(
v
)
!=
self
->
s
.
end
()
);
}
Box
*
setEq
(
BoxedSet
*
self
,
BoxedSet
*
rhs
)
{
...
...
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