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
2a223ebd
Commit
2a223ebd
authored
Aug 23, 2014
by
Travis Hance
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
import os.path
parent
d93ebf0f
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
139 additions
and
69 deletions
+139
-69
src/codegen/runtime_hooks.cpp
src/codegen/runtime_hooks.cpp
+1
-0
src/runtime/capi.cpp
src/runtime/capi.cpp
+1
-0
src/runtime/import.cpp
src/runtime/import.cpp
+107
-0
src/runtime/import.h
src/runtime/import.h
+25
-0
src/runtime/inline/link_forcer.cpp
src/runtime/inline/link_forcer.cpp
+1
-0
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+0
-68
src/runtime/objmodel.h
src/runtime/objmodel.h
+0
-1
test/tests/os_path.py
test/tests/os_path.py
+4
-0
No files found.
src/codegen/runtime_hooks.cpp
View file @
2a223ebd
...
...
@@ -35,6 +35,7 @@
#include "runtime/complex.h"
#include "runtime/float.h"
#include "runtime/generator.h"
#include "runtime/import.h"
#include "runtime/inline/boxing.h"
#include "runtime/int.h"
#include "runtime/long.h"
...
...
src/runtime/capi.cpp
View file @
2a223ebd
...
...
@@ -22,6 +22,7 @@
#include "codegen/compvars.h"
#include "core/threading.h"
#include "core/types.h"
#include "runtime/import.h"
#include "runtime/objmodel.h"
#include "runtime/types.h"
...
...
src/runtime/import.cpp
0 → 100644
View file @
2a223ebd
// Copyright (c) 2014 Dropbox, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "runtime/import.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "codegen/irgen/hooks.h"
#include "codegen/parser.h"
#include "runtime/capi.h"
#include "runtime/objmodel.h"
namespace
pyston
{
BoxedModule
*
compileAndRunModule
(
const
std
::
string
&
name
,
const
std
::
string
&
fn
,
bool
add_to_sys_modules
)
{
BoxedModule
*
module
=
createModule
(
name
,
fn
,
add_to_sys_modules
);
AST_Module
*
ast
=
caching_parse
(
fn
.
c_str
());
compileAndRunModule
(
ast
,
module
);
return
module
;
}
#if LLVMREV < 210072
#define LLVM_SYS_FS_EXISTS_CODE_OKAY(code) ((code) == 0)
#else
#define LLVM_SYS_FS_EXISTS_CODE_OKAY(code) (!(code))
#endif
extern
"C"
Box
*
import
(
const
std
::
string
*
name
)
{
assert
(
name
);
static
StatCounter
slowpath_import
(
"slowpath_import"
);
slowpath_import
.
log
();
Box
*
parent_module
=
NULL
;
size_t
periodIndex
=
name
->
rfind
(
'.'
);
if
(
periodIndex
!=
std
::
string
::
npos
)
{
std
::
string
parent_name
(
*
name
,
0
,
periodIndex
);
parent_module
=
import
(
&
parent_name
);
}
BoxedDict
*
sys_modules
=
getSysModulesDict
();
Box
*
s
=
boxStringPtr
(
name
);
if
(
sys_modules
->
d
.
find
(
s
)
!=
sys_modules
->
d
.
end
())
return
sys_modules
->
d
[
s
];
BoxedList
*
path_list
;
if
(
parent_module
==
NULL
)
{
path_list
=
getSysPath
();
if
(
path_list
==
NULL
||
path_list
->
cls
!=
list_cls
)
{
raiseExcHelper
(
RuntimeError
,
"sys.path must be a list of directory names"
);
}
}
else
{
path_list
=
static_cast
<
BoxedList
*>
(
parent_module
->
getattr
(
"__path__"
,
NULL
));
if
(
path_list
==
NULL
||
path_list
->
cls
!=
list_cls
)
{
raiseExcHelper
(
ImportError
,
"No module named %s"
,
name
->
c_str
());
}
}
llvm
::
SmallString
<
128
>
joined_path
;
for
(
int
i
=
0
;
i
<
path_list
->
size
;
i
++
)
{
Box
*
_p
=
path_list
->
elts
->
elts
[
i
];
if
(
_p
->
cls
!=
str_cls
)
continue
;
BoxedString
*
p
=
static_cast
<
BoxedString
*>
(
_p
);
joined_path
.
clear
();
llvm
::
sys
::
path
::
append
(
joined_path
,
p
->
s
,
*
name
+
".py"
);
std
::
string
fn
(
joined_path
.
str
());
if
(
VERBOSITY
()
>=
2
)
printf
(
"Searching for %s at %s...
\n
"
,
name
->
c_str
(),
fn
.
c_str
());
bool
exists
;
llvm
::
error_code
code
=
llvm
::
sys
::
fs
::
exists
(
joined_path
.
str
(),
exists
);
assert
(
LLVM_SYS_FS_EXISTS_CODE_OKAY
(
code
));
if
(
!
exists
)
continue
;
if
(
VERBOSITY
()
>=
1
)
printf
(
"Importing %s from %s
\n
"
,
name
->
c_str
(),
fn
.
c_str
());
// TODO duplication with jit.cpp:
BoxedModule
*
module
=
compileAndRunModule
(
*
name
,
fn
,
true
);
return
module
;
}
if
(
*
name
==
"test"
)
{
return
importTestExtension
();
}
raiseExcHelper
(
ImportError
,
"No module named %s"
,
name
->
c_str
());
}
}
src/runtime/import.h
0 → 100644
View file @
2a223ebd
// Copyright (c) 2014 Dropbox, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef PYSTON_RUNTIME_IMPORT_H
#define PYSTON_RUNTIME_IMPORT_H
#include "runtime/types.h"
namespace
pyston
{
extern
"C"
Box
*
import
(
const
std
::
string
*
name
);
}
#endif
src/runtime/inline/link_forcer.cpp
View file @
2a223ebd
...
...
@@ -20,6 +20,7 @@
#include "runtime/complex.h"
#include "runtime/float.h"
#include "runtime/generator.h"
#include "runtime/import.h"
#include "runtime/inline/boxing.h"
#include "runtime/int.h"
#include "runtime/list.h"
...
...
src/runtime/objmodel.cpp
View file @
2a223ebd
...
...
@@ -21,9 +21,6 @@
#include <memory>
#include <stdint.h>
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "asm_writing/icinfo.h"
#include "asm_writing/rewriter.h"
#include "codegen/compvars.h"
...
...
@@ -3587,71 +3584,6 @@ extern "C" Box* getGlobal(BoxedModule* m, std::string* name) {
raiseExcHelper
(
NameError
,
"global name '%s' is not defined"
,
name
->
c_str
());
}
BoxedModule
*
compileAndRunModule
(
const
std
::
string
&
name
,
const
std
::
string
&
fn
,
bool
add_to_sys_modules
)
{
BoxedModule
*
module
=
createModule
(
name
,
fn
,
add_to_sys_modules
);
AST_Module
*
ast
=
caching_parse
(
fn
.
c_str
());
compileAndRunModule
(
ast
,
module
);
return
module
;
}
// TODO I feel like importing should go somewhere else; it's more closely tied to codegen
// than to the object model.
extern
"C"
Box
*
import
(
const
std
::
string
*
name
)
{
assert
(
name
);
static
StatCounter
slowpath_import
(
"slowpath_import"
);
slowpath_import
.
log
();
BoxedDict
*
sys_modules
=
getSysModulesDict
();
Box
*
s
=
boxStringPtr
(
name
);
if
(
sys_modules
->
d
.
find
(
s
)
!=
sys_modules
->
d
.
end
())
return
sys_modules
->
d
[
s
];
BoxedList
*
sys_path
=
getSysPath
();
if
(
sys_path
->
cls
!=
list_cls
)
{
raiseExcHelper
(
RuntimeError
,
"sys.path must be a list of directory name"
);
}
llvm
::
SmallString
<
128
>
joined_path
;
for
(
int
i
=
0
;
i
<
sys_path
->
size
;
i
++
)
{
Box
*
_p
=
sys_path
->
elts
->
elts
[
i
];
if
(
_p
->
cls
!=
str_cls
)
continue
;
BoxedString
*
p
=
static_cast
<
BoxedString
*>
(
_p
);
joined_path
.
clear
();
llvm
::
sys
::
path
::
append
(
joined_path
,
p
->
s
,
*
name
+
".py"
);
std
::
string
fn
(
joined_path
.
str
());
if
(
VERBOSITY
()
>=
2
)
printf
(
"Searching for %s at %s...
\n
"
,
name
->
c_str
(),
fn
.
c_str
());
bool
exists
;
llvm
::
error_code
code
=
llvm
::
sys
::
fs
::
exists
(
joined_path
.
str
(),
exists
);
#if LLVMREV < 210072
assert
(
code
==
0
);
#else
assert
(
!
code
);
#endif
if
(
!
exists
)
continue
;
if
(
VERBOSITY
()
>=
1
)
printf
(
"Importing %s from %s
\n
"
,
name
->
c_str
(),
fn
.
c_str
());
// TODO duplication with jit.cpp:
BoxedModule
*
module
=
compileAndRunModule
(
*
name
,
fn
,
true
);
return
module
;
}
if
(
*
name
==
"test"
)
{
return
importTestExtension
();
}
raiseExcHelper
(
ImportError
,
"No module named %s"
,
name
->
c_str
());
}
extern
"C"
Box
*
importFrom
(
Box
*
_m
,
const
std
::
string
*
name
)
{
assert
(
_m
->
cls
==
module_cls
);
...
...
src/runtime/objmodel.h
View file @
2a223ebd
...
...
@@ -75,7 +75,6 @@ extern "C" void setitem(Box* target, Box* slice, Box* value);
extern
"C"
void
delitem
(
Box
*
target
,
Box
*
slice
);
extern
"C"
Box
*
getclsattr
(
Box
*
obj
,
const
char
*
attr
);
extern
"C"
Box
*
unaryop
(
Box
*
operand
,
int
op_type
);
extern
"C"
Box
*
import
(
const
std
::
string
*
name
);
extern
"C"
Box
*
importFrom
(
Box
*
obj
,
const
std
::
string
*
attr
);
extern
"C"
void
importStar
(
Box
*
from_module
,
BoxedModule
*
to_module
);
extern
"C"
void
checkUnpackingLength
(
i64
expected
,
i64
given
);
...
...
test/tests/os_path.py
0 → 100644
View file @
2a223ebd
# allow-warning
# gives some warnings about converting unicode -> str
import
os.path
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