#include "EXTERN.h"
#include "perl.h"
+#ifdef PERL_OBJECT
+#define CHECKCALL this->*check
+#else
+#define CHECKCALL *check
+#endif
+
/*
* In the following definition, the ", Nullop" is just to make the compiler
* think the expression is of the right type: croak actually does a Siglongjmp.
*/
#define CHECKOP(type,o) \
- ((op_mask && op_mask[type]) \
+ ((PL_op_mask && PL_op_mask[type]) \
? ( op_free((OP*)o), \
croak("%s trapped by operation mask", op_desc[type]), \
Nullop ) \
- : (*check[type])((OP*)o))
+ : (CHECKCALL[type])((OP*)o))
+
+#define PAD_MAX 999999999
+static bool scalar_mod_type _((OP *o, I32 type));
+#ifndef PERL_OBJECT
static I32 list_assignment _((OP *o));
static void bad_type _((I32 n, char *t, char *name, OP *kid));
static OP *modkids _((OP *o, I32 type));
static OP *no_fh_allowed _((OP *o));
-static bool scalar_mod_type _((OP *o, I32 type));
static OP *scalarboolean _((OP *o));
static OP *too_few_arguments _((OP *o, char* name));
static OP *too_many_arguments _((OP *o, char* name));
static void null _((OP* o));
static PADOFFSET pad_findlex _((char* name, PADOFFSET newoff, U32 seq,
- CV* startcv, I32 cx_ix));
+ CV* startcv, I32 cx_ix, I32 saweval));
static OP *newDEFSVOP _((void));
static OP *new_logop _((I32 type, I32 flags, OP **firstp, OP **otherp));
+#endif
-static char*
+STATIC char*
gv_ename(GV *gv)
{
SV* tmpsv = sv_newmortal();
gv_efullname3(tmpsv, gv, Nullch);
- return SvPV(tmpsv,na);
+ return SvPV(tmpsv,PL_na);
}
-static OP *
+STATIC OP *
no_fh_allowed(OP *o)
{
yyerror(form("Missing comma after first argument to %s function",
return o;
}
-static OP *
+STATIC OP *
too_few_arguments(OP *o, char *name)
{
yyerror(form("Not enough arguments for %s", name));
return o;
}
-static OP *
+STATIC OP *
too_many_arguments(OP *o, char *name)
{
yyerror(form("Too many arguments for %s", name));
return o;
}
-static void
+STATIC void
bad_type(I32 n, char *t, char *name, OP *kid)
{
yyerror(form("Type of arg %d to %s must be %s (not %s)",
assertref(OP *o)
{
int type = o->op_type;
- if (type != OP_AELEM && type != OP_HELEM) {
+ if (type != OP_AELEM && type != OP_HELEM && type != OP_GELEM) {
yyerror(form("Can't use subscript on %s", op_desc[type]));
if (type == OP_ENTERSUB || type == OP_RV2HV || type == OP_PADHV) {
dTHR;
SV *msg = sv_2mortal(
newSVpvf("(Did you mean $ or @ instead of %c?)\n",
type == OP_ENTERSUB ? '&' : '%'));
- if (in_eval & 2)
+ if (PL_in_eval & 2)
warn("%_", msg);
- else if (in_eval)
- sv_catsv(GvSV(errgv), msg);
+ else if (PL_in_eval)
+ sv_catsv(GvSV(PL_errgv), msg);
else
PerlIO_write(PerlIO_stderr(), SvPVX(msg), SvCUR(msg));
}
PADOFFSET off;
SV *sv;
- if (!(isALPHA(name[1]) || name[1] == '_' && (int)strlen(name) > 2)) {
+ if (!(
+ isALPHA(name[1]) ||
+ (PL_hints & HINT_UTF8 && (name[1] & 0xc0) == 0xc0) ||
+ name[1] == '_' && (int)strlen(name) > 2))
+ {
if (!isPRINT(name[1])) {
name[3] = '\0';
name[2] = toCTRL(name[1]);
}
croak("Can't use global %s in \"my\"",name);
}
- if (dowarn && AvFILLp(comppad_name) >= 0) {
- SV **svp = AvARRAY(comppad_name);
- for (off = AvFILLp(comppad_name); off > comppad_name_floor; off--) {
+ if (ckWARN(WARN_UNSAFE) && AvFILLp(PL_comppad_name) >= 0) {
+ SV **svp = AvARRAY(PL_comppad_name);
+ for (off = AvFILLp(PL_comppad_name); off > PL_comppad_name_floor; off--) {
if ((sv = svp[off])
- && sv != &sv_undef
- && SvIVX(sv) == 999999999 /* var is in open scope */
+ && sv != &PL_sv_undef
+ && (SvIVX(sv) == PAD_MAX || SvIVX(sv) == 0)
&& strEQ(name, SvPVX(sv)))
{
- warn("\"my\" variable %s masks earlier declaration in same scope", name);
+ warner(WARN_UNSAFE,
+ "\"my\" variable %s masks earlier declaration in same %s",
+ name, (SvIVX(sv) == PAD_MAX ? "scope" : "statement"));
break;
}
}
sv = NEWSV(1102,0);
sv_upgrade(sv, SVt_PVNV);
sv_setpv(sv, name);
- if (in_my_stash) {
+ if (PL_in_my_stash) {
if (*name != '$')
croak("Can't declare class for non-scalar %s in \"my\"",name);
SvOBJECT_on(sv);
(void)SvUPGRADE(sv, SVt_PVMG);
- SvSTASH(sv) = (HV*)SvREFCNT_inc(in_my_stash);
- sv_objcount++;
+ SvSTASH(sv) = (HV*)SvREFCNT_inc(PL_in_my_stash);
+ PL_sv_objcount++;
}
- av_store(comppad_name, off, sv);
- SvNVX(sv) = (double)999999999;
+ av_store(PL_comppad_name, off, sv);
+ SvNVX(sv) = (double)PAD_MAX;
SvIVX(sv) = 0; /* Not yet introduced--see newSTATEOP */
- if (!min_intro_pending)
- min_intro_pending = off;
- max_intro_pending = off;
+ if (!PL_min_intro_pending)
+ PL_min_intro_pending = off;
+ PL_max_intro_pending = off;
if (*name == '@')
- av_store(comppad, off, (SV*)newAV());
+ av_store(PL_comppad, off, (SV*)newAV());
else if (*name == '%')
- av_store(comppad, off, (SV*)newHV());
- SvPADMY_on(curpad[off]);
+ av_store(PL_comppad, off, (SV*)newHV());
+ SvPADMY_on(PL_curpad[off]);
return off;
}
-static PADOFFSET
-pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix)
+STATIC PADOFFSET
+pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix, I32 saweval)
{
dTHR;
CV *cv;
SV *sv;
register I32 i;
register PERL_CONTEXT *cx;
- int saweval;
for (cv = startcv; cv; cv = CvOUTSIDE(cv)) {
AV *curlist = CvPADLIST(cv);
SV **svp = av_fetch(curlist, 0, FALSE);
AV *curname;
- if (!svp || *svp == &sv_undef)
+ if (!svp || *svp == &PL_sv_undef)
continue;
curname = (AV*)*svp;
svp = AvARRAY(curname);
for (off = AvFILLp(curname); off > 0; off--) {
if ((sv = svp[off]) &&
- sv != &sv_undef &&
+ sv != &PL_sv_undef &&
seq <= SvIVX(sv) &&
seq > I_32(SvNVX(sv)) &&
strEQ(SvPVX(sv), name))
newoff = pad_alloc(OP_PADSV, SVs_PADMY);
sv_upgrade(namesv, SVt_PVNV);
sv_setpv(namesv, name);
- av_store(comppad_name, newoff, namesv);
- SvNVX(namesv) = (double)curcop->cop_seq;
- SvIVX(namesv) = 999999999; /* A ref, intro immediately */
+ av_store(PL_comppad_name, newoff, namesv);
+ SvNVX(namesv) = (double)PL_curcop->cop_seq;
+ SvIVX(namesv) = PAD_MAX; /* A ref, intro immediately */
SvFAKE_on(namesv); /* A ref, not a real var */
- if (CvANON(compcv) || SvTYPE(compcv) == SVt_PVFM) {
+ if (SvOBJECT(sv)) { /* A typed var */
+ SvOBJECT_on(namesv);
+ (void)SvUPGRADE(namesv, SVt_PVMG);
+ SvSTASH(namesv) = (HV*)SvREFCNT_inc((SV*)SvSTASH(sv));
+ PL_sv_objcount++;
+ }
+ if (CvANON(PL_compcv) || SvTYPE(PL_compcv) == SVt_PVFM) {
/* "It's closures all the way down." */
- CvCLONE_on(compcv);
+ CvCLONE_on(PL_compcv);
if (cv == startcv) {
- if (CvANON(compcv))
+ if (CvANON(PL_compcv))
oldsv = Nullsv; /* no need to keep ref */
}
else {
CV *bcv;
for (bcv = startcv;
bcv && bcv != cv && !CvCLONE(bcv);
- bcv = CvOUTSIDE(bcv)) {
+ bcv = CvOUTSIDE(bcv))
+ {
if (CvANON(bcv))
CvCLONE_on(bcv);
else {
- if (dowarn && !CvUNIQUE(cv))
- warn(
+ if (ckWARN(WARN_CLOSURE)
+ && !CvUNIQUE(bcv) && !CvUNIQUE(cv))
+ {
+ warner(WARN_CLOSURE,
"Variable \"%s\" may be unavailable",
name);
+ }
break;
}
}
}
}
- else if (!CvUNIQUE(compcv)) {
- if (dowarn && !SvFAKE(sv) && !CvUNIQUE(cv))
- warn("Variable \"%s\" will not stay shared", name);
+ else if (!CvUNIQUE(PL_compcv)) {
+ if (ckWARN(WARN_CLOSURE) && !SvFAKE(sv) && !CvUNIQUE(cv))
+ warner(WARN_CLOSURE,
+ "Variable \"%s\" will not stay shared", name);
}
}
- av_store(comppad, newoff, SvREFCNT_inc(oldsv));
+ av_store(PL_comppad, newoff, SvREFCNT_inc(oldsv));
return newoff;
}
}
* XXX This will also probably interact badly with eval tree caching.
*/
- saweval = 0;
for (i = cx_ix; i >= 0; i--) {
cx = &cxstack[i];
- switch (cx->cx_type) {
+ switch (CxTYPE(cx)) {
default:
if (i == 0 && saweval) {
seq = cxstack[saweval].blk_oldcop->cop_seq;
- return pad_findlex(name, newoff, seq, main_cv, 0);
+ return pad_findlex(name, newoff, seq, PL_main_cv, -1, saweval);
}
break;
case CXt_EVAL:
switch (cx->blk_eval.old_op_type) {
case OP_ENTEREVAL:
- saweval = i;
+ if (CxREALEVAL(cx))
+ saweval = i;
break;
case OP_REQUIRE:
/* require must have its own scope */
if (!saweval)
return 0;
cv = cx->blk_sub.cv;
- if (debstash && CvSTASH(cv) == debstash) { /* ignore DB'* scope */
+ if (PL_debstash && CvSTASH(cv) == PL_debstash) { /* ignore DB'* scope */
saweval = i; /* so we know where we were called from */
continue;
}
seq = cxstack[saweval].blk_oldcop->cop_seq;
- return pad_findlex(name, newoff, seq, cv, i-1);
+ return pad_findlex(name, newoff, seq, cv, i-1, saweval);
}
}
I32 off;
I32 pendoff = 0;
SV *sv;
- SV **svp = AvARRAY(comppad_name);
- U32 seq = cop_seqmax;
+ SV **svp = AvARRAY(PL_comppad_name);
+ U32 seq = PL_cop_seqmax;
+ PERL_CONTEXT *cx;
+ CV *outside;
#ifdef USE_THREADS
/*
#endif /* USE_THREADS */
/* The one we're looking for is probably just before comppad_name_fill. */
- for (off = AvFILLp(comppad_name); off > 0; off--) {
+ for (off = AvFILLp(PL_comppad_name); off > 0; off--) {
if ((sv = svp[off]) &&
- sv != &sv_undef &&
+ sv != &PL_sv_undef &&
(!SvIVX(sv) ||
(seq <= SvIVX(sv) &&
seq > I_32(SvNVX(sv)))) &&
}
}
+ outside = CvOUTSIDE(PL_compcv);
+
+ /* Check if if we're compiling an eval'', and adjust seq to be the
+ * eval's seq number. This depends on eval'' having a non-null
+ * CvOUTSIDE() while it is being compiled. The eval'' itself is
+ * identified by CvUNIQUE being set and CvGV being null. */
+ if (outside && CvUNIQUE(PL_compcv) && !CvGV(PL_compcv) && cxstack_ix >= 0) {
+ cx = &cxstack[cxstack_ix];
+ if (CxREALEVAL(cx))
+ seq = cx->blk_oldcop->cop_seq;
+ }
+
/* See if it's in a nested scope */
- off = pad_findlex(name, 0, seq, CvOUTSIDE(compcv), cxstack_ix);
+ off = pad_findlex(name, 0, seq, outside, cxstack_ix, 0);
if (off) {
/* If there is a pending local definition, this new alias must die */
if (pendoff)
- SvIVX(AvARRAY(comppad_name)[off]) = seq;
+ SvIVX(AvARRAY(PL_comppad_name)[off]) = seq;
return off; /* pad_findlex returns 0 for failure...*/
}
return NOT_IN_PAD; /* ...but we return NOT_IN_PAD for failure */
pad_leavemy(I32 fill)
{
I32 off;
- SV **svp = AvARRAY(comppad_name);
+ SV **svp = AvARRAY(PL_comppad_name);
SV *sv;
- if (min_intro_pending && fill < min_intro_pending) {
- for (off = max_intro_pending; off >= min_intro_pending; off--) {
- if ((sv = svp[off]) && sv != &sv_undef)
+ if (PL_min_intro_pending && fill < PL_min_intro_pending) {
+ for (off = PL_max_intro_pending; off >= PL_min_intro_pending; off--) {
+ if ((sv = svp[off]) && sv != &PL_sv_undef)
warn("%s never introduced", SvPVX(sv));
}
}
/* "Deintroduce" my variables that are leaving with this scope. */
- for (off = AvFILLp(comppad_name); off > fill; off--) {
- if ((sv = svp[off]) && sv != &sv_undef && SvIVX(sv) == 999999999)
- SvIVX(sv) = cop_seqmax;
+ for (off = AvFILLp(PL_comppad_name); off > fill; off--) {
+ if ((sv = svp[off]) && sv != &PL_sv_undef && SvIVX(sv) == PAD_MAX)
+ SvIVX(sv) = PL_cop_seqmax;
}
}
SV *sv;
I32 retval;
- if (AvARRAY(comppad) != curpad)
+ if (AvARRAY(PL_comppad) != PL_curpad)
croak("panic: pad_alloc");
- if (pad_reset_pending)
+ if (PL_pad_reset_pending)
pad_reset();
if (tmptype & SVs_PADMY) {
do {
- sv = *av_fetch(comppad, AvFILLp(comppad) + 1, TRUE);
+ sv = *av_fetch(PL_comppad, AvFILLp(PL_comppad) + 1, TRUE);
} while (SvPADBUSY(sv)); /* need a fresh one */
- retval = AvFILLp(comppad);
+ retval = AvFILLp(PL_comppad);
}
else {
- SV **names = AvARRAY(comppad_name);
- SSize_t names_fill = AvFILLp(comppad_name);
+ SV **names = AvARRAY(PL_comppad_name);
+ SSize_t names_fill = AvFILLp(PL_comppad_name);
for (;;) {
/*
* "foreach" index vars temporarily become aliases to non-"my"
* values. Thus we must skip, not just pad values that are
* marked as current pad values, but also those with names.
*/
- if (++padix <= names_fill &&
- (sv = names[padix]) && sv != &sv_undef)
+ if (++PL_padix <= names_fill &&
+ (sv = names[PL_padix]) && sv != &PL_sv_undef)
continue;
- sv = *av_fetch(comppad, padix, TRUE);
+ sv = *av_fetch(PL_comppad, PL_padix, TRUE);
if (!(SvFLAGS(sv) & (SVs_PADTMP|SVs_PADMY)))
break;
}
- retval = padix;
+ retval = PL_padix;
}
SvFLAGS(sv) |= tmptype;
- curpad = AvARRAY(comppad);
+ PL_curpad = AvARRAY(PL_comppad);
#ifdef USE_THREADS
DEBUG_X(PerlIO_printf(Perl_debug_log, "0x%lx Pad 0x%lx alloc %ld for %s\n",
- (unsigned long) thr, (unsigned long) curpad,
+ (unsigned long) thr, (unsigned long) PL_curpad,
(long) retval, op_name[optype]));
#else
DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%lx alloc %ld for %s\n",
- (unsigned long) curpad,
+ (unsigned long) PL_curpad,
(long) retval, op_name[optype]));
#endif /* USE_THREADS */
return (PADOFFSET)retval;
dTHR;
#ifdef USE_THREADS
DEBUG_X(PerlIO_printf(Perl_debug_log, "0x%lx Pad 0x%lx sv %d\n",
- (unsigned long) thr, (unsigned long) curpad, po));
+ (unsigned long) thr, (unsigned long) PL_curpad, po));
#else
if (!po)
croak("panic: pad_sv po");
DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%lx sv %d\n",
- (unsigned long) curpad, po));
+ (unsigned long) PL_curpad, po));
#endif /* USE_THREADS */
- return curpad[po]; /* eventually we'll turn this into a macro */
+ return PL_curpad[po]; /* eventually we'll turn this into a macro */
}
void
pad_free(PADOFFSET po)
{
dTHR;
- if (!curpad)
+ if (!PL_curpad)
return;
- if (AvARRAY(comppad) != curpad)
+ if (AvARRAY(PL_comppad) != PL_curpad)
croak("panic: pad_free curpad");
if (!po)
croak("panic: pad_free po");
#ifdef USE_THREADS
DEBUG_X(PerlIO_printf(Perl_debug_log, "0x%lx Pad 0x%lx free %d\n",
- (unsigned long) thr, (unsigned long) curpad, po));
+ (unsigned long) thr, (unsigned long) PL_curpad, po));
#else
DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%lx free %d\n",
- (unsigned long) curpad, po));
+ (unsigned long) PL_curpad, po));
#endif /* USE_THREADS */
- if (curpad[po] && curpad[po] != &sv_undef)
- SvPADTMP_off(curpad[po]);
- if ((I32)po < padix)
- padix = po - 1;
+ if (PL_curpad[po] && PL_curpad[po] != &PL_sv_undef)
+ SvPADTMP_off(PL_curpad[po]);
+ if ((I32)po < PL_padix)
+ PL_padix = po - 1;
}
void
pad_swipe(PADOFFSET po)
{
dTHR;
- if (AvARRAY(comppad) != curpad)
+ if (AvARRAY(PL_comppad) != PL_curpad)
croak("panic: pad_swipe curpad");
if (!po)
croak("panic: pad_swipe po");
#ifdef USE_THREADS
DEBUG_X(PerlIO_printf(Perl_debug_log, "0x%lx Pad 0x%lx swipe %d\n",
- (unsigned long) thr, (unsigned long) curpad, po));
+ (unsigned long) thr, (unsigned long) PL_curpad, po));
#else
DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%lx swipe %d\n",
- (unsigned long) curpad, po));
+ (unsigned long) PL_curpad, po));
#endif /* USE_THREADS */
- SvPADTMP_off(curpad[po]);
- curpad[po] = NEWSV(1107,0);
- SvPADTMP_on(curpad[po]);
- if ((I32)po < padix)
- padix = po - 1;
+ SvPADTMP_off(PL_curpad[po]);
+ PL_curpad[po] = NEWSV(1107,0);
+ SvPADTMP_on(PL_curpad[po]);
+ if ((I32)po < PL_padix)
+ PL_padix = po - 1;
}
/* XXX pad_reset() is currently disabled because it results in serious bugs.
dTHR;
register I32 po;
- if (AvARRAY(comppad) != curpad)
+ if (AvARRAY(PL_comppad) != PL_curpad)
croak("panic: pad_reset curpad");
#ifdef USE_THREADS
DEBUG_X(PerlIO_printf(Perl_debug_log, "0x%lx Pad 0x%lx reset\n",
- (unsigned long) thr, (unsigned long) curpad));
+ (unsigned long) thr, (unsigned long) PL_curpad));
#else
DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%lx reset\n",
- (unsigned long) curpad));
+ (unsigned long) PL_curpad));
#endif /* USE_THREADS */
- if (!tainting) { /* Can't mix tainted and non-tainted temporaries. */
- for (po = AvMAX(comppad); po > padix_floor; po--) {
- if (curpad[po] && !SvIMMORTAL(curpad[po]))
- SvPADTMP_off(curpad[po]);
+ if (!PL_tainting) { /* Can't mix tainted and non-tainted temporaries. */
+ for (po = AvMAX(PL_comppad); po > PL_padix_floor; po--) {
+ if (PL_curpad[po] && !SvIMMORTAL(PL_curpad[po]))
+ SvPADTMP_off(PL_curpad[po]);
}
- padix = padix_floor;
+ PL_padix = PL_padix_floor;
}
#endif
- pad_reset_pending = FALSE;
+ PL_pad_reset_pending = FALSE;
}
#ifdef USE_THREADS
PADOFFSET key;
SV **svp;
/* We currently only handle names of a single character */
- p = strchr(threadsv_names, *name);
+ p = strchr(PL_threadsv_names, *name);
if (!p)
return NOT_IN_PAD;
- key = p - threadsv_names;
+ key = p - PL_threadsv_names;
svp = av_fetch(thr->threadsv, key, FALSE);
if (!svp) {
SV *sv = NEWSV(0, 0);
case '&':
case '`':
case '\'':
- sawampersand = TRUE;
+ PL_sawampersand = TRUE;
SvREADONLY_on(sv);
/* FALL THROUGH */
+
+ /* XXX %! tied to Errno.pm needs to be added here.
+ * See gv_fetchpv(). */
+ /* case '!': */
+
default:
sv_magic(sv, 0, 0, name, 1);
}
- DEBUG_L(PerlIO_printf(PerlIO_stderr(),
+ DEBUG_S(PerlIO_printf(PerlIO_stderr(),
"find_threadsv: new SV %p for $%s%c\n",
sv, (*name < 32) ? "^" : "",
(*name < 32) ? toCTRL(*name) : *name));
o->op_targ = 0; /* Was holding hints. */
break;
#ifdef USE_THREADS
+ case OP_ENTERITER:
+ if (!(o->op_flags & OPf_SPECIAL))
+ break;
+ /* FALL THROUGH */
case OP_THREADSV:
o->op_targ = 0; /* Was holding index into thr->threadsv AV. */
break;
#endif /* USE_THREADS */
default:
- if (!(o->op_flags & OPf_REF) || (check[o->op_type] != ck_ftst))
+ if (!(o->op_flags & OPf_REF)
+ || (check[o->op_type] != FUNC_NAME_TO_PTR(ck_ftst)))
break;
/* FALL THROUGH */
case OP_GVSV:
case OP_DBSTATE:
Safefree(cCOPo->cop_label);
SvREFCNT_dec(cCOPo->cop_filegv);
+ if (cCOPo->cop_warnings != WARN_NONE && cCOPo->cop_warnings != WARN_ALL)
+ SvREFCNT_dec(cCOPo->cop_warnings);
break;
case OP_CONST:
SvREFCNT_dec(cSVOPo->op_sv);
break;
/* FALL THROUGH */
case OP_TRANS:
- Safefree(cPVOPo->op_pv);
+ if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF))
+ SvREFCNT_dec(cSVOPo->op_sv);
+ else
+ Safefree(cPVOPo->op_pv);
break;
case OP_SUBST:
op_free(cPMOPo->op_pmreplroot);
/* FALL THROUGH */
case OP_PUSHRE:
case OP_MATCH:
+ case OP_QR:
ReREFCNT_dec(cPMOPo->op_pmregexp);
break;
}
Safefree(o);
}
-static void
+STATIC void
null(OP *o)
{
if (o->op_type != OP_NULL && o->op_type != OP_THREADSV && o->op_targ > 0)
return o;
}
-static OP *
+STATIC OP *
scalarboolean(OP *o)
{
- if (dowarn &&
- o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST) {
+ if (o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST) {
dTHR;
- line_t oldline = curcop->cop_line;
+ if (ckWARN(WARN_SYNTAX)) {
+ line_t oldline = PL_curcop->cop_line;
- if (copline != NOLINE)
- curcop->cop_line = copline;
- warn("Found = in conditional, should be ==");
- curcop->cop_line = oldline;
+ if (PL_copline != NOLINE)
+ PL_curcop->cop_line = PL_copline;
+ warner(WARN_SYNTAX, "Found = in conditional, should be ==");
+ PL_curcop->cop_line = oldline;
+ }
}
return scalar(o);
}
OP *kid;
/* assumes no premature commitment */
- if (!o || (o->op_flags & OPf_WANT) || error_count
+ if (!o || (o->op_flags & OPf_WANT) || PL_error_count
|| o->op_type == OP_RETURN)
return o;
}
/* FALL THROUGH */
case OP_MATCH:
+ case OP_QR:
case OP_SUBST:
case OP_NULL:
default:
else
scalar(kid);
}
- WITH_THR(curcop = &compiling);
+ WITH_THR(PL_curcop = &PL_compiling);
break;
case OP_SCOPE:
case OP_LINESEQ:
else
scalar(kid);
}
- WITH_THR(curcop = &compiling);
+ WITH_THR(PL_curcop = &PL_compiling);
break;
}
return o;
SV* sv;
/* assumes no premature commitment */
- if (!o || (o->op_flags & OPf_WANT) == OPf_WANT_LIST || error_count
+ if (!o || (o->op_flags & OPf_WANT) == OPf_WANT_LIST || PL_error_count
|| o->op_type == OP_RETURN)
return o;
case OP_REPEAT:
if (o->op_flags & OPf_STACKED)
break;
+ goto func_ops;
+ case OP_SUBSTR:
+ if (o->op_private == 4)
+ break;
/* FALL THROUGH */
case OP_GVSV:
case OP_WANTARRAY:
case OP_HEX:
case OP_OCT:
case OP_LENGTH:
- case OP_SUBSTR:
case OP_VEC:
case OP_INDEX:
case OP_RINDEX:
case OP_GGRNAM:
case OP_GGRGID:
case OP_GETLOGIN:
+ func_ops:
if (!(o->op_private & OPpLVAL_INTRO))
useless = op_desc[o->op_type];
break;
case OP_NEXTSTATE:
case OP_DBSTATE:
- WITH_THR(curcop = ((COP*)o)); /* for warning below */
+ WITH_THR(PL_curcop = ((COP*)o)); /* for warning below */
break;
case OP_CONST:
sv = cSVOPo->op_sv;
- if (dowarn) {
- useless = "a constant";
- if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
- useless = 0;
- else if (SvPOK(sv)) {
- if (strnEQ(SvPVX(sv), "di", 2) ||
- strnEQ(SvPVX(sv), "ds", 2) ||
- strnEQ(SvPVX(sv), "ig", 2))
- useless = 0;
+ {
+ dTHR;
+ if (ckWARN(WARN_VOID)) {
+ useless = "a constant";
+ if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
+ useless = 0;
+ else if (SvPOK(sv)) {
+ if (strnEQ(SvPVX(sv), "di", 2) ||
+ strnEQ(SvPVX(sv), "ds", 2) ||
+ strnEQ(SvPVX(sv), "ig", 2))
+ useless = 0;
+ }
}
}
null(o); /* don't execute a constant */
case OP_NULL:
if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE)
- WITH_THR(curcop = ((COP*)o)); /* for warning below */
+ WITH_THR(PL_curcop = ((COP*)o)); /* for warning below */
if (o->op_flags & OPf_STACKED)
break;
/* FALL THROUGH */
}
break;
}
- if (useless && dowarn)
- warn("Useless use of %s in void context", useless);
+ if (useless) {
+ dTHR;
+ if (ckWARN(WARN_VOID))
+ warner(WARN_VOID, "Useless use of %s in void context", useless);
+ }
return o;
}
OP *kid;
/* assumes no premature commitment */
- if (!o || (o->op_flags & OPf_WANT) || error_count
+ if (!o || (o->op_flags & OPf_WANT) || PL_error_count
|| o->op_type == OP_RETURN)
return o;
break;
default:
case OP_MATCH:
+ case OP_QR:
case OP_SUBST:
case OP_NULL:
if (!(o->op_flags & OPf_KIDS))
else
list(kid);
}
- WITH_THR(curcop = &compiling);
+ WITH_THR(PL_curcop = &PL_compiling);
break;
case OP_SCOPE:
case OP_LINESEQ:
else
list(kid);
}
- WITH_THR(curcop = &compiling);
+ WITH_THR(PL_curcop = &PL_compiling);
break;
case OP_REQUIRE:
/* all requires must return a boolean value */
scalarvoid(kid);
}
}
- curcop = &compiling;
+ PL_curcop = &PL_compiling;
}
o->op_flags &= ~OPf_PARENS;
- if (hints & HINT_BLOCK_SCOPE)
+ if (PL_hints & HINT_BLOCK_SCOPE)
o->op_flags |= OPf_PARENS;
}
else
return o;
}
-static OP *
+STATIC OP *
modkids(OP *o, I32 type)
{
OP *kid;
OP *kid;
SV *sv;
- if (!o || error_count)
+ if (!o || PL_error_count)
return o;
switch (o->op_type) {
case OP_UNDEF:
- modcount++;
+ PL_modcount++;
return o;
case OP_CONST:
if (!(o->op_private & (OPpCONST_ARYBASE)))
goto nomod;
- if (eval_start && eval_start->op_type == OP_CONST) {
- compiling.cop_arybase = (I32)SvIV(((SVOP*)eval_start)->op_sv);
- eval_start = 0;
+ if (PL_eval_start && PL_eval_start->op_type == OP_CONST) {
+ PL_compiling.cop_arybase = (I32)SvIV(((SVOP*)PL_eval_start)->op_sv);
+ PL_eval_start = 0;
}
else if (!type) {
- SAVEI32(compiling.cop_arybase);
- compiling.cop_arybase = 0;
+ SAVEI32(PL_compiling.cop_arybase);
+ PL_compiling.cop_arybase = 0;
}
else if (type == OP_REFGEN)
goto nomod;
if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
break;
yyerror(form("Can't modify %s in %s",
- op_desc[o->op_type],
+ (o->op_type == OP_NULL && (o->op_flags & OPf_SPECIAL)
+ ? "do block" : op_desc[o->op_type]),
type ? op_desc[type] : "local"));
return o;
case OP_I_SUBTRACT:
if (!(o->op_flags & OPf_STACKED))
goto nomod;
- modcount++;
+ PL_modcount++;
break;
case OP_COND_EXPR:
if (!type && cUNOPo->op_first->op_type != OP_GV)
croak("Can't localize through a reference");
if (type == OP_REFGEN && o->op_flags & OPf_PARENS) {
- modcount = 10000;
+ PL_modcount = 10000;
return o; /* Treat \(@foo) like ordinary list. */
}
/* FALL THROUGH */
case OP_DBSTATE:
case OP_REFGEN:
case OP_CHOMP:
- modcount = 10000;
+ PL_modcount = 10000;
break;
case OP_RV2SV:
if (!type && cUNOPo->op_first->op_type != OP_GV)
/* FALL THROUGH */
case OP_GV:
case OP_AV2ARYLEN:
- hints |= HINT_BLOCK_SCOPE;
+ PL_hints |= HINT_BLOCK_SCOPE;
case OP_SASSIGN:
case OP_AELEMFAST:
- modcount++;
+ PL_modcount++;
break;
case OP_PADAV:
case OP_PADHV:
- modcount = 10000;
+ PL_modcount = 10000;
if (type == OP_REFGEN && o->op_flags & OPf_PARENS)
return o; /* Treat \(@foo) like ordinary list. */
if (scalar_mod_type(o, type))
goto nomod;
/* FALL THROUGH */
case OP_PADSV:
- modcount++;
+ PL_modcount++;
if (!type)
croak("Can't localize lexical variable %s",
- SvPV(*av_fetch(comppad_name, o->op_targ, 4), na));
+ SvPV(*av_fetch(PL_comppad_name, o->op_targ, 4), PL_na));
break;
#ifdef USE_THREADS
case OP_THREADSV:
- modcount++; /* XXX ??? */
+ PL_modcount++; /* XXX ??? */
break;
#endif /* USE_THREADS */
case OP_KEYS:
if (type != OP_SASSIGN)
goto nomod;
+ goto lvalue_func;
+ case OP_SUBSTR:
+ if (o->op_private == 4) /* don't allow 4 arg substr as lvalue */
+ goto nomod;
/* FALL THROUGH */
case OP_POS:
case OP_VEC:
- case OP_SUBSTR:
+ lvalue_func:
pad_free(o->op_targ);
o->op_targ = pad_alloc(o->op_type, SVs_PADMY);
assert(SvTYPE(PAD_SV(o->op_targ)) == SVt_NULL);
if (type == OP_ENTERSUB &&
!(o->op_private & (OPpLVAL_INTRO | OPpDEREF)))
o->op_private |= OPpLVAL_DEFER;
- modcount++;
+ PL_modcount++;
break;
case OP_SCOPE:
break;
case OP_NULL:
- if (!(o->op_flags & OPf_KIDS))
+ if (o->op_flags & OPf_SPECIAL) /* do BLOCK */
+ goto nomod;
+ else if (!(o->op_flags & OPf_KIDS))
break;
if (o->op_targ != OP_LIST) {
mod(cBINOPo->op_first, type);
else if (!type) {
o->op_private |= OPpLVAL_INTRO;
o->op_flags &= ~OPf_SPECIAL;
+ PL_hints |= HINT_BLOCK_SCOPE;
}
else if (type != OP_GREPSTART && type != OP_ENTERSUB)
o->op_flags |= OPf_REF;
case OP_CONCAT:
case OP_SUBST:
case OP_TRANS:
+ case OP_READ:
+ case OP_SYSREAD:
+ case OP_RECV:
case OP_ANDASSIGN: /* may work later */
case OP_ORASSIGN: /* may work later */
return TRUE;
{
OP *kid;
- if (!o || error_count)
+ if (!o || PL_error_count)
return o;
switch (o->op_type) {
OP *kid;
I32 type;
- if (!o || error_count)
+ if (!o || PL_error_count)
return o;
type = o->op_type;
OP *
bind_match(I32 type, OP *left, OP *right)
{
+ dTHR;
OP *o;
- if (dowarn &&
- (left->op_type == OP_RV2AV ||
- left->op_type == OP_RV2HV ||
- left->op_type == OP_PADAV ||
- left->op_type == OP_PADHV)) {
- char *desc = op_desc[(right->op_type == OP_SUBST ||
- right->op_type == OP_TRANS)
- ? right->op_type : OP_MATCH];
- char *sample = ((left->op_type == OP_RV2AV ||
- left->op_type == OP_PADAV)
- ? "@array" : "%hash");
- warn("Applying %s to %s will act on scalar(%s)", desc, sample, sample);
+ if (ckWARN(WARN_UNSAFE) &&
+ (left->op_type == OP_RV2AV ||
+ left->op_type == OP_RV2HV ||
+ left->op_type == OP_PADAV ||
+ left->op_type == OP_PADHV)) {
+ char *desc = op_desc[(right->op_type == OP_SUBST ||
+ right->op_type == OP_TRANS)
+ ? right->op_type : OP_MATCH];
+ char *sample = ((left->op_type == OP_RV2AV ||
+ left->op_type == OP_PADAV)
+ ? "@array" : "%hash");
+ warner(WARN_UNSAFE,
+ "Applying %s to %s will act on scalar(%s)",
+ desc, sample, sample);
}
if (right->op_type == OP_MATCH ||
scope(OP *o)
{
if (o) {
- if (o->op_flags & OPf_PARENS || PERLDB_NOOPT || tainting) {
+ if (o->op_flags & OPf_PARENS || PERLDB_NOOPT || PL_tainting) {
o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
o->op_type = OP_LEAVE;
o->op_ppaddr = ppaddr[OP_LEAVE];
return o;
}
+void
+save_hints(void)
+{
+ SAVEI32(PL_hints);
+ SAVESPTR(GvHV(PL_hintgv));
+ GvHV(PL_hintgv) = newHVhv(GvHV(PL_hintgv));
+ SAVEFREESV(GvHV(PL_hintgv));
+}
+
int
block_start(int full)
{
dTHR;
- int retval = savestack_ix;
- SAVEI32(comppad_name_floor);
+ int retval = PL_savestack_ix;
+
+ SAVEI32(PL_comppad_name_floor);
if (full) {
- if ((comppad_name_fill = AvFILLp(comppad_name)) > 0)
- comppad_name_floor = comppad_name_fill;
+ if ((PL_comppad_name_fill = AvFILLp(PL_comppad_name)) > 0)
+ PL_comppad_name_floor = PL_comppad_name_fill;
else
- comppad_name_floor = 0;
- }
- SAVEI32(min_intro_pending);
- SAVEI32(max_intro_pending);
- min_intro_pending = 0;
- SAVEI32(comppad_name_fill);
- SAVEI32(padix_floor);
- padix_floor = padix;
- pad_reset_pending = FALSE;
- SAVEI32(hints);
- hints &= ~HINT_BLOCK_SCOPE;
+ PL_comppad_name_floor = 0;
+ }
+ SAVEI32(PL_min_intro_pending);
+ SAVEI32(PL_max_intro_pending);
+ PL_min_intro_pending = 0;
+ SAVEI32(PL_comppad_name_fill);
+ SAVEI32(PL_padix_floor);
+ PL_padix_floor = PL_padix;
+ PL_pad_reset_pending = FALSE;
+ SAVEHINTS();
+ PL_hints &= ~HINT_BLOCK_SCOPE;
+ SAVEPPTR(PL_compiling.cop_warnings);
+ if (PL_compiling.cop_warnings != WARN_ALL &&
+ PL_compiling.cop_warnings != WARN_NONE) {
+ PL_compiling.cop_warnings = newSVsv(PL_compiling.cop_warnings) ;
+ SAVEFREESV(PL_compiling.cop_warnings) ;
+ }
+
+
return retval;
}
block_end(I32 floor, OP *seq)
{
dTHR;
- int needblockscope = hints & HINT_BLOCK_SCOPE;
+ int needblockscope = PL_hints & HINT_BLOCK_SCOPE;
OP* retval = scalarseq(seq);
LEAVE_SCOPE(floor);
- pad_reset_pending = FALSE;
+ PL_pad_reset_pending = FALSE;
+ PL_compiling.op_private = PL_hints;
if (needblockscope)
- hints |= HINT_BLOCK_SCOPE; /* propagate out */
- pad_leavemy(comppad_name_fill);
- cop_seqmax++;
+ PL_hints |= HINT_BLOCK_SCOPE; /* propagate out */
+ pad_leavemy(PL_comppad_name_fill);
+ PL_cop_seqmax++;
return retval;
}
-static OP *
+STATIC OP *
newDEFSVOP(void)
{
#ifdef USE_THREADS
o->op_targ = find_threadsv("_");
return o;
#else
- return newSVREF(newGVOP(OP_GV, 0, defgv));
+ return newSVREF(newGVOP(OP_GV, 0, PL_defgv));
#endif /* USE_THREADS */
}
newPROG(OP *o)
{
dTHR;
- if (in_eval) {
- eval_root = newUNOP(OP_LEAVEEVAL, ((in_eval & 4) ? OPf_SPECIAL : 0), o);
- eval_start = linklist(eval_root);
- eval_root->op_next = 0;
- peep(eval_start);
+ if (PL_in_eval) {
+ PL_eval_root = newUNOP(OP_LEAVEEVAL, ((PL_in_eval & 4) ? OPf_SPECIAL : 0), o);
+ PL_eval_start = linklist(PL_eval_root);
+ PL_eval_root->op_next = 0;
+ peep(PL_eval_start);
}
else {
if (!o)
return;
- main_root = scope(sawparens(scalarvoid(o)));
- curcop = &compiling;
- main_start = LINKLIST(main_root);
- main_root->op_next = 0;
- peep(main_start);
- compcv = 0;
+ PL_main_root = scope(sawparens(scalarvoid(o)));
+ PL_curcop = &PL_compiling;
+ PL_main_start = LINKLIST(PL_main_root);
+ PL_main_root->op_next = 0;
+ peep(PL_main_start);
+ PL_compcv = 0;
/* Register with debugger */
if (PERLDB_INTER) {
if (cv) {
dSP;
PUSHMARK(SP);
- XPUSHs((SV*)compiling.cop_filegv);
+ XPUSHs((SV*)PL_compiling.cop_filegv);
PUTBACK;
perl_call_sv((SV*)cv, G_DISCARD);
}
if (o->op_flags & OPf_PARENS)
list(o);
else {
- if (dowarn && bufptr > oldbufptr && bufptr[-1] == ',') {
+ dTHR;
+ if (ckWARN(WARN_PARENTHESIS) && PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == ',') {
char *s;
- for (s = bufptr; *s && (isALNUM(*s) || strchr("@$%, ",*s)); s++) ;
+ for (s = PL_bufptr; *s && (isALNUM(*s) || (*s & 0x80) || strchr("@$%, ",*s)); s++) ;
if (*s == ';' || *s == '=')
- warn("Parens missing around \"%s\" list", lex ? "my" : "local");
+ warner(WARN_PARENTHESIS, "Parens missing around \"%s\" list",
+ lex ? "my" : "local");
}
}
- in_my = FALSE;
- in_my_stash = Nullhv;
+ PL_in_my = FALSE;
+ PL_in_my_stash = Nullhv;
if (lex)
return my(o);
else
if (opargs[type] & OA_TARGET)
o->op_targ = pad_alloc(type, SVs_PADTMP);
- if ((opargs[type] & OA_OTHERINT) && (hints & HINT_INTEGER))
+ if ((opargs[type] & OA_OTHERINT) && (PL_hints & HINT_INTEGER))
o->op_ppaddr = ppaddr[type = ++(o->op_type)];
if (!(opargs[type] & OA_FOLDCONST))
goto nope;
}
- if (error_count)
+ if (PL_error_count)
goto nope; /* Don't try to run w/ errors */
for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
curop = LINKLIST(o);
o->op_next = 0;
- op = curop;
- runops();
- sv = *(stack_sp--);
+ PL_op = curop;
+ CALLRUNOPS();
+ sv = *(PL_stack_sp--);
if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
pad_swipe(o->op_targ);
else if (SvTEMP(sv)) { /* grab mortal temp? */
if (type == OP_RV2GV)
return newGVOP(OP_GV, 0, (GV*)sv);
else {
- if ((SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK)) == SVf_NOK) {
+ /* try to smush double to int, but don't smush -2.0 to -2 */
+ if ((SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK)) == SVf_NOK &&
+ type != OP_NEGATE)
+ {
IV iv = SvIV(sv);
- if ((double)iv == SvNV(sv)) { /* can we smush double to int */
+ if ((double)iv == SvNV(sv)) {
SvREFCNT_dec(sv);
sv = newSViv(iv);
}
if (!(opargs[type] & OA_OTHERINT))
return o;
- if (!(hints & HINT_INTEGER)) {
+ if (!(PL_hints & HINT_INTEGER)) {
if (type == OP_DIVIDE || !(o->op_flags & OPf_KIDS))
return o;
{
dTHR;
register OP *curop;
- I32 oldtmps_floor = tmps_floor;
+ I32 oldtmps_floor = PL_tmps_floor;
list(o);
- if (error_count)
+ if (PL_error_count)
return o; /* Don't attempt to run with errors */
- op = curop = LINKLIST(o);
+ PL_op = curop = LINKLIST(o);
o->op_next = 0;
pp_pushmark(ARGS);
- runops();
- op = curop;
+ CALLRUNOPS();
+ PL_op = curop;
pp_anonlist(ARGS);
- tmps_floor = oldtmps_floor;
+ PL_tmps_floor = oldtmps_floor;
o->op_type = OP_RV2AV;
o->op_ppaddr = ppaddr[OP_RV2AV];
curop = ((UNOP*)o)->op_first;
- ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*stack_sp--));
+ ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*PL_stack_sp--));
op_free(curop);
linklist(o);
return list(o);
first->op_last = last->op_last;
first->op_children += last->op_children;
if (first->op_children)
- last->op_flags |= OPf_KIDS;
+ first->op_flags |= OPf_KIDS;
Safefree(last);
return (OP*)first;
unop->op_first = first;
unop->op_flags = flags | OPf_KIDS;
unop->op_private = 1 | (flags >> 8);
-#if 1
- if(type == OP_STUDY && first->op_type == OP_MATCH) {
- first->op_type = OP_PUSHRE;
- first->op_ppaddr = ppaddr[OP_PUSHRE];
- }
-#endif
unop = (UNOP*) CHECKOP(type, unop);
if (unop->op_next)
return (OP*)unop;
if (binop->op_next)
return (OP*)binop;
- binop->op_last = last = binop->op_first->op_sibling;
+ binop->op_last = binop->op_first->op_sibling;
return fold_constants((OP *)binop);
}
+static int
+utf8compare(const void *a, const void *b)
+{
+ int i;
+ for (i = 0; i < 10; i++) {
+ if ((*(U8**)a)[i] < (*(U8**)b)[i])
+ return -1;
+ if ((*(U8**)a)[i] > (*(U8**)b)[i])
+ return 1;
+ }
+ return 0;
+}
+
OP *
pmtrans(OP *o, OP *expr, OP *repl)
{
register U8 *r = (U8*)SvPV(rstr, rlen);
register I32 i;
register I32 j;
- I32 Delete;
+ I32 del;
I32 complement;
I32 squash;
register short *tbl;
- tbl = (short*)cPVOPo->op_pv;
complement = o->op_private & OPpTRANS_COMPLEMENT;
- Delete = o->op_private & OPpTRANS_DELETE;
+ del = o->op_private & OPpTRANS_DELETE;
squash = o->op_private & OPpTRANS_SQUASH;
+ if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
+ SV* listsv = newSVpv("# comment\n",0);
+ SV* transv = 0;
+ U8* tend = t + tlen;
+ U8* rend = r + rlen;
+ I32 ulen;
+ U32 tfirst = 1;
+ U32 tlast = 0;
+ I32 tdiff;
+ U32 rfirst = 1;
+ U32 rlast = 0;
+ I32 rdiff;
+ I32 diff;
+ I32 none = 0;
+ U32 max = 0;
+ I32 bits;
+ I32 grows = 0;
+ I32 havefinal = 0;
+ U32 final;
+ HV *hv;
+ I32 from_utf = o->op_private & OPpTRANS_FROM_UTF;
+ I32 to_utf = o->op_private & OPpTRANS_TO_UTF;
+
+ if (complement) {
+ U8 tmpbuf[10];
+ U8** cp;
+ UV nextmin = 0;
+ New(1109, cp, tlen, U8*);
+ i = 0;
+ transv = newSVpv("",0);
+ while (t < tend) {
+ cp[i++] = t;
+ t += UTF8SKIP(t);
+ if (*t == 0xff) {
+ t++;
+ t += UTF8SKIP(t);
+ }
+ }
+ qsort(cp, i, sizeof(U8*), utf8compare);
+ for (j = 0; j < i; j++) {
+ U8 *s = cp[j];
+ UV val = utf8_to_uv(s, &ulen);
+ s += ulen;
+ diff = val - nextmin;
+ if (diff > 0) {
+ t = uv_to_utf8(tmpbuf,nextmin);
+ sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
+ if (diff > 1) {
+ t = uv_to_utf8(tmpbuf, val - 1);
+ sv_catpvn(transv, "\377", 1);
+ sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
+ }
+ }
+ if (*s == 0xff)
+ val = utf8_to_uv(s+1, &ulen);
+ if (val >= nextmin)
+ nextmin = val + 1;
+ }
+ t = uv_to_utf8(tmpbuf,nextmin);
+ sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
+ t = uv_to_utf8(tmpbuf, 0x7fffffff);
+ sv_catpvn(transv, "\377", 1);
+ sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
+ t = (U8*)SvPVX(transv);
+ tlen = SvCUR(transv);
+ tend = t + tlen;
+ }
+ else if (!rlen && !del) {
+ r = t; rlen = tlen; rend = tend;
+ }
+ if (!squash) {
+ if (to_utf && from_utf) { /* only counting characters */
+ if (t == r || (tlen == rlen && memEQ(t, r, tlen)))
+ o->op_private |= OPpTRANS_IDENTICAL;
+ }
+ else { /* straight latin-1 translation */
+ if (tlen == 4 && memEQ(t, "\0\377\303\277", 4) &&
+ rlen == 4 && memEQ(r, "\0\377\303\277", 4))
+ o->op_private |= OPpTRANS_IDENTICAL;
+ }
+ }
+
+ while (t < tend || tfirst <= tlast) {
+ /* see if we need more "t" chars */
+ if (tfirst > tlast) {
+ tfirst = (I32)utf8_to_uv(t, &ulen);
+ t += ulen;
+ if (t < tend && *t == 0xff) { /* illegal utf8 val indicates range */
+ tlast = (I32)utf8_to_uv(++t, &ulen);
+ t += ulen;
+ }
+ else
+ tlast = tfirst;
+ }
+
+ /* now see if we need more "r" chars */
+ if (rfirst > rlast) {
+ if (r < rend) {
+ rfirst = (I32)utf8_to_uv(r, &ulen);
+ r += ulen;
+ if (r < rend && *r == 0xff) { /* illegal utf8 val indicates range */
+ rlast = (I32)utf8_to_uv(++r, &ulen);
+ r += ulen;
+ }
+ else
+ rlast = rfirst;
+ }
+ else {
+ if (!havefinal++)
+ final = rlast;
+ rfirst = rlast = 0xffffffff;
+ }
+ }
+
+ /* now see which range will peter our first, if either. */
+ tdiff = tlast - tfirst;
+ rdiff = rlast - rfirst;
+
+ if (tdiff <= rdiff)
+ diff = tdiff;
+ else
+ diff = rdiff;
+
+ if (rfirst == 0xffffffff) {
+ diff = tdiff; /* oops, pretend rdiff is infinite */
+ if (diff > 0)
+ sv_catpvf(listsv, "%04x\t%04x\tXXXX\n", tfirst, tlast);
+ else
+ sv_catpvf(listsv, "%04x\t\tXXXX\n", tfirst);
+ }
+ else {
+ if (diff > 0)
+ sv_catpvf(listsv, "%04x\t%04x\t%04x\n", tfirst, tfirst + diff, rfirst);
+ else
+ sv_catpvf(listsv, "%04x\t\t%04x\n", tfirst, rfirst);
+
+ if (rfirst + diff > max)
+ max = rfirst + diff;
+ rfirst += diff + 1;
+ if (!grows) {
+ if (rfirst <= 0x80)
+ ;
+ else if (rfirst <= 0x800)
+ grows |= (tfirst < 0x80);
+ else if (rfirst <= 0x10000)
+ grows |= (tfirst < 0x800);
+ else if (rfirst <= 0x200000)
+ grows |= (tfirst < 0x10000);
+ else if (rfirst <= 0x4000000)
+ grows |= (tfirst < 0x200000);
+ else if (rfirst <= 0x80000000)
+ grows |= (tfirst < 0x4000000);
+ }
+ }
+ tfirst += diff + 1;
+ }
+
+ none = ++max;
+ if (del)
+ del = ++max;
+
+ if (max > 0xffff)
+ bits = 32;
+ else if (max > 0xff)
+ bits = 16;
+ else
+ bits = 8;
+
+ cSVOPo->op_sv = (SV*)swash_init("utf8", "", listsv, bits, none);
+ SvREFCNT_dec(listsv);
+ if (transv)
+ SvREFCNT_dec(transv);
+
+ if (!del && havefinal)
+ (void)hv_store((HV*)SvRV((cSVOPo->op_sv)), "FINAL", 5, newSViv((IV)final), 0);
+
+ if (grows && to_utf)
+ o->op_private |= OPpTRANS_GROWS;
+
+ op_free(expr);
+ op_free(repl);
+ return o;
+ }
+
+ tbl = (short*)cPVOPo->op_pv;
if (complement) {
Zero(tbl, 256, short);
for (i = 0; i < tlen; i++)
for (i = 0, j = 0; i < 256; i++) {
if (!tbl[i]) {
if (j >= rlen) {
- if (Delete)
+ if (del)
tbl[i] = -2;
else if (rlen)
tbl[i] = r[j-1];
}
}
else {
- if (!rlen && !Delete) {
+ if (!rlen && !del) {
r = t; rlen = tlen;
if (!squash)
- o->op_private |= OPpTRANS_COUNTONLY;
+ o->op_private |= OPpTRANS_IDENTICAL;
}
for (i = 0; i < 256; i++)
tbl[i] = -1;
for (i = 0, j = 0; i < tlen; i++,j++) {
if (j >= rlen) {
- if (Delete) {
+ if (del) {
if (tbl[t[i]] == -1)
tbl[t[i]] = -2;
continue;
pmop->op_flags = flags;
pmop->op_private = 0 | (flags >> 8);
- if (hints & HINT_LOCALE)
- pmop->op_pmpermflags = (pmop->op_pmflags |= PMf_LOCALE);
+ if (PL_hints & HINT_RE_TAINT)
+ pmop->op_pmpermflags |= PMf_RETAINT;
+ if (PL_hints & HINT_LOCALE)
+ pmop->op_pmpermflags |= PMf_LOCALE;
+ pmop->op_pmflags = pmop->op_pmpermflags;
/* link into pm list */
- if (type != OP_TRANS && curstash) {
- pmop->op_pmnext = HvPMROOT(curstash);
- HvPMROOT(curstash) = pmop;
+ if (type != OP_TRANS && PL_curstash) {
+ pmop->op_pmnext = HvPMROOT(PL_curstash);
+ HvPMROOT(PL_curstash) = pmop;
}
return (OP*)pmop;
OP *
pmruntime(OP *o, OP *expr, OP *repl)
{
+ dTHR;
PMOP *pm;
LOGOP *rcop;
+ I32 repl_has_vars = 0;
if (o->op_type == OP_TRANS)
return pmtrans(o, expr, repl);
- hints |= HINT_BLOCK_SCOPE;
+ PL_hints |= HINT_BLOCK_SCOPE;
pm = (PMOP*)o;
if (expr->op_type == OP_CONST) {
p = SvPV(pat, plen);
pm->op_pmflags |= PMf_SKIPWHITE;
}
- pm->op_pmregexp = pregcomp(p, p + plen, pm);
+ pm->op_pmregexp = CALLREGCOMP(p, p + plen, pm);
if (strEQ("\\s+", pm->op_pmregexp->precomp))
pm->op_pmflags |= PMf_WHITE;
op_free(expr);
}
else {
- if (pm->op_pmflags & PMf_KEEP)
- expr = newUNOP(OP_REGCMAYBE,0,expr);
+ if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL))
+ expr = newUNOP((!(PL_hints & HINT_RE_EVAL)
+ ? OP_REGCRESET
+ : OP_REGCMAYBE),0,expr);
Newz(1101, rcop, 1, LOGOP);
rcop->op_type = OP_REGCOMP;
rcop->op_ppaddr = ppaddr[OP_REGCOMP];
rcop->op_first = scalar(expr);
- rcop->op_flags |= OPf_KIDS;
+ rcop->op_flags |= ((PL_hints & HINT_RE_EVAL)
+ ? (OPf_SPECIAL | OPf_KIDS)
+ : OPf_KIDS);
rcop->op_private = 1;
rcop->op_other = o;
/* establish postfix order */
- if (pm->op_pmflags & PMf_KEEP) {
+ if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL)) {
LINKLIST(expr);
rcop->op_next = expr;
((UNOP*)expr)->op_first->op_next = (OP*)rcop;
#ifdef USE_THREADS
else if (repl->op_type == OP_THREADSV
&& strchr("&`'123456789+",
- threadsv_names[repl->op_targ]))
+ PL_threadsv_names[repl->op_targ]))
{
curop = 0;
}
for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
if (opargs[curop->op_type] & OA_DANGEROUS) {
#ifdef USE_THREADS
- if (curop->op_type == OP_THREADSV
- && strchr("&`'123456789+", curop->op_private)) {
- break;
+ if (curop->op_type == OP_THREADSV) {
+ repl_has_vars = 1;
+ if (strchr("&`'123456789+", curop->op_private))
+ break;
}
#else
if (curop->op_type == OP_GV) {
GV *gv = ((GVOP*)curop)->op_gv;
+ repl_has_vars = 1;
if (strchr("&`'123456789+", *GvENAME(gv)))
break;
}
curop->op_type == OP_PADAV ||
curop->op_type == OP_PADHV ||
curop->op_type == OP_PADANY) {
- /* is okay */
+ repl_has_vars = 1;
}
+ else if (curop->op_type == OP_PUSHRE)
+ ; /* Okay here, dangerous in newASSIGNOP */
else
break;
}
lastop = curop;
}
}
- if (curop == repl) {
+ if (curop == repl
+ && !(repl_has_vars
+ && (!pm->op_pmregexp
+ || pm->op_pmregexp->reganch & ROPT_EVAL_SEEN))) {
pm->op_pmflags |= PMf_CONST; /* const for long enough */
pm->op_pmpermflags |= PMf_CONST; /* const for long enough */
prepend_elem(o->op_type, scalar(repl), o);
}
else {
+ if (curop == repl && !pm->op_pmregexp) { /* Has variables. */
+ pm->op_pmflags |= PMf_MAYBE_CONST;
+ pm->op_pmpermflags |= PMf_MAYBE_CONST;
+ }
Newz(1101, rcop, 1, LOGOP);
rcop->op_type = OP_SUBSTCONT;
rcop->op_ppaddr = ppaddr[OP_SUBSTCONT];
dTHR;
SV *sv;
- save_hptr(&curstash);
- save_item(curstname);
+ save_hptr(&PL_curstash);
+ save_item(PL_curstname);
if (o) {
STRLEN len;
char *name;
sv = cSVOPo->op_sv;
name = SvPV(sv, len);
- curstash = gv_stashpvn(name,len,TRUE);
- sv_setpvn(curstname, name, len);
+ PL_curstash = gv_stashpvn(name,len,TRUE);
+ sv_setpvn(PL_curstname, name, len);
op_free(o);
}
else {
- sv_setpv(curstname,"<none>");
- curstash = Nullhv;
+ sv_setpv(PL_curstname,"<none>");
+ PL_curstash = Nullhv;
}
- copline = NOLINE;
- expect = XSTATE;
+ PL_copline = NOLINE;
+ PL_expect = XSTATE;
}
void
OP *rqop;
OP *imop;
OP *veop;
+ GV *gv;
if (id->op_type != OP_CONST)
croak("Module name must be constant");
newUNOP(OP_METHOD, 0, meth)));
}
- /* Fake up a require */
- rqop = newUNOP(OP_REQUIRE, 0, id);
+ /* Fake up a require, handle override, if any */
+ gv = gv_fetchpv("require", FALSE, SVt_PVCV);
+ if (!(gv && GvIMPORTED_CV(gv)))
+ gv = gv_fetchpv("CORE::GLOBAL::require", FALSE, SVt_PVCV);
+
+ if (gv && GvIMPORTED_CV(gv)) {
+ rqop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
+ append_elem(OP_LIST, id,
+ scalar(newUNOP(OP_RV2CV, 0,
+ newGVOP(OP_GV, 0,
+ gv))))));
+ }
+ else {
+ rqop = newUNOP(OP_REQUIRE, 0, id);
+ }
/* Fake up the BEGIN {}, which does its thing immediately. */
newSUB(floor,
newSTATEOP(0, Nullch, veop)),
newSTATEOP(0, Nullch, imop) ));
- copline = NOLINE;
- expect = XSTATE;
+ PL_copline = NOLINE;
+ PL_expect = XSTATE;
+}
+
+OP *
+dofile(OP *term)
+{
+ OP *doop;
+ GV *gv;
+
+ gv = gv_fetchpv("do", FALSE, SVt_PVCV);
+ if (!(gv && GvIMPORTED_CV(gv)))
+ gv = gv_fetchpv("CORE::GLOBAL::do", FALSE, SVt_PVCV);
+
+ if (gv && GvIMPORTED_CV(gv)) {
+ doop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
+ append_elem(OP_LIST, term,
+ scalar(newUNOP(OP_RV2CV, 0,
+ newGVOP(OP_GV, 0,
+ gv))))));
+ }
+ else {
+ doop = newUNOP(OP_DOFILE, 0, scalar(term));
+ }
+ return doop;
}
OP *
list(force_list(listval)) );
}
-static I32
+STATIC I32
list_assignment(register OP *o)
{
if (!o)
if (list_assignment(left)) {
dTHR;
- modcount = 0;
- eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
+ PL_modcount = 0;
+ PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
left = mod(left, OP_AASSIGN);
- if (eval_start)
- eval_start = 0;
+ if (PL_eval_start)
+ PL_eval_start = 0;
else {
op_free(left);
op_free(right);
list(force_list(left)) );
o->op_private = 0 | (flags >> 8);
if (!(left->op_private & OPpLVAL_INTRO)) {
- static int generation = 100;
OP *curop;
OP *lastop = o;
- generation++;
+ PL_generation++;
for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
if (opargs[curop->op_type] & OA_DANGEROUS) {
if (curop->op_type == OP_GV) {
GV *gv = ((GVOP*)curop)->op_gv;
- if (gv == defgv || SvCUR(gv) == generation)
+ if (gv == PL_defgv || SvCUR(gv) == PL_generation)
break;
- SvCUR(gv) = generation;
+ SvCUR(gv) = PL_generation;
}
else if (curop->op_type == OP_PADSV ||
curop->op_type == OP_PADAV ||
curop->op_type == OP_PADHV ||
curop->op_type == OP_PADANY) {
- SV **svp = AvARRAY(comppad_name);
+ SV **svp = AvARRAY(PL_comppad_name);
SV *sv = svp[curop->op_targ];
- if (SvCUR(sv) == generation)
+ if (SvCUR(sv) == PL_generation)
break;
- SvCUR(sv) = generation; /* (SvCUR not used any more) */
+ SvCUR(sv) = PL_generation; /* (SvCUR not used any more) */
}
else if (curop->op_type == OP_RV2CV)
break;
if (lastop->op_type != OP_GV) /* funny deref? */
break;
}
+ else if (curop->op_type == OP_PUSHRE) {
+ if (((PMOP*)curop)->op_pmreplroot) {
+ GV *gv = (GV*)((PMOP*)curop)->op_pmreplroot;
+ if (gv == PL_defgv || SvCUR(gv) == PL_generation)
+ break;
+ SvCUR(gv) = PL_generation;
+ }
+ }
else
break;
}
}
}
else {
- if (modcount < 10000 &&
+ if (PL_modcount < 10000 &&
((LISTOP*)right)->op_last->op_type == OP_CONST)
{
SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
if (SvIVX(sv) == 0)
- sv_setiv(sv, modcount+1);
+ sv_setiv(sv, PL_modcount+1);
}
}
}
return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
}
else {
- eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
+ PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
o = newBINOP(OP_SASSIGN, flags,
scalar(right), mod(scalar(left), OP_SASSIGN) );
- if (eval_start)
- eval_start = 0;
+ if (PL_eval_start)
+ PL_eval_start = 0;
else {
op_free(o);
return Nullop;
register COP *cop;
Newz(1101, cop, 1, COP);
- if (PERLDB_LINE && curcop->cop_line && curstash != debstash) {
+ if (PERLDB_LINE && PL_curcop->cop_line && PL_curstash != PL_debstash) {
cop->op_type = OP_DBSTATE;
cop->op_ppaddr = ppaddr[ OP_DBSTATE ];
}
cop->op_ppaddr = ppaddr[ OP_NEXTSTATE ];
}
cop->op_flags = flags;
- cop->op_private = 0 | (flags >> 8);
+ cop->op_private = (PL_hints & HINT_UTF8);
#ifdef NATIVE_HINTS
cop->op_private |= NATIVE_HINTS;
#endif
+ PL_compiling.op_private = cop->op_private;
cop->op_next = (OP*)cop;
if (label) {
cop->cop_label = label;
- hints |= HINT_BLOCK_SCOPE;
+ PL_hints |= HINT_BLOCK_SCOPE;
}
cop->cop_seq = seq;
- cop->cop_arybase = curcop->cop_arybase;
+ cop->cop_arybase = PL_curcop->cop_arybase;
+ if (PL_curcop->cop_warnings == WARN_NONE
+ || PL_curcop->cop_warnings == WARN_ALL)
+ cop->cop_warnings = PL_curcop->cop_warnings ;
+ else
+ cop->cop_warnings = newSVsv(PL_curcop->cop_warnings) ;
+
- if (copline == NOLINE)
- cop->cop_line = curcop->cop_line;
+ if (PL_copline == NOLINE)
+ cop->cop_line = PL_curcop->cop_line;
else {
- cop->cop_line = copline;
- copline = NOLINE;
+ cop->cop_line = PL_copline;
+ PL_copline = NOLINE;
}
- cop->cop_filegv = (GV*)SvREFCNT_inc(curcop->cop_filegv);
- cop->cop_stash = curstash;
+ cop->cop_filegv = (GV*)SvREFCNT_inc(PL_curcop->cop_filegv);
+ cop->cop_stash = PL_curstash;
- if (PERLDB_LINE && curstash != debstash) {
- SV **svp = av_fetch(GvAV(curcop->cop_filegv),(I32)cop->cop_line, FALSE);
- if (svp && *svp != &sv_undef && !SvIOK(*svp)) {
+ if (PERLDB_LINE && PL_curstash != PL_debstash) {
+ SV **svp = av_fetch(GvAV(PL_curcop->cop_filegv),(I32)cop->cop_line, FALSE);
+ if (svp && *svp != &PL_sv_undef && !SvIOK(*svp)) {
(void)SvIOK_on(*svp);
SvIVX(*svp) = 1;
SvSTASH(*svp) = (HV*)cop;
SV *sv;
I32 i;
- if (! min_intro_pending)
- return cop_seqmax;
+ if (! PL_min_intro_pending)
+ return PL_cop_seqmax;
- svp = AvARRAY(comppad_name);
- for (i = min_intro_pending; i <= max_intro_pending; i++) {
- if ((sv = svp[i]) && sv != &sv_undef && !SvIVX(sv)) {
- SvIVX(sv) = 999999999; /* Don't know scope end yet. */
- SvNVX(sv) = (double)cop_seqmax;
+ svp = AvARRAY(PL_comppad_name);
+ for (i = PL_min_intro_pending; i <= PL_max_intro_pending; i++) {
+ if ((sv = svp[i]) && sv != &PL_sv_undef && !SvIVX(sv)) {
+ SvIVX(sv) = PAD_MAX; /* Don't know scope end yet. */
+ SvNVX(sv) = (double)PL_cop_seqmax;
}
}
- min_intro_pending = 0;
- comppad_name_fill = max_intro_pending; /* Needn't search higher */
- return cop_seqmax++;
+ PL_min_intro_pending = 0;
+ PL_comppad_name_fill = PL_max_intro_pending; /* Needn't search higher */
+ return PL_cop_seqmax++;
}
OP *
return new_logop(type, flags, &first, &other);
}
-static OP *
+STATIC OP *
new_logop(I32 type, I32 flags, OP** firstp, OP** otherp)
{
dTHR;
}
}
if (first->op_type == OP_CONST) {
- if (dowarn && (first->op_private & OPpCONST_BARE))
- warn("Probable precedence problem on %s", op_desc[type]);
+ if (ckWARN(WARN_PRECEDENCE) && (first->op_private & OPpCONST_BARE))
+ warner(WARN_PRECEDENCE, "Probable precedence problem on %s",
+ op_desc[type]);
if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
op_free(first);
*firstp = Nullop;
else
scalar(other);
}
- else if (dowarn && (first->op_flags & OPf_KIDS)) {
+ else if (ckWARN(WARN_UNSAFE) && (first->op_flags & OPf_KIDS)) {
OP *k1 = ((UNOP*)first)->op_first;
OP *k2 = k1->op_sibling;
OPCODE warnop = 0;
case OP_NULL:
if (k2 && k2->op_type == OP_READLINE
&& (k2->op_flags & OPf_STACKED)
- && (k1->op_type == OP_RV2SV || k1->op_type == OP_PADSV))
+ && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
warnop = k2->op_type;
break;
break;
}
if (warnop) {
- line_t oldline = curcop->cop_line;
- curcop->cop_line = copline;
- warn("Value of %s%s can be \"0\"; test with defined()",
+ line_t oldline = PL_curcop->cop_line;
+ PL_curcop->cop_line = PL_copline;
+ warner(WARN_UNSAFE,
+ "Value of %s%s can be \"0\"; test with defined()",
op_desc[warnop],
((warnop == OP_READLINE || warnop == OP_GLOB)
? " construct" : "() operator"));
- curcop->cop_line = oldline;
+ PL_curcop->cop_line = oldline;
}
}
|| (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB)) {
expr = newUNOP(OP_DEFINED, 0,
newASSIGNOP(0, newDEFSVOP(), 0, expr) );
+ } else if (expr->op_flags & OPf_KIDS) {
+ OP *k1 = ((UNOP*)expr)->op_first;
+ OP *k2 = (k1) ? k1->op_sibling : NULL;
+ switch (expr->op_type) {
+ case OP_NULL:
+ if (k2 && k2->op_type == OP_READLINE
+ && (k2->op_flags & OPf_STACKED)
+ && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
+ expr = newUNOP(OP_DEFINED, 0, expr);
+ break;
+
+ case OP_SASSIGN:
+ if (k1->op_type == OP_READDIR
+ || k1->op_type == OP_GLOB
+ || k1->op_type == OP_EACH)
+ expr = newUNOP(OP_DEFINED, 0, expr);
+ break;
+ }
}
}
|| (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB))) {
expr = newUNOP(OP_DEFINED, 0,
newASSIGNOP(0, newDEFSVOP(), 0, expr) );
+ } else if (expr && (expr->op_flags & OPf_KIDS)) {
+ OP *k1 = ((UNOP*)expr)->op_first;
+ OP *k2 = (k1) ? k1->op_sibling : NULL;
+ switch (expr->op_type) {
+ case OP_NULL:
+ if (k2 && k2->op_type == OP_READLINE
+ && (k2->op_flags & OPf_STACKED)
+ && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
+ expr = newUNOP(OP_DEFINED, 0, expr);
+ break;
+
+ case OP_SASSIGN:
+ if (k1->op_type == OP_READDIR
+ || k1->op_type == OP_GLOB
+ || k1->op_type == OP_EACH)
+ expr = newUNOP(OP_DEFINED, 0, expr);
+ break;
+ }
}
if (!block)
if (expr) {
cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
if ((line_t)whileline != NOLINE) {
- copline = whileline;
+ PL_copline = whileline;
cont = append_elem(OP_LINESEQ, cont,
newSTATEOP(0, Nullch, Nullop));
}
redo = LINKLIST(listop);
if (expr) {
- copline = whileline;
+ PL_copline = whileline;
scalar(listop);
o = new_logop(OP_AND, 0, &expr, &listop);
if (o == expr && o->op_type == OP_CONST && !SvTRUE(cSVOPo->op_sv)) {
padoff = find_threadsv("_");
iterflags |= OPf_SPECIAL;
#else
- sv = newGVOP(OP_GV, 0, defgv);
+ sv = newGVOP(OP_GV, 0, PL_defgv);
#endif
}
if (expr->op_type == OP_RV2AV || expr->op_type == OP_PADAV) {
- expr = scalar(ref(expr, OP_ITER));
+ expr = mod(force_list(scalar(ref(expr, OP_ITER))), OP_GREPSTART);
+ iterflags |= OPf_STACKED;
+ }
+ else if (expr->op_type == OP_NULL &&
+ (expr->op_flags & OPf_KIDS) &&
+ ((BINOP*)expr)->op_first->op_type == OP_FLOP)
+ {
+ /* Basically turn for($x..$y) into the same as for($x,$y), but we
+ * set the STACKED flag to indicate that these values are to be
+ * treated as min/max values by 'pp_iterinit'.
+ */
+ UNOP* flip = (UNOP*)((UNOP*)((BINOP*)expr)->op_first)->op_first;
+ CONDOP* range = (CONDOP*) flip->op_first;
+ OP* left = range->op_first;
+ OP* right = left->op_sibling;
+ LISTOP* listop;
+
+ range->op_flags &= ~OPf_KIDS;
+ range->op_first = Nullop;
+
+ listop = (LISTOP*)newLISTOP(OP_LIST, 0, left, right);
+ listop->op_first->op_next = range->op_true;
+ left->op_next = range->op_false;
+ right->op_next = (OP*)listop;
+ listop->op_next = listop->op_first;
+
+ op_free(expr);
+ expr = (OP*)(listop);
+ null(expr);
iterflags |= OPf_STACKED;
}
+ else {
+ expr = mod(force_list(expr), OP_GREPSTART);
+ }
+
+
loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
- append_elem(OP_LIST, mod(force_list(expr), OP_GREPSTART),
- scalar(sv))));
+ append_elem(OP_LIST, expr, scalar(sv))));
assert(!loop->op_next);
Renew(loop, 1, LOOP);
loop->op_targ = padoff;
wop = newWHILEOP(flags, 1, loop, forline, newOP(OP_ITER, 0), block, cont);
- copline = forline;
+ PL_copline = forline;
return newSTATEOP(0, label, wop);
}
o = newOP(type, OPf_SPECIAL);
else {
o = newPVOP(type, 0, savepv(label->op_type == OP_CONST
- ? SvPVx(((SVOP*)label)->op_sv, na)
+ ? SvPVx(((SVOP*)label)->op_sv, PL_na)
: ""));
}
op_free(label);
label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
o = newUNOP(type, OPf_STACKED, label);
}
- hints |= HINT_BLOCK_SCOPE;
+ PL_hints |= HINT_BLOCK_SCOPE;
return o;
}
#endif /* USE_THREADS */
ENTER;
- SAVESPTR(curpad);
- curpad = 0;
+ SAVESPTR(PL_curpad);
+ PL_curpad = 0;
if (!CvCLONED(cv))
op_free(CvROOT(cv));
SV* sv = svp ? *svp : Nullsv;
if (!sv)
continue;
- if (sv == (SV*)comppad_name)
- comppad_name = Nullav;
- else if (sv == (SV*)comppad) {
- comppad = Nullav;
- curpad = Null(SV**);
+ if (sv == (SV*)PL_comppad_name)
+ PL_comppad_name = Nullav;
+ else if (sv == (SV*)PL_comppad) {
+ PL_comppad = Nullav;
+ PL_curpad = Null(SV**);
}
SvREFCNT_dec(sv);
}
}
#ifdef DEBUG_CLOSURES
-static void
+STATIC void
cv_dump(cv)
CV* cv;
{
PerlIO_printf(Perl_debug_log, "\tCV=0x%lx (%s), OUTSIDE=0x%lx (%s)\n",
cv,
(CvANON(cv) ? "ANON"
- : (cv == main_cv) ? "MAIN"
- : CvUNIQUE(outside) ? "UNIQUE"
+ : (cv == PL_main_cv) ? "MAIN"
+ : CvUNIQUE(cv) ? "UNIQUE"
: CvGV(cv) ? GvNAME(CvGV(cv)) : "UNDEFINED"),
outside,
(!outside ? "null"
: CvANON(outside) ? "ANON"
- : (outside == main_cv) ? "MAIN"
+ : (outside == PL_main_cv) ? "MAIN"
: CvUNIQUE(outside) ? "UNIQUE"
: CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
}
#endif /* DEBUG_CLOSURES */
-static CV *
+STATIC CV *
cv_clone2(CV *proto, CV *outside)
{
dTHR;
assert(!CvUNIQUE(proto));
ENTER;
- SAVESPTR(curpad);
- SAVESPTR(comppad);
- SAVESPTR(comppad_name);
- SAVESPTR(compcv);
+ SAVESPTR(PL_curpad);
+ SAVESPTR(PL_comppad);
+ SAVESPTR(PL_comppad_name);
+ SAVESPTR(PL_compcv);
- cv = compcv = (CV*)NEWSV(1104,0);
+ cv = PL_compcv = (CV*)NEWSV(1104,0);
sv_upgrade((SV *)cv, SvTYPE(proto));
CvCLONED_on(cv);
if (CvANON(proto))
if (SvPOK(proto))
sv_setpvn((SV*)cv, SvPVX(proto), SvCUR(proto));
- comppad_name = newAV();
+ PL_comppad_name = newAV();
for (ix = fname; ix >= 0; ix--)
- av_store(comppad_name, ix, SvREFCNT_inc(pname[ix]));
+ av_store(PL_comppad_name, ix, SvREFCNT_inc(pname[ix]));
- comppad = newAV();
+ PL_comppad = newAV();
comppadlist = newAV();
AvREAL_off(comppadlist);
- av_store(comppadlist, 0, (SV*)comppad_name);
- av_store(comppadlist, 1, (SV*)comppad);
+ av_store(comppadlist, 0, (SV*)PL_comppad_name);
+ av_store(comppadlist, 1, (SV*)PL_comppad);
CvPADLIST(cv) = comppadlist;
- av_fill(comppad, AvFILLp(protopad));
- curpad = AvARRAY(comppad);
+ av_fill(PL_comppad, AvFILLp(protopad));
+ PL_curpad = AvARRAY(PL_comppad);
av = newAV(); /* will be @_ */
av_extend(av, 0);
- av_store(comppad, 0, (SV*)av);
+ av_store(PL_comppad, 0, (SV*)av);
AvFLAGS(av) = AVf_REIFY;
for (ix = fpad; ix > 0; ix--) {
SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
- if (namesv && namesv != &sv_undef) {
+ if (namesv && namesv != &PL_sv_undef) {
char *name = SvPVX(namesv); /* XXX */
if (SvFLAGS(namesv) & SVf_FAKE) { /* lexical from outside? */
I32 off = pad_findlex(name, ix, SvIVX(namesv),
- CvOUTSIDE(cv), cxstack_ix);
+ CvOUTSIDE(cv), cxstack_ix, 0);
if (!off)
- curpad[ix] = SvREFCNT_inc(ppad[ix]);
+ PL_curpad[ix] = SvREFCNT_inc(ppad[ix]);
else if (off != ix)
croak("panic: cv_clone: %s", name);
}
sv = NEWSV(0,0);
if (!SvPADBUSY(sv))
SvPADMY_on(sv);
- curpad[ix] = sv;
+ PL_curpad[ix] = sv;
}
}
else {
SV* sv = NEWSV(0,0);
SvPADTMP_on(sv);
- curpad[ix] = sv;
+ PL_curpad[ix] = sv;
}
}
for (ix = fpad; ix > 0; ix--) {
SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
if (namesv
- && namesv != &sv_undef
+ && namesv != &PL_sv_undef
&& !(SvFLAGS(namesv) & SVf_FAKE)
&& *SvPVX(namesv) == '&'
&& CvCLONE(ppad[ix]))
SvREFCNT_dec(ppad[ix]);
CvCLONE_on(kid);
SvPADMY_on(kid);
- curpad[ix] = (SV*)kid;
+ PL_curpad[ix] = (SV*)kid;
}
}
SV *
cv_const_sv(CV *cv)
{
- OP *o;
- SV *sv;
-
if (!cv || !SvPOK(cv) || SvCUR(cv))
return Nullsv;
+ return op_const_sv(CvSTART(cv), cv);
+}
+
+SV *
+op_const_sv(OP *o, CV *cv)
+{
+ SV *sv = Nullsv;
+
+ if(!o)
+ return Nullsv;
+
+ if(o->op_type == OP_LINESEQ && cLISTOPo->op_first)
+ o = cLISTOPo->op_first->op_sibling;
- sv = Nullsv;
- for (o = CvSTART(cv); o; o = o->op_next) {
+ for (; o; o = o->op_next) {
OPCODE type = o->op_type;
-
+
+ if(sv && o->op_next == o)
+ return sv;
if (type == OP_NEXTSTATE || type == OP_NULL || type == OP_PUSHMARK)
continue;
if (type == OP_LEAVESUB || type == OP_RETURN)
return Nullsv;
if (type == OP_CONST)
sv = cSVOPo->op_sv;
- else if (type == OP_PADSV) {
+ else if (type == OP_PADSV && cv) {
AV* padav = (AV*)(AvARRAY(CvPADLIST(cv))[1]);
sv = padav ? AvARRAY(padav)[o->op_targ] : Nullsv;
if (!sv || (!SvREADONLY(sv) && SvREFCNT(sv) > 1))
newSUB(I32 floor, OP *o, OP *proto, OP *block)
{
dTHR;
- char *name = o ? SvPVx(cSVOPo->op_sv, na) : Nullch;
- GV *gv = gv_fetchpv(name ? name : "__ANON__", GV_ADDMULTI, SVt_PVCV);
- char *ps = proto ? SvPVx(((SVOP*)proto)->op_sv, na) : Nullch;
- register CV *cv;
+ char *name = o ? SvPVx(cSVOPo->op_sv, PL_na) : Nullch;
+ GV *gv = gv_fetchpv(name ? name : "__ANON__",
+ GV_ADDMULTI | (block ? 0 : GV_NOINIT), SVt_PVCV);
+ char *ps = proto ? SvPVx(((SVOP*)proto)->op_sv, PL_na) : Nullch;
+ register CV *cv=0;
I32 ix;
if (o)
if (proto)
SAVEFREEOP(proto);
+ if (SvTYPE(gv) != SVt_PVGV) { /* Prototype now, and had
+ maximum a prototype before. */
+ if (SvTYPE(gv) > SVt_NULL) {
+ if (!SvPOK((SV*)gv) && !(SvIOK((SV*)gv) && SvIVX((SV*)gv) == -1))
+ warn("Runaway prototype");
+ cv_ckproto((CV*)gv, NULL, ps);
+ }
+ if (ps)
+ sv_setpv((SV*)gv, ps);
+ else
+ sv_setiv((SV*)gv, -1);
+ SvREFCNT_dec(PL_compcv);
+ cv = PL_compcv = NULL;
+ PL_sub_generation++;
+ goto noblock;
+ }
+
if (!name || GvCVGEN(gv))
cv = Nullcv;
else if (cv = GvCV(gv)) {
/* already defined (or promised)? */
if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
SV* const_sv;
+ bool const_changed = TRUE;
if (!block) {
/* just a "sub foo;" when &foo is already defined */
- SAVEFREESV(compcv);
+ SAVEFREESV(PL_compcv);
goto done;
}
/* ahem, death to those who redefine active sort subs */
- if (curstackinfo->si_type == SI_SORT && sortcop == CvSTART(cv))
+ if (PL_curstackinfo->si_type == PERLSI_SORT && PL_sortcop == CvSTART(cv))
croak("Can't redefine active sort subroutine %s", name);
- const_sv = cv_const_sv(cv);
- if (const_sv || dowarn && !(CvGV(cv) && GvSTASH(CvGV(cv))
+ if(const_sv = cv_const_sv(cv))
+ const_changed = sv_cmp(const_sv, op_const_sv(block, Nullcv));
+ if ((const_sv && const_changed) || ckWARN(WARN_REDEFINE)
+ && !(CvGV(cv) && GvSTASH(CvGV(cv))
&& HvNAME(GvSTASH(CvGV(cv)))
&& strEQ(HvNAME(GvSTASH(CvGV(cv))),
"autouse"))) {
- line_t oldline = curcop->cop_line;
- curcop->cop_line = copline;
- warn(const_sv ? "Constant subroutine %s redefined"
- : "Subroutine %s redefined", name);
- curcop->cop_line = oldline;
+ line_t oldline = PL_curcop->cop_line;
+ PL_curcop->cop_line = PL_copline;
+ warner(WARN_REDEFINE,
+ const_sv ? "Constant subroutine %s redefined"
+ : "Subroutine %s redefined", name);
+ PL_curcop->cop_line = oldline;
}
SvREFCNT_dec(cv);
cv = Nullcv;
}
if (cv) { /* must reuse cv if autoloaded */
cv_undef(cv);
- CvFLAGS(cv) = CvFLAGS(compcv);
- CvOUTSIDE(cv) = CvOUTSIDE(compcv);
- CvOUTSIDE(compcv) = 0;
- CvPADLIST(cv) = CvPADLIST(compcv);
- CvPADLIST(compcv) = 0;
- if (SvREFCNT(compcv) > 1) /* XXX Make closures transit through stub. */
- CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc((SV*)cv);
- SvREFCNT_dec(compcv);
+ CvFLAGS(cv) = CvFLAGS(PL_compcv);
+ CvOUTSIDE(cv) = CvOUTSIDE(PL_compcv);
+ CvOUTSIDE(PL_compcv) = 0;
+ CvPADLIST(cv) = CvPADLIST(PL_compcv);
+ CvPADLIST(PL_compcv) = 0;
+ if (SvREFCNT(PL_compcv) > 1) /* XXX Make closures transit through stub. */
+ CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc((SV*)cv);
+ SvREFCNT_dec(PL_compcv);
}
else {
- cv = compcv;
+ cv = PL_compcv;
if (name) {
GvCV(gv) = cv;
GvCVGEN(gv) = 0;
- sub_generation++;
+ PL_sub_generation++;
}
}
CvGV(cv) = (GV*)SvREFCNT_inc(gv);
- CvFILEGV(cv) = curcop->cop_filegv;
- CvSTASH(cv) = curstash;
+ CvFILEGV(cv) = PL_curcop->cop_filegv;
+ CvSTASH(cv) = PL_curstash;
#ifdef USE_THREADS
CvOWNER(cv) = 0;
- New(666, CvMUTEXP(cv), 1, perl_mutex);
- MUTEX_INIT(CvMUTEXP(cv));
+ if (!CvMUTEXP(cv)) {
+ New(666, CvMUTEXP(cv), 1, perl_mutex);
+ MUTEX_INIT(CvMUTEXP(cv));
+ }
#endif /* USE_THREADS */
if (ps)
sv_setpv((SV*)cv, ps);
- if (error_count) {
+ if (PL_error_count) {
op_free(block);
block = Nullop;
if (name) {
if (strEQ(s, "BEGIN")) {
char *not_safe =
"BEGIN not safe after errors--compilation aborted";
- if (in_eval & 4)
+ if (PL_in_eval & 4)
croak(not_safe);
else {
/* force display of errors found but not reported */
sv_catpv(ERRSV, not_safe);
- croak("%s", SvPVx(ERRSV, na));
+ croak("%s", SvPVx(ERRSV, PL_na));
}
}
}
}
if (!block) {
- copline = NOLINE;
+ noblock:
+ PL_copline = NOLINE;
LEAVE_SCOPE(floor);
return cv;
}
- if (AvFILLp(comppad_name) < AvFILLp(comppad))
- av_store(comppad_name, AvFILLp(comppad), Nullsv);
+ if (AvFILLp(PL_comppad_name) < AvFILLp(PL_comppad))
+ av_store(PL_comppad_name, AvFILLp(PL_comppad), Nullsv);
if (CvCLONE(cv)) {
- SV **namep = AvARRAY(comppad_name);
- for (ix = AvFILLp(comppad); ix > 0; ix--) {
+ SV **namep = AvARRAY(PL_comppad_name);
+ for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
SV *namesv;
- if (SvIMMORTAL(curpad[ix]))
+ if (SvIMMORTAL(PL_curpad[ix]))
continue;
/*
* The only things that a clonable function needs in its
* The rest are created anew during cloning.
*/
if (!((namesv = namep[ix]) != Nullsv &&
- namesv != &sv_undef &&
+ namesv != &PL_sv_undef &&
(SvFAKE(namesv) ||
*SvPVX(namesv) == '&')))
{
- SvREFCNT_dec(curpad[ix]);
- curpad[ix] = Nullsv;
+ SvREFCNT_dec(PL_curpad[ix]);
+ PL_curpad[ix] = Nullsv;
}
}
}
else {
AV *av = newAV(); /* Will be @_ */
av_extend(av, 0);
- av_store(comppad, 0, (SV*)av);
+ av_store(PL_comppad, 0, (SV*)av);
AvFLAGS(av) = AVf_REIFY;
- for (ix = AvFILLp(comppad); ix > 0; ix--) {
- if (SvIMMORTAL(curpad[ix]))
+ for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
+ if (SvIMMORTAL(PL_curpad[ix]))
continue;
- if (!SvPADMY(curpad[ix]))
- SvPADTMP_on(curpad[ix]);
+ if (!SvPADMY(PL_curpad[ix]))
+ SvPADTMP_on(PL_curpad[ix]);
}
}
if (name) {
char *s;
- if (PERLDB_SUBLINE && curstash != debstash) {
+ if (PERLDB_SUBLINE && PL_curstash != PL_debstash) {
SV *sv = NEWSV(0,0);
SV *tmpstr = sv_newmortal();
GV *db_postponed = gv_fetchpv("DB::postponed", GV_ADDMULTI, SVt_PVHV);
HV *hv;
sv_setpvf(sv, "%_:%ld-%ld",
- GvSV(curcop->cop_filegv),
- (long)subline, (long)curcop->cop_line);
+ GvSV(PL_curcop->cop_filegv),
+ (long)PL_subline, (long)PL_curcop->cop_line);
gv_efullname3(tmpstr, gv, Nullch);
- hv_store(GvHV(DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
+ hv_store(GvHV(PL_DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
hv = GvHVn(db_postponed);
if (HvFILL(hv) > 0 && hv_exists(hv, SvPVX(tmpstr), SvCUR(tmpstr))
&& (cv = GvCV(db_postponed))) {
else
s = name;
if (strEQ(s, "BEGIN")) {
- I32 oldscope = scopestack_ix;
+ I32 oldscope = PL_scopestack_ix;
ENTER;
- SAVESPTR(compiling.cop_filegv);
- SAVEI16(compiling.cop_line);
- SAVEI32(perldb);
- save_svref(&rs);
- sv_setsv(rs, nrs);
-
- if (!beginav)
- beginav = newAV();
+ SAVESPTR(PL_compiling.cop_filegv);
+ SAVEI16(PL_compiling.cop_line);
+ save_svref(&PL_rs);
+ sv_setsv(PL_rs, PL_nrs);
+
+ if (!PL_beginav)
+ PL_beginav = newAV();
DEBUG_x( dump_sub(gv) );
- av_push(beginav, (SV *)cv);
+ av_push(PL_beginav, (SV *)cv);
GvCV(gv) = 0;
- call_list(oldscope, beginav);
+ call_list(oldscope, PL_beginav);
- curcop = &compiling;
+ PL_curcop = &PL_compiling;
+ PL_compiling.op_private = PL_hints;
LEAVE;
}
- else if (strEQ(s, "END") && !error_count) {
- if (!endav)
- endav = newAV();
- av_unshift(endav, 1);
- av_store(endav, 0, (SV *)cv);
+ else if (strEQ(s, "END") && !PL_error_count) {
+ if (!PL_endav)
+ PL_endav = newAV();
+ av_unshift(PL_endav, 1);
+ av_store(PL_endav, 0, (SV *)cv);
GvCV(gv) = 0;
}
- else if (strEQ(s, "INIT") && !error_count) {
- if (!initav)
- initav = newAV();
- av_push(initav, SvREFCNT_inc(cv));
+ else if (strEQ(s, "INIT") && !PL_error_count) {
+ if (!PL_initav)
+ PL_initav = newAV();
+ av_push(PL_initav, SvREFCNT_inc(cv));
+ GvCV(gv) = 0;
}
}
done:
- copline = NOLINE;
+ PL_copline = NOLINE;
LEAVE_SCOPE(floor);
return cv;
}
newCONSTSUB(HV *stash, char *name, SV *sv)
{
dTHR;
- U32 oldhints = hints;
- HV *old_cop_stash = curcop->cop_stash;
- HV *old_curstash = curstash;
- line_t oldline = curcop->cop_line;
- curcop->cop_line = copline;
+ U32 oldhints = PL_hints;
+ HV *old_cop_stash = PL_curcop->cop_stash;
+ HV *old_curstash = PL_curstash;
+ line_t oldline = PL_curcop->cop_line;
+ PL_curcop->cop_line = PL_copline;
- hints &= ~HINT_BLOCK_SCOPE;
+ PL_hints &= ~HINT_BLOCK_SCOPE;
if(stash)
- curstash = curcop->cop_stash = stash;
+ PL_curstash = PL_curcop->cop_stash = stash;
newSUB(
start_subparse(FALSE, 0),
newSVOP(OP_CONST, 0, newSVpv(name,0)),
- newSVOP(OP_CONST, 0, &sv_no), /* SvPV(&sv_no) == "" -- GMB */
+ newSVOP(OP_CONST, 0, &PL_sv_no), /* SvPV(&PL_sv_no) == "" -- GMB */
newSTATEOP(0, Nullch, newSVOP(OP_CONST, 0, sv))
);
- hints = oldhints;
- curcop->cop_stash = old_cop_stash;
- curstash = old_curstash;
- curcop->cop_line = oldline;
+ PL_hints = oldhints;
+ PL_curcop->cop_stash = old_cop_stash;
+ PL_curstash = old_curstash;
+ PL_curcop->cop_line = oldline;
}
CV *
-newXS(char *name, void (*subaddr) (CV *), char *filename)
+newXS(char *name, void (*subaddr) (CV * _CPERLproto), char *filename)
{
dTHR;
GV *gv = gv_fetchpv(name ? name : "__ANON__", GV_ADDMULTI, SVt_PVCV);
}
else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
/* already defined (or promised) */
- if (dowarn && !(CvGV(cv) && GvSTASH(CvGV(cv))
+ if (ckWARN(WARN_REDEFINE) && !(CvGV(cv) && GvSTASH(CvGV(cv))
&& HvNAME(GvSTASH(CvGV(cv)))
&& strEQ(HvNAME(GvSTASH(CvGV(cv))), "autouse"))) {
- line_t oldline = curcop->cop_line;
- curcop->cop_line = copline;
- warn("Subroutine %s redefined",name);
- curcop->cop_line = oldline;
+ line_t oldline = PL_curcop->cop_line;
+ if (PL_copline != NOLINE)
+ PL_curcop->cop_line = PL_copline;
+ warner(WARN_REDEFINE, "Subroutine %s redefined",name);
+ PL_curcop->cop_line = oldline;
}
SvREFCNT_dec(cv);
cv = 0;
if (name) {
GvCV(gv) = cv;
GvCVGEN(gv) = 0;
- sub_generation++;
+ PL_sub_generation++;
}
}
CvGV(cv) = (GV*)SvREFCNT_inc(gv);
else
s = name;
if (strEQ(s, "BEGIN")) {
- if (!beginav)
- beginav = newAV();
- av_push(beginav, (SV *)cv);
+ if (!PL_beginav)
+ PL_beginav = newAV();
+ av_push(PL_beginav, (SV *)cv);
GvCV(gv) = 0;
}
else if (strEQ(s, "END")) {
- if (!endav)
- endav = newAV();
- av_unshift(endav, 1);
- av_store(endav, 0, (SV *)cv);
+ if (!PL_endav)
+ PL_endav = newAV();
+ av_unshift(PL_endav, 1);
+ av_store(PL_endav, 0, (SV *)cv);
GvCV(gv) = 0;
}
else if (strEQ(s, "INIT")) {
- if (!initav)
- initav = newAV();
- av_push(initav, (SV *)cv);
+ if (!PL_initav)
+ PL_initav = newAV();
+ av_push(PL_initav, (SV *)cv);
+ GvCV(gv) = 0;
}
}
else
I32 ix;
if (o)
- name = SvPVx(cSVOPo->op_sv, na);
+ name = SvPVx(cSVOPo->op_sv, PL_na);
else
name = "STDOUT";
gv = gv_fetchpv(name,TRUE, SVt_PVFM);
GvMULTI_on(gv);
if (cv = GvFORM(gv)) {
- if (dowarn) {
- line_t oldline = curcop->cop_line;
+ if (ckWARN(WARN_REDEFINE)) {
+ line_t oldline = PL_curcop->cop_line;
- curcop->cop_line = copline;
- warn("Format %s redefined",name);
- curcop->cop_line = oldline;
+ PL_curcop->cop_line = PL_copline;
+ warner(WARN_REDEFINE, "Format %s redefined",name);
+ PL_curcop->cop_line = oldline;
}
SvREFCNT_dec(cv);
}
- cv = compcv;
+ cv = PL_compcv;
GvFORM(gv) = cv;
CvGV(cv) = (GV*)SvREFCNT_inc(gv);
- CvFILEGV(cv) = curcop->cop_filegv;
+ CvFILEGV(cv) = PL_curcop->cop_filegv;
- for (ix = AvFILLp(comppad); ix > 0; ix--) {
- if (!SvPADMY(curpad[ix]) && !SvIMMORTAL(curpad[ix]))
- SvPADTMP_on(curpad[ix]);
+ for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
+ if (!SvPADMY(PL_curpad[ix]) && !SvIMMORTAL(PL_curpad[ix]))
+ SvPADTMP_on(PL_curpad[ix]);
}
CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
CvROOT(cv)->op_next = 0;
peep(CvSTART(cv));
op_free(o);
- copline = NOLINE;
+ PL_copline = NOLINE;
LEAVE_SCOPE(floor);
}
case OP_PADSV:
o->op_type = OP_PADAV;
o->op_ppaddr = ppaddr[OP_PADAV];
- return ref(newUNOP(OP_RV2AV, 0, scalar(o)), OP_RV2AV);
+ return ref(o, OP_RV2AV);
case OP_RV2SV:
o->op_type = OP_RV2AV;
case OP_PADAV:
o->op_type = OP_PADHV;
o->op_ppaddr = ppaddr[OP_PADHV];
- return ref(newUNOP(OP_RV2HV, 0, scalar(o)), OP_RV2HV);
+ return ref(o, OP_RV2HV);
case OP_RV2SV:
case OP_RV2AV:
SvIVX(name) = -1;
SvNVX(name) = 1;
ix = pad_alloc(o->op_type, SVs_PADMY);
- av_store(comppad_name, ix, name);
- av_store(comppad, ix, cSVOPo->op_sv);
+ av_store(PL_comppad_name, ix, name);
+ av_store(PL_comppad, ix, cSVOPo->op_sv);
SvPADMY_on(cSVOPo->op_sv);
cSVOPo->op_sv = Nullsv;
cSVOPo->op_targ = ix;
OP *
ck_bitop(OP *o)
{
- o->op_private = hints;
+ o->op_private = PL_hints;
return o;
}
OP *
ck_eval(OP *o)
{
- hints |= HINT_BLOCK_SCOPE;
+ PL_hints |= HINT_BLOCK_SCOPE;
if (o->op_flags & OPf_KIDS) {
SVOP *kid = (SVOP*)cUNOPo->op_first;
op_free(o);
o = newUNOP(OP_ENTEREVAL, 0, newDEFSVOP());
}
- o->op_targ = (PADOFFSET)hints;
+ o->op_targ = (PADOFFSET)PL_hints;
return o;
}
dTHR;
SVOP *kid = (SVOP*)cUNOPo->op_first;
- o->op_private |= (hints & HINT_STRICT_REFS);
+ o->op_private |= (PL_hints & HINT_STRICT_REFS);
if (kid->op_type == OP_CONST) {
char *name;
int iscv;
GV *gv;
+ SV *kidsv = kid->op_sv;
+
+ /* Is it a constant from cv_const_sv()? */
+ if (SvROK(kidsv) && SvREADONLY(kidsv)) {
+ SV *rsv = SvRV(kidsv);
+ int svtype = SvTYPE(rsv);
+ char *badtype = Nullch;
- name = SvPV(kid->op_sv, na);
- if ((hints & HINT_STRICT_REFS) && (kid->op_private & OPpCONST_BARE)) {
+ switch (o->op_type) {
+ case OP_RV2SV:
+ if (svtype > SVt_PVMG)
+ badtype = "a SCALAR";
+ break;
+ case OP_RV2AV:
+ if (svtype != SVt_PVAV)
+ badtype = "an ARRAY";
+ break;
+ case OP_RV2HV:
+ if (svtype != SVt_PVHV) {
+ if (svtype == SVt_PVAV) { /* pseudohash? */
+ SV **ksv = av_fetch((AV*)rsv, 0, FALSE);
+ if (ksv && SvROK(*ksv)
+ && SvTYPE(SvRV(*ksv)) == SVt_PVHV)
+ {
+ break;
+ }
+ }
+ badtype = "a HASH";
+ }
+ break;
+ case OP_RV2CV:
+ if (svtype != SVt_PVCV)
+ badtype = "a CODE";
+ break;
+ }
+ if (badtype)
+ croak("Constant is not %s reference", badtype);
+ return o;
+ }
+ name = SvPV(kidsv, PL_na);
+ if ((PL_hints & HINT_STRICT_REFS) && (kid->op_private & OPpCONST_BARE)) {
char *badthing = Nullch;
switch (o->op_type) {
case OP_RV2SV:
if (o->op_flags & OPf_REF)
return o;
- if (o->op_flags & OPf_KIDS) {
+ if (o->op_flags & OPf_KIDS && cUNOPo->op_first->op_type != OP_STUB) {
SVOP *kid = (SVOP*)cUNOPo->op_first;
if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
OP *newop = newGVOP(type, OPf_REF,
- gv_fetchpv(SvPVx(kid->op_sv, na), TRUE, SVt_PVIO));
+ gv_fetchpv(SvPVx(kid->op_sv, PL_na), TRUE, SVt_PVIO));
op_free(o);
return newop;
}
case OA_AVREF:
if (kid->op_type == OP_CONST &&
(kid->op_private & OPpCONST_BARE)) {
- char *name = SvPVx(((SVOP*)kid)->op_sv, na);
+ char *name = SvPVx(((SVOP*)kid)->op_sv, PL_na);
OP *newop = newAVREF(newGVOP(OP_GV, 0,
gv_fetchpv(name, TRUE, SVt_PVAV) ));
- if (dowarn)
- warn("Array @%s missing the @ in argument %ld of %s()",
+ if (ckWARN(WARN_SYNTAX))
+ warner(WARN_SYNTAX,
+ "Array @%s missing the @ in argument %ld of %s()",
name, (long)numargs, op_desc[type]);
op_free(kid);
kid = newop;
case OA_HVREF:
if (kid->op_type == OP_CONST &&
(kid->op_private & OPpCONST_BARE)) {
- char *name = SvPVx(((SVOP*)kid)->op_sv, na);
+ char *name = SvPVx(((SVOP*)kid)->op_sv, PL_na);
OP *newop = newHVREF(newGVOP(OP_GV, 0,
gv_fetchpv(name, TRUE, SVt_PVHV) ));
- if (dowarn)
- warn("Hash %%%s missing the %% in argument %ld of %s()",
+ if (ckWARN(WARN_SYNTAX))
+ warner(WARN_SYNTAX,
+ "Hash %%%s missing the %% in argument %ld of %s()",
name, (long)numargs, op_desc[type]);
op_free(kid);
kid = newop;
}
break;
case OA_FILEREF:
- if (kid->op_type != OP_GV) {
+ if (kid->op_type != OP_GV && kid->op_type != OP_RV2GV) {
if (kid->op_type == OP_CONST &&
(kid->op_private & OPpCONST_BARE)) {
OP *newop = newGVOP(OP_GV, 0,
- gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, na), TRUE,
+ gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, PL_na), TRUE,
SVt_PVIO) );
op_free(kid);
kid = newop;
else
scalar(kid);
o = ck_fun(o);
- if (error_count)
+ if (PL_error_count)
return o;
kid = cLISTOPo->op_first->op_sibling;
if (kid->op_type != OP_NULL)
{
if (o->op_flags & OPf_KIDS) {
OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
+ if (kid)
+ kid = kid->op_sibling; /* get past "big" */
if (kid && kid->op_type == OP_CONST)
fbm_compile(((SVOP*)kid)->op_sv, 0);
}
o->op_private = 0;
#ifdef USE_LOCALE
- if (hints & HINT_LOCALE)
+ if (PL_hints & HINT_LOCALE)
o->op_private |= OPpLOCALE;
#endif
o->op_private = 0;
#ifdef USE_LOCALE
- if (hints & HINT_LOCALE)
+ if (PL_hints & HINT_LOCALE)
o->op_private |= OPpLOCALE;
#endif
{
o->op_private = 0;
#ifdef USE_LOCALE
- if (hints & HINT_LOCALE)
+ if (PL_hints & HINT_LOCALE)
o->op_private |= OPpLOCALE;
#endif
op_free(o);
#ifdef USE_THREADS
- if (!CvUNIQUE(compcv)) {
+ if (!CvUNIQUE(PL_compcv)) {
argop = newOP(OP_PADAV, OPf_REF);
- argop->op_targ = 0; /* curpad[0] is @_ */
+ argop->op_targ = 0; /* PL_curpad[0] is @_ */
}
else {
argop = newUNOP(OP_RV2AV, 0,
}
#else
argop = newUNOP(OP_RV2AV, 0,
- scalar(newGVOP(OP_GV, 0, !CvUNIQUE(compcv) ?
- defgv : gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
+ scalar(newGVOP(OP_GV, 0, !CvUNIQUE(PL_compcv) ?
+ PL_defgv : gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
#endif /* USE_THREADS */
return newUNOP(type, 0, scalar(argop));
}
{
o->op_private = 0;
#ifdef USE_LOCALE
- if (hints & HINT_LOCALE)
+ if (PL_hints & HINT_LOCALE)
o->op_private |= OPpLOCALE;
#endif
cv = GvCVu(tmpop->op_sv);
if (cv && SvPOK(cv) && !(o->op_private & OPpENTERSUB_AMPER)) {
namegv = CvANON(cv) ? (GV*)tmpop->op_sv : CvGV(cv);
- proto = SvPV((SV*)cv, na);
+ proto = SvPV((SV*)cv, PL_na);
}
}
}
- o->op_private |= (hints & HINT_STRICT_REFS);
- if (PERLDB_SUB && curstash != debstash)
+ o->op_private |= (PL_hints & HINT_STRICT_REFS);
+ if (PERLDB_SUB && PL_curstash != PL_debstash)
o->op_private |= OPpENTERSUB_DB;
while (o2 != cvop) {
if (proto) {
bad_type(arg, "sub", gv_ename(namegv), o2);
goto wrapref;
case '$':
- if (o2->op_type != OP_RV2SV && o2->op_type != OP_PADSV)
+ if (o2->op_type != OP_RV2SV
+ && o2->op_type != OP_PADSV
+ && o2->op_type != OP_THREADSV)
+ {
bad_type(arg, "scalar", gv_ename(namegv), o2);
+ }
goto wrapref;
case '@':
if (o2->op_type != OP_RV2AV && o2->op_type != OP_PADAV)
default:
oops:
croak("Malformed prototype for %s: %s",
- gv_ename(namegv), SvPV((SV*)cv, na));
+ gv_ename(namegv), SvPV((SV*)cv, PL_na));
}
}
else
return;
ENTER;
SAVEOP();
- SAVESPTR(curcop);
+ SAVESPTR(PL_curcop);
for (; o; o = o->op_next) {
if (o->op_seq)
break;
- if (!op_seqmax)
- op_seqmax++;
- op = o;
+ if (!PL_op_seqmax)
+ PL_op_seqmax++;
+ PL_op = o;
switch (o->op_type) {
case OP_NEXTSTATE:
case OP_DBSTATE:
- curcop = ((COP*)o); /* for warnings */
- o->op_seq = op_seqmax++;
+ PL_curcop = ((COP*)o); /* for warnings */
+ o->op_seq = PL_op_seqmax++;
break;
case OP_CONCAT:
case OP_QUOTEMETA:
if (o->op_next && o->op_next->op_type == OP_STRINGIFY)
null(o->op_next);
- o->op_seq = op_seqmax++;
+ o->op_seq = PL_op_seqmax++;
break;
case OP_STUB:
if ((o->op_flags & OPf_WANT) != OPf_WANT_LIST) {
- o->op_seq = op_seqmax++;
+ o->op_seq = PL_op_seqmax++;
break; /* Scalar stub must produce undef. List stub is noop */
}
goto nothin;
case OP_NULL:
if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE)
- curcop = ((COP*)o);
+ PL_curcop = ((COP*)o);
goto nothin;
case OP_SCALAR:
case OP_LINESEQ:
oldop->op_next = o->op_next;
continue;
}
- o->op_seq = op_seqmax++;
+ o->op_seq = PL_op_seqmax++;
break;
case OP_GV:
OP* pop = o->op_next->op_next;
IV i;
if (pop->op_type == OP_CONST &&
- (op = pop->op_next) &&
+ (PL_op = pop->op_next) &&
pop->op_next->op_type == OP_AELEM &&
!(pop->op_next->op_private &
(OPpLVAL_INTRO|OPpLVAL_DEFER|OPpDEREF)) &&
- (i = SvIV(((SVOP*)pop)->op_sv) - compiling.cop_arybase)
+ (i = SvIV(((SVOP*)pop)->op_sv) - PL_compiling.cop_arybase)
<= 255 &&
i >= 0)
{
GvAVn(((GVOP*)o)->op_gv);
}
}
- o->op_seq = op_seqmax++;
- break;
-
- case OP_PADAV:
- if (o->op_next->op_type == OP_RV2AV
- && (o->op_next->op_flags && OPf_REF))
- {
- null(o->op_next);
- o->op_next = o->op_next->op_next;
- }
- break;
-
- case OP_PADHV:
- if (o->op_next->op_type == OP_RV2HV
- && (o->op_next->op_flags && OPf_REF))
- {
- null(o->op_next);
- o->op_next = o->op_next->op_next;
- }
+ o->op_seq = PL_op_seqmax++;
break;
case OP_MAPWHILE:
case OP_GREPWHILE:
case OP_AND:
case OP_OR:
- o->op_seq = op_seqmax++;
+ o->op_seq = PL_op_seqmax++;
while (cLOGOP->op_other->op_type == OP_NULL)
cLOGOP->op_other = cLOGOP->op_other->op_next;
peep(cLOGOP->op_other);
break;
case OP_COND_EXPR:
- o->op_seq = op_seqmax++;
+ o->op_seq = PL_op_seqmax++;
peep(cCONDOP->op_true);
peep(cCONDOP->op_false);
break;
case OP_ENTERLOOP:
- o->op_seq = op_seqmax++;
+ o->op_seq = PL_op_seqmax++;
peep(cLOOP->op_redoop);
peep(cLOOP->op_nextop);
peep(cLOOP->op_lastop);
break;
+ case OP_QR:
case OP_MATCH:
case OP_SUBST:
- o->op_seq = op_seqmax++;
+ o->op_seq = PL_op_seqmax++;
peep(cPMOP->op_pmreplstart);
break;
case OP_EXEC:
- o->op_seq = op_seqmax++;
- if (dowarn && o->op_next && o->op_next->op_type == OP_NEXTSTATE) {
+ o->op_seq = PL_op_seqmax++;
+ if (ckWARN(WARN_SYNTAX) && o->op_next
+ && o->op_next->op_type == OP_NEXTSTATE) {
if (o->op_next->op_sibling &&
+ o->op_next->op_sibling->op_type != OP_EXIT &&
+ o->op_next->op_sibling->op_type != OP_WARN &&
o->op_next->op_sibling->op_type != OP_DIE) {
- line_t oldline = curcop->cop_line;
+ line_t oldline = PL_curcop->cop_line;
- curcop->cop_line = ((COP*)o->op_next)->cop_line;
- warn("Statement unlikely to be reached");
- warn("(Maybe you meant system() when you said exec()?)\n");
- curcop->cop_line = oldline;
+ PL_curcop->cop_line = ((COP*)o->op_next)->cop_line;
+ warner(WARN_SYNTAX, "Statement unlikely to be reached");
+ warner(WARN_SYNTAX, "(Maybe you meant system() when you said exec()?)\n");
+ PL_curcop->cop_line = oldline;
}
}
break;
rop = (UNOP*)((BINOP*)o)->op_first;
if (rop->op_type != OP_RV2HV || rop->op_first->op_type != OP_PADSV)
break;
- lexname = *av_fetch(comppad_name, rop->op_first->op_targ, TRUE);
+ lexname = *av_fetch(PL_comppad_name, rop->op_first->op_targ, TRUE);
if (!SvOBJECT(lexname))
break;
fields = (GV**)hv_fetch(SvSTASH(lexname), "FIELDS", 6, FALSE);
indsvp = hv_fetch(GvHV(*fields), key, keylen, FALSE);
if (!indsvp) {
croak("No such field \"%s\" in variable %s of type %s",
- key, SvPV(lexname, na), HvNAME(SvSTASH(lexname)));
+ key, SvPV(lexname, PL_na), HvNAME(SvSTASH(lexname)));
}
ind = SvIV(*indsvp);
if (ind < 1)
}
default:
- o->op_seq = op_seqmax++;
+ o->op_seq = PL_op_seqmax++;
break;
}
oldop = o;