This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
add option to omit Changes file, from Abigail <abigail@delanet.com>;
[perl5.git] / op.c
diff --git a/op.c b/op.c
index 91e996e..755c34e 100644 (file)
--- a/op.c
+++ b/op.c
@@ -38,7 +38,7 @@ static int     PL_OpSpace = 0;
                            } while (0)
 
 STATIC void *           
-Slab_Alloc(pTHX_ int m, size_t sz)
+S_Slab_Alloc(pTHX_ int m, size_t sz)
 { 
  Newz(m,PL_OpPtr,SLAB_SIZE,char);
  PL_OpSpace = SLAB_SIZE - sz;
@@ -55,14 +55,14 @@ Slab_Alloc(pTHX_ int m, size_t sz)
 #define CHECKOP(type,o) \
     ((PL_op_mask && PL_op_mask[type])                                  \
      ? ( op_free((OP*)o),                                      \
-        croak("%s trapped by operation mask", PL_op_desc[type]),       \
+        Perl_croak(aTHX_ "%s trapped by operation mask", PL_op_desc[type]),    \
         Nullop )                                               \
-     : (CHECKCALL[type])((OP*)o))
+     : (CHECKCALL[type])(aTHX_ (OP*)o))
 
 #define PAD_MAX 999999999
 
 STATIC char*
-gv_ename(pTHX_ GV *gv)
+S_gv_ename(pTHX_ GV *gv)
 {
     STRLEN n_a;
     SV* tmpsv = sv_newmortal();
@@ -71,38 +71,38 @@ gv_ename(pTHX_ GV *gv)
 }
 
 STATIC OP *
-no_fh_allowed(pTHX_ OP *o)
+S_no_fh_allowed(pTHX_ OP *o)
 {
-    yyerror(form("Missing comma after first argument to %s function",
+    yyerror(Perl_form(aTHX_ "Missing comma after first argument to %s function",
                 PL_op_desc[o->op_type]));
     return o;
 }
 
 STATIC OP *
-too_few_arguments(pTHX_ OP *o, char *name)
+S_too_few_arguments(pTHX_ OP *o, char *name)
 {
-    yyerror(form("Not enough arguments for %s", name));
+    yyerror(Perl_form(aTHX_ "Not enough arguments for %s", name));
     return o;
 }
 
 STATIC OP *
-too_many_arguments(pTHX_ OP *o, char *name)
+S_too_many_arguments(pTHX_ OP *o, char *name)
 {
-    yyerror(form("Too many arguments for %s", name));
+    yyerror(Perl_form(aTHX_ "Too many arguments for %s", name));
     return o;
 }
 
 STATIC void
-bad_type(pTHX_ I32 n, char *t, char *name, OP *kid)
+S_bad_type(pTHX_ I32 n, char *t, char *name, OP *kid)
 {
-    yyerror(form("Type of arg %d to %s must be %s (not %s)",
+    yyerror(Perl_form(aTHX_ "Type of arg %d to %s must be %s (not %s)",
                 (int)n, name, t, PL_op_desc[kid->op_type]));
 }
 
 STATIC void
-no_bareword_allowed(pTHX_ OP *o)
+S_no_bareword_allowed(pTHX_ OP *o)
 {
-    warn("Bareword \"%s\" not allowed while \"strict subs\" in use",
+    Perl_warn(aTHX_ "Bareword \"%s\" not allowed while \"strict subs\" in use",
          SvPV_nolen(cSVOPo->op_sv));
     ++PL_error_count;
 }
@@ -112,14 +112,14 @@ Perl_assertref(pTHX_ OP *o)
 {
     int type = o->op_type;
     if (type != OP_AELEM && type != OP_HELEM && type != OP_GELEM) {
-       yyerror(form("Can't use subscript on %s", PL_op_desc[type]));
+       yyerror(Perl_form(aTHX_ "Can't use subscript on %s", PL_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",
+                       Perl_newSVpvf(aTHX_ "(Did you mean $ or @ instead of %c?)\n",
                                 type == OP_ENTERSUB ? '&' : '%'));
            if (PL_in_eval & EVAL_WARNONLY)
-               warn("%_", msg);
+               Perl_warn(aTHX_ "%_", msg);
            else if (PL_in_eval)
                sv_catsv(GvSV(PL_errgv), msg);
            else
@@ -142,7 +142,7 @@ Perl_pad_allocmy(pTHX_ char *name)
        (PL_hints & HINT_UTF8 && (name[1] & 0xc0) == 0xc0) ||
        name[1] == '_' && (int)strlen(name) > 2))
     {
-       if (!isPRINT(name[1])) {
+       if (!isPRINT(name[1]) || strchr("\t\n\r\f", name[1])) {
            /* 1999-02-27 mjd@plover.com */
            char *p;
            p = strchr(name, '\0');
@@ -161,7 +161,7 @@ Perl_pad_allocmy(pTHX_ char *name)
            name[2] = toCTRL(name[1]);
            name[1] = '^';
        }
-       yyerror(form("Can't use global %s in \"my\"",name));
+       yyerror(Perl_form(aTHX_ "Can't use global %s in \"my\"",name));
     }
     if (ckWARN(WARN_UNSAFE) && AvFILLp(PL_comppad_name) >= 0) {
        SV **svp = AvARRAY(PL_comppad_name);
@@ -171,7 +171,7 @@ Perl_pad_allocmy(pTHX_ char *name)
                && (SvIVX(sv) == PAD_MAX || SvIVX(sv) == 0)
                && strEQ(name, SvPVX(sv)))
            {
-               warner(WARN_UNSAFE,
+               Perl_warner(aTHX_ WARN_UNSAFE,
                        "\"my\" variable %s masks earlier declaration in same %s", 
                        name, (SvIVX(sv) == PAD_MAX ? "scope" : "statement"));
                break;
@@ -184,7 +184,7 @@ Perl_pad_allocmy(pTHX_ char *name)
     sv_setpv(sv, name);
     if (PL_in_my_stash) {
        if (*name != '$')
-           yyerror(form("Can't declare class for non-scalar %s in \"my\"",
+           yyerror(Perl_form(aTHX_ "Can't declare class for non-scalar %s in \"my\"",
                         name));
        SvOBJECT_on(sv);
        (void)SvUPGRADE(sv, SVt_PVMG);
@@ -192,7 +192,7 @@ Perl_pad_allocmy(pTHX_ char *name)
        PL_sv_objcount++;
     }
     av_store(PL_comppad_name, off, sv);
-    SvNVX(sv) = (double)PAD_MAX;
+    SvNVX(sv) = (NV)PAD_MAX;
     SvIVX(sv) = 0;                     /* Not yet introduced--see newSTATEOP */
     if (!PL_min_intro_pending)
        PL_min_intro_pending = off;
@@ -208,7 +208,7 @@ Perl_pad_allocmy(pTHX_ char *name)
 #define FINDLEX_NOSEARCH       1               /* don't search outer contexts */
 
 STATIC PADOFFSET
-pad_findlex(pTHX_ char *name, PADOFFSET newoff, U32 seq, CV* startcv,
+S_pad_findlex(pTHX_ char *name, PADOFFSET newoff, U32 seq, CV* startcv,
            I32 cx_ix, I32 saweval, U32 flags)
 {
     dTHR;
@@ -255,7 +255,7 @@ pad_findlex(pTHX_ char *name, PADOFFSET newoff, U32 seq, CV* startcv,
                    sv_upgrade(namesv, SVt_PVNV);
                    sv_setpv(namesv, name);
                    av_store(PL_comppad_name, newoff, namesv);
-                   SvNVX(namesv) = (double)PL_curcop->cop_seq;
+                   SvNVX(namesv) = (NV)PL_curcop->cop_seq;
                    SvIVX(namesv) = PAD_MAX;    /* A ref, intro immediately */
                    SvFAKE_on(namesv);          /* A ref, not a real var */
                    if (SvOBJECT(sv)) {         /* A typed var */
@@ -283,7 +283,7 @@ pad_findlex(pTHX_ char *name, PADOFFSET newoff, U32 seq, CV* startcv,
                                    if (ckWARN(WARN_CLOSURE)
                                        && !CvUNIQUE(bcv) && !CvUNIQUE(cv))
                                    {
-                                       warner(WARN_CLOSURE,
+                                       Perl_warner(aTHX_ WARN_CLOSURE,
                                          "Variable \"%s\" may be unavailable",
                                             name);
                                    }
@@ -294,7 +294,7 @@ pad_findlex(pTHX_ char *name, PADOFFSET newoff, U32 seq, CV* startcv,
                    }
                    else if (!CvUNIQUE(PL_compcv)) {
                        if (ckWARN(WARN_CLOSURE) && !SvFAKE(sv) && !CvUNIQUE(cv))
-                           warner(WARN_CLOSURE,
+                           Perl_warner(aTHX_ WARN_CLOSURE,
                                "Variable \"%s\" will not stay shared", name);
                    }
                }
@@ -414,13 +414,14 @@ Perl_pad_findmy(pTHX_ char *name)
 void
 Perl_pad_leavemy(pTHX_ I32 fill)
 {
+    dTHR;
     I32 off;
     SV **svp = AvARRAY(PL_comppad_name);
     SV *sv;
     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));
+           if ((sv = svp[off]) && sv != &PL_sv_undef && ckWARN_d(WARN_INTERNAL))
+               Perl_warner(aTHX_ WARN_INTERNAL, "%s never introduced", SvPVX(sv));
        }
     }
     /* "Deintroduce" my variables that are leaving with this scope. */
@@ -438,7 +439,7 @@ Perl_pad_alloc(pTHX_ I32 optype, U32 tmptype)
     I32 retval;
 
     if (AvARRAY(PL_comppad) != PL_curpad)
-       croak("panic: pad_alloc");
+       Perl_croak(aTHX_ "panic: pad_alloc");
     if (PL_pad_reset_pending)
        pad_reset();
     if (tmptype & SVs_PADMY) {
@@ -488,7 +489,7 @@ Perl_pad_sv(pTHX_ PADOFFSET po)
                          (unsigned long) thr, (unsigned long) PL_curpad, po));
 #else
     if (!po)
-       croak("panic: pad_sv po");
+       Perl_croak(aTHX_ "panic: pad_sv po");
     DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%lx sv %d\n",
                          (unsigned long) PL_curpad, po));
 #endif /* USE_THREADS */
@@ -502,9 +503,9 @@ Perl_pad_free(pTHX_ PADOFFSET po)
     if (!PL_curpad)
        return;
     if (AvARRAY(PL_comppad) != PL_curpad)
-       croak("panic: pad_free curpad");
+       Perl_croak(aTHX_ "panic: pad_free curpad");
     if (!po)
-       croak("panic: pad_free po");
+       Perl_croak(aTHX_ "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) PL_curpad, po));
@@ -523,9 +524,9 @@ Perl_pad_swipe(pTHX_ PADOFFSET po)
 {
     dTHR;
     if (AvARRAY(PL_comppad) != PL_curpad)
-       croak("panic: pad_swipe curpad");
+       Perl_croak(aTHX_ "panic: pad_swipe curpad");
     if (!po)
-       croak("panic: pad_swipe po");
+       Perl_croak(aTHX_ "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) PL_curpad, po));
@@ -554,7 +555,7 @@ Perl_pad_reset(pTHX)
     register I32 po;
 
     if (AvARRAY(PL_comppad) != PL_curpad)
-       croak("panic: pad_reset curpad");
+       Perl_croak(aTHX_ "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) PL_curpad));
@@ -647,6 +648,7 @@ void
 Perl_op_free(pTHX_ OP *o)
 {
     register OP *kid, *nextkid;
+    OPCODE type;
 
     if (!o || o->op_seq == (U16)-1)
        return;
@@ -657,42 +659,57 @@ Perl_op_free(pTHX_ OP *o)
            op_free(kid);
        }
     }
+    type = o->op_type;
+    if (type == OP_NULL)
+       type = o->op_targ;
+
+    /* COP* is not cleared by op_clear() so that we may track line
+     * numbers etc even after null() */
+    if (type == OP_NEXTSTATE || type == OP_SETSTATE || type == OP_DBSTATE)
+       cop_free((COP*)o);
+
+    op_clear(o);
+
+#ifdef PL_OP_SLAB_ALLOC
+    if ((char *) o == PL_OpPtr)
+     {
+     }
+#else
+    Safefree(o);
+#endif
+}
 
+STATIC void
+S_op_clear(pTHX_ OP *o)
+{
     switch (o->op_type) {
-    case OP_NULL:
-       o->op_targ = 0; /* Was holding old type, if any. */
-       break;
-    case OP_ENTEREVAL:
-       o->op_targ = 0; /* Was holding hints. */
+    case OP_NULL:      /* Was holding old type, if any. */
+    case OP_ENTEREVAL: /* Was holding hints. */
+#ifdef USE_THREADS
+    case OP_THREADSV:  /* Was holding index into thr->threadsv AV. */
+#endif
+       o->op_targ = 0;
        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)
-           || (PL_check[o->op_type] != FUNC_NAME_TO_PTR(ck_ftst)))
+           || (PL_check[o->op_type] != MEMBER_TO_FPTR(Perl_ck_ftst)))
            break;
        /* FALL THROUGH */
     case OP_GVSV:
     case OP_GV:
     case OP_AELEMFAST:
        SvREFCNT_dec(cGVOPo->op_gv);
-       break;
-    case OP_NEXTSTATE:
-    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);
+       cGVOPo->op_gv = Nullgv;
        break;
     case OP_CONST:
        SvREFCNT_dec(cSVOPo->op_sv);
+       cSVOPo->op_sv = Nullsv;
        break;
     case OP_GOTO:
     case OP_NEXT:
@@ -702,38 +719,46 @@ Perl_op_free(pTHX_ OP *o)
            break;
        /* FALL THROUGH */
     case OP_TRANS:
-       if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF))
+       if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
            SvREFCNT_dec(cSVOPo->op_sv);
-       else
+           cSVOPo->op_sv = Nullsv;
+       }
+       else {
            Safefree(cPVOPo->op_pv);
+           cPVOPo->op_pv = Nullch;
+       }
        break;
     case OP_SUBST:
        op_free(cPMOPo->op_pmreplroot);
+       cPMOPo->op_pmreplroot = Nullop;
        /* FALL THROUGH */
     case OP_PUSHRE:
     case OP_MATCH:
     case OP_QR:
        ReREFCNT_dec(cPMOPo->op_pmregexp);
+       cPMOPo->op_pmregexp = (REGEXP*)NULL;
        break;
     }
 
     if (o->op_targ > 0)
        pad_free(o->op_targ);
+}
 
-#ifdef PL_OP_SLAB_ALLOC
-    if ((char *) o == PL_OpPtr)
-     {
-     }
-#else
-    Safefree(o);
-#endif
+STATIC void
+S_cop_free(pTHX_ COP* cop)
+{
+    Safefree(cop->cop_label);
+    SvREFCNT_dec(cop->cop_filegv);
+    if (! specialWARN(cop->cop_warnings))
+       SvREFCNT_dec(cop->cop_warnings);
 }
 
 STATIC void
-null(pTHX_ OP *o)
+S_null(pTHX_ OP *o)
 {
-    if (o->op_type != OP_NULL && o->op_type != OP_THREADSV && o->op_targ > 0)
-       pad_free(o->op_targ);
+    if (o->op_type == OP_NULL)
+       return;
+    op_clear(o);
     o->op_targ = o->op_type;
     o->op_type = OP_NULL;
     o->op_ppaddr = PL_ppaddr[OP_NULL];
@@ -779,7 +804,7 @@ Perl_scalarkids(pTHX_ OP *o)
 }
 
 STATIC OP *
-scalarboolean(pTHX_ OP *o)
+S_scalarboolean(pTHX_ OP *o)
 {
     if (o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST) {
        dTHR;
@@ -788,7 +813,7 @@ scalarboolean(pTHX_ OP *o)
 
            if (PL_copline != NOLINE)
                PL_curcop->cop_line = PL_copline;
-           warner(WARN_SYNTAX, "Found = in conditional, should be ==");
+           Perl_warner(aTHX_ WARN_SYNTAX, "Found = in conditional, should be ==");
            PL_curcop->cop_line = oldline;
        }
     }
@@ -805,6 +830,10 @@ Perl_scalar(pTHX_ OP *o)
         || o->op_type == OP_RETURN)
        return o;
 
+    if ((o->op_private & OPpTARGET_MY)
+       && (PL_opargs[o->op_type] & OA_TARGLEX)) /* OPp share the meaning */
+       return scalar(o);                       /* As if inside SASSIGN */
+    
     o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_SCALAR;
 
     switch (o->op_type) {
@@ -870,9 +899,12 @@ Perl_scalarvoid(pTHX_ OP *o)
     SV* sv;
     U8 want;
 
-    if (o->op_type == OP_NEXTSTATE || o->op_type == OP_DBSTATE ||
-       (o->op_type == OP_NULL &&
-        (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE)))
+    if (o->op_type == OP_NEXTSTATE
+       || o->op_type == OP_SETSTATE
+       || o->op_type == OP_DBSTATE
+       || (o->op_type == OP_NULL && (o->op_targ == OP_NEXTSTATE
+                                     || o->op_targ == OP_SETSTATE
+                                     || o->op_targ == OP_DBSTATE)))
     {
        dTHR;
        PL_curcop = (COP*)o;            /* for warning below */
@@ -884,6 +916,10 @@ Perl_scalarvoid(pTHX_ OP *o)
         || o->op_type == OP_RETURN)
        return o;
 
+    if ((o->op_private & OPpTARGET_MY)
+       && (PL_opargs[o->op_type] & OA_TARGLEX)) /* OPp share the meaning */
+       return scalar(o);                       /* As if inside SASSIGN */
+    
     o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_VOID;
 
     switch (o->op_type) {
@@ -998,8 +1034,7 @@ Perl_scalarvoid(pTHX_ OP *o)
                }
            }
        }
-       null(o);                /* don't execute a constant */
-       SvREFCNT_dec(sv);       /* don't even remember it */
+       null(o);                /* don't execute or even remember it */
        break;
 
     case OP_POSTINC:
@@ -1057,7 +1092,7 @@ Perl_scalarvoid(pTHX_ OP *o)
     if (useless) {
        dTHR;
        if (ckWARN(WARN_VOID))
-           warner(WARN_VOID, "Useless use of %s in void context", useless);
+           Perl_warner(aTHX_ WARN_VOID, "Useless use of %s in void context", useless);
     }
     return o;
 }
@@ -1083,6 +1118,10 @@ Perl_list(pTHX_ OP *o)
         || o->op_type == OP_RETURN)
        return o;
 
+    if ((o->op_private & OPpTARGET_MY)
+       && (PL_opargs[o->op_type] & OA_TARGLEX)) /* OPp share the meaning */
+       return o;                               /* As if inside SASSIGN */
+    
     o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_LIST;
 
     switch (o->op_type) {
@@ -1169,7 +1208,7 @@ Perl_scalarseq(pTHX_ OP *o)
 }
 
 STATIC OP *
-modkids(pTHX_ OP *o, I32 type)
+S_modkids(pTHX_ OP *o, I32 type)
 {
     OP *kid;
     if (o && o->op_flags & OPf_KIDS) {
@@ -1190,6 +1229,10 @@ Perl_mod(pTHX_ OP *o, I32 type)
     if (!o || PL_error_count)
        return o;
 
+    if ((o->op_private & OPpTARGET_MY)
+       && (PL_opargs[o->op_type] & OA_TARGLEX)) /* OPp share the meaning */
+       return o;
+    
     switch (o->op_type) {
     case OP_UNDEF:
        PL_modcount++;
@@ -1208,7 +1251,7 @@ Perl_mod(pTHX_ OP *o, I32 type)
        else if (type == OP_REFGEN)
            goto nomod;
        else
-           croak("That use of $[ is unsupported");
+           Perl_croak(aTHX_ "That use of $[ is unsupported");
        break;
     case OP_STUB:
        if (o->op_flags & OPf_PARENS)
@@ -1229,7 +1272,7 @@ Perl_mod(pTHX_ OP *o, I32 type)
        /* grep, foreach, subcalls, refgen */
        if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
            break;
-       yyerror(form("Can't modify %s in %s",
+       yyerror(Perl_form(aTHX_ "Can't modify %s in %s",
                     (o->op_type == OP_NULL && (o->op_flags & OPf_SPECIAL)
                      ? "do block" : PL_op_desc[o->op_type]),
                     type ? PL_op_desc[type] : "local"));
@@ -1268,7 +1311,7 @@ Perl_mod(pTHX_ OP *o, I32 type)
     case OP_RV2AV:
     case OP_RV2HV:
        if (!type && cUNOPo->op_first->op_type != OP_GV)
-           croak("Can't localize through a reference");
+           Perl_croak(aTHX_ "Can't localize through a reference");
        if (type == OP_REFGEN && o->op_flags & OPf_PARENS) {
            PL_modcount = 10000;
            return o;           /* Treat \(@foo) like ordinary list. */
@@ -1290,7 +1333,7 @@ Perl_mod(pTHX_ OP *o, I32 type)
        break;
     case OP_RV2SV:
        if (!type && cUNOPo->op_first->op_type != OP_GV)
-           croak("Can't localize through a reference");
+           Perl_croak(aTHX_ "Can't localize through a reference");
        ref(cUNOPo->op_first, o->op_type);
        /* FALL THROUGH */
     case OP_GV:
@@ -1314,7 +1357,7 @@ Perl_mod(pTHX_ OP *o, I32 type)
     case OP_PADSV:
        PL_modcount++;
        if (!type)
-           croak("Can't localize lexical variable %s",
+           Perl_croak(aTHX_ "Can't localize lexical variable %s",
                SvPV(*av_fetch(PL_comppad_name, o->op_targ, 4), n_a));
        break;
 
@@ -1391,7 +1434,7 @@ Perl_mod(pTHX_ OP *o, I32 type)
 }
 
 STATIC bool
-scalar_mod_type(pTHX_ OP *o, I32 type)
+S_scalar_mod_type(pTHX_ OP *o, I32 type)
 {
     switch (type) {
     case OP_SASSIGN:
@@ -1438,7 +1481,7 @@ scalar_mod_type(pTHX_ OP *o, I32 type)
 }
 
 STATIC bool
-is_handle_constructor(pTHX_ OP *o, I32 argnum)
+S_is_handle_constructor(pTHX_ OP *o, I32 argnum)
 {
     switch (o->op_type) {
     case OP_PIPE_OP:
@@ -1580,7 +1623,7 @@ Perl_my(pTHX_ OP *o)
             type != OP_PADHV &&
             type != OP_PUSHMARK)
     {
-       yyerror(form("Can't declare %s in my", PL_op_desc[o->op_type]));
+       yyerror(Perl_form(aTHX_ "Can't declare %s in my", PL_op_desc[o->op_type]));
        return o;
     }
     o->op_flags |= OPf_MOD;
@@ -1613,7 +1656,7 @@ Perl_bind_match(pTHX_ I32 type, OP *left, OP *right)
       char *sample = ((left->op_type == OP_RV2AV ||
                        left->op_type == OP_PADAV)
                       ? "@array" : "%hash");
-      warner(WARN_UNSAFE,
+      Perl_warner(aTHX_ WARN_UNSAFE,
              "Applying %s to %s will act on scalar(%s)", 
              desc, sample, sample);
     }
@@ -1662,8 +1705,8 @@ Perl_scope(pTHX_ OP *o)
                o->op_ppaddr = PL_ppaddr[OP_SCOPE];
                kid = ((LISTOP*)o)->op_first;
                if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE){
-                   SvREFCNT_dec(((COP*)kid)->cop_filegv);
-                   null(kid);
+                   kid->op_type = OP_SETSTATE;
+                   kid->op_ppaddr = PL_ppaddr[OP_SETSTATE];
                }
            }
            else
@@ -1705,8 +1748,7 @@ Perl_block_start(pTHX_ int full)
     SAVEHINTS();
     PL_hints &= ~HINT_BLOCK_SCOPE;
     SAVEPPTR(PL_compiling.cop_warnings); 
-    if (PL_compiling.cop_warnings != WARN_ALL && 
-       PL_compiling.cop_warnings != WARN_NONE) {
+    if (! specialWARN(PL_compiling.cop_warnings)) {
         PL_compiling.cop_warnings = newSVsv(PL_compiling.cop_warnings) ;
         SAVEFREESV(PL_compiling.cop_warnings) ;
     }
@@ -1732,7 +1774,7 @@ Perl_block_end(pTHX_ I32 floor, OP *seq)
 }
 
 STATIC OP *
-newDEFSVOP(pTHX)
+S_newDEFSVOP(pTHX)
 {
 #ifdef USE_THREADS
     OP *o = newOP(OP_THREADSV, 0);
@@ -1792,7 +1834,7 @@ Perl_localize(pTHX_ OP *o, I32 lex)
            char *s;
            for (s = PL_bufptr; *s && (isALNUM(*s) || (*s & 0x80) || strchr("@$%, ",*s)); s++) ;
            if (*s == ';' || *s == '=')
-               warner(WARN_PARENTHESIS, "Parentheses missing around \"%s\" list",
+               Perl_warner(aTHX_ WARN_PARENTHESIS, "Parentheses missing around \"%s\" list",
                                lex ? "my" : "local");
        }
     }
@@ -1830,11 +1872,17 @@ Perl_fold_constants(pTHX_ register OP *o)
 
     if (PL_opargs[type] & OA_RETSCALAR)
        scalar(o);
-    if (PL_opargs[type] & OA_TARGET)
+    if (PL_opargs[type] & OA_TARGET && !o->op_targ)
        o->op_targ = pad_alloc(type, SVs_PADTMP);
 
-    if ((PL_opargs[type] & OA_OTHERINT) && (PL_hints & HINT_INTEGER))
+    /* integerize op, unless it happens to be C<-foo>.
+     * XXX should pp_i_negate() do magic string negation instead? */
+    if ((PL_opargs[type] & OA_OTHERINT) && (PL_hints & HINT_INTEGER)
+       && !(type == OP_NEGATE && cUNOPo->op_first->op_type == OP_CONST
+            && (cUNOPo->op_first->op_private & OPpCONST_BARE)))
+    {
        o->op_ppaddr = PL_ppaddr[type = ++(o->op_type)];
+    }
 
     if (!(PL_opargs[type] & OA_FOLDCONST))
        goto nope;
@@ -1876,7 +1924,7 @@ Perl_fold_constants(pTHX_ register OP *o)
     curop = LINKLIST(o);
     o->op_next = 0;
     PL_op = curop;
-    CALLRUNOPS();
+    CALLRUNOPS(aTHX);
     sv = *(PL_stack_sp--);
     if (o->op_targ && sv == PAD_SV(o->op_targ))        /* grab pad temp? */
        pad_swipe(o->op_targ);
@@ -1893,7 +1941,7 @@ Perl_fold_constants(pTHX_ register OP *o)
            type != OP_NEGATE)
        {
            IV iv = SvIV(sv);
-           if ((double)iv == SvNV(sv)) {
+           if ((NV)iv == SvNV(sv)) {
                SvREFCNT_dec(sv);
                sv = newSViv(iv);
            }
@@ -1940,10 +1988,10 @@ Perl_gen_constant_list(pTHX_ register OP *o)
 
     PL_op = curop = LINKLIST(o);
     o->op_next = 0;
-    pp_pushmark(ARGS);
-    CALLRUNOPS();
+    pp_pushmark();
+    CALLRUNOPS(aTHX);
     PL_op = curop;
-    pp_anonlist(ARGS);
+    pp_anonlist();
     PL_tmps_floor = oldtmps_floor;
 
     o->op_type = OP_RV2AV;
@@ -2185,7 +2233,7 @@ Perl_newBINOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
     }
 
     binop = (BINOP*)CHECKOP(type, binop);
-    if (binop->op_next)
+    if (binop->op_next || binop->op_type != type)
        return (OP*)binop;
 
     binop->op_last = binop->op_first->op_sibling;
@@ -2352,15 +2400,15 @@ Perl_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
            if (rfirst == 0xffffffff) {
                diff = tdiff;   /* oops, pretend rdiff is infinite */
                if (diff > 0)
-                   sv_catpvf(listsv, "%04x\t%04x\tXXXX\n", tfirst, tlast);
+                   Perl_sv_catpvf(aTHX_ listsv, "%04x\t%04x\tXXXX\n", tfirst, tlast);
                else
-                   sv_catpvf(listsv, "%04x\t\tXXXX\n", tfirst);
+                   Perl_sv_catpvf(aTHX_ listsv, "%04x\t\tXXXX\n", tfirst);
            }
            else {
                if (diff > 0)
-                   sv_catpvf(listsv, "%04x\t%04x\t%04x\n", tfirst, tfirst + diff, rfirst);
+                   Perl_sv_catpvf(aTHX_ listsv, "%04x\t%04x\t%04x\n", tfirst, tfirst + diff, rfirst);
                else
-                   sv_catpvf(listsv, "%04x\t\t%04x\n", tfirst, rfirst);
+                   Perl_sv_catpvf(aTHX_ listsv, "%04x\t\t%04x\n", tfirst, rfirst);
 
                if (rfirst + diff > max)
                    max = rfirst + diff;
@@ -2507,7 +2555,7 @@ Perl_pmruntime(pTHX_ OP *o, OP *expr, OP *repl)
            p = SvPV(pat, plen);
            pm->op_pmflags |= PMf_SKIPWHITE;
        }
-       pm->op_pmregexp = CALLREGCOMP(p, p + plen, pm);
+       pm->op_pmregexp = CALLREGCOMP(aTHX_ p, p + plen, pm);
        if (strEQ("\\s+", pm->op_pmregexp->precomp))
            pm->op_pmflags |= PMf_WHITE;
        op_free(expr);
@@ -2723,7 +2771,7 @@ Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *id, OP *arg)
     GV *gv;
 
     if (id->op_type != OP_CONST)
-       croak("Module name must be constant");
+       Perl_croak(aTHX_ "Module name must be constant");
 
     veop = Nullop;
 
@@ -2738,7 +2786,7 @@ Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *id, OP *arg)
            OP *meth;
 
            if (version->op_type != OP_CONST || !SvNIOK(vesv))
-               croak("Version number must be constant number");
+               Perl_croak(aTHX_ "Version number must be constant number");
 
            /* Make copy of id so we don't free it twice */
            pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
@@ -2834,7 +2882,7 @@ Perl_newSLICEOP(pTHX_ I32 flags, OP *subscript, OP *listval)
 }
 
 STATIC I32
-list_assignment(pTHX_ register OP *o)
+S_list_assignment(pTHX_ register OP *o)
 {
     if (!o)
        return TRUE;
@@ -2843,8 +2891,8 @@ list_assignment(pTHX_ register OP *o)
        o = cUNOPo->op_first;
 
     if (o->op_type == OP_COND_EXPR) {
-       I32 t = list_assignment(cCONDOPo->op_first->op_sibling);
-       I32 f = list_assignment(cCONDOPo->op_first->op_sibling->op_sibling);
+       I32 t = list_assignment(cLOGOPo->op_first->op_sibling);
+       I32 f = list_assignment(cLOGOPo->op_first->op_sibling->op_sibling);
 
        if (t && f)
            return TRUE;
@@ -3034,8 +3082,7 @@ Perl_newSTATEOP(pTHX_ I32 flags, char *label, OP *o)
     }
     cop->cop_seq = seq;
     cop->cop_arybase = PL_curcop->cop_arybase;
-    if (PL_curcop->cop_warnings == WARN_NONE 
-       || PL_curcop->cop_warnings == WARN_ALL)
+    if (specialWARN(PL_curcop->cop_warnings))
         cop->cop_warnings = PL_curcop->cop_warnings ;
     else 
         cop->cop_warnings = newSVsv(PL_curcop->cop_warnings) ;
@@ -3077,7 +3124,7 @@ Perl_intro_my(pTHX)
     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;
+           SvNVX(sv) = (NV)PL_cop_seqmax;
        }
     }
     PL_min_intro_pending = 0;
@@ -3092,7 +3139,7 @@ Perl_newLOGOP(pTHX_ I32 type, I32 flags, OP *first, OP *other)
 }
 
 STATIC OP *
-new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp)
+S_new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp)
 {
     dTHR;
     LOGOP *logop;
@@ -3121,7 +3168,7 @@ new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp)
     }
     if (first->op_type == OP_CONST) {
        if (ckWARN(WARN_PRECEDENCE) && (first->op_private & OPpCONST_BARE))
-           warner(WARN_PRECEDENCE, "Probable precedence problem on %s", 
+           Perl_warner(aTHX_ WARN_PRECEDENCE, "Probable precedence problem on %s", 
                        PL_op_desc[type]);
        if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
            op_free(first);
@@ -3163,7 +3210,7 @@ new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp)
        if (warnop) {
            line_t oldline = PL_curcop->cop_line;
            PL_curcop->cop_line = PL_copline;
-           warner(WARN_UNSAFE,
+           Perl_warner(aTHX_ WARN_UNSAFE,
                 "Value of %s%s can be \"0\"; test with defined()",
                 PL_op_desc[warnop],
                 ((warnop == OP_READLINE || warnop == OP_GLOB)
@@ -3202,7 +3249,8 @@ OP *
 Perl_newCONDOP(pTHX_ I32 flags, OP *first, OP *trueop, OP *falseop)
 {
     dTHR;
-    CONDOP *condop;
+    LOGOP *logop;
+    OP *start;
     OP *o;
 
     if (!falseop)
@@ -3227,27 +3275,27 @@ Perl_newCONDOP(pTHX_ I32 flags, OP *first, OP *trueop, OP *falseop)
        list(trueop);
        scalar(falseop);
     }
-    NewOp(1101, condop, 1, CONDOP);
+    NewOp(1101, logop, 1, LOGOP);
+    logop->op_type = OP_COND_EXPR;
+    logop->op_ppaddr = PL_ppaddr[OP_COND_EXPR];
+    logop->op_first = first;
+    logop->op_flags = flags | OPf_KIDS;
+    logop->op_private = 1 | (flags >> 8);
+    logop->op_other = LINKLIST(trueop);
+    logop->op_next = LINKLIST(falseop);
 
-    condop->op_type = OP_COND_EXPR;
-    condop->op_ppaddr = PL_ppaddr[OP_COND_EXPR];
-    condop->op_first = first;
-    condop->op_flags = flags | OPf_KIDS;
-    condop->op_true = LINKLIST(trueop);
-    condop->op_false = LINKLIST(falseop);
-    condop->op_private = 1 | (flags >> 8);
 
     /* establish postfix order */
-    condop->op_next = LINKLIST(first);
-    first->op_next = (OP*)condop;
+    start = LINKLIST(first);
+    first->op_next = (OP*)logop;
 
     first->op_sibling = trueop;
     trueop->op_sibling = falseop;
-    o = newUNOP(OP_NULL, 0, (OP*)condop);
+    o = newUNOP(OP_NULL, 0, (OP*)logop);
 
-    trueop->op_next = o;
-    falseop->op_next = o;
+    trueop->op_next = falseop->op_next = o;
 
+    o->op_next = start;
     return o;
 }
 
@@ -3255,34 +3303,36 @@ OP *
 Perl_newRANGE(pTHX_ I32 flags, OP *left, OP *right)
 {
     dTHR;
-    CONDOP *condop;
+    LOGOP *range;
     OP *flip;
     OP *flop;
+    OP *leftstart;
     OP *o;
 
-    NewOp(1101, condop, 1, CONDOP);
+    NewOp(1101, range, 1, LOGOP);
 
-    condop->op_type = OP_RANGE;
-    condop->op_ppaddr = PL_ppaddr[OP_RANGE];
-    condop->op_first = left;
-    condop->op_flags = OPf_KIDS;
-    condop->op_true = LINKLIST(left);
-    condop->op_false = LINKLIST(right);
-    condop->op_private = 1 | (flags >> 8);
+    range->op_type = OP_RANGE;
+    range->op_ppaddr = PL_ppaddr[OP_RANGE];
+    range->op_first = left;
+    range->op_flags = OPf_KIDS;
+    leftstart = LINKLIST(left);
+    range->op_other = LINKLIST(right);
+    range->op_private = 1 | (flags >> 8);
 
     left->op_sibling = right;
 
-    condop->op_next = (OP*)condop;
-    flip = newUNOP(OP_FLIP, flags, (OP*)condop);
+    range->op_next = (OP*)range;
+    flip = newUNOP(OP_FLIP, flags, (OP*)range);
     flop = newUNOP(OP_FLOP, 0, flip);
     o = newUNOP(OP_NULL, 0, flop);
     linklist(flop);
+    range->op_next = leftstart;
 
     left->op_next = flip;
     right->op_next = flop;
 
-    condop->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
-    sv_upgrade(PAD_SV(condop->op_targ), SVt_PVNV);
+    range->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
+    sv_upgrade(PAD_SV(range->op_targ), SVt_PVNV);
     flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
     sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
 
@@ -3469,7 +3519,7 @@ Perl_newFOROP(pTHX_ I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *blo
            sv = Nullop;
        }
        else
-           croak("Can't use %s for loop variable", PL_op_desc[sv->op_type]);
+           Perl_croak(aTHX_ "Can't use %s for loop variable", PL_op_desc[sv->op_type]);
     }
     else {
 #ifdef USE_THREADS
@@ -3492,7 +3542,7 @@ Perl_newFOROP(pTHX_ I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *blo
         * treated as min/max values by 'pp_iterinit'.
         */
        UNOP* flip = (UNOP*)((UNOP*)((BINOP*)expr)->op_first)->op_first;
-       CONDOP* range = (CONDOP*) flip->op_first;
+       LOGOP* range = (LOGOP*) flip->op_first;
        OP* left  = range->op_first;
        OP* right = left->op_sibling;
        LISTOP* listop;
@@ -3501,8 +3551,8 @@ Perl_newFOROP(pTHX_ I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *blo
        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;
+       listop->op_first->op_next = range->op_next;
+       left->op_next = range->op_other;
        right->op_next = (OP*)listop;
        listop->op_next = listop->op_first;
 
@@ -3574,10 +3624,10 @@ Perl_cv_undef(pTHX_ CV *cv)
     if (!CvXSUB(cv) && CvROOT(cv)) {
 #ifdef USE_THREADS
        if (CvDEPTH(cv) || (CvOWNER(cv) && CvOWNER(cv) != thr))
-           croak("Can't undef active subroutine");
+           Perl_croak(aTHX_ "Can't undef active subroutine");
 #else
        if (CvDEPTH(cv))
-           croak("Can't undef active subroutine");
+           Perl_croak(aTHX_ "Can't undef active subroutine");
 #endif /* USE_THREADS */
        ENTER;
 
@@ -3664,7 +3714,7 @@ cv_dump(CV *cv)
 #endif /* DEBUG_CLOSURES */
 
 STATIC CV *
-cv_clone2(pTHX_ CV *proto, CV *outside)
+S_cv_clone2(pTHX_ CV *proto, CV *outside)
 {
     dTHR;
     AV* av;
@@ -3738,7 +3788,7 @@ cv_clone2(pTHX_ CV *proto, CV *outside)
                if (!off)
                    PL_curpad[ix] = SvREFCNT_inc(ppad[ix]);
                else if (off != ix)
-                   croak("panic: cv_clone: %s", name);
+                   Perl_croak(aTHX_ "panic: cv_clone: %s", name);
            }
            else {                              /* our own lexical */
                SV* sv;
@@ -3808,7 +3858,9 @@ Perl_cv_clone(pTHX_ CV *proto)
 void
 Perl_cv_ckproto(pTHX_ CV *cv, GV *gv, char *p)
 {
-    if ((!p != !SvPOK(cv)) || (p && strNE(p, SvPVX(cv)))) {
+    dTHR;
+
+    if (((!p != !SvPOK(cv)) || (p && strNE(p, SvPVX(cv)))) && ckWARN_d(WARN_UNSAFE)) {
        SV* msg = sv_newmortal();
        SV* name = Nullsv;
 
@@ -3816,15 +3868,15 @@ Perl_cv_ckproto(pTHX_ CV *cv, GV *gv, char *p)
            gv_efullname3(name = sv_newmortal(), gv, Nullch);
        sv_setpv(msg, "Prototype mismatch:");
        if (name)
-           sv_catpvf(msg, " sub %_", name);
+           Perl_sv_catpvf(aTHX_ msg, " sub %_", name);
        if (SvPOK(cv))
-           sv_catpvf(msg, " (%s)", SvPVX(cv));
+           Perl_sv_catpvf(aTHX_ msg, " (%s)", SvPVX(cv));
        sv_catpv(msg, " vs ");
        if (p)
-           sv_catpvf(msg, "(%s)", p);
+           Perl_sv_catpvf(aTHX_ msg, "(%s)", p);
        else
            sv_catpv(msg, "none");
-       warn("%_", msg);
+       Perl_warner(aTHX_ WARN_UNSAFE, "%_", msg);
     }
 }
 
@@ -3850,7 +3902,7 @@ Perl_op_const_sv(pTHX_ OP *o, CV *cv)
     for (; o; o = o->op_next) {
        OPCODE type = o->op_type;
 
-       if(sv && o->op_next == o) 
+       if (sv && o->op_next == o) 
            return sv;
        if (type == OP_NEXTSTATE || type == OP_NULL || type == OP_PUSHMARK)
            continue;
@@ -3894,8 +3946,11 @@ Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block)
     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");
+           if (!SvPOK((SV*)gv) && !(SvIOK((SV*)gv) && SvIVX((SV*)gv) == -1)
+               && ckWARN_d(WARN_UNSAFE))
+           {
+               Perl_warner(aTHX_ WARN_UNSAFE, "Runaway prototype");
+           }
            cv_ckproto((CV*)gv, NULL, ps);
        }
        if (ps)
@@ -3923,7 +3978,7 @@ Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block)
            }
            /* ahem, death to those who redefine active sort subs */
            if (PL_curstackinfo->si_type == PERLSI_SORT && PL_sortcop == CvSTART(cv))
-               croak("Can't redefine active sort subroutine %s", name);
+               Perl_croak(aTHX_ "Can't redefine active sort subroutine %s", name);
            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) 
@@ -3933,7 +3988,7 @@ Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block)
                                                 "autouse"))) {
                line_t oldline = PL_curcop->cop_line;
                PL_curcop->cop_line = PL_copline;
-               warner(WARN_REDEFINE,
+               Perl_warner(aTHX_ WARN_REDEFINE,
                        const_sv ? "Constant subroutine %s redefined"
                                 : "Subroutine %s redefined", name);
                PL_curcop->cop_line = oldline;
@@ -3985,11 +4040,11 @@ Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block)
                char *not_safe =
                    "BEGIN not safe after errors--compilation aborted";
                if (PL_in_eval & EVAL_KEEPERR)
-                   croak(not_safe);
+                   Perl_croak(aTHX_ not_safe);
                else {
                    /* force display of errors found but not reported */
                    sv_catpv(ERRSV, not_safe);
-                   croak("%s", SvPVx(ERRSV, n_a));
+                   Perl_croak(aTHX_ "%s", SvPVx(ERRSV, n_a));
                }
            }
        }
@@ -4055,7 +4110,7 @@ Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block)
            CV *cv;
            HV *hv;
 
-           sv_setpvf(sv, "%_:%ld-%ld",
+           Perl_sv_setpvf(aTHX_ sv, "%_:%ld-%ld",
                    GvSV(PL_curcop->cop_filegv),
                    (long)PL_subline, (long)PL_curcop->cop_line);
            gv_efullname3(tmpstr, gv, Nullch);
@@ -4164,7 +4219,7 @@ Perl_newXS(pTHX_ char *name, XSUBADDR_t subaddr, char *filename)
                line_t oldline = PL_curcop->cop_line;
                if (PL_copline != NOLINE)
                    PL_curcop->cop_line = PL_copline;
-               warner(WARN_REDEFINE, "Subroutine %s redefined",name);
+               Perl_warner(aTHX_ WARN_REDEFINE, "Subroutine %s redefined",name);
                PL_curcop->cop_line = oldline;
            }
            SvREFCNT_dec(cv);
@@ -4245,7 +4300,7 @@ Perl_newFORM(pTHX_ I32 floor, OP *o, OP *block)
            line_t oldline = PL_curcop->cop_line;
 
            PL_curcop->cop_line = PL_copline;
-           warner(WARN_REDEFINE, "Format %s redefined",name);
+           Perl_warner(aTHX_ WARN_REDEFINE, "Format %s redefined",name);
            PL_curcop->cop_line = oldline;
        }
        SvREFCNT_dec(cv);
@@ -4306,7 +4361,8 @@ Perl_oopsAV(pTHX_ OP *o)
        break;
 
     default:
-       warn("oops: oopsAV");
+       if (ckWARN_d(WARN_INTERNAL))
+           Perl_warner(aTHX_ WARN_INTERNAL, "oops: oopsAV");
        break;
     }
     return o;
@@ -4315,6 +4371,8 @@ Perl_oopsAV(pTHX_ OP *o)
 OP *
 Perl_oopsHV(pTHX_ OP *o)
 {
+    dTHR;
+    
     switch (o->op_type) {
     case OP_PADSV:
     case OP_PADAV:
@@ -4330,7 +4388,8 @@ Perl_oopsHV(pTHX_ OP *o)
        break;
 
     default:
-       warn("oops: oopsHV");
+       if (ckWARN_d(WARN_INTERNAL))
+           Perl_warner(aTHX_ WARN_INTERNAL, "oops: oopsHV");
        break;
     }
     return o;
@@ -4369,7 +4428,7 @@ Perl_newHVREF(pTHX_ OP *o)
 OP *
 Perl_oopsCV(pTHX_ OP *o)
 {
-    croak("NOT IMPL LINE %d",__LINE__);
+    Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
     /* STUB */
     return o;
 }
@@ -4398,7 +4457,7 @@ Perl_newSVREF(pTHX_ OP *o)
 /* Check routines. */
 
 OP *
-ck_anoncode(OP *o)
+Perl_ck_anoncode(pTHX_ OP *o)
 {
     PADOFFSET ix;
     SV* name;
@@ -4418,14 +4477,14 @@ ck_anoncode(OP *o)
 }
 
 OP *
-ck_bitop(OP *o)
+Perl_ck_bitop(pTHX_ OP *o)
 {
     o->op_private = PL_hints;
     return o;
 }
 
 OP *
-ck_concat(OP *o)
+Perl_ck_concat(pTHX_ OP *o)
 {
     if (cUNOPo->op_first->op_type == OP_CONCAT)
        o->op_flags |= OPf_STACKED;
@@ -4433,7 +4492,7 @@ ck_concat(OP *o)
 }
 
 OP *
-ck_spair(OP *o)
+Perl_ck_spair(pTHX_ OP *o)
 {
     if (o->op_flags & OPf_KIDS) {
        OP* newop;
@@ -4458,7 +4517,7 @@ ck_spair(OP *o)
 }
 
 OP *
-ck_delete(OP *o)
+Perl_ck_delete(pTHX_ OP *o)
 {
     o = ck_fun(o);
     o->op_private = 0;
@@ -4467,7 +4526,7 @@ ck_delete(OP *o)
        if (kid->op_type == OP_HSLICE)
            o->op_private |= OPpSLICE;
        else if (kid->op_type != OP_HELEM)
-           croak("%s argument is not a HASH element or slice",
+           Perl_croak(aTHX_ "%s argument is not a HASH element or slice",
                  PL_op_desc[o->op_type]);
        null(kid);
     }
@@ -4475,7 +4534,7 @@ ck_delete(OP *o)
 }
 
 OP *
-ck_eof(OP *o)
+Perl_ck_eof(pTHX_ OP *o)
 {
     I32 type = o->op_type;
 
@@ -4491,7 +4550,7 @@ ck_eof(OP *o)
 }
 
 OP *
-ck_eval(OP *o)
+Perl_ck_eval(pTHX_ OP *o)
 {
     PL_hints |= HINT_BLOCK_SCOPE;
     if (o->op_flags & OPf_KIDS) {
@@ -4534,7 +4593,7 @@ ck_eval(OP *o)
 }
 
 OP *
-ck_exec(OP *o)
+Perl_ck_exec(pTHX_ OP *o)
 {
     OP *kid;
     if (o->op_flags & OPf_STACKED) {
@@ -4549,13 +4608,13 @@ ck_exec(OP *o)
 }
 
 OP *
-ck_exists(OP *o)
+Perl_ck_exists(pTHX_ OP *o)
 {
     o = ck_fun(o);
     if (o->op_flags & OPf_KIDS) {
        OP *kid = cUNOPo->op_first;
        if (kid->op_type != OP_HELEM)
-           croak("%s argument is not a HASH element", PL_op_desc[o->op_type]);
+           Perl_croak(aTHX_ "%s argument is not a HASH element", PL_op_desc[o->op_type]);
        null(kid);
     }
     return o;
@@ -4563,7 +4622,7 @@ ck_exists(OP *o)
 
 #if 0
 OP *
-ck_gvconst(register OP *o)
+Perl_ck_gvconst(pTHX_ register OP *o)
 {
     o = fold_constants(o);
     if (o->op_type == OP_CONST)
@@ -4573,7 +4632,7 @@ ck_gvconst(register OP *o)
 #endif
 
 OP *
-ck_rvconst(register OP *o)
+Perl_ck_rvconst(pTHX_ register OP *o)
 {
     dTHR;
     SVOP *kid = (SVOP*)cUNOPo->op_first;
@@ -4620,7 +4679,7 @@ ck_rvconst(register OP *o)
                break;
            }
            if (badtype)
-               croak("Constant is not %s reference", badtype);
+               Perl_croak(aTHX_ "Constant is not %s reference", badtype);
            return o;
        }
        name = SvPV(kidsv, n_a);
@@ -4638,7 +4697,7 @@ ck_rvconst(register OP *o)
                break;
            }
            if (badthing)
-               croak(
+               Perl_croak(aTHX_ 
          "Can't use bareword (\"%s\") as %s ref while \"strict refs\" in use",
                      name, badthing);
        }
@@ -4668,13 +4727,14 @@ ck_rvconst(register OP *o)
            kid->op_type = OP_GV;
            SvREFCNT_dec(kid->op_sv);
            kid->op_sv = SvREFCNT_inc(gv);
+           kid->op_ppaddr = PL_ppaddr[OP_GV];
        }
     }
     return o;
 }
 
 OP *
-ck_ftst(OP *o)
+Perl_ck_ftst(pTHX_ OP *o)
 {
     dTHR;
     I32 type = o->op_type;
@@ -4705,7 +4765,7 @@ ck_ftst(OP *o)
 }
 
 OP *
-ck_fun(OP *o)
+Perl_ck_fun(pTHX_ OP *o)
 {
     dTHR;
     register OP *kid;
@@ -4764,7 +4824,7 @@ ck_fun(OP *o)
                    OP *newop = newAVREF(newGVOP(OP_GV, 0,
                        gv_fetchpv(name, TRUE, SVt_PVAV) ));
                    if (ckWARN(WARN_SYNTAX))
-                       warner(WARN_SYNTAX,
+                       Perl_warner(aTHX_ WARN_SYNTAX,
                            "Array @%s missing the @ in argument %ld of %s()",
                            name, (long)numargs, PL_op_desc[type]);
                    op_free(kid);
@@ -4784,7 +4844,7 @@ ck_fun(OP *o)
                    OP *newop = newHVREF(newGVOP(OP_GV, 0,
                        gv_fetchpv(name, TRUE, SVt_PVHV) ));
                    if (ckWARN(WARN_SYNTAX))
-                       warner(WARN_SYNTAX,
+                       Perl_warner(aTHX_ WARN_SYNTAX,
                            "Hash %%%s missing the %% in argument %ld of %s()",
                            name, (long)numargs, PL_op_desc[type]);
                    op_free(kid);
@@ -4879,7 +4939,7 @@ ck_fun(OP *o)
 }
 
 OP *
-ck_glob(OP *o)
+Perl_ck_glob(pTHX_ OP *o)
 {
     GV *gv;
 
@@ -4912,7 +4972,7 @@ ck_glob(OP *o)
 }
 
 OP *
-ck_grep(OP *o)
+Perl_ck_grep(pTHX_ OP *o)
 {
     LOGOP *gwop;
     OP *kid;
@@ -4941,7 +5001,7 @@ ck_grep(OP *o)
        return o;
     kid = cLISTOPo->op_first->op_sibling;
     if (kid->op_type != OP_NULL)
-       croak("panic: ck_grep");
+       Perl_croak(aTHX_ "panic: ck_grep");
     kid = kUNOP->op_first;
 
     gwop->op_type = type;
@@ -4963,7 +5023,7 @@ ck_grep(OP *o)
 }
 
 OP *
-ck_index(OP *o)
+Perl_ck_index(pTHX_ OP *o)
 {
     if (o->op_flags & OPf_KIDS) {
        OP *kid = cLISTOPo->op_first->op_sibling;       /* get past pushmark */
@@ -4976,53 +5036,57 @@ ck_index(OP *o)
 }
 
 OP *
-ck_lengthconst(OP *o)
+Perl_ck_lengthconst(pTHX_ OP *o)
 {
     /* XXX length optimization goes here */
     return ck_fun(o);
 }
 
 OP *
-ck_lfun(OP *o)
+Perl_ck_lfun(pTHX_ OP *o)
 {
     OPCODE type = o->op_type;
     return modkids(ck_fun(o), type);
 }
 
 OP *
-ck_defined(OP *o)              /* 19990527 MJD */
+Perl_ck_defined(pTHX_ OP *o)           /* 19990527 MJD */
 {
     dTHR;
-    if (ckWARN(WARN_DEPRECATED)) {
-      switch (cUNOPo->op_first->op_type) {
-      case OP_RV2AV:
-      case OP_PADAV:
-      case OP_AASSIGN:         /* Is this a good idea? */
-       warner(WARN_DEPRECATED, "defined(@array) is deprecated (and not really meaningful)");
-       warner(WARN_DEPRECATED, "(Maybe you should just omit the defined()?)\n");
-       break;
-      case OP_RV2HV:
-      case OP_PADHV:
-       warner(WARN_DEPRECATED, "defined(%hash) is deprecated (and not really meaningful)");
-       warner(WARN_DEPRECATED, "(Maybe you should just omit the defined()?)\n");
-       break;
-      default:
-       /* no warning */
+    if ((o->op_flags & OPf_KIDS) && ckWARN(WARN_DEPRECATED)) {
+       switch (cUNOPo->op_first->op_type) {
+       case OP_RV2AV:
+       case OP_PADAV:
+       case OP_AASSIGN:                /* Is this a good idea? */
+           Perl_warner(aTHX_ WARN_DEPRECATED,
+                       "defined(@array) is deprecated");
+           Perl_warner(aTHX_ WARN_DEPRECATED,
+                       "(Maybe you should just omit the defined()?)\n");
        break;
-      }
+       case OP_RV2HV:
+       case OP_PADHV:
+           Perl_warner(aTHX_ WARN_DEPRECATED,
+                       "defined(%hash) is deprecated");
+           Perl_warner(aTHX_ WARN_DEPRECATED,
+                       "(Maybe you should just omit the defined()?)\n");
+           break;
+       default:
+           /* no warning */
+           break;
+       }
     }
     return ck_rfun(o);
 }
 
 OP *
-ck_rfun(OP *o)
+Perl_ck_rfun(pTHX_ OP *o)
 {
     OPCODE type = o->op_type;
     return refkids(ck_fun(o), type);
 }
 
 OP *
-ck_listiob(OP *o)
+Perl_ck_listiob(pTHX_ OP *o)
 {
     register OP *kid;
 
@@ -5060,7 +5124,7 @@ ck_listiob(OP *o)
 }
 
 OP *
-ck_fun_locale(OP *o)
+Perl_ck_fun_locale(pTHX_ OP *o)
 {
     o = ck_fun(o);
 
@@ -5074,7 +5138,39 @@ ck_fun_locale(OP *o)
 }
 
 OP *
-ck_scmp(OP *o)
+Perl_ck_sassign(pTHX_ OP *o)
+{
+    OP *kid = cLISTOPo->op_first;
+    /* has a disposable target? */
+    if ((PL_opargs[kid->op_type] & OA_TARGLEX)
+       && !(kid->op_flags & OPf_STACKED))
+    {
+       OP *kkid = kid->op_sibling;
+
+       /* Can just relocate the target. */
+       if (kkid && kkid->op_type == OP_PADSV) {
+           /* Concat has problems if target is equal to right arg. */
+           if (kid->op_type == OP_CONCAT
+               && kLISTOP->op_first->op_sibling->op_type == OP_PADSV
+               && kLISTOP->op_first->op_sibling->op_targ == kkid->op_targ)
+           {
+               return o;
+           }
+           kid->op_targ = kkid->op_targ;
+           /* Now we do not need PADSV and SASSIGN. */
+           kid->op_sibling = o->op_sibling;    /* NULL */
+           cLISTOPo->op_first = NULL;
+           op_free(o);
+           op_free(kkid);
+           kid->op_private |= OPpTARGET_MY;    /* Used for context settings */
+           return kid;
+       }
+    }
+    return o;
+}
+
+OP *
+Perl_ck_scmp(pTHX_ OP *o)
 {
     o->op_private = 0;
 #ifdef USE_LOCALE
@@ -5086,20 +5182,20 @@ ck_scmp(OP *o)
 }
 
 OP *
-ck_match(OP *o)
+Perl_ck_match(pTHX_ OP *o)
 {
     o->op_private |= OPpRUNTIME;
     return o;
 }
 
 OP *
-ck_null(OP *o)
+Perl_ck_null(pTHX_ OP *o)
 {
     return o;
 }
 
 OP *
-ck_repeat(OP *o)
+Perl_ck_repeat(pTHX_ OP *o)
 {
     if (cBINOPo->op_first->op_flags & OPf_PARENS) {
        o->op_private |= OPpREPEAT_DOLIST;
@@ -5111,7 +5207,7 @@ ck_repeat(OP *o)
 }
 
 OP *
-ck_require(OP *o)
+Perl_ck_require(pTHX_ OP *o)
 {
     if (o->op_flags & OPf_KIDS) {      /* Shall we supply missing .pm? */
        SVOP *kid = (SVOP*)cUNOPo->op_first;
@@ -5133,16 +5229,16 @@ ck_require(OP *o)
 
 #if 0
 OP *
-ck_retarget(OP *o)
+Perl_ck_retarget(pTHX_ OP *o)
 {
-    croak("NOT IMPL LINE %d",__LINE__);
+    Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
     /* STUB */
     return o;
 }
 #endif
 
 OP *
-ck_select(OP *o)
+Perl_ck_select(pTHX_ OP *o)
 {
     OP* kid;
     if (o->op_flags & OPf_KIDS) {
@@ -5162,7 +5258,7 @@ ck_select(OP *o)
 }
 
 OP *
-ck_shift(OP *o)
+Perl_ck_shift(pTHX_ OP *o)
 {
     I32 type = o->op_type;
 
@@ -5191,7 +5287,7 @@ ck_shift(OP *o)
 }
 
 OP *
-ck_sort(OP *o)
+Perl_ck_sort(pTHX_ OP *o)
 {
     o->op_private = 0;
 #ifdef USE_LOCALE
@@ -5243,7 +5339,7 @@ ck_sort(OP *o)
 }
 
 STATIC void
-simplify_sort(pTHX_ OP *o)
+S_simplify_sort(pTHX_ OP *o)
 {
     dTHR;
     register OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
@@ -5305,7 +5401,7 @@ simplify_sort(pTHX_ OP *o)
 }
 
 OP *
-ck_split(OP *o)
+Perl_ck_split(pTHX_ OP *o)
 {
     register OP *kid;
 
@@ -5314,7 +5410,7 @@ ck_split(OP *o)
 
     kid = cLISTOPo->op_first;
     if (kid->op_type != OP_NULL)
-       croak("panic: ck_split");
+       Perl_croak(aTHX_ "panic: ck_split");
     kid = kid->op_sibling;
     op_free(cLISTOPo->op_first);
     cLISTOPo->op_first = kid;
@@ -5356,7 +5452,7 @@ ck_split(OP *o)
 }
 
 OP *
-ck_subr(OP *o)
+Perl_ck_subr(pTHX_ OP *o)
 {
     dTHR;
     OP *prev = ((cUNOPo->op_first->op_sibling)
@@ -5376,9 +5472,11 @@ ck_subr(OP *o)
        o->op_private |= (cvop->op_private & OPpENTERSUB_AMPER);
        null(cvop);             /* disable rv2cv */
        tmpop = (SVOP*)((UNOP*)cvop)->op_first;
-       if (tmpop->op_type == OP_GV) {
+       if (tmpop->op_type == OP_GV && !(o->op_private & OPpENTERSUB_AMPER)) {
            cv = GvCVu(tmpop->op_sv);
-           if (cv && SvPOK(cv) && !(o->op_private & OPpENTERSUB_AMPER)) {
+           if (!cv)
+               tmpop->op_private |= OPpEARLY_CV;
+           else if (SvPOK(cv)) {
                namegv = CvANON(cv) ? (GV*)tmpop->op_sv : CvGV(cv);
                proto = SvPV((SV*)cv, n_a);
            }
@@ -5473,6 +5571,8 @@ ck_subr(OP *o)
                case '$':
                    if (o2->op_type != OP_RV2SV
                        && o2->op_type != OP_PADSV
+                       && o2->op_type != OP_HELEM
+                       && o2->op_type != OP_AELEM
                        && o2->op_type != OP_THREADSV)
                    {
                        bad_type(arg, "scalar", gv_ename(namegv), o2);
@@ -5503,7 +5603,7 @@ ck_subr(OP *o)
                continue;
            default:
              oops:
-               croak("Malformed prototype for %s: %s",
+               Perl_croak(aTHX_ "Malformed prototype for %s: %s",
                        gv_ename(namegv), SvPV((SV*)cv, n_a));
            }
        }
@@ -5520,23 +5620,26 @@ ck_subr(OP *o)
 }
 
 OP *
-ck_svconst(OP *o)
+Perl_ck_svconst(pTHX_ OP *o)
 {
     SvREADONLY_on(cSVOPo->op_sv);
     return o;
 }
 
 OP *
-ck_trunc(OP *o)
+Perl_ck_trunc(pTHX_ OP *o)
 {
     if (o->op_flags & OPf_KIDS) {
        SVOP *kid = (SVOP*)cUNOPo->op_first;
 
        if (kid->op_type == OP_NULL)
            kid = (SVOP*)kid->op_sibling;
-       if (kid &&
-         kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE))
+       if (kid && kid->op_type == OP_CONST &&
+           (kid->op_private & OPpCONST_BARE))
+       {
            o->op_flags |= OPf_SPECIAL;
+           kid->op_private &= ~OPpCONST_STRICT;
+       }
     }
     return ck_fun(o);
 }
@@ -5562,6 +5665,7 @@ Perl_peep(pTHX_ register OP *o)
            PL_op_seqmax++;
        PL_op = o;
        switch (o->op_type) {
+       case OP_SETSTATE:
        case OP_NEXTSTATE:
        case OP_DBSTATE:
            PL_curcop = ((COP*)o);              /* for warnings */
@@ -5572,15 +5676,35 @@ Perl_peep(pTHX_ register OP *o)
            if (cSVOPo->op_private & OPpCONST_STRICT)
                no_bareword_allowed(o);
            /* FALL THROUGH */
-       case OP_CONCAT:
-       case OP_JOIN:
        case OP_UC:
        case OP_UCFIRST:
        case OP_LC:
        case OP_LCFIRST:
+           if ( o->op_next && o->op_next->op_type == OP_STRINGIFY
+                && !(o->op_next->op_private & OPpTARGET_MY) )
+               null(o->op_next);
+           o->op_seq = PL_op_seqmax++;
+           break;
+       case OP_CONCAT:
+       case OP_JOIN:
        case OP_QUOTEMETA:
-           if (o->op_next && o->op_next->op_type == OP_STRINGIFY)
+           if (o->op_next && o->op_next->op_type == OP_STRINGIFY) {
+               if (o->op_next->op_private & OPpTARGET_MY) {
+                   if ((o->op_flags & OPf_STACKED) /* chained concats */
+                       || (o->op_type == OP_CONCAT
+           /* Concat has problems if target is equal to right arg. */
+                           && (((LISTOP*)o)->op_first->op_sibling->op_type
+                               == OP_PADSV)
+                           && (((LISTOP*)o)->op_first->op_sibling->op_targ
+                               == o->op_next->op_targ))) {
+                       goto ignore_optimization;
+                   } else {
+                       o->op_targ = o->op_next->op_targ;
+                   }
+               }
                null(o->op_next);
+           }
+         ignore_optimization:
            o->op_seq = PL_op_seqmax++;
            break;
        case OP_STUB:
@@ -5590,8 +5714,12 @@ Perl_peep(pTHX_ register OP *o)
            }
            goto nothin;
        case OP_NULL:
-           if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE)
+           if (o->op_targ == OP_NEXTSTATE
+               || o->op_targ == OP_DBSTATE
+               || o->op_targ == OP_SETSTATE)
+           {
                PL_curcop = ((COP*)o);
+           }
            goto nothin;
        case OP_SCALAR:
        case OP_LINESEQ:
@@ -5626,7 +5754,6 @@ Perl_peep(pTHX_ register OP *o)
                                <= 255 &&
                    i >= 0)
                {
-                   SvREFCNT_dec(((SVOP*)pop)->op_sv);
                    null(o->op_next);
                    null(pop->op_next);
                    null(pop);
@@ -5638,6 +5765,18 @@ Perl_peep(pTHX_ register OP *o)
                    GvAVn(((GVOP*)o)->op_gv);
                }
            }
+           else if ((o->op_private & OPpEARLY_CV) && ckWARN(WARN_UNSAFE)) {
+               GV *gv = cGVOPo->op_gv;
+               if (SvTYPE(gv) == SVt_PVGV && GvCV(gv) && SvPVX(GvCV(gv))) {
+                   /* XXX could check prototype here instead of just carping */
+                   SV *sv = sv_newmortal();
+                   gv_efullname3(sv, gv, Nullch);
+                   Perl_warner(aTHX_ WARN_UNSAFE,
+                               "%s() called too early to check prototype",
+                               SvPV_nolen(sv));
+               }
+           }
+
            o->op_seq = PL_op_seqmax++;
            break;
 
@@ -5645,18 +5784,14 @@ Perl_peep(pTHX_ register OP *o)
        case OP_GREPWHILE:
        case OP_AND:
        case OP_OR:
+       case OP_COND_EXPR:
+       case OP_RANGE:
            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 = PL_op_seqmax++;
-           peep(cCONDOP->op_true);
-           peep(cCONDOP->op_false);
-           break;
-
        case OP_ENTERLOOP:
            o->op_seq = PL_op_seqmax++;
            peep(cLOOP->op_redoop);
@@ -5682,8 +5817,8 @@ Perl_peep(pTHX_ register OP *o)
                    line_t oldline = PL_curcop->cop_line;
 
                    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");
+                   Perl_warner(aTHX_ WARN_SYNTAX, "Statement unlikely to be reached");
+                   Perl_warner(aTHX_ WARN_SYNTAX, "(Maybe you meant system() when you said exec()?)\n");
                    PL_curcop->cop_line = oldline;
                }
            }
@@ -5714,12 +5849,12 @@ Perl_peep(pTHX_ register OP *o)
            key = SvPV(*svp, keylen);
            indsvp = hv_fetch(GvHV(*fields), key, keylen, FALSE);
            if (!indsvp) {
-               croak("No such field \"%s\" in variable %s of type %s",
+               Perl_croak(aTHX_ "No such field \"%s\" in variable %s of type %s",
                      key, SvPV(lexname, n_a), HvNAME(SvSTASH(lexname)));
            }
            ind = SvIV(*indsvp);
            if (ind < 1)
-               croak("Bad index while coercing array into hash");
+               Perl_croak(aTHX_ "Bad index while coercing array into hash");
            rop->op_type = OP_RV2AV;
            rop->op_ppaddr = PL_ppaddr[OP_RV2AV];
            o->op_type = OP_AELEM;