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
ef3644bb
Commit
ef3644bb
authored
Mar 13, 2015
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement 'or, xor, and' for bool and setiterator.__iter__
parent
7e26d109
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
0 deletions
+49
-0
src/runtime/bool.cpp
src/runtime/bool.cpp
+36
-0
src/runtime/set.cpp
src/runtime/set.cpp
+7
-0
test/tests/bool_functions.py
test/tests/bool_functions.py
+6
-0
No files found.
src/runtime/bool.cpp
View file @
ef3644bb
...
...
@@ -47,6 +47,39 @@ extern "C" Box* boolNew(Box* cls, Box* val) {
return
boxBool
(
b
);
}
extern
"C"
Box
*
boolAnd
(
BoxedBool
*
lhs
,
BoxedBool
*
rhs
)
{
if
(
lhs
->
cls
!=
bool_cls
)
raiseExcHelper
(
TypeError
,
"descriptor '__and__' requires a 'bool' object but received a '%s'"
,
getTypeName
(
lhs
));
if
(
rhs
->
cls
!=
bool_cls
)
return
NotImplemented
;
return
boxBool
(
lhs
->
n
&&
rhs
->
n
);
}
extern
"C"
Box
*
boolOr
(
BoxedBool
*
lhs
,
BoxedBool
*
rhs
)
{
if
(
lhs
->
cls
!=
bool_cls
)
raiseExcHelper
(
TypeError
,
"descriptor '__or__' requires a 'bool' object but received a '%s'"
,
getTypeName
(
lhs
));
if
(
rhs
->
cls
!=
bool_cls
)
return
NotImplemented
;
return
boxBool
(
lhs
->
n
||
rhs
->
n
);
}
extern
"C"
Box
*
boolXor
(
BoxedBool
*
lhs
,
BoxedBool
*
rhs
)
{
if
(
lhs
->
cls
!=
bool_cls
)
raiseExcHelper
(
TypeError
,
"descriptor '__xor__' requires a 'bool' object but received a '%s'"
,
getTypeName
(
lhs
));
if
(
rhs
->
cls
!=
bool_cls
)
return
NotImplemented
;
return
boxBool
(
lhs
->
n
^
rhs
->
n
);
}
void
setupBool
()
{
bool_cls
->
giveAttr
(
"__nonzero__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
boolNonzero
,
BOXED_BOOL
,
1
)));
bool_cls
->
giveAttr
(
"__repr__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
boolRepr
,
STR
,
1
)));
...
...
@@ -55,6 +88,9 @@ void setupBool() {
bool_cls
->
giveAttr
(
"__new__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
boolNew
,
UNKNOWN
,
2
,
1
,
false
,
false
),
{
None
}));
bool_cls
->
giveAttr
(
"__and__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
boolAnd
,
BOXED_BOOL
,
2
)));
bool_cls
->
giveAttr
(
"__or__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
boolOr
,
BOXED_BOOL
,
2
)));
bool_cls
->
giveAttr
(
"__xor__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
boolXor
,
BOXED_BOOL
,
2
)));
bool_cls
->
freeze
();
...
...
src/runtime/set.cpp
View file @
ef3644bb
...
...
@@ -66,6 +66,11 @@ Box* setiteratorNext(BoxedSetIterator* self) {
return
self
->
next
();
}
Box
*
setiteratorIter
(
BoxedSetIterator
*
self
)
{
assert
(
self
->
cls
==
set_iterator_cls
);
return
self
;
}
Box
*
setAdd2
(
Box
*
_self
,
Box
*
b
)
{
assert
(
_self
->
cls
==
set_cls
||
_self
->
cls
==
frozenset_cls
);
BoxedSet
*
self
=
static_cast
<
BoxedSet
*>
(
_self
);
...
...
@@ -272,6 +277,8 @@ using namespace pyston::set;
void
setupSet
()
{
set_iterator_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
&
setIteratorGCHandler
,
0
,
0
,
sizeof
(
BoxedSet
),
false
,
"setiterator"
);
set_iterator_cls
->
giveAttr
(
"__iter__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
setiteratorIter
,
typeFromClass
(
set_iterator_cls
),
1
)));
set_iterator_cls
->
giveAttr
(
"__hasnext__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
setiteratorHasnext
,
BOXED_BOOL
,
1
)));
set_iterator_cls
->
giveAttr
(
"next"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
setiteratorNext
,
UNKNOWN
,
1
)));
...
...
test/tests/bool_functions.py
View file @
ef3644bb
...
...
@@ -30,6 +30,12 @@ print hash(1) == hash(True)
print
isinstance
(
True
,
int
)
print
isinstance
(
False
,
int
)
for
lhs
in
(
True
,
False
):
for
rhs
in
(
True
,
False
):
print
lhs
|
rhs
print
lhs
&
rhs
print
lhs
^
rhs
print
range
(
False
,
True
,
True
)
print
abs
(
True
),
abs
(
False
)
...
...
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