3 * Copyright (c) 1991-2000, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 * "You see: Mr. Drogo, he married poor Miss Primula Brandybuck. She was
12 * our Mr. Bilbo's first cousin on the mother's side (her mother being the
13 * youngest of the Old Took's daughters); and Mr. Drogo was his second
14 * cousin. So Mr. Frodo is his first *and* second cousin, once removed
15 * either way, as the saying is, if you follow me." --the Gaffer
23 /* #define PL_OP_SLAB_ALLOC */
25 #ifdef PL_OP_SLAB_ALLOC
26 #define SLAB_SIZE 8192
27 static char *PL_OpPtr = NULL;
28 static int PL_OpSpace = 0;
29 #define NewOp(m,var,c,type) do { if ((PL_OpSpace -= c*sizeof(type)) >= 0) \
30 var = (type *)(PL_OpPtr -= c*sizeof(type)); \
32 var = (type *) Slab_Alloc(m,c*sizeof(type)); \
36 S_Slab_Alloc(pTHX_ int m, size_t sz)
38 Newz(m,PL_OpPtr,SLAB_SIZE,char);
39 PL_OpSpace = SLAB_SIZE - sz;
40 return PL_OpPtr += PL_OpSpace;
44 #define NewOp(m, var, c, type) Newz(m, var, c, type)
47 * In the following definition, the ", Nullop" is just to make the compiler
48 * think the expression is of the right type: croak actually does a Siglongjmp.
50 #define CHECKOP(type,o) \
51 ((PL_op_mask && PL_op_mask[type]) \
52 ? ( op_free((OP*)o), \
53 Perl_croak(aTHX_ "%s trapped by operation mask", PL_op_desc[type]), \
55 : CALL_FPTR(PL_check[type])(aTHX_ (OP*)o))
57 #define PAD_MAX 999999999
60 S_gv_ename(pTHX_ GV *gv)
63 SV* tmpsv = sv_newmortal();
64 gv_efullname3(tmpsv, gv, Nullch);
65 return SvPV(tmpsv,n_a);
69 S_no_fh_allowed(pTHX_ OP *o)
71 yyerror(Perl_form(aTHX_ "Missing comma after first argument to %s function",
72 PL_op_desc[o->op_type]));
77 S_too_few_arguments(pTHX_ OP *o, char *name)
79 yyerror(Perl_form(aTHX_ "Not enough arguments for %s", name));
84 S_too_many_arguments(pTHX_ OP *o, char *name)
86 yyerror(Perl_form(aTHX_ "Too many arguments for %s", name));
91 S_bad_type(pTHX_ I32 n, char *t, char *name, OP *kid)
93 yyerror(Perl_form(aTHX_ "Type of arg %d to %s must be %s (not %s)",
94 (int)n, name, t, PL_op_desc[kid->op_type]));
98 S_no_bareword_allowed(pTHX_ OP *o)
100 qerror(Perl_mess(aTHX_
101 "Bareword \"%s\" not allowed while \"strict subs\" in use",
102 SvPV_nolen(cSVOPo_sv)));
105 /* "register" allocation */
108 Perl_pad_allocmy(pTHX_ char *name)
114 if (!(PL_in_my == KEY_our ||
116 (PL_hints & HINT_UTF8 && (name[1] & 0xc0) == 0xc0) ||
117 (name[1] == '_' && (int)strlen(name) > 2)))
119 if (!isPRINT(name[1]) || strchr("\t\n\r\f", name[1])) {
120 /* 1999-02-27 mjd@plover.com */
122 p = strchr(name, '\0');
123 /* The next block assumes the buffer is at least 205 chars
124 long. At present, it's always at least 256 chars. */
126 strcpy(name+200, "...");
132 /* Move everything else down one character */
133 for (; p-name > 2; p--)
135 name[2] = toCTRL(name[1]);
138 yyerror(Perl_form(aTHX_ "Can't use global %s in \"my\"",name));
140 if (ckWARN(WARN_MISC) && AvFILLp(PL_comppad_name) >= 0) {
141 SV **svp = AvARRAY(PL_comppad_name);
142 HV *ourstash = (PL_curstash ? PL_curstash : PL_defstash);
143 PADOFFSET top = AvFILLp(PL_comppad_name);
144 for (off = top; off > PL_comppad_name_floor; off--) {
146 && sv != &PL_sv_undef
147 && (SvIVX(sv) == PAD_MAX || SvIVX(sv) == 0)
148 && (PL_in_my != KEY_our
149 || ((SvFLAGS(sv) & SVpad_OUR) && GvSTASH(sv) == ourstash))
150 && strEQ(name, SvPVX(sv)))
152 Perl_warner(aTHX_ WARN_MISC,
153 "\"%s\" variable %s masks earlier declaration in same %s",
154 (PL_in_my == KEY_our ? "our" : "my"),
156 (SvIVX(sv) == PAD_MAX ? "scope" : "statement"));
161 if (PL_in_my == KEY_our) {
164 && sv != &PL_sv_undef
165 && ((SvFLAGS(sv) & SVpad_OUR) && GvSTASH(sv) == ourstash)
166 && strEQ(name, SvPVX(sv)))
168 Perl_warner(aTHX_ WARN_MISC,
169 "\"our\" variable %s redeclared", name);
170 Perl_warner(aTHX_ WARN_MISC,
171 "(Did you mean \"local\" instead of \"our\"?)\n");
178 off = pad_alloc(OP_PADSV, SVs_PADMY);
180 sv_upgrade(sv, SVt_PVNV);
182 if (PL_in_my_stash) {
184 yyerror(Perl_form(aTHX_ "Can't declare class for non-scalar %s in \"%s\"",
185 name, PL_in_my == KEY_our ? "our" : "my"));
187 (void)SvUPGRADE(sv, SVt_PVMG);
188 SvSTASH(sv) = (HV*)SvREFCNT_inc(PL_in_my_stash);
191 if (PL_in_my == KEY_our) {
192 (void)SvUPGRADE(sv, SVt_PVGV);
193 GvSTASH(sv) = (HV*)SvREFCNT_inc(PL_curstash ? (SV*)PL_curstash : (SV*)PL_defstash);
194 SvFLAGS(sv) |= SVpad_OUR;
196 av_store(PL_comppad_name, off, sv);
197 SvNVX(sv) = (NV)PAD_MAX;
198 SvIVX(sv) = 0; /* Not yet introduced--see newSTATEOP */
199 if (!PL_min_intro_pending)
200 PL_min_intro_pending = off;
201 PL_max_intro_pending = off;
203 av_store(PL_comppad, off, (SV*)newAV());
204 else if (*name == '%')
205 av_store(PL_comppad, off, (SV*)newHV());
206 SvPADMY_on(PL_curpad[off]);
211 S_pad_addlex(pTHX_ SV *proto_namesv)
213 SV *namesv = NEWSV(1103,0);
214 PADOFFSET newoff = pad_alloc(OP_PADSV, SVs_PADMY);
215 sv_upgrade(namesv, SVt_PVNV);
216 sv_setpv(namesv, SvPVX(proto_namesv));
217 av_store(PL_comppad_name, newoff, namesv);
218 SvNVX(namesv) = (NV)PL_curcop->cop_seq;
219 SvIVX(namesv) = PAD_MAX; /* A ref, intro immediately */
220 SvFAKE_on(namesv); /* A ref, not a real var */
221 if (SvFLAGS(proto_namesv) & SVpad_OUR) { /* An "our" variable */
222 SvFLAGS(namesv) |= SVpad_OUR;
223 (void)SvUPGRADE(namesv, SVt_PVGV);
224 GvSTASH(namesv) = (HV*)SvREFCNT_inc((SV*)GvSTASH(proto_namesv));
226 if (SvOBJECT(proto_namesv)) { /* A typed var */
228 (void)SvUPGRADE(namesv, SVt_PVMG);
229 SvSTASH(namesv) = (HV*)SvREFCNT_inc((SV*)SvSTASH(proto_namesv));
235 #define FINDLEX_NOSEARCH 1 /* don't search outer contexts */
238 S_pad_findlex(pTHX_ char *name, PADOFFSET newoff, U32 seq, CV* startcv,
239 I32 cx_ix, I32 saweval, U32 flags)
246 register PERL_CONTEXT *cx;
248 for (cv = startcv; cv; cv = CvOUTSIDE(cv)) {
249 AV *curlist = CvPADLIST(cv);
250 SV **svp = av_fetch(curlist, 0, FALSE);
253 if (!svp || *svp == &PL_sv_undef)
256 svp = AvARRAY(curname);
257 for (off = AvFILLp(curname); off > 0; off--) {
258 if ((sv = svp[off]) &&
259 sv != &PL_sv_undef &&
261 seq > I_32(SvNVX(sv)) &&
262 strEQ(SvPVX(sv), name))
273 return 0; /* don't clone from inactive stack frame */
277 oldpad = (AV*)AvARRAY(curlist)[depth];
278 oldsv = *av_fetch(oldpad, off, TRUE);
279 if (!newoff) { /* Not a mere clone operation. */
280 newoff = pad_addlex(sv);
281 if (CvANON(PL_compcv) || SvTYPE(PL_compcv) == SVt_PVFM) {
282 /* "It's closures all the way down." */
283 CvCLONE_on(PL_compcv);
285 if (CvANON(PL_compcv))
286 oldsv = Nullsv; /* no need to keep ref */
291 bcv && bcv != cv && !CvCLONE(bcv);
292 bcv = CvOUTSIDE(bcv))
295 /* install the missing pad entry in intervening
296 * nested subs and mark them cloneable.
297 * XXX fix pad_foo() to not use globals */
298 AV *ocomppad_name = PL_comppad_name;
299 AV *ocomppad = PL_comppad;
300 SV **ocurpad = PL_curpad;
301 AV *padlist = CvPADLIST(bcv);
302 PL_comppad_name = (AV*)AvARRAY(padlist)[0];
303 PL_comppad = (AV*)AvARRAY(padlist)[1];
304 PL_curpad = AvARRAY(PL_comppad);
306 PL_comppad_name = ocomppad_name;
307 PL_comppad = ocomppad;
312 if (ckWARN(WARN_CLOSURE)
313 && !CvUNIQUE(bcv) && !CvUNIQUE(cv))
315 Perl_warner(aTHX_ WARN_CLOSURE,
316 "Variable \"%s\" may be unavailable",
324 else if (!CvUNIQUE(PL_compcv)) {
325 if (ckWARN(WARN_CLOSURE) && !SvFAKE(sv) && !CvUNIQUE(cv))
326 Perl_warner(aTHX_ WARN_CLOSURE,
327 "Variable \"%s\" will not stay shared", name);
330 av_store(PL_comppad, newoff, SvREFCNT_inc(oldsv));
336 if (flags & FINDLEX_NOSEARCH)
339 /* Nothing in current lexical context--try eval's context, if any.
340 * This is necessary to let the perldb get at lexically scoped variables.
341 * XXX This will also probably interact badly with eval tree caching.
344 for (i = cx_ix; i >= 0; i--) {
346 switch (CxTYPE(cx)) {
348 if (i == 0 && saweval) {
349 seq = cxstack[saweval].blk_oldcop->cop_seq;
350 return pad_findlex(name, newoff, seq, PL_main_cv, -1, saweval, 0);
354 switch (cx->blk_eval.old_op_type) {
360 /* require must have its own scope */
369 if (PL_debstash && CvSTASH(cv) == PL_debstash) { /* ignore DB'* scope */
370 saweval = i; /* so we know where we were called from */
373 seq = cxstack[saweval].blk_oldcop->cop_seq;
374 return pad_findlex(name, newoff, seq, cv, i-1, saweval,FINDLEX_NOSEARCH);
382 Perl_pad_findmy(pTHX_ char *name)
388 SV **svp = AvARRAY(PL_comppad_name);
389 U32 seq = PL_cop_seqmax;
395 * Special case to get lexical (and hence per-thread) @_.
396 * XXX I need to find out how to tell at parse-time whether use
397 * of @_ should refer to a lexical (from a sub) or defgv (global
398 * scope and maybe weird sub-ish things like formats). See
399 * startsub in perly.y. It's possible that @_ could be lexical
400 * (at least from subs) even in non-threaded perl.
402 if (strEQ(name, "@_"))
403 return 0; /* success. (NOT_IN_PAD indicates failure) */
404 #endif /* USE_THREADS */
406 /* The one we're looking for is probably just before comppad_name_fill. */
407 for (off = AvFILLp(PL_comppad_name); off > 0; off--) {
408 if ((sv = svp[off]) &&
409 sv != &PL_sv_undef &&
412 seq > I_32(SvNVX(sv)))) &&
413 strEQ(SvPVX(sv), name))
415 if (SvIVX(sv) || SvFLAGS(sv) & SVpad_OUR)
416 return (PADOFFSET)off;
417 pendoff = off; /* this pending def. will override import */
421 outside = CvOUTSIDE(PL_compcv);
423 /* Check if if we're compiling an eval'', and adjust seq to be the
424 * eval's seq number. This depends on eval'' having a non-null
425 * CvOUTSIDE() while it is being compiled. The eval'' itself is
426 * identified by CvEVAL being true and CvGV being null. */
427 if (outside && CvEVAL(PL_compcv) && !CvGV(PL_compcv) && cxstack_ix >= 0) {
428 cx = &cxstack[cxstack_ix];
430 seq = cx->blk_oldcop->cop_seq;
433 /* See if it's in a nested scope */
434 off = pad_findlex(name, 0, seq, outside, cxstack_ix, 0, 0);
436 /* If there is a pending local definition, this new alias must die */
438 SvIVX(AvARRAY(PL_comppad_name)[off]) = seq;
439 return off; /* pad_findlex returns 0 for failure...*/
441 return NOT_IN_PAD; /* ...but we return NOT_IN_PAD for failure */
445 Perl_pad_leavemy(pTHX_ I32 fill)
449 SV **svp = AvARRAY(PL_comppad_name);
451 if (PL_min_intro_pending && fill < PL_min_intro_pending) {
452 for (off = PL_max_intro_pending; off >= PL_min_intro_pending; off--) {
453 if ((sv = svp[off]) && sv != &PL_sv_undef && ckWARN_d(WARN_INTERNAL))
454 Perl_warner(aTHX_ WARN_INTERNAL, "%s never introduced", SvPVX(sv));
457 /* "Deintroduce" my variables that are leaving with this scope. */
458 for (off = AvFILLp(PL_comppad_name); off > fill; off--) {
459 if ((sv = svp[off]) && sv != &PL_sv_undef && SvIVX(sv) == PAD_MAX)
460 SvIVX(sv) = PL_cop_seqmax;
465 Perl_pad_alloc(pTHX_ I32 optype, U32 tmptype)
471 if (AvARRAY(PL_comppad) != PL_curpad)
472 Perl_croak(aTHX_ "panic: pad_alloc");
473 if (PL_pad_reset_pending)
475 if (tmptype & SVs_PADMY) {
477 sv = *av_fetch(PL_comppad, AvFILLp(PL_comppad) + 1, TRUE);
478 } while (SvPADBUSY(sv)); /* need a fresh one */
479 retval = AvFILLp(PL_comppad);
482 SV **names = AvARRAY(PL_comppad_name);
483 SSize_t names_fill = AvFILLp(PL_comppad_name);
486 * "foreach" index vars temporarily become aliases to non-"my"
487 * values. Thus we must skip, not just pad values that are
488 * marked as current pad values, but also those with names.
490 if (++PL_padix <= names_fill &&
491 (sv = names[PL_padix]) && sv != &PL_sv_undef)
493 sv = *av_fetch(PL_comppad, PL_padix, TRUE);
494 if (!(SvFLAGS(sv) & (SVs_PADTMP|SVs_PADMY)) && !IS_PADGV(sv))
499 SvFLAGS(sv) |= tmptype;
500 PL_curpad = AvARRAY(PL_comppad);
502 DEBUG_X(PerlIO_printf(Perl_debug_log,
503 "0x%"UVxf" Pad 0x%"UVxf" alloc %ld for %s\n",
504 PTR2UV(thr), PTR2UV(PL_curpad),
505 (long) retval, PL_op_name[optype]));
507 DEBUG_X(PerlIO_printf(Perl_debug_log,
508 "Pad 0x%"UVxf" alloc %ld for %s\n",
510 (long) retval, PL_op_name[optype]));
511 #endif /* USE_THREADS */
512 return (PADOFFSET)retval;
516 Perl_pad_sv(pTHX_ PADOFFSET po)
520 DEBUG_X(PerlIO_printf(Perl_debug_log,
521 "0x%"UVxf" Pad 0x%"UVxf" sv %"IVdf"\n",
522 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
525 Perl_croak(aTHX_ "panic: pad_sv po");
526 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" sv %"IVdf"\n",
527 PTR2UV(PL_curpad), (IV)po));
528 #endif /* USE_THREADS */
529 return PL_curpad[po]; /* eventually we'll turn this into a macro */
533 Perl_pad_free(pTHX_ PADOFFSET po)
538 if (AvARRAY(PL_comppad) != PL_curpad)
539 Perl_croak(aTHX_ "panic: pad_free curpad");
541 Perl_croak(aTHX_ "panic: pad_free po");
543 DEBUG_X(PerlIO_printf(Perl_debug_log,
544 "0x%"UVxf" Pad 0x%"UVxf" free %"IVdf"\n",
545 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
547 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" free %"IVdf"\n",
548 PTR2UV(PL_curpad), (IV)po));
549 #endif /* USE_THREADS */
550 if (PL_curpad[po] && PL_curpad[po] != &PL_sv_undef) {
551 SvPADTMP_off(PL_curpad[po]);
553 SvREADONLY_off(PL_curpad[po]); /* could be a freed constant */
556 if ((I32)po < PL_padix)
561 Perl_pad_swipe(pTHX_ PADOFFSET po)
564 if (AvARRAY(PL_comppad) != PL_curpad)
565 Perl_croak(aTHX_ "panic: pad_swipe curpad");
567 Perl_croak(aTHX_ "panic: pad_swipe po");
569 DEBUG_X(PerlIO_printf(Perl_debug_log,
570 "0x%"UVxf" Pad 0x%"UVxf" swipe %"IVdf"\n",
571 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
573 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" swipe %"IVdf"\n",
574 PTR2UV(PL_curpad), (IV)po));
575 #endif /* USE_THREADS */
576 SvPADTMP_off(PL_curpad[po]);
577 PL_curpad[po] = NEWSV(1107,0);
578 SvPADTMP_on(PL_curpad[po]);
579 if ((I32)po < PL_padix)
583 /* XXX pad_reset() is currently disabled because it results in serious bugs.
584 * It causes pad temp TARGs to be shared between OPs. Since TARGs are pushed
585 * on the stack by OPs that use them, there are several ways to get an alias
586 * to a shared TARG. Such an alias will change randomly and unpredictably.
587 * We avoid doing this until we can think of a Better Way.
592 #ifdef USE_BROKEN_PAD_RESET
596 if (AvARRAY(PL_comppad) != PL_curpad)
597 Perl_croak(aTHX_ "panic: pad_reset curpad");
599 DEBUG_X(PerlIO_printf(Perl_debug_log,
600 "0x%"UVxf" Pad 0x%"UVxf" reset\n",
601 PTR2UV(thr), PTR2UV(PL_curpad)));
603 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" reset\n",
605 #endif /* USE_THREADS */
606 if (!PL_tainting) { /* Can't mix tainted and non-tainted temporaries. */
607 for (po = AvMAX(PL_comppad); po > PL_padix_floor; po--) {
608 if (PL_curpad[po] && !SvIMMORTAL(PL_curpad[po]))
609 SvPADTMP_off(PL_curpad[po]);
611 PL_padix = PL_padix_floor;
614 PL_pad_reset_pending = FALSE;
618 /* find_threadsv is not reentrant */
620 Perl_find_threadsv(pTHX_ const char *name)
626 /* We currently only handle names of a single character */
627 p = strchr(PL_threadsv_names, *name);
630 key = p - PL_threadsv_names;
631 MUTEX_LOCK(&thr->mutex);
632 svp = av_fetch(thr->threadsv, key, FALSE);
634 MUTEX_UNLOCK(&thr->mutex);
636 SV *sv = NEWSV(0, 0);
637 av_store(thr->threadsv, key, sv);
638 thr->threadsvp = AvARRAY(thr->threadsv);
639 MUTEX_UNLOCK(&thr->mutex);
641 * Some magic variables used to be automagically initialised
642 * in gv_fetchpv. Those which are now per-thread magicals get
643 * initialised here instead.
649 sv_setpv(sv, "\034");
650 sv_magic(sv, 0, 0, name, 1);
655 PL_sawampersand = TRUE;
669 /* XXX %! tied to Errno.pm needs to be added here.
670 * See gv_fetchpv(). */
674 sv_magic(sv, 0, 0, name, 1);
676 DEBUG_S(PerlIO_printf(Perl_error_log,
677 "find_threadsv: new SV %p for $%s%c\n",
678 sv, (*name < 32) ? "^" : "",
679 (*name < 32) ? toCTRL(*name) : *name));
683 #endif /* USE_THREADS */
688 Perl_op_free(pTHX_ OP *o)
690 register OP *kid, *nextkid;
693 if (!o || o->op_seq == (U16)-1)
696 if (o->op_private & OPpREFCOUNTED) {
697 switch (o->op_type) {
705 if (OpREFCNT_dec(o)) {
716 if (o->op_flags & OPf_KIDS) {
717 for (kid = cUNOPo->op_first; kid; kid = nextkid) {
718 nextkid = kid->op_sibling; /* Get before next freeing kid */
726 /* COP* is not cleared by op_clear() so that we may track line
727 * numbers etc even after null() */
728 if (type == OP_NEXTSTATE || type == OP_SETSTATE || type == OP_DBSTATE)
733 #ifdef PL_OP_SLAB_ALLOC
734 if ((char *) o == PL_OpPtr)
743 S_op_clear(pTHX_ OP *o)
745 switch (o->op_type) {
746 case OP_NULL: /* Was holding old type, if any. */
747 case OP_ENTEREVAL: /* Was holding hints. */
749 case OP_THREADSV: /* Was holding index into thr->threadsv AV. */
755 if (!(o->op_flags & OPf_SPECIAL))
758 #endif /* USE_THREADS */
760 if (!(o->op_flags & OPf_REF)
761 || (PL_check[o->op_type] != MEMBER_TO_FPTR(Perl_ck_ftst)))
768 if (cPADOPo->op_padix > 0) {
771 pad_swipe(cPADOPo->op_padix);
772 /* No GvIN_PAD_off(gv) here, because other references may still
773 * exist on the pad */
776 cPADOPo->op_padix = 0;
779 SvREFCNT_dec(cSVOPo->op_sv);
780 cSVOPo->op_sv = Nullsv;
784 SvREFCNT_dec(cSVOPo->op_sv);
785 cSVOPo->op_sv = Nullsv;
791 if (o->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
795 if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
796 SvREFCNT_dec(cSVOPo->op_sv);
797 cSVOPo->op_sv = Nullsv;
800 Safefree(cPVOPo->op_pv);
801 cPVOPo->op_pv = Nullch;
805 op_free(cPMOPo->op_pmreplroot);
809 if ((PADOFFSET)cPMOPo->op_pmreplroot) {
811 GV *gv = (GV*)PL_curpad[(PADOFFSET)cPMOPo->op_pmreplroot];
812 pad_swipe((PADOFFSET)cPMOPo->op_pmreplroot);
813 /* No GvIN_PAD_off(gv) here, because other references may still
814 * exist on the pad */
819 SvREFCNT_dec((SV*)cPMOPo->op_pmreplroot);
825 cPMOPo->op_pmreplroot = Nullop;
826 ReREFCNT_dec(cPMOPo->op_pmregexp);
827 cPMOPo->op_pmregexp = (REGEXP*)NULL;
831 if (o->op_targ > 0) {
832 pad_free(o->op_targ);
838 S_cop_free(pTHX_ COP* cop)
840 Safefree(cop->cop_label);
842 Safefree(CopFILE(cop)); /* XXXXX share in a pvtable? */
843 Safefree(CopSTASHPV(cop)); /* XXXXX share in a pvtable? */
845 /* NOTE: COP.cop_stash is not refcounted */
846 SvREFCNT_dec(CopFILEGV(cop));
848 if (! specialWARN(cop->cop_warnings))
849 SvREFCNT_dec(cop->cop_warnings);
855 if (o->op_type == OP_NULL)
858 o->op_targ = o->op_type;
859 o->op_type = OP_NULL;
860 o->op_ppaddr = PL_ppaddr[OP_NULL];
863 /* Contextualizers */
865 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
868 Perl_linklist(pTHX_ OP *o)
875 /* establish postfix order */
876 if (cUNOPo->op_first) {
877 o->op_next = LINKLIST(cUNOPo->op_first);
878 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
880 kid->op_next = LINKLIST(kid->op_sibling);
892 Perl_scalarkids(pTHX_ OP *o)
895 if (o && o->op_flags & OPf_KIDS) {
896 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
903 S_scalarboolean(pTHX_ OP *o)
905 if (o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST) {
907 if (ckWARN(WARN_SYNTAX)) {
908 line_t oldline = CopLINE(PL_curcop);
910 if (PL_copline != NOLINE)
911 CopLINE_set(PL_curcop, PL_copline);
912 Perl_warner(aTHX_ WARN_SYNTAX, "Found = in conditional, should be ==");
913 CopLINE_set(PL_curcop, oldline);
920 Perl_scalar(pTHX_ OP *o)
924 /* assumes no premature commitment */
925 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
926 || o->op_type == OP_RETURN)
931 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_SCALAR;
933 switch (o->op_type) {
935 if (o->op_private & OPpREPEAT_DOLIST)
936 null(((LISTOP*)cBINOPo->op_first)->op_first);
937 scalar(cBINOPo->op_first);
942 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
946 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
947 if (!kPMOP->op_pmreplroot)
948 deprecate("implicit split to @_");
956 if (o->op_flags & OPf_KIDS) {
957 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
963 kid = cLISTOPo->op_first;
965 while ((kid = kid->op_sibling)) {
971 WITH_THR(PL_curcop = &PL_compiling);
976 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
982 WITH_THR(PL_curcop = &PL_compiling);
989 Perl_scalarvoid(pTHX_ OP *o)
996 if (o->op_type == OP_NEXTSTATE
997 || o->op_type == OP_SETSTATE
998 || o->op_type == OP_DBSTATE
999 || (o->op_type == OP_NULL && (o->op_targ == OP_NEXTSTATE
1000 || o->op_targ == OP_SETSTATE
1001 || o->op_targ == OP_DBSTATE)))
1004 PL_curcop = (COP*)o; /* for warning below */
1007 /* assumes no premature commitment */
1008 want = o->op_flags & OPf_WANT;
1009 if ((want && want != OPf_WANT_SCALAR) || PL_error_count
1010 || o->op_type == OP_RETURN)
1015 if ((o->op_private & OPpTARGET_MY)
1016 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
1018 return scalar(o); /* As if inside SASSIGN */
1021 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_VOID;
1023 switch (o->op_type) {
1025 if (!(PL_opargs[o->op_type] & OA_FOLDCONST))
1029 if (o->op_flags & OPf_STACKED)
1033 if (o->op_private == 4)
1075 case OP_GETSOCKNAME:
1076 case OP_GETPEERNAME:
1081 case OP_GETPRIORITY:
1104 if (!(o->op_private & (OPpLVAL_INTRO|OPpOUR_INTRO)))
1105 useless = PL_op_desc[o->op_type];
1112 if (!(o->op_private & (OPpLVAL_INTRO|OPpOUR_INTRO)) &&
1113 (!o->op_sibling || o->op_sibling->op_type != OP_READLINE))
1114 useless = "a variable";
1119 if (cSVOPo->op_private & OPpCONST_STRICT)
1120 no_bareword_allowed(o);
1123 if (ckWARN(WARN_VOID)) {
1124 useless = "a constant";
1125 if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
1127 else if (SvPOK(sv)) {
1128 if (strnEQ(SvPVX(sv), "di", 2) ||
1129 strnEQ(SvPVX(sv), "ds", 2) ||
1130 strnEQ(SvPVX(sv), "ig", 2))
1135 null(o); /* don't execute or even remember it */
1139 o->op_type = OP_PREINC; /* pre-increment is faster */
1140 o->op_ppaddr = PL_ppaddr[OP_PREINC];
1144 o->op_type = OP_PREDEC; /* pre-decrement is faster */
1145 o->op_ppaddr = PL_ppaddr[OP_PREDEC];
1151 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1156 if (o->op_flags & OPf_STACKED)
1164 if (!(o->op_flags & OPf_KIDS))
1173 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1180 /* all requires must return a boolean value */
1181 o->op_flags &= ~OPf_WANT;
1184 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
1185 if (!kPMOP->op_pmreplroot)
1186 deprecate("implicit split to @_");
1192 if (ckWARN(WARN_VOID))
1193 Perl_warner(aTHX_ WARN_VOID, "Useless use of %s in void context", useless);
1199 Perl_listkids(pTHX_ OP *o)
1202 if (o && o->op_flags & OPf_KIDS) {
1203 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1210 Perl_list(pTHX_ OP *o)
1214 /* assumes no premature commitment */
1215 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
1216 || o->op_type == OP_RETURN)
1221 if ((o->op_private & OPpTARGET_MY)
1222 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
1224 return o; /* As if inside SASSIGN */
1227 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_LIST;
1229 switch (o->op_type) {
1232 list(cBINOPo->op_first);
1237 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1245 if (!(o->op_flags & OPf_KIDS))
1247 if (!o->op_next && cUNOPo->op_first->op_type == OP_FLOP) {
1248 list(cBINOPo->op_first);
1249 return gen_constant_list(o);
1256 kid = cLISTOPo->op_first;
1258 while ((kid = kid->op_sibling)) {
1259 if (kid->op_sibling)
1264 WITH_THR(PL_curcop = &PL_compiling);
1268 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
1269 if (kid->op_sibling)
1274 WITH_THR(PL_curcop = &PL_compiling);
1277 /* all requires must return a boolean value */
1278 o->op_flags &= ~OPf_WANT;
1285 Perl_scalarseq(pTHX_ OP *o)
1290 if (o->op_type == OP_LINESEQ ||
1291 o->op_type == OP_SCOPE ||
1292 o->op_type == OP_LEAVE ||
1293 o->op_type == OP_LEAVETRY)
1296 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
1297 if (kid->op_sibling) {
1301 PL_curcop = &PL_compiling;
1303 o->op_flags &= ~OPf_PARENS;
1304 if (PL_hints & HINT_BLOCK_SCOPE)
1305 o->op_flags |= OPf_PARENS;
1308 o = newOP(OP_STUB, 0);
1313 S_modkids(pTHX_ OP *o, I32 type)
1316 if (o && o->op_flags & OPf_KIDS) {
1317 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1324 Perl_mod(pTHX_ OP *o, I32 type)
1330 if (!o || PL_error_count)
1333 if ((o->op_private & OPpTARGET_MY)
1334 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
1339 switch (o->op_type) {
1344 if (!(o->op_private & (OPpCONST_ARYBASE)))
1346 if (PL_eval_start && PL_eval_start->op_type == OP_CONST) {
1347 PL_compiling.cop_arybase = (I32)SvIV(cSVOPx(PL_eval_start)->op_sv);
1351 SAVEI32(PL_compiling.cop_arybase);
1352 PL_compiling.cop_arybase = 0;
1354 else if (type == OP_REFGEN)
1357 Perl_croak(aTHX_ "That use of $[ is unsupported");
1360 if (o->op_flags & OPf_PARENS)
1364 if ((type == OP_UNDEF || type == OP_REFGEN) &&
1365 !(o->op_flags & OPf_STACKED)) {
1366 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1367 o->op_ppaddr = PL_ppaddr[OP_RV2CV];
1368 assert(cUNOPo->op_first->op_type == OP_NULL);
1369 null(((LISTOP*)cUNOPo->op_first)->op_first);/* disable pushmark */
1372 else { /* lvalue subroutine call */
1373 o->op_private |= OPpLVAL_INTRO;
1374 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN) {
1375 /* Backward compatibility mode: */
1376 o->op_private |= OPpENTERSUB_INARGS;
1379 else { /* Compile-time error message: */
1380 OP *kid = cUNOPo->op_first;
1384 if (kid->op_type == OP_PUSHMARK)
1386 if (kid->op_type != OP_NULL || kid->op_targ != OP_LIST)
1388 "panic: unexpected lvalue entersub "
1389 "args: type/targ %ld:%ld",
1390 (long)kid->op_type,kid->op_targ);
1391 kid = kLISTOP->op_first;
1393 while (kid->op_sibling)
1394 kid = kid->op_sibling;
1395 if (!(kid->op_type == OP_NULL && kid->op_targ == OP_RV2CV)) {
1397 if (kid->op_type == OP_METHOD_NAMED
1398 || kid->op_type == OP_METHOD)
1402 if (kid->op_sibling || kid->op_next != kid) {
1403 yyerror("panic: unexpected optree near method call");
1407 NewOp(1101, newop, 1, UNOP);
1408 newop->op_type = OP_RV2CV;
1409 newop->op_ppaddr = PL_ppaddr[OP_RV2CV];
1410 newop->op_first = Nullop;
1411 newop->op_next = (OP*)newop;
1412 kid->op_sibling = (OP*)newop;
1413 newop->op_private |= OPpLVAL_INTRO;
1417 if (kid->op_type != OP_RV2CV)
1419 "panic: unexpected lvalue entersub "
1420 "entry via type/targ %ld:%ld",
1421 (long)kid->op_type,kid->op_targ);
1422 kid->op_private |= OPpLVAL_INTRO;
1423 break; /* Postpone until runtime */
1427 kid = kUNOP->op_first;
1428 if (kid->op_type == OP_NULL && kid->op_targ == OP_RV2SV)
1429 kid = kUNOP->op_first;
1430 if (kid->op_type == OP_NULL)
1432 "Unexpected constant lvalue entersub "
1433 "entry via type/targ %ld:%ld",
1434 (long)kid->op_type,kid->op_targ);
1435 if (kid->op_type != OP_GV) {
1436 /* Restore RV2CV to check lvalueness */
1438 if (kid->op_next && kid->op_next != kid) { /* Happens? */
1439 okid->op_next = kid->op_next;
1440 kid->op_next = okid;
1443 okid->op_next = Nullop;
1444 okid->op_type = OP_RV2CV;
1446 okid->op_ppaddr = PL_ppaddr[OP_RV2CV];
1447 okid->op_private |= OPpLVAL_INTRO;
1451 cv = GvCV(kGVOP_gv);
1461 /* grep, foreach, subcalls, refgen */
1462 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
1464 yyerror(Perl_form(aTHX_ "Can't modify %s in %s",
1465 (o->op_type == OP_NULL && (o->op_flags & OPf_SPECIAL)
1467 : (o->op_type == OP_ENTERSUB
1468 ? "non-lvalue subroutine call"
1469 : PL_op_desc[o->op_type])),
1470 type ? PL_op_desc[type] : "local"));
1484 case OP_RIGHT_SHIFT:
1493 if (!(o->op_flags & OPf_STACKED))
1499 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1505 if (!type && cUNOPo->op_first->op_type != OP_GV)
1506 Perl_croak(aTHX_ "Can't localize through a reference");
1507 if (type == OP_REFGEN && o->op_flags & OPf_PARENS) {
1508 PL_modcount = 10000;
1509 return o; /* Treat \(@foo) like ordinary list. */
1513 if (scalar_mod_type(o, type))
1515 ref(cUNOPo->op_first, o->op_type);
1524 PL_modcount = 10000;
1527 if (!type && cUNOPo->op_first->op_type != OP_GV)
1528 Perl_croak(aTHX_ "Can't localize through a reference");
1529 ref(cUNOPo->op_first, o->op_type);
1533 PL_hints |= HINT_BLOCK_SCOPE;
1543 PL_modcount = 10000;
1544 if (type == OP_REFGEN && o->op_flags & OPf_PARENS)
1545 return o; /* Treat \(@foo) like ordinary list. */
1546 if (scalar_mod_type(o, type))
1552 Perl_croak(aTHX_ "Can't localize lexical variable %s",
1553 SvPV(*av_fetch(PL_comppad_name, o->op_targ, 4), n_a));
1558 PL_modcount++; /* XXX ??? */
1560 #endif /* USE_THREADS */
1566 if (type != OP_SASSIGN)
1570 if (o->op_private == 4) /* don't allow 4 arg substr as lvalue */
1576 pad_free(o->op_targ);
1577 o->op_targ = pad_alloc(o->op_type, SVs_PADMY);
1578 assert(SvTYPE(PAD_SV(o->op_targ)) == SVt_NULL);
1579 if (o->op_flags & OPf_KIDS)
1580 mod(cBINOPo->op_first->op_sibling, type);
1585 ref(cBINOPo->op_first, o->op_type);
1586 if (type == OP_ENTERSUB &&
1587 !(o->op_private & (OPpLVAL_INTRO | OPpDEREF)))
1588 o->op_private |= OPpLVAL_DEFER;
1595 if (o->op_flags & OPf_KIDS)
1596 mod(cLISTOPo->op_last, type);
1600 if (o->op_flags & OPf_SPECIAL) /* do BLOCK */
1602 else if (!(o->op_flags & OPf_KIDS))
1604 if (o->op_targ != OP_LIST) {
1605 mod(cBINOPo->op_first, type);
1610 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1614 o->op_flags |= OPf_MOD;
1616 if (type == OP_AASSIGN || type == OP_SASSIGN)
1617 o->op_flags |= OPf_SPECIAL|OPf_REF;
1619 o->op_private |= OPpLVAL_INTRO;
1620 o->op_flags &= ~OPf_SPECIAL;
1621 PL_hints |= HINT_BLOCK_SCOPE;
1623 else if (type != OP_GREPSTART && type != OP_ENTERSUB)
1624 o->op_flags |= OPf_REF;
1629 S_scalar_mod_type(pTHX_ OP *o, I32 type)
1633 if (o->op_type == OP_RV2GV)
1657 case OP_RIGHT_SHIFT:
1676 S_is_handle_constructor(pTHX_ OP *o, I32 argnum)
1678 switch (o->op_type) {
1686 case OP_SELECT: /* XXX c.f. SelectSaver.pm */
1699 Perl_refkids(pTHX_ OP *o, I32 type)
1702 if (o && o->op_flags & OPf_KIDS) {
1703 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1710 Perl_ref(pTHX_ OP *o, I32 type)
1714 if (!o || PL_error_count)
1717 switch (o->op_type) {
1719 if ((type == OP_EXISTS || type == OP_DEFINED || type == OP_LOCK) &&
1720 !(o->op_flags & OPf_STACKED)) {
1721 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1722 o->op_ppaddr = PL_ppaddr[OP_RV2CV];
1723 assert(cUNOPo->op_first->op_type == OP_NULL);
1724 null(((LISTOP*)cUNOPo->op_first)->op_first); /* disable pushmark */
1725 o->op_flags |= OPf_SPECIAL;
1730 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1734 if (type == OP_DEFINED)
1735 o->op_flags |= OPf_SPECIAL; /* don't create GV */
1736 ref(cUNOPo->op_first, o->op_type);
1739 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1740 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1741 : type == OP_RV2HV ? OPpDEREF_HV
1743 o->op_flags |= OPf_MOD;
1748 o->op_flags |= OPf_MOD; /* XXX ??? */
1753 o->op_flags |= OPf_REF;
1756 if (type == OP_DEFINED)
1757 o->op_flags |= OPf_SPECIAL; /* don't create GV */
1758 ref(cUNOPo->op_first, o->op_type);
1763 o->op_flags |= OPf_REF;
1768 if (!(o->op_flags & OPf_KIDS))
1770 ref(cBINOPo->op_first, type);
1774 ref(cBINOPo->op_first, o->op_type);
1775 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1776 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1777 : type == OP_RV2HV ? OPpDEREF_HV
1779 o->op_flags |= OPf_MOD;
1787 if (!(o->op_flags & OPf_KIDS))
1789 ref(cLISTOPo->op_last, type);
1799 S_dup_attrlist(pTHX_ OP *o)
1803 /* An attrlist is either a simple OP_CONST or an OP_LIST with kids,
1804 * where the first kid is OP_PUSHMARK and the remaining ones
1805 * are OP_CONST. We need to push the OP_CONST values.
1807 if (o->op_type == OP_CONST)
1808 rop = newSVOP(OP_CONST, o->op_flags, SvREFCNT_inc(cSVOPo->op_sv));
1810 assert((o->op_type == OP_LIST) && (o->op_flags & OPf_KIDS));
1811 for (o = cLISTOPo->op_first; o; o=o->op_sibling) {
1812 if (o->op_type == OP_CONST)
1813 rop = append_elem(OP_LIST, rop,
1814 newSVOP(OP_CONST, o->op_flags,
1815 SvREFCNT_inc(cSVOPo->op_sv)));
1822 S_apply_attrs(pTHX_ HV *stash, SV *target, OP *attrs)
1824 OP *modname; /* for 'use' */
1827 /* fake up C<use attributes $pkg,$rv,@attrs> */
1828 ENTER; /* need to protect against side-effects of 'use' */
1830 if (stash && HvNAME(stash))
1831 stashsv = newSVpv(HvNAME(stash), 0);
1833 stashsv = &PL_sv_no;
1834 #define ATTRSMODULE "attributes"
1835 modname = newSVOP(OP_CONST, 0,
1836 newSVpvn(ATTRSMODULE, sizeof(ATTRSMODULE)-1));
1837 modname->op_private |= OPpCONST_BARE;
1838 /* that flag is required to make 'use' work right */
1839 utilize(1, start_subparse(FALSE, 0),
1840 Nullop, /* version */
1842 prepend_elem(OP_LIST,
1843 newSVOP(OP_CONST, 0, stashsv),
1844 prepend_elem(OP_LIST,
1845 newSVOP(OP_CONST, 0, newRV(target)),
1846 dup_attrlist(attrs))));
1851 S_my_kid(pTHX_ OP *o, OP *attrs)
1856 if (!o || PL_error_count)
1860 if (type == OP_LIST) {
1861 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1863 } else if (type == OP_UNDEF) {
1865 } else if (type == OP_RV2SV || /* "our" declaration */
1867 type == OP_RV2HV) { /* XXX does this let anything illegal in? */
1868 o->op_private |= OPpOUR_INTRO;
1870 } else if (type != OP_PADSV &&
1873 type != OP_PUSHMARK)
1875 yyerror(Perl_form(aTHX_ "Can't declare %s in \"%s\"",
1876 PL_op_desc[o->op_type],
1877 PL_in_my == KEY_our ? "our" : "my"));
1880 else if (attrs && type != OP_PUSHMARK) {
1886 PL_in_my_stash = Nullhv;
1888 /* check for C<my Dog $spot> when deciding package */
1889 namesvp = av_fetch(PL_comppad_name, o->op_targ, FALSE);
1890 if (namesvp && *namesvp && SvOBJECT(*namesvp) && HvNAME(SvSTASH(*namesvp)))
1891 stash = SvSTASH(*namesvp);
1893 stash = PL_curstash;
1894 padsv = PAD_SV(o->op_targ);
1895 apply_attrs(stash, padsv, attrs);
1897 o->op_flags |= OPf_MOD;
1898 o->op_private |= OPpLVAL_INTRO;
1903 Perl_my_attrs(pTHX_ OP *o, OP *attrs)
1905 if (o->op_flags & OPf_PARENS)
1909 o = my_kid(o, attrs);
1911 PL_in_my_stash = Nullhv;
1916 Perl_my(pTHX_ OP *o)
1918 return my_kid(o, Nullop);
1922 Perl_sawparens(pTHX_ OP *o)
1925 o->op_flags |= OPf_PARENS;
1930 Perl_bind_match(pTHX_ I32 type, OP *left, OP *right)
1935 if (ckWARN(WARN_MISC) &&
1936 (left->op_type == OP_RV2AV ||
1937 left->op_type == OP_RV2HV ||
1938 left->op_type == OP_PADAV ||
1939 left->op_type == OP_PADHV)) {
1940 char *desc = PL_op_desc[(right->op_type == OP_SUBST ||
1941 right->op_type == OP_TRANS)
1942 ? right->op_type : OP_MATCH];
1943 const char *sample = ((left->op_type == OP_RV2AV ||
1944 left->op_type == OP_PADAV)
1945 ? "@array" : "%hash");
1946 Perl_warner(aTHX_ WARN_MISC,
1947 "Applying %s to %s will act on scalar(%s)",
1948 desc, sample, sample);
1951 if (right->op_type == OP_MATCH ||
1952 right->op_type == OP_SUBST ||
1953 right->op_type == OP_TRANS) {
1954 right->op_flags |= OPf_STACKED;
1955 if (right->op_type != OP_MATCH)
1956 left = mod(left, right->op_type);
1957 if (right->op_type == OP_TRANS)
1958 o = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
1960 o = prepend_elem(right->op_type, scalar(left), right);
1962 return newUNOP(OP_NOT, 0, scalar(o));
1966 return bind_match(type, left,
1967 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
1971 Perl_invert(pTHX_ OP *o)
1975 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
1976 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(o));
1980 Perl_scope(pTHX_ OP *o)
1983 if (o->op_flags & OPf_PARENS || PERLDB_NOOPT || PL_tainting) {
1984 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
1985 o->op_type = OP_LEAVE;
1986 o->op_ppaddr = PL_ppaddr[OP_LEAVE];
1989 if (o->op_type == OP_LINESEQ) {
1991 o->op_type = OP_SCOPE;
1992 o->op_ppaddr = PL_ppaddr[OP_SCOPE];
1993 kid = ((LISTOP*)o)->op_first;
1994 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE)
1998 o = newLISTOP(OP_SCOPE, 0, o, Nullop);
2005 Perl_save_hints(pTHX)
2008 SAVESPTR(GvHV(PL_hintgv));
2009 GvHV(PL_hintgv) = newHVhv(GvHV(PL_hintgv));
2010 SAVEFREESV(GvHV(PL_hintgv));
2014 Perl_block_start(pTHX_ int full)
2017 int retval = PL_savestack_ix;
2019 SAVEI32(PL_comppad_name_floor);
2020 PL_comppad_name_floor = AvFILLp(PL_comppad_name);
2022 PL_comppad_name_fill = PL_comppad_name_floor;
2023 if (PL_comppad_name_floor < 0)
2024 PL_comppad_name_floor = 0;
2025 SAVEI32(PL_min_intro_pending);
2026 SAVEI32(PL_max_intro_pending);
2027 PL_min_intro_pending = 0;
2028 SAVEI32(PL_comppad_name_fill);
2029 SAVEI32(PL_padix_floor);
2030 PL_padix_floor = PL_padix;
2031 PL_pad_reset_pending = FALSE;
2033 PL_hints &= ~HINT_BLOCK_SCOPE;
2034 SAVESPTR(PL_compiling.cop_warnings);
2035 if (! specialWARN(PL_compiling.cop_warnings)) {
2036 PL_compiling.cop_warnings = newSVsv(PL_compiling.cop_warnings) ;
2037 SAVEFREESV(PL_compiling.cop_warnings) ;
2043 Perl_block_end(pTHX_ I32 floor, OP *seq)
2046 int needblockscope = PL_hints & HINT_BLOCK_SCOPE;
2047 OP* retval = scalarseq(seq);
2049 PL_pad_reset_pending = FALSE;
2050 PL_compiling.op_private = PL_hints;
2052 PL_hints |= HINT_BLOCK_SCOPE; /* propagate out */
2053 pad_leavemy(PL_comppad_name_fill);
2062 OP *o = newOP(OP_THREADSV, 0);
2063 o->op_targ = find_threadsv("_");
2066 return newSVREF(newGVOP(OP_GV, 0, PL_defgv));
2067 #endif /* USE_THREADS */
2071 Perl_newPROG(pTHX_ OP *o)
2077 PL_eval_root = newUNOP(OP_LEAVEEVAL,
2078 ((PL_in_eval & EVAL_KEEPERR)
2079 ? OPf_SPECIAL : 0), o);
2080 PL_eval_start = linklist(PL_eval_root);
2081 PL_eval_root->op_private |= OPpREFCOUNTED;
2082 OpREFCNT_set(PL_eval_root, 1);
2083 PL_eval_root->op_next = 0;
2084 peep(PL_eval_start);
2089 PL_main_root = scope(sawparens(scalarvoid(o)));
2090 PL_curcop = &PL_compiling;
2091 PL_main_start = LINKLIST(PL_main_root);
2092 PL_main_root->op_private |= OPpREFCOUNTED;
2093 OpREFCNT_set(PL_main_root, 1);
2094 PL_main_root->op_next = 0;
2095 peep(PL_main_start);
2098 /* Register with debugger */
2100 CV *cv = get_cv("DB::postponed", FALSE);
2104 XPUSHs((SV*)CopFILEGV(&PL_compiling));
2106 call_sv((SV*)cv, G_DISCARD);
2113 Perl_localize(pTHX_ OP *o, I32 lex)
2115 if (o->op_flags & OPf_PARENS)
2119 if (ckWARN(WARN_PARENTHESIS) && PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == ',') {
2121 for (s = PL_bufptr; *s && (isALNUM(*s) || (*s & 0x80) || strchr("@$%, ",*s)); s++) ;
2122 if (*s == ';' || *s == '=')
2123 Perl_warner(aTHX_ WARN_PARENTHESIS,
2124 "Parentheses missing around \"%s\" list",
2125 lex ? (PL_in_my == KEY_our ? "our" : "my") : "local");
2131 o = mod(o, OP_NULL); /* a bit kludgey */
2133 PL_in_my_stash = Nullhv;
2138 Perl_jmaybe(pTHX_ OP *o)
2140 if (o->op_type == OP_LIST) {
2143 o2 = newOP(OP_THREADSV, 0);
2144 o2->op_targ = find_threadsv(";");
2146 o2 = newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
2147 #endif /* USE_THREADS */
2148 o = convert(OP_JOIN, 0, prepend_elem(OP_LIST, o2, o));
2154 Perl_fold_constants(pTHX_ register OP *o)
2158 I32 type = o->op_type;
2161 if (PL_opargs[type] & OA_RETSCALAR)
2163 if (PL_opargs[type] & OA_TARGET && !o->op_targ)
2164 o->op_targ = pad_alloc(type, SVs_PADTMP);
2166 /* integerize op, unless it happens to be C<-foo>.
2167 * XXX should pp_i_negate() do magic string negation instead? */
2168 if ((PL_opargs[type] & OA_OTHERINT) && (PL_hints & HINT_INTEGER)
2169 && !(type == OP_NEGATE && cUNOPo->op_first->op_type == OP_CONST
2170 && (cUNOPo->op_first->op_private & OPpCONST_BARE)))
2172 o->op_ppaddr = PL_ppaddr[type = ++(o->op_type)];
2175 if (!(PL_opargs[type] & OA_FOLDCONST))
2180 /* XXX might want a ck_negate() for this */
2181 cUNOPo->op_first->op_private &= ~OPpCONST_STRICT;
2194 if (o->op_private & OPpLOCALE)
2199 goto nope; /* Don't try to run w/ errors */
2201 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
2202 if ((curop->op_type != OP_CONST ||
2203 (curop->op_private & OPpCONST_BARE)) &&
2204 curop->op_type != OP_LIST &&
2205 curop->op_type != OP_SCALAR &&
2206 curop->op_type != OP_NULL &&
2207 curop->op_type != OP_PUSHMARK)
2213 curop = LINKLIST(o);
2217 sv = *(PL_stack_sp--);
2218 if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
2219 pad_swipe(o->op_targ);
2220 else if (SvTEMP(sv)) { /* grab mortal temp? */
2221 (void)SvREFCNT_inc(sv);
2225 if (type == OP_RV2GV)
2226 return newGVOP(OP_GV, 0, (GV*)sv);
2228 /* try to smush double to int, but don't smush -2.0 to -2 */
2229 if ((SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK)) == SVf_NOK &&
2233 if ((NV)iv == SvNV(sv)) {
2238 SvIOK_off(sv); /* undo SvIV() damage */
2240 return newSVOP(OP_CONST, 0, sv);
2244 if (!(PL_opargs[type] & OA_OTHERINT))
2247 if (!(PL_hints & HINT_INTEGER)) {
2248 if (type == OP_MODULO
2249 || type == OP_DIVIDE
2250 || !(o->op_flags & OPf_KIDS))
2255 for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
2256 if (curop->op_type == OP_CONST) {
2257 if (SvIOK(((SVOP*)curop)->op_sv))
2261 if (PL_opargs[curop->op_type] & OA_RETINTEGER)
2265 o->op_ppaddr = PL_ppaddr[++(o->op_type)];
2272 Perl_gen_constant_list(pTHX_ register OP *o)
2276 I32 oldtmps_floor = PL_tmps_floor;
2280 return o; /* Don't attempt to run with errors */
2282 PL_op = curop = LINKLIST(o);
2289 PL_tmps_floor = oldtmps_floor;
2291 o->op_type = OP_RV2AV;
2292 o->op_ppaddr = PL_ppaddr[OP_RV2AV];
2293 curop = ((UNOP*)o)->op_first;
2294 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*PL_stack_sp--));
2301 Perl_convert(pTHX_ I32 type, I32 flags, OP *o)
2306 if (!o || o->op_type != OP_LIST)
2307 o = newLISTOP(OP_LIST, 0, o, Nullop);
2309 o->op_flags &= ~OPf_WANT;
2311 if (!(PL_opargs[type] & OA_MARK))
2312 null(cLISTOPo->op_first);
2315 o->op_ppaddr = PL_ppaddr[type];
2316 o->op_flags |= flags;
2318 o = CHECKOP(type, o);
2319 if (o->op_type != type)
2322 if (cLISTOPo->op_children < 7) {
2323 /* XXX do we really need to do this if we're done appending?? */
2324 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
2326 cLISTOPo->op_last = last; /* in case check substituted last arg */
2329 return fold_constants(o);
2332 /* List constructors */
2335 Perl_append_elem(pTHX_ I32 type, OP *first, OP *last)
2343 if (first->op_type != type
2344 || (type == OP_LIST && (first->op_flags & OPf_PARENS)))
2346 return newLISTOP(type, 0, first, last);
2349 if (first->op_flags & OPf_KIDS)
2350 ((LISTOP*)first)->op_last->op_sibling = last;
2352 first->op_flags |= OPf_KIDS;
2353 ((LISTOP*)first)->op_first = last;
2355 ((LISTOP*)first)->op_last = last;
2356 ((LISTOP*)first)->op_children++;
2361 Perl_append_list(pTHX_ I32 type, LISTOP *first, LISTOP *last)
2369 if (first->op_type != type)
2370 return prepend_elem(type, (OP*)first, (OP*)last);
2372 if (last->op_type != type)
2373 return append_elem(type, (OP*)first, (OP*)last);
2375 first->op_last->op_sibling = last->op_first;
2376 first->op_last = last->op_last;
2377 first->op_children += last->op_children;
2378 if (first->op_children)
2379 first->op_flags |= OPf_KIDS;
2381 #ifdef PL_OP_SLAB_ALLOC
2389 Perl_prepend_elem(pTHX_ I32 type, OP *first, OP *last)
2397 if (last->op_type == type) {
2398 if (type == OP_LIST) { /* already a PUSHMARK there */
2399 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
2400 ((LISTOP*)last)->op_first->op_sibling = first;
2403 if (!(last->op_flags & OPf_KIDS)) {
2404 ((LISTOP*)last)->op_last = first;
2405 last->op_flags |= OPf_KIDS;
2407 first->op_sibling = ((LISTOP*)last)->op_first;
2408 ((LISTOP*)last)->op_first = first;
2410 ((LISTOP*)last)->op_children++;
2414 return newLISTOP(type, 0, first, last);
2420 Perl_newNULLLIST(pTHX)
2422 return newOP(OP_STUB, 0);
2426 Perl_force_list(pTHX_ OP *o)
2428 if (!o || o->op_type != OP_LIST)
2429 o = newLISTOP(OP_LIST, 0, o, Nullop);
2435 Perl_newLISTOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
2439 NewOp(1101, listop, 1, LISTOP);
2441 listop->op_type = type;
2442 listop->op_ppaddr = PL_ppaddr[type];
2443 listop->op_children = (first != 0) + (last != 0);
2444 listop->op_flags = flags;
2448 else if (!first && last)
2451 first->op_sibling = last;
2452 listop->op_first = first;
2453 listop->op_last = last;
2454 if (type == OP_LIST) {
2456 pushop = newOP(OP_PUSHMARK, 0);
2457 pushop->op_sibling = first;
2458 listop->op_first = pushop;
2459 listop->op_flags |= OPf_KIDS;
2461 listop->op_last = pushop;
2463 else if (listop->op_children)
2464 listop->op_flags |= OPf_KIDS;
2470 Perl_newOP(pTHX_ I32 type, I32 flags)
2473 NewOp(1101, o, 1, OP);
2475 o->op_ppaddr = PL_ppaddr[type];
2476 o->op_flags = flags;
2479 o->op_private = 0 + (flags >> 8);
2480 if (PL_opargs[type] & OA_RETSCALAR)
2482 if (PL_opargs[type] & OA_TARGET)
2483 o->op_targ = pad_alloc(type, SVs_PADTMP);
2484 return CHECKOP(type, o);
2488 Perl_newUNOP(pTHX_ I32 type, I32 flags, OP *first)
2493 first = newOP(OP_STUB, 0);
2494 if (PL_opargs[type] & OA_MARK)
2495 first = force_list(first);
2497 NewOp(1101, unop, 1, UNOP);
2498 unop->op_type = type;
2499 unop->op_ppaddr = PL_ppaddr[type];
2500 unop->op_first = first;
2501 unop->op_flags = flags | OPf_KIDS;
2502 unop->op_private = 1 | (flags >> 8);
2503 unop = (UNOP*) CHECKOP(type, unop);
2507 return fold_constants((OP *) unop);
2511 Perl_newBINOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
2514 NewOp(1101, binop, 1, BINOP);
2517 first = newOP(OP_NULL, 0);
2519 binop->op_type = type;
2520 binop->op_ppaddr = PL_ppaddr[type];
2521 binop->op_first = first;
2522 binop->op_flags = flags | OPf_KIDS;
2525 binop->op_private = 1 | (flags >> 8);
2528 binop->op_private = 2 | (flags >> 8);
2529 first->op_sibling = last;
2532 binop = (BINOP*)CHECKOP(type, binop);
2533 if (binop->op_next || binop->op_type != type)
2536 binop->op_last = binop->op_first->op_sibling;
2538 return fold_constants((OP *)binop);
2542 utf8compare(const void *a, const void *b)
2545 for (i = 0; i < 10; i++) {
2546 if ((*(U8**)a)[i] < (*(U8**)b)[i])
2548 if ((*(U8**)a)[i] > (*(U8**)b)[i])
2555 Perl_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
2557 SV *tstr = ((SVOP*)expr)->op_sv;
2558 SV *rstr = ((SVOP*)repl)->op_sv;
2561 register U8 *t = (U8*)SvPV(tstr, tlen);
2562 register U8 *r = (U8*)SvPV(rstr, rlen);
2568 register short *tbl;
2570 complement = o->op_private & OPpTRANS_COMPLEMENT;
2571 del = o->op_private & OPpTRANS_DELETE;
2572 squash = o->op_private & OPpTRANS_SQUASH;
2574 if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
2575 SV* listsv = newSVpvn("# comment\n",10);
2577 U8* tend = t + tlen;
2578 U8* rend = r + rlen;
2593 I32 from_utf = o->op_private & OPpTRANS_FROM_UTF;
2594 I32 to_utf = o->op_private & OPpTRANS_TO_UTF;
2597 U8 tmpbuf[UTF8_MAXLEN];
2600 New(1109, cp, tlen, U8*);
2602 transv = newSVpvn("",0);
2611 qsort(cp, i, sizeof(U8*), utf8compare);
2612 for (j = 0; j < i; j++) {
2614 UV val = utf8_to_uv(s, &ulen);
2616 diff = val - nextmin;
2618 t = uv_to_utf8(tmpbuf,nextmin);
2619 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2621 t = uv_to_utf8(tmpbuf, val - 1);
2622 sv_catpvn(transv, "\377", 1);
2623 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2627 val = utf8_to_uv(s+1, &ulen);
2631 t = uv_to_utf8(tmpbuf,nextmin);
2632 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2633 t = uv_to_utf8(tmpbuf, 0x7fffffff);
2634 sv_catpvn(transv, "\377", 1);
2635 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2636 t = (U8*)SvPVX(transv);
2637 tlen = SvCUR(transv);
2640 else if (!rlen && !del) {
2641 r = t; rlen = tlen; rend = tend;
2644 if (to_utf && from_utf) { /* only counting characters */
2645 if (t == r || (tlen == rlen && memEQ(t, r, tlen)))
2646 o->op_private |= OPpTRANS_IDENTICAL;
2648 else { /* straight latin-1 translation */
2649 if (tlen == 4 && memEQ(t, "\0\377\303\277", 4) &&
2650 rlen == 4 && memEQ(r, "\0\377\303\277", 4))
2651 o->op_private |= OPpTRANS_IDENTICAL;
2655 while (t < tend || tfirst <= tlast) {
2656 /* see if we need more "t" chars */
2657 if (tfirst > tlast) {
2658 tfirst = (I32)utf8_to_uv(t, &ulen);
2660 if (t < tend && *t == 0xff) { /* illegal utf8 val indicates range */
2661 tlast = (I32)utf8_to_uv(++t, &ulen);
2668 /* now see if we need more "r" chars */
2669 if (rfirst > rlast) {
2671 rfirst = (I32)utf8_to_uv(r, &ulen);
2673 if (r < rend && *r == 0xff) { /* illegal utf8 val indicates range */
2674 rlast = (I32)utf8_to_uv(++r, &ulen);
2683 rfirst = rlast = 0xffffffff;
2687 /* now see which range will peter our first, if either. */
2688 tdiff = tlast - tfirst;
2689 rdiff = rlast - rfirst;
2696 if (rfirst == 0xffffffff) {
2697 diff = tdiff; /* oops, pretend rdiff is infinite */
2699 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t%04lx\tXXXX\n",
2700 (long)tfirst, (long)tlast);
2702 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t\tXXXX\n", (long)tfirst);
2706 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t%04lx\t%04lx\n",
2707 (long)tfirst, (long)(tfirst + diff),
2710 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t\t%04lx\n",
2711 (long)tfirst, (long)rfirst);
2713 if (rfirst + diff > max)
2714 max = rfirst + diff;
2719 else if (rfirst <= 0x800)
2720 grows |= (tfirst < 0x80);
2721 else if (rfirst <= 0x10000)
2722 grows |= (tfirst < 0x800);
2723 else if (rfirst <= 0x200000)
2724 grows |= (tfirst < 0x10000);
2725 else if (rfirst <= 0x4000000)
2726 grows |= (tfirst < 0x200000);
2727 else if (rfirst <= 0x80000000)
2728 grows |= (tfirst < 0x4000000);
2740 else if (max > 0xff)
2745 cSVOPo->op_sv = (SV*)swash_init("utf8", "", listsv, bits, none);
2746 SvREFCNT_dec(listsv);
2748 SvREFCNT_dec(transv);
2750 if (!del && havefinal)
2751 (void)hv_store((HV*)SvRV((cSVOPo->op_sv)), "FINAL", 5, newSViv((IV)final), 0);
2753 if (grows && to_utf)
2754 o->op_private |= OPpTRANS_GROWS;
2761 tbl = (short*)cPVOPo->op_pv;
2763 Zero(tbl, 256, short);
2764 for (i = 0; i < tlen; i++)
2766 for (i = 0, j = 0; i < 256; i++) {
2782 if (!rlen && !del) {
2785 o->op_private |= OPpTRANS_IDENTICAL;
2787 for (i = 0; i < 256; i++)
2789 for (i = 0, j = 0; i < tlen; i++,j++) {
2792 if (tbl[t[i]] == -1)
2798 if (tbl[t[i]] == -1)
2809 Perl_newPMOP(pTHX_ I32 type, I32 flags)
2814 NewOp(1101, pmop, 1, PMOP);
2815 pmop->op_type = type;
2816 pmop->op_ppaddr = PL_ppaddr[type];
2817 pmop->op_flags = flags;
2818 pmop->op_private = 0 | (flags >> 8);
2820 if (PL_hints & HINT_RE_TAINT)
2821 pmop->op_pmpermflags |= PMf_RETAINT;
2822 if (PL_hints & HINT_LOCALE)
2823 pmop->op_pmpermflags |= PMf_LOCALE;
2824 pmop->op_pmflags = pmop->op_pmpermflags;
2826 /* link into pm list */
2827 if (type != OP_TRANS && PL_curstash) {
2828 pmop->op_pmnext = HvPMROOT(PL_curstash);
2829 HvPMROOT(PL_curstash) = pmop;
2836 Perl_pmruntime(pTHX_ OP *o, OP *expr, OP *repl)
2841 I32 repl_has_vars = 0;
2843 if (o->op_type == OP_TRANS)
2844 return pmtrans(o, expr, repl);
2846 PL_hints |= HINT_BLOCK_SCOPE;
2849 if (expr->op_type == OP_CONST) {
2851 SV *pat = ((SVOP*)expr)->op_sv;
2852 char *p = SvPV(pat, plen);
2853 if ((o->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
2854 sv_setpvn(pat, "\\s+", 3);
2855 p = SvPV(pat, plen);
2856 pm->op_pmflags |= PMf_SKIPWHITE;
2858 if ((PL_hints & HINT_UTF8) || (SvUTF8(pat) && !(PL_hints & HINT_BYTE)))
2859 pm->op_pmdynflags |= PMdf_UTF8;
2860 pm->op_pmregexp = CALLREGCOMP(aTHX_ p, p + plen, pm);
2861 if (strEQ("\\s+", pm->op_pmregexp->precomp))
2862 pm->op_pmflags |= PMf_WHITE;
2866 if (PL_hints & HINT_UTF8)
2867 pm->op_pmdynflags |= PMdf_UTF8;
2868 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL))
2869 expr = newUNOP((!(PL_hints & HINT_RE_EVAL)
2871 : OP_REGCMAYBE),0,expr);
2873 NewOp(1101, rcop, 1, LOGOP);
2874 rcop->op_type = OP_REGCOMP;
2875 rcop->op_ppaddr = PL_ppaddr[OP_REGCOMP];
2876 rcop->op_first = scalar(expr);
2877 rcop->op_flags |= ((PL_hints & HINT_RE_EVAL)
2878 ? (OPf_SPECIAL | OPf_KIDS)
2880 rcop->op_private = 1;
2883 /* establish postfix order */
2884 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL)) {
2886 rcop->op_next = expr;
2887 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
2890 rcop->op_next = LINKLIST(expr);
2891 expr->op_next = (OP*)rcop;
2894 prepend_elem(o->op_type, scalar((OP*)rcop), o);
2899 if (pm->op_pmflags & PMf_EVAL) {
2901 if (CopLINE(PL_curcop) < PL_multi_end)
2902 CopLINE_set(PL_curcop, PL_multi_end);
2905 else if (repl->op_type == OP_THREADSV
2906 && strchr("&`'123456789+",
2907 PL_threadsv_names[repl->op_targ]))
2911 #endif /* USE_THREADS */
2912 else if (repl->op_type == OP_CONST)
2916 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
2917 if (PL_opargs[curop->op_type] & OA_DANGEROUS) {
2919 if (curop->op_type == OP_THREADSV) {
2921 if (strchr("&`'123456789+", curop->op_private))
2925 if (curop->op_type == OP_GV) {
2926 GV *gv = cGVOPx_gv(curop);
2928 if (strchr("&`'123456789+", *GvENAME(gv)))
2931 #endif /* USE_THREADS */
2932 else if (curop->op_type == OP_RV2CV)
2934 else if (curop->op_type == OP_RV2SV ||
2935 curop->op_type == OP_RV2AV ||
2936 curop->op_type == OP_RV2HV ||
2937 curop->op_type == OP_RV2GV) {
2938 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
2941 else if (curop->op_type == OP_PADSV ||
2942 curop->op_type == OP_PADAV ||
2943 curop->op_type == OP_PADHV ||
2944 curop->op_type == OP_PADANY) {
2947 else if (curop->op_type == OP_PUSHRE)
2948 ; /* Okay here, dangerous in newASSIGNOP */
2957 && (!pm->op_pmregexp
2958 || pm->op_pmregexp->reganch & ROPT_EVAL_SEEN))) {
2959 pm->op_pmflags |= PMf_CONST; /* const for long enough */
2960 pm->op_pmpermflags |= PMf_CONST; /* const for long enough */
2961 prepend_elem(o->op_type, scalar(repl), o);
2964 if (curop == repl && !pm->op_pmregexp) { /* Has variables. */
2965 pm->op_pmflags |= PMf_MAYBE_CONST;
2966 pm->op_pmpermflags |= PMf_MAYBE_CONST;
2968 NewOp(1101, rcop, 1, LOGOP);
2969 rcop->op_type = OP_SUBSTCONT;
2970 rcop->op_ppaddr = PL_ppaddr[OP_SUBSTCONT];
2971 rcop->op_first = scalar(repl);
2972 rcop->op_flags |= OPf_KIDS;
2973 rcop->op_private = 1;
2976 /* establish postfix order */
2977 rcop->op_next = LINKLIST(repl);
2978 repl->op_next = (OP*)rcop;
2980 pm->op_pmreplroot = scalar((OP*)rcop);
2981 pm->op_pmreplstart = LINKLIST(rcop);
2990 Perl_newSVOP(pTHX_ I32 type, I32 flags, SV *sv)
2993 NewOp(1101, svop, 1, SVOP);
2994 svop->op_type = type;
2995 svop->op_ppaddr = PL_ppaddr[type];
2997 svop->op_next = (OP*)svop;
2998 svop->op_flags = flags;
2999 if (PL_opargs[type] & OA_RETSCALAR)
3001 if (PL_opargs[type] & OA_TARGET)
3002 svop->op_targ = pad_alloc(type, SVs_PADTMP);
3003 return CHECKOP(type, svop);
3007 Perl_newPADOP(pTHX_ I32 type, I32 flags, SV *sv)
3010 NewOp(1101, padop, 1, PADOP);
3011 padop->op_type = type;
3012 padop->op_ppaddr = PL_ppaddr[type];
3013 padop->op_padix = pad_alloc(type, SVs_PADTMP);
3014 SvREFCNT_dec(PL_curpad[padop->op_padix]);
3015 PL_curpad[padop->op_padix] = sv;
3017 padop->op_next = (OP*)padop;
3018 padop->op_flags = flags;
3019 if (PL_opargs[type] & OA_RETSCALAR)
3021 if (PL_opargs[type] & OA_TARGET)
3022 padop->op_targ = pad_alloc(type, SVs_PADTMP);
3023 return CHECKOP(type, padop);
3027 Perl_newGVOP(pTHX_ I32 type, I32 flags, GV *gv)
3032 return newPADOP(type, flags, SvREFCNT_inc(gv));
3034 return newSVOP(type, flags, SvREFCNT_inc(gv));
3039 Perl_newPVOP(pTHX_ I32 type, I32 flags, char *pv)
3042 NewOp(1101, pvop, 1, PVOP);
3043 pvop->op_type = type;
3044 pvop->op_ppaddr = PL_ppaddr[type];
3046 pvop->op_next = (OP*)pvop;
3047 pvop->op_flags = flags;
3048 if (PL_opargs[type] & OA_RETSCALAR)
3050 if (PL_opargs[type] & OA_TARGET)
3051 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
3052 return CHECKOP(type, pvop);
3056 Perl_package(pTHX_ OP *o)
3061 save_hptr(&PL_curstash);
3062 save_item(PL_curstname);
3067 name = SvPV(sv, len);
3068 PL_curstash = gv_stashpvn(name,len,TRUE);
3069 sv_setpvn(PL_curstname, name, len);
3073 sv_setpv(PL_curstname,"<none>");
3074 PL_curstash = Nullhv;
3076 PL_hints |= HINT_BLOCK_SCOPE;
3077 PL_copline = NOLINE;
3082 Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *id, OP *arg)
3090 if (id->op_type != OP_CONST)
3091 Perl_croak(aTHX_ "Module name must be constant");
3095 if (version != Nullop) {
3096 SV *vesv = ((SVOP*)version)->op_sv;
3098 if (arg == Nullop && !SvNIOKp(vesv)) {
3105 if (version->op_type != OP_CONST || !SvNIOKp(vesv))
3106 Perl_croak(aTHX_ "Version number must be constant number");
3108 /* Make copy of id so we don't free it twice */
3109 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
3111 /* Fake up a method call to VERSION */
3112 meth = newSVpvn("VERSION",7);
3113 sv_upgrade(meth, SVt_PVIV);
3114 (void)SvIOK_on(meth);
3115 PERL_HASH(SvUVX(meth), SvPVX(meth), SvCUR(meth));
3116 veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
3117 append_elem(OP_LIST,
3118 prepend_elem(OP_LIST, pack, list(version)),
3119 newSVOP(OP_METHOD_NAMED, 0, meth)));
3123 /* Fake up an import/unimport */
3124 if (arg && arg->op_type == OP_STUB)
3125 imop = arg; /* no import on explicit () */
3126 else if (SvNIOKp(((SVOP*)id)->op_sv)) {
3127 imop = Nullop; /* use 5.0; */
3132 /* Make copy of id so we don't free it twice */
3133 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
3135 /* Fake up a method call to import/unimport */
3136 meth = aver ? newSVpvn("import",6) : newSVpvn("unimport", 8);;
3137 sv_upgrade(meth, SVt_PVIV);
3138 (void)SvIOK_on(meth);
3139 PERL_HASH(SvUVX(meth), SvPVX(meth), SvCUR(meth));
3140 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
3141 append_elem(OP_LIST,
3142 prepend_elem(OP_LIST, pack, list(arg)),
3143 newSVOP(OP_METHOD_NAMED, 0, meth)));
3146 /* Fake up a require, handle override, if any */
3147 gv = gv_fetchpv("require", FALSE, SVt_PVCV);
3148 if (!(gv && GvIMPORTED_CV(gv)))
3149 gv = gv_fetchpv("CORE::GLOBAL::require", FALSE, SVt_PVCV);
3151 if (gv && GvIMPORTED_CV(gv)) {
3152 rqop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
3153 append_elem(OP_LIST, id,
3154 scalar(newUNOP(OP_RV2CV, 0,
3159 rqop = newUNOP(OP_REQUIRE, 0, id);
3162 /* Fake up the BEGIN {}, which does its thing immediately. */
3164 newSVOP(OP_CONST, 0, newSVpvn("BEGIN", 5)),
3167 append_elem(OP_LINESEQ,
3168 append_elem(OP_LINESEQ,
3169 newSTATEOP(0, Nullch, rqop),
3170 newSTATEOP(0, Nullch, veop)),
3171 newSTATEOP(0, Nullch, imop) ));
3173 PL_hints |= HINT_BLOCK_SCOPE;
3174 PL_copline = NOLINE;
3179 Perl_dofile(pTHX_ OP *term)
3184 gv = gv_fetchpv("do", FALSE, SVt_PVCV);
3185 if (!(gv && GvIMPORTED_CV(gv)))
3186 gv = gv_fetchpv("CORE::GLOBAL::do", FALSE, SVt_PVCV);
3188 if (gv && GvIMPORTED_CV(gv)) {
3189 doop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
3190 append_elem(OP_LIST, term,
3191 scalar(newUNOP(OP_RV2CV, 0,
3196 doop = newUNOP(OP_DOFILE, 0, scalar(term));
3202 Perl_newSLICEOP(pTHX_ I32 flags, OP *subscript, OP *listval)
3204 return newBINOP(OP_LSLICE, flags,
3205 list(force_list(subscript)),
3206 list(force_list(listval)) );
3210 S_list_assignment(pTHX_ register OP *o)
3215 if (o->op_type == OP_NULL && o->op_flags & OPf_KIDS)
3216 o = cUNOPo->op_first;
3218 if (o->op_type == OP_COND_EXPR) {
3219 I32 t = list_assignment(cLOGOPo->op_first->op_sibling);
3220 I32 f = list_assignment(cLOGOPo->op_first->op_sibling->op_sibling);
3225 yyerror("Assignment to both a list and a scalar");
3229 if (o->op_type == OP_LIST || o->op_flags & OPf_PARENS ||
3230 o->op_type == OP_RV2AV || o->op_type == OP_RV2HV ||
3231 o->op_type == OP_ASLICE || o->op_type == OP_HSLICE)
3234 if (o->op_type == OP_PADAV || o->op_type == OP_PADHV)
3237 if (o->op_type == OP_RV2SV)
3244 Perl_newASSIGNOP(pTHX_ I32 flags, OP *left, I32 optype, OP *right)
3249 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN) {
3250 return newLOGOP(optype, 0,
3251 mod(scalar(left), optype),
3252 newUNOP(OP_SASSIGN, 0, scalar(right)));
3255 return newBINOP(optype, OPf_STACKED,
3256 mod(scalar(left), optype), scalar(right));
3260 if (list_assignment(left)) {
3265 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
3266 left = mod(left, OP_AASSIGN);
3274 curop = list(force_list(left));
3275 o = newBINOP(OP_AASSIGN, flags, list(force_list(right)), curop);
3276 o->op_private = 0 | (flags >> 8);
3277 for (curop = ((LISTOP*)curop)->op_first;
3278 curop; curop = curop->op_sibling)
3280 if (curop->op_type == OP_RV2HV &&
3281 ((UNOP*)curop)->op_first->op_type != OP_GV) {
3282 o->op_private |= OPpASSIGN_HASH;
3286 if (!(left->op_private & OPpLVAL_INTRO)) {
3289 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
3290 if (PL_opargs[curop->op_type] & OA_DANGEROUS) {
3291 if (curop->op_type == OP_GV) {
3292 GV *gv = cGVOPx_gv(curop);
3293 if (gv == PL_defgv || SvCUR(gv) == PL_generation)
3295 SvCUR(gv) = PL_generation;
3297 else if (curop->op_type == OP_PADSV ||
3298 curop->op_type == OP_PADAV ||
3299 curop->op_type == OP_PADHV ||
3300 curop->op_type == OP_PADANY) {
3301 SV **svp = AvARRAY(PL_comppad_name);
3302 SV *sv = svp[curop->op_targ];
3303 if (SvCUR(sv) == PL_generation)
3305 SvCUR(sv) = PL_generation; /* (SvCUR not used any more) */
3307 else if (curop->op_type == OP_RV2CV)
3309 else if (curop->op_type == OP_RV2SV ||
3310 curop->op_type == OP_RV2AV ||
3311 curop->op_type == OP_RV2HV ||
3312 curop->op_type == OP_RV2GV) {
3313 if (lastop->op_type != OP_GV) /* funny deref? */
3316 else if (curop->op_type == OP_PUSHRE) {
3317 if (((PMOP*)curop)->op_pmreplroot) {
3318 GV *gv = (GV*)((PMOP*)curop)->op_pmreplroot;
3319 if (gv == PL_defgv || SvCUR(gv) == PL_generation)
3321 SvCUR(gv) = PL_generation;
3330 o->op_private |= OPpASSIGN_COMMON;
3332 if (right && right->op_type == OP_SPLIT) {
3334 if ((tmpop = ((LISTOP*)right)->op_first) &&
3335 tmpop->op_type == OP_PUSHRE)
3337 PMOP *pm = (PMOP*)tmpop;
3338 if (left->op_type == OP_RV2AV &&
3339 !(left->op_private & OPpLVAL_INTRO) &&
3340 !(o->op_private & OPpASSIGN_COMMON) )
3342 tmpop = ((UNOP*)left)->op_first;
3343 if (tmpop->op_type == OP_GV && !pm->op_pmreplroot) {
3345 pm->op_pmreplroot = (OP*)cPADOPx(tmpop)->op_padix;
3346 cPADOPx(tmpop)->op_padix = 0; /* steal it */
3348 pm->op_pmreplroot = (OP*)cSVOPx(tmpop)->op_sv;
3349 cSVOPx(tmpop)->op_sv = Nullsv; /* steal it */
3351 pm->op_pmflags |= PMf_ONCE;
3352 tmpop = cUNOPo->op_first; /* to list (nulled) */
3353 tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */
3354 tmpop->op_sibling = Nullop; /* don't free split */
3355 right->op_next = tmpop->op_next; /* fix starting loc */
3356 op_free(o); /* blow off assign */
3357 right->op_flags &= ~OPf_WANT;
3358 /* "I don't know and I don't care." */
3363 if (PL_modcount < 10000 &&
3364 ((LISTOP*)right)->op_last->op_type == OP_CONST)
3366 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
3368 sv_setiv(sv, PL_modcount+1);
3376 right = newOP(OP_UNDEF, 0);
3377 if (right->op_type == OP_READLINE) {
3378 right->op_flags |= OPf_STACKED;
3379 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
3382 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
3383 o = newBINOP(OP_SASSIGN, flags,
3384 scalar(right), mod(scalar(left), OP_SASSIGN) );
3396 Perl_newSTATEOP(pTHX_ I32 flags, char *label, OP *o)
3399 U32 seq = intro_my();
3402 NewOp(1101, cop, 1, COP);
3403 if (PERLDB_LINE && CopLINE(PL_curcop) && PL_curstash != PL_debstash) {
3404 cop->op_type = OP_DBSTATE;
3405 cop->op_ppaddr = PL_ppaddr[ OP_DBSTATE ];
3408 cop->op_type = OP_NEXTSTATE;
3409 cop->op_ppaddr = PL_ppaddr[ OP_NEXTSTATE ];
3411 cop->op_flags = flags;
3412 cop->op_private = (PL_hints & HINT_BYTE);
3414 cop->op_private |= NATIVE_HINTS;
3416 PL_compiling.op_private = cop->op_private;
3417 cop->op_next = (OP*)cop;
3420 cop->cop_label = label;
3421 PL_hints |= HINT_BLOCK_SCOPE;
3424 cop->cop_arybase = PL_curcop->cop_arybase;
3425 if (specialWARN(PL_curcop->cop_warnings))
3426 cop->cop_warnings = PL_curcop->cop_warnings ;
3428 cop->cop_warnings = newSVsv(PL_curcop->cop_warnings) ;
3431 if (PL_copline == NOLINE)
3432 CopLINE_set(cop, CopLINE(PL_curcop));
3434 CopLINE_set(cop, PL_copline);
3435 PL_copline = NOLINE;
3438 CopFILE_set(cop, CopFILE(PL_curcop)); /* XXXXX share in a pvtable? */
3440 CopFILEGV_set(cop, (GV*)SvREFCNT_inc(CopFILEGV(PL_curcop)));
3442 CopSTASH_set(cop, PL_curstash);
3444 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3445 SV **svp = av_fetch(CopFILEAV(PL_curcop), (I32)CopLINE(cop), FALSE);
3446 if (svp && *svp != &PL_sv_undef && !SvIOK(*svp)) {
3447 (void)SvIOK_on(*svp);
3448 SvIVX(*svp) = PTR2IV(cop);
3452 return prepend_elem(OP_LINESEQ, (OP*)cop, o);
3455 /* "Introduce" my variables to visible status. */
3463 if (! PL_min_intro_pending)
3464 return PL_cop_seqmax;
3466 svp = AvARRAY(PL_comppad_name);
3467 for (i = PL_min_intro_pending; i <= PL_max_intro_pending; i++) {
3468 if ((sv = svp[i]) && sv != &PL_sv_undef && !SvIVX(sv)) {
3469 SvIVX(sv) = PAD_MAX; /* Don't know scope end yet. */
3470 SvNVX(sv) = (NV)PL_cop_seqmax;
3473 PL_min_intro_pending = 0;
3474 PL_comppad_name_fill = PL_max_intro_pending; /* Needn't search higher */
3475 return PL_cop_seqmax++;
3479 Perl_newLOGOP(pTHX_ I32 type, I32 flags, OP *first, OP *other)
3481 return new_logop(type, flags, &first, &other);
3485 S_new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp)
3490 OP *first = *firstp;
3491 OP *other = *otherp;
3493 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
3494 return newBINOP(type, flags, scalar(first), scalar(other));
3496 scalarboolean(first);
3497 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
3498 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
3499 if (type == OP_AND || type == OP_OR) {
3505 first = *firstp = cUNOPo->op_first;
3507 first->op_next = o->op_next;
3508 cUNOPo->op_first = Nullop;
3512 if (first->op_type == OP_CONST) {
3513 if (ckWARN(WARN_BAREWORD) && (first->op_private & OPpCONST_BARE))
3514 Perl_warner(aTHX_ WARN_BAREWORD, "Bareword found in conditional");
3515 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
3526 else if (first->op_type == OP_WANTARRAY) {
3532 else if (ckWARN(WARN_MISC) && (first->op_flags & OPf_KIDS)) {
3533 OP *k1 = ((UNOP*)first)->op_first;
3534 OP *k2 = k1->op_sibling;
3536 switch (first->op_type)
3539 if (k2 && k2->op_type == OP_READLINE
3540 && (k2->op_flags & OPf_STACKED)
3541 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3543 warnop = k2->op_type;
3548 if (k1->op_type == OP_READDIR
3549 || k1->op_type == OP_GLOB
3550 || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
3551 || k1->op_type == OP_EACH)
3553 warnop = ((k1->op_type == OP_NULL)
3554 ? k1->op_targ : k1->op_type);
3559 line_t oldline = CopLINE(PL_curcop);
3560 CopLINE_set(PL_curcop, PL_copline);
3561 Perl_warner(aTHX_ WARN_MISC,
3562 "Value of %s%s can be \"0\"; test with defined()",
3564 ((warnop == OP_READLINE || warnop == OP_GLOB)
3565 ? " construct" : "() operator"));
3566 CopLINE_set(PL_curcop, oldline);
3573 if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
3574 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
3576 NewOp(1101, logop, 1, LOGOP);
3578 logop->op_type = type;
3579 logop->op_ppaddr = PL_ppaddr[type];
3580 logop->op_first = first;
3581 logop->op_flags = flags | OPf_KIDS;
3582 logop->op_other = LINKLIST(other);
3583 logop->op_private = 1 | (flags >> 8);
3585 /* establish postfix order */
3586 logop->op_next = LINKLIST(first);
3587 first->op_next = (OP*)logop;
3588 first->op_sibling = other;
3590 o = newUNOP(OP_NULL, 0, (OP*)logop);
3597 Perl_newCONDOP(pTHX_ I32 flags, OP *first, OP *trueop, OP *falseop)
3605 return newLOGOP(OP_AND, 0, first, trueop);
3607 return newLOGOP(OP_OR, 0, first, falseop);
3609 scalarboolean(first);
3610 if (first->op_type == OP_CONST) {
3611 if (SvTRUE(((SVOP*)first)->op_sv)) {
3622 else if (first->op_type == OP_WANTARRAY) {
3626 NewOp(1101, logop, 1, LOGOP);
3627 logop->op_type = OP_COND_EXPR;
3628 logop->op_ppaddr = PL_ppaddr[OP_COND_EXPR];
3629 logop->op_first = first;
3630 logop->op_flags = flags | OPf_KIDS;
3631 logop->op_private = 1 | (flags >> 8);
3632 logop->op_other = LINKLIST(trueop);
3633 logop->op_next = LINKLIST(falseop);
3636 /* establish postfix order */
3637 start = LINKLIST(first);
3638 first->op_next = (OP*)logop;
3640 first->op_sibling = trueop;
3641 trueop->op_sibling = falseop;
3642 o = newUNOP(OP_NULL, 0, (OP*)logop);
3644 trueop->op_next = falseop->op_next = o;
3651 Perl_newRANGE(pTHX_ I32 flags, OP *left, OP *right)
3660 NewOp(1101, range, 1, LOGOP);
3662 range->op_type = OP_RANGE;
3663 range->op_ppaddr = PL_ppaddr[OP_RANGE];
3664 range->op_first = left;
3665 range->op_flags = OPf_KIDS;
3666 leftstart = LINKLIST(left);
3667 range->op_other = LINKLIST(right);
3668 range->op_private = 1 | (flags >> 8);
3670 left->op_sibling = right;
3672 range->op_next = (OP*)range;
3673 flip = newUNOP(OP_FLIP, flags, (OP*)range);
3674 flop = newUNOP(OP_FLOP, 0, flip);
3675 o = newUNOP(OP_NULL, 0, flop);
3677 range->op_next = leftstart;
3679 left->op_next = flip;
3680 right->op_next = flop;
3682 range->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
3683 sv_upgrade(PAD_SV(range->op_targ), SVt_PVNV);
3684 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
3685 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
3687 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
3688 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
3691 if (!flip->op_private || !flop->op_private)
3692 linklist(o); /* blow off optimizer unless constant */
3698 Perl_newLOOPOP(pTHX_ I32 flags, I32 debuggable, OP *expr, OP *block)
3703 int once = block && block->op_flags & OPf_SPECIAL &&
3704 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
3707 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
3708 return block; /* do {} while 0 does once */
3709 if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
3710 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB)) {
3711 expr = newUNOP(OP_DEFINED, 0,
3712 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
3713 } else if (expr->op_flags & OPf_KIDS) {
3714 OP *k1 = ((UNOP*)expr)->op_first;
3715 OP *k2 = (k1) ? k1->op_sibling : NULL;
3716 switch (expr->op_type) {
3718 if (k2 && k2->op_type == OP_READLINE
3719 && (k2->op_flags & OPf_STACKED)
3720 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3721 expr = newUNOP(OP_DEFINED, 0, expr);
3725 if (k1->op_type == OP_READDIR
3726 || k1->op_type == OP_GLOB
3727 || (k1->op_type == OP_NULL && k1->op_targ == OP_NULL)
3728 || k1->op_type == OP_EACH)
3729 expr = newUNOP(OP_DEFINED, 0, expr);
3735 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
3736 o = new_logop(OP_AND, 0, &expr, &listop);
3739 ((LISTOP*)listop)->op_last->op_next = LINKLIST(o);
3741 if (once && o != listop)
3742 o->op_next = ((LOGOP*)cUNOPo->op_first)->op_other;
3745 o = newUNOP(OP_NULL, 0, o); /* or do {} while 1 loses outer block */
3747 o->op_flags |= flags;
3749 o->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/
3754 Perl_newWHILEOP(pTHX_ I32 flags, I32 debuggable, LOOP *loop, I32 whileline, OP *expr, OP *block, OP *cont)
3764 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
3765 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB))) {
3766 expr = newUNOP(OP_DEFINED, 0,
3767 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
3768 } else if (expr && (expr->op_flags & OPf_KIDS)) {
3769 OP *k1 = ((UNOP*)expr)->op_first;
3770 OP *k2 = (k1) ? k1->op_sibling : NULL;
3771 switch (expr->op_type) {
3773 if (k2 && k2->op_type == OP_READLINE
3774 && (k2->op_flags & OPf_STACKED)
3775 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3776 expr = newUNOP(OP_DEFINED, 0, expr);
3780 if (k1->op_type == OP_READDIR
3781 || k1->op_type == OP_GLOB
3782 || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
3783 || k1->op_type == OP_EACH)
3784 expr = newUNOP(OP_DEFINED, 0, expr);
3790 block = newOP(OP_NULL, 0);
3792 block = scope(block);
3796 next = LINKLIST(cont);
3797 loopflags |= OPpLOOP_CONTINUE;
3800 cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
3801 if ((line_t)whileline != NOLINE) {
3802 PL_copline = whileline;
3803 cont = append_elem(OP_LINESEQ, cont,
3804 newSTATEOP(0, Nullch, Nullop));
3808 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
3809 redo = LINKLIST(listop);
3812 PL_copline = whileline;
3814 o = new_logop(OP_AND, 0, &expr, &listop);
3815 if (o == expr && o->op_type == OP_CONST && !SvTRUE(cSVOPo->op_sv)) {
3816 op_free(expr); /* oops, it's a while (0) */
3818 return Nullop; /* listop already freed by new_logop */
3821 ((LISTOP*)listop)->op_last->op_next = condop =
3822 (o == listop ? redo : LINKLIST(o));
3830 NewOp(1101,loop,1,LOOP);
3831 loop->op_type = OP_ENTERLOOP;
3832 loop->op_ppaddr = PL_ppaddr[OP_ENTERLOOP];
3833 loop->op_private = 0;
3834 loop->op_next = (OP*)loop;
3837 o = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, o);
3839 loop->op_redoop = redo;
3840 loop->op_lastop = o;
3841 o->op_private |= loopflags;
3844 loop->op_nextop = next;
3846 loop->op_nextop = o;
3848 o->op_flags |= flags;
3849 o->op_private |= (flags >> 8);
3854 Perl_newFOROP(pTHX_ I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
3862 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
3863 sv->op_type = OP_RV2GV;
3864 sv->op_ppaddr = PL_ppaddr[OP_RV2GV];
3866 else if (sv->op_type == OP_PADSV) { /* private variable */
3867 padoff = sv->op_targ;
3872 else if (sv->op_type == OP_THREADSV) { /* per-thread variable */
3873 padoff = sv->op_targ;
3875 iterflags |= OPf_SPECIAL;
3880 Perl_croak(aTHX_ "Can't use %s for loop variable", PL_op_desc[sv->op_type]);
3884 padoff = find_threadsv("_");
3885 iterflags |= OPf_SPECIAL;
3887 sv = newGVOP(OP_GV, 0, PL_defgv);
3890 if (expr->op_type == OP_RV2AV || expr->op_type == OP_PADAV) {
3891 expr = mod(force_list(scalar(ref(expr, OP_ITER))), OP_GREPSTART);
3892 iterflags |= OPf_STACKED;
3894 else if (expr->op_type == OP_NULL &&
3895 (expr->op_flags & OPf_KIDS) &&
3896 ((BINOP*)expr)->op_first->op_type == OP_FLOP)
3898 /* Basically turn for($x..$y) into the same as for($x,$y), but we
3899 * set the STACKED flag to indicate that these values are to be
3900 * treated as min/max values by 'pp_iterinit'.
3902 UNOP* flip = (UNOP*)((UNOP*)((BINOP*)expr)->op_first)->op_first;
3903 LOGOP* range = (LOGOP*) flip->op_first;
3904 OP* left = range->op_first;
3905 OP* right = left->op_sibling;
3908 range->op_flags &= ~OPf_KIDS;
3909 range->op_first = Nullop;
3911 listop = (LISTOP*)newLISTOP(OP_LIST, 0, left, right);
3912 listop->op_first->op_next = range->op_next;
3913 left->op_next = range->op_other;
3914 right->op_next = (OP*)listop;
3915 listop->op_next = listop->op_first;
3918 expr = (OP*)(listop);
3920 iterflags |= OPf_STACKED;
3923 expr = mod(force_list(expr), OP_GREPSTART);
3927 loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
3928 append_elem(OP_LIST, expr, scalar(sv))));
3929 assert(!loop->op_next);
3930 #ifdef PL_OP_SLAB_ALLOC
3933 NewOp(1234,tmp,1,LOOP);
3934 Copy(loop,tmp,1,LOOP);
3938 Renew(loop, 1, LOOP);
3940 loop->op_targ = padoff;
3941 wop = newWHILEOP(flags, 1, loop, forline, newOP(OP_ITER, 0), block, cont);
3942 PL_copline = forline;
3943 return newSTATEOP(0, label, wop);
3947 Perl_newLOOPEX(pTHX_ I32 type, OP *label)
3953 if (type != OP_GOTO || label->op_type == OP_CONST) {
3954 /* "last()" means "last" */
3955 if (label->op_type == OP_STUB && (label->op_flags & OPf_PARENS))
3956 o = newOP(type, OPf_SPECIAL);
3958 o = newPVOP(type, 0, savepv(label->op_type == OP_CONST
3959 ? SvPVx(((SVOP*)label)->op_sv, n_a)
3965 if (label->op_type == OP_ENTERSUB)
3966 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
3967 o = newUNOP(type, OPf_STACKED, label);
3969 PL_hints |= HINT_BLOCK_SCOPE;
3974 Perl_cv_undef(pTHX_ CV *cv)
3979 MUTEX_DESTROY(CvMUTEXP(cv));
3980 Safefree(CvMUTEXP(cv));
3983 #endif /* USE_THREADS */
3985 if (!CvXSUB(cv) && CvROOT(cv)) {
3987 if (CvDEPTH(cv) || (CvOWNER(cv) && CvOWNER(cv) != thr))
3988 Perl_croak(aTHX_ "Can't undef active subroutine");
3991 Perl_croak(aTHX_ "Can't undef active subroutine");
3992 #endif /* USE_THREADS */
3995 SAVEVPTR(PL_curpad);
3999 op_free(CvROOT(cv));
4000 CvROOT(cv) = Nullop;
4003 SvPOK_off((SV*)cv); /* forget prototype */
4005 SvREFCNT_dec(CvGV(cv));
4007 SvREFCNT_dec(CvOUTSIDE(cv));
4008 CvOUTSIDE(cv) = Nullcv;
4009 if (CvPADLIST(cv)) {
4010 /* may be during global destruction */
4011 if (SvREFCNT(CvPADLIST(cv))) {
4012 I32 i = AvFILLp(CvPADLIST(cv));
4014 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
4015 SV* sv = svp ? *svp : Nullsv;
4018 if (sv == (SV*)PL_comppad_name)
4019 PL_comppad_name = Nullav;
4020 else if (sv == (SV*)PL_comppad) {
4021 PL_comppad = Nullav;
4022 PL_curpad = Null(SV**);
4026 SvREFCNT_dec((SV*)CvPADLIST(cv));
4028 CvPADLIST(cv) = Nullav;
4033 S_cv_dump(pTHX_ CV *cv)
4036 CV *outside = CvOUTSIDE(cv);
4037 AV* padlist = CvPADLIST(cv);
4044 PerlIO_printf(Perl_debug_log,
4045 "\tCV=0x%"UVxf" (%s), OUTSIDE=0x%"UVxf" (%s)\n",
4047 (CvANON(cv) ? "ANON"
4048 : (cv == PL_main_cv) ? "MAIN"
4049 : CvUNIQUE(cv) ? "UNIQUE"
4050 : CvGV(cv) ? GvNAME(CvGV(cv)) : "UNDEFINED"),
4053 : CvANON(outside) ? "ANON"
4054 : (outside == PL_main_cv) ? "MAIN"
4055 : CvUNIQUE(outside) ? "UNIQUE"
4056 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
4061 pad_name = (AV*)*av_fetch(padlist, 0, FALSE);
4062 pad = (AV*)*av_fetch(padlist, 1, FALSE);
4063 pname = AvARRAY(pad_name);
4064 ppad = AvARRAY(pad);
4066 for (ix = 1; ix <= AvFILLp(pad_name); ix++) {
4067 if (SvPOK(pname[ix]))
4068 PerlIO_printf(Perl_debug_log,
4069 "\t%4d. 0x%"UVxf" (%s\"%s\" %"IVdf"-%"IVdf")\n",
4070 (int)ix, PTR2UV(ppad[ix]),
4071 SvFAKE(pname[ix]) ? "FAKE " : "",
4073 (IV)I_32(SvNVX(pname[ix])),
4076 #endif /* DEBUGGING */
4080 S_cv_clone2(pTHX_ CV *proto, CV *outside)
4085 AV* protopadlist = CvPADLIST(proto);
4086 AV* protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
4087 AV* protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
4088 SV** pname = AvARRAY(protopad_name);
4089 SV** ppad = AvARRAY(protopad);
4090 I32 fname = AvFILLp(protopad_name);
4091 I32 fpad = AvFILLp(protopad);
4095 assert(!CvUNIQUE(proto));
4099 SAVESPTR(PL_comppad_name);
4100 SAVESPTR(PL_compcv);
4102 cv = PL_compcv = (CV*)NEWSV(1104,0);
4103 sv_upgrade((SV *)cv, SvTYPE(proto));
4109 New(666, CvMUTEXP(cv), 1, perl_mutex);
4110 MUTEX_INIT(CvMUTEXP(cv));
4112 #endif /* USE_THREADS */
4113 CvFILE(cv) = CvFILE(proto);
4114 CvGV(cv) = (GV*)SvREFCNT_inc(CvGV(proto));
4115 CvSTASH(cv) = CvSTASH(proto);
4116 CvROOT(cv) = CvROOT(proto);
4117 CvSTART(cv) = CvSTART(proto);
4119 CvOUTSIDE(cv) = (CV*)SvREFCNT_inc(outside);
4122 sv_setpvn((SV*)cv, SvPVX(proto), SvCUR(proto));
4124 PL_comppad_name = newAV();
4125 for (ix = fname; ix >= 0; ix--)
4126 av_store(PL_comppad_name, ix, SvREFCNT_inc(pname[ix]));
4128 PL_comppad = newAV();
4130 comppadlist = newAV();
4131 AvREAL_off(comppadlist);
4132 av_store(comppadlist, 0, (SV*)PL_comppad_name);
4133 av_store(comppadlist, 1, (SV*)PL_comppad);
4134 CvPADLIST(cv) = comppadlist;
4135 av_fill(PL_comppad, AvFILLp(protopad));
4136 PL_curpad = AvARRAY(PL_comppad);
4138 av = newAV(); /* will be @_ */
4140 av_store(PL_comppad, 0, (SV*)av);
4141 AvFLAGS(av) = AVf_REIFY;
4143 for (ix = fpad; ix > 0; ix--) {
4144 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
4145 if (namesv && namesv != &PL_sv_undef) {
4146 char *name = SvPVX(namesv); /* XXX */
4147 if (SvFLAGS(namesv) & SVf_FAKE) { /* lexical from outside? */
4148 I32 off = pad_findlex(name, ix, SvIVX(namesv),
4149 CvOUTSIDE(cv), cxstack_ix, 0, 0);
4151 PL_curpad[ix] = SvREFCNT_inc(ppad[ix]);
4153 Perl_croak(aTHX_ "panic: cv_clone: %s", name);
4155 else { /* our own lexical */
4158 /* anon code -- we'll come back for it */
4159 sv = SvREFCNT_inc(ppad[ix]);
4161 else if (*name == '@')
4163 else if (*name == '%')
4172 else if (IS_PADGV(ppad[ix]) || IS_PADCONST(ppad[ix])) {
4173 PL_curpad[ix] = SvREFCNT_inc(ppad[ix]);
4176 SV* sv = NEWSV(0,0);
4182 /* Now that vars are all in place, clone nested closures. */
4184 for (ix = fpad; ix > 0; ix--) {
4185 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
4187 && namesv != &PL_sv_undef
4188 && !(SvFLAGS(namesv) & SVf_FAKE)
4189 && *SvPVX(namesv) == '&'
4190 && CvCLONE(ppad[ix]))
4192 CV *kid = cv_clone2((CV*)ppad[ix], cv);
4193 SvREFCNT_dec(ppad[ix]);
4196 PL_curpad[ix] = (SV*)kid;
4200 #ifdef DEBUG_CLOSURES
4201 PerlIO_printf(Perl_debug_log, "Cloned inside:\n");
4203 PerlIO_printf(Perl_debug_log, " from:\n");
4205 PerlIO_printf(Perl_debug_log, " to:\n");
4214 Perl_cv_clone(pTHX_ CV *proto)
4217 LOCK_CRED_MUTEX; /* XXX create separate mutex */
4218 cv = cv_clone2(proto, CvOUTSIDE(proto));
4219 UNLOCK_CRED_MUTEX; /* XXX create separate mutex */
4224 Perl_cv_ckproto(pTHX_ CV *cv, GV *gv, char *p)
4228 if (((!p != !SvPOK(cv)) || (p && strNE(p, SvPVX(cv)))) && ckWARN_d(WARN_PROTOTYPE)) {
4229 SV* msg = sv_newmortal();
4233 gv_efullname3(name = sv_newmortal(), gv, Nullch);
4234 sv_setpv(msg, "Prototype mismatch:");
4236 Perl_sv_catpvf(aTHX_ msg, " sub %"SVf, name);
4238 Perl_sv_catpvf(aTHX_ msg, " (%s)", SvPVX(cv));
4239 sv_catpv(msg, " vs ");
4241 Perl_sv_catpvf(aTHX_ msg, "(%s)", p);
4243 sv_catpv(msg, "none");
4244 Perl_warner(aTHX_ WARN_PROTOTYPE, "%"SVf, msg);
4249 Perl_cv_const_sv(pTHX_ CV *cv)
4251 if (!cv || !SvPOK(cv) || SvCUR(cv))
4253 return op_const_sv(CvSTART(cv), cv);
4257 Perl_op_const_sv(pTHX_ OP *o, CV *cv)
4264 if (o->op_type == OP_LINESEQ && cLISTOPo->op_first)
4265 o = cLISTOPo->op_first->op_sibling;
4267 for (; o; o = o->op_next) {
4268 OPCODE type = o->op_type;
4270 if (sv && o->op_next == o)
4272 if (type == OP_NEXTSTATE || type == OP_NULL || type == OP_PUSHMARK)
4274 if (type == OP_LEAVESUB || type == OP_RETURN)
4278 if (type == OP_CONST && cSVOPo->op_sv)
4280 else if ((type == OP_PADSV || type == OP_CONST) && cv) {
4281 AV* padav = (AV*)(AvARRAY(CvPADLIST(cv))[1]);
4282 sv = padav ? AvARRAY(padav)[o->op_targ] : Nullsv;
4283 if (!sv || (!SvREADONLY(sv) && SvREFCNT(sv) > 1))
4295 Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
4305 Perl_croak(aTHX_ "\"my sub\" not yet implemented");
4309 Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block)
4311 return Perl_newATTRSUB(aTHX_ floor, o, proto, Nullop, block);
4315 Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
4322 char *ps = proto ? SvPVx(((SVOP*)proto)->op_sv, n_a) : Nullch;
4326 name = o ? SvPVx(cSVOPo->op_sv, n_a) : Nullch;
4327 if (!name && PERLDB_NAMEANON && CopLINE(PL_curcop)) {
4328 SV *sv = sv_newmortal();
4329 Perl_sv_setpvf(aTHX_ sv, "__ANON__[%s:%"IVdf"]",
4330 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
4335 gv = gv_fetchpv(name ? name : (aname ? aname : "__ANON__"),
4336 GV_ADDMULTI | ((block || attrs) ? 0 : GV_NOINIT),
4346 if (SvTYPE(gv) != SVt_PVGV) { /* Maybe prototype now, and had at
4347 maximum a prototype before. */
4348 if (SvTYPE(gv) > SVt_NULL) {
4349 if (!SvPOK((SV*)gv) && !(SvIOK((SV*)gv) && SvIVX((SV*)gv) == -1)
4350 && ckWARN_d(WARN_PROTOTYPE))
4352 Perl_warner(aTHX_ WARN_PROTOTYPE, "Runaway prototype");
4354 cv_ckproto((CV*)gv, NULL, ps);
4357 sv_setpv((SV*)gv, ps);
4359 sv_setiv((SV*)gv, -1);
4360 SvREFCNT_dec(PL_compcv);
4361 cv = PL_compcv = NULL;
4362 PL_sub_generation++;
4366 if (!name || GvCVGEN(gv))
4368 else if ((cv = GvCV(gv))) {
4369 cv_ckproto(cv, gv, ps);
4370 /* already defined (or promised)? */
4371 if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
4373 bool const_changed = TRUE;
4374 if (!block && !attrs) {
4375 /* just a "sub foo;" when &foo is already defined */
4376 SAVEFREESV(PL_compcv);
4379 /* ahem, death to those who redefine active sort subs */
4380 if (PL_curstackinfo->si_type == PERLSI_SORT && PL_sortcop == CvSTART(cv))
4381 Perl_croak(aTHX_ "Can't redefine active sort subroutine %s", name);
4384 if ((const_sv = cv_const_sv(cv)))
4385 const_changed = sv_cmp(const_sv, op_const_sv(block, Nullcv));
4386 if ((const_sv || const_changed) && ckWARN(WARN_REDEFINE))
4388 line_t oldline = CopLINE(PL_curcop);
4389 CopLINE_set(PL_curcop, PL_copline);
4390 Perl_warner(aTHX_ WARN_REDEFINE,
4391 const_sv ? "Constant subroutine %s redefined"
4392 : "Subroutine %s redefined", name);
4393 CopLINE_set(PL_curcop, oldline);
4404 /* Need to do a C<use attributes $stash_of_cv,\&cv,@attrs>
4405 * before we clobber PL_compcv.
4409 if (CvGV(cv) && GvSTASH(CvGV(cv)) && HvNAME(GvSTASH(CvGV(cv))))
4410 stash = GvSTASH(CvGV(cv));
4411 else if (CvSTASH(cv) && HvNAME(CvSTASH(cv)))
4412 stash = CvSTASH(cv);
4414 stash = PL_curstash;
4417 /* possibly about to re-define existing subr -- ignore old cv */
4418 rcv = (SV*)PL_compcv;
4419 if (name && GvSTASH(gv) && HvNAME(GvSTASH(gv)))
4420 stash = GvSTASH(gv);
4422 stash = PL_curstash;
4424 apply_attrs(stash, rcv, attrs);
4426 if (cv) { /* must reuse cv if autoloaded */
4428 /* got here with just attrs -- work done, so bug out */
4429 SAVEFREESV(PL_compcv);
4433 CvFLAGS(cv) = CvFLAGS(PL_compcv);
4434 CvOUTSIDE(cv) = CvOUTSIDE(PL_compcv);
4435 CvOUTSIDE(PL_compcv) = 0;
4436 CvPADLIST(cv) = CvPADLIST(PL_compcv);
4437 CvPADLIST(PL_compcv) = 0;
4438 if (SvREFCNT(PL_compcv) > 1) /* XXX Make closures transit through stub. */
4439 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc((SV*)cv);
4440 SvREFCNT_dec(PL_compcv);
4447 PL_sub_generation++;
4450 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4451 CvFILE(cv) = CopFILE(PL_curcop);
4452 CvSTASH(cv) = PL_curstash;
4455 if (!CvMUTEXP(cv)) {
4456 New(666, CvMUTEXP(cv), 1, perl_mutex);
4457 MUTEX_INIT(CvMUTEXP(cv));
4459 #endif /* USE_THREADS */
4462 sv_setpv((SV*)cv, ps);
4464 if (PL_error_count) {
4468 char *s = strrchr(name, ':');
4470 if (strEQ(s, "BEGIN")) {
4472 "BEGIN not safe after errors--compilation aborted";
4473 if (PL_in_eval & EVAL_KEEPERR)
4474 Perl_croak(aTHX_ not_safe);
4476 /* force display of errors found but not reported */
4477 sv_catpv(ERRSV, not_safe);
4478 Perl_croak(aTHX_ "%s", SvPVx(ERRSV, n_a));
4485 PL_copline = NOLINE;
4490 if (AvFILLp(PL_comppad_name) < AvFILLp(PL_comppad))
4491 av_store(PL_comppad_name, AvFILLp(PL_comppad), Nullsv);
4494 CvROOT(cv) = newUNOP(OP_LEAVESUBLV, 0, scalarseq(block));
4497 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
4499 CvROOT(cv)->op_private |= OPpREFCOUNTED;
4500 OpREFCNT_set(CvROOT(cv), 1);
4501 CvSTART(cv) = LINKLIST(CvROOT(cv));
4502 CvROOT(cv)->op_next = 0;
4505 /* now that optimizer has done its work, adjust pad values */
4507 SV **namep = AvARRAY(PL_comppad_name);
4508 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4511 if (SvIMMORTAL(PL_curpad[ix]) || IS_PADGV(PL_curpad[ix]) || IS_PADCONST(PL_curpad[ix]))
4514 * The only things that a clonable function needs in its
4515 * pad are references to outer lexicals and anonymous subs.
4516 * The rest are created anew during cloning.
4518 if (!((namesv = namep[ix]) != Nullsv &&
4519 namesv != &PL_sv_undef &&
4521 *SvPVX(namesv) == '&')))
4523 SvREFCNT_dec(PL_curpad[ix]);
4524 PL_curpad[ix] = Nullsv;
4529 AV *av = newAV(); /* Will be @_ */
4531 av_store(PL_comppad, 0, (SV*)av);
4532 AvFLAGS(av) = AVf_REIFY;
4534 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4535 if (SvIMMORTAL(PL_curpad[ix]) || IS_PADGV(PL_curpad[ix]) || IS_PADCONST(PL_curpad[ix]))
4537 if (!SvPADMY(PL_curpad[ix]))
4538 SvPADTMP_on(PL_curpad[ix]);
4542 if (name || aname) {
4544 char *tname = (name ? name : aname);
4546 if (PERLDB_SUBLINE && PL_curstash != PL_debstash) {
4547 SV *sv = NEWSV(0,0);
4548 SV *tmpstr = sv_newmortal();
4549 GV *db_postponed = gv_fetchpv("DB::postponed", GV_ADDMULTI, SVt_PVHV);
4553 Perl_sv_setpvf(aTHX_ sv, "%s:%ld-%ld",
4555 (long)PL_subline, (long)CopLINE(PL_curcop));
4556 gv_efullname3(tmpstr, gv, Nullch);
4557 hv_store(GvHV(PL_DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
4558 hv = GvHVn(db_postponed);
4559 if (HvFILL(hv) > 0 && hv_exists(hv, SvPVX(tmpstr), SvCUR(tmpstr))
4560 && (pcv = GvCV(db_postponed)))
4566 call_sv((SV*)pcv, G_DISCARD);
4570 if ((s = strrchr(tname,':')))
4575 if (*s != 'B' && *s != 'E' && *s != 'C' && *s != 'I')
4578 if (strEQ(s, "BEGIN")) {
4579 I32 oldscope = PL_scopestack_ix;
4581 SAVECOPFILE(&PL_compiling);
4582 SAVECOPLINE(&PL_compiling);
4584 sv_setsv(PL_rs, PL_nrs);
4587 PL_beginav = newAV();
4588 DEBUG_x( dump_sub(gv) );
4589 av_push(PL_beginav, SvREFCNT_inc(cv));
4591 call_list(oldscope, PL_beginav);
4593 PL_curcop = &PL_compiling;
4594 PL_compiling.op_private = PL_hints;
4597 else if (strEQ(s, "END") && !PL_error_count) {
4600 DEBUG_x( dump_sub(gv) );
4601 av_unshift(PL_endav, 1);
4602 av_store(PL_endav, 0, SvREFCNT_inc(cv));
4605 else if (strEQ(s, "CHECK") && !PL_error_count) {
4607 PL_checkav = newAV();
4608 DEBUG_x( dump_sub(gv) );
4609 av_unshift(PL_checkav, 1);
4610 av_store(PL_checkav, 0, SvREFCNT_inc(cv));
4613 else if (strEQ(s, "INIT") && !PL_error_count) {
4615 PL_initav = newAV();
4616 DEBUG_x( dump_sub(gv) );
4617 av_push(PL_initav, SvREFCNT_inc(cv));
4623 PL_copline = NOLINE;
4628 /* XXX unsafe for threads if eval_owner isn't held */
4630 =for apidoc newCONSTSUB
4632 Creates a constant sub equivalent to Perl C<sub FOO () { 123 }> which is
4633 eligible for inlining at compile-time.
4639 Perl_newCONSTSUB(pTHX_ HV *stash, char *name, SV *sv)
4644 SAVECOPLINE(PL_curcop);
4647 CopLINE_set(PL_curcop, PL_copline);
4648 PL_hints &= ~HINT_BLOCK_SCOPE;
4651 SAVESPTR(PL_curstash);
4652 SAVECOPSTASH(PL_curcop);
4653 PL_curstash = stash;
4655 CopSTASHPV(PL_curcop) = stash ? HvNAME(stash) : Nullch;
4657 CopSTASH(PL_curcop) = stash;
4662 start_subparse(FALSE, 0),
4663 newSVOP(OP_CONST, 0, newSVpv(name,0)),
4664 newSVOP(OP_CONST, 0, &PL_sv_no), /* SvPV(&PL_sv_no) == "" -- GMB */
4666 newSTATEOP(0, Nullch, newSVOP(OP_CONST, 0, sv))
4673 =for apidoc U||newXS
4675 Used by C<xsubpp> to hook up XSUBs as Perl subs.
4681 Perl_newXS(pTHX_ char *name, XSUBADDR_t subaddr, char *filename)
4684 GV *gv = gv_fetchpv(name ? name : "__ANON__", GV_ADDMULTI, SVt_PVCV);
4687 if ((cv = (name ? GvCV(gv) : Nullcv))) {
4689 /* just a cached method */
4693 else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
4694 /* already defined (or promised) */
4695 if (ckWARN(WARN_REDEFINE) && !(CvGV(cv) && GvSTASH(CvGV(cv))
4696 && HvNAME(GvSTASH(CvGV(cv)))
4697 && strEQ(HvNAME(GvSTASH(CvGV(cv))), "autouse"))) {
4698 line_t oldline = CopLINE(PL_curcop);
4699 if (PL_copline != NOLINE)
4700 CopLINE_set(PL_curcop, PL_copline);
4701 Perl_warner(aTHX_ WARN_REDEFINE, "Subroutine %s redefined",name);
4702 CopLINE_set(PL_curcop, oldline);
4709 if (cv) /* must reuse cv if autoloaded */
4712 cv = (CV*)NEWSV(1105,0);
4713 sv_upgrade((SV *)cv, SVt_PVCV);
4717 PL_sub_generation++;
4720 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4722 New(666, CvMUTEXP(cv), 1, perl_mutex);
4723 MUTEX_INIT(CvMUTEXP(cv));
4725 #endif /* USE_THREADS */
4726 (void)gv_fetchfile(filename);
4727 CvFILE(cv) = filename; /* NOTE: not copied, as it is expected to be
4728 an external constant string */
4729 CvXSUB(cv) = subaddr;
4732 char *s = strrchr(name,':');
4738 if (*s != 'B' && *s != 'E' && *s != 'C' && *s != 'I')
4741 if (strEQ(s, "BEGIN")) {
4743 PL_beginav = newAV();
4744 av_push(PL_beginav, SvREFCNT_inc(cv));
4747 else if (strEQ(s, "END")) {
4750 av_unshift(PL_endav, 1);
4751 av_store(PL_endav, 0, SvREFCNT_inc(cv));
4754 else if (strEQ(s, "CHECK")) {
4756 PL_checkav = newAV();
4757 av_unshift(PL_checkav, 1);
4758 av_store(PL_checkav, 0, SvREFCNT_inc(cv));
4761 else if (strEQ(s, "INIT")) {
4763 PL_initav = newAV();
4764 av_push(PL_initav, SvREFCNT_inc(cv));
4776 Perl_newFORM(pTHX_ I32 floor, OP *o, OP *block)
4786 name = SvPVx(cSVOPo->op_sv, n_a);
4789 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
4791 if ((cv = GvFORM(gv))) {
4792 if (ckWARN(WARN_REDEFINE)) {
4793 line_t oldline = CopLINE(PL_curcop);
4795 CopLINE_set(PL_curcop, PL_copline);
4796 Perl_warner(aTHX_ WARN_REDEFINE, "Format %s redefined",name);
4797 CopLINE_set(PL_curcop, oldline);
4803 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4804 CvFILE(cv) = CopFILE(PL_curcop);
4806 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4807 if (!SvPADMY(PL_curpad[ix]) && !SvIMMORTAL(PL_curpad[ix]))
4808 SvPADTMP_on(PL_curpad[ix]);
4811 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
4812 CvROOT(cv)->op_private |= OPpREFCOUNTED;
4813 OpREFCNT_set(CvROOT(cv), 1);
4814 CvSTART(cv) = LINKLIST(CvROOT(cv));
4815 CvROOT(cv)->op_next = 0;
4818 PL_copline = NOLINE;
4823 Perl_newANONLIST(pTHX_ OP *o)
4825 return newUNOP(OP_REFGEN, 0,
4826 mod(list(convert(OP_ANONLIST, 0, o)), OP_REFGEN));
4830 Perl_newANONHASH(pTHX_ OP *o)
4832 return newUNOP(OP_REFGEN, 0,
4833 mod(list(convert(OP_ANONHASH, 0, o)), OP_REFGEN));
4837 Perl_newANONSUB(pTHX_ I32 floor, OP *proto, OP *block)
4839 return newANONATTRSUB(floor, proto, Nullop, block);
4843 Perl_newANONATTRSUB(pTHX_ I32 floor, OP *proto, OP *attrs, OP *block)
4845 return newUNOP(OP_REFGEN, 0,
4846 newSVOP(OP_ANONCODE, 0,
4847 (SV*)newATTRSUB(floor, 0, proto, attrs, block)));
4851 Perl_oopsAV(pTHX_ OP *o)
4853 switch (o->op_type) {
4855 o->op_type = OP_PADAV;
4856 o->op_ppaddr = PL_ppaddr[OP_PADAV];
4857 return ref(o, OP_RV2AV);
4860 o->op_type = OP_RV2AV;
4861 o->op_ppaddr = PL_ppaddr[OP_RV2AV];
4866 if (ckWARN_d(WARN_INTERNAL))
4867 Perl_warner(aTHX_ WARN_INTERNAL, "oops: oopsAV");
4874 Perl_oopsHV(pTHX_ OP *o)
4878 switch (o->op_type) {
4881 o->op_type = OP_PADHV;
4882 o->op_ppaddr = PL_ppaddr[OP_PADHV];
4883 return ref(o, OP_RV2HV);
4887 o->op_type = OP_RV2HV;
4888 o->op_ppaddr = PL_ppaddr[OP_RV2HV];
4893 if (ckWARN_d(WARN_INTERNAL))
4894 Perl_warner(aTHX_ WARN_INTERNAL, "oops: oopsHV");
4901 Perl_newAVREF(pTHX_ OP *o)
4903 if (o->op_type == OP_PADANY) {
4904 o->op_type = OP_PADAV;
4905 o->op_ppaddr = PL_ppaddr[OP_PADAV];
4908 return newUNOP(OP_RV2AV, 0, scalar(o));
4912 Perl_newGVREF(pTHX_ I32 type, OP *o)
4914 if (type == OP_MAPSTART || type == OP_GREPSTART || type == OP_SORT)
4915 return newUNOP(OP_NULL, 0, o);
4916 return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
4920 Perl_newHVREF(pTHX_ OP *o)
4922 if (o->op_type == OP_PADANY) {
4923 o->op_type = OP_PADHV;
4924 o->op_ppaddr = PL_ppaddr[OP_PADHV];
4927 return newUNOP(OP_RV2HV, 0, scalar(o));
4931 Perl_oopsCV(pTHX_ OP *o)
4933 Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
4939 Perl_newCVREF(pTHX_ I32 flags, OP *o)
4941 return newUNOP(OP_RV2CV, flags, scalar(o));
4945 Perl_newSVREF(pTHX_ OP *o)
4947 if (o->op_type == OP_PADANY) {
4948 o->op_type = OP_PADSV;
4949 o->op_ppaddr = PL_ppaddr[OP_PADSV];
4952 else if (o->op_type == OP_THREADSV && !(o->op_flags & OPpDONE_SVREF)) {
4953 o->op_flags |= OPpDONE_SVREF;
4956 return newUNOP(OP_RV2SV, 0, scalar(o));
4959 /* Check routines. */
4962 Perl_ck_anoncode(pTHX_ OP *o)
4967 name = NEWSV(1106,0);
4968 sv_upgrade(name, SVt_PVNV);
4969 sv_setpvn(name, "&", 1);
4972 ix = pad_alloc(o->op_type, SVs_PADMY);
4973 av_store(PL_comppad_name, ix, name);
4974 av_store(PL_comppad, ix, cSVOPo->op_sv);
4975 SvPADMY_on(cSVOPo->op_sv);
4976 cSVOPo->op_sv = Nullsv;
4977 cSVOPo->op_targ = ix;
4982 Perl_ck_bitop(pTHX_ OP *o)
4984 o->op_private = PL_hints;
4989 Perl_ck_concat(pTHX_ OP *o)
4991 if (cUNOPo->op_first->op_type == OP_CONCAT)
4992 o->op_flags |= OPf_STACKED;
4997 Perl_ck_spair(pTHX_ OP *o)
4999 if (o->op_flags & OPf_KIDS) {
5002 OPCODE type = o->op_type;
5003 o = modkids(ck_fun(o), type);
5004 kid = cUNOPo->op_first;
5005 newop = kUNOP->op_first->op_sibling;
5007 (newop->op_sibling ||
5008 !(PL_opargs[newop->op_type] & OA_RETSCALAR) ||
5009 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
5010 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
5014 op_free(kUNOP->op_first);
5015 kUNOP->op_first = newop;
5017 o->op_ppaddr = PL_ppaddr[++o->op_type];
5022 Perl_ck_delete(pTHX_ OP *o)
5026 if (o->op_flags & OPf_KIDS) {
5027 OP *kid = cUNOPo->op_first;
5028 switch (kid->op_type) {
5030 o->op_flags |= OPf_SPECIAL;
5033 o->op_private |= OPpSLICE;
5036 o->op_flags |= OPf_SPECIAL;
5041 Perl_croak(aTHX_ "%s argument is not a HASH or ARRAY element or slice",
5042 PL_op_desc[o->op_type]);
5050 Perl_ck_eof(pTHX_ OP *o)
5052 I32 type = o->op_type;
5054 if (o->op_flags & OPf_KIDS) {
5055 if (cLISTOPo->op_first->op_type == OP_STUB) {
5057 o = newUNOP(type, OPf_SPECIAL,
5058 newGVOP(OP_GV, 0, gv_fetchpv("main::ARGV", TRUE, SVt_PVAV)));
5066 Perl_ck_eval(pTHX_ OP *o)
5068 PL_hints |= HINT_BLOCK_SCOPE;
5069 if (o->op_flags & OPf_KIDS) {
5070 SVOP *kid = (SVOP*)cUNOPo->op_first;
5073 o->op_flags &= ~OPf_KIDS;
5076 else if (kid->op_type == OP_LINESEQ) {
5079 kid->op_next = o->op_next;
5080 cUNOPo->op_first = 0;
5083 NewOp(1101, enter, 1, LOGOP);
5084 enter->op_type = OP_ENTERTRY;
5085 enter->op_ppaddr = PL_ppaddr[OP_ENTERTRY];
5086 enter->op_private = 0;
5088 /* establish postfix order */
5089 enter->op_next = (OP*)enter;
5091 o = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
5092 o->op_type = OP_LEAVETRY;
5093 o->op_ppaddr = PL_ppaddr[OP_LEAVETRY];
5094 enter->op_other = o;
5102 o = newUNOP(OP_ENTEREVAL, 0, newDEFSVOP());
5104 o->op_targ = (PADOFFSET)PL_hints;
5109 Perl_ck_exec(pTHX_ OP *o)
5112 if (o->op_flags & OPf_STACKED) {
5114 kid = cUNOPo->op_first->op_sibling;
5115 if (kid->op_type == OP_RV2GV)
5124 Perl_ck_exists(pTHX_ OP *o)
5127 if (o->op_flags & OPf_KIDS) {
5128 OP *kid = cUNOPo->op_first;
5129 if (kid->op_type == OP_ENTERSUB) {
5130 (void) ref(kid, o->op_type);
5131 if (kid->op_type != OP_RV2CV && !PL_error_count)
5132 Perl_croak(aTHX_ "%s argument is not a subroutine name",
5133 PL_op_desc[o->op_type]);
5134 o->op_private |= OPpEXISTS_SUB;
5136 else if (kid->op_type == OP_AELEM)
5137 o->op_flags |= OPf_SPECIAL;
5138 else if (kid->op_type != OP_HELEM)
5139 Perl_croak(aTHX_ "%s argument is not a HASH or ARRAY element",
5140 PL_op_desc[o->op_type]);
5148 Perl_ck_gvconst(pTHX_ register OP *o)
5150 o = fold_constants(o);
5151 if (o->op_type == OP_CONST)
5158 Perl_ck_rvconst(pTHX_ register OP *o)
5161 SVOP *kid = (SVOP*)cUNOPo->op_first;
5163 o->op_private |= (PL_hints & HINT_STRICT_REFS);
5164 if (kid->op_type == OP_CONST) {
5168 SV *kidsv = kid->op_sv;
5171 /* Is it a constant from cv_const_sv()? */
5172 if (SvROK(kidsv) && SvREADONLY(kidsv)) {
5173 SV *rsv = SvRV(kidsv);
5174 int svtype = SvTYPE(rsv);
5175 char *badtype = Nullch;
5177 switch (o->op_type) {
5179 if (svtype > SVt_PVMG)
5180 badtype = "a SCALAR";
5183 if (svtype != SVt_PVAV)
5184 badtype = "an ARRAY";
5187 if (svtype != SVt_PVHV) {
5188 if (svtype == SVt_PVAV) { /* pseudohash? */
5189 SV **ksv = av_fetch((AV*)rsv, 0, FALSE);
5190 if (ksv && SvROK(*ksv)
5191 && SvTYPE(SvRV(*ksv)) == SVt_PVHV)
5200 if (svtype != SVt_PVCV)
5205 Perl_croak(aTHX_ "Constant is not %s reference", badtype);
5208 name = SvPV(kidsv, n_a);
5209 if ((PL_hints & HINT_STRICT_REFS) && (kid->op_private & OPpCONST_BARE)) {
5210 char *badthing = Nullch;
5211 switch (o->op_type) {
5213 badthing = "a SCALAR";
5216 badthing = "an ARRAY";
5219 badthing = "a HASH";
5224 "Can't use bareword (\"%s\") as %s ref while \"strict refs\" in use",
5228 * This is a little tricky. We only want to add the symbol if we
5229 * didn't add it in the lexer. Otherwise we get duplicate strict
5230 * warnings. But if we didn't add it in the lexer, we must at
5231 * least pretend like we wanted to add it even if it existed before,
5232 * or we get possible typo warnings. OPpCONST_ENTERED says
5233 * whether the lexer already added THIS instance of this symbol.
5235 iscv = (o->op_type == OP_RV2CV) * 2;
5237 gv = gv_fetchpv(name,
5238 iscv | !(kid->op_private & OPpCONST_ENTERED),
5241 : o->op_type == OP_RV2SV
5243 : o->op_type == OP_RV2AV
5245 : o->op_type == OP_RV2HV
5248 } while (!gv && !(kid->op_private & OPpCONST_ENTERED) && !iscv++);
5250 kid->op_type = OP_GV;
5251 SvREFCNT_dec(kid->op_sv);
5253 /* XXX hack: dependence on sizeof(PADOP) <= sizeof(SVOP) */
5254 kPADOP->op_padix = pad_alloc(OP_GV, SVs_PADTMP);
5256 PL_curpad[kPADOP->op_padix] = SvREFCNT_inc(gv);
5258 kid->op_sv = SvREFCNT_inc(gv);
5260 kid->op_ppaddr = PL_ppaddr[OP_GV];
5267 Perl_ck_ftst(pTHX_ OP *o)
5270 I32 type = o->op_type;
5272 if (o->op_flags & OPf_REF) {
5275 else if (o->op_flags & OPf_KIDS && cUNOPo->op_first->op_type != OP_STUB) {
5276 SVOP *kid = (SVOP*)cUNOPo->op_first;
5278 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
5280 OP *newop = newGVOP(type, OPf_REF,
5281 gv_fetchpv(SvPVx(kid->op_sv, n_a), TRUE, SVt_PVIO));
5288 if (type == OP_FTTTY)
5289 o = newGVOP(type, OPf_REF, gv_fetchpv("main::STDIN", TRUE,
5292 o = newUNOP(type, 0, newDEFSVOP());
5295 if (type == OP_FTTEXT || type == OP_FTBINARY) {
5297 if (PL_hints & HINT_LOCALE)
5298 o->op_private |= OPpLOCALE;
5305 Perl_ck_fun(pTHX_ OP *o)
5312 int type = o->op_type;
5313 register I32 oa = PL_opargs[type] >> OASHIFT;
5315 if (o->op_flags & OPf_STACKED) {
5316 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
5319 return no_fh_allowed(o);
5322 if (o->op_flags & OPf_KIDS) {
5324 tokid = &cLISTOPo->op_first;
5325 kid = cLISTOPo->op_first;
5326 if (kid->op_type == OP_PUSHMARK ||
5327 (kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK))
5329 tokid = &kid->op_sibling;
5330 kid = kid->op_sibling;
5332 if (!kid && PL_opargs[type] & OA_DEFGV)
5333 *tokid = kid = newDEFSVOP();
5337 sibl = kid->op_sibling;
5340 /* list seen where single (scalar) arg expected? */
5341 if (numargs == 1 && !(oa >> 4)
5342 && kid->op_type == OP_LIST && type != OP_SCALAR)
5344 return too_many_arguments(o,PL_op_desc[type]);
5357 if (kid->op_type == OP_CONST &&
5358 (kid->op_private & OPpCONST_BARE))
5360 char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
5361 OP *newop = newAVREF(newGVOP(OP_GV, 0,
5362 gv_fetchpv(name, TRUE, SVt_PVAV) ));
5363 if (ckWARN(WARN_DEPRECATED))
5364 Perl_warner(aTHX_ WARN_DEPRECATED,
5365 "Array @%s missing the @ in argument %"IVdf" of %s()",
5366 name, (IV)numargs, PL_op_desc[type]);
5369 kid->op_sibling = sibl;
5372 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
5373 bad_type(numargs, "array", PL_op_desc[type], kid);
5377 if (kid->op_type == OP_CONST &&
5378 (kid->op_private & OPpCONST_BARE))
5380 char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
5381 OP *newop = newHVREF(newGVOP(OP_GV, 0,
5382 gv_fetchpv(name, TRUE, SVt_PVHV) ));
5383 if (ckWARN(WARN_DEPRECATED))
5384 Perl_warner(aTHX_ WARN_DEPRECATED,
5385 "Hash %%%s missing the %% in argument %"IVdf" of %s()",
5386 name, (IV)numargs, PL_op_desc[type]);
5389 kid->op_sibling = sibl;
5392 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
5393 bad_type(numargs, "hash", PL_op_desc[type], kid);
5398 OP *newop = newUNOP(OP_NULL, 0, kid);
5399 kid->op_sibling = 0;
5401 newop->op_next = newop;
5403 kid->op_sibling = sibl;
5408 if (kid->op_type != OP_GV && kid->op_type != OP_RV2GV) {
5409 if (kid->op_type == OP_CONST &&
5410 (kid->op_private & OPpCONST_BARE))
5412 OP *newop = newGVOP(OP_GV, 0,
5413 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, n_a), TRUE,
5418 else if (kid->op_type == OP_READLINE) {
5419 /* neophyte patrol: open(<FH>), close(<FH>) etc. */
5420 bad_type(numargs, "HANDLE", PL_op_desc[o->op_type], kid);
5423 I32 flags = OPf_SPECIAL;
5427 /* is this op a FH constructor? */
5428 if (is_handle_constructor(o,numargs)) {
5429 char *name = Nullch;
5433 /* Set a flag to tell rv2gv to vivify
5434 * need to "prove" flag does not mean something
5435 * else already - NI-S 1999/05/07
5438 if (kid->op_type == OP_PADSV) {
5439 SV **namep = av_fetch(PL_comppad_name,
5441 if (namep && *namep)
5442 name = SvPV(*namep, len);
5444 else if (kid->op_type == OP_RV2SV
5445 && kUNOP->op_first->op_type == OP_GV)
5447 GV *gv = cGVOPx_gv(kUNOP->op_first);
5449 len = GvNAMELEN(gv);
5453 targ = pad_alloc(OP_RV2GV, SVs_PADTMP);
5454 namesv = PL_curpad[targ];
5455 (void)SvUPGRADE(namesv, SVt_PV);
5457 sv_setpvn(namesv, "$", 1);
5458 sv_catpvn(namesv, name, len);
5461 kid->op_sibling = 0;
5462 kid = newUNOP(OP_RV2GV, flags, scalar(kid));
5463 kid->op_targ = targ;
5464 kid->op_private |= priv;
5466 kid->op_sibling = sibl;
5472 mod(scalar(kid), type);
5476 tokid = &kid->op_sibling;
5477 kid = kid->op_sibling;
5479 o->op_private |= numargs;
5481 return too_many_arguments(o,PL_op_desc[o->op_type]);
5484 else if (PL_opargs[type] & OA_DEFGV) {
5486 return newUNOP(type, 0, newDEFSVOP());
5490 while (oa & OA_OPTIONAL)
5492 if (oa && oa != OA_LIST)
5493 return too_few_arguments(o,PL_op_desc[o->op_type]);
5499 Perl_ck_glob(pTHX_ OP *o)
5504 if ((o->op_flags & OPf_KIDS) && !cLISTOPo->op_first->op_sibling)
5505 append_elem(OP_GLOB, o, newDEFSVOP());
5507 if (!((gv = gv_fetchpv("glob", FALSE, SVt_PVCV)) && GvIMPORTED_CV(gv)))
5508 gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
5510 #if !defined(PERL_EXTERNAL_GLOB)
5511 /* XXX this can be tightened up and made more failsafe. */
5513 OP *modname = newSVOP(OP_CONST, 0, newSVpvn("File::Glob", 10));
5514 modname->op_private |= OPpCONST_BARE;
5516 utilize(1, start_subparse(FALSE, 0), Nullop, modname,
5517 newSVOP(OP_CONST, 0, newSVpvn(":globally", 9)));
5518 gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
5521 #endif /* PERL_EXTERNAL_GLOB */
5523 if (gv && GvIMPORTED_CV(gv)) {
5524 append_elem(OP_GLOB, o,
5525 newSVOP(OP_CONST, 0, newSViv(PL_glob_index++)));
5526 o->op_type = OP_LIST;
5527 o->op_ppaddr = PL_ppaddr[OP_LIST];
5528 cLISTOPo->op_first->op_type = OP_PUSHMARK;
5529 cLISTOPo->op_first->op_ppaddr = PL_ppaddr[OP_PUSHMARK];
5530 o = newUNOP(OP_ENTERSUB, OPf_STACKED,
5531 append_elem(OP_LIST, o,
5532 scalar(newUNOP(OP_RV2CV, 0,
5533 newGVOP(OP_GV, 0, gv)))));
5534 o = newUNOP(OP_NULL, 0, ck_subr(o));
5535 o->op_targ = OP_GLOB; /* hint at what it used to be */
5538 gv = newGVgen("main");
5540 append_elem(OP_GLOB, o, newGVOP(OP_GV, 0, gv));
5546 Perl_ck_grep(pTHX_ OP *o)
5550 OPCODE type = o->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
5552 o->op_ppaddr = PL_ppaddr[OP_GREPSTART];
5553 NewOp(1101, gwop, 1, LOGOP);
5555 if (o->op_flags & OPf_STACKED) {
5558 kid = cLISTOPo->op_first->op_sibling;
5559 for (k = cLISTOPo->op_first->op_sibling->op_next; k; k = k->op_next) {
5562 kid->op_next = (OP*)gwop;
5563 o->op_flags &= ~OPf_STACKED;
5565 kid = cLISTOPo->op_first->op_sibling;
5566 if (type == OP_MAPWHILE)
5573 kid = cLISTOPo->op_first->op_sibling;
5574 if (kid->op_type != OP_NULL)
5575 Perl_croak(aTHX_ "panic: ck_grep");
5576 kid = kUNOP->op_first;
5578 gwop->op_type = type;
5579 gwop->op_ppaddr = PL_ppaddr[type];
5580 gwop->op_first = listkids(o);
5581 gwop->op_flags |= OPf_KIDS;
5582 gwop->op_private = 1;
5583 gwop->op_other = LINKLIST(kid);
5584 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
5585 kid->op_next = (OP*)gwop;
5587 kid = cLISTOPo->op_first->op_sibling;
5588 if (!kid || !kid->op_sibling)
5589 return too_few_arguments(o,PL_op_desc[o->op_type]);
5590 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
5591 mod(kid, OP_GREPSTART);
5597 Perl_ck_index(pTHX_ OP *o)
5599 if (o->op_flags & OPf_KIDS) {
5600 OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5602 kid = kid->op_sibling; /* get past "big" */
5603 if (kid && kid->op_type == OP_CONST)
5604 fbm_compile(((SVOP*)kid)->op_sv, 0);
5610 Perl_ck_lengthconst(pTHX_ OP *o)
5612 /* XXX length optimization goes here */
5617 Perl_ck_lfun(pTHX_ OP *o)
5619 OPCODE type = o->op_type;
5620 return modkids(ck_fun(o), type);
5624 Perl_ck_defined(pTHX_ OP *o) /* 19990527 MJD */
5627 if ((o->op_flags & OPf_KIDS) && ckWARN(WARN_DEPRECATED)) {
5628 switch (cUNOPo->op_first->op_type) {
5630 break; /* Globals via GV can be undef */
5632 case OP_AASSIGN: /* Is this a good idea? */
5633 Perl_warner(aTHX_ WARN_DEPRECATED,
5634 "defined(@array) is deprecated");
5635 Perl_warner(aTHX_ WARN_DEPRECATED,
5636 "(Maybe you should just omit the defined()?)\n");
5639 break; /* Globals via GV can be undef */
5641 Perl_warner(aTHX_ WARN_DEPRECATED,
5642 "defined(%%hash) is deprecated");
5643 Perl_warner(aTHX_ WARN_DEPRECATED,
5644 "(Maybe you should just omit the defined()?)\n");
5655 Perl_ck_rfun(pTHX_ OP *o)
5657 OPCODE type = o->op_type;
5658 return refkids(ck_fun(o), type);
5662 Perl_ck_listiob(pTHX_ OP *o)
5666 kid = cLISTOPo->op_first;
5669 kid = cLISTOPo->op_first;
5671 if (kid->op_type == OP_PUSHMARK)
5672 kid = kid->op_sibling;
5673 if (kid && o->op_flags & OPf_STACKED)
5674 kid = kid->op_sibling;
5675 else if (kid && !kid->op_sibling) { /* print HANDLE; */
5676 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
5677 o->op_flags |= OPf_STACKED; /* make it a filehandle */
5678 kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
5679 cLISTOPo->op_first->op_sibling = kid;
5680 cLISTOPo->op_last = kid;
5681 kid = kid->op_sibling;
5686 append_elem(o->op_type, o, newDEFSVOP());
5692 if (PL_hints & HINT_LOCALE)
5693 o->op_private |= OPpLOCALE;
5700 Perl_ck_fun_locale(pTHX_ OP *o)
5706 if (PL_hints & HINT_LOCALE)
5707 o->op_private |= OPpLOCALE;
5714 Perl_ck_sassign(pTHX_ OP *o)
5716 OP *kid = cLISTOPo->op_first;
5717 /* has a disposable target? */
5718 if ((PL_opargs[kid->op_type] & OA_TARGLEX)
5719 && !(kid->op_flags & OPf_STACKED)
5720 /* Cannot steal the second time! */
5721 && !(kid->op_private & OPpTARGET_MY))
5723 OP *kkid = kid->op_sibling;
5725 /* Can just relocate the target. */
5726 if (kkid && kkid->op_type == OP_PADSV
5727 && !(kkid->op_private & OPpLVAL_INTRO))
5729 kid->op_targ = kkid->op_targ;
5731 /* Now we do not need PADSV and SASSIGN. */
5732 kid->op_sibling = o->op_sibling; /* NULL */
5733 cLISTOPo->op_first = NULL;
5736 kid->op_private |= OPpTARGET_MY; /* Used for context settings */
5744 Perl_ck_scmp(pTHX_ OP *o)
5748 if (PL_hints & HINT_LOCALE)
5749 o->op_private |= OPpLOCALE;
5756 Perl_ck_match(pTHX_ OP *o)
5758 o->op_private |= OPpRUNTIME;
5763 Perl_ck_method(pTHX_ OP *o)
5765 OP *kid = cUNOPo->op_first;
5766 if (kid->op_type == OP_CONST) {
5767 SV* sv = kSVOP->op_sv;
5768 if (!(strchr(SvPVX(sv), ':') || strchr(SvPVX(sv), '\''))) {
5770 (void)SvUPGRADE(sv, SVt_PVIV);
5772 PERL_HASH(SvUVX(sv), SvPVX(sv), SvCUR(sv));
5773 cmop = newSVOP(OP_METHOD_NAMED, 0, sv);
5774 kSVOP->op_sv = Nullsv;
5783 Perl_ck_null(pTHX_ OP *o)
5789 Perl_ck_repeat(pTHX_ OP *o)
5791 if (cBINOPo->op_first->op_flags & OPf_PARENS) {
5792 o->op_private |= OPpREPEAT_DOLIST;
5793 cBINOPo->op_first = force_list(cBINOPo->op_first);
5801 Perl_ck_require(pTHX_ OP *o)
5803 if (o->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
5804 SVOP *kid = (SVOP*)cUNOPo->op_first;
5806 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
5808 for (s = SvPVX(kid->op_sv); *s; s++) {
5809 if (*s == ':' && s[1] == ':') {
5811 Move(s+2, s+1, strlen(s+2)+1, char);
5812 --SvCUR(kid->op_sv);
5815 sv_catpvn(kid->op_sv, ".pm", 3);
5823 Perl_ck_retarget(pTHX_ OP *o)
5825 Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
5832 Perl_ck_select(pTHX_ OP *o)
5835 if (o->op_flags & OPf_KIDS) {
5836 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5837 if (kid && kid->op_sibling) {
5838 o->op_type = OP_SSELECT;
5839 o->op_ppaddr = PL_ppaddr[OP_SSELECT];
5841 return fold_constants(o);
5845 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5846 if (kid && kid->op_type == OP_RV2GV)
5847 kid->op_private &= ~HINT_STRICT_REFS;
5852 Perl_ck_shift(pTHX_ OP *o)
5854 I32 type = o->op_type;
5856 if (!(o->op_flags & OPf_KIDS)) {
5861 if (!CvUNIQUE(PL_compcv)) {
5862 argop = newOP(OP_PADAV, OPf_REF);
5863 argop->op_targ = 0; /* PL_curpad[0] is @_ */
5866 argop = newUNOP(OP_RV2AV, 0,
5867 scalar(newGVOP(OP_GV, 0,
5868 gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
5871 argop = newUNOP(OP_RV2AV, 0,
5872 scalar(newGVOP(OP_GV, 0, !CvUNIQUE(PL_compcv) ?
5873 PL_defgv : gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
5874 #endif /* USE_THREADS */
5875 return newUNOP(type, 0, scalar(argop));
5877 return scalar(modkids(ck_fun(o), type));
5881 Perl_ck_sort(pTHX_ OP *o)
5885 if (PL_hints & HINT_LOCALE)
5886 o->op_private |= OPpLOCALE;
5889 if (o->op_type == OP_SORT && o->op_flags & OPf_STACKED)
5891 if (o->op_flags & OPf_STACKED) { /* may have been cleared */
5892 OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5894 kid = kUNOP->op_first; /* get past null */
5896 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
5898 if (kid->op_type == OP_SCOPE) {
5902 else if (kid->op_type == OP_LEAVE) {
5903 if (o->op_type == OP_SORT) {
5904 null(kid); /* wipe out leave */
5907 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
5908 if (k->op_next == kid)
5913 kid->op_next = 0; /* just disconnect the leave */
5914 k = kLISTOP->op_first;
5918 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5919 if (o->op_type == OP_SORT)
5923 o->op_flags |= OPf_SPECIAL;
5925 else if (kid->op_type == OP_RV2SV || kid->op_type == OP_PADSV)
5926 null(cLISTOPo->op_first->op_sibling);
5933 S_simplify_sort(pTHX_ OP *o)
5936 register OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5940 if (!(o->op_flags & OPf_STACKED))
5942 GvMULTI_on(gv_fetchpv("a", TRUE, SVt_PV));
5943 GvMULTI_on(gv_fetchpv("b", TRUE, SVt_PV));
5944 kid = kUNOP->op_first; /* get past null */
5945 if (kid->op_type != OP_SCOPE)
5947 kid = kLISTOP->op_last; /* get past scope */
5948 switch(kid->op_type) {
5956 k = kid; /* remember this node*/
5957 if (kBINOP->op_first->op_type != OP_RV2SV)
5959 kid = kBINOP->op_first; /* get past cmp */
5960 if (kUNOP->op_first->op_type != OP_GV)
5962 kid = kUNOP->op_first; /* get past rv2sv */
5964 if (GvSTASH(gv) != PL_curstash)
5966 if (strEQ(GvNAME(gv), "a"))
5968 else if (strEQ(GvNAME(gv), "b"))
5972 kid = k; /* back to cmp */
5973 if (kBINOP->op_last->op_type != OP_RV2SV)
5975 kid = kBINOP->op_last; /* down to 2nd arg */
5976 if (kUNOP->op_first->op_type != OP_GV)
5978 kid = kUNOP->op_first; /* get past rv2sv */
5980 if (GvSTASH(gv) != PL_curstash
5982 ? strNE(GvNAME(gv), "a")
5983 : strNE(GvNAME(gv), "b")))
5985 o->op_flags &= ~(OPf_STACKED | OPf_SPECIAL);
5987 o->op_private |= OPpSORT_REVERSE;
5988 if (k->op_type == OP_NCMP)
5989 o->op_private |= OPpSORT_NUMERIC;
5990 if (k->op_type == OP_I_NCMP)
5991 o->op_private |= OPpSORT_NUMERIC | OPpSORT_INTEGER;
5992 kid = cLISTOPo->op_first->op_sibling;
5993 cLISTOPo->op_first->op_sibling = kid->op_sibling; /* bypass old block */
5994 op_free(kid); /* then delete it */
5995 cLISTOPo->op_children--;
5999 Perl_ck_split(pTHX_ OP *o)
6003 if (o->op_flags & OPf_STACKED)
6004 return no_fh_allowed(o);
6006 kid = cLISTOPo->op_first;
6007 if (kid->op_type != OP_NULL)
6008 Perl_croak(aTHX_ "panic: ck_split");
6009 kid = kid->op_sibling;
6010 op_free(cLISTOPo->op_first);
6011 cLISTOPo->op_first = kid;
6013 cLISTOPo->op_first = kid = newSVOP(OP_CONST, 0, newSVpvn(" ", 1));
6014 cLISTOPo->op_last = kid; /* There was only one element previously */
6017 if (kid->op_type != OP_MATCH) {
6018 OP *sibl = kid->op_sibling;
6019 kid->op_sibling = 0;
6020 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
6021 if (cLISTOPo->op_first == cLISTOPo->op_last)
6022 cLISTOPo->op_last = kid;
6023 cLISTOPo->op_first = kid;
6024 kid->op_sibling = sibl;
6027 kid->op_type = OP_PUSHRE;
6028 kid->op_ppaddr = PL_ppaddr[OP_PUSHRE];
6031 if (!kid->op_sibling)
6032 append_elem(OP_SPLIT, o, newDEFSVOP());
6034 kid = kid->op_sibling;
6037 if (!kid->op_sibling)
6038 append_elem(OP_SPLIT, o, newSVOP(OP_CONST, 0, newSViv(0)));
6040 kid = kid->op_sibling;
6043 if (kid->op_sibling)
6044 return too_many_arguments(o,PL_op_desc[o->op_type]);
6050 Perl_ck_join(pTHX_ OP *o)
6052 if (ckWARN(WARN_SYNTAX)) {
6053 OP *kid = cLISTOPo->op_first->op_sibling;
6054 if (kid && kid->op_type == OP_MATCH) {
6055 char *pmstr = "STRING";
6056 if (kPMOP->op_pmregexp)
6057 pmstr = kPMOP->op_pmregexp->precomp;
6058 Perl_warner(aTHX_ WARN_SYNTAX,
6059 "/%s/ should probably be written as \"%s\"",
6067 Perl_ck_subr(pTHX_ OP *o)
6070 OP *prev = ((cUNOPo->op_first->op_sibling)
6071 ? cUNOPo : ((UNOP*)cUNOPo->op_first))->op_first;
6072 OP *o2 = prev->op_sibling;
6081 o->op_private |= OPpENTERSUB_HASTARG;
6082 for (cvop = o2; cvop->op_sibling; cvop = cvop->op_sibling) ;
6083 if (cvop->op_type == OP_RV2CV) {
6085 o->op_private |= (cvop->op_private & OPpENTERSUB_AMPER);
6086 null(cvop); /* disable rv2cv */
6087 tmpop = (SVOP*)((UNOP*)cvop)->op_first;
6088 if (tmpop->op_type == OP_GV && !(o->op_private & OPpENTERSUB_AMPER)) {
6089 GV *gv = cGVOPx_gv(tmpop);
6092 tmpop->op_private |= OPpEARLY_CV;
6093 else if (SvPOK(cv)) {
6094 namegv = CvANON(cv) ? gv : CvGV(cv);
6095 proto = SvPV((SV*)cv, n_a);
6099 else if (cvop->op_type == OP_METHOD || cvop->op_type == OP_METHOD_NAMED) {
6100 if (o2->op_type == OP_CONST)
6101 o2->op_private &= ~OPpCONST_STRICT;
6102 else if (o2->op_type == OP_LIST) {
6103 OP *o = ((UNOP*)o2)->op_first->op_sibling;
6104 if (o && o->op_type == OP_CONST)
6105 o->op_private &= ~OPpCONST_STRICT;
6108 o->op_private |= (PL_hints & HINT_STRICT_REFS);
6109 if (PERLDB_SUB && PL_curstash != PL_debstash)
6110 o->op_private |= OPpENTERSUB_DB;
6111 while (o2 != cvop) {
6115 return too_many_arguments(o, gv_ename(namegv));
6133 if (o2->op_type != OP_REFGEN && o2->op_type != OP_UNDEF)
6134 bad_type(arg, "block", gv_ename(namegv), o2);
6137 /* '*' allows any scalar type, including bareword */
6140 if (o2->op_type == OP_RV2GV)
6141 goto wrapref; /* autoconvert GLOB -> GLOBref */
6142 else if (o2->op_type == OP_CONST)
6143 o2->op_private &= ~OPpCONST_STRICT;
6144 else if (o2->op_type == OP_ENTERSUB) {
6145 /* accidental subroutine, revert to bareword */
6146 OP *gvop = ((UNOP*)o2)->op_first;
6147 if (gvop && gvop->op_type == OP_NULL) {
6148 gvop = ((UNOP*)gvop)->op_first;
6150 for (; gvop->op_sibling; gvop = gvop->op_sibling)
6153 (gvop->op_private & OPpENTERSUB_NOPAREN) &&
6154 (gvop = ((UNOP*)gvop)->op_first) &&
6155 gvop->op_type == OP_GV)
6157 GV *gv = cGVOPx_gv(gvop);
6158 OP *sibling = o2->op_sibling;
6159 SV *n = newSVpvn("",0);
6161 gv_fullname3(n, gv, "");
6162 if (SvCUR(n)>6 && strnEQ(SvPVX(n),"main::",6))
6163 sv_chop(n, SvPVX(n)+6);
6164 o2 = newSVOP(OP_CONST, 0, n);
6165 prev->op_sibling = o2;
6166 o2->op_sibling = sibling;
6178 if (o2->op_type != OP_RV2GV)
6179 bad_type(arg, "symbol", gv_ename(namegv), o2);
6182 if (o2->op_type != OP_RV2CV)
6183 bad_type(arg, "sub", gv_ename(namegv), o2);
6186 if (o2->op_type != OP_RV2SV
6187 && o2->op_type != OP_PADSV
6188 && o2->op_type != OP_HELEM
6189 && o2->op_type != OP_AELEM
6190 && o2->op_type != OP_THREADSV)
6192 bad_type(arg, "scalar", gv_ename(namegv), o2);
6196 if (o2->op_type != OP_RV2AV && o2->op_type != OP_PADAV)
6197 bad_type(arg, "array", gv_ename(namegv), o2);
6200 if (o2->op_type != OP_RV2HV && o2->op_type != OP_PADHV)
6201 bad_type(arg, "hash", gv_ename(namegv), o2);
6205 OP* sib = kid->op_sibling;
6206 kid->op_sibling = 0;
6207 o2 = newUNOP(OP_REFGEN, 0, kid);
6208 o2->op_sibling = sib;
6209 prev->op_sibling = o2;
6220 Perl_croak(aTHX_ "Malformed prototype for %s: %s",
6221 gv_ename(namegv), SvPV((SV*)cv, n_a));
6226 mod(o2, OP_ENTERSUB);
6228 o2 = o2->op_sibling;
6230 if (proto && !optional &&
6231 (*proto && *proto != '@' && *proto != '%' && *proto != ';'))
6232 return too_few_arguments(o, gv_ename(namegv));
6237 Perl_ck_svconst(pTHX_ OP *o)
6239 SvREADONLY_on(cSVOPo->op_sv);
6244 Perl_ck_trunc(pTHX_ OP *o)
6246 if (o->op_flags & OPf_KIDS) {
6247 SVOP *kid = (SVOP*)cUNOPo->op_first;
6249 if (kid->op_type == OP_NULL)
6250 kid = (SVOP*)kid->op_sibling;
6251 if (kid && kid->op_type == OP_CONST &&
6252 (kid->op_private & OPpCONST_BARE))
6254 o->op_flags |= OPf_SPECIAL;
6255 kid->op_private &= ~OPpCONST_STRICT;
6261 /* A peephole optimizer. We visit the ops in the order they're to execute. */
6264 Perl_peep(pTHX_ register OP *o)
6267 register OP* oldop = 0;
6269 OP *last_composite = Nullop;
6271 if (!o || o->op_seq)
6275 SAVEVPTR(PL_curcop);
6276 for (; o; o = o->op_next) {
6282 switch (o->op_type) {
6286 PL_curcop = ((COP*)o); /* for warnings */
6287 o->op_seq = PL_op_seqmax++;
6288 last_composite = Nullop;
6292 if (cSVOPo->op_private & OPpCONST_STRICT)
6293 no_bareword_allowed(o);
6295 /* Relocate sv to the pad for thread safety.
6296 * Despite being a "constant", the SV is written to,
6297 * for reference counts, sv_upgrade() etc. */
6299 PADOFFSET ix = pad_alloc(OP_CONST, SVs_PADTMP);
6300 SvREFCNT_dec(PL_curpad[ix]);
6301 SvPADTMP_on(cSVOPo->op_sv);
6302 PL_curpad[ix] = cSVOPo->op_sv;
6303 cSVOPo->op_sv = Nullsv;
6315 if (o->op_next && o->op_next->op_type == OP_STRINGIFY) {
6316 if (o->op_next->op_private & OPpTARGET_MY) {
6317 if (o->op_flags & OPf_STACKED) /* chained concats */
6318 goto ignore_optimization;
6320 o->op_targ = o->op_next->op_targ;
6321 o->op_next->op_targ = 0;
6322 o->op_private |= OPpTARGET_MY;
6327 ignore_optimization:
6328 o->op_seq = PL_op_seqmax++;
6331 if ((o->op_flags & OPf_WANT) != OPf_WANT_LIST) {
6332 o->op_seq = PL_op_seqmax++;
6333 break; /* Scalar stub must produce undef. List stub is noop */
6337 if (o->op_targ == OP_NEXTSTATE
6338 || o->op_targ == OP_DBSTATE
6339 || o->op_targ == OP_SETSTATE)
6341 PL_curcop = ((COP*)o);
6348 if (oldop && o->op_next) {
6349 oldop->op_next = o->op_next;
6352 o->op_seq = PL_op_seqmax++;
6356 if (o->op_next->op_type == OP_RV2SV) {
6357 if (!(o->op_next->op_private & OPpDEREF)) {
6359 o->op_private |= o->op_next->op_private & (OPpLVAL_INTRO
6361 o->op_next = o->op_next->op_next;
6362 o->op_type = OP_GVSV;
6363 o->op_ppaddr = PL_ppaddr[OP_GVSV];
6366 else if (o->op_next->op_type == OP_RV2AV) {
6367 OP* pop = o->op_next->op_next;
6369 if (pop->op_type == OP_CONST &&
6370 (PL_op = pop->op_next) &&
6371 pop->op_next->op_type == OP_AELEM &&
6372 !(pop->op_next->op_private &
6373 (OPpLVAL_INTRO|OPpLVAL_DEFER|OPpDEREF)) &&
6374 (i = SvIV(((SVOP*)pop)->op_sv) - PL_compiling.cop_arybase)
6382 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
6383 o->op_next = pop->op_next->op_next;
6384 o->op_type = OP_AELEMFAST;
6385 o->op_ppaddr = PL_ppaddr[OP_AELEMFAST];
6386 o->op_private = (U8)i;
6391 else if ((o->op_private & OPpEARLY_CV) && ckWARN(WARN_PROTOTYPE)) {
6393 if (SvTYPE(gv) == SVt_PVGV && GvCV(gv) && SvPVX(GvCV(gv))) {
6394 /* XXX could check prototype here instead of just carping */
6395 SV *sv = sv_newmortal();
6396 gv_efullname3(sv, gv, Nullch);
6397 Perl_warner(aTHX_ WARN_PROTOTYPE,
6398 "%s() called too early to check prototype",
6403 o->op_seq = PL_op_seqmax++;
6414 o->op_seq = PL_op_seqmax++;
6415 while (cLOGOP->op_other->op_type == OP_NULL)
6416 cLOGOP->op_other = cLOGOP->op_other->op_next;
6417 peep(cLOGOP->op_other);
6421 o->op_seq = PL_op_seqmax++;
6422 peep(cLOOP->op_redoop);
6423 peep(cLOOP->op_nextop);
6424 peep(cLOOP->op_lastop);
6430 o->op_seq = PL_op_seqmax++;
6431 peep(cPMOP->op_pmreplstart);
6435 o->op_seq = PL_op_seqmax++;
6436 if (ckWARN(WARN_SYNTAX) && o->op_next
6437 && o->op_next->op_type == OP_NEXTSTATE) {
6438 if (o->op_next->op_sibling &&
6439 o->op_next->op_sibling->op_type != OP_EXIT &&
6440 o->op_next->op_sibling->op_type != OP_WARN &&
6441 o->op_next->op_sibling->op_type != OP_DIE) {
6442 line_t oldline = CopLINE(PL_curcop);
6444 CopLINE_set(PL_curcop, CopLINE((COP*)o->op_next));
6445 Perl_warner(aTHX_ WARN_EXEC,
6446 "Statement unlikely to be reached");
6447 Perl_warner(aTHX_ WARN_EXEC,
6448 "(Maybe you meant system() when you said exec()?)\n");
6449 CopLINE_set(PL_curcop, oldline);
6458 SV **svp, **indsvp, *sv;
6463 o->op_seq = PL_op_seqmax++;
6464 if ((o->op_private & (OPpLVAL_INTRO))
6465 || ((BINOP*)o)->op_last->op_type != OP_CONST)
6467 rop = (UNOP*)((BINOP*)o)->op_first;
6468 if (rop->op_type != OP_RV2HV || rop->op_first->op_type != OP_PADSV)
6470 lexname = *av_fetch(PL_comppad_name, rop->op_first->op_targ, TRUE);
6471 if (!SvOBJECT(lexname))
6473 fields = (GV**)hv_fetch(SvSTASH(lexname), "FIELDS", 6, FALSE);
6474 if (!fields || !GvHV(*fields))
6476 svp = cSVOPx_svp(((BINOP*)o)->op_last);
6477 key = SvPV(*svp, keylen);
6478 indsvp = hv_fetch(GvHV(*fields), key, keylen, FALSE);
6480 Perl_croak(aTHX_ "No such pseudo-hash field \"%s\" in variable %s of type %s",
6481 key, SvPV(lexname, n_a), HvNAME(SvSTASH(lexname)));
6483 ind = SvIV(*indsvp);
6485 Perl_croak(aTHX_ "Bad index while coercing array into hash");
6486 rop->op_type = OP_RV2AV;
6487 rop->op_ppaddr = PL_ppaddr[OP_RV2AV];
6488 o->op_type = OP_AELEM;
6489 o->op_ppaddr = PL_ppaddr[OP_AELEM];
6491 if (SvREADONLY(*svp))
6493 SvFLAGS(sv) |= (SvFLAGS(*svp)
6494 & (SVs_PADBUSY|SVs_PADTMP|SVs_PADMY));
6504 SV **svp, **indsvp, *sv;
6508 SVOP *first_key_op, *key_op;
6510 o->op_seq = PL_op_seqmax++;
6511 if ((o->op_private & (OPpLVAL_INTRO))
6512 /* I bet there's always a pushmark... */
6513 || ((LISTOP*)o)->op_first->op_sibling->op_type != OP_LIST)
6514 /* hmmm, no optimization if list contains only one key. */
6516 rop = (UNOP*)((LISTOP*)o)->op_last;
6517 if (rop->op_type != OP_RV2HV || rop->op_first->op_type != OP_PADSV)
6519 lexname = *av_fetch(PL_comppad_name, rop->op_first->op_targ, TRUE);
6520 if (!SvOBJECT(lexname))
6522 fields = (GV**)hv_fetch(SvSTASH(lexname), "FIELDS", 6, FALSE);
6523 if (!fields || !GvHV(*fields))
6525 /* Again guessing that the pushmark can be jumped over.... */
6526 first_key_op = (SVOP*)((LISTOP*)((LISTOP*)o)->op_first->op_sibling)
6527 ->op_first->op_sibling;
6528 /* Check that the key list contains only constants. */
6529 for (key_op = first_key_op; key_op;
6530 key_op = (SVOP*)key_op->op_sibling)
6531 if (key_op->op_type != OP_CONST)
6535 rop->op_type = OP_RV2AV;
6536 rop->op_ppaddr = PL_ppaddr[OP_RV2AV];
6537 o->op_type = OP_ASLICE;
6538 o->op_ppaddr = PL_ppaddr[OP_ASLICE];
6539 for (key_op = first_key_op; key_op;
6540 key_op = (SVOP*)key_op->op_sibling) {
6541 svp = cSVOPx_svp(key_op);
6542 key = SvPV(*svp, keylen);
6543 indsvp = hv_fetch(GvHV(*fields), key, keylen, FALSE);
6545 Perl_croak(aTHX_ "No such pseudo-hash field \"%s\" "
6546 "in variable %s of type %s",
6547 key, SvPV(lexname, n_a), HvNAME(SvSTASH(lexname)));
6549 ind = SvIV(*indsvp);
6551 Perl_croak(aTHX_ "Bad index while coercing array into hash");
6553 if (SvREADONLY(*svp))
6555 SvFLAGS(sv) |= (SvFLAGS(*svp)
6556 & (SVs_PADBUSY|SVs_PADTMP|SVs_PADMY));
6565 if (!(o->op_flags & OPf_WANT)
6566 || (o->op_flags & OPf_WANT) == OPf_WANT_LIST)
6570 o->op_seq = PL_op_seqmax++;
6574 if (o->op_next && o->op_next->op_type != OP_LEAVESUBLV) {
6575 o->op_seq = PL_op_seqmax++;
6581 if (last_composite) {
6582 OP *r = last_composite;
6584 while (r->op_sibling)
6587 || (r->op_next->op_type == OP_LIST
6588 && r->op_next->op_next == o))
6590 if (last_composite->op_type == OP_RV2AV)
6591 yyerror("Lvalue subs returning arrays not implemented yet");
6593 yyerror("Lvalue subs returning hashes not implemented yet");
6600 o->op_seq = PL_op_seqmax++;