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
a6aee748
Commit
a6aee748
authored
May 15, 2014
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement all(iterable), any(iterable) and nonzero check for 'None'
parent
6d8b2e91
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
0 deletions
+28
-0
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+21
-0
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+2
-0
test/tests/builtins.py
test/tests/builtins.py
+3
-0
test/tests/unaryops.py
test/tests/unaryops.py
+2
-0
No files found.
src/runtime/builtin_modules/builtins.cpp
View file @
a6aee748
...
...
@@ -49,6 +49,24 @@ extern "C" Box* abs_(Box* x) {
}
}
extern
"C"
Box
*
all
(
Box
*
container
)
{
for
(
Box
*
e
:
container
->
pyElements
())
{
if
(
!
nonzero
(
e
))
{
return
boxBool
(
false
);
}
}
return
boxBool
(
true
);
}
extern
"C"
Box
*
any
(
Box
*
container
)
{
for
(
Box
*
e
:
container
->
pyElements
())
{
if
(
nonzero
(
e
))
{
return
boxBool
(
true
);
}
}
return
boxBool
(
false
);
}
extern
"C"
Box
*
min1
(
Box
*
container
)
{
Box
*
minElement
=
nullptr
;
for
(
Box
*
e
:
container
->
pyElements
())
{
...
...
@@ -292,6 +310,9 @@ void setupBuiltins() {
builtins_module
->
giveAttr
(
"NotImplemented"
,
NotImplemented
);
builtins_module
->
giveAttr
(
"NotImplementedType"
,
notimplemented_cls
);
builtins_module
->
giveAttr
(
"all"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
all
,
BOXED_BOOL
,
1
,
false
)));
builtins_module
->
giveAttr
(
"any"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
any
,
BOXED_BOOL
,
1
,
false
)));
repr_obj
=
new
BoxedFunction
(
boxRTFunction
((
void
*
)
repr
,
NULL
,
1
,
false
));
builtins_module
->
giveAttr
(
"repr"
,
repr_obj
);
len_obj
=
new
BoxedFunction
(
boxRTFunction
((
void
*
)
len
,
NULL
,
1
,
false
));
...
...
src/runtime/objmodel.cpp
View file @
a6aee748
...
...
@@ -933,6 +933,8 @@ extern "C" bool nonzero(Box* obj) {
rewriter
->
commit
();
}
return
static_cast
<
BoxedFloat
*>
(
obj
)
->
d
!=
0
;
}
else
if
(
obj
->
cls
==
none_cls
)
{
return
false
;
}
// FIXME we have internal functions calling this method;
...
...
test/tests/builtins.py
View file @
a6aee748
...
...
@@ -11,3 +11,6 @@ print __builtins__
__builtins__
=
2
print
__builtins__
print
all
([]),
all
([
True
]),
all
([
False
]),
all
([
None
]),
all
([
True
,
False
,
None
])
print
any
([]),
any
([
True
]),
any
([
False
]),
any
([
None
]),
any
([
True
,
False
,
None
])
test/tests/unaryops.py
View file @
a6aee748
...
...
@@ -6,3 +6,5 @@ f(1)
f
(
-
1
)
f
(
True
)
f
(
False
)
print
None
print
not
None
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