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 \"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]);
207 #define FINDLEX_NOSEARCH 1 /* don't search outer contexts */
210 S_pad_findlex(pTHX_ char *name, PADOFFSET newoff, U32 seq, CV* startcv,
211 I32 cx_ix, I32 saweval, U32 flags)
218 register PERL_CONTEXT *cx;
220 for (cv = startcv; cv; cv = CvOUTSIDE(cv)) {
221 AV *curlist = CvPADLIST(cv);
222 SV **svp = av_fetch(curlist, 0, FALSE);
225 if (!svp || *svp == &PL_sv_undef)
228 svp = AvARRAY(curname);
229 for (off = AvFILLp(curname); off > 0; off--) {
230 if ((sv = svp[off]) &&
231 sv != &PL_sv_undef &&
233 seq > I_32(SvNVX(sv)) &&
234 strEQ(SvPVX(sv), name))
245 return 0; /* don't clone from inactive stack frame */
249 oldpad = (AV*)*av_fetch(curlist, depth, FALSE);
250 oldsv = *av_fetch(oldpad, off, TRUE);
251 if (!newoff) { /* Not a mere clone operation. */
252 SV *namesv = NEWSV(1103,0);
253 newoff = pad_alloc(OP_PADSV, SVs_PADMY);
254 sv_upgrade(namesv, SVt_PVNV);
255 sv_setpv(namesv, name);
256 av_store(PL_comppad_name, newoff, namesv);
257 SvNVX(namesv) = (NV)PL_curcop->cop_seq;
258 SvIVX(namesv) = PAD_MAX; /* A ref, intro immediately */
259 SvFAKE_on(namesv); /* A ref, not a real var */
260 if (SvFLAGS(sv) & SVpad_OUR) { /* An "our" variable */
261 SvFLAGS(namesv) |= SVpad_OUR;
262 (void)SvUPGRADE(namesv, SVt_PVGV);
263 GvSTASH(namesv) = (HV*)SvREFCNT_inc((SV*)GvSTASH(sv));
265 if (SvOBJECT(sv)) { /* A typed var */
267 (void)SvUPGRADE(namesv, SVt_PVMG);
268 SvSTASH(namesv) = (HV*)SvREFCNT_inc((SV*)SvSTASH(sv));
271 if (CvANON(PL_compcv) || SvTYPE(PL_compcv) == SVt_PVFM) {
272 /* "It's closures all the way down." */
273 CvCLONE_on(PL_compcv);
275 if (CvANON(PL_compcv))
276 oldsv = Nullsv; /* no need to keep ref */
281 bcv && bcv != cv && !CvCLONE(bcv);
282 bcv = CvOUTSIDE(bcv))
287 if (ckWARN(WARN_CLOSURE)
288 && !CvUNIQUE(bcv) && !CvUNIQUE(cv))
290 Perl_warner(aTHX_ WARN_CLOSURE,
291 "Variable \"%s\" may be unavailable",
299 else if (!CvUNIQUE(PL_compcv)) {
300 if (ckWARN(WARN_CLOSURE) && !SvFAKE(sv) && !CvUNIQUE(cv))
301 Perl_warner(aTHX_ WARN_CLOSURE,
302 "Variable \"%s\" will not stay shared", name);
305 av_store(PL_comppad, newoff, SvREFCNT_inc(oldsv));
311 if (flags & FINDLEX_NOSEARCH)
314 /* Nothing in current lexical context--try eval's context, if any.
315 * This is necessary to let the perldb get at lexically scoped variables.
316 * XXX This will also probably interact badly with eval tree caching.
319 for (i = cx_ix; i >= 0; i--) {
321 switch (CxTYPE(cx)) {
323 if (i == 0 && saweval) {
324 seq = cxstack[saweval].blk_oldcop->cop_seq;
325 return pad_findlex(name, newoff, seq, PL_main_cv, -1, saweval, 0);
329 switch (cx->blk_eval.old_op_type) {
335 /* require must have its own scope */
344 if (PL_debstash && CvSTASH(cv) == PL_debstash) { /* ignore DB'* scope */
345 saweval = i; /* so we know where we were called from */
348 seq = cxstack[saweval].blk_oldcop->cop_seq;
349 return pad_findlex(name, newoff, seq, cv, i-1, saweval,FINDLEX_NOSEARCH);
357 Perl_pad_findmy(pTHX_ char *name)
363 SV **svp = AvARRAY(PL_comppad_name);
364 U32 seq = PL_cop_seqmax;
370 * Special case to get lexical (and hence per-thread) @_.
371 * XXX I need to find out how to tell at parse-time whether use
372 * of @_ should refer to a lexical (from a sub) or defgv (global
373 * scope and maybe weird sub-ish things like formats). See
374 * startsub in perly.y. It's possible that @_ could be lexical
375 * (at least from subs) even in non-threaded perl.
377 if (strEQ(name, "@_"))
378 return 0; /* success. (NOT_IN_PAD indicates failure) */
379 #endif /* USE_THREADS */
381 /* The one we're looking for is probably just before comppad_name_fill. */
382 for (off = AvFILLp(PL_comppad_name); off > 0; off--) {
383 if ((sv = svp[off]) &&
384 sv != &PL_sv_undef &&
387 seq > I_32(SvNVX(sv)))) &&
388 strEQ(SvPVX(sv), name))
390 if (SvIVX(sv) || SvFLAGS(sv) & SVpad_OUR)
391 return (PADOFFSET)off;
392 pendoff = off; /* this pending def. will override import */
396 outside = CvOUTSIDE(PL_compcv);
398 /* Check if if we're compiling an eval'', and adjust seq to be the
399 * eval's seq number. This depends on eval'' having a non-null
400 * CvOUTSIDE() while it is being compiled. The eval'' itself is
401 * identified by CvEVAL being true and CvGV being null. */
402 if (outside && CvEVAL(PL_compcv) && !CvGV(PL_compcv) && cxstack_ix >= 0) {
403 cx = &cxstack[cxstack_ix];
405 seq = cx->blk_oldcop->cop_seq;
408 /* See if it's in a nested scope */
409 off = pad_findlex(name, 0, seq, outside, cxstack_ix, 0, 0);
411 /* If there is a pending local definition, this new alias must die */
413 SvIVX(AvARRAY(PL_comppad_name)[off]) = seq;
414 return off; /* pad_findlex returns 0 for failure...*/
416 return NOT_IN_PAD; /* ...but we return NOT_IN_PAD for failure */
420 Perl_pad_leavemy(pTHX_ I32 fill)
424 SV **svp = AvARRAY(PL_comppad_name);
426 if (PL_min_intro_pending && fill < PL_min_intro_pending) {
427 for (off = PL_max_intro_pending; off >= PL_min_intro_pending; off--) {
428 if ((sv = svp[off]) && sv != &PL_sv_undef && ckWARN_d(WARN_INTERNAL))
429 Perl_warner(aTHX_ WARN_INTERNAL, "%s never introduced", SvPVX(sv));
432 /* "Deintroduce" my variables that are leaving with this scope. */
433 for (off = AvFILLp(PL_comppad_name); off > fill; off--) {
434 if ((sv = svp[off]) && sv != &PL_sv_undef && SvIVX(sv) == PAD_MAX)
435 SvIVX(sv) = PL_cop_seqmax;
440 Perl_pad_alloc(pTHX_ I32 optype, U32 tmptype)
446 if (AvARRAY(PL_comppad) != PL_curpad)
447 Perl_croak(aTHX_ "panic: pad_alloc");
448 if (PL_pad_reset_pending)
450 if (tmptype & SVs_PADMY) {
452 sv = *av_fetch(PL_comppad, AvFILLp(PL_comppad) + 1, TRUE);
453 } while (SvPADBUSY(sv)); /* need a fresh one */
454 retval = AvFILLp(PL_comppad);
457 SV **names = AvARRAY(PL_comppad_name);
458 SSize_t names_fill = AvFILLp(PL_comppad_name);
461 * "foreach" index vars temporarily become aliases to non-"my"
462 * values. Thus we must skip, not just pad values that are
463 * marked as current pad values, but also those with names.
465 if (++PL_padix <= names_fill &&
466 (sv = names[PL_padix]) && sv != &PL_sv_undef)
468 sv = *av_fetch(PL_comppad, PL_padix, TRUE);
469 if (!(SvFLAGS(sv) & (SVs_PADTMP|SVs_PADMY)) && !IS_PADGV(sv))
474 SvFLAGS(sv) |= tmptype;
475 PL_curpad = AvARRAY(PL_comppad);
477 DEBUG_X(PerlIO_printf(Perl_debug_log,
478 "0x%"UVxf" Pad 0x%"UVxf" alloc %ld for %s\n",
479 PTR2UV(thr), PTR2UV(PL_curpad),
480 (long) retval, PL_op_name[optype]));
482 DEBUG_X(PerlIO_printf(Perl_debug_log,
483 "Pad 0x%"UVxf" alloc %ld for %s\n",
485 (long) retval, PL_op_name[optype]));
486 #endif /* USE_THREADS */
487 return (PADOFFSET)retval;
491 Perl_pad_sv(pTHX_ PADOFFSET po)
495 DEBUG_X(PerlIO_printf(Perl_debug_log,
496 "0x%"UVxf" Pad 0x%"UVxf" sv %"IVdf"\n",
497 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
500 Perl_croak(aTHX_ "panic: pad_sv po");
501 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" sv %"IVdf"\n",
502 PTR2UV(PL_curpad), (IV)po));
503 #endif /* USE_THREADS */
504 return PL_curpad[po]; /* eventually we'll turn this into a macro */
508 Perl_pad_free(pTHX_ PADOFFSET po)
513 if (AvARRAY(PL_comppad) != PL_curpad)
514 Perl_croak(aTHX_ "panic: pad_free curpad");
516 Perl_croak(aTHX_ "panic: pad_free po");
518 DEBUG_X(PerlIO_printf(Perl_debug_log,
519 "0x%"UVxf" Pad 0x%"UVxf" free %"IVdf"\n",
520 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
522 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" free %"IVdf"\n",
523 PTR2UV(PL_curpad), (IV)po));
524 #endif /* USE_THREADS */
525 if (PL_curpad[po] && PL_curpad[po] != &PL_sv_undef) {
526 SvPADTMP_off(PL_curpad[po]);
528 SvREADONLY_off(PL_curpad[po]); /* could be a freed constant */
531 if ((I32)po < PL_padix)
536 Perl_pad_swipe(pTHX_ PADOFFSET po)
539 if (AvARRAY(PL_comppad) != PL_curpad)
540 Perl_croak(aTHX_ "panic: pad_swipe curpad");
542 Perl_croak(aTHX_ "panic: pad_swipe po");
544 DEBUG_X(PerlIO_printf(Perl_debug_log,
545 "0x%"UVxf" Pad 0x%"UVxf" swipe %"IVdf"\n",
546 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
548 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" swipe %"IVdf"\n",
549 PTR2UV(PL_curpad), (IV)po));
550 #endif /* USE_THREADS */
551 SvPADTMP_off(PL_curpad[po]);
552 PL_curpad[po] = NEWSV(1107,0);
553 SvPADTMP_on(PL_curpad[po]);
554 if ((I32)po < PL_padix)
558 /* XXX pad_reset() is currently disabled because it results in serious bugs.
559 * It causes pad temp TARGs to be shared between OPs. Since TARGs are pushed
560 * on the stack by OPs that use them, there are several ways to get an alias
561 * to a shared TARG. Such an alias will change randomly and unpredictably.
562 * We avoid doing this until we can think of a Better Way.
567 #ifdef USE_BROKEN_PAD_RESET
571 if (AvARRAY(PL_comppad) != PL_curpad)
572 Perl_croak(aTHX_ "panic: pad_reset curpad");
574 DEBUG_X(PerlIO_printf(Perl_debug_log,
575 "0x%"UVxf" Pad 0x%"UVxf" reset\n",
576 PTR2UV(thr), PTR2UV(PL_curpad)));
578 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" reset\n",
580 #endif /* USE_THREADS */
581 if (!PL_tainting) { /* Can't mix tainted and non-tainted temporaries. */
582 for (po = AvMAX(PL_comppad); po > PL_padix_floor; po--) {
583 if (PL_curpad[po] && !SvIMMORTAL(PL_curpad[po]))
584 SvPADTMP_off(PL_curpad[po]);
586 PL_padix = PL_padix_floor;
589 PL_pad_reset_pending = FALSE;
593 /* find_threadsv is not reentrant */
595 Perl_find_threadsv(pTHX_ const char *name)
601 /* We currently only handle names of a single character */
602 p = strchr(PL_threadsv_names, *name);
605 key = p - PL_threadsv_names;
606 MUTEX_LOCK(&thr->mutex);
607 svp = av_fetch(thr->threadsv, key, FALSE);
609 MUTEX_UNLOCK(&thr->mutex);
611 SV *sv = NEWSV(0, 0);
612 av_store(thr->threadsv, key, sv);
613 thr->threadsvp = AvARRAY(thr->threadsv);
614 MUTEX_UNLOCK(&thr->mutex);
616 * Some magic variables used to be automagically initialised
617 * in gv_fetchpv. Those which are now per-thread magicals get
618 * initialised here instead.
624 sv_setpv(sv, "\034");
625 sv_magic(sv, 0, 0, name, 1);
630 PL_sawampersand = TRUE;
644 /* XXX %! tied to Errno.pm needs to be added here.
645 * See gv_fetchpv(). */
649 sv_magic(sv, 0, 0, name, 1);
651 DEBUG_S(PerlIO_printf(Perl_error_log,
652 "find_threadsv: new SV %p for $%s%c\n",
653 sv, (*name < 32) ? "^" : "",
654 (*name < 32) ? toCTRL(*name) : *name));
658 #endif /* USE_THREADS */
663 Perl_op_free(pTHX_ OP *o)
665 register OP *kid, *nextkid;
668 if (!o || o->op_seq == (U16)-1)
671 if (o->op_private & OPpREFCOUNTED) {
672 switch (o->op_type) {
680 if (OpREFCNT_dec(o)) {
691 if (o->op_flags & OPf_KIDS) {
692 for (kid = cUNOPo->op_first; kid; kid = nextkid) {
693 nextkid = kid->op_sibling; /* Get before next freeing kid */
701 /* COP* is not cleared by op_clear() so that we may track line
702 * numbers etc even after null() */
703 if (type == OP_NEXTSTATE || type == OP_SETSTATE || type == OP_DBSTATE)
708 #ifdef PL_OP_SLAB_ALLOC
709 if ((char *) o == PL_OpPtr)
718 S_op_clear(pTHX_ OP *o)
720 switch (o->op_type) {
721 case OP_NULL: /* Was holding old type, if any. */
722 case OP_ENTEREVAL: /* Was holding hints. */
724 case OP_THREADSV: /* Was holding index into thr->threadsv AV. */
730 if (!(o->op_flags & OPf_SPECIAL))
733 #endif /* USE_THREADS */
735 if (!(o->op_flags & OPf_REF)
736 || (PL_check[o->op_type] != MEMBER_TO_FPTR(Perl_ck_ftst)))
743 if (cPADOPo->op_padix > 0) {
746 pad_swipe(cPADOPo->op_padix);
747 /* No GvIN_PAD_off(gv) here, because other references may still
748 * exist on the pad */
751 cPADOPo->op_padix = 0;
754 SvREFCNT_dec(cSVOPo->op_sv);
755 cSVOPo->op_sv = Nullsv;
759 SvREFCNT_dec(cSVOPo->op_sv);
760 cSVOPo->op_sv = Nullsv;
766 if (o->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
770 if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
771 SvREFCNT_dec(cSVOPo->op_sv);
772 cSVOPo->op_sv = Nullsv;
775 Safefree(cPVOPo->op_pv);
776 cPVOPo->op_pv = Nullch;
780 op_free(cPMOPo->op_pmreplroot);
784 if ((PADOFFSET)cPMOPo->op_pmreplroot) {
786 GV *gv = (GV*)PL_curpad[(PADOFFSET)cPMOPo->op_pmreplroot];
787 pad_swipe((PADOFFSET)cPMOPo->op_pmreplroot);
788 /* No GvIN_PAD_off(gv) here, because other references may still
789 * exist on the pad */
794 SvREFCNT_dec((SV*)cPMOPo->op_pmreplroot);
800 cPMOPo->op_pmreplroot = Nullop;
801 ReREFCNT_dec(cPMOPo->op_pmregexp);
802 cPMOPo->op_pmregexp = (REGEXP*)NULL;
806 if (o->op_targ > 0) {
807 pad_free(o->op_targ);
813 S_cop_free(pTHX_ COP* cop)
815 Safefree(cop->cop_label);
817 Safefree(CopFILE(cop)); /* XXXXX share in a pvtable? */
818 Safefree(CopSTASHPV(cop)); /* XXXXX share in a pvtable? */
820 /* NOTE: COP.cop_stash is not refcounted */
821 SvREFCNT_dec(CopFILEGV(cop));
823 if (! specialWARN(cop->cop_warnings))
824 SvREFCNT_dec(cop->cop_warnings);
830 if (o->op_type == OP_NULL)
833 o->op_targ = o->op_type;
834 o->op_type = OP_NULL;
835 o->op_ppaddr = PL_ppaddr[OP_NULL];
838 /* Contextualizers */
840 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
843 Perl_linklist(pTHX_ OP *o)
850 /* establish postfix order */
851 if (cUNOPo->op_first) {
852 o->op_next = LINKLIST(cUNOPo->op_first);
853 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
855 kid->op_next = LINKLIST(kid->op_sibling);
867 Perl_scalarkids(pTHX_ OP *o)
870 if (o && o->op_flags & OPf_KIDS) {
871 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
878 S_scalarboolean(pTHX_ OP *o)
880 if (o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST) {
882 if (ckWARN(WARN_SYNTAX)) {
883 line_t oldline = CopLINE(PL_curcop);
885 if (PL_copline != NOLINE)
886 CopLINE_set(PL_curcop, PL_copline);
887 Perl_warner(aTHX_ WARN_SYNTAX, "Found = in conditional, should be ==");
888 CopLINE_set(PL_curcop, oldline);
895 Perl_scalar(pTHX_ OP *o)
899 /* assumes no premature commitment */
900 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
901 || o->op_type == OP_RETURN)
906 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_SCALAR;
908 switch (o->op_type) {
910 if (o->op_private & OPpREPEAT_DOLIST)
911 null(((LISTOP*)cBINOPo->op_first)->op_first);
912 scalar(cBINOPo->op_first);
917 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
921 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
922 if (!kPMOP->op_pmreplroot)
923 deprecate("implicit split to @_");
931 if (o->op_flags & OPf_KIDS) {
932 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
938 kid = cLISTOPo->op_first;
940 while (kid = kid->op_sibling) {
946 WITH_THR(PL_curcop = &PL_compiling);
951 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
957 WITH_THR(PL_curcop = &PL_compiling);
964 Perl_scalarvoid(pTHX_ OP *o)
971 if (o->op_type == OP_NEXTSTATE
972 || o->op_type == OP_SETSTATE
973 || o->op_type == OP_DBSTATE
974 || (o->op_type == OP_NULL && (o->op_targ == OP_NEXTSTATE
975 || o->op_targ == OP_SETSTATE
976 || o->op_targ == OP_DBSTATE)))
979 PL_curcop = (COP*)o; /* for warning below */
982 /* assumes no premature commitment */
983 want = o->op_flags & OPf_WANT;
984 if ((want && want != OPf_WANT_SCALAR) || PL_error_count
985 || o->op_type == OP_RETURN)
990 if ((o->op_private & OPpTARGET_MY)
991 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
993 return scalar(o); /* As if inside SASSIGN */
996 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_VOID;
998 switch (o->op_type) {
1000 if (!(PL_opargs[o->op_type] & OA_FOLDCONST))
1004 if (o->op_flags & OPf_STACKED)
1008 if (o->op_private == 4)
1050 case OP_GETSOCKNAME:
1051 case OP_GETPEERNAME:
1056 case OP_GETPRIORITY:
1079 if (!(o->op_private & OPpLVAL_INTRO))
1080 useless = PL_op_desc[o->op_type];
1087 if (!(o->op_private & (OPpLVAL_INTRO|OPpOUR_INTRO)) &&
1088 (!o->op_sibling || o->op_sibling->op_type != OP_READLINE))
1089 useless = "a variable";
1094 if (cSVOPo->op_private & OPpCONST_STRICT)
1095 no_bareword_allowed(o);
1098 if (ckWARN(WARN_VOID)) {
1099 useless = "a constant";
1100 if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
1102 else if (SvPOK(sv)) {
1103 if (strnEQ(SvPVX(sv), "di", 2) ||
1104 strnEQ(SvPVX(sv), "ds", 2) ||
1105 strnEQ(SvPVX(sv), "ig", 2))
1110 null(o); /* don't execute or even remember it */
1114 o->op_type = OP_PREINC; /* pre-increment is faster */
1115 o->op_ppaddr = PL_ppaddr[OP_PREINC];
1119 o->op_type = OP_PREDEC; /* pre-decrement is faster */
1120 o->op_ppaddr = PL_ppaddr[OP_PREDEC];
1126 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1131 if (o->op_flags & OPf_STACKED)
1139 if (!(o->op_flags & OPf_KIDS))
1148 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1155 /* all requires must return a boolean value */
1156 o->op_flags &= ~OPf_WANT;
1159 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
1160 if (!kPMOP->op_pmreplroot)
1161 deprecate("implicit split to @_");
1167 if (ckWARN(WARN_VOID))
1168 Perl_warner(aTHX_ WARN_VOID, "Useless use of %s in void context", useless);
1174 Perl_listkids(pTHX_ OP *o)
1177 if (o && o->op_flags & OPf_KIDS) {
1178 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1185 Perl_list(pTHX_ OP *o)
1189 /* assumes no premature commitment */
1190 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
1191 || o->op_type == OP_RETURN)
1196 if ((o->op_private & OPpTARGET_MY)
1197 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
1199 return o; /* As if inside SASSIGN */
1202 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_LIST;
1204 switch (o->op_type) {
1207 list(cBINOPo->op_first);
1212 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1220 if (!(o->op_flags & OPf_KIDS))
1222 if (!o->op_next && cUNOPo->op_first->op_type == OP_FLOP) {
1223 list(cBINOPo->op_first);
1224 return gen_constant_list(o);
1231 kid = cLISTOPo->op_first;
1233 while (kid = kid->op_sibling) {
1234 if (kid->op_sibling)
1239 WITH_THR(PL_curcop = &PL_compiling);
1243 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
1244 if (kid->op_sibling)
1249 WITH_THR(PL_curcop = &PL_compiling);
1252 /* all requires must return a boolean value */
1253 o->op_flags &= ~OPf_WANT;
1260 Perl_scalarseq(pTHX_ OP *o)
1265 if (o->op_type == OP_LINESEQ ||
1266 o->op_type == OP_SCOPE ||
1267 o->op_type == OP_LEAVE ||
1268 o->op_type == OP_LEAVETRY)
1271 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
1272 if (kid->op_sibling) {
1276 PL_curcop = &PL_compiling;
1278 o->op_flags &= ~OPf_PARENS;
1279 if (PL_hints & HINT_BLOCK_SCOPE)
1280 o->op_flags |= OPf_PARENS;
1283 o = newOP(OP_STUB, 0);
1288 S_modkids(pTHX_ OP *o, I32 type)
1291 if (o && o->op_flags & OPf_KIDS) {
1292 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1299 Perl_mod(pTHX_ OP *o, I32 type)
1306 if (!o || PL_error_count)
1309 if ((o->op_private & OPpTARGET_MY)
1310 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
1315 switch (o->op_type) {
1320 if (!(o->op_private & (OPpCONST_ARYBASE)))
1322 if (PL_eval_start && PL_eval_start->op_type == OP_CONST) {
1323 PL_compiling.cop_arybase = (I32)SvIV(cSVOPx(PL_eval_start)->op_sv);
1327 SAVEI32(PL_compiling.cop_arybase);
1328 PL_compiling.cop_arybase = 0;
1330 else if (type == OP_REFGEN)
1333 Perl_croak(aTHX_ "That use of $[ is unsupported");
1336 if (o->op_flags & OPf_PARENS)
1340 if ((type == OP_UNDEF || type == OP_REFGEN) &&
1341 !(o->op_flags & OPf_STACKED)) {
1342 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1343 o->op_ppaddr = PL_ppaddr[OP_RV2CV];
1344 assert(cUNOPo->op_first->op_type == OP_NULL);
1345 null(((LISTOP*)cUNOPo->op_first)->op_first);/* disable pushmark */
1348 else { /* lvalue subroutine call */
1349 o->op_private |= OPpLVAL_INTRO;
1350 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN) {
1351 /* Backward compatibility mode: */
1352 o->op_private |= OPpENTERSUB_INARGS;
1355 else { /* Compile-time error message: */
1356 OP *kid = cUNOPo->op_first;
1360 if (kid->op_type == OP_PUSHMARK)
1362 if (kid->op_type != OP_NULL || kid->op_targ != OP_LIST)
1364 "panic: unexpected lvalue entersub "
1365 "args: type/targ %ld:%ld",
1366 (long)kid->op_type,kid->op_targ);
1367 kid = kLISTOP->op_first;
1369 while (kid->op_sibling)
1370 kid = kid->op_sibling;
1371 if (!(kid->op_type == OP_NULL && kid->op_targ == OP_RV2CV)) {
1373 if (kid->op_type == OP_METHOD_NAMED
1374 || kid->op_type == OP_METHOD)
1378 if (kid->op_sibling || kid->op_next != kid) {
1379 yyerror("panic: unexpected optree near method call");
1383 NewOp(1101, newop, 1, OP);
1384 newop->op_type = OP_RV2CV;
1385 newop->op_ppaddr = PL_ppaddr[OP_RV2CV];
1386 newop->op_next = newop;
1387 kid->op_sibling = newop;
1388 newop->op_private |= OPpLVAL_INTRO;
1392 if (kid->op_type != OP_RV2CV)
1394 "panic: unexpected lvalue entersub "
1395 "entry via type/targ %ld:%ld",
1396 (long)kid->op_type,kid->op_targ);
1397 kid->op_private |= OPpLVAL_INTRO;
1398 break; /* Postpone until runtime */
1402 kid = kUNOP->op_first;
1403 if (kid->op_type == OP_NULL && kid->op_targ == OP_RV2SV)
1404 kid = kUNOP->op_first;
1405 if (kid->op_type == OP_NULL)
1407 "Unexpected constant lvalue entersub "
1408 "entry via type/targ %ld:%ld",
1409 (long)kid->op_type,kid->op_targ);
1410 if (kid->op_type != OP_GV) {
1411 /* Restore RV2CV to check lvalueness */
1413 if (kid->op_next && kid->op_next != kid) { /* Happens? */
1414 okid->op_next = kid->op_next;
1415 kid->op_next = okid;
1418 okid->op_next = Nullop;
1419 okid->op_type = OP_RV2CV;
1421 okid->op_ppaddr = PL_ppaddr[OP_RV2CV];
1422 okid->op_private |= OPpLVAL_INTRO;
1426 cv = GvCV(kGVOP_gv);
1436 /* grep, foreach, subcalls, refgen */
1437 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
1439 yyerror(Perl_form(aTHX_ "Can't modify %s in %s",
1440 (o->op_type == OP_NULL && (o->op_flags & OPf_SPECIAL)
1442 : (o->op_type == OP_ENTERSUB
1443 ? "non-lvalue subroutine call"
1444 : PL_op_desc[o->op_type])),
1445 type ? PL_op_desc[type] : "local"));
1459 case OP_RIGHT_SHIFT:
1468 if (!(o->op_flags & OPf_STACKED))
1474 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1480 if (!type && cUNOPo->op_first->op_type != OP_GV)
1481 Perl_croak(aTHX_ "Can't localize through a reference");
1482 if (type == OP_REFGEN && o->op_flags & OPf_PARENS) {
1483 PL_modcount = 10000;
1484 return o; /* Treat \(@foo) like ordinary list. */
1488 if (scalar_mod_type(o, type))
1490 ref(cUNOPo->op_first, o->op_type);
1499 PL_modcount = 10000;
1502 if (!type && cUNOPo->op_first->op_type != OP_GV)
1503 Perl_croak(aTHX_ "Can't localize through a reference");
1504 ref(cUNOPo->op_first, o->op_type);
1508 PL_hints |= HINT_BLOCK_SCOPE;
1518 PL_modcount = 10000;
1519 if (type == OP_REFGEN && o->op_flags & OPf_PARENS)
1520 return o; /* Treat \(@foo) like ordinary list. */
1521 if (scalar_mod_type(o, type))
1527 Perl_croak(aTHX_ "Can't localize lexical variable %s",
1528 SvPV(*av_fetch(PL_comppad_name, o->op_targ, 4), n_a));
1533 PL_modcount++; /* XXX ??? */
1535 #endif /* USE_THREADS */
1541 if (type != OP_SASSIGN)
1545 if (o->op_private == 4) /* don't allow 4 arg substr as lvalue */
1551 pad_free(o->op_targ);
1552 o->op_targ = pad_alloc(o->op_type, SVs_PADMY);
1553 assert(SvTYPE(PAD_SV(o->op_targ)) == SVt_NULL);
1554 if (o->op_flags & OPf_KIDS)
1555 mod(cBINOPo->op_first->op_sibling, type);
1560 ref(cBINOPo->op_first, o->op_type);
1561 if (type == OP_ENTERSUB &&
1562 !(o->op_private & (OPpLVAL_INTRO | OPpDEREF)))
1563 o->op_private |= OPpLVAL_DEFER;
1570 if (o->op_flags & OPf_KIDS)
1571 mod(cLISTOPo->op_last, type);
1575 if (o->op_flags & OPf_SPECIAL) /* do BLOCK */
1577 else if (!(o->op_flags & OPf_KIDS))
1579 if (o->op_targ != OP_LIST) {
1580 mod(cBINOPo->op_first, type);
1585 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1589 o->op_flags |= OPf_MOD;
1591 if (type == OP_AASSIGN || type == OP_SASSIGN)
1592 o->op_flags |= OPf_SPECIAL|OPf_REF;
1594 o->op_private |= OPpLVAL_INTRO;
1595 o->op_flags &= ~OPf_SPECIAL;
1596 PL_hints |= HINT_BLOCK_SCOPE;
1598 else if (type != OP_GREPSTART && type != OP_ENTERSUB)
1599 o->op_flags |= OPf_REF;
1604 S_scalar_mod_type(pTHX_ OP *o, I32 type)
1608 if (o->op_type == OP_RV2GV)
1632 case OP_RIGHT_SHIFT:
1651 S_is_handle_constructor(pTHX_ OP *o, I32 argnum)
1653 switch (o->op_type) {
1661 case OP_SELECT: /* XXX c.f. SelectSaver.pm */
1674 Perl_refkids(pTHX_ OP *o, I32 type)
1677 if (o && o->op_flags & OPf_KIDS) {
1678 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1685 Perl_ref(pTHX_ OP *o, I32 type)
1689 if (!o || PL_error_count)
1692 switch (o->op_type) {
1694 if ((type == OP_EXISTS || type == OP_DEFINED || type == OP_LOCK) &&
1695 !(o->op_flags & OPf_STACKED)) {
1696 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1697 o->op_ppaddr = PL_ppaddr[OP_RV2CV];
1698 assert(cUNOPo->op_first->op_type == OP_NULL);
1699 null(((LISTOP*)cUNOPo->op_first)->op_first); /* disable pushmark */
1700 o->op_flags |= OPf_SPECIAL;
1705 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1709 if (type == OP_DEFINED)
1710 o->op_flags |= OPf_SPECIAL; /* don't create GV */
1711 ref(cUNOPo->op_first, o->op_type);
1714 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1715 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1716 : type == OP_RV2HV ? OPpDEREF_HV
1718 o->op_flags |= OPf_MOD;
1723 o->op_flags |= OPf_MOD; /* XXX ??? */
1728 o->op_flags |= OPf_REF;
1731 if (type == OP_DEFINED)
1732 o->op_flags |= OPf_SPECIAL; /* don't create GV */
1733 ref(cUNOPo->op_first, o->op_type);
1738 o->op_flags |= OPf_REF;
1743 if (!(o->op_flags & OPf_KIDS))
1745 ref(cBINOPo->op_first, type);
1749 ref(cBINOPo->op_first, o->op_type);
1750 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1751 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1752 : type == OP_RV2HV ? OPpDEREF_HV
1754 o->op_flags |= OPf_MOD;
1762 if (!(o->op_flags & OPf_KIDS))
1764 ref(cLISTOPo->op_last, type);
1774 S_dup_attrlist(pTHX_ OP *o)
1778 /* An attrlist is either a simple OP_CONST or an OP_LIST with kids,
1779 * where the first kid is OP_PUSHMARK and the remaining ones
1780 * are OP_CONST. We need to push the OP_CONST values.
1782 if (o->op_type == OP_CONST)
1783 rop = newSVOP(OP_CONST, o->op_flags, SvREFCNT_inc(cSVOPo->op_sv));
1785 assert((o->op_type == OP_LIST) && (o->op_flags & OPf_KIDS));
1786 for (o = cLISTOPo->op_first; o; o=o->op_sibling) {
1787 if (o->op_type == OP_CONST)
1788 rop = append_elem(OP_LIST, rop,
1789 newSVOP(OP_CONST, o->op_flags,
1790 SvREFCNT_inc(cSVOPo->op_sv)));
1797 S_apply_attrs(pTHX_ HV *stash, SV *target, OP *attrs)
1799 OP *modname; /* for 'use' */
1802 /* fake up C<use attributes $pkg,$rv,@attrs> */
1803 ENTER; /* need to protect against side-effects of 'use' */
1805 if (stash && HvNAME(stash))
1806 stashsv = newSVpv(HvNAME(stash), 0);
1808 stashsv = &PL_sv_no;
1809 #define ATTRSMODULE "attributes"
1810 modname = newSVOP(OP_CONST, 0,
1811 newSVpvn(ATTRSMODULE, sizeof(ATTRSMODULE)-1));
1812 modname->op_private |= OPpCONST_BARE;
1813 /* that flag is required to make 'use' work right */
1814 utilize(1, start_subparse(FALSE, 0),
1815 Nullop, /* version */
1817 prepend_elem(OP_LIST,
1818 newSVOP(OP_CONST, 0, stashsv),
1819 prepend_elem(OP_LIST,
1820 newSVOP(OP_CONST, 0, newRV(target)),
1821 dup_attrlist(attrs))));
1826 S_my_kid(pTHX_ OP *o, OP *attrs)
1831 if (!o || PL_error_count)
1835 if (type == OP_LIST) {
1836 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1838 } else if (type == OP_UNDEF) {
1840 } else if (type == OP_RV2SV || /* "our" declaration */
1842 type == OP_RV2HV) { /* XXX does this let anything illegal in? */
1843 o->op_private |= OPpOUR_INTRO;
1845 } else if (type != OP_PADSV &&
1848 type != OP_PUSHMARK)
1850 yyerror(Perl_form(aTHX_ "Can't declare %s in my", PL_op_desc[o->op_type]));
1853 else if (attrs && type != OP_PUSHMARK) {
1858 /* check for C<my Dog $spot> when deciding package */
1859 namesvp = av_fetch(PL_comppad_name, o->op_targ, FALSE);
1860 if (namesvp && *namesvp && SvOBJECT(*namesvp) && HvNAME(SvSTASH(*namesvp)))
1861 stash = SvSTASH(*namesvp);
1863 stash = PL_curstash;
1864 padsv = PAD_SV(o->op_targ);
1865 apply_attrs(stash, padsv, attrs);
1867 o->op_flags |= OPf_MOD;
1868 o->op_private |= OPpLVAL_INTRO;
1873 Perl_my_attrs(pTHX_ OP *o, OP *attrs)
1875 if (o->op_flags & OPf_PARENS)
1878 PL_in_my_stash = Nullhv;
1881 return my_kid(o, attrs);
1885 Perl_my(pTHX_ OP *o)
1887 return my_kid(o, Nullop);
1891 Perl_sawparens(pTHX_ OP *o)
1894 o->op_flags |= OPf_PARENS;
1899 Perl_bind_match(pTHX_ I32 type, OP *left, OP *right)
1904 if (ckWARN(WARN_UNSAFE) &&
1905 (left->op_type == OP_RV2AV ||
1906 left->op_type == OP_RV2HV ||
1907 left->op_type == OP_PADAV ||
1908 left->op_type == OP_PADHV)) {
1909 char *desc = PL_op_desc[(right->op_type == OP_SUBST ||
1910 right->op_type == OP_TRANS)
1911 ? right->op_type : OP_MATCH];
1912 const char *sample = ((left->op_type == OP_RV2AV ||
1913 left->op_type == OP_PADAV)
1914 ? "@array" : "%hash");
1915 Perl_warner(aTHX_ WARN_UNSAFE,
1916 "Applying %s to %s will act on scalar(%s)",
1917 desc, sample, sample);
1920 if (right->op_type == OP_MATCH ||
1921 right->op_type == OP_SUBST ||
1922 right->op_type == OP_TRANS) {
1923 right->op_flags |= OPf_STACKED;
1924 if (right->op_type != OP_MATCH)
1925 left = mod(left, right->op_type);
1926 if (right->op_type == OP_TRANS)
1927 o = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
1929 o = prepend_elem(right->op_type, scalar(left), right);
1931 return newUNOP(OP_NOT, 0, scalar(o));
1935 return bind_match(type, left,
1936 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
1940 Perl_invert(pTHX_ OP *o)
1944 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
1945 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(o));
1949 Perl_scope(pTHX_ OP *o)
1952 if (o->op_flags & OPf_PARENS || PERLDB_NOOPT || PL_tainting) {
1953 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
1954 o->op_type = OP_LEAVE;
1955 o->op_ppaddr = PL_ppaddr[OP_LEAVE];
1958 if (o->op_type == OP_LINESEQ) {
1960 o->op_type = OP_SCOPE;
1961 o->op_ppaddr = PL_ppaddr[OP_SCOPE];
1962 kid = ((LISTOP*)o)->op_first;
1963 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE)
1967 o = newLISTOP(OP_SCOPE, 0, o, Nullop);
1974 Perl_save_hints(pTHX)
1977 SAVESPTR(GvHV(PL_hintgv));
1978 GvHV(PL_hintgv) = newHVhv(GvHV(PL_hintgv));
1979 SAVEFREESV(GvHV(PL_hintgv));
1983 Perl_block_start(pTHX_ int full)
1986 int retval = PL_savestack_ix;
1988 SAVEI32(PL_comppad_name_floor);
1990 if ((PL_comppad_name_fill = AvFILLp(PL_comppad_name)) > 0)
1991 PL_comppad_name_floor = PL_comppad_name_fill;
1993 PL_comppad_name_floor = 0;
1995 SAVEI32(PL_min_intro_pending);
1996 SAVEI32(PL_max_intro_pending);
1997 PL_min_intro_pending = 0;
1998 SAVEI32(PL_comppad_name_fill);
1999 SAVEI32(PL_padix_floor);
2000 PL_padix_floor = PL_padix;
2001 PL_pad_reset_pending = FALSE;
2003 PL_hints &= ~HINT_BLOCK_SCOPE;
2004 SAVESPTR(PL_compiling.cop_warnings);
2005 if (! specialWARN(PL_compiling.cop_warnings)) {
2006 PL_compiling.cop_warnings = newSVsv(PL_compiling.cop_warnings) ;
2007 SAVEFREESV(PL_compiling.cop_warnings) ;
2015 Perl_block_end(pTHX_ I32 floor, OP *seq)
2018 int needblockscope = PL_hints & HINT_BLOCK_SCOPE;
2019 OP* retval = scalarseq(seq);
2021 PL_pad_reset_pending = FALSE;
2022 PL_compiling.op_private = PL_hints;
2024 PL_hints |= HINT_BLOCK_SCOPE; /* propagate out */
2025 pad_leavemy(PL_comppad_name_fill);
2034 OP *o = newOP(OP_THREADSV, 0);
2035 o->op_targ = find_threadsv("_");
2038 return newSVREF(newGVOP(OP_GV, 0, PL_defgv));
2039 #endif /* USE_THREADS */
2043 Perl_newPROG(pTHX_ OP *o)
2049 PL_eval_root = newUNOP(OP_LEAVEEVAL,
2050 ((PL_in_eval & EVAL_KEEPERR)
2051 ? OPf_SPECIAL : 0), o);
2052 PL_eval_start = linklist(PL_eval_root);
2053 PL_eval_root->op_private |= OPpREFCOUNTED;
2054 OpREFCNT_set(PL_eval_root, 1);
2055 PL_eval_root->op_next = 0;
2056 peep(PL_eval_start);
2061 PL_main_root = scope(sawparens(scalarvoid(o)));
2062 PL_curcop = &PL_compiling;
2063 PL_main_start = LINKLIST(PL_main_root);
2064 PL_main_root->op_private |= OPpREFCOUNTED;
2065 OpREFCNT_set(PL_main_root, 1);
2066 PL_main_root->op_next = 0;
2067 peep(PL_main_start);
2070 /* Register with debugger */
2072 CV *cv = get_cv("DB::postponed", FALSE);
2076 XPUSHs((SV*)CopFILEGV(&PL_compiling));
2078 call_sv((SV*)cv, G_DISCARD);
2085 Perl_localize(pTHX_ OP *o, I32 lex)
2087 if (o->op_flags & OPf_PARENS)
2091 if (ckWARN(WARN_PARENTHESIS) && PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == ',') {
2093 for (s = PL_bufptr; *s && (isALNUM(*s) || (*s & 0x80) || strchr("@$%, ",*s)); s++) ;
2094 if (*s == ';' || *s == '=')
2095 Perl_warner(aTHX_ WARN_PARENTHESIS, "Parentheses missing around \"%s\" list",
2096 lex ? "my" : "local");
2100 PL_in_my_stash = Nullhv;
2104 return mod(o, OP_NULL); /* a bit kludgey */
2108 Perl_jmaybe(pTHX_ OP *o)
2110 if (o->op_type == OP_LIST) {
2113 o2 = newOP(OP_THREADSV, 0);
2114 o2->op_targ = find_threadsv(";");
2116 o2 = newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
2117 #endif /* USE_THREADS */
2118 o = convert(OP_JOIN, 0, prepend_elem(OP_LIST, o2, o));
2124 Perl_fold_constants(pTHX_ register OP *o)
2128 I32 type = o->op_type;
2131 if (PL_opargs[type] & OA_RETSCALAR)
2133 if (PL_opargs[type] & OA_TARGET && !o->op_targ)
2134 o->op_targ = pad_alloc(type, SVs_PADTMP);
2136 /* integerize op, unless it happens to be C<-foo>.
2137 * XXX should pp_i_negate() do magic string negation instead? */
2138 if ((PL_opargs[type] & OA_OTHERINT) && (PL_hints & HINT_INTEGER)
2139 && !(type == OP_NEGATE && cUNOPo->op_first->op_type == OP_CONST
2140 && (cUNOPo->op_first->op_private & OPpCONST_BARE)))
2142 o->op_ppaddr = PL_ppaddr[type = ++(o->op_type)];
2145 if (!(PL_opargs[type] & OA_FOLDCONST))
2150 /* XXX might want a ck_negate() for this */
2151 cUNOPo->op_first->op_private &= ~OPpCONST_STRICT;
2164 if (o->op_private & OPpLOCALE)
2169 goto nope; /* Don't try to run w/ errors */
2171 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
2172 if ((curop->op_type != OP_CONST ||
2173 (curop->op_private & OPpCONST_BARE)) &&
2174 curop->op_type != OP_LIST &&
2175 curop->op_type != OP_SCALAR &&
2176 curop->op_type != OP_NULL &&
2177 curop->op_type != OP_PUSHMARK)
2183 curop = LINKLIST(o);
2187 sv = *(PL_stack_sp--);
2188 if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
2189 pad_swipe(o->op_targ);
2190 else if (SvTEMP(sv)) { /* grab mortal temp? */
2191 (void)SvREFCNT_inc(sv);
2195 if (type == OP_RV2GV)
2196 return newGVOP(OP_GV, 0, (GV*)sv);
2198 /* try to smush double to int, but don't smush -2.0 to -2 */
2199 if ((SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK)) == SVf_NOK &&
2203 if ((NV)iv == SvNV(sv)) {
2208 SvIOK_off(sv); /* undo SvIV() damage */
2210 return newSVOP(OP_CONST, 0, sv);
2214 if (!(PL_opargs[type] & OA_OTHERINT))
2217 if (!(PL_hints & HINT_INTEGER)) {
2218 if (type == OP_MODULO
2219 || type == OP_DIVIDE
2220 || !(o->op_flags & OPf_KIDS))
2225 for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
2226 if (curop->op_type == OP_CONST) {
2227 if (SvIOK(((SVOP*)curop)->op_sv))
2231 if (PL_opargs[curop->op_type] & OA_RETINTEGER)
2235 o->op_ppaddr = PL_ppaddr[++(o->op_type)];
2242 Perl_gen_constant_list(pTHX_ register OP *o)
2246 I32 oldtmps_floor = PL_tmps_floor;
2250 return o; /* Don't attempt to run with errors */
2252 PL_op = curop = LINKLIST(o);
2259 PL_tmps_floor = oldtmps_floor;
2261 o->op_type = OP_RV2AV;
2262 o->op_ppaddr = PL_ppaddr[OP_RV2AV];
2263 curop = ((UNOP*)o)->op_first;
2264 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*PL_stack_sp--));
2271 Perl_convert(pTHX_ I32 type, I32 flags, OP *o)
2276 if (!o || o->op_type != OP_LIST)
2277 o = newLISTOP(OP_LIST, 0, o, Nullop);
2279 o->op_flags &= ~OPf_WANT;
2281 if (!(PL_opargs[type] & OA_MARK))
2282 null(cLISTOPo->op_first);
2285 o->op_ppaddr = PL_ppaddr[type];
2286 o->op_flags |= flags;
2288 o = CHECKOP(type, o);
2289 if (o->op_type != type)
2292 if (cLISTOPo->op_children < 7) {
2293 /* XXX do we really need to do this if we're done appending?? */
2294 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
2296 cLISTOPo->op_last = last; /* in case check substituted last arg */
2299 return fold_constants(o);
2302 /* List constructors */
2305 Perl_append_elem(pTHX_ I32 type, OP *first, OP *last)
2313 if (first->op_type != type || type==OP_LIST && first->op_flags & OPf_PARENS)
2314 return newLISTOP(type, 0, first, last);
2316 if (first->op_flags & OPf_KIDS)
2317 ((LISTOP*)first)->op_last->op_sibling = last;
2319 first->op_flags |= OPf_KIDS;
2320 ((LISTOP*)first)->op_first = last;
2322 ((LISTOP*)first)->op_last = last;
2323 ((LISTOP*)first)->op_children++;
2328 Perl_append_list(pTHX_ I32 type, LISTOP *first, LISTOP *last)
2336 if (first->op_type != type)
2337 return prepend_elem(type, (OP*)first, (OP*)last);
2339 if (last->op_type != type)
2340 return append_elem(type, (OP*)first, (OP*)last);
2342 first->op_last->op_sibling = last->op_first;
2343 first->op_last = last->op_last;
2344 first->op_children += last->op_children;
2345 if (first->op_children)
2346 first->op_flags |= OPf_KIDS;
2348 #ifdef PL_OP_SLAB_ALLOC
2356 Perl_prepend_elem(pTHX_ I32 type, OP *first, OP *last)
2364 if (last->op_type == type) {
2365 if (type == OP_LIST) { /* already a PUSHMARK there */
2366 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
2367 ((LISTOP*)last)->op_first->op_sibling = first;
2370 if (!(last->op_flags & OPf_KIDS)) {
2371 ((LISTOP*)last)->op_last = first;
2372 last->op_flags |= OPf_KIDS;
2374 first->op_sibling = ((LISTOP*)last)->op_first;
2375 ((LISTOP*)last)->op_first = first;
2377 ((LISTOP*)last)->op_children++;
2381 return newLISTOP(type, 0, first, last);
2387 Perl_newNULLLIST(pTHX)
2389 return newOP(OP_STUB, 0);
2393 Perl_force_list(pTHX_ OP *o)
2395 if (!o || o->op_type != OP_LIST)
2396 o = newLISTOP(OP_LIST, 0, o, Nullop);
2402 Perl_newLISTOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
2406 NewOp(1101, listop, 1, LISTOP);
2408 listop->op_type = type;
2409 listop->op_ppaddr = PL_ppaddr[type];
2410 listop->op_children = (first != 0) + (last != 0);
2411 listop->op_flags = flags;
2415 else if (!first && last)
2418 first->op_sibling = last;
2419 listop->op_first = first;
2420 listop->op_last = last;
2421 if (type == OP_LIST) {
2423 pushop = newOP(OP_PUSHMARK, 0);
2424 pushop->op_sibling = first;
2425 listop->op_first = pushop;
2426 listop->op_flags |= OPf_KIDS;
2428 listop->op_last = pushop;
2430 else if (listop->op_children)
2431 listop->op_flags |= OPf_KIDS;
2437 Perl_newOP(pTHX_ I32 type, I32 flags)
2440 NewOp(1101, o, 1, OP);
2442 o->op_ppaddr = PL_ppaddr[type];
2443 o->op_flags = flags;
2446 o->op_private = 0 + (flags >> 8);
2447 if (PL_opargs[type] & OA_RETSCALAR)
2449 if (PL_opargs[type] & OA_TARGET)
2450 o->op_targ = pad_alloc(type, SVs_PADTMP);
2451 return CHECKOP(type, o);
2455 Perl_newUNOP(pTHX_ I32 type, I32 flags, OP *first)
2460 first = newOP(OP_STUB, 0);
2461 if (PL_opargs[type] & OA_MARK)
2462 first = force_list(first);
2464 NewOp(1101, unop, 1, UNOP);
2465 unop->op_type = type;
2466 unop->op_ppaddr = PL_ppaddr[type];
2467 unop->op_first = first;
2468 unop->op_flags = flags | OPf_KIDS;
2469 unop->op_private = 1 | (flags >> 8);
2470 unop = (UNOP*) CHECKOP(type, unop);
2474 return fold_constants((OP *) unop);
2478 Perl_newBINOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
2481 NewOp(1101, binop, 1, BINOP);
2484 first = newOP(OP_NULL, 0);
2486 binop->op_type = type;
2487 binop->op_ppaddr = PL_ppaddr[type];
2488 binop->op_first = first;
2489 binop->op_flags = flags | OPf_KIDS;
2492 binop->op_private = 1 | (flags >> 8);
2495 binop->op_private = 2 | (flags >> 8);
2496 first->op_sibling = last;
2499 binop = (BINOP*)CHECKOP(type, binop);
2500 if (binop->op_next || binop->op_type != type)
2503 binop->op_last = binop->op_first->op_sibling;
2505 return fold_constants((OP *)binop);
2509 utf8compare(const void *a, const void *b)
2512 for (i = 0; i < 10; i++) {
2513 if ((*(U8**)a)[i] < (*(U8**)b)[i])
2515 if ((*(U8**)a)[i] > (*(U8**)b)[i])
2522 Perl_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
2524 SV *tstr = ((SVOP*)expr)->op_sv;
2525 SV *rstr = ((SVOP*)repl)->op_sv;
2528 register U8 *t = (U8*)SvPV(tstr, tlen);
2529 register U8 *r = (U8*)SvPV(rstr, rlen);
2535 register short *tbl;
2537 complement = o->op_private & OPpTRANS_COMPLEMENT;
2538 del = o->op_private & OPpTRANS_DELETE;
2539 squash = o->op_private & OPpTRANS_SQUASH;
2541 if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
2542 SV* listsv = newSVpvn("# comment\n",10);
2544 U8* tend = t + tlen;
2545 U8* rend = r + rlen;
2561 I32 from_utf = o->op_private & OPpTRANS_FROM_UTF;
2562 I32 to_utf = o->op_private & OPpTRANS_TO_UTF;
2568 New(1109, cp, tlen, U8*);
2570 transv = newSVpvn("",0);
2579 qsort(cp, i, sizeof(U8*), utf8compare);
2580 for (j = 0; j < i; j++) {
2582 UV val = utf8_to_uv(s, &ulen);
2584 diff = val - nextmin;
2586 t = uv_to_utf8(tmpbuf,nextmin);
2587 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2589 t = uv_to_utf8(tmpbuf, val - 1);
2590 sv_catpvn(transv, "\377", 1);
2591 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2595 val = utf8_to_uv(s+1, &ulen);
2599 t = uv_to_utf8(tmpbuf,nextmin);
2600 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2601 t = uv_to_utf8(tmpbuf, 0x7fffffff);
2602 sv_catpvn(transv, "\377", 1);
2603 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2604 t = (U8*)SvPVX(transv);
2605 tlen = SvCUR(transv);
2608 else if (!rlen && !del) {
2609 r = t; rlen = tlen; rend = tend;
2612 if (to_utf && from_utf) { /* only counting characters */
2613 if (t == r || (tlen == rlen && memEQ(t, r, tlen)))
2614 o->op_private |= OPpTRANS_IDENTICAL;
2616 else { /* straight latin-1 translation */
2617 if (tlen == 4 && memEQ(t, "\0\377\303\277", 4) &&
2618 rlen == 4 && memEQ(r, "\0\377\303\277", 4))
2619 o->op_private |= OPpTRANS_IDENTICAL;
2623 while (t < tend || tfirst <= tlast) {
2624 /* see if we need more "t" chars */
2625 if (tfirst > tlast) {
2626 tfirst = (I32)utf8_to_uv(t, &ulen);
2628 if (t < tend && *t == 0xff) { /* illegal utf8 val indicates range */
2629 tlast = (I32)utf8_to_uv(++t, &ulen);
2636 /* now see if we need more "r" chars */
2637 if (rfirst > rlast) {
2639 rfirst = (I32)utf8_to_uv(r, &ulen);
2641 if (r < rend && *r == 0xff) { /* illegal utf8 val indicates range */
2642 rlast = (I32)utf8_to_uv(++r, &ulen);
2651 rfirst = rlast = 0xffffffff;
2655 /* now see which range will peter our first, if either. */
2656 tdiff = tlast - tfirst;
2657 rdiff = rlast - rfirst;
2664 if (rfirst == 0xffffffff) {
2665 diff = tdiff; /* oops, pretend rdiff is infinite */
2667 Perl_sv_catpvf(aTHX_ listsv, "%04x\t%04x\tXXXX\n", tfirst, tlast);
2669 Perl_sv_catpvf(aTHX_ listsv, "%04x\t\tXXXX\n", tfirst);
2673 Perl_sv_catpvf(aTHX_ listsv, "%04x\t%04x\t%04x\n", tfirst, tfirst + diff, rfirst);
2675 Perl_sv_catpvf(aTHX_ listsv, "%04x\t\t%04x\n", tfirst, rfirst);
2677 if (rfirst + diff > max)
2678 max = rfirst + diff;
2683 else if (rfirst <= 0x800)
2684 grows |= (tfirst < 0x80);
2685 else if (rfirst <= 0x10000)
2686 grows |= (tfirst < 0x800);
2687 else if (rfirst <= 0x200000)
2688 grows |= (tfirst < 0x10000);
2689 else if (rfirst <= 0x4000000)
2690 grows |= (tfirst < 0x200000);
2691 else if (rfirst <= 0x80000000)
2692 grows |= (tfirst < 0x4000000);
2704 else if (max > 0xff)
2709 cSVOPo->op_sv = (SV*)swash_init("utf8", "", listsv, bits, none);
2710 SvREFCNT_dec(listsv);
2712 SvREFCNT_dec(transv);
2714 if (!del && havefinal)
2715 (void)hv_store((HV*)SvRV((cSVOPo->op_sv)), "FINAL", 5, newSViv((IV)final), 0);
2717 if (grows && to_utf)
2718 o->op_private |= OPpTRANS_GROWS;
2725 tbl = (short*)cPVOPo->op_pv;
2727 Zero(tbl, 256, short);
2728 for (i = 0; i < tlen; i++)
2730 for (i = 0, j = 0; i < 256; i++) {
2746 if (!rlen && !del) {
2749 o->op_private |= OPpTRANS_IDENTICAL;
2751 for (i = 0; i < 256; i++)
2753 for (i = 0, j = 0; i < tlen; i++,j++) {
2756 if (tbl[t[i]] == -1)
2762 if (tbl[t[i]] == -1)
2773 Perl_newPMOP(pTHX_ I32 type, I32 flags)
2778 NewOp(1101, pmop, 1, PMOP);
2779 pmop->op_type = type;
2780 pmop->op_ppaddr = PL_ppaddr[type];
2781 pmop->op_flags = flags;
2782 pmop->op_private = 0 | (flags >> 8);
2784 if (PL_hints & HINT_RE_TAINT)
2785 pmop->op_pmpermflags |= PMf_RETAINT;
2786 if (PL_hints & HINT_LOCALE)
2787 pmop->op_pmpermflags |= PMf_LOCALE;
2788 pmop->op_pmflags = pmop->op_pmpermflags;
2790 /* link into pm list */
2791 if (type != OP_TRANS && PL_curstash) {
2792 pmop->op_pmnext = HvPMROOT(PL_curstash);
2793 HvPMROOT(PL_curstash) = pmop;
2800 Perl_pmruntime(pTHX_ OP *o, OP *expr, OP *repl)
2805 I32 repl_has_vars = 0;
2807 if (o->op_type == OP_TRANS)
2808 return pmtrans(o, expr, repl);
2810 PL_hints |= HINT_BLOCK_SCOPE;
2813 if (expr->op_type == OP_CONST) {
2815 SV *pat = ((SVOP*)expr)->op_sv;
2816 char *p = SvPV(pat, plen);
2817 if ((o->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
2818 sv_setpvn(pat, "\\s+", 3);
2819 p = SvPV(pat, plen);
2820 pm->op_pmflags |= PMf_SKIPWHITE;
2822 pm->op_pmregexp = CALLREGCOMP(aTHX_ p, p + plen, pm);
2823 if (strEQ("\\s+", pm->op_pmregexp->precomp))
2824 pm->op_pmflags |= PMf_WHITE;
2828 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL))
2829 expr = newUNOP((!(PL_hints & HINT_RE_EVAL)
2831 : OP_REGCMAYBE),0,expr);
2833 NewOp(1101, rcop, 1, LOGOP);
2834 rcop->op_type = OP_REGCOMP;
2835 rcop->op_ppaddr = PL_ppaddr[OP_REGCOMP];
2836 rcop->op_first = scalar(expr);
2837 rcop->op_flags |= ((PL_hints & HINT_RE_EVAL)
2838 ? (OPf_SPECIAL | OPf_KIDS)
2840 rcop->op_private = 1;
2843 /* establish postfix order */
2844 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL)) {
2846 rcop->op_next = expr;
2847 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
2850 rcop->op_next = LINKLIST(expr);
2851 expr->op_next = (OP*)rcop;
2854 prepend_elem(o->op_type, scalar((OP*)rcop), o);
2859 if (pm->op_pmflags & PMf_EVAL) {
2861 if (CopLINE(PL_curcop) < PL_multi_end)
2862 CopLINE_set(PL_curcop, PL_multi_end);
2865 else if (repl->op_type == OP_THREADSV
2866 && strchr("&`'123456789+",
2867 PL_threadsv_names[repl->op_targ]))
2871 #endif /* USE_THREADS */
2872 else if (repl->op_type == OP_CONST)
2876 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
2877 if (PL_opargs[curop->op_type] & OA_DANGEROUS) {
2879 if (curop->op_type == OP_THREADSV) {
2881 if (strchr("&`'123456789+", curop->op_private))
2885 if (curop->op_type == OP_GV) {
2886 GV *gv = cGVOPx_gv(curop);
2888 if (strchr("&`'123456789+", *GvENAME(gv)))
2891 #endif /* USE_THREADS */
2892 else if (curop->op_type == OP_RV2CV)
2894 else if (curop->op_type == OP_RV2SV ||
2895 curop->op_type == OP_RV2AV ||
2896 curop->op_type == OP_RV2HV ||
2897 curop->op_type == OP_RV2GV) {
2898 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
2901 else if (curop->op_type == OP_PADSV ||
2902 curop->op_type == OP_PADAV ||
2903 curop->op_type == OP_PADHV ||
2904 curop->op_type == OP_PADANY) {
2907 else if (curop->op_type == OP_PUSHRE)
2908 ; /* Okay here, dangerous in newASSIGNOP */
2917 && (!pm->op_pmregexp
2918 || pm->op_pmregexp->reganch & ROPT_EVAL_SEEN))) {
2919 pm->op_pmflags |= PMf_CONST; /* const for long enough */
2920 pm->op_pmpermflags |= PMf_CONST; /* const for long enough */
2921 prepend_elem(o->op_type, scalar(repl), o);
2924 if (curop == repl && !pm->op_pmregexp) { /* Has variables. */
2925 pm->op_pmflags |= PMf_MAYBE_CONST;
2926 pm->op_pmpermflags |= PMf_MAYBE_CONST;
2928 NewOp(1101, rcop, 1, LOGOP);
2929 rcop->op_type = OP_SUBSTCONT;
2930 rcop->op_ppaddr = PL_ppaddr[OP_SUBSTCONT];
2931 rcop->op_first = scalar(repl);
2932 rcop->op_flags |= OPf_KIDS;
2933 rcop->op_private = 1;
2936 /* establish postfix order */
2937 rcop->op_next = LINKLIST(repl);
2938 repl->op_next = (OP*)rcop;
2940 pm->op_pmreplroot = scalar((OP*)rcop);
2941 pm->op_pmreplstart = LINKLIST(rcop);
2950 Perl_newSVOP(pTHX_ I32 type, I32 flags, SV *sv)
2953 NewOp(1101, svop, 1, SVOP);
2954 svop->op_type = type;
2955 svop->op_ppaddr = PL_ppaddr[type];
2957 svop->op_next = (OP*)svop;
2958 svop->op_flags = flags;
2959 if (PL_opargs[type] & OA_RETSCALAR)
2961 if (PL_opargs[type] & OA_TARGET)
2962 svop->op_targ = pad_alloc(type, SVs_PADTMP);
2963 return CHECKOP(type, svop);
2967 Perl_newPADOP(pTHX_ I32 type, I32 flags, SV *sv)
2970 NewOp(1101, padop, 1, PADOP);
2971 padop->op_type = type;
2972 padop->op_ppaddr = PL_ppaddr[type];
2973 padop->op_padix = pad_alloc(type, SVs_PADTMP);
2974 SvREFCNT_dec(PL_curpad[padop->op_padix]);
2975 PL_curpad[padop->op_padix] = sv;
2977 padop->op_next = (OP*)padop;
2978 padop->op_flags = flags;
2979 if (PL_opargs[type] & OA_RETSCALAR)
2981 if (PL_opargs[type] & OA_TARGET)
2982 padop->op_targ = pad_alloc(type, SVs_PADTMP);
2983 return CHECKOP(type, padop);
2987 Perl_newGVOP(pTHX_ I32 type, I32 flags, GV *gv)
2992 return newPADOP(type, flags, SvREFCNT_inc(gv));
2994 return newSVOP(type, flags, SvREFCNT_inc(gv));
2999 Perl_newPVOP(pTHX_ I32 type, I32 flags, char *pv)
3002 NewOp(1101, pvop, 1, PVOP);
3003 pvop->op_type = type;
3004 pvop->op_ppaddr = PL_ppaddr[type];
3006 pvop->op_next = (OP*)pvop;
3007 pvop->op_flags = flags;
3008 if (PL_opargs[type] & OA_RETSCALAR)
3010 if (PL_opargs[type] & OA_TARGET)
3011 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
3012 return CHECKOP(type, pvop);
3016 Perl_package(pTHX_ OP *o)
3021 save_hptr(&PL_curstash);
3022 save_item(PL_curstname);
3027 name = SvPV(sv, len);
3028 PL_curstash = gv_stashpvn(name,len,TRUE);
3029 sv_setpvn(PL_curstname, name, len);
3033 sv_setpv(PL_curstname,"<none>");
3034 PL_curstash = Nullhv;
3036 PL_hints |= HINT_BLOCK_SCOPE;
3037 PL_copline = NOLINE;
3042 Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *id, OP *arg)
3051 if (id->op_type != OP_CONST)
3052 Perl_croak(aTHX_ "Module name must be constant");
3056 if(version != Nullop) {
3057 SV *vesv = ((SVOP*)version)->op_sv;
3059 if (arg == Nullop && !SvNIOK(vesv)) {
3065 if (version->op_type != OP_CONST || !SvNIOK(vesv))
3066 Perl_croak(aTHX_ "Version number must be constant number");
3068 /* Make copy of id so we don't free it twice */
3069 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
3071 /* Fake up a method call to VERSION */
3072 veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
3073 append_elem(OP_LIST,
3074 prepend_elem(OP_LIST, pack, list(version)),
3075 newSVOP(OP_METHOD_NAMED, 0,
3076 newSVpvn("VERSION", 7))));
3080 /* Fake up an import/unimport */
3081 if (arg && arg->op_type == OP_STUB)
3082 imop = arg; /* no import on explicit () */
3083 else if(SvNIOK(((SVOP*)id)->op_sv)) {
3084 imop = Nullop; /* use 5.0; */
3087 /* Make copy of id so we don't free it twice */
3088 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
3089 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
3090 append_elem(OP_LIST,
3091 prepend_elem(OP_LIST, pack, list(arg)),
3092 newSVOP(OP_METHOD_NAMED, 0,
3093 aver ? newSVpvn("import", 6)
3094 : newSVpvn("unimport", 8))));
3097 /* Fake up a require, handle override, if any */
3098 gv = gv_fetchpv("require", FALSE, SVt_PVCV);
3099 if (!(gv && GvIMPORTED_CV(gv)))
3100 gv = gv_fetchpv("CORE::GLOBAL::require", FALSE, SVt_PVCV);
3102 if (gv && GvIMPORTED_CV(gv)) {
3103 rqop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
3104 append_elem(OP_LIST, id,
3105 scalar(newUNOP(OP_RV2CV, 0,
3110 rqop = newUNOP(OP_REQUIRE, 0, id);
3113 /* Fake up the BEGIN {}, which does its thing immediately. */
3115 newSVOP(OP_CONST, 0, newSVpvn("BEGIN", 5)),
3118 append_elem(OP_LINESEQ,
3119 append_elem(OP_LINESEQ,
3120 newSTATEOP(0, Nullch, rqop),
3121 newSTATEOP(0, Nullch, veop)),
3122 newSTATEOP(0, Nullch, imop) ));
3124 PL_hints |= HINT_BLOCK_SCOPE;
3125 PL_copline = NOLINE;
3130 Perl_dofile(pTHX_ OP *term)
3135 gv = gv_fetchpv("do", FALSE, SVt_PVCV);
3136 if (!(gv && GvIMPORTED_CV(gv)))
3137 gv = gv_fetchpv("CORE::GLOBAL::do", FALSE, SVt_PVCV);
3139 if (gv && GvIMPORTED_CV(gv)) {
3140 doop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
3141 append_elem(OP_LIST, term,
3142 scalar(newUNOP(OP_RV2CV, 0,
3147 doop = newUNOP(OP_DOFILE, 0, scalar(term));
3153 Perl_newSLICEOP(pTHX_ I32 flags, OP *subscript, OP *listval)
3155 return newBINOP(OP_LSLICE, flags,
3156 list(force_list(subscript)),
3157 list(force_list(listval)) );
3161 S_list_assignment(pTHX_ register OP *o)
3166 if (o->op_type == OP_NULL && o->op_flags & OPf_KIDS)
3167 o = cUNOPo->op_first;
3169 if (o->op_type == OP_COND_EXPR) {
3170 I32 t = list_assignment(cLOGOPo->op_first->op_sibling);
3171 I32 f = list_assignment(cLOGOPo->op_first->op_sibling->op_sibling);
3176 yyerror("Assignment to both a list and a scalar");
3180 if (o->op_type == OP_LIST || o->op_flags & OPf_PARENS ||
3181 o->op_type == OP_RV2AV || o->op_type == OP_RV2HV ||
3182 o->op_type == OP_ASLICE || o->op_type == OP_HSLICE)
3185 if (o->op_type == OP_PADAV || o->op_type == OP_PADHV)
3188 if (o->op_type == OP_RV2SV)
3195 Perl_newASSIGNOP(pTHX_ I32 flags, OP *left, I32 optype, OP *right)
3200 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN) {
3201 return newLOGOP(optype, 0,
3202 mod(scalar(left), optype),
3203 newUNOP(OP_SASSIGN, 0, scalar(right)));
3206 return newBINOP(optype, OPf_STACKED,
3207 mod(scalar(left), optype), scalar(right));
3211 if (list_assignment(left)) {
3214 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
3215 left = mod(left, OP_AASSIGN);
3223 o = newBINOP(OP_AASSIGN, flags,
3224 list(force_list(right)),
3225 list(force_list(left)) );
3226 o->op_private = 0 | (flags >> 8);
3227 if (!(left->op_private & OPpLVAL_INTRO)) {
3231 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
3232 if (PL_opargs[curop->op_type] & OA_DANGEROUS) {
3233 if (curop->op_type == OP_GV) {
3234 GV *gv = cGVOPx_gv(curop);
3235 if (gv == PL_defgv || SvCUR(gv) == PL_generation)
3237 SvCUR(gv) = PL_generation;
3239 else if (curop->op_type == OP_PADSV ||
3240 curop->op_type == OP_PADAV ||
3241 curop->op_type == OP_PADHV ||
3242 curop->op_type == OP_PADANY) {
3243 SV **svp = AvARRAY(PL_comppad_name);
3244 SV *sv = svp[curop->op_targ];
3245 if (SvCUR(sv) == PL_generation)
3247 SvCUR(sv) = PL_generation; /* (SvCUR not used any more) */
3249 else if (curop->op_type == OP_RV2CV)
3251 else if (curop->op_type == OP_RV2SV ||
3252 curop->op_type == OP_RV2AV ||
3253 curop->op_type == OP_RV2HV ||
3254 curop->op_type == OP_RV2GV) {
3255 if (lastop->op_type != OP_GV) /* funny deref? */
3258 else if (curop->op_type == OP_PUSHRE) {
3259 if (((PMOP*)curop)->op_pmreplroot) {
3260 GV *gv = (GV*)((PMOP*)curop)->op_pmreplroot;
3261 if (gv == PL_defgv || SvCUR(gv) == PL_generation)
3263 SvCUR(gv) = PL_generation;
3272 o->op_private = OPpASSIGN_COMMON;
3274 if (right && right->op_type == OP_SPLIT) {
3276 if ((tmpop = ((LISTOP*)right)->op_first) &&
3277 tmpop->op_type == OP_PUSHRE)
3279 PMOP *pm = (PMOP*)tmpop;
3280 if (left->op_type == OP_RV2AV &&
3281 !(left->op_private & OPpLVAL_INTRO) &&
3282 !(o->op_private & OPpASSIGN_COMMON) )
3284 tmpop = ((UNOP*)left)->op_first;
3285 if (tmpop->op_type == OP_GV && !pm->op_pmreplroot) {
3287 pm->op_pmreplroot = (OP*)cPADOPx(tmpop)->op_padix;
3288 cPADOPx(tmpop)->op_padix = 0; /* steal it */
3290 pm->op_pmreplroot = (OP*)cSVOPx(tmpop)->op_sv;
3291 cSVOPx(tmpop)->op_sv = Nullsv; /* steal it */
3293 pm->op_pmflags |= PMf_ONCE;
3294 tmpop = cUNOPo->op_first; /* to list (nulled) */
3295 tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */
3296 tmpop->op_sibling = Nullop; /* don't free split */
3297 right->op_next = tmpop->op_next; /* fix starting loc */
3298 op_free(o); /* blow off assign */
3299 right->op_flags &= ~OPf_WANT;
3300 /* "I don't know and I don't care." */
3305 if (PL_modcount < 10000 &&
3306 ((LISTOP*)right)->op_last->op_type == OP_CONST)
3308 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
3310 sv_setiv(sv, PL_modcount+1);
3318 right = newOP(OP_UNDEF, 0);
3319 if (right->op_type == OP_READLINE) {
3320 right->op_flags |= OPf_STACKED;
3321 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
3324 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
3325 o = newBINOP(OP_SASSIGN, flags,
3326 scalar(right), mod(scalar(left), OP_SASSIGN) );
3338 Perl_newSTATEOP(pTHX_ I32 flags, char *label, OP *o)
3341 U32 seq = intro_my();
3344 NewOp(1101, cop, 1, COP);
3345 if (PERLDB_LINE && CopLINE(PL_curcop) && PL_curstash != PL_debstash) {
3346 cop->op_type = OP_DBSTATE;
3347 cop->op_ppaddr = PL_ppaddr[ OP_DBSTATE ];
3350 cop->op_type = OP_NEXTSTATE;
3351 cop->op_ppaddr = PL_ppaddr[ OP_NEXTSTATE ];
3353 cop->op_flags = flags;
3354 cop->op_private = (PL_hints & HINT_UTF8);
3356 cop->op_private |= NATIVE_HINTS;
3358 PL_compiling.op_private = cop->op_private;
3359 cop->op_next = (OP*)cop;
3362 cop->cop_label = label;
3363 PL_hints |= HINT_BLOCK_SCOPE;
3366 cop->cop_arybase = PL_curcop->cop_arybase;
3367 if (specialWARN(PL_curcop->cop_warnings))
3368 cop->cop_warnings = PL_curcop->cop_warnings ;
3370 cop->cop_warnings = newSVsv(PL_curcop->cop_warnings) ;
3373 if (PL_copline == NOLINE)
3374 CopLINE_set(cop, CopLINE(PL_curcop));
3376 CopLINE_set(cop, PL_copline);
3377 PL_copline = NOLINE;
3380 CopFILE_set(cop, CopFILE(PL_curcop)); /* XXXXX share in a pvtable? */
3382 CopFILEGV_set(cop, (GV*)SvREFCNT_inc(CopFILEGV(PL_curcop)));
3384 CopSTASH_set(cop, PL_curstash);
3386 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3387 SV **svp = av_fetch(CopFILEAV(PL_curcop), (I32)CopLINE(cop), FALSE);
3388 if (svp && *svp != &PL_sv_undef && !SvIOK(*svp)) {
3389 (void)SvIOK_on(*svp);
3390 SvIVX(*svp) = PTR2IV(cop);
3394 return prepend_elem(OP_LINESEQ, (OP*)cop, o);
3397 /* "Introduce" my variables to visible status. */
3405 if (! PL_min_intro_pending)
3406 return PL_cop_seqmax;
3408 svp = AvARRAY(PL_comppad_name);
3409 for (i = PL_min_intro_pending; i <= PL_max_intro_pending; i++) {
3410 if ((sv = svp[i]) && sv != &PL_sv_undef && !SvIVX(sv)) {
3411 SvIVX(sv) = PAD_MAX; /* Don't know scope end yet. */
3412 SvNVX(sv) = (NV)PL_cop_seqmax;
3415 PL_min_intro_pending = 0;
3416 PL_comppad_name_fill = PL_max_intro_pending; /* Needn't search higher */
3417 return PL_cop_seqmax++;
3421 Perl_newLOGOP(pTHX_ I32 type, I32 flags, OP *first, OP *other)
3423 return new_logop(type, flags, &first, &other);
3427 S_new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp)
3432 OP *first = *firstp;
3433 OP *other = *otherp;
3435 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
3436 return newBINOP(type, flags, scalar(first), scalar(other));
3438 scalarboolean(first);
3439 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
3440 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
3441 if (type == OP_AND || type == OP_OR) {
3447 first = *firstp = cUNOPo->op_first;
3449 first->op_next = o->op_next;
3450 cUNOPo->op_first = Nullop;
3454 if (first->op_type == OP_CONST) {
3455 if (ckWARN(WARN_PRECEDENCE) && (first->op_private & OPpCONST_BARE))
3456 Perl_warner(aTHX_ WARN_PRECEDENCE, "Probable precedence problem on %s",
3458 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
3469 else if (first->op_type == OP_WANTARRAY) {
3475 else if (ckWARN(WARN_UNSAFE) && (first->op_flags & OPf_KIDS)) {
3476 OP *k1 = ((UNOP*)first)->op_first;
3477 OP *k2 = k1->op_sibling;
3479 switch (first->op_type)
3482 if (k2 && k2->op_type == OP_READLINE
3483 && (k2->op_flags & OPf_STACKED)
3484 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3486 warnop = k2->op_type;
3491 if (k1->op_type == OP_READDIR
3492 || k1->op_type == OP_GLOB
3493 || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
3494 || k1->op_type == OP_EACH)
3496 warnop = ((k1->op_type == OP_NULL)
3497 ? k1->op_targ : k1->op_type);
3502 line_t oldline = CopLINE(PL_curcop);
3503 CopLINE_set(PL_curcop, PL_copline);
3504 Perl_warner(aTHX_ WARN_UNSAFE,
3505 "Value of %s%s can be \"0\"; test with defined()",
3507 ((warnop == OP_READLINE || warnop == OP_GLOB)
3508 ? " construct" : "() operator"));
3509 CopLINE_set(PL_curcop, oldline);
3516 if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
3517 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
3519 NewOp(1101, logop, 1, LOGOP);
3521 logop->op_type = type;
3522 logop->op_ppaddr = PL_ppaddr[type];
3523 logop->op_first = first;
3524 logop->op_flags = flags | OPf_KIDS;
3525 logop->op_other = LINKLIST(other);
3526 logop->op_private = 1 | (flags >> 8);
3528 /* establish postfix order */
3529 logop->op_next = LINKLIST(first);
3530 first->op_next = (OP*)logop;
3531 first->op_sibling = other;
3533 o = newUNOP(OP_NULL, 0, (OP*)logop);
3540 Perl_newCONDOP(pTHX_ I32 flags, OP *first, OP *trueop, OP *falseop)
3548 return newLOGOP(OP_AND, 0, first, trueop);
3550 return newLOGOP(OP_OR, 0, first, falseop);
3552 scalarboolean(first);
3553 if (first->op_type == OP_CONST) {
3554 if (SvTRUE(((SVOP*)first)->op_sv)) {
3565 else if (first->op_type == OP_WANTARRAY) {
3569 NewOp(1101, logop, 1, LOGOP);
3570 logop->op_type = OP_COND_EXPR;
3571 logop->op_ppaddr = PL_ppaddr[OP_COND_EXPR];
3572 logop->op_first = first;
3573 logop->op_flags = flags | OPf_KIDS;
3574 logop->op_private = 1 | (flags >> 8);
3575 logop->op_other = LINKLIST(trueop);
3576 logop->op_next = LINKLIST(falseop);
3579 /* establish postfix order */
3580 start = LINKLIST(first);
3581 first->op_next = (OP*)logop;
3583 first->op_sibling = trueop;
3584 trueop->op_sibling = falseop;
3585 o = newUNOP(OP_NULL, 0, (OP*)logop);
3587 trueop->op_next = falseop->op_next = o;
3594 Perl_newRANGE(pTHX_ I32 flags, OP *left, OP *right)
3603 NewOp(1101, range, 1, LOGOP);
3605 range->op_type = OP_RANGE;
3606 range->op_ppaddr = PL_ppaddr[OP_RANGE];
3607 range->op_first = left;
3608 range->op_flags = OPf_KIDS;
3609 leftstart = LINKLIST(left);
3610 range->op_other = LINKLIST(right);
3611 range->op_private = 1 | (flags >> 8);
3613 left->op_sibling = right;
3615 range->op_next = (OP*)range;
3616 flip = newUNOP(OP_FLIP, flags, (OP*)range);
3617 flop = newUNOP(OP_FLOP, 0, flip);
3618 o = newUNOP(OP_NULL, 0, flop);
3620 range->op_next = leftstart;
3622 left->op_next = flip;
3623 right->op_next = flop;
3625 range->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
3626 sv_upgrade(PAD_SV(range->op_targ), SVt_PVNV);
3627 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
3628 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
3630 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
3631 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
3634 if (!flip->op_private || !flop->op_private)
3635 linklist(o); /* blow off optimizer unless constant */
3641 Perl_newLOOPOP(pTHX_ I32 flags, I32 debuggable, OP *expr, OP *block)
3646 int once = block && block->op_flags & OPf_SPECIAL &&
3647 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
3650 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
3651 return block; /* do {} while 0 does once */
3652 if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
3653 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB)) {
3654 expr = newUNOP(OP_DEFINED, 0,
3655 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
3656 } else if (expr->op_flags & OPf_KIDS) {
3657 OP *k1 = ((UNOP*)expr)->op_first;
3658 OP *k2 = (k1) ? k1->op_sibling : NULL;
3659 switch (expr->op_type) {
3661 if (k2 && k2->op_type == OP_READLINE
3662 && (k2->op_flags & OPf_STACKED)
3663 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3664 expr = newUNOP(OP_DEFINED, 0, expr);
3668 if (k1->op_type == OP_READDIR
3669 || k1->op_type == OP_GLOB
3670 || (k1->op_type == OP_NULL && k1->op_targ == OP_NULL)
3671 || k1->op_type == OP_EACH)
3672 expr = newUNOP(OP_DEFINED, 0, expr);
3678 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
3679 o = new_logop(OP_AND, 0, &expr, &listop);
3682 ((LISTOP*)listop)->op_last->op_next = LINKLIST(o);
3684 if (once && o != listop)
3685 o->op_next = ((LOGOP*)cUNOPo->op_first)->op_other;
3688 o = newUNOP(OP_NULL, 0, o); /* or do {} while 1 loses outer block */
3690 o->op_flags |= flags;
3692 o->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/
3697 Perl_newWHILEOP(pTHX_ I32 flags, I32 debuggable, LOOP *loop, I32 whileline, OP *expr, OP *block, OP *cont)
3706 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
3707 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB))) {
3708 expr = newUNOP(OP_DEFINED, 0,
3709 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
3710 } else if (expr && (expr->op_flags & OPf_KIDS)) {
3711 OP *k1 = ((UNOP*)expr)->op_first;
3712 OP *k2 = (k1) ? k1->op_sibling : NULL;
3713 switch (expr->op_type) {
3715 if (k2 && k2->op_type == OP_READLINE
3716 && (k2->op_flags & OPf_STACKED)
3717 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3718 expr = newUNOP(OP_DEFINED, 0, expr);
3722 if (k1->op_type == OP_READDIR
3723 || k1->op_type == OP_GLOB
3724 || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
3725 || k1->op_type == OP_EACH)
3726 expr = newUNOP(OP_DEFINED, 0, expr);
3732 block = newOP(OP_NULL, 0);
3735 next = LINKLIST(cont);
3737 cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
3738 if ((line_t)whileline != NOLINE) {
3739 PL_copline = whileline;
3740 cont = append_elem(OP_LINESEQ, cont,
3741 newSTATEOP(0, Nullch, Nullop));
3745 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
3746 redo = LINKLIST(listop);
3749 PL_copline = whileline;
3751 o = new_logop(OP_AND, 0, &expr, &listop);
3752 if (o == expr && o->op_type == OP_CONST && !SvTRUE(cSVOPo->op_sv)) {
3753 op_free(expr); /* oops, it's a while (0) */
3755 return Nullop; /* listop already freed by new_logop */
3758 ((LISTOP*)listop)->op_last->op_next = condop =
3759 (o == listop ? redo : LINKLIST(o));
3767 NewOp(1101,loop,1,LOOP);
3768 loop->op_type = OP_ENTERLOOP;
3769 loop->op_ppaddr = PL_ppaddr[OP_ENTERLOOP];
3770 loop->op_private = 0;
3771 loop->op_next = (OP*)loop;
3774 o = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, o);
3776 loop->op_redoop = redo;
3777 loop->op_lastop = o;
3780 loop->op_nextop = next;
3782 loop->op_nextop = o;
3784 o->op_flags |= flags;
3785 o->op_private |= (flags >> 8);
3790 Perl_newFOROP(pTHX_ I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
3799 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
3800 sv->op_type = OP_RV2GV;
3801 sv->op_ppaddr = PL_ppaddr[OP_RV2GV];
3803 else if (sv->op_type == OP_PADSV) { /* private variable */
3804 padoff = sv->op_targ;
3809 else if (sv->op_type == OP_THREADSV) { /* per-thread variable */
3810 padoff = sv->op_targ;
3812 iterflags |= OPf_SPECIAL;
3817 Perl_croak(aTHX_ "Can't use %s for loop variable", PL_op_desc[sv->op_type]);
3821 padoff = find_threadsv("_");
3822 iterflags |= OPf_SPECIAL;
3824 sv = newGVOP(OP_GV, 0, PL_defgv);
3827 if (expr->op_type == OP_RV2AV || expr->op_type == OP_PADAV) {
3828 expr = mod(force_list(scalar(ref(expr, OP_ITER))), OP_GREPSTART);
3829 iterflags |= OPf_STACKED;
3831 else if (expr->op_type == OP_NULL &&
3832 (expr->op_flags & OPf_KIDS) &&
3833 ((BINOP*)expr)->op_first->op_type == OP_FLOP)
3835 /* Basically turn for($x..$y) into the same as for($x,$y), but we
3836 * set the STACKED flag to indicate that these values are to be
3837 * treated as min/max values by 'pp_iterinit'.
3839 UNOP* flip = (UNOP*)((UNOP*)((BINOP*)expr)->op_first)->op_first;
3840 LOGOP* range = (LOGOP*) flip->op_first;
3841 OP* left = range->op_first;
3842 OP* right = left->op_sibling;
3845 range->op_flags &= ~OPf_KIDS;
3846 range->op_first = Nullop;
3848 listop = (LISTOP*)newLISTOP(OP_LIST, 0, left, right);
3849 listop->op_first->op_next = range->op_next;
3850 left->op_next = range->op_other;
3851 right->op_next = (OP*)listop;
3852 listop->op_next = listop->op_first;
3855 expr = (OP*)(listop);
3857 iterflags |= OPf_STACKED;
3860 expr = mod(force_list(expr), OP_GREPSTART);
3864 loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
3865 append_elem(OP_LIST, expr, scalar(sv))));
3866 assert(!loop->op_next);
3867 #ifdef PL_OP_SLAB_ALLOC
3868 NewOp(1234,tmp,1,LOOP);
3869 Copy(loop,tmp,1,LOOP);
3872 Renew(loop, 1, LOOP);
3874 loop->op_targ = padoff;
3875 wop = newWHILEOP(flags, 1, loop, forline, newOP(OP_ITER, 0), block, cont);
3876 PL_copline = forline;
3877 return newSTATEOP(0, label, wop);
3881 Perl_newLOOPEX(pTHX_ I32 type, OP *label)
3887 if (type != OP_GOTO || label->op_type == OP_CONST) {
3888 /* "last()" means "last" */
3889 if (label->op_type == OP_STUB && (label->op_flags & OPf_PARENS))
3890 o = newOP(type, OPf_SPECIAL);
3892 o = newPVOP(type, 0, savepv(label->op_type == OP_CONST
3893 ? SvPVx(((SVOP*)label)->op_sv, n_a)
3899 if (label->op_type == OP_ENTERSUB)
3900 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
3901 o = newUNOP(type, OPf_STACKED, label);
3903 PL_hints |= HINT_BLOCK_SCOPE;
3908 Perl_cv_undef(pTHX_ CV *cv)
3913 MUTEX_DESTROY(CvMUTEXP(cv));
3914 Safefree(CvMUTEXP(cv));
3917 #endif /* USE_THREADS */
3919 if (!CvXSUB(cv) && CvROOT(cv)) {
3921 if (CvDEPTH(cv) || (CvOWNER(cv) && CvOWNER(cv) != thr))
3922 Perl_croak(aTHX_ "Can't undef active subroutine");
3925 Perl_croak(aTHX_ "Can't undef active subroutine");
3926 #endif /* USE_THREADS */
3929 SAVEVPTR(PL_curpad);
3933 op_free(CvROOT(cv));
3934 CvROOT(cv) = Nullop;
3937 SvPOK_off((SV*)cv); /* forget prototype */
3939 SvREFCNT_dec(CvGV(cv));
3941 SvREFCNT_dec(CvOUTSIDE(cv));
3942 CvOUTSIDE(cv) = Nullcv;
3943 if (CvPADLIST(cv)) {
3944 /* may be during global destruction */
3945 if (SvREFCNT(CvPADLIST(cv))) {
3946 I32 i = AvFILLp(CvPADLIST(cv));
3948 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
3949 SV* sv = svp ? *svp : Nullsv;
3952 if (sv == (SV*)PL_comppad_name)
3953 PL_comppad_name = Nullav;
3954 else if (sv == (SV*)PL_comppad) {
3955 PL_comppad = Nullav;
3956 PL_curpad = Null(SV**);
3960 SvREFCNT_dec((SV*)CvPADLIST(cv));
3962 CvPADLIST(cv) = Nullav;
3967 S_cv_dump(pTHX_ CV *cv)
3970 CV *outside = CvOUTSIDE(cv);
3971 AV* padlist = CvPADLIST(cv);
3978 PerlIO_printf(Perl_debug_log,
3979 "\tCV=0x%"UVxf" (%s), OUTSIDE=0x%"UVxf" (%s)\n",
3981 (CvANON(cv) ? "ANON"
3982 : (cv == PL_main_cv) ? "MAIN"
3983 : CvUNIQUE(cv) ? "UNIQUE"
3984 : CvGV(cv) ? GvNAME(CvGV(cv)) : "UNDEFINED"),
3987 : CvANON(outside) ? "ANON"
3988 : (outside == PL_main_cv) ? "MAIN"
3989 : CvUNIQUE(outside) ? "UNIQUE"
3990 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
3995 pad_name = (AV*)*av_fetch(padlist, 0, FALSE);
3996 pad = (AV*)*av_fetch(padlist, 1, FALSE);
3997 pname = AvARRAY(pad_name);
3998 ppad = AvARRAY(pad);
4000 for (ix = 1; ix <= AvFILLp(pad_name); ix++) {
4001 if (SvPOK(pname[ix]))
4002 PerlIO_printf(Perl_debug_log,
4003 "\t%4d. 0x%"UVxf" (%s\"%s\" %"IVdf"-%"IVdf")\n",
4004 ix, PTR2UV(ppad[ix]),
4005 SvFAKE(pname[ix]) ? "FAKE " : "",
4007 (IV)I_32(SvNVX(pname[ix])),
4010 #endif /* DEBUGGING */
4014 S_cv_clone2(pTHX_ CV *proto, CV *outside)
4019 AV* protopadlist = CvPADLIST(proto);
4020 AV* protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
4021 AV* protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
4022 SV** pname = AvARRAY(protopad_name);
4023 SV** ppad = AvARRAY(protopad);
4024 I32 fname = AvFILLp(protopad_name);
4025 I32 fpad = AvFILLp(protopad);
4029 assert(!CvUNIQUE(proto));
4032 SAVEVPTR(PL_curpad);
4033 SAVESPTR(PL_comppad);
4034 SAVESPTR(PL_comppad_name);
4035 SAVESPTR(PL_compcv);
4037 cv = PL_compcv = (CV*)NEWSV(1104,0);
4038 sv_upgrade((SV *)cv, SvTYPE(proto));
4044 New(666, CvMUTEXP(cv), 1, perl_mutex);
4045 MUTEX_INIT(CvMUTEXP(cv));
4047 #endif /* USE_THREADS */
4048 CvFILE(cv) = CvFILE(proto);
4049 CvGV(cv) = (GV*)SvREFCNT_inc(CvGV(proto));
4050 CvSTASH(cv) = CvSTASH(proto);
4051 CvROOT(cv) = CvROOT(proto);
4052 CvSTART(cv) = CvSTART(proto);
4054 CvOUTSIDE(cv) = (CV*)SvREFCNT_inc(outside);
4057 sv_setpvn((SV*)cv, SvPVX(proto), SvCUR(proto));
4059 PL_comppad_name = newAV();
4060 for (ix = fname; ix >= 0; ix--)
4061 av_store(PL_comppad_name, ix, SvREFCNT_inc(pname[ix]));
4063 PL_comppad = newAV();
4065 comppadlist = newAV();
4066 AvREAL_off(comppadlist);
4067 av_store(comppadlist, 0, (SV*)PL_comppad_name);
4068 av_store(comppadlist, 1, (SV*)PL_comppad);
4069 CvPADLIST(cv) = comppadlist;
4070 av_fill(PL_comppad, AvFILLp(protopad));
4071 PL_curpad = AvARRAY(PL_comppad);
4073 av = newAV(); /* will be @_ */
4075 av_store(PL_comppad, 0, (SV*)av);
4076 AvFLAGS(av) = AVf_REIFY;
4078 for (ix = fpad; ix > 0; ix--) {
4079 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
4080 if (namesv && namesv != &PL_sv_undef) {
4081 char *name = SvPVX(namesv); /* XXX */
4082 if (SvFLAGS(namesv) & SVf_FAKE) { /* lexical from outside? */
4083 I32 off = pad_findlex(name, ix, SvIVX(namesv),
4084 CvOUTSIDE(cv), cxstack_ix, 0, 0);
4086 PL_curpad[ix] = SvREFCNT_inc(ppad[ix]);
4088 Perl_croak(aTHX_ "panic: cv_clone: %s", name);
4090 else { /* our own lexical */
4093 /* anon code -- we'll come back for it */
4094 sv = SvREFCNT_inc(ppad[ix]);
4096 else if (*name == '@')
4098 else if (*name == '%')
4107 else if (IS_PADGV(ppad[ix]) || IS_PADCONST(ppad[ix])) {
4108 PL_curpad[ix] = SvREFCNT_inc(ppad[ix]);
4111 SV* sv = NEWSV(0,0);
4117 /* Now that vars are all in place, clone nested closures. */
4119 for (ix = fpad; ix > 0; ix--) {
4120 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
4122 && namesv != &PL_sv_undef
4123 && !(SvFLAGS(namesv) & SVf_FAKE)
4124 && *SvPVX(namesv) == '&'
4125 && CvCLONE(ppad[ix]))
4127 CV *kid = cv_clone2((CV*)ppad[ix], cv);
4128 SvREFCNT_dec(ppad[ix]);
4131 PL_curpad[ix] = (SV*)kid;
4135 #ifdef DEBUG_CLOSURES
4136 PerlIO_printf(Perl_debug_log, "Cloned inside:\n");
4138 PerlIO_printf(Perl_debug_log, " from:\n");
4140 PerlIO_printf(Perl_debug_log, " to:\n");
4149 Perl_cv_clone(pTHX_ CV *proto)
4152 LOCK_CRED_MUTEX; /* XXX create separate mutex */
4153 cv = cv_clone2(proto, CvOUTSIDE(proto));
4154 UNLOCK_CRED_MUTEX; /* XXX create separate mutex */
4159 Perl_cv_ckproto(pTHX_ CV *cv, GV *gv, char *p)
4163 if (((!p != !SvPOK(cv)) || (p && strNE(p, SvPVX(cv)))) && ckWARN_d(WARN_UNSAFE)) {
4164 SV* msg = sv_newmortal();
4168 gv_efullname3(name = sv_newmortal(), gv, Nullch);
4169 sv_setpv(msg, "Prototype mismatch:");
4171 Perl_sv_catpvf(aTHX_ msg, " sub %_", name);
4173 Perl_sv_catpvf(aTHX_ msg, " (%s)", SvPVX(cv));
4174 sv_catpv(msg, " vs ");
4176 Perl_sv_catpvf(aTHX_ msg, "(%s)", p);
4178 sv_catpv(msg, "none");
4179 Perl_warner(aTHX_ WARN_UNSAFE, "%_", msg);
4184 Perl_cv_const_sv(pTHX_ CV *cv)
4186 if (!cv || !SvPOK(cv) || SvCUR(cv))
4188 return op_const_sv(CvSTART(cv), cv);
4192 Perl_op_const_sv(pTHX_ OP *o, CV *cv)
4199 if(o->op_type == OP_LINESEQ && cLISTOPo->op_first)
4200 o = cLISTOPo->op_first->op_sibling;
4202 for (; o; o = o->op_next) {
4203 OPCODE type = o->op_type;
4205 if (sv && o->op_next == o)
4207 if (type == OP_NEXTSTATE || type == OP_NULL || type == OP_PUSHMARK)
4209 if (type == OP_LEAVESUB || type == OP_RETURN)
4213 if (type == OP_CONST && cSVOPo->op_sv)
4215 else if ((type == OP_PADSV || type == OP_CONST) && cv) {
4216 AV* padav = (AV*)(AvARRAY(CvPADLIST(cv))[1]);
4217 sv = padav ? AvARRAY(padav)[o->op_targ] : Nullsv;
4218 if (!sv || (!SvREADONLY(sv) && SvREFCNT(sv) > 1))
4230 Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
4240 Perl_croak(aTHX_ "\"my sub\" not yet implemented");
4244 Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block)
4246 return Perl_newATTRSUB(aTHX_ floor, o, proto, Nullop, block);
4250 Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
4254 char *name = o ? SvPVx(cSVOPo->op_sv, n_a) : Nullch;
4255 GV *gv = gv_fetchpv(name ? name : "__ANON__",
4256 GV_ADDMULTI | ((block || attrs) ? 0 : GV_NOINIT),
4258 char *ps = proto ? SvPVx(((SVOP*)proto)->op_sv, n_a) : Nullch;
4269 if (SvTYPE(gv) != SVt_PVGV) { /* Maybe prototype now, and had at
4270 maximum a prototype before. */
4271 if (SvTYPE(gv) > SVt_NULL) {
4272 if (!SvPOK((SV*)gv) && !(SvIOK((SV*)gv) && SvIVX((SV*)gv) == -1)
4273 && ckWARN_d(WARN_UNSAFE))
4275 Perl_warner(aTHX_ WARN_UNSAFE, "Runaway prototype");
4277 cv_ckproto((CV*)gv, NULL, ps);
4280 sv_setpv((SV*)gv, ps);
4282 sv_setiv((SV*)gv, -1);
4283 SvREFCNT_dec(PL_compcv);
4284 cv = PL_compcv = NULL;
4285 PL_sub_generation++;
4289 if (!name || GvCVGEN(gv))
4291 else if (cv = GvCV(gv)) {
4292 cv_ckproto(cv, gv, ps);
4293 /* already defined (or promised)? */
4294 if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
4296 bool const_changed = TRUE;
4297 if (!block && !attrs) {
4298 /* just a "sub foo;" when &foo is already defined */
4299 SAVEFREESV(PL_compcv);
4302 /* ahem, death to those who redefine active sort subs */
4303 if (PL_curstackinfo->si_type == PERLSI_SORT && PL_sortcop == CvSTART(cv))
4304 Perl_croak(aTHX_ "Can't redefine active sort subroutine %s", name);
4307 if(const_sv = cv_const_sv(cv))
4308 const_changed = sv_cmp(const_sv, op_const_sv(block, Nullcv));
4309 if ((const_sv && const_changed) || ckWARN(WARN_REDEFINE)
4310 && !(CvGV(cv) && GvSTASH(CvGV(cv))
4311 && HvNAME(GvSTASH(CvGV(cv)))
4312 && strEQ(HvNAME(GvSTASH(CvGV(cv))),
4314 line_t oldline = CopLINE(PL_curcop);
4315 CopLINE_set(PL_curcop, PL_copline);
4316 Perl_warner(aTHX_ WARN_REDEFINE,
4317 const_sv ? "Constant subroutine %s redefined"
4318 : "Subroutine %s redefined", name);
4319 CopLINE_set(PL_curcop, oldline);
4330 /* Need to do a C<use attributes $stash_of_cv,\&cv,@attrs>
4331 * before we clobber PL_compcv.
4335 if (CvGV(cv) && GvSTASH(CvGV(cv)) && HvNAME(GvSTASH(CvGV(cv))))
4336 stash = GvSTASH(CvGV(cv));
4337 else if (CvSTASH(cv) && HvNAME(CvSTASH(cv)))
4338 stash = CvSTASH(cv);
4340 stash = PL_curstash;
4343 /* possibly about to re-define existing subr -- ignore old cv */
4344 rcv = (SV*)PL_compcv;
4345 if (name && GvSTASH(gv) && HvNAME(GvSTASH(gv)))
4346 stash = GvSTASH(gv);
4348 stash = PL_curstash;
4350 apply_attrs(stash, rcv, attrs);
4352 if (cv) { /* must reuse cv if autoloaded */
4354 /* got here with just attrs -- work done, so bug out */
4355 SAVEFREESV(PL_compcv);
4359 CvFLAGS(cv) = CvFLAGS(PL_compcv);
4360 CvOUTSIDE(cv) = CvOUTSIDE(PL_compcv);
4361 CvOUTSIDE(PL_compcv) = 0;
4362 CvPADLIST(cv) = CvPADLIST(PL_compcv);
4363 CvPADLIST(PL_compcv) = 0;
4364 if (SvREFCNT(PL_compcv) > 1) /* XXX Make closures transit through stub. */
4365 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc((SV*)cv);
4366 SvREFCNT_dec(PL_compcv);
4373 PL_sub_generation++;
4376 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4377 CvFILE(cv) = CopFILE(PL_curcop);
4378 CvSTASH(cv) = PL_curstash;
4381 if (!CvMUTEXP(cv)) {
4382 New(666, CvMUTEXP(cv), 1, perl_mutex);
4383 MUTEX_INIT(CvMUTEXP(cv));
4385 #endif /* USE_THREADS */
4388 sv_setpv((SV*)cv, ps);
4390 if (PL_error_count) {
4394 char *s = strrchr(name, ':');
4396 if (strEQ(s, "BEGIN")) {
4398 "BEGIN not safe after errors--compilation aborted";
4399 if (PL_in_eval & EVAL_KEEPERR)
4400 Perl_croak(aTHX_ not_safe);
4402 /* force display of errors found but not reported */
4403 sv_catpv(ERRSV, not_safe);
4404 Perl_croak(aTHX_ "%s", SvPVx(ERRSV, n_a));
4411 PL_copline = NOLINE;
4416 if (AvFILLp(PL_comppad_name) < AvFILLp(PL_comppad))
4417 av_store(PL_comppad_name, AvFILLp(PL_comppad), Nullsv);
4420 CvROOT(cv) = newUNOP(OP_LEAVESUBLV, 0, scalarseq(block));
4423 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
4425 CvROOT(cv)->op_private |= OPpREFCOUNTED;
4426 OpREFCNT_set(CvROOT(cv), 1);
4427 CvSTART(cv) = LINKLIST(CvROOT(cv));
4428 CvROOT(cv)->op_next = 0;
4431 /* now that optimizer has done its work, adjust pad values */
4433 SV **namep = AvARRAY(PL_comppad_name);
4434 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4437 if (SvIMMORTAL(PL_curpad[ix]) || IS_PADGV(PL_curpad[ix]) || IS_PADCONST(PL_curpad[ix]))
4440 * The only things that a clonable function needs in its
4441 * pad are references to outer lexicals and anonymous subs.
4442 * The rest are created anew during cloning.
4444 if (!((namesv = namep[ix]) != Nullsv &&
4445 namesv != &PL_sv_undef &&
4447 *SvPVX(namesv) == '&')))
4449 SvREFCNT_dec(PL_curpad[ix]);
4450 PL_curpad[ix] = Nullsv;
4455 AV *av = newAV(); /* Will be @_ */
4457 av_store(PL_comppad, 0, (SV*)av);
4458 AvFLAGS(av) = AVf_REIFY;
4460 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4461 if (SvIMMORTAL(PL_curpad[ix]) || IS_PADGV(PL_curpad[ix]) || IS_PADCONST(PL_curpad[ix]))
4463 if (!SvPADMY(PL_curpad[ix]))
4464 SvPADTMP_on(PL_curpad[ix]);
4471 if (PERLDB_SUBLINE && PL_curstash != PL_debstash) {
4472 SV *sv = NEWSV(0,0);
4473 SV *tmpstr = sv_newmortal();
4474 GV *db_postponed = gv_fetchpv("DB::postponed", GV_ADDMULTI, SVt_PVHV);
4478 Perl_sv_setpvf(aTHX_ sv, "%s:%ld-%ld",
4480 (long)PL_subline, (long)CopLINE(PL_curcop));
4481 gv_efullname3(tmpstr, gv, Nullch);
4482 hv_store(GvHV(PL_DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
4483 hv = GvHVn(db_postponed);
4484 if (HvFILL(hv) > 0 && hv_exists(hv, SvPVX(tmpstr), SvCUR(tmpstr))
4485 && (cv = GvCV(db_postponed))) {
4490 call_sv((SV*)cv, G_DISCARD);
4494 if ((s = strrchr(name,':')))
4499 if (*s != 'B' && *s != 'E' && *s != 'S' && *s != 'I')
4502 if (strEQ(s, "BEGIN")) {
4503 I32 oldscope = PL_scopestack_ix;
4505 SAVECOPFILE(&PL_compiling);
4506 SAVECOPLINE(&PL_compiling);
4508 sv_setsv(PL_rs, PL_nrs);
4511 PL_beginav = newAV();
4512 DEBUG_x( dump_sub(gv) );
4513 av_push(PL_beginav, SvREFCNT_inc(cv));
4515 call_list(oldscope, PL_beginav);
4517 PL_curcop = &PL_compiling;
4518 PL_compiling.op_private = PL_hints;
4521 else if (strEQ(s, "END") && !PL_error_count) {
4524 DEBUG_x( dump_sub(gv) );
4525 av_unshift(PL_endav, 1);
4526 av_store(PL_endav, 0, SvREFCNT_inc(cv));
4529 else if (strEQ(s, "STOP") && !PL_error_count) {
4531 PL_stopav = newAV();
4532 DEBUG_x( dump_sub(gv) );
4533 av_unshift(PL_stopav, 1);
4534 av_store(PL_stopav, 0, SvREFCNT_inc(cv));
4537 else if (strEQ(s, "INIT") && !PL_error_count) {
4539 PL_initav = newAV();
4540 DEBUG_x( dump_sub(gv) );
4541 av_push(PL_initav, SvREFCNT_inc(cv));
4547 PL_copline = NOLINE;
4552 /* XXX unsafe for threads if eval_owner isn't held */
4554 Perl_newCONSTSUB(pTHX_ HV *stash, char *name, SV *sv)
4559 SAVECOPLINE(PL_curcop);
4562 CopLINE_set(PL_curcop, PL_copline);
4563 PL_hints &= ~HINT_BLOCK_SCOPE;
4566 SAVESPTR(PL_curstash);
4567 SAVECOPSTASH(PL_curcop);
4568 PL_curstash = stash;
4570 CopSTASHPV(PL_curcop) = stash ? HvNAME(stash) : Nullch;
4572 CopSTASH(PL_curcop) = stash;
4577 start_subparse(FALSE, 0),
4578 newSVOP(OP_CONST, 0, newSVpv(name,0)),
4579 newSVOP(OP_CONST, 0, &PL_sv_no), /* SvPV(&PL_sv_no) == "" -- GMB */
4581 newSTATEOP(0, Nullch, newSVOP(OP_CONST, 0, sv))
4588 Perl_newXS(pTHX_ char *name, XSUBADDR_t subaddr, char *filename)
4591 GV *gv = gv_fetchpv(name ? name : "__ANON__", GV_ADDMULTI, SVt_PVCV);
4594 if (cv = (name ? GvCV(gv) : Nullcv)) {
4596 /* just a cached method */
4600 else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
4601 /* already defined (or promised) */
4602 if (ckWARN(WARN_REDEFINE) && !(CvGV(cv) && GvSTASH(CvGV(cv))
4603 && HvNAME(GvSTASH(CvGV(cv)))
4604 && strEQ(HvNAME(GvSTASH(CvGV(cv))), "autouse"))) {
4605 line_t oldline = CopLINE(PL_curcop);
4606 if (PL_copline != NOLINE)
4607 CopLINE_set(PL_curcop, PL_copline);
4608 Perl_warner(aTHX_ WARN_REDEFINE, "Subroutine %s redefined",name);
4609 CopLINE_set(PL_curcop, oldline);
4616 if (cv) /* must reuse cv if autoloaded */
4619 cv = (CV*)NEWSV(1105,0);
4620 sv_upgrade((SV *)cv, SVt_PVCV);
4624 PL_sub_generation++;
4627 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4629 New(666, CvMUTEXP(cv), 1, perl_mutex);
4630 MUTEX_INIT(CvMUTEXP(cv));
4632 #endif /* USE_THREADS */
4633 (void)gv_fetchfile(filename);
4634 CvFILE(cv) = filename; /* NOTE: not copied, as it is expected to be
4635 an external constant string */
4636 CvXSUB(cv) = subaddr;
4639 char *s = strrchr(name,':');
4645 if (*s != 'B' && *s != 'E' && *s != 'S' && *s != 'I')
4648 if (strEQ(s, "BEGIN")) {
4650 PL_beginav = newAV();
4651 av_push(PL_beginav, SvREFCNT_inc(cv));
4654 else if (strEQ(s, "END")) {
4657 av_unshift(PL_endav, 1);
4658 av_store(PL_endav, 0, SvREFCNT_inc(cv));
4661 else if (strEQ(s, "STOP")) {
4663 PL_stopav = newAV();
4664 av_unshift(PL_stopav, 1);
4665 av_store(PL_stopav, 0, SvREFCNT_inc(cv));
4668 else if (strEQ(s, "INIT")) {
4670 PL_initav = newAV();
4671 av_push(PL_initav, SvREFCNT_inc(cv));
4683 Perl_newFORM(pTHX_ I32 floor, OP *o, OP *block)
4693 name = SvPVx(cSVOPo->op_sv, n_a);
4696 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
4698 if (cv = GvFORM(gv)) {
4699 if (ckWARN(WARN_REDEFINE)) {
4700 line_t oldline = CopLINE(PL_curcop);
4702 CopLINE_set(PL_curcop, PL_copline);
4703 Perl_warner(aTHX_ WARN_REDEFINE, "Format %s redefined",name);
4704 CopLINE_set(PL_curcop, oldline);
4710 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4711 CvFILE(cv) = CopFILE(PL_curcop);
4713 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4714 if (!SvPADMY(PL_curpad[ix]) && !SvIMMORTAL(PL_curpad[ix]))
4715 SvPADTMP_on(PL_curpad[ix]);
4718 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
4719 CvROOT(cv)->op_private |= OPpREFCOUNTED;
4720 OpREFCNT_set(CvROOT(cv), 1);
4721 CvSTART(cv) = LINKLIST(CvROOT(cv));
4722 CvROOT(cv)->op_next = 0;
4725 PL_copline = NOLINE;
4730 Perl_newANONLIST(pTHX_ OP *o)
4732 return newUNOP(OP_REFGEN, 0,
4733 mod(list(convert(OP_ANONLIST, 0, o)), OP_REFGEN));
4737 Perl_newANONHASH(pTHX_ OP *o)
4739 return newUNOP(OP_REFGEN, 0,
4740 mod(list(convert(OP_ANONHASH, 0, o)), OP_REFGEN));
4744 Perl_newANONSUB(pTHX_ I32 floor, OP *proto, OP *block)
4746 return newANONATTRSUB(floor, proto, Nullop, block);
4750 Perl_newANONATTRSUB(pTHX_ I32 floor, OP *proto, OP *attrs, OP *block)
4752 return newUNOP(OP_REFGEN, 0,
4753 newSVOP(OP_ANONCODE, 0,
4754 (SV*)newATTRSUB(floor, 0, proto, attrs, block)));
4758 Perl_oopsAV(pTHX_ OP *o)
4760 switch (o->op_type) {
4762 o->op_type = OP_PADAV;
4763 o->op_ppaddr = PL_ppaddr[OP_PADAV];
4764 return ref(o, OP_RV2AV);
4767 o->op_type = OP_RV2AV;
4768 o->op_ppaddr = PL_ppaddr[OP_RV2AV];
4773 if (ckWARN_d(WARN_INTERNAL))
4774 Perl_warner(aTHX_ WARN_INTERNAL, "oops: oopsAV");
4781 Perl_oopsHV(pTHX_ OP *o)
4785 switch (o->op_type) {
4788 o->op_type = OP_PADHV;
4789 o->op_ppaddr = PL_ppaddr[OP_PADHV];
4790 return ref(o, OP_RV2HV);
4794 o->op_type = OP_RV2HV;
4795 o->op_ppaddr = PL_ppaddr[OP_RV2HV];
4800 if (ckWARN_d(WARN_INTERNAL))
4801 Perl_warner(aTHX_ WARN_INTERNAL, "oops: oopsHV");
4808 Perl_newAVREF(pTHX_ OP *o)
4810 if (o->op_type == OP_PADANY) {
4811 o->op_type = OP_PADAV;
4812 o->op_ppaddr = PL_ppaddr[OP_PADAV];
4815 return newUNOP(OP_RV2AV, 0, scalar(o));
4819 Perl_newGVREF(pTHX_ I32 type, OP *o)
4821 if (type == OP_MAPSTART || type == OP_GREPSTART || type == OP_SORT)
4822 return newUNOP(OP_NULL, 0, o);
4823 return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
4827 Perl_newHVREF(pTHX_ OP *o)
4829 if (o->op_type == OP_PADANY) {
4830 o->op_type = OP_PADHV;
4831 o->op_ppaddr = PL_ppaddr[OP_PADHV];
4834 return newUNOP(OP_RV2HV, 0, scalar(o));
4838 Perl_oopsCV(pTHX_ OP *o)
4840 Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
4846 Perl_newCVREF(pTHX_ I32 flags, OP *o)
4848 return newUNOP(OP_RV2CV, flags, scalar(o));
4852 Perl_newSVREF(pTHX_ OP *o)
4854 if (o->op_type == OP_PADANY) {
4855 o->op_type = OP_PADSV;
4856 o->op_ppaddr = PL_ppaddr[OP_PADSV];
4859 else if (o->op_type == OP_THREADSV && !(o->op_flags & OPpDONE_SVREF)) {
4860 o->op_flags |= OPpDONE_SVREF;
4863 return newUNOP(OP_RV2SV, 0, scalar(o));
4866 /* Check routines. */
4869 Perl_ck_anoncode(pTHX_ OP *o)
4874 name = NEWSV(1106,0);
4875 sv_upgrade(name, SVt_PVNV);
4876 sv_setpvn(name, "&", 1);
4879 ix = pad_alloc(o->op_type, SVs_PADMY);
4880 av_store(PL_comppad_name, ix, name);
4881 av_store(PL_comppad, ix, cSVOPo->op_sv);
4882 SvPADMY_on(cSVOPo->op_sv);
4883 cSVOPo->op_sv = Nullsv;
4884 cSVOPo->op_targ = ix;
4889 Perl_ck_bitop(pTHX_ OP *o)
4891 o->op_private = PL_hints;
4896 Perl_ck_concat(pTHX_ OP *o)
4898 if (cUNOPo->op_first->op_type == OP_CONCAT)
4899 o->op_flags |= OPf_STACKED;
4904 Perl_ck_spair(pTHX_ OP *o)
4906 if (o->op_flags & OPf_KIDS) {
4909 OPCODE type = o->op_type;
4910 o = modkids(ck_fun(o), type);
4911 kid = cUNOPo->op_first;
4912 newop = kUNOP->op_first->op_sibling;
4914 (newop->op_sibling ||
4915 !(PL_opargs[newop->op_type] & OA_RETSCALAR) ||
4916 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
4917 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
4921 op_free(kUNOP->op_first);
4922 kUNOP->op_first = newop;
4924 o->op_ppaddr = PL_ppaddr[++o->op_type];
4929 Perl_ck_delete(pTHX_ OP *o)
4933 if (o->op_flags & OPf_KIDS) {
4934 OP *kid = cUNOPo->op_first;
4935 switch (kid->op_type) {
4937 o->op_flags |= OPf_SPECIAL;
4940 o->op_private |= OPpSLICE;
4943 o->op_flags |= OPf_SPECIAL;
4948 Perl_croak(aTHX_ "%s argument is not a HASH or ARRAY element or slice",
4949 PL_op_desc[o->op_type]);
4957 Perl_ck_eof(pTHX_ OP *o)
4959 I32 type = o->op_type;
4961 if (o->op_flags & OPf_KIDS) {
4962 if (cLISTOPo->op_first->op_type == OP_STUB) {
4964 o = newUNOP(type, OPf_SPECIAL,
4965 newGVOP(OP_GV, 0, gv_fetchpv("main::ARGV", TRUE, SVt_PVAV)));
4973 Perl_ck_eval(pTHX_ OP *o)
4975 PL_hints |= HINT_BLOCK_SCOPE;
4976 if (o->op_flags & OPf_KIDS) {
4977 SVOP *kid = (SVOP*)cUNOPo->op_first;
4980 o->op_flags &= ~OPf_KIDS;
4983 else if (kid->op_type == OP_LINESEQ) {
4986 kid->op_next = o->op_next;
4987 cUNOPo->op_first = 0;
4990 NewOp(1101, enter, 1, LOGOP);
4991 enter->op_type = OP_ENTERTRY;
4992 enter->op_ppaddr = PL_ppaddr[OP_ENTERTRY];
4993 enter->op_private = 0;
4995 /* establish postfix order */
4996 enter->op_next = (OP*)enter;
4998 o = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
4999 o->op_type = OP_LEAVETRY;
5000 o->op_ppaddr = PL_ppaddr[OP_LEAVETRY];
5001 enter->op_other = o;
5009 o = newUNOP(OP_ENTEREVAL, 0, newDEFSVOP());
5011 o->op_targ = (PADOFFSET)PL_hints;
5016 Perl_ck_exec(pTHX_ OP *o)
5019 if (o->op_flags & OPf_STACKED) {
5021 kid = cUNOPo->op_first->op_sibling;
5022 if (kid->op_type == OP_RV2GV)
5031 Perl_ck_exists(pTHX_ OP *o)
5034 if (o->op_flags & OPf_KIDS) {
5035 OP *kid = cUNOPo->op_first;
5036 if (kid->op_type == OP_ENTERSUB) {
5037 (void) ref(kid, o->op_type);
5038 if (kid->op_type != OP_RV2CV && !PL_error_count)
5039 Perl_croak(aTHX_ "%s argument is not a subroutine name",
5040 PL_op_desc[o->op_type]);
5041 o->op_private |= OPpEXISTS_SUB;
5043 else if (kid->op_type == OP_AELEM)
5044 o->op_flags |= OPf_SPECIAL;
5045 else if (kid->op_type != OP_HELEM)
5046 Perl_croak(aTHX_ "%s argument is not a HASH or ARRAY element",
5047 PL_op_desc[o->op_type]);
5055 Perl_ck_gvconst(pTHX_ register OP *o)
5057 o = fold_constants(o);
5058 if (o->op_type == OP_CONST)
5065 Perl_ck_rvconst(pTHX_ register OP *o)
5068 SVOP *kid = (SVOP*)cUNOPo->op_first;
5070 o->op_private |= (PL_hints & HINT_STRICT_REFS);
5071 if (kid->op_type == OP_CONST) {
5075 SV *kidsv = kid->op_sv;
5078 /* Is it a constant from cv_const_sv()? */
5079 if (SvROK(kidsv) && SvREADONLY(kidsv)) {
5080 SV *rsv = SvRV(kidsv);
5081 int svtype = SvTYPE(rsv);
5082 char *badtype = Nullch;
5084 switch (o->op_type) {
5086 if (svtype > SVt_PVMG)
5087 badtype = "a SCALAR";
5090 if (svtype != SVt_PVAV)
5091 badtype = "an ARRAY";
5094 if (svtype != SVt_PVHV) {
5095 if (svtype == SVt_PVAV) { /* pseudohash? */
5096 SV **ksv = av_fetch((AV*)rsv, 0, FALSE);
5097 if (ksv && SvROK(*ksv)
5098 && SvTYPE(SvRV(*ksv)) == SVt_PVHV)
5107 if (svtype != SVt_PVCV)
5112 Perl_croak(aTHX_ "Constant is not %s reference", badtype);
5115 name = SvPV(kidsv, n_a);
5116 if ((PL_hints & HINT_STRICT_REFS) && (kid->op_private & OPpCONST_BARE)) {
5117 char *badthing = Nullch;
5118 switch (o->op_type) {
5120 badthing = "a SCALAR";
5123 badthing = "an ARRAY";
5126 badthing = "a HASH";
5131 "Can't use bareword (\"%s\") as %s ref while \"strict refs\" in use",
5135 * This is a little tricky. We only want to add the symbol if we
5136 * didn't add it in the lexer. Otherwise we get duplicate strict
5137 * warnings. But if we didn't add it in the lexer, we must at
5138 * least pretend like we wanted to add it even if it existed before,
5139 * or we get possible typo warnings. OPpCONST_ENTERED says
5140 * whether the lexer already added THIS instance of this symbol.
5142 iscv = (o->op_type == OP_RV2CV) * 2;
5144 gv = gv_fetchpv(name,
5145 iscv | !(kid->op_private & OPpCONST_ENTERED),
5148 : o->op_type == OP_RV2SV
5150 : o->op_type == OP_RV2AV
5152 : o->op_type == OP_RV2HV
5155 } while (!gv && !(kid->op_private & OPpCONST_ENTERED) && !iscv++);
5157 kid->op_type = OP_GV;
5158 SvREFCNT_dec(kid->op_sv);
5160 /* XXX hack: dependence on sizeof(PADOP) <= sizeof(SVOP) */
5161 kPADOP->op_padix = pad_alloc(OP_GV, SVs_PADTMP);
5163 PL_curpad[kPADOP->op_padix] = SvREFCNT_inc(gv);
5165 kid->op_sv = SvREFCNT_inc(gv);
5167 kid->op_ppaddr = PL_ppaddr[OP_GV];
5174 Perl_ck_ftst(pTHX_ OP *o)
5177 I32 type = o->op_type;
5179 if (o->op_flags & OPf_REF) {
5182 else if (o->op_flags & OPf_KIDS && cUNOPo->op_first->op_type != OP_STUB) {
5183 SVOP *kid = (SVOP*)cUNOPo->op_first;
5185 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
5187 OP *newop = newGVOP(type, OPf_REF,
5188 gv_fetchpv(SvPVx(kid->op_sv, n_a), TRUE, SVt_PVIO));
5195 if (type == OP_FTTTY)
5196 o = newGVOP(type, OPf_REF, gv_fetchpv("main::STDIN", TRUE,
5199 o = newUNOP(type, 0, newDEFSVOP());
5202 if (type == OP_FTTEXT || type == OP_FTBINARY) {
5204 if (PL_hints & HINT_LOCALE)
5205 o->op_private |= OPpLOCALE;
5212 Perl_ck_fun(pTHX_ OP *o)
5219 int type = o->op_type;
5220 register I32 oa = PL_opargs[type] >> OASHIFT;
5222 if (o->op_flags & OPf_STACKED) {
5223 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
5226 return no_fh_allowed(o);
5229 if (o->op_flags & OPf_KIDS) {
5231 tokid = &cLISTOPo->op_first;
5232 kid = cLISTOPo->op_first;
5233 if (kid->op_type == OP_PUSHMARK ||
5234 kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK)
5236 tokid = &kid->op_sibling;
5237 kid = kid->op_sibling;
5239 if (!kid && PL_opargs[type] & OA_DEFGV)
5240 *tokid = kid = newDEFSVOP();
5244 sibl = kid->op_sibling;
5247 /* list seen where single (scalar) arg expected? */
5248 if (numargs == 1 && !(oa >> 4)
5249 && kid->op_type == OP_LIST && type != OP_SCALAR)
5251 return too_many_arguments(o,PL_op_desc[type]);
5264 if (kid->op_type == OP_CONST &&
5265 (kid->op_private & OPpCONST_BARE))
5267 char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
5268 OP *newop = newAVREF(newGVOP(OP_GV, 0,
5269 gv_fetchpv(name, TRUE, SVt_PVAV) ));
5270 if (ckWARN(WARN_SYNTAX))
5271 Perl_warner(aTHX_ WARN_SYNTAX,
5272 "Array @%s missing the @ in argument %"IVdf" of %s()",
5273 name, (IV)numargs, PL_op_desc[type]);
5276 kid->op_sibling = sibl;
5279 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
5280 bad_type(numargs, "array", PL_op_desc[type], kid);
5284 if (kid->op_type == OP_CONST &&
5285 (kid->op_private & OPpCONST_BARE))
5287 char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
5288 OP *newop = newHVREF(newGVOP(OP_GV, 0,
5289 gv_fetchpv(name, TRUE, SVt_PVHV) ));
5290 if (ckWARN(WARN_SYNTAX))
5291 Perl_warner(aTHX_ WARN_SYNTAX,
5292 "Hash %%%s missing the %% in argument %"IVdf" of %s()",
5293 name, (IV)numargs, PL_op_desc[type]);
5296 kid->op_sibling = sibl;
5299 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
5300 bad_type(numargs, "hash", PL_op_desc[type], kid);
5305 OP *newop = newUNOP(OP_NULL, 0, kid);
5306 kid->op_sibling = 0;
5308 newop->op_next = newop;
5310 kid->op_sibling = sibl;
5315 if (kid->op_type != OP_GV && kid->op_type != OP_RV2GV) {
5316 if (kid->op_type == OP_CONST &&
5317 (kid->op_private & OPpCONST_BARE))
5319 OP *newop = newGVOP(OP_GV, 0,
5320 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, n_a), TRUE,
5325 else if (kid->op_type == OP_READLINE) {
5326 /* neophyte patrol: open(<FH>), close(<FH>) etc. */
5327 bad_type(numargs, "HANDLE", PL_op_desc[o->op_type], kid);
5330 I32 flags = OPf_SPECIAL;
5334 /* is this op a FH constructor? */
5335 if (is_handle_constructor(o,numargs)) {
5336 char *name = Nullch;
5340 /* Set a flag to tell rv2gv to vivify
5341 * need to "prove" flag does not mean something
5342 * else already - NI-S 1999/05/07
5345 if (kid->op_type == OP_PADSV) {
5346 SV **namep = av_fetch(PL_comppad_name,
5348 if (namep && *namep)
5349 name = SvPV(*namep, len);
5351 else if (kid->op_type == OP_RV2SV
5352 && kUNOP->op_first->op_type == OP_GV)
5354 GV *gv = cGVOPx_gv(kUNOP->op_first);
5356 len = GvNAMELEN(gv);
5360 targ = pad_alloc(OP_RV2GV, SVs_PADTMP);
5361 namesv = PL_curpad[targ];
5362 SvUPGRADE(namesv, SVt_PV);
5364 sv_setpvn(namesv, "$", 1);
5365 sv_catpvn(namesv, name, len);
5368 kid->op_sibling = 0;
5369 kid = newUNOP(OP_RV2GV, flags, scalar(kid));
5370 kid->op_targ = targ;
5371 kid->op_private |= priv;
5373 kid->op_sibling = sibl;
5379 mod(scalar(kid), type);
5383 tokid = &kid->op_sibling;
5384 kid = kid->op_sibling;
5386 o->op_private |= numargs;
5388 return too_many_arguments(o,PL_op_desc[o->op_type]);
5391 else if (PL_opargs[type] & OA_DEFGV) {
5393 return newUNOP(type, 0, newDEFSVOP());
5397 while (oa & OA_OPTIONAL)
5399 if (oa && oa != OA_LIST)
5400 return too_few_arguments(o,PL_op_desc[o->op_type]);
5406 Perl_ck_glob(pTHX_ OP *o)
5410 if ((o->op_flags & OPf_KIDS) && !cLISTOPo->op_first->op_sibling)
5411 append_elem(OP_GLOB, o, newDEFSVOP());
5413 if (!((gv = gv_fetchpv("glob", FALSE, SVt_PVCV)) && GvIMPORTED_CV(gv)))
5414 gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
5416 #if !defined(PERL_EXTERNAL_GLOB)
5417 /* XXX this can be tightened up and made more failsafe. */
5419 OP *modname = newSVOP(OP_CONST, 0, newSVpvn("File::Glob", 10));
5420 modname->op_private |= OPpCONST_BARE;
5422 utilize(1, start_subparse(FALSE, 0), Nullop, modname,
5423 newSVOP(OP_CONST, 0, newSVpvn(":globally", 9)));
5424 gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
5427 #endif /* PERL_EXTERNAL_GLOB */
5429 if (gv && GvIMPORTED_CV(gv)) {
5430 append_elem(OP_GLOB, o,
5431 newSVOP(OP_CONST, 0, newSViv(PL_glob_index++)));
5432 o->op_type = OP_LIST;
5433 o->op_ppaddr = PL_ppaddr[OP_LIST];
5434 cLISTOPo->op_first->op_type = OP_PUSHMARK;
5435 cLISTOPo->op_first->op_ppaddr = PL_ppaddr[OP_PUSHMARK];
5436 o = newUNOP(OP_ENTERSUB, OPf_STACKED,
5437 append_elem(OP_LIST, o,
5438 scalar(newUNOP(OP_RV2CV, 0,
5439 newGVOP(OP_GV, 0, gv)))));
5440 o = newUNOP(OP_NULL, 0, ck_subr(o));
5441 o->op_targ = OP_GLOB; /* hint at what it used to be */
5444 gv = newGVgen("main");
5446 append_elem(OP_GLOB, o, newGVOP(OP_GV, 0, gv));
5452 Perl_ck_grep(pTHX_ OP *o)
5456 OPCODE type = o->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
5458 o->op_ppaddr = PL_ppaddr[OP_GREPSTART];
5459 NewOp(1101, gwop, 1, LOGOP);
5461 if (o->op_flags & OPf_STACKED) {
5464 kid = cLISTOPo->op_first->op_sibling;
5465 for (k = cLISTOPo->op_first->op_sibling->op_next; k; k = k->op_next) {
5468 kid->op_next = (OP*)gwop;
5469 o->op_flags &= ~OPf_STACKED;
5471 kid = cLISTOPo->op_first->op_sibling;
5472 if (type == OP_MAPWHILE)
5479 kid = cLISTOPo->op_first->op_sibling;
5480 if (kid->op_type != OP_NULL)
5481 Perl_croak(aTHX_ "panic: ck_grep");
5482 kid = kUNOP->op_first;
5484 gwop->op_type = type;
5485 gwop->op_ppaddr = PL_ppaddr[type];
5486 gwop->op_first = listkids(o);
5487 gwop->op_flags |= OPf_KIDS;
5488 gwop->op_private = 1;
5489 gwop->op_other = LINKLIST(kid);
5490 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
5491 kid->op_next = (OP*)gwop;
5493 kid = cLISTOPo->op_first->op_sibling;
5494 if (!kid || !kid->op_sibling)
5495 return too_few_arguments(o,PL_op_desc[o->op_type]);
5496 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
5497 mod(kid, OP_GREPSTART);
5503 Perl_ck_index(pTHX_ OP *o)
5505 if (o->op_flags & OPf_KIDS) {
5506 OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5508 kid = kid->op_sibling; /* get past "big" */
5509 if (kid && kid->op_type == OP_CONST)
5510 fbm_compile(((SVOP*)kid)->op_sv, 0);
5516 Perl_ck_lengthconst(pTHX_ OP *o)
5518 /* XXX length optimization goes here */
5523 Perl_ck_lfun(pTHX_ OP *o)
5525 OPCODE type = o->op_type;
5526 return modkids(ck_fun(o), type);
5530 Perl_ck_defined(pTHX_ OP *o) /* 19990527 MJD */
5533 if ((o->op_flags & OPf_KIDS) && ckWARN(WARN_DEPRECATED)) {
5534 switch (cUNOPo->op_first->op_type) {
5536 break; /* Globals via GV can be undef */
5538 case OP_AASSIGN: /* Is this a good idea? */
5539 Perl_warner(aTHX_ WARN_DEPRECATED,
5540 "defined(@array) is deprecated");
5541 Perl_warner(aTHX_ WARN_DEPRECATED,
5542 "(Maybe you should just omit the defined()?)\n");
5545 break; /* Globals via GV can be undef */
5547 Perl_warner(aTHX_ WARN_DEPRECATED,
5548 "defined(%hash) is deprecated");
5549 Perl_warner(aTHX_ WARN_DEPRECATED,
5550 "(Maybe you should just omit the defined()?)\n");
5561 Perl_ck_rfun(pTHX_ OP *o)
5563 OPCODE type = o->op_type;
5564 return refkids(ck_fun(o), type);
5568 Perl_ck_listiob(pTHX_ OP *o)
5572 kid = cLISTOPo->op_first;
5575 kid = cLISTOPo->op_first;
5577 if (kid->op_type == OP_PUSHMARK)
5578 kid = kid->op_sibling;
5579 if (kid && o->op_flags & OPf_STACKED)
5580 kid = kid->op_sibling;
5581 else if (kid && !kid->op_sibling) { /* print HANDLE; */
5582 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
5583 o->op_flags |= OPf_STACKED; /* make it a filehandle */
5584 kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
5585 cLISTOPo->op_first->op_sibling = kid;
5586 cLISTOPo->op_last = kid;
5587 kid = kid->op_sibling;
5592 append_elem(o->op_type, o, newDEFSVOP());
5598 if (PL_hints & HINT_LOCALE)
5599 o->op_private |= OPpLOCALE;
5606 Perl_ck_fun_locale(pTHX_ OP *o)
5612 if (PL_hints & HINT_LOCALE)
5613 o->op_private |= OPpLOCALE;
5620 Perl_ck_sassign(pTHX_ OP *o)
5622 OP *kid = cLISTOPo->op_first;
5623 /* has a disposable target? */
5624 if ((PL_opargs[kid->op_type] & OA_TARGLEX)
5625 && !(kid->op_flags & OPf_STACKED))
5627 OP *kkid = kid->op_sibling;
5629 /* Can just relocate the target. */
5630 if (kkid && kkid->op_type == OP_PADSV
5631 && !(kkid->op_private & OPpLVAL_INTRO))
5633 kid->op_targ = kkid->op_targ;
5635 /* Now we do not need PADSV and SASSIGN. */
5636 kid->op_sibling = o->op_sibling; /* NULL */
5637 cLISTOPo->op_first = NULL;
5640 kid->op_private |= OPpTARGET_MY; /* Used for context settings */
5648 Perl_ck_scmp(pTHX_ OP *o)
5652 if (PL_hints & HINT_LOCALE)
5653 o->op_private |= OPpLOCALE;
5660 Perl_ck_match(pTHX_ OP *o)
5662 o->op_private |= OPpRUNTIME;
5667 Perl_ck_method(pTHX_ OP *o)
5669 OP *kid = cUNOPo->op_first;
5670 if (kid->op_type == OP_CONST) {
5671 SV* sv = kSVOP->op_sv;
5672 if (!(strchr(SvPVX(sv), ':') || strchr(SvPVX(sv), '\''))) {
5674 sv_upgrade(sv, SVt_PVIV);
5676 PERL_HASH(SvUVX(sv), SvPVX(sv), SvCUR(sv));
5677 cmop = newSVOP(OP_METHOD_NAMED, 0, sv);
5678 kSVOP->op_sv = Nullsv;
5687 Perl_ck_null(pTHX_ OP *o)
5693 Perl_ck_repeat(pTHX_ OP *o)
5695 if (cBINOPo->op_first->op_flags & OPf_PARENS) {
5696 o->op_private |= OPpREPEAT_DOLIST;
5697 cBINOPo->op_first = force_list(cBINOPo->op_first);
5705 Perl_ck_require(pTHX_ OP *o)
5707 if (o->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
5708 SVOP *kid = (SVOP*)cUNOPo->op_first;
5710 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
5712 for (s = SvPVX(kid->op_sv); *s; s++) {
5713 if (*s == ':' && s[1] == ':') {
5715 Move(s+2, s+1, strlen(s+2)+1, char);
5716 --SvCUR(kid->op_sv);
5719 sv_catpvn(kid->op_sv, ".pm", 3);
5727 Perl_ck_retarget(pTHX_ OP *o)
5729 Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
5736 Perl_ck_select(pTHX_ OP *o)
5739 if (o->op_flags & OPf_KIDS) {
5740 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5741 if (kid && kid->op_sibling) {
5742 o->op_type = OP_SSELECT;
5743 o->op_ppaddr = PL_ppaddr[OP_SSELECT];
5745 return fold_constants(o);
5749 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5750 if (kid && kid->op_type == OP_RV2GV)
5751 kid->op_private &= ~HINT_STRICT_REFS;
5756 Perl_ck_shift(pTHX_ OP *o)
5758 I32 type = o->op_type;
5760 if (!(o->op_flags & OPf_KIDS)) {
5765 if (!CvUNIQUE(PL_compcv)) {
5766 argop = newOP(OP_PADAV, OPf_REF);
5767 argop->op_targ = 0; /* PL_curpad[0] is @_ */
5770 argop = newUNOP(OP_RV2AV, 0,
5771 scalar(newGVOP(OP_GV, 0,
5772 gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
5775 argop = newUNOP(OP_RV2AV, 0,
5776 scalar(newGVOP(OP_GV, 0, !CvUNIQUE(PL_compcv) ?
5777 PL_defgv : gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
5778 #endif /* USE_THREADS */
5779 return newUNOP(type, 0, scalar(argop));
5781 return scalar(modkids(ck_fun(o), type));
5785 Perl_ck_sort(pTHX_ OP *o)
5789 if (PL_hints & HINT_LOCALE)
5790 o->op_private |= OPpLOCALE;
5793 if (o->op_type == OP_SORT && o->op_flags & OPf_STACKED)
5795 if (o->op_flags & OPf_STACKED) { /* may have been cleared */
5796 OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5798 kid = kUNOP->op_first; /* get past null */
5800 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
5802 if (kid->op_type == OP_SCOPE) {
5806 else if (kid->op_type == OP_LEAVE) {
5807 if (o->op_type == OP_SORT) {
5808 null(kid); /* wipe out leave */
5811 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
5812 if (k->op_next == kid)
5817 kid->op_next = 0; /* just disconnect the leave */
5818 k = kLISTOP->op_first;
5822 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5823 if (o->op_type == OP_SORT)
5827 o->op_flags |= OPf_SPECIAL;
5829 else if (kid->op_type == OP_RV2SV || kid->op_type == OP_PADSV)
5830 null(cLISTOPo->op_first->op_sibling);
5837 S_simplify_sort(pTHX_ OP *o)
5840 register OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5844 if (!(o->op_flags & OPf_STACKED))
5846 GvMULTI_on(gv_fetchpv("a", TRUE, SVt_PV));
5847 GvMULTI_on(gv_fetchpv("b", TRUE, SVt_PV));
5848 kid = kUNOP->op_first; /* get past null */
5849 if (kid->op_type != OP_SCOPE)
5851 kid = kLISTOP->op_last; /* get past scope */
5852 switch(kid->op_type) {
5860 k = kid; /* remember this node*/
5861 if (kBINOP->op_first->op_type != OP_RV2SV)
5863 kid = kBINOP->op_first; /* get past cmp */
5864 if (kUNOP->op_first->op_type != OP_GV)
5866 kid = kUNOP->op_first; /* get past rv2sv */
5868 if (GvSTASH(gv) != PL_curstash)
5870 if (strEQ(GvNAME(gv), "a"))
5872 else if(strEQ(GvNAME(gv), "b"))
5876 kid = k; /* back to cmp */
5877 if (kBINOP->op_last->op_type != OP_RV2SV)
5879 kid = kBINOP->op_last; /* down to 2nd arg */
5880 if (kUNOP->op_first->op_type != OP_GV)
5882 kid = kUNOP->op_first; /* get past rv2sv */
5884 if (GvSTASH(gv) != PL_curstash
5886 ? strNE(GvNAME(gv), "a")
5887 : strNE(GvNAME(gv), "b")))
5889 o->op_flags &= ~(OPf_STACKED | OPf_SPECIAL);
5891 o->op_private |= OPpSORT_REVERSE;
5892 if (k->op_type == OP_NCMP)
5893 o->op_private |= OPpSORT_NUMERIC;
5894 if (k->op_type == OP_I_NCMP)
5895 o->op_private |= OPpSORT_NUMERIC | OPpSORT_INTEGER;
5896 kid = cLISTOPo->op_first->op_sibling;
5897 cLISTOPo->op_first->op_sibling = kid->op_sibling; /* bypass old block */
5898 op_free(kid); /* then delete it */
5899 cLISTOPo->op_children--;
5903 Perl_ck_split(pTHX_ OP *o)
5907 if (o->op_flags & OPf_STACKED)
5908 return no_fh_allowed(o);
5910 kid = cLISTOPo->op_first;
5911 if (kid->op_type != OP_NULL)
5912 Perl_croak(aTHX_ "panic: ck_split");
5913 kid = kid->op_sibling;
5914 op_free(cLISTOPo->op_first);
5915 cLISTOPo->op_first = kid;
5917 cLISTOPo->op_first = kid = newSVOP(OP_CONST, 0, newSVpvn(" ", 1));
5918 cLISTOPo->op_last = kid; /* There was only one element previously */
5921 if (kid->op_type != OP_MATCH) {
5922 OP *sibl = kid->op_sibling;
5923 kid->op_sibling = 0;
5924 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
5925 if (cLISTOPo->op_first == cLISTOPo->op_last)
5926 cLISTOPo->op_last = kid;
5927 cLISTOPo->op_first = kid;
5928 kid->op_sibling = sibl;
5931 kid->op_type = OP_PUSHRE;
5932 kid->op_ppaddr = PL_ppaddr[OP_PUSHRE];
5935 if (!kid->op_sibling)
5936 append_elem(OP_SPLIT, o, newDEFSVOP());
5938 kid = kid->op_sibling;
5941 if (!kid->op_sibling)
5942 append_elem(OP_SPLIT, o, newSVOP(OP_CONST, 0, newSViv(0)));
5944 kid = kid->op_sibling;
5947 if (kid->op_sibling)
5948 return too_many_arguments(o,PL_op_desc[o->op_type]);
5954 Perl_ck_join(pTHX_ OP *o)
5956 if (ckWARN(WARN_SYNTAX)) {
5957 OP *kid = cLISTOPo->op_first->op_sibling;
5958 if (kid && kid->op_type == OP_MATCH) {
5959 char *pmstr = "STRING";
5960 if (kPMOP->op_pmregexp)
5961 pmstr = kPMOP->op_pmregexp->precomp;
5962 Perl_warner(aTHX_ WARN_SYNTAX,
5963 "/%s/ should probably be written as \"%s\"",
5971 Perl_ck_subr(pTHX_ OP *o)
5974 OP *prev = ((cUNOPo->op_first->op_sibling)
5975 ? cUNOPo : ((UNOP*)cUNOPo->op_first))->op_first;
5976 OP *o2 = prev->op_sibling;
5985 o->op_private |= OPpENTERSUB_HASTARG;
5986 for (cvop = o2; cvop->op_sibling; cvop = cvop->op_sibling) ;
5987 if (cvop->op_type == OP_RV2CV) {
5989 o->op_private |= (cvop->op_private & OPpENTERSUB_AMPER);
5990 null(cvop); /* disable rv2cv */
5991 tmpop = (SVOP*)((UNOP*)cvop)->op_first;
5992 if (tmpop->op_type == OP_GV && !(o->op_private & OPpENTERSUB_AMPER)) {
5993 GV *gv = cGVOPx_gv(tmpop);
5996 tmpop->op_private |= OPpEARLY_CV;
5997 else if (SvPOK(cv)) {
5998 namegv = CvANON(cv) ? gv : CvGV(cv);
5999 proto = SvPV((SV*)cv, n_a);
6003 else if (cvop->op_type == OP_METHOD || cvop->op_type == OP_METHOD_NAMED) {
6004 if (o2->op_type == OP_CONST)
6005 o2->op_private &= ~OPpCONST_STRICT;
6006 else if (o2->op_type == OP_LIST) {
6007 OP *o = ((UNOP*)o2)->op_first->op_sibling;
6008 if (o && o->op_type == OP_CONST)
6009 o->op_private &= ~OPpCONST_STRICT;
6012 o->op_private |= (PL_hints & HINT_STRICT_REFS);
6013 if (PERLDB_SUB && PL_curstash != PL_debstash)
6014 o->op_private |= OPpENTERSUB_DB;
6015 while (o2 != cvop) {
6019 return too_many_arguments(o, gv_ename(namegv));
6037 if (o2->op_type != OP_REFGEN && o2->op_type != OP_UNDEF)
6038 bad_type(arg, "block", gv_ename(namegv), o2);
6041 /* '*' allows any scalar type, including bareword */
6044 if (o2->op_type == OP_RV2GV)
6045 goto wrapref; /* autoconvert GLOB -> GLOBref */
6046 else if (o2->op_type == OP_CONST)
6047 o2->op_private &= ~OPpCONST_STRICT;
6048 else if (o2->op_type == OP_ENTERSUB) {
6049 /* accidental subroutine, revert to bareword */
6050 OP *gvop = ((UNOP*)o2)->op_first;
6051 if (gvop && gvop->op_type == OP_NULL) {
6052 gvop = ((UNOP*)gvop)->op_first;
6054 for (; gvop->op_sibling; gvop = gvop->op_sibling)
6057 (gvop->op_private & OPpENTERSUB_NOPAREN) &&
6058 (gvop = ((UNOP*)gvop)->op_first) &&
6059 gvop->op_type == OP_GV)
6061 GV *gv = cGVOPx_gv(gvop);
6062 OP *sibling = o2->op_sibling;
6063 SV *n = newSVpvn("",0);
6065 gv_fullname3(n, gv, "");
6066 if (SvCUR(n)>6 && strnEQ(SvPVX(n),"main::",6))
6067 sv_chop(n, SvPVX(n)+6);
6068 o2 = newSVOP(OP_CONST, 0, n);
6069 prev->op_sibling = o2;
6070 o2->op_sibling = sibling;
6082 if (o2->op_type != OP_RV2GV)
6083 bad_type(arg, "symbol", gv_ename(namegv), o2);
6086 if (o2->op_type != OP_RV2CV)
6087 bad_type(arg, "sub", gv_ename(namegv), o2);
6090 if (o2->op_type != OP_RV2SV
6091 && o2->op_type != OP_PADSV
6092 && o2->op_type != OP_HELEM
6093 && o2->op_type != OP_AELEM
6094 && o2->op_type != OP_THREADSV)
6096 bad_type(arg, "scalar", gv_ename(namegv), o2);
6100 if (o2->op_type != OP_RV2AV && o2->op_type != OP_PADAV)
6101 bad_type(arg, "array", gv_ename(namegv), o2);
6104 if (o2->op_type != OP_RV2HV && o2->op_type != OP_PADHV)
6105 bad_type(arg, "hash", gv_ename(namegv), o2);
6109 OP* sib = kid->op_sibling;
6110 kid->op_sibling = 0;
6111 o2 = newUNOP(OP_REFGEN, 0, kid);
6112 o2->op_sibling = sib;
6113 prev->op_sibling = o2;
6124 Perl_croak(aTHX_ "Malformed prototype for %s: %s",
6125 gv_ename(namegv), SvPV((SV*)cv, n_a));
6130 mod(o2, OP_ENTERSUB);
6132 o2 = o2->op_sibling;
6134 if (proto && !optional &&
6135 (*proto && *proto != '@' && *proto != '%' && *proto != ';'))
6136 return too_few_arguments(o, gv_ename(namegv));
6141 Perl_ck_svconst(pTHX_ OP *o)
6143 SvREADONLY_on(cSVOPo->op_sv);
6148 Perl_ck_trunc(pTHX_ OP *o)
6150 if (o->op_flags & OPf_KIDS) {
6151 SVOP *kid = (SVOP*)cUNOPo->op_first;
6153 if (kid->op_type == OP_NULL)
6154 kid = (SVOP*)kid->op_sibling;
6155 if (kid && kid->op_type == OP_CONST &&
6156 (kid->op_private & OPpCONST_BARE))
6158 o->op_flags |= OPf_SPECIAL;
6159 kid->op_private &= ~OPpCONST_STRICT;
6165 /* A peephole optimizer. We visit the ops in the order they're to execute. */
6168 Perl_peep(pTHX_ register OP *o)
6171 register OP* oldop = 0;
6173 OP *last_composite = Nullop;
6175 if (!o || o->op_seq)
6179 SAVEVPTR(PL_curcop);
6180 for (; o; o = o->op_next) {
6186 switch (o->op_type) {
6190 PL_curcop = ((COP*)o); /* for warnings */
6191 o->op_seq = PL_op_seqmax++;
6192 last_composite = Nullop;
6196 if (cSVOPo->op_private & OPpCONST_STRICT)
6197 no_bareword_allowed(o);
6199 /* Relocate sv to the pad for thread safety.
6200 * Despite being a "constant", the SV is written to,
6201 * for reference counts, sv_upgrade() etc. */
6203 PADOFFSET ix = pad_alloc(OP_CONST, SVs_PADTMP);
6204 SvREFCNT_dec(PL_curpad[ix]);
6205 SvPADTMP_on(cSVOPo->op_sv);
6206 PL_curpad[ix] = cSVOPo->op_sv;
6207 cSVOPo->op_sv = Nullsv;
6219 if (o->op_next && o->op_next->op_type == OP_STRINGIFY) {
6220 if (o->op_next->op_private & OPpTARGET_MY) {
6221 if (o->op_flags & OPf_STACKED) /* chained concats */
6222 goto ignore_optimization;
6224 o->op_targ = o->op_next->op_targ;
6225 o->op_next->op_targ = 0;
6226 o->op_private |= OPpTARGET_MY;
6231 ignore_optimization:
6232 o->op_seq = PL_op_seqmax++;
6235 if ((o->op_flags & OPf_WANT) != OPf_WANT_LIST) {
6236 o->op_seq = PL_op_seqmax++;
6237 break; /* Scalar stub must produce undef. List stub is noop */
6241 if (o->op_targ == OP_NEXTSTATE
6242 || o->op_targ == OP_DBSTATE
6243 || o->op_targ == OP_SETSTATE)
6245 PL_curcop = ((COP*)o);
6252 if (oldop && o->op_next) {
6253 oldop->op_next = o->op_next;
6256 o->op_seq = PL_op_seqmax++;
6260 if (o->op_next->op_type == OP_RV2SV) {
6261 if (!(o->op_next->op_private & OPpDEREF)) {
6263 o->op_private |= o->op_next->op_private & OPpLVAL_INTRO;
6264 o->op_next = o->op_next->op_next;
6265 o->op_type = OP_GVSV;
6266 o->op_ppaddr = PL_ppaddr[OP_GVSV];
6269 else if (o->op_next->op_type == OP_RV2AV) {
6270 OP* pop = o->op_next->op_next;
6272 if (pop->op_type == OP_CONST &&
6273 (PL_op = pop->op_next) &&
6274 pop->op_next->op_type == OP_AELEM &&
6275 !(pop->op_next->op_private &
6276 (OPpLVAL_INTRO|OPpLVAL_DEFER|OPpDEREF)) &&
6277 (i = SvIV(((SVOP*)pop)->op_sv) - PL_compiling.cop_arybase)
6285 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
6286 o->op_next = pop->op_next->op_next;
6287 o->op_type = OP_AELEMFAST;
6288 o->op_ppaddr = PL_ppaddr[OP_AELEMFAST];
6289 o->op_private = (U8)i;
6294 else if ((o->op_private & OPpEARLY_CV) && ckWARN(WARN_UNSAFE)) {
6296 if (SvTYPE(gv) == SVt_PVGV && GvCV(gv) && SvPVX(GvCV(gv))) {
6297 /* XXX could check prototype here instead of just carping */
6298 SV *sv = sv_newmortal();
6299 gv_efullname3(sv, gv, Nullch);
6300 Perl_warner(aTHX_ WARN_UNSAFE,
6301 "%s() called too early to check prototype",
6306 o->op_seq = PL_op_seqmax++;
6317 o->op_seq = PL_op_seqmax++;
6318 while (cLOGOP->op_other->op_type == OP_NULL)
6319 cLOGOP->op_other = cLOGOP->op_other->op_next;
6320 peep(cLOGOP->op_other);
6324 o->op_seq = PL_op_seqmax++;
6325 peep(cLOOP->op_redoop);
6326 peep(cLOOP->op_nextop);
6327 peep(cLOOP->op_lastop);
6333 o->op_seq = PL_op_seqmax++;
6334 peep(cPMOP->op_pmreplstart);
6338 o->op_seq = PL_op_seqmax++;
6339 if (ckWARN(WARN_SYNTAX) && o->op_next
6340 && o->op_next->op_type == OP_NEXTSTATE) {
6341 if (o->op_next->op_sibling &&
6342 o->op_next->op_sibling->op_type != OP_EXIT &&
6343 o->op_next->op_sibling->op_type != OP_WARN &&
6344 o->op_next->op_sibling->op_type != OP_DIE) {
6345 line_t oldline = CopLINE(PL_curcop);
6347 CopLINE_set(PL_curcop, CopLINE((COP*)o->op_next));
6348 Perl_warner(aTHX_ WARN_SYNTAX, "Statement unlikely to be reached");
6349 Perl_warner(aTHX_ WARN_SYNTAX, "(Maybe you meant system() when you said exec()?)\n");
6350 CopLINE_set(PL_curcop, oldline);
6364 if ((o->op_private & (OPpLVAL_INTRO))
6365 || ((BINOP*)o)->op_last->op_type != OP_CONST)
6367 rop = (UNOP*)((BINOP*)o)->op_first;
6368 if (rop->op_type != OP_RV2HV || rop->op_first->op_type != OP_PADSV)
6370 lexname = *av_fetch(PL_comppad_name, rop->op_first->op_targ, TRUE);
6371 if (!SvOBJECT(lexname))
6373 fields = (GV**)hv_fetch(SvSTASH(lexname), "FIELDS", 6, FALSE);
6374 if (!fields || !GvHV(*fields))
6376 svp = cSVOPx_svp(((BINOP*)o)->op_last);
6377 key = SvPV(*svp, keylen);
6378 indsvp = hv_fetch(GvHV(*fields), key, keylen, FALSE);
6380 Perl_croak(aTHX_ "No such pseudo-hash field \"%s\" in variable %s of type %s",
6381 key, SvPV(lexname, n_a), HvNAME(SvSTASH(lexname)));
6383 ind = SvIV(*indsvp);
6385 Perl_croak(aTHX_ "Bad index while coercing array into hash");
6386 rop->op_type = OP_RV2AV;
6387 rop->op_ppaddr = PL_ppaddr[OP_RV2AV];
6388 o->op_type = OP_AELEM;
6389 o->op_ppaddr = PL_ppaddr[OP_AELEM];
6391 *svp = newSViv(ind);
6397 if (!(o->op_flags & OPf_WANT)
6398 || (o->op_flags & OPf_WANT) == OPf_WANT_LIST)
6402 o->op_seq = PL_op_seqmax++;
6406 if (o->op_next && o->op_next->op_type != OP_LEAVESUBLV) {
6407 o->op_seq = PL_op_seqmax++;
6413 if (last_composite) {
6414 OP *r = last_composite;
6416 while (r->op_sibling)
6419 || (r->op_next->op_type == OP_LIST
6420 && r->op_next->op_next == o))
6422 if (last_composite->op_type == OP_RV2AV)
6423 yyerror("Lvalue subs returning arrays not implemented yet");
6425 yyerror("Lvalue subs returning hashes not implemented yet");
6432 o->op_seq = PL_op_seqmax++;