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
d50f760f
Commit
d50f760f
authored
Aug 21, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert parts of the import system to use BoxedStrings
Reduces boxing during the import process
parent
2e409bdd
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
56 additions
and
61 deletions
+56
-61
src/capi/modsupport.cpp
src/capi/modsupport.cpp
+1
-1
src/core/types.h
src/core/types.h
+2
-2
src/jit.cpp
src/jit.cpp
+4
-4
src/runtime/builtin_modules/ast.cpp
src/runtime/builtin_modules/ast.cpp
+1
-1
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+3
-3
src/runtime/builtin_modules/gc.cpp
src/runtime/builtin_modules/gc.cpp
+1
-1
src/runtime/builtin_modules/pyston.cpp
src/runtime/builtin_modules/pyston.cpp
+1
-1
src/runtime/builtin_modules/sys.cpp
src/runtime/builtin_modules/sys.cpp
+1
-1
src/runtime/import.cpp
src/runtime/import.cpp
+34
-38
src/runtime/import.h
src/runtime/import.h
+1
-1
src/runtime/types.cpp
src/runtime/types.cpp
+5
-6
test/unittests/analysis.cpp
test/unittests/analysis.cpp
+2
-2
No files found.
src/capi/modsupport.cpp
View file @
d50f760f
...
@@ -417,7 +417,7 @@ extern "C" PyObject* Py_InitModule4(const char* name, PyMethodDef* methods, cons
...
@@ -417,7 +417,7 @@ extern "C" PyObject* Py_InitModule4(const char* name, PyMethodDef* methods, cons
}
}
}
}
BoxedModule
*
module
=
createModule
(
name
,
NULL
,
doc
);
BoxedModule
*
module
=
createModule
(
boxString
(
name
)
,
NULL
,
doc
);
// Pass self as is, even if NULL we are not allowed to change it to None
// Pass self as is, even if NULL we are not allowed to change it to None
Box
*
passthrough
=
static_cast
<
Box
*>
(
self
);
Box
*
passthrough
=
static_cast
<
Box
*>
(
self
);
...
...
src/core/types.h
View file @
d50f760f
...
@@ -711,8 +711,8 @@ class BoxedClass;
...
@@ -711,8 +711,8 @@ class BoxedClass;
// TODO these shouldn't be here
// TODO these shouldn't be here
void
setupRuntime
();
void
setupRuntime
();
void
teardownRuntime
();
void
teardownRuntime
();
Box
*
createAndRunModule
(
const
std
::
string
&
name
,
const
std
::
string
&
fn
);
Box
*
createAndRunModule
(
BoxedString
*
name
,
const
std
::
string
&
fn
);
BoxedModule
*
createModule
(
const
std
::
string
&
name
,
const
char
*
fn
=
NULL
,
const
char
*
doc
=
NULL
);
BoxedModule
*
createModule
(
BoxedString
*
name
,
const
char
*
fn
=
NULL
,
const
char
*
doc
=
NULL
);
Box
*
moduleInit
(
BoxedModule
*
self
,
Box
*
name
,
Box
*
doc
=
NULL
);
Box
*
moduleInit
(
BoxedModule
*
self
,
Box
*
name
,
Box
*
doc
=
NULL
);
// TODO where to put this
// TODO where to put this
...
...
src/jit.cpp
View file @
d50f760f
...
@@ -417,7 +417,7 @@ static int main(int argc, char** argv) {
...
@@ -417,7 +417,7 @@ static int main(int argc, char** argv) {
// if the user invoked `pyston -c command`
// if the user invoked `pyston -c command`
if
(
command
!=
NULL
)
{
if
(
command
!=
NULL
)
{
try
{
try
{
main_module
=
createModule
(
"__main__"
,
"<string>"
);
main_module
=
createModule
(
boxString
(
"__main__"
)
,
"<string>"
);
AST_Module
*
m
=
parse_string
(
command
);
AST_Module
*
m
=
parse_string
(
command
);
compileAndRunModule
(
m
,
main_module
);
compileAndRunModule
(
m
,
main_module
);
rtncode
=
0
;
rtncode
=
0
;
...
@@ -428,7 +428,7 @@ static int main(int argc, char** argv) {
...
@@ -428,7 +428,7 @@ static int main(int argc, char** argv) {
}
}
}
else
if
(
module
!=
NULL
)
{
}
else
if
(
module
!=
NULL
)
{
// TODO: CPython uses the same main module for all code paths
// TODO: CPython uses the same main module for all code paths
main_module
=
createModule
(
"__main__"
,
"<string>"
);
main_module
=
createModule
(
boxString
(
"__main__"
)
,
"<string>"
);
rtncode
=
(
RunModule
(
module
,
1
)
!=
0
);
rtncode
=
(
RunModule
(
module
,
1
)
!=
0
);
}
else
{
}
else
{
rtncode
=
0
;
rtncode
=
0
;
...
@@ -455,7 +455,7 @@ static int main(int argc, char** argv) {
...
@@ -455,7 +455,7 @@ static int main(int argc, char** argv) {
prependToSysPath
(
real_path
);
prependToSysPath
(
real_path
);
free
(
real_path
);
free
(
real_path
);
main_module
=
createModule
(
"__main__"
,
fn
);
main_module
=
createModule
(
boxString
(
"__main__"
)
,
fn
);
try
{
try
{
AST_Module
*
ast
=
caching_parse_file
(
fn
);
AST_Module
*
ast
=
caching_parse_file
(
fn
);
compileAndRunModule
(
ast
,
main_module
);
compileAndRunModule
(
ast
,
main_module
);
...
@@ -474,7 +474,7 @@ static int main(int argc, char** argv) {
...
@@ -474,7 +474,7 @@ static int main(int argc, char** argv) {
Py_InspectFlag
=
0
;
Py_InspectFlag
=
0
;
if
(
!
main_module
)
{
if
(
!
main_module
)
{
main_module
=
createModule
(
"__main__"
,
"<stdin>"
);
main_module
=
createModule
(
boxString
(
"__main__"
)
,
"<stdin>"
);
}
else
{
}
else
{
// main_module->fn = "<stdin>";
// main_module->fn = "<stdin>";
}
}
...
...
src/runtime/builtin_modules/ast.cpp
View file @
d50f760f
...
@@ -66,7 +66,7 @@ extern "C" int PyAST_Check(PyObject* o) noexcept {
...
@@ -66,7 +66,7 @@ extern "C" int PyAST_Check(PyObject* o) noexcept {
}
}
void
setupAST
()
{
void
setupAST
()
{
BoxedModule
*
ast_module
=
createModule
(
"_ast"
,
"__builtin__"
);
BoxedModule
*
ast_module
=
createModule
(
boxString
(
"_ast"
)
,
"__builtin__"
);
ast_module
->
giveAttr
(
"PyCF_ONLY_AST"
,
boxInt
(
PyCF_ONLY_AST
));
ast_module
->
giveAttr
(
"PyCF_ONLY_AST"
,
boxInt
(
PyCF_ONLY_AST
));
...
...
src/runtime/builtin_modules/builtins.cpp
View file @
d50f760f
...
@@ -1449,9 +1449,9 @@ Box* builtinFormat(Box* value, Box* format_spec) {
...
@@ -1449,9 +1449,9 @@ Box* builtinFormat(Box* value, Box* format_spec) {
}
}
void
setupBuiltins
()
{
void
setupBuiltins
()
{
builtins_module
builtins_module
=
createModule
(
boxString
(
"__builtin__"
),
NULL
,
=
createModule
(
"__builtin__"
,
NULL
,
"Built-in functions, exceptions, and other objects.
\n\n
Noteworthy: None is "
"Built-in functions, exceptions, and other objects.
\n\n
Noteworthy: None is "
"the `nil' object; Ellipsis represents `...' in slices."
);
"the `nil' object; Ellipsis represents `...' in slices."
);
BoxedHeapClass
*
ellipsis_cls
BoxedHeapClass
*
ellipsis_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
NULL
,
0
,
0
,
sizeof
(
Box
),
false
,
"ellipsis"
);
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
NULL
,
0
,
0
,
sizeof
(
Box
),
false
,
"ellipsis"
);
...
...
src/runtime/builtin_modules/gc.cpp
View file @
d50f760f
...
@@ -43,7 +43,7 @@ static Box* enable() {
...
@@ -43,7 +43,7 @@ static Box* enable() {
}
}
void
setupGC
()
{
void
setupGC
()
{
BoxedModule
*
gc_module
=
createModule
(
"gc"
);
BoxedModule
*
gc_module
=
createModule
(
boxString
(
"gc"
)
);
gc_module
->
giveAttr
(
"collect"
,
gc_module
->
giveAttr
(
"collect"
,
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
gcCollect
,
NONE
,
0
),
"collect"
));
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
gcCollect
,
NONE
,
0
),
"collect"
));
...
...
src/runtime/builtin_modules/pyston.cpp
View file @
d50f760f
...
@@ -64,7 +64,7 @@ static Box* dumpStats(Box* includeZeros) {
...
@@ -64,7 +64,7 @@ static Box* dumpStats(Box* includeZeros) {
}
}
void
setupPyston
()
{
void
setupPyston
()
{
pyston_module
=
createModule
(
"__pyston__"
);
pyston_module
=
createModule
(
boxString
(
"__pyston__"
)
);
pyston_module
->
giveAttr
(
"setOption"
,
pyston_module
->
giveAttr
(
"setOption"
,
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
setOption
,
UNKNOWN
,
2
),
"setOption"
));
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
setOption
,
UNKNOWN
,
2
),
"setOption"
));
...
...
src/runtime/builtin_modules/sys.cpp
View file @
d50f760f
...
@@ -586,7 +586,7 @@ void setupSys() {
...
@@ -586,7 +586,7 @@ void setupSys() {
gc
::
registerPermanentRoot
(
sys_modules_dict
);
gc
::
registerPermanentRoot
(
sys_modules_dict
);
// This is ok to call here because we've already created the sys_modules_dict
// This is ok to call here because we've already created the sys_modules_dict
sys_module
=
createModule
(
"sys"
);
sys_module
=
createModule
(
boxString
(
"sys"
)
);
sys_module
->
giveAttr
(
"modules"
,
sys_modules_dict
);
sys_module
->
giveAttr
(
"modules"
,
sys_modules_dict
);
...
...
src/runtime/import.cpp
View file @
d50f760f
This diff is collapsed.
Click to expand it.
src/runtime/import.h
View file @
d50f760f
...
@@ -21,7 +21,7 @@ namespace pyston {
...
@@ -21,7 +21,7 @@ namespace pyston {
extern
"C"
Box
*
import
(
int
level
,
Box
*
from_imports
,
llvm
::
StringRef
module_name
);
extern
"C"
Box
*
import
(
int
level
,
Box
*
from_imports
,
llvm
::
StringRef
module_name
);
extern
Box
*
importModuleLevel
(
llvm
::
StringRef
module_name
,
Box
*
globals
,
Box
*
from_imports
,
int
level
);
extern
Box
*
importModuleLevel
(
llvm
::
StringRef
module_name
,
Box
*
globals
,
Box
*
from_imports
,
int
level
);
BoxedModule
*
importCExtension
(
const
std
::
string
&
full_name
,
const
std
::
string
&
last_name
,
const
std
::
string
&
path
);
BoxedModule
*
importCExtension
(
BoxedString
*
full_name
,
const
std
::
string
&
last_name
,
const
std
::
string
&
path
);
}
}
#endif
#endif
src/runtime/types.cpp
View file @
d50f760f
...
@@ -3816,26 +3816,25 @@ void setupRuntime() {
...
@@ -3816,26 +3816,25 @@ void setupRuntime() {
TRACK_ALLOCATIONS
=
true
;
TRACK_ALLOCATIONS
=
true
;
}
}
BoxedModule
*
createModule
(
const
std
::
string
&
name
,
const
char
*
fn
,
const
char
*
doc
)
{
BoxedModule
*
createModule
(
BoxedString
*
name
,
const
char
*
fn
,
const
char
*
doc
)
{
assert
((
!
fn
||
strlen
(
fn
))
&&
"probably wanted to set the fn to <stdin>?"
);
assert
((
!
fn
||
strlen
(
fn
))
&&
"probably wanted to set the fn to <stdin>?"
);
BoxedDict
*
d
=
getSysModulesDict
();
BoxedDict
*
d
=
getSysModulesDict
();
Box
*
b_name
=
boxString
(
name
);
// Surprisingly, there are times that we need to return the existing module if
// Surprisingly, there are times that we need to return the existing module if
// one exists:
// one exists:
Box
*
existing
=
d
->
getOrNull
(
b_
name
);
Box
*
existing
=
d
->
getOrNull
(
name
);
if
(
existing
&&
PyModule_Check
(
existing
))
{
if
(
existing
&&
PyModule_Check
(
existing
))
{
return
static_cast
<
BoxedModule
*>
(
existing
);
return
static_cast
<
BoxedModule
*>
(
existing
);
}
}
BoxedModule
*
module
=
new
BoxedModule
();
BoxedModule
*
module
=
new
BoxedModule
();
moduleInit
(
module
,
boxString
(
name
)
,
boxString
(
doc
?
doc
:
""
));
moduleInit
(
module
,
name
,
boxString
(
doc
?
doc
:
""
));
if
(
fn
)
if
(
fn
)
module
->
giveAttr
(
"__file__"
,
boxString
(
fn
));
module
->
giveAttr
(
"__file__"
,
boxString
(
fn
));
d
->
d
[
b_
name
]
=
module
;
d
->
d
[
name
]
=
module
;
if
(
name
==
"__main__"
)
if
(
name
->
s
()
==
"__main__"
)
module
->
giveAttr
(
"__builtins__"
,
builtins_module
);
module
->
giveAttr
(
"__builtins__"
,
builtins_module
);
return
module
;
return
module
;
}
}
...
...
test/unittests/analysis.cpp
View file @
d50f760f
...
@@ -40,7 +40,7 @@ TEST_F(AnalysisTest, augassign) {
...
@@ -40,7 +40,7 @@ TEST_F(AnalysisTest, augassign) {
FutureFlags
future_flags
=
getFutureFlags
(
module
->
body
,
fn
.
c_str
());
FutureFlags
future_flags
=
getFutureFlags
(
module
->
body
,
fn
.
c_str
());
SourceInfo
*
si
=
new
SourceInfo
(
createModule
(
"augassign"
,
fn
.
c_str
()),
scoping
,
future_flags
,
func
,
SourceInfo
*
si
=
new
SourceInfo
(
createModule
(
boxString
(
"augassign"
)
,
fn
.
c_str
()),
scoping
,
future_flags
,
func
,
func
->
body
,
boxString
(
fn
));
func
->
body
,
boxString
(
fn
));
CFG
*
cfg
=
computeCFG
(
si
,
func
->
body
);
CFG
*
cfg
=
computeCFG
(
si
,
func
->
body
);
...
@@ -70,7 +70,7 @@ void doOsrTest(bool is_osr, bool i_maybe_undefined) {
...
@@ -70,7 +70,7 @@ void doOsrTest(bool is_osr, bool i_maybe_undefined) {
FutureFlags
future_flags
=
getFutureFlags
(
module
->
body
,
fn
.
c_str
());
FutureFlags
future_flags
=
getFutureFlags
(
module
->
body
,
fn
.
c_str
());
ScopeInfo
*
scope_info
=
scoping
->
getScopeInfoForNode
(
func
);
ScopeInfo
*
scope_info
=
scoping
->
getScopeInfoForNode
(
func
);
std
::
unique_ptr
<
SourceInfo
>
si
(
new
SourceInfo
(
createModule
(
"osr"
+
std
::
to_string
((
is_osr
<<
1
)
+
i_maybe_undefined
),
std
::
unique_ptr
<
SourceInfo
>
si
(
new
SourceInfo
(
createModule
(
boxString
(
"osr"
+
std
::
to_string
((
is_osr
<<
1
)
+
i_maybe_undefined
)
),
fn
.
c_str
()),
scoping
,
future_flags
,
func
,
func
->
body
,
boxString
(
fn
)));
fn
.
c_str
()),
scoping
,
future_flags
,
func
,
func
->
body
,
boxString
(
fn
)));
CLFunction
*
clfunc
=
new
CLFunction
(
0
,
0
,
false
,
false
,
std
::
move
(
si
));
CLFunction
*
clfunc
=
new
CLFunction
(
0
,
0
,
false
,
false
,
std
::
move
(
si
));
...
...
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