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
c7b6726c
Commit
c7b6726c
authored
Oct 06, 2015
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #951 from undingen/rewritable2
Add more Rewritable template args to functions
parents
30f254d3
476ba43e
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
57 additions
and
20 deletions
+57
-20
src/core/types.h
src/core/types.h
+1
-1
src/runtime/generator.cpp
src/runtime/generator.cpp
+2
-2
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+51
-15
src/runtime/objmodel.h
src/runtime/objmodel.h
+2
-2
src/runtime/rewrite_args.h
src/runtime/rewrite_args.h
+1
-0
No files found.
src/core/types.h
View file @
c7b6726c
...
...
@@ -52,8 +52,8 @@ enum ExceptionStyle {
};
enum
Rewritable
{
REWRITABLE
,
NOT_REWRITABLE
,
REWRITABLE
,
};
template
<
typename
T
>
struct
ExceptionSwitchable
{
...
...
src/runtime/generator.cpp
View file @
c7b6726c
...
...
@@ -97,8 +97,8 @@ void generatorEntry(BoxedGenerator* g) {
BoxedFunctionBase
*
func
=
g
->
function
;
Box
**
args
=
g
->
args
?
&
g
->
args
->
elts
[
0
]
:
nullptr
;
callCLFunc
<
ExceptionStyle
::
CXX
>
(
func
->
f
,
nullptr
,
func
->
f
->
numReceivedArgs
(),
func
->
closure
,
g
,
func
->
globals
,
g
->
arg1
,
g
->
arg2
,
g
->
arg3
,
args
);
callCLFunc
<
ExceptionStyle
::
CXX
,
NOT_REWRITABLE
>
(
func
->
f
,
nullptr
,
func
->
f
->
numReceivedArgs
(),
func
->
closure
,
g
,
func
->
globals
,
g
->
arg1
,
g
->
arg2
,
g
->
arg3
,
args
);
}
catch
(
ExcInfo
e
)
{
// unhandled exception: propagate the exception to the caller
g
->
exception
=
e
;
...
...
src/runtime/objmodel.cpp
View file @
c7b6726c
...
...
@@ -1730,7 +1730,7 @@ Box* getattrInternalGeneric(Box* obj, BoxedString* attr, GetattrRewriteArgs* rew
grewrite_args
.
assertReturnConvention
(
ReturnConvention
::
NO_RETURN
);
}
}
else
{
descr
=
typeLookup
<
rewritable
>
(
obj
->
cls
,
attr
,
NULL
);
descr
=
typeLookup
(
obj
->
cls
,
attr
);
}
// Check if it's a data descriptor
...
...
@@ -3306,11 +3306,16 @@ ArgPassSpec bindObjIntoArgs(Box* bind_obj, RewriterVar* r_bind_obj, _CallRewrite
return
ArgPassSpec
(
argspec
.
num_args
+
1
,
argspec
.
num_keywords
,
argspec
.
has_starargs
,
argspec
.
has_kwargs
);
}
template
<
typename
FuncNameCB
>
template
<
Rewritable
rewritable
,
typename
FuncNameCB
>
void
rearrangeArgumentsInternal
(
ParamReceiveSpec
paramspec
,
const
ParamNames
*
param_names
,
FuncNameCB
func_name_cb
,
Box
**
defaults
,
_CallRewriteArgsBase
*
rewrite_args
,
bool
&
rewrite_success
,
ArgPassSpec
argspec
,
Box
*&
oarg1
,
Box
*&
oarg2
,
Box
*&
oarg3
,
Box
**
args
,
Box
**
oargs
,
const
std
::
vector
<
BoxedString
*>*
keyword_names
)
{
if
(
rewritable
==
NOT_REWRITABLE
)
{
assert
(
!
rewrite_args
);
rewrite_args
=
NULL
;
}
/*
* Procedure:
* - First match up positional arguments; any extra go to varargs. error if too many.
...
...
@@ -3689,19 +3694,35 @@ void rearrangeArgumentsInternal(ParamReceiveSpec paramspec, const ParamNames* pa
}
}
template
<
Rewritable
rewritable
>
void
rearrangeArguments
(
ParamReceiveSpec
paramspec
,
const
ParamNames
*
param_names
,
const
char
*
func_name
,
Box
**
defaults
,
_CallRewriteArgsBase
*
rewrite_args
,
bool
&
rewrite_success
,
ArgPassSpec
argspec
,
Box
*&
oarg1
,
Box
*&
oarg2
,
Box
*&
oarg3
,
Box
**
args
,
Box
**
oargs
,
const
std
::
vector
<
BoxedString
*>*
keyword_names
)
{
auto
func
=
[
func_name
]()
{
return
func_name
;
};
return
rearrangeArgumentsInternal
(
paramspec
,
param_names
,
func
,
defaults
,
rewrite_args
,
rewrite_success
,
argspec
,
oarg1
,
oarg2
,
oarg3
,
args
,
oargs
,
keyword_names
);
return
rearrangeArgumentsInternal
<
rewritable
>
(
paramspec
,
param_names
,
func
,
defaults
,
rewrite_args
,
rewrite_success
,
argspec
,
oarg1
,
oarg2
,
oarg3
,
args
,
oargs
,
keyword_names
);
}
template
void
rearrangeArguments
<
REWRITABLE
>(
ParamReceiveSpec
,
const
ParamNames
*
,
const
char
*
,
Box
**
,
_CallRewriteArgsBase
*
,
bool
&
,
ArgPassSpec
,
Box
*&
,
Box
*&
,
Box
*&
,
Box
**
,
Box
**
,
const
std
::
vector
<
BoxedString
*>*
);
template
void
rearrangeArguments
<
NOT_REWRITABLE
>(
ParamReceiveSpec
,
const
ParamNames
*
,
const
char
*
,
Box
**
,
_CallRewriteArgsBase
*
,
bool
&
,
ArgPassSpec
,
Box
*&
,
Box
*&
,
Box
*&
,
Box
**
,
Box
**
,
const
std
::
vector
<
BoxedString
*>*
);
static
StatCounter
slowpath_callfunc
(
"slowpath_callfunc"
);
template
<
ExceptionStyle
S
>
template
<
ExceptionStyle
S
,
Rewritable
rewritable
>
Box
*
callFunc
(
BoxedFunctionBase
*
func
,
CallRewriteArgs
*
rewrite_args
,
ArgPassSpec
argspec
,
Box
*
arg1
,
Box
*
arg2
,
Box
*
arg3
,
Box
**
args
,
const
std
::
vector
<
BoxedString
*>*
keyword_names
)
noexcept
(
S
==
CAPI
)
{
if
(
rewritable
==
NOT_REWRITABLE
)
{
assert
(
!
rewrite_args
);
rewrite_args
=
NULL
;
}
if
(
rewritable
==
REWRITABLE
&&
!
rewrite_args
)
return
callFunc
<
S
,
NOT_REWRITABLE
>
(
func
,
rewrite_args
,
argspec
,
arg1
,
arg2
,
arg3
,
args
,
keyword_names
);
#if STAT_TIMERS
StatTimer
::
assertActive
();
STAT_TIMER
(
t0
,
"us_timer_slowpath_callFunc"
,
0
);
...
...
@@ -3740,9 +3761,9 @@ Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpe
try
{
auto
func_name_cb
=
[
f
]()
{
return
getFunctionName
(
f
).
data
();
};
rearrangeArgumentsInternal
(
paramspec
,
&
f
->
param_names
,
func_name_cb
,
paramspec
.
num_defaults
?
func
->
defaults
->
elts
:
NULL
,
rewrite_args
,
rewrite_succes
s
,
argspec
,
arg1
,
arg2
,
arg3
,
args
,
oargs
,
keyword_names
);
rearrangeArgumentsInternal
<
rewritable
>
(
paramspec
,
&
f
->
param_names
,
func_name_cb
,
paramspec
.
num_defaults
?
func
->
defaults
->
elts
:
NULL
,
rewrite_arg
s
,
rewrite_success
,
argspec
,
arg1
,
arg2
,
arg3
,
args
,
oargs
,
keyword_names
);
}
catch
(
ExcInfo
e
)
{
if
(
S
==
CAPI
)
{
setCAPIException
(
e
);
...
...
@@ -3842,7 +3863,8 @@ Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpe
rewrite_args
->
out_success
=
true
;
}
}
else
{
res
=
callCLFunc
<
S
>
(
f
,
rewrite_args
,
num_output_args
,
closure
,
NULL
,
func
->
globals
,
arg1
,
arg2
,
arg3
,
oargs
);
res
=
callCLFunc
<
S
,
rewritable
>
(
f
,
rewrite_args
,
num_output_args
,
closure
,
NULL
,
func
->
globals
,
arg1
,
arg2
,
arg3
,
oargs
);
}
return
res
;
...
...
@@ -3926,10 +3948,15 @@ static Box* capiCallCxxHelper(Box* (*func_ptr)(void*, void*, void*, void*, void*
}
}
template
<
ExceptionStyle
S
>
template
<
ExceptionStyle
S
,
Rewritable
rewritable
>
Box
*
callCLFunc
(
CLFunction
*
f
,
CallRewriteArgs
*
rewrite_args
,
int
num_output_args
,
BoxedClosure
*
closure
,
BoxedGenerator
*
generator
,
Box
*
globals
,
Box
*
oarg1
,
Box
*
oarg2
,
Box
*
oarg3
,
Box
**
oargs
)
noexcept
(
S
==
CAPI
)
{
if
(
rewritable
==
NOT_REWRITABLE
)
{
assert
(
!
rewrite_args
);
rewrite_args
=
NULL
;
}
CompiledFunction
*
chosen_cf
=
pickVersion
(
f
,
S
,
num_output_args
,
oarg1
,
oarg2
,
oarg3
,
oargs
);
if
(
!
chosen_cf
)
{
...
...
@@ -4053,11 +4080,18 @@ Box* callCLFunc(CLFunction* f, CallRewriteArgs* rewrite_args, int num_output_arg
}
// force instantiation:
template
Box
*
callCLFunc
<
CAPI
>(
CLFunction
*
f
,
CallRewriteArgs
*
rewrite_args
,
int
num_output_args
,
BoxedClosure
*
closure
,
BoxedGenerator
*
generator
,
Box
*
globals
,
Box
*
oarg1
,
Box
*
oarg2
,
Box
*
oarg3
,
Box
**
oargs
);
template
Box
*
callCLFunc
<
CXX
>(
CLFunction
*
f
,
CallRewriteArgs
*
rewrite_args
,
int
num_output_args
,
BoxedClosure
*
closure
,
BoxedGenerator
*
generator
,
Box
*
globals
,
Box
*
oarg1
,
Box
*
oarg2
,
Box
*
oarg3
,
Box
**
oargs
);
template
Box
*
callCLFunc
<
CAPI
,
REWRITABLE
>(
CLFunction
*
f
,
CallRewriteArgs
*
rewrite_args
,
int
num_output_args
,
BoxedClosure
*
closure
,
BoxedGenerator
*
generator
,
Box
*
globals
,
Box
*
oarg1
,
Box
*
oarg2
,
Box
*
oarg3
,
Box
**
oargs
);
template
Box
*
callCLFunc
<
CXX
,
REWRITABLE
>(
CLFunction
*
f
,
CallRewriteArgs
*
rewrite_args
,
int
num_output_args
,
BoxedClosure
*
closure
,
BoxedGenerator
*
generator
,
Box
*
globals
,
Box
*
oarg1
,
Box
*
oarg2
,
Box
*
oarg3
,
Box
**
oargs
);
template
Box
*
callCLFunc
<
CAPI
,
NOT_REWRITABLE
>(
CLFunction
*
f
,
CallRewriteArgs
*
rewrite_args
,
int
num_output_args
,
BoxedClosure
*
closure
,
BoxedGenerator
*
generator
,
Box
*
globals
,
Box
*
oarg1
,
Box
*
oarg2
,
Box
*
oarg3
,
Box
**
oargs
);
template
Box
*
callCLFunc
<
CXX
,
NOT_REWRITABLE
>(
CLFunction
*
f
,
CallRewriteArgs
*
rewrite_args
,
int
num_output_args
,
BoxedClosure
*
closure
,
BoxedGenerator
*
generator
,
Box
*
globals
,
Box
*
oarg1
,
Box
*
oarg2
,
Box
*
oarg3
,
Box
**
oargs
);
template
<
ExceptionStyle
S
,
Rewritable
rewritable
>
Box
*
runtimeCallInternal
(
Box
*
obj
,
CallRewriteArgs
*
rewrite_args
,
ArgPassSpec
argspec
,
Box
*
arg1
,
Box
*
arg2
,
Box
*
arg3
,
...
...
@@ -4481,6 +4515,8 @@ Box* binopInternal(Box* lhs, Box* rhs, int op_type, bool inplace, BinopRewriteAr
raiseExcHelper
(
TypeError
,
"unsupported operand type(s) for %s%s: '%s' and '%s'"
,
op_sym
.
data
(),
op_sym_suffix
,
getTypeName
(
lhs
),
getTypeName
(
rhs
));
}
template
Box
*
binopInternal
<
REWRITABLE
>(
Box
*
,
Box
*
,
int
,
bool
,
BinopRewriteArgs
*
);
template
Box
*
binopInternal
<
NOT_REWRITABLE
>(
Box
*
,
Box
*
,
int
,
bool
,
BinopRewriteArgs
*
);
extern
"C"
Box
*
binop
(
Box
*
lhs
,
Box
*
rhs
,
int
op_type
)
{
STAT_TIMER
(
t0
,
"us_timer_slowpath_binop"
,
10
);
...
...
src/runtime/objmodel.h
View file @
c7b6726c
...
...
@@ -138,7 +138,7 @@ BoxedInt* lenInternal(Box* obj, LenRewriteArgs* rewrite_args) noexcept(S == CAPI
Box
*
lenCallInternal
(
BoxedFunctionBase
*
f
,
CallRewriteArgs
*
rewrite_args
,
ArgPassSpec
argspec
,
Box
*
arg1
,
Box
*
arg2
,
Box
*
arg3
,
Box
**
args
,
const
std
::
vector
<
BoxedString
*>*
keyword_names
);
template
<
ExceptionStyle
S
>
template
<
ExceptionStyle
S
,
Rewritable
rewritable
=
REWRITABLE
>
Box
*
callFunc
(
BoxedFunctionBase
*
func
,
CallRewriteArgs
*
rewrite_args
,
ArgPassSpec
argspec
,
Box
*
arg1
,
Box
*
arg2
,
Box
*
arg3
,
Box
**
args
,
const
std
::
vector
<
BoxedString
*>*
keyword_names
)
noexcept
(
S
==
CAPI
);
...
...
@@ -200,7 +200,7 @@ Box* typeNewGeneric(Box* cls, Box* arg1, Box* arg2, Box** _args);
Box
*
processDescriptor
(
Box
*
obj
,
Box
*
inst
,
Box
*
owner
);
Box
*
processDescriptorOrNull
(
Box
*
obj
,
Box
*
inst
,
Box
*
owner
);
template
<
ExceptionStyle
S
>
template
<
ExceptionStyle
S
,
Rewritable
rewritable
>
Box
*
callCLFunc
(
CLFunction
*
f
,
CallRewriteArgs
*
rewrite_args
,
int
num_output_args
,
BoxedClosure
*
closure
,
BoxedGenerator
*
generator
,
Box
*
globals
,
Box
*
oarg1
,
Box
*
oarg2
,
Box
*
oarg3
,
Box
**
oargs
)
noexcept
(
S
==
CAPI
);
...
...
src/runtime/rewrite_args.h
View file @
c7b6726c
...
...
@@ -279,6 +279,7 @@ struct CompareRewriteArgs {
// The caller is responsible for guarding for paramspec, argspec, param_names, and defaults.
// TODO Fix this function's signature. should we pass back out through args? the common case is that they
// match anyway. Or maybe it should call a callback function, which could save on the common case.
template
<
Rewritable
rewritable
=
REWRITABLE
>
void
rearrangeArguments
(
ParamReceiveSpec
paramspec
,
const
ParamNames
*
param_names
,
const
char
*
func_name
,
Box
**
defaults
,
_CallRewriteArgsBase
*
rewrite_args
,
bool
&
rewrite_success
,
ArgPassSpec
argspec
,
Box
*&
arg1
,
Box
*&
arg2
,
Box
*&
arg3
,
Box
**
args
,
Box
**
oargs
,
...
...
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