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
b0aea029
Commit
b0aea029
authored
Dec 17, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'tmp'
parents
daa43b67
101c6e94
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
108 additions
and
50 deletions
+108
-50
CMakeLists.txt
CMakeLists.txt
+2
-1
lib_python/2.7/UserDict.py
lib_python/2.7/UserDict.py
+3
-2
lib_python/2.7/_abcoll.py
lib_python/2.7/_abcoll.py
+3
-0
lib_python/2.7/collections.py
lib_python/2.7/collections.py
+4
-3
src/capi/typeobject.cpp
src/capi/typeobject.cpp
+1
-0
src/core/threading.cpp
src/core/threading.cpp
+3
-3
src/core/threading.h
src/core/threading.h
+4
-4
src/gc/root_finder.cpp
src/gc/root_finder.cpp
+2
-2
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+53
-13
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+13
-1
src/runtime/types.cpp
src/runtime/types.cpp
+16
-20
src/runtime/types.h
src/runtime/types.h
+2
-1
test/tests/os_test.py
test/tests/os_test.py
+2
-0
No files found.
CMakeLists.txt
View file @
b0aea029
...
...
@@ -141,7 +141,8 @@ add_subdirectory(test/unittests)
add_subdirectory
(
tools
)
add_executable
(
pyston $<TARGET_OBJECTS:PYSTON_MAIN_OBJECT> $<TARGET_OBJECTS:PYSTON_OBJECTS> $<TARGET_OBJECTS:FROM_CPYTHON>
)
target_link_libraries
(
pyston stdlib pthread m readline gmp unwind pypa double-conversion
${
LLVM_LIBS
}
${
LIBLZMA_LIBRARIES
}
)
# Wrap the stdlib in --whole-archive to force all the symbols to be included and eventually exported
target_link_libraries
(
pyston -Wl,--whole-archive stdlib -Wl,--no-whole-archive pthread m readline gmp unwind pypa double-conversion
${
LLVM_LIBS
}
${
LIBLZMA_LIBRARIES
}
)
# copy the python standard library (lib_python/2.7) and src/codegen/parse_ast.py to the build directory
add_custom_command
(
TARGET pyston POST_BUILD COMMAND
${
CMAKE_COMMAND
}
-E copy_directory
${
CMAKE_SOURCE_DIR
}
/lib_python/2.7
${
CMAKE_BINARY_DIR
}
/lib_python/2.7
)
...
...
lib_python/2.7/UserDict.py
View file @
b0aea029
...
...
@@ -80,8 +80,9 @@ class IterableUserDict(UserDict):
def
__iter__
(
self
):
return
iter
(
self
.
data
)
import
_abcoll
_abcoll
.
MutableMapping
.
register
(
IterableUserDict
)
# Pyston change: disable using the _abcoll module for now.
# import _abcoll
# _abcoll.MutableMapping.register(IterableUserDict)
class
DictMixin
:
...
...
lib_python/2.7/_abcoll.py
View file @
b0aea029
# Copyright 2007 Google, Inc. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
# Pyston change: disable using the _abcoll module for now.
raise
NotImplementedError
()
"""Abstract Base Classes (ABCs) for collections, according to PEP 3119.
DON'T USE THIS MODULE DIRECTLY! The classes here should be imported
...
...
lib_python/2.7/collections.py
View file @
b0aea029
__all__
=
[
'Counter'
,
'deque'
,
'defaultdict'
,
'namedtuple'
,
'OrderedDict'
]
# For bootstrapping reasons, the collection ABCs are defined in _abcoll.py.
# They should however be considered an integral part of collections.py.
from
_abcoll
import
*
import
_abcoll
__all__
+=
_abcoll
.
__all__
# Pyston change: disable using the _abcoll module for now.
# from _abcoll import *
# import _abcoll
# __all__ += _abcoll.__all__
from
_collections
import
deque
,
defaultdict
from
operator
import
itemgetter
as
_itemgetter
,
eq
as
_eq
...
...
src/capi/typeobject.cpp
View file @
b0aea029
...
...
@@ -877,6 +877,7 @@ extern "C" int PyType_Ready(PyTypeObject* cls) {
}
cls
->
gc_visit
=
&
conservativeGCHandler
;
cls
->
is_user_defined
=
true
;
// TODO not sure how we can handle extension types that manually
// specify a dict...
...
...
src/core/threading.cpp
View file @
b0aea029
...
...
@@ -117,7 +117,7 @@ void popGenerator() {
}
static
int
signals_waiting
(
0
);
static
std
::
vector
<
ThreadState
>
thread_states
;
static
std
::
vector
<
Thread
GC
State
>
thread_states
;
static
void
pushThreadState
(
pthread_t
tid
,
ucontext_t
*
context
)
{
#if STACK_GROWS_DOWN
...
...
@@ -128,10 +128,10 @@ static void pushThreadState(pthread_t tid, ucontext_t* context) {
void
*
stack_end
=
(
void
*
)(
context
->
uc_mcontext
.
gregs
[
REG_RSP
]
+
sizeof
(
void
*
));
#endif
assert
(
stack_start
<
stack_end
);
thread_states
.
push_back
(
ThreadState
(
tid
,
context
,
stack_start
,
stack_end
));
thread_states
.
push_back
(
Thread
GC
State
(
tid
,
context
,
stack_start
,
stack_end
));
}
std
::
vector
<
ThreadState
>
getAllThreadStates
()
{
std
::
vector
<
Thread
GC
State
>
getAllThreadStates
()
{
// TODO need to prevent new threads from starting,
// though I suppose that will have been taken care of
// by the caller of this function.
...
...
src/core/threading.h
View file @
b0aea029
...
...
@@ -36,7 +36,7 @@ intptr_t start_thread(void* (*start_func)(Box*, Box*, Box*), Box* arg1, Box* arg
void
registerMainThread
();
void
finishMainThread
();
struct
ThreadState
{
struct
Thread
GC
State
{
pthread_t
tid
;
// useful mostly for debugging
ucontext_t
*
ucontext
;
...
...
@@ -45,13 +45,13 @@ struct ThreadState {
// in a generator, but those generators will be tracked separately.
void
*
stack_start
,
*
stack_end
;
ThreadState
(
pthread_t
tid
,
ucontext_t
*
ucontext
,
void
*
stack_start
,
void
*
stack_end
)
Thread
GC
State
(
pthread_t
tid
,
ucontext_t
*
ucontext
,
void
*
stack_start
,
void
*
stack_end
)
:
tid
(
tid
),
ucontext
(
ucontext
),
stack_start
(
stack_start
),
stack_end
(
stack_end
)
{}
};
// Gets a ThreadState per thread, not including the thread calling this function.
// Gets a Thread
GC
State per thread, not including the thread calling this function.
// For this call to make sense, the threads all should be blocked;
// as a corollary, this thread is very much not thread safe.
std
::
vector
<
ThreadState
>
getAllThreadStates
();
std
::
vector
<
Thread
GC
State
>
getAllThreadStates
();
// Get the stack "bottom" (ie first pushed data. For stacks that grow down, this
// will be the highest address).
...
...
src/gc/root_finder.cpp
View file @
b0aea029
...
...
@@ -47,9 +47,9 @@ void collectRoots(void* start, void* end, TraceStack* stack) {
void
collectOtherThreadsStacks
(
TraceStack
*
stack
)
{
std
::
vector
<
threading
::
ThreadState
>
threads
=
threading
::
getAllThreadStates
();
std
::
vector
<
threading
::
Thread
GC
State
>
threads
=
threading
::
getAllThreadStates
();
for
(
threading
::
ThreadState
&
tstate
:
threads
)
{
for
(
threading
::
Thread
GC
State
&
tstate
:
threads
)
{
collectRoots
(
tstate
.
stack_start
,
tstate
.
stack_end
,
stack
);
collectRoots
(
tstate
.
ucontext
,
tstate
.
ucontext
+
1
,
stack
);
}
...
...
src/runtime/builtin_modules/builtins.cpp
View file @
b0aea029
...
...
@@ -482,7 +482,7 @@ BoxedClass* BaseException, *Exception, *StandardError, *AssertionError, *Attribu
}
Box
*
exceptionNew1
(
BoxedClass
*
cls
)
{
return
exceptionNew
2
(
cls
,
boxStrConstant
(
""
)
);
return
exceptionNew
(
cls
,
EmptyTuple
);
}
class
BoxedException
:
public
Box
{
...
...
@@ -492,11 +492,29 @@ public:
};
Box
*
exceptionNew2
(
BoxedClass
*
cls
,
Box
*
message
)
{
assert
(
cls
->
tp_basicsize
==
sizeof
(
BoxedException
));
Box
*
r
=
new
BoxedException
(
cls
);
// TODO: maybe this should be a MemberDescriptor?
r
->
giveAttr
(
"message"
,
message
);
return
r
;
return
exceptionNew
(
cls
,
new
BoxedTuple
({
message
}));
}
Box
*
exceptionNew
(
BoxedClass
*
cls
,
BoxedTuple
*
args
)
{
if
(
!
isSubclass
(
cls
->
cls
,
type_cls
))
raiseExcHelper
(
TypeError
,
"exceptions.__new__(X): X is not a type object (%s)"
,
getTypeName
(
cls
)
->
c_str
());
if
(
!
isSubclass
(
cls
,
BaseException
))
raiseExcHelper
(
TypeError
,
"BaseException.__new__(%s): %s is not a subtype of BaseException"
,
getNameOfClass
(
cls
)
->
c_str
(),
getNameOfClass
(
cls
)
->
c_str
());
assert
(
cls
->
tp_basicsize
>=
sizeof
(
BoxedException
));
void
*
mem
=
gc_alloc
(
cls
->
tp_basicsize
,
gc
::
GCKind
::
PYTHON
);
memset
((
char
*
)
mem
+
sizeof
(
BoxedException
),
0
,
cls
->
tp_basicsize
-
sizeof
(
BoxedException
));
BoxedException
*
rtn
=
::
new
(
mem
)
BoxedException
(
cls
);
initUserAttrs
(
rtn
,
cls
);
// TODO: this should be a MemberDescriptor and set during init
if
(
args
->
elts
.
size
()
==
1
)
rtn
->
giveAttr
(
"message"
,
args
->
elts
[
0
]);
else
rtn
->
giveAttr
(
"message"
,
boxStrConstant
(
""
));
return
rtn
;
}
Box
*
exceptionStr
(
Box
*
b
)
{
...
...
@@ -520,15 +538,16 @@ Box* exceptionRepr(Box* b) {
return
boxString
(
*
getTypeName
(
b
)
+
"("
+
message_s
->
s
+
",)"
);
}
static
BoxedClass
*
makeBuiltinException
(
BoxedClass
*
base
,
const
char
*
name
)
{
BoxedClass
*
cls
=
new
BoxedHeapClass
(
type_cls
,
base
,
NULL
,
offsetof
(
BoxedException
,
attrs
),
sizeof
(
BoxedException
),
false
);
static
BoxedClass
*
makeBuiltinException
(
BoxedClass
*
base
,
const
char
*
name
,
int
size
=
0
)
{
if
(
size
==
0
)
size
=
base
->
tp_basicsize
;
BoxedClass
*
cls
=
new
BoxedHeapClass
(
type_cls
,
base
,
NULL
,
offsetof
(
BoxedException
,
attrs
),
size
,
false
);
cls
->
giveAttr
(
"__name__"
,
boxStrConstant
(
name
));
cls
->
giveAttr
(
"__module__"
,
boxStrConstant
(
"exceptions"
));
if
(
base
==
object_cls
)
{
cls
->
giveAttr
(
"__new__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
exceptionNew2
,
UNKNOWN
,
2
,
1
,
false
,
false
),
{
boxStrConstant
(
""
)
}));
cls
->
giveAttr
(
"__new__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
exceptionNew
,
UNKNOWN
,
1
,
0
,
true
,
true
)));
cls
->
giveAttr
(
"__str__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
exceptionStr
,
STR
,
1
)));
cls
->
giveAttr
(
"__repr__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
exceptionRepr
,
STR
,
1
)));
}
...
...
@@ -720,6 +739,23 @@ Box* pydump(void* p) {
return
None
;
}
class
BoxedEnvironmentError
:
public
BoxedException
{
public:
// Box* args, *message, *myerrno, *strerror, *filename;
Box
*
myerrno
,
*
strerror
,
*
filename
;
static
Box
*
__init__
(
BoxedEnvironmentError
*
self
,
Box
*
errno_
,
Box
*
strerror
,
Box
**
_args
)
{
Box
*
filename
=
_args
[
0
];
RELEASE_ASSERT
(
isSubclass
(
self
->
cls
,
EnvironmentError
),
""
);
self
->
myerrno
=
errno_
;
self
->
strerror
=
strerror
;
self
->
filename
=
filename
;
return
None
;
}
};
void
setupBuiltins
()
{
builtins_module
=
createModule
(
"__builtin__"
,
"__builtin__"
);
...
...
@@ -740,7 +776,7 @@ void setupBuiltins() {
builtins_module
->
giveAttr
(
"all"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
all
,
BOXED_BOOL
,
1
)));
builtins_module
->
giveAttr
(
"any"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
any
,
BOXED_BOOL
,
1
)));
BaseException
=
makeBuiltinException
(
object_cls
,
"BaseException"
);
BaseException
=
makeBuiltinException
(
object_cls
,
"BaseException"
,
sizeof
(
BoxedException
)
);
Exception
=
makeBuiltinException
(
BaseException
,
"Exception"
);
StandardError
=
makeBuiltinException
(
Exception
,
"StandardError"
);
AssertionError
=
makeBuiltinException
(
StandardError
,
"AssertionError"
);
...
...
@@ -751,7 +787,7 @@ void setupBuiltins() {
LookupError
=
makeBuiltinException
(
StandardError
,
"LookupError"
);
KeyError
=
makeBuiltinException
(
LookupError
,
"KeyError"
);
IndexError
=
makeBuiltinException
(
LookupError
,
"IndexError"
);
EnvironmentError
=
makeBuiltinException
(
StandardError
,
"EnvironmentError"
);
EnvironmentError
=
makeBuiltinException
(
StandardError
,
"EnvironmentError"
,
sizeof
(
BoxedEnvironmentError
)
);
IOError
=
makeBuiltinException
(
EnvironmentError
,
"IOError"
);
OSError
=
makeBuiltinException
(
EnvironmentError
,
"OSError"
);
ArithmeticError
=
makeBuiltinException
(
StandardError
,
"ArithmeticError"
);
...
...
@@ -775,6 +811,10 @@ void setupBuiltins() {
SystemError
=
makeBuiltinException
(
StandardError
,
"SystemError"
);
NotImplementedError
=
makeBuiltinException
(
RuntimeError
,
"NotImplementedError"
);
EnvironmentError
->
giveAttr
(
"__init__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
BoxedEnvironmentError
::
__init__
,
NONE
,
4
,
1
,
false
,
false
),
{
None
}));
repr_obj
=
new
BoxedFunction
(
boxRTFunction
((
void
*
)
repr
,
UNKNOWN
,
1
));
builtins_module
->
giveAttr
(
"repr"
,
repr_obj
);
len_obj
=
new
BoxedFunction
(
boxRTFunction
((
void
*
)
len
,
UNKNOWN
,
1
));
...
...
src/runtime/objmodel.cpp
View file @
b0aea029
...
...
@@ -19,6 +19,7 @@
#include <cstdlib>
#include <cstring>
#include <memory>
#include <sstream>
#include <stdint.h>
#include "asm_writing/icinfo.h"
...
...
@@ -351,6 +352,8 @@ BoxedClass::BoxedClass(BoxedClass* metaclass, BoxedClass* base, gcvisit_func gc_
memset
(
&
tp_name
,
0
,
(
char
*
)(
&
tp_version_tag
+
1
)
-
(
char
*
)(
&
tp_name
));
tp_basicsize
=
instance_size
;
tp_flags
|=
Py_TPFLAGS_HEAPTYPE
;
if
(
metaclass
==
NULL
)
{
assert
(
type_cls
==
NULL
);
}
else
{
...
...
@@ -2313,7 +2316,16 @@ Box* callFunc(BoxedFunction* func, CallRewriteArgs* rewrite_args, ArgPassSpec ar
Box
*
ovarargs
=
new
BoxedTuple
(
unused_positional
);
getArg
(
varargs_idx
,
oarg1
,
oarg2
,
oarg3
,
oargs
)
=
ovarargs
;
}
else
if
(
unused_positional
.
size
())
{
raiseExcHelper
(
TypeError
,
"<function>() takes at most %d argument%s (%d given)"
,
f
->
num_args
,
std
::
string
name
=
"<unknown function>"
;
if
(
f
->
source
)
name
=
f
->
source
->
getName
();
else
if
(
f
->
versions
.
size
())
{
std
::
ostringstream
oss
;
oss
<<
"<function at "
<<
f
->
versions
[
0
]
->
code
<<
">"
;
name
=
oss
.
str
();
}
raiseExcHelper
(
TypeError
,
"%s() takes at most %d argument%s (%d given)"
,
name
.
c_str
(),
f
->
num_args
,
(
f
->
num_args
==
1
?
""
:
"s"
),
argspec
.
num_args
+
argspec
.
num_keywords
+
varargs
.
size
());
}
...
...
src/runtime/types.cpp
View file @
b0aea029
...
...
@@ -607,31 +607,27 @@ extern "C" int PySlice_GetIndicesEx(PySliceObject* r, Py_ssize_t length, Py_ssiz
}
Box
*
typeRepr
(
BoxedClass
*
self
)
{
if
(
isUserDefined
(
self
))
{
std
::
ostringstream
os
;
std
::
ostringstream
os
;
if
((
self
->
tp_flags
&
Py_TPFLAGS_HEAPTYPE
)
&&
isUserDefined
(
self
))
os
<<
"<class '"
;
else
os
<<
"<type '"
;
Box
*
m
=
self
->
getattr
(
"__module__"
);
RELEASE_ASSERT
(
m
,
""
);
if
(
m
->
cls
==
str_cls
)
{
BoxedString
*
sm
=
static_cast
<
BoxedString
*>
(
m
);
os
<<
sm
->
s
<<
'.'
;
}
Box
*
m
=
self
->
getattr
(
"__module__"
);
if
(
m
&&
m
->
cls
==
str_cls
)
{
BoxedString
*
sm
=
static_cast
<
BoxedString
*>
(
m
);
os
<<
sm
->
s
<<
'.'
;
}
Box
*
n
=
self
->
getattr
(
"__name__"
);
RELEASE_ASSERT
(
n
,
""
);
RELEASE_ASSERT
(
n
->
cls
==
str_cls
,
"should have prevented you from setting __name__ to non-string"
);
BoxedString
*
sn
=
static_cast
<
BoxedString
*>
(
n
);
os
<<
sn
->
s
;
Box
*
n
=
self
->
getattr
(
"__name__"
);
RELEASE_ASSERT
(
n
,
""
);
RELEASE_ASSERT
(
n
->
cls
==
str_cls
,
"should have prevented you from setting __name__ to non-string"
);
BoxedString
*
sn
=
static_cast
<
BoxedString
*>
(
n
);
os
<<
sn
->
s
;
os
<<
"'>"
;
os
<<
"'>"
;
return
boxString
(
os
.
str
());
}
else
{
char
buf
[
80
];
snprintf
(
buf
,
80
,
"<type '%s'>"
,
getNameOfClass
(
self
)
->
c_str
());
return
boxStrConstant
(
buf
);
}
return
boxString
(
os
.
str
());
}
Box
*
typeHash
(
BoxedClass
*
self
)
{
...
...
src/runtime/types.h
View file @
b0aea029
...
...
@@ -217,7 +217,7 @@ public:
// Whether this class was defined by the user or is a builtin type.
// this is used mostly for debugging.
const
bool
is_user_defined
;
bool
is_user_defined
;
// will need to update this once we support tp_getattr-style overriding:
bool
hasGenericGetattr
()
{
return
true
;
}
...
...
@@ -539,6 +539,7 @@ extern "C" void boxGCHandler(GCVisitor* v, Box* b);
Box
*
exceptionNew1
(
BoxedClass
*
cls
);
Box
*
exceptionNew2
(
BoxedClass
*
cls
,
Box
*
message
);
Box
*
exceptionNew
(
BoxedClass
*
cls
,
BoxedTuple
*
args
);
extern
"C"
BoxedClass
*
Exception
,
*
AssertionError
,
*
AttributeError
,
*
TypeError
,
*
NameError
,
*
KeyError
,
*
IndexError
,
*
IOError
,
*
OSError
,
*
ZeroDivisionError
,
*
ValueError
,
*
UnboundLocalError
,
*
RuntimeError
,
*
ImportError
,
...
...
test/tests/os_test.py
View file @
b0aea029
...
...
@@ -12,3 +12,5 @@ print len(r1), len(r2), type(r1), type(r2), r1 == r2
print
type
(
os
.
stat
(
"/dev/null"
))
print
os
.
path
.
expanduser
(
"~"
)
==
os
.
environ
[
"HOME"
]
OSError
(
1
,
2
,
3
)
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