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
56f2d23f
Commit
56f2d23f
authored
May 21, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #546 from tjhance/clean-boxed-string
remove the llvm::StringRef from BoxedString
parents
9f318d52
283f90df
Changes
24
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
178 additions
and
178 deletions
+178
-178
src/analysis/scoping_analysis.cpp
src/analysis/scoping_analysis.cpp
+5
-5
src/capi/object.cpp
src/capi/object.cpp
+4
-4
src/codegen/ast_interpreter.cpp
src/codegen/ast_interpreter.cpp
+1
-1
src/codegen/irgen/hooks.cpp
src/codegen/irgen/hooks.cpp
+5
-5
src/codegen/pypa-parser.cpp
src/codegen/pypa-parser.cpp
+5
-5
src/core/cfg.cpp
src/core/cfg.cpp
+1
-1
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+10
-10
src/runtime/builtin_modules/pyston.cpp
src/runtime/builtin_modules/pyston.cpp
+2
-2
src/runtime/builtin_modules/thread.cpp
src/runtime/builtin_modules/thread.cpp
+2
-2
src/runtime/capi.cpp
src/runtime/capi.cpp
+2
-2
src/runtime/classobj.cpp
src/runtime/classobj.cpp
+21
-21
src/runtime/dict.cpp
src/runtime/dict.cpp
+2
-2
src/runtime/file.cpp
src/runtime/file.cpp
+2
-2
src/runtime/float.cpp
src/runtime/float.cpp
+1
-1
src/runtime/import.cpp
src/runtime/import.cpp
+20
-20
src/runtime/list.cpp
src/runtime/list.cpp
+1
-1
src/runtime/long.cpp
src/runtime/long.cpp
+2
-2
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+9
-9
src/runtime/set.cpp
src/runtime/set.cpp
+1
-1
src/runtime/str.cpp
src/runtime/str.cpp
+53
-54
src/runtime/super.cpp
src/runtime/super.cpp
+3
-3
src/runtime/tuple.cpp
src/runtime/tuple.cpp
+2
-2
src/runtime/types.cpp
src/runtime/types.cpp
+16
-16
src/runtime/types.h
src/runtime/types.h
+8
-7
No files found.
src/analysis/scoping_analysis.cpp
View file @
56f2d23f
...
@@ -59,14 +59,14 @@ bool containsYield(AST* ast) {
...
@@ -59,14 +59,14 @@ bool containsYield(AST* ast) {
BoxedString
*
mangleNameBoxedString
(
BoxedString
*
id
,
BoxedString
*
private_name
)
{
BoxedString
*
mangleNameBoxedString
(
BoxedString
*
id
,
BoxedString
*
private_name
)
{
assert
(
id
);
assert
(
id
);
assert
(
private_name
);
assert
(
private_name
);
int
len
=
id
->
s
.
s
ize
();
int
len
=
id
->
size
();
if
(
len
<
2
||
id
->
s
[
0
]
!=
'_'
||
id
->
s
[
1
]
!=
'_'
)
if
(
len
<
2
||
id
->
s
()[
0
]
!=
'_'
||
id
->
s
()
[
1
]
!=
'_'
)
return
id
;
return
id
;
if
((
id
->
s
[
len
-
2
]
==
'_'
&&
id
->
s
[
len
-
1
]
==
'_'
)
||
id
->
s
.
find
(
'.'
)
!=
llvm
::
StringRef
::
npos
)
if
((
id
->
s
()[
len
-
2
]
==
'_'
&&
id
->
s
()[
len
-
1
]
==
'_'
)
||
id
->
s
()
.
find
(
'.'
)
!=
llvm
::
StringRef
::
npos
)
return
id
;
return
id
;
const
char
*
p
=
private_name
->
s
.
data
();
const
char
*
p
=
private_name
->
data
();
while
(
*
p
==
'_'
)
{
while
(
*
p
==
'_'
)
{
p
++
;
p
++
;
len
--
;
len
--
;
...
@@ -74,7 +74,7 @@ BoxedString* mangleNameBoxedString(BoxedString* id, BoxedString* private_name) {
...
@@ -74,7 +74,7 @@ BoxedString* mangleNameBoxedString(BoxedString* id, BoxedString* private_name) {
if
(
*
p
==
'\0'
)
if
(
*
p
==
'\0'
)
return
id
;
return
id
;
return
static_cast
<
BoxedString
*>
(
boxStringTwine
(
"_"
+
(
p
+
id
->
s
)));
return
static_cast
<
BoxedString
*>
(
boxStringTwine
(
"_"
+
(
p
+
id
->
s
()
)));
}
}
static
void
mangleNameInPlace
(
InternedString
&
id
,
const
std
::
string
*
private_name
,
static
void
mangleNameInPlace
(
InternedString
&
id
,
const
std
::
string
*
private_name
,
...
...
src/capi/object.cpp
View file @
56f2d23f
...
@@ -421,9 +421,9 @@ extern "C" PyObject* PyObject_SelfIter(PyObject* obj) noexcept {
...
@@ -421,9 +421,9 @@ extern "C" PyObject* PyObject_SelfIter(PyObject* obj) noexcept {
extern
"C"
int
PyObject_GenericSetAttr
(
PyObject
*
obj
,
PyObject
*
name
,
PyObject
*
value
)
noexcept
{
extern
"C"
int
PyObject_GenericSetAttr
(
PyObject
*
obj
,
PyObject
*
name
,
PyObject
*
value
)
noexcept
{
try
{
try
{
if
(
value
==
NULL
)
if
(
value
==
NULL
)
delattrGeneric
(
obj
,
std
::
string
(
static_cast
<
BoxedString
*>
(
name
)
->
s
),
NULL
);
delattrGeneric
(
obj
,
std
::
string
(
static_cast
<
BoxedString
*>
(
name
)
->
s
()
),
NULL
);
else
else
setattrGeneric
(
obj
,
std
::
string
(
static_cast
<
BoxedString
*>
(
name
)
->
s
),
value
,
NULL
);
setattrGeneric
(
obj
,
std
::
string
(
static_cast
<
BoxedString
*>
(
name
)
->
s
()
),
value
,
NULL
);
}
catch
(
ExcInfo
e
)
{
}
catch
(
ExcInfo
e
)
{
setCAPIException
(
e
);
setCAPIException
(
e
);
return
-
1
;
return
-
1
;
...
@@ -445,9 +445,9 @@ extern "C" int PyObject_SetAttr(PyObject* obj, PyObject* name, PyObject* value)
...
@@ -445,9 +445,9 @@ extern "C" int PyObject_SetAttr(PyObject* obj, PyObject* name, PyObject* value)
try
{
try
{
if
(
value
==
NULL
)
if
(
value
==
NULL
)
delattr
(
obj
,
static_cast
<
BoxedString
*>
(
name
)
->
s
.
data
());
delattr
(
obj
,
static_cast
<
BoxedString
*>
(
name
)
->
data
());
else
else
setattr
(
obj
,
static_cast
<
BoxedString
*>
(
name
)
->
s
.
data
(),
value
);
setattr
(
obj
,
static_cast
<
BoxedString
*>
(
name
)
->
data
(),
value
);
}
catch
(
ExcInfo
e
)
{
}
catch
(
ExcInfo
e
)
{
setCAPIException
(
e
);
setCAPIException
(
e
);
return
-
1
;
return
-
1
;
...
...
src/codegen/ast_interpreter.cpp
View file @
56f2d23f
...
@@ -1303,7 +1303,7 @@ Box* astInterpretFrom(CompiledFunction* cf, AST_expr* after_expr, AST_stmt* encl
...
@@ -1303,7 +1303,7 @@ Box* astInterpretFrom(CompiledFunction* cf, AST_expr* after_expr, AST_stmt* encl
for
(
const
auto
&
p
:
frame_state
.
locals
->
d
)
{
for
(
const
auto
&
p
:
frame_state
.
locals
->
d
)
{
assert
(
p
.
first
->
cls
==
str_cls
);
assert
(
p
.
first
->
cls
==
str_cls
);
auto
&
name
=
static_cast
<
BoxedString
*>
(
p
.
first
)
->
s
;
auto
name
=
static_cast
<
BoxedString
*>
(
p
.
first
)
->
s
()
;
if
(
name
==
PASSED_GENERATOR_NAME
)
{
if
(
name
==
PASSED_GENERATOR_NAME
)
{
interpreter
.
setGenerator
(
p
.
second
);
interpreter
.
setGenerator
(
p
.
second
);
}
else
if
(
name
==
PASSED_CLOSURE_NAME
)
{
}
else
if
(
name
==
PASSED_CLOSURE_NAME
)
{
...
...
src/codegen/irgen/hooks.cpp
View file @
56f2d23f
...
@@ -457,8 +457,8 @@ Box* compile(Box* source, Box* fn, Box* type, Box** _args) {
...
@@ -457,8 +457,8 @@ Box* compile(Box* source, Box* fn, Box* type, Box** _args) {
}
}
RELEASE_ASSERT
(
isSubclass
(
type
->
cls
,
str_cls
),
""
);
RELEASE_ASSERT
(
isSubclass
(
type
->
cls
,
str_cls
),
""
);
llvm
::
StringRef
filename_str
=
static_cast
<
BoxedString
*>
(
fn
)
->
s
;
llvm
::
StringRef
filename_str
=
static_cast
<
BoxedString
*>
(
fn
)
->
s
()
;
llvm
::
StringRef
type_str
=
static_cast
<
BoxedString
*>
(
type
)
->
s
;
llvm
::
StringRef
type_str
=
static_cast
<
BoxedString
*>
(
type
)
->
s
()
;
if
(
iflags
&
~
(
/*PyCF_MASK | PyCF_MASK_OBSOLETE | PyCF_DONT_IMPLY_DEDENT | */
PyCF_ONLY_AST
))
{
if
(
iflags
&
~
(
/*PyCF_MASK | PyCF_MASK_OBSOLETE | PyCF_DONT_IMPLY_DEDENT | */
PyCF_ONLY_AST
))
{
raiseExcHelper
(
ValueError
,
"compile(): unrecognised flags"
);
raiseExcHelper
(
ValueError
,
"compile(): unrecognised flags"
);
...
@@ -474,7 +474,7 @@ Box* compile(Box* source, Box* fn, Box* type, Box** _args) {
...
@@ -474,7 +474,7 @@ Box* compile(Box* source, Box* fn, Box* type, Box** _args) {
parsed
=
unboxAst
(
source
);
parsed
=
unboxAst
(
source
);
}
else
{
}
else
{
RELEASE_ASSERT
(
isSubclass
(
source
->
cls
,
str_cls
),
""
);
RELEASE_ASSERT
(
isSubclass
(
source
->
cls
,
str_cls
),
""
);
llvm
::
StringRef
source_str
=
static_cast
<
BoxedString
*>
(
source
)
->
s
;
llvm
::
StringRef
source_str
=
static_cast
<
BoxedString
*>
(
source
)
->
s
()
;
if
(
type_str
==
"exec"
)
{
if
(
type_str
==
"exec"
)
{
parsed
=
parseExec
(
source_str
);
parsed
=
parseExec
(
source_str
);
...
@@ -543,7 +543,7 @@ Box* eval(Box* boxedCode, Box* globals, Box* locals) {
...
@@ -543,7 +543,7 @@ Box* eval(Box* boxedCode, Box* globals, Box* locals) {
CLFunction
*
cl
;
CLFunction
*
cl
;
if
(
boxedCode
->
cls
==
str_cls
)
{
if
(
boxedCode
->
cls
==
str_cls
)
{
AST_Expression
*
parsed
=
parseEval
(
static_cast
<
BoxedString
*>
(
boxedCode
)
->
s
);
AST_Expression
*
parsed
=
parseEval
(
static_cast
<
BoxedString
*>
(
boxedCode
)
->
s
()
);
cl
=
compileEval
(
parsed
,
"<string>"
);
cl
=
compileEval
(
parsed
,
"<string>"
);
}
else
if
(
boxedCode
->
cls
==
code_cls
)
{
}
else
if
(
boxedCode
->
cls
==
code_cls
)
{
cl
=
clfunctionFromCode
(
boxedCode
);
cl
=
clfunctionFromCode
(
boxedCode
);
...
@@ -610,7 +610,7 @@ Box* exec(Box* boxedCode, Box* globals, Box* locals) {
...
@@ -610,7 +610,7 @@ Box* exec(Box* boxedCode, Box* globals, Box* locals) {
CLFunction
*
cl
;
CLFunction
*
cl
;
if
(
boxedCode
->
cls
==
str_cls
)
{
if
(
boxedCode
->
cls
==
str_cls
)
{
AST_Suite
*
parsed
=
parseExec
(
static_cast
<
BoxedString
*>
(
boxedCode
)
->
s
);
AST_Suite
*
parsed
=
parseExec
(
static_cast
<
BoxedString
*>
(
boxedCode
)
->
s
()
);
cl
=
compileExec
(
parsed
,
"<string>"
);
cl
=
compileExec
(
parsed
,
"<string>"
);
}
else
if
(
boxedCode
->
cls
==
code_cls
)
{
}
else
if
(
boxedCode
->
cls
==
code_cls
)
{
cl
=
clfunctionFromCode
(
boxedCode
);
cl
=
clfunctionFromCode
(
boxedCode
);
...
...
src/codegen/pypa-parser.cpp
View file @
56f2d23f
...
@@ -932,7 +932,7 @@ pypa::String pypaEscapeDecoder(const pypa::String& s, const pypa::String& encodi
...
@@ -932,7 +932,7 @@ pypa::String pypaEscapeDecoder(const pypa::String& s, const pypa::String& encodi
BoxedString
*
str_utf8
=
(
BoxedString
*
)
PyUnicode_AsUTF8String
(
str
);
BoxedString
*
str_utf8
=
(
BoxedString
*
)
PyUnicode_AsUTF8String
(
str
);
assert
(
str_utf8
->
cls
==
str_cls
);
assert
(
str_utf8
->
cls
==
str_cls
);
checkAndThrowCAPIException
();
checkAndThrowCAPIException
();
return
str_utf8
->
s
.
str
();
return
str_utf8
->
s
()
.
str
();
}
}
bool
need_encoding
=
encoding
!=
"utf-8"
&&
encoding
!=
"iso-8859-1"
;
bool
need_encoding
=
encoding
!=
"utf-8"
&&
encoding
!=
"iso-8859-1"
;
...
@@ -943,7 +943,7 @@ pypa::String pypaEscapeDecoder(const pypa::String& s, const pypa::String& encodi
...
@@ -943,7 +943,7 @@ pypa::String pypaEscapeDecoder(const pypa::String& s, const pypa::String& encodi
throwCAPIException
();
throwCAPIException
();
BoxedString
*
str
=
(
BoxedString
*
)
PyUnicode_AsEncodedString
(
u
,
encoding
.
c_str
(),
NULL
);
BoxedString
*
str
=
(
BoxedString
*
)
PyUnicode_AsEncodedString
(
u
,
encoding
.
c_str
(),
NULL
);
assert
(
str
->
cls
==
str_cls
);
assert
(
str
->
cls
==
str_cls
);
return
str
->
s
.
str
();
return
str
->
s
()
.
str
();
}
else
{
}
else
{
return
s
;
return
s
;
}
}
...
@@ -954,12 +954,12 @@ pypa::String pypaEscapeDecoder(const pypa::String& s, const pypa::String& encodi
...
@@ -954,12 +954,12 @@ pypa::String pypaEscapeDecoder(const pypa::String& s, const pypa::String& encodi
if
(
!
decoded
)
if
(
!
decoded
)
throwCAPIException
();
throwCAPIException
();
assert
(
decoded
->
cls
==
str_cls
);
assert
(
decoded
->
cls
==
str_cls
);
return
decoded
->
s
.
str
();
return
decoded
->
s
()
.
str
();
}
catch
(
ExcInfo
e
)
{
}
catch
(
ExcInfo
e
)
{
error
=
true
;
error
=
true
;
BoxedString
*
error_message
=
str
(
e
.
value
);
BoxedString
*
error_message
=
str
(
e
.
value
);
if
(
error_message
&&
error_message
->
cls
==
str_cls
)
if
(
error_message
&&
error_message
->
cls
==
str_cls
)
return
std
::
string
(
error_message
->
s
);
return
std
::
string
(
error_message
->
s
()
);
return
"Encountered an unknown error inside pypaEscapeDecoder"
;
return
"Encountered an unknown error inside pypaEscapeDecoder"
;
}
}
}
}
...
@@ -1080,7 +1080,7 @@ std::string PystonSourceReader::get_line() {
...
@@ -1080,7 +1080,7 @@ std::string PystonSourceReader::get_line() {
if
(
!
line
->
size
())
if
(
!
line
->
size
())
is_eof
=
true
;
is_eof
=
true
;
++
line_number
;
++
line_number
;
return
line
->
s
;
return
line
->
s
()
;
}
}
AST_Module
*
pypa_parse
(
char
const
*
file_path
)
{
AST_Module
*
pypa_parse
(
char
const
*
file_path
)
{
...
...
src/core/cfg.cpp
View file @
56f2d23f
...
@@ -2479,7 +2479,7 @@ CFG* computeCFG(SourceInfo* source, std::vector<AST_stmt*> body) {
...
@@ -2479,7 +2479,7 @@ CFG* computeCFG(SourceInfo* source, std::vector<AST_stmt*> body) {
if
(
source
->
scoping
->
areGlobalsFromModule
())
{
if
(
source
->
scoping
->
areGlobalsFromModule
())
{
Box
*
module_name
=
source
->
parent_module
->
getattr
(
"__name__"
,
NULL
);
Box
*
module_name
=
source
->
parent_module
->
getattr
(
"__name__"
,
NULL
);
assert
(
module_name
->
cls
==
str_cls
);
assert
(
module_name
->
cls
==
str_cls
);
module_assign
->
value
=
new
AST_Str
(
static_cast
<
BoxedString
*>
(
module_name
)
->
s
);
module_assign
->
value
=
new
AST_Str
(
static_cast
<
BoxedString
*>
(
module_name
)
->
s
()
);
}
else
{
}
else
{
module_assign
->
value
module_assign
->
value
=
new
AST_Name
(
source
->
getInternedStrings
().
get
(
"__name__"
),
AST_TYPE
::
Load
,
source
->
ast
->
lineno
);
=
new
AST_Name
(
source
->
getInternedStrings
().
get
(
"__name__"
),
AST_TYPE
::
Load
,
source
->
ast
->
lineno
);
...
...
src/runtime/builtin_modules/builtins.cpp
View file @
56f2d23f
...
@@ -402,7 +402,7 @@ Box* bltinImport(Box* name, Box* globals, Box* locals, Box** args) {
...
@@ -402,7 +402,7 @@ Box* bltinImport(Box* name, Box* globals, Box* locals, Box** args) {
raiseExcHelper
(
TypeError
,
"an integer is required"
);
raiseExcHelper
(
TypeError
,
"an integer is required"
);
}
}
std
::
string
_name
=
static_cast
<
BoxedString
*>
(
name
)
->
s
;
std
::
string
_name
=
static_cast
<
BoxedString
*>
(
name
)
->
s
()
;
return
importModuleLevel
(
_name
,
globals
,
fromlist
,
((
BoxedInt
*
)
level
)
->
n
);
return
importModuleLevel
(
_name
,
globals
,
fromlist
,
((
BoxedInt
*
)
level
)
->
n
);
}
}
...
@@ -412,7 +412,7 @@ Box* delattrFunc(Box* obj, Box* _str) {
...
@@ -412,7 +412,7 @@ Box* delattrFunc(Box* obj, Box* _str) {
if
(
_str
->
cls
!=
str_cls
)
if
(
_str
->
cls
!=
str_cls
)
raiseExcHelper
(
TypeError
,
"attribute name must be string, not '%s'"
,
getTypeName
(
_str
));
raiseExcHelper
(
TypeError
,
"attribute name must be string, not '%s'"
,
getTypeName
(
_str
));
BoxedString
*
str
=
static_cast
<
BoxedString
*>
(
_str
);
BoxedString
*
str
=
static_cast
<
BoxedString
*>
(
_str
);
delattr
(
obj
,
str
->
s
.
data
());
delattr
(
obj
,
str
->
data
());
return
None
;
return
None
;
}
}
...
@@ -427,7 +427,7 @@ Box* getattrFunc(Box* obj, Box* _str, Box* default_value) {
...
@@ -427,7 +427,7 @@ Box* getattrFunc(Box* obj, Box* _str, Box* default_value) {
Box
*
rtn
=
NULL
;
Box
*
rtn
=
NULL
;
try
{
try
{
rtn
=
getattr
(
obj
,
str
->
s
.
data
());
rtn
=
getattr
(
obj
,
str
->
data
());
}
catch
(
ExcInfo
e
)
{
}
catch
(
ExcInfo
e
)
{
if
(
!
e
.
matches
(
AttributeError
))
if
(
!
e
.
matches
(
AttributeError
))
throw
e
;
throw
e
;
...
@@ -437,7 +437,7 @@ Box* getattrFunc(Box* obj, Box* _str, Box* default_value) {
...
@@ -437,7 +437,7 @@ Box* getattrFunc(Box* obj, Box* _str, Box* default_value) {
if
(
default_value
)
if
(
default_value
)
return
default_value
;
return
default_value
;
else
else
raiseExcHelper
(
AttributeError
,
"'%s' object has no attribute '%s'"
,
getTypeName
(
obj
),
str
->
s
.
data
());
raiseExcHelper
(
AttributeError
,
"'%s' object has no attribute '%s'"
,
getTypeName
(
obj
),
str
->
data
());
}
}
return
rtn
;
return
rtn
;
...
@@ -451,7 +451,7 @@ Box* setattrFunc(Box* obj, Box* _str, Box* value) {
...
@@ -451,7 +451,7 @@ Box* setattrFunc(Box* obj, Box* _str, Box* value) {
}
}
BoxedString
*
str
=
static_cast
<
BoxedString
*>
(
_str
);
BoxedString
*
str
=
static_cast
<
BoxedString
*>
(
_str
);
setattr
(
obj
,
str
->
s
.
data
(),
value
);
setattr
(
obj
,
str
->
data
(),
value
);
return
None
;
return
None
;
}
}
...
@@ -465,7 +465,7 @@ Box* hasattr(Box* obj, Box* _str) {
...
@@ -465,7 +465,7 @@ Box* hasattr(Box* obj, Box* _str) {
BoxedString
*
str
=
static_cast
<
BoxedString
*>
(
_str
);
BoxedString
*
str
=
static_cast
<
BoxedString
*>
(
_str
);
Box
*
attr
;
Box
*
attr
;
try
{
try
{
attr
=
getattrInternal
(
obj
,
str
->
s
,
NULL
);
attr
=
getattrInternal
(
obj
,
str
->
s
()
,
NULL
);
}
catch
(
ExcInfo
e
)
{
}
catch
(
ExcInfo
e
)
{
if
(
e
.
matches
(
Exception
))
if
(
e
.
matches
(
Exception
))
return
False
;
return
False
;
...
@@ -672,7 +672,7 @@ Box* exceptionRepr(Box* b) {
...
@@ -672,7 +672,7 @@ Box* exceptionRepr(Box* b) {
assert
(
message
->
cls
==
str_cls
);
assert
(
message
->
cls
==
str_cls
);
BoxedString
*
message_s
=
static_cast
<
BoxedString
*>
(
message
);
BoxedString
*
message_s
=
static_cast
<
BoxedString
*>
(
message
);
return
boxStringTwine
(
llvm
::
Twine
(
getTypeName
(
b
))
+
"("
+
message_s
->
s
+
",)"
);
return
boxStringTwine
(
llvm
::
Twine
(
getTypeName
(
b
))
+
"("
+
message_s
->
s
()
+
",)"
);
}
}
static
BoxedClass
*
makeBuiltinException
(
BoxedClass
*
base
,
const
char
*
name
,
int
size
=
0
)
{
static
BoxedClass
*
makeBuiltinException
(
BoxedClass
*
base
,
const
char
*
name
,
int
size
=
0
)
{
...
@@ -833,14 +833,14 @@ Box* execfile(Box* _fn) {
...
@@ -833,14 +833,14 @@ Box* execfile(Box* _fn) {
#endif
#endif
#else
#else
bool
exists
=
llvm
::
sys
::
fs
::
exists
(
std
::
string
(
fn
->
s
));
bool
exists
=
llvm
::
sys
::
fs
::
exists
(
std
::
string
(
fn
->
s
()
));
#endif
#endif
if
(
!
exists
)
if
(
!
exists
)
raiseExcHelper
(
IOError
,
"No such file or directory: '%s'"
,
fn
->
s
.
data
());
raiseExcHelper
(
IOError
,
"No such file or directory: '%s'"
,
fn
->
data
());
// Run directly inside the current module:
// Run directly inside the current module:
AST_Module
*
ast
=
caching_parse_file
(
fn
->
s
.
data
());
AST_Module
*
ast
=
caching_parse_file
(
fn
->
data
());
ASSERT
(
getExecutionPoint
().
cf
->
clfunc
->
source
->
scoping
->
areGlobalsFromModule
(),
"need to pass custom globals in"
);
ASSERT
(
getExecutionPoint
().
cf
->
clfunc
->
source
->
scoping
->
areGlobalsFromModule
(),
"need to pass custom globals in"
);
compileAndRunModule
(
ast
,
getCurrentModule
());
compileAndRunModule
(
ast
,
getCurrentModule
());
...
...
src/runtime/builtin_modules/pyston.cpp
View file @
56f2d23f
...
@@ -30,7 +30,7 @@ static Box* setOption(Box* option, Box* value) {
...
@@ -30,7 +30,7 @@ static Box* setOption(Box* option, Box* value) {
int
n
=
((
BoxedInt
*
)
value
)
->
n
;
int
n
=
((
BoxedInt
*
)
value
)
->
n
;
#define CHECK(_s) \
#define CHECK(_s) \
if (option_string->s
== STRINGIFY(_s))
\
if (option_string->s
() == STRINGIFY(_s))
\
_s = n
_s = n
// :)
// :)
...
@@ -43,7 +43,7 @@ static Box* setOption(Box* option, Box* value) {
...
@@ -43,7 +43,7 @@ static Box* setOption(Box* option, Box* value) {
else
CHECK
(
REOPT_THRESHOLD_BASELINE
);
else
CHECK
(
REOPT_THRESHOLD_BASELINE
);
else
CHECK
(
OSR_THRESHOLD_BASELINE
);
else
CHECK
(
OSR_THRESHOLD_BASELINE
);
else
CHECK
(
SPECULATION_THRESHOLD
);
else
CHECK
(
SPECULATION_THRESHOLD
);
else
raiseExcHelper
(
ValueError
,
"unknown option name '%s"
,
option_string
->
s
.
data
());
else
raiseExcHelper
(
ValueError
,
"unknown option name '%s"
,
option_string
->
data
());
return
None
;
return
None
;
}
}
...
...
src/runtime/builtin_modules/thread.cpp
View file @
56f2d23f
...
@@ -168,7 +168,7 @@ public:
...
@@ -168,7 +168,7 @@ public:
}
}
static
Box
*
setattrPyston
(
Box
*
obj
,
Box
*
name
,
Box
*
val
)
noexcept
{
static
Box
*
setattrPyston
(
Box
*
obj
,
Box
*
name
,
Box
*
val
)
noexcept
{
if
(
isSubclass
(
name
->
cls
,
str_cls
)
&&
static_cast
<
BoxedString
*>
(
name
)
->
s
==
"__dict__"
)
{
if
(
isSubclass
(
name
->
cls
,
str_cls
)
&&
static_cast
<
BoxedString
*>
(
name
)
->
s
()
==
"__dict__"
)
{
raiseExcHelper
(
AttributeError
,
"'%.50s' object attribute '__dict__' is read-only"
,
Py_TYPE
(
obj
)
->
tp_name
);
raiseExcHelper
(
AttributeError
,
"'%.50s' object attribute '__dict__' is read-only"
,
Py_TYPE
(
obj
)
->
tp_name
);
}
}
...
@@ -189,7 +189,7 @@ public:
...
@@ -189,7 +189,7 @@ public:
static
Box
*
getattro
(
Box
*
obj
,
Box
*
name
)
noexcept
{
static
Box
*
getattro
(
Box
*
obj
,
Box
*
name
)
noexcept
{
assert
(
name
->
cls
==
str_cls
);
assert
(
name
->
cls
==
str_cls
);
llvm
::
StringRef
s
=
static_cast
<
BoxedString
*>
(
name
)
->
s
;
llvm
::
StringRef
s
=
static_cast
<
BoxedString
*>
(
name
)
->
s
()
;
Box
*
tls_obj
=
getThreadLocalObject
(
obj
);
Box
*
tls_obj
=
getThreadLocalObject
(
obj
);
if
(
s
==
"__dict__"
)
if
(
s
==
"__dict__"
)
...
...
src/runtime/capi.cpp
View file @
56f2d23f
...
@@ -258,7 +258,7 @@ extern "C" PyObject* PyObject_GetAttr(PyObject* o, PyObject* attr_name) noexcept
...
@@ -258,7 +258,7 @@ extern "C" PyObject* PyObject_GetAttr(PyObject* o, PyObject* attr_name) noexcept
extern
"C"
PyObject
*
PyObject_GenericGetAttr
(
PyObject
*
o
,
PyObject
*
name
)
noexcept
{
extern
"C"
PyObject
*
PyObject_GenericGetAttr
(
PyObject
*
o
,
PyObject
*
name
)
noexcept
{
try
{
try
{
Box
*
r
=
getattrInternalGeneric
(
o
,
static_cast
<
BoxedString
*>
(
name
)
->
s
.
data
(),
NULL
,
false
,
false
,
NULL
,
NULL
);
Box
*
r
=
getattrInternalGeneric
(
o
,
static_cast
<
BoxedString
*>
(
name
)
->
data
(),
NULL
,
false
,
false
,
NULL
,
NULL
);
if
(
!
r
)
if
(
!
r
)
PyErr_Format
(
PyExc_AttributeError
,
"'%.50s' object has no attribute '%.400s'"
,
o
->
cls
->
tp_name
,
PyErr_Format
(
PyExc_AttributeError
,
"'%.50s' object has no attribute '%.400s'"
,
o
->
cls
->
tp_name
,
PyString_AS_STRING
(
name
));
PyString_AS_STRING
(
name
));
...
@@ -868,7 +868,7 @@ extern "C" PyObject* PyImport_Import(PyObject* module_name) noexcept {
...
@@ -868,7 +868,7 @@ extern "C" PyObject* PyImport_Import(PyObject* module_name) noexcept {
RELEASE_ASSERT
(
module_name
->
cls
==
str_cls
,
""
);
RELEASE_ASSERT
(
module_name
->
cls
==
str_cls
,
""
);
try
{
try
{
std
::
string
_module_name
=
static_cast
<
BoxedString
*>
(
module_name
)
->
s
;
std
::
string
_module_name
=
static_cast
<
BoxedString
*>
(
module_name
)
->
s
()
;
return
importModuleLevel
(
_module_name
,
None
,
None
,
-
1
);
return
importModuleLevel
(
_module_name
,
None
,
None
,
-
1
);
}
catch
(
ExcInfo
e
)
{
}
catch
(
ExcInfo
e
)
{
fatalOrError
(
PyExc_NotImplementedError
,
"unimplemented"
);
fatalOrError
(
PyExc_NotImplementedError
,
"unimplemented"
);
...
...
src/runtime/classobj.cpp
View file @
56f2d23f
...
@@ -104,7 +104,7 @@ Box* classobjNew(Box* _cls, Box* _name, Box* _bases, Box** _args) {
...
@@ -104,7 +104,7 @@ Box* classobjNew(Box* _cls, Box* _name, Box* _bases, Box** _args) {
for
(
auto
&
p
:
dict
->
d
)
{
for
(
auto
&
p
:
dict
->
d
)
{
RELEASE_ASSERT
(
p
.
first
->
cls
==
str_cls
,
""
);
RELEASE_ASSERT
(
p
.
first
->
cls
==
str_cls
,
""
);
made
->
setattr
(
std
::
string
(
static_cast
<
BoxedString
*>
(
p
.
first
)
->
s
),
p
.
second
,
NULL
);
made
->
setattr
(
std
::
string
(
static_cast
<
BoxedString
*>
(
p
.
first
)
->
s
()
),
p
.
second
,
NULL
);
}
}
// Note: make sure to do this after assigning the attrs, since it will overwrite any defined __name__
// Note: make sure to do this after assigning the attrs, since it will overwrite any defined __name__
...
@@ -148,21 +148,21 @@ static Box* classobjGetattribute(Box* _cls, Box* _attr) {
...
@@ -148,21 +148,21 @@ static Box* classobjGetattribute(Box* _cls, Box* _attr) {
BoxedString
*
attr
=
static_cast
<
BoxedString
*>
(
_attr
);
BoxedString
*
attr
=
static_cast
<
BoxedString
*>
(
_attr
);
// These are special cases in CPython as well:
// These are special cases in CPython as well:
if
(
attr
->
s
[
0
]
==
'_'
&&
attr
->
s
[
1
]
==
'_'
)
{
if
(
attr
->
s
()[
0
]
==
'_'
&&
attr
->
s
()
[
1
]
==
'_'
)
{
if
(
attr
->
s
==
"__dict__"
)
if
(
attr
->
s
()
==
"__dict__"
)
return
cls
->
getAttrWrapper
();
return
cls
->
getAttrWrapper
();
if
(
attr
->
s
==
"__bases__"
)
if
(
attr
->
s
()
==
"__bases__"
)
return
cls
->
bases
;
return
cls
->
bases
;
if
(
attr
->
s
==
"__name__"
)
{
if
(
attr
->
s
()
==
"__name__"
)
{
if
(
cls
->
name
)
if
(
cls
->
name
)
return
cls
->
name
;
return
cls
->
name
;
return
None
;
return
None
;
}
}
}
}
Box
*
r
=
classLookup
(
cls
,
std
::
string
(
attr
->
s
));
Box
*
r
=
classLookup
(
cls
,
std
::
string
(
attr
->
s
()
));
if
(
!
r
)
if
(
!
r
)
raiseExcHelper
(
AttributeError
,
"class %s has no attribute '%s'"
,
cls
->
name
->
data
(),
attr
->
data
());
raiseExcHelper
(
AttributeError
,
"class %s has no attribute '%s'"
,
cls
->
name
->
data
(),
attr
->
data
());
...
@@ -206,7 +206,7 @@ static void classobjSetattr(Box* _cls, Box* _attr, Box* _value) {
...
@@ -206,7 +206,7 @@ static void classobjSetattr(Box* _cls, Box* _attr, Box* _value) {
RELEASE_ASSERT
(
_attr
->
cls
==
str_cls
,
""
);
RELEASE_ASSERT
(
_attr
->
cls
==
str_cls
,
""
);
BoxedString
*
attr
=
static_cast
<
BoxedString
*>
(
_attr
);
BoxedString
*
attr
=
static_cast
<
BoxedString
*>
(
_attr
);
if
(
attr
->
s
==
"__bases__"
)
{
if
(
attr
->
s
()
==
"__bases__"
)
{
const
char
*
error_str
=
set_bases
((
PyClassObject
*
)
cls
,
_value
);
const
char
*
error_str
=
set_bases
((
PyClassObject
*
)
cls
,
_value
);
if
(
error_str
&&
error_str
[
0
]
!=
'\0'
)
if
(
error_str
&&
error_str
[
0
]
!=
'\0'
)
raiseExcHelper
(
TypeError
,
"%s"
,
error_str
);
raiseExcHelper
(
TypeError
,
"%s"
,
error_str
);
...
@@ -242,7 +242,7 @@ Box* classobjStr(Box* _obj) {
...
@@ -242,7 +242,7 @@ Box* classobjStr(Box* _obj) {
Box
*
_mod
=
cls
->
getattr
(
"__module__"
);
Box
*
_mod
=
cls
->
getattr
(
"__module__"
);
RELEASE_ASSERT
(
_mod
,
""
);
RELEASE_ASSERT
(
_mod
,
""
);
RELEASE_ASSERT
(
_mod
->
cls
==
str_cls
,
""
);
RELEASE_ASSERT
(
_mod
->
cls
==
str_cls
,
""
);
return
boxStringTwine
(
llvm
::
Twine
(
static_cast
<
BoxedString
*>
(
_mod
)
->
s
)
+
"."
+
cls
->
name
->
s
);
return
boxStringTwine
(
llvm
::
Twine
(
static_cast
<
BoxedString
*>
(
_mod
)
->
s
())
+
"."
+
cls
->
name
->
s
()
);
}
}
static
Box
*
_instanceGetattribute
(
Box
*
_inst
,
Box
*
_attr
,
bool
raise_on_missing
)
{
static
Box
*
_instanceGetattribute
(
Box
*
_inst
,
Box
*
_attr
,
bool
raise_on_missing
)
{
...
@@ -253,19 +253,19 @@ static Box* _instanceGetattribute(Box* _inst, Box* _attr, bool raise_on_missing)
...
@@ -253,19 +253,19 @@ static Box* _instanceGetattribute(Box* _inst, Box* _attr, bool raise_on_missing)
BoxedString
*
attr
=
static_cast
<
BoxedString
*>
(
_attr
);
BoxedString
*
attr
=
static_cast
<
BoxedString
*>
(
_attr
);
// These are special cases in CPython as well:
// These are special cases in CPython as well:
if
(
attr
->
s
[
0
]
==
'_'
&&
attr
->
s
[
1
]
==
'_'
)
{
if
(
attr
->
s
()[
0
]
==
'_'
&&
attr
->
s
()
[
1
]
==
'_'
)
{
if
(
attr
->
s
==
"__dict__"
)
if
(
attr
->
s
()
==
"__dict__"
)
return
inst
->
getAttrWrapper
();
return
inst
->
getAttrWrapper
();
if
(
attr
->
s
==
"__class__"
)
if
(
attr
->
s
()
==
"__class__"
)
return
inst
->
inst_cls
;
return
inst
->
inst_cls
;
}
}
Box
*
r
=
inst
->
getattr
(
attr
->
s
);
Box
*
r
=
inst
->
getattr
(
attr
->
s
()
);
if
(
r
)
if
(
r
)
return
r
;
return
r
;
r
=
classLookup
(
inst
->
inst_cls
,
attr
->
s
);
r
=
classLookup
(
inst
->
inst_cls
,
attr
->
s
()
);
if
(
r
)
{
if
(
r
)
{
return
processDescriptor
(
r
,
inst
,
inst
->
inst_cls
);
return
processDescriptor
(
r
,
inst
,
inst
->
inst_cls
);
}
}
...
@@ -308,11 +308,11 @@ Box* instanceSetattr(Box* _inst, Box* _attr, Box* value) {
...
@@ -308,11 +308,11 @@ Box* instanceSetattr(Box* _inst, Box* _attr, Box* value) {
assert
(
value
);
assert
(
value
);
// These are special cases in CPython as well:
// These are special cases in CPython as well:
if
(
attr
->
s
[
0
]
==
'_'
&&
attr
->
s
[
1
]
==
'_'
)
{
if
(
attr
->
s
()[
0
]
==
'_'
&&
attr
->
s
()
[
1
]
==
'_'
)
{
if
(
attr
->
s
==
"__dict__"
)
if
(
attr
->
s
()
==
"__dict__"
)
Py_FatalError
(
"unimplemented"
);
Py_FatalError
(
"unimplemented"
);
if
(
attr
->
s
==
"__class__"
)
{
if
(
attr
->
s
()
==
"__class__"
)
{
if
(
value
->
cls
!=
classobj_cls
)
if
(
value
->
cls
!=
classobj_cls
)
raiseExcHelper
(
TypeError
,
"__class__ must be set to a class"
);
raiseExcHelper
(
TypeError
,
"__class__ must be set to a class"
);
...
@@ -329,7 +329,7 @@ Box* instanceSetattr(Box* _inst, Box* _attr, Box* value) {
...
@@ -329,7 +329,7 @@ Box* instanceSetattr(Box* _inst, Box* _attr, Box* value) {
return
runtimeCall
(
setattr
,
ArgPassSpec
(
2
),
_attr
,
value
,
NULL
,
NULL
,
NULL
);
return
runtimeCall
(
setattr
,
ArgPassSpec
(
2
),
_attr
,
value
,
NULL
,
NULL
,
NULL
);
}
}
_inst
->
setattr
(
attr
->
s
,
value
,
NULL
);
_inst
->
setattr
(
attr
->
s
()
,
value
,
NULL
);
return
None
;
return
None
;
}
}
...
@@ -341,11 +341,11 @@ Box* instanceDelattr(Box* _inst, Box* _attr) {
...
@@ -341,11 +341,11 @@ Box* instanceDelattr(Box* _inst, Box* _attr) {
BoxedString
*
attr
=
static_cast
<
BoxedString
*>
(
_attr
);
BoxedString
*
attr
=
static_cast
<
BoxedString
*>
(
_attr
);
// These are special cases in CPython as well:
// These are special cases in CPython as well:
if
(
attr
->
s
[
0
]
==
'_'
&&
attr
->
s
[
1
]
==
'_'
)
{
if
(
attr
->
s
()[
0
]
==
'_'
&&
attr
->
s
()
[
1
]
==
'_'
)
{
if
(
attr
->
s
==
"__dict__"
)
if
(
attr
->
s
()
==
"__dict__"
)
raiseExcHelper
(
TypeError
,
"__dict__ must be set to a dictionary"
);
raiseExcHelper
(
TypeError
,
"__dict__ must be set to a dictionary"
);
if
(
attr
->
s
==
"__class__"
)
if
(
attr
->
s
()
==
"__class__"
)
raiseExcHelper
(
TypeError
,
"__class__ must be set to a class"
);
raiseExcHelper
(
TypeError
,
"__class__ must be set to a class"
);
}
}
...
@@ -357,7 +357,7 @@ Box* instanceDelattr(Box* _inst, Box* _attr) {
...
@@ -357,7 +357,7 @@ Box* instanceDelattr(Box* _inst, Box* _attr) {
return
runtimeCall
(
delattr
,
ArgPassSpec
(
1
),
_attr
,
NULL
,
NULL
,
NULL
,
NULL
);
return
runtimeCall
(
delattr
,
ArgPassSpec
(
1
),
_attr
,
NULL
,
NULL
,
NULL
,
NULL
);
}
}
_inst
->
delattr
(
attr
->
s
,
NULL
);
_inst
->
delattr
(
attr
->
s
()
,
NULL
);
return
None
;
return
None
;
}
}
...
...
src/runtime/dict.cpp
View file @
56f2d23f
...
@@ -38,10 +38,10 @@ Box* dictRepr(BoxedDict* self) {
...
@@ -38,10 +38,10 @@ Box* dictRepr(BoxedDict* self) {
BoxedString
*
k
=
static_cast
<
BoxedString
*>
(
repr
(
p
.
first
));
BoxedString
*
k
=
static_cast
<
BoxedString
*>
(
repr
(
p
.
first
));
BoxedString
*
v
=
static_cast
<
BoxedString
*>
(
repr
(
p
.
second
));
BoxedString
*
v
=
static_cast
<
BoxedString
*>
(
repr
(
p
.
second
));
chars
.
insert
(
chars
.
end
(),
k
->
s
.
begin
(),
k
->
s
.
end
());
chars
.
insert
(
chars
.
end
(),
k
->
s
().
begin
(),
k
->
s
()
.
end
());
chars
.
push_back
(
':'
);
chars
.
push_back
(
':'
);
chars
.
push_back
(
' '
);
chars
.
push_back
(
' '
);
chars
.
insert
(
chars
.
end
(),
v
->
s
.
begin
(),
v
->
s
.
end
());
chars
.
insert
(
chars
.
end
(),
v
->
s
().
begin
(),
v
->
s
()
.
end
());
}
}
chars
.
push_back
(
'}'
);
chars
.
push_back
(
'}'
);
return
boxString
(
llvm
::
StringRef
(
&
chars
[
0
],
chars
.
size
()));
return
boxString
(
llvm
::
StringRef
(
&
chars
[
0
],
chars
.
size
()));
...
...
src/runtime/file.cpp
View file @
56f2d23f
...
@@ -971,7 +971,7 @@ Box* fileNew(BoxedClass* cls, Box* s, Box* m, Box** args) {
...
@@ -971,7 +971,7 @@ Box* fileNew(BoxedClass* cls, Box* s, Box* m, Box** args) {
abort
();
// unreachable;
abort
();
// unreachable;
}
}
auto
file
=
new
BoxedFile
(
f
,
fn
->
s
,
PyString_AsString
(
m
));
auto
file
=
new
BoxedFile
(
f
,
fn
->
s
()
,
PyString_AsString
(
m
));
PyFile_SetBufSize
(
file
,
buffering
->
n
);
PyFile_SetBufSize
(
file
,
buffering
->
n
);
return
file
;
return
file
;
}
}
...
@@ -1110,7 +1110,7 @@ error:
...
@@ -1110,7 +1110,7 @@ error:
Box
*
fileIterNext
(
BoxedFile
*
s
)
{
Box
*
fileIterNext
(
BoxedFile
*
s
)
{
Box
*
rtn
=
fileReadline1
(
s
);
Box
*
rtn
=
fileReadline1
(
s
);
assert
(
!
rtn
||
rtn
->
cls
==
str_cls
);
assert
(
!
rtn
||
rtn
->
cls
==
str_cls
);
if
(
!
rtn
||
((
BoxedString
*
)
rtn
)
->
s
.
empty
())
if
(
!
rtn
||
((
BoxedString
*
)
rtn
)
->
s
()
.
empty
())
raiseExcHelper
(
StopIteration
,
""
);
raiseExcHelper
(
StopIteration
,
""
);
return
rtn
;
return
rtn
;
}
}
...
...
src/runtime/float.cpp
View file @
56f2d23f
...
@@ -627,7 +627,7 @@ BoxedFloat* _floatNew(Box* a) {
...
@@ -627,7 +627,7 @@ BoxedFloat* _floatNew(Box* a) {
}
else
if
(
isSubclass
(
a
->
cls
,
int_cls
))
{
}
else
if
(
isSubclass
(
a
->
cls
,
int_cls
))
{
return
new
BoxedFloat
(
static_cast
<
BoxedInt
*>
(
a
)
->
n
);
return
new
BoxedFloat
(
static_cast
<
BoxedInt
*>
(
a
)
->
n
);
}
else
if
(
a
->
cls
==
str_cls
)
{
}
else
if
(
a
->
cls
==
str_cls
)
{
const
std
::
string
&
s
=
static_cast
<
BoxedString
*>
(
a
)
->
s
;
const
std
::
string
&
s
=
static_cast
<
BoxedString
*>
(
a
)
->
s
()
;
if
(
s
==
"nan"
)
if
(
s
==
"nan"
)
return
new
BoxedFloat
(
NAN
);
return
new
BoxedFloat
(
NAN
);
if
(
s
==
"-nan"
)
if
(
s
==
"-nan"
)
...
...
src/runtime/import.cpp
View file @
56f2d23f
...
@@ -220,7 +220,7 @@ SearchResult findModule(const std::string& name, const std::string& full_name, B
...
@@ -220,7 +220,7 @@ SearchResult findModule(const std::string& name, const std::string& full_name, B
BoxedString
*
p
=
static_cast
<
BoxedString
*>
(
_p
);
BoxedString
*
p
=
static_cast
<
BoxedString
*>
(
_p
);
joined_path
.
clear
();
joined_path
.
clear
();
llvm
::
sys
::
path
::
append
(
joined_path
,
std
::
string
(
p
->
s
),
name
);
llvm
::
sys
::
path
::
append
(
joined_path
,
std
::
string
(
p
->
s
()
),
name
);
std
::
string
dn
(
joined_path
.
str
());
std
::
string
dn
(
joined_path
.
str
());
llvm
::
sys
::
path
::
append
(
joined_path
,
"__init__.py"
);
llvm
::
sys
::
path
::
append
(
joined_path
,
"__init__.py"
);
...
@@ -242,14 +242,14 @@ SearchResult findModule(const std::string& name, const std::string& full_name, B
...
@@ -242,14 +242,14 @@ SearchResult findModule(const std::string& name, const std::string& full_name, B
return
SearchResult
(
std
::
move
(
dn
),
SearchResult
::
PKG_DIRECTORY
);
return
SearchResult
(
std
::
move
(
dn
),
SearchResult
::
PKG_DIRECTORY
);
joined_path
.
clear
();
joined_path
.
clear
();
llvm
::
sys
::
path
::
append
(
joined_path
,
std
::
string
(
p
->
s
),
name
+
".py"
);
llvm
::
sys
::
path
::
append
(
joined_path
,
std
::
string
(
p
->
s
()
),
name
+
".py"
);
fn
=
joined_path
.
str
();
fn
=
joined_path
.
str
();
if
(
pathExists
(
fn
))
if
(
pathExists
(
fn
))
return
SearchResult
(
std
::
move
(
fn
),
SearchResult
::
PY_SOURCE
);
return
SearchResult
(
std
::
move
(
fn
),
SearchResult
::
PY_SOURCE
);
joined_path
.
clear
();
joined_path
.
clear
();
llvm
::
sys
::
path
::
append
(
joined_path
,
p
->
s
,
name
+
".pyston.so"
);
llvm
::
sys
::
path
::
append
(
joined_path
,
p
->
s
()
,
name
+
".pyston.so"
);
fn
=
joined_path
.
str
();
fn
=
joined_path
.
str
();
if
(
pathExists
(
fn
))
if
(
pathExists
(
fn
))
...
@@ -291,7 +291,7 @@ static Box* getParent(Box* globals, int level, std::string& buf) {
...
@@ -291,7 +291,7 @@ static Box* getParent(Box* globals, int level, std::string& buf) {
if
(
len
>
PATH_MAX
)
{
if
(
len
>
PATH_MAX
)
{
raiseExcHelper
(
ValueError
,
"Package name too long"
);
raiseExcHelper
(
ValueError
,
"Package name too long"
);
}
}
buf
+=
pkgname
->
s
;
buf
+=
pkgname
->
s
()
;
}
else
{
}
else
{
/* __package__ not set, so figure it out and set it */
/* __package__ not set, so figure it out and set it */
BoxedString
*
modname
=
static_cast
<
BoxedString
*>
(
getFromGlobals
(
globals
,
name_str
));
BoxedString
*
modname
=
static_cast
<
BoxedString
*>
(
getFromGlobals
(
globals
,
name_str
));
...
@@ -305,11 +305,11 @@ static Box* getParent(Box* globals, int level, std::string& buf) {
...
@@ -305,11 +305,11 @@ static Box* getParent(Box* globals, int level, std::string& buf) {
if
(
modname
->
size
()
>
PATH_MAX
)
{
if
(
modname
->
size
()
>
PATH_MAX
)
{
raiseExcHelper
(
ValueError
,
"Module name too long"
);
raiseExcHelper
(
ValueError
,
"Module name too long"
);
}
}
buf
+=
modname
->
s
;
buf
+=
modname
->
s
()
;
setGlobal
(
globals
,
package_str
,
modname
);
setGlobal
(
globals
,
package_str
,
modname
);
}
else
{
}
else
{
/* Normal module, so work out the package name if any */
/* Normal module, so work out the package name if any */
size_t
lastdot
=
modname
->
s
.
rfind
(
'.'
);
size_t
lastdot
=
modname
->
s
()
.
rfind
(
'.'
);
if
(
lastdot
==
std
::
string
::
npos
&&
level
>
0
)
{
if
(
lastdot
==
std
::
string
::
npos
&&
level
>
0
)
{
raiseExcHelper
(
ValueError
,
"Attempted relative import in non-package"
);
raiseExcHelper
(
ValueError
,
"Attempted relative import in non-package"
);
}
}
...
@@ -321,7 +321,7 @@ static Box* getParent(Box* globals, int level, std::string& buf) {
...
@@ -321,7 +321,7 @@ static Box* getParent(Box* globals, int level, std::string& buf) {
raiseExcHelper
(
ValueError
,
"Module name too long"
);
raiseExcHelper
(
ValueError
,
"Module name too long"
);
}
}
buf
=
std
::
string
(
modname
->
s
,
0
,
lastdot
);
buf
=
std
::
string
(
modname
->
s
()
,
0
,
lastdot
);
setGlobal
(
globals
,
package_str
,
boxStringPtr
(
&
buf
));
setGlobal
(
globals
,
package_str
,
boxStringPtr
(
&
buf
));
}
}
}
}
...
@@ -562,7 +562,7 @@ static void ensureFromlist(Box* module, Box* fromlist, std::string& buf, bool re
...
@@ -562,7 +562,7 @@ static void ensureFromlist(Box* module, Box* fromlist, std::string& buf, bool re
assert
(
_s
->
cls
==
str_cls
);
assert
(
_s
->
cls
==
str_cls
);
BoxedString
*
s
=
static_cast
<
BoxedString
*>
(
_s
);
BoxedString
*
s
=
static_cast
<
BoxedString
*>
(
_s
);
if
(
s
->
s
[
0
]
==
'*'
)
{
if
(
s
->
s
()
[
0
]
==
'*'
)
{
// If __all__ contains a '*', just skip it:
// If __all__ contains a '*', just skip it:
if
(
recursive
)
if
(
recursive
)
continue
;
continue
;
...
@@ -574,12 +574,12 @@ static void ensureFromlist(Box* module, Box* fromlist, std::string& buf, bool re
...
@@ -574,12 +574,12 @@ static void ensureFromlist(Box* module, Box* fromlist, std::string& buf, bool re
continue
;
continue
;
}
}
Box
*
attr
=
getattrInternal
(
module
,
s
->
s
,
NULL
);
Box
*
attr
=
getattrInternal
(
module
,
s
->
s
()
,
NULL
);
if
(
attr
!=
NULL
)
if
(
attr
!=
NULL
)
continue
;
continue
;
// Just want to import it and add it to the modules list for now:
// Just want to import it and add it to the modules list for now:
importSub
(
s
->
s
,
(
llvm
::
Twine
(
buf
)
+
"."
+
s
->
s
).
str
(),
module
);
importSub
(
s
->
s
(),
(
llvm
::
Twine
(
buf
)
+
"."
+
s
->
s
()
).
str
(),
module
);
}
}
}
}
...
@@ -651,7 +651,7 @@ Box* nullImporterInit(Box* self, Box* _path) {
...
@@ -651,7 +651,7 @@ Box* nullImporterInit(Box* self, Box* _path) {
raiseExcHelper
(
TypeError
,
"must be string, not %s"
,
getTypeName
(
_path
));
raiseExcHelper
(
TypeError
,
"must be string, not %s"
,
getTypeName
(
_path
));
BoxedString
*
path
=
(
BoxedString
*
)
_path
;
BoxedString
*
path
=
(
BoxedString
*
)
_path
;
if
(
path
->
s
.
empty
())
if
(
path
->
s
()
.
empty
())
raiseExcHelper
(
ImportError
,
"empty pathname"
);
raiseExcHelper
(
ImportError
,
"empty pathname"
);
if
(
isdir
(
path
->
data
()))
if
(
isdir
(
path
->
data
()))
...
@@ -676,7 +676,7 @@ Box* impFindModule(Box* _name, BoxedList* path) {
...
@@ -676,7 +676,7 @@ Box* impFindModule(Box* _name, BoxedList* path) {
BoxedString
*
name
=
static_cast
<
BoxedString
*>
(
_name
);
BoxedString
*
name
=
static_cast
<
BoxedString
*>
(
_name
);
BoxedList
*
path_list
=
path
&&
path
!=
None
?
path
:
getSysPath
();
BoxedList
*
path_list
=
path
&&
path
!=
None
?
path
:
getSysPath
();
SearchResult
sr
=
findModule
(
name
->
s
,
name
->
s
,
path_list
);
SearchResult
sr
=
findModule
(
name
->
s
(),
name
->
s
()
,
path_list
);
if
(
sr
.
type
==
SearchResult
::
SEARCH_ERROR
)
if
(
sr
.
type
==
SearchResult
::
SEARCH_ERROR
)
raiseExcHelper
(
ImportError
,
"%s"
,
name
->
data
());
raiseExcHelper
(
ImportError
,
"%s"
,
name
->
data
());
...
@@ -726,13 +726,13 @@ Box* impLoadModule(Box* _name, Box* _file, Box* _pathname, Box** args) {
...
@@ -726,13 +726,13 @@ Box* impLoadModule(Box* _name, Box* _file, Box* _pathname, Box** args) {
if
(
type
->
n
==
SearchResult
::
PKG_DIRECTORY
)
{
if
(
type
->
n
==
SearchResult
::
PKG_DIRECTORY
)
{
RELEASE_ASSERT
(
suffix
->
cls
==
str_cls
,
""
);
RELEASE_ASSERT
(
suffix
->
cls
==
str_cls
,
""
);
RELEASE_ASSERT
(
suffix
->
s
.
empty
(),
""
);
RELEASE_ASSERT
(
suffix
->
s
()
.
empty
(),
""
);
RELEASE_ASSERT
(
mode
->
s
.
empty
(),
""
);
RELEASE_ASSERT
(
mode
->
s
()
.
empty
(),
""
);
RELEASE_ASSERT
(
_file
==
None
,
""
);
RELEASE_ASSERT
(
_file
==
None
,
""
);
return
createAndRunModule
(
name
->
s
,
(
llvm
::
Twine
(
pathname
->
s
)
+
"/__init__.py"
).
str
(),
pathname
->
s
);
return
createAndRunModule
(
name
->
s
(),
(
llvm
::
Twine
(
pathname
->
s
())
+
"/__init__.py"
).
str
(),
pathname
->
s
()
);
}
else
if
(
type
->
n
==
SearchResult
::
PY_SOURCE
)
{
}
else
if
(
type
->
n
==
SearchResult
::
PY_SOURCE
)
{
RELEASE_ASSERT
(
_file
->
cls
==
file_cls
,
""
);
RELEASE_ASSERT
(
_file
->
cls
==
file_cls
,
""
);
return
createAndRunModule
(
name
->
s
,
pathname
->
s
);
return
createAndRunModule
(
name
->
s
(),
pathname
->
s
()
);
}
}
Py_FatalError
(
"unimplemented"
);
Py_FatalError
(
"unimplemented"
);
...
@@ -744,7 +744,7 @@ Box* impLoadSource(Box* _name, Box* _pathname, Box* _file) {
...
@@ -744,7 +744,7 @@ Box* impLoadSource(Box* _name, Box* _pathname, Box* _file) {
RELEASE_ASSERT
(
_name
->
cls
==
str_cls
,
""
);
RELEASE_ASSERT
(
_name
->
cls
==
str_cls
,
""
);
RELEASE_ASSERT
(
_pathname
->
cls
==
str_cls
,
""
);
RELEASE_ASSERT
(
_pathname
->
cls
==
str_cls
,
""
);
return
createAndRunModule
(
static_cast
<
BoxedString
*>
(
_name
)
->
s
,
static_cast
<
BoxedString
*>
(
_pathname
)
->
s
);
return
createAndRunModule
(
static_cast
<
BoxedString
*>
(
_name
)
->
s
(),
static_cast
<
BoxedString
*>
(
_pathname
)
->
s
()
);
}
}
Box
*
impLoadDynamic
(
Box
*
_name
,
Box
*
_pathname
,
Box
*
_file
)
{
Box
*
impLoadDynamic
(
Box
*
_name
,
Box
*
_pathname
,
Box
*
_file
)
{
...
@@ -755,16 +755,16 @@ Box* impLoadDynamic(Box* _name, Box* _pathname, Box* _file) {
...
@@ -755,16 +755,16 @@ Box* impLoadDynamic(Box* _name, Box* _pathname, Box* _file) {
BoxedString
*
name
=
(
BoxedString
*
)
_name
;
BoxedString
*
name
=
(
BoxedString
*
)
_name
;
BoxedString
*
pathname
=
(
BoxedString
*
)
_pathname
;
BoxedString
*
pathname
=
(
BoxedString
*
)
_pathname
;
const
char
*
lastdot
=
strrchr
(
name
->
s
.
data
(),
'.'
);
const
char
*
lastdot
=
strrchr
(
name
->
s
()
.
data
(),
'.'
);
const
char
*
shortname
;
const
char
*
shortname
;
if
(
lastdot
==
NULL
)
{
if
(
lastdot
==
NULL
)
{
shortname
=
name
->
s
.
data
();
shortname
=
name
->
s
()
.
data
();
}
else
{
}
else
{
shortname
=
lastdot
+
1
;
shortname
=
lastdot
+
1
;
}
}
return
importCExtension
(
name
->
s
,
shortname
,
pathname
->
s
);
return
importCExtension
(
name
->
s
(),
shortname
,
pathname
->
s
()
);
}
}
Box
*
impGetSuffixes
()
{
Box
*
impGetSuffixes
()
{
...
...
src/runtime/list.cpp
View file @
56f2d23f
...
@@ -76,7 +76,7 @@ extern "C" Box* listRepr(BoxedList* self) {
...
@@ -76,7 +76,7 @@ extern "C" Box* listRepr(BoxedList* self) {
assert
(
r
->
cls
==
str_cls
);
assert
(
r
->
cls
==
str_cls
);
BoxedString
*
s
=
static_cast
<
BoxedString
*>
(
r
);
BoxedString
*
s
=
static_cast
<
BoxedString
*>
(
r
);
os
<<
s
->
s
;
os
<<
s
->
s
()
;
}
}
os
<<
']'
;
os
<<
']'
;
return
boxString
(
os
.
str
());
return
boxString
(
os
.
str
());
...
...
src/runtime/long.cpp
View file @
56f2d23f
...
@@ -612,7 +612,7 @@ BoxedLong* _longNew(Box* val, Box* _base) {
...
@@ -612,7 +612,7 @@ BoxedLong* _longNew(Box* val, Box* _base) {
raiseExcHelper
(
TypeError
,
"long() can't convert non-string with explicit base"
);
raiseExcHelper
(
TypeError
,
"long() can't convert non-string with explicit base"
);
BoxedString
*
s
=
static_cast
<
BoxedString
*>
(
val
);
BoxedString
*
s
=
static_cast
<
BoxedString
*>
(
val
);
rtn
=
(
BoxedLong
*
)
PyLong_FromString
(
s
->
s
.
str
().
c_str
(),
NULL
,
base
);
rtn
=
(
BoxedLong
*
)
PyLong_FromString
(
s
->
data
(),
NULL
,
base
);
checkAndThrowCAPIException
();
checkAndThrowCAPIException
();
}
else
{
}
else
{
if
(
isSubclass
(
val
->
cls
,
long_cls
))
{
if
(
isSubclass
(
val
->
cls
,
long_cls
))
{
...
@@ -625,7 +625,7 @@ BoxedLong* _longNew(Box* val, Box* _base) {
...
@@ -625,7 +625,7 @@ BoxedLong* _longNew(Box* val, Box* _base) {
}
else
if
(
isSubclass
(
val
->
cls
,
int_cls
))
{
}
else
if
(
isSubclass
(
val
->
cls
,
int_cls
))
{
mpz_init_set_si
(
rtn
->
n
,
static_cast
<
BoxedInt
*>
(
val
)
->
n
);
mpz_init_set_si
(
rtn
->
n
,
static_cast
<
BoxedInt
*>
(
val
)
->
n
);
}
else
if
(
val
->
cls
==
str_cls
)
{
}
else
if
(
val
->
cls
==
str_cls
)
{
const
std
::
string
&
s
=
static_cast
<
BoxedString
*>
(
val
)
->
s
;
const
std
::
string
&
s
=
static_cast
<
BoxedString
*>
(
val
)
->
s
()
;
int
r
=
mpz_init_set_str
(
rtn
->
n
,
s
.
c_str
(),
10
);
int
r
=
mpz_init_set_str
(
rtn
->
n
,
s
.
c_str
(),
10
);
RELEASE_ASSERT
(
r
==
0
,
""
);
RELEASE_ASSERT
(
r
==
0
,
""
);
}
else
if
(
val
->
cls
==
float_cls
)
{
}
else
if
(
val
->
cls
==
float_cls
)
{
...
...
src/runtime/objmodel.cpp
View file @
56f2d23f
...
@@ -146,7 +146,7 @@ bool PyEq::operator()(Box* lhs, Box* rhs) const {
...
@@ -146,7 +146,7 @@ bool PyEq::operator()(Box* lhs, Box* rhs) const {
if
(
lhs
->
cls
==
rhs
->
cls
)
{
if
(
lhs
->
cls
==
rhs
->
cls
)
{
if
(
lhs
->
cls
==
str_cls
)
{
if
(
lhs
->
cls
==
str_cls
)
{
return
static_cast
<
BoxedString
*>
(
lhs
)
->
s
==
static_cast
<
BoxedString
*>
(
rhs
)
->
s
;
return
static_cast
<
BoxedString
*>
(
lhs
)
->
s
()
==
static_cast
<
BoxedString
*>
(
rhs
)
->
s
()
;
}
}
}
}
...
@@ -464,7 +464,7 @@ std::string getFullNameOfClass(BoxedClass* cls) {
...
@@ -464,7 +464,7 @@ std::string getFullNameOfClass(BoxedClass* cls) {
BoxedString
*
module
=
static_cast
<
BoxedString
*>
(
b
);
BoxedString
*
module
=
static_cast
<
BoxedString
*>
(
b
);
return
(
llvm
::
Twine
(
module
->
s
)
+
"."
+
cls
->
tp_name
).
str
();
return
(
llvm
::
Twine
(
module
->
s
()
)
+
"."
+
cls
->
tp_name
).
str
();
}
}
std
::
string
getFullTypeName
(
Box
*
o
)
{
std
::
string
getFullTypeName
(
Box
*
o
)
{
...
@@ -3104,7 +3104,7 @@ Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpe
...
@@ -3104,7 +3104,7 @@ Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpe
if
(
param_names
.
takes_param_names
)
{
if
(
param_names
.
takes_param_names
)
{
assert
(
!
rewrite_args
&&
"would need to make sure that this didn't need to go into r_kwargs"
);
assert
(
!
rewrite_args
&&
"would need to make sure that this didn't need to go into r_kwargs"
);
placeKeyword
(
param_names
,
params_filled
,
s
->
s
,
p
.
second
,
oarg1
,
oarg2
,
oarg3
,
oargs
,
okwargs
,
f
);
placeKeyword
(
param_names
,
params_filled
,
s
->
s
()
,
p
.
second
,
oarg1
,
oarg2
,
oarg3
,
oargs
,
okwargs
,
f
);
}
else
{
}
else
{
assert
(
!
rewrite_args
&&
"would need to make sure that this didn't need to go into r_kwargs"
);
assert
(
!
rewrite_args
&&
"would need to make sure that this didn't need to go into r_kwargs"
);
assert
(
okwargs
);
assert
(
okwargs
);
...
@@ -4261,14 +4261,14 @@ Box* typeNew(Box* _cls, Box* arg1, Box* arg2, Box** _args) {
...
@@ -4261,14 +4261,14 @@ Box* typeNew(Box* _cls, Box* arg1, Box* arg2, Box** _args) {
Box
*
tmp
=
slots
[
i
];
Box
*
tmp
=
slots
[
i
];
assertValidSlotIdentifier
(
tmp
);
assertValidSlotIdentifier
(
tmp
);
assert
(
PyString_Check
(
tmp
));
assert
(
PyString_Check
(
tmp
));
if
(
static_cast
<
BoxedString
*>
(
tmp
)
->
s
==
"__dict__"
)
{
if
(
static_cast
<
BoxedString
*>
(
tmp
)
->
s
()
==
"__dict__"
)
{
if
(
!
may_add_dict
||
add_dict
)
{
if
(
!
may_add_dict
||
add_dict
)
{
raiseExcHelper
(
TypeError
,
"__dict__ slot disallowed: "
raiseExcHelper
(
TypeError
,
"__dict__ slot disallowed: "
"we already got one"
);
"we already got one"
);
}
}
add_dict
++
;
add_dict
++
;
continue
;
continue
;
}
else
if
(
static_cast
<
BoxedString
*>
(
tmp
)
->
s
==
"__weakref__"
)
{
}
else
if
(
static_cast
<
BoxedString
*>
(
tmp
)
->
s
()
==
"__weakref__"
)
{
if
(
!
may_add_weak
||
add_weak
)
{
if
(
!
may_add_weak
||
add_weak
)
{
raiseExcHelper
(
TypeError
,
"__weakref__ slot disallowed: "
raiseExcHelper
(
TypeError
,
"__weakref__ slot disallowed: "
"either we already got one, "
"either we already got one, "
...
@@ -4356,7 +4356,7 @@ Box* typeNew(Box* _cls, Box* arg1, Box* arg2, Box** _args) {
...
@@ -4356,7 +4356,7 @@ Box* typeNew(Box* _cls, Box* arg1, Box* arg2, Box** _args) {
// Add the member descriptors
// Add the member descriptors
size_t
offset
=
base
->
tp_basicsize
;
size_t
offset
=
base
->
tp_basicsize
;
for
(
size_t
i
=
0
;
i
<
final_slot_names
.
size
();
i
++
)
{
for
(
size_t
i
=
0
;
i
<
final_slot_names
.
size
();
i
++
)
{
made
->
giveAttr
(
static_cast
<
BoxedString
*>
(
slotsTuple
->
elts
[
i
])
->
s
.
data
(),
made
->
giveAttr
(
static_cast
<
BoxedString
*>
(
slotsTuple
->
elts
[
i
])
->
data
(),
new
BoxedMemberDescriptor
(
BoxedMemberDescriptor
::
OBJECT_EX
,
offset
,
false
/* read only */
));
new
BoxedMemberDescriptor
(
BoxedMemberDescriptor
::
OBJECT_EX
,
offset
,
false
/* read only */
));
slot_offsets
[
i
]
=
offset
;
slot_offsets
[
i
]
=
offset
;
offset
+=
sizeof
(
Box
*
);
offset
+=
sizeof
(
Box
*
);
...
@@ -4381,7 +4381,7 @@ Box* typeNew(Box* _cls, Box* arg1, Box* arg2, Box** _args) {
...
@@ -4381,7 +4381,7 @@ Box* typeNew(Box* _cls, Box* arg1, Box* arg2, Box** _args) {
auto
k
=
coerceUnicodeToStr
(
p
.
first
);
auto
k
=
coerceUnicodeToStr
(
p
.
first
);
RELEASE_ASSERT
(
k
->
cls
==
str_cls
,
""
);
RELEASE_ASSERT
(
k
->
cls
==
str_cls
,
""
);
made
->
setattr
(
static_cast
<
BoxedString
*>
(
k
)
->
s
,
p
.
second
,
NULL
);
made
->
setattr
(
static_cast
<
BoxedString
*>
(
k
)
->
s
()
,
p
.
second
,
NULL
);
}
}
if
(
!
made
->
hasattr
(
"__module__"
))
{
if
(
!
made
->
hasattr
(
"__module__"
))
{
...
@@ -4911,11 +4911,11 @@ extern "C" Box* importStar(Box* _from_module, Box* to_globals) {
...
@@ -4911,11 +4911,11 @@ extern "C" Box* importStar(Box* _from_module, Box* to_globals) {
raiseExcHelper
(
TypeError
,
"attribute name must be string, not '%s'"
,
getTypeName
(
attr_name
));
raiseExcHelper
(
TypeError
,
"attribute name must be string, not '%s'"
,
getTypeName
(
attr_name
));
BoxedString
*
casted_attr_name
=
static_cast
<
BoxedString
*>
(
attr_name
);
BoxedString
*
casted_attr_name
=
static_cast
<
BoxedString
*>
(
attr_name
);
Box
*
attr_value
=
from_module
->
getattr
(
casted_attr_name
->
s
);
Box
*
attr_value
=
from_module
->
getattr
(
casted_attr_name
->
s
()
);
if
(
!
attr_value
)
if
(
!
attr_value
)
raiseExcHelper
(
AttributeError
,
"'module' object has no attribute '%s'"
,
casted_attr_name
->
data
());
raiseExcHelper
(
AttributeError
,
"'module' object has no attribute '%s'"
,
casted_attr_name
->
data
());
setGlobal
(
to_globals
,
casted_attr_name
->
s
,
attr_value
);
setGlobal
(
to_globals
,
casted_attr_name
->
s
()
,
attr_value
);
}
}
return
None
;
return
None
;
}
}
...
...
src/runtime/set.cpp
View file @
56f2d23f
...
@@ -106,7 +106,7 @@ static Box* _setRepr(BoxedSet* self, const char* type_name) {
...
@@ -106,7 +106,7 @@ static Box* _setRepr(BoxedSet* self, const char* type_name) {
if
(
!
first
)
{
if
(
!
first
)
{
os
<<
", "
;
os
<<
", "
;
}
}
os
<<
static_cast
<
BoxedString
*>
(
repr
(
elt
))
->
s
;
os
<<
static_cast
<
BoxedString
*>
(
repr
(
elt
))
->
s
()
;
first
=
false
;
first
=
false
;
}
}
os
<<
"])"
;
os
<<
"])"
;
...
...
src/runtime/str.cpp
View file @
56f2d23f
This diff is collapsed.
Click to expand it.
src/runtime/super.cpp
View file @
56f2d23f
...
@@ -64,7 +64,7 @@ Box* superGetattribute(Box* _s, Box* _attr) {
...
@@ -64,7 +64,7 @@ Box* superGetattribute(Box* _s, Box* _attr) {
if
(
!
skip
)
{
if
(
!
skip
)
{
// Looks like __class__ is supposed to be "super", not the class of the the proxied object.
// Looks like __class__ is supposed to be "super", not the class of the the proxied object.
skip
=
(
attr
->
s
==
class_str
);
skip
=
(
attr
->
s
()
==
class_str
);
}
}
if
(
!
skip
)
{
if
(
!
skip
)
{
...
@@ -101,7 +101,7 @@ Box* superGetattribute(Box* _s, Box* _attr) {
...
@@ -101,7 +101,7 @@ Box* superGetattribute(Box* _s, Box* _attr) {
continue;
continue;
res = PyDict_GetItem(dict, name);
res = PyDict_GetItem(dict, name);
#endif
#endif
res
=
tmp
->
getattr
(
std
::
string
(
attr
->
s
));
res
=
tmp
->
getattr
(
std
::
string
(
attr
->
s
()
));
if
(
res
!=
NULL
)
{
if
(
res
!=
NULL
)
{
// Pyston change:
// Pyston change:
...
@@ -128,7 +128,7 @@ Box* superGetattribute(Box* _s, Box* _attr) {
...
@@ -128,7 +128,7 @@ Box* superGetattribute(Box* _s, Box* _attr) {
}
}
}
}
Box
*
r
=
typeLookup
(
s
->
cls
,
std
::
string
(
attr
->
s
),
NULL
);
Box
*
r
=
typeLookup
(
s
->
cls
,
std
::
string
(
attr
->
s
()
),
NULL
);
// TODO implement this
// TODO implement this
RELEASE_ASSERT
(
r
,
"should call the equivalent of objectGetattr here"
);
RELEASE_ASSERT
(
r
,
"should call the equivalent of objectGetattr here"
);
return
processDescriptor
(
r
,
s
,
s
->
cls
);
return
processDescriptor
(
r
,
s
,
s
->
cls
);
...
...
src/runtime/tuple.cpp
View file @
56f2d23f
...
@@ -215,7 +215,7 @@ Box* tupleRepr(BoxedTuple* t) {
...
@@ -215,7 +215,7 @@ Box* tupleRepr(BoxedTuple* t) {
os
<<
", "
;
os
<<
", "
;
BoxedString
*
elt_repr
=
static_cast
<
BoxedString
*>
(
repr
(
t
->
elts
[
i
]));
BoxedString
*
elt_repr
=
static_cast
<
BoxedString
*>
(
repr
(
t
->
elts
[
i
]));
os
<<
elt_repr
->
s
;
os
<<
elt_repr
->
s
()
;
}
}
if
(
n
==
1
)
if
(
n
==
1
)
os
<<
","
;
os
<<
","
;
...
@@ -376,7 +376,7 @@ extern "C" Box* tupleNew(Box* _cls, BoxedTuple* args, BoxedDict* kwargs) {
...
@@ -376,7 +376,7 @@ extern "C" Box* tupleNew(Box* _cls, BoxedTuple* args, BoxedDict* kwargs) {
auto
const
seq
=
*
(
kwargs
->
d
.
begin
());
auto
const
seq
=
*
(
kwargs
->
d
.
begin
());
auto
const
kw
=
static_cast
<
BoxedString
*>
(
seq
.
first
);
auto
const
kw
=
static_cast
<
BoxedString
*>
(
seq
.
first
);
if
(
kw
->
s
==
"sequence"
)
if
(
kw
->
s
()
==
"sequence"
)
elements
=
seq
.
second
;
elements
=
seq
.
second
;
else
else
raiseExcHelper
(
TypeError
,
"'%s' is an invalid keyword argument for this function"
,
kw
->
data
());
raiseExcHelper
(
TypeError
,
"'%s' is an invalid keyword argument for this function"
,
kw
->
data
());
...
...
src/runtime/types.cpp
View file @
56f2d23f
...
@@ -401,7 +401,7 @@ std::string BoxedModule::name() {
...
@@ -401,7 +401,7 @@ std::string BoxedModule::name() {
return
"?"
;
return
"?"
;
}
else
{
}
else
{
BoxedString
*
sname
=
static_cast
<
BoxedString
*>
(
name
);
BoxedString
*
sname
=
static_cast
<
BoxedString
*>
(
name
);
return
sname
->
s
;
return
sname
->
s
()
;
}
}
}
}
...
@@ -1038,7 +1038,7 @@ Box* sliceRepr(BoxedSlice* self) {
...
@@ -1038,7 +1038,7 @@ Box* sliceRepr(BoxedSlice* self) {
BoxedString
*
start
=
static_cast
<
BoxedString
*>
(
repr
(
self
->
start
));
BoxedString
*
start
=
static_cast
<
BoxedString
*>
(
repr
(
self
->
start
));
BoxedString
*
stop
=
static_cast
<
BoxedString
*>
(
repr
(
self
->
stop
));
BoxedString
*
stop
=
static_cast
<
BoxedString
*>
(
repr
(
self
->
stop
));
BoxedString
*
step
=
static_cast
<
BoxedString
*>
(
repr
(
self
->
step
));
BoxedString
*
step
=
static_cast
<
BoxedString
*>
(
repr
(
self
->
step
));
return
boxStringTwine
(
llvm
::
Twine
(
"slice("
)
+
start
->
s
+
", "
+
stop
->
s
+
", "
+
step
->
s
+
")"
);
return
boxStringTwine
(
llvm
::
Twine
(
"slice("
)
+
start
->
s
()
+
", "
+
stop
->
s
()
+
", "
+
step
->
s
()
+
")"
);
}
}
extern
"C"
int
PySlice_GetIndices
(
PySliceObject
*
r
,
Py_ssize_t
length
,
Py_ssize_t
*
start
,
Py_ssize_t
*
stop
,
extern
"C"
int
PySlice_GetIndices
(
PySliceObject
*
r
,
Py_ssize_t
length
,
Py_ssize_t
*
start
,
Py_ssize_t
*
stop
,
...
@@ -1150,8 +1150,8 @@ Box* typeRepr(BoxedClass* self) {
...
@@ -1150,8 +1150,8 @@ Box* typeRepr(BoxedClass* self) {
Box
*
m
=
self
->
getattr
(
"__module__"
);
Box
*
m
=
self
->
getattr
(
"__module__"
);
if
(
m
&&
m
->
cls
==
str_cls
)
{
if
(
m
&&
m
->
cls
==
str_cls
)
{
BoxedString
*
sm
=
static_cast
<
BoxedString
*>
(
m
);
BoxedString
*
sm
=
static_cast
<
BoxedString
*>
(
m
);
if
(
sm
->
s
!=
"__builtin__"
)
if
(
sm
->
s
()
!=
"__builtin__"
)
os
<<
sm
->
s
<<
'.'
;
os
<<
sm
->
s
()
<<
'.'
;
}
}
os
<<
self
->
tp_name
;
os
<<
self
->
tp_name
;
...
@@ -1347,7 +1347,7 @@ public:
...
@@ -1347,7 +1347,7 @@ public:
RELEASE_ASSERT
(
_key
->
cls
==
str_cls
,
""
);
RELEASE_ASSERT
(
_key
->
cls
==
str_cls
,
""
);
BoxedString
*
key
=
static_cast
<
BoxedString
*>
(
_key
);
BoxedString
*
key
=
static_cast
<
BoxedString
*>
(
_key
);
self
->
b
->
setattr
(
key
->
s
,
value
,
NULL
);
self
->
b
->
setattr
(
key
->
s
()
,
value
,
NULL
);
return
None
;
return
None
;
}
}
...
@@ -1360,10 +1360,10 @@ public:
...
@@ -1360,10 +1360,10 @@ public:
RELEASE_ASSERT
(
_key
->
cls
==
str_cls
,
""
);
RELEASE_ASSERT
(
_key
->
cls
==
str_cls
,
""
);
BoxedString
*
key
=
static_cast
<
BoxedString
*>
(
_key
);
BoxedString
*
key
=
static_cast
<
BoxedString
*>
(
_key
);
Box
*
cur
=
self
->
b
->
getattr
(
key
->
s
);
Box
*
cur
=
self
->
b
->
getattr
(
key
->
s
()
);
if
(
cur
)
if
(
cur
)
return
cur
;
return
cur
;
self
->
b
->
setattr
(
key
->
s
,
value
,
NULL
);
self
->
b
->
setattr
(
key
->
s
()
,
value
,
NULL
);
return
value
;
return
value
;
}
}
...
@@ -1376,7 +1376,7 @@ public:
...
@@ -1376,7 +1376,7 @@ public:
RELEASE_ASSERT
(
_key
->
cls
==
str_cls
,
""
);
RELEASE_ASSERT
(
_key
->
cls
==
str_cls
,
""
);
BoxedString
*
key
=
static_cast
<
BoxedString
*>
(
_key
);
BoxedString
*
key
=
static_cast
<
BoxedString
*>
(
_key
);
Box
*
r
=
self
->
b
->
getattr
(
key
->
s
);
Box
*
r
=
self
->
b
->
getattr
(
key
->
s
()
);
if
(
!
r
)
if
(
!
r
)
return
def
;
return
def
;
return
r
;
return
r
;
...
@@ -1391,7 +1391,7 @@ public:
...
@@ -1391,7 +1391,7 @@ public:
RELEASE_ASSERT
(
_key
->
cls
==
str_cls
,
"%s"
,
_key
->
cls
->
tp_name
);
RELEASE_ASSERT
(
_key
->
cls
==
str_cls
,
"%s"
,
_key
->
cls
->
tp_name
);
BoxedString
*
key
=
static_cast
<
BoxedString
*>
(
_key
);
BoxedString
*
key
=
static_cast
<
BoxedString
*>
(
_key
);
Box
*
r
=
self
->
b
->
getattr
(
key
->
s
);
Box
*
r
=
self
->
b
->
getattr
(
key
->
s
()
);
if
(
!
r
)
if
(
!
r
)
raiseExcHelper
(
KeyError
,
"'%s'"
,
key
->
data
());
raiseExcHelper
(
KeyError
,
"'%s'"
,
key
->
data
());
return
r
;
return
r
;
...
@@ -1405,9 +1405,9 @@ public:
...
@@ -1405,9 +1405,9 @@ public:
RELEASE_ASSERT
(
_key
->
cls
==
str_cls
,
""
);
RELEASE_ASSERT
(
_key
->
cls
==
str_cls
,
""
);
BoxedString
*
key
=
static_cast
<
BoxedString
*>
(
_key
);
BoxedString
*
key
=
static_cast
<
BoxedString
*>
(
_key
);
Box
*
r
=
self
->
b
->
getattr
(
key
->
s
);
Box
*
r
=
self
->
b
->
getattr
(
key
->
s
()
);
if
(
r
)
{
if
(
r
)
{
self
->
b
->
delattr
(
key
->
s
,
NULL
);
self
->
b
->
delattr
(
key
->
s
()
,
NULL
);
return
r
;
return
r
;
}
else
{
}
else
{
if
(
default_
)
if
(
default_
)
...
@@ -1425,8 +1425,8 @@ public:
...
@@ -1425,8 +1425,8 @@ public:
RELEASE_ASSERT
(
_key
->
cls
==
str_cls
,
"%s"
,
_key
->
cls
->
tp_name
);
RELEASE_ASSERT
(
_key
->
cls
==
str_cls
,
"%s"
,
_key
->
cls
->
tp_name
);
BoxedString
*
key
=
static_cast
<
BoxedString
*>
(
_key
);
BoxedString
*
key
=
static_cast
<
BoxedString
*>
(
_key
);
if
(
self
->
b
->
getattr
(
key
->
s
))
if
(
self
->
b
->
getattr
(
key
->
s
()
))
self
->
b
->
delattr
(
key
->
s
,
NULL
);
self
->
b
->
delattr
(
key
->
s
()
,
NULL
);
else
else
raiseExcHelper
(
KeyError
,
"'%s'"
,
key
->
data
());
raiseExcHelper
(
KeyError
,
"'%s'"
,
key
->
data
());
return
None
;
return
None
;
...
@@ -1450,7 +1450,7 @@ public:
...
@@ -1450,7 +1450,7 @@ public:
first
=
false
;
first
=
false
;
BoxedString
*
v
=
attrs
->
attr_list
->
attrs
[
p
.
second
]
->
reprICAsString
();
BoxedString
*
v
=
attrs
->
attr_list
->
attrs
[
p
.
second
]
->
reprICAsString
();
os
<<
p
.
first
().
str
()
<<
": "
<<
v
->
s
;
os
<<
p
.
first
().
str
()
<<
": "
<<
v
->
s
()
;
}
}
os
<<
"})"
;
os
<<
"})"
;
return
boxString
(
os
.
str
());
return
boxString
(
os
.
str
());
...
@@ -1464,7 +1464,7 @@ public:
...
@@ -1464,7 +1464,7 @@ public:
RELEASE_ASSERT
(
_key
->
cls
==
str_cls
,
""
);
RELEASE_ASSERT
(
_key
->
cls
==
str_cls
,
""
);
BoxedString
*
key
=
static_cast
<
BoxedString
*>
(
_key
);
BoxedString
*
key
=
static_cast
<
BoxedString
*>
(
_key
);
Box
*
r
=
self
->
b
->
getattr
(
key
->
s
);
Box
*
r
=
self
->
b
->
getattr
(
key
->
s
()
);
return
r
?
True
:
False
;
return
r
?
True
:
False
;
}
}
...
@@ -1728,7 +1728,7 @@ Box* objectSetattr(Box* obj, Box* attr, Box* value) {
...
@@ -1728,7 +1728,7 @@ Box* objectSetattr(Box* obj, Box* attr, Box* value) {
}
}
BoxedString
*
attr_str
=
static_cast
<
BoxedString
*>
(
attr
);
BoxedString
*
attr_str
=
static_cast
<
BoxedString
*>
(
attr
);
setattrGeneric
(
obj
,
attr_str
->
s
,
value
,
NULL
);
setattrGeneric
(
obj
,
attr_str
->
s
()
,
value
,
NULL
);
return
None
;
return
None
;
}
}
...
...
src/runtime/types.h
View file @
56f2d23f
...
@@ -427,11 +427,14 @@ public:
...
@@ -427,11 +427,14 @@ public:
class
BoxedString
:
public
BoxVar
{
class
BoxedString
:
public
BoxVar
{
public:
public:
llvm
::
StringRef
s
;
// llvm::StringRef is basically just a pointer and a length, so with proper compiler
// optimizations and inlining, creating a new one each time shouldn't have any cost.
llvm
::
StringRef
s
()
const
{
return
llvm
::
StringRef
(
s_data
,
ob_size
);
};
char
interned_state
;
char
interned_state
;
char
*
data
()
{
return
const_cast
<
char
*>
(
s
.
data
())
;
}
char
*
data
()
{
return
s_data
;
}
size_t
size
()
{
return
s
.
size
()
;
}
size_t
size
()
{
return
this
->
ob_size
;
}
// DEFAULT_CLASS_VAR_SIMPLE doesn't work because of the +1 for the null byte
// DEFAULT_CLASS_VAR_SIMPLE doesn't work because of the +1 for the null byte
void
*
operator
new
(
size_t
size
,
BoxedClass
*
cls
,
size_t
nitems
)
__attribute__
((
visibility
(
"default"
)))
{
void
*
operator
new
(
size_t
size
,
BoxedClass
*
cls
,
size_t
nitems
)
__attribute__
((
visibility
(
"default"
)))
{
...
@@ -465,11 +468,9 @@ public:
...
@@ -465,11 +468,9 @@ public:
explicit
BoxedString
(
llvm
::
StringRef
lhs
,
llvm
::
StringRef
rhs
)
__attribute__
((
visibility
(
"default"
)));
explicit
BoxedString
(
llvm
::
StringRef
lhs
,
llvm
::
StringRef
rhs
)
__attribute__
((
visibility
(
"default"
)));
private:
private:
// used only in ctors to give our llvm::StringRef the proper pointer
// Note: sizeof(BoxedString) = str_cls->tp_basicsize - 1
char
*
storage
()
{
return
(
char
*
)
this
+
sizeof
(
BoxedString
);
}
void
*
operator
new
(
size_t
size
)
=
delete
;
void
*
operator
new
(
size_t
size
)
=
delete
;
char
s_data
[
0
];
};
};
template
<
typename
T
>
struct
StringHash
{
template
<
typename
T
>
struct
StringHash
{
...
...
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