X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=op.c;h=907e9755d7f1d340f91639739eef91af25ea7239;hb=2779dcf1a3ceec167d36a36fc44de44737edcc4c;hp=243b3c7cc378344973431dec8cd98875bfd06b17;hpb=199100c871a030cc44240072644abe9aab66bc02;p=p5sagit%2Fp5-mst-13.2.git diff --git a/op.c b/op.c index 243b3c7..907e975 100644 --- a/op.c +++ b/op.c @@ -40,10 +40,11 @@ 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)); +static OP *newDEFSVOP _((void)); +static OP *new_logop _((I32 type, I32 flags, OP **firstp, OP **otherp)); static char* -gv_ename(gv) -GV* gv; +gv_ename(GV *gv) { SV* tmpsv = sv_newmortal(); gv_efullname3(tmpsv, gv, Nullch); @@ -51,8 +52,7 @@ GV* gv; } static OP * -no_fh_allowed(o) -OP *o; +no_fh_allowed(OP *o) { yyerror(form("Missing comma after first argument to %s function", op_desc[o->op_type])); @@ -60,52 +60,50 @@ OP *o; } static OP * -too_few_arguments(o, name) -OP* o; -char* name; +too_few_arguments(OP *o, char *name) { yyerror(form("Not enough arguments for %s", name)); return o; } static OP * -too_many_arguments(o, name) -OP *o; -char* name; +too_many_arguments(OP *o, char *name) { yyerror(form("Too many arguments for %s", name)); return o; } static void -bad_type(n, t, name, kid) -I32 n; -char *t; -char *name; -OP *kid; +bad_type(I32 n, char *t, char *name, OP *kid) { yyerror(form("Type of arg %d to %s must be %s (not %s)", (int)n, name, t, op_desc[kid->op_type])); } void -assertref(o) -OP *o; +assertref(OP *o) { int type = o->op_type; if (type != OP_AELEM && type != OP_HELEM) { yyerror(form("Can't use subscript on %s", op_desc[type])); - if (type == OP_ENTERSUB || type == OP_RV2HV || type == OP_PADHV) - warn("(Did you mean $ or @ instead of %c?)\n", - type == OP_ENTERSUB ? '&' : '%'); + if (type == OP_ENTERSUB || type == OP_RV2HV || type == OP_PADHV) { + SV *msg = sv_2mortal( + newSVpvf("(Did you mean $ or @ instead of %c?)\n", + type == OP_ENTERSUB ? '&' : '%')); + if (in_eval & 2) + warn("%_", msg); + else if (in_eval) + sv_catsv(GvSV(errgv), msg); + else + PerlIO_write(PerlIO_stderr(), SvPVX(msg), SvCUR(msg)); + } } } /* "register" allocation */ PADOFFSET -pad_allocmy(name) -char *name; +pad_allocmy(char *name) { dTHR; PADOFFSET off; @@ -119,9 +117,9 @@ char *name; } croak("Can't use global %s in \"my\"",name); } - if (dowarn && AvFILL(comppad_name) >= 0) { + if (dowarn && AvFILLp(comppad_name) >= 0) { SV **svp = AvARRAY(comppad_name); - for (off = AvFILL(comppad_name); off > comppad_name_floor; off--) { + for (off = AvFILLp(comppad_name); off > comppad_name_floor; off--) { if ((sv = svp[off]) && sv != &sv_undef && SvIVX(sv) == 999999999 /* var is in open scope */ @@ -159,23 +157,14 @@ char *name; } static PADOFFSET -#ifndef CAN_PROTOTYPE -pad_findlex(name, newoff, seq, startcv, cx_ix) -char *name; -PADOFFSET newoff; -U32 seq; -CV* startcv; -I32 cx_ix; -#else pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix) -#endif { dTHR; CV *cv; I32 off; SV *sv; register I32 i; - register CONTEXT *cx; + register PERL_CONTEXT *cx; int saweval; for (cv = startcv; cv; cv = CvOUTSIDE(cv)) { @@ -187,7 +176,7 @@ pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix) continue; curname = (AV*)*svp; svp = AvARRAY(curname); - for (off = AvFILL(curname); off > 0; off--) { + for (off = AvFILLp(curname); off > 0; off--) { if ((sv = svp[off]) && sv != &sv_undef && seq <= SvIVX(sv) && @@ -295,8 +284,7 @@ pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix) } PADOFFSET -pad_findmy(name) -char *name; +pad_findmy(char *name) { dTHR; I32 off; @@ -319,7 +307,7 @@ char *name; #endif /* USE_THREADS */ /* The one we're looking for is probably just before comppad_name_fill. */ - for (off = AvFILL(comppad_name); off > 0; off--) { + for (off = AvFILLp(comppad_name); off > 0; off--) { if ((sv = svp[off]) && sv != &sv_undef && (!SvIVX(sv) || @@ -345,8 +333,7 @@ char *name; } void -pad_leavemy(fill) -I32 fill; +pad_leavemy(I32 fill) { I32 off; SV **svp = AvARRAY(comppad_name); @@ -358,16 +345,14 @@ I32 fill; } } /* "Deintroduce" my variables that are leaving with this scope. */ - for (off = AvFILL(comppad_name); off > fill; off--) { + for (off = AvFILLp(comppad_name); off > fill; off--) { if ((sv = svp[off]) && sv != &sv_undef && SvIVX(sv) == 999999999) SvIVX(sv) = cop_seqmax; } } PADOFFSET -pad_alloc(optype,tmptype) -I32 optype; -U32 tmptype; +pad_alloc(I32 optype, U32 tmptype) { dTHR; SV *sv; @@ -379,13 +364,13 @@ U32 tmptype; pad_reset(); if (tmptype & SVs_PADMY) { do { - sv = *av_fetch(comppad, AvFILL(comppad) + 1, TRUE); + sv = *av_fetch(comppad, AvFILLp(comppad) + 1, TRUE); } while (SvPADBUSY(sv)); /* need a fresh one */ - retval = AvFILL(comppad); + retval = AvFILLp(comppad); } else { SV **names = AvARRAY(comppad_name); - SSize_t names_fill = AvFILL(comppad_name); + SSize_t names_fill = AvFILLp(comppad_name); for (;;) { /* * "foreach" index vars temporarily become aliases to non-"my" @@ -408,19 +393,15 @@ U32 tmptype; (unsigned long) thr, (unsigned long) curpad, (long) retval, op_name[optype])); #else - DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad alloc %ld for %s\n", + DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%lx alloc %ld for %s\n", + (unsigned long) curpad, (long) retval, op_name[optype])); #endif /* USE_THREADS */ return (PADOFFSET)retval; } SV * -#ifndef CAN_PROTOTYPE -pad_sv(po) -PADOFFSET po; -#else pad_sv(PADOFFSET po) -#endif /* CAN_PROTOTYPE */ { dTHR; #ifdef USE_THREADS @@ -429,18 +410,14 @@ pad_sv(PADOFFSET po) #else if (!po) croak("panic: pad_sv po"); - DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad sv %d\n", po)); + DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%lx sv %d\n", + (unsigned long) curpad, po)); #endif /* USE_THREADS */ return curpad[po]; /* eventually we'll turn this into a macro */ } void -#ifndef CAN_PROTOTYPE -pad_free(po) -PADOFFSET po; -#else pad_free(PADOFFSET po) -#endif /* CAN_PROTOTYPE */ { dTHR; if (!curpad) @@ -453,7 +430,8 @@ pad_free(PADOFFSET po) DEBUG_X(PerlIO_printf(Perl_debug_log, "0x%lx Pad 0x%lx free %d\n", (unsigned long) thr, (unsigned long) curpad, po)); #else - DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad free %d\n", po)); + DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%lx free %d\n", + (unsigned long) curpad, po)); #endif /* USE_THREADS */ if (curpad[po] && curpad[po] != &sv_undef) SvPADTMP_off(curpad[po]); @@ -462,12 +440,7 @@ pad_free(PADOFFSET po) } void -#ifndef CAN_PROTOTYPE -pad_swipe(po) -PADOFFSET po; -#else pad_swipe(PADOFFSET po) -#endif /* CAN_PROTOTYPE */ { dTHR; if (AvARRAY(comppad) != curpad) @@ -478,7 +451,8 @@ pad_swipe(PADOFFSET po) DEBUG_X(PerlIO_printf(Perl_debug_log, "0x%lx Pad 0x%lx swipe %d\n", (unsigned long) thr, (unsigned long) curpad, po)); #else - DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad swipe %d\n", po)); + DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%lx swipe %d\n", + (unsigned long) curpad, po)); #endif /* USE_THREADS */ SvPADTMP_off(curpad[po]); curpad[po] = NEWSV(1107,0); @@ -487,9 +461,16 @@ pad_swipe(PADOFFSET po) padix = po - 1; } +/* XXX pad_reset() is currently disabled because it results in serious bugs. + * It causes pad temp TARGs to be shared between OPs. Since TARGs are pushed + * on the stack by OPs that use them, there are several ways to get an alias + * to a shared TARG. Such an alias will change randomly and unpredictably. + * We avoid doing this until we can think of a Better Way. + * GSAR 97-10-29 */ void -pad_reset() +pad_reset(void) { +#ifdef USE_BROKEN_PAD_RESET dTHR; register I32 po; @@ -499,7 +480,8 @@ pad_reset() DEBUG_X(PerlIO_printf(Perl_debug_log, "0x%lx Pad 0x%lx reset\n", (unsigned long) thr, (unsigned long) curpad)); #else - DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad reset\n")); + DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%lx reset\n", + (unsigned long) curpad)); #endif /* USE_THREADS */ if (!tainting) { /* Can't mix tainted and non-tainted temporaries. */ for (po = AvMAX(comppad); po > padix_floor; po--) { @@ -508,41 +490,52 @@ pad_reset() } padix = padix_floor; } +#endif pad_reset_pending = FALSE; } #ifdef USE_THREADS -/* find_thread_magical is not reentrant */ +/* find_threadsv is not reentrant */ PADOFFSET -find_thread_magical(name) -char *name; +find_threadsv(char *name) { dTHR; char *p; PADOFFSET key; SV **svp; - /* We currently only handle single character magicals */ - p = strchr(per_thread_magicals, *name); + /* We currently only handle names of a single character */ + p = strchr(threadsv_names, *name); if (!p) return NOT_IN_PAD; - key = p - per_thread_magicals; - svp = av_fetch(thr->magicals, key, FALSE); + key = p - threadsv_names; + svp = av_fetch(thr->threadsv, key, FALSE); if (!svp) { SV *sv = NEWSV(0, 0); - av_store(thr->magicals, key, sv); + av_store(thr->threadsv, key, sv); + thr->threadsvp = AvARRAY(thr->threadsv); /* * Some magic variables used to be automagically initialised * in gv_fetchpv. Those which are now per-thread magicals get * initialised here instead. */ switch (*name) { + case '_': + break; case ';': sv_setpv(sv, "\034"); + sv_magic(sv, 0, 0, name, 1); break; + case '&': + case '`': + case '\'': + sawampersand = TRUE; + SvREADONLY_on(sv); + /* FALL THROUGH */ + default: + sv_magic(sv, 0, 0, name, 1); } - sv_magic(sv, 0, 0, name, 1); DEBUG_L(PerlIO_printf(PerlIO_stderr(), - "find_thread_magical: new SV %p for $%s%c\n", + "find_threadsv: new SV %p for $%s%c\n", sv, (*name < 32) ? "^" : "", (*name < 32) ? toCTRL(*name) : *name)); } @@ -553,8 +546,7 @@ char *name; /* Destructor */ void -op_free(o) -OP *o; +op_free(OP *o) { register OP *kid, *nextkid; @@ -576,8 +568,8 @@ OP *o; o->op_targ = 0; /* Was holding hints. */ break; #ifdef USE_THREADS - case OP_SPECIFIC: - o->op_targ = 0; /* Was holding index into thr->magicals AV. */ + case OP_THREADSV: + o->op_targ = 0; /* Was holding index into thr->threadsv AV. */ break; #endif /* USE_THREADS */ default: @@ -612,8 +604,7 @@ OP *o; /* FALL THROUGH */ case OP_PUSHRE: case OP_MATCH: - pregfree(cPMOPo->op_pmregexp); - SvREFCNT_dec(cPMOPo->op_pmshort); + ReREFCNT_dec(cPMOPo->op_pmregexp); break; } @@ -624,10 +615,9 @@ OP *o; } static void -null(o) -OP* o; +null(OP *o) { - if (o->op_type != OP_NULL && o->op_targ > 0) + if (o->op_type != OP_NULL && o->op_type != OP_THREADSV && o->op_targ > 0) pad_free(o->op_targ); o->op_targ = o->op_type; o->op_type = OP_NULL; @@ -639,8 +629,7 @@ OP* o; #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o)) OP * -linklist(o) -OP *o; +linklist(OP *o) { register OP *kid; @@ -664,8 +653,7 @@ OP *o; } OP * -scalarkids(o) -OP *o; +scalarkids(OP *o) { OP *kid; if (o && o->op_flags & OPf_KIDS) { @@ -676,8 +664,7 @@ OP *o; } static OP * -scalarboolean(o) -OP *o; +scalarboolean(OP *o) { if (dowarn && o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST) { @@ -693,8 +680,7 @@ OP *o; } OP * -scalar(o) -OP *o; +scalar(OP *o) { OP *kid; @@ -760,8 +746,7 @@ OP *o; } OP * -scalarvoid(o) -OP *o; +scalarvoid(OP *o) { OP *kid; char* useless = 0; @@ -944,8 +929,7 @@ OP *o; } OP * -listkids(o) -OP *o; +listkids(OP *o) { OP *kid; if (o && o->op_flags & OPf_KIDS) { @@ -956,8 +940,7 @@ OP *o; } OP * -list(o) -OP *o; +list(OP *o) { OP *kid; @@ -1023,8 +1006,7 @@ OP *o; } OP * -scalarseq(o) -OP *o; +scalarseq(OP *o) { OP *kid; @@ -1052,9 +1034,7 @@ OP *o; } static OP * -modkids(o, type) -OP *o; -I32 type; +modkids(OP *o, I32 type) { OP *kid; if (o && o->op_flags & OPf_KIDS) { @@ -1067,9 +1047,7 @@ I32 type; static I32 modcount; OP * -mod(o, type) -OP *o; -I32 type; +mod(OP *o, I32 type) { dTHR; OP *kid; @@ -1178,10 +1156,11 @@ I32 type; case OP_RV2SV: if (!type && cUNOPo->op_first->op_type != OP_GV) croak("Can't localize through a reference"); - ref(cUNOPo->op_first, o->op_type); + ref(cUNOPo->op_first, o->op_type); /* FALL THROUGH */ case OP_GV: case OP_AV2ARYLEN: + hints |= HINT_BLOCK_SCOPE; case OP_SASSIGN: case OP_AELEMFAST: modcount++; @@ -1203,12 +1182,8 @@ I32 type; break; #ifdef USE_THREADS - case OP_SPECIFIC: + case OP_THREADSV: modcount++; /* XXX ??? */ -#if 0 - if (!type) - croak("Can't localize thread-specific variable"); -#endif break; #endif /* USE_THREADS */ @@ -1272,9 +1247,7 @@ I32 type; } static bool -scalar_mod_type(o, type) -OP *o; -I32 type; +scalar_mod_type(OP *o, I32 type) { switch (type) { case OP_SASSIGN: @@ -1318,9 +1291,7 @@ I32 type; } OP * -refkids(o, type) -OP *o; -I32 type; +refkids(OP *o, I32 type) { OP *kid; if (o && o->op_flags & OPf_KIDS) { @@ -1331,9 +1302,7 @@ I32 type; } OP * -ref(o, type) -OP *o; -I32 type; +ref(OP *o, I32 type) { OP *kid; @@ -1351,7 +1320,7 @@ I32 type; o->op_flags |= OPf_SPECIAL; } break; - + case OP_COND_EXPR: for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling) ref(kid, type); @@ -1368,13 +1337,13 @@ I32 type; } break; - case OP_SPECIFIC: + case OP_THREADSV: o->op_flags |= OPf_MOD; /* XXX ??? */ break; case OP_RV2AV: case OP_RV2HV: - o->op_flags |= OPf_REF; + o->op_flags |= OPf_REF; /* FALL THROUGH */ case OP_RV2GV: ref(cUNOPo->op_first, o->op_type); @@ -1382,9 +1351,9 @@ I32 type; case OP_PADAV: case OP_PADHV: - o->op_flags |= OPf_REF; + o->op_flags |= OPf_REF; break; - + case OP_SCALAR: case OP_NULL: if (!(o->op_flags & OPf_KIDS)) @@ -1418,8 +1387,7 @@ I32 type; } OP * -my(o) -OP *o; +my(OP *o) { OP *kid; I32 type; @@ -1431,8 +1399,9 @@ OP *o; if (type == OP_LIST) { for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) my(kid); - } - else if (type != OP_PADSV && + } else if (type == OP_UNDEF) { + return o; + } else if (type != OP_PADSV && type != OP_PADAV && type != OP_PADHV && type != OP_PUSHMARK) @@ -1446,8 +1415,7 @@ OP *o; } OP * -sawparens(o) -OP *o; +sawparens(OP *o) { if (o) o->op_flags |= OPf_PARENS; @@ -1455,10 +1423,7 @@ OP *o; } OP * -bind_match(type, left, right) -I32 type; -OP *left; -OP *right; +bind_match(I32 type, OP *left, OP *right) { OP *o; @@ -1496,8 +1461,7 @@ OP *right; } OP * -invert(o) -OP *o; +invert(OP *o) { if (!o) return o; @@ -1506,8 +1470,7 @@ OP *o; } OP * -scope(o) -OP *o; +scope(OP *o) { if (o) { if (o->op_flags & OPf_PARENS || PERLDB_NOOPT || tainting) { @@ -1534,14 +1497,13 @@ OP *o; } int -block_start(full) -int full; +block_start(int full) { dTHR; int retval = savestack_ix; SAVEI32(comppad_name_floor); if (full) { - if ((comppad_name_fill = AvFILL(comppad_name)) > 0) + if ((comppad_name_fill = AvFILLp(comppad_name)) > 0) comppad_name_floor = comppad_name_fill; else comppad_name_floor = 0; @@ -1559,9 +1521,7 @@ int full; } OP* -block_end(floor, seq) -I32 floor; -OP* seq; +block_end(I32 floor, OP *seq) { dTHR; int needblockscope = hints & HINT_BLOCK_SCOPE; @@ -1575,9 +1535,20 @@ OP* seq; return retval; } +static OP * +newDEFSVOP(void) +{ +#ifdef USE_THREADS + OP *o = newOP(OP_THREADSV, 0); + o->op_targ = find_threadsv("_"); + return o; +#else + return newSVREF(newGVOP(OP_GV, 0, defgv)); +#endif /* USE_THREADS */ +} + void -newPROG(o) -OP *o; +newPROG(OP *o) { dTHR; if (in_eval) { @@ -1611,14 +1582,11 @@ OP *o; } OP * -localize(o, lex) -OP *o; -I32 lex; +localize(OP *o, I32 lex) { if (o->op_flags & OPf_PARENS) list(o); else { - scalar(o); if (dowarn && bufptr > oldbufptr && bufptr[-1] == ',') { char *s; for (s = bufptr; *s && (isALNUM(*s) || strchr("@$%, ",*s)); s++) ; @@ -1635,14 +1603,13 @@ I32 lex; } OP * -jmaybe(o) -OP *o; +jmaybe(OP *o) { if (o->op_type == OP_LIST) { OP *o2; #ifdef USE_THREADS - o2 = newOP(OP_SPECIFIC, 0); - o2->op_targ = find_thread_magical(";"); + o2 = newOP(OP_THREADSV, 0); + o2->op_targ = find_threadsv(";"); #else o2 = newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))), #endif /* USE_THREADS */ @@ -1652,8 +1619,7 @@ OP *o; } OP * -fold_constants(o) -register OP *o; +fold_constants(register OP *o) { dTHR; register OP *curop; @@ -1677,6 +1643,12 @@ register OP *o; case OP_LCFIRST: case OP_UC: case OP_LC: + case OP_SLT: + case OP_SGT: + case OP_SLE: + case OP_SGE: + case OP_SCMP: + if (o->op_private & OPpLOCALE) goto nope; } @@ -1720,7 +1692,7 @@ register OP *o; } return newSVOP(OP_CONST, 0, sv); } - + nope: if (!(opargs[type] & OA_OTHERINT)) return o; @@ -1746,8 +1718,7 @@ register OP *o; } OP * -gen_constant_list(o) -register OP *o; +gen_constant_list(register OP *o) { dTHR; register OP *curop; @@ -1775,10 +1746,7 @@ register OP *o; } OP * -convert(type, flags, o) -I32 type; -I32 flags; -OP* o; +convert(I32 type, I32 flags, OP *o) { OP *kid; OP *last = 0; @@ -1812,10 +1780,7 @@ OP* o; /* List constructors */ OP * -append_elem(type, first, last) -I32 type; -OP* first; -OP* last; +append_elem(I32 type, OP *first, OP *last) { if (!first) return last; @@ -1838,10 +1803,7 @@ OP* last; } OP * -append_list(type, first, last) -I32 type; -LISTOP* first; -LISTOP* last; +append_list(I32 type, LISTOP *first, LISTOP *last) { if (!first) return (OP*)last; @@ -1866,10 +1828,7 @@ LISTOP* last; } OP * -prepend_elem(type, first, last) -I32 type; -OP* first; -OP* last; +prepend_elem(I32 type, OP *first, OP *last) { if (!first) return last; @@ -1900,14 +1859,13 @@ OP* last; /* Constructors */ OP * -newNULLLIST() +newNULLLIST(void) { return newOP(OP_STUB, 0); } OP * -force_list(o) -OP *o; +force_list(OP *o) { if (!o || o->op_type != OP_LIST) o = newLISTOP(OP_LIST, 0, o, Nullop); @@ -1916,11 +1874,7 @@ OP *o; } OP * -newLISTOP(type, flags, first, last) -I32 type; -I32 flags; -OP* first; -OP* last; +newLISTOP(I32 type, I32 flags, OP *first, OP *last) { LISTOP *listop; @@ -1955,9 +1909,7 @@ OP* last; } OP * -newOP(type, flags) -I32 type; -I32 flags; +newOP(I32 type, I32 flags) { OP *o; Newz(1101, o, 1, OP); @@ -1975,15 +1927,12 @@ I32 flags; } OP * -newUNOP(type, flags, first) -I32 type; -I32 flags; -OP* first; +newUNOP(I32 type, I32 flags, OP *first) { UNOP *unop; if (!first) - first = newOP(OP_STUB, 0); + first = newOP(OP_STUB, 0); if (opargs[type] & OA_MARK) first = force_list(first); @@ -1993,7 +1942,12 @@ 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; @@ -2002,11 +1956,7 @@ OP* first; } OP * -newBINOP(type, flags, first, last) -I32 type; -I32 flags; -OP* first; -OP* last; +newBINOP(I32 type, I32 flags, OP *first, OP *last) { BINOP *binop; Newz(1101, binop, 1, BINOP); @@ -2037,10 +1987,7 @@ OP* last; } OP * -pmtrans(o, expr, repl) -OP *o; -OP *expr; -OP *repl; +pmtrans(OP *o, OP *expr, OP *repl) { SV *tstr = ((SVOP*)expr)->op_sv; SV *rstr = ((SVOP*)repl)->op_sv; @@ -2050,14 +1997,15 @@ OP *repl; register U8 *r = (U8*)SvPV(rstr, rlen); register I32 i; register I32 j; - I32 delete; + I32 Delete; I32 complement; + I32 squash; register short *tbl; tbl = (short*)cPVOPo->op_pv; complement = o->op_private & OPpTRANS_COMPLEMENT; - delete = o->op_private & OPpTRANS_DELETE; - /* squash = o->op_private & OPpTRANS_SQUASH; */ + Delete = o->op_private & OPpTRANS_DELETE; + squash = o->op_private & OPpTRANS_SQUASH; if (complement) { Zero(tbl, 256, short); @@ -2066,7 +2014,7 @@ OP *repl; for (i = 0, j = 0; i < 256; i++) { if (!tbl[i]) { if (j >= rlen) { - if (delete) + if (Delete) tbl[i] = -2; else if (rlen) tbl[i] = r[j-1]; @@ -2079,14 +2027,16 @@ OP *repl; } } else { - if (!rlen && !delete) { + if (!rlen && !Delete) { r = t; rlen = tlen; + if (!squash) + o->op_private |= OPpTRANS_COUNTONLY; } for (i = 0; i < 256; i++) tbl[i] = -1; for (i = 0, j = 0; i < tlen; i++,j++) { if (j >= rlen) { - if (delete) { + if (Delete) { if (tbl[t[i]] == -1) tbl[t[i]] = -2; continue; @@ -2104,9 +2054,7 @@ OP *repl; } OP * -newPMOP(type, flags) -I32 type; -I32 flags; +newPMOP(I32 type, I32 flags) { dTHR; PMOP *pmop; @@ -2130,10 +2078,7 @@ I32 flags; } OP * -pmruntime(o, expr, repl) -OP *o; -OP *expr; -OP *repl; +pmruntime(OP *o, OP *expr, OP *repl) { PMOP *pm; LOGOP *rcop; @@ -2154,9 +2099,8 @@ OP *repl; pm->op_pmflags |= PMf_SKIPWHITE; } pm->op_pmregexp = pregcomp(p, p + plen, pm); - if (strEQ("\\s+", pm->op_pmregexp->precomp)) + if (strEQ("\\s+", pm->op_pmregexp->precomp)) pm->op_pmflags |= PMf_WHITE; - hoistmust(pm); op_free(expr); } else { @@ -2190,9 +2134,9 @@ OP *repl; if (pm->op_pmflags & PMf_EVAL) curop = 0; #ifdef USE_THREADS - else if (repl->op_type == OP_SPECIFIC + else if (repl->op_type == OP_THREADSV && strchr("&`'123456789+", - per_thread_magicals[repl->op_targ])) + threadsv_names[repl->op_targ])) { curop = 0; } @@ -2204,7 +2148,7 @@ OP *repl; for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) { if (opargs[curop->op_type] & OA_DANGEROUS) { #ifdef USE_THREADS - if (curop->op_type == OP_SPECIFIC + if (curop->op_type == OP_THREADSV && strchr("&`'123456789+", curop->op_private)) { break; } @@ -2264,10 +2208,7 @@ OP *repl; } OP * -newSVOP(type, flags, sv) -I32 type; -I32 flags; -SV *sv; +newSVOP(I32 type, I32 flags, SV *sv) { SVOP *svop; Newz(1101, svop, 1, SVOP); @@ -2284,10 +2225,7 @@ SV *sv; } OP * -newGVOP(type, flags, gv) -I32 type; -I32 flags; -GV *gv; +newGVOP(I32 type, I32 flags, GV *gv) { dTHR; GVOP *gvop; @@ -2305,10 +2243,7 @@ GV *gv; } OP * -newPVOP(type, flags, pv) -I32 type; -I32 flags; -char *pv; +newPVOP(I32 type, I32 flags, char *pv) { PVOP *pvop; Newz(1101, pvop, 1, PVOP); @@ -2325,8 +2260,7 @@ char *pv; } void -package(o) -OP *o; +package(OP *o) { dTHR; SV *sv; @@ -2351,12 +2285,7 @@ OP *o; } void -utilize(aver, floor, version, id, arg) -int aver; -I32 floor; -OP *version; -OP *id; -OP *arg; +utilize(int aver, I32 floor, OP *version, OP *id, OP *arg) { OP *pack; OP *meth; @@ -2393,7 +2322,7 @@ OP *arg; newUNOP(OP_METHOD, 0, meth))); } } - + /* Fake up an import/unimport */ if (arg && arg->op_type == OP_STUB) imop = arg; /* no import on explicit () */ @@ -2432,10 +2361,7 @@ OP *arg; } OP * -newSLICEOP(flags, subscript, listval) -I32 flags; -OP *subscript; -OP *listval; +newSLICEOP(I32 flags, OP *subscript, OP *listval) { return newBINOP(OP_LSLICE, flags, list(force_list(subscript)), @@ -2443,8 +2369,7 @@ OP *listval; } static I32 -list_assignment(o) -register OP *o; +list_assignment(register OP *o) { if (!o) return TRUE; @@ -2478,11 +2403,7 @@ register OP *o; } OP * -newASSIGNOP(flags, left, optype, right) -I32 flags; -OP *left; -I32 optype; -OP *right; +newASSIGNOP(I32 flags, OP *left, I32 optype, OP *right) { OP *o; @@ -2611,10 +2532,7 @@ OP *right; } OP * -newSTATEOP(flags, label, o) -I32 flags; -char *label; -OP *o; +newSTATEOP(I32 flags, char *label, OP *o) { dTHR; U32 seq = intro_my(); @@ -2666,7 +2584,7 @@ OP *o; /* "Introduce" my variables to visible status. */ U32 -intro_my() +intro_my(void) { SV **svp; SV *sv; @@ -2688,15 +2606,19 @@ intro_my() } OP * -newLOGOP(type, flags, first, other) -I32 type; -I32 flags; -OP* first; -OP* other; +newLOGOP(I32 type, I32 flags, OP *first, OP *other) +{ + return new_logop(type, flags, &first, &other); +} + +static OP * +new_logop(I32 type, I32 flags, OP** firstp, OP** otherp) { dTHR; LOGOP *logop; OP *o; + OP *first = *firstp; + OP *other = *otherp; if (type == OP_XOR) /* Not short circuit, but here by precedence. */ return newBINOP(type, flags, scalar(first), scalar(other)); @@ -2710,7 +2632,7 @@ OP* other; else type = OP_AND; o = first; - first = cUNOPo->op_first; + first = *firstp = cUNOPo->op_first; if (o->op_next) first->op_next = o->op_next; cUNOPo->op_first = Nullop; @@ -2722,10 +2644,12 @@ OP* other; warn("Probable precedence problem on %s", op_desc[type]); if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) { op_free(first); + *firstp = Nullop; return other; } else { op_free(other); + *otherp = Nullop; return first; } } @@ -2793,11 +2717,7 @@ OP* other; } OP * -newCONDOP(flags, first, trueop, falseop) -I32 flags; -OP* first; -OP* trueop; -OP* falseop; +newCONDOP(I32 flags, OP *first, OP *trueop, OP *falseop) { dTHR; CONDOP *condop; @@ -2850,10 +2770,7 @@ OP* falseop; } OP * -newRANGE(flags, left, right) -I32 flags; -OP *left; -OP *right; +newRANGE(I32 flags, OP *left, OP *right) { dTHR; CONDOP *condop; @@ -2898,11 +2815,7 @@ OP *right; } OP * -newLOOPOP(flags, debuggable, expr, block) -I32 flags; -I32 debuggable; -OP *expr; -OP *block; +newLOOPOP(I32 flags, I32 debuggable, OP *expr, OP *block) { dTHR; OP* listop; @@ -2916,14 +2829,15 @@ OP *block; if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB)) { expr = newUNOP(OP_DEFINED, 0, - newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr) ); + newASSIGNOP(0, newDEFSVOP(), 0, expr) ); } } listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0)); - o = newLOGOP(OP_AND, 0, expr, listop); + o = new_logop(OP_AND, 0, &expr, &listop); - ((LISTOP*)listop)->op_last->op_next = LINKLIST(o); + if (listop) + ((LISTOP*)listop)->op_last->op_next = LINKLIST(o); if (once && o != listop) o->op_next = ((LOGOP*)cUNOPo->op_first)->op_other; @@ -2938,14 +2852,7 @@ OP *block; } OP * -newWHILEOP(flags, debuggable, loop, whileline, expr, block, cont) -I32 flags; -I32 debuggable; -LOOP *loop; -I32 whileline; -OP *expr; -OP *block; -OP *cont; +newWHILEOP(I32 flags, I32 debuggable, LOOP *loop, I32 whileline, OP *expr, OP *block, OP *cont) { dTHR; OP *redo; @@ -2957,7 +2864,7 @@ OP *cont; if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB))) { expr = newUNOP(OP_DEFINED, 0, - newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr) ); + newASSIGNOP(0, newDEFSVOP(), 0, expr) ); } if (!block) @@ -2978,14 +2885,17 @@ OP *cont; redo = LINKLIST(listop); if (expr) { - o = newLOGOP(OP_AND, 0, expr, scalar(listop)); + copline = whileline; + scalar(listop); + o = new_logop(OP_AND, 0, &expr, &listop); if (o == expr && o->op_type == OP_CONST && !SvTRUE(cSVOPo->op_sv)) { op_free(expr); /* oops, it's a while (0) */ op_free((OP*)loop); - return Nullop; /* (listop already freed by newLOGOP) */ + return Nullop; /* listop already freed by new_logop */ } - ((LISTOP*)listop)->op_last->op_next = condop = - (o == listop ? redo : LINKLIST(o)); + if (listop) + ((LISTOP*)listop)->op_last->op_next = condop = + (o == listop ? redo : LINKLIST(o)); if (!next) next = condop; } @@ -3016,18 +2926,7 @@ OP *cont; } OP * -#ifndef CAN_PROTOTYPE -newFOROP(flags,label,forline,sv,expr,block,cont) -I32 flags; -char *label; -line_t forline; -OP* sv; -OP* expr; -OP*block; -OP*cont; -#else newFOROP(I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont) -#endif /* CAN_PROTOTYPE */ { LOOP *loop; OP *wop; @@ -3044,11 +2943,22 @@ newFOROP(I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont op_free(sv); sv = Nullop; } + else if (sv->op_type == OP_THREADSV) { /* per-thread variable */ + padoff = sv->op_targ; + iterflags |= OPf_SPECIAL; + op_free(sv); + sv = Nullop; + } else croak("Can't use %s for loop variable", op_desc[sv->op_type]); } else { +#ifdef USE_THREADS + padoff = find_threadsv("_"); + iterflags |= OPf_SPECIAL; +#else sv = newGVOP(OP_GV, 0, defgv); +#endif } if (expr->op_type == OP_RV2AV || expr->op_type == OP_PADAV) { expr = scalar(ref(expr, OP_ITER)); @@ -3066,17 +2976,19 @@ newFOROP(I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont } OP* -newLOOPEX(type, label) -I32 type; -OP* label; +newLOOPEX(I32 type, OP *label) { dTHR; OP *o; if (type != OP_GOTO || label->op_type == OP_CONST) { - o = newPVOP(type, 0, savepv( - label->op_type == OP_CONST - ? SvPVx(((SVOP*)label)->op_sv, na) - : "" )); + /* "last()" means "last" */ + if (label->op_type == OP_STUB && (label->op_flags & OPf_PARENS)) + o = newOP(type, OPf_SPECIAL); + else { + o = newPVOP(type, 0, savepv(label->op_type == OP_CONST + ? SvPVx(((SVOP*)label)->op_sv, na) + : "")); + } op_free(label); } else { @@ -3089,8 +3001,7 @@ OP* label; } void -cv_undef(cv) -CV *cv; +cv_undef(CV *cv) { dTHR; #ifdef USE_THREADS @@ -3128,7 +3039,7 @@ CV *cv; if (CvPADLIST(cv)) { /* may be during global destruction */ if (SvREFCNT(CvPADLIST(cv))) { - I32 i = AvFILL(CvPADLIST(cv)); + I32 i = AvFILLp(CvPADLIST(cv)); while (i >= 0) { SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE); SV* sv = svp ? *svp : Nullsv; @@ -3182,7 +3093,7 @@ CV* cv; pname = AvARRAY(pad_name); ppad = AvARRAY(pad); - for (ix = 1; ix <= AvFILL(pad_name); ix++) { + for (ix = 1; ix <= AvFILLp(pad_name); ix++) { if (SvPOK(pname[ix])) PerlIO_printf(Perl_debug_log, "\t%4d. 0x%lx (%s\"%s\" %ld-%ld)\n", ix, ppad[ix], @@ -3195,9 +3106,7 @@ CV* cv; #endif /* DEBUG_CLOSURES */ static CV * -cv_clone2(proto, outside) -CV* proto; -CV* outside; +cv_clone2(CV *proto, CV *outside) { dTHR; AV* av; @@ -3207,8 +3116,8 @@ CV* outside; AV* protopad = (AV*)*av_fetch(protopadlist, 1, FALSE); SV** pname = AvARRAY(protopad_name); SV** ppad = AvARRAY(protopad); - I32 fname = AvFILL(protopad_name); - I32 fpad = AvFILL(protopad); + I32 fname = AvFILLp(protopad_name); + I32 fpad = AvFILLp(protopad); AV* comppadlist; CV* cv; @@ -3253,7 +3162,7 @@ CV* outside; av_store(comppadlist, 0, (SV*)comppad_name); av_store(comppadlist, 1, (SV*)comppad); CvPADLIST(cv) = comppadlist; - av_fill(comppad, AvFILL(protopad)); + av_fill(comppad, AvFILLp(protopad)); curpad = AvARRAY(comppad); av = newAV(); /* will be @_ */ @@ -3329,17 +3238,13 @@ CV* outside; } CV * -cv_clone(proto) -CV* proto; +cv_clone(CV *proto) { return cv_clone2(proto, CvOUTSIDE(proto)); } void -cv_ckproto(cv, gv, p) -CV* cv; -GV* gv; -char* p; +cv_ckproto(CV *cv, GV *gv, char *p) { if ((!p != !SvPOK(cv)) || (p && strNE(p, SvPVX(cv)))) { SV* msg = sv_newmortal(); @@ -3362,12 +3267,11 @@ char* p; } SV * -cv_const_sv(cv) -CV* cv; +cv_const_sv(CV *cv) { OP *o; SV *sv; - + if (!cv || !SvPOK(cv) || SvCUR(cv)) return Nullsv; @@ -3398,11 +3302,7 @@ CV* cv; } CV * -newSUB(floor,o,proto,block) -I32 floor; -OP *o; -OP *proto; -OP *block; +newSUB(I32 floor, OP *o, OP *proto, OP *block) { dTHR; char *name = o ? SvPVx(cSVOPo->op_sv, na) : Nullch; @@ -3432,7 +3332,10 @@ OP *block; if (curstack == sortstack && sortcop == CvSTART(cv)) croak("Can't redefine active sort subroutine %s", name); const_sv = cv_const_sv(cv); - if (const_sv || dowarn) { + if (const_sv || dowarn && !(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" @@ -3487,8 +3390,8 @@ OP *block; croak(not_safe); else { /* force display of errors found but not reported */ - sv_catpv(errsv, not_safe); - croak("%s", SvPV(errsv, na)); + sv_catpv(ERRSV, not_safe); + croak("%s", SvPVx(ERRSV, na)); } } } @@ -3499,12 +3402,12 @@ OP *block; return cv; } - if (AvFILL(comppad_name) < AvFILL(comppad)) - av_store(comppad_name, AvFILL(comppad), Nullsv); + if (AvFILLp(comppad_name) < AvFILLp(comppad)) + av_store(comppad_name, AvFILLp(comppad), Nullsv); if (CvCLONE(cv)) { SV **namep = AvARRAY(comppad_name); - for (ix = AvFILL(comppad); ix > 0; ix--) { + for (ix = AvFILLp(comppad); ix > 0; ix--) { SV *namesv; if (SvIMMORTAL(curpad[ix])) @@ -3530,7 +3433,7 @@ OP *block; av_store(comppad, 0, (SV*)av); AvFLAGS(av) = AVf_REIFY; - for (ix = AvFILL(comppad); ix > 0; ix--) { + for (ix = AvFILLp(comppad); ix > 0; ix--) { if (SvIMMORTAL(curpad[ix])) continue; if (!SvPADMY(curpad[ix])) @@ -3549,7 +3452,7 @@ OP *block; if (PERLDB_SUBLINE && curstash != debstash) { SV *sv = NEWSV(0,0); SV *tmpstr = sv_newmortal(); - static GV *db_postponed; + GV *db_postponed = gv_fetchpv("DB::postponed", GV_ADDMULTI, SVt_PVHV); CV *cv; HV *hv; @@ -3558,9 +3461,6 @@ OP *block; (long)subline, (long)curcop->cop_line); gv_efullname3(tmpstr, gv, Nullch); hv_store(GvHV(DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0); - if (!db_postponed) { - db_postponed = gv_fetchpv("DB::postponed", GV_ADDMULTI, SVt_PVHV); - } hv = GvHVn(db_postponed); if (HvFILL(hv) > 0 && hv_exists(hv, SvPVX(tmpstr), SvCUR(tmpstr)) && (cv = GvCV(db_postponed))) { @@ -3615,26 +3515,8 @@ OP *block; return cv; } -#ifdef DEPRECATED -CV * -newXSUB(name, ix, subaddr, filename) -char *name; -I32 ix; -I32 (*subaddr)(); -char *filename; -{ - CV* cv = newXS(name, (void(*)())subaddr, filename); - CvOLDSTYLE_on(cv); - CvXSUBANY(cv).any_i32 = ix; - return cv; -} -#endif - CV * -newXS(name, subaddr, filename) -char *name; -void (*subaddr) _((CV*)); -char *filename; +newXS(char *name, void (*subaddr) (CV *), char *filename) { dTHR; GV *gv = gv_fetchpv(name ? name : "__ANON__", GV_ADDMULTI, SVt_PVCV); @@ -3648,7 +3530,9 @@ char *filename; } else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) { /* already defined (or promised) */ - if (dowarn) { + if (dowarn && !(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); @@ -3711,10 +3595,7 @@ char *filename; } void -newFORM(floor,o,block) -I32 floor; -OP *o; -OP *block; +newFORM(I32 floor, OP *o, OP *block) { dTHR; register CV *cv; @@ -3743,7 +3624,7 @@ OP *block; CvGV(cv) = (GV*)SvREFCNT_inc(gv); CvFILEGV(cv) = curcop->cop_filegv; - for (ix = AvFILL(comppad); ix > 0; ix--) { + for (ix = AvFILLp(comppad); ix > 0; ix--) { if (!SvPADMY(curpad[ix]) && !SvIMMORTAL(curpad[ix])) SvPADTMP_on(curpad[ix]); } @@ -3758,34 +3639,28 @@ OP *block; } OP * -newANONLIST(o) -OP* o; +newANONLIST(OP *o) { return newUNOP(OP_REFGEN, 0, mod(list(convert(OP_ANONLIST, 0, o)), OP_REFGEN)); } OP * -newANONHASH(o) -OP* o; +newANONHASH(OP *o) { return newUNOP(OP_REFGEN, 0, mod(list(convert(OP_ANONHASH, 0, o)), OP_REFGEN)); } OP * -newANONSUB(floor, proto, block) -I32 floor; -OP *proto; -OP *block; +newANONSUB(I32 floor, OP *proto, OP *block) { return newUNOP(OP_REFGEN, 0, newSVOP(OP_ANONCODE, 0, (SV*)newSUB(floor, 0, proto, block))); } OP * -oopsAV(o) -OP *o; +oopsAV(OP *o) { switch (o->op_type) { case OP_PADSV: @@ -3807,8 +3682,7 @@ OP *o; } OP * -oopsHV(o) -OP *o; +oopsHV(OP *o) { switch (o->op_type) { case OP_PADSV: @@ -3832,8 +3706,7 @@ OP *o; } OP * -newAVREF(o) -OP *o; +newAVREF(OP *o) { if (o->op_type == OP_PADANY) { o->op_type = OP_PADAV; @@ -3844,9 +3717,7 @@ OP *o; } OP * -newGVREF(type,o) -I32 type; -OP *o; +newGVREF(I32 type, OP *o) { if (type == OP_MAPSTART) return newUNOP(OP_NULL, 0, o); @@ -3854,8 +3725,7 @@ OP *o; } OP * -newHVREF(o) -OP *o; +newHVREF(OP *o) { if (o->op_type == OP_PADANY) { o->op_type = OP_PADHV; @@ -3866,8 +3736,7 @@ OP *o; } OP * -oopsCV(o) -OP *o; +oopsCV(OP *o) { croak("NOT IMPL LINE %d",__LINE__); /* STUB */ @@ -3875,32 +3744,30 @@ OP *o; } OP * -newCVREF(flags, o) -I32 flags; -OP *o; +newCVREF(I32 flags, OP *o) { return newUNOP(OP_RV2CV, flags, scalar(o)); } OP * -newSVREF(o) -OP *o; +newSVREF(OP *o) { if (o->op_type == OP_PADANY) { o->op_type = OP_PADSV; o->op_ppaddr = ppaddr[OP_PADSV]; return o; } - else if (o->op_type == OP_SPECIFIC) + else if (o->op_type == OP_THREADSV && !(o->op_flags & OPpDONE_SVREF)) { + o->op_flags |= OPpDONE_SVREF; return o; + } return newUNOP(OP_RV2SV, 0, scalar(o)); } /* Check routines. */ OP * -ck_anoncode(o) -OP *o; +ck_anoncode(OP *o) { PADOFFSET ix; SV* name; @@ -3920,16 +3787,14 @@ OP *o; } OP * -ck_bitop(o) -OP *o; +ck_bitop(OP *o) { o->op_private = hints; return o; } OP * -ck_concat(o) -OP *o; +ck_concat(OP *o) { if (cUNOPo->op_first->op_type == OP_CONCAT) o->op_flags |= OPf_STACKED; @@ -3937,8 +3802,7 @@ OP *o; } OP * -ck_spair(o) -OP *o; +ck_spair(OP *o) { if (o->op_flags & OPf_KIDS) { OP* newop; @@ -3952,7 +3816,7 @@ OP *o; !(opargs[newop->op_type] & OA_RETSCALAR) || newop->op_type == OP_PADAV || newop->op_type == OP_PADHV || newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) { - + return o; } op_free(kUNOP->op_first); @@ -3963,8 +3827,7 @@ OP *o; } OP * -ck_delete(o) -OP *o; +ck_delete(OP *o) { o = ck_fun(o); o->op_private = 0; @@ -3981,8 +3844,7 @@ OP *o; } OP * -ck_eof(o) -OP *o; +ck_eof(OP *o) { I32 type = o->op_type; @@ -3998,8 +3860,7 @@ OP *o; } OP * -ck_eval(o) -OP *o; +ck_eval(OP *o) { hints |= HINT_BLOCK_SCOPE; if (o->op_flags & OPf_KIDS) { @@ -4030,18 +3891,19 @@ OP *o; enter->op_other = o; return o; } + else + scalar((OP*)kid); } else { op_free(o); - o = newUNOP(OP_ENTEREVAL, 0, newSVREF(newGVOP(OP_GV, 0, defgv))); + o = newUNOP(OP_ENTEREVAL, 0, newDEFSVOP()); } o->op_targ = (PADOFFSET)hints; return o; } OP * -ck_exec(o) -OP *o; +ck_exec(OP *o) { OP *kid; if (o->op_flags & OPf_STACKED) { @@ -4056,8 +3918,7 @@ OP *o; } OP * -ck_exists(o) -OP *o; +ck_exists(OP *o) { o = ck_fun(o); if (o->op_flags & OPf_KIDS) { @@ -4070,8 +3931,7 @@ OP *o; } OP * -ck_gvconst(o) -register OP *o; +ck_gvconst(register OP *o) { o = fold_constants(o); if (o->op_type == OP_CONST) @@ -4080,8 +3940,7 @@ register OP *o; } OP * -ck_rvconst(o) -register OP *o; +ck_rvconst(register OP *o) { dTHR; SVOP *kid = (SVOP*)cUNOPo->op_first; @@ -4111,17 +3970,16 @@ register OP *o; "Can't use bareword (\"%s\") as %s ref while \"strict refs\" in use", name, badthing); } - kid->op_type = OP_GV; + /* + * This is a little tricky. We only want to add the symbol if we + * didn't add it in the lexer. Otherwise we get duplicate strict + * warnings. But if we didn't add it in the lexer, we must at + * least pretend like we wanted to add it even if it existed before, + * or we get possible typo warnings. OPpCONST_ENTERED says + * whether the lexer already added THIS instance of this symbol. + */ iscv = (o->op_type == OP_RV2CV) * 2; - for (gv = 0; !gv; iscv++) { - /* - * This is a little tricky. We only want to add the symbol if we - * didn't add it in the lexer. Otherwise we get duplicate strict - * warnings. But if we didn't add it in the lexer, we must at - * least pretend like we wanted to add it even if it existed before, - * or we get possible typo warnings. OPpCONST_ENTERED says - * whether the lexer already added THIS instance of this symbol. - */ + do { gv = gv_fetchpv(name, iscv | !(kid->op_private & OPpCONST_ENTERED), iscv @@ -4133,16 +3991,18 @@ register OP *o; : o->op_type == OP_RV2HV ? SVt_PVHV : SVt_PVGV); + } while (!gv && !(kid->op_private & OPpCONST_ENTERED) && !iscv++); + if (gv) { + kid->op_type = OP_GV; + SvREFCNT_dec(kid->op_sv); + kid->op_sv = SvREFCNT_inc(gv); } - SvREFCNT_dec(kid->op_sv); - kid->op_sv = SvREFCNT_inc(gv); } return o; } OP * -ck_ftst(o) -OP *o; +ck_ftst(OP *o) { dTHR; I32 type = o->op_type; @@ -4166,14 +4026,13 @@ OP *o; return newGVOP(type, OPf_REF, gv_fetchpv("main::STDIN", TRUE, SVt_PVIO)); else - return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv))); + return newUNOP(type, 0, newDEFSVOP()); } return o; } OP * -ck_fun(o) -OP *o; +ck_fun(OP *o) { dTHR; register OP *kid; @@ -4182,7 +4041,7 @@ OP *o; I32 numargs = 0; int type = o->op_type; register I32 oa = opargs[type] >> OASHIFT; - + if (o->op_flags & OPf_STACKED) { if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL)) oa &= ~OA_OPTIONAL; @@ -4200,7 +4059,7 @@ OP *o; kid = kid->op_sibling; } if (!kid && opargs[type] & OA_DEFGV) - *tokid = kid = newSVREF(newGVOP(OP_GV, 0, defgv)); + *tokid = kid = newDEFSVOP(); while (oa && kid) { numargs++; @@ -4298,7 +4157,7 @@ OP *o; } else if (opargs[type] & OA_DEFGV) { op_free(o); - return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv))); + return newUNOP(type, 0, newDEFSVOP()); } if (oa) { @@ -4311,13 +4170,12 @@ OP *o; } OP * -ck_glob(o) -OP *o; +ck_glob(OP *o) { GV *gv; if ((o->op_flags & OPf_KIDS) && !cLISTOPo->op_first->op_sibling) - append_elem(OP_GLOB, o, newSVREF(newGVOP(OP_GV, 0, defgv))); + append_elem(OP_GLOB, o, newDEFSVOP()); if (!((gv = gv_fetchpv("glob", FALSE, SVt_PVCV)) && GvIMPORTED_CV(gv))) gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV); @@ -4332,7 +4190,7 @@ OP *o; cLISTOPo->op_first->op_type = OP_PUSHMARK; cLISTOPo->op_first->op_ppaddr = ppaddr[OP_PUSHMARK]; o = newUNOP(OP_ENTERSUB, OPf_STACKED, - append_elem(OP_LIST, o, + append_elem(OP_LIST, o, scalar(newUNOP(OP_RV2CV, 0, newGVOP(OP_GV, 0, gv))))); o = newUNOP(OP_NULL, 0, ck_subr(o)); @@ -4347,8 +4205,7 @@ OP *o; } OP * -ck_grep(o) -OP *o; +ck_grep(OP *o) { LOGOP *gwop; OP *kid; @@ -4356,7 +4213,7 @@ OP *o; o->op_ppaddr = ppaddr[OP_GREPSTART]; Newz(1101, gwop, 1, LOGOP); - + if (o->op_flags & OPf_STACKED) { OP* k; o = ck_sort(o); @@ -4375,7 +4232,7 @@ OP *o; o = ck_fun(o); if (error_count) return o; - kid = cLISTOPo->op_first->op_sibling; + kid = cLISTOPo->op_first->op_sibling; if (kid->op_type != OP_NULL) croak("panic: ck_grep"); kid = kUNOP->op_first; @@ -4399,47 +4256,42 @@ OP *o; } OP * -ck_index(o) -OP *o; +ck_index(OP *o) { if (o->op_flags & OPf_KIDS) { OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */ if (kid && kid->op_type == OP_CONST) - fbm_compile(((SVOP*)kid)->op_sv); + fbm_compile(((SVOP*)kid)->op_sv, 0); } return ck_fun(o); } OP * -ck_lengthconst(o) -OP *o; +ck_lengthconst(OP *o) { /* XXX length optimization goes here */ return ck_fun(o); } OP * -ck_lfun(o) -OP *o; +ck_lfun(OP *o) { OPCODE type = o->op_type; return modkids(ck_fun(o), type); } OP * -ck_rfun(o) -OP *o; +ck_rfun(OP *o) { OPCODE type = o->op_type; return refkids(ck_fun(o), type); } OP * -ck_listiob(o) -OP *o; +ck_listiob(OP *o) { register OP *kid; - + kid = cLISTOPo->op_first; if (!kid) { o = force_list(o); @@ -4460,7 +4312,7 @@ OP *o; } if (!kid) - append_elem(o->op_type, o, newSVREF(newGVOP(OP_GV, 0, defgv)) ); + append_elem(o->op_type, o, newDEFSVOP()); o = listkids(o); @@ -4474,8 +4326,7 @@ OP *o; } OP * -ck_fun_locale(o) -OP *o; +ck_fun_locale(OP *o) { o = ck_fun(o); @@ -4489,8 +4340,7 @@ OP *o; } OP * -ck_scmp(o) -OP *o; +ck_scmp(OP *o) { o->op_private = 0; #ifdef USE_LOCALE @@ -4502,23 +4352,20 @@ OP *o; } OP * -ck_match(o) -OP *o; +ck_match(OP *o) { o->op_private |= OPpRUNTIME; return o; } OP * -ck_null(o) -OP *o; +ck_null(OP *o) { return o; } OP * -ck_repeat(o) -OP *o; +ck_repeat(OP *o) { if (cBINOPo->op_first->op_flags & OPf_PARENS) { o->op_private |= OPpREPEAT_DOLIST; @@ -4530,8 +4377,7 @@ OP *o; } OP * -ck_require(o) -OP *o; +ck_require(OP *o) { if (o->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */ SVOP *kid = (SVOP*)cUNOPo->op_first; @@ -4552,8 +4398,7 @@ OP *o; } OP * -ck_retarget(o) -OP *o; +ck_retarget(OP *o) { croak("NOT IMPL LINE %d",__LINE__); /* STUB */ @@ -4561,8 +4406,7 @@ OP *o; } OP * -ck_select(o) -OP *o; +ck_select(OP *o) { OP* kid; if (o->op_flags & OPf_KIDS) { @@ -4582,8 +4426,7 @@ OP *o; } OP * -ck_shift(o) -OP *o; +ck_shift(OP *o) { I32 type = o->op_type; @@ -4592,7 +4435,7 @@ OP *o; op_free(o); #ifdef USE_THREADS - if (subline) { + if (!CvUNIQUE(compcv)) { argop = newOP(OP_PADAV, OPf_REF); argop->op_targ = 0; /* curpad[0] is @_ */ } @@ -4603,7 +4446,7 @@ OP *o; } #else argop = newUNOP(OP_RV2AV, 0, - scalar(newGVOP(OP_GV, 0, subline ? + scalar(newGVOP(OP_GV, 0, !CvUNIQUE(compcv) ? defgv : gv_fetchpv("ARGV", TRUE, SVt_PVAV)))); #endif /* USE_THREADS */ return newUNOP(type, 0, scalar(argop)); @@ -4612,8 +4455,7 @@ OP *o; } OP * -ck_sort(o) -OP *o; +ck_sort(OP *o) { o->op_private = 0; #ifdef USE_LOCALE @@ -4662,12 +4504,10 @@ OP *o; } OP * -ck_split(o) -OP *o; +ck_split(OP *o) { register OP *kid; - PMOP* pm; - + if (o->op_flags & OPf_STACKED) return no_fh_allowed(o); @@ -4691,18 +4531,13 @@ OP *o; cLISTOPo->op_first = kid; kid->op_sibling = sibl; } - pm = (PMOP*)kid; - if (pm->op_pmshort && !(pm->op_pmflags & PMf_ALL)) { - SvREFCNT_dec(pm->op_pmshort); /* can't use substring to optimize */ - pm->op_pmshort = 0; - } kid->op_type = OP_PUSHRE; kid->op_ppaddr = ppaddr[OP_PUSHRE]; scalar(kid); if (!kid->op_sibling) - append_elem(OP_SPLIT, o, newSVREF(newGVOP(OP_GV, 0, defgv)) ); + append_elem(OP_SPLIT, o, newDEFSVOP()); kid = kid->op_sibling; scalar(kid); @@ -4720,8 +4555,7 @@ OP *o; } OP * -ck_subr(o) -OP *o; +ck_subr(OP *o) { dTHR; OP *prev = ((cUNOPo->op_first->op_sibling) @@ -4783,10 +4617,11 @@ OP *o; goto wrapref; { OP* kid = o2; - o2 = newUNOP(OP_RV2GV, 0, kid); - o2->op_sibling = kid->op_sibling; + OP* sib = kid->op_sibling; kid->op_sibling = 0; - prev->op_sibling = o; + o2 = newUNOP(OP_RV2GV, 0, kid); + o2->op_sibling = sib; + prev->op_sibling = o2; } goto wrapref; case '\\': @@ -4815,9 +4650,10 @@ OP *o; wrapref: { OP* kid = o2; - o2 = newUNOP(OP_REFGEN, 0, kid); - o2->op_sibling = kid->op_sibling; + OP* sib = kid->op_sibling; kid->op_sibling = 0; + o2 = newUNOP(OP_REFGEN, 0, kid); + o2->op_sibling = sib; prev->op_sibling = o2; } break; @@ -4846,16 +4682,14 @@ OP *o; } OP * -ck_svconst(o) -OP *o; +ck_svconst(OP *o) { SvREADONLY_on(cSVOPo->op_sv); return o; } OP * -ck_trunc(o) -OP *o; +ck_trunc(OP *o) { if (o->op_flags & OPf_KIDS) { SVOP *kid = (SVOP*)cUNOPo->op_first; @@ -4872,8 +4706,7 @@ OP *o; /* A peephole optimizer. We visit the ops in the order they're to execute. */ void -peep(o) -register OP* o; +peep(register OP *o) { dTHR; register OP* oldop = 0; @@ -4903,7 +4736,7 @@ register OP* o; case OP_LC: case OP_LCFIRST: case OP_QUOTEMETA: - if (o->op_next->op_type == OP_STRINGIFY) + if (o->op_next && o->op_next->op_type == OP_STRINGIFY) null(o->op_next); o->op_seq = op_seqmax++; break; @@ -4915,7 +4748,7 @@ register OP* o; goto nothin; case OP_NULL: if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE) - curcop = ((COP*)op); + curcop = ((COP*)o); goto nothin; case OP_SCALAR: case OP_LINESEQ: @@ -4973,7 +4806,7 @@ register OP* o; 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)) @@ -4988,6 +4821,8 @@ register OP* o; case OP_AND: case OP_OR: o->op_seq = op_seqmax++; + while (cLOGOP->op_other->op_type == OP_NULL) + cLOGOP->op_other = cLOGOP->op_other->op_next; peep(cLOGOP->op_other); break; @@ -5024,7 +4859,7 @@ register OP* o; } } break; - + case OP_HELEM: { UNOP *rop; SV *lexname; @@ -5033,7 +4868,7 @@ register OP* o; I32 ind; char *key; STRLEN keylen; - + if (o->op_private & (OPpDEREF_HV|OPpDEREF_AV|OPpLVAL_INTRO) || ((BINOP*)o)->op_last->op_type != OP_CONST) break;