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
409288eb
Commit
409288eb
authored
Jul 31, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CAPI exceptions for runtimeCall
parent
81a9564c
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
75 additions
and
27 deletions
+75
-27
src/codegen/compvars.cpp
src/codegen/compvars.cpp
+15
-8
src/codegen/runtime_hooks.cpp
src/codegen/runtime_hooks.cpp
+22
-8
src/codegen/runtime_hooks.h
src/codegen/runtime_hooks.h
+1
-1
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+19
-7
src/runtime/inline/link_forcer.cpp
src/runtime/inline/link_forcer.cpp
+1
-0
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+16
-3
src/runtime/objmodel.h
src/runtime/objmodel.h
+1
-0
No files found.
src/codegen/compvars.cpp
View file @
409288eb
...
...
@@ -613,7 +613,8 @@ static ConcreteCompilerVariable* _call(IREmitter& emitter, const OpInfo& info, l
// for (auto a : llvm_args)
// a->dump();
bool
do_patchpoint
=
ENABLE_ICCALLSITES
&&
(
func_addr
==
runtimeCall
||
func_addr
==
pyston
::
callattr
);
bool
do_patchpoint
=
ENABLE_ICCALLSITES
&&
(
func_addr
==
runtimeCall
||
func_addr
==
runtimeCallCapi
||
func_addr
==
pyston
::
callattr
);
if
(
do_patchpoint
)
{
assert
(
func_addr
);
...
...
@@ -655,26 +656,32 @@ CompilerVariable* UnknownType::call(IREmitter& emitter, const OpInfo& info, Conc
bool
pass_keywords
=
(
argspec
.
num_keywords
!=
0
);
int
npassed_args
=
argspec
.
totalPassed
();
ExceptionStyle
exception_style
=
((
FORCE_LLVM_CAPI
&&
!
info
.
unw_info
.
cxx_exc_dest
)
||
info
.
unw_info
.
capi_exc_dest
)
?
ExceptionStyle
::
CAPI
:
ExceptionStyle
::
CXX
;
llvm
::
Value
*
func
;
if
(
pass_keywords
)
func
=
g
.
funcs
.
runtimeCall
;
func
=
g
.
funcs
.
runtimeCall
.
get
(
exception_style
)
;
else
if
(
npassed_args
==
0
)
func
=
g
.
funcs
.
runtimeCall0
;
func
=
g
.
funcs
.
runtimeCall0
.
get
(
exception_style
)
;
else
if
(
npassed_args
==
1
)
func
=
g
.
funcs
.
runtimeCall1
;
func
=
g
.
funcs
.
runtimeCall1
.
get
(
exception_style
)
;
else
if
(
npassed_args
==
2
)
func
=
g
.
funcs
.
runtimeCall2
;
func
=
g
.
funcs
.
runtimeCall2
.
get
(
exception_style
)
;
else
if
(
npassed_args
==
3
)
func
=
g
.
funcs
.
runtimeCall3
;
func
=
g
.
funcs
.
runtimeCall3
.
get
(
exception_style
)
;
else
func
=
g
.
funcs
.
runtimeCallN
;
func
=
g
.
funcs
.
runtimeCallN
.
get
(
exception_style
);
void
*
func_ptr
=
(
exception_style
==
ExceptionStyle
::
CXX
)
?
(
void
*
)
runtimeCall
:
(
void
*
)
runtimeCallCapi
;
std
::
vector
<
llvm
::
Value
*>
other_args
;
other_args
.
push_back
(
var
->
getValue
());
llvm
::
Value
*
llvm_argspec
=
llvm
::
ConstantInt
::
get
(
g
.
i32
,
argspec
.
asInt
(),
false
);
other_args
.
push_back
(
llvm_argspec
);
return
_call
(
emitter
,
info
,
func
,
CXX
,
(
void
*
)
runtimeCall
,
other_args
,
argspec
,
args
,
keyword_names
,
UNKNOWN
);
return
_call
(
emitter
,
info
,
func
,
exception_style
,
func_ptr
,
other_args
,
argspec
,
args
,
keyword_names
,
UNKNOWN
);
}
CompilerVariable
*
UnknownType
::
callattr
(
IREmitter
&
emitter
,
const
OpInfo
&
info
,
ConcreteCompilerVariable
*
var
,
...
...
src/codegen/runtime_hooks.cpp
View file @
409288eb
...
...
@@ -245,18 +245,32 @@ void initGlobalFuncs(GlobalState& g) {
GET
(
boxedLocalsGet
);
GET
(
boxedLocalsDel
);
g
.
funcs
.
runtimeCall
=
getFunc
((
void
*
)
runtimeCall
,
"runtimeCall"
);
g
.
funcs
.
runtimeCall0
=
addFunc
((
void
*
)
runtimeCall
,
g
.
llvm_value_type_ptr
,
g
.
llvm_value_type_ptr
,
g
.
i32
);
g
.
funcs
.
runtimeCall1
g
.
funcs
.
runtimeCall
.
cxx_val
=
getFunc
((
void
*
)
runtimeCall
,
"runtimeCall"
);
g
.
funcs
.
runtimeCall0
.
cxx_val
=
addFunc
((
void
*
)
runtimeCall
,
g
.
llvm_value_type_ptr
,
g
.
llvm_value_type_ptr
,
g
.
i32
);
g
.
funcs
.
runtimeCall1
.
cxx_val
=
addFunc
((
void
*
)
runtimeCall
,
g
.
llvm_value_type_ptr
,
g
.
llvm_value_type_ptr
,
g
.
i32
,
g
.
llvm_value_type_ptr
);
g
.
funcs
.
runtimeCall2
=
addFunc
((
void
*
)
runtimeCall
,
g
.
llvm_value_type_ptr
,
g
.
llvm_value_type_ptr
,
g
.
i32
,
g
.
funcs
.
runtimeCall2
.
cxx_val
=
addFunc
((
void
*
)
runtimeCall
,
g
.
llvm_value_type_ptr
,
g
.
llvm_value_type_ptr
,
g
.
i32
,
g
.
llvm_value_type_ptr
,
g
.
llvm_value_type_ptr
);
g
.
funcs
.
runtimeCall3
=
addFunc
((
void
*
)
runtimeCall
,
g
.
llvm_value_type_ptr
,
g
.
llvm_value_type_ptr
,
g
.
i32
,
g
.
funcs
.
runtimeCall3
.
cxx_val
=
addFunc
((
void
*
)
runtimeCall
,
g
.
llvm_value_type_ptr
,
g
.
llvm_value_type_ptr
,
g
.
i32
,
g
.
llvm_value_type_ptr
,
g
.
llvm_value_type_ptr
,
g
.
llvm_value_type_ptr
);
g
.
funcs
.
runtimeCallN
g
.
funcs
.
runtimeCallN
.
cxx_val
=
addFunc
((
void
*
)
runtimeCall
,
g
.
llvm_value_type_ptr
,
g
.
llvm_value_type_ptr
,
g
.
i32
,
g
.
llvm_value_type_ptr
,
g
.
llvm_value_type_ptr
,
g
.
llvm_value_type_ptr
,
g
.
llvm_value_type_ptr
->
getPointerTo
());
g
.
funcs
.
runtimeCall
.
capi_val
=
getFunc
((
void
*
)
runtimeCallCapi
,
"runtimeCallCapi"
);
g
.
funcs
.
runtimeCall0
.
capi_val
=
addFunc
((
void
*
)
runtimeCallCapi
,
g
.
llvm_value_type_ptr
,
g
.
llvm_value_type_ptr
,
g
.
i32
);
g
.
funcs
.
runtimeCall1
.
capi_val
=
addFunc
((
void
*
)
runtimeCallCapi
,
g
.
llvm_value_type_ptr
,
g
.
llvm_value_type_ptr
,
g
.
i32
,
g
.
llvm_value_type_ptr
);
g
.
funcs
.
runtimeCall2
.
capi_val
=
addFunc
((
void
*
)
runtimeCallCapi
,
g
.
llvm_value_type_ptr
,
g
.
llvm_value_type_ptr
,
g
.
i32
,
g
.
llvm_value_type_ptr
,
g
.
llvm_value_type_ptr
);
g
.
funcs
.
runtimeCall3
.
capi_val
=
addFunc
((
void
*
)
runtimeCallCapi
,
g
.
llvm_value_type_ptr
,
g
.
llvm_value_type_ptr
,
g
.
i32
,
g
.
llvm_value_type_ptr
,
g
.
llvm_value_type_ptr
,
g
.
llvm_value_type_ptr
);
g
.
funcs
.
runtimeCallN
.
capi_val
=
addFunc
((
void
*
)
runtimeCallCapi
,
g
.
llvm_value_type_ptr
,
g
.
llvm_value_type_ptr
,
g
.
i32
,
g
.
llvm_value_type_ptr
,
g
.
llvm_value_type_ptr
,
g
.
llvm_value_type_ptr
,
g
.
llvm_value_type_ptr
->
getPointerTo
());
g
.
funcs
.
callattr
=
getFunc
((
void
*
)
callattr
,
"callattr"
);
g
.
funcs
.
callattr0
=
addFunc
((
void
*
)
callattr
,
g
.
llvm_value_type_ptr
,
g
.
llvm_value_type_ptr
,
g
.
llvm_boxedstring_type_ptr
,
g
.
i64
);
...
...
src/codegen/runtime_hooks.h
View file @
409288eb
...
...
@@ -43,7 +43,7 @@ struct GlobalFuncs {
*
raiseAttributeErrorStrCapi
,
*
raiseNotIterableError
,
*
raiseIndexErrorStr
,
*
raiseIndexErrorStrCapi
,
*
assertNameDefined
,
*
assertFail
,
*
assertFailDerefNameDefined
,
*
printExprHelper
;
llvm
::
Value
*
printFloat
,
*
listAppendInternal
,
*
getSysStdout
;
llvm
::
Value
*
runtimeCall0
,
*
runtimeCall1
,
*
runtimeCall2
,
*
runtimeCall3
,
*
runtimeCall
,
*
runtimeCallN
;
ExceptionSwitchable
<
llvm
::
Value
*>
runtimeCall0
,
runtimeCall1
,
runtimeCall2
,
runtimeCall3
,
runtimeCall
,
runtimeCallN
;
llvm
::
Value
*
callattr0
,
*
callattr1
,
*
callattr2
,
*
callattr3
,
*
callattr
,
*
callattrN
;
llvm
::
Value
*
reoptCompiledFunc
,
*
compilePartialFunc
;
llvm
::
Value
*
exec
;
...
...
src/runtime/builtin_modules/builtins.cpp
View file @
409288eb
...
...
@@ -457,10 +457,22 @@ Box* delattrFunc(Box* obj, Box* _str) {
return
None
;
}
Box
*
getattrFunc
(
Box
*
obj
,
Box
*
_str
,
Box
*
default_value
)
{
template
<
ExceptionStyle
S
>
Box
*
getattrFunc
(
Box
*
obj
,
Box
*
_str
,
Box
*
default_value
)
noexcept
(
S
==
CAPI
)
{
try
{
_str
=
coerceUnicodeToStr
(
_str
);
}
catch
(
ExcInfo
e
)
{
if
(
S
==
CAPI
)
{
setCAPIException
(
e
);
return
NULL
;
}
else
throw
e
;
}
if
(
!
isSubclass
(
_str
->
cls
,
str_cls
))
{
if
(
S
==
CAPI
)
{
PyErr_SetString
(
TypeError
,
"getattr(): attribute name must be string"
);
return
NULL
;
}
else
raiseExcHelper
(
TypeError
,
"getattr(): attribute name must be string"
);
}
...
...
@@ -470,7 +482,7 @@ Box* getattrFunc(Box* obj, Box* _str, Box* default_value) {
return
default_value
;
}
if
(
!
rtn
)
if
(
S
==
CXX
&&
!
rtn
)
throwCAPIException
();
return
rtn
;
}
...
...
@@ -1437,9 +1449,9 @@ void setupBuiltins() {
builtins_module
->
giveAttr
(
"delattr"
,
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
delattrFunc
,
NONE
,
2
),
"delattr"
));
builtins_module
->
giveAttr
(
"getattr"
,
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
getattrFunc
,
UNKNOWN
,
3
,
1
,
false
,
false
),
"getattr"
,
{
NULL
}));
auto
getattr_func
=
boxRTFunction
((
void
*
)
getattrFunc
<
CXX
>
,
UNKNOWN
,
3
,
1
,
false
,
false
,
ParamNames
::
empty
(),
CXX
);
addRTFunction
(
getattr_func
,
(
void
*
)
getattrFunc
<
CAPI
>
,
UNKNOWN
,
CAPI
);
builtins_module
->
giveAttr
(
"getattr"
,
new
BoxedBuiltinFunctionOrMethod
(
getattr_func
,
"getattr"
,
{
NULL
}));
builtins_module
->
giveAttr
(
"setattr"
,
...
...
src/runtime/inline/link_forcer.cpp
View file @
409288eb
...
...
@@ -120,6 +120,7 @@ void force() {
FORCE
(
getSysStdout
);
FORCE
(
runtimeCall
);
FORCE
(
runtimeCallCapi
);
FORCE
(
callattr
);
FORCE
(
raise0
);
...
...
src/runtime/objmodel.cpp
View file @
409288eb
...
...
@@ -3366,9 +3366,17 @@ Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpe
oargs
=
NULL
;
}
try
{
rearrangeArguments
(
paramspec
,
&
f
->
param_names
,
getFunctionName
(
f
).
data
(),
paramspec
.
num_defaults
?
func
->
defaults
->
elts
:
NULL
,
rewrite_args
,
rewrite_success
,
argspec
,
arg1
,
arg2
,
arg3
,
args
,
keyword_names
,
oarg1
,
oarg2
,
oarg3
,
oargs
);
}
catch
(
ExcInfo
e
)
{
if
(
S
==
CAPI
)
{
setCAPIException
(
e
);
return
NULL
;
}
else
throw
e
;
}
#if 0
for (int i = 0; i < num_output_args; i++) {
...
...
@@ -3850,6 +3858,11 @@ extern "C" Box* runtimeCall(Box* obj, ArgPassSpec argspec, Box* arg1, Box* arg2,
return
rtn
;
}
extern
"C"
Box
*
runtimeCallCapi
(
Box
*
obj
,
ArgPassSpec
argspec
,
Box
*
arg1
,
Box
*
arg2
,
Box
*
arg3
,
Box
**
args
,
const
std
::
vector
<
BoxedString
*>*
keyword_names
)
noexcept
{
return
runtimeCallInternal
<
CAPI
>
(
obj
,
NULL
,
argspec
,
arg1
,
arg2
,
arg3
,
args
,
keyword_names
);
}
extern
"C"
Box
*
binopInternal
(
Box
*
lhs
,
Box
*
rhs
,
int
op_type
,
bool
inplace
,
BinopRewriteArgs
*
rewrite_args
)
{
// TODO handle the case of the rhs being a subclass of the lhs
// this could get really annoying because you can dynamically make one type a subclass
...
...
src/runtime/objmodel.h
View file @
409288eb
...
...
@@ -65,6 +65,7 @@ extern "C" void delattrMaybeNonstring(Box* obj, Box* attr);
extern
"C"
void
delattrGeneric
(
Box
*
obj
,
BoxedString
*
attr
,
DelattrRewriteArgs
*
rewrite_args
);
extern
"C"
bool
nonzero
(
Box
*
obj
);
extern
"C"
Box
*
runtimeCall
(
Box
*
,
ArgPassSpec
,
Box
*
,
Box
*
,
Box
*
,
Box
**
,
const
std
::
vector
<
BoxedString
*>*
);
extern
"C"
Box
*
runtimeCallCapi
(
Box
*
,
ArgPassSpec
,
Box
*
,
Box
*
,
Box
*
,
Box
**
,
const
std
::
vector
<
BoxedString
*>*
)
noexcept
;
extern
"C"
Box
*
callattr
(
Box
*
,
BoxedString
*
,
CallattrFlags
,
Box
*
,
Box
*
,
Box
*
,
Box
**
,
const
std
::
vector
<
BoxedString
*>*
);
extern
"C"
BoxedString
*
str
(
Box
*
obj
);
extern
"C"
BoxedString
*
repr
(
Box
*
obj
);
...
...
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