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
f17535bc
Commit
f17535bc
authored
Feb 05, 2015
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add array module
parent
2df05571
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
64 additions
and
8 deletions
+64
-8
Makefile
Makefile
+1
-1
from_cpython/CMakeLists.txt
from_cpython/CMakeLists.txt
+1
-1
from_cpython/Modules/arraymodule.c
from_cpython/Modules/arraymodule.c
+7
-0
src/capi/typeobject.cpp
src/capi/typeobject.cpp
+0
-1
src/runtime/capi.cpp
src/runtime/capi.cpp
+6
-0
src/runtime/str.cpp
src/runtime/str.cpp
+18
-1
src/runtime/types.cpp
src/runtime/types.cpp
+15
-2
src/runtime/util.cpp
src/runtime/util.cpp
+2
-2
test/tests/array.py
test/tests/array.py
+14
-0
No files found.
Makefile
View file @
f17535bc
...
...
@@ -290,7 +290,7 @@ SRCS := $(MAIN_SRCS) $(STDLIB_SRCS)
STDLIB_OBJS
:=
stdlib.bc.o stdlib.stripped.bc.o
STDLIB_RELEASE_OBJS
:=
stdlib.release.bc.o
STDMODULE_SRCS
:=
errnomodule.c shamodule.c sha256module.c sha512module.c _math.c mathmodule.c md5.c md5module.c _randommodule.c _sre.c operator.c binascii.c pwdmodule.c posixmodule.c _struct.c datetimemodule.c _functoolsmodule.c _collectionsmodule.c itertoolsmodule.c resource.c signalmodule.c selectmodule.c fcntlmodule.c timemodule.c
$(EXTRA_STDMODULE_SRCS)
STDMODULE_SRCS
:=
errnomodule.c shamodule.c sha256module.c sha512module.c _math.c mathmodule.c md5.c md5module.c _randommodule.c _sre.c operator.c binascii.c pwdmodule.c posixmodule.c _struct.c datetimemodule.c _functoolsmodule.c _collectionsmodule.c itertoolsmodule.c resource.c signalmodule.c selectmodule.c fcntlmodule.c timemodule.c
arraymodule.c
$(EXTRA_STDMODULE_SRCS)
STDOBJECT_SRCS
:=
structseq.c capsule.c stringobject.c
$(EXTRA_STDOBJECT_SRCS)
STDPYTHON_SRCS
:=
pyctype.c getargs.c formatter_string.c pystrtod.c dtoa.c
$(EXTRA_STDPYTHON_SRCS)
FROM_CPYTHON_SRCS
:=
$(
addprefix
from_cpython/Modules/,
$(STDMODULE_SRCS)
)
$(
addprefix
from_cpython/Objects/,
$(STDOBJECT_SRCS)
)
$(
addprefix
from_cpython/Python/,
$(STDPYTHON_SRCS)
)
...
...
from_cpython/CMakeLists.txt
View file @
f17535bc
...
...
@@ -15,7 +15,7 @@ endforeach(STDLIB_FILE)
add_custom_target
(
copy_stdlib ALL DEPENDS
${
STDLIB_TARGETS
}
)
# compile specified files in from_cpython/Modules
file
(
GLOB_RECURSE STDMODULE_SRCS Modules errnomodule.c shamodule.c sha256module.c sha512module.c _math.c mathmodule.c md5.c md5module.c _randommodule.c _sre.c operator.c binascii.c pwdmodule.c posixmodule.c _struct.c datetimemodule.c _functoolsmodule.c _collectionsmodule.c itertoolsmodule.c resource.c signalmodule.c selectmodule.c fcntlmodule.c timemodule.c
)
file
(
GLOB_RECURSE STDMODULE_SRCS Modules errnomodule.c shamodule.c sha256module.c sha512module.c _math.c mathmodule.c md5.c md5module.c _randommodule.c _sre.c operator.c binascii.c pwdmodule.c posixmodule.c _struct.c datetimemodule.c _functoolsmodule.c _collectionsmodule.c itertoolsmodule.c resource.c signalmodule.c selectmodule.c fcntlmodule.c timemodule.c
arraymodule.c
)
# compile specified files in from_cpython/Objects
file
(
GLOB_RECURSE STDOBJECT_SRCS Objects structseq.c capsule.c stringobject.c
)
...
...
from_cpython/Modules/arraymodule.c
View file @
f17535bc
...
...
@@ -2249,6 +2249,13 @@ initarray(void)
Arraytype
.
ob_type
=
&
PyType_Type
;
PyArrayIter_Type
.
ob_type
=
&
PyType_Type
;
// Pyston change: let the GC know about our type
if
(
PyType_Ready
(
&
Arraytype
))
return
;
if
(
PyType_Ready
(
&
PyArrayIter_Type
))
return
;
m
=
Py_InitModule3
(
"array"
,
a_methods
,
module_doc
);
if
(
m
==
NULL
)
return
;
...
...
src/capi/typeobject.cpp
View file @
f17535bc
...
...
@@ -1729,7 +1729,6 @@ extern "C" int PyType_Ready(PyTypeObject* cls) noexcept {
RELEASE_ASSERT
(
cls
->
tp_getattro
==
NULL
||
cls
->
tp_getattro
==
PyObject_GenericGetAttr
,
""
);
RELEASE_ASSERT
(
cls
->
tp_setattro
==
NULL
||
cls
->
tp_setattro
==
PyObject_GenericSetAttr
,
""
);
RELEASE_ASSERT
(
cls
->
tp_as_buffer
==
NULL
,
""
);
int
ALLOWABLE_FLAGS
=
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_BASETYPE
|
Py_TPFLAGS_HAVE_GC
|
Py_TPFLAGS_CHECKTYPES
;
RELEASE_ASSERT
((
cls
->
tp_flags
&
~
ALLOWABLE_FLAGS
)
==
0
,
""
);
...
...
src/runtime/capi.cpp
View file @
f17535bc
...
...
@@ -738,6 +738,12 @@ extern "C" PyObject* PyErr_Format(PyObject* exception, const char* format, ...)
Py_FatalError
(
"unimplemented"
);
}
extern
"C"
int
PyErr_BadArgument
()
noexcept
{
// TODO this is untested
PyErr_SetString
(
PyExc_TypeError
,
"bad argument type for built-in operation"
);
return
0
;
}
extern
"C"
PyObject
*
PyErr_NoMemory
()
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
...
...
src/runtime/str.cpp
View file @
f17535bc
...
...
@@ -1835,8 +1835,25 @@ extern "C" int _PyString_Resize(PyObject** pv, Py_ssize_t newsize) noexcept {
return
0
;
}
extern
"C"
void
PyString_Concat
(
register
PyObject
**
pv
,
register
PyObject
*
w
)
noexcept
{
try
{
if
(
*
pv
==
NULL
)
return
;
if
(
w
==
NULL
||
!
PyString_Check
(
*
pv
))
{
*
pv
=
NULL
;
return
;
}
*
pv
=
strAdd
((
BoxedString
*
)
*
pv
,
w
);
}
catch
(
ExcInfo
e
)
{
setCAPIException
(
e
);
*
pv
=
NULL
;
}
}
extern
"C"
void
PyString_ConcatAndDel
(
register
PyObject
**
pv
,
register
PyObject
*
w
)
noexcept
{
Py
_FatalError
(
"unimplemented"
);
Py
String_Concat
(
pv
,
w
);
}
...
...
src/runtime/types.cpp
View file @
f17535bc
...
...
@@ -34,6 +34,7 @@
#include "runtime/objmodel.h"
#include "runtime/set.h"
#include "runtime/super.h"
#include "runtime/util.h"
extern
"C"
void
initerrno
();
extern
"C"
void
init_sha
();
...
...
@@ -57,6 +58,7 @@ extern "C" void initsignal();
extern
"C"
void
initselect
();
extern
"C"
void
initfcntl
();
extern
"C"
void
inittime
();
extern
"C"
void
initarray
();
namespace
pyston
{
...
...
@@ -727,9 +729,19 @@ extern "C" int PySlice_GetIndices(PySliceObject* r, Py_ssize_t length, Py_ssize_
Py_FatalError
(
"unimplemented"
);
}
extern
"C"
int
PySlice_GetIndicesEx
(
PySliceObject
*
r
,
Py_ssize_t
length
,
Py_ssize_t
*
start
,
Py_ssize_t
*
stop
,
extern
"C"
int
PySlice_GetIndicesEx
(
PySliceObject
*
_
r
,
Py_ssize_t
length
,
Py_ssize_t
*
start
,
Py_ssize_t
*
stop
,
Py_ssize_t
*
step
,
Py_ssize_t
*
slicelength
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
try
{
BoxedSlice
*
r
=
(
BoxedSlice
*
)
_r
;
assert
(
r
->
cls
==
slice_cls
);
// parseSlice has the exact same behaviour as CPythons PySlice_GetIndicesEx apart from throwing c++ exceptions
// on error.
parseSlice
(
r
,
length
,
start
,
stop
,
step
,
slicelength
);
}
catch
(
ExcInfo
e
)
{
setCAPIException
(
e
);
return
-
1
;
}
return
0
;
}
Box
*
typeRepr
(
BoxedClass
*
self
)
{
...
...
@@ -1192,6 +1204,7 @@ void setupRuntime() {
initselect
();
initfcntl
();
inittime
();
initarray
();
setupSysEnd
();
...
...
src/runtime/util.cpp
View file @
f17535bc
...
...
@@ -20,6 +20,7 @@
namespace
pyston
{
// Provides the exact same behaviour as CPythons PySlice_GetIndicesEx apart from throwing c++ exceptions on error
void
parseSlice
(
BoxedSlice
*
slice
,
int
size
,
i64
*
out_start
,
i64
*
out_stop
,
i64
*
out_step
,
i64
*
out_length
)
{
BoxedSlice
*
sslice
=
static_cast
<
BoxedSlice
*>
(
slice
);
...
...
@@ -91,8 +92,7 @@ void parseSlice(BoxedSlice* slice, int size, i64* out_start, i64* out_stop, i64*
else
*
out_length
=
(
istop
-
istart
-
1
)
/
istep
+
1
;
if
(
*
out_length
<
0
)
*
out_length
=
0
;
RELEASE_ASSERT
(
*
out_length
>=
0
,
"negative length, should never happen"
);
}
}
}
test/tests/array.py
0 → 100644
View file @
f17535bc
import
array
a
=
array
.
array
(
"c"
,
"hello world"
)
print
type
(
a
)
print
a
a
.
append
(
"!"
)
print
a
for
c
in
a
:
print
c
,
print
a
.
tostring
()
print
a
[
2
],
a
[
4
]
try
:
print
a
[
200
]
except
IndexError
:
print
"cought an IndexError"
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