3 * Copyright (c) 1991-2000, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 * "You see: Mr. Drogo, he married poor Miss Primula Brandybuck. She was
12 * our Mr. Bilbo's first cousin on the mother's side (her mother being the
13 * youngest of the Old Took's daughters); and Mr. Drogo was his second
14 * cousin. So Mr. Frodo is his first *and* second cousin, once removed
15 * either way, as the saying is, if you follow me." --the Gaffer
23 /* #define PL_OP_SLAB_ALLOC */
25 #ifdef PL_OP_SLAB_ALLOC
26 #define SLAB_SIZE 8192
27 static char *PL_OpPtr = NULL;
28 static int PL_OpSpace = 0;
29 #define NewOp(m,var,c,type) do { if ((PL_OpSpace -= c*sizeof(type)) >= 0) \
30 var = (type *)(PL_OpPtr -= c*sizeof(type)); \
32 var = (type *) Slab_Alloc(m,c*sizeof(type)); \
36 S_Slab_Alloc(pTHX_ int m, size_t sz)
38 Newz(m,PL_OpPtr,SLAB_SIZE,char);
39 PL_OpSpace = SLAB_SIZE - sz;
40 return PL_OpPtr += PL_OpSpace;
44 #define NewOp(m, var, c, type) Newz(m, var, c, type)
47 * In the following definition, the ", Nullop" is just to make the compiler
48 * think the expression is of the right type: croak actually does a Siglongjmp.
50 #define CHECKOP(type,o) \
51 ((PL_op_mask && PL_op_mask[type]) \
52 ? ( op_free((OP*)o), \
53 Perl_croak(aTHX_ "%s trapped by operation mask", PL_op_desc[type]), \
55 : CALL_FPTR(PL_check[type])(aTHX_ (OP*)o))
57 #define PAD_MAX 999999999
60 S_gv_ename(pTHX_ GV *gv)
63 SV* tmpsv = sv_newmortal();
64 gv_efullname3(tmpsv, gv, Nullch);
65 return SvPV(tmpsv,n_a);
69 S_no_fh_allowed(pTHX_ OP *o)
71 yyerror(Perl_form(aTHX_ "Missing comma after first argument to %s function",
72 PL_op_desc[o->op_type]));
77 S_too_few_arguments(pTHX_ OP *o, char *name)
79 yyerror(Perl_form(aTHX_ "Not enough arguments for %s", name));
84 S_too_many_arguments(pTHX_ OP *o, char *name)
86 yyerror(Perl_form(aTHX_ "Too many arguments for %s", name));
91 S_bad_type(pTHX_ I32 n, char *t, char *name, OP *kid)
93 yyerror(Perl_form(aTHX_ "Type of arg %d to %s must be %s (not %s)",
94 (int)n, name, t, PL_op_desc[kid->op_type]));
98 S_no_bareword_allowed(pTHX_ OP *o)
100 qerror(Perl_mess(aTHX_
101 "Bareword \"%s\" not allowed while \"strict subs\" in use",
102 SvPV_nolen(cSVOPo_sv)));
105 /* "register" allocation */
108 Perl_pad_allocmy(pTHX_ char *name)
114 if (!(PL_in_my == KEY_our ||
116 (PL_hints & HINT_UTF8 && (name[1] & 0xc0) == 0xc0) ||
117 (name[1] == '_' && (int)strlen(name) > 2)))
119 if (!isPRINT(name[1]) || strchr("\t\n\r\f", name[1])) {
120 /* 1999-02-27 mjd@plover.com */
122 p = strchr(name, '\0');
123 /* The next block assumes the buffer is at least 205 chars
124 long. At present, it's always at least 256 chars. */
126 strcpy(name+200, "...");
132 /* Move everything else down one character */
133 for (; p-name > 2; p--)
135 name[2] = toCTRL(name[1]);
138 yyerror(Perl_form(aTHX_ "Can't use global %s in \"my\"",name));
140 if (ckWARN(WARN_MISC) && AvFILLp(PL_comppad_name) >= 0) {
141 SV **svp = AvARRAY(PL_comppad_name);
142 HV *ourstash = (PL_curstash ? PL_curstash : PL_defstash);
143 PADOFFSET top = AvFILLp(PL_comppad_name);
144 for (off = top; off > PL_comppad_name_floor; off--) {
146 && sv != &PL_sv_undef
147 && (SvIVX(sv) == PAD_MAX || SvIVX(sv) == 0)
148 && (PL_in_my != KEY_our
149 || ((SvFLAGS(sv) & SVpad_OUR) && GvSTASH(sv) == ourstash))
150 && strEQ(name, SvPVX(sv)))
152 Perl_warner(aTHX_ WARN_MISC,
153 "\"%s\" variable %s masks earlier declaration in same %s",
154 (PL_in_my == KEY_our ? "our" : "my"),
156 (SvIVX(sv) == PAD_MAX ? "scope" : "statement"));
161 if (PL_in_my == KEY_our) {
164 && sv != &PL_sv_undef
165 && ((SvFLAGS(sv) & SVpad_OUR) && GvSTASH(sv) == ourstash)
166 && strEQ(name, SvPVX(sv)))
168 Perl_warner(aTHX_ WARN_MISC,
169 "\"our\" variable %s redeclared", name);
170 Perl_warner(aTHX_ WARN_MISC,
171 "(Did you mean \"local\" instead of \"our\"?)\n");
178 off = pad_alloc(OP_PADSV, SVs_PADMY);
180 sv_upgrade(sv, SVt_PVNV);
182 if (PL_in_my_stash) {
184 yyerror(Perl_form(aTHX_ "Can't declare class for non-scalar %s in \"%s\"",
185 name, PL_in_my == KEY_our ? "our" : "my"));
187 (void)SvUPGRADE(sv, SVt_PVMG);
188 SvSTASH(sv) = (HV*)SvREFCNT_inc(PL_in_my_stash);
191 if (PL_in_my == KEY_our) {
192 (void)SvUPGRADE(sv, SVt_PVGV);
193 GvSTASH(sv) = (HV*)SvREFCNT_inc(PL_curstash ? (SV*)PL_curstash : (SV*)PL_defstash);
194 SvFLAGS(sv) |= SVpad_OUR;
196 av_store(PL_comppad_name, off, sv);
197 SvNVX(sv) = (NV)PAD_MAX;
198 SvIVX(sv) = 0; /* Not yet introduced--see newSTATEOP */
199 if (!PL_min_intro_pending)
200 PL_min_intro_pending = off;
201 PL_max_intro_pending = off;
203 av_store(PL_comppad, off, (SV*)newAV());
204 else if (*name == '%')
205 av_store(PL_comppad, off, (SV*)newHV());
206 SvPADMY_on(PL_curpad[off]);
211 S_pad_addlex(pTHX_ SV *proto_namesv)
213 SV *namesv = NEWSV(1103,0);
214 PADOFFSET newoff = pad_alloc(OP_PADSV, SVs_PADMY);
215 sv_upgrade(namesv, SVt_PVNV);
216 sv_setpv(namesv, SvPVX(proto_namesv));
217 av_store(PL_comppad_name, newoff, namesv);
218 SvNVX(namesv) = (NV)PL_curcop->cop_seq;
219 SvIVX(namesv) = PAD_MAX; /* A ref, intro immediately */
220 SvFAKE_on(namesv); /* A ref, not a real var */
221 if (SvFLAGS(proto_namesv) & SVpad_OUR) { /* An "our" variable */
222 SvFLAGS(namesv) |= SVpad_OUR;
223 (void)SvUPGRADE(namesv, SVt_PVGV);
224 GvSTASH(namesv) = (HV*)SvREFCNT_inc((SV*)GvSTASH(proto_namesv));
226 if (SvOBJECT(proto_namesv)) { /* A typed var */
228 (void)SvUPGRADE(namesv, SVt_PVMG);
229 SvSTASH(namesv) = (HV*)SvREFCNT_inc((SV*)SvSTASH(proto_namesv));
235 #define FINDLEX_NOSEARCH 1 /* don't search outer contexts */
238 S_pad_findlex(pTHX_ char *name, PADOFFSET newoff, U32 seq, CV* startcv,
239 I32 cx_ix, I32 saweval, U32 flags)
246 register PERL_CONTEXT *cx;
248 for (cv = startcv; cv; cv = CvOUTSIDE(cv)) {
249 AV *curlist = CvPADLIST(cv);
250 SV **svp = av_fetch(curlist, 0, FALSE);
253 if (!svp || *svp == &PL_sv_undef)
256 svp = AvARRAY(curname);
257 for (off = AvFILLp(curname); off > 0; off--) {
258 if ((sv = svp[off]) &&
259 sv != &PL_sv_undef &&
261 seq > I_32(SvNVX(sv)) &&
262 strEQ(SvPVX(sv), name))
273 return 0; /* don't clone from inactive stack frame */
277 oldpad = (AV*)AvARRAY(curlist)[depth];
278 oldsv = *av_fetch(oldpad, off, TRUE);
279 if (!newoff) { /* Not a mere clone operation. */
280 newoff = pad_addlex(sv);
281 if (CvANON(PL_compcv) || SvTYPE(PL_compcv) == SVt_PVFM) {
282 /* "It's closures all the way down." */
283 CvCLONE_on(PL_compcv);
285 if (CvANON(PL_compcv))
286 oldsv = Nullsv; /* no need to keep ref */
291 bcv && bcv != cv && !CvCLONE(bcv);
292 bcv = CvOUTSIDE(bcv))
295 /* install the missing pad entry in intervening
296 * nested subs and mark them cloneable.
297 * XXX fix pad_foo() to not use globals */
298 AV *ocomppad_name = PL_comppad_name;
299 AV *ocomppad = PL_comppad;
300 SV **ocurpad = PL_curpad;
301 AV *padlist = CvPADLIST(bcv);
302 PL_comppad_name = (AV*)AvARRAY(padlist)[0];
303 PL_comppad = (AV*)AvARRAY(padlist)[1];
304 PL_curpad = AvARRAY(PL_comppad);
306 PL_comppad_name = ocomppad_name;
307 PL_comppad = ocomppad;
312 if (ckWARN(WARN_CLOSURE)
313 && !CvUNIQUE(bcv) && !CvUNIQUE(cv))
315 Perl_warner(aTHX_ WARN_CLOSURE,
316 "Variable \"%s\" may be unavailable",
324 else if (!CvUNIQUE(PL_compcv)) {
325 if (ckWARN(WARN_CLOSURE) && !SvFAKE(sv) && !CvUNIQUE(cv))
326 Perl_warner(aTHX_ WARN_CLOSURE,
327 "Variable \"%s\" will not stay shared", name);
330 av_store(PL_comppad, newoff, SvREFCNT_inc(oldsv));
336 if (flags & FINDLEX_NOSEARCH)
339 /* Nothing in current lexical context--try eval's context, if any.
340 * This is necessary to let the perldb get at lexically scoped variables.
341 * XXX This will also probably interact badly with eval tree caching.
344 for (i = cx_ix; i >= 0; i--) {
346 switch (CxTYPE(cx)) {
348 if (i == 0 && saweval) {
349 seq = cxstack[saweval].blk_oldcop->cop_seq;
350 return pad_findlex(name, newoff, seq, PL_main_cv, -1, saweval, 0);
354 switch (cx->blk_eval.old_op_type) {
361 /* require/do must have their own scope */
370 if (PL_debstash && CvSTASH(cv) == PL_debstash) { /* ignore DB'* scope */
371 saweval = i; /* so we know where we were called from */
374 seq = cxstack[saweval].blk_oldcop->cop_seq;
375 return pad_findlex(name, newoff, seq, cv, i-1, saweval,FINDLEX_NOSEARCH);
383 Perl_pad_findmy(pTHX_ char *name)
389 SV **svp = AvARRAY(PL_comppad_name);
390 U32 seq = PL_cop_seqmax;
396 * Special case to get lexical (and hence per-thread) @_.
397 * XXX I need to find out how to tell at parse-time whether use
398 * of @_ should refer to a lexical (from a sub) or defgv (global
399 * scope and maybe weird sub-ish things like formats). See
400 * startsub in perly.y. It's possible that @_ could be lexical
401 * (at least from subs) even in non-threaded perl.
403 if (strEQ(name, "@_"))
404 return 0; /* success. (NOT_IN_PAD indicates failure) */
405 #endif /* USE_THREADS */
407 /* The one we're looking for is probably just before comppad_name_fill. */
408 for (off = AvFILLp(PL_comppad_name); off > 0; off--) {
409 if ((sv = svp[off]) &&
410 sv != &PL_sv_undef &&
413 seq > I_32(SvNVX(sv)))) &&
414 strEQ(SvPVX(sv), name))
416 if (SvIVX(sv) || SvFLAGS(sv) & SVpad_OUR)
417 return (PADOFFSET)off;
418 pendoff = off; /* this pending def. will override import */
422 outside = CvOUTSIDE(PL_compcv);
424 /* Check if if we're compiling an eval'', and adjust seq to be the
425 * eval's seq number. This depends on eval'' having a non-null
426 * CvOUTSIDE() while it is being compiled. The eval'' itself is
427 * identified by CvEVAL being true and CvGV being null. */
428 if (outside && CvEVAL(PL_compcv) && !CvGV(PL_compcv) && cxstack_ix >= 0) {
429 cx = &cxstack[cxstack_ix];
431 seq = cx->blk_oldcop->cop_seq;
434 /* See if it's in a nested scope */
435 off = pad_findlex(name, 0, seq, outside, cxstack_ix, 0, 0);
437 /* If there is a pending local definition, this new alias must die */
439 SvIVX(AvARRAY(PL_comppad_name)[off]) = seq;
440 return off; /* pad_findlex returns 0 for failure...*/
442 return NOT_IN_PAD; /* ...but we return NOT_IN_PAD for failure */
446 Perl_pad_leavemy(pTHX_ I32 fill)
450 SV **svp = AvARRAY(PL_comppad_name);
452 if (PL_min_intro_pending && fill < PL_min_intro_pending) {
453 for (off = PL_max_intro_pending; off >= PL_min_intro_pending; off--) {
454 if ((sv = svp[off]) && sv != &PL_sv_undef && ckWARN_d(WARN_INTERNAL))
455 Perl_warner(aTHX_ WARN_INTERNAL, "%s never introduced", SvPVX(sv));
458 /* "Deintroduce" my variables that are leaving with this scope. */
459 for (off = AvFILLp(PL_comppad_name); off > fill; off--) {
460 if ((sv = svp[off]) && sv != &PL_sv_undef && SvIVX(sv) == PAD_MAX)
461 SvIVX(sv) = PL_cop_seqmax;
466 Perl_pad_alloc(pTHX_ I32 optype, U32 tmptype)
472 if (AvARRAY(PL_comppad) != PL_curpad)
473 Perl_croak(aTHX_ "panic: pad_alloc");
474 if (PL_pad_reset_pending)
476 if (tmptype & SVs_PADMY) {
478 sv = *av_fetch(PL_comppad, AvFILLp(PL_comppad) + 1, TRUE);
479 } while (SvPADBUSY(sv)); /* need a fresh one */
480 retval = AvFILLp(PL_comppad);
483 SV **names = AvARRAY(PL_comppad_name);
484 SSize_t names_fill = AvFILLp(PL_comppad_name);
487 * "foreach" index vars temporarily become aliases to non-"my"
488 * values. Thus we must skip, not just pad values that are
489 * marked as current pad values, but also those with names.
491 if (++PL_padix <= names_fill &&
492 (sv = names[PL_padix]) && sv != &PL_sv_undef)
494 sv = *av_fetch(PL_comppad, PL_padix, TRUE);
495 if (!(SvFLAGS(sv) & (SVs_PADTMP|SVs_PADMY)) && !IS_PADGV(sv))
500 SvFLAGS(sv) |= tmptype;
501 PL_curpad = AvARRAY(PL_comppad);
503 DEBUG_X(PerlIO_printf(Perl_debug_log,
504 "0x%"UVxf" Pad 0x%"UVxf" alloc %ld for %s\n",
505 PTR2UV(thr), PTR2UV(PL_curpad),
506 (long) retval, PL_op_name[optype]));
508 DEBUG_X(PerlIO_printf(Perl_debug_log,
509 "Pad 0x%"UVxf" alloc %ld for %s\n",
511 (long) retval, PL_op_name[optype]));
512 #endif /* USE_THREADS */
513 return (PADOFFSET)retval;
517 Perl_pad_sv(pTHX_ PADOFFSET po)
521 DEBUG_X(PerlIO_printf(Perl_debug_log,
522 "0x%"UVxf" Pad 0x%"UVxf" sv %"IVdf"\n",
523 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
526 Perl_croak(aTHX_ "panic: pad_sv po");
527 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" sv %"IVdf"\n",
528 PTR2UV(PL_curpad), (IV)po));
529 #endif /* USE_THREADS */
530 return PL_curpad[po]; /* eventually we'll turn this into a macro */
534 Perl_pad_free(pTHX_ PADOFFSET po)
539 if (AvARRAY(PL_comppad) != PL_curpad)
540 Perl_croak(aTHX_ "panic: pad_free curpad");
542 Perl_croak(aTHX_ "panic: pad_free po");
544 DEBUG_X(PerlIO_printf(Perl_debug_log,
545 "0x%"UVxf" Pad 0x%"UVxf" free %"IVdf"\n",
546 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
548 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" free %"IVdf"\n",
549 PTR2UV(PL_curpad), (IV)po));
550 #endif /* USE_THREADS */
551 if (PL_curpad[po] && PL_curpad[po] != &PL_sv_undef) {
552 SvPADTMP_off(PL_curpad[po]);
554 SvREADONLY_off(PL_curpad[po]); /* could be a freed constant */
557 if ((I32)po < PL_padix)
562 Perl_pad_swipe(pTHX_ PADOFFSET po)
565 if (AvARRAY(PL_comppad) != PL_curpad)
566 Perl_croak(aTHX_ "panic: pad_swipe curpad");
568 Perl_croak(aTHX_ "panic: pad_swipe po");
570 DEBUG_X(PerlIO_printf(Perl_debug_log,
571 "0x%"UVxf" Pad 0x%"UVxf" swipe %"IVdf"\n",
572 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
574 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" swipe %"IVdf"\n",
575 PTR2UV(PL_curpad), (IV)po));
576 #endif /* USE_THREADS */
577 SvPADTMP_off(PL_curpad[po]);
578 PL_curpad[po] = NEWSV(1107,0);
579 SvPADTMP_on(PL_curpad[po]);
580 if ((I32)po < PL_padix)
584 /* XXX pad_reset() is currently disabled because it results in serious bugs.
585 * It causes pad temp TARGs to be shared between OPs. Since TARGs are pushed
586 * on the stack by OPs that use them, there are several ways to get an alias
587 * to a shared TARG. Such an alias will change randomly and unpredictably.
588 * We avoid doing this until we can think of a Better Way.
593 #ifdef USE_BROKEN_PAD_RESET
597 if (AvARRAY(PL_comppad) != PL_curpad)
598 Perl_croak(aTHX_ "panic: pad_reset curpad");
600 DEBUG_X(PerlIO_printf(Perl_debug_log,
601 "0x%"UVxf" Pad 0x%"UVxf" reset\n",
602 PTR2UV(thr), PTR2UV(PL_curpad)));
604 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" reset\n",
606 #endif /* USE_THREADS */
607 if (!PL_tainting) { /* Can't mix tainted and non-tainted temporaries. */
608 for (po = AvMAX(PL_comppad); po > PL_padix_floor; po--) {
609 if (PL_curpad[po] && !SvIMMORTAL(PL_curpad[po]))
610 SvPADTMP_off(PL_curpad[po]);
612 PL_padix = PL_padix_floor;
615 PL_pad_reset_pending = FALSE;
619 /* find_threadsv is not reentrant */
621 Perl_find_threadsv(pTHX_ const char *name)
627 /* We currently only handle names of a single character */
628 p = strchr(PL_threadsv_names, *name);
631 key = p - PL_threadsv_names;
632 MUTEX_LOCK(&thr->mutex);
633 svp = av_fetch(thr->threadsv, key, FALSE);
635 MUTEX_UNLOCK(&thr->mutex);
637 SV *sv = NEWSV(0, 0);
638 av_store(thr->threadsv, key, sv);
639 thr->threadsvp = AvARRAY(thr->threadsv);
640 MUTEX_UNLOCK(&thr->mutex);
642 * Some magic variables used to be automagically initialised
643 * in gv_fetchpv. Those which are now per-thread magicals get
644 * initialised here instead.
650 sv_setpv(sv, "\034");
651 sv_magic(sv, 0, 0, name, 1);
656 PL_sawampersand = TRUE;
670 /* XXX %! tied to Errno.pm needs to be added here.
671 * See gv_fetchpv(). */
675 sv_magic(sv, 0, 0, name, 1);
677 DEBUG_S(PerlIO_printf(Perl_error_log,
678 "find_threadsv: new SV %p for $%s%c\n",
679 sv, (*name < 32) ? "^" : "",
680 (*name < 32) ? toCTRL(*name) : *name));
684 #endif /* USE_THREADS */
689 Perl_op_free(pTHX_ OP *o)
691 register OP *kid, *nextkid;
694 if (!o || o->op_seq == (U16)-1)
697 if (o->op_private & OPpREFCOUNTED) {
698 switch (o->op_type) {
706 if (OpREFCNT_dec(o)) {
717 if (o->op_flags & OPf_KIDS) {
718 for (kid = cUNOPo->op_first; kid; kid = nextkid) {
719 nextkid = kid->op_sibling; /* Get before next freeing kid */
727 /* COP* is not cleared by op_clear() so that we may track line
728 * numbers etc even after null() */
729 if (type == OP_NEXTSTATE || type == OP_SETSTATE || type == OP_DBSTATE)
734 #ifdef PL_OP_SLAB_ALLOC
735 if ((char *) o == PL_OpPtr)
744 S_op_clear(pTHX_ OP *o)
746 switch (o->op_type) {
747 case OP_NULL: /* Was holding old type, if any. */
748 case OP_ENTEREVAL: /* Was holding hints. */
750 case OP_THREADSV: /* Was holding index into thr->threadsv AV. */
756 if (!(o->op_flags & OPf_SPECIAL))
759 #endif /* USE_THREADS */
761 if (!(o->op_flags & OPf_REF)
762 || (PL_check[o->op_type] != MEMBER_TO_FPTR(Perl_ck_ftst)))
769 if (cPADOPo->op_padix > 0) {
772 pad_swipe(cPADOPo->op_padix);
773 /* No GvIN_PAD_off(gv) here, because other references may still
774 * exist on the pad */
777 cPADOPo->op_padix = 0;
780 SvREFCNT_dec(cSVOPo->op_sv);
781 cSVOPo->op_sv = Nullsv;
785 SvREFCNT_dec(cSVOPo->op_sv);
786 cSVOPo->op_sv = Nullsv;
792 if (o->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
796 if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
797 SvREFCNT_dec(cSVOPo->op_sv);
798 cSVOPo->op_sv = Nullsv;
801 Safefree(cPVOPo->op_pv);
802 cPVOPo->op_pv = Nullch;
806 op_free(cPMOPo->op_pmreplroot);
810 if ((PADOFFSET)cPMOPo->op_pmreplroot) {
812 GV *gv = (GV*)PL_curpad[(PADOFFSET)cPMOPo->op_pmreplroot];
813 pad_swipe((PADOFFSET)cPMOPo->op_pmreplroot);
814 /* No GvIN_PAD_off(gv) here, because other references may still
815 * exist on the pad */
820 SvREFCNT_dec((SV*)cPMOPo->op_pmreplroot);
826 cPMOPo->op_pmreplroot = Nullop;
827 ReREFCNT_dec(cPMOPo->op_pmregexp);
828 cPMOPo->op_pmregexp = (REGEXP*)NULL;
832 if (o->op_targ > 0) {
833 pad_free(o->op_targ);
839 S_cop_free(pTHX_ COP* cop)
841 Safefree(cop->cop_label);
843 Safefree(CopFILE(cop)); /* XXXXX share in a pvtable? */
844 Safefree(CopSTASHPV(cop)); /* XXXXX share in a pvtable? */
846 /* NOTE: COP.cop_stash is not refcounted */
847 SvREFCNT_dec(CopFILEGV(cop));
849 if (! specialWARN(cop->cop_warnings))
850 SvREFCNT_dec(cop->cop_warnings);
856 if (o->op_type == OP_NULL)
859 o->op_targ = o->op_type;
860 o->op_type = OP_NULL;
861 o->op_ppaddr = PL_ppaddr[OP_NULL];
864 /* Contextualizers */
866 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
869 Perl_linklist(pTHX_ OP *o)
876 /* establish postfix order */
877 if (cUNOPo->op_first) {
878 o->op_next = LINKLIST(cUNOPo->op_first);
879 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
881 kid->op_next = LINKLIST(kid->op_sibling);
893 Perl_scalarkids(pTHX_ OP *o)
896 if (o && o->op_flags & OPf_KIDS) {
897 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
904 S_scalarboolean(pTHX_ OP *o)
906 if (o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST) {
908 if (ckWARN(WARN_SYNTAX)) {
909 line_t oldline = CopLINE(PL_curcop);
911 if (PL_copline != NOLINE)
912 CopLINE_set(PL_curcop, PL_copline);
913 Perl_warner(aTHX_ WARN_SYNTAX, "Found = in conditional, should be ==");
914 CopLINE_set(PL_curcop, oldline);
921 Perl_scalar(pTHX_ OP *o)
925 /* assumes no premature commitment */
926 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
927 || o->op_type == OP_RETURN)
932 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_SCALAR;
934 switch (o->op_type) {
936 if (o->op_private & OPpREPEAT_DOLIST)
937 null(((LISTOP*)cBINOPo->op_first)->op_first);
938 scalar(cBINOPo->op_first);
943 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
947 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
948 if (!kPMOP->op_pmreplroot)
949 deprecate("implicit split to @_");
957 if (o->op_flags & OPf_KIDS) {
958 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
964 kid = cLISTOPo->op_first;
966 while ((kid = kid->op_sibling)) {
972 WITH_THR(PL_curcop = &PL_compiling);
977 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
983 WITH_THR(PL_curcop = &PL_compiling);
990 Perl_scalarvoid(pTHX_ OP *o)
997 if (o->op_type == OP_NEXTSTATE
998 || o->op_type == OP_SETSTATE
999 || o->op_type == OP_DBSTATE
1000 || (o->op_type == OP_NULL && (o->op_targ == OP_NEXTSTATE
1001 || o->op_targ == OP_SETSTATE
1002 || o->op_targ == OP_DBSTATE)))
1005 PL_curcop = (COP*)o; /* for warning below */
1008 /* assumes no premature commitment */
1009 want = o->op_flags & OPf_WANT;
1010 if ((want && want != OPf_WANT_SCALAR) || PL_error_count
1011 || o->op_type == OP_RETURN)
1016 if ((o->op_private & OPpTARGET_MY)
1017 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
1019 return scalar(o); /* As if inside SASSIGN */
1022 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_VOID;
1024 switch (o->op_type) {
1026 if (!(PL_opargs[o->op_type] & OA_FOLDCONST))
1030 if (o->op_flags & OPf_STACKED)
1034 if (o->op_private == 4)
1076 case OP_GETSOCKNAME:
1077 case OP_GETPEERNAME:
1082 case OP_GETPRIORITY:
1105 if (!(o->op_private & (OPpLVAL_INTRO|OPpOUR_INTRO)))
1106 useless = PL_op_desc[o->op_type];
1113 if (!(o->op_private & (OPpLVAL_INTRO|OPpOUR_INTRO)) &&
1114 (!o->op_sibling || o->op_sibling->op_type != OP_READLINE))
1115 useless = "a variable";
1120 if (cSVOPo->op_private & OPpCONST_STRICT)
1121 no_bareword_allowed(o);
1124 if (ckWARN(WARN_VOID)) {
1125 useless = "a constant";
1126 if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
1128 else if (SvPOK(sv)) {
1129 if (strnEQ(SvPVX(sv), "di", 2) ||
1130 strnEQ(SvPVX(sv), "ds", 2) ||
1131 strnEQ(SvPVX(sv), "ig", 2))
1136 null(o); /* don't execute or even remember it */
1140 o->op_type = OP_PREINC; /* pre-increment is faster */
1141 o->op_ppaddr = PL_ppaddr[OP_PREINC];
1145 o->op_type = OP_PREDEC; /* pre-decrement is faster */
1146 o->op_ppaddr = PL_ppaddr[OP_PREDEC];
1152 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1157 if (o->op_flags & OPf_STACKED)
1165 if (!(o->op_flags & OPf_KIDS))
1174 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1181 /* all requires must return a boolean value */
1182 o->op_flags &= ~OPf_WANT;
1185 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
1186 if (!kPMOP->op_pmreplroot)
1187 deprecate("implicit split to @_");
1193 if (ckWARN(WARN_VOID))
1194 Perl_warner(aTHX_ WARN_VOID, "Useless use of %s in void context", useless);
1200 Perl_listkids(pTHX_ OP *o)
1203 if (o && o->op_flags & OPf_KIDS) {
1204 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1211 Perl_list(pTHX_ OP *o)
1215 /* assumes no premature commitment */
1216 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
1217 || o->op_type == OP_RETURN)
1222 if ((o->op_private & OPpTARGET_MY)
1223 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
1225 return o; /* As if inside SASSIGN */
1228 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_LIST;
1230 switch (o->op_type) {
1233 list(cBINOPo->op_first);
1238 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1246 if (!(o->op_flags & OPf_KIDS))
1248 if (!o->op_next && cUNOPo->op_first->op_type == OP_FLOP) {
1249 list(cBINOPo->op_first);
1250 return gen_constant_list(o);
1257 kid = cLISTOPo->op_first;
1259 while ((kid = kid->op_sibling)) {
1260 if (kid->op_sibling)
1265 WITH_THR(PL_curcop = &PL_compiling);
1269 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
1270 if (kid->op_sibling)
1275 WITH_THR(PL_curcop = &PL_compiling);
1278 /* all requires must return a boolean value */
1279 o->op_flags &= ~OPf_WANT;
1286 Perl_scalarseq(pTHX_ OP *o)
1291 if (o->op_type == OP_LINESEQ ||
1292 o->op_type == OP_SCOPE ||
1293 o->op_type == OP_LEAVE ||
1294 o->op_type == OP_LEAVETRY)
1297 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
1298 if (kid->op_sibling) {
1302 PL_curcop = &PL_compiling;
1304 o->op_flags &= ~OPf_PARENS;
1305 if (PL_hints & HINT_BLOCK_SCOPE)
1306 o->op_flags |= OPf_PARENS;
1309 o = newOP(OP_STUB, 0);
1314 S_modkids(pTHX_ OP *o, I32 type)
1317 if (o && o->op_flags & OPf_KIDS) {
1318 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1325 Perl_mod(pTHX_ OP *o, I32 type)
1331 if (!o || PL_error_count)
1334 if ((o->op_private & OPpTARGET_MY)
1335 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
1340 switch (o->op_type) {
1345 if (!(o->op_private & (OPpCONST_ARYBASE)))
1347 if (PL_eval_start && PL_eval_start->op_type == OP_CONST) {
1348 PL_compiling.cop_arybase = (I32)SvIV(cSVOPx(PL_eval_start)->op_sv);
1352 SAVEI32(PL_compiling.cop_arybase);
1353 PL_compiling.cop_arybase = 0;
1355 else if (type == OP_REFGEN)
1358 Perl_croak(aTHX_ "That use of $[ is unsupported");
1361 if (o->op_flags & OPf_PARENS)
1365 if ((type == OP_UNDEF || type == OP_REFGEN) &&
1366 !(o->op_flags & OPf_STACKED)) {
1367 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1368 o->op_ppaddr = PL_ppaddr[OP_RV2CV];
1369 assert(cUNOPo->op_first->op_type == OP_NULL);
1370 null(((LISTOP*)cUNOPo->op_first)->op_first);/* disable pushmark */
1373 else { /* lvalue subroutine call */
1374 o->op_private |= OPpLVAL_INTRO;
1375 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN) {
1376 /* Backward compatibility mode: */
1377 o->op_private |= OPpENTERSUB_INARGS;
1380 else { /* Compile-time error message: */
1381 OP *kid = cUNOPo->op_first;
1385 if (kid->op_type == OP_PUSHMARK)
1387 if (kid->op_type != OP_NULL || kid->op_targ != OP_LIST)
1389 "panic: unexpected lvalue entersub "
1390 "args: type/targ %ld:%ld",
1391 (long)kid->op_type,kid->op_targ);
1392 kid = kLISTOP->op_first;
1394 while (kid->op_sibling)
1395 kid = kid->op_sibling;
1396 if (!(kid->op_type == OP_NULL && kid->op_targ == OP_RV2CV)) {
1398 if (kid->op_type == OP_METHOD_NAMED
1399 || kid->op_type == OP_METHOD)
1403 if (kid->op_sibling || kid->op_next != kid) {
1404 yyerror("panic: unexpected optree near method call");
1408 NewOp(1101, newop, 1, UNOP);
1409 newop->op_type = OP_RV2CV;
1410 newop->op_ppaddr = PL_ppaddr[OP_RV2CV];
1411 newop->op_first = Nullop;
1412 newop->op_next = (OP*)newop;
1413 kid->op_sibling = (OP*)newop;
1414 newop->op_private |= OPpLVAL_INTRO;
1418 if (kid->op_type != OP_RV2CV)
1420 "panic: unexpected lvalue entersub "
1421 "entry via type/targ %ld:%ld",
1422 (long)kid->op_type,kid->op_targ);
1423 kid->op_private |= OPpLVAL_INTRO;
1424 break; /* Postpone until runtime */
1428 kid = kUNOP->op_first;
1429 if (kid->op_type == OP_NULL && kid->op_targ == OP_RV2SV)
1430 kid = kUNOP->op_first;
1431 if (kid->op_type == OP_NULL)
1433 "Unexpected constant lvalue entersub "
1434 "entry via type/targ %ld:%ld",
1435 (long)kid->op_type,kid->op_targ);
1436 if (kid->op_type != OP_GV) {
1437 /* Restore RV2CV to check lvalueness */
1439 if (kid->op_next && kid->op_next != kid) { /* Happens? */
1440 okid->op_next = kid->op_next;
1441 kid->op_next = okid;
1444 okid->op_next = Nullop;
1445 okid->op_type = OP_RV2CV;
1447 okid->op_ppaddr = PL_ppaddr[OP_RV2CV];
1448 okid->op_private |= OPpLVAL_INTRO;
1452 cv = GvCV(kGVOP_gv);
1462 /* grep, foreach, subcalls, refgen */
1463 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
1465 yyerror(Perl_form(aTHX_ "Can't modify %s in %s",
1466 (o->op_type == OP_NULL && (o->op_flags & OPf_SPECIAL)
1468 : (o->op_type == OP_ENTERSUB
1469 ? "non-lvalue subroutine call"
1470 : PL_op_desc[o->op_type])),
1471 type ? PL_op_desc[type] : "local"));
1485 case OP_RIGHT_SHIFT:
1494 if (!(o->op_flags & OPf_STACKED))
1500 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1506 if (!type && cUNOPo->op_first->op_type != OP_GV)
1507 Perl_croak(aTHX_ "Can't localize through a reference");
1508 if (type == OP_REFGEN && o->op_flags & OPf_PARENS) {
1509 PL_modcount = 10000;
1510 return o; /* Treat \(@foo) like ordinary list. */
1514 if (scalar_mod_type(o, type))
1516 ref(cUNOPo->op_first, o->op_type);
1525 PL_modcount = 10000;
1528 if (!type && cUNOPo->op_first->op_type != OP_GV)
1529 Perl_croak(aTHX_ "Can't localize through a reference");
1530 ref(cUNOPo->op_first, o->op_type);
1534 PL_hints |= HINT_BLOCK_SCOPE;
1544 PL_modcount = 10000;
1545 if (type == OP_REFGEN && o->op_flags & OPf_PARENS)
1546 return o; /* Treat \(@foo) like ordinary list. */
1547 if (scalar_mod_type(o, type))
1553 Perl_croak(aTHX_ "Can't localize lexical variable %s",
1554 SvPV(*av_fetch(PL_comppad_name, o->op_targ, 4), n_a));
1559 PL_modcount++; /* XXX ??? */
1561 #endif /* USE_THREADS */
1567 if (type != OP_SASSIGN)
1571 if (o->op_private == 4) /* don't allow 4 arg substr as lvalue */
1577 pad_free(o->op_targ);
1578 o->op_targ = pad_alloc(o->op_type, SVs_PADMY);
1579 assert(SvTYPE(PAD_SV(o->op_targ)) == SVt_NULL);
1580 if (o->op_flags & OPf_KIDS)
1581 mod(cBINOPo->op_first->op_sibling, type);
1586 ref(cBINOPo->op_first, o->op_type);
1587 if (type == OP_ENTERSUB &&
1588 !(o->op_private & (OPpLVAL_INTRO | OPpDEREF)))
1589 o->op_private |= OPpLVAL_DEFER;
1596 if (o->op_flags & OPf_KIDS)
1597 mod(cLISTOPo->op_last, type);
1601 if (o->op_flags & OPf_SPECIAL) /* do BLOCK */
1603 else if (!(o->op_flags & OPf_KIDS))
1605 if (o->op_targ != OP_LIST) {
1606 mod(cBINOPo->op_first, type);
1611 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1615 o->op_flags |= OPf_MOD;
1617 if (type == OP_AASSIGN || type == OP_SASSIGN)
1618 o->op_flags |= OPf_SPECIAL|OPf_REF;
1620 o->op_private |= OPpLVAL_INTRO;
1621 o->op_flags &= ~OPf_SPECIAL;
1622 PL_hints |= HINT_BLOCK_SCOPE;
1624 else if (type != OP_GREPSTART && type != OP_ENTERSUB)
1625 o->op_flags |= OPf_REF;
1630 S_scalar_mod_type(pTHX_ OP *o, I32 type)
1634 if (o->op_type == OP_RV2GV)
1658 case OP_RIGHT_SHIFT:
1677 S_is_handle_constructor(pTHX_ OP *o, I32 argnum)
1679 switch (o->op_type) {
1687 case OP_SELECT: /* XXX c.f. SelectSaver.pm */
1700 Perl_refkids(pTHX_ OP *o, I32 type)
1703 if (o && o->op_flags & OPf_KIDS) {
1704 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1711 Perl_ref(pTHX_ OP *o, I32 type)
1715 if (!o || PL_error_count)
1718 switch (o->op_type) {
1720 if ((type == OP_EXISTS || type == OP_DEFINED || type == OP_LOCK) &&
1721 !(o->op_flags & OPf_STACKED)) {
1722 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1723 o->op_ppaddr = PL_ppaddr[OP_RV2CV];
1724 assert(cUNOPo->op_first->op_type == OP_NULL);
1725 null(((LISTOP*)cUNOPo->op_first)->op_first); /* disable pushmark */
1726 o->op_flags |= OPf_SPECIAL;
1731 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1735 if (type == OP_DEFINED)
1736 o->op_flags |= OPf_SPECIAL; /* don't create GV */
1737 ref(cUNOPo->op_first, o->op_type);
1740 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1741 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1742 : type == OP_RV2HV ? OPpDEREF_HV
1744 o->op_flags |= OPf_MOD;
1749 o->op_flags |= OPf_MOD; /* XXX ??? */
1754 o->op_flags |= OPf_REF;
1757 if (type == OP_DEFINED)
1758 o->op_flags |= OPf_SPECIAL; /* don't create GV */
1759 ref(cUNOPo->op_first, o->op_type);
1764 o->op_flags |= OPf_REF;
1769 if (!(o->op_flags & OPf_KIDS))
1771 ref(cBINOPo->op_first, type);
1775 ref(cBINOPo->op_first, o->op_type);
1776 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1777 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1778 : type == OP_RV2HV ? OPpDEREF_HV
1780 o->op_flags |= OPf_MOD;
1788 if (!(o->op_flags & OPf_KIDS))
1790 ref(cLISTOPo->op_last, type);
1800 S_dup_attrlist(pTHX_ OP *o)
1804 /* An attrlist is either a simple OP_CONST or an OP_LIST with kids,
1805 * where the first kid is OP_PUSHMARK and the remaining ones
1806 * are OP_CONST. We need to push the OP_CONST values.
1808 if (o->op_type == OP_CONST)
1809 rop = newSVOP(OP_CONST, o->op_flags, SvREFCNT_inc(cSVOPo->op_sv));
1811 assert((o->op_type == OP_LIST) && (o->op_flags & OPf_KIDS));
1812 for (o = cLISTOPo->op_first; o; o=o->op_sibling) {
1813 if (o->op_type == OP_CONST)
1814 rop = append_elem(OP_LIST, rop,
1815 newSVOP(OP_CONST, o->op_flags,
1816 SvREFCNT_inc(cSVOPo->op_sv)));
1823 S_apply_attrs(pTHX_ HV *stash, SV *target, OP *attrs)
1827 /* fake up C<use attributes $pkg,$rv,@attrs> */
1828 ENTER; /* need to protect against side-effects of 'use' */
1830 if (stash && HvNAME(stash))
1831 stashsv = newSVpv(HvNAME(stash), 0);
1833 stashsv = &PL_sv_no;
1835 #define ATTRSMODULE "attributes"
1837 Perl_load_module(aTHX_ PERL_LOADMOD_IMPORT_OPS,
1838 newSVpvn(ATTRSMODULE, sizeof(ATTRSMODULE)-1),
1840 prepend_elem(OP_LIST,
1841 newSVOP(OP_CONST, 0, stashsv),
1842 prepend_elem(OP_LIST,
1843 newSVOP(OP_CONST, 0,
1845 dup_attrlist(attrs))));
1850 S_my_kid(pTHX_ OP *o, OP *attrs)
1855 if (!o || PL_error_count)
1859 if (type == OP_LIST) {
1860 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1862 } else if (type == OP_UNDEF) {
1864 } else if (type == OP_RV2SV || /* "our" declaration */
1866 type == OP_RV2HV) { /* XXX does this let anything illegal in? */
1867 o->op_private |= OPpOUR_INTRO;
1869 } else if (type != OP_PADSV &&
1872 type != OP_PUSHMARK)
1874 yyerror(Perl_form(aTHX_ "Can't declare %s in \"%s\"",
1875 PL_op_desc[o->op_type],
1876 PL_in_my == KEY_our ? "our" : "my"));
1879 else if (attrs && type != OP_PUSHMARK) {
1885 PL_in_my_stash = Nullhv;
1887 /* check for C<my Dog $spot> when deciding package */
1888 namesvp = av_fetch(PL_comppad_name, o->op_targ, FALSE);
1889 if (namesvp && *namesvp && SvOBJECT(*namesvp) && HvNAME(SvSTASH(*namesvp)))
1890 stash = SvSTASH(*namesvp);
1892 stash = PL_curstash;
1893 padsv = PAD_SV(o->op_targ);
1894 apply_attrs(stash, padsv, attrs);
1896 o->op_flags |= OPf_MOD;
1897 o->op_private |= OPpLVAL_INTRO;
1902 Perl_my_attrs(pTHX_ OP *o, OP *attrs)
1904 if (o->op_flags & OPf_PARENS)
1908 o = my_kid(o, attrs);
1910 PL_in_my_stash = Nullhv;
1915 Perl_my(pTHX_ OP *o)
1917 return my_kid(o, Nullop);
1921 Perl_sawparens(pTHX_ OP *o)
1924 o->op_flags |= OPf_PARENS;
1929 Perl_bind_match(pTHX_ I32 type, OP *left, OP *right)
1934 if (ckWARN(WARN_MISC) &&
1935 (left->op_type == OP_RV2AV ||
1936 left->op_type == OP_RV2HV ||
1937 left->op_type == OP_PADAV ||
1938 left->op_type == OP_PADHV)) {
1939 char *desc = PL_op_desc[(right->op_type == OP_SUBST ||
1940 right->op_type == OP_TRANS)
1941 ? right->op_type : OP_MATCH];
1942 const char *sample = ((left->op_type == OP_RV2AV ||
1943 left->op_type == OP_PADAV)
1944 ? "@array" : "%hash");
1945 Perl_warner(aTHX_ WARN_MISC,
1946 "Applying %s to %s will act on scalar(%s)",
1947 desc, sample, sample);
1950 if (right->op_type == OP_MATCH ||
1951 right->op_type == OP_SUBST ||
1952 right->op_type == OP_TRANS) {
1953 right->op_flags |= OPf_STACKED;
1954 if (right->op_type != OP_MATCH)
1955 left = mod(left, right->op_type);
1956 if (right->op_type == OP_TRANS)
1957 o = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
1959 o = prepend_elem(right->op_type, scalar(left), right);
1961 return newUNOP(OP_NOT, 0, scalar(o));
1965 return bind_match(type, left,
1966 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
1970 Perl_invert(pTHX_ OP *o)
1974 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
1975 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(o));
1979 Perl_scope(pTHX_ OP *o)
1982 if (o->op_flags & OPf_PARENS || PERLDB_NOOPT || PL_tainting) {
1983 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
1984 o->op_type = OP_LEAVE;
1985 o->op_ppaddr = PL_ppaddr[OP_LEAVE];
1988 if (o->op_type == OP_LINESEQ) {
1990 o->op_type = OP_SCOPE;
1991 o->op_ppaddr = PL_ppaddr[OP_SCOPE];
1992 kid = ((LISTOP*)o)->op_first;
1993 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE)
1997 o = newLISTOP(OP_SCOPE, 0, o, Nullop);
2004 Perl_save_hints(pTHX)
2007 SAVESPTR(GvHV(PL_hintgv));
2008 GvHV(PL_hintgv) = newHVhv(GvHV(PL_hintgv));
2009 SAVEFREESV(GvHV(PL_hintgv));
2013 Perl_block_start(pTHX_ int full)
2016 int retval = PL_savestack_ix;
2018 SAVEI32(PL_comppad_name_floor);
2019 PL_comppad_name_floor = AvFILLp(PL_comppad_name);
2021 PL_comppad_name_fill = PL_comppad_name_floor;
2022 if (PL_comppad_name_floor < 0)
2023 PL_comppad_name_floor = 0;
2024 SAVEI32(PL_min_intro_pending);
2025 SAVEI32(PL_max_intro_pending);
2026 PL_min_intro_pending = 0;
2027 SAVEI32(PL_comppad_name_fill);
2028 SAVEI32(PL_padix_floor);
2029 PL_padix_floor = PL_padix;
2030 PL_pad_reset_pending = FALSE;
2032 PL_hints &= ~HINT_BLOCK_SCOPE;
2033 SAVESPTR(PL_compiling.cop_warnings);
2034 if (! specialWARN(PL_compiling.cop_warnings)) {
2035 PL_compiling.cop_warnings = newSVsv(PL_compiling.cop_warnings) ;
2036 SAVEFREESV(PL_compiling.cop_warnings) ;
2042 Perl_block_end(pTHX_ I32 floor, OP *seq)
2045 int needblockscope = PL_hints & HINT_BLOCK_SCOPE;
2046 OP* retval = scalarseq(seq);
2048 PL_pad_reset_pending = FALSE;
2049 PL_compiling.op_private = PL_hints;
2051 PL_hints |= HINT_BLOCK_SCOPE; /* propagate out */
2052 pad_leavemy(PL_comppad_name_fill);
2061 OP *o = newOP(OP_THREADSV, 0);
2062 o->op_targ = find_threadsv("_");
2065 return newSVREF(newGVOP(OP_GV, 0, PL_defgv));
2066 #endif /* USE_THREADS */
2070 Perl_newPROG(pTHX_ OP *o)
2076 PL_eval_root = newUNOP(OP_LEAVEEVAL,
2077 ((PL_in_eval & EVAL_KEEPERR)
2078 ? OPf_SPECIAL : 0), o);
2079 PL_eval_start = linklist(PL_eval_root);
2080 PL_eval_root->op_private |= OPpREFCOUNTED;
2081 OpREFCNT_set(PL_eval_root, 1);
2082 PL_eval_root->op_next = 0;
2083 peep(PL_eval_start);
2088 PL_main_root = scope(sawparens(scalarvoid(o)));
2089 PL_curcop = &PL_compiling;
2090 PL_main_start = LINKLIST(PL_main_root);
2091 PL_main_root->op_private |= OPpREFCOUNTED;
2092 OpREFCNT_set(PL_main_root, 1);
2093 PL_main_root->op_next = 0;
2094 peep(PL_main_start);
2097 /* Register with debugger */
2099 CV *cv = get_cv("DB::postponed", FALSE);
2103 XPUSHs((SV*)CopFILEGV(&PL_compiling));
2105 call_sv((SV*)cv, G_DISCARD);
2112 Perl_localize(pTHX_ OP *o, I32 lex)
2114 if (o->op_flags & OPf_PARENS)
2118 if (ckWARN(WARN_PARENTHESIS) && PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == ',') {
2120 for (s = PL_bufptr; *s && (isALNUM(*s) || (*s & 0x80) || strchr("@$%, ",*s)); s++) ;
2121 if (*s == ';' || *s == '=')
2122 Perl_warner(aTHX_ WARN_PARENTHESIS,
2123 "Parentheses missing around \"%s\" list",
2124 lex ? (PL_in_my == KEY_our ? "our" : "my") : "local");
2130 o = mod(o, OP_NULL); /* a bit kludgey */
2132 PL_in_my_stash = Nullhv;
2137 Perl_jmaybe(pTHX_ OP *o)
2139 if (o->op_type == OP_LIST) {
2142 o2 = newOP(OP_THREADSV, 0);
2143 o2->op_targ = find_threadsv(";");
2145 o2 = newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
2146 #endif /* USE_THREADS */
2147 o = convert(OP_JOIN, 0, prepend_elem(OP_LIST, o2, o));
2153 Perl_fold_constants(pTHX_ register OP *o)
2157 I32 type = o->op_type;
2160 if (PL_opargs[type] & OA_RETSCALAR)
2162 if (PL_opargs[type] & OA_TARGET && !o->op_targ)
2163 o->op_targ = pad_alloc(type, SVs_PADTMP);
2165 /* integerize op, unless it happens to be C<-foo>.
2166 * XXX should pp_i_negate() do magic string negation instead? */
2167 if ((PL_opargs[type] & OA_OTHERINT) && (PL_hints & HINT_INTEGER)
2168 && !(type == OP_NEGATE && cUNOPo->op_first->op_type == OP_CONST
2169 && (cUNOPo->op_first->op_private & OPpCONST_BARE)))
2171 o->op_ppaddr = PL_ppaddr[type = ++(o->op_type)];
2174 if (!(PL_opargs[type] & OA_FOLDCONST))
2179 /* XXX might want a ck_negate() for this */
2180 cUNOPo->op_first->op_private &= ~OPpCONST_STRICT;
2193 if (o->op_private & OPpLOCALE)
2198 goto nope; /* Don't try to run w/ errors */
2200 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
2201 if ((curop->op_type != OP_CONST ||
2202 (curop->op_private & OPpCONST_BARE)) &&
2203 curop->op_type != OP_LIST &&
2204 curop->op_type != OP_SCALAR &&
2205 curop->op_type != OP_NULL &&
2206 curop->op_type != OP_PUSHMARK)
2212 curop = LINKLIST(o);
2216 sv = *(PL_stack_sp--);
2217 if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
2218 pad_swipe(o->op_targ);
2219 else if (SvTEMP(sv)) { /* grab mortal temp? */
2220 (void)SvREFCNT_inc(sv);
2224 if (type == OP_RV2GV)
2225 return newGVOP(OP_GV, 0, (GV*)sv);
2227 /* try to smush double to int, but don't smush -2.0 to -2 */
2228 if ((SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK)) == SVf_NOK &&
2232 if ((NV)iv == SvNV(sv)) {
2237 SvIOK_off(sv); /* undo SvIV() damage */
2239 return newSVOP(OP_CONST, 0, sv);
2243 if (!(PL_opargs[type] & OA_OTHERINT))
2246 if (!(PL_hints & HINT_INTEGER)) {
2247 if (type == OP_MODULO
2248 || type == OP_DIVIDE
2249 || !(o->op_flags & OPf_KIDS))
2254 for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
2255 if (curop->op_type == OP_CONST) {
2256 if (SvIOK(((SVOP*)curop)->op_sv))
2260 if (PL_opargs[curop->op_type] & OA_RETINTEGER)
2264 o->op_ppaddr = PL_ppaddr[++(o->op_type)];
2271 Perl_gen_constant_list(pTHX_ register OP *o)
2275 I32 oldtmps_floor = PL_tmps_floor;
2279 return o; /* Don't attempt to run with errors */
2281 PL_op = curop = LINKLIST(o);
2288 PL_tmps_floor = oldtmps_floor;
2290 o->op_type = OP_RV2AV;
2291 o->op_ppaddr = PL_ppaddr[OP_RV2AV];
2292 curop = ((UNOP*)o)->op_first;
2293 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*PL_stack_sp--));
2300 Perl_convert(pTHX_ I32 type, I32 flags, OP *o)
2305 if (!o || o->op_type != OP_LIST)
2306 o = newLISTOP(OP_LIST, 0, o, Nullop);
2308 o->op_flags &= ~OPf_WANT;
2310 if (!(PL_opargs[type] & OA_MARK))
2311 null(cLISTOPo->op_first);
2314 o->op_ppaddr = PL_ppaddr[type];
2315 o->op_flags |= flags;
2317 o = CHECKOP(type, o);
2318 if (o->op_type != type)
2321 if (cLISTOPo->op_children < 7) {
2322 /* XXX do we really need to do this if we're done appending?? */
2323 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
2325 cLISTOPo->op_last = last; /* in case check substituted last arg */
2328 return fold_constants(o);
2331 /* List constructors */
2334 Perl_append_elem(pTHX_ I32 type, OP *first, OP *last)
2342 if (first->op_type != type
2343 || (type == OP_LIST && (first->op_flags & OPf_PARENS)))
2345 return newLISTOP(type, 0, first, last);
2348 if (first->op_flags & OPf_KIDS)
2349 ((LISTOP*)first)->op_last->op_sibling = last;
2351 first->op_flags |= OPf_KIDS;
2352 ((LISTOP*)first)->op_first = last;
2354 ((LISTOP*)first)->op_last = last;
2355 ((LISTOP*)first)->op_children++;
2360 Perl_append_list(pTHX_ I32 type, LISTOP *first, LISTOP *last)
2368 if (first->op_type != type)
2369 return prepend_elem(type, (OP*)first, (OP*)last);
2371 if (last->op_type != type)
2372 return append_elem(type, (OP*)first, (OP*)last);
2374 first->op_last->op_sibling = last->op_first;
2375 first->op_last = last->op_last;
2376 first->op_children += last->op_children;
2377 if (first->op_children)
2378 first->op_flags |= OPf_KIDS;
2380 #ifdef PL_OP_SLAB_ALLOC
2388 Perl_prepend_elem(pTHX_ I32 type, OP *first, OP *last)
2396 if (last->op_type == type) {
2397 if (type == OP_LIST) { /* already a PUSHMARK there */
2398 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
2399 ((LISTOP*)last)->op_first->op_sibling = first;
2402 if (!(last->op_flags & OPf_KIDS)) {
2403 ((LISTOP*)last)->op_last = first;
2404 last->op_flags |= OPf_KIDS;
2406 first->op_sibling = ((LISTOP*)last)->op_first;
2407 ((LISTOP*)last)->op_first = first;
2409 ((LISTOP*)last)->op_children++;
2413 return newLISTOP(type, 0, first, last);
2419 Perl_newNULLLIST(pTHX)
2421 return newOP(OP_STUB, 0);
2425 Perl_force_list(pTHX_ OP *o)
2427 if (!o || o->op_type != OP_LIST)
2428 o = newLISTOP(OP_LIST, 0, o, Nullop);
2434 Perl_newLISTOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
2438 NewOp(1101, listop, 1, LISTOP);
2440 listop->op_type = type;
2441 listop->op_ppaddr = PL_ppaddr[type];
2442 listop->op_children = (first != 0) + (last != 0);
2443 listop->op_flags = flags;
2447 else if (!first && last)
2450 first->op_sibling = last;
2451 listop->op_first = first;
2452 listop->op_last = last;
2453 if (type == OP_LIST) {
2455 pushop = newOP(OP_PUSHMARK, 0);
2456 pushop->op_sibling = first;
2457 listop->op_first = pushop;
2458 listop->op_flags |= OPf_KIDS;
2460 listop->op_last = pushop;
2462 else if (listop->op_children)
2463 listop->op_flags |= OPf_KIDS;
2469 Perl_newOP(pTHX_ I32 type, I32 flags)
2472 NewOp(1101, o, 1, OP);
2474 o->op_ppaddr = PL_ppaddr[type];
2475 o->op_flags = flags;
2478 o->op_private = 0 + (flags >> 8);
2479 if (PL_opargs[type] & OA_RETSCALAR)
2481 if (PL_opargs[type] & OA_TARGET)
2482 o->op_targ = pad_alloc(type, SVs_PADTMP);
2483 return CHECKOP(type, o);
2487 Perl_newUNOP(pTHX_ I32 type, I32 flags, OP *first)
2492 first = newOP(OP_STUB, 0);
2493 if (PL_opargs[type] & OA_MARK)
2494 first = force_list(first);
2496 NewOp(1101, unop, 1, UNOP);
2497 unop->op_type = type;
2498 unop->op_ppaddr = PL_ppaddr[type];
2499 unop->op_first = first;
2500 unop->op_flags = flags | OPf_KIDS;
2501 unop->op_private = 1 | (flags >> 8);
2502 unop = (UNOP*) CHECKOP(type, unop);
2506 return fold_constants((OP *) unop);
2510 Perl_newBINOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
2513 NewOp(1101, binop, 1, BINOP);
2516 first = newOP(OP_NULL, 0);
2518 binop->op_type = type;
2519 binop->op_ppaddr = PL_ppaddr[type];
2520 binop->op_first = first;
2521 binop->op_flags = flags | OPf_KIDS;
2524 binop->op_private = 1 | (flags >> 8);
2527 binop->op_private = 2 | (flags >> 8);
2528 first->op_sibling = last;
2531 binop = (BINOP*)CHECKOP(type, binop);
2532 if (binop->op_next || binop->op_type != type)
2535 binop->op_last = binop->op_first->op_sibling;
2537 return fold_constants((OP *)binop);
2541 utf8compare(const void *a, const void *b)
2544 for (i = 0; i < 10; i++) {
2545 if ((*(U8**)a)[i] < (*(U8**)b)[i])
2547 if ((*(U8**)a)[i] > (*(U8**)b)[i])
2554 Perl_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
2556 SV *tstr = ((SVOP*)expr)->op_sv;
2557 SV *rstr = ((SVOP*)repl)->op_sv;
2560 register U8 *t = (U8*)SvPV(tstr, tlen);
2561 register U8 *r = (U8*)SvPV(rstr, rlen);
2567 register short *tbl;
2569 complement = o->op_private & OPpTRANS_COMPLEMENT;
2570 del = o->op_private & OPpTRANS_DELETE;
2571 squash = o->op_private & OPpTRANS_SQUASH;
2573 if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
2574 SV* listsv = newSVpvn("# comment\n",10);
2576 U8* tend = t + tlen;
2577 U8* rend = r + rlen;
2592 I32 from_utf = o->op_private & OPpTRANS_FROM_UTF;
2593 I32 to_utf = o->op_private & OPpTRANS_TO_UTF;
2596 U8 tmpbuf[UTF8_MAXLEN];
2599 New(1109, cp, tlen, U8*);
2601 transv = newSVpvn("",0);
2610 qsort(cp, i, sizeof(U8*), utf8compare);
2611 for (j = 0; j < i; j++) {
2613 UV val = utf8_to_uv(s, &ulen);
2615 diff = val - nextmin;
2617 t = uv_to_utf8(tmpbuf,nextmin);
2618 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2620 t = uv_to_utf8(tmpbuf, val - 1);
2621 sv_catpvn(transv, "\377", 1);
2622 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2626 val = utf8_to_uv(s+1, &ulen);
2630 t = uv_to_utf8(tmpbuf,nextmin);
2631 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2632 t = uv_to_utf8(tmpbuf, 0x7fffffff);
2633 sv_catpvn(transv, "\377", 1);
2634 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2635 t = (U8*)SvPVX(transv);
2636 tlen = SvCUR(transv);
2639 else if (!rlen && !del) {
2640 r = t; rlen = tlen; rend = tend;
2643 if (to_utf && from_utf) { /* only counting characters */
2644 if (t == r || (tlen == rlen && memEQ(t, r, tlen)))
2645 o->op_private |= OPpTRANS_IDENTICAL;
2647 else { /* straight latin-1 translation */
2648 if (tlen == 4 && memEQ(t, "\0\377\303\277", 4) &&
2649 rlen == 4 && memEQ(r, "\0\377\303\277", 4))
2650 o->op_private |= OPpTRANS_IDENTICAL;
2654 while (t < tend || tfirst <= tlast) {
2655 /* see if we need more "t" chars */
2656 if (tfirst > tlast) {
2657 tfirst = (I32)utf8_to_uv(t, &ulen);
2659 if (t < tend && *t == 0xff) { /* illegal utf8 val indicates range */
2660 tlast = (I32)utf8_to_uv(++t, &ulen);
2667 /* now see if we need more "r" chars */
2668 if (rfirst > rlast) {
2670 rfirst = (I32)utf8_to_uv(r, &ulen);
2672 if (r < rend && *r == 0xff) { /* illegal utf8 val indicates range */
2673 rlast = (I32)utf8_to_uv(++r, &ulen);
2682 rfirst = rlast = 0xffffffff;
2686 /* now see which range will peter our first, if either. */
2687 tdiff = tlast - tfirst;
2688 rdiff = rlast - rfirst;
2695 if (rfirst == 0xffffffff) {
2696 diff = tdiff; /* oops, pretend rdiff is infinite */
2698 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t%04lx\tXXXX\n",
2699 (long)tfirst, (long)tlast);
2701 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t\tXXXX\n", (long)tfirst);
2705 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t%04lx\t%04lx\n",
2706 (long)tfirst, (long)(tfirst + diff),
2709 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t\t%04lx\n",
2710 (long)tfirst, (long)rfirst);
2712 if (rfirst + diff > max)
2713 max = rfirst + diff;
2718 else if (rfirst <= 0x800)
2719 grows |= (tfirst < 0x80);
2720 else if (rfirst <= 0x10000)
2721 grows |= (tfirst < 0x800);
2722 else if (rfirst <= 0x200000)
2723 grows |= (tfirst < 0x10000);
2724 else if (rfirst <= 0x4000000)
2725 grows |= (tfirst < 0x200000);
2726 else if (rfirst <= 0x80000000)
2727 grows |= (tfirst < 0x4000000);
2739 else if (max > 0xff)
2744 cSVOPo->op_sv = (SV*)swash_init("utf8", "", listsv, bits, none);
2745 SvREFCNT_dec(listsv);
2747 SvREFCNT_dec(transv);
2749 if (!del && havefinal)
2750 (void)hv_store((HV*)SvRV((cSVOPo->op_sv)), "FINAL", 5, newSViv((IV)final), 0);
2752 if (grows && to_utf)
2753 o->op_private |= OPpTRANS_GROWS;
2760 tbl = (short*)cPVOPo->op_pv;
2762 Zero(tbl, 256, short);
2763 for (i = 0; i < tlen; i++)
2765 for (i = 0, j = 0; i < 256; i++) {
2781 if (!rlen && !del) {
2784 o->op_private |= OPpTRANS_IDENTICAL;
2786 for (i = 0; i < 256; i++)
2788 for (i = 0, j = 0; i < tlen; i++,j++) {
2791 if (tbl[t[i]] == -1)
2797 if (tbl[t[i]] == -1)
2808 Perl_newPMOP(pTHX_ I32 type, I32 flags)
2813 NewOp(1101, pmop, 1, PMOP);
2814 pmop->op_type = type;
2815 pmop->op_ppaddr = PL_ppaddr[type];
2816 pmop->op_flags = flags;
2817 pmop->op_private = 0 | (flags >> 8);
2819 if (PL_hints & HINT_RE_TAINT)
2820 pmop->op_pmpermflags |= PMf_RETAINT;
2821 if (PL_hints & HINT_LOCALE)
2822 pmop->op_pmpermflags |= PMf_LOCALE;
2823 pmop->op_pmflags = pmop->op_pmpermflags;
2825 /* link into pm list */
2826 if (type != OP_TRANS && PL_curstash) {
2827 pmop->op_pmnext = HvPMROOT(PL_curstash);
2828 HvPMROOT(PL_curstash) = pmop;
2835 Perl_pmruntime(pTHX_ OP *o, OP *expr, OP *repl)
2840 I32 repl_has_vars = 0;
2842 if (o->op_type == OP_TRANS)
2843 return pmtrans(o, expr, repl);
2845 PL_hints |= HINT_BLOCK_SCOPE;
2848 if (expr->op_type == OP_CONST) {
2850 SV *pat = ((SVOP*)expr)->op_sv;
2851 char *p = SvPV(pat, plen);
2852 if ((o->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
2853 sv_setpvn(pat, "\\s+", 3);
2854 p = SvPV(pat, plen);
2855 pm->op_pmflags |= PMf_SKIPWHITE;
2857 if ((PL_hints & HINT_UTF8) || (SvUTF8(pat) && !(PL_hints & HINT_BYTE)))
2858 pm->op_pmdynflags |= PMdf_UTF8;
2859 pm->op_pmregexp = CALLREGCOMP(aTHX_ p, p + plen, pm);
2860 if (strEQ("\\s+", pm->op_pmregexp->precomp))
2861 pm->op_pmflags |= PMf_WHITE;
2865 if (PL_hints & HINT_UTF8)
2866 pm->op_pmdynflags |= PMdf_UTF8;
2867 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL))
2868 expr = newUNOP((!(PL_hints & HINT_RE_EVAL)
2870 : OP_REGCMAYBE),0,expr);
2872 NewOp(1101, rcop, 1, LOGOP);
2873 rcop->op_type = OP_REGCOMP;
2874 rcop->op_ppaddr = PL_ppaddr[OP_REGCOMP];
2875 rcop->op_first = scalar(expr);
2876 rcop->op_flags |= ((PL_hints & HINT_RE_EVAL)
2877 ? (OPf_SPECIAL | OPf_KIDS)
2879 rcop->op_private = 1;
2882 /* establish postfix order */
2883 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL)) {
2885 rcop->op_next = expr;
2886 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
2889 rcop->op_next = LINKLIST(expr);
2890 expr->op_next = (OP*)rcop;
2893 prepend_elem(o->op_type, scalar((OP*)rcop), o);
2898 if (pm->op_pmflags & PMf_EVAL) {
2900 if (CopLINE(PL_curcop) < PL_multi_end)
2901 CopLINE_set(PL_curcop, PL_multi_end);
2904 else if (repl->op_type == OP_THREADSV
2905 && strchr("&`'123456789+",
2906 PL_threadsv_names[repl->op_targ]))
2910 #endif /* USE_THREADS */
2911 else if (repl->op_type == OP_CONST)
2915 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
2916 if (PL_opargs[curop->op_type] & OA_DANGEROUS) {
2918 if (curop->op_type == OP_THREADSV) {
2920 if (strchr("&`'123456789+", curop->op_private))
2924 if (curop->op_type == OP_GV) {
2925 GV *gv = cGVOPx_gv(curop);
2927 if (strchr("&`'123456789+", *GvENAME(gv)))
2930 #endif /* USE_THREADS */
2931 else if (curop->op_type == OP_RV2CV)
2933 else if (curop->op_type == OP_RV2SV ||
2934 curop->op_type == OP_RV2AV ||
2935 curop->op_type == OP_RV2HV ||
2936 curop->op_type == OP_RV2GV) {
2937 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
2940 else if (curop->op_type == OP_PADSV ||
2941 curop->op_type == OP_PADAV ||
2942 curop->op_type == OP_PADHV ||
2943 curop->op_type == OP_PADANY) {
2946 else if (curop->op_type == OP_PUSHRE)
2947 ; /* Okay here, dangerous in newASSIGNOP */
2956 && (!pm->op_pmregexp
2957 || pm->op_pmregexp->reganch & ROPT_EVAL_SEEN))) {
2958 pm->op_pmflags |= PMf_CONST; /* const for long enough */
2959 pm->op_pmpermflags |= PMf_CONST; /* const for long enough */
2960 prepend_elem(o->op_type, scalar(repl), o);
2963 if (curop == repl && !pm->op_pmregexp) { /* Has variables. */
2964 pm->op_pmflags |= PMf_MAYBE_CONST;
2965 pm->op_pmpermflags |= PMf_MAYBE_CONST;
2967 NewOp(1101, rcop, 1, LOGOP);
2968 rcop->op_type = OP_SUBSTCONT;
2969 rcop->op_ppaddr = PL_ppaddr[OP_SUBSTCONT];
2970 rcop->op_first = scalar(repl);
2971 rcop->op_flags |= OPf_KIDS;
2972 rcop->op_private = 1;
2975 /* establish postfix order */
2976 rcop->op_next = LINKLIST(repl);
2977 repl->op_next = (OP*)rcop;
2979 pm->op_pmreplroot = scalar((OP*)rcop);
2980 pm->op_pmreplstart = LINKLIST(rcop);
2989 Perl_newSVOP(pTHX_ I32 type, I32 flags, SV *sv)
2992 NewOp(1101, svop, 1, SVOP);
2993 svop->op_type = type;
2994 svop->op_ppaddr = PL_ppaddr[type];
2996 svop->op_next = (OP*)svop;
2997 svop->op_flags = flags;
2998 if (PL_opargs[type] & OA_RETSCALAR)
3000 if (PL_opargs[type] & OA_TARGET)
3001 svop->op_targ = pad_alloc(type, SVs_PADTMP);
3002 return CHECKOP(type, svop);
3006 Perl_newPADOP(pTHX_ I32 type, I32 flags, SV *sv)
3009 NewOp(1101, padop, 1, PADOP);
3010 padop->op_type = type;
3011 padop->op_ppaddr = PL_ppaddr[type];
3012 padop->op_padix = pad_alloc(type, SVs_PADTMP);
3013 SvREFCNT_dec(PL_curpad[padop->op_padix]);
3014 PL_curpad[padop->op_padix] = sv;
3016 padop->op_next = (OP*)padop;
3017 padop->op_flags = flags;
3018 if (PL_opargs[type] & OA_RETSCALAR)
3020 if (PL_opargs[type] & OA_TARGET)
3021 padop->op_targ = pad_alloc(type, SVs_PADTMP);
3022 return CHECKOP(type, padop);
3026 Perl_newGVOP(pTHX_ I32 type, I32 flags, GV *gv)
3031 return newPADOP(type, flags, SvREFCNT_inc(gv));
3033 return newSVOP(type, flags, SvREFCNT_inc(gv));
3038 Perl_newPVOP(pTHX_ I32 type, I32 flags, char *pv)
3041 NewOp(1101, pvop, 1, PVOP);
3042 pvop->op_type = type;
3043 pvop->op_ppaddr = PL_ppaddr[type];
3045 pvop->op_next = (OP*)pvop;
3046 pvop->op_flags = flags;
3047 if (PL_opargs[type] & OA_RETSCALAR)
3049 if (PL_opargs[type] & OA_TARGET)
3050 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
3051 return CHECKOP(type, pvop);
3055 Perl_package(pTHX_ OP *o)
3060 save_hptr(&PL_curstash);
3061 save_item(PL_curstname);
3066 name = SvPV(sv, len);
3067 PL_curstash = gv_stashpvn(name,len,TRUE);
3068 sv_setpvn(PL_curstname, name, len);
3072 sv_setpv(PL_curstname,"<none>");
3073 PL_curstash = Nullhv;
3075 PL_hints |= HINT_BLOCK_SCOPE;
3076 PL_copline = NOLINE;
3081 Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *id, OP *arg)
3089 if (id->op_type != OP_CONST)
3090 Perl_croak(aTHX_ "Module name must be constant");
3094 if (version != Nullop) {
3095 SV *vesv = ((SVOP*)version)->op_sv;
3097 if (arg == Nullop && !SvNIOKp(vesv)) {
3104 if (version->op_type != OP_CONST || !SvNIOKp(vesv))
3105 Perl_croak(aTHX_ "Version number must be constant number");
3107 /* Make copy of id so we don't free it twice */
3108 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
3110 /* Fake up a method call to VERSION */
3111 meth = newSVpvn("VERSION",7);
3112 sv_upgrade(meth, SVt_PVIV);
3113 (void)SvIOK_on(meth);
3114 PERL_HASH(SvUVX(meth), SvPVX(meth), SvCUR(meth));
3115 veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
3116 append_elem(OP_LIST,
3117 prepend_elem(OP_LIST, pack, list(version)),
3118 newSVOP(OP_METHOD_NAMED, 0, meth)));
3122 /* Fake up an import/unimport */
3123 if (arg && arg->op_type == OP_STUB)
3124 imop = arg; /* no import on explicit () */
3125 else if (SvNIOKp(((SVOP*)id)->op_sv)) {
3126 imop = Nullop; /* use 5.0; */
3131 /* Make copy of id so we don't free it twice */
3132 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
3134 /* Fake up a method call to import/unimport */
3135 meth = aver ? newSVpvn("import",6) : newSVpvn("unimport", 8);;
3136 sv_upgrade(meth, SVt_PVIV);
3137 (void)SvIOK_on(meth);
3138 PERL_HASH(SvUVX(meth), SvPVX(meth), SvCUR(meth));
3139 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
3140 append_elem(OP_LIST,
3141 prepend_elem(OP_LIST, pack, list(arg)),
3142 newSVOP(OP_METHOD_NAMED, 0, meth)));
3145 /* Fake up a require, handle override, if any */
3146 gv = gv_fetchpv("require", FALSE, SVt_PVCV);
3147 if (!(gv && GvIMPORTED_CV(gv)))
3148 gv = gv_fetchpv("CORE::GLOBAL::require", FALSE, SVt_PVCV);
3150 if (gv && GvIMPORTED_CV(gv)) {
3151 rqop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
3152 append_elem(OP_LIST, id,
3153 scalar(newUNOP(OP_RV2CV, 0,
3158 rqop = newUNOP(OP_REQUIRE, 0, id);
3161 /* Fake up the BEGIN {}, which does its thing immediately. */
3163 newSVOP(OP_CONST, 0, newSVpvn("BEGIN", 5)),
3166 append_elem(OP_LINESEQ,
3167 append_elem(OP_LINESEQ,
3168 newSTATEOP(0, Nullch, rqop),
3169 newSTATEOP(0, Nullch, veop)),
3170 newSTATEOP(0, Nullch, imop) ));
3172 PL_hints |= HINT_BLOCK_SCOPE;
3173 PL_copline = NOLINE;
3178 Perl_load_module(pTHX_ U32 flags, SV *name, SV *ver, ...)
3181 va_start(args, ver);
3182 vload_module(flags, name, ver, &args);
3186 #ifdef PERL_IMPLICIT_CONTEXT
3188 Perl_load_module_nocontext(U32 flags, SV *name, SV *ver, ...)
3192 va_start(args, ver);
3193 vload_module(flags, name, ver, &args);
3199 Perl_vload_module(pTHX_ U32 flags, SV *name, SV *ver, va_list *args)
3201 OP *modname, *veop, *imop;
3203 modname = newSVOP(OP_CONST, 0, name);
3204 modname->op_private |= OPpCONST_BARE;
3206 veop = newSVOP(OP_CONST, 0, ver);
3210 if (flags & PERL_LOADMOD_NOIMPORT) {
3211 imop = sawparens(newNULLLIST());
3213 else if (flags & PERL_LOADMOD_IMPORT_OPS) {
3214 imop = va_arg(*args, OP*);
3219 sv = va_arg(*args, SV*);
3221 imop = append_elem(OP_LIST, imop, newSVOP(OP_CONST, 0, sv));
3222 sv = va_arg(*args, SV*);
3225 utilize(!(flags & PERL_LOADMOD_DENY), start_subparse(FALSE, 0),
3226 veop, modname, imop);
3230 Perl_dofile(pTHX_ OP *term)
3235 gv = gv_fetchpv("do", FALSE, SVt_PVCV);
3236 if (!(gv && GvIMPORTED_CV(gv)))
3237 gv = gv_fetchpv("CORE::GLOBAL::do", FALSE, SVt_PVCV);
3239 if (gv && GvIMPORTED_CV(gv)) {
3240 doop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
3241 append_elem(OP_LIST, term,
3242 scalar(newUNOP(OP_RV2CV, 0,
3247 doop = newUNOP(OP_DOFILE, 0, scalar(term));
3253 Perl_newSLICEOP(pTHX_ I32 flags, OP *subscript, OP *listval)
3255 return newBINOP(OP_LSLICE, flags,
3256 list(force_list(subscript)),
3257 list(force_list(listval)) );
3261 S_list_assignment(pTHX_ register OP *o)
3266 if (o->op_type == OP_NULL && o->op_flags & OPf_KIDS)
3267 o = cUNOPo->op_first;
3269 if (o->op_type == OP_COND_EXPR) {
3270 I32 t = list_assignment(cLOGOPo->op_first->op_sibling);
3271 I32 f = list_assignment(cLOGOPo->op_first->op_sibling->op_sibling);
3276 yyerror("Assignment to both a list and a scalar");
3280 if (o->op_type == OP_LIST || o->op_flags & OPf_PARENS ||
3281 o->op_type == OP_RV2AV || o->op_type == OP_RV2HV ||
3282 o->op_type == OP_ASLICE || o->op_type == OP_HSLICE)
3285 if (o->op_type == OP_PADAV || o->op_type == OP_PADHV)
3288 if (o->op_type == OP_RV2SV)
3295 Perl_newASSIGNOP(pTHX_ I32 flags, OP *left, I32 optype, OP *right)
3300 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN) {
3301 return newLOGOP(optype, 0,
3302 mod(scalar(left), optype),
3303 newUNOP(OP_SASSIGN, 0, scalar(right)));
3306 return newBINOP(optype, OPf_STACKED,
3307 mod(scalar(left), optype), scalar(right));
3311 if (list_assignment(left)) {
3316 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
3317 left = mod(left, OP_AASSIGN);
3325 curop = list(force_list(left));
3326 o = newBINOP(OP_AASSIGN, flags, list(force_list(right)), curop);
3327 o->op_private = 0 | (flags >> 8);
3328 for (curop = ((LISTOP*)curop)->op_first;
3329 curop; curop = curop->op_sibling)
3331 if (curop->op_type == OP_RV2HV &&
3332 ((UNOP*)curop)->op_first->op_type != OP_GV) {
3333 o->op_private |= OPpASSIGN_HASH;
3337 if (!(left->op_private & OPpLVAL_INTRO)) {
3340 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
3341 if (PL_opargs[curop->op_type] & OA_DANGEROUS) {
3342 if (curop->op_type == OP_GV) {
3343 GV *gv = cGVOPx_gv(curop);
3344 if (gv == PL_defgv || SvCUR(gv) == PL_generation)
3346 SvCUR(gv) = PL_generation;
3348 else if (curop->op_type == OP_PADSV ||
3349 curop->op_type == OP_PADAV ||
3350 curop->op_type == OP_PADHV ||
3351 curop->op_type == OP_PADANY) {
3352 SV **svp = AvARRAY(PL_comppad_name);
3353 SV *sv = svp[curop->op_targ];
3354 if (SvCUR(sv) == PL_generation)
3356 SvCUR(sv) = PL_generation; /* (SvCUR not used any more) */
3358 else if (curop->op_type == OP_RV2CV)
3360 else if (curop->op_type == OP_RV2SV ||
3361 curop->op_type == OP_RV2AV ||
3362 curop->op_type == OP_RV2HV ||
3363 curop->op_type == OP_RV2GV) {
3364 if (lastop->op_type != OP_GV) /* funny deref? */
3367 else if (curop->op_type == OP_PUSHRE) {
3368 if (((PMOP*)curop)->op_pmreplroot) {
3369 GV *gv = (GV*)((PMOP*)curop)->op_pmreplroot;
3370 if (gv == PL_defgv || SvCUR(gv) == PL_generation)
3372 SvCUR(gv) = PL_generation;
3381 o->op_private |= OPpASSIGN_COMMON;
3383 if (right && right->op_type == OP_SPLIT) {
3385 if ((tmpop = ((LISTOP*)right)->op_first) &&
3386 tmpop->op_type == OP_PUSHRE)
3388 PMOP *pm = (PMOP*)tmpop;
3389 if (left->op_type == OP_RV2AV &&
3390 !(left->op_private & OPpLVAL_INTRO) &&
3391 !(o->op_private & OPpASSIGN_COMMON) )
3393 tmpop = ((UNOP*)left)->op_first;
3394 if (tmpop->op_type == OP_GV && !pm->op_pmreplroot) {
3396 pm->op_pmreplroot = (OP*)cPADOPx(tmpop)->op_padix;
3397 cPADOPx(tmpop)->op_padix = 0; /* steal it */
3399 pm->op_pmreplroot = (OP*)cSVOPx(tmpop)->op_sv;
3400 cSVOPx(tmpop)->op_sv = Nullsv; /* steal it */
3402 pm->op_pmflags |= PMf_ONCE;
3403 tmpop = cUNOPo->op_first; /* to list (nulled) */
3404 tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */
3405 tmpop->op_sibling = Nullop; /* don't free split */
3406 right->op_next = tmpop->op_next; /* fix starting loc */
3407 op_free(o); /* blow off assign */
3408 right->op_flags &= ~OPf_WANT;
3409 /* "I don't know and I don't care." */
3414 if (PL_modcount < 10000 &&
3415 ((LISTOP*)right)->op_last->op_type == OP_CONST)
3417 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
3419 sv_setiv(sv, PL_modcount+1);
3427 right = newOP(OP_UNDEF, 0);
3428 if (right->op_type == OP_READLINE) {
3429 right->op_flags |= OPf_STACKED;
3430 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
3433 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
3434 o = newBINOP(OP_SASSIGN, flags,
3435 scalar(right), mod(scalar(left), OP_SASSIGN) );
3447 Perl_newSTATEOP(pTHX_ I32 flags, char *label, OP *o)
3450 U32 seq = intro_my();
3453 NewOp(1101, cop, 1, COP);
3454 if (PERLDB_LINE && CopLINE(PL_curcop) && PL_curstash != PL_debstash) {
3455 cop->op_type = OP_DBSTATE;
3456 cop->op_ppaddr = PL_ppaddr[ OP_DBSTATE ];
3459 cop->op_type = OP_NEXTSTATE;
3460 cop->op_ppaddr = PL_ppaddr[ OP_NEXTSTATE ];
3462 cop->op_flags = flags;
3463 cop->op_private = (PL_hints & HINT_BYTE);
3465 cop->op_private |= NATIVE_HINTS;
3467 PL_compiling.op_private = cop->op_private;
3468 cop->op_next = (OP*)cop;
3471 cop->cop_label = label;
3472 PL_hints |= HINT_BLOCK_SCOPE;
3475 cop->cop_arybase = PL_curcop->cop_arybase;
3476 if (specialWARN(PL_curcop->cop_warnings))
3477 cop->cop_warnings = PL_curcop->cop_warnings ;
3479 cop->cop_warnings = newSVsv(PL_curcop->cop_warnings) ;
3482 if (PL_copline == NOLINE)
3483 CopLINE_set(cop, CopLINE(PL_curcop));
3485 CopLINE_set(cop, PL_copline);
3486 PL_copline = NOLINE;
3489 CopFILE_set(cop, CopFILE(PL_curcop)); /* XXXXX share in a pvtable? */
3491 CopFILEGV_set(cop, (GV*)SvREFCNT_inc(CopFILEGV(PL_curcop)));
3493 CopSTASH_set(cop, PL_curstash);
3495 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3496 SV **svp = av_fetch(CopFILEAV(PL_curcop), (I32)CopLINE(cop), FALSE);
3497 if (svp && *svp != &PL_sv_undef && !SvIOK(*svp)) {
3498 (void)SvIOK_on(*svp);
3499 SvIVX(*svp) = PTR2IV(cop);
3503 return prepend_elem(OP_LINESEQ, (OP*)cop, o);
3506 /* "Introduce" my variables to visible status. */
3514 if (! PL_min_intro_pending)
3515 return PL_cop_seqmax;
3517 svp = AvARRAY(PL_comppad_name);
3518 for (i = PL_min_intro_pending; i <= PL_max_intro_pending; i++) {
3519 if ((sv = svp[i]) && sv != &PL_sv_undef && !SvIVX(sv)) {
3520 SvIVX(sv) = PAD_MAX; /* Don't know scope end yet. */
3521 SvNVX(sv) = (NV)PL_cop_seqmax;
3524 PL_min_intro_pending = 0;
3525 PL_comppad_name_fill = PL_max_intro_pending; /* Needn't search higher */
3526 return PL_cop_seqmax++;
3530 Perl_newLOGOP(pTHX_ I32 type, I32 flags, OP *first, OP *other)
3532 return new_logop(type, flags, &first, &other);
3536 S_new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp)
3541 OP *first = *firstp;
3542 OP *other = *otherp;
3544 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
3545 return newBINOP(type, flags, scalar(first), scalar(other));
3547 scalarboolean(first);
3548 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
3549 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
3550 if (type == OP_AND || type == OP_OR) {
3556 first = *firstp = cUNOPo->op_first;
3558 first->op_next = o->op_next;
3559 cUNOPo->op_first = Nullop;
3563 if (first->op_type == OP_CONST) {
3564 if (ckWARN(WARN_BAREWORD) && (first->op_private & OPpCONST_BARE))
3565 Perl_warner(aTHX_ WARN_BAREWORD, "Bareword found in conditional");
3566 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
3577 else if (first->op_type == OP_WANTARRAY) {
3583 else if (ckWARN(WARN_MISC) && (first->op_flags & OPf_KIDS)) {
3584 OP *k1 = ((UNOP*)first)->op_first;
3585 OP *k2 = k1->op_sibling;
3587 switch (first->op_type)
3590 if (k2 && k2->op_type == OP_READLINE
3591 && (k2->op_flags & OPf_STACKED)
3592 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3594 warnop = k2->op_type;
3599 if (k1->op_type == OP_READDIR
3600 || k1->op_type == OP_GLOB
3601 || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
3602 || k1->op_type == OP_EACH)
3604 warnop = ((k1->op_type == OP_NULL)
3605 ? k1->op_targ : k1->op_type);
3610 line_t oldline = CopLINE(PL_curcop);
3611 CopLINE_set(PL_curcop, PL_copline);
3612 Perl_warner(aTHX_ WARN_MISC,
3613 "Value of %s%s can be \"0\"; test with defined()",
3615 ((warnop == OP_READLINE || warnop == OP_GLOB)
3616 ? " construct" : "() operator"));
3617 CopLINE_set(PL_curcop, oldline);
3624 if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
3625 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
3627 NewOp(1101, logop, 1, LOGOP);
3629 logop->op_type = type;
3630 logop->op_ppaddr = PL_ppaddr[type];
3631 logop->op_first = first;
3632 logop->op_flags = flags | OPf_KIDS;
3633 logop->op_other = LINKLIST(other);
3634 logop->op_private = 1 | (flags >> 8);
3636 /* establish postfix order */
3637 logop->op_next = LINKLIST(first);
3638 first->op_next = (OP*)logop;
3639 first->op_sibling = other;
3641 o = newUNOP(OP_NULL, 0, (OP*)logop);
3648 Perl_newCONDOP(pTHX_ I32 flags, OP *first, OP *trueop, OP *falseop)
3656 return newLOGOP(OP_AND, 0, first, trueop);
3658 return newLOGOP(OP_OR, 0, first, falseop);
3660 scalarboolean(first);
3661 if (first->op_type == OP_CONST) {
3662 if (SvTRUE(((SVOP*)first)->op_sv)) {
3673 else if (first->op_type == OP_WANTARRAY) {
3677 NewOp(1101, logop, 1, LOGOP);
3678 logop->op_type = OP_COND_EXPR;
3679 logop->op_ppaddr = PL_ppaddr[OP_COND_EXPR];
3680 logop->op_first = first;
3681 logop->op_flags = flags | OPf_KIDS;
3682 logop->op_private = 1 | (flags >> 8);
3683 logop->op_other = LINKLIST(trueop);
3684 logop->op_next = LINKLIST(falseop);
3687 /* establish postfix order */
3688 start = LINKLIST(first);
3689 first->op_next = (OP*)logop;
3691 first->op_sibling = trueop;
3692 trueop->op_sibling = falseop;
3693 o = newUNOP(OP_NULL, 0, (OP*)logop);
3695 trueop->op_next = falseop->op_next = o;
3702 Perl_newRANGE(pTHX_ I32 flags, OP *left, OP *right)
3711 NewOp(1101, range, 1, LOGOP);
3713 range->op_type = OP_RANGE;
3714 range->op_ppaddr = PL_ppaddr[OP_RANGE];
3715 range->op_first = left;
3716 range->op_flags = OPf_KIDS;
3717 leftstart = LINKLIST(left);
3718 range->op_other = LINKLIST(right);
3719 range->op_private = 1 | (flags >> 8);
3721 left->op_sibling = right;
3723 range->op_next = (OP*)range;
3724 flip = newUNOP(OP_FLIP, flags, (OP*)range);
3725 flop = newUNOP(OP_FLOP, 0, flip);
3726 o = newUNOP(OP_NULL, 0, flop);
3728 range->op_next = leftstart;
3730 left->op_next = flip;
3731 right->op_next = flop;
3733 range->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
3734 sv_upgrade(PAD_SV(range->op_targ), SVt_PVNV);
3735 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
3736 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
3738 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
3739 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
3742 if (!flip->op_private || !flop->op_private)
3743 linklist(o); /* blow off optimizer unless constant */
3749 Perl_newLOOPOP(pTHX_ I32 flags, I32 debuggable, OP *expr, OP *block)
3754 int once = block && block->op_flags & OPf_SPECIAL &&
3755 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
3758 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
3759 return block; /* do {} while 0 does once */
3760 if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
3761 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB)) {
3762 expr = newUNOP(OP_DEFINED, 0,
3763 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
3764 } else if (expr->op_flags & OPf_KIDS) {
3765 OP *k1 = ((UNOP*)expr)->op_first;
3766 OP *k2 = (k1) ? k1->op_sibling : NULL;
3767 switch (expr->op_type) {
3769 if (k2 && k2->op_type == OP_READLINE
3770 && (k2->op_flags & OPf_STACKED)
3771 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3772 expr = newUNOP(OP_DEFINED, 0, expr);
3776 if (k1->op_type == OP_READDIR
3777 || k1->op_type == OP_GLOB
3778 || (k1->op_type == OP_NULL && k1->op_targ == OP_NULL)
3779 || k1->op_type == OP_EACH)
3780 expr = newUNOP(OP_DEFINED, 0, expr);
3786 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
3787 o = new_logop(OP_AND, 0, &expr, &listop);
3790 ((LISTOP*)listop)->op_last->op_next = LINKLIST(o);
3792 if (once && o != listop)
3793 o->op_next = ((LOGOP*)cUNOPo->op_first)->op_other;
3796 o = newUNOP(OP_NULL, 0, o); /* or do {} while 1 loses outer block */
3798 o->op_flags |= flags;
3800 o->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/
3805 Perl_newWHILEOP(pTHX_ I32 flags, I32 debuggable, LOOP *loop, I32 whileline, OP *expr, OP *block, OP *cont)
3815 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
3816 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB))) {
3817 expr = newUNOP(OP_DEFINED, 0,
3818 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
3819 } else if (expr && (expr->op_flags & OPf_KIDS)) {
3820 OP *k1 = ((UNOP*)expr)->op_first;
3821 OP *k2 = (k1) ? k1->op_sibling : NULL;
3822 switch (expr->op_type) {
3824 if (k2 && k2->op_type == OP_READLINE
3825 && (k2->op_flags & OPf_STACKED)
3826 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3827 expr = newUNOP(OP_DEFINED, 0, expr);
3831 if (k1->op_type == OP_READDIR
3832 || k1->op_type == OP_GLOB
3833 || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
3834 || k1->op_type == OP_EACH)
3835 expr = newUNOP(OP_DEFINED, 0, expr);
3841 block = newOP(OP_NULL, 0);
3843 block = scope(block);
3847 next = LINKLIST(cont);
3848 loopflags |= OPpLOOP_CONTINUE;
3851 cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
3852 if ((line_t)whileline != NOLINE) {
3853 PL_copline = whileline;
3854 cont = append_elem(OP_LINESEQ, cont,
3855 newSTATEOP(0, Nullch, Nullop));
3859 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
3860 redo = LINKLIST(listop);
3863 PL_copline = whileline;
3865 o = new_logop(OP_AND, 0, &expr, &listop);
3866 if (o == expr && o->op_type == OP_CONST && !SvTRUE(cSVOPo->op_sv)) {
3867 op_free(expr); /* oops, it's a while (0) */
3869 return Nullop; /* listop already freed by new_logop */
3872 ((LISTOP*)listop)->op_last->op_next = condop =
3873 (o == listop ? redo : LINKLIST(o));
3881 NewOp(1101,loop,1,LOOP);
3882 loop->op_type = OP_ENTERLOOP;
3883 loop->op_ppaddr = PL_ppaddr[OP_ENTERLOOP];
3884 loop->op_private = 0;
3885 loop->op_next = (OP*)loop;
3888 o = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, o);
3890 loop->op_redoop = redo;
3891 loop->op_lastop = o;
3892 o->op_private |= loopflags;
3895 loop->op_nextop = next;
3897 loop->op_nextop = o;
3899 o->op_flags |= flags;
3900 o->op_private |= (flags >> 8);
3905 Perl_newFOROP(pTHX_ I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
3913 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
3914 sv->op_type = OP_RV2GV;
3915 sv->op_ppaddr = PL_ppaddr[OP_RV2GV];
3917 else if (sv->op_type == OP_PADSV) { /* private variable */
3918 padoff = sv->op_targ;
3923 else if (sv->op_type == OP_THREADSV) { /* per-thread variable */
3924 padoff = sv->op_targ;
3926 iterflags |= OPf_SPECIAL;
3931 Perl_croak(aTHX_ "Can't use %s for loop variable", PL_op_desc[sv->op_type]);
3935 padoff = find_threadsv("_");
3936 iterflags |= OPf_SPECIAL;
3938 sv = newGVOP(OP_GV, 0, PL_defgv);
3941 if (expr->op_type == OP_RV2AV || expr->op_type == OP_PADAV) {
3942 expr = mod(force_list(scalar(ref(expr, OP_ITER))), OP_GREPSTART);
3943 iterflags |= OPf_STACKED;
3945 else if (expr->op_type == OP_NULL &&
3946 (expr->op_flags & OPf_KIDS) &&
3947 ((BINOP*)expr)->op_first->op_type == OP_FLOP)
3949 /* Basically turn for($x..$y) into the same as for($x,$y), but we
3950 * set the STACKED flag to indicate that these values are to be
3951 * treated as min/max values by 'pp_iterinit'.
3953 UNOP* flip = (UNOP*)((UNOP*)((BINOP*)expr)->op_first)->op_first;
3954 LOGOP* range = (LOGOP*) flip->op_first;
3955 OP* left = range->op_first;
3956 OP* right = left->op_sibling;
3959 range->op_flags &= ~OPf_KIDS;
3960 range->op_first = Nullop;
3962 listop = (LISTOP*)newLISTOP(OP_LIST, 0, left, right);
3963 listop->op_first->op_next = range->op_next;
3964 left->op_next = range->op_other;
3965 right->op_next = (OP*)listop;
3966 listop->op_next = listop->op_first;
3969 expr = (OP*)(listop);
3971 iterflags |= OPf_STACKED;
3974 expr = mod(force_list(expr), OP_GREPSTART);
3978 loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
3979 append_elem(OP_LIST, expr, scalar(sv))));
3980 assert(!loop->op_next);
3981 #ifdef PL_OP_SLAB_ALLOC
3984 NewOp(1234,tmp,1,LOOP);
3985 Copy(loop,tmp,1,LOOP);
3989 Renew(loop, 1, LOOP);
3991 loop->op_targ = padoff;
3992 wop = newWHILEOP(flags, 1, loop, forline, newOP(OP_ITER, 0), block, cont);
3993 PL_copline = forline;
3994 return newSTATEOP(0, label, wop);
3998 Perl_newLOOPEX(pTHX_ I32 type, OP *label)
4004 if (type != OP_GOTO || label->op_type == OP_CONST) {
4005 /* "last()" means "last" */
4006 if (label->op_type == OP_STUB && (label->op_flags & OPf_PARENS))
4007 o = newOP(type, OPf_SPECIAL);
4009 o = newPVOP(type, 0, savepv(label->op_type == OP_CONST
4010 ? SvPVx(((SVOP*)label)->op_sv, n_a)
4016 if (label->op_type == OP_ENTERSUB)
4017 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
4018 o = newUNOP(type, OPf_STACKED, label);
4020 PL_hints |= HINT_BLOCK_SCOPE;
4025 Perl_cv_undef(pTHX_ CV *cv)
4030 MUTEX_DESTROY(CvMUTEXP(cv));
4031 Safefree(CvMUTEXP(cv));
4034 #endif /* USE_THREADS */
4036 if (!CvXSUB(cv) && CvROOT(cv)) {
4038 if (CvDEPTH(cv) || (CvOWNER(cv) && CvOWNER(cv) != thr))
4039 Perl_croak(aTHX_ "Can't undef active subroutine");
4042 Perl_croak(aTHX_ "Can't undef active subroutine");
4043 #endif /* USE_THREADS */
4046 SAVEVPTR(PL_curpad);
4050 op_free(CvROOT(cv));
4051 CvROOT(cv) = Nullop;
4054 SvPOK_off((SV*)cv); /* forget prototype */
4056 SvREFCNT_dec(CvGV(cv));
4058 SvREFCNT_dec(CvOUTSIDE(cv));
4059 CvOUTSIDE(cv) = Nullcv;
4060 if (CvPADLIST(cv)) {
4061 /* may be during global destruction */
4062 if (SvREFCNT(CvPADLIST(cv))) {
4063 I32 i = AvFILLp(CvPADLIST(cv));
4065 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
4066 SV* sv = svp ? *svp : Nullsv;
4069 if (sv == (SV*)PL_comppad_name)
4070 PL_comppad_name = Nullav;
4071 else if (sv == (SV*)PL_comppad) {
4072 PL_comppad = Nullav;
4073 PL_curpad = Null(SV**);
4077 SvREFCNT_dec((SV*)CvPADLIST(cv));
4079 CvPADLIST(cv) = Nullav;
4084 S_cv_dump(pTHX_ CV *cv)
4087 CV *outside = CvOUTSIDE(cv);
4088 AV* padlist = CvPADLIST(cv);
4095 PerlIO_printf(Perl_debug_log,
4096 "\tCV=0x%"UVxf" (%s), OUTSIDE=0x%"UVxf" (%s)\n",
4098 (CvANON(cv) ? "ANON"
4099 : (cv == PL_main_cv) ? "MAIN"
4100 : CvUNIQUE(cv) ? "UNIQUE"
4101 : CvGV(cv) ? GvNAME(CvGV(cv)) : "UNDEFINED"),
4104 : CvANON(outside) ? "ANON"
4105 : (outside == PL_main_cv) ? "MAIN"
4106 : CvUNIQUE(outside) ? "UNIQUE"
4107 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
4112 pad_name = (AV*)*av_fetch(padlist, 0, FALSE);
4113 pad = (AV*)*av_fetch(padlist, 1, FALSE);
4114 pname = AvARRAY(pad_name);
4115 ppad = AvARRAY(pad);
4117 for (ix = 1; ix <= AvFILLp(pad_name); ix++) {
4118 if (SvPOK(pname[ix]))
4119 PerlIO_printf(Perl_debug_log,
4120 "\t%4d. 0x%"UVxf" (%s\"%s\" %"IVdf"-%"IVdf")\n",
4121 (int)ix, PTR2UV(ppad[ix]),
4122 SvFAKE(pname[ix]) ? "FAKE " : "",
4124 (IV)I_32(SvNVX(pname[ix])),
4127 #endif /* DEBUGGING */
4131 S_cv_clone2(pTHX_ CV *proto, CV *outside)
4136 AV* protopadlist = CvPADLIST(proto);
4137 AV* protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
4138 AV* protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
4139 SV** pname = AvARRAY(protopad_name);
4140 SV** ppad = AvARRAY(protopad);
4141 I32 fname = AvFILLp(protopad_name);
4142 I32 fpad = AvFILLp(protopad);
4146 assert(!CvUNIQUE(proto));
4150 SAVESPTR(PL_comppad_name);
4151 SAVESPTR(PL_compcv);
4153 cv = PL_compcv = (CV*)NEWSV(1104,0);
4154 sv_upgrade((SV *)cv, SvTYPE(proto));
4160 New(666, CvMUTEXP(cv), 1, perl_mutex);
4161 MUTEX_INIT(CvMUTEXP(cv));
4163 #endif /* USE_THREADS */
4164 CvFILE(cv) = CvFILE(proto);
4165 CvGV(cv) = (GV*)SvREFCNT_inc(CvGV(proto));
4166 CvSTASH(cv) = CvSTASH(proto);
4167 CvROOT(cv) = CvROOT(proto);
4168 CvSTART(cv) = CvSTART(proto);
4170 CvOUTSIDE(cv) = (CV*)SvREFCNT_inc(outside);
4173 sv_setpvn((SV*)cv, SvPVX(proto), SvCUR(proto));
4175 PL_comppad_name = newAV();
4176 for (ix = fname; ix >= 0; ix--)
4177 av_store(PL_comppad_name, ix, SvREFCNT_inc(pname[ix]));
4179 PL_comppad = newAV();
4181 comppadlist = newAV();
4182 AvREAL_off(comppadlist);
4183 av_store(comppadlist, 0, (SV*)PL_comppad_name);
4184 av_store(comppadlist, 1, (SV*)PL_comppad);
4185 CvPADLIST(cv) = comppadlist;
4186 av_fill(PL_comppad, AvFILLp(protopad));
4187 PL_curpad = AvARRAY(PL_comppad);
4189 av = newAV(); /* will be @_ */
4191 av_store(PL_comppad, 0, (SV*)av);
4192 AvFLAGS(av) = AVf_REIFY;
4194 for (ix = fpad; ix > 0; ix--) {
4195 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
4196 if (namesv && namesv != &PL_sv_undef) {
4197 char *name = SvPVX(namesv); /* XXX */
4198 if (SvFLAGS(namesv) & SVf_FAKE) { /* lexical from outside? */
4199 I32 off = pad_findlex(name, ix, SvIVX(namesv),
4200 CvOUTSIDE(cv), cxstack_ix, 0, 0);
4202 PL_curpad[ix] = SvREFCNT_inc(ppad[ix]);
4204 Perl_croak(aTHX_ "panic: cv_clone: %s", name);
4206 else { /* our own lexical */
4209 /* anon code -- we'll come back for it */
4210 sv = SvREFCNT_inc(ppad[ix]);
4212 else if (*name == '@')
4214 else if (*name == '%')
4223 else if (IS_PADGV(ppad[ix]) || IS_PADCONST(ppad[ix])) {
4224 PL_curpad[ix] = SvREFCNT_inc(ppad[ix]);
4227 SV* sv = NEWSV(0,0);
4233 /* Now that vars are all in place, clone nested closures. */
4235 for (ix = fpad; ix > 0; ix--) {
4236 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
4238 && namesv != &PL_sv_undef
4239 && !(SvFLAGS(namesv) & SVf_FAKE)
4240 && *SvPVX(namesv) == '&'
4241 && CvCLONE(ppad[ix]))
4243 CV *kid = cv_clone2((CV*)ppad[ix], cv);
4244 SvREFCNT_dec(ppad[ix]);
4247 PL_curpad[ix] = (SV*)kid;
4251 #ifdef DEBUG_CLOSURES
4252 PerlIO_printf(Perl_debug_log, "Cloned inside:\n");
4254 PerlIO_printf(Perl_debug_log, " from:\n");
4256 PerlIO_printf(Perl_debug_log, " to:\n");
4265 Perl_cv_clone(pTHX_ CV *proto)
4268 LOCK_CRED_MUTEX; /* XXX create separate mutex */
4269 cv = cv_clone2(proto, CvOUTSIDE(proto));
4270 UNLOCK_CRED_MUTEX; /* XXX create separate mutex */
4275 Perl_cv_ckproto(pTHX_ CV *cv, GV *gv, char *p)
4279 if (((!p != !SvPOK(cv)) || (p && strNE(p, SvPVX(cv)))) && ckWARN_d(WARN_PROTOTYPE)) {
4280 SV* msg = sv_newmortal();
4284 gv_efullname3(name = sv_newmortal(), gv, Nullch);
4285 sv_setpv(msg, "Prototype mismatch:");
4287 Perl_sv_catpvf(aTHX_ msg, " sub %"SVf, name);
4289 Perl_sv_catpvf(aTHX_ msg, " (%s)", SvPVX(cv));
4290 sv_catpv(msg, " vs ");
4292 Perl_sv_catpvf(aTHX_ msg, "(%s)", p);
4294 sv_catpv(msg, "none");
4295 Perl_warner(aTHX_ WARN_PROTOTYPE, "%"SVf, msg);
4300 Perl_cv_const_sv(pTHX_ CV *cv)
4302 if (!cv || !SvPOK(cv) || SvCUR(cv))
4304 return op_const_sv(CvSTART(cv), cv);
4308 Perl_op_const_sv(pTHX_ OP *o, CV *cv)
4315 if (o->op_type == OP_LINESEQ && cLISTOPo->op_first)
4316 o = cLISTOPo->op_first->op_sibling;
4318 for (; o; o = o->op_next) {
4319 OPCODE type = o->op_type;
4321 if (sv && o->op_next == o)
4323 if (type == OP_NEXTSTATE || type == OP_NULL || type == OP_PUSHMARK)
4325 if (type == OP_LEAVESUB || type == OP_RETURN)
4329 if (type == OP_CONST && cSVOPo->op_sv)
4331 else if ((type == OP_PADSV || type == OP_CONST) && cv) {
4332 AV* padav = (AV*)(AvARRAY(CvPADLIST(cv))[1]);
4333 sv = padav ? AvARRAY(padav)[o->op_targ] : Nullsv;
4334 if (!sv || (!SvREADONLY(sv) && SvREFCNT(sv) > 1))
4346 Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
4356 Perl_croak(aTHX_ "\"my sub\" not yet implemented");
4360 Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block)
4362 return Perl_newATTRSUB(aTHX_ floor, o, proto, Nullop, block);
4366 Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
4373 char *ps = proto ? SvPVx(((SVOP*)proto)->op_sv, n_a) : Nullch;
4377 name = o ? SvPVx(cSVOPo->op_sv, n_a) : Nullch;
4378 if (!name && PERLDB_NAMEANON && CopLINE(PL_curcop)) {
4379 SV *sv = sv_newmortal();
4380 Perl_sv_setpvf(aTHX_ sv, "__ANON__[%s:%"IVdf"]",
4381 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
4386 gv = gv_fetchpv(name ? name : (aname ? aname : "__ANON__"),
4387 GV_ADDMULTI | ((block || attrs) ? 0 : GV_NOINIT),
4397 if (SvTYPE(gv) != SVt_PVGV) { /* Maybe prototype now, and had at
4398 maximum a prototype before. */
4399 if (SvTYPE(gv) > SVt_NULL) {
4400 if (!SvPOK((SV*)gv) && !(SvIOK((SV*)gv) && SvIVX((SV*)gv) == -1)
4401 && ckWARN_d(WARN_PROTOTYPE))
4403 Perl_warner(aTHX_ WARN_PROTOTYPE, "Runaway prototype");
4405 cv_ckproto((CV*)gv, NULL, ps);
4408 sv_setpv((SV*)gv, ps);
4410 sv_setiv((SV*)gv, -1);
4411 SvREFCNT_dec(PL_compcv);
4412 cv = PL_compcv = NULL;
4413 PL_sub_generation++;
4417 if (!name || GvCVGEN(gv))
4419 else if ((cv = GvCV(gv))) {
4420 cv_ckproto(cv, gv, ps);
4421 /* already defined (or promised)? */
4422 if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
4424 bool const_changed = TRUE;
4425 if (!block && !attrs) {
4426 /* just a "sub foo;" when &foo is already defined */
4427 SAVEFREESV(PL_compcv);
4430 /* ahem, death to those who redefine active sort subs */
4431 if (PL_curstackinfo->si_type == PERLSI_SORT && PL_sortcop == CvSTART(cv))
4432 Perl_croak(aTHX_ "Can't redefine active sort subroutine %s", name);
4435 if ((const_sv = cv_const_sv(cv)))
4436 const_changed = sv_cmp(const_sv, op_const_sv(block, Nullcv));
4437 if ((const_sv || const_changed) && ckWARN(WARN_REDEFINE))
4439 line_t oldline = CopLINE(PL_curcop);
4440 CopLINE_set(PL_curcop, PL_copline);
4441 Perl_warner(aTHX_ WARN_REDEFINE,
4442 const_sv ? "Constant subroutine %s redefined"
4443 : "Subroutine %s redefined", name);
4444 CopLINE_set(PL_curcop, oldline);
4455 /* Need to do a C<use attributes $stash_of_cv,\&cv,@attrs>
4456 * before we clobber PL_compcv.
4460 if (CvGV(cv) && GvSTASH(CvGV(cv)) && HvNAME(GvSTASH(CvGV(cv))))
4461 stash = GvSTASH(CvGV(cv));
4462 else if (CvSTASH(cv) && HvNAME(CvSTASH(cv)))
4463 stash = CvSTASH(cv);
4465 stash = PL_curstash;
4468 /* possibly about to re-define existing subr -- ignore old cv */
4469 rcv = (SV*)PL_compcv;
4470 if (name && GvSTASH(gv) && HvNAME(GvSTASH(gv)))
4471 stash = GvSTASH(gv);
4473 stash = PL_curstash;
4475 apply_attrs(stash, rcv, attrs);
4477 if (cv) { /* must reuse cv if autoloaded */
4479 /* got here with just attrs -- work done, so bug out */
4480 SAVEFREESV(PL_compcv);
4484 CvFLAGS(cv) = CvFLAGS(PL_compcv);
4485 CvOUTSIDE(cv) = CvOUTSIDE(PL_compcv);
4486 CvOUTSIDE(PL_compcv) = 0;
4487 CvPADLIST(cv) = CvPADLIST(PL_compcv);
4488 CvPADLIST(PL_compcv) = 0;
4489 if (SvREFCNT(PL_compcv) > 1) /* XXX Make closures transit through stub. */
4490 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc((SV*)cv);
4491 SvREFCNT_dec(PL_compcv);
4498 PL_sub_generation++;
4501 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4502 CvFILE(cv) = CopFILE(PL_curcop);
4503 CvSTASH(cv) = PL_curstash;
4506 if (!CvMUTEXP(cv)) {
4507 New(666, CvMUTEXP(cv), 1, perl_mutex);
4508 MUTEX_INIT(CvMUTEXP(cv));
4510 #endif /* USE_THREADS */
4513 sv_setpv((SV*)cv, ps);
4515 if (PL_error_count) {
4519 char *s = strrchr(name, ':');
4521 if (strEQ(s, "BEGIN")) {
4523 "BEGIN not safe after errors--compilation aborted";
4524 if (PL_in_eval & EVAL_KEEPERR)
4525 Perl_croak(aTHX_ not_safe);
4527 /* force display of errors found but not reported */
4528 sv_catpv(ERRSV, not_safe);
4529 Perl_croak(aTHX_ "%s", SvPVx(ERRSV, n_a));
4536 PL_copline = NOLINE;
4541 if (AvFILLp(PL_comppad_name) < AvFILLp(PL_comppad))
4542 av_store(PL_comppad_name, AvFILLp(PL_comppad), Nullsv);
4545 CvROOT(cv) = newUNOP(OP_LEAVESUBLV, 0, scalarseq(block));
4548 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
4550 CvROOT(cv)->op_private |= OPpREFCOUNTED;
4551 OpREFCNT_set(CvROOT(cv), 1);
4552 CvSTART(cv) = LINKLIST(CvROOT(cv));
4553 CvROOT(cv)->op_next = 0;
4556 /* now that optimizer has done its work, adjust pad values */
4558 SV **namep = AvARRAY(PL_comppad_name);
4559 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4562 if (SvIMMORTAL(PL_curpad[ix]) || IS_PADGV(PL_curpad[ix]) || IS_PADCONST(PL_curpad[ix]))
4565 * The only things that a clonable function needs in its
4566 * pad are references to outer lexicals and anonymous subs.
4567 * The rest are created anew during cloning.
4569 if (!((namesv = namep[ix]) != Nullsv &&
4570 namesv != &PL_sv_undef &&
4572 *SvPVX(namesv) == '&')))
4574 SvREFCNT_dec(PL_curpad[ix]);
4575 PL_curpad[ix] = Nullsv;
4580 AV *av = newAV(); /* Will be @_ */
4582 av_store(PL_comppad, 0, (SV*)av);
4583 AvFLAGS(av) = AVf_REIFY;
4585 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4586 if (SvIMMORTAL(PL_curpad[ix]) || IS_PADGV(PL_curpad[ix]) || IS_PADCONST(PL_curpad[ix]))
4588 if (!SvPADMY(PL_curpad[ix]))
4589 SvPADTMP_on(PL_curpad[ix]);
4593 if (name || aname) {
4595 char *tname = (name ? name : aname);
4597 if (PERLDB_SUBLINE && PL_curstash != PL_debstash) {
4598 SV *sv = NEWSV(0,0);
4599 SV *tmpstr = sv_newmortal();
4600 GV *db_postponed = gv_fetchpv("DB::postponed", GV_ADDMULTI, SVt_PVHV);
4604 Perl_sv_setpvf(aTHX_ sv, "%s:%ld-%ld",
4606 (long)PL_subline, (long)CopLINE(PL_curcop));
4607 gv_efullname3(tmpstr, gv, Nullch);
4608 hv_store(GvHV(PL_DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
4609 hv = GvHVn(db_postponed);
4610 if (HvFILL(hv) > 0 && hv_exists(hv, SvPVX(tmpstr), SvCUR(tmpstr))
4611 && (pcv = GvCV(db_postponed)))
4617 call_sv((SV*)pcv, G_DISCARD);
4621 if ((s = strrchr(tname,':')))
4626 if (*s != 'B' && *s != 'E' && *s != 'C' && *s != 'I')
4629 if (strEQ(s, "BEGIN")) {
4630 I32 oldscope = PL_scopestack_ix;
4632 SAVECOPFILE(&PL_compiling);
4633 SAVECOPLINE(&PL_compiling);
4635 sv_setsv(PL_rs, PL_nrs);
4638 PL_beginav = newAV();
4639 DEBUG_x( dump_sub(gv) );
4640 av_push(PL_beginav, SvREFCNT_inc(cv));
4642 call_list(oldscope, PL_beginav);
4644 PL_curcop = &PL_compiling;
4645 PL_compiling.op_private = PL_hints;
4648 else if (strEQ(s, "END") && !PL_error_count) {
4651 DEBUG_x( dump_sub(gv) );
4652 av_unshift(PL_endav, 1);
4653 av_store(PL_endav, 0, SvREFCNT_inc(cv));
4656 else if (strEQ(s, "CHECK") && !PL_error_count) {
4658 PL_checkav = newAV();
4659 DEBUG_x( dump_sub(gv) );
4660 av_unshift(PL_checkav, 1);
4661 av_store(PL_checkav, 0, SvREFCNT_inc(cv));
4664 else if (strEQ(s, "INIT") && !PL_error_count) {
4666 PL_initav = newAV();
4667 DEBUG_x( dump_sub(gv) );
4668 av_push(PL_initav, SvREFCNT_inc(cv));
4674 PL_copline = NOLINE;
4679 /* XXX unsafe for threads if eval_owner isn't held */
4681 =for apidoc newCONSTSUB
4683 Creates a constant sub equivalent to Perl C<sub FOO () { 123 }> which is
4684 eligible for inlining at compile-time.
4690 Perl_newCONSTSUB(pTHX_ HV *stash, char *name, SV *sv)
4695 SAVECOPLINE(PL_curcop);
4698 CopLINE_set(PL_curcop, PL_copline);
4699 PL_hints &= ~HINT_BLOCK_SCOPE;
4702 SAVESPTR(PL_curstash);
4703 SAVECOPSTASH(PL_curcop);
4704 PL_curstash = stash;
4706 CopSTASHPV(PL_curcop) = stash ? HvNAME(stash) : Nullch;
4708 CopSTASH(PL_curcop) = stash;
4713 start_subparse(FALSE, 0),
4714 newSVOP(OP_CONST, 0, newSVpv(name,0)),
4715 newSVOP(OP_CONST, 0, &PL_sv_no), /* SvPV(&PL_sv_no) == "" -- GMB */
4717 newSTATEOP(0, Nullch, newSVOP(OP_CONST, 0, sv))
4724 =for apidoc U||newXS
4726 Used by C<xsubpp> to hook up XSUBs as Perl subs.
4732 Perl_newXS(pTHX_ char *name, XSUBADDR_t subaddr, char *filename)
4735 GV *gv = gv_fetchpv(name ? name : "__ANON__", GV_ADDMULTI, SVt_PVCV);
4738 if ((cv = (name ? GvCV(gv) : Nullcv))) {
4740 /* just a cached method */
4744 else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
4745 /* already defined (or promised) */
4746 if (ckWARN(WARN_REDEFINE) && !(CvGV(cv) && GvSTASH(CvGV(cv))
4747 && HvNAME(GvSTASH(CvGV(cv)))
4748 && strEQ(HvNAME(GvSTASH(CvGV(cv))), "autouse"))) {
4749 line_t oldline = CopLINE(PL_curcop);
4750 if (PL_copline != NOLINE)
4751 CopLINE_set(PL_curcop, PL_copline);
4752 Perl_warner(aTHX_ WARN_REDEFINE, "Subroutine %s redefined",name);
4753 CopLINE_set(PL_curcop, oldline);
4760 if (cv) /* must reuse cv if autoloaded */
4763 cv = (CV*)NEWSV(1105,0);
4764 sv_upgrade((SV *)cv, SVt_PVCV);
4768 PL_sub_generation++;
4771 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4773 New(666, CvMUTEXP(cv), 1, perl_mutex);
4774 MUTEX_INIT(CvMUTEXP(cv));
4776 #endif /* USE_THREADS */
4777 (void)gv_fetchfile(filename);
4778 CvFILE(cv) = filename; /* NOTE: not copied, as it is expected to be
4779 an external constant string */
4780 CvXSUB(cv) = subaddr;
4783 char *s = strrchr(name,':');
4789 if (*s != 'B' && *s != 'E' && *s != 'C' && *s != 'I')
4792 if (strEQ(s, "BEGIN")) {
4794 PL_beginav = newAV();
4795 av_push(PL_beginav, SvREFCNT_inc(cv));
4798 else if (strEQ(s, "END")) {
4801 av_unshift(PL_endav, 1);
4802 av_store(PL_endav, 0, SvREFCNT_inc(cv));
4805 else if (strEQ(s, "CHECK")) {
4807 PL_checkav = newAV();
4808 av_unshift(PL_checkav, 1);
4809 av_store(PL_checkav, 0, SvREFCNT_inc(cv));
4812 else if (strEQ(s, "INIT")) {
4814 PL_initav = newAV();
4815 av_push(PL_initav, SvREFCNT_inc(cv));
4827 Perl_newFORM(pTHX_ I32 floor, OP *o, OP *block)
4837 name = SvPVx(cSVOPo->op_sv, n_a);
4840 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
4842 if ((cv = GvFORM(gv))) {
4843 if (ckWARN(WARN_REDEFINE)) {
4844 line_t oldline = CopLINE(PL_curcop);
4846 CopLINE_set(PL_curcop, PL_copline);
4847 Perl_warner(aTHX_ WARN_REDEFINE, "Format %s redefined",name);
4848 CopLINE_set(PL_curcop, oldline);
4854 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4855 CvFILE(cv) = CopFILE(PL_curcop);
4857 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4858 if (!SvPADMY(PL_curpad[ix]) && !SvIMMORTAL(PL_curpad[ix]))
4859 SvPADTMP_on(PL_curpad[ix]);
4862 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
4863 CvROOT(cv)->op_private |= OPpREFCOUNTED;
4864 OpREFCNT_set(CvROOT(cv), 1);
4865 CvSTART(cv) = LINKLIST(CvROOT(cv));
4866 CvROOT(cv)->op_next = 0;
4869 PL_copline = NOLINE;
4874 Perl_newANONLIST(pTHX_ OP *o)
4876 return newUNOP(OP_REFGEN, 0,
4877 mod(list(convert(OP_ANONLIST, 0, o)), OP_REFGEN));
4881 Perl_newANONHASH(pTHX_ OP *o)
4883 return newUNOP(OP_REFGEN, 0,
4884 mod(list(convert(OP_ANONHASH, 0, o)), OP_REFGEN));
4888 Perl_newANONSUB(pTHX_ I32 floor, OP *proto, OP *block)
4890 return newANONATTRSUB(floor, proto, Nullop, block);
4894 Perl_newANONATTRSUB(pTHX_ I32 floor, OP *proto, OP *attrs, OP *block)
4896 return newUNOP(OP_REFGEN, 0,
4897 newSVOP(OP_ANONCODE, 0,
4898 (SV*)newATTRSUB(floor, 0, proto, attrs, block)));
4902 Perl_oopsAV(pTHX_ OP *o)
4904 switch (o->op_type) {
4906 o->op_type = OP_PADAV;
4907 o->op_ppaddr = PL_ppaddr[OP_PADAV];
4908 return ref(o, OP_RV2AV);
4911 o->op_type = OP_RV2AV;
4912 o->op_ppaddr = PL_ppaddr[OP_RV2AV];
4917 if (ckWARN_d(WARN_INTERNAL))
4918 Perl_warner(aTHX_ WARN_INTERNAL, "oops: oopsAV");
4925 Perl_oopsHV(pTHX_ OP *o)
4929 switch (o->op_type) {
4932 o->op_type = OP_PADHV;
4933 o->op_ppaddr = PL_ppaddr[OP_PADHV];
4934 return ref(o, OP_RV2HV);
4938 o->op_type = OP_RV2HV;
4939 o->op_ppaddr = PL_ppaddr[OP_RV2HV];
4944 if (ckWARN_d(WARN_INTERNAL))
4945 Perl_warner(aTHX_ WARN_INTERNAL, "oops: oopsHV");
4952 Perl_newAVREF(pTHX_ OP *o)
4954 if (o->op_type == OP_PADANY) {
4955 o->op_type = OP_PADAV;
4956 o->op_ppaddr = PL_ppaddr[OP_PADAV];
4959 return newUNOP(OP_RV2AV, 0, scalar(o));
4963 Perl_newGVREF(pTHX_ I32 type, OP *o)
4965 if (type == OP_MAPSTART || type == OP_GREPSTART || type == OP_SORT)
4966 return newUNOP(OP_NULL, 0, o);
4967 return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
4971 Perl_newHVREF(pTHX_ OP *o)
4973 if (o->op_type == OP_PADANY) {
4974 o->op_type = OP_PADHV;
4975 o->op_ppaddr = PL_ppaddr[OP_PADHV];
4978 return newUNOP(OP_RV2HV, 0, scalar(o));
4982 Perl_oopsCV(pTHX_ OP *o)
4984 Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
4990 Perl_newCVREF(pTHX_ I32 flags, OP *o)
4992 return newUNOP(OP_RV2CV, flags, scalar(o));
4996 Perl_newSVREF(pTHX_ OP *o)
4998 if (o->op_type == OP_PADANY) {
4999 o->op_type = OP_PADSV;
5000 o->op_ppaddr = PL_ppaddr[OP_PADSV];
5003 else if (o->op_type == OP_THREADSV && !(o->op_flags & OPpDONE_SVREF)) {
5004 o->op_flags |= OPpDONE_SVREF;
5007 return newUNOP(OP_RV2SV, 0, scalar(o));
5010 /* Check routines. */
5013 Perl_ck_anoncode(pTHX_ OP *o)
5018 name = NEWSV(1106,0);
5019 sv_upgrade(name, SVt_PVNV);
5020 sv_setpvn(name, "&", 1);
5023 ix = pad_alloc(o->op_type, SVs_PADMY);
5024 av_store(PL_comppad_name, ix, name);
5025 av_store(PL_comppad, ix, cSVOPo->op_sv);
5026 SvPADMY_on(cSVOPo->op_sv);
5027 cSVOPo->op_sv = Nullsv;
5028 cSVOPo->op_targ = ix;
5033 Perl_ck_bitop(pTHX_ OP *o)
5035 o->op_private = PL_hints;
5040 Perl_ck_concat(pTHX_ OP *o)
5042 if (cUNOPo->op_first->op_type == OP_CONCAT)
5043 o->op_flags |= OPf_STACKED;
5048 Perl_ck_spair(pTHX_ OP *o)
5050 if (o->op_flags & OPf_KIDS) {
5053 OPCODE type = o->op_type;
5054 o = modkids(ck_fun(o), type);
5055 kid = cUNOPo->op_first;
5056 newop = kUNOP->op_first->op_sibling;
5058 (newop->op_sibling ||
5059 !(PL_opargs[newop->op_type] & OA_RETSCALAR) ||
5060 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
5061 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
5065 op_free(kUNOP->op_first);
5066 kUNOP->op_first = newop;
5068 o->op_ppaddr = PL_ppaddr[++o->op_type];
5073 Perl_ck_delete(pTHX_ OP *o)
5077 if (o->op_flags & OPf_KIDS) {
5078 OP *kid = cUNOPo->op_first;
5079 switch (kid->op_type) {
5081 o->op_flags |= OPf_SPECIAL;
5084 o->op_private |= OPpSLICE;
5087 o->op_flags |= OPf_SPECIAL;
5092 Perl_croak(aTHX_ "%s argument is not a HASH or ARRAY element or slice",
5093 PL_op_desc[o->op_type]);
5101 Perl_ck_eof(pTHX_ OP *o)
5103 I32 type = o->op_type;
5105 if (o->op_flags & OPf_KIDS) {
5106 if (cLISTOPo->op_first->op_type == OP_STUB) {
5108 o = newUNOP(type, OPf_SPECIAL,
5109 newGVOP(OP_GV, 0, gv_fetchpv("main::ARGV", TRUE, SVt_PVAV)));
5117 Perl_ck_eval(pTHX_ OP *o)
5119 PL_hints |= HINT_BLOCK_SCOPE;
5120 if (o->op_flags & OPf_KIDS) {
5121 SVOP *kid = (SVOP*)cUNOPo->op_first;
5124 o->op_flags &= ~OPf_KIDS;
5127 else if (kid->op_type == OP_LINESEQ) {
5130 kid->op_next = o->op_next;
5131 cUNOPo->op_first = 0;
5134 NewOp(1101, enter, 1, LOGOP);
5135 enter->op_type = OP_ENTERTRY;
5136 enter->op_ppaddr = PL_ppaddr[OP_ENTERTRY];
5137 enter->op_private = 0;
5139 /* establish postfix order */
5140 enter->op_next = (OP*)enter;
5142 o = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
5143 o->op_type = OP_LEAVETRY;
5144 o->op_ppaddr = PL_ppaddr[OP_LEAVETRY];
5145 enter->op_other = o;
5153 o = newUNOP(OP_ENTEREVAL, 0, newDEFSVOP());
5155 o->op_targ = (PADOFFSET)PL_hints;
5160 Perl_ck_exec(pTHX_ OP *o)
5163 if (o->op_flags & OPf_STACKED) {
5165 kid = cUNOPo->op_first->op_sibling;
5166 if (kid->op_type == OP_RV2GV)
5175 Perl_ck_exists(pTHX_ OP *o)
5178 if (o->op_flags & OPf_KIDS) {
5179 OP *kid = cUNOPo->op_first;
5180 if (kid->op_type == OP_ENTERSUB) {
5181 (void) ref(kid, o->op_type);
5182 if (kid->op_type != OP_RV2CV && !PL_error_count)
5183 Perl_croak(aTHX_ "%s argument is not a subroutine name",
5184 PL_op_desc[o->op_type]);
5185 o->op_private |= OPpEXISTS_SUB;
5187 else if (kid->op_type == OP_AELEM)
5188 o->op_flags |= OPf_SPECIAL;
5189 else if (kid->op_type != OP_HELEM)
5190 Perl_croak(aTHX_ "%s argument is not a HASH or ARRAY element",
5191 PL_op_desc[o->op_type]);
5199 Perl_ck_gvconst(pTHX_ register OP *o)
5201 o = fold_constants(o);
5202 if (o->op_type == OP_CONST)
5209 Perl_ck_rvconst(pTHX_ register OP *o)
5212 SVOP *kid = (SVOP*)cUNOPo->op_first;
5214 o->op_private |= (PL_hints & HINT_STRICT_REFS);
5215 if (kid->op_type == OP_CONST) {
5219 SV *kidsv = kid->op_sv;
5222 /* Is it a constant from cv_const_sv()? */
5223 if (SvROK(kidsv) && SvREADONLY(kidsv)) {
5224 SV *rsv = SvRV(kidsv);
5225 int svtype = SvTYPE(rsv);
5226 char *badtype = Nullch;
5228 switch (o->op_type) {
5230 if (svtype > SVt_PVMG)
5231 badtype = "a SCALAR";
5234 if (svtype != SVt_PVAV)
5235 badtype = "an ARRAY";
5238 if (svtype != SVt_PVHV) {
5239 if (svtype == SVt_PVAV) { /* pseudohash? */
5240 SV **ksv = av_fetch((AV*)rsv, 0, FALSE);
5241 if (ksv && SvROK(*ksv)
5242 && SvTYPE(SvRV(*ksv)) == SVt_PVHV)
5251 if (svtype != SVt_PVCV)
5256 Perl_croak(aTHX_ "Constant is not %s reference", badtype);
5259 name = SvPV(kidsv, n_a);
5260 if ((PL_hints & HINT_STRICT_REFS) && (kid->op_private & OPpCONST_BARE)) {
5261 char *badthing = Nullch;
5262 switch (o->op_type) {
5264 badthing = "a SCALAR";
5267 badthing = "an ARRAY";
5270 badthing = "a HASH";
5275 "Can't use bareword (\"%s\") as %s ref while \"strict refs\" in use",
5279 * This is a little tricky. We only want to add the symbol if we
5280 * didn't add it in the lexer. Otherwise we get duplicate strict
5281 * warnings. But if we didn't add it in the lexer, we must at
5282 * least pretend like we wanted to add it even if it existed before,
5283 * or we get possible typo warnings. OPpCONST_ENTERED says
5284 * whether the lexer already added THIS instance of this symbol.
5286 iscv = (o->op_type == OP_RV2CV) * 2;
5288 gv = gv_fetchpv(name,
5289 iscv | !(kid->op_private & OPpCONST_ENTERED),
5292 : o->op_type == OP_RV2SV
5294 : o->op_type == OP_RV2AV
5296 : o->op_type == OP_RV2HV
5299 } while (!gv && !(kid->op_private & OPpCONST_ENTERED) && !iscv++);
5301 kid->op_type = OP_GV;
5302 SvREFCNT_dec(kid->op_sv);
5304 /* XXX hack: dependence on sizeof(PADOP) <= sizeof(SVOP) */
5305 kPADOP->op_padix = pad_alloc(OP_GV, SVs_PADTMP);
5307 PL_curpad[kPADOP->op_padix] = SvREFCNT_inc(gv);
5309 kid->op_sv = SvREFCNT_inc(gv);
5311 kid->op_ppaddr = PL_ppaddr[OP_GV];
5318 Perl_ck_ftst(pTHX_ OP *o)
5321 I32 type = o->op_type;
5323 if (o->op_flags & OPf_REF) {
5326 else if (o->op_flags & OPf_KIDS && cUNOPo->op_first->op_type != OP_STUB) {
5327 SVOP *kid = (SVOP*)cUNOPo->op_first;
5329 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
5331 OP *newop = newGVOP(type, OPf_REF,
5332 gv_fetchpv(SvPVx(kid->op_sv, n_a), TRUE, SVt_PVIO));
5339 if (type == OP_FTTTY)
5340 o = newGVOP(type, OPf_REF, gv_fetchpv("main::STDIN", TRUE,
5343 o = newUNOP(type, 0, newDEFSVOP());
5346 if (type == OP_FTTEXT || type == OP_FTBINARY) {
5348 if (PL_hints & HINT_LOCALE)
5349 o->op_private |= OPpLOCALE;
5356 Perl_ck_fun(pTHX_ OP *o)
5363 int type = o->op_type;
5364 register I32 oa = PL_opargs[type] >> OASHIFT;
5366 if (o->op_flags & OPf_STACKED) {
5367 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
5370 return no_fh_allowed(o);
5373 if (o->op_flags & OPf_KIDS) {
5375 tokid = &cLISTOPo->op_first;
5376 kid = cLISTOPo->op_first;
5377 if (kid->op_type == OP_PUSHMARK ||
5378 (kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK))
5380 tokid = &kid->op_sibling;
5381 kid = kid->op_sibling;
5383 if (!kid && PL_opargs[type] & OA_DEFGV)
5384 *tokid = kid = newDEFSVOP();
5388 sibl = kid->op_sibling;
5391 /* list seen where single (scalar) arg expected? */
5392 if (numargs == 1 && !(oa >> 4)
5393 && kid->op_type == OP_LIST && type != OP_SCALAR)
5395 return too_many_arguments(o,PL_op_desc[type]);
5408 if (kid->op_type == OP_CONST &&
5409 (kid->op_private & OPpCONST_BARE))
5411 char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
5412 OP *newop = newAVREF(newGVOP(OP_GV, 0,
5413 gv_fetchpv(name, TRUE, SVt_PVAV) ));
5414 if (ckWARN(WARN_DEPRECATED))
5415 Perl_warner(aTHX_ WARN_DEPRECATED,
5416 "Array @%s missing the @ in argument %"IVdf" of %s()",
5417 name, (IV)numargs, PL_op_desc[type]);
5420 kid->op_sibling = sibl;
5423 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
5424 bad_type(numargs, "array", PL_op_desc[type], kid);
5428 if (kid->op_type == OP_CONST &&
5429 (kid->op_private & OPpCONST_BARE))
5431 char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
5432 OP *newop = newHVREF(newGVOP(OP_GV, 0,
5433 gv_fetchpv(name, TRUE, SVt_PVHV) ));
5434 if (ckWARN(WARN_DEPRECATED))
5435 Perl_warner(aTHX_ WARN_DEPRECATED,
5436 "Hash %%%s missing the %% in argument %"IVdf" of %s()",
5437 name, (IV)numargs, PL_op_desc[type]);
5440 kid->op_sibling = sibl;
5443 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
5444 bad_type(numargs, "hash", PL_op_desc[type], kid);
5449 OP *newop = newUNOP(OP_NULL, 0, kid);
5450 kid->op_sibling = 0;
5452 newop->op_next = newop;
5454 kid->op_sibling = sibl;
5459 if (kid->op_type != OP_GV && kid->op_type != OP_RV2GV) {
5460 if (kid->op_type == OP_CONST &&
5461 (kid->op_private & OPpCONST_BARE))
5463 OP *newop = newGVOP(OP_GV, 0,
5464 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, n_a), TRUE,
5469 else if (kid->op_type == OP_READLINE) {
5470 /* neophyte patrol: open(<FH>), close(<FH>) etc. */
5471 bad_type(numargs, "HANDLE", PL_op_desc[o->op_type], kid);
5474 I32 flags = OPf_SPECIAL;
5478 /* is this op a FH constructor? */
5479 if (is_handle_constructor(o,numargs)) {
5480 char *name = Nullch;
5484 /* Set a flag to tell rv2gv to vivify
5485 * need to "prove" flag does not mean something
5486 * else already - NI-S 1999/05/07
5489 if (kid->op_type == OP_PADSV) {
5490 SV **namep = av_fetch(PL_comppad_name,
5492 if (namep && *namep)
5493 name = SvPV(*namep, len);
5495 else if (kid->op_type == OP_RV2SV
5496 && kUNOP->op_first->op_type == OP_GV)
5498 GV *gv = cGVOPx_gv(kUNOP->op_first);
5500 len = GvNAMELEN(gv);
5504 targ = pad_alloc(OP_RV2GV, SVs_PADTMP);
5505 namesv = PL_curpad[targ];
5506 (void)SvUPGRADE(namesv, SVt_PV);
5508 sv_setpvn(namesv, "$", 1);
5509 sv_catpvn(namesv, name, len);
5512 kid->op_sibling = 0;
5513 kid = newUNOP(OP_RV2GV, flags, scalar(kid));
5514 kid->op_targ = targ;
5515 kid->op_private |= priv;
5517 kid->op_sibling = sibl;
5523 mod(scalar(kid), type);
5527 tokid = &kid->op_sibling;
5528 kid = kid->op_sibling;
5530 o->op_private |= numargs;
5532 return too_many_arguments(o,PL_op_desc[o->op_type]);
5535 else if (PL_opargs[type] & OA_DEFGV) {
5537 return newUNOP(type, 0, newDEFSVOP());
5541 while (oa & OA_OPTIONAL)
5543 if (oa && oa != OA_LIST)
5544 return too_few_arguments(o,PL_op_desc[o->op_type]);
5550 Perl_ck_glob(pTHX_ OP *o)
5555 if ((o->op_flags & OPf_KIDS) && !cLISTOPo->op_first->op_sibling)
5556 append_elem(OP_GLOB, o, newDEFSVOP());
5558 if (!((gv = gv_fetchpv("glob", FALSE, SVt_PVCV)) && GvIMPORTED_CV(gv)))
5559 gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
5561 #if !defined(PERL_EXTERNAL_GLOB)
5562 /* XXX this can be tightened up and made more failsafe. */
5565 Perl_load_module(aTHX_ 0, newSVpvn("File::Glob", 10), Nullsv,
5566 /* null-terminated import list */
5567 newSVpvn(":globally", 9), Nullsv);
5568 gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
5571 #endif /* PERL_EXTERNAL_GLOB */
5573 if (gv && GvIMPORTED_CV(gv)) {
5574 append_elem(OP_GLOB, o,
5575 newSVOP(OP_CONST, 0, newSViv(PL_glob_index++)));
5576 o->op_type = OP_LIST;
5577 o->op_ppaddr = PL_ppaddr[OP_LIST];
5578 cLISTOPo->op_first->op_type = OP_PUSHMARK;
5579 cLISTOPo->op_first->op_ppaddr = PL_ppaddr[OP_PUSHMARK];
5580 o = newUNOP(OP_ENTERSUB, OPf_STACKED,
5581 append_elem(OP_LIST, o,
5582 scalar(newUNOP(OP_RV2CV, 0,
5583 newGVOP(OP_GV, 0, gv)))));
5584 o = newUNOP(OP_NULL, 0, ck_subr(o));
5585 o->op_targ = OP_GLOB; /* hint at what it used to be */
5588 gv = newGVgen("main");
5590 append_elem(OP_GLOB, o, newGVOP(OP_GV, 0, gv));
5596 Perl_ck_grep(pTHX_ OP *o)
5600 OPCODE type = o->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
5602 o->op_ppaddr = PL_ppaddr[OP_GREPSTART];
5603 NewOp(1101, gwop, 1, LOGOP);
5605 if (o->op_flags & OPf_STACKED) {
5608 kid = cLISTOPo->op_first->op_sibling;
5609 for (k = cLISTOPo->op_first->op_sibling->op_next; k; k = k->op_next) {
5612 kid->op_next = (OP*)gwop;
5613 o->op_flags &= ~OPf_STACKED;
5615 kid = cLISTOPo->op_first->op_sibling;
5616 if (type == OP_MAPWHILE)
5623 kid = cLISTOPo->op_first->op_sibling;
5624 if (kid->op_type != OP_NULL)
5625 Perl_croak(aTHX_ "panic: ck_grep");
5626 kid = kUNOP->op_first;
5628 gwop->op_type = type;
5629 gwop->op_ppaddr = PL_ppaddr[type];
5630 gwop->op_first = listkids(o);
5631 gwop->op_flags |= OPf_KIDS;
5632 gwop->op_private = 1;
5633 gwop->op_other = LINKLIST(kid);
5634 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
5635 kid->op_next = (OP*)gwop;
5637 kid = cLISTOPo->op_first->op_sibling;
5638 if (!kid || !kid->op_sibling)
5639 return too_few_arguments(o,PL_op_desc[o->op_type]);
5640 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
5641 mod(kid, OP_GREPSTART);
5647 Perl_ck_index(pTHX_ OP *o)
5649 if (o->op_flags & OPf_KIDS) {
5650 OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5652 kid = kid->op_sibling; /* get past "big" */
5653 if (kid && kid->op_type == OP_CONST)
5654 fbm_compile(((SVOP*)kid)->op_sv, 0);
5660 Perl_ck_lengthconst(pTHX_ OP *o)
5662 /* XXX length optimization goes here */
5667 Perl_ck_lfun(pTHX_ OP *o)
5669 OPCODE type = o->op_type;
5670 return modkids(ck_fun(o), type);
5674 Perl_ck_defined(pTHX_ OP *o) /* 19990527 MJD */
5677 if ((o->op_flags & OPf_KIDS) && ckWARN(WARN_DEPRECATED)) {
5678 switch (cUNOPo->op_first->op_type) {
5680 break; /* Globals via GV can be undef */
5682 case OP_AASSIGN: /* Is this a good idea? */
5683 Perl_warner(aTHX_ WARN_DEPRECATED,
5684 "defined(@array) is deprecated");
5685 Perl_warner(aTHX_ WARN_DEPRECATED,
5686 "(Maybe you should just omit the defined()?)\n");
5689 break; /* Globals via GV can be undef */
5691 Perl_warner(aTHX_ WARN_DEPRECATED,
5692 "defined(%%hash) is deprecated");
5693 Perl_warner(aTHX_ WARN_DEPRECATED,
5694 "(Maybe you should just omit the defined()?)\n");
5705 Perl_ck_rfun(pTHX_ OP *o)
5707 OPCODE type = o->op_type;
5708 return refkids(ck_fun(o), type);
5712 Perl_ck_listiob(pTHX_ OP *o)
5716 kid = cLISTOPo->op_first;
5719 kid = cLISTOPo->op_first;
5721 if (kid->op_type == OP_PUSHMARK)
5722 kid = kid->op_sibling;
5723 if (kid && o->op_flags & OPf_STACKED)
5724 kid = kid->op_sibling;
5725 else if (kid && !kid->op_sibling) { /* print HANDLE; */
5726 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
5727 o->op_flags |= OPf_STACKED; /* make it a filehandle */
5728 kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
5729 cLISTOPo->op_first->op_sibling = kid;
5730 cLISTOPo->op_last = kid;
5731 kid = kid->op_sibling;
5736 append_elem(o->op_type, o, newDEFSVOP());
5742 if (PL_hints & HINT_LOCALE)
5743 o->op_private |= OPpLOCALE;
5750 Perl_ck_fun_locale(pTHX_ OP *o)
5756 if (PL_hints & HINT_LOCALE)
5757 o->op_private |= OPpLOCALE;
5764 Perl_ck_sassign(pTHX_ OP *o)
5766 OP *kid = cLISTOPo->op_first;
5767 /* has a disposable target? */
5768 if ((PL_opargs[kid->op_type] & OA_TARGLEX)
5769 && !(kid->op_flags & OPf_STACKED)
5770 /* Cannot steal the second time! */
5771 && !(kid->op_private & OPpTARGET_MY))
5773 OP *kkid = kid->op_sibling;
5775 /* Can just relocate the target. */
5776 if (kkid && kkid->op_type == OP_PADSV
5777 && !(kkid->op_private & OPpLVAL_INTRO))
5779 kid->op_targ = kkid->op_targ;
5781 /* Now we do not need PADSV and SASSIGN. */
5782 kid->op_sibling = o->op_sibling; /* NULL */
5783 cLISTOPo->op_first = NULL;
5786 kid->op_private |= OPpTARGET_MY; /* Used for context settings */
5794 Perl_ck_scmp(pTHX_ OP *o)
5798 if (PL_hints & HINT_LOCALE)
5799 o->op_private |= OPpLOCALE;
5806 Perl_ck_match(pTHX_ OP *o)
5808 o->op_private |= OPpRUNTIME;
5813 Perl_ck_method(pTHX_ OP *o)
5815 OP *kid = cUNOPo->op_first;
5816 if (kid->op_type == OP_CONST) {
5817 SV* sv = kSVOP->op_sv;
5818 if (!(strchr(SvPVX(sv), ':') || strchr(SvPVX(sv), '\''))) {
5820 (void)SvUPGRADE(sv, SVt_PVIV);
5822 PERL_HASH(SvUVX(sv), SvPVX(sv), SvCUR(sv));
5823 cmop = newSVOP(OP_METHOD_NAMED, 0, sv);
5824 kSVOP->op_sv = Nullsv;
5833 Perl_ck_null(pTHX_ OP *o)
5839 Perl_ck_repeat(pTHX_ OP *o)
5841 if (cBINOPo->op_first->op_flags & OPf_PARENS) {
5842 o->op_private |= OPpREPEAT_DOLIST;
5843 cBINOPo->op_first = force_list(cBINOPo->op_first);
5851 Perl_ck_require(pTHX_ OP *o)
5853 if (o->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
5854 SVOP *kid = (SVOP*)cUNOPo->op_first;
5856 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
5858 for (s = SvPVX(kid->op_sv); *s; s++) {
5859 if (*s == ':' && s[1] == ':') {
5861 Move(s+2, s+1, strlen(s+2)+1, char);
5862 --SvCUR(kid->op_sv);
5865 sv_catpvn(kid->op_sv, ".pm", 3);
5873 Perl_ck_retarget(pTHX_ OP *o)
5875 Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
5882 Perl_ck_select(pTHX_ OP *o)
5885 if (o->op_flags & OPf_KIDS) {
5886 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5887 if (kid && kid->op_sibling) {
5888 o->op_type = OP_SSELECT;
5889 o->op_ppaddr = PL_ppaddr[OP_SSELECT];
5891 return fold_constants(o);
5895 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5896 if (kid && kid->op_type == OP_RV2GV)
5897 kid->op_private &= ~HINT_STRICT_REFS;
5902 Perl_ck_shift(pTHX_ OP *o)
5904 I32 type = o->op_type;
5906 if (!(o->op_flags & OPf_KIDS)) {
5911 if (!CvUNIQUE(PL_compcv)) {
5912 argop = newOP(OP_PADAV, OPf_REF);
5913 argop->op_targ = 0; /* PL_curpad[0] is @_ */
5916 argop = newUNOP(OP_RV2AV, 0,
5917 scalar(newGVOP(OP_GV, 0,
5918 gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
5921 argop = newUNOP(OP_RV2AV, 0,
5922 scalar(newGVOP(OP_GV, 0, !CvUNIQUE(PL_compcv) ?
5923 PL_defgv : gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
5924 #endif /* USE_THREADS */
5925 return newUNOP(type, 0, scalar(argop));
5927 return scalar(modkids(ck_fun(o), type));
5931 Perl_ck_sort(pTHX_ OP *o)
5935 if (PL_hints & HINT_LOCALE)
5936 o->op_private |= OPpLOCALE;
5939 if (o->op_type == OP_SORT && o->op_flags & OPf_STACKED)
5941 if (o->op_flags & OPf_STACKED) { /* may have been cleared */
5942 OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5944 kid = kUNOP->op_first; /* get past null */
5946 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
5948 if (kid->op_type == OP_SCOPE) {
5952 else if (kid->op_type == OP_LEAVE) {
5953 if (o->op_type == OP_SORT) {
5954 null(kid); /* wipe out leave */
5957 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
5958 if (k->op_next == kid)
5963 kid->op_next = 0; /* just disconnect the leave */
5964 k = kLISTOP->op_first;
5968 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5969 if (o->op_type == OP_SORT)
5973 o->op_flags |= OPf_SPECIAL;
5975 else if (kid->op_type == OP_RV2SV || kid->op_type == OP_PADSV)
5976 null(cLISTOPo->op_first->op_sibling);
5983 S_simplify_sort(pTHX_ OP *o)
5986 register OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5990 if (!(o->op_flags & OPf_STACKED))
5992 GvMULTI_on(gv_fetchpv("a", TRUE, SVt_PV));
5993 GvMULTI_on(gv_fetchpv("b", TRUE, SVt_PV));
5994 kid = kUNOP->op_first; /* get past null */
5995 if (kid->op_type != OP_SCOPE)
5997 kid = kLISTOP->op_last; /* get past scope */
5998 switch(kid->op_type) {
6006 k = kid; /* remember this node*/
6007 if (kBINOP->op_first->op_type != OP_RV2SV)
6009 kid = kBINOP->op_first; /* get past cmp */
6010 if (kUNOP->op_first->op_type != OP_GV)
6012 kid = kUNOP->op_first; /* get past rv2sv */
6014 if (GvSTASH(gv) != PL_curstash)
6016 if (strEQ(GvNAME(gv), "a"))
6018 else if (strEQ(GvNAME(gv), "b"))
6022 kid = k; /* back to cmp */
6023 if (kBINOP->op_last->op_type != OP_RV2SV)
6025 kid = kBINOP->op_last; /* down to 2nd arg */
6026 if (kUNOP->op_first->op_type != OP_GV)
6028 kid = kUNOP->op_first; /* get past rv2sv */
6030 if (GvSTASH(gv) != PL_curstash
6032 ? strNE(GvNAME(gv), "a")
6033 : strNE(GvNAME(gv), "b")))
6035 o->op_flags &= ~(OPf_STACKED | OPf_SPECIAL);
6037 o->op_private |= OPpSORT_REVERSE;
6038 if (k->op_type == OP_NCMP)
6039 o->op_private |= OPpSORT_NUMERIC;
6040 if (k->op_type == OP_I_NCMP)
6041 o->op_private |= OPpSORT_NUMERIC | OPpSORT_INTEGER;
6042 kid = cLISTOPo->op_first->op_sibling;
6043 cLISTOPo->op_first->op_sibling = kid->op_sibling; /* bypass old block */
6044 op_free(kid); /* then delete it */
6045 cLISTOPo->op_children--;
6049 Perl_ck_split(pTHX_ OP *o)
6053 if (o->op_flags & OPf_STACKED)
6054 return no_fh_allowed(o);
6056 kid = cLISTOPo->op_first;
6057 if (kid->op_type != OP_NULL)
6058 Perl_croak(aTHX_ "panic: ck_split");
6059 kid = kid->op_sibling;
6060 op_free(cLISTOPo->op_first);
6061 cLISTOPo->op_first = kid;
6063 cLISTOPo->op_first = kid = newSVOP(OP_CONST, 0, newSVpvn(" ", 1));
6064 cLISTOPo->op_last = kid; /* There was only one element previously */
6067 if (kid->op_type != OP_MATCH) {
6068 OP *sibl = kid->op_sibling;
6069 kid->op_sibling = 0;
6070 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
6071 if (cLISTOPo->op_first == cLISTOPo->op_last)
6072 cLISTOPo->op_last = kid;
6073 cLISTOPo->op_first = kid;
6074 kid->op_sibling = sibl;
6077 kid->op_type = OP_PUSHRE;
6078 kid->op_ppaddr = PL_ppaddr[OP_PUSHRE];
6081 if (!kid->op_sibling)
6082 append_elem(OP_SPLIT, o, newDEFSVOP());
6084 kid = kid->op_sibling;
6087 if (!kid->op_sibling)
6088 append_elem(OP_SPLIT, o, newSVOP(OP_CONST, 0, newSViv(0)));
6090 kid = kid->op_sibling;
6093 if (kid->op_sibling)
6094 return too_many_arguments(o,PL_op_desc[o->op_type]);
6100 Perl_ck_join(pTHX_ OP *o)
6102 if (ckWARN(WARN_SYNTAX)) {
6103 OP *kid = cLISTOPo->op_first->op_sibling;
6104 if (kid && kid->op_type == OP_MATCH) {
6105 char *pmstr = "STRING";
6106 if (kPMOP->op_pmregexp)
6107 pmstr = kPMOP->op_pmregexp->precomp;
6108 Perl_warner(aTHX_ WARN_SYNTAX,
6109 "/%s/ should probably be written as \"%s\"",
6117 Perl_ck_subr(pTHX_ OP *o)
6120 OP *prev = ((cUNOPo->op_first->op_sibling)
6121 ? cUNOPo : ((UNOP*)cUNOPo->op_first))->op_first;
6122 OP *o2 = prev->op_sibling;
6131 o->op_private |= OPpENTERSUB_HASTARG;
6132 for (cvop = o2; cvop->op_sibling; cvop = cvop->op_sibling) ;
6133 if (cvop->op_type == OP_RV2CV) {
6135 o->op_private |= (cvop->op_private & OPpENTERSUB_AMPER);
6136 null(cvop); /* disable rv2cv */
6137 tmpop = (SVOP*)((UNOP*)cvop)->op_first;
6138 if (tmpop->op_type == OP_GV && !(o->op_private & OPpENTERSUB_AMPER)) {
6139 GV *gv = cGVOPx_gv(tmpop);
6142 tmpop->op_private |= OPpEARLY_CV;
6143 else if (SvPOK(cv)) {
6144 namegv = CvANON(cv) ? gv : CvGV(cv);
6145 proto = SvPV((SV*)cv, n_a);
6149 else if (cvop->op_type == OP_METHOD || cvop->op_type == OP_METHOD_NAMED) {
6150 if (o2->op_type == OP_CONST)
6151 o2->op_private &= ~OPpCONST_STRICT;
6152 else if (o2->op_type == OP_LIST) {
6153 OP *o = ((UNOP*)o2)->op_first->op_sibling;
6154 if (o && o->op_type == OP_CONST)
6155 o->op_private &= ~OPpCONST_STRICT;
6158 o->op_private |= (PL_hints & HINT_STRICT_REFS);
6159 if (PERLDB_SUB && PL_curstash != PL_debstash)
6160 o->op_private |= OPpENTERSUB_DB;
6161 while (o2 != cvop) {
6165 return too_many_arguments(o, gv_ename(namegv));
6183 if (o2->op_type != OP_REFGEN && o2->op_type != OP_UNDEF)
6184 bad_type(arg, "block", gv_ename(namegv), o2);
6187 /* '*' allows any scalar type, including bareword */
6190 if (o2->op_type == OP_RV2GV)
6191 goto wrapref; /* autoconvert GLOB -> GLOBref */
6192 else if (o2->op_type == OP_CONST)
6193 o2->op_private &= ~OPpCONST_STRICT;
6194 else if (o2->op_type == OP_ENTERSUB) {
6195 /* accidental subroutine, revert to bareword */
6196 OP *gvop = ((UNOP*)o2)->op_first;
6197 if (gvop && gvop->op_type == OP_NULL) {
6198 gvop = ((UNOP*)gvop)->op_first;
6200 for (; gvop->op_sibling; gvop = gvop->op_sibling)
6203 (gvop->op_private & OPpENTERSUB_NOPAREN) &&
6204 (gvop = ((UNOP*)gvop)->op_first) &&
6205 gvop->op_type == OP_GV)
6207 GV *gv = cGVOPx_gv(gvop);
6208 OP *sibling = o2->op_sibling;
6209 SV *n = newSVpvn("",0);
6211 gv_fullname3(n, gv, "");
6212 if (SvCUR(n)>6 && strnEQ(SvPVX(n),"main::",6))
6213 sv_chop(n, SvPVX(n)+6);
6214 o2 = newSVOP(OP_CONST, 0, n);
6215 prev->op_sibling = o2;
6216 o2->op_sibling = sibling;
6228 if (o2->op_type != OP_RV2GV)
6229 bad_type(arg, "symbol", gv_ename(namegv), o2);
6232 if (o2->op_type != OP_RV2CV)
6233 bad_type(arg, "sub", gv_ename(namegv), o2);
6236 if (o2->op_type != OP_RV2SV
6237 && o2->op_type != OP_PADSV
6238 && o2->op_type != OP_HELEM
6239 && o2->op_type != OP_AELEM
6240 && o2->op_type != OP_THREADSV)
6242 bad_type(arg, "scalar", gv_ename(namegv), o2);
6246 if (o2->op_type != OP_RV2AV && o2->op_type != OP_PADAV)
6247 bad_type(arg, "array", gv_ename(namegv), o2);
6250 if (o2->op_type != OP_RV2HV && o2->op_type != OP_PADHV)
6251 bad_type(arg, "hash", gv_ename(namegv), o2);
6255 OP* sib = kid->op_sibling;
6256 kid->op_sibling = 0;
6257 o2 = newUNOP(OP_REFGEN, 0, kid);
6258 o2->op_sibling = sib;
6259 prev->op_sibling = o2;
6270 Perl_croak(aTHX_ "Malformed prototype for %s: %s",
6271 gv_ename(namegv), SvPV((SV*)cv, n_a));
6276 mod(o2, OP_ENTERSUB);
6278 o2 = o2->op_sibling;
6280 if (proto && !optional &&
6281 (*proto && *proto != '@' && *proto != '%' && *proto != ';'))
6282 return too_few_arguments(o, gv_ename(namegv));
6287 Perl_ck_svconst(pTHX_ OP *o)
6289 SvREADONLY_on(cSVOPo->op_sv);
6294 Perl_ck_trunc(pTHX_ OP *o)
6296 if (o->op_flags & OPf_KIDS) {
6297 SVOP *kid = (SVOP*)cUNOPo->op_first;
6299 if (kid->op_type == OP_NULL)
6300 kid = (SVOP*)kid->op_sibling;
6301 if (kid && kid->op_type == OP_CONST &&
6302 (kid->op_private & OPpCONST_BARE))
6304 o->op_flags |= OPf_SPECIAL;
6305 kid->op_private &= ~OPpCONST_STRICT;
6311 /* A peephole optimizer. We visit the ops in the order they're to execute. */
6314 Perl_peep(pTHX_ register OP *o)
6317 register OP* oldop = 0;
6319 OP *last_composite = Nullop;
6321 if (!o || o->op_seq)
6325 SAVEVPTR(PL_curcop);
6326 for (; o; o = o->op_next) {
6332 switch (o->op_type) {
6336 PL_curcop = ((COP*)o); /* for warnings */
6337 o->op_seq = PL_op_seqmax++;
6338 last_composite = Nullop;
6342 if (cSVOPo->op_private & OPpCONST_STRICT)
6343 no_bareword_allowed(o);
6345 /* Relocate sv to the pad for thread safety.
6346 * Despite being a "constant", the SV is written to,
6347 * for reference counts, sv_upgrade() etc. */
6349 PADOFFSET ix = pad_alloc(OP_CONST, SVs_PADTMP);
6350 SvREFCNT_dec(PL_curpad[ix]);
6351 SvPADTMP_on(cSVOPo->op_sv);
6352 PL_curpad[ix] = cSVOPo->op_sv;
6353 cSVOPo->op_sv = Nullsv;
6365 if (o->op_next && o->op_next->op_type == OP_STRINGIFY) {
6366 if (o->op_next->op_private & OPpTARGET_MY) {
6367 if (o->op_flags & OPf_STACKED) /* chained concats */
6368 goto ignore_optimization;
6370 o->op_targ = o->op_next->op_targ;
6371 o->op_next->op_targ = 0;
6372 o->op_private |= OPpTARGET_MY;
6377 ignore_optimization:
6378 o->op_seq = PL_op_seqmax++;
6381 if ((o->op_flags & OPf_WANT) != OPf_WANT_LIST) {
6382 o->op_seq = PL_op_seqmax++;
6383 break; /* Scalar stub must produce undef. List stub is noop */
6387 if (o->op_targ == OP_NEXTSTATE
6388 || o->op_targ == OP_DBSTATE
6389 || o->op_targ == OP_SETSTATE)
6391 PL_curcop = ((COP*)o);
6398 if (oldop && o->op_next) {
6399 oldop->op_next = o->op_next;
6402 o->op_seq = PL_op_seqmax++;
6406 if (o->op_next->op_type == OP_RV2SV) {
6407 if (!(o->op_next->op_private & OPpDEREF)) {
6409 o->op_private |= o->op_next->op_private & (OPpLVAL_INTRO
6411 o->op_next = o->op_next->op_next;
6412 o->op_type = OP_GVSV;
6413 o->op_ppaddr = PL_ppaddr[OP_GVSV];
6416 else if (o->op_next->op_type == OP_RV2AV) {
6417 OP* pop = o->op_next->op_next;
6419 if (pop->op_type == OP_CONST &&
6420 (PL_op = pop->op_next) &&
6421 pop->op_next->op_type == OP_AELEM &&
6422 !(pop->op_next->op_private &
6423 (OPpLVAL_INTRO|OPpLVAL_DEFER|OPpDEREF)) &&
6424 (i = SvIV(((SVOP*)pop)->op_sv) - PL_compiling.cop_arybase)
6432 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
6433 o->op_next = pop->op_next->op_next;
6434 o->op_type = OP_AELEMFAST;
6435 o->op_ppaddr = PL_ppaddr[OP_AELEMFAST];
6436 o->op_private = (U8)i;
6441 else if ((o->op_private & OPpEARLY_CV) && ckWARN(WARN_PROTOTYPE)) {
6443 if (SvTYPE(gv) == SVt_PVGV && GvCV(gv) && SvPVX(GvCV(gv))) {
6444 /* XXX could check prototype here instead of just carping */
6445 SV *sv = sv_newmortal();
6446 gv_efullname3(sv, gv, Nullch);
6447 Perl_warner(aTHX_ WARN_PROTOTYPE,
6448 "%s() called too early to check prototype",
6453 o->op_seq = PL_op_seqmax++;
6464 o->op_seq = PL_op_seqmax++;
6465 while (cLOGOP->op_other->op_type == OP_NULL)
6466 cLOGOP->op_other = cLOGOP->op_other->op_next;
6467 peep(cLOGOP->op_other);
6471 o->op_seq = PL_op_seqmax++;
6472 peep(cLOOP->op_redoop);
6473 peep(cLOOP->op_nextop);
6474 peep(cLOOP->op_lastop);
6480 o->op_seq = PL_op_seqmax++;
6481 peep(cPMOP->op_pmreplstart);
6485 o->op_seq = PL_op_seqmax++;
6486 if (ckWARN(WARN_SYNTAX) && o->op_next
6487 && o->op_next->op_type == OP_NEXTSTATE) {
6488 if (o->op_next->op_sibling &&
6489 o->op_next->op_sibling->op_type != OP_EXIT &&
6490 o->op_next->op_sibling->op_type != OP_WARN &&
6491 o->op_next->op_sibling->op_type != OP_DIE) {
6492 line_t oldline = CopLINE(PL_curcop);
6494 CopLINE_set(PL_curcop, CopLINE((COP*)o->op_next));
6495 Perl_warner(aTHX_ WARN_EXEC,
6496 "Statement unlikely to be reached");
6497 Perl_warner(aTHX_ WARN_EXEC,
6498 "(Maybe you meant system() when you said exec()?)\n");
6499 CopLINE_set(PL_curcop, oldline);
6508 SV **svp, **indsvp, *sv;
6513 o->op_seq = PL_op_seqmax++;
6514 if ((o->op_private & (OPpLVAL_INTRO))
6515 || ((BINOP*)o)->op_last->op_type != OP_CONST)
6517 rop = (UNOP*)((BINOP*)o)->op_first;
6518 if (rop->op_type != OP_RV2HV || rop->op_first->op_type != OP_PADSV)
6520 lexname = *av_fetch(PL_comppad_name, rop->op_first->op_targ, TRUE);
6521 if (!SvOBJECT(lexname))
6523 fields = (GV**)hv_fetch(SvSTASH(lexname), "FIELDS", 6, FALSE);
6524 if (!fields || !GvHV(*fields))
6526 svp = cSVOPx_svp(((BINOP*)o)->op_last);
6527 key = SvPV(*svp, keylen);
6528 indsvp = hv_fetch(GvHV(*fields), key, keylen, FALSE);
6530 Perl_croak(aTHX_ "No such pseudo-hash field \"%s\" in variable %s of type %s",
6531 key, SvPV(lexname, n_a), HvNAME(SvSTASH(lexname)));
6533 ind = SvIV(*indsvp);
6535 Perl_croak(aTHX_ "Bad index while coercing array into hash");
6536 rop->op_type = OP_RV2AV;
6537 rop->op_ppaddr = PL_ppaddr[OP_RV2AV];
6538 o->op_type = OP_AELEM;
6539 o->op_ppaddr = PL_ppaddr[OP_AELEM];
6541 if (SvREADONLY(*svp))
6543 SvFLAGS(sv) |= (SvFLAGS(*svp)
6544 & (SVs_PADBUSY|SVs_PADTMP|SVs_PADMY));
6554 SV **svp, **indsvp, *sv;
6558 SVOP *first_key_op, *key_op;
6560 o->op_seq = PL_op_seqmax++;
6561 if ((o->op_private & (OPpLVAL_INTRO))
6562 /* I bet there's always a pushmark... */
6563 || ((LISTOP*)o)->op_first->op_sibling->op_type != OP_LIST)
6564 /* hmmm, no optimization if list contains only one key. */
6566 rop = (UNOP*)((LISTOP*)o)->op_last;
6567 if (rop->op_type != OP_RV2HV || rop->op_first->op_type != OP_PADSV)
6569 lexname = *av_fetch(PL_comppad_name, rop->op_first->op_targ, TRUE);
6570 if (!SvOBJECT(lexname))
6572 fields = (GV**)hv_fetch(SvSTASH(lexname), "FIELDS", 6, FALSE);
6573 if (!fields || !GvHV(*fields))
6575 /* Again guessing that the pushmark can be jumped over.... */
6576 first_key_op = (SVOP*)((LISTOP*)((LISTOP*)o)->op_first->op_sibling)
6577 ->op_first->op_sibling;
6578 /* Check that the key list contains only constants. */
6579 for (key_op = first_key_op; key_op;
6580 key_op = (SVOP*)key_op->op_sibling)
6581 if (key_op->op_type != OP_CONST)
6585 rop->op_type = OP_RV2AV;
6586 rop->op_ppaddr = PL_ppaddr[OP_RV2AV];
6587 o->op_type = OP_ASLICE;
6588 o->op_ppaddr = PL_ppaddr[OP_ASLICE];
6589 for (key_op = first_key_op; key_op;
6590 key_op = (SVOP*)key_op->op_sibling) {
6591 svp = cSVOPx_svp(key_op);
6592 key = SvPV(*svp, keylen);
6593 indsvp = hv_fetch(GvHV(*fields), key, keylen, FALSE);
6595 Perl_croak(aTHX_ "No such pseudo-hash field \"%s\" "
6596 "in variable %s of type %s",
6597 key, SvPV(lexname, n_a), HvNAME(SvSTASH(lexname)));
6599 ind = SvIV(*indsvp);
6601 Perl_croak(aTHX_ "Bad index while coercing array into hash");
6603 if (SvREADONLY(*svp))
6605 SvFLAGS(sv) |= (SvFLAGS(*svp)
6606 & (SVs_PADBUSY|SVs_PADTMP|SVs_PADMY));
6615 if (!(o->op_flags & OPf_WANT)
6616 || (o->op_flags & OPf_WANT) == OPf_WANT_LIST)
6620 o->op_seq = PL_op_seqmax++;
6624 if (o->op_next && o->op_next->op_type != OP_LEAVESUBLV) {
6625 o->op_seq = PL_op_seqmax++;
6631 if (last_composite) {
6632 OP *r = last_composite;
6634 while (r->op_sibling)
6637 || (r->op_next->op_type == OP_LIST
6638 && r->op_next->op_next == o))
6640 if (last_composite->op_type == OP_RV2AV)
6641 yyerror("Lvalue subs returning arrays not implemented yet");
6643 yyerror("Lvalue subs returning hashes not implemented yet");
6650 o->op_seq = PL_op_seqmax++;