Commit 1f087c42 authored by Radford Neal's avatar Radford Neal

add VARIANT_NOT_WHOLE_BODY to do UseMethod functions properly

parent f34b0b9f
......@@ -644,7 +644,13 @@ typedef struct {
error. Does not set R_variant_result. */
#define VARIANT_WHOLE_BODY 0x20000 /* Expression is the entire body of a
function. May allow optimizations. */
function. Allows avoidance of increment
of NAMEDCNT in .Internal. */
#define VARIANT_NOT_WHOLE_BODY 0x40000 /* Suppress use of VARIANT_WHOLE_BODY
in applyClosure_v. Used when S4
method, or S3 method called via
UseMethod that's not the whole body.*/
/* Flags in R_variant_result. */
......
......@@ -965,6 +965,9 @@ SEXP attribute_hidden applyClosure_v(SEXP call, SEXP op, SEXP arglist, SEXP rho,
int vrnt = VARIANT_PENDING_OK | VARIANT_DIRECT_RETURN | VARIANT_WHOLE_BODY
| VARIANT_PASS_ON(variant);
if (variant & VARIANT_NOT_WHOLE_BODY)
vrnt &= ~VARIANT_WHOLE_BODY;
SEXP formals, actuals, savedrho, savedsrcref;
volatile SEXP body, newrho;
SEXP f, a, res;
......@@ -1208,7 +1211,7 @@ static SEXP R_execClosure(SEXP call, SEXP op, SEXP arglist, SEXP rho,
if (R_ReturnedValue == R_RestartToken) {
cntxt.callflag = CTXT_RETURN; /* turn restart off */
R_ReturnedValue = R_NilValue; /* remove restart token */
PROTECT(res = eval(body, newrho));
PROTECT(res = evalv(body, newrho, VARIANT_NOT_WHOLE_BODY));
}
else {
PROTECT(res = R_ReturnedValue);
......
......@@ -382,7 +382,9 @@ found: ;
supplied[i] = bindings;
}
*ans = applyMethod(newcall, sxp, matchedarg, rho, supplied, variant);
*ans = applyMethod (newcall, sxp, matchedarg, rho, supplied,
variant & VARIANT_WHOLE_BODY ? variant
: variant | VARIANT_NOT_WHOLE_BODY);
R_GlobalContext->callflag = CTXT_RETURN;
UNPROTECT(nprotect+5);
......@@ -854,7 +856,8 @@ static SEXP do_nextmethod (SEXP call, SEXP op, SEXP args, SEXP env,
SETCAR(newcall, install(buf));
ans = applyMethod(newcall, nextfun, matchedarg, env, supplied, variant);
ans = applyMethod (newcall, nextfun, matchedarg, env, supplied,
variant & ~VARIANT_WHOLE_BODY);
UNPROTECT(nprotect+7);
return(ans);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment