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
09a5a8e0
Commit
09a5a8e0
authored
Nov 27, 2015
by
Boxiang Sun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some misc fixing
parent
b5682e5d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
17 deletions
+58
-17
src/runtime/capi.cpp
src/runtime/capi.cpp
+5
-3
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+1
-1
src/runtime/str.cpp
src/runtime/str.cpp
+37
-11
src/runtime/tuple.cpp
src/runtime/tuple.cpp
+3
-1
src/runtime/types.cpp
src/runtime/types.cpp
+11
-0
src/runtime/types.h
src/runtime/types.h
+1
-1
No files found.
src/runtime/capi.cpp
View file @
09a5a8e0
...
@@ -583,10 +583,12 @@ extern "C" int PyObject_IsTrue(PyObject* o) noexcept {
...
@@ -583,10 +583,12 @@ extern "C" int PyObject_IsTrue(PyObject* o) noexcept {
}
}
}
}
extern
"C"
int
PyObject_Not
(
PyObject
*
o
)
noexcept
{
extern
"C"
int
PyObject_Not
(
PyObject
*
o
)
noexcept
{
fatalOrError
(
PyExc_NotImplementedError
,
"unimplemented"
);
int
res
;
return
-
1
;
res
=
PyObject_IsTrue
(
o
);
if
(
res
<
0
)
return
res
;
return
res
==
0
;
}
}
extern
"C"
PyObject
*
PyObject_Call
(
PyObject
*
callable_object
,
PyObject
*
args
,
PyObject
*
kw
)
noexcept
{
extern
"C"
PyObject
*
PyObject_Call
(
PyObject
*
callable_object
,
PyObject
*
args
,
PyObject
*
kw
)
noexcept
{
...
...
src/runtime/objmodel.cpp
View file @
09a5a8e0
...
@@ -4160,7 +4160,7 @@ Box* callCLFunc(FunctionMetadata* md, CallRewriteArgs* rewrite_args, int num_out
...
@@ -4160,7 +4160,7 @@ Box* callCLFunc(FunctionMetadata* md, CallRewriteArgs* rewrite_args, int num_out
ASSERT
(
chosen_cf
->
spec
->
rtn_type
->
isFitBy
(
r
->
cls
),
"%s (%p) was supposed to return %s, but gave a %s"
,
ASSERT
(
chosen_cf
->
spec
->
rtn_type
->
isFitBy
(
r
->
cls
),
"%s (%p) was supposed to return %s, but gave a %s"
,
g
.
func_addr_registry
.
getFuncNameAtAddress
(
chosen_cf
->
code
,
true
,
NULL
).
c_str
(),
chosen_cf
->
code
,
g
.
func_addr_registry
.
getFuncNameAtAddress
(
chosen_cf
->
code
,
true
,
NULL
).
c_str
(),
chosen_cf
->
code
,
chosen_cf
->
spec
->
rtn_type
->
debugName
().
c_str
(),
r
->
cls
->
tp_name
);
chosen_cf
->
spec
->
rtn_type
->
debugName
().
c_str
(),
r
->
cls
->
tp_name
);
ASSERT
(
!
PyErr_Occurred
(),
"%p"
,
chosen_cf
->
code
);
ASSERT
(
!
PyErr_Occurred
()
||
S
==
CAPI
,
"%p"
,
chosen_cf
->
code
);
}
}
return
r
;
return
r
;
...
...
src/runtime/str.cpp
View file @
09a5a8e0
...
@@ -1226,9 +1226,13 @@ Box* str_richcompare(Box* lhs, Box* rhs, int op) {
...
@@ -1226,9 +1226,13 @@ Box* str_richcompare(Box* lhs, Box* rhs, int op) {
#define JUST_RIGHT 1
#define JUST_RIGHT 1
#define JUST_CENTER 2
#define JUST_CENTER 2
static
Box
*
pad
(
BoxedString
*
self
,
Box
*
width
,
Box
*
fillchar
,
int
justType
)
{
static
Box
*
pad
(
BoxedString
*
self
,
Box
*
width
,
Box
*
fillchar
,
int
justType
)
{
assert
(
width
->
cls
==
int_cls
);
if
(
!
PyInt_Check
(
width
))
{
assert
(
PyString_Check
(
fillchar
));
raiseExcHelper
(
TypeError
,
"an integer is required"
);
assert
(
static_cast
<
BoxedString
*>
(
fillchar
)
->
size
()
==
1
);
}
if
(
!
PyString_Check
(
fillchar
)
||
static_cast
<
BoxedString
*>
(
fillchar
)
->
size
()
!=
1
)
{
raiseExcHelper
(
TypeError
,
"must be char, not %s"
,
fillchar
->
cls
->
tp_name
);
}
int64_t
curWidth
=
self
->
size
();
int64_t
curWidth
=
self
->
size
();
int64_t
targetWidth
=
static_cast
<
BoxedInt
*>
(
width
)
->
n
;
int64_t
targetWidth
=
static_cast
<
BoxedInt
*>
(
width
)
->
n
;
...
@@ -1628,11 +1632,11 @@ extern "C" Box* strNonzero(BoxedString* self) {
...
@@ -1628,11 +1632,11 @@ extern "C" Box* strNonzero(BoxedString* self) {
return
boxBool
(
self
->
size
()
!=
0
);
return
boxBool
(
self
->
size
()
!=
0
);
}
}
extern
"C"
Box
*
strNew
(
BoxedClass
*
cls
,
Box
*
obj
)
{
template
<
ExceptionStyle
S
>
Box
*
strNew
(
BoxedClass
*
cls
,
Box
*
obj
)
{
assert
(
isSubclass
(
cls
,
str_cls
));
assert
(
isSubclass
(
cls
,
str_cls
));
if
(
cls
!=
str_cls
)
{
if
(
cls
!=
str_cls
)
{
Box
*
tmp
=
strNew
(
str_cls
,
obj
);
Box
*
tmp
=
strNew
<
S
>
(
str_cls
,
obj
);
assert
(
PyString_Check
(
tmp
));
assert
(
PyString_Check
(
tmp
));
BoxedString
*
tmp_s
=
static_cast
<
BoxedString
*>
(
tmp
);
BoxedString
*
tmp_s
=
static_cast
<
BoxedString
*>
(
tmp
);
...
@@ -1640,10 +1644,30 @@ extern "C" Box* strNew(BoxedClass* cls, Box* obj) {
...
@@ -1640,10 +1644,30 @@ extern "C" Box* strNew(BoxedClass* cls, Box* obj) {
}
}
Box
*
r
=
PyObject_Str
(
obj
);
Box
*
r
=
PyObject_Str
(
obj
);
if
(
!
r
)
if
(
S
==
CAPI
)
throwCAPIException
();
return
r
;
assert
(
PyString_Check
(
r
));
else
{
return
r
;
if
(
!
r
)
throwCAPIException
();
assert
(
PyString_Check
(
r
));
return
r
;
}
}
// Roughly analogous to CPython's string_new.
// The arguments need to be unpacked from args and kwds.
static
Box
*
strNewPacked
(
BoxedClass
*
type
,
Box
*
args
,
Box
*
kwds
)
noexcept
{
PyObject
*
x
=
NULL
;
static
char
*
kwlist
[
2
]
=
{
NULL
,
NULL
};
kwlist
[
0
]
=
const_cast
<
char
*>
(
"object"
);
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"|O:str"
,
kwlist
,
&
x
))
return
NULL
;
if
(
x
==
NULL
)
return
PyString_FromString
(
""
);
return
strNew
<
CAPI
>
(
type
,
x
);
}
}
extern
"C"
Box
*
basestringNew
(
BoxedClass
*
cls
,
Box
*
args
,
Box
*
kwargs
)
{
extern
"C"
Box
*
basestringNew
(
BoxedClass
*
cls
,
Box
*
args
,
Box
*
kwargs
)
{
...
@@ -2898,8 +2922,9 @@ void setupStr() {
...
@@ -2898,8 +2922,9 @@ void setupStr() {
str_cls
->
giveAttr
(
md
.
ml_name
,
new
BoxedMethodDescriptor
(
&
md
,
str_cls
));
str_cls
->
giveAttr
(
md
.
ml_name
,
new
BoxedMethodDescriptor
(
&
md
,
str_cls
));
}
}
str_cls
->
giveAttr
(
"__new__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
strNew
,
UNKNOWN
,
2
,
false
,
false
),
auto
str_new
=
FunctionMetadata
::
create
((
void
*
)
strNew
<
CXX
>
,
UNKNOWN
,
2
,
false
,
false
,
ParamNames
::
empty
(),
CXX
);
{
EmptyString
}));
str_new
->
addVersion
((
void
*
)
strNew
<
CAPI
>
,
UNKNOWN
,
CAPI
);
str_cls
->
giveAttr
(
"__new__"
,
new
BoxedFunction
(
str_new
,
{
EmptyString
}));
add_operators
(
str_cls
);
add_operators
(
str_cls
);
str_cls
->
freeze
();
str_cls
->
freeze
();
...
@@ -2912,6 +2937,7 @@ void setupStr() {
...
@@ -2912,6 +2937,7 @@ void setupStr() {
str_cls
->
tp_as_sequence
->
sq_item
=
(
ssizeargfunc
)
string_item
;
str_cls
->
tp_as_sequence
->
sq_item
=
(
ssizeargfunc
)
string_item
;
str_cls
->
tp_as_sequence
->
sq_slice
=
str_slice
;
str_cls
->
tp_as_sequence
->
sq_slice
=
str_slice
;
str_cls
->
tp_as_sequence
->
sq_contains
=
(
objobjproc
)
string_contains
;
str_cls
->
tp_as_sequence
->
sq_contains
=
(
objobjproc
)
string_contains
;
str_cls
->
tp_new
=
(
newfunc
)
strNewPacked
;
basestring_cls
->
giveAttr
(
"__doc__"
,
basestring_cls
->
giveAttr
(
"__doc__"
,
boxString
(
"Type basestring cannot be instantiated; it is the base for str and unicode."
));
boxString
(
"Type basestring cannot be instantiated; it is the base for str and unicode."
));
...
...
src/runtime/tuple.cpp
View file @
09a5a8e0
...
@@ -156,9 +156,11 @@ template <ExceptionStyle S> Box* tupleGetitem(BoxedTuple* self, Box* slice) {
...
@@ -156,9 +156,11 @@ template <ExceptionStyle S> Box* tupleGetitem(BoxedTuple* self, Box* slice) {
raiseExcHelper
(
TypeError
,
"tuple indices must be integers, not %s"
,
getTypeName
(
slice
));
raiseExcHelper
(
TypeError
,
"tuple indices must be integers, not %s"
,
getTypeName
(
slice
));
}
}
// TODO: duplicate with tupleconcat?
Box
*
tupleAdd
(
BoxedTuple
*
self
,
Box
*
rhs
)
{
Box
*
tupleAdd
(
BoxedTuple
*
self
,
Box
*
rhs
)
{
if
(
!
PyTuple_Check
(
rhs
))
{
if
(
!
PyTuple_Check
(
rhs
))
{
return
NotImplemented
;
raiseExcHelper
(
TypeError
,
"can only concatenate tuple (not
\"
%.200s
\"
) to tuple"
,
getTypeName
(
rhs
));
return
NULL
;
}
}
BoxedTuple
*
_rhs
=
static_cast
<
BoxedTuple
*>
(
rhs
);
BoxedTuple
*
_rhs
=
static_cast
<
BoxedTuple
*>
(
rhs
);
...
...
src/runtime/types.cpp
View file @
09a5a8e0
...
@@ -3568,6 +3568,9 @@ static Box* getsetGet(Box* self, Box* obj, Box* type) {
...
@@ -3568,6 +3568,9 @@ static Box* getsetGet(Box* self, Box* obj, Box* type) {
return
self
;
return
self
;
BoxedGetsetDescriptor
*
getset_descr
=
static_cast
<
BoxedGetsetDescriptor
*>
(
self
);
BoxedGetsetDescriptor
*
getset_descr
=
static_cast
<
BoxedGetsetDescriptor
*>
(
self
);
assert
(
getset_descr
->
get
!=
NULL
);
if
(
isSubclass
(
self
->
cls
,
pyston_getset_cls
))
{
if
(
isSubclass
(
self
->
cls
,
pyston_getset_cls
))
{
return
getset_descr
->
get
(
obj
,
getset_descr
->
closure
);
return
getset_descr
->
get
(
obj
,
getset_descr
->
closure
);
}
else
{
}
else
{
...
@@ -3583,6 +3586,10 @@ static Box* getsetSet(Box* self, Box* obj, Box* val) {
...
@@ -3583,6 +3586,10 @@ static Box* getsetSet(Box* self, Box* obj, Box* val) {
assert
(
obj
!=
NULL
&&
obj
!=
None
);
assert
(
obj
!=
NULL
&&
obj
!=
None
);
BoxedGetsetDescriptor
*
getset_descr
=
static_cast
<
BoxedGetsetDescriptor
*>
(
self
);
BoxedGetsetDescriptor
*
getset_descr
=
static_cast
<
BoxedGetsetDescriptor
*>
(
self
);
if
(
getset_descr
->
set
==
NULL
)
return
None
;
if
(
isSubclass
(
self
->
cls
,
pyston_getset_cls
))
{
if
(
isSubclass
(
self
->
cls
,
pyston_getset_cls
))
{
getset_descr
->
set
(
obj
,
val
,
getset_descr
->
closure
);
getset_descr
->
set
(
obj
,
val
,
getset_descr
->
closure
);
return
None
;
return
None
;
...
@@ -3598,6 +3605,10 @@ static Box* getsetDelete(Box* self, Box* obj) {
...
@@ -3598,6 +3605,10 @@ static Box* getsetDelete(Box* self, Box* obj) {
assert
(
obj
!=
NULL
&&
obj
!=
None
);
assert
(
obj
!=
NULL
&&
obj
!=
None
);
BoxedGetsetDescriptor
*
getset_descr
=
static_cast
<
BoxedGetsetDescriptor
*>
(
self
);
BoxedGetsetDescriptor
*
getset_descr
=
static_cast
<
BoxedGetsetDescriptor
*>
(
self
);
if
(
getset_descr
->
set
==
NULL
)
return
None
;
if
(
isSubclass
(
self
->
cls
,
pyston_getset_cls
))
{
if
(
isSubclass
(
self
->
cls
,
pyston_getset_cls
))
{
getset_descr
->
set
(
obj
,
NULL
,
getset_descr
->
closure
);
getset_descr
->
set
(
obj
,
NULL
,
getset_descr
->
closure
);
return
None
;
return
None
;
...
...
src/runtime/types.h
View file @
09a5a8e0
...
@@ -429,7 +429,7 @@ public:
...
@@ -429,7 +429,7 @@ public:
assert
(
str_cls
->
is_pyston_class
);
assert
(
str_cls
->
is_pyston_class
);
assert
(
str_cls
->
attrs_offset
==
0
);
assert
(
str_cls
->
attrs_offset
==
0
);
void
*
mem
=
gc_alloc
(
sizeof
(
BoxedString
)
+
1
+
nitems
,
gc
::
GCKind
::
PYTHON
);
void
*
mem
=
gc_alloc
(
sizeof
(
BoxedString
)
+
2
+
nitems
,
gc
::
GCKind
::
PYTHON
);
assert
(
mem
);
assert
(
mem
);
BoxVar
*
rtn
=
static_cast
<
BoxVar
*>
(
mem
);
BoxVar
*
rtn
=
static_cast
<
BoxVar
*>
(
mem
);
...
...
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