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
d84100af
Commit
d84100af
authored
Aug 27, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #140 from tjhance/basestring
basestring
parents
d021017c
69c1a6d4
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
27 additions
and
4 deletions
+27
-4
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+1
-0
src/runtime/str.cpp
src/runtime/str.cpp
+11
-0
src/runtime/types.cpp
src/runtime/types.cpp
+7
-3
src/runtime/types.h
src/runtime/types.h
+1
-1
test/tests/basestring.py
test/tests/basestring.py
+7
-0
No files found.
src/runtime/builtin_modules/builtins.cpp
View file @
d84100af
...
...
@@ -684,6 +684,7 @@ void setupBuiltins() {
builtins_module
->
giveAttr
(
"dir"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dir
,
LIST
,
1
,
1
,
false
,
false
),
{
NULL
}));
builtins_module
->
giveAttr
(
"object"
,
object_cls
);
builtins_module
->
giveAttr
(
"str"
,
str_cls
);
builtins_module
->
giveAttr
(
"basestring"
,
basestring_cls
);
builtins_module
->
giveAttr
(
"int"
,
int_cls
);
builtins_module
->
giveAttr
(
"long"
,
long_cls
);
builtins_module
->
giveAttr
(
"float"
,
float_cls
);
...
...
src/runtime/str.cpp
View file @
d84100af
...
...
@@ -353,6 +353,10 @@ extern "C" Box* strNew(BoxedClass* cls, Box* obj) {
return
str
(
obj
);
}
extern
"C"
Box
*
basestringNew
(
BoxedClass
*
cls
,
Box
*
args
,
Box
*
kwargs
)
{
raiseExcHelper
(
TypeError
,
"The basestring type cannot be instantiated"
);
}
Box
*
_strSlice
(
BoxedString
*
self
,
i64
start
,
i64
stop
,
i64
step
)
{
assert
(
self
->
cls
==
str_cls
);
...
...
@@ -954,6 +958,13 @@ void setupStr() {
{
boxStrConstant
(
""
)
}));
str_cls
->
freeze
();
basestring_cls
->
giveAttr
(
"__doc__"
,
boxStrConstant
(
"Type basestring cannot be instantiated; it is the base for str and unicode."
));
basestring_cls
->
giveAttr
(
"__new__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
basestringNew
,
UNKNOWN
,
1
,
0
,
true
,
true
)));
basestring_cls
->
giveAttr
(
"__name__"
,
boxStrConstant
(
"basestring"
));
basestring_cls
->
freeze
();
}
void
teardownStr
()
{
...
...
src/runtime/types.cpp
View file @
d84100af
...
...
@@ -300,7 +300,7 @@ extern "C" void closureGCHandler(GCVisitor* v, Box* b) {
extern
"C"
{
BoxedClass
*
object_cls
,
*
type_cls
,
*
none_cls
,
*
bool_cls
,
*
int_cls
,
*
float_cls
,
*
str_cls
,
*
function_cls
,
*
instancemethod_cls
,
*
list_cls
,
*
slice_cls
,
*
module_cls
,
*
dict_cls
,
*
tuple_cls
,
*
file_cls
,
*
member_cls
,
*
closure_cls
,
*
generator_cls
,
*
complex_cls
;
*
closure_cls
,
*
generator_cls
,
*
complex_cls
,
*
basestring_cls
;
BoxedTuple
*
EmptyTuple
;
...
...
@@ -646,12 +646,16 @@ void setupRuntime() {
None
=
new
Box
(
none_cls
);
gc
::
registerPermanentRoot
(
None
);
// You can't actually have an instance of basestring
basestring_cls
=
new
BoxedClass
(
type_cls
,
object_cls
,
NULL
,
0
,
sizeof
(
Box
),
false
);
// TODO we leak all the string data!
str_cls
=
new
BoxedClass
(
type_cls
,
object
_cls
,
NULL
,
0
,
sizeof
(
BoxedString
),
false
);
str_cls
=
new
BoxedClass
(
type_cls
,
basestring
_cls
,
NULL
,
0
,
sizeof
(
BoxedString
),
false
);
// It wasn't safe to add __base__ attributes until object+type+str are set up, so do that now:
type_cls
->
giveAttr
(
"__base__"
,
object_cls
);
str_cls
->
giveAttr
(
"__base__"
,
object_cls
);
basestring_cls
->
giveAttr
(
"__base__"
,
object_cls
);
str_cls
->
giveAttr
(
"__base__"
,
basestring_cls
);
none_cls
->
giveAttr
(
"__base__"
,
object_cls
);
object_cls
->
giveAttr
(
"__base__"
,
None
);
...
...
src/runtime/types.h
View file @
d84100af
...
...
@@ -77,7 +77,7 @@ Box* getSysStdout();
extern
"C"
{
extern
BoxedClass
*
object_cls
,
*
type_cls
,
*
bool_cls
,
*
int_cls
,
*
long_cls
,
*
float_cls
,
*
str_cls
,
*
function_cls
,
*
none_cls
,
*
instancemethod_cls
,
*
list_cls
,
*
slice_cls
,
*
module_cls
,
*
dict_cls
,
*
tuple_cls
,
*
file_cls
,
*
xrange_cls
,
*
member_cls
,
*
method_cls
,
*
closure_cls
,
*
generator_cls
,
*
complex_cls
;
*
member_cls
,
*
method_cls
,
*
closure_cls
,
*
generator_cls
,
*
complex_cls
,
*
basestring_cls
;
}
extern
"C"
{
extern
Box
*
None
,
*
NotImplemented
,
*
True
,
*
False
;
}
extern
"C"
{
...
...
test/tests/basestring.py
0 → 100644
View file @
d84100af
print
isinstance
(
""
,
basestring
)
print
isinstance
(
3
,
basestring
)
print
basestring
.
__doc__
# should raise an exception
t
=
basestring
.
__new__
(
basestring
)
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