3 * Copyright (c) 1991-1999, 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 */
27 # define OP_REFCNT_LOCK NOOP
28 # define OP_REFCNT_UNLOCK NOOP
29 # define OpREFCNT_set(o,n) ((o)->op_targ = (n))
30 # define OpREFCNT_dec(o) (--(o)->op_targ)
32 # define OP_REFCNT_LOCK NOOP
33 # define OP_REFCNT_UNLOCK NOOP
34 # define OpREFCNT_set(o,n) NOOP
35 # define OpREFCNT_dec(o) 0
38 #ifdef PL_OP_SLAB_ALLOC
39 #define SLAB_SIZE 8192
40 static char *PL_OpPtr = NULL;
41 static int PL_OpSpace = 0;
42 #define NewOp(m,var,c,type) do { if ((PL_OpSpace -= c*sizeof(type)) >= 0) \
43 var = (type *)(PL_OpPtr -= c*sizeof(type)); \
45 var = (type *) Slab_Alloc(m,c*sizeof(type)); \
49 S_Slab_Alloc(pTHX_ int m, size_t sz)
51 Newz(m,PL_OpPtr,SLAB_SIZE,char);
52 PL_OpSpace = SLAB_SIZE - sz;
53 return PL_OpPtr += PL_OpSpace;
57 #define NewOp(m, var, c, type) Newz(m, var, c, type)
60 * In the following definition, the ", Nullop" is just to make the compiler
61 * think the expression is of the right type: croak actually does a Siglongjmp.
63 #define CHECKOP(type,o) \
64 ((PL_op_mask && PL_op_mask[type]) \
65 ? ( op_free((OP*)o), \
66 Perl_croak(aTHX_ "%s trapped by operation mask", PL_op_desc[type]), \
68 : CALL_FPTR(PL_check[type])(aTHX_ (OP*)o))
70 #define PAD_MAX 999999999
73 S_gv_ename(pTHX_ GV *gv)
76 SV* tmpsv = sv_newmortal();
77 gv_efullname3(tmpsv, gv, Nullch);
78 return SvPV(tmpsv,n_a);
82 S_no_fh_allowed(pTHX_ OP *o)
84 yyerror(Perl_form(aTHX_ "Missing comma after first argument to %s function",
85 PL_op_desc[o->op_type]));
90 S_too_few_arguments(pTHX_ OP *o, char *name)
92 yyerror(Perl_form(aTHX_ "Not enough arguments for %s", name));
97 S_too_many_arguments(pTHX_ OP *o, char *name)
99 yyerror(Perl_form(aTHX_ "Too many arguments for %s", name));
104 S_bad_type(pTHX_ I32 n, char *t, char *name, OP *kid)
106 yyerror(Perl_form(aTHX_ "Type of arg %d to %s must be %s (not %s)",
107 (int)n, name, t, PL_op_desc[kid->op_type]));
111 S_no_bareword_allowed(pTHX_ OP *o)
113 qerror(Perl_mess(aTHX_
114 "Bareword \"%s\" not allowed while \"strict subs\" in use",
115 SvPV_nolen(cSVOPo_sv)));
118 /* "register" allocation */
121 Perl_pad_allocmy(pTHX_ char *name)
128 PL_in_my == KEY_our ||
130 (PL_hints & HINT_UTF8 && (name[1] & 0xc0) == 0xc0) ||
131 name[1] == '_' && (int)strlen(name) > 2 ))
133 if (!isPRINT(name[1]) || strchr("\t\n\r\f", name[1])) {
134 /* 1999-02-27 mjd@plover.com */
136 p = strchr(name, '\0');
137 /* The next block assumes the buffer is at least 205 chars
138 long. At present, it's always at least 256 chars. */
140 strcpy(name+200, "...");
146 /* Move everything else down one character */
147 for (; p-name > 2; p--)
149 name[2] = toCTRL(name[1]);
152 yyerror(Perl_form(aTHX_ "Can't use global %s in \"my\"",name));
154 if (ckWARN(WARN_UNSAFE) && AvFILLp(PL_comppad_name) >= 0) {
155 SV **svp = AvARRAY(PL_comppad_name);
156 for (off = AvFILLp(PL_comppad_name); off > PL_comppad_name_floor; off--) {
158 && sv != &PL_sv_undef
159 && (SvIVX(sv) == PAD_MAX || SvIVX(sv) == 0)
160 && strEQ(name, SvPVX(sv)))
162 if (PL_in_my != KEY_our
163 || GvSTASH(sv) == (PL_curstash ? PL_curstash : PL_defstash))
165 Perl_warner(aTHX_ WARN_UNSAFE,
166 "\"%s\" variable %s masks earlier declaration in same %s",
167 (PL_in_my == KEY_our ? "our" : "my"),
169 (SvIVX(sv) == PAD_MAX ? "scope" : "statement"));
175 off = pad_alloc(OP_PADSV, SVs_PADMY);
177 sv_upgrade(sv, SVt_PVNV);
179 if (PL_in_my_stash) {
181 yyerror(Perl_form(aTHX_ "Can't declare class for non-scalar %s in \"%s\"",
182 name, PL_in_my == KEY_our ? "our" : "my"));
184 (void)SvUPGRADE(sv, SVt_PVMG);
185 SvSTASH(sv) = (HV*)SvREFCNT_inc(PL_in_my_stash);
188 if (PL_in_my == KEY_our) {
189 (void)SvUPGRADE(sv, SVt_PVGV);
190 GvSTASH(sv) = (HV*)SvREFCNT_inc(PL_curstash ? PL_curstash : PL_defstash);
191 SvFLAGS(sv) |= SVpad_OUR;
193 av_store(PL_comppad_name, off, sv);
194 SvNVX(sv) = (NV)PAD_MAX;
195 SvIVX(sv) = 0; /* Not yet introduced--see newSTATEOP */
196 if (!PL_min_intro_pending)
197 PL_min_intro_pending = off;
198 PL_max_intro_pending = off;
200 av_store(PL_comppad, off, (SV*)newAV());
201 else if (*name == '%')
202 av_store(PL_comppad, off, (SV*)newHV());
203 SvPADMY_on(PL_curpad[off]);
208 S_pad_addlex(pTHX_ SV *proto_namesv)
210 SV *namesv = NEWSV(1103,0);
211 PADOFFSET newoff = pad_alloc(OP_PADSV, SVs_PADMY);
212 sv_upgrade(namesv, SVt_PVNV);
213 sv_setpv(namesv, SvPVX(proto_namesv));
214 av_store(PL_comppad_name, newoff, namesv);
215 SvNVX(namesv) = (NV)PL_curcop->cop_seq;
216 SvIVX(namesv) = PAD_MAX; /* A ref, intro immediately */
217 SvFAKE_on(namesv); /* A ref, not a real var */
218 if (SvFLAGS(proto_namesv) & SVpad_OUR) { /* An "our" variable */
219 SvFLAGS(namesv) |= SVpad_OUR;
220 (void)SvUPGRADE(namesv, SVt_PVGV);
221 GvSTASH(namesv) = (HV*)SvREFCNT_inc((SV*)GvSTASH(proto_namesv));
223 if (SvOBJECT(proto_namesv)) { /* A typed var */
225 (void)SvUPGRADE(namesv, SVt_PVMG);
226 SvSTASH(namesv) = (HV*)SvREFCNT_inc((SV*)SvSTASH(proto_namesv));
232 #define FINDLEX_NOSEARCH 1 /* don't search outer contexts */
235 S_pad_findlex(pTHX_ char *name, PADOFFSET newoff, U32 seq, CV* startcv,
236 I32 cx_ix, I32 saweval, U32 flags)
243 register PERL_CONTEXT *cx;
245 for (cv = startcv; cv; cv = CvOUTSIDE(cv)) {
246 AV *curlist = CvPADLIST(cv);
247 SV **svp = av_fetch(curlist, 0, FALSE);
250 if (!svp || *svp == &PL_sv_undef)
253 svp = AvARRAY(curname);
254 for (off = AvFILLp(curname); off > 0; off--) {
255 if ((sv = svp[off]) &&
256 sv != &PL_sv_undef &&
258 seq > I_32(SvNVX(sv)) &&
259 strEQ(SvPVX(sv), name))
270 return 0; /* don't clone from inactive stack frame */
274 oldpad = (AV*)AvARRAY(curlist)[depth];
275 oldsv = *av_fetch(oldpad, off, TRUE);
276 if (!newoff) { /* Not a mere clone operation. */
277 newoff = pad_addlex(sv);
278 if (CvANON(PL_compcv) || SvTYPE(PL_compcv) == SVt_PVFM) {
279 /* "It's closures all the way down." */
280 CvCLONE_on(PL_compcv);
282 if (CvANON(PL_compcv))
283 oldsv = Nullsv; /* no need to keep ref */
288 bcv && bcv != cv && !CvCLONE(bcv);
289 bcv = CvOUTSIDE(bcv))
292 /* install the missing pad entry in intervening
293 * nested subs and mark them cloneable.
294 * XXX fix pad_foo() to not use globals */
295 AV *ocomppad_name = PL_comppad_name;
296 AV *ocomppad = PL_comppad;
297 SV **ocurpad = PL_curpad;
298 AV *padlist = CvPADLIST(bcv);
299 PL_comppad_name = (AV*)AvARRAY(padlist)[0];
300 PL_comppad = (AV*)AvARRAY(padlist)[1];
301 PL_curpad = AvARRAY(PL_comppad);
303 PL_comppad_name = ocomppad_name;
304 PL_comppad = ocomppad;
309 if (ckWARN(WARN_CLOSURE)
310 && !CvUNIQUE(bcv) && !CvUNIQUE(cv))
312 Perl_warner(aTHX_ WARN_CLOSURE,
313 "Variable \"%s\" may be unavailable",
321 else if (!CvUNIQUE(PL_compcv)) {
322 if (ckWARN(WARN_CLOSURE) && !SvFAKE(sv) && !CvUNIQUE(cv))
323 Perl_warner(aTHX_ WARN_CLOSURE,
324 "Variable \"%s\" will not stay shared", name);
327 av_store(PL_comppad, newoff, SvREFCNT_inc(oldsv));
333 if (flags & FINDLEX_NOSEARCH)
336 /* Nothing in current lexical context--try eval's context, if any.
337 * This is necessary to let the perldb get at lexically scoped variables.
338 * XXX This will also probably interact badly with eval tree caching.
341 for (i = cx_ix; i >= 0; i--) {
343 switch (CxTYPE(cx)) {
345 if (i == 0 && saweval) {
346 seq = cxstack[saweval].blk_oldcop->cop_seq;
347 return pad_findlex(name, newoff, seq, PL_main_cv, -1, saweval, 0);
351 switch (cx->blk_eval.old_op_type) {
357 /* require must have its own scope */
366 if (PL_debstash && CvSTASH(cv) == PL_debstash) { /* ignore DB'* scope */
367 saweval = i; /* so we know where we were called from */
370 seq = cxstack[saweval].blk_oldcop->cop_seq;
371 return pad_findlex(name, newoff, seq, cv, i-1, saweval,FINDLEX_NOSEARCH);
379 Perl_pad_findmy(pTHX_ char *name)
385 SV **svp = AvARRAY(PL_comppad_name);
386 U32 seq = PL_cop_seqmax;
392 * Special case to get lexical (and hence per-thread) @_.
393 * XXX I need to find out how to tell at parse-time whether use
394 * of @_ should refer to a lexical (from a sub) or defgv (global
395 * scope and maybe weird sub-ish things like formats). See
396 * startsub in perly.y. It's possible that @_ could be lexical
397 * (at least from subs) even in non-threaded perl.
399 if (strEQ(name, "@_"))
400 return 0; /* success. (NOT_IN_PAD indicates failure) */
401 #endif /* USE_THREADS */
403 /* The one we're looking for is probably just before comppad_name_fill. */
404 for (off = AvFILLp(PL_comppad_name); off > 0; off--) {
405 if ((sv = svp[off]) &&
406 sv != &PL_sv_undef &&
409 seq > I_32(SvNVX(sv)))) &&
410 strEQ(SvPVX(sv), name))
412 if (SvIVX(sv) || SvFLAGS(sv) & SVpad_OUR)
413 return (PADOFFSET)off;
414 pendoff = off; /* this pending def. will override import */
418 outside = CvOUTSIDE(PL_compcv);
420 /* Check if if we're compiling an eval'', and adjust seq to be the
421 * eval's seq number. This depends on eval'' having a non-null
422 * CvOUTSIDE() while it is being compiled. The eval'' itself is
423 * identified by CvEVAL being true and CvGV being null. */
424 if (outside && CvEVAL(PL_compcv) && !CvGV(PL_compcv) && cxstack_ix >= 0) {
425 cx = &cxstack[cxstack_ix];
427 seq = cx->blk_oldcop->cop_seq;
430 /* See if it's in a nested scope */
431 off = pad_findlex(name, 0, seq, outside, cxstack_ix, 0, 0);
433 /* If there is a pending local definition, this new alias must die */
435 SvIVX(AvARRAY(PL_comppad_name)[off]) = seq;
436 return off; /* pad_findlex returns 0 for failure...*/
438 return NOT_IN_PAD; /* ...but we return NOT_IN_PAD for failure */
442 Perl_pad_leavemy(pTHX_ I32 fill)
446 SV **svp = AvARRAY(PL_comppad_name);
448 if (PL_min_intro_pending && fill < PL_min_intro_pending) {
449 for (off = PL_max_intro_pending; off >= PL_min_intro_pending; off--) {
450 if ((sv = svp[off]) && sv != &PL_sv_undef && ckWARN_d(WARN_INTERNAL))
451 Perl_warner(aTHX_ WARN_INTERNAL, "%s never introduced", SvPVX(sv));
454 /* "Deintroduce" my variables that are leaving with this scope. */
455 for (off = AvFILLp(PL_comppad_name); off > fill; off--) {
456 if ((sv = svp[off]) && sv != &PL_sv_undef && SvIVX(sv) == PAD_MAX)
457 SvIVX(sv) = PL_cop_seqmax;
462 Perl_pad_alloc(pTHX_ I32 optype, U32 tmptype)
468 if (AvARRAY(PL_comppad) != PL_curpad)
469 Perl_croak(aTHX_ "panic: pad_alloc");
470 if (PL_pad_reset_pending)
472 if (tmptype & SVs_PADMY) {
474 sv = *av_fetch(PL_comppad, AvFILLp(PL_comppad) + 1, TRUE);
475 } while (SvPADBUSY(sv)); /* need a fresh one */
476 retval = AvFILLp(PL_comppad);
479 SV **names = AvARRAY(PL_comppad_name);
480 SSize_t names_fill = AvFILLp(PL_comppad_name);
483 * "foreach" index vars temporarily become aliases to non-"my"
484 * values. Thus we must skip, not just pad values that are
485 * marked as current pad values, but also those with names.
487 if (++PL_padix <= names_fill &&
488 (sv = names[PL_padix]) && sv != &PL_sv_undef)
490 sv = *av_fetch(PL_comppad, PL_padix, TRUE);
491 if (!(SvFLAGS(sv) & (SVs_PADTMP|SVs_PADMY)) && !IS_PADGV(sv))
496 SvFLAGS(sv) |= tmptype;
497 PL_curpad = AvARRAY(PL_comppad);
499 DEBUG_X(PerlIO_printf(Perl_debug_log,
500 "0x%"UVxf" Pad 0x%"UVxf" alloc %ld for %s\n",
501 PTR2UV(thr), PTR2UV(PL_curpad),
502 (long) retval, PL_op_name[optype]));
504 DEBUG_X(PerlIO_printf(Perl_debug_log,
505 "Pad 0x%"UVxf" alloc %ld for %s\n",
507 (long) retval, PL_op_name[optype]));
508 #endif /* USE_THREADS */
509 return (PADOFFSET)retval;
513 Perl_pad_sv(pTHX_ PADOFFSET po)
517 DEBUG_X(PerlIO_printf(Perl_debug_log,
518 "0x%"UVxf" Pad 0x%"UVxf" sv %"IVdf"\n",
519 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
522 Perl_croak(aTHX_ "panic: pad_sv po");
523 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" sv %"IVdf"\n",
524 PTR2UV(PL_curpad), (IV)po));
525 #endif /* USE_THREADS */
526 return PL_curpad[po]; /* eventually we'll turn this into a macro */
530 Perl_pad_free(pTHX_ PADOFFSET po)
535 if (AvARRAY(PL_comppad) != PL_curpad)
536 Perl_croak(aTHX_ "panic: pad_free curpad");
538 Perl_croak(aTHX_ "panic: pad_free po");
540 DEBUG_X(PerlIO_printf(Perl_debug_log,
541 "0x%"UVxf" Pad 0x%"UVxf" free %"IVdf"\n",
542 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
544 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" free %"IVdf"\n",
545 PTR2UV(PL_curpad), (IV)po));
546 #endif /* USE_THREADS */
547 if (PL_curpad[po] && PL_curpad[po] != &PL_sv_undef) {
548 SvPADTMP_off(PL_curpad[po]);
550 SvREADONLY_off(PL_curpad[po]); /* could be a freed constant */
553 if ((I32)po < PL_padix)
558 Perl_pad_swipe(pTHX_ PADOFFSET po)
561 if (AvARRAY(PL_comppad) != PL_curpad)
562 Perl_croak(aTHX_ "panic: pad_swipe curpad");
564 Perl_croak(aTHX_ "panic: pad_swipe po");
566 DEBUG_X(PerlIO_printf(Perl_debug_log,
567 "0x%"UVxf" Pad 0x%"UVxf" swipe %"IVdf"\n",
568 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
570 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" swipe %"IVdf"\n",
571 PTR2UV(PL_curpad), (IV)po));
572 #endif /* USE_THREADS */
573 SvPADTMP_off(PL_curpad[po]);
574 PL_curpad[po] = NEWSV(1107,0);
575 SvPADTMP_on(PL_curpad[po]);
576 if ((I32)po < PL_padix)
580 /* XXX pad_reset() is currently disabled because it results in serious bugs.
581 * It causes pad temp TARGs to be shared between OPs. Since TARGs are pushed
582 * on the stack by OPs that use them, there are several ways to get an alias
583 * to a shared TARG. Such an alias will change randomly and unpredictably.
584 * We avoid doing this until we can think of a Better Way.
589 #ifdef USE_BROKEN_PAD_RESET
593 if (AvARRAY(PL_comppad) != PL_curpad)
594 Perl_croak(aTHX_ "panic: pad_reset curpad");
596 DEBUG_X(PerlIO_printf(Perl_debug_log,
597 "0x%"UVxf" Pad 0x%"UVxf" reset\n",
598 PTR2UV(thr), PTR2UV(PL_curpad)));
600 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" reset\n",
602 #endif /* USE_THREADS */
603 if (!PL_tainting) { /* Can't mix tainted and non-tainted temporaries. */
604 for (po = AvMAX(PL_comppad); po > PL_padix_floor; po--) {
605 if (PL_curpad[po] && !SvIMMORTAL(PL_curpad[po]))
606 SvPADTMP_off(PL_curpad[po]);
608 PL_padix = PL_padix_floor;
611 PL_pad_reset_pending = FALSE;
615 /* find_threadsv is not reentrant */
617 Perl_find_threadsv(pTHX_ const char *name)
623 /* We currently only handle names of a single character */
624 p = strchr(PL_threadsv_names, *name);
627 key = p - PL_threadsv_names;
628 MUTEX_LOCK(&thr->mutex);
629 svp = av_fetch(thr->threadsv, key, FALSE);
631 MUTEX_UNLOCK(&thr->mutex);
633 SV *sv = NEWSV(0, 0);
634 av_store(thr->threadsv, key, sv);
635 thr->threadsvp = AvARRAY(thr->threadsv);
636 MUTEX_UNLOCK(&thr->mutex);
638 * Some magic variables used to be automagically initialised
639 * in gv_fetchpv. Those which are now per-thread magicals get
640 * initialised here instead.
646 sv_setpv(sv, "\034");
647 sv_magic(sv, 0, 0, name, 1);
652 PL_sawampersand = TRUE;
666 /* XXX %! tied to Errno.pm needs to be added here.
667 * See gv_fetchpv(). */
671 sv_magic(sv, 0, 0, name, 1);
673 DEBUG_S(PerlIO_printf(Perl_error_log,
674 "find_threadsv: new SV %p for $%s%c\n",
675 sv, (*name < 32) ? "^" : "",
676 (*name < 32) ? toCTRL(*name) : *name));
680 #endif /* USE_THREADS */
685 Perl_op_free(pTHX_ OP *o)
687 register OP *kid, *nextkid;
690 if (!o || o->op_seq == (U16)-1)
693 if (o->op_private & OPpREFCOUNTED) {
694 switch (o->op_type) {
702 if (OpREFCNT_dec(o)) {
713 if (o->op_flags & OPf_KIDS) {
714 for (kid = cUNOPo->op_first; kid; kid = nextkid) {
715 nextkid = kid->op_sibling; /* Get before next freeing kid */
723 /* COP* is not cleared by op_clear() so that we may track line
724 * numbers etc even after null() */
725 if (type == OP_NEXTSTATE || type == OP_SETSTATE || type == OP_DBSTATE)
730 #ifdef PL_OP_SLAB_ALLOC
731 if ((char *) o == PL_OpPtr)
740 S_op_clear(pTHX_ OP *o)
742 switch (o->op_type) {
743 case OP_NULL: /* Was holding old type, if any. */
744 case OP_ENTEREVAL: /* Was holding hints. */
746 case OP_THREADSV: /* Was holding index into thr->threadsv AV. */
752 if (!(o->op_flags & OPf_SPECIAL))
755 #endif /* USE_THREADS */
757 if (!(o->op_flags & OPf_REF)
758 || (PL_check[o->op_type] != MEMBER_TO_FPTR(Perl_ck_ftst)))
765 if (cPADOPo->op_padix > 0) {
768 pad_swipe(cPADOPo->op_padix);
769 /* No GvIN_PAD_off(gv) here, because other references may still
770 * exist on the pad */
773 cPADOPo->op_padix = 0;
776 SvREFCNT_dec(cSVOPo->op_sv);
777 cSVOPo->op_sv = Nullsv;
781 SvREFCNT_dec(cSVOPo->op_sv);
782 cSVOPo->op_sv = Nullsv;
788 if (o->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
792 if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
793 SvREFCNT_dec(cSVOPo->op_sv);
794 cSVOPo->op_sv = Nullsv;
797 Safefree(cPVOPo->op_pv);
798 cPVOPo->op_pv = Nullch;
802 op_free(cPMOPo->op_pmreplroot);
806 if ((PADOFFSET)cPMOPo->op_pmreplroot) {
808 GV *gv = (GV*)PL_curpad[(PADOFFSET)cPMOPo->op_pmreplroot];
809 pad_swipe((PADOFFSET)cPMOPo->op_pmreplroot);
810 /* No GvIN_PAD_off(gv) here, because other references may still
811 * exist on the pad */
816 SvREFCNT_dec((SV*)cPMOPo->op_pmreplroot);
822 cPMOPo->op_pmreplroot = Nullop;
823 ReREFCNT_dec(cPMOPo->op_pmregexp);
824 cPMOPo->op_pmregexp = (REGEXP*)NULL;
828 if (o->op_targ > 0) {
829 pad_free(o->op_targ);
835 S_cop_free(pTHX_ COP* cop)
837 Safefree(cop->cop_label);
839 Safefree(CopFILE(cop)); /* XXXXX share in a pvtable? */
840 Safefree(CopSTASHPV(cop)); /* XXXXX share in a pvtable? */
842 /* NOTE: COP.cop_stash is not refcounted */
843 SvREFCNT_dec(CopFILEGV(cop));
845 if (! specialWARN(cop->cop_warnings))
846 SvREFCNT_dec(cop->cop_warnings);
852 if (o->op_type == OP_NULL)
855 o->op_targ = o->op_type;
856 o->op_type = OP_NULL;
857 o->op_ppaddr = PL_ppaddr[OP_NULL];
860 /* Contextualizers */
862 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
865 Perl_linklist(pTHX_ OP *o)
872 /* establish postfix order */
873 if (cUNOPo->op_first) {
874 o->op_next = LINKLIST(cUNOPo->op_first);
875 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
877 kid->op_next = LINKLIST(kid->op_sibling);
889 Perl_scalarkids(pTHX_ OP *o)
892 if (o && o->op_flags & OPf_KIDS) {
893 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
900 S_scalarboolean(pTHX_ OP *o)
902 if (o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST) {
904 if (ckWARN(WARN_SYNTAX)) {
905 line_t oldline = CopLINE(PL_curcop);
907 if (PL_copline != NOLINE)
908 CopLINE_set(PL_curcop, PL_copline);
909 Perl_warner(aTHX_ WARN_SYNTAX, "Found = in conditional, should be ==");
910 CopLINE_set(PL_curcop, oldline);
917 Perl_scalar(pTHX_ OP *o)
921 /* assumes no premature commitment */
922 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
923 || o->op_type == OP_RETURN)
928 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_SCALAR;
930 switch (o->op_type) {
932 if (o->op_private & OPpREPEAT_DOLIST)
933 null(((LISTOP*)cBINOPo->op_first)->op_first);
934 scalar(cBINOPo->op_first);
939 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
943 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
944 if (!kPMOP->op_pmreplroot)
945 deprecate("implicit split to @_");
953 if (o->op_flags & OPf_KIDS) {
954 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
960 kid = cLISTOPo->op_first;
962 while (kid = kid->op_sibling) {
968 WITH_THR(PL_curcop = &PL_compiling);
973 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
979 WITH_THR(PL_curcop = &PL_compiling);
986 Perl_scalarvoid(pTHX_ OP *o)
993 if (o->op_type == OP_NEXTSTATE
994 || o->op_type == OP_SETSTATE
995 || o->op_type == OP_DBSTATE
996 || (o->op_type == OP_NULL && (o->op_targ == OP_NEXTSTATE
997 || o->op_targ == OP_SETSTATE
998 || o->op_targ == OP_DBSTATE)))
1001 PL_curcop = (COP*)o; /* for warning below */
1004 /* assumes no premature commitment */
1005 want = o->op_flags & OPf_WANT;
1006 if ((want && want != OPf_WANT_SCALAR) || PL_error_count
1007 || o->op_type == OP_RETURN)
1012 if ((o->op_private & OPpTARGET_MY)
1013 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
1015 return scalar(o); /* As if inside SASSIGN */
1018 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_VOID;
1020 switch (o->op_type) {
1022 if (!(PL_opargs[o->op_type] & OA_FOLDCONST))
1026 if (o->op_flags & OPf_STACKED)
1030 if (o->op_private == 4)
1072 case OP_GETSOCKNAME:
1073 case OP_GETPEERNAME:
1078 case OP_GETPRIORITY:
1101 if (!(o->op_private & OPpLVAL_INTRO))
1102 useless = PL_op_desc[o->op_type];
1109 if (!(o->op_private & (OPpLVAL_INTRO|OPpOUR_INTRO)) &&
1110 (!o->op_sibling || o->op_sibling->op_type != OP_READLINE))
1111 useless = "a variable";
1116 if (cSVOPo->op_private & OPpCONST_STRICT)
1117 no_bareword_allowed(o);
1120 if (ckWARN(WARN_VOID)) {
1121 useless = "a constant";
1122 if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
1124 else if (SvPOK(sv)) {
1125 if (strnEQ(SvPVX(sv), "di", 2) ||
1126 strnEQ(SvPVX(sv), "ds", 2) ||
1127 strnEQ(SvPVX(sv), "ig", 2))
1132 null(o); /* don't execute or even remember it */
1136 o->op_type = OP_PREINC; /* pre-increment is faster */
1137 o->op_ppaddr = PL_ppaddr[OP_PREINC];
1141 o->op_type = OP_PREDEC; /* pre-decrement is faster */
1142 o->op_ppaddr = PL_ppaddr[OP_PREDEC];
1148 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1153 if (o->op_flags & OPf_STACKED)
1161 if (!(o->op_flags & OPf_KIDS))
1170 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1177 /* all requires must return a boolean value */
1178 o->op_flags &= ~OPf_WANT;
1181 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
1182 if (!kPMOP->op_pmreplroot)
1183 deprecate("implicit split to @_");
1189 if (ckWARN(WARN_VOID))
1190 Perl_warner(aTHX_ WARN_VOID, "Useless use of %s in void context", useless);
1196 Perl_listkids(pTHX_ OP *o)
1199 if (o && o->op_flags & OPf_KIDS) {
1200 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1207 Perl_list(pTHX_ OP *o)
1211 /* assumes no premature commitment */
1212 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
1213 || o->op_type == OP_RETURN)
1218 if ((o->op_private & OPpTARGET_MY)
1219 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
1221 return o; /* As if inside SASSIGN */
1224 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_LIST;
1226 switch (o->op_type) {
1229 list(cBINOPo->op_first);
1234 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1242 if (!(o->op_flags & OPf_KIDS))
1244 if (!o->op_next && cUNOPo->op_first->op_type == OP_FLOP) {
1245 list(cBINOPo->op_first);
1246 return gen_constant_list(o);
1253 kid = cLISTOPo->op_first;
1255 while (kid = kid->op_sibling) {
1256 if (kid->op_sibling)
1261 WITH_THR(PL_curcop = &PL_compiling);
1265 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
1266 if (kid->op_sibling)
1271 WITH_THR(PL_curcop = &PL_compiling);
1274 /* all requires must return a boolean value */
1275 o->op_flags &= ~OPf_WANT;
1282 Perl_scalarseq(pTHX_ OP *o)
1287 if (o->op_type == OP_LINESEQ ||
1288 o->op_type == OP_SCOPE ||
1289 o->op_type == OP_LEAVE ||
1290 o->op_type == OP_LEAVETRY)
1293 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
1294 if (kid->op_sibling) {
1298 PL_curcop = &PL_compiling;
1300 o->op_flags &= ~OPf_PARENS;
1301 if (PL_hints & HINT_BLOCK_SCOPE)
1302 o->op_flags |= OPf_PARENS;
1305 o = newOP(OP_STUB, 0);
1310 S_modkids(pTHX_ OP *o, I32 type)
1313 if (o && o->op_flags & OPf_KIDS) {
1314 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1321 Perl_mod(pTHX_ OP *o, I32 type)
1328 if (!o || PL_error_count)
1331 if ((o->op_private & OPpTARGET_MY)
1332 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
1337 switch (o->op_type) {
1342 if (!(o->op_private & (OPpCONST_ARYBASE)))
1344 if (PL_eval_start && PL_eval_start->op_type == OP_CONST) {
1345 PL_compiling.cop_arybase = (I32)SvIV(cSVOPx(PL_eval_start)->op_sv);
1349 SAVEI32(PL_compiling.cop_arybase);
1350 PL_compiling.cop_arybase = 0;
1352 else if (type == OP_REFGEN)
1355 Perl_croak(aTHX_ "That use of $[ is unsupported");
1358 if (o->op_flags & OPf_PARENS)
1362 if ((type == OP_UNDEF || type == OP_REFGEN) &&
1363 !(o->op_flags & OPf_STACKED)) {
1364 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1365 o->op_ppaddr = PL_ppaddr[OP_RV2CV];
1366 assert(cUNOPo->op_first->op_type == OP_NULL);
1367 null(((LISTOP*)cUNOPo->op_first)->op_first);/* disable pushmark */
1370 else { /* lvalue subroutine call */
1371 o->op_private |= OPpLVAL_INTRO;
1372 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN) {
1373 /* Backward compatibility mode: */
1374 o->op_private |= OPpENTERSUB_INARGS;
1377 else { /* Compile-time error message: */
1378 OP *kid = cUNOPo->op_first;
1382 if (kid->op_type == OP_PUSHMARK)
1384 if (kid->op_type != OP_NULL || kid->op_targ != OP_LIST)
1386 "panic: unexpected lvalue entersub "
1387 "args: type/targ %ld:%ld",
1388 (long)kid->op_type,kid->op_targ);
1389 kid = kLISTOP->op_first;
1391 while (kid->op_sibling)
1392 kid = kid->op_sibling;
1393 if (!(kid->op_type == OP_NULL && kid->op_targ == OP_RV2CV)) {
1395 if (kid->op_type == OP_METHOD_NAMED
1396 || kid->op_type == OP_METHOD)
1400 if (kid->op_sibling || kid->op_next != kid) {
1401 yyerror("panic: unexpected optree near method call");
1405 NewOp(1101, newop, 1, OP);
1406 newop->op_type = OP_RV2CV;
1407 newop->op_ppaddr = PL_ppaddr[OP_RV2CV];
1408 newop->op_next = newop;
1409 kid->op_sibling = newop;
1410 newop->op_private |= OPpLVAL_INTRO;
1414 if (kid->op_type != OP_RV2CV)
1416 "panic: unexpected lvalue entersub "
1417 "entry via type/targ %ld:%ld",
1418 (long)kid->op_type,kid->op_targ);
1419 kid->op_private |= OPpLVAL_INTRO;
1420 break; /* Postpone until runtime */
1424 kid = kUNOP->op_first;
1425 if (kid->op_type == OP_NULL && kid->op_targ == OP_RV2SV)
1426 kid = kUNOP->op_first;
1427 if (kid->op_type == OP_NULL)
1429 "Unexpected constant lvalue entersub "
1430 "entry via type/targ %ld:%ld",
1431 (long)kid->op_type,kid->op_targ);
1432 if (kid->op_type != OP_GV) {
1433 /* Restore RV2CV to check lvalueness */
1435 if (kid->op_next && kid->op_next != kid) { /* Happens? */
1436 okid->op_next = kid->op_next;
1437 kid->op_next = okid;
1440 okid->op_next = Nullop;
1441 okid->op_type = OP_RV2CV;
1443 okid->op_ppaddr = PL_ppaddr[OP_RV2CV];
1444 okid->op_private |= OPpLVAL_INTRO;
1448 cv = GvCV(kGVOP_gv);
1458 /* grep, foreach, subcalls, refgen */
1459 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
1461 yyerror(Perl_form(aTHX_ "Can't modify %s in %s",
1462 (o->op_type == OP_NULL && (o->op_flags & OPf_SPECIAL)
1464 : (o->op_type == OP_ENTERSUB
1465 ? "non-lvalue subroutine call"
1466 : PL_op_desc[o->op_type])),
1467 type ? PL_op_desc[type] : "local"));
1481 case OP_RIGHT_SHIFT:
1490 if (!(o->op_flags & OPf_STACKED))
1496 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1502 if (!type && cUNOPo->op_first->op_type != OP_GV)
1503 Perl_croak(aTHX_ "Can't localize through a reference");
1504 if (type == OP_REFGEN && o->op_flags & OPf_PARENS) {
1505 PL_modcount = 10000;
1506 return o; /* Treat \(@foo) like ordinary list. */
1510 if (scalar_mod_type(o, type))
1512 ref(cUNOPo->op_first, o->op_type);
1521 PL_modcount = 10000;
1524 if (!type && cUNOPo->op_first->op_type != OP_GV)
1525 Perl_croak(aTHX_ "Can't localize through a reference");
1526 ref(cUNOPo->op_first, o->op_type);
1530 PL_hints |= HINT_BLOCK_SCOPE;
1540 PL_modcount = 10000;
1541 if (type == OP_REFGEN && o->op_flags & OPf_PARENS)
1542 return o; /* Treat \(@foo) like ordinary list. */
1543 if (scalar_mod_type(o, type))
1549 Perl_croak(aTHX_ "Can't localize lexical variable %s",
1550 SvPV(*av_fetch(PL_comppad_name, o->op_targ, 4), n_a));
1555 PL_modcount++; /* XXX ??? */
1557 #endif /* USE_THREADS */
1563 if (type != OP_SASSIGN)
1567 if (o->op_private == 4) /* don't allow 4 arg substr as lvalue */
1573 pad_free(o->op_targ);
1574 o->op_targ = pad_alloc(o->op_type, SVs_PADMY);
1575 assert(SvTYPE(PAD_SV(o->op_targ)) == SVt_NULL);
1576 if (o->op_flags & OPf_KIDS)
1577 mod(cBINOPo->op_first->op_sibling, type);
1582 ref(cBINOPo->op_first, o->op_type);
1583 if (type == OP_ENTERSUB &&
1584 !(o->op_private & (OPpLVAL_INTRO | OPpDEREF)))
1585 o->op_private |= OPpLVAL_DEFER;
1592 if (o->op_flags & OPf_KIDS)
1593 mod(cLISTOPo->op_last, type);
1597 if (o->op_flags & OPf_SPECIAL) /* do BLOCK */
1599 else if (!(o->op_flags & OPf_KIDS))
1601 if (o->op_targ != OP_LIST) {
1602 mod(cBINOPo->op_first, type);
1607 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1611 o->op_flags |= OPf_MOD;
1613 if (type == OP_AASSIGN || type == OP_SASSIGN)
1614 o->op_flags |= OPf_SPECIAL|OPf_REF;
1616 o->op_private |= OPpLVAL_INTRO;
1617 o->op_flags &= ~OPf_SPECIAL;
1618 PL_hints |= HINT_BLOCK_SCOPE;
1620 else if (type != OP_GREPSTART && type != OP_ENTERSUB)
1621 o->op_flags |= OPf_REF;
1626 S_scalar_mod_type(pTHX_ OP *o, I32 type)
1630 if (o->op_type == OP_RV2GV)
1654 case OP_RIGHT_SHIFT:
1673 S_is_handle_constructor(pTHX_ OP *o, I32 argnum)
1675 switch (o->op_type) {
1683 case OP_SELECT: /* XXX c.f. SelectSaver.pm */
1696 Perl_refkids(pTHX_ OP *o, I32 type)
1699 if (o && o->op_flags & OPf_KIDS) {
1700 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1707 Perl_ref(pTHX_ OP *o, I32 type)
1711 if (!o || PL_error_count)
1714 switch (o->op_type) {
1716 if ((type == OP_EXISTS || type == OP_DEFINED || type == OP_LOCK) &&
1717 !(o->op_flags & OPf_STACKED)) {
1718 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1719 o->op_ppaddr = PL_ppaddr[OP_RV2CV];
1720 assert(cUNOPo->op_first->op_type == OP_NULL);
1721 null(((LISTOP*)cUNOPo->op_first)->op_first); /* disable pushmark */
1722 o->op_flags |= OPf_SPECIAL;
1727 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1731 if (type == OP_DEFINED)
1732 o->op_flags |= OPf_SPECIAL; /* don't create GV */
1733 ref(cUNOPo->op_first, o->op_type);
1736 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1737 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1738 : type == OP_RV2HV ? OPpDEREF_HV
1740 o->op_flags |= OPf_MOD;
1745 o->op_flags |= OPf_MOD; /* XXX ??? */
1750 o->op_flags |= OPf_REF;
1753 if (type == OP_DEFINED)
1754 o->op_flags |= OPf_SPECIAL; /* don't create GV */
1755 ref(cUNOPo->op_first, o->op_type);
1760 o->op_flags |= OPf_REF;
1765 if (!(o->op_flags & OPf_KIDS))
1767 ref(cBINOPo->op_first, type);
1771 ref(cBINOPo->op_first, o->op_type);
1772 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1773 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1774 : type == OP_RV2HV ? OPpDEREF_HV
1776 o->op_flags |= OPf_MOD;
1784 if (!(o->op_flags & OPf_KIDS))
1786 ref(cLISTOPo->op_last, type);
1796 S_dup_attrlist(pTHX_ OP *o)
1800 /* An attrlist is either a simple OP_CONST or an OP_LIST with kids,
1801 * where the first kid is OP_PUSHMARK and the remaining ones
1802 * are OP_CONST. We need to push the OP_CONST values.
1804 if (o->op_type == OP_CONST)
1805 rop = newSVOP(OP_CONST, o->op_flags, SvREFCNT_inc(cSVOPo->op_sv));
1807 assert((o->op_type == OP_LIST) && (o->op_flags & OPf_KIDS));
1808 for (o = cLISTOPo->op_first; o; o=o->op_sibling) {
1809 if (o->op_type == OP_CONST)
1810 rop = append_elem(OP_LIST, rop,
1811 newSVOP(OP_CONST, o->op_flags,
1812 SvREFCNT_inc(cSVOPo->op_sv)));
1819 S_apply_attrs(pTHX_ HV *stash, SV *target, OP *attrs)
1821 OP *modname; /* for 'use' */
1824 /* fake up C<use attributes $pkg,$rv,@attrs> */
1825 ENTER; /* need to protect against side-effects of 'use' */
1827 if (stash && HvNAME(stash))
1828 stashsv = newSVpv(HvNAME(stash), 0);
1830 stashsv = &PL_sv_no;
1831 #define ATTRSMODULE "attributes"
1832 modname = newSVOP(OP_CONST, 0,
1833 newSVpvn(ATTRSMODULE, sizeof(ATTRSMODULE)-1));
1834 modname->op_private |= OPpCONST_BARE;
1835 /* that flag is required to make 'use' work right */
1836 utilize(1, start_subparse(FALSE, 0),
1837 Nullop, /* version */
1839 prepend_elem(OP_LIST,
1840 newSVOP(OP_CONST, 0, stashsv),
1841 prepend_elem(OP_LIST,
1842 newSVOP(OP_CONST, 0, newRV(target)),
1843 dup_attrlist(attrs))));
1848 S_my_kid(pTHX_ OP *o, OP *attrs)
1853 if (!o || PL_error_count)
1857 if (type == OP_LIST) {
1858 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1860 } else if (type == OP_UNDEF) {
1862 } else if (type == OP_RV2SV || /* "our" declaration */
1864 type == OP_RV2HV) { /* XXX does this let anything illegal in? */
1865 o->op_private |= OPpOUR_INTRO;
1867 } else if (type != OP_PADSV &&
1870 type != OP_PUSHMARK)
1872 yyerror(Perl_form(aTHX_ "Can't declare %s in \"%s\"",
1873 PL_op_desc[o->op_type],
1874 PL_in_my == KEY_our ? "our" : "my"));
1877 else if (attrs && type != OP_PUSHMARK) {
1883 PL_in_my_stash = Nullhv;
1885 /* check for C<my Dog $spot> when deciding package */
1886 namesvp = av_fetch(PL_comppad_name, o->op_targ, FALSE);
1887 if (namesvp && *namesvp && SvOBJECT(*namesvp) && HvNAME(SvSTASH(*namesvp)))
1888 stash = SvSTASH(*namesvp);
1890 stash = PL_curstash;
1891 padsv = PAD_SV(o->op_targ);
1892 apply_attrs(stash, padsv, attrs);
1894 o->op_flags |= OPf_MOD;
1895 o->op_private |= OPpLVAL_INTRO;
1900 Perl_my_attrs(pTHX_ OP *o, OP *attrs)
1902 if (o->op_flags & OPf_PARENS)
1906 o = my_kid(o, attrs);
1908 PL_in_my_stash = Nullhv;
1913 Perl_my(pTHX_ OP *o)
1915 return my_kid(o, Nullop);
1919 Perl_sawparens(pTHX_ OP *o)
1922 o->op_flags |= OPf_PARENS;
1927 Perl_bind_match(pTHX_ I32 type, OP *left, OP *right)
1932 if (ckWARN(WARN_UNSAFE) &&
1933 (left->op_type == OP_RV2AV ||
1934 left->op_type == OP_RV2HV ||
1935 left->op_type == OP_PADAV ||
1936 left->op_type == OP_PADHV)) {
1937 char *desc = PL_op_desc[(right->op_type == OP_SUBST ||
1938 right->op_type == OP_TRANS)
1939 ? right->op_type : OP_MATCH];
1940 const char *sample = ((left->op_type == OP_RV2AV ||
1941 left->op_type == OP_PADAV)
1942 ? "@array" : "%hash");
1943 Perl_warner(aTHX_ WARN_UNSAFE,
1944 "Applying %s to %s will act on scalar(%s)",
1945 desc, sample, sample);
1948 if (right->op_type == OP_MATCH ||
1949 right->op_type == OP_SUBST ||
1950 right->op_type == OP_TRANS) {
1951 right->op_flags |= OPf_STACKED;
1952 if (right->op_type != OP_MATCH)
1953 left = mod(left, right->op_type);
1954 if (right->op_type == OP_TRANS)
1955 o = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
1957 o = prepend_elem(right->op_type, scalar(left), right);
1959 return newUNOP(OP_NOT, 0, scalar(o));
1963 return bind_match(type, left,
1964 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
1968 Perl_invert(pTHX_ OP *o)
1972 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
1973 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(o));
1977 Perl_scope(pTHX_ OP *o)
1980 if (o->op_flags & OPf_PARENS || PERLDB_NOOPT || PL_tainting) {
1981 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
1982 o->op_type = OP_LEAVE;
1983 o->op_ppaddr = PL_ppaddr[OP_LEAVE];
1986 if (o->op_type == OP_LINESEQ) {
1988 o->op_type = OP_SCOPE;
1989 o->op_ppaddr = PL_ppaddr[OP_SCOPE];
1990 kid = ((LISTOP*)o)->op_first;
1991 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE)
1995 o = newLISTOP(OP_SCOPE, 0, o, Nullop);
2002 Perl_save_hints(pTHX)
2005 SAVESPTR(GvHV(PL_hintgv));
2006 GvHV(PL_hintgv) = newHVhv(GvHV(PL_hintgv));
2007 SAVEFREESV(GvHV(PL_hintgv));
2011 Perl_block_start(pTHX_ int full)
2014 int retval = PL_savestack_ix;
2016 SAVEI32(PL_comppad_name_floor);
2017 PL_comppad_name_floor = AvFILLp(PL_comppad_name);
2019 PL_comppad_name_fill = PL_comppad_name_floor;
2020 if (PL_comppad_name_floor < 0)
2021 PL_comppad_name_floor = 0;
2022 SAVEI32(PL_min_intro_pending);
2023 SAVEI32(PL_max_intro_pending);
2024 PL_min_intro_pending = 0;
2025 SAVEI32(PL_comppad_name_fill);
2026 SAVEI32(PL_padix_floor);
2027 PL_padix_floor = PL_padix;
2028 PL_pad_reset_pending = FALSE;
2030 PL_hints &= ~HINT_BLOCK_SCOPE;
2031 SAVESPTR(PL_compiling.cop_warnings);
2032 if (! specialWARN(PL_compiling.cop_warnings)) {
2033 PL_compiling.cop_warnings = newSVsv(PL_compiling.cop_warnings) ;
2034 SAVEFREESV(PL_compiling.cop_warnings) ;
2040 Perl_block_end(pTHX_ I32 floor, OP *seq)
2043 int needblockscope = PL_hints & HINT_BLOCK_SCOPE;
2044 OP* retval = scalarseq(seq);
2046 PL_pad_reset_pending = FALSE;
2047 PL_compiling.op_private = PL_hints;
2049 PL_hints |= HINT_BLOCK_SCOPE; /* propagate out */
2050 pad_leavemy(PL_comppad_name_fill);
2059 OP *o = newOP(OP_THREADSV, 0);
2060 o->op_targ = find_threadsv("_");
2063 return newSVREF(newGVOP(OP_GV, 0, PL_defgv));
2064 #endif /* USE_THREADS */
2068 Perl_newPROG(pTHX_ OP *o)
2074 PL_eval_root = newUNOP(OP_LEAVEEVAL,
2075 ((PL_in_eval & EVAL_KEEPERR)
2076 ? OPf_SPECIAL : 0), o);
2077 PL_eval_start = linklist(PL_eval_root);
2078 PL_eval_root->op_private |= OPpREFCOUNTED;
2079 OpREFCNT_set(PL_eval_root, 1);
2080 PL_eval_root->op_next = 0;
2081 peep(PL_eval_start);
2086 PL_main_root = scope(sawparens(scalarvoid(o)));
2087 PL_curcop = &PL_compiling;
2088 PL_main_start = LINKLIST(PL_main_root);
2089 PL_main_root->op_private |= OPpREFCOUNTED;
2090 OpREFCNT_set(PL_main_root, 1);
2091 PL_main_root->op_next = 0;
2092 peep(PL_main_start);
2095 /* Register with debugger */
2097 CV *cv = get_cv("DB::postponed", FALSE);
2101 XPUSHs((SV*)CopFILEGV(&PL_compiling));
2103 call_sv((SV*)cv, G_DISCARD);
2110 Perl_localize(pTHX_ OP *o, I32 lex)
2112 if (o->op_flags & OPf_PARENS)
2116 if (ckWARN(WARN_PARENTHESIS) && PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == ',') {
2118 for (s = PL_bufptr; *s && (isALNUM(*s) || (*s & 0x80) || strchr("@$%, ",*s)); s++) ;
2119 if (*s == ';' || *s == '=')
2120 Perl_warner(aTHX_ WARN_PARENTHESIS,
2121 "Parentheses missing around \"%s\" list",
2122 lex ? (PL_in_my == KEY_our ? "our" : "my") : "local");
2128 o = mod(o, OP_NULL); /* a bit kludgey */
2130 PL_in_my_stash = Nullhv;
2135 Perl_jmaybe(pTHX_ OP *o)
2137 if (o->op_type == OP_LIST) {
2140 o2 = newOP(OP_THREADSV, 0);
2141 o2->op_targ = find_threadsv(";");
2143 o2 = newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
2144 #endif /* USE_THREADS */
2145 o = convert(OP_JOIN, 0, prepend_elem(OP_LIST, o2, o));
2151 Perl_fold_constants(pTHX_ register OP *o)
2155 I32 type = o->op_type;
2158 if (PL_opargs[type] & OA_RETSCALAR)
2160 if (PL_opargs[type] & OA_TARGET && !o->op_targ)
2161 o->op_targ = pad_alloc(type, SVs_PADTMP);
2163 /* integerize op, unless it happens to be C<-foo>.
2164 * XXX should pp_i_negate() do magic string negation instead? */
2165 if ((PL_opargs[type] & OA_OTHERINT) && (PL_hints & HINT_INTEGER)
2166 && !(type == OP_NEGATE && cUNOPo->op_first->op_type == OP_CONST
2167 && (cUNOPo->op_first->op_private & OPpCONST_BARE)))
2169 o->op_ppaddr = PL_ppaddr[type = ++(o->op_type)];
2172 if (!(PL_opargs[type] & OA_FOLDCONST))
2177 /* XXX might want a ck_negate() for this */
2178 cUNOPo->op_first->op_private &= ~OPpCONST_STRICT;
2191 if (o->op_private & OPpLOCALE)
2196 goto nope; /* Don't try to run w/ errors */
2198 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
2199 if ((curop->op_type != OP_CONST ||
2200 (curop->op_private & OPpCONST_BARE)) &&
2201 curop->op_type != OP_LIST &&
2202 curop->op_type != OP_SCALAR &&
2203 curop->op_type != OP_NULL &&
2204 curop->op_type != OP_PUSHMARK)
2210 curop = LINKLIST(o);
2214 sv = *(PL_stack_sp--);
2215 if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
2216 pad_swipe(o->op_targ);
2217 else if (SvTEMP(sv)) { /* grab mortal temp? */
2218 (void)SvREFCNT_inc(sv);
2222 if (type == OP_RV2GV)
2223 return newGVOP(OP_GV, 0, (GV*)sv);
2225 /* try to smush double to int, but don't smush -2.0 to -2 */
2226 if ((SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK)) == SVf_NOK &&
2230 if ((NV)iv == SvNV(sv)) {
2235 SvIOK_off(sv); /* undo SvIV() damage */
2237 return newSVOP(OP_CONST, 0, sv);
2241 if (!(PL_opargs[type] & OA_OTHERINT))
2244 if (!(PL_hints & HINT_INTEGER)) {
2245 if (type == OP_MODULO
2246 || type == OP_DIVIDE
2247 || !(o->op_flags & OPf_KIDS))
2252 for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
2253 if (curop->op_type == OP_CONST) {
2254 if (SvIOK(((SVOP*)curop)->op_sv))
2258 if (PL_opargs[curop->op_type] & OA_RETINTEGER)
2262 o->op_ppaddr = PL_ppaddr[++(o->op_type)];
2269 Perl_gen_constant_list(pTHX_ register OP *o)
2273 I32 oldtmps_floor = PL_tmps_floor;
2277 return o; /* Don't attempt to run with errors */
2279 PL_op = curop = LINKLIST(o);
2286 PL_tmps_floor = oldtmps_floor;
2288 o->op_type = OP_RV2AV;
2289 o->op_ppaddr = PL_ppaddr[OP_RV2AV];
2290 curop = ((UNOP*)o)->op_first;
2291 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*PL_stack_sp--));
2298 Perl_convert(pTHX_ I32 type, I32 flags, OP *o)
2303 if (!o || o->op_type != OP_LIST)
2304 o = newLISTOP(OP_LIST, 0, o, Nullop);
2306 o->op_flags &= ~OPf_WANT;
2308 if (!(PL_opargs[type] & OA_MARK))
2309 null(cLISTOPo->op_first);
2312 o->op_ppaddr = PL_ppaddr[type];
2313 o->op_flags |= flags;
2315 o = CHECKOP(type, o);
2316 if (o->op_type != type)
2319 if (cLISTOPo->op_children < 7) {
2320 /* XXX do we really need to do this if we're done appending?? */
2321 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
2323 cLISTOPo->op_last = last; /* in case check substituted last arg */
2326 return fold_constants(o);
2329 /* List constructors */
2332 Perl_append_elem(pTHX_ I32 type, OP *first, OP *last)
2340 if (first->op_type != type || type==OP_LIST && first->op_flags & OPf_PARENS)
2341 return newLISTOP(type, 0, first, last);
2343 if (first->op_flags & OPf_KIDS)
2344 ((LISTOP*)first)->op_last->op_sibling = last;
2346 first->op_flags |= OPf_KIDS;
2347 ((LISTOP*)first)->op_first = last;
2349 ((LISTOP*)first)->op_last = last;
2350 ((LISTOP*)first)->op_children++;
2355 Perl_append_list(pTHX_ I32 type, LISTOP *first, LISTOP *last)
2363 if (first->op_type != type)
2364 return prepend_elem(type, (OP*)first, (OP*)last);
2366 if (last->op_type != type)
2367 return append_elem(type, (OP*)first, (OP*)last);
2369 first->op_last->op_sibling = last->op_first;
2370 first->op_last = last->op_last;
2371 first->op_children += last->op_children;
2372 if (first->op_children)
2373 first->op_flags |= OPf_KIDS;
2375 #ifdef PL_OP_SLAB_ALLOC
2383 Perl_prepend_elem(pTHX_ I32 type, OP *first, OP *last)
2391 if (last->op_type == type) {
2392 if (type == OP_LIST) { /* already a PUSHMARK there */
2393 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
2394 ((LISTOP*)last)->op_first->op_sibling = first;
2397 if (!(last->op_flags & OPf_KIDS)) {
2398 ((LISTOP*)last)->op_last = first;
2399 last->op_flags |= OPf_KIDS;
2401 first->op_sibling = ((LISTOP*)last)->op_first;
2402 ((LISTOP*)last)->op_first = first;
2404 ((LISTOP*)last)->op_children++;
2408 return newLISTOP(type, 0, first, last);
2414 Perl_newNULLLIST(pTHX)
2416 return newOP(OP_STUB, 0);
2420 Perl_force_list(pTHX_ OP *o)
2422 if (!o || o->op_type != OP_LIST)
2423 o = newLISTOP(OP_LIST, 0, o, Nullop);
2429 Perl_newLISTOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
2433 NewOp(1101, listop, 1, LISTOP);
2435 listop->op_type = type;
2436 listop->op_ppaddr = PL_ppaddr[type];
2437 listop->op_children = (first != 0) + (last != 0);
2438 listop->op_flags = flags;
2442 else if (!first && last)
2445 first->op_sibling = last;
2446 listop->op_first = first;
2447 listop->op_last = last;
2448 if (type == OP_LIST) {
2450 pushop = newOP(OP_PUSHMARK, 0);
2451 pushop->op_sibling = first;
2452 listop->op_first = pushop;
2453 listop->op_flags |= OPf_KIDS;
2455 listop->op_last = pushop;
2457 else if (listop->op_children)
2458 listop->op_flags |= OPf_KIDS;
2464 Perl_newOP(pTHX_ I32 type, I32 flags)
2467 NewOp(1101, o, 1, OP);
2469 o->op_ppaddr = PL_ppaddr[type];
2470 o->op_flags = flags;
2473 o->op_private = 0 + (flags >> 8);
2474 if (PL_opargs[type] & OA_RETSCALAR)
2476 if (PL_opargs[type] & OA_TARGET)
2477 o->op_targ = pad_alloc(type, SVs_PADTMP);
2478 return CHECKOP(type, o);
2482 Perl_newUNOP(pTHX_ I32 type, I32 flags, OP *first)
2487 first = newOP(OP_STUB, 0);
2488 if (PL_opargs[type] & OA_MARK)
2489 first = force_list(first);
2491 NewOp(1101, unop, 1, UNOP);
2492 unop->op_type = type;
2493 unop->op_ppaddr = PL_ppaddr[type];
2494 unop->op_first = first;
2495 unop->op_flags = flags | OPf_KIDS;
2496 unop->op_private = 1 | (flags >> 8);
2497 unop = (UNOP*) CHECKOP(type, unop);
2501 return fold_constants((OP *) unop);
2505 Perl_newBINOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
2508 NewOp(1101, binop, 1, BINOP);
2511 first = newOP(OP_NULL, 0);
2513 binop->op_type = type;
2514 binop->op_ppaddr = PL_ppaddr[type];
2515 binop->op_first = first;
2516 binop->op_flags = flags | OPf_KIDS;
2519 binop->op_private = 1 | (flags >> 8);
2522 binop->op_private = 2 | (flags >> 8);
2523 first->op_sibling = last;
2526 binop = (BINOP*)CHECKOP(type, binop);
2527 if (binop->op_next || binop->op_type != type)
2530 binop->op_last = binop->op_first->op_sibling;
2532 return fold_constants((OP *)binop);
2536 utf8compare(const void *a, const void *b)
2539 for (i = 0; i < 10; i++) {
2540 if ((*(U8**)a)[i] < (*(U8**)b)[i])
2542 if ((*(U8**)a)[i] > (*(U8**)b)[i])
2549 Perl_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
2551 SV *tstr = ((SVOP*)expr)->op_sv;
2552 SV *rstr = ((SVOP*)repl)->op_sv;
2555 register U8 *t = (U8*)SvPV(tstr, tlen);
2556 register U8 *r = (U8*)SvPV(rstr, rlen);
2562 register short *tbl;
2564 complement = o->op_private & OPpTRANS_COMPLEMENT;
2565 del = o->op_private & OPpTRANS_DELETE;
2566 squash = o->op_private & OPpTRANS_SQUASH;
2568 if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
2569 SV* listsv = newSVpvn("# comment\n",10);
2571 U8* tend = t + tlen;
2572 U8* rend = r + rlen;
2588 I32 from_utf = o->op_private & OPpTRANS_FROM_UTF;
2589 I32 to_utf = o->op_private & OPpTRANS_TO_UTF;
2595 New(1109, cp, tlen, U8*);
2597 transv = newSVpvn("",0);
2606 qsort(cp, i, sizeof(U8*), utf8compare);
2607 for (j = 0; j < i; j++) {
2609 UV val = utf8_to_uv(s, &ulen);
2611 diff = val - nextmin;
2613 t = uv_to_utf8(tmpbuf,nextmin);
2614 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2616 t = uv_to_utf8(tmpbuf, val - 1);
2617 sv_catpvn(transv, "\377", 1);
2618 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2622 val = utf8_to_uv(s+1, &ulen);
2626 t = uv_to_utf8(tmpbuf,nextmin);
2627 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2628 t = uv_to_utf8(tmpbuf, 0x7fffffff);
2629 sv_catpvn(transv, "\377", 1);
2630 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2631 t = (U8*)SvPVX(transv);
2632 tlen = SvCUR(transv);
2635 else if (!rlen && !del) {
2636 r = t; rlen = tlen; rend = tend;
2639 if (to_utf && from_utf) { /* only counting characters */
2640 if (t == r || (tlen == rlen && memEQ(t, r, tlen)))
2641 o->op_private |= OPpTRANS_IDENTICAL;
2643 else { /* straight latin-1 translation */
2644 if (tlen == 4 && memEQ(t, "\0\377\303\277", 4) &&
2645 rlen == 4 && memEQ(r, "\0\377\303\277", 4))
2646 o->op_private |= OPpTRANS_IDENTICAL;
2650 while (t < tend || tfirst <= tlast) {
2651 /* see if we need more "t" chars */
2652 if (tfirst > tlast) {
2653 tfirst = (I32)utf8_to_uv(t, &ulen);
2655 if (t < tend && *t == 0xff) { /* illegal utf8 val indicates range */
2656 tlast = (I32)utf8_to_uv(++t, &ulen);
2663 /* now see if we need more "r" chars */
2664 if (rfirst > rlast) {
2666 rfirst = (I32)utf8_to_uv(r, &ulen);
2668 if (r < rend && *r == 0xff) { /* illegal utf8 val indicates range */
2669 rlast = (I32)utf8_to_uv(++r, &ulen);
2678 rfirst = rlast = 0xffffffff;
2682 /* now see which range will peter our first, if either. */
2683 tdiff = tlast - tfirst;
2684 rdiff = rlast - rfirst;
2691 if (rfirst == 0xffffffff) {
2692 diff = tdiff; /* oops, pretend rdiff is infinite */
2694 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t%04lx\tXXXX\n",
2695 (long)tfirst, (long)tlast);
2697 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t\tXXXX\n", (long)tfirst);
2701 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t%04lx\t%04lx\n",
2702 (long)tfirst, (long)(tfirst + diff),
2705 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t\t%04lx\n",
2706 (long)tfirst, (long)rfirst);
2708 if (rfirst + diff > max)
2709 max = rfirst + diff;
2714 else if (rfirst <= 0x800)
2715 grows |= (tfirst < 0x80);
2716 else if (rfirst <= 0x10000)
2717 grows |= (tfirst < 0x800);
2718 else if (rfirst <= 0x200000)
2719 grows |= (tfirst < 0x10000);
2720 else if (rfirst <= 0x4000000)
2721 grows |= (tfirst < 0x200000);
2722 else if (rfirst <= 0x80000000)
2723 grows |= (tfirst < 0x4000000);
2735 else if (max > 0xff)
2740 cSVOPo->op_sv = (SV*)swash_init("utf8", "", listsv, bits, none);
2741 SvREFCNT_dec(listsv);
2743 SvREFCNT_dec(transv);
2745 if (!del && havefinal)
2746 (void)hv_store((HV*)SvRV((cSVOPo->op_sv)), "FINAL", 5, newSViv((IV)final), 0);
2748 if (grows && to_utf)
2749 o->op_private |= OPpTRANS_GROWS;
2756 tbl = (short*)cPVOPo->op_pv;
2758 Zero(tbl, 256, short);
2759 for (i = 0; i < tlen; i++)
2761 for (i = 0, j = 0; i < 256; i++) {
2777 if (!rlen && !del) {
2780 o->op_private |= OPpTRANS_IDENTICAL;
2782 for (i = 0; i < 256; i++)
2784 for (i = 0, j = 0; i < tlen; i++,j++) {
2787 if (tbl[t[i]] == -1)
2793 if (tbl[t[i]] == -1)
2804 Perl_newPMOP(pTHX_ I32 type, I32 flags)
2809 NewOp(1101, pmop, 1, PMOP);
2810 pmop->op_type = type;
2811 pmop->op_ppaddr = PL_ppaddr[type];
2812 pmop->op_flags = flags;
2813 pmop->op_private = 0 | (flags >> 8);
2815 if (PL_hints & HINT_RE_TAINT)
2816 pmop->op_pmpermflags |= PMf_RETAINT;
2817 if (PL_hints & HINT_LOCALE)
2818 pmop->op_pmpermflags |= PMf_LOCALE;
2819 pmop->op_pmflags = pmop->op_pmpermflags;
2821 /* link into pm list */
2822 if (type != OP_TRANS && PL_curstash) {
2823 pmop->op_pmnext = HvPMROOT(PL_curstash);
2824 HvPMROOT(PL_curstash) = pmop;
2831 Perl_pmruntime(pTHX_ OP *o, OP *expr, OP *repl)
2836 I32 repl_has_vars = 0;
2838 if (o->op_type == OP_TRANS)
2839 return pmtrans(o, expr, repl);
2841 PL_hints |= HINT_BLOCK_SCOPE;
2844 if (expr->op_type == OP_CONST) {
2846 SV *pat = ((SVOP*)expr)->op_sv;
2847 char *p = SvPV(pat, plen);
2848 if ((o->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
2849 sv_setpvn(pat, "\\s+", 3);
2850 p = SvPV(pat, plen);
2851 pm->op_pmflags |= PMf_SKIPWHITE;
2853 pm->op_pmregexp = CALLREGCOMP(aTHX_ p, p + plen, pm);
2854 if (strEQ("\\s+", pm->op_pmregexp->precomp))
2855 pm->op_pmflags |= PMf_WHITE;
2859 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL))
2860 expr = newUNOP((!(PL_hints & HINT_RE_EVAL)
2862 : OP_REGCMAYBE),0,expr);
2864 NewOp(1101, rcop, 1, LOGOP);
2865 rcop->op_type = OP_REGCOMP;
2866 rcop->op_ppaddr = PL_ppaddr[OP_REGCOMP];
2867 rcop->op_first = scalar(expr);
2868 rcop->op_flags |= ((PL_hints & HINT_RE_EVAL)
2869 ? (OPf_SPECIAL | OPf_KIDS)
2871 rcop->op_private = 1;
2874 /* establish postfix order */
2875 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL)) {
2877 rcop->op_next = expr;
2878 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
2881 rcop->op_next = LINKLIST(expr);
2882 expr->op_next = (OP*)rcop;
2885 prepend_elem(o->op_type, scalar((OP*)rcop), o);
2890 if (pm->op_pmflags & PMf_EVAL) {
2892 if (CopLINE(PL_curcop) < PL_multi_end)
2893 CopLINE_set(PL_curcop, PL_multi_end);
2896 else if (repl->op_type == OP_THREADSV
2897 && strchr("&`'123456789+",
2898 PL_threadsv_names[repl->op_targ]))
2902 #endif /* USE_THREADS */
2903 else if (repl->op_type == OP_CONST)
2907 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
2908 if (PL_opargs[curop->op_type] & OA_DANGEROUS) {
2910 if (curop->op_type == OP_THREADSV) {
2912 if (strchr("&`'123456789+", curop->op_private))
2916 if (curop->op_type == OP_GV) {
2917 GV *gv = cGVOPx_gv(curop);
2919 if (strchr("&`'123456789+", *GvENAME(gv)))
2922 #endif /* USE_THREADS */
2923 else if (curop->op_type == OP_RV2CV)
2925 else if (curop->op_type == OP_RV2SV ||
2926 curop->op_type == OP_RV2AV ||
2927 curop->op_type == OP_RV2HV ||
2928 curop->op_type == OP_RV2GV) {
2929 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
2932 else if (curop->op_type == OP_PADSV ||
2933 curop->op_type == OP_PADAV ||
2934 curop->op_type == OP_PADHV ||
2935 curop->op_type == OP_PADANY) {
2938 else if (curop->op_type == OP_PUSHRE)
2939 ; /* Okay here, dangerous in newASSIGNOP */
2948 && (!pm->op_pmregexp
2949 || pm->op_pmregexp->reganch & ROPT_EVAL_SEEN))) {
2950 pm->op_pmflags |= PMf_CONST; /* const for long enough */
2951 pm->op_pmpermflags |= PMf_CONST; /* const for long enough */
2952 prepend_elem(o->op_type, scalar(repl), o);
2955 if (curop == repl && !pm->op_pmregexp) { /* Has variables. */
2956 pm->op_pmflags |= PMf_MAYBE_CONST;
2957 pm->op_pmpermflags |= PMf_MAYBE_CONST;
2959 NewOp(1101, rcop, 1, LOGOP);
2960 rcop->op_type = OP_SUBSTCONT;
2961 rcop->op_ppaddr = PL_ppaddr[OP_SUBSTCONT];
2962 rcop->op_first = scalar(repl);
2963 rcop->op_flags |= OPf_KIDS;
2964 rcop->op_private = 1;
2967 /* establish postfix order */
2968 rcop->op_next = LINKLIST(repl);
2969 repl->op_next = (OP*)rcop;
2971 pm->op_pmreplroot = scalar((OP*)rcop);
2972 pm->op_pmreplstart = LINKLIST(rcop);
2981 Perl_newSVOP(pTHX_ I32 type, I32 flags, SV *sv)
2984 NewOp(1101, svop, 1, SVOP);
2985 svop->op_type = type;
2986 svop->op_ppaddr = PL_ppaddr[type];
2988 svop->op_next = (OP*)svop;
2989 svop->op_flags = flags;
2990 if (PL_opargs[type] & OA_RETSCALAR)
2992 if (PL_opargs[type] & OA_TARGET)
2993 svop->op_targ = pad_alloc(type, SVs_PADTMP);
2994 return CHECKOP(type, svop);
2998 Perl_newPADOP(pTHX_ I32 type, I32 flags, SV *sv)
3001 NewOp(1101, padop, 1, PADOP);
3002 padop->op_type = type;
3003 padop->op_ppaddr = PL_ppaddr[type];
3004 padop->op_padix = pad_alloc(type, SVs_PADTMP);
3005 SvREFCNT_dec(PL_curpad[padop->op_padix]);
3006 PL_curpad[padop->op_padix] = sv;
3008 padop->op_next = (OP*)padop;
3009 padop->op_flags = flags;
3010 if (PL_opargs[type] & OA_RETSCALAR)
3012 if (PL_opargs[type] & OA_TARGET)
3013 padop->op_targ = pad_alloc(type, SVs_PADTMP);
3014 return CHECKOP(type, padop);
3018 Perl_newGVOP(pTHX_ I32 type, I32 flags, GV *gv)
3023 return newPADOP(type, flags, SvREFCNT_inc(gv));
3025 return newSVOP(type, flags, SvREFCNT_inc(gv));
3030 Perl_newPVOP(pTHX_ I32 type, I32 flags, char *pv)
3033 NewOp(1101, pvop, 1, PVOP);
3034 pvop->op_type = type;
3035 pvop->op_ppaddr = PL_ppaddr[type];
3037 pvop->op_next = (OP*)pvop;
3038 pvop->op_flags = flags;
3039 if (PL_opargs[type] & OA_RETSCALAR)
3041 if (PL_opargs[type] & OA_TARGET)
3042 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
3043 return CHECKOP(type, pvop);
3047 Perl_package(pTHX_ OP *o)
3052 save_hptr(&PL_curstash);
3053 save_item(PL_curstname);
3058 name = SvPV(sv, len);
3059 PL_curstash = gv_stashpvn(name,len,TRUE);
3060 sv_setpvn(PL_curstname, name, len);
3064 sv_setpv(PL_curstname,"<none>");
3065 PL_curstash = Nullhv;
3067 PL_hints |= HINT_BLOCK_SCOPE;
3068 PL_copline = NOLINE;
3073 Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *id, OP *arg)
3082 if (id->op_type != OP_CONST)
3083 Perl_croak(aTHX_ "Module name must be constant");
3087 if(version != Nullop) {
3088 SV *vesv = ((SVOP*)version)->op_sv;
3090 if (arg == Nullop && !SvNIOK(vesv)) {
3096 if (version->op_type != OP_CONST || !SvNIOK(vesv))
3097 Perl_croak(aTHX_ "Version number must be constant number");
3099 /* Make copy of id so we don't free it twice */
3100 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
3102 /* Fake up a method call to VERSION */
3103 veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
3104 append_elem(OP_LIST,
3105 prepend_elem(OP_LIST, pack, list(version)),
3106 newSVOP(OP_METHOD_NAMED, 0,
3107 newSVpvn("VERSION", 7))));
3111 /* Fake up an import/unimport */
3112 if (arg && arg->op_type == OP_STUB)
3113 imop = arg; /* no import on explicit () */
3114 else if(SvNIOK(((SVOP*)id)->op_sv)) {
3115 imop = Nullop; /* use 5.0; */
3118 /* Make copy of id so we don't free it twice */
3119 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
3120 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
3121 append_elem(OP_LIST,
3122 prepend_elem(OP_LIST, pack, list(arg)),
3123 newSVOP(OP_METHOD_NAMED, 0,
3124 aver ? newSVpvn("import", 6)
3125 : newSVpvn("unimport", 8))));
3128 /* Fake up a require, handle override, if any */
3129 gv = gv_fetchpv("require", FALSE, SVt_PVCV);
3130 if (!(gv && GvIMPORTED_CV(gv)))
3131 gv = gv_fetchpv("CORE::GLOBAL::require", FALSE, SVt_PVCV);
3133 if (gv && GvIMPORTED_CV(gv)) {
3134 rqop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
3135 append_elem(OP_LIST, id,
3136 scalar(newUNOP(OP_RV2CV, 0,
3141 rqop = newUNOP(OP_REQUIRE, 0, id);
3144 /* Fake up the BEGIN {}, which does its thing immediately. */
3146 newSVOP(OP_CONST, 0, newSVpvn("BEGIN", 5)),
3149 append_elem(OP_LINESEQ,
3150 append_elem(OP_LINESEQ,
3151 newSTATEOP(0, Nullch, rqop),
3152 newSTATEOP(0, Nullch, veop)),
3153 newSTATEOP(0, Nullch, imop) ));
3155 PL_hints |= HINT_BLOCK_SCOPE;
3156 PL_copline = NOLINE;
3161 Perl_dofile(pTHX_ OP *term)
3166 gv = gv_fetchpv("do", FALSE, SVt_PVCV);
3167 if (!(gv && GvIMPORTED_CV(gv)))
3168 gv = gv_fetchpv("CORE::GLOBAL::do", FALSE, SVt_PVCV);
3170 if (gv && GvIMPORTED_CV(gv)) {
3171 doop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
3172 append_elem(OP_LIST, term,
3173 scalar(newUNOP(OP_RV2CV, 0,
3178 doop = newUNOP(OP_DOFILE, 0, scalar(term));
3184 Perl_newSLICEOP(pTHX_ I32 flags, OP *subscript, OP *listval)
3186 return newBINOP(OP_LSLICE, flags,
3187 list(force_list(subscript)),
3188 list(force_list(listval)) );
3192 S_list_assignment(pTHX_ register OP *o)
3197 if (o->op_type == OP_NULL && o->op_flags & OPf_KIDS)
3198 o = cUNOPo->op_first;
3200 if (o->op_type == OP_COND_EXPR) {
3201 I32 t = list_assignment(cLOGOPo->op_first->op_sibling);
3202 I32 f = list_assignment(cLOGOPo->op_first->op_sibling->op_sibling);
3207 yyerror("Assignment to both a list and a scalar");
3211 if (o->op_type == OP_LIST || o->op_flags & OPf_PARENS ||
3212 o->op_type == OP_RV2AV || o->op_type == OP_RV2HV ||
3213 o->op_type == OP_ASLICE || o->op_type == OP_HSLICE)
3216 if (o->op_type == OP_PADAV || o->op_type == OP_PADHV)
3219 if (o->op_type == OP_RV2SV)
3226 Perl_newASSIGNOP(pTHX_ I32 flags, OP *left, I32 optype, OP *right)
3231 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN) {
3232 return newLOGOP(optype, 0,
3233 mod(scalar(left), optype),
3234 newUNOP(OP_SASSIGN, 0, scalar(right)));
3237 return newBINOP(optype, OPf_STACKED,
3238 mod(scalar(left), optype), scalar(right));
3242 if (list_assignment(left)) {
3245 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
3246 left = mod(left, OP_AASSIGN);
3254 o = newBINOP(OP_AASSIGN, flags,
3255 list(force_list(right)),
3256 list(force_list(left)) );
3257 o->op_private = 0 | (flags >> 8);
3258 if (!(left->op_private & OPpLVAL_INTRO)) {
3262 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
3263 if (PL_opargs[curop->op_type] & OA_DANGEROUS) {
3264 if (curop->op_type == OP_GV) {
3265 GV *gv = cGVOPx_gv(curop);
3266 if (gv == PL_defgv || SvCUR(gv) == PL_generation)
3268 SvCUR(gv) = PL_generation;
3270 else if (curop->op_type == OP_PADSV ||
3271 curop->op_type == OP_PADAV ||
3272 curop->op_type == OP_PADHV ||
3273 curop->op_type == OP_PADANY) {
3274 SV **svp = AvARRAY(PL_comppad_name);
3275 SV *sv = svp[curop->op_targ];
3276 if (SvCUR(sv) == PL_generation)
3278 SvCUR(sv) = PL_generation; /* (SvCUR not used any more) */
3280 else if (curop->op_type == OP_RV2CV)
3282 else if (curop->op_type == OP_RV2SV ||
3283 curop->op_type == OP_RV2AV ||
3284 curop->op_type == OP_RV2HV ||
3285 curop->op_type == OP_RV2GV) {
3286 if (lastop->op_type != OP_GV) /* funny deref? */
3289 else if (curop->op_type == OP_PUSHRE) {
3290 if (((PMOP*)curop)->op_pmreplroot) {
3291 GV *gv = (GV*)((PMOP*)curop)->op_pmreplroot;
3292 if (gv == PL_defgv || SvCUR(gv) == PL_generation)
3294 SvCUR(gv) = PL_generation;
3303 o->op_private = OPpASSIGN_COMMON;
3305 if (right && right->op_type == OP_SPLIT) {
3307 if ((tmpop = ((LISTOP*)right)->op_first) &&
3308 tmpop->op_type == OP_PUSHRE)
3310 PMOP *pm = (PMOP*)tmpop;
3311 if (left->op_type == OP_RV2AV &&
3312 !(left->op_private & OPpLVAL_INTRO) &&
3313 !(o->op_private & OPpASSIGN_COMMON) )
3315 tmpop = ((UNOP*)left)->op_first;
3316 if (tmpop->op_type == OP_GV && !pm->op_pmreplroot) {
3318 pm->op_pmreplroot = (OP*)cPADOPx(tmpop)->op_padix;
3319 cPADOPx(tmpop)->op_padix = 0; /* steal it */
3321 pm->op_pmreplroot = (OP*)cSVOPx(tmpop)->op_sv;
3322 cSVOPx(tmpop)->op_sv = Nullsv; /* steal it */
3324 pm->op_pmflags |= PMf_ONCE;
3325 tmpop = cUNOPo->op_first; /* to list (nulled) */
3326 tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */
3327 tmpop->op_sibling = Nullop; /* don't free split */
3328 right->op_next = tmpop->op_next; /* fix starting loc */
3329 op_free(o); /* blow off assign */
3330 right->op_flags &= ~OPf_WANT;
3331 /* "I don't know and I don't care." */
3336 if (PL_modcount < 10000 &&
3337 ((LISTOP*)right)->op_last->op_type == OP_CONST)
3339 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
3341 sv_setiv(sv, PL_modcount+1);
3349 right = newOP(OP_UNDEF, 0);
3350 if (right->op_type == OP_READLINE) {
3351 right->op_flags |= OPf_STACKED;
3352 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
3355 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
3356 o = newBINOP(OP_SASSIGN, flags,
3357 scalar(right), mod(scalar(left), OP_SASSIGN) );
3369 Perl_newSTATEOP(pTHX_ I32 flags, char *label, OP *o)
3372 U32 seq = intro_my();
3375 NewOp(1101, cop, 1, COP);
3376 if (PERLDB_LINE && CopLINE(PL_curcop) && PL_curstash != PL_debstash) {
3377 cop->op_type = OP_DBSTATE;
3378 cop->op_ppaddr = PL_ppaddr[ OP_DBSTATE ];
3381 cop->op_type = OP_NEXTSTATE;
3382 cop->op_ppaddr = PL_ppaddr[ OP_NEXTSTATE ];
3384 cop->op_flags = flags;
3385 cop->op_private = (PL_hints & HINT_UTF8);
3387 cop->op_private |= NATIVE_HINTS;
3389 PL_compiling.op_private = cop->op_private;
3390 cop->op_next = (OP*)cop;
3393 cop->cop_label = label;
3394 PL_hints |= HINT_BLOCK_SCOPE;
3397 cop->cop_arybase = PL_curcop->cop_arybase;
3398 if (specialWARN(PL_curcop->cop_warnings))
3399 cop->cop_warnings = PL_curcop->cop_warnings ;
3401 cop->cop_warnings = newSVsv(PL_curcop->cop_warnings) ;
3404 if (PL_copline == NOLINE)
3405 CopLINE_set(cop, CopLINE(PL_curcop));
3407 CopLINE_set(cop, PL_copline);
3408 PL_copline = NOLINE;
3411 CopFILE_set(cop, CopFILE(PL_curcop)); /* XXXXX share in a pvtable? */
3413 CopFILEGV_set(cop, (GV*)SvREFCNT_inc(CopFILEGV(PL_curcop)));
3415 CopSTASH_set(cop, PL_curstash);
3417 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3418 SV **svp = av_fetch(CopFILEAV(PL_curcop), (I32)CopLINE(cop), FALSE);
3419 if (svp && *svp != &PL_sv_undef && !SvIOK(*svp)) {
3420 (void)SvIOK_on(*svp);
3421 SvIVX(*svp) = PTR2IV(cop);
3425 return prepend_elem(OP_LINESEQ, (OP*)cop, o);
3428 /* "Introduce" my variables to visible status. */
3436 if (! PL_min_intro_pending)
3437 return PL_cop_seqmax;
3439 svp = AvARRAY(PL_comppad_name);
3440 for (i = PL_min_intro_pending; i <= PL_max_intro_pending; i++) {
3441 if ((sv = svp[i]) && sv != &PL_sv_undef && !SvIVX(sv)) {
3442 SvIVX(sv) = PAD_MAX; /* Don't know scope end yet. */
3443 SvNVX(sv) = (NV)PL_cop_seqmax;
3446 PL_min_intro_pending = 0;
3447 PL_comppad_name_fill = PL_max_intro_pending; /* Needn't search higher */
3448 return PL_cop_seqmax++;
3452 Perl_newLOGOP(pTHX_ I32 type, I32 flags, OP *first, OP *other)
3454 return new_logop(type, flags, &first, &other);
3458 S_new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp)
3463 OP *first = *firstp;
3464 OP *other = *otherp;
3466 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
3467 return newBINOP(type, flags, scalar(first), scalar(other));
3469 scalarboolean(first);
3470 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
3471 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
3472 if (type == OP_AND || type == OP_OR) {
3478 first = *firstp = cUNOPo->op_first;
3480 first->op_next = o->op_next;
3481 cUNOPo->op_first = Nullop;
3485 if (first->op_type == OP_CONST) {
3486 if (ckWARN(WARN_PRECEDENCE) && (first->op_private & OPpCONST_BARE))
3487 Perl_warner(aTHX_ WARN_PRECEDENCE, "Probable precedence problem on %s",
3489 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
3500 else if (first->op_type == OP_WANTARRAY) {
3506 else if (ckWARN(WARN_UNSAFE) && (first->op_flags & OPf_KIDS)) {
3507 OP *k1 = ((UNOP*)first)->op_first;
3508 OP *k2 = k1->op_sibling;
3510 switch (first->op_type)
3513 if (k2 && k2->op_type == OP_READLINE
3514 && (k2->op_flags & OPf_STACKED)
3515 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3517 warnop = k2->op_type;
3522 if (k1->op_type == OP_READDIR
3523 || k1->op_type == OP_GLOB
3524 || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
3525 || k1->op_type == OP_EACH)
3527 warnop = ((k1->op_type == OP_NULL)
3528 ? k1->op_targ : k1->op_type);
3533 line_t oldline = CopLINE(PL_curcop);
3534 CopLINE_set(PL_curcop, PL_copline);
3535 Perl_warner(aTHX_ WARN_UNSAFE,
3536 "Value of %s%s can be \"0\"; test with defined()",
3538 ((warnop == OP_READLINE || warnop == OP_GLOB)
3539 ? " construct" : "() operator"));
3540 CopLINE_set(PL_curcop, oldline);
3547 if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
3548 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
3550 NewOp(1101, logop, 1, LOGOP);
3552 logop->op_type = type;
3553 logop->op_ppaddr = PL_ppaddr[type];
3554 logop->op_first = first;
3555 logop->op_flags = flags | OPf_KIDS;
3556 logop->op_other = LINKLIST(other);
3557 logop->op_private = 1 | (flags >> 8);
3559 /* establish postfix order */
3560 logop->op_next = LINKLIST(first);
3561 first->op_next = (OP*)logop;
3562 first->op_sibling = other;
3564 o = newUNOP(OP_NULL, 0, (OP*)logop);
3571 Perl_newCONDOP(pTHX_ I32 flags, OP *first, OP *trueop, OP *falseop)
3579 return newLOGOP(OP_AND, 0, first, trueop);
3581 return newLOGOP(OP_OR, 0, first, falseop);
3583 scalarboolean(first);
3584 if (first->op_type == OP_CONST) {
3585 if (SvTRUE(((SVOP*)first)->op_sv)) {
3596 else if (first->op_type == OP_WANTARRAY) {
3600 NewOp(1101, logop, 1, LOGOP);
3601 logop->op_type = OP_COND_EXPR;
3602 logop->op_ppaddr = PL_ppaddr[OP_COND_EXPR];
3603 logop->op_first = first;
3604 logop->op_flags = flags | OPf_KIDS;
3605 logop->op_private = 1 | (flags >> 8);
3606 logop->op_other = LINKLIST(trueop);
3607 logop->op_next = LINKLIST(falseop);
3610 /* establish postfix order */
3611 start = LINKLIST(first);
3612 first->op_next = (OP*)logop;
3614 first->op_sibling = trueop;
3615 trueop->op_sibling = falseop;
3616 o = newUNOP(OP_NULL, 0, (OP*)logop);
3618 trueop->op_next = falseop->op_next = o;
3625 Perl_newRANGE(pTHX_ I32 flags, OP *left, OP *right)
3634 NewOp(1101, range, 1, LOGOP);
3636 range->op_type = OP_RANGE;
3637 range->op_ppaddr = PL_ppaddr[OP_RANGE];
3638 range->op_first = left;
3639 range->op_flags = OPf_KIDS;
3640 leftstart = LINKLIST(left);
3641 range->op_other = LINKLIST(right);
3642 range->op_private = 1 | (flags >> 8);
3644 left->op_sibling = right;
3646 range->op_next = (OP*)range;
3647 flip = newUNOP(OP_FLIP, flags, (OP*)range);
3648 flop = newUNOP(OP_FLOP, 0, flip);
3649 o = newUNOP(OP_NULL, 0, flop);
3651 range->op_next = leftstart;
3653 left->op_next = flip;
3654 right->op_next = flop;
3656 range->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
3657 sv_upgrade(PAD_SV(range->op_targ), SVt_PVNV);
3658 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
3659 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
3661 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
3662 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
3665 if (!flip->op_private || !flop->op_private)
3666 linklist(o); /* blow off optimizer unless constant */
3672 Perl_newLOOPOP(pTHX_ I32 flags, I32 debuggable, OP *expr, OP *block)
3677 int once = block && block->op_flags & OPf_SPECIAL &&
3678 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
3681 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
3682 return block; /* do {} while 0 does once */
3683 if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
3684 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB)) {
3685 expr = newUNOP(OP_DEFINED, 0,
3686 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
3687 } else if (expr->op_flags & OPf_KIDS) {
3688 OP *k1 = ((UNOP*)expr)->op_first;
3689 OP *k2 = (k1) ? k1->op_sibling : NULL;
3690 switch (expr->op_type) {
3692 if (k2 && k2->op_type == OP_READLINE
3693 && (k2->op_flags & OPf_STACKED)
3694 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3695 expr = newUNOP(OP_DEFINED, 0, expr);
3699 if (k1->op_type == OP_READDIR
3700 || k1->op_type == OP_GLOB
3701 || (k1->op_type == OP_NULL && k1->op_targ == OP_NULL)
3702 || k1->op_type == OP_EACH)
3703 expr = newUNOP(OP_DEFINED, 0, expr);
3709 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
3710 o = new_logop(OP_AND, 0, &expr, &listop);
3713 ((LISTOP*)listop)->op_last->op_next = LINKLIST(o);
3715 if (once && o != listop)
3716 o->op_next = ((LOGOP*)cUNOPo->op_first)->op_other;
3719 o = newUNOP(OP_NULL, 0, o); /* or do {} while 1 loses outer block */
3721 o->op_flags |= flags;
3723 o->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/
3728 Perl_newWHILEOP(pTHX_ I32 flags, I32 debuggable, LOOP *loop, I32 whileline, OP *expr, OP *block, OP *cont)
3737 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
3738 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB))) {
3739 expr = newUNOP(OP_DEFINED, 0,
3740 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
3741 } else if (expr && (expr->op_flags & OPf_KIDS)) {
3742 OP *k1 = ((UNOP*)expr)->op_first;
3743 OP *k2 = (k1) ? k1->op_sibling : NULL;
3744 switch (expr->op_type) {
3746 if (k2 && k2->op_type == OP_READLINE
3747 && (k2->op_flags & OPf_STACKED)
3748 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3749 expr = newUNOP(OP_DEFINED, 0, expr);
3753 if (k1->op_type == OP_READDIR
3754 || k1->op_type == OP_GLOB
3755 || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
3756 || k1->op_type == OP_EACH)
3757 expr = newUNOP(OP_DEFINED, 0, expr);
3763 block = newOP(OP_NULL, 0);
3765 block = scope(block);
3769 next = LINKLIST(cont);
3771 cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
3772 if ((line_t)whileline != NOLINE) {
3773 PL_copline = whileline;
3774 cont = append_elem(OP_LINESEQ, cont,
3775 newSTATEOP(0, Nullch, Nullop));
3779 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
3780 redo = LINKLIST(listop);
3783 PL_copline = whileline;
3785 o = new_logop(OP_AND, 0, &expr, &listop);
3786 if (o == expr && o->op_type == OP_CONST && !SvTRUE(cSVOPo->op_sv)) {
3787 op_free(expr); /* oops, it's a while (0) */
3789 return Nullop; /* listop already freed by new_logop */
3792 ((LISTOP*)listop)->op_last->op_next = condop =
3793 (o == listop ? redo : LINKLIST(o));
3801 NewOp(1101,loop,1,LOOP);
3802 loop->op_type = OP_ENTERLOOP;
3803 loop->op_ppaddr = PL_ppaddr[OP_ENTERLOOP];
3804 loop->op_private = 0;
3805 loop->op_next = (OP*)loop;
3808 o = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, o);
3810 loop->op_redoop = redo;
3811 loop->op_lastop = o;
3814 loop->op_nextop = next;
3816 loop->op_nextop = o;
3818 o->op_flags |= flags;
3819 o->op_private |= (flags >> 8);
3824 Perl_newFOROP(pTHX_ I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
3833 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
3834 sv->op_type = OP_RV2GV;
3835 sv->op_ppaddr = PL_ppaddr[OP_RV2GV];
3837 else if (sv->op_type == OP_PADSV) { /* private variable */
3838 padoff = sv->op_targ;
3843 else if (sv->op_type == OP_THREADSV) { /* per-thread variable */
3844 padoff = sv->op_targ;
3846 iterflags |= OPf_SPECIAL;
3851 Perl_croak(aTHX_ "Can't use %s for loop variable", PL_op_desc[sv->op_type]);
3855 padoff = find_threadsv("_");
3856 iterflags |= OPf_SPECIAL;
3858 sv = newGVOP(OP_GV, 0, PL_defgv);
3861 if (expr->op_type == OP_RV2AV || expr->op_type == OP_PADAV) {
3862 expr = mod(force_list(scalar(ref(expr, OP_ITER))), OP_GREPSTART);
3863 iterflags |= OPf_STACKED;
3865 else if (expr->op_type == OP_NULL &&
3866 (expr->op_flags & OPf_KIDS) &&
3867 ((BINOP*)expr)->op_first->op_type == OP_FLOP)
3869 /* Basically turn for($x..$y) into the same as for($x,$y), but we
3870 * set the STACKED flag to indicate that these values are to be
3871 * treated as min/max values by 'pp_iterinit'.
3873 UNOP* flip = (UNOP*)((UNOP*)((BINOP*)expr)->op_first)->op_first;
3874 LOGOP* range = (LOGOP*) flip->op_first;
3875 OP* left = range->op_first;
3876 OP* right = left->op_sibling;
3879 range->op_flags &= ~OPf_KIDS;
3880 range->op_first = Nullop;
3882 listop = (LISTOP*)newLISTOP(OP_LIST, 0, left, right);
3883 listop->op_first->op_next = range->op_next;
3884 left->op_next = range->op_other;
3885 right->op_next = (OP*)listop;
3886 listop->op_next = listop->op_first;
3889 expr = (OP*)(listop);
3891 iterflags |= OPf_STACKED;
3894 expr = mod(force_list(expr), OP_GREPSTART);
3898 loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
3899 append_elem(OP_LIST, expr, scalar(sv))));
3900 assert(!loop->op_next);
3901 #ifdef PL_OP_SLAB_ALLOC
3902 NewOp(1234,tmp,1,LOOP);
3903 Copy(loop,tmp,1,LOOP);
3906 Renew(loop, 1, LOOP);
3908 loop->op_targ = padoff;
3909 wop = newWHILEOP(flags, 1, loop, forline, newOP(OP_ITER, 0), block, cont);
3910 PL_copline = forline;
3911 return newSTATEOP(0, label, wop);
3915 Perl_newLOOPEX(pTHX_ I32 type, OP *label)
3921 if (type != OP_GOTO || label->op_type == OP_CONST) {
3922 /* "last()" means "last" */
3923 if (label->op_type == OP_STUB && (label->op_flags & OPf_PARENS))
3924 o = newOP(type, OPf_SPECIAL);
3926 o = newPVOP(type, 0, savepv(label->op_type == OP_CONST
3927 ? SvPVx(((SVOP*)label)->op_sv, n_a)
3933 if (label->op_type == OP_ENTERSUB)
3934 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
3935 o = newUNOP(type, OPf_STACKED, label);
3937 PL_hints |= HINT_BLOCK_SCOPE;
3942 Perl_cv_undef(pTHX_ CV *cv)
3947 MUTEX_DESTROY(CvMUTEXP(cv));
3948 Safefree(CvMUTEXP(cv));
3951 #endif /* USE_THREADS */
3953 if (!CvXSUB(cv) && CvROOT(cv)) {
3955 if (CvDEPTH(cv) || (CvOWNER(cv) && CvOWNER(cv) != thr))
3956 Perl_croak(aTHX_ "Can't undef active subroutine");
3959 Perl_croak(aTHX_ "Can't undef active subroutine");
3960 #endif /* USE_THREADS */
3963 SAVEVPTR(PL_curpad);
3967 op_free(CvROOT(cv));
3968 CvROOT(cv) = Nullop;
3971 SvPOK_off((SV*)cv); /* forget prototype */
3973 SvREFCNT_dec(CvGV(cv));
3975 SvREFCNT_dec(CvOUTSIDE(cv));
3976 CvOUTSIDE(cv) = Nullcv;
3977 if (CvPADLIST(cv)) {
3978 /* may be during global destruction */
3979 if (SvREFCNT(CvPADLIST(cv))) {
3980 I32 i = AvFILLp(CvPADLIST(cv));
3982 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
3983 SV* sv = svp ? *svp : Nullsv;
3986 if (sv == (SV*)PL_comppad_name)
3987 PL_comppad_name = Nullav;
3988 else if (sv == (SV*)PL_comppad) {
3989 PL_comppad = Nullav;
3990 PL_curpad = Null(SV**);
3994 SvREFCNT_dec((SV*)CvPADLIST(cv));
3996 CvPADLIST(cv) = Nullav;
4001 S_cv_dump(pTHX_ CV *cv)
4004 CV *outside = CvOUTSIDE(cv);
4005 AV* padlist = CvPADLIST(cv);
4012 PerlIO_printf(Perl_debug_log,
4013 "\tCV=0x%"UVxf" (%s), OUTSIDE=0x%"UVxf" (%s)\n",
4015 (CvANON(cv) ? "ANON"
4016 : (cv == PL_main_cv) ? "MAIN"
4017 : CvUNIQUE(cv) ? "UNIQUE"
4018 : CvGV(cv) ? GvNAME(CvGV(cv)) : "UNDEFINED"),
4021 : CvANON(outside) ? "ANON"
4022 : (outside == PL_main_cv) ? "MAIN"
4023 : CvUNIQUE(outside) ? "UNIQUE"
4024 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
4029 pad_name = (AV*)*av_fetch(padlist, 0, FALSE);
4030 pad = (AV*)*av_fetch(padlist, 1, FALSE);
4031 pname = AvARRAY(pad_name);
4032 ppad = AvARRAY(pad);
4034 for (ix = 1; ix <= AvFILLp(pad_name); ix++) {
4035 if (SvPOK(pname[ix]))
4036 PerlIO_printf(Perl_debug_log,
4037 "\t%4d. 0x%"UVxf" (%s\"%s\" %"IVdf"-%"IVdf")\n",
4038 (int)ix, PTR2UV(ppad[ix]),
4039 SvFAKE(pname[ix]) ? "FAKE " : "",
4041 (IV)I_32(SvNVX(pname[ix])),
4044 #endif /* DEBUGGING */
4048 S_cv_clone2(pTHX_ CV *proto, CV *outside)
4053 AV* protopadlist = CvPADLIST(proto);
4054 AV* protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
4055 AV* protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
4056 SV** pname = AvARRAY(protopad_name);
4057 SV** ppad = AvARRAY(protopad);
4058 I32 fname = AvFILLp(protopad_name);
4059 I32 fpad = AvFILLp(protopad);
4063 assert(!CvUNIQUE(proto));
4066 SAVEVPTR(PL_curpad);
4067 SAVESPTR(PL_comppad);
4068 SAVESPTR(PL_comppad_name);
4069 SAVESPTR(PL_compcv);
4071 cv = PL_compcv = (CV*)NEWSV(1104,0);
4072 sv_upgrade((SV *)cv, SvTYPE(proto));
4078 New(666, CvMUTEXP(cv), 1, perl_mutex);
4079 MUTEX_INIT(CvMUTEXP(cv));
4081 #endif /* USE_THREADS */
4082 CvFILE(cv) = CvFILE(proto);
4083 CvGV(cv) = (GV*)SvREFCNT_inc(CvGV(proto));
4084 CvSTASH(cv) = CvSTASH(proto);
4085 CvROOT(cv) = CvROOT(proto);
4086 CvSTART(cv) = CvSTART(proto);
4088 CvOUTSIDE(cv) = (CV*)SvREFCNT_inc(outside);
4091 sv_setpvn((SV*)cv, SvPVX(proto), SvCUR(proto));
4093 PL_comppad_name = newAV();
4094 for (ix = fname; ix >= 0; ix--)
4095 av_store(PL_comppad_name, ix, SvREFCNT_inc(pname[ix]));
4097 PL_comppad = newAV();
4099 comppadlist = newAV();
4100 AvREAL_off(comppadlist);
4101 av_store(comppadlist, 0, (SV*)PL_comppad_name);
4102 av_store(comppadlist, 1, (SV*)PL_comppad);
4103 CvPADLIST(cv) = comppadlist;
4104 av_fill(PL_comppad, AvFILLp(protopad));
4105 PL_curpad = AvARRAY(PL_comppad);
4107 av = newAV(); /* will be @_ */
4109 av_store(PL_comppad, 0, (SV*)av);
4110 AvFLAGS(av) = AVf_REIFY;
4112 for (ix = fpad; ix > 0; ix--) {
4113 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
4114 if (namesv && namesv != &PL_sv_undef) {
4115 char *name = SvPVX(namesv); /* XXX */
4116 if (SvFLAGS(namesv) & SVf_FAKE) { /* lexical from outside? */
4117 I32 off = pad_findlex(name, ix, SvIVX(namesv),
4118 CvOUTSIDE(cv), cxstack_ix, 0, 0);
4120 PL_curpad[ix] = SvREFCNT_inc(ppad[ix]);
4122 Perl_croak(aTHX_ "panic: cv_clone: %s", name);
4124 else { /* our own lexical */
4127 /* anon code -- we'll come back for it */
4128 sv = SvREFCNT_inc(ppad[ix]);
4130 else if (*name == '@')
4132 else if (*name == '%')
4141 else if (IS_PADGV(ppad[ix]) || IS_PADCONST(ppad[ix])) {
4142 PL_curpad[ix] = SvREFCNT_inc(ppad[ix]);
4145 SV* sv = NEWSV(0,0);
4151 /* Now that vars are all in place, clone nested closures. */
4153 for (ix = fpad; ix > 0; ix--) {
4154 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
4156 && namesv != &PL_sv_undef
4157 && !(SvFLAGS(namesv) & SVf_FAKE)
4158 && *SvPVX(namesv) == '&'
4159 && CvCLONE(ppad[ix]))
4161 CV *kid = cv_clone2((CV*)ppad[ix], cv);
4162 SvREFCNT_dec(ppad[ix]);
4165 PL_curpad[ix] = (SV*)kid;
4169 #ifdef DEBUG_CLOSURES
4170 PerlIO_printf(Perl_debug_log, "Cloned inside:\n");
4172 PerlIO_printf(Perl_debug_log, " from:\n");
4174 PerlIO_printf(Perl_debug_log, " to:\n");
4183 Perl_cv_clone(pTHX_ CV *proto)
4186 LOCK_CRED_MUTEX; /* XXX create separate mutex */
4187 cv = cv_clone2(proto, CvOUTSIDE(proto));
4188 UNLOCK_CRED_MUTEX; /* XXX create separate mutex */
4193 Perl_cv_ckproto(pTHX_ CV *cv, GV *gv, char *p)
4197 if (((!p != !SvPOK(cv)) || (p && strNE(p, SvPVX(cv)))) && ckWARN_d(WARN_UNSAFE)) {
4198 SV* msg = sv_newmortal();
4202 gv_efullname3(name = sv_newmortal(), gv, Nullch);
4203 sv_setpv(msg, "Prototype mismatch:");
4205 Perl_sv_catpvf(aTHX_ msg, " sub %"SVf, name);
4207 Perl_sv_catpvf(aTHX_ msg, " (%s)", SvPVX(cv));
4208 sv_catpv(msg, " vs ");
4210 Perl_sv_catpvf(aTHX_ msg, "(%s)", p);
4212 sv_catpv(msg, "none");
4213 Perl_warner(aTHX_ WARN_UNSAFE, "%"SVf, msg);
4218 Perl_cv_const_sv(pTHX_ CV *cv)
4220 if (!cv || !SvPOK(cv) || SvCUR(cv))
4222 return op_const_sv(CvSTART(cv), cv);
4226 Perl_op_const_sv(pTHX_ OP *o, CV *cv)
4233 if(o->op_type == OP_LINESEQ && cLISTOPo->op_first)
4234 o = cLISTOPo->op_first->op_sibling;
4236 for (; o; o = o->op_next) {
4237 OPCODE type = o->op_type;
4239 if (sv && o->op_next == o)
4241 if (type == OP_NEXTSTATE || type == OP_NULL || type == OP_PUSHMARK)
4243 if (type == OP_LEAVESUB || type == OP_RETURN)
4247 if (type == OP_CONST && cSVOPo->op_sv)
4249 else if ((type == OP_PADSV || type == OP_CONST) && cv) {
4250 AV* padav = (AV*)(AvARRAY(CvPADLIST(cv))[1]);
4251 sv = padav ? AvARRAY(padav)[o->op_targ] : Nullsv;
4252 if (!sv || (!SvREADONLY(sv) && SvREFCNT(sv) > 1))
4264 Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
4274 Perl_croak(aTHX_ "\"my sub\" not yet implemented");
4278 Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block)
4280 return Perl_newATTRSUB(aTHX_ floor, o, proto, Nullop, block);
4284 Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
4288 char *name = o ? SvPVx(cSVOPo->op_sv, n_a) : Nullch;
4289 GV *gv = gv_fetchpv(name ? name : "__ANON__",
4290 GV_ADDMULTI | ((block || attrs) ? 0 : GV_NOINIT),
4292 char *ps = proto ? SvPVx(((SVOP*)proto)->op_sv, n_a) : Nullch;
4303 if (SvTYPE(gv) != SVt_PVGV) { /* Maybe prototype now, and had at
4304 maximum a prototype before. */
4305 if (SvTYPE(gv) > SVt_NULL) {
4306 if (!SvPOK((SV*)gv) && !(SvIOK((SV*)gv) && SvIVX((SV*)gv) == -1)
4307 && ckWARN_d(WARN_UNSAFE))
4309 Perl_warner(aTHX_ WARN_UNSAFE, "Runaway prototype");
4311 cv_ckproto((CV*)gv, NULL, ps);
4314 sv_setpv((SV*)gv, ps);
4316 sv_setiv((SV*)gv, -1);
4317 SvREFCNT_dec(PL_compcv);
4318 cv = PL_compcv = NULL;
4319 PL_sub_generation++;
4323 if (!name || GvCVGEN(gv))
4325 else if (cv = GvCV(gv)) {
4326 cv_ckproto(cv, gv, ps);
4327 /* already defined (or promised)? */
4328 if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
4330 bool const_changed = TRUE;
4331 if (!block && !attrs) {
4332 /* just a "sub foo;" when &foo is already defined */
4333 SAVEFREESV(PL_compcv);
4336 /* ahem, death to those who redefine active sort subs */
4337 if (PL_curstackinfo->si_type == PERLSI_SORT && PL_sortcop == CvSTART(cv))
4338 Perl_croak(aTHX_ "Can't redefine active sort subroutine %s", name);
4341 if(const_sv = cv_const_sv(cv))
4342 const_changed = sv_cmp(const_sv, op_const_sv(block, Nullcv));
4343 if ((const_sv && const_changed) || ckWARN(WARN_REDEFINE)
4344 && !(CvGV(cv) && GvSTASH(CvGV(cv))
4345 && HvNAME(GvSTASH(CvGV(cv)))
4346 && strEQ(HvNAME(GvSTASH(CvGV(cv))),
4348 line_t oldline = CopLINE(PL_curcop);
4349 CopLINE_set(PL_curcop, PL_copline);
4350 Perl_warner(aTHX_ WARN_REDEFINE,
4351 const_sv ? "Constant subroutine %s redefined"
4352 : "Subroutine %s redefined", name);
4353 CopLINE_set(PL_curcop, oldline);
4364 /* Need to do a C<use attributes $stash_of_cv,\&cv,@attrs>
4365 * before we clobber PL_compcv.
4369 if (CvGV(cv) && GvSTASH(CvGV(cv)) && HvNAME(GvSTASH(CvGV(cv))))
4370 stash = GvSTASH(CvGV(cv));
4371 else if (CvSTASH(cv) && HvNAME(CvSTASH(cv)))
4372 stash = CvSTASH(cv);
4374 stash = PL_curstash;
4377 /* possibly about to re-define existing subr -- ignore old cv */
4378 rcv = (SV*)PL_compcv;
4379 if (name && GvSTASH(gv) && HvNAME(GvSTASH(gv)))
4380 stash = GvSTASH(gv);
4382 stash = PL_curstash;
4384 apply_attrs(stash, rcv, attrs);
4386 if (cv) { /* must reuse cv if autoloaded */
4388 /* got here with just attrs -- work done, so bug out */
4389 SAVEFREESV(PL_compcv);
4393 CvFLAGS(cv) = CvFLAGS(PL_compcv);
4394 CvOUTSIDE(cv) = CvOUTSIDE(PL_compcv);
4395 CvOUTSIDE(PL_compcv) = 0;
4396 CvPADLIST(cv) = CvPADLIST(PL_compcv);
4397 CvPADLIST(PL_compcv) = 0;
4398 if (SvREFCNT(PL_compcv) > 1) /* XXX Make closures transit through stub. */
4399 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc((SV*)cv);
4400 SvREFCNT_dec(PL_compcv);
4407 PL_sub_generation++;
4410 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4411 CvFILE(cv) = CopFILE(PL_curcop);
4412 CvSTASH(cv) = PL_curstash;
4415 if (!CvMUTEXP(cv)) {
4416 New(666, CvMUTEXP(cv), 1, perl_mutex);
4417 MUTEX_INIT(CvMUTEXP(cv));
4419 #endif /* USE_THREADS */
4422 sv_setpv((SV*)cv, ps);
4424 if (PL_error_count) {
4428 char *s = strrchr(name, ':');
4430 if (strEQ(s, "BEGIN")) {
4432 "BEGIN not safe after errors--compilation aborted";
4433 if (PL_in_eval & EVAL_KEEPERR)
4434 Perl_croak(aTHX_ not_safe);
4436 /* force display of errors found but not reported */
4437 sv_catpv(ERRSV, not_safe);
4438 Perl_croak(aTHX_ "%s", SvPVx(ERRSV, n_a));
4445 PL_copline = NOLINE;
4450 if (AvFILLp(PL_comppad_name) < AvFILLp(PL_comppad))
4451 av_store(PL_comppad_name, AvFILLp(PL_comppad), Nullsv);
4454 CvROOT(cv) = newUNOP(OP_LEAVESUBLV, 0, scalarseq(block));
4457 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
4459 CvROOT(cv)->op_private |= OPpREFCOUNTED;
4460 OpREFCNT_set(CvROOT(cv), 1);
4461 CvSTART(cv) = LINKLIST(CvROOT(cv));
4462 CvROOT(cv)->op_next = 0;
4465 /* now that optimizer has done its work, adjust pad values */
4467 SV **namep = AvARRAY(PL_comppad_name);
4468 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4471 if (SvIMMORTAL(PL_curpad[ix]) || IS_PADGV(PL_curpad[ix]) || IS_PADCONST(PL_curpad[ix]))
4474 * The only things that a clonable function needs in its
4475 * pad are references to outer lexicals and anonymous subs.
4476 * The rest are created anew during cloning.
4478 if (!((namesv = namep[ix]) != Nullsv &&
4479 namesv != &PL_sv_undef &&
4481 *SvPVX(namesv) == '&')))
4483 SvREFCNT_dec(PL_curpad[ix]);
4484 PL_curpad[ix] = Nullsv;
4489 AV *av = newAV(); /* Will be @_ */
4491 av_store(PL_comppad, 0, (SV*)av);
4492 AvFLAGS(av) = AVf_REIFY;
4494 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4495 if (SvIMMORTAL(PL_curpad[ix]) || IS_PADGV(PL_curpad[ix]) || IS_PADCONST(PL_curpad[ix]))
4497 if (!SvPADMY(PL_curpad[ix]))
4498 SvPADTMP_on(PL_curpad[ix]);
4505 if (PERLDB_SUBLINE && PL_curstash != PL_debstash) {
4506 SV *sv = NEWSV(0,0);
4507 SV *tmpstr = sv_newmortal();
4508 GV *db_postponed = gv_fetchpv("DB::postponed", GV_ADDMULTI, SVt_PVHV);
4512 Perl_sv_setpvf(aTHX_ sv, "%s:%ld-%ld",
4514 (long)PL_subline, (long)CopLINE(PL_curcop));
4515 gv_efullname3(tmpstr, gv, Nullch);
4516 hv_store(GvHV(PL_DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
4517 hv = GvHVn(db_postponed);
4518 if (HvFILL(hv) > 0 && hv_exists(hv, SvPVX(tmpstr), SvCUR(tmpstr))
4519 && (cv = GvCV(db_postponed))) {
4524 call_sv((SV*)cv, G_DISCARD);
4528 if ((s = strrchr(name,':')))
4533 if (*s != 'B' && *s != 'E' && *s != 'S' && *s != 'I')
4536 if (strEQ(s, "BEGIN")) {
4537 I32 oldscope = PL_scopestack_ix;
4539 SAVECOPFILE(&PL_compiling);
4540 SAVECOPLINE(&PL_compiling);
4542 sv_setsv(PL_rs, PL_nrs);
4545 PL_beginav = newAV();
4546 DEBUG_x( dump_sub(gv) );
4547 av_push(PL_beginav, SvREFCNT_inc(cv));
4549 call_list(oldscope, PL_beginav);
4551 PL_curcop = &PL_compiling;
4552 PL_compiling.op_private = PL_hints;
4555 else if (strEQ(s, "END") && !PL_error_count) {
4558 DEBUG_x( dump_sub(gv) );
4559 av_unshift(PL_endav, 1);
4560 av_store(PL_endav, 0, SvREFCNT_inc(cv));
4563 else if (strEQ(s, "STOP") && !PL_error_count) {
4565 PL_stopav = newAV();
4566 DEBUG_x( dump_sub(gv) );
4567 av_unshift(PL_stopav, 1);
4568 av_store(PL_stopav, 0, SvREFCNT_inc(cv));
4571 else if (strEQ(s, "INIT") && !PL_error_count) {
4573 PL_initav = newAV();
4574 DEBUG_x( dump_sub(gv) );
4575 av_push(PL_initav, SvREFCNT_inc(cv));
4581 PL_copline = NOLINE;
4586 /* XXX unsafe for threads if eval_owner isn't held */
4588 Perl_newCONSTSUB(pTHX_ HV *stash, char *name, SV *sv)
4593 SAVECOPLINE(PL_curcop);
4596 CopLINE_set(PL_curcop, PL_copline);
4597 PL_hints &= ~HINT_BLOCK_SCOPE;
4600 SAVESPTR(PL_curstash);
4601 SAVECOPSTASH(PL_curcop);
4602 PL_curstash = stash;
4604 CopSTASHPV(PL_curcop) = stash ? HvNAME(stash) : Nullch;
4606 CopSTASH(PL_curcop) = stash;
4611 start_subparse(FALSE, 0),
4612 newSVOP(OP_CONST, 0, newSVpv(name,0)),
4613 newSVOP(OP_CONST, 0, &PL_sv_no), /* SvPV(&PL_sv_no) == "" -- GMB */
4615 newSTATEOP(0, Nullch, newSVOP(OP_CONST, 0, sv))
4622 Perl_newXS(pTHX_ char *name, XSUBADDR_t subaddr, char *filename)
4625 GV *gv = gv_fetchpv(name ? name : "__ANON__", GV_ADDMULTI, SVt_PVCV);
4628 if (cv = (name ? GvCV(gv) : Nullcv)) {
4630 /* just a cached method */
4634 else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
4635 /* already defined (or promised) */
4636 if (ckWARN(WARN_REDEFINE) && !(CvGV(cv) && GvSTASH(CvGV(cv))
4637 && HvNAME(GvSTASH(CvGV(cv)))
4638 && strEQ(HvNAME(GvSTASH(CvGV(cv))), "autouse"))) {
4639 line_t oldline = CopLINE(PL_curcop);
4640 if (PL_copline != NOLINE)
4641 CopLINE_set(PL_curcop, PL_copline);
4642 Perl_warner(aTHX_ WARN_REDEFINE, "Subroutine %s redefined",name);
4643 CopLINE_set(PL_curcop, oldline);
4650 if (cv) /* must reuse cv if autoloaded */
4653 cv = (CV*)NEWSV(1105,0);
4654 sv_upgrade((SV *)cv, SVt_PVCV);
4658 PL_sub_generation++;
4661 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4663 New(666, CvMUTEXP(cv), 1, perl_mutex);
4664 MUTEX_INIT(CvMUTEXP(cv));
4666 #endif /* USE_THREADS */
4667 (void)gv_fetchfile(filename);
4668 CvFILE(cv) = filename; /* NOTE: not copied, as it is expected to be
4669 an external constant string */
4670 CvXSUB(cv) = subaddr;
4673 char *s = strrchr(name,':');
4679 if (*s != 'B' && *s != 'E' && *s != 'S' && *s != 'I')
4682 if (strEQ(s, "BEGIN")) {
4684 PL_beginav = newAV();
4685 av_push(PL_beginav, SvREFCNT_inc(cv));
4688 else if (strEQ(s, "END")) {
4691 av_unshift(PL_endav, 1);
4692 av_store(PL_endav, 0, SvREFCNT_inc(cv));
4695 else if (strEQ(s, "STOP")) {
4697 PL_stopav = newAV();
4698 av_unshift(PL_stopav, 1);
4699 av_store(PL_stopav, 0, SvREFCNT_inc(cv));
4702 else if (strEQ(s, "INIT")) {
4704 PL_initav = newAV();
4705 av_push(PL_initav, SvREFCNT_inc(cv));
4717 Perl_newFORM(pTHX_ I32 floor, OP *o, OP *block)
4727 name = SvPVx(cSVOPo->op_sv, n_a);
4730 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
4732 if (cv = GvFORM(gv)) {
4733 if (ckWARN(WARN_REDEFINE)) {
4734 line_t oldline = CopLINE(PL_curcop);
4736 CopLINE_set(PL_curcop, PL_copline);
4737 Perl_warner(aTHX_ WARN_REDEFINE, "Format %s redefined",name);
4738 CopLINE_set(PL_curcop, oldline);
4744 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4745 CvFILE(cv) = CopFILE(PL_curcop);
4747 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4748 if (!SvPADMY(PL_curpad[ix]) && !SvIMMORTAL(PL_curpad[ix]))
4749 SvPADTMP_on(PL_curpad[ix]);
4752 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
4753 CvROOT(cv)->op_private |= OPpREFCOUNTED;
4754 OpREFCNT_set(CvROOT(cv), 1);
4755 CvSTART(cv) = LINKLIST(CvROOT(cv));
4756 CvROOT(cv)->op_next = 0;
4759 PL_copline = NOLINE;
4764 Perl_newANONLIST(pTHX_ OP *o)
4766 return newUNOP(OP_REFGEN, 0,
4767 mod(list(convert(OP_ANONLIST, 0, o)), OP_REFGEN));
4771 Perl_newANONHASH(pTHX_ OP *o)
4773 return newUNOP(OP_REFGEN, 0,
4774 mod(list(convert(OP_ANONHASH, 0, o)), OP_REFGEN));
4778 Perl_newANONSUB(pTHX_ I32 floor, OP *proto, OP *block)
4780 return newANONATTRSUB(floor, proto, Nullop, block);
4784 Perl_newANONATTRSUB(pTHX_ I32 floor, OP *proto, OP *attrs, OP *block)
4786 return newUNOP(OP_REFGEN, 0,
4787 newSVOP(OP_ANONCODE, 0,
4788 (SV*)newATTRSUB(floor, 0, proto, attrs, block)));
4792 Perl_oopsAV(pTHX_ OP *o)
4794 switch (o->op_type) {
4796 o->op_type = OP_PADAV;
4797 o->op_ppaddr = PL_ppaddr[OP_PADAV];
4798 return ref(o, OP_RV2AV);
4801 o->op_type = OP_RV2AV;
4802 o->op_ppaddr = PL_ppaddr[OP_RV2AV];
4807 if (ckWARN_d(WARN_INTERNAL))
4808 Perl_warner(aTHX_ WARN_INTERNAL, "oops: oopsAV");
4815 Perl_oopsHV(pTHX_ OP *o)
4819 switch (o->op_type) {
4822 o->op_type = OP_PADHV;
4823 o->op_ppaddr = PL_ppaddr[OP_PADHV];
4824 return ref(o, OP_RV2HV);
4828 o->op_type = OP_RV2HV;
4829 o->op_ppaddr = PL_ppaddr[OP_RV2HV];
4834 if (ckWARN_d(WARN_INTERNAL))
4835 Perl_warner(aTHX_ WARN_INTERNAL, "oops: oopsHV");
4842 Perl_newAVREF(pTHX_ OP *o)
4844 if (o->op_type == OP_PADANY) {
4845 o->op_type = OP_PADAV;
4846 o->op_ppaddr = PL_ppaddr[OP_PADAV];
4849 return newUNOP(OP_RV2AV, 0, scalar(o));
4853 Perl_newGVREF(pTHX_ I32 type, OP *o)
4855 if (type == OP_MAPSTART || type == OP_GREPSTART || type == OP_SORT)
4856 return newUNOP(OP_NULL, 0, o);
4857 return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
4861 Perl_newHVREF(pTHX_ OP *o)
4863 if (o->op_type == OP_PADANY) {
4864 o->op_type = OP_PADHV;
4865 o->op_ppaddr = PL_ppaddr[OP_PADHV];
4868 return newUNOP(OP_RV2HV, 0, scalar(o));
4872 Perl_oopsCV(pTHX_ OP *o)
4874 Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
4880 Perl_newCVREF(pTHX_ I32 flags, OP *o)
4882 return newUNOP(OP_RV2CV, flags, scalar(o));
4886 Perl_newSVREF(pTHX_ OP *o)
4888 if (o->op_type == OP_PADANY) {
4889 o->op_type = OP_PADSV;
4890 o->op_ppaddr = PL_ppaddr[OP_PADSV];
4893 else if (o->op_type == OP_THREADSV && !(o->op_flags & OPpDONE_SVREF)) {
4894 o->op_flags |= OPpDONE_SVREF;
4897 return newUNOP(OP_RV2SV, 0, scalar(o));
4900 /* Check routines. */
4903 Perl_ck_anoncode(pTHX_ OP *o)
4908 name = NEWSV(1106,0);
4909 sv_upgrade(name, SVt_PVNV);
4910 sv_setpvn(name, "&", 1);
4913 ix = pad_alloc(o->op_type, SVs_PADMY);
4914 av_store(PL_comppad_name, ix, name);
4915 av_store(PL_comppad, ix, cSVOPo->op_sv);
4916 SvPADMY_on(cSVOPo->op_sv);
4917 cSVOPo->op_sv = Nullsv;
4918 cSVOPo->op_targ = ix;
4923 Perl_ck_bitop(pTHX_ OP *o)
4925 o->op_private = PL_hints;
4930 Perl_ck_concat(pTHX_ OP *o)
4932 if (cUNOPo->op_first->op_type == OP_CONCAT)
4933 o->op_flags |= OPf_STACKED;
4938 Perl_ck_spair(pTHX_ OP *o)
4940 if (o->op_flags & OPf_KIDS) {
4943 OPCODE type = o->op_type;
4944 o = modkids(ck_fun(o), type);
4945 kid = cUNOPo->op_first;
4946 newop = kUNOP->op_first->op_sibling;
4948 (newop->op_sibling ||
4949 !(PL_opargs[newop->op_type] & OA_RETSCALAR) ||
4950 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
4951 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
4955 op_free(kUNOP->op_first);
4956 kUNOP->op_first = newop;
4958 o->op_ppaddr = PL_ppaddr[++o->op_type];
4963 Perl_ck_delete(pTHX_ OP *o)
4967 if (o->op_flags & OPf_KIDS) {
4968 OP *kid = cUNOPo->op_first;
4969 switch (kid->op_type) {
4971 o->op_flags |= OPf_SPECIAL;
4974 o->op_private |= OPpSLICE;
4977 o->op_flags |= OPf_SPECIAL;
4982 Perl_croak(aTHX_ "%s argument is not a HASH or ARRAY element or slice",
4983 PL_op_desc[o->op_type]);
4991 Perl_ck_eof(pTHX_ OP *o)
4993 I32 type = o->op_type;
4995 if (o->op_flags & OPf_KIDS) {
4996 if (cLISTOPo->op_first->op_type == OP_STUB) {
4998 o = newUNOP(type, OPf_SPECIAL,
4999 newGVOP(OP_GV, 0, gv_fetchpv("main::ARGV", TRUE, SVt_PVAV)));
5007 Perl_ck_eval(pTHX_ OP *o)
5009 PL_hints |= HINT_BLOCK_SCOPE;
5010 if (o->op_flags & OPf_KIDS) {
5011 SVOP *kid = (SVOP*)cUNOPo->op_first;
5014 o->op_flags &= ~OPf_KIDS;
5017 else if (kid->op_type == OP_LINESEQ) {
5020 kid->op_next = o->op_next;
5021 cUNOPo->op_first = 0;
5024 NewOp(1101, enter, 1, LOGOP);
5025 enter->op_type = OP_ENTERTRY;
5026 enter->op_ppaddr = PL_ppaddr[OP_ENTERTRY];
5027 enter->op_private = 0;
5029 /* establish postfix order */
5030 enter->op_next = (OP*)enter;
5032 o = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
5033 o->op_type = OP_LEAVETRY;
5034 o->op_ppaddr = PL_ppaddr[OP_LEAVETRY];
5035 enter->op_other = o;
5043 o = newUNOP(OP_ENTEREVAL, 0, newDEFSVOP());
5045 o->op_targ = (PADOFFSET)PL_hints;
5050 Perl_ck_exec(pTHX_ OP *o)
5053 if (o->op_flags & OPf_STACKED) {
5055 kid = cUNOPo->op_first->op_sibling;
5056 if (kid->op_type == OP_RV2GV)
5065 Perl_ck_exists(pTHX_ OP *o)
5068 if (o->op_flags & OPf_KIDS) {
5069 OP *kid = cUNOPo->op_first;
5070 if (kid->op_type == OP_ENTERSUB) {
5071 (void) ref(kid, o->op_type);
5072 if (kid->op_type != OP_RV2CV && !PL_error_count)
5073 Perl_croak(aTHX_ "%s argument is not a subroutine name",
5074 PL_op_desc[o->op_type]);
5075 o->op_private |= OPpEXISTS_SUB;
5077 else if (kid->op_type == OP_AELEM)
5078 o->op_flags |= OPf_SPECIAL;
5079 else if (kid->op_type != OP_HELEM)
5080 Perl_croak(aTHX_ "%s argument is not a HASH or ARRAY element",
5081 PL_op_desc[o->op_type]);
5089 Perl_ck_gvconst(pTHX_ register OP *o)
5091 o = fold_constants(o);
5092 if (o->op_type == OP_CONST)
5099 Perl_ck_rvconst(pTHX_ register OP *o)
5102 SVOP *kid = (SVOP*)cUNOPo->op_first;
5104 o->op_private |= (PL_hints & HINT_STRICT_REFS);
5105 if (kid->op_type == OP_CONST) {
5109 SV *kidsv = kid->op_sv;
5112 /* Is it a constant from cv_const_sv()? */
5113 if (SvROK(kidsv) && SvREADONLY(kidsv)) {
5114 SV *rsv = SvRV(kidsv);
5115 int svtype = SvTYPE(rsv);
5116 char *badtype = Nullch;
5118 switch (o->op_type) {
5120 if (svtype > SVt_PVMG)
5121 badtype = "a SCALAR";
5124 if (svtype != SVt_PVAV)
5125 badtype = "an ARRAY";
5128 if (svtype != SVt_PVHV) {
5129 if (svtype == SVt_PVAV) { /* pseudohash? */
5130 SV **ksv = av_fetch((AV*)rsv, 0, FALSE);
5131 if (ksv && SvROK(*ksv)
5132 && SvTYPE(SvRV(*ksv)) == SVt_PVHV)
5141 if (svtype != SVt_PVCV)
5146 Perl_croak(aTHX_ "Constant is not %s reference", badtype);
5149 name = SvPV(kidsv, n_a);
5150 if ((PL_hints & HINT_STRICT_REFS) && (kid->op_private & OPpCONST_BARE)) {
5151 char *badthing = Nullch;
5152 switch (o->op_type) {
5154 badthing = "a SCALAR";
5157 badthing = "an ARRAY";
5160 badthing = "a HASH";
5165 "Can't use bareword (\"%s\") as %s ref while \"strict refs\" in use",
5169 * This is a little tricky. We only want to add the symbol if we
5170 * didn't add it in the lexer. Otherwise we get duplicate strict
5171 * warnings. But if we didn't add it in the lexer, we must at
5172 * least pretend like we wanted to add it even if it existed before,
5173 * or we get possible typo warnings. OPpCONST_ENTERED says
5174 * whether the lexer already added THIS instance of this symbol.
5176 iscv = (o->op_type == OP_RV2CV) * 2;
5178 gv = gv_fetchpv(name,
5179 iscv | !(kid->op_private & OPpCONST_ENTERED),
5182 : o->op_type == OP_RV2SV
5184 : o->op_type == OP_RV2AV
5186 : o->op_type == OP_RV2HV
5189 } while (!gv && !(kid->op_private & OPpCONST_ENTERED) && !iscv++);
5191 kid->op_type = OP_GV;
5192 SvREFCNT_dec(kid->op_sv);
5194 /* XXX hack: dependence on sizeof(PADOP) <= sizeof(SVOP) */
5195 kPADOP->op_padix = pad_alloc(OP_GV, SVs_PADTMP);
5197 PL_curpad[kPADOP->op_padix] = SvREFCNT_inc(gv);
5199 kid->op_sv = SvREFCNT_inc(gv);
5201 kid->op_ppaddr = PL_ppaddr[OP_GV];
5208 Perl_ck_ftst(pTHX_ OP *o)
5211 I32 type = o->op_type;
5213 if (o->op_flags & OPf_REF) {
5216 else if (o->op_flags & OPf_KIDS && cUNOPo->op_first->op_type != OP_STUB) {
5217 SVOP *kid = (SVOP*)cUNOPo->op_first;
5219 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
5221 OP *newop = newGVOP(type, OPf_REF,
5222 gv_fetchpv(SvPVx(kid->op_sv, n_a), TRUE, SVt_PVIO));
5229 if (type == OP_FTTTY)
5230 o = newGVOP(type, OPf_REF, gv_fetchpv("main::STDIN", TRUE,
5233 o = newUNOP(type, 0, newDEFSVOP());
5236 if (type == OP_FTTEXT || type == OP_FTBINARY) {
5238 if (PL_hints & HINT_LOCALE)
5239 o->op_private |= OPpLOCALE;
5246 Perl_ck_fun(pTHX_ OP *o)
5253 int type = o->op_type;
5254 register I32 oa = PL_opargs[type] >> OASHIFT;
5256 if (o->op_flags & OPf_STACKED) {
5257 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
5260 return no_fh_allowed(o);
5263 if (o->op_flags & OPf_KIDS) {
5265 tokid = &cLISTOPo->op_first;
5266 kid = cLISTOPo->op_first;
5267 if (kid->op_type == OP_PUSHMARK ||
5268 kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK)
5270 tokid = &kid->op_sibling;
5271 kid = kid->op_sibling;
5273 if (!kid && PL_opargs[type] & OA_DEFGV)
5274 *tokid = kid = newDEFSVOP();
5278 sibl = kid->op_sibling;
5281 /* list seen where single (scalar) arg expected? */
5282 if (numargs == 1 && !(oa >> 4)
5283 && kid->op_type == OP_LIST && type != OP_SCALAR)
5285 return too_many_arguments(o,PL_op_desc[type]);
5298 if (kid->op_type == OP_CONST &&
5299 (kid->op_private & OPpCONST_BARE))
5301 char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
5302 OP *newop = newAVREF(newGVOP(OP_GV, 0,
5303 gv_fetchpv(name, TRUE, SVt_PVAV) ));
5304 if (ckWARN(WARN_SYNTAX))
5305 Perl_warner(aTHX_ WARN_SYNTAX,
5306 "Array @%s missing the @ in argument %"IVdf" of %s()",
5307 name, (IV)numargs, PL_op_desc[type]);
5310 kid->op_sibling = sibl;
5313 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
5314 bad_type(numargs, "array", PL_op_desc[type], kid);
5318 if (kid->op_type == OP_CONST &&
5319 (kid->op_private & OPpCONST_BARE))
5321 char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
5322 OP *newop = newHVREF(newGVOP(OP_GV, 0,
5323 gv_fetchpv(name, TRUE, SVt_PVHV) ));
5324 if (ckWARN(WARN_SYNTAX))
5325 Perl_warner(aTHX_ WARN_SYNTAX,
5326 "Hash %%%s missing the %% in argument %"IVdf" of %s()",
5327 name, (IV)numargs, PL_op_desc[type]);
5330 kid->op_sibling = sibl;
5333 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
5334 bad_type(numargs, "hash", PL_op_desc[type], kid);
5339 OP *newop = newUNOP(OP_NULL, 0, kid);
5340 kid->op_sibling = 0;
5342 newop->op_next = newop;
5344 kid->op_sibling = sibl;
5349 if (kid->op_type != OP_GV && kid->op_type != OP_RV2GV) {
5350 if (kid->op_type == OP_CONST &&
5351 (kid->op_private & OPpCONST_BARE))
5353 OP *newop = newGVOP(OP_GV, 0,
5354 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, n_a), TRUE,
5359 else if (kid->op_type == OP_READLINE) {
5360 /* neophyte patrol: open(<FH>), close(<FH>) etc. */
5361 bad_type(numargs, "HANDLE", PL_op_desc[o->op_type], kid);
5364 I32 flags = OPf_SPECIAL;
5368 /* is this op a FH constructor? */
5369 if (is_handle_constructor(o,numargs)) {
5370 char *name = Nullch;
5374 /* Set a flag to tell rv2gv to vivify
5375 * need to "prove" flag does not mean something
5376 * else already - NI-S 1999/05/07
5379 if (kid->op_type == OP_PADSV) {
5380 SV **namep = av_fetch(PL_comppad_name,
5382 if (namep && *namep)
5383 name = SvPV(*namep, len);
5385 else if (kid->op_type == OP_RV2SV
5386 && kUNOP->op_first->op_type == OP_GV)
5388 GV *gv = cGVOPx_gv(kUNOP->op_first);
5390 len = GvNAMELEN(gv);
5394 targ = pad_alloc(OP_RV2GV, SVs_PADTMP);
5395 namesv = PL_curpad[targ];
5396 SvUPGRADE(namesv, SVt_PV);
5398 sv_setpvn(namesv, "$", 1);
5399 sv_catpvn(namesv, name, len);
5402 kid->op_sibling = 0;
5403 kid = newUNOP(OP_RV2GV, flags, scalar(kid));
5404 kid->op_targ = targ;
5405 kid->op_private |= priv;
5407 kid->op_sibling = sibl;
5413 mod(scalar(kid), type);
5417 tokid = &kid->op_sibling;
5418 kid = kid->op_sibling;
5420 o->op_private |= numargs;
5422 return too_many_arguments(o,PL_op_desc[o->op_type]);
5425 else if (PL_opargs[type] & OA_DEFGV) {
5427 return newUNOP(type, 0, newDEFSVOP());
5431 while (oa & OA_OPTIONAL)
5433 if (oa && oa != OA_LIST)
5434 return too_few_arguments(o,PL_op_desc[o->op_type]);
5440 Perl_ck_glob(pTHX_ OP *o)
5444 if ((o->op_flags & OPf_KIDS) && !cLISTOPo->op_first->op_sibling)
5445 append_elem(OP_GLOB, o, newDEFSVOP());
5447 if (!((gv = gv_fetchpv("glob", FALSE, SVt_PVCV)) && GvIMPORTED_CV(gv)))
5448 gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
5450 #if !defined(PERL_EXTERNAL_GLOB)
5451 /* XXX this can be tightened up and made more failsafe. */
5453 OP *modname = newSVOP(OP_CONST, 0, newSVpvn("File::Glob", 10));
5454 modname->op_private |= OPpCONST_BARE;
5456 utilize(1, start_subparse(FALSE, 0), Nullop, modname,
5457 newSVOP(OP_CONST, 0, newSVpvn(":globally", 9)));
5458 gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
5461 #endif /* PERL_EXTERNAL_GLOB */
5463 if (gv && GvIMPORTED_CV(gv)) {
5464 append_elem(OP_GLOB, o,
5465 newSVOP(OP_CONST, 0, newSViv(PL_glob_index++)));
5466 o->op_type = OP_LIST;
5467 o->op_ppaddr = PL_ppaddr[OP_LIST];
5468 cLISTOPo->op_first->op_type = OP_PUSHMARK;
5469 cLISTOPo->op_first->op_ppaddr = PL_ppaddr[OP_PUSHMARK];
5470 o = newUNOP(OP_ENTERSUB, OPf_STACKED,
5471 append_elem(OP_LIST, o,
5472 scalar(newUNOP(OP_RV2CV, 0,
5473 newGVOP(OP_GV, 0, gv)))));
5474 o = newUNOP(OP_NULL, 0, ck_subr(o));
5475 o->op_targ = OP_GLOB; /* hint at what it used to be */
5478 gv = newGVgen("main");
5480 append_elem(OP_GLOB, o, newGVOP(OP_GV, 0, gv));
5486 Perl_ck_grep(pTHX_ OP *o)
5490 OPCODE type = o->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
5492 o->op_ppaddr = PL_ppaddr[OP_GREPSTART];
5493 NewOp(1101, gwop, 1, LOGOP);
5495 if (o->op_flags & OPf_STACKED) {
5498 kid = cLISTOPo->op_first->op_sibling;
5499 for (k = cLISTOPo->op_first->op_sibling->op_next; k; k = k->op_next) {
5502 kid->op_next = (OP*)gwop;
5503 o->op_flags &= ~OPf_STACKED;
5505 kid = cLISTOPo->op_first->op_sibling;
5506 if (type == OP_MAPWHILE)
5513 kid = cLISTOPo->op_first->op_sibling;
5514 if (kid->op_type != OP_NULL)
5515 Perl_croak(aTHX_ "panic: ck_grep");
5516 kid = kUNOP->op_first;
5518 gwop->op_type = type;
5519 gwop->op_ppaddr = PL_ppaddr[type];
5520 gwop->op_first = listkids(o);
5521 gwop->op_flags |= OPf_KIDS;
5522 gwop->op_private = 1;
5523 gwop->op_other = LINKLIST(kid);
5524 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
5525 kid->op_next = (OP*)gwop;
5527 kid = cLISTOPo->op_first->op_sibling;
5528 if (!kid || !kid->op_sibling)
5529 return too_few_arguments(o,PL_op_desc[o->op_type]);
5530 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
5531 mod(kid, OP_GREPSTART);
5537 Perl_ck_index(pTHX_ OP *o)
5539 if (o->op_flags & OPf_KIDS) {
5540 OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5542 kid = kid->op_sibling; /* get past "big" */
5543 if (kid && kid->op_type == OP_CONST)
5544 fbm_compile(((SVOP*)kid)->op_sv, 0);
5550 Perl_ck_lengthconst(pTHX_ OP *o)
5552 /* XXX length optimization goes here */
5557 Perl_ck_lfun(pTHX_ OP *o)
5559 OPCODE type = o->op_type;
5560 return modkids(ck_fun(o), type);
5564 Perl_ck_defined(pTHX_ OP *o) /* 19990527 MJD */
5567 if ((o->op_flags & OPf_KIDS) && ckWARN(WARN_DEPRECATED)) {
5568 switch (cUNOPo->op_first->op_type) {
5570 break; /* Globals via GV can be undef */
5572 case OP_AASSIGN: /* Is this a good idea? */
5573 Perl_warner(aTHX_ WARN_DEPRECATED,
5574 "defined(@array) is deprecated");
5575 Perl_warner(aTHX_ WARN_DEPRECATED,
5576 "(Maybe you should just omit the defined()?)\n");
5579 break; /* Globals via GV can be undef */
5581 Perl_warner(aTHX_ WARN_DEPRECATED,
5582 "defined(%%hash) is deprecated");
5583 Perl_warner(aTHX_ WARN_DEPRECATED,
5584 "(Maybe you should just omit the defined()?)\n");
5595 Perl_ck_rfun(pTHX_ OP *o)
5597 OPCODE type = o->op_type;
5598 return refkids(ck_fun(o), type);
5602 Perl_ck_listiob(pTHX_ OP *o)
5606 kid = cLISTOPo->op_first;
5609 kid = cLISTOPo->op_first;
5611 if (kid->op_type == OP_PUSHMARK)
5612 kid = kid->op_sibling;
5613 if (kid && o->op_flags & OPf_STACKED)
5614 kid = kid->op_sibling;
5615 else if (kid && !kid->op_sibling) { /* print HANDLE; */
5616 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
5617 o->op_flags |= OPf_STACKED; /* make it a filehandle */
5618 kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
5619 cLISTOPo->op_first->op_sibling = kid;
5620 cLISTOPo->op_last = kid;
5621 kid = kid->op_sibling;
5626 append_elem(o->op_type, o, newDEFSVOP());
5632 if (PL_hints & HINT_LOCALE)
5633 o->op_private |= OPpLOCALE;
5640 Perl_ck_fun_locale(pTHX_ OP *o)
5646 if (PL_hints & HINT_LOCALE)
5647 o->op_private |= OPpLOCALE;
5654 Perl_ck_sassign(pTHX_ OP *o)
5656 OP *kid = cLISTOPo->op_first;
5657 /* has a disposable target? */
5658 if ((PL_opargs[kid->op_type] & OA_TARGLEX)
5659 && !(kid->op_flags & OPf_STACKED))
5661 OP *kkid = kid->op_sibling;
5663 /* Can just relocate the target. */
5664 if (kkid && kkid->op_type == OP_PADSV
5665 && !(kkid->op_private & OPpLVAL_INTRO))
5667 kid->op_targ = kkid->op_targ;
5669 /* Now we do not need PADSV and SASSIGN. */
5670 kid->op_sibling = o->op_sibling; /* NULL */
5671 cLISTOPo->op_first = NULL;
5674 kid->op_private |= OPpTARGET_MY; /* Used for context settings */
5682 Perl_ck_scmp(pTHX_ OP *o)
5686 if (PL_hints & HINT_LOCALE)
5687 o->op_private |= OPpLOCALE;
5694 Perl_ck_match(pTHX_ OP *o)
5696 o->op_private |= OPpRUNTIME;
5701 Perl_ck_method(pTHX_ OP *o)
5703 OP *kid = cUNOPo->op_first;
5704 if (kid->op_type == OP_CONST) {
5705 SV* sv = kSVOP->op_sv;
5706 if (!(strchr(SvPVX(sv), ':') || strchr(SvPVX(sv), '\''))) {
5708 sv_upgrade(sv, SVt_PVIV);
5710 PERL_HASH(SvUVX(sv), SvPVX(sv), SvCUR(sv));
5711 cmop = newSVOP(OP_METHOD_NAMED, 0, sv);
5712 kSVOP->op_sv = Nullsv;
5721 Perl_ck_null(pTHX_ OP *o)
5727 Perl_ck_repeat(pTHX_ OP *o)
5729 if (cBINOPo->op_first->op_flags & OPf_PARENS) {
5730 o->op_private |= OPpREPEAT_DOLIST;
5731 cBINOPo->op_first = force_list(cBINOPo->op_first);
5739 Perl_ck_require(pTHX_ OP *o)
5741 if (o->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
5742 SVOP *kid = (SVOP*)cUNOPo->op_first;
5744 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
5746 for (s = SvPVX(kid->op_sv); *s; s++) {
5747 if (*s == ':' && s[1] == ':') {
5749 Move(s+2, s+1, strlen(s+2)+1, char);
5750 --SvCUR(kid->op_sv);
5753 sv_catpvn(kid->op_sv, ".pm", 3);
5761 Perl_ck_retarget(pTHX_ OP *o)
5763 Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
5770 Perl_ck_select(pTHX_ OP *o)
5773 if (o->op_flags & OPf_KIDS) {
5774 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5775 if (kid && kid->op_sibling) {
5776 o->op_type = OP_SSELECT;
5777 o->op_ppaddr = PL_ppaddr[OP_SSELECT];
5779 return fold_constants(o);
5783 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5784 if (kid && kid->op_type == OP_RV2GV)
5785 kid->op_private &= ~HINT_STRICT_REFS;
5790 Perl_ck_shift(pTHX_ OP *o)
5792 I32 type = o->op_type;
5794 if (!(o->op_flags & OPf_KIDS)) {
5799 if (!CvUNIQUE(PL_compcv)) {
5800 argop = newOP(OP_PADAV, OPf_REF);
5801 argop->op_targ = 0; /* PL_curpad[0] is @_ */
5804 argop = newUNOP(OP_RV2AV, 0,
5805 scalar(newGVOP(OP_GV, 0,
5806 gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
5809 argop = newUNOP(OP_RV2AV, 0,
5810 scalar(newGVOP(OP_GV, 0, !CvUNIQUE(PL_compcv) ?
5811 PL_defgv : gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
5812 #endif /* USE_THREADS */
5813 return newUNOP(type, 0, scalar(argop));
5815 return scalar(modkids(ck_fun(o), type));
5819 Perl_ck_sort(pTHX_ OP *o)
5823 if (PL_hints & HINT_LOCALE)
5824 o->op_private |= OPpLOCALE;
5827 if (o->op_type == OP_SORT && o->op_flags & OPf_STACKED)
5829 if (o->op_flags & OPf_STACKED) { /* may have been cleared */
5830 OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5832 kid = kUNOP->op_first; /* get past null */
5834 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
5836 if (kid->op_type == OP_SCOPE) {
5840 else if (kid->op_type == OP_LEAVE) {
5841 if (o->op_type == OP_SORT) {
5842 null(kid); /* wipe out leave */
5845 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
5846 if (k->op_next == kid)
5851 kid->op_next = 0; /* just disconnect the leave */
5852 k = kLISTOP->op_first;
5856 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5857 if (o->op_type == OP_SORT)
5861 o->op_flags |= OPf_SPECIAL;
5863 else if (kid->op_type == OP_RV2SV || kid->op_type == OP_PADSV)
5864 null(cLISTOPo->op_first->op_sibling);
5871 S_simplify_sort(pTHX_ OP *o)
5874 register OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5878 if (!(o->op_flags & OPf_STACKED))
5880 GvMULTI_on(gv_fetchpv("a", TRUE, SVt_PV));
5881 GvMULTI_on(gv_fetchpv("b", TRUE, SVt_PV));
5882 kid = kUNOP->op_first; /* get past null */
5883 if (kid->op_type != OP_SCOPE)
5885 kid = kLISTOP->op_last; /* get past scope */
5886 switch(kid->op_type) {
5894 k = kid; /* remember this node*/
5895 if (kBINOP->op_first->op_type != OP_RV2SV)
5897 kid = kBINOP->op_first; /* get past cmp */
5898 if (kUNOP->op_first->op_type != OP_GV)
5900 kid = kUNOP->op_first; /* get past rv2sv */
5902 if (GvSTASH(gv) != PL_curstash)
5904 if (strEQ(GvNAME(gv), "a"))
5906 else if(strEQ(GvNAME(gv), "b"))
5910 kid = k; /* back to cmp */
5911 if (kBINOP->op_last->op_type != OP_RV2SV)
5913 kid = kBINOP->op_last; /* down to 2nd arg */
5914 if (kUNOP->op_first->op_type != OP_GV)
5916 kid = kUNOP->op_first; /* get past rv2sv */
5918 if (GvSTASH(gv) != PL_curstash
5920 ? strNE(GvNAME(gv), "a")
5921 : strNE(GvNAME(gv), "b")))
5923 o->op_flags &= ~(OPf_STACKED | OPf_SPECIAL);
5925 o->op_private |= OPpSORT_REVERSE;
5926 if (k->op_type == OP_NCMP)
5927 o->op_private |= OPpSORT_NUMERIC;
5928 if (k->op_type == OP_I_NCMP)
5929 o->op_private |= OPpSORT_NUMERIC | OPpSORT_INTEGER;
5930 kid = cLISTOPo->op_first->op_sibling;
5931 cLISTOPo->op_first->op_sibling = kid->op_sibling; /* bypass old block */
5932 op_free(kid); /* then delete it */
5933 cLISTOPo->op_children--;
5937 Perl_ck_split(pTHX_ OP *o)
5941 if (o->op_flags & OPf_STACKED)
5942 return no_fh_allowed(o);
5944 kid = cLISTOPo->op_first;
5945 if (kid->op_type != OP_NULL)
5946 Perl_croak(aTHX_ "panic: ck_split");
5947 kid = kid->op_sibling;
5948 op_free(cLISTOPo->op_first);
5949 cLISTOPo->op_first = kid;
5951 cLISTOPo->op_first = kid = newSVOP(OP_CONST, 0, newSVpvn(" ", 1));
5952 cLISTOPo->op_last = kid; /* There was only one element previously */
5955 if (kid->op_type != OP_MATCH) {
5956 OP *sibl = kid->op_sibling;
5957 kid->op_sibling = 0;
5958 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
5959 if (cLISTOPo->op_first == cLISTOPo->op_last)
5960 cLISTOPo->op_last = kid;
5961 cLISTOPo->op_first = kid;
5962 kid->op_sibling = sibl;
5965 kid->op_type = OP_PUSHRE;
5966 kid->op_ppaddr = PL_ppaddr[OP_PUSHRE];
5969 if (!kid->op_sibling)
5970 append_elem(OP_SPLIT, o, newDEFSVOP());
5972 kid = kid->op_sibling;
5975 if (!kid->op_sibling)
5976 append_elem(OP_SPLIT, o, newSVOP(OP_CONST, 0, newSViv(0)));
5978 kid = kid->op_sibling;
5981 if (kid->op_sibling)
5982 return too_many_arguments(o,PL_op_desc[o->op_type]);
5988 Perl_ck_join(pTHX_ OP *o)
5990 if (ckWARN(WARN_SYNTAX)) {
5991 OP *kid = cLISTOPo->op_first->op_sibling;
5992 if (kid && kid->op_type == OP_MATCH) {
5993 char *pmstr = "STRING";
5994 if (kPMOP->op_pmregexp)
5995 pmstr = kPMOP->op_pmregexp->precomp;
5996 Perl_warner(aTHX_ WARN_SYNTAX,
5997 "/%s/ should probably be written as \"%s\"",
6005 Perl_ck_subr(pTHX_ OP *o)
6008 OP *prev = ((cUNOPo->op_first->op_sibling)
6009 ? cUNOPo : ((UNOP*)cUNOPo->op_first))->op_first;
6010 OP *o2 = prev->op_sibling;
6019 o->op_private |= OPpENTERSUB_HASTARG;
6020 for (cvop = o2; cvop->op_sibling; cvop = cvop->op_sibling) ;
6021 if (cvop->op_type == OP_RV2CV) {
6023 o->op_private |= (cvop->op_private & OPpENTERSUB_AMPER);
6024 null(cvop); /* disable rv2cv */
6025 tmpop = (SVOP*)((UNOP*)cvop)->op_first;
6026 if (tmpop->op_type == OP_GV && !(o->op_private & OPpENTERSUB_AMPER)) {
6027 GV *gv = cGVOPx_gv(tmpop);
6030 tmpop->op_private |= OPpEARLY_CV;
6031 else if (SvPOK(cv)) {
6032 namegv = CvANON(cv) ? gv : CvGV(cv);
6033 proto = SvPV((SV*)cv, n_a);
6037 else if (cvop->op_type == OP_METHOD || cvop->op_type == OP_METHOD_NAMED) {
6038 if (o2->op_type == OP_CONST)
6039 o2->op_private &= ~OPpCONST_STRICT;
6040 else if (o2->op_type == OP_LIST) {
6041 OP *o = ((UNOP*)o2)->op_first->op_sibling;
6042 if (o && o->op_type == OP_CONST)
6043 o->op_private &= ~OPpCONST_STRICT;
6046 o->op_private |= (PL_hints & HINT_STRICT_REFS);
6047 if (PERLDB_SUB && PL_curstash != PL_debstash)
6048 o->op_private |= OPpENTERSUB_DB;
6049 while (o2 != cvop) {
6053 return too_many_arguments(o, gv_ename(namegv));
6071 if (o2->op_type != OP_REFGEN && o2->op_type != OP_UNDEF)
6072 bad_type(arg, "block", gv_ename(namegv), o2);
6075 /* '*' allows any scalar type, including bareword */
6078 if (o2->op_type == OP_RV2GV)
6079 goto wrapref; /* autoconvert GLOB -> GLOBref */
6080 else if (o2->op_type == OP_CONST)
6081 o2->op_private &= ~OPpCONST_STRICT;
6082 else if (o2->op_type == OP_ENTERSUB) {
6083 /* accidental subroutine, revert to bareword */
6084 OP *gvop = ((UNOP*)o2)->op_first;
6085 if (gvop && gvop->op_type == OP_NULL) {
6086 gvop = ((UNOP*)gvop)->op_first;
6088 for (; gvop->op_sibling; gvop = gvop->op_sibling)
6091 (gvop->op_private & OPpENTERSUB_NOPAREN) &&
6092 (gvop = ((UNOP*)gvop)->op_first) &&
6093 gvop->op_type == OP_GV)
6095 GV *gv = cGVOPx_gv(gvop);
6096 OP *sibling = o2->op_sibling;
6097 SV *n = newSVpvn("",0);
6099 gv_fullname3(n, gv, "");
6100 if (SvCUR(n)>6 && strnEQ(SvPVX(n),"main::",6))
6101 sv_chop(n, SvPVX(n)+6);
6102 o2 = newSVOP(OP_CONST, 0, n);
6103 prev->op_sibling = o2;
6104 o2->op_sibling = sibling;
6116 if (o2->op_type != OP_RV2GV)
6117 bad_type(arg, "symbol", gv_ename(namegv), o2);
6120 if (o2->op_type != OP_RV2CV)
6121 bad_type(arg, "sub", gv_ename(namegv), o2);
6124 if (o2->op_type != OP_RV2SV
6125 && o2->op_type != OP_PADSV
6126 && o2->op_type != OP_HELEM
6127 && o2->op_type != OP_AELEM
6128 && o2->op_type != OP_THREADSV)
6130 bad_type(arg, "scalar", gv_ename(namegv), o2);
6134 if (o2->op_type != OP_RV2AV && o2->op_type != OP_PADAV)
6135 bad_type(arg, "array", gv_ename(namegv), o2);
6138 if (o2->op_type != OP_RV2HV && o2->op_type != OP_PADHV)
6139 bad_type(arg, "hash", gv_ename(namegv), o2);
6143 OP* sib = kid->op_sibling;
6144 kid->op_sibling = 0;
6145 o2 = newUNOP(OP_REFGEN, 0, kid);
6146 o2->op_sibling = sib;
6147 prev->op_sibling = o2;
6158 Perl_croak(aTHX_ "Malformed prototype for %s: %s",
6159 gv_ename(namegv), SvPV((SV*)cv, n_a));
6164 mod(o2, OP_ENTERSUB);
6166 o2 = o2->op_sibling;
6168 if (proto && !optional &&
6169 (*proto && *proto != '@' && *proto != '%' && *proto != ';'))
6170 return too_few_arguments(o, gv_ename(namegv));
6175 Perl_ck_svconst(pTHX_ OP *o)
6177 SvREADONLY_on(cSVOPo->op_sv);
6182 Perl_ck_trunc(pTHX_ OP *o)
6184 if (o->op_flags & OPf_KIDS) {
6185 SVOP *kid = (SVOP*)cUNOPo->op_first;
6187 if (kid->op_type == OP_NULL)
6188 kid = (SVOP*)kid->op_sibling;
6189 if (kid && kid->op_type == OP_CONST &&
6190 (kid->op_private & OPpCONST_BARE))
6192 o->op_flags |= OPf_SPECIAL;
6193 kid->op_private &= ~OPpCONST_STRICT;
6199 /* A peephole optimizer. We visit the ops in the order they're to execute. */
6202 Perl_peep(pTHX_ register OP *o)
6205 register OP* oldop = 0;
6207 OP *last_composite = Nullop;
6209 if (!o || o->op_seq)
6213 SAVEVPTR(PL_curcop);
6214 for (; o; o = o->op_next) {
6220 switch (o->op_type) {
6224 PL_curcop = ((COP*)o); /* for warnings */
6225 o->op_seq = PL_op_seqmax++;
6226 last_composite = Nullop;
6230 if (cSVOPo->op_private & OPpCONST_STRICT)
6231 no_bareword_allowed(o);
6233 /* Relocate sv to the pad for thread safety.
6234 * Despite being a "constant", the SV is written to,
6235 * for reference counts, sv_upgrade() etc. */
6237 PADOFFSET ix = pad_alloc(OP_CONST, SVs_PADTMP);
6238 SvREFCNT_dec(PL_curpad[ix]);
6239 SvPADTMP_on(cSVOPo->op_sv);
6240 PL_curpad[ix] = cSVOPo->op_sv;
6241 cSVOPo->op_sv = Nullsv;
6253 if (o->op_next && o->op_next->op_type == OP_STRINGIFY) {
6254 if (o->op_next->op_private & OPpTARGET_MY) {
6255 if (o->op_flags & OPf_STACKED) /* chained concats */
6256 goto ignore_optimization;
6258 o->op_targ = o->op_next->op_targ;
6259 o->op_next->op_targ = 0;
6260 o->op_private |= OPpTARGET_MY;
6265 ignore_optimization:
6266 o->op_seq = PL_op_seqmax++;
6269 if ((o->op_flags & OPf_WANT) != OPf_WANT_LIST) {
6270 o->op_seq = PL_op_seqmax++;
6271 break; /* Scalar stub must produce undef. List stub is noop */
6275 if (o->op_targ == OP_NEXTSTATE
6276 || o->op_targ == OP_DBSTATE
6277 || o->op_targ == OP_SETSTATE)
6279 PL_curcop = ((COP*)o);
6286 if (oldop && o->op_next) {
6287 oldop->op_next = o->op_next;
6290 o->op_seq = PL_op_seqmax++;
6294 if (o->op_next->op_type == OP_RV2SV) {
6295 /* don't execute our($foo) */
6296 if (o->op_next->op_private & OPpOUR_INTRO) {
6298 o->op_next = o->op_next->op_next;
6300 if (oldop && o->op_next)
6301 oldop->op_next = o->op_next;
6303 else if (!(o->op_next->op_private & OPpDEREF)) {
6305 o->op_private |= o->op_next->op_private & OPpLVAL_INTRO;
6306 o->op_next = o->op_next->op_next;
6307 o->op_type = OP_GVSV;
6308 o->op_ppaddr = PL_ppaddr[OP_GVSV];
6311 else if (o->op_next->op_type == OP_RV2AV) {
6312 OP* pop = o->op_next->op_next;
6314 if (pop->op_type == OP_CONST &&
6315 (PL_op = pop->op_next) &&
6316 pop->op_next->op_type == OP_AELEM &&
6317 !(pop->op_next->op_private &
6318 (OPpLVAL_INTRO|OPpLVAL_DEFER|OPpDEREF)) &&
6319 (i = SvIV(((SVOP*)pop)->op_sv) - PL_compiling.cop_arybase)
6327 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
6328 o->op_next = pop->op_next->op_next;
6329 o->op_type = OP_AELEMFAST;
6330 o->op_ppaddr = PL_ppaddr[OP_AELEMFAST];
6331 o->op_private = (U8)i;
6336 else if ((o->op_private & OPpEARLY_CV) && ckWARN(WARN_UNSAFE)) {
6338 if (SvTYPE(gv) == SVt_PVGV && GvCV(gv) && SvPVX(GvCV(gv))) {
6339 /* XXX could check prototype here instead of just carping */
6340 SV *sv = sv_newmortal();
6341 gv_efullname3(sv, gv, Nullch);
6342 Perl_warner(aTHX_ WARN_UNSAFE,
6343 "%s() called too early to check prototype",
6348 o->op_seq = PL_op_seqmax++;
6359 o->op_seq = PL_op_seqmax++;
6360 while (cLOGOP->op_other->op_type == OP_NULL)
6361 cLOGOP->op_other = cLOGOP->op_other->op_next;
6362 peep(cLOGOP->op_other);
6366 o->op_seq = PL_op_seqmax++;
6367 peep(cLOOP->op_redoop);
6368 peep(cLOOP->op_nextop);
6369 peep(cLOOP->op_lastop);
6375 o->op_seq = PL_op_seqmax++;
6376 peep(cPMOP->op_pmreplstart);
6380 o->op_seq = PL_op_seqmax++;
6381 if (ckWARN(WARN_SYNTAX) && o->op_next
6382 && o->op_next->op_type == OP_NEXTSTATE) {
6383 if (o->op_next->op_sibling &&
6384 o->op_next->op_sibling->op_type != OP_EXIT &&
6385 o->op_next->op_sibling->op_type != OP_WARN &&
6386 o->op_next->op_sibling->op_type != OP_DIE) {
6387 line_t oldline = CopLINE(PL_curcop);
6389 CopLINE_set(PL_curcop, CopLINE((COP*)o->op_next));
6390 Perl_warner(aTHX_ WARN_EXEC,
6391 "Statement unlikely to be reached");
6392 Perl_warner(aTHX_ WARN_EXEC,
6393 "(Maybe you meant system() when you said exec()?)\n");
6394 CopLINE_set(PL_curcop, oldline);
6408 if ((o->op_private & (OPpLVAL_INTRO))
6409 || ((BINOP*)o)->op_last->op_type != OP_CONST)
6411 rop = (UNOP*)((BINOP*)o)->op_first;
6412 if (rop->op_type != OP_RV2HV || rop->op_first->op_type != OP_PADSV)
6414 lexname = *av_fetch(PL_comppad_name, rop->op_first->op_targ, TRUE);
6415 if (!SvOBJECT(lexname))
6417 fields = (GV**)hv_fetch(SvSTASH(lexname), "FIELDS", 6, FALSE);
6418 if (!fields || !GvHV(*fields))
6420 svp = cSVOPx_svp(((BINOP*)o)->op_last);
6421 key = SvPV(*svp, keylen);
6422 indsvp = hv_fetch(GvHV(*fields), key, keylen, FALSE);
6424 Perl_croak(aTHX_ "No such pseudo-hash field \"%s\" in variable %s of type %s",
6425 key, SvPV(lexname, n_a), HvNAME(SvSTASH(lexname)));
6427 ind = SvIV(*indsvp);
6429 Perl_croak(aTHX_ "Bad index while coercing array into hash");
6430 rop->op_type = OP_RV2AV;
6431 rop->op_ppaddr = PL_ppaddr[OP_RV2AV];
6432 o->op_type = OP_AELEM;
6433 o->op_ppaddr = PL_ppaddr[OP_AELEM];
6435 *svp = newSViv(ind);
6441 if (!(o->op_flags & OPf_WANT)
6442 || (o->op_flags & OPf_WANT) == OPf_WANT_LIST)
6446 o->op_seq = PL_op_seqmax++;
6450 if (o->op_next && o->op_next->op_type != OP_LEAVESUBLV) {
6451 o->op_seq = PL_op_seqmax++;
6457 if (last_composite) {
6458 OP *r = last_composite;
6460 while (r->op_sibling)
6463 || (r->op_next->op_type == OP_LIST
6464 && r->op_next->op_next == o))
6466 if (last_composite->op_type == OP_RV2AV)
6467 yyerror("Lvalue subs returning arrays not implemented yet");
6469 yyerror("Lvalue subs returning hashes not implemented yet");
6476 o->op_seq = PL_op_seqmax++;