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 */
27 # define OP_REFCNT_LOCK NOOP
28 # define OP_REFCNT_UNLOCK NOOP
29 # define OpREFCNT_set(o,n) ((o)->op_targ = (n))
30 # define OpREFCNT_dec(o) (--(o)->op_targ)
32 # define OP_REFCNT_LOCK NOOP
33 # define OP_REFCNT_UNLOCK NOOP
34 # define OpREFCNT_set(o,n) NOOP
35 # define OpREFCNT_dec(o) 0
38 #ifdef PL_OP_SLAB_ALLOC
39 #define SLAB_SIZE 8192
40 static char *PL_OpPtr = NULL;
41 static int PL_OpSpace = 0;
42 #define NewOp(m,var,c,type) do { if ((PL_OpSpace -= c*sizeof(type)) >= 0) \
43 var = (type *)(PL_OpPtr -= c*sizeof(type)); \
45 var = (type *) Slab_Alloc(m,c*sizeof(type)); \
49 S_Slab_Alloc(pTHX_ int m, size_t sz)
51 Newz(m,PL_OpPtr,SLAB_SIZE,char);
52 PL_OpSpace = SLAB_SIZE - sz;
53 return PL_OpPtr += PL_OpSpace;
57 #define NewOp(m, var, c, type) Newz(m, var, c, type)
60 * In the following definition, the ", Nullop" is just to make the compiler
61 * think the expression is of the right type: croak actually does a Siglongjmp.
63 #define CHECKOP(type,o) \
64 ((PL_op_mask && PL_op_mask[type]) \
65 ? ( op_free((OP*)o), \
66 Perl_croak(aTHX_ "%s trapped by operation mask", PL_op_desc[type]), \
68 : CALL_FPTR(PL_check[type])(aTHX_ (OP*)o))
70 #define PAD_MAX 999999999
73 S_gv_ename(pTHX_ GV *gv)
76 SV* tmpsv = sv_newmortal();
77 gv_efullname3(tmpsv, gv, Nullch);
78 return SvPV(tmpsv,n_a);
82 S_no_fh_allowed(pTHX_ OP *o)
84 yyerror(Perl_form(aTHX_ "Missing comma after first argument to %s function",
85 PL_op_desc[o->op_type]));
90 S_too_few_arguments(pTHX_ OP *o, char *name)
92 yyerror(Perl_form(aTHX_ "Not enough arguments for %s", name));
97 S_too_many_arguments(pTHX_ OP *o, char *name)
99 yyerror(Perl_form(aTHX_ "Too many arguments for %s", name));
104 S_bad_type(pTHX_ I32 n, char *t, char *name, OP *kid)
106 yyerror(Perl_form(aTHX_ "Type of arg %d to %s must be %s (not %s)",
107 (int)n, name, t, PL_op_desc[kid->op_type]));
111 S_no_bareword_allowed(pTHX_ OP *o)
113 qerror(Perl_mess(aTHX_
114 "Bareword \"%s\" not allowed while \"strict subs\" in use",
115 SvPV_nolen(cSVOPo_sv)));
118 /* "register" allocation */
121 Perl_pad_allocmy(pTHX_ char *name)
128 PL_in_my == KEY_our ||
130 (PL_hints & HINT_UTF8 && (name[1] & 0xc0) == 0xc0) ||
131 name[1] == '_' && (int)strlen(name) > 2 ))
133 if (!isPRINT(name[1]) || strchr("\t\n\r\f", name[1])) {
134 /* 1999-02-27 mjd@plover.com */
136 p = strchr(name, '\0');
137 /* The next block assumes the buffer is at least 205 chars
138 long. At present, it's always at least 256 chars. */
140 strcpy(name+200, "...");
146 /* Move everything else down one character */
147 for (; p-name > 2; p--)
149 name[2] = toCTRL(name[1]);
152 yyerror(Perl_form(aTHX_ "Can't use global %s in \"my\"",name));
154 if (ckWARN(WARN_MISC) && AvFILLp(PL_comppad_name) >= 0) {
155 SV **svp = AvARRAY(PL_comppad_name);
156 HV *ourstash = (PL_curstash ? PL_curstash : PL_defstash);
157 PADOFFSET top = AvFILLp(PL_comppad_name);
158 for (off = top; off > PL_comppad_name_floor; off--) {
160 && sv != &PL_sv_undef
161 && (SvIVX(sv) == PAD_MAX || SvIVX(sv) == 0)
162 && (PL_in_my != KEY_our
163 || ((SvFLAGS(sv) & SVpad_OUR) && GvSTASH(sv) == ourstash))
164 && strEQ(name, SvPVX(sv)))
166 Perl_warner(aTHX_ WARN_MISC,
167 "\"%s\" variable %s masks earlier declaration in same %s",
168 (PL_in_my == KEY_our ? "our" : "my"),
170 (SvIVX(sv) == PAD_MAX ? "scope" : "statement"));
175 if (PL_in_my == KEY_our) {
176 while (off >= 0 && off <= top) {
178 && sv != &PL_sv_undef
179 && ((SvFLAGS(sv) & SVpad_OUR) && GvSTASH(sv) == ourstash)
180 && strEQ(name, SvPVX(sv)))
182 Perl_warner(aTHX_ WARN_MISC,
183 "\"our\" variable %s redeclared", name);
184 Perl_warner(aTHX_ WARN_MISC,
185 "(Did you mean \"local\" instead of \"our\"?)\n");
192 off = pad_alloc(OP_PADSV, SVs_PADMY);
194 sv_upgrade(sv, SVt_PVNV);
196 if (PL_in_my_stash) {
198 yyerror(Perl_form(aTHX_ "Can't declare class for non-scalar %s in \"%s\"",
199 name, PL_in_my == KEY_our ? "our" : "my"));
201 (void)SvUPGRADE(sv, SVt_PVMG);
202 SvSTASH(sv) = (HV*)SvREFCNT_inc(PL_in_my_stash);
205 if (PL_in_my == KEY_our) {
206 (void)SvUPGRADE(sv, SVt_PVGV);
207 GvSTASH(sv) = (HV*)SvREFCNT_inc(PL_curstash ? (SV*)PL_curstash : (SV*)PL_defstash);
208 SvFLAGS(sv) |= SVpad_OUR;
210 av_store(PL_comppad_name, off, sv);
211 SvNVX(sv) = (NV)PAD_MAX;
212 SvIVX(sv) = 0; /* Not yet introduced--see newSTATEOP */
213 if (!PL_min_intro_pending)
214 PL_min_intro_pending = off;
215 PL_max_intro_pending = off;
217 av_store(PL_comppad, off, (SV*)newAV());
218 else if (*name == '%')
219 av_store(PL_comppad, off, (SV*)newHV());
220 SvPADMY_on(PL_curpad[off]);
225 S_pad_addlex(pTHX_ SV *proto_namesv)
227 SV *namesv = NEWSV(1103,0);
228 PADOFFSET newoff = pad_alloc(OP_PADSV, SVs_PADMY);
229 sv_upgrade(namesv, SVt_PVNV);
230 sv_setpv(namesv, SvPVX(proto_namesv));
231 av_store(PL_comppad_name, newoff, namesv);
232 SvNVX(namesv) = (NV)PL_curcop->cop_seq;
233 SvIVX(namesv) = PAD_MAX; /* A ref, intro immediately */
234 SvFAKE_on(namesv); /* A ref, not a real var */
235 if (SvFLAGS(proto_namesv) & SVpad_OUR) { /* An "our" variable */
236 SvFLAGS(namesv) |= SVpad_OUR;
237 (void)SvUPGRADE(namesv, SVt_PVGV);
238 GvSTASH(namesv) = (HV*)SvREFCNT_inc((SV*)GvSTASH(proto_namesv));
240 if (SvOBJECT(proto_namesv)) { /* A typed var */
242 (void)SvUPGRADE(namesv, SVt_PVMG);
243 SvSTASH(namesv) = (HV*)SvREFCNT_inc((SV*)SvSTASH(proto_namesv));
249 #define FINDLEX_NOSEARCH 1 /* don't search outer contexts */
252 S_pad_findlex(pTHX_ char *name, PADOFFSET newoff, U32 seq, CV* startcv,
253 I32 cx_ix, I32 saweval, U32 flags)
260 register PERL_CONTEXT *cx;
262 for (cv = startcv; cv; cv = CvOUTSIDE(cv)) {
263 AV *curlist = CvPADLIST(cv);
264 SV **svp = av_fetch(curlist, 0, FALSE);
267 if (!svp || *svp == &PL_sv_undef)
270 svp = AvARRAY(curname);
271 for (off = AvFILLp(curname); off > 0; off--) {
272 if ((sv = svp[off]) &&
273 sv != &PL_sv_undef &&
275 seq > I_32(SvNVX(sv)) &&
276 strEQ(SvPVX(sv), name))
287 return 0; /* don't clone from inactive stack frame */
291 oldpad = (AV*)AvARRAY(curlist)[depth];
292 oldsv = *av_fetch(oldpad, off, TRUE);
293 if (!newoff) { /* Not a mere clone operation. */
294 newoff = pad_addlex(sv);
295 if (CvANON(PL_compcv) || SvTYPE(PL_compcv) == SVt_PVFM) {
296 /* "It's closures all the way down." */
297 CvCLONE_on(PL_compcv);
299 if (CvANON(PL_compcv))
300 oldsv = Nullsv; /* no need to keep ref */
305 bcv && bcv != cv && !CvCLONE(bcv);
306 bcv = CvOUTSIDE(bcv))
309 /* install the missing pad entry in intervening
310 * nested subs and mark them cloneable.
311 * XXX fix pad_foo() to not use globals */
312 AV *ocomppad_name = PL_comppad_name;
313 AV *ocomppad = PL_comppad;
314 SV **ocurpad = PL_curpad;
315 AV *padlist = CvPADLIST(bcv);
316 PL_comppad_name = (AV*)AvARRAY(padlist)[0];
317 PL_comppad = (AV*)AvARRAY(padlist)[1];
318 PL_curpad = AvARRAY(PL_comppad);
320 PL_comppad_name = ocomppad_name;
321 PL_comppad = ocomppad;
326 if (ckWARN(WARN_CLOSURE)
327 && !CvUNIQUE(bcv) && !CvUNIQUE(cv))
329 Perl_warner(aTHX_ WARN_CLOSURE,
330 "Variable \"%s\" may be unavailable",
338 else if (!CvUNIQUE(PL_compcv)) {
339 if (ckWARN(WARN_CLOSURE) && !SvFAKE(sv) && !CvUNIQUE(cv))
340 Perl_warner(aTHX_ WARN_CLOSURE,
341 "Variable \"%s\" will not stay shared", name);
344 av_store(PL_comppad, newoff, SvREFCNT_inc(oldsv));
350 if (flags & FINDLEX_NOSEARCH)
353 /* Nothing in current lexical context--try eval's context, if any.
354 * This is necessary to let the perldb get at lexically scoped variables.
355 * XXX This will also probably interact badly with eval tree caching.
358 for (i = cx_ix; i >= 0; i--) {
360 switch (CxTYPE(cx)) {
362 if (i == 0 && saweval) {
363 seq = cxstack[saweval].blk_oldcop->cop_seq;
364 return pad_findlex(name, newoff, seq, PL_main_cv, -1, saweval, 0);
368 switch (cx->blk_eval.old_op_type) {
374 /* require must have its own scope */
383 if (PL_debstash && CvSTASH(cv) == PL_debstash) { /* ignore DB'* scope */
384 saweval = i; /* so we know where we were called from */
387 seq = cxstack[saweval].blk_oldcop->cop_seq;
388 return pad_findlex(name, newoff, seq, cv, i-1, saweval,FINDLEX_NOSEARCH);
396 Perl_pad_findmy(pTHX_ char *name)
402 SV **svp = AvARRAY(PL_comppad_name);
403 U32 seq = PL_cop_seqmax;
409 * Special case to get lexical (and hence per-thread) @_.
410 * XXX I need to find out how to tell at parse-time whether use
411 * of @_ should refer to a lexical (from a sub) or defgv (global
412 * scope and maybe weird sub-ish things like formats). See
413 * startsub in perly.y. It's possible that @_ could be lexical
414 * (at least from subs) even in non-threaded perl.
416 if (strEQ(name, "@_"))
417 return 0; /* success. (NOT_IN_PAD indicates failure) */
418 #endif /* USE_THREADS */
420 /* The one we're looking for is probably just before comppad_name_fill. */
421 for (off = AvFILLp(PL_comppad_name); off > 0; off--) {
422 if ((sv = svp[off]) &&
423 sv != &PL_sv_undef &&
426 seq > I_32(SvNVX(sv)))) &&
427 strEQ(SvPVX(sv), name))
429 if (SvIVX(sv) || SvFLAGS(sv) & SVpad_OUR)
430 return (PADOFFSET)off;
431 pendoff = off; /* this pending def. will override import */
435 outside = CvOUTSIDE(PL_compcv);
437 /* Check if if we're compiling an eval'', and adjust seq to be the
438 * eval's seq number. This depends on eval'' having a non-null
439 * CvOUTSIDE() while it is being compiled. The eval'' itself is
440 * identified by CvEVAL being true and CvGV being null. */
441 if (outside && CvEVAL(PL_compcv) && !CvGV(PL_compcv) && cxstack_ix >= 0) {
442 cx = &cxstack[cxstack_ix];
444 seq = cx->blk_oldcop->cop_seq;
447 /* See if it's in a nested scope */
448 off = pad_findlex(name, 0, seq, outside, cxstack_ix, 0, 0);
450 /* If there is a pending local definition, this new alias must die */
452 SvIVX(AvARRAY(PL_comppad_name)[off]) = seq;
453 return off; /* pad_findlex returns 0 for failure...*/
455 return NOT_IN_PAD; /* ...but we return NOT_IN_PAD for failure */
459 Perl_pad_leavemy(pTHX_ I32 fill)
463 SV **svp = AvARRAY(PL_comppad_name);
465 if (PL_min_intro_pending && fill < PL_min_intro_pending) {
466 for (off = PL_max_intro_pending; off >= PL_min_intro_pending; off--) {
467 if ((sv = svp[off]) && sv != &PL_sv_undef && ckWARN_d(WARN_INTERNAL))
468 Perl_warner(aTHX_ WARN_INTERNAL, "%s never introduced", SvPVX(sv));
471 /* "Deintroduce" my variables that are leaving with this scope. */
472 for (off = AvFILLp(PL_comppad_name); off > fill; off--) {
473 if ((sv = svp[off]) && sv != &PL_sv_undef && SvIVX(sv) == PAD_MAX)
474 SvIVX(sv) = PL_cop_seqmax;
479 Perl_pad_alloc(pTHX_ I32 optype, U32 tmptype)
485 if (AvARRAY(PL_comppad) != PL_curpad)
486 Perl_croak(aTHX_ "panic: pad_alloc");
487 if (PL_pad_reset_pending)
489 if (tmptype & SVs_PADMY) {
491 sv = *av_fetch(PL_comppad, AvFILLp(PL_comppad) + 1, TRUE);
492 } while (SvPADBUSY(sv)); /* need a fresh one */
493 retval = AvFILLp(PL_comppad);
496 SV **names = AvARRAY(PL_comppad_name);
497 SSize_t names_fill = AvFILLp(PL_comppad_name);
500 * "foreach" index vars temporarily become aliases to non-"my"
501 * values. Thus we must skip, not just pad values that are
502 * marked as current pad values, but also those with names.
504 if (++PL_padix <= names_fill &&
505 (sv = names[PL_padix]) && sv != &PL_sv_undef)
507 sv = *av_fetch(PL_comppad, PL_padix, TRUE);
508 if (!(SvFLAGS(sv) & (SVs_PADTMP|SVs_PADMY)) && !IS_PADGV(sv))
513 SvFLAGS(sv) |= tmptype;
514 PL_curpad = AvARRAY(PL_comppad);
516 DEBUG_X(PerlIO_printf(Perl_debug_log,
517 "0x%"UVxf" Pad 0x%"UVxf" alloc %ld for %s\n",
518 PTR2UV(thr), PTR2UV(PL_curpad),
519 (long) retval, PL_op_name[optype]));
521 DEBUG_X(PerlIO_printf(Perl_debug_log,
522 "Pad 0x%"UVxf" alloc %ld for %s\n",
524 (long) retval, PL_op_name[optype]));
525 #endif /* USE_THREADS */
526 return (PADOFFSET)retval;
530 Perl_pad_sv(pTHX_ PADOFFSET po)
534 DEBUG_X(PerlIO_printf(Perl_debug_log,
535 "0x%"UVxf" Pad 0x%"UVxf" sv %"IVdf"\n",
536 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
539 Perl_croak(aTHX_ "panic: pad_sv po");
540 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" sv %"IVdf"\n",
541 PTR2UV(PL_curpad), (IV)po));
542 #endif /* USE_THREADS */
543 return PL_curpad[po]; /* eventually we'll turn this into a macro */
547 Perl_pad_free(pTHX_ PADOFFSET po)
552 if (AvARRAY(PL_comppad) != PL_curpad)
553 Perl_croak(aTHX_ "panic: pad_free curpad");
555 Perl_croak(aTHX_ "panic: pad_free po");
557 DEBUG_X(PerlIO_printf(Perl_debug_log,
558 "0x%"UVxf" Pad 0x%"UVxf" free %"IVdf"\n",
559 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
561 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" free %"IVdf"\n",
562 PTR2UV(PL_curpad), (IV)po));
563 #endif /* USE_THREADS */
564 if (PL_curpad[po] && PL_curpad[po] != &PL_sv_undef) {
565 SvPADTMP_off(PL_curpad[po]);
567 SvREADONLY_off(PL_curpad[po]); /* could be a freed constant */
570 if ((I32)po < PL_padix)
575 Perl_pad_swipe(pTHX_ PADOFFSET po)
578 if (AvARRAY(PL_comppad) != PL_curpad)
579 Perl_croak(aTHX_ "panic: pad_swipe curpad");
581 Perl_croak(aTHX_ "panic: pad_swipe po");
583 DEBUG_X(PerlIO_printf(Perl_debug_log,
584 "0x%"UVxf" Pad 0x%"UVxf" swipe %"IVdf"\n",
585 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
587 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" swipe %"IVdf"\n",
588 PTR2UV(PL_curpad), (IV)po));
589 #endif /* USE_THREADS */
590 SvPADTMP_off(PL_curpad[po]);
591 PL_curpad[po] = NEWSV(1107,0);
592 SvPADTMP_on(PL_curpad[po]);
593 if ((I32)po < PL_padix)
597 /* XXX pad_reset() is currently disabled because it results in serious bugs.
598 * It causes pad temp TARGs to be shared between OPs. Since TARGs are pushed
599 * on the stack by OPs that use them, there are several ways to get an alias
600 * to a shared TARG. Such an alias will change randomly and unpredictably.
601 * We avoid doing this until we can think of a Better Way.
606 #ifdef USE_BROKEN_PAD_RESET
610 if (AvARRAY(PL_comppad) != PL_curpad)
611 Perl_croak(aTHX_ "panic: pad_reset curpad");
613 DEBUG_X(PerlIO_printf(Perl_debug_log,
614 "0x%"UVxf" Pad 0x%"UVxf" reset\n",
615 PTR2UV(thr), PTR2UV(PL_curpad)));
617 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" reset\n",
619 #endif /* USE_THREADS */
620 if (!PL_tainting) { /* Can't mix tainted and non-tainted temporaries. */
621 for (po = AvMAX(PL_comppad); po > PL_padix_floor; po--) {
622 if (PL_curpad[po] && !SvIMMORTAL(PL_curpad[po]))
623 SvPADTMP_off(PL_curpad[po]);
625 PL_padix = PL_padix_floor;
628 PL_pad_reset_pending = FALSE;
632 /* find_threadsv is not reentrant */
634 Perl_find_threadsv(pTHX_ const char *name)
640 /* We currently only handle names of a single character */
641 p = strchr(PL_threadsv_names, *name);
644 key = p - PL_threadsv_names;
645 MUTEX_LOCK(&thr->mutex);
646 svp = av_fetch(thr->threadsv, key, FALSE);
648 MUTEX_UNLOCK(&thr->mutex);
650 SV *sv = NEWSV(0, 0);
651 av_store(thr->threadsv, key, sv);
652 thr->threadsvp = AvARRAY(thr->threadsv);
653 MUTEX_UNLOCK(&thr->mutex);
655 * Some magic variables used to be automagically initialised
656 * in gv_fetchpv. Those which are now per-thread magicals get
657 * initialised here instead.
663 sv_setpv(sv, "\034");
664 sv_magic(sv, 0, 0, name, 1);
669 PL_sawampersand = TRUE;
683 /* XXX %! tied to Errno.pm needs to be added here.
684 * See gv_fetchpv(). */
688 sv_magic(sv, 0, 0, name, 1);
690 DEBUG_S(PerlIO_printf(Perl_error_log,
691 "find_threadsv: new SV %p for $%s%c\n",
692 sv, (*name < 32) ? "^" : "",
693 (*name < 32) ? toCTRL(*name) : *name));
697 #endif /* USE_THREADS */
702 Perl_op_free(pTHX_ OP *o)
704 register OP *kid, *nextkid;
707 if (!o || o->op_seq == (U16)-1)
710 if (o->op_private & OPpREFCOUNTED) {
711 switch (o->op_type) {
719 if (OpREFCNT_dec(o)) {
730 if (o->op_flags & OPf_KIDS) {
731 for (kid = cUNOPo->op_first; kid; kid = nextkid) {
732 nextkid = kid->op_sibling; /* Get before next freeing kid */
740 /* COP* is not cleared by op_clear() so that we may track line
741 * numbers etc even after null() */
742 if (type == OP_NEXTSTATE || type == OP_SETSTATE || type == OP_DBSTATE)
747 #ifdef PL_OP_SLAB_ALLOC
748 if ((char *) o == PL_OpPtr)
757 S_op_clear(pTHX_ OP *o)
759 switch (o->op_type) {
760 case OP_NULL: /* Was holding old type, if any. */
761 case OP_ENTEREVAL: /* Was holding hints. */
763 case OP_THREADSV: /* Was holding index into thr->threadsv AV. */
769 if (!(o->op_flags & OPf_SPECIAL))
772 #endif /* USE_THREADS */
774 if (!(o->op_flags & OPf_REF)
775 || (PL_check[o->op_type] != MEMBER_TO_FPTR(Perl_ck_ftst)))
782 if (cPADOPo->op_padix > 0) {
785 pad_swipe(cPADOPo->op_padix);
786 /* No GvIN_PAD_off(gv) here, because other references may still
787 * exist on the pad */
790 cPADOPo->op_padix = 0;
793 SvREFCNT_dec(cSVOPo->op_sv);
794 cSVOPo->op_sv = Nullsv;
798 SvREFCNT_dec(cSVOPo->op_sv);
799 cSVOPo->op_sv = Nullsv;
805 if (o->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
809 if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
810 SvREFCNT_dec(cSVOPo->op_sv);
811 cSVOPo->op_sv = Nullsv;
814 Safefree(cPVOPo->op_pv);
815 cPVOPo->op_pv = Nullch;
819 op_free(cPMOPo->op_pmreplroot);
823 if ((PADOFFSET)cPMOPo->op_pmreplroot) {
825 GV *gv = (GV*)PL_curpad[(PADOFFSET)cPMOPo->op_pmreplroot];
826 pad_swipe((PADOFFSET)cPMOPo->op_pmreplroot);
827 /* No GvIN_PAD_off(gv) here, because other references may still
828 * exist on the pad */
833 SvREFCNT_dec((SV*)cPMOPo->op_pmreplroot);
839 cPMOPo->op_pmreplroot = Nullop;
840 ReREFCNT_dec(cPMOPo->op_pmregexp);
841 cPMOPo->op_pmregexp = (REGEXP*)NULL;
845 if (o->op_targ > 0) {
846 pad_free(o->op_targ);
852 S_cop_free(pTHX_ COP* cop)
854 Safefree(cop->cop_label);
856 Safefree(CopFILE(cop)); /* XXXXX share in a pvtable? */
857 Safefree(CopSTASHPV(cop)); /* XXXXX share in a pvtable? */
859 /* NOTE: COP.cop_stash is not refcounted */
860 SvREFCNT_dec(CopFILEGV(cop));
862 if (! specialWARN(cop->cop_warnings))
863 SvREFCNT_dec(cop->cop_warnings);
869 if (o->op_type == OP_NULL)
872 o->op_targ = o->op_type;
873 o->op_type = OP_NULL;
874 o->op_ppaddr = PL_ppaddr[OP_NULL];
877 /* Contextualizers */
879 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
882 Perl_linklist(pTHX_ OP *o)
889 /* establish postfix order */
890 if (cUNOPo->op_first) {
891 o->op_next = LINKLIST(cUNOPo->op_first);
892 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
894 kid->op_next = LINKLIST(kid->op_sibling);
906 Perl_scalarkids(pTHX_ OP *o)
909 if (o && o->op_flags & OPf_KIDS) {
910 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
917 S_scalarboolean(pTHX_ OP *o)
919 if (o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST) {
921 if (ckWARN(WARN_SYNTAX)) {
922 line_t oldline = CopLINE(PL_curcop);
924 if (PL_copline != NOLINE)
925 CopLINE_set(PL_curcop, PL_copline);
926 Perl_warner(aTHX_ WARN_SYNTAX, "Found = in conditional, should be ==");
927 CopLINE_set(PL_curcop, oldline);
934 Perl_scalar(pTHX_ OP *o)
938 /* assumes no premature commitment */
939 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
940 || o->op_type == OP_RETURN)
945 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_SCALAR;
947 switch (o->op_type) {
949 if (o->op_private & OPpREPEAT_DOLIST)
950 null(((LISTOP*)cBINOPo->op_first)->op_first);
951 scalar(cBINOPo->op_first);
956 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
960 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
961 if (!kPMOP->op_pmreplroot)
962 deprecate("implicit split to @_");
970 if (o->op_flags & OPf_KIDS) {
971 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
977 kid = cLISTOPo->op_first;
979 while (kid = kid->op_sibling) {
985 WITH_THR(PL_curcop = &PL_compiling);
990 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
996 WITH_THR(PL_curcop = &PL_compiling);
1003 Perl_scalarvoid(pTHX_ OP *o)
1010 if (o->op_type == OP_NEXTSTATE
1011 || o->op_type == OP_SETSTATE
1012 || o->op_type == OP_DBSTATE
1013 || (o->op_type == OP_NULL && (o->op_targ == OP_NEXTSTATE
1014 || o->op_targ == OP_SETSTATE
1015 || o->op_targ == OP_DBSTATE)))
1018 PL_curcop = (COP*)o; /* for warning below */
1021 /* assumes no premature commitment */
1022 want = o->op_flags & OPf_WANT;
1023 if ((want && want != OPf_WANT_SCALAR) || PL_error_count
1024 || o->op_type == OP_RETURN)
1029 if ((o->op_private & OPpTARGET_MY)
1030 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
1032 return scalar(o); /* As if inside SASSIGN */
1035 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_VOID;
1037 switch (o->op_type) {
1039 if (!(PL_opargs[o->op_type] & OA_FOLDCONST))
1043 if (o->op_flags & OPf_STACKED)
1047 if (o->op_private == 4)
1089 case OP_GETSOCKNAME:
1090 case OP_GETPEERNAME:
1095 case OP_GETPRIORITY:
1118 if (!(o->op_private & (OPpLVAL_INTRO|OPpOUR_INTRO)))
1119 useless = PL_op_desc[o->op_type];
1126 if (!(o->op_private & (OPpLVAL_INTRO|OPpOUR_INTRO)) &&
1127 (!o->op_sibling || o->op_sibling->op_type != OP_READLINE))
1128 useless = "a variable";
1133 if (cSVOPo->op_private & OPpCONST_STRICT)
1134 no_bareword_allowed(o);
1137 if (ckWARN(WARN_VOID)) {
1138 useless = "a constant";
1139 if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
1141 else if (SvPOK(sv)) {
1142 if (strnEQ(SvPVX(sv), "di", 2) ||
1143 strnEQ(SvPVX(sv), "ds", 2) ||
1144 strnEQ(SvPVX(sv), "ig", 2))
1149 null(o); /* don't execute or even remember it */
1153 o->op_type = OP_PREINC; /* pre-increment is faster */
1154 o->op_ppaddr = PL_ppaddr[OP_PREINC];
1158 o->op_type = OP_PREDEC; /* pre-decrement is faster */
1159 o->op_ppaddr = PL_ppaddr[OP_PREDEC];
1165 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1170 if (o->op_flags & OPf_STACKED)
1178 if (!(o->op_flags & OPf_KIDS))
1187 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1194 /* all requires must return a boolean value */
1195 o->op_flags &= ~OPf_WANT;
1198 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
1199 if (!kPMOP->op_pmreplroot)
1200 deprecate("implicit split to @_");
1206 if (ckWARN(WARN_VOID))
1207 Perl_warner(aTHX_ WARN_VOID, "Useless use of %s in void context", useless);
1213 Perl_listkids(pTHX_ OP *o)
1216 if (o && o->op_flags & OPf_KIDS) {
1217 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1224 Perl_list(pTHX_ OP *o)
1228 /* assumes no premature commitment */
1229 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
1230 || o->op_type == OP_RETURN)
1235 if ((o->op_private & OPpTARGET_MY)
1236 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
1238 return o; /* As if inside SASSIGN */
1241 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_LIST;
1243 switch (o->op_type) {
1246 list(cBINOPo->op_first);
1251 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1259 if (!(o->op_flags & OPf_KIDS))
1261 if (!o->op_next && cUNOPo->op_first->op_type == OP_FLOP) {
1262 list(cBINOPo->op_first);
1263 return gen_constant_list(o);
1270 kid = cLISTOPo->op_first;
1272 while (kid = kid->op_sibling) {
1273 if (kid->op_sibling)
1278 WITH_THR(PL_curcop = &PL_compiling);
1282 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
1283 if (kid->op_sibling)
1288 WITH_THR(PL_curcop = &PL_compiling);
1291 /* all requires must return a boolean value */
1292 o->op_flags &= ~OPf_WANT;
1299 Perl_scalarseq(pTHX_ OP *o)
1304 if (o->op_type == OP_LINESEQ ||
1305 o->op_type == OP_SCOPE ||
1306 o->op_type == OP_LEAVE ||
1307 o->op_type == OP_LEAVETRY)
1310 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
1311 if (kid->op_sibling) {
1315 PL_curcop = &PL_compiling;
1317 o->op_flags &= ~OPf_PARENS;
1318 if (PL_hints & HINT_BLOCK_SCOPE)
1319 o->op_flags |= OPf_PARENS;
1322 o = newOP(OP_STUB, 0);
1327 S_modkids(pTHX_ OP *o, I32 type)
1330 if (o && o->op_flags & OPf_KIDS) {
1331 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1338 Perl_mod(pTHX_ OP *o, I32 type)
1345 if (!o || PL_error_count)
1348 if ((o->op_private & OPpTARGET_MY)
1349 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
1354 switch (o->op_type) {
1359 if (!(o->op_private & (OPpCONST_ARYBASE)))
1361 if (PL_eval_start && PL_eval_start->op_type == OP_CONST) {
1362 PL_compiling.cop_arybase = (I32)SvIV(cSVOPx(PL_eval_start)->op_sv);
1366 SAVEI32(PL_compiling.cop_arybase);
1367 PL_compiling.cop_arybase = 0;
1369 else if (type == OP_REFGEN)
1372 Perl_croak(aTHX_ "That use of $[ is unsupported");
1375 if (o->op_flags & OPf_PARENS)
1379 if ((type == OP_UNDEF || type == OP_REFGEN) &&
1380 !(o->op_flags & OPf_STACKED)) {
1381 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1382 o->op_ppaddr = PL_ppaddr[OP_RV2CV];
1383 assert(cUNOPo->op_first->op_type == OP_NULL);
1384 null(((LISTOP*)cUNOPo->op_first)->op_first);/* disable pushmark */
1387 else { /* lvalue subroutine call */
1388 o->op_private |= OPpLVAL_INTRO;
1389 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN) {
1390 /* Backward compatibility mode: */
1391 o->op_private |= OPpENTERSUB_INARGS;
1394 else { /* Compile-time error message: */
1395 OP *kid = cUNOPo->op_first;
1399 if (kid->op_type == OP_PUSHMARK)
1401 if (kid->op_type != OP_NULL || kid->op_targ != OP_LIST)
1403 "panic: unexpected lvalue entersub "
1404 "args: type/targ %ld:%ld",
1405 (long)kid->op_type,kid->op_targ);
1406 kid = kLISTOP->op_first;
1408 while (kid->op_sibling)
1409 kid = kid->op_sibling;
1410 if (!(kid->op_type == OP_NULL && kid->op_targ == OP_RV2CV)) {
1412 if (kid->op_type == OP_METHOD_NAMED
1413 || kid->op_type == OP_METHOD)
1417 if (kid->op_sibling || kid->op_next != kid) {
1418 yyerror("panic: unexpected optree near method call");
1422 NewOp(1101, newop, 1, UNOP);
1423 newop->op_type = OP_RV2CV;
1424 newop->op_ppaddr = PL_ppaddr[OP_RV2CV];
1425 newop->op_first = Nullop;
1426 newop->op_next = (OP*)newop;
1427 kid->op_sibling = (OP*)newop;
1428 newop->op_private |= OPpLVAL_INTRO;
1432 if (kid->op_type != OP_RV2CV)
1434 "panic: unexpected lvalue entersub "
1435 "entry via type/targ %ld:%ld",
1436 (long)kid->op_type,kid->op_targ);
1437 kid->op_private |= OPpLVAL_INTRO;
1438 break; /* Postpone until runtime */
1442 kid = kUNOP->op_first;
1443 if (kid->op_type == OP_NULL && kid->op_targ == OP_RV2SV)
1444 kid = kUNOP->op_first;
1445 if (kid->op_type == OP_NULL)
1447 "Unexpected constant lvalue entersub "
1448 "entry via type/targ %ld:%ld",
1449 (long)kid->op_type,kid->op_targ);
1450 if (kid->op_type != OP_GV) {
1451 /* Restore RV2CV to check lvalueness */
1453 if (kid->op_next && kid->op_next != kid) { /* Happens? */
1454 okid->op_next = kid->op_next;
1455 kid->op_next = okid;
1458 okid->op_next = Nullop;
1459 okid->op_type = OP_RV2CV;
1461 okid->op_ppaddr = PL_ppaddr[OP_RV2CV];
1462 okid->op_private |= OPpLVAL_INTRO;
1466 cv = GvCV(kGVOP_gv);
1476 /* grep, foreach, subcalls, refgen */
1477 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
1479 yyerror(Perl_form(aTHX_ "Can't modify %s in %s",
1480 (o->op_type == OP_NULL && (o->op_flags & OPf_SPECIAL)
1482 : (o->op_type == OP_ENTERSUB
1483 ? "non-lvalue subroutine call"
1484 : PL_op_desc[o->op_type])),
1485 type ? PL_op_desc[type] : "local"));
1499 case OP_RIGHT_SHIFT:
1508 if (!(o->op_flags & OPf_STACKED))
1514 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1520 if (!type && cUNOPo->op_first->op_type != OP_GV)
1521 Perl_croak(aTHX_ "Can't localize through a reference");
1522 if (type == OP_REFGEN && o->op_flags & OPf_PARENS) {
1523 PL_modcount = 10000;
1524 return o; /* Treat \(@foo) like ordinary list. */
1528 if (scalar_mod_type(o, type))
1530 ref(cUNOPo->op_first, o->op_type);
1539 PL_modcount = 10000;
1542 if (!type && cUNOPo->op_first->op_type != OP_GV)
1543 Perl_croak(aTHX_ "Can't localize through a reference");
1544 ref(cUNOPo->op_first, o->op_type);
1548 PL_hints |= HINT_BLOCK_SCOPE;
1558 PL_modcount = 10000;
1559 if (type == OP_REFGEN && o->op_flags & OPf_PARENS)
1560 return o; /* Treat \(@foo) like ordinary list. */
1561 if (scalar_mod_type(o, type))
1567 Perl_croak(aTHX_ "Can't localize lexical variable %s",
1568 SvPV(*av_fetch(PL_comppad_name, o->op_targ, 4), n_a));
1573 PL_modcount++; /* XXX ??? */
1575 #endif /* USE_THREADS */
1581 if (type != OP_SASSIGN)
1585 if (o->op_private == 4) /* don't allow 4 arg substr as lvalue */
1591 pad_free(o->op_targ);
1592 o->op_targ = pad_alloc(o->op_type, SVs_PADMY);
1593 assert(SvTYPE(PAD_SV(o->op_targ)) == SVt_NULL);
1594 if (o->op_flags & OPf_KIDS)
1595 mod(cBINOPo->op_first->op_sibling, type);
1600 ref(cBINOPo->op_first, o->op_type);
1601 if (type == OP_ENTERSUB &&
1602 !(o->op_private & (OPpLVAL_INTRO | OPpDEREF)))
1603 o->op_private |= OPpLVAL_DEFER;
1610 if (o->op_flags & OPf_KIDS)
1611 mod(cLISTOPo->op_last, type);
1615 if (o->op_flags & OPf_SPECIAL) /* do BLOCK */
1617 else if (!(o->op_flags & OPf_KIDS))
1619 if (o->op_targ != OP_LIST) {
1620 mod(cBINOPo->op_first, type);
1625 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1629 o->op_flags |= OPf_MOD;
1631 if (type == OP_AASSIGN || type == OP_SASSIGN)
1632 o->op_flags |= OPf_SPECIAL|OPf_REF;
1634 o->op_private |= OPpLVAL_INTRO;
1635 o->op_flags &= ~OPf_SPECIAL;
1636 PL_hints |= HINT_BLOCK_SCOPE;
1638 else if (type != OP_GREPSTART && type != OP_ENTERSUB)
1639 o->op_flags |= OPf_REF;
1644 S_scalar_mod_type(pTHX_ OP *o, I32 type)
1648 if (o->op_type == OP_RV2GV)
1672 case OP_RIGHT_SHIFT:
1691 S_is_handle_constructor(pTHX_ OP *o, I32 argnum)
1693 switch (o->op_type) {
1701 case OP_SELECT: /* XXX c.f. SelectSaver.pm */
1714 Perl_refkids(pTHX_ OP *o, I32 type)
1717 if (o && o->op_flags & OPf_KIDS) {
1718 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1725 Perl_ref(pTHX_ OP *o, I32 type)
1729 if (!o || PL_error_count)
1732 switch (o->op_type) {
1734 if ((type == OP_EXISTS || type == OP_DEFINED || type == OP_LOCK) &&
1735 !(o->op_flags & OPf_STACKED)) {
1736 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1737 o->op_ppaddr = PL_ppaddr[OP_RV2CV];
1738 assert(cUNOPo->op_first->op_type == OP_NULL);
1739 null(((LISTOP*)cUNOPo->op_first)->op_first); /* disable pushmark */
1740 o->op_flags |= OPf_SPECIAL;
1745 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1749 if (type == OP_DEFINED)
1750 o->op_flags |= OPf_SPECIAL; /* don't create GV */
1751 ref(cUNOPo->op_first, o->op_type);
1754 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1755 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1756 : type == OP_RV2HV ? OPpDEREF_HV
1758 o->op_flags |= OPf_MOD;
1763 o->op_flags |= OPf_MOD; /* XXX ??? */
1768 o->op_flags |= OPf_REF;
1771 if (type == OP_DEFINED)
1772 o->op_flags |= OPf_SPECIAL; /* don't create GV */
1773 ref(cUNOPo->op_first, o->op_type);
1778 o->op_flags |= OPf_REF;
1783 if (!(o->op_flags & OPf_KIDS))
1785 ref(cBINOPo->op_first, type);
1789 ref(cBINOPo->op_first, o->op_type);
1790 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1791 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1792 : type == OP_RV2HV ? OPpDEREF_HV
1794 o->op_flags |= OPf_MOD;
1802 if (!(o->op_flags & OPf_KIDS))
1804 ref(cLISTOPo->op_last, type);
1814 S_dup_attrlist(pTHX_ OP *o)
1818 /* An attrlist is either a simple OP_CONST or an OP_LIST with kids,
1819 * where the first kid is OP_PUSHMARK and the remaining ones
1820 * are OP_CONST. We need to push the OP_CONST values.
1822 if (o->op_type == OP_CONST)
1823 rop = newSVOP(OP_CONST, o->op_flags, SvREFCNT_inc(cSVOPo->op_sv));
1825 assert((o->op_type == OP_LIST) && (o->op_flags & OPf_KIDS));
1826 for (o = cLISTOPo->op_first; o; o=o->op_sibling) {
1827 if (o->op_type == OP_CONST)
1828 rop = append_elem(OP_LIST, rop,
1829 newSVOP(OP_CONST, o->op_flags,
1830 SvREFCNT_inc(cSVOPo->op_sv)));
1837 S_apply_attrs(pTHX_ HV *stash, SV *target, OP *attrs)
1839 OP *modname; /* for 'use' */
1842 /* fake up C<use attributes $pkg,$rv,@attrs> */
1843 ENTER; /* need to protect against side-effects of 'use' */
1845 if (stash && HvNAME(stash))
1846 stashsv = newSVpv(HvNAME(stash), 0);
1848 stashsv = &PL_sv_no;
1849 #define ATTRSMODULE "attributes"
1850 modname = newSVOP(OP_CONST, 0,
1851 newSVpvn(ATTRSMODULE, sizeof(ATTRSMODULE)-1));
1852 modname->op_private |= OPpCONST_BARE;
1853 /* that flag is required to make 'use' work right */
1854 utilize(1, start_subparse(FALSE, 0),
1855 Nullop, /* version */
1857 prepend_elem(OP_LIST,
1858 newSVOP(OP_CONST, 0, stashsv),
1859 prepend_elem(OP_LIST,
1860 newSVOP(OP_CONST, 0, newRV(target)),
1861 dup_attrlist(attrs))));
1866 S_my_kid(pTHX_ OP *o, OP *attrs)
1871 if (!o || PL_error_count)
1875 if (type == OP_LIST) {
1876 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1878 } else if (type == OP_UNDEF) {
1880 } else if (type == OP_RV2SV || /* "our" declaration */
1882 type == OP_RV2HV) { /* XXX does this let anything illegal in? */
1883 o->op_private |= OPpOUR_INTRO;
1885 } else if (type != OP_PADSV &&
1888 type != OP_PUSHMARK)
1890 yyerror(Perl_form(aTHX_ "Can't declare %s in \"%s\"",
1891 PL_op_desc[o->op_type],
1892 PL_in_my == KEY_our ? "our" : "my"));
1895 else if (attrs && type != OP_PUSHMARK) {
1901 PL_in_my_stash = Nullhv;
1903 /* check for C<my Dog $spot> when deciding package */
1904 namesvp = av_fetch(PL_comppad_name, o->op_targ, FALSE);
1905 if (namesvp && *namesvp && SvOBJECT(*namesvp) && HvNAME(SvSTASH(*namesvp)))
1906 stash = SvSTASH(*namesvp);
1908 stash = PL_curstash;
1909 padsv = PAD_SV(o->op_targ);
1910 apply_attrs(stash, padsv, attrs);
1912 o->op_flags |= OPf_MOD;
1913 o->op_private |= OPpLVAL_INTRO;
1918 Perl_my_attrs(pTHX_ OP *o, OP *attrs)
1920 if (o->op_flags & OPf_PARENS)
1924 o = my_kid(o, attrs);
1926 PL_in_my_stash = Nullhv;
1931 Perl_my(pTHX_ OP *o)
1933 return my_kid(o, Nullop);
1937 Perl_sawparens(pTHX_ OP *o)
1940 o->op_flags |= OPf_PARENS;
1945 Perl_bind_match(pTHX_ I32 type, OP *left, OP *right)
1950 if (ckWARN(WARN_MISC) &&
1951 (left->op_type == OP_RV2AV ||
1952 left->op_type == OP_RV2HV ||
1953 left->op_type == OP_PADAV ||
1954 left->op_type == OP_PADHV)) {
1955 char *desc = PL_op_desc[(right->op_type == OP_SUBST ||
1956 right->op_type == OP_TRANS)
1957 ? right->op_type : OP_MATCH];
1958 const char *sample = ((left->op_type == OP_RV2AV ||
1959 left->op_type == OP_PADAV)
1960 ? "@array" : "%hash");
1961 Perl_warner(aTHX_ WARN_MISC,
1962 "Applying %s to %s will act on scalar(%s)",
1963 desc, sample, sample);
1966 if (right->op_type == OP_MATCH ||
1967 right->op_type == OP_SUBST ||
1968 right->op_type == OP_TRANS) {
1969 right->op_flags |= OPf_STACKED;
1970 if (right->op_type != OP_MATCH)
1971 left = mod(left, right->op_type);
1972 if (right->op_type == OP_TRANS)
1973 o = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
1975 o = prepend_elem(right->op_type, scalar(left), right);
1977 return newUNOP(OP_NOT, 0, scalar(o));
1981 return bind_match(type, left,
1982 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
1986 Perl_invert(pTHX_ OP *o)
1990 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
1991 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(o));
1995 Perl_scope(pTHX_ OP *o)
1998 if (o->op_flags & OPf_PARENS || PERLDB_NOOPT || PL_tainting) {
1999 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
2000 o->op_type = OP_LEAVE;
2001 o->op_ppaddr = PL_ppaddr[OP_LEAVE];
2004 if (o->op_type == OP_LINESEQ) {
2006 o->op_type = OP_SCOPE;
2007 o->op_ppaddr = PL_ppaddr[OP_SCOPE];
2008 kid = ((LISTOP*)o)->op_first;
2009 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE)
2013 o = newLISTOP(OP_SCOPE, 0, o, Nullop);
2020 Perl_save_hints(pTHX)
2023 SAVESPTR(GvHV(PL_hintgv));
2024 GvHV(PL_hintgv) = newHVhv(GvHV(PL_hintgv));
2025 SAVEFREESV(GvHV(PL_hintgv));
2029 Perl_block_start(pTHX_ int full)
2032 int retval = PL_savestack_ix;
2034 SAVEI32(PL_comppad_name_floor);
2035 PL_comppad_name_floor = AvFILLp(PL_comppad_name);
2037 PL_comppad_name_fill = PL_comppad_name_floor;
2038 if (PL_comppad_name_floor < 0)
2039 PL_comppad_name_floor = 0;
2040 SAVEI32(PL_min_intro_pending);
2041 SAVEI32(PL_max_intro_pending);
2042 PL_min_intro_pending = 0;
2043 SAVEI32(PL_comppad_name_fill);
2044 SAVEI32(PL_padix_floor);
2045 PL_padix_floor = PL_padix;
2046 PL_pad_reset_pending = FALSE;
2048 PL_hints &= ~HINT_BLOCK_SCOPE;
2049 SAVESPTR(PL_compiling.cop_warnings);
2050 if (! specialWARN(PL_compiling.cop_warnings)) {
2051 PL_compiling.cop_warnings = newSVsv(PL_compiling.cop_warnings) ;
2052 SAVEFREESV(PL_compiling.cop_warnings) ;
2058 Perl_block_end(pTHX_ I32 floor, OP *seq)
2061 int needblockscope = PL_hints & HINT_BLOCK_SCOPE;
2062 OP* retval = scalarseq(seq);
2064 PL_pad_reset_pending = FALSE;
2065 PL_compiling.op_private = PL_hints;
2067 PL_hints |= HINT_BLOCK_SCOPE; /* propagate out */
2068 pad_leavemy(PL_comppad_name_fill);
2077 OP *o = newOP(OP_THREADSV, 0);
2078 o->op_targ = find_threadsv("_");
2081 return newSVREF(newGVOP(OP_GV, 0, PL_defgv));
2082 #endif /* USE_THREADS */
2086 Perl_newPROG(pTHX_ OP *o)
2092 PL_eval_root = newUNOP(OP_LEAVEEVAL,
2093 ((PL_in_eval & EVAL_KEEPERR)
2094 ? OPf_SPECIAL : 0), o);
2095 PL_eval_start = linklist(PL_eval_root);
2096 PL_eval_root->op_private |= OPpREFCOUNTED;
2097 OpREFCNT_set(PL_eval_root, 1);
2098 PL_eval_root->op_next = 0;
2099 peep(PL_eval_start);
2104 PL_main_root = scope(sawparens(scalarvoid(o)));
2105 PL_curcop = &PL_compiling;
2106 PL_main_start = LINKLIST(PL_main_root);
2107 PL_main_root->op_private |= OPpREFCOUNTED;
2108 OpREFCNT_set(PL_main_root, 1);
2109 PL_main_root->op_next = 0;
2110 peep(PL_main_start);
2113 /* Register with debugger */
2115 CV *cv = get_cv("DB::postponed", FALSE);
2119 XPUSHs((SV*)CopFILEGV(&PL_compiling));
2121 call_sv((SV*)cv, G_DISCARD);
2128 Perl_localize(pTHX_ OP *o, I32 lex)
2130 if (o->op_flags & OPf_PARENS)
2134 if (ckWARN(WARN_PARENTHESIS) && PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == ',') {
2136 for (s = PL_bufptr; *s && (isALNUM(*s) || (*s & 0x80) || strchr("@$%, ",*s)); s++) ;
2137 if (*s == ';' || *s == '=')
2138 Perl_warner(aTHX_ WARN_PARENTHESIS,
2139 "Parentheses missing around \"%s\" list",
2140 lex ? (PL_in_my == KEY_our ? "our" : "my") : "local");
2146 o = mod(o, OP_NULL); /* a bit kludgey */
2148 PL_in_my_stash = Nullhv;
2153 Perl_jmaybe(pTHX_ OP *o)
2155 if (o->op_type == OP_LIST) {
2158 o2 = newOP(OP_THREADSV, 0);
2159 o2->op_targ = find_threadsv(";");
2161 o2 = newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
2162 #endif /* USE_THREADS */
2163 o = convert(OP_JOIN, 0, prepend_elem(OP_LIST, o2, o));
2169 Perl_fold_constants(pTHX_ register OP *o)
2173 I32 type = o->op_type;
2176 if (PL_opargs[type] & OA_RETSCALAR)
2178 if (PL_opargs[type] & OA_TARGET && !o->op_targ)
2179 o->op_targ = pad_alloc(type, SVs_PADTMP);
2181 /* integerize op, unless it happens to be C<-foo>.
2182 * XXX should pp_i_negate() do magic string negation instead? */
2183 if ((PL_opargs[type] & OA_OTHERINT) && (PL_hints & HINT_INTEGER)
2184 && !(type == OP_NEGATE && cUNOPo->op_first->op_type == OP_CONST
2185 && (cUNOPo->op_first->op_private & OPpCONST_BARE)))
2187 o->op_ppaddr = PL_ppaddr[type = ++(o->op_type)];
2190 if (!(PL_opargs[type] & OA_FOLDCONST))
2195 /* XXX might want a ck_negate() for this */
2196 cUNOPo->op_first->op_private &= ~OPpCONST_STRICT;
2209 if (o->op_private & OPpLOCALE)
2214 goto nope; /* Don't try to run w/ errors */
2216 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
2217 if ((curop->op_type != OP_CONST ||
2218 (curop->op_private & OPpCONST_BARE)) &&
2219 curop->op_type != OP_LIST &&
2220 curop->op_type != OP_SCALAR &&
2221 curop->op_type != OP_NULL &&
2222 curop->op_type != OP_PUSHMARK)
2228 curop = LINKLIST(o);
2232 sv = *(PL_stack_sp--);
2233 if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
2234 pad_swipe(o->op_targ);
2235 else if (SvTEMP(sv)) { /* grab mortal temp? */
2236 (void)SvREFCNT_inc(sv);
2240 if (type == OP_RV2GV)
2241 return newGVOP(OP_GV, 0, (GV*)sv);
2243 /* try to smush double to int, but don't smush -2.0 to -2 */
2244 if ((SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK)) == SVf_NOK &&
2248 if ((NV)iv == SvNV(sv)) {
2253 SvIOK_off(sv); /* undo SvIV() damage */
2255 return newSVOP(OP_CONST, 0, sv);
2259 if (!(PL_opargs[type] & OA_OTHERINT))
2262 if (!(PL_hints & HINT_INTEGER)) {
2263 if (type == OP_MODULO
2264 || type == OP_DIVIDE
2265 || !(o->op_flags & OPf_KIDS))
2270 for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
2271 if (curop->op_type == OP_CONST) {
2272 if (SvIOK(((SVOP*)curop)->op_sv))
2276 if (PL_opargs[curop->op_type] & OA_RETINTEGER)
2280 o->op_ppaddr = PL_ppaddr[++(o->op_type)];
2287 Perl_gen_constant_list(pTHX_ register OP *o)
2291 I32 oldtmps_floor = PL_tmps_floor;
2295 return o; /* Don't attempt to run with errors */
2297 PL_op = curop = LINKLIST(o);
2304 PL_tmps_floor = oldtmps_floor;
2306 o->op_type = OP_RV2AV;
2307 o->op_ppaddr = PL_ppaddr[OP_RV2AV];
2308 curop = ((UNOP*)o)->op_first;
2309 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*PL_stack_sp--));
2316 Perl_convert(pTHX_ I32 type, I32 flags, OP *o)
2321 if (!o || o->op_type != OP_LIST)
2322 o = newLISTOP(OP_LIST, 0, o, Nullop);
2324 o->op_flags &= ~OPf_WANT;
2326 if (!(PL_opargs[type] & OA_MARK))
2327 null(cLISTOPo->op_first);
2330 o->op_ppaddr = PL_ppaddr[type];
2331 o->op_flags |= flags;
2333 o = CHECKOP(type, o);
2334 if (o->op_type != type)
2337 if (cLISTOPo->op_children < 7) {
2338 /* XXX do we really need to do this if we're done appending?? */
2339 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
2341 cLISTOPo->op_last = last; /* in case check substituted last arg */
2344 return fold_constants(o);
2347 /* List constructors */
2350 Perl_append_elem(pTHX_ I32 type, OP *first, OP *last)
2358 if (first->op_type != type || type==OP_LIST && first->op_flags & OPf_PARENS)
2359 return newLISTOP(type, 0, first, last);
2361 if (first->op_flags & OPf_KIDS)
2362 ((LISTOP*)first)->op_last->op_sibling = last;
2364 first->op_flags |= OPf_KIDS;
2365 ((LISTOP*)first)->op_first = last;
2367 ((LISTOP*)first)->op_last = last;
2368 ((LISTOP*)first)->op_children++;
2373 Perl_append_list(pTHX_ I32 type, LISTOP *first, LISTOP *last)
2381 if (first->op_type != type)
2382 return prepend_elem(type, (OP*)first, (OP*)last);
2384 if (last->op_type != type)
2385 return append_elem(type, (OP*)first, (OP*)last);
2387 first->op_last->op_sibling = last->op_first;
2388 first->op_last = last->op_last;
2389 first->op_children += last->op_children;
2390 if (first->op_children)
2391 first->op_flags |= OPf_KIDS;
2393 #ifdef PL_OP_SLAB_ALLOC
2401 Perl_prepend_elem(pTHX_ I32 type, OP *first, OP *last)
2409 if (last->op_type == type) {
2410 if (type == OP_LIST) { /* already a PUSHMARK there */
2411 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
2412 ((LISTOP*)last)->op_first->op_sibling = first;
2415 if (!(last->op_flags & OPf_KIDS)) {
2416 ((LISTOP*)last)->op_last = first;
2417 last->op_flags |= OPf_KIDS;
2419 first->op_sibling = ((LISTOP*)last)->op_first;
2420 ((LISTOP*)last)->op_first = first;
2422 ((LISTOP*)last)->op_children++;
2426 return newLISTOP(type, 0, first, last);
2432 Perl_newNULLLIST(pTHX)
2434 return newOP(OP_STUB, 0);
2438 Perl_force_list(pTHX_ OP *o)
2440 if (!o || o->op_type != OP_LIST)
2441 o = newLISTOP(OP_LIST, 0, o, Nullop);
2447 Perl_newLISTOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
2451 NewOp(1101, listop, 1, LISTOP);
2453 listop->op_type = type;
2454 listop->op_ppaddr = PL_ppaddr[type];
2455 listop->op_children = (first != 0) + (last != 0);
2456 listop->op_flags = flags;
2460 else if (!first && last)
2463 first->op_sibling = last;
2464 listop->op_first = first;
2465 listop->op_last = last;
2466 if (type == OP_LIST) {
2468 pushop = newOP(OP_PUSHMARK, 0);
2469 pushop->op_sibling = first;
2470 listop->op_first = pushop;
2471 listop->op_flags |= OPf_KIDS;
2473 listop->op_last = pushop;
2475 else if (listop->op_children)
2476 listop->op_flags |= OPf_KIDS;
2482 Perl_newOP(pTHX_ I32 type, I32 flags)
2485 NewOp(1101, o, 1, OP);
2487 o->op_ppaddr = PL_ppaddr[type];
2488 o->op_flags = flags;
2491 o->op_private = 0 + (flags >> 8);
2492 if (PL_opargs[type] & OA_RETSCALAR)
2494 if (PL_opargs[type] & OA_TARGET)
2495 o->op_targ = pad_alloc(type, SVs_PADTMP);
2496 return CHECKOP(type, o);
2500 Perl_newUNOP(pTHX_ I32 type, I32 flags, OP *first)
2505 first = newOP(OP_STUB, 0);
2506 if (PL_opargs[type] & OA_MARK)
2507 first = force_list(first);
2509 NewOp(1101, unop, 1, UNOP);
2510 unop->op_type = type;
2511 unop->op_ppaddr = PL_ppaddr[type];
2512 unop->op_first = first;
2513 unop->op_flags = flags | OPf_KIDS;
2514 unop->op_private = 1 | (flags >> 8);
2515 unop = (UNOP*) CHECKOP(type, unop);
2519 return fold_constants((OP *) unop);
2523 Perl_newBINOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
2526 NewOp(1101, binop, 1, BINOP);
2529 first = newOP(OP_NULL, 0);
2531 binop->op_type = type;
2532 binop->op_ppaddr = PL_ppaddr[type];
2533 binop->op_first = first;
2534 binop->op_flags = flags | OPf_KIDS;
2537 binop->op_private = 1 | (flags >> 8);
2540 binop->op_private = 2 | (flags >> 8);
2541 first->op_sibling = last;
2544 binop = (BINOP*)CHECKOP(type, binop);
2545 if (binop->op_next || binop->op_type != type)
2548 binop->op_last = binop->op_first->op_sibling;
2550 return fold_constants((OP *)binop);
2554 utf8compare(const void *a, const void *b)
2557 for (i = 0; i < 10; i++) {
2558 if ((*(U8**)a)[i] < (*(U8**)b)[i])
2560 if ((*(U8**)a)[i] > (*(U8**)b)[i])
2567 Perl_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
2569 SV *tstr = ((SVOP*)expr)->op_sv;
2570 SV *rstr = ((SVOP*)repl)->op_sv;
2573 register U8 *t = (U8*)SvPV(tstr, tlen);
2574 register U8 *r = (U8*)SvPV(rstr, rlen);
2580 register short *tbl;
2582 complement = o->op_private & OPpTRANS_COMPLEMENT;
2583 del = o->op_private & OPpTRANS_DELETE;
2584 squash = o->op_private & OPpTRANS_SQUASH;
2586 if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
2587 SV* listsv = newSVpvn("# comment\n",10);
2589 U8* tend = t + tlen;
2590 U8* rend = r + rlen;
2606 I32 from_utf = o->op_private & OPpTRANS_FROM_UTF;
2607 I32 to_utf = o->op_private & OPpTRANS_TO_UTF;
2610 U8 tmpbuf[UTF8_MAXLEN];
2613 New(1109, cp, tlen, U8*);
2615 transv = newSVpvn("",0);
2624 qsort(cp, i, sizeof(U8*), utf8compare);
2625 for (j = 0; j < i; j++) {
2627 UV val = utf8_to_uv(s, &ulen);
2629 diff = val - nextmin;
2631 t = uv_to_utf8(tmpbuf,nextmin);
2632 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2634 t = uv_to_utf8(tmpbuf, val - 1);
2635 sv_catpvn(transv, "\377", 1);
2636 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2640 val = utf8_to_uv(s+1, &ulen);
2644 t = uv_to_utf8(tmpbuf,nextmin);
2645 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2646 t = uv_to_utf8(tmpbuf, 0x7fffffff);
2647 sv_catpvn(transv, "\377", 1);
2648 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2649 t = (U8*)SvPVX(transv);
2650 tlen = SvCUR(transv);
2653 else if (!rlen && !del) {
2654 r = t; rlen = tlen; rend = tend;
2657 if (to_utf && from_utf) { /* only counting characters */
2658 if (t == r || (tlen == rlen && memEQ(t, r, tlen)))
2659 o->op_private |= OPpTRANS_IDENTICAL;
2661 else { /* straight latin-1 translation */
2662 if (tlen == 4 && memEQ(t, "\0\377\303\277", 4) &&
2663 rlen == 4 && memEQ(r, "\0\377\303\277", 4))
2664 o->op_private |= OPpTRANS_IDENTICAL;
2668 while (t < tend || tfirst <= tlast) {
2669 /* see if we need more "t" chars */
2670 if (tfirst > tlast) {
2671 tfirst = (I32)utf8_to_uv(t, &ulen);
2673 if (t < tend && *t == 0xff) { /* illegal utf8 val indicates range */
2674 tlast = (I32)utf8_to_uv(++t, &ulen);
2681 /* now see if we need more "r" chars */
2682 if (rfirst > rlast) {
2684 rfirst = (I32)utf8_to_uv(r, &ulen);
2686 if (r < rend && *r == 0xff) { /* illegal utf8 val indicates range */
2687 rlast = (I32)utf8_to_uv(++r, &ulen);
2696 rfirst = rlast = 0xffffffff;
2700 /* now see which range will peter our first, if either. */
2701 tdiff = tlast - tfirst;
2702 rdiff = rlast - rfirst;
2709 if (rfirst == 0xffffffff) {
2710 diff = tdiff; /* oops, pretend rdiff is infinite */
2712 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t%04lx\tXXXX\n",
2713 (long)tfirst, (long)tlast);
2715 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t\tXXXX\n", (long)tfirst);
2719 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t%04lx\t%04lx\n",
2720 (long)tfirst, (long)(tfirst + diff),
2723 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t\t%04lx\n",
2724 (long)tfirst, (long)rfirst);
2726 if (rfirst + diff > max)
2727 max = rfirst + diff;
2732 else if (rfirst <= 0x800)
2733 grows |= (tfirst < 0x80);
2734 else if (rfirst <= 0x10000)
2735 grows |= (tfirst < 0x800);
2736 else if (rfirst <= 0x200000)
2737 grows |= (tfirst < 0x10000);
2738 else if (rfirst <= 0x4000000)
2739 grows |= (tfirst < 0x200000);
2740 else if (rfirst <= 0x80000000)
2741 grows |= (tfirst < 0x4000000);
2753 else if (max > 0xff)
2758 cSVOPo->op_sv = (SV*)swash_init("utf8", "", listsv, bits, none);
2759 SvREFCNT_dec(listsv);
2761 SvREFCNT_dec(transv);
2763 if (!del && havefinal)
2764 (void)hv_store((HV*)SvRV((cSVOPo->op_sv)), "FINAL", 5, newSViv((IV)final), 0);
2766 if (grows && to_utf)
2767 o->op_private |= OPpTRANS_GROWS;
2774 tbl = (short*)cPVOPo->op_pv;
2776 Zero(tbl, 256, short);
2777 for (i = 0; i < tlen; i++)
2779 for (i = 0, j = 0; i < 256; i++) {
2795 if (!rlen && !del) {
2798 o->op_private |= OPpTRANS_IDENTICAL;
2800 for (i = 0; i < 256; i++)
2802 for (i = 0, j = 0; i < tlen; i++,j++) {
2805 if (tbl[t[i]] == -1)
2811 if (tbl[t[i]] == -1)
2822 Perl_newPMOP(pTHX_ I32 type, I32 flags)
2827 NewOp(1101, pmop, 1, PMOP);
2828 pmop->op_type = type;
2829 pmop->op_ppaddr = PL_ppaddr[type];
2830 pmop->op_flags = flags;
2831 pmop->op_private = 0 | (flags >> 8);
2833 if (PL_hints & HINT_RE_TAINT)
2834 pmop->op_pmpermflags |= PMf_RETAINT;
2835 if (PL_hints & HINT_LOCALE)
2836 pmop->op_pmpermflags |= PMf_LOCALE;
2837 pmop->op_pmflags = pmop->op_pmpermflags;
2839 /* link into pm list */
2840 if (type != OP_TRANS && PL_curstash) {
2841 pmop->op_pmnext = HvPMROOT(PL_curstash);
2842 HvPMROOT(PL_curstash) = pmop;
2849 Perl_pmruntime(pTHX_ OP *o, OP *expr, OP *repl)
2854 I32 repl_has_vars = 0;
2856 if (o->op_type == OP_TRANS)
2857 return pmtrans(o, expr, repl);
2859 PL_hints |= HINT_BLOCK_SCOPE;
2862 if (expr->op_type == OP_CONST) {
2864 SV *pat = ((SVOP*)expr)->op_sv;
2865 char *p = SvPV(pat, plen);
2866 if ((o->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
2867 sv_setpvn(pat, "\\s+", 3);
2868 p = SvPV(pat, plen);
2869 pm->op_pmflags |= PMf_SKIPWHITE;
2871 if ((PL_hints & HINT_UTF8) || (SvUTF8(pat) && !(PL_hints & HINT_BYTE)))
2872 pm->op_pmdynflags |= PMdf_UTF8;
2873 pm->op_pmregexp = CALLREGCOMP(aTHX_ p, p + plen, pm);
2874 if (strEQ("\\s+", pm->op_pmregexp->precomp))
2875 pm->op_pmflags |= PMf_WHITE;
2879 if (PL_hints & HINT_UTF8)
2880 pm->op_pmdynflags |= PMdf_UTF8;
2881 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL))
2882 expr = newUNOP((!(PL_hints & HINT_RE_EVAL)
2884 : OP_REGCMAYBE),0,expr);
2886 NewOp(1101, rcop, 1, LOGOP);
2887 rcop->op_type = OP_REGCOMP;
2888 rcop->op_ppaddr = PL_ppaddr[OP_REGCOMP];
2889 rcop->op_first = scalar(expr);
2890 rcop->op_flags |= ((PL_hints & HINT_RE_EVAL)
2891 ? (OPf_SPECIAL | OPf_KIDS)
2893 rcop->op_private = 1;
2896 /* establish postfix order */
2897 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL)) {
2899 rcop->op_next = expr;
2900 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
2903 rcop->op_next = LINKLIST(expr);
2904 expr->op_next = (OP*)rcop;
2907 prepend_elem(o->op_type, scalar((OP*)rcop), o);
2912 if (pm->op_pmflags & PMf_EVAL) {
2914 if (CopLINE(PL_curcop) < PL_multi_end)
2915 CopLINE_set(PL_curcop, PL_multi_end);
2918 else if (repl->op_type == OP_THREADSV
2919 && strchr("&`'123456789+",
2920 PL_threadsv_names[repl->op_targ]))
2924 #endif /* USE_THREADS */
2925 else if (repl->op_type == OP_CONST)
2929 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
2930 if (PL_opargs[curop->op_type] & OA_DANGEROUS) {
2932 if (curop->op_type == OP_THREADSV) {
2934 if (strchr("&`'123456789+", curop->op_private))
2938 if (curop->op_type == OP_GV) {
2939 GV *gv = cGVOPx_gv(curop);
2941 if (strchr("&`'123456789+", *GvENAME(gv)))
2944 #endif /* USE_THREADS */
2945 else if (curop->op_type == OP_RV2CV)
2947 else if (curop->op_type == OP_RV2SV ||
2948 curop->op_type == OP_RV2AV ||
2949 curop->op_type == OP_RV2HV ||
2950 curop->op_type == OP_RV2GV) {
2951 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
2954 else if (curop->op_type == OP_PADSV ||
2955 curop->op_type == OP_PADAV ||
2956 curop->op_type == OP_PADHV ||
2957 curop->op_type == OP_PADANY) {
2960 else if (curop->op_type == OP_PUSHRE)
2961 ; /* Okay here, dangerous in newASSIGNOP */
2970 && (!pm->op_pmregexp
2971 || pm->op_pmregexp->reganch & ROPT_EVAL_SEEN))) {
2972 pm->op_pmflags |= PMf_CONST; /* const for long enough */
2973 pm->op_pmpermflags |= PMf_CONST; /* const for long enough */
2974 prepend_elem(o->op_type, scalar(repl), o);
2977 if (curop == repl && !pm->op_pmregexp) { /* Has variables. */
2978 pm->op_pmflags |= PMf_MAYBE_CONST;
2979 pm->op_pmpermflags |= PMf_MAYBE_CONST;
2981 NewOp(1101, rcop, 1, LOGOP);
2982 rcop->op_type = OP_SUBSTCONT;
2983 rcop->op_ppaddr = PL_ppaddr[OP_SUBSTCONT];
2984 rcop->op_first = scalar(repl);
2985 rcop->op_flags |= OPf_KIDS;
2986 rcop->op_private = 1;
2989 /* establish postfix order */
2990 rcop->op_next = LINKLIST(repl);
2991 repl->op_next = (OP*)rcop;
2993 pm->op_pmreplroot = scalar((OP*)rcop);
2994 pm->op_pmreplstart = LINKLIST(rcop);
3003 Perl_newSVOP(pTHX_ I32 type, I32 flags, SV *sv)
3006 NewOp(1101, svop, 1, SVOP);
3007 svop->op_type = type;
3008 svop->op_ppaddr = PL_ppaddr[type];
3010 svop->op_next = (OP*)svop;
3011 svop->op_flags = flags;
3012 if (PL_opargs[type] & OA_RETSCALAR)
3014 if (PL_opargs[type] & OA_TARGET)
3015 svop->op_targ = pad_alloc(type, SVs_PADTMP);
3016 return CHECKOP(type, svop);
3020 Perl_newPADOP(pTHX_ I32 type, I32 flags, SV *sv)
3023 NewOp(1101, padop, 1, PADOP);
3024 padop->op_type = type;
3025 padop->op_ppaddr = PL_ppaddr[type];
3026 padop->op_padix = pad_alloc(type, SVs_PADTMP);
3027 SvREFCNT_dec(PL_curpad[padop->op_padix]);
3028 PL_curpad[padop->op_padix] = sv;
3030 padop->op_next = (OP*)padop;
3031 padop->op_flags = flags;
3032 if (PL_opargs[type] & OA_RETSCALAR)
3034 if (PL_opargs[type] & OA_TARGET)
3035 padop->op_targ = pad_alloc(type, SVs_PADTMP);
3036 return CHECKOP(type, padop);
3040 Perl_newGVOP(pTHX_ I32 type, I32 flags, GV *gv)
3045 return newPADOP(type, flags, SvREFCNT_inc(gv));
3047 return newSVOP(type, flags, SvREFCNT_inc(gv));
3052 Perl_newPVOP(pTHX_ I32 type, I32 flags, char *pv)
3055 NewOp(1101, pvop, 1, PVOP);
3056 pvop->op_type = type;
3057 pvop->op_ppaddr = PL_ppaddr[type];
3059 pvop->op_next = (OP*)pvop;
3060 pvop->op_flags = flags;
3061 if (PL_opargs[type] & OA_RETSCALAR)
3063 if (PL_opargs[type] & OA_TARGET)
3064 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
3065 return CHECKOP(type, pvop);
3069 Perl_package(pTHX_ OP *o)
3074 save_hptr(&PL_curstash);
3075 save_item(PL_curstname);
3080 name = SvPV(sv, len);
3081 PL_curstash = gv_stashpvn(name,len,TRUE);
3082 sv_setpvn(PL_curstname, name, len);
3086 sv_setpv(PL_curstname,"<none>");
3087 PL_curstash = Nullhv;
3089 PL_hints |= HINT_BLOCK_SCOPE;
3090 PL_copline = NOLINE;
3095 Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *id, OP *arg)
3104 if (id->op_type != OP_CONST)
3105 Perl_croak(aTHX_ "Module name must be constant");
3109 if (version != Nullop) {
3110 SV *vesv = ((SVOP*)version)->op_sv;
3112 if (arg == Nullop && !SvNIOKp(vesv)) {
3119 if (version->op_type != OP_CONST || !SvNIOKp(vesv))
3120 Perl_croak(aTHX_ "Version number must be constant number");
3122 /* Make copy of id so we don't free it twice */
3123 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
3125 /* Fake up a method call to VERSION */
3126 meth = newSVpvn("VERSION",7);
3127 sv_upgrade(meth, SVt_PVIV);
3129 PERL_HASH(SvUVX(meth), SvPVX(meth), SvCUR(meth));
3130 veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
3131 append_elem(OP_LIST,
3132 prepend_elem(OP_LIST, pack, list(version)),
3133 newSVOP(OP_METHOD_NAMED, 0, meth)));
3137 /* Fake up an import/unimport */
3138 if (arg && arg->op_type == OP_STUB)
3139 imop = arg; /* no import on explicit () */
3140 else if (SvNIOKp(((SVOP*)id)->op_sv)) {
3141 imop = Nullop; /* use 5.0; */
3146 /* Make copy of id so we don't free it twice */
3147 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
3149 /* Fake up a method call to import/unimport */
3150 meth = aver ? newSVpvn("import",6) : newSVpvn("unimport", 8);;
3151 sv_upgrade(meth, SVt_PVIV);
3153 PERL_HASH(SvUVX(meth), SvPVX(meth), SvCUR(meth));
3154 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
3155 append_elem(OP_LIST,
3156 prepend_elem(OP_LIST, pack, list(arg)),
3157 newSVOP(OP_METHOD_NAMED, 0, meth)));
3160 /* Fake up a require, handle override, if any */
3161 gv = gv_fetchpv("require", FALSE, SVt_PVCV);
3162 if (!(gv && GvIMPORTED_CV(gv)))
3163 gv = gv_fetchpv("CORE::GLOBAL::require", FALSE, SVt_PVCV);
3165 if (gv && GvIMPORTED_CV(gv)) {
3166 rqop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
3167 append_elem(OP_LIST, id,
3168 scalar(newUNOP(OP_RV2CV, 0,
3173 rqop = newUNOP(OP_REQUIRE, 0, id);
3176 /* Fake up the BEGIN {}, which does its thing immediately. */
3178 newSVOP(OP_CONST, 0, newSVpvn("BEGIN", 5)),
3181 append_elem(OP_LINESEQ,
3182 append_elem(OP_LINESEQ,
3183 newSTATEOP(0, Nullch, rqop),
3184 newSTATEOP(0, Nullch, veop)),
3185 newSTATEOP(0, Nullch, imop) ));
3187 PL_hints |= HINT_BLOCK_SCOPE;
3188 PL_copline = NOLINE;
3193 Perl_dofile(pTHX_ OP *term)
3198 gv = gv_fetchpv("do", FALSE, SVt_PVCV);
3199 if (!(gv && GvIMPORTED_CV(gv)))
3200 gv = gv_fetchpv("CORE::GLOBAL::do", FALSE, SVt_PVCV);
3202 if (gv && GvIMPORTED_CV(gv)) {
3203 doop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
3204 append_elem(OP_LIST, term,
3205 scalar(newUNOP(OP_RV2CV, 0,
3210 doop = newUNOP(OP_DOFILE, 0, scalar(term));
3216 Perl_newSLICEOP(pTHX_ I32 flags, OP *subscript, OP *listval)
3218 return newBINOP(OP_LSLICE, flags,
3219 list(force_list(subscript)),
3220 list(force_list(listval)) );
3224 S_list_assignment(pTHX_ register OP *o)
3229 if (o->op_type == OP_NULL && o->op_flags & OPf_KIDS)
3230 o = cUNOPo->op_first;
3232 if (o->op_type == OP_COND_EXPR) {
3233 I32 t = list_assignment(cLOGOPo->op_first->op_sibling);
3234 I32 f = list_assignment(cLOGOPo->op_first->op_sibling->op_sibling);
3239 yyerror("Assignment to both a list and a scalar");
3243 if (o->op_type == OP_LIST || o->op_flags & OPf_PARENS ||
3244 o->op_type == OP_RV2AV || o->op_type == OP_RV2HV ||
3245 o->op_type == OP_ASLICE || o->op_type == OP_HSLICE)
3248 if (o->op_type == OP_PADAV || o->op_type == OP_PADHV)
3251 if (o->op_type == OP_RV2SV)
3258 Perl_newASSIGNOP(pTHX_ I32 flags, OP *left, I32 optype, OP *right)
3263 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN) {
3264 return newLOGOP(optype, 0,
3265 mod(scalar(left), optype),
3266 newUNOP(OP_SASSIGN, 0, scalar(right)));
3269 return newBINOP(optype, OPf_STACKED,
3270 mod(scalar(left), optype), scalar(right));
3274 if (list_assignment(left)) {
3277 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
3278 left = mod(left, OP_AASSIGN);
3286 o = newBINOP(OP_AASSIGN, flags,
3287 list(force_list(right)),
3288 list(force_list(left)) );
3289 o->op_private = 0 | (flags >> 8);
3290 if (!(left->op_private & OPpLVAL_INTRO)) {
3294 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
3295 if (PL_opargs[curop->op_type] & OA_DANGEROUS) {
3296 if (curop->op_type == OP_GV) {
3297 GV *gv = cGVOPx_gv(curop);
3298 if (gv == PL_defgv || SvCUR(gv) == PL_generation)
3300 SvCUR(gv) = PL_generation;
3302 else if (curop->op_type == OP_PADSV ||
3303 curop->op_type == OP_PADAV ||
3304 curop->op_type == OP_PADHV ||
3305 curop->op_type == OP_PADANY) {
3306 SV **svp = AvARRAY(PL_comppad_name);
3307 SV *sv = svp[curop->op_targ];
3308 if (SvCUR(sv) == PL_generation)
3310 SvCUR(sv) = PL_generation; /* (SvCUR not used any more) */
3312 else if (curop->op_type == OP_RV2CV)
3314 else if (curop->op_type == OP_RV2SV ||
3315 curop->op_type == OP_RV2AV ||
3316 curop->op_type == OP_RV2HV ||
3317 curop->op_type == OP_RV2GV) {
3318 if (lastop->op_type != OP_GV) /* funny deref? */
3321 else if (curop->op_type == OP_PUSHRE) {
3322 if (((PMOP*)curop)->op_pmreplroot) {
3323 GV *gv = (GV*)((PMOP*)curop)->op_pmreplroot;
3324 if (gv == PL_defgv || SvCUR(gv) == PL_generation)
3326 SvCUR(gv) = PL_generation;
3335 o->op_private = OPpASSIGN_COMMON;
3337 if (right && right->op_type == OP_SPLIT) {
3339 if ((tmpop = ((LISTOP*)right)->op_first) &&
3340 tmpop->op_type == OP_PUSHRE)
3342 PMOP *pm = (PMOP*)tmpop;
3343 if (left->op_type == OP_RV2AV &&
3344 !(left->op_private & OPpLVAL_INTRO) &&
3345 !(o->op_private & OPpASSIGN_COMMON) )
3347 tmpop = ((UNOP*)left)->op_first;
3348 if (tmpop->op_type == OP_GV && !pm->op_pmreplroot) {
3350 pm->op_pmreplroot = (OP*)cPADOPx(tmpop)->op_padix;
3351 cPADOPx(tmpop)->op_padix = 0; /* steal it */
3353 pm->op_pmreplroot = (OP*)cSVOPx(tmpop)->op_sv;
3354 cSVOPx(tmpop)->op_sv = Nullsv; /* steal it */
3356 pm->op_pmflags |= PMf_ONCE;
3357 tmpop = cUNOPo->op_first; /* to list (nulled) */
3358 tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */
3359 tmpop->op_sibling = Nullop; /* don't free split */
3360 right->op_next = tmpop->op_next; /* fix starting loc */
3361 op_free(o); /* blow off assign */
3362 right->op_flags &= ~OPf_WANT;
3363 /* "I don't know and I don't care." */
3368 if (PL_modcount < 10000 &&
3369 ((LISTOP*)right)->op_last->op_type == OP_CONST)
3371 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
3373 sv_setiv(sv, PL_modcount+1);
3381 right = newOP(OP_UNDEF, 0);
3382 if (right->op_type == OP_READLINE) {
3383 right->op_flags |= OPf_STACKED;
3384 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
3387 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
3388 o = newBINOP(OP_SASSIGN, flags,
3389 scalar(right), mod(scalar(left), OP_SASSIGN) );
3401 Perl_newSTATEOP(pTHX_ I32 flags, char *label, OP *o)
3404 U32 seq = intro_my();
3407 NewOp(1101, cop, 1, COP);
3408 if (PERLDB_LINE && CopLINE(PL_curcop) && PL_curstash != PL_debstash) {
3409 cop->op_type = OP_DBSTATE;
3410 cop->op_ppaddr = PL_ppaddr[ OP_DBSTATE ];
3413 cop->op_type = OP_NEXTSTATE;
3414 cop->op_ppaddr = PL_ppaddr[ OP_NEXTSTATE ];
3416 cop->op_flags = flags;
3417 cop->op_private = (PL_hints & HINT_BYTE);
3419 cop->op_private |= NATIVE_HINTS;
3421 PL_compiling.op_private = cop->op_private;
3422 cop->op_next = (OP*)cop;
3425 cop->cop_label = label;
3426 PL_hints |= HINT_BLOCK_SCOPE;
3429 cop->cop_arybase = PL_curcop->cop_arybase;
3430 if (specialWARN(PL_curcop->cop_warnings))
3431 cop->cop_warnings = PL_curcop->cop_warnings ;
3433 cop->cop_warnings = newSVsv(PL_curcop->cop_warnings) ;
3436 if (PL_copline == NOLINE)
3437 CopLINE_set(cop, CopLINE(PL_curcop));
3439 CopLINE_set(cop, PL_copline);
3440 PL_copline = NOLINE;
3443 CopFILE_set(cop, CopFILE(PL_curcop)); /* XXXXX share in a pvtable? */
3445 CopFILEGV_set(cop, (GV*)SvREFCNT_inc(CopFILEGV(PL_curcop)));
3447 CopSTASH_set(cop, PL_curstash);
3449 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3450 SV **svp = av_fetch(CopFILEAV(PL_curcop), (I32)CopLINE(cop), FALSE);
3451 if (svp && *svp != &PL_sv_undef && !SvIOK(*svp)) {
3452 (void)SvIOK_on(*svp);
3453 SvIVX(*svp) = PTR2IV(cop);
3457 return prepend_elem(OP_LINESEQ, (OP*)cop, o);
3460 /* "Introduce" my variables to visible status. */
3468 if (! PL_min_intro_pending)
3469 return PL_cop_seqmax;
3471 svp = AvARRAY(PL_comppad_name);
3472 for (i = PL_min_intro_pending; i <= PL_max_intro_pending; i++) {
3473 if ((sv = svp[i]) && sv != &PL_sv_undef && !SvIVX(sv)) {
3474 SvIVX(sv) = PAD_MAX; /* Don't know scope end yet. */
3475 SvNVX(sv) = (NV)PL_cop_seqmax;
3478 PL_min_intro_pending = 0;
3479 PL_comppad_name_fill = PL_max_intro_pending; /* Needn't search higher */
3480 return PL_cop_seqmax++;
3484 Perl_newLOGOP(pTHX_ I32 type, I32 flags, OP *first, OP *other)
3486 return new_logop(type, flags, &first, &other);
3490 S_new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp)
3495 OP *first = *firstp;
3496 OP *other = *otherp;
3498 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
3499 return newBINOP(type, flags, scalar(first), scalar(other));
3501 scalarboolean(first);
3502 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
3503 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
3504 if (type == OP_AND || type == OP_OR) {
3510 first = *firstp = cUNOPo->op_first;
3512 first->op_next = o->op_next;
3513 cUNOPo->op_first = Nullop;
3517 if (first->op_type == OP_CONST) {
3518 if (ckWARN(WARN_BAREWORD) && (first->op_private & OPpCONST_BARE))
3519 Perl_warner(aTHX_ WARN_BAREWORD, "Bareword found in conditional");
3520 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
3531 else if (first->op_type == OP_WANTARRAY) {
3537 else if (ckWARN(WARN_MISC) && (first->op_flags & OPf_KIDS)) {
3538 OP *k1 = ((UNOP*)first)->op_first;
3539 OP *k2 = k1->op_sibling;
3541 switch (first->op_type)
3544 if (k2 && k2->op_type == OP_READLINE
3545 && (k2->op_flags & OPf_STACKED)
3546 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3548 warnop = k2->op_type;
3553 if (k1->op_type == OP_READDIR
3554 || k1->op_type == OP_GLOB
3555 || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
3556 || k1->op_type == OP_EACH)
3558 warnop = ((k1->op_type == OP_NULL)
3559 ? k1->op_targ : k1->op_type);
3564 line_t oldline = CopLINE(PL_curcop);
3565 CopLINE_set(PL_curcop, PL_copline);
3566 Perl_warner(aTHX_ WARN_MISC,
3567 "Value of %s%s can be \"0\"; test with defined()",
3569 ((warnop == OP_READLINE || warnop == OP_GLOB)
3570 ? " construct" : "() operator"));
3571 CopLINE_set(PL_curcop, oldline);
3578 if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
3579 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
3581 NewOp(1101, logop, 1, LOGOP);
3583 logop->op_type = type;
3584 logop->op_ppaddr = PL_ppaddr[type];
3585 logop->op_first = first;
3586 logop->op_flags = flags | OPf_KIDS;
3587 logop->op_other = LINKLIST(other);
3588 logop->op_private = 1 | (flags >> 8);
3590 /* establish postfix order */
3591 logop->op_next = LINKLIST(first);
3592 first->op_next = (OP*)logop;
3593 first->op_sibling = other;
3595 o = newUNOP(OP_NULL, 0, (OP*)logop);
3602 Perl_newCONDOP(pTHX_ I32 flags, OP *first, OP *trueop, OP *falseop)
3610 return newLOGOP(OP_AND, 0, first, trueop);
3612 return newLOGOP(OP_OR, 0, first, falseop);
3614 scalarboolean(first);
3615 if (first->op_type == OP_CONST) {
3616 if (SvTRUE(((SVOP*)first)->op_sv)) {
3627 else if (first->op_type == OP_WANTARRAY) {
3631 NewOp(1101, logop, 1, LOGOP);
3632 logop->op_type = OP_COND_EXPR;
3633 logop->op_ppaddr = PL_ppaddr[OP_COND_EXPR];
3634 logop->op_first = first;
3635 logop->op_flags = flags | OPf_KIDS;
3636 logop->op_private = 1 | (flags >> 8);
3637 logop->op_other = LINKLIST(trueop);
3638 logop->op_next = LINKLIST(falseop);
3641 /* establish postfix order */
3642 start = LINKLIST(first);
3643 first->op_next = (OP*)logop;
3645 first->op_sibling = trueop;
3646 trueop->op_sibling = falseop;
3647 o = newUNOP(OP_NULL, 0, (OP*)logop);
3649 trueop->op_next = falseop->op_next = o;
3656 Perl_newRANGE(pTHX_ I32 flags, OP *left, OP *right)
3665 NewOp(1101, range, 1, LOGOP);
3667 range->op_type = OP_RANGE;
3668 range->op_ppaddr = PL_ppaddr[OP_RANGE];
3669 range->op_first = left;
3670 range->op_flags = OPf_KIDS;
3671 leftstart = LINKLIST(left);
3672 range->op_other = LINKLIST(right);
3673 range->op_private = 1 | (flags >> 8);
3675 left->op_sibling = right;
3677 range->op_next = (OP*)range;
3678 flip = newUNOP(OP_FLIP, flags, (OP*)range);
3679 flop = newUNOP(OP_FLOP, 0, flip);
3680 o = newUNOP(OP_NULL, 0, flop);
3682 range->op_next = leftstart;
3684 left->op_next = flip;
3685 right->op_next = flop;
3687 range->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
3688 sv_upgrade(PAD_SV(range->op_targ), SVt_PVNV);
3689 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
3690 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
3692 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
3693 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
3696 if (!flip->op_private || !flop->op_private)
3697 linklist(o); /* blow off optimizer unless constant */
3703 Perl_newLOOPOP(pTHX_ I32 flags, I32 debuggable, OP *expr, OP *block)
3708 int once = block && block->op_flags & OPf_SPECIAL &&
3709 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
3712 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
3713 return block; /* do {} while 0 does once */
3714 if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
3715 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB)) {
3716 expr = newUNOP(OP_DEFINED, 0,
3717 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
3718 } else if (expr->op_flags & OPf_KIDS) {
3719 OP *k1 = ((UNOP*)expr)->op_first;
3720 OP *k2 = (k1) ? k1->op_sibling : NULL;
3721 switch (expr->op_type) {
3723 if (k2 && k2->op_type == OP_READLINE
3724 && (k2->op_flags & OPf_STACKED)
3725 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3726 expr = newUNOP(OP_DEFINED, 0, expr);
3730 if (k1->op_type == OP_READDIR
3731 || k1->op_type == OP_GLOB
3732 || (k1->op_type == OP_NULL && k1->op_targ == OP_NULL)
3733 || k1->op_type == OP_EACH)
3734 expr = newUNOP(OP_DEFINED, 0, expr);
3740 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
3741 o = new_logop(OP_AND, 0, &expr, &listop);
3744 ((LISTOP*)listop)->op_last->op_next = LINKLIST(o);
3746 if (once && o != listop)
3747 o->op_next = ((LOGOP*)cUNOPo->op_first)->op_other;
3750 o = newUNOP(OP_NULL, 0, o); /* or do {} while 1 loses outer block */
3752 o->op_flags |= flags;
3754 o->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/
3759 Perl_newWHILEOP(pTHX_ I32 flags, I32 debuggable, LOOP *loop, I32 whileline, OP *expr, OP *block, OP *cont)
3769 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
3770 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB))) {
3771 expr = newUNOP(OP_DEFINED, 0,
3772 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
3773 } else if (expr && (expr->op_flags & OPf_KIDS)) {
3774 OP *k1 = ((UNOP*)expr)->op_first;
3775 OP *k2 = (k1) ? k1->op_sibling : NULL;
3776 switch (expr->op_type) {
3778 if (k2 && k2->op_type == OP_READLINE
3779 && (k2->op_flags & OPf_STACKED)
3780 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3781 expr = newUNOP(OP_DEFINED, 0, expr);
3785 if (k1->op_type == OP_READDIR
3786 || k1->op_type == OP_GLOB
3787 || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
3788 || k1->op_type == OP_EACH)
3789 expr = newUNOP(OP_DEFINED, 0, expr);
3795 block = newOP(OP_NULL, 0);
3797 block = scope(block);
3801 next = LINKLIST(cont);
3802 loopflags |= OPpLOOP_CONTINUE;
3805 cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
3806 if ((line_t)whileline != NOLINE) {
3807 PL_copline = whileline;
3808 cont = append_elem(OP_LINESEQ, cont,
3809 newSTATEOP(0, Nullch, Nullop));
3813 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
3814 redo = LINKLIST(listop);
3817 PL_copline = whileline;
3819 o = new_logop(OP_AND, 0, &expr, &listop);
3820 if (o == expr && o->op_type == OP_CONST && !SvTRUE(cSVOPo->op_sv)) {
3821 op_free(expr); /* oops, it's a while (0) */
3823 return Nullop; /* listop already freed by new_logop */
3826 ((LISTOP*)listop)->op_last->op_next = condop =
3827 (o == listop ? redo : LINKLIST(o));
3835 NewOp(1101,loop,1,LOOP);
3836 loop->op_type = OP_ENTERLOOP;
3837 loop->op_ppaddr = PL_ppaddr[OP_ENTERLOOP];
3838 loop->op_private = 0;
3839 loop->op_next = (OP*)loop;
3842 o = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, o);
3844 loop->op_redoop = redo;
3845 loop->op_lastop = o;
3846 o->op_private |= loopflags;
3849 loop->op_nextop = next;
3851 loop->op_nextop = o;
3853 o->op_flags |= flags;
3854 o->op_private |= (flags >> 8);
3859 Perl_newFOROP(pTHX_ I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
3868 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
3869 sv->op_type = OP_RV2GV;
3870 sv->op_ppaddr = PL_ppaddr[OP_RV2GV];
3872 else if (sv->op_type == OP_PADSV) { /* private variable */
3873 padoff = sv->op_targ;
3878 else if (sv->op_type == OP_THREADSV) { /* per-thread variable */
3879 padoff = sv->op_targ;
3881 iterflags |= OPf_SPECIAL;
3886 Perl_croak(aTHX_ "Can't use %s for loop variable", PL_op_desc[sv->op_type]);
3890 padoff = find_threadsv("_");
3891 iterflags |= OPf_SPECIAL;
3893 sv = newGVOP(OP_GV, 0, PL_defgv);
3896 if (expr->op_type == OP_RV2AV || expr->op_type == OP_PADAV) {
3897 expr = mod(force_list(scalar(ref(expr, OP_ITER))), OP_GREPSTART);
3898 iterflags |= OPf_STACKED;
3900 else if (expr->op_type == OP_NULL &&
3901 (expr->op_flags & OPf_KIDS) &&
3902 ((BINOP*)expr)->op_first->op_type == OP_FLOP)
3904 /* Basically turn for($x..$y) into the same as for($x,$y), but we
3905 * set the STACKED flag to indicate that these values are to be
3906 * treated as min/max values by 'pp_iterinit'.
3908 UNOP* flip = (UNOP*)((UNOP*)((BINOP*)expr)->op_first)->op_first;
3909 LOGOP* range = (LOGOP*) flip->op_first;
3910 OP* left = range->op_first;
3911 OP* right = left->op_sibling;
3914 range->op_flags &= ~OPf_KIDS;
3915 range->op_first = Nullop;
3917 listop = (LISTOP*)newLISTOP(OP_LIST, 0, left, right);
3918 listop->op_first->op_next = range->op_next;
3919 left->op_next = range->op_other;
3920 right->op_next = (OP*)listop;
3921 listop->op_next = listop->op_first;
3924 expr = (OP*)(listop);
3926 iterflags |= OPf_STACKED;
3929 expr = mod(force_list(expr), OP_GREPSTART);
3933 loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
3934 append_elem(OP_LIST, expr, scalar(sv))));
3935 assert(!loop->op_next);
3936 #ifdef PL_OP_SLAB_ALLOC
3937 NewOp(1234,tmp,1,LOOP);
3938 Copy(loop,tmp,1,LOOP);
3941 Renew(loop, 1, LOOP);
3943 loop->op_targ = padoff;
3944 wop = newWHILEOP(flags, 1, loop, forline, newOP(OP_ITER, 0), block, cont);
3945 PL_copline = forline;
3946 return newSTATEOP(0, label, wop);
3950 Perl_newLOOPEX(pTHX_ I32 type, OP *label)
3956 if (type != OP_GOTO || label->op_type == OP_CONST) {
3957 /* "last()" means "last" */
3958 if (label->op_type == OP_STUB && (label->op_flags & OPf_PARENS))
3959 o = newOP(type, OPf_SPECIAL);
3961 o = newPVOP(type, 0, savepv(label->op_type == OP_CONST
3962 ? SvPVx(((SVOP*)label)->op_sv, n_a)
3968 if (label->op_type == OP_ENTERSUB)
3969 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
3970 o = newUNOP(type, OPf_STACKED, label);
3972 PL_hints |= HINT_BLOCK_SCOPE;
3977 Perl_cv_undef(pTHX_ CV *cv)
3982 MUTEX_DESTROY(CvMUTEXP(cv));
3983 Safefree(CvMUTEXP(cv));
3986 #endif /* USE_THREADS */
3988 if (!CvXSUB(cv) && CvROOT(cv)) {
3990 if (CvDEPTH(cv) || (CvOWNER(cv) && CvOWNER(cv) != thr))
3991 Perl_croak(aTHX_ "Can't undef active subroutine");
3994 Perl_croak(aTHX_ "Can't undef active subroutine");
3995 #endif /* USE_THREADS */
3998 SAVEVPTR(PL_curpad);
4002 op_free(CvROOT(cv));
4003 CvROOT(cv) = Nullop;
4006 SvPOK_off((SV*)cv); /* forget prototype */
4008 SvREFCNT_dec(CvGV(cv));
4010 SvREFCNT_dec(CvOUTSIDE(cv));
4011 CvOUTSIDE(cv) = Nullcv;
4012 if (CvPADLIST(cv)) {
4013 /* may be during global destruction */
4014 if (SvREFCNT(CvPADLIST(cv))) {
4015 I32 i = AvFILLp(CvPADLIST(cv));
4017 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
4018 SV* sv = svp ? *svp : Nullsv;
4021 if (sv == (SV*)PL_comppad_name)
4022 PL_comppad_name = Nullav;
4023 else if (sv == (SV*)PL_comppad) {
4024 PL_comppad = Nullav;
4025 PL_curpad = Null(SV**);
4029 SvREFCNT_dec((SV*)CvPADLIST(cv));
4031 CvPADLIST(cv) = Nullav;
4036 S_cv_dump(pTHX_ CV *cv)
4039 CV *outside = CvOUTSIDE(cv);
4040 AV* padlist = CvPADLIST(cv);
4047 PerlIO_printf(Perl_debug_log,
4048 "\tCV=0x%"UVxf" (%s), OUTSIDE=0x%"UVxf" (%s)\n",
4050 (CvANON(cv) ? "ANON"
4051 : (cv == PL_main_cv) ? "MAIN"
4052 : CvUNIQUE(cv) ? "UNIQUE"
4053 : CvGV(cv) ? GvNAME(CvGV(cv)) : "UNDEFINED"),
4056 : CvANON(outside) ? "ANON"
4057 : (outside == PL_main_cv) ? "MAIN"
4058 : CvUNIQUE(outside) ? "UNIQUE"
4059 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
4064 pad_name = (AV*)*av_fetch(padlist, 0, FALSE);
4065 pad = (AV*)*av_fetch(padlist, 1, FALSE);
4066 pname = AvARRAY(pad_name);
4067 ppad = AvARRAY(pad);
4069 for (ix = 1; ix <= AvFILLp(pad_name); ix++) {
4070 if (SvPOK(pname[ix]))
4071 PerlIO_printf(Perl_debug_log,
4072 "\t%4d. 0x%"UVxf" (%s\"%s\" %"IVdf"-%"IVdf")\n",
4073 (int)ix, PTR2UV(ppad[ix]),
4074 SvFAKE(pname[ix]) ? "FAKE " : "",
4076 (IV)I_32(SvNVX(pname[ix])),
4079 #endif /* DEBUGGING */
4083 S_cv_clone2(pTHX_ CV *proto, CV *outside)
4088 AV* protopadlist = CvPADLIST(proto);
4089 AV* protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
4090 AV* protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
4091 SV** pname = AvARRAY(protopad_name);
4092 SV** ppad = AvARRAY(protopad);
4093 I32 fname = AvFILLp(protopad_name);
4094 I32 fpad = AvFILLp(protopad);
4098 assert(!CvUNIQUE(proto));
4102 SAVESPTR(PL_comppad_name);
4103 SAVESPTR(PL_compcv);
4105 cv = PL_compcv = (CV*)NEWSV(1104,0);
4106 sv_upgrade((SV *)cv, SvTYPE(proto));
4112 New(666, CvMUTEXP(cv), 1, perl_mutex);
4113 MUTEX_INIT(CvMUTEXP(cv));
4115 #endif /* USE_THREADS */
4116 CvFILE(cv) = CvFILE(proto);
4117 CvGV(cv) = (GV*)SvREFCNT_inc(CvGV(proto));
4118 CvSTASH(cv) = CvSTASH(proto);
4119 CvROOT(cv) = CvROOT(proto);
4120 CvSTART(cv) = CvSTART(proto);
4122 CvOUTSIDE(cv) = (CV*)SvREFCNT_inc(outside);
4125 sv_setpvn((SV*)cv, SvPVX(proto), SvCUR(proto));
4127 PL_comppad_name = newAV();
4128 for (ix = fname; ix >= 0; ix--)
4129 av_store(PL_comppad_name, ix, SvREFCNT_inc(pname[ix]));
4131 PL_comppad = newAV();
4133 comppadlist = newAV();
4134 AvREAL_off(comppadlist);
4135 av_store(comppadlist, 0, (SV*)PL_comppad_name);
4136 av_store(comppadlist, 1, (SV*)PL_comppad);
4137 CvPADLIST(cv) = comppadlist;
4138 av_fill(PL_comppad, AvFILLp(protopad));
4139 PL_curpad = AvARRAY(PL_comppad);
4141 av = newAV(); /* will be @_ */
4143 av_store(PL_comppad, 0, (SV*)av);
4144 AvFLAGS(av) = AVf_REIFY;
4146 for (ix = fpad; ix > 0; ix--) {
4147 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
4148 if (namesv && namesv != &PL_sv_undef) {
4149 char *name = SvPVX(namesv); /* XXX */
4150 if (SvFLAGS(namesv) & SVf_FAKE) { /* lexical from outside? */
4151 I32 off = pad_findlex(name, ix, SvIVX(namesv),
4152 CvOUTSIDE(cv), cxstack_ix, 0, 0);
4154 PL_curpad[ix] = SvREFCNT_inc(ppad[ix]);
4156 Perl_croak(aTHX_ "panic: cv_clone: %s", name);
4158 else { /* our own lexical */
4161 /* anon code -- we'll come back for it */
4162 sv = SvREFCNT_inc(ppad[ix]);
4164 else if (*name == '@')
4166 else if (*name == '%')
4175 else if (IS_PADGV(ppad[ix]) || IS_PADCONST(ppad[ix])) {
4176 PL_curpad[ix] = SvREFCNT_inc(ppad[ix]);
4179 SV* sv = NEWSV(0,0);
4185 /* Now that vars are all in place, clone nested closures. */
4187 for (ix = fpad; ix > 0; ix--) {
4188 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
4190 && namesv != &PL_sv_undef
4191 && !(SvFLAGS(namesv) & SVf_FAKE)
4192 && *SvPVX(namesv) == '&'
4193 && CvCLONE(ppad[ix]))
4195 CV *kid = cv_clone2((CV*)ppad[ix], cv);
4196 SvREFCNT_dec(ppad[ix]);
4199 PL_curpad[ix] = (SV*)kid;
4203 #ifdef DEBUG_CLOSURES
4204 PerlIO_printf(Perl_debug_log, "Cloned inside:\n");
4206 PerlIO_printf(Perl_debug_log, " from:\n");
4208 PerlIO_printf(Perl_debug_log, " to:\n");
4217 Perl_cv_clone(pTHX_ CV *proto)
4220 LOCK_CRED_MUTEX; /* XXX create separate mutex */
4221 cv = cv_clone2(proto, CvOUTSIDE(proto));
4222 UNLOCK_CRED_MUTEX; /* XXX create separate mutex */
4227 Perl_cv_ckproto(pTHX_ CV *cv, GV *gv, char *p)
4231 if (((!p != !SvPOK(cv)) || (p && strNE(p, SvPVX(cv)))) && ckWARN_d(WARN_PROTOTYPE)) {
4232 SV* msg = sv_newmortal();
4236 gv_efullname3(name = sv_newmortal(), gv, Nullch);
4237 sv_setpv(msg, "Prototype mismatch:");
4239 Perl_sv_catpvf(aTHX_ msg, " sub %"SVf, name);
4241 Perl_sv_catpvf(aTHX_ msg, " (%s)", SvPVX(cv));
4242 sv_catpv(msg, " vs ");
4244 Perl_sv_catpvf(aTHX_ msg, "(%s)", p);
4246 sv_catpv(msg, "none");
4247 Perl_warner(aTHX_ WARN_PROTOTYPE, "%"SVf, msg);
4252 Perl_cv_const_sv(pTHX_ CV *cv)
4254 if (!cv || !SvPOK(cv) || SvCUR(cv))
4256 return op_const_sv(CvSTART(cv), cv);
4260 Perl_op_const_sv(pTHX_ OP *o, CV *cv)
4267 if (o->op_type == OP_LINESEQ && cLISTOPo->op_first)
4268 o = cLISTOPo->op_first->op_sibling;
4270 for (; o; o = o->op_next) {
4271 OPCODE type = o->op_type;
4273 if (sv && o->op_next == o)
4275 if (type == OP_NEXTSTATE || type == OP_NULL || type == OP_PUSHMARK)
4277 if (type == OP_LEAVESUB || type == OP_RETURN)
4281 if (type == OP_CONST && cSVOPo->op_sv)
4283 else if ((type == OP_PADSV || type == OP_CONST) && cv) {
4284 AV* padav = (AV*)(AvARRAY(CvPADLIST(cv))[1]);
4285 sv = padav ? AvARRAY(padav)[o->op_targ] : Nullsv;
4286 if (!sv || (!SvREADONLY(sv) && SvREFCNT(sv) > 1))
4298 Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
4308 Perl_croak(aTHX_ "\"my sub\" not yet implemented");
4312 Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block)
4314 return Perl_newATTRSUB(aTHX_ floor, o, proto, Nullop, block);
4318 Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
4325 char *ps = proto ? SvPVx(((SVOP*)proto)->op_sv, n_a) : Nullch;
4329 name = o ? SvPVx(cSVOPo->op_sv, n_a) : Nullch;
4330 if (!name && PERLDB_NAMEANON && CopLINE(PL_curcop)) {
4331 SV *sv = sv_newmortal();
4332 Perl_sv_setpvf(aTHX_ sv, "__ANON__[%s:%"IVdf"]",
4333 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
4338 gv = gv_fetchpv(name ? name : (aname ? aname : "__ANON__"),
4339 GV_ADDMULTI | ((block || attrs) ? 0 : GV_NOINIT),
4349 if (SvTYPE(gv) != SVt_PVGV) { /* Maybe prototype now, and had at
4350 maximum a prototype before. */
4351 if (SvTYPE(gv) > SVt_NULL) {
4352 if (!SvPOK((SV*)gv) && !(SvIOK((SV*)gv) && SvIVX((SV*)gv) == -1)
4353 && ckWARN_d(WARN_PROTOTYPE))
4355 Perl_warner(aTHX_ WARN_PROTOTYPE, "Runaway prototype");
4357 cv_ckproto((CV*)gv, NULL, ps);
4360 sv_setpv((SV*)gv, ps);
4362 sv_setiv((SV*)gv, -1);
4363 SvREFCNT_dec(PL_compcv);
4364 cv = PL_compcv = NULL;
4365 PL_sub_generation++;
4369 if (!name || GvCVGEN(gv))
4371 else if (cv = GvCV(gv)) {
4372 cv_ckproto(cv, gv, ps);
4373 /* already defined (or promised)? */
4374 if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
4376 bool const_changed = TRUE;
4377 if (!block && !attrs) {
4378 /* just a "sub foo;" when &foo is already defined */
4379 SAVEFREESV(PL_compcv);
4382 /* ahem, death to those who redefine active sort subs */
4383 if (PL_curstackinfo->si_type == PERLSI_SORT && PL_sortcop == CvSTART(cv))
4384 Perl_croak(aTHX_ "Can't redefine active sort subroutine %s", name);
4387 if (const_sv = cv_const_sv(cv))
4388 const_changed = sv_cmp(const_sv, op_const_sv(block, Nullcv));
4389 if ((const_sv || const_changed) && ckWARN(WARN_REDEFINE))
4391 line_t oldline = CopLINE(PL_curcop);
4392 CopLINE_set(PL_curcop, PL_copline);
4393 Perl_warner(aTHX_ WARN_REDEFINE,
4394 const_sv ? "Constant subroutine %s redefined"
4395 : "Subroutine %s redefined", name);
4396 CopLINE_set(PL_curcop, oldline);
4407 /* Need to do a C<use attributes $stash_of_cv,\&cv,@attrs>
4408 * before we clobber PL_compcv.
4412 if (CvGV(cv) && GvSTASH(CvGV(cv)) && HvNAME(GvSTASH(CvGV(cv))))
4413 stash = GvSTASH(CvGV(cv));
4414 else if (CvSTASH(cv) && HvNAME(CvSTASH(cv)))
4415 stash = CvSTASH(cv);
4417 stash = PL_curstash;
4420 /* possibly about to re-define existing subr -- ignore old cv */
4421 rcv = (SV*)PL_compcv;
4422 if (name && GvSTASH(gv) && HvNAME(GvSTASH(gv)))
4423 stash = GvSTASH(gv);
4425 stash = PL_curstash;
4427 apply_attrs(stash, rcv, attrs);
4429 if (cv) { /* must reuse cv if autoloaded */
4431 /* got here with just attrs -- work done, so bug out */
4432 SAVEFREESV(PL_compcv);
4436 CvFLAGS(cv) = CvFLAGS(PL_compcv);
4437 CvOUTSIDE(cv) = CvOUTSIDE(PL_compcv);
4438 CvOUTSIDE(PL_compcv) = 0;
4439 CvPADLIST(cv) = CvPADLIST(PL_compcv);
4440 CvPADLIST(PL_compcv) = 0;
4441 if (SvREFCNT(PL_compcv) > 1) /* XXX Make closures transit through stub. */
4442 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc((SV*)cv);
4443 SvREFCNT_dec(PL_compcv);
4450 PL_sub_generation++;
4453 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4454 CvFILE(cv) = CopFILE(PL_curcop);
4455 CvSTASH(cv) = PL_curstash;
4458 if (!CvMUTEXP(cv)) {
4459 New(666, CvMUTEXP(cv), 1, perl_mutex);
4460 MUTEX_INIT(CvMUTEXP(cv));
4462 #endif /* USE_THREADS */
4465 sv_setpv((SV*)cv, ps);
4467 if (PL_error_count) {
4471 char *s = strrchr(name, ':');
4473 if (strEQ(s, "BEGIN")) {
4475 "BEGIN not safe after errors--compilation aborted";
4476 if (PL_in_eval & EVAL_KEEPERR)
4477 Perl_croak(aTHX_ not_safe);
4479 /* force display of errors found but not reported */
4480 sv_catpv(ERRSV, not_safe);
4481 Perl_croak(aTHX_ "%s", SvPVx(ERRSV, n_a));
4488 PL_copline = NOLINE;
4493 if (AvFILLp(PL_comppad_name) < AvFILLp(PL_comppad))
4494 av_store(PL_comppad_name, AvFILLp(PL_comppad), Nullsv);
4497 CvROOT(cv) = newUNOP(OP_LEAVESUBLV, 0, scalarseq(block));
4500 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
4502 CvROOT(cv)->op_private |= OPpREFCOUNTED;
4503 OpREFCNT_set(CvROOT(cv), 1);
4504 CvSTART(cv) = LINKLIST(CvROOT(cv));
4505 CvROOT(cv)->op_next = 0;
4508 /* now that optimizer has done its work, adjust pad values */
4510 SV **namep = AvARRAY(PL_comppad_name);
4511 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4514 if (SvIMMORTAL(PL_curpad[ix]) || IS_PADGV(PL_curpad[ix]) || IS_PADCONST(PL_curpad[ix]))
4517 * The only things that a clonable function needs in its
4518 * pad are references to outer lexicals and anonymous subs.
4519 * The rest are created anew during cloning.
4521 if (!((namesv = namep[ix]) != Nullsv &&
4522 namesv != &PL_sv_undef &&
4524 *SvPVX(namesv) == '&')))
4526 SvREFCNT_dec(PL_curpad[ix]);
4527 PL_curpad[ix] = Nullsv;
4532 AV *av = newAV(); /* Will be @_ */
4534 av_store(PL_comppad, 0, (SV*)av);
4535 AvFLAGS(av) = AVf_REIFY;
4537 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4538 if (SvIMMORTAL(PL_curpad[ix]) || IS_PADGV(PL_curpad[ix]) || IS_PADCONST(PL_curpad[ix]))
4540 if (!SvPADMY(PL_curpad[ix]))
4541 SvPADTMP_on(PL_curpad[ix]);
4545 if (name || aname) {
4547 char *tname = (name ? name : aname);
4549 if (PERLDB_SUBLINE && PL_curstash != PL_debstash) {
4550 SV *sv = NEWSV(0,0);
4551 SV *tmpstr = sv_newmortal();
4552 GV *db_postponed = gv_fetchpv("DB::postponed", GV_ADDMULTI, SVt_PVHV);
4557 Perl_sv_setpvf(aTHX_ sv, "%s:%ld-%ld",
4559 (long)PL_subline, (long)CopLINE(PL_curcop));
4560 gv_efullname3(tmpstr, gv, Nullch);
4561 hv_store(GvHV(PL_DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
4562 hv = GvHVn(db_postponed);
4563 if (HvFILL(hv) > 0 && hv_exists(hv, SvPVX(tmpstr), SvCUR(tmpstr))
4564 && (pcv = GvCV(db_postponed)))
4570 call_sv((SV*)pcv, G_DISCARD);
4574 if ((s = strrchr(tname,':')))
4579 if (*s != 'B' && *s != 'E' && *s != 'C' && *s != 'I')
4582 if (strEQ(s, "BEGIN")) {
4583 I32 oldscope = PL_scopestack_ix;
4585 SAVECOPFILE(&PL_compiling);
4586 SAVECOPLINE(&PL_compiling);
4588 sv_setsv(PL_rs, PL_nrs);
4591 PL_beginav = newAV();
4592 DEBUG_x( dump_sub(gv) );
4593 av_push(PL_beginav, SvREFCNT_inc(cv));
4595 call_list(oldscope, PL_beginav);
4597 PL_curcop = &PL_compiling;
4598 PL_compiling.op_private = PL_hints;
4601 else if (strEQ(s, "END") && !PL_error_count) {
4604 DEBUG_x( dump_sub(gv) );
4605 av_unshift(PL_endav, 1);
4606 av_store(PL_endav, 0, SvREFCNT_inc(cv));
4609 else if (strEQ(s, "CHECK") && !PL_error_count) {
4611 PL_checkav = newAV();
4612 DEBUG_x( dump_sub(gv) );
4613 av_unshift(PL_checkav, 1);
4614 av_store(PL_checkav, 0, SvREFCNT_inc(cv));
4617 else if (strEQ(s, "INIT") && !PL_error_count) {
4619 PL_initav = newAV();
4620 DEBUG_x( dump_sub(gv) );
4621 av_push(PL_initav, SvREFCNT_inc(cv));
4627 PL_copline = NOLINE;
4632 /* XXX unsafe for threads if eval_owner isn't held */
4634 =for apidoc newCONSTSUB
4636 Creates a constant sub equivalent to Perl C<sub FOO () { 123 }> which is
4637 eligible for inlining at compile-time.
4643 Perl_newCONSTSUB(pTHX_ HV *stash, char *name, SV *sv)
4648 SAVECOPLINE(PL_curcop);
4651 CopLINE_set(PL_curcop, PL_copline);
4652 PL_hints &= ~HINT_BLOCK_SCOPE;
4655 SAVESPTR(PL_curstash);
4656 SAVECOPSTASH(PL_curcop);
4657 PL_curstash = stash;
4659 CopSTASHPV(PL_curcop) = stash ? HvNAME(stash) : Nullch;
4661 CopSTASH(PL_curcop) = stash;
4666 start_subparse(FALSE, 0),
4667 newSVOP(OP_CONST, 0, newSVpv(name,0)),
4668 newSVOP(OP_CONST, 0, &PL_sv_no), /* SvPV(&PL_sv_no) == "" -- GMB */
4670 newSTATEOP(0, Nullch, newSVOP(OP_CONST, 0, sv))
4677 =for apidoc U||newXS
4679 Used by C<xsubpp> to hook up XSUBs as Perl subs.
4685 Perl_newXS(pTHX_ char *name, XSUBADDR_t subaddr, char *filename)
4688 GV *gv = gv_fetchpv(name ? name : "__ANON__", GV_ADDMULTI, SVt_PVCV);
4691 if (cv = (name ? GvCV(gv) : Nullcv)) {
4693 /* just a cached method */
4697 else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
4698 /* already defined (or promised) */
4699 if (ckWARN(WARN_REDEFINE) && !(CvGV(cv) && GvSTASH(CvGV(cv))
4700 && HvNAME(GvSTASH(CvGV(cv)))
4701 && strEQ(HvNAME(GvSTASH(CvGV(cv))), "autouse"))) {
4702 line_t oldline = CopLINE(PL_curcop);
4703 if (PL_copline != NOLINE)
4704 CopLINE_set(PL_curcop, PL_copline);
4705 Perl_warner(aTHX_ WARN_REDEFINE, "Subroutine %s redefined",name);
4706 CopLINE_set(PL_curcop, oldline);
4713 if (cv) /* must reuse cv if autoloaded */
4716 cv = (CV*)NEWSV(1105,0);
4717 sv_upgrade((SV *)cv, SVt_PVCV);
4721 PL_sub_generation++;
4724 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4726 New(666, CvMUTEXP(cv), 1, perl_mutex);
4727 MUTEX_INIT(CvMUTEXP(cv));
4729 #endif /* USE_THREADS */
4730 (void)gv_fetchfile(filename);
4731 CvFILE(cv) = filename; /* NOTE: not copied, as it is expected to be
4732 an external constant string */
4733 CvXSUB(cv) = subaddr;
4736 char *s = strrchr(name,':');
4742 if (*s != 'B' && *s != 'E' && *s != 'C' && *s != 'I')
4745 if (strEQ(s, "BEGIN")) {
4747 PL_beginav = newAV();
4748 av_push(PL_beginav, SvREFCNT_inc(cv));
4751 else if (strEQ(s, "END")) {
4754 av_unshift(PL_endav, 1);
4755 av_store(PL_endav, 0, SvREFCNT_inc(cv));
4758 else if (strEQ(s, "CHECK")) {
4760 PL_checkav = newAV();
4761 av_unshift(PL_checkav, 1);
4762 av_store(PL_checkav, 0, SvREFCNT_inc(cv));
4765 else if (strEQ(s, "INIT")) {
4767 PL_initav = newAV();
4768 av_push(PL_initav, SvREFCNT_inc(cv));
4780 Perl_newFORM(pTHX_ I32 floor, OP *o, OP *block)
4790 name = SvPVx(cSVOPo->op_sv, n_a);
4793 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
4795 if (cv = GvFORM(gv)) {
4796 if (ckWARN(WARN_REDEFINE)) {
4797 line_t oldline = CopLINE(PL_curcop);
4799 CopLINE_set(PL_curcop, PL_copline);
4800 Perl_warner(aTHX_ WARN_REDEFINE, "Format %s redefined",name);
4801 CopLINE_set(PL_curcop, oldline);
4807 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4808 CvFILE(cv) = CopFILE(PL_curcop);
4810 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4811 if (!SvPADMY(PL_curpad[ix]) && !SvIMMORTAL(PL_curpad[ix]))
4812 SvPADTMP_on(PL_curpad[ix]);
4815 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
4816 CvROOT(cv)->op_private |= OPpREFCOUNTED;
4817 OpREFCNT_set(CvROOT(cv), 1);
4818 CvSTART(cv) = LINKLIST(CvROOT(cv));
4819 CvROOT(cv)->op_next = 0;
4822 PL_copline = NOLINE;
4827 Perl_newANONLIST(pTHX_ OP *o)
4829 return newUNOP(OP_REFGEN, 0,
4830 mod(list(convert(OP_ANONLIST, 0, o)), OP_REFGEN));
4834 Perl_newANONHASH(pTHX_ OP *o)
4836 return newUNOP(OP_REFGEN, 0,
4837 mod(list(convert(OP_ANONHASH, 0, o)), OP_REFGEN));
4841 Perl_newANONSUB(pTHX_ I32 floor, OP *proto, OP *block)
4843 return newANONATTRSUB(floor, proto, Nullop, block);
4847 Perl_newANONATTRSUB(pTHX_ I32 floor, OP *proto, OP *attrs, OP *block)
4849 return newUNOP(OP_REFGEN, 0,
4850 newSVOP(OP_ANONCODE, 0,
4851 (SV*)newATTRSUB(floor, 0, proto, attrs, block)));
4855 Perl_oopsAV(pTHX_ OP *o)
4857 switch (o->op_type) {
4859 o->op_type = OP_PADAV;
4860 o->op_ppaddr = PL_ppaddr[OP_PADAV];
4861 return ref(o, OP_RV2AV);
4864 o->op_type = OP_RV2AV;
4865 o->op_ppaddr = PL_ppaddr[OP_RV2AV];
4870 if (ckWARN_d(WARN_INTERNAL))
4871 Perl_warner(aTHX_ WARN_INTERNAL, "oops: oopsAV");
4878 Perl_oopsHV(pTHX_ OP *o)
4882 switch (o->op_type) {
4885 o->op_type = OP_PADHV;
4886 o->op_ppaddr = PL_ppaddr[OP_PADHV];
4887 return ref(o, OP_RV2HV);
4891 o->op_type = OP_RV2HV;
4892 o->op_ppaddr = PL_ppaddr[OP_RV2HV];
4897 if (ckWARN_d(WARN_INTERNAL))
4898 Perl_warner(aTHX_ WARN_INTERNAL, "oops: oopsHV");
4905 Perl_newAVREF(pTHX_ OP *o)
4907 if (o->op_type == OP_PADANY) {
4908 o->op_type = OP_PADAV;
4909 o->op_ppaddr = PL_ppaddr[OP_PADAV];
4912 return newUNOP(OP_RV2AV, 0, scalar(o));
4916 Perl_newGVREF(pTHX_ I32 type, OP *o)
4918 if (type == OP_MAPSTART || type == OP_GREPSTART || type == OP_SORT)
4919 return newUNOP(OP_NULL, 0, o);
4920 return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
4924 Perl_newHVREF(pTHX_ OP *o)
4926 if (o->op_type == OP_PADANY) {
4927 o->op_type = OP_PADHV;
4928 o->op_ppaddr = PL_ppaddr[OP_PADHV];
4931 return newUNOP(OP_RV2HV, 0, scalar(o));
4935 Perl_oopsCV(pTHX_ OP *o)
4937 Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
4943 Perl_newCVREF(pTHX_ I32 flags, OP *o)
4945 return newUNOP(OP_RV2CV, flags, scalar(o));
4949 Perl_newSVREF(pTHX_ OP *o)
4951 if (o->op_type == OP_PADANY) {
4952 o->op_type = OP_PADSV;
4953 o->op_ppaddr = PL_ppaddr[OP_PADSV];
4956 else if (o->op_type == OP_THREADSV && !(o->op_flags & OPpDONE_SVREF)) {
4957 o->op_flags |= OPpDONE_SVREF;
4960 return newUNOP(OP_RV2SV, 0, scalar(o));
4963 /* Check routines. */
4966 Perl_ck_anoncode(pTHX_ OP *o)
4971 name = NEWSV(1106,0);
4972 sv_upgrade(name, SVt_PVNV);
4973 sv_setpvn(name, "&", 1);
4976 ix = pad_alloc(o->op_type, SVs_PADMY);
4977 av_store(PL_comppad_name, ix, name);
4978 av_store(PL_comppad, ix, cSVOPo->op_sv);
4979 SvPADMY_on(cSVOPo->op_sv);
4980 cSVOPo->op_sv = Nullsv;
4981 cSVOPo->op_targ = ix;
4986 Perl_ck_bitop(pTHX_ OP *o)
4988 o->op_private = PL_hints;
4993 Perl_ck_concat(pTHX_ OP *o)
4995 if (cUNOPo->op_first->op_type == OP_CONCAT)
4996 o->op_flags |= OPf_STACKED;
5001 Perl_ck_spair(pTHX_ OP *o)
5003 if (o->op_flags & OPf_KIDS) {
5006 OPCODE type = o->op_type;
5007 o = modkids(ck_fun(o), type);
5008 kid = cUNOPo->op_first;
5009 newop = kUNOP->op_first->op_sibling;
5011 (newop->op_sibling ||
5012 !(PL_opargs[newop->op_type] & OA_RETSCALAR) ||
5013 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
5014 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
5018 op_free(kUNOP->op_first);
5019 kUNOP->op_first = newop;
5021 o->op_ppaddr = PL_ppaddr[++o->op_type];
5026 Perl_ck_delete(pTHX_ OP *o)
5030 if (o->op_flags & OPf_KIDS) {
5031 OP *kid = cUNOPo->op_first;
5032 switch (kid->op_type) {
5034 o->op_flags |= OPf_SPECIAL;
5037 o->op_private |= OPpSLICE;
5040 o->op_flags |= OPf_SPECIAL;
5045 Perl_croak(aTHX_ "%s argument is not a HASH or ARRAY element or slice",
5046 PL_op_desc[o->op_type]);
5054 Perl_ck_eof(pTHX_ OP *o)
5056 I32 type = o->op_type;
5058 if (o->op_flags & OPf_KIDS) {
5059 if (cLISTOPo->op_first->op_type == OP_STUB) {
5061 o = newUNOP(type, OPf_SPECIAL,
5062 newGVOP(OP_GV, 0, gv_fetchpv("main::ARGV", TRUE, SVt_PVAV)));
5070 Perl_ck_eval(pTHX_ OP *o)
5072 PL_hints |= HINT_BLOCK_SCOPE;
5073 if (o->op_flags & OPf_KIDS) {
5074 SVOP *kid = (SVOP*)cUNOPo->op_first;
5077 o->op_flags &= ~OPf_KIDS;
5080 else if (kid->op_type == OP_LINESEQ) {
5083 kid->op_next = o->op_next;
5084 cUNOPo->op_first = 0;
5087 NewOp(1101, enter, 1, LOGOP);
5088 enter->op_type = OP_ENTERTRY;
5089 enter->op_ppaddr = PL_ppaddr[OP_ENTERTRY];
5090 enter->op_private = 0;
5092 /* establish postfix order */
5093 enter->op_next = (OP*)enter;
5095 o = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
5096 o->op_type = OP_LEAVETRY;
5097 o->op_ppaddr = PL_ppaddr[OP_LEAVETRY];
5098 enter->op_other = o;
5106 o = newUNOP(OP_ENTEREVAL, 0, newDEFSVOP());
5108 o->op_targ = (PADOFFSET)PL_hints;
5113 Perl_ck_exec(pTHX_ OP *o)
5116 if (o->op_flags & OPf_STACKED) {
5118 kid = cUNOPo->op_first->op_sibling;
5119 if (kid->op_type == OP_RV2GV)
5128 Perl_ck_exists(pTHX_ OP *o)
5131 if (o->op_flags & OPf_KIDS) {
5132 OP *kid = cUNOPo->op_first;
5133 if (kid->op_type == OP_ENTERSUB) {
5134 (void) ref(kid, o->op_type);
5135 if (kid->op_type != OP_RV2CV && !PL_error_count)
5136 Perl_croak(aTHX_ "%s argument is not a subroutine name",
5137 PL_op_desc[o->op_type]);
5138 o->op_private |= OPpEXISTS_SUB;
5140 else if (kid->op_type == OP_AELEM)
5141 o->op_flags |= OPf_SPECIAL;
5142 else if (kid->op_type != OP_HELEM)
5143 Perl_croak(aTHX_ "%s argument is not a HASH or ARRAY element",
5144 PL_op_desc[o->op_type]);
5152 Perl_ck_gvconst(pTHX_ register OP *o)
5154 o = fold_constants(o);
5155 if (o->op_type == OP_CONST)
5162 Perl_ck_rvconst(pTHX_ register OP *o)
5165 SVOP *kid = (SVOP*)cUNOPo->op_first;
5167 o->op_private |= (PL_hints & HINT_STRICT_REFS);
5168 if (kid->op_type == OP_CONST) {
5172 SV *kidsv = kid->op_sv;
5175 /* Is it a constant from cv_const_sv()? */
5176 if (SvROK(kidsv) && SvREADONLY(kidsv)) {
5177 SV *rsv = SvRV(kidsv);
5178 int svtype = SvTYPE(rsv);
5179 char *badtype = Nullch;
5181 switch (o->op_type) {
5183 if (svtype > SVt_PVMG)
5184 badtype = "a SCALAR";
5187 if (svtype != SVt_PVAV)
5188 badtype = "an ARRAY";
5191 if (svtype != SVt_PVHV) {
5192 if (svtype == SVt_PVAV) { /* pseudohash? */
5193 SV **ksv = av_fetch((AV*)rsv, 0, FALSE);
5194 if (ksv && SvROK(*ksv)
5195 && SvTYPE(SvRV(*ksv)) == SVt_PVHV)
5204 if (svtype != SVt_PVCV)
5209 Perl_croak(aTHX_ "Constant is not %s reference", badtype);
5212 name = SvPV(kidsv, n_a);
5213 if ((PL_hints & HINT_STRICT_REFS) && (kid->op_private & OPpCONST_BARE)) {
5214 char *badthing = Nullch;
5215 switch (o->op_type) {
5217 badthing = "a SCALAR";
5220 badthing = "an ARRAY";
5223 badthing = "a HASH";
5228 "Can't use bareword (\"%s\") as %s ref while \"strict refs\" in use",
5232 * This is a little tricky. We only want to add the symbol if we
5233 * didn't add it in the lexer. Otherwise we get duplicate strict
5234 * warnings. But if we didn't add it in the lexer, we must at
5235 * least pretend like we wanted to add it even if it existed before,
5236 * or we get possible typo warnings. OPpCONST_ENTERED says
5237 * whether the lexer already added THIS instance of this symbol.
5239 iscv = (o->op_type == OP_RV2CV) * 2;
5241 gv = gv_fetchpv(name,
5242 iscv | !(kid->op_private & OPpCONST_ENTERED),
5245 : o->op_type == OP_RV2SV
5247 : o->op_type == OP_RV2AV
5249 : o->op_type == OP_RV2HV
5252 } while (!gv && !(kid->op_private & OPpCONST_ENTERED) && !iscv++);
5254 kid->op_type = OP_GV;
5255 SvREFCNT_dec(kid->op_sv);
5257 /* XXX hack: dependence on sizeof(PADOP) <= sizeof(SVOP) */
5258 kPADOP->op_padix = pad_alloc(OP_GV, SVs_PADTMP);
5260 PL_curpad[kPADOP->op_padix] = SvREFCNT_inc(gv);
5262 kid->op_sv = SvREFCNT_inc(gv);
5264 kid->op_ppaddr = PL_ppaddr[OP_GV];
5271 Perl_ck_ftst(pTHX_ OP *o)
5274 I32 type = o->op_type;
5276 if (o->op_flags & OPf_REF) {
5279 else if (o->op_flags & OPf_KIDS && cUNOPo->op_first->op_type != OP_STUB) {
5280 SVOP *kid = (SVOP*)cUNOPo->op_first;
5282 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
5284 OP *newop = newGVOP(type, OPf_REF,
5285 gv_fetchpv(SvPVx(kid->op_sv, n_a), TRUE, SVt_PVIO));
5292 if (type == OP_FTTTY)
5293 o = newGVOP(type, OPf_REF, gv_fetchpv("main::STDIN", TRUE,
5296 o = newUNOP(type, 0, newDEFSVOP());
5299 if (type == OP_FTTEXT || type == OP_FTBINARY) {
5301 if (PL_hints & HINT_LOCALE)
5302 o->op_private |= OPpLOCALE;
5309 Perl_ck_fun(pTHX_ OP *o)
5316 int type = o->op_type;
5317 register I32 oa = PL_opargs[type] >> OASHIFT;
5319 if (o->op_flags & OPf_STACKED) {
5320 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
5323 return no_fh_allowed(o);
5326 if (o->op_flags & OPf_KIDS) {
5328 tokid = &cLISTOPo->op_first;
5329 kid = cLISTOPo->op_first;
5330 if (kid->op_type == OP_PUSHMARK ||
5331 kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK)
5333 tokid = &kid->op_sibling;
5334 kid = kid->op_sibling;
5336 if (!kid && PL_opargs[type] & OA_DEFGV)
5337 *tokid = kid = newDEFSVOP();
5341 sibl = kid->op_sibling;
5344 /* list seen where single (scalar) arg expected? */
5345 if (numargs == 1 && !(oa >> 4)
5346 && kid->op_type == OP_LIST && type != OP_SCALAR)
5348 return too_many_arguments(o,PL_op_desc[type]);
5361 if (kid->op_type == OP_CONST &&
5362 (kid->op_private & OPpCONST_BARE))
5364 char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
5365 OP *newop = newAVREF(newGVOP(OP_GV, 0,
5366 gv_fetchpv(name, TRUE, SVt_PVAV) ));
5367 if (ckWARN(WARN_DEPRECATED))
5368 Perl_warner(aTHX_ WARN_DEPRECATED,
5369 "Array @%s missing the @ in argument %"IVdf" of %s()",
5370 name, (IV)numargs, PL_op_desc[type]);
5373 kid->op_sibling = sibl;
5376 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
5377 bad_type(numargs, "array", PL_op_desc[type], kid);
5381 if (kid->op_type == OP_CONST &&
5382 (kid->op_private & OPpCONST_BARE))
5384 char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
5385 OP *newop = newHVREF(newGVOP(OP_GV, 0,
5386 gv_fetchpv(name, TRUE, SVt_PVHV) ));
5387 if (ckWARN(WARN_DEPRECATED))
5388 Perl_warner(aTHX_ WARN_DEPRECATED,
5389 "Hash %%%s missing the %% in argument %"IVdf" of %s()",
5390 name, (IV)numargs, PL_op_desc[type]);
5393 kid->op_sibling = sibl;
5396 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
5397 bad_type(numargs, "hash", PL_op_desc[type], kid);
5402 OP *newop = newUNOP(OP_NULL, 0, kid);
5403 kid->op_sibling = 0;
5405 newop->op_next = newop;
5407 kid->op_sibling = sibl;
5412 if (kid->op_type != OP_GV && kid->op_type != OP_RV2GV) {
5413 if (kid->op_type == OP_CONST &&
5414 (kid->op_private & OPpCONST_BARE))
5416 OP *newop = newGVOP(OP_GV, 0,
5417 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, n_a), TRUE,
5422 else if (kid->op_type == OP_READLINE) {
5423 /* neophyte patrol: open(<FH>), close(<FH>) etc. */
5424 bad_type(numargs, "HANDLE", PL_op_desc[o->op_type], kid);
5427 I32 flags = OPf_SPECIAL;
5431 /* is this op a FH constructor? */
5432 if (is_handle_constructor(o,numargs)) {
5433 char *name = Nullch;
5437 /* Set a flag to tell rv2gv to vivify
5438 * need to "prove" flag does not mean something
5439 * else already - NI-S 1999/05/07
5442 if (kid->op_type == OP_PADSV) {
5443 SV **namep = av_fetch(PL_comppad_name,
5445 if (namep && *namep)
5446 name = SvPV(*namep, len);
5448 else if (kid->op_type == OP_RV2SV
5449 && kUNOP->op_first->op_type == OP_GV)
5451 GV *gv = cGVOPx_gv(kUNOP->op_first);
5453 len = GvNAMELEN(gv);
5457 targ = pad_alloc(OP_RV2GV, SVs_PADTMP);
5458 namesv = PL_curpad[targ];
5459 SvUPGRADE(namesv, SVt_PV);
5461 sv_setpvn(namesv, "$", 1);
5462 sv_catpvn(namesv, name, len);
5465 kid->op_sibling = 0;
5466 kid = newUNOP(OP_RV2GV, flags, scalar(kid));
5467 kid->op_targ = targ;
5468 kid->op_private |= priv;
5470 kid->op_sibling = sibl;
5476 mod(scalar(kid), type);
5480 tokid = &kid->op_sibling;
5481 kid = kid->op_sibling;
5483 o->op_private |= numargs;
5485 return too_many_arguments(o,PL_op_desc[o->op_type]);
5488 else if (PL_opargs[type] & OA_DEFGV) {
5490 return newUNOP(type, 0, newDEFSVOP());
5494 while (oa & OA_OPTIONAL)
5496 if (oa && oa != OA_LIST)
5497 return too_few_arguments(o,PL_op_desc[o->op_type]);
5503 Perl_ck_glob(pTHX_ OP *o)
5508 if ((o->op_flags & OPf_KIDS) && !cLISTOPo->op_first->op_sibling)
5509 append_elem(OP_GLOB, o, newDEFSVOP());
5511 if (!((gv = gv_fetchpv("glob", FALSE, SVt_PVCV)) && GvIMPORTED_CV(gv)))
5512 gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
5514 #if !defined(PERL_EXTERNAL_GLOB)
5515 /* XXX this can be tightened up and made more failsafe. */
5517 OP *modname = newSVOP(OP_CONST, 0, newSVpvn("File::Glob", 10));
5518 modname->op_private |= OPpCONST_BARE;
5520 utilize(1, start_subparse(FALSE, 0), Nullop, modname,
5521 newSVOP(OP_CONST, 0, newSVpvn(":globally", 9)));
5522 gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
5525 #endif /* PERL_EXTERNAL_GLOB */
5527 if (gv && GvIMPORTED_CV(gv)) {
5528 append_elem(OP_GLOB, o,
5529 newSVOP(OP_CONST, 0, newSViv(PL_glob_index++)));
5530 o->op_type = OP_LIST;
5531 o->op_ppaddr = PL_ppaddr[OP_LIST];
5532 cLISTOPo->op_first->op_type = OP_PUSHMARK;
5533 cLISTOPo->op_first->op_ppaddr = PL_ppaddr[OP_PUSHMARK];
5534 o = newUNOP(OP_ENTERSUB, OPf_STACKED,
5535 append_elem(OP_LIST, o,
5536 scalar(newUNOP(OP_RV2CV, 0,
5537 newGVOP(OP_GV, 0, gv)))));
5538 o = newUNOP(OP_NULL, 0, ck_subr(o));
5539 o->op_targ = OP_GLOB; /* hint at what it used to be */
5542 gv = newGVgen("main");
5544 append_elem(OP_GLOB, o, newGVOP(OP_GV, 0, gv));
5550 Perl_ck_grep(pTHX_ OP *o)
5554 OPCODE type = o->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
5556 o->op_ppaddr = PL_ppaddr[OP_GREPSTART];
5557 NewOp(1101, gwop, 1, LOGOP);
5559 if (o->op_flags & OPf_STACKED) {
5562 kid = cLISTOPo->op_first->op_sibling;
5563 for (k = cLISTOPo->op_first->op_sibling->op_next; k; k = k->op_next) {
5566 kid->op_next = (OP*)gwop;
5567 o->op_flags &= ~OPf_STACKED;
5569 kid = cLISTOPo->op_first->op_sibling;
5570 if (type == OP_MAPWHILE)
5577 kid = cLISTOPo->op_first->op_sibling;
5578 if (kid->op_type != OP_NULL)
5579 Perl_croak(aTHX_ "panic: ck_grep");
5580 kid = kUNOP->op_first;
5582 gwop->op_type = type;
5583 gwop->op_ppaddr = PL_ppaddr[type];
5584 gwop->op_first = listkids(o);
5585 gwop->op_flags |= OPf_KIDS;
5586 gwop->op_private = 1;
5587 gwop->op_other = LINKLIST(kid);
5588 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
5589 kid->op_next = (OP*)gwop;
5591 kid = cLISTOPo->op_first->op_sibling;
5592 if (!kid || !kid->op_sibling)
5593 return too_few_arguments(o,PL_op_desc[o->op_type]);
5594 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
5595 mod(kid, OP_GREPSTART);
5601 Perl_ck_index(pTHX_ OP *o)
5603 if (o->op_flags & OPf_KIDS) {
5604 OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5606 kid = kid->op_sibling; /* get past "big" */
5607 if (kid && kid->op_type == OP_CONST)
5608 fbm_compile(((SVOP*)kid)->op_sv, 0);
5614 Perl_ck_lengthconst(pTHX_ OP *o)
5616 /* XXX length optimization goes here */
5621 Perl_ck_lfun(pTHX_ OP *o)
5623 OPCODE type = o->op_type;
5624 return modkids(ck_fun(o), type);
5628 Perl_ck_defined(pTHX_ OP *o) /* 19990527 MJD */
5631 if ((o->op_flags & OPf_KIDS) && ckWARN(WARN_DEPRECATED)) {
5632 switch (cUNOPo->op_first->op_type) {
5634 break; /* Globals via GV can be undef */
5636 case OP_AASSIGN: /* Is this a good idea? */
5637 Perl_warner(aTHX_ WARN_DEPRECATED,
5638 "defined(@array) is deprecated");
5639 Perl_warner(aTHX_ WARN_DEPRECATED,
5640 "(Maybe you should just omit the defined()?)\n");
5643 break; /* Globals via GV can be undef */
5645 Perl_warner(aTHX_ WARN_DEPRECATED,
5646 "defined(%%hash) is deprecated");
5647 Perl_warner(aTHX_ WARN_DEPRECATED,
5648 "(Maybe you should just omit the defined()?)\n");
5659 Perl_ck_rfun(pTHX_ OP *o)
5661 OPCODE type = o->op_type;
5662 return refkids(ck_fun(o), type);
5666 Perl_ck_listiob(pTHX_ OP *o)
5670 kid = cLISTOPo->op_first;
5673 kid = cLISTOPo->op_first;
5675 if (kid->op_type == OP_PUSHMARK)
5676 kid = kid->op_sibling;
5677 if (kid && o->op_flags & OPf_STACKED)
5678 kid = kid->op_sibling;
5679 else if (kid && !kid->op_sibling) { /* print HANDLE; */
5680 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
5681 o->op_flags |= OPf_STACKED; /* make it a filehandle */
5682 kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
5683 cLISTOPo->op_first->op_sibling = kid;
5684 cLISTOPo->op_last = kid;
5685 kid = kid->op_sibling;
5690 append_elem(o->op_type, o, newDEFSVOP());
5696 if (PL_hints & HINT_LOCALE)
5697 o->op_private |= OPpLOCALE;
5704 Perl_ck_fun_locale(pTHX_ OP *o)
5710 if (PL_hints & HINT_LOCALE)
5711 o->op_private |= OPpLOCALE;
5718 Perl_ck_sassign(pTHX_ OP *o)
5720 OP *kid = cLISTOPo->op_first;
5721 /* has a disposable target? */
5722 if ((PL_opargs[kid->op_type] & OA_TARGLEX)
5723 && !(kid->op_flags & OPf_STACKED)
5724 /* Cannot steal the second time! */
5725 && !(kid->op_private & OPpTARGET_MY))
5727 OP *kkid = kid->op_sibling;
5729 /* Can just relocate the target. */
5730 if (kkid && kkid->op_type == OP_PADSV
5731 && !(kkid->op_private & OPpLVAL_INTRO))
5733 kid->op_targ = kkid->op_targ;
5735 /* Now we do not need PADSV and SASSIGN. */
5736 kid->op_sibling = o->op_sibling; /* NULL */
5737 cLISTOPo->op_first = NULL;
5740 kid->op_private |= OPpTARGET_MY; /* Used for context settings */
5748 Perl_ck_scmp(pTHX_ OP *o)
5752 if (PL_hints & HINT_LOCALE)
5753 o->op_private |= OPpLOCALE;
5760 Perl_ck_match(pTHX_ OP *o)
5762 o->op_private |= OPpRUNTIME;
5767 Perl_ck_method(pTHX_ OP *o)
5769 OP *kid = cUNOPo->op_first;
5770 if (kid->op_type == OP_CONST) {
5771 SV* sv = kSVOP->op_sv;
5772 if (!(strchr(SvPVX(sv), ':') || strchr(SvPVX(sv), '\''))) {
5774 sv_upgrade(sv, SVt_PVIV);
5776 PERL_HASH(SvUVX(sv), SvPVX(sv), SvCUR(sv));
5777 cmop = newSVOP(OP_METHOD_NAMED, 0, sv);
5778 kSVOP->op_sv = Nullsv;
5787 Perl_ck_null(pTHX_ OP *o)
5793 Perl_ck_repeat(pTHX_ OP *o)
5795 if (cBINOPo->op_first->op_flags & OPf_PARENS) {
5796 o->op_private |= OPpREPEAT_DOLIST;
5797 cBINOPo->op_first = force_list(cBINOPo->op_first);
5805 Perl_ck_require(pTHX_ OP *o)
5807 if (o->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
5808 SVOP *kid = (SVOP*)cUNOPo->op_first;
5810 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
5812 for (s = SvPVX(kid->op_sv); *s; s++) {
5813 if (*s == ':' && s[1] == ':') {
5815 Move(s+2, s+1, strlen(s+2)+1, char);
5816 --SvCUR(kid->op_sv);
5819 sv_catpvn(kid->op_sv, ".pm", 3);
5827 Perl_ck_retarget(pTHX_ OP *o)
5829 Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
5836 Perl_ck_select(pTHX_ OP *o)
5839 if (o->op_flags & OPf_KIDS) {
5840 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5841 if (kid && kid->op_sibling) {
5842 o->op_type = OP_SSELECT;
5843 o->op_ppaddr = PL_ppaddr[OP_SSELECT];
5845 return fold_constants(o);
5849 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5850 if (kid && kid->op_type == OP_RV2GV)
5851 kid->op_private &= ~HINT_STRICT_REFS;
5856 Perl_ck_shift(pTHX_ OP *o)
5858 I32 type = o->op_type;
5860 if (!(o->op_flags & OPf_KIDS)) {
5865 if (!CvUNIQUE(PL_compcv)) {
5866 argop = newOP(OP_PADAV, OPf_REF);
5867 argop->op_targ = 0; /* PL_curpad[0] is @_ */
5870 argop = newUNOP(OP_RV2AV, 0,
5871 scalar(newGVOP(OP_GV, 0,
5872 gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
5875 argop = newUNOP(OP_RV2AV, 0,
5876 scalar(newGVOP(OP_GV, 0, !CvUNIQUE(PL_compcv) ?
5877 PL_defgv : gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
5878 #endif /* USE_THREADS */
5879 return newUNOP(type, 0, scalar(argop));
5881 return scalar(modkids(ck_fun(o), type));
5885 Perl_ck_sort(pTHX_ OP *o)
5889 if (PL_hints & HINT_LOCALE)
5890 o->op_private |= OPpLOCALE;
5893 if (o->op_type == OP_SORT && o->op_flags & OPf_STACKED)
5895 if (o->op_flags & OPf_STACKED) { /* may have been cleared */
5896 OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5898 kid = kUNOP->op_first; /* get past null */
5900 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
5902 if (kid->op_type == OP_SCOPE) {
5906 else if (kid->op_type == OP_LEAVE) {
5907 if (o->op_type == OP_SORT) {
5908 null(kid); /* wipe out leave */
5911 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
5912 if (k->op_next == kid)
5917 kid->op_next = 0; /* just disconnect the leave */
5918 k = kLISTOP->op_first;
5922 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5923 if (o->op_type == OP_SORT)
5927 o->op_flags |= OPf_SPECIAL;
5929 else if (kid->op_type == OP_RV2SV || kid->op_type == OP_PADSV)
5930 null(cLISTOPo->op_first->op_sibling);
5937 S_simplify_sort(pTHX_ OP *o)
5940 register OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5944 if (!(o->op_flags & OPf_STACKED))
5946 GvMULTI_on(gv_fetchpv("a", TRUE, SVt_PV));
5947 GvMULTI_on(gv_fetchpv("b", TRUE, SVt_PV));
5948 kid = kUNOP->op_first; /* get past null */
5949 if (kid->op_type != OP_SCOPE)
5951 kid = kLISTOP->op_last; /* get past scope */
5952 switch(kid->op_type) {
5960 k = kid; /* remember this node*/
5961 if (kBINOP->op_first->op_type != OP_RV2SV)
5963 kid = kBINOP->op_first; /* get past cmp */
5964 if (kUNOP->op_first->op_type != OP_GV)
5966 kid = kUNOP->op_first; /* get past rv2sv */
5968 if (GvSTASH(gv) != PL_curstash)
5970 if (strEQ(GvNAME(gv), "a"))
5972 else if (strEQ(GvNAME(gv), "b"))
5976 kid = k; /* back to cmp */
5977 if (kBINOP->op_last->op_type != OP_RV2SV)
5979 kid = kBINOP->op_last; /* down to 2nd arg */
5980 if (kUNOP->op_first->op_type != OP_GV)
5982 kid = kUNOP->op_first; /* get past rv2sv */
5984 if (GvSTASH(gv) != PL_curstash
5986 ? strNE(GvNAME(gv), "a")
5987 : strNE(GvNAME(gv), "b")))
5989 o->op_flags &= ~(OPf_STACKED | OPf_SPECIAL);
5991 o->op_private |= OPpSORT_REVERSE;
5992 if (k->op_type == OP_NCMP)
5993 o->op_private |= OPpSORT_NUMERIC;
5994 if (k->op_type == OP_I_NCMP)
5995 o->op_private |= OPpSORT_NUMERIC | OPpSORT_INTEGER;
5996 kid = cLISTOPo->op_first->op_sibling;
5997 cLISTOPo->op_first->op_sibling = kid->op_sibling; /* bypass old block */
5998 op_free(kid); /* then delete it */
5999 cLISTOPo->op_children--;
6003 Perl_ck_split(pTHX_ OP *o)
6007 if (o->op_flags & OPf_STACKED)
6008 return no_fh_allowed(o);
6010 kid = cLISTOPo->op_first;
6011 if (kid->op_type != OP_NULL)
6012 Perl_croak(aTHX_ "panic: ck_split");
6013 kid = kid->op_sibling;
6014 op_free(cLISTOPo->op_first);
6015 cLISTOPo->op_first = kid;
6017 cLISTOPo->op_first = kid = newSVOP(OP_CONST, 0, newSVpvn(" ", 1));
6018 cLISTOPo->op_last = kid; /* There was only one element previously */
6021 if (kid->op_type != OP_MATCH) {
6022 OP *sibl = kid->op_sibling;
6023 kid->op_sibling = 0;
6024 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
6025 if (cLISTOPo->op_first == cLISTOPo->op_last)
6026 cLISTOPo->op_last = kid;
6027 cLISTOPo->op_first = kid;
6028 kid->op_sibling = sibl;
6031 kid->op_type = OP_PUSHRE;
6032 kid->op_ppaddr = PL_ppaddr[OP_PUSHRE];
6035 if (!kid->op_sibling)
6036 append_elem(OP_SPLIT, o, newDEFSVOP());
6038 kid = kid->op_sibling;
6041 if (!kid->op_sibling)
6042 append_elem(OP_SPLIT, o, newSVOP(OP_CONST, 0, newSViv(0)));
6044 kid = kid->op_sibling;
6047 if (kid->op_sibling)
6048 return too_many_arguments(o,PL_op_desc[o->op_type]);
6054 Perl_ck_join(pTHX_ OP *o)
6056 if (ckWARN(WARN_SYNTAX)) {
6057 OP *kid = cLISTOPo->op_first->op_sibling;
6058 if (kid && kid->op_type == OP_MATCH) {
6059 char *pmstr = "STRING";
6060 if (kPMOP->op_pmregexp)
6061 pmstr = kPMOP->op_pmregexp->precomp;
6062 Perl_warner(aTHX_ WARN_SYNTAX,
6063 "/%s/ should probably be written as \"%s\"",
6071 Perl_ck_subr(pTHX_ OP *o)
6074 OP *prev = ((cUNOPo->op_first->op_sibling)
6075 ? cUNOPo : ((UNOP*)cUNOPo->op_first))->op_first;
6076 OP *o2 = prev->op_sibling;
6085 o->op_private |= OPpENTERSUB_HASTARG;
6086 for (cvop = o2; cvop->op_sibling; cvop = cvop->op_sibling) ;
6087 if (cvop->op_type == OP_RV2CV) {
6089 o->op_private |= (cvop->op_private & OPpENTERSUB_AMPER);
6090 null(cvop); /* disable rv2cv */
6091 tmpop = (SVOP*)((UNOP*)cvop)->op_first;
6092 if (tmpop->op_type == OP_GV && !(o->op_private & OPpENTERSUB_AMPER)) {
6093 GV *gv = cGVOPx_gv(tmpop);
6096 tmpop->op_private |= OPpEARLY_CV;
6097 else if (SvPOK(cv)) {
6098 namegv = CvANON(cv) ? gv : CvGV(cv);
6099 proto = SvPV((SV*)cv, n_a);
6103 else if (cvop->op_type == OP_METHOD || cvop->op_type == OP_METHOD_NAMED) {
6104 if (o2->op_type == OP_CONST)
6105 o2->op_private &= ~OPpCONST_STRICT;
6106 else if (o2->op_type == OP_LIST) {
6107 OP *o = ((UNOP*)o2)->op_first->op_sibling;
6108 if (o && o->op_type == OP_CONST)
6109 o->op_private &= ~OPpCONST_STRICT;
6112 o->op_private |= (PL_hints & HINT_STRICT_REFS);
6113 if (PERLDB_SUB && PL_curstash != PL_debstash)
6114 o->op_private |= OPpENTERSUB_DB;
6115 while (o2 != cvop) {
6119 return too_many_arguments(o, gv_ename(namegv));
6137 if (o2->op_type != OP_REFGEN && o2->op_type != OP_UNDEF)
6138 bad_type(arg, "block", gv_ename(namegv), o2);
6141 /* '*' allows any scalar type, including bareword */
6144 if (o2->op_type == OP_RV2GV)
6145 goto wrapref; /* autoconvert GLOB -> GLOBref */
6146 else if (o2->op_type == OP_CONST)
6147 o2->op_private &= ~OPpCONST_STRICT;
6148 else if (o2->op_type == OP_ENTERSUB) {
6149 /* accidental subroutine, revert to bareword */
6150 OP *gvop = ((UNOP*)o2)->op_first;
6151 if (gvop && gvop->op_type == OP_NULL) {
6152 gvop = ((UNOP*)gvop)->op_first;
6154 for (; gvop->op_sibling; gvop = gvop->op_sibling)
6157 (gvop->op_private & OPpENTERSUB_NOPAREN) &&
6158 (gvop = ((UNOP*)gvop)->op_first) &&
6159 gvop->op_type == OP_GV)
6161 GV *gv = cGVOPx_gv(gvop);
6162 OP *sibling = o2->op_sibling;
6163 SV *n = newSVpvn("",0);
6165 gv_fullname3(n, gv, "");
6166 if (SvCUR(n)>6 && strnEQ(SvPVX(n),"main::",6))
6167 sv_chop(n, SvPVX(n)+6);
6168 o2 = newSVOP(OP_CONST, 0, n);
6169 prev->op_sibling = o2;
6170 o2->op_sibling = sibling;
6182 if (o2->op_type != OP_RV2GV)
6183 bad_type(arg, "symbol", gv_ename(namegv), o2);
6186 if (o2->op_type != OP_RV2CV)
6187 bad_type(arg, "sub", gv_ename(namegv), o2);
6190 if (o2->op_type != OP_RV2SV
6191 && o2->op_type != OP_PADSV
6192 && o2->op_type != OP_HELEM
6193 && o2->op_type != OP_AELEM
6194 && o2->op_type != OP_THREADSV)
6196 bad_type(arg, "scalar", gv_ename(namegv), o2);
6200 if (o2->op_type != OP_RV2AV && o2->op_type != OP_PADAV)
6201 bad_type(arg, "array", gv_ename(namegv), o2);
6204 if (o2->op_type != OP_RV2HV && o2->op_type != OP_PADHV)
6205 bad_type(arg, "hash", gv_ename(namegv), o2);
6209 OP* sib = kid->op_sibling;
6210 kid->op_sibling = 0;
6211 o2 = newUNOP(OP_REFGEN, 0, kid);
6212 o2->op_sibling = sib;
6213 prev->op_sibling = o2;
6224 Perl_croak(aTHX_ "Malformed prototype for %s: %s",
6225 gv_ename(namegv), SvPV((SV*)cv, n_a));
6230 mod(o2, OP_ENTERSUB);
6232 o2 = o2->op_sibling;
6234 if (proto && !optional &&
6235 (*proto && *proto != '@' && *proto != '%' && *proto != ';'))
6236 return too_few_arguments(o, gv_ename(namegv));
6241 Perl_ck_svconst(pTHX_ OP *o)
6243 SvREADONLY_on(cSVOPo->op_sv);
6248 Perl_ck_trunc(pTHX_ OP *o)
6250 if (o->op_flags & OPf_KIDS) {
6251 SVOP *kid = (SVOP*)cUNOPo->op_first;
6253 if (kid->op_type == OP_NULL)
6254 kid = (SVOP*)kid->op_sibling;
6255 if (kid && kid->op_type == OP_CONST &&
6256 (kid->op_private & OPpCONST_BARE))
6258 o->op_flags |= OPf_SPECIAL;
6259 kid->op_private &= ~OPpCONST_STRICT;
6265 /* A peephole optimizer. We visit the ops in the order they're to execute. */
6268 Perl_peep(pTHX_ register OP *o)
6271 register OP* oldop = 0;
6273 OP *last_composite = Nullop;
6275 if (!o || o->op_seq)
6279 SAVEVPTR(PL_curcop);
6280 for (; o; o = o->op_next) {
6286 switch (o->op_type) {
6290 PL_curcop = ((COP*)o); /* for warnings */
6291 o->op_seq = PL_op_seqmax++;
6292 last_composite = Nullop;
6296 if (cSVOPo->op_private & OPpCONST_STRICT)
6297 no_bareword_allowed(o);
6299 /* Relocate sv to the pad for thread safety.
6300 * Despite being a "constant", the SV is written to,
6301 * for reference counts, sv_upgrade() etc. */
6303 PADOFFSET ix = pad_alloc(OP_CONST, SVs_PADTMP);
6304 SvREFCNT_dec(PL_curpad[ix]);
6305 SvPADTMP_on(cSVOPo->op_sv);
6306 PL_curpad[ix] = cSVOPo->op_sv;
6307 cSVOPo->op_sv = Nullsv;
6319 if (o->op_next && o->op_next->op_type == OP_STRINGIFY) {
6320 if (o->op_next->op_private & OPpTARGET_MY) {
6321 if (o->op_flags & OPf_STACKED) /* chained concats */
6322 goto ignore_optimization;
6324 o->op_targ = o->op_next->op_targ;
6325 o->op_next->op_targ = 0;
6326 o->op_private |= OPpTARGET_MY;
6331 ignore_optimization:
6332 o->op_seq = PL_op_seqmax++;
6335 if ((o->op_flags & OPf_WANT) != OPf_WANT_LIST) {
6336 o->op_seq = PL_op_seqmax++;
6337 break; /* Scalar stub must produce undef. List stub is noop */
6341 if (o->op_targ == OP_NEXTSTATE
6342 || o->op_targ == OP_DBSTATE
6343 || o->op_targ == OP_SETSTATE)
6345 PL_curcop = ((COP*)o);
6352 if (oldop && o->op_next) {
6353 oldop->op_next = o->op_next;
6356 o->op_seq = PL_op_seqmax++;
6360 if (o->op_next->op_type == OP_RV2SV) {
6361 if (!(o->op_next->op_private & OPpDEREF)) {
6363 o->op_private |= o->op_next->op_private & (OPpLVAL_INTRO
6365 o->op_next = o->op_next->op_next;
6366 o->op_type = OP_GVSV;
6367 o->op_ppaddr = PL_ppaddr[OP_GVSV];
6370 else if (o->op_next->op_type == OP_RV2AV) {
6371 OP* pop = o->op_next->op_next;
6373 if (pop->op_type == OP_CONST &&
6374 (PL_op = pop->op_next) &&
6375 pop->op_next->op_type == OP_AELEM &&
6376 !(pop->op_next->op_private &
6377 (OPpLVAL_INTRO|OPpLVAL_DEFER|OPpDEREF)) &&
6378 (i = SvIV(((SVOP*)pop)->op_sv) - PL_compiling.cop_arybase)
6386 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
6387 o->op_next = pop->op_next->op_next;
6388 o->op_type = OP_AELEMFAST;
6389 o->op_ppaddr = PL_ppaddr[OP_AELEMFAST];
6390 o->op_private = (U8)i;
6395 else if ((o->op_private & OPpEARLY_CV) && ckWARN(WARN_PROTOTYPE)) {
6397 if (SvTYPE(gv) == SVt_PVGV && GvCV(gv) && SvPVX(GvCV(gv))) {
6398 /* XXX could check prototype here instead of just carping */
6399 SV *sv = sv_newmortal();
6400 gv_efullname3(sv, gv, Nullch);
6401 Perl_warner(aTHX_ WARN_PROTOTYPE,
6402 "%s() called too early to check prototype",
6407 o->op_seq = PL_op_seqmax++;
6418 o->op_seq = PL_op_seqmax++;
6419 while (cLOGOP->op_other->op_type == OP_NULL)
6420 cLOGOP->op_other = cLOGOP->op_other->op_next;
6421 peep(cLOGOP->op_other);
6425 o->op_seq = PL_op_seqmax++;
6426 peep(cLOOP->op_redoop);
6427 peep(cLOOP->op_nextop);
6428 peep(cLOOP->op_lastop);
6434 o->op_seq = PL_op_seqmax++;
6435 peep(cPMOP->op_pmreplstart);
6439 o->op_seq = PL_op_seqmax++;
6440 if (ckWARN(WARN_SYNTAX) && o->op_next
6441 && o->op_next->op_type == OP_NEXTSTATE) {
6442 if (o->op_next->op_sibling &&
6443 o->op_next->op_sibling->op_type != OP_EXIT &&
6444 o->op_next->op_sibling->op_type != OP_WARN &&
6445 o->op_next->op_sibling->op_type != OP_DIE) {
6446 line_t oldline = CopLINE(PL_curcop);
6448 CopLINE_set(PL_curcop, CopLINE((COP*)o->op_next));
6449 Perl_warner(aTHX_ WARN_EXEC,
6450 "Statement unlikely to be reached");
6451 Perl_warner(aTHX_ WARN_EXEC,
6452 "(Maybe you meant system() when you said exec()?)\n");
6453 CopLINE_set(PL_curcop, oldline);
6462 SV **svp, **indsvp, *sv;
6467 o->op_seq = PL_op_seqmax++;
6468 if ((o->op_private & (OPpLVAL_INTRO))
6469 || ((BINOP*)o)->op_last->op_type != OP_CONST)
6471 rop = (UNOP*)((BINOP*)o)->op_first;
6472 if (rop->op_type != OP_RV2HV || rop->op_first->op_type != OP_PADSV)
6474 lexname = *av_fetch(PL_comppad_name, rop->op_first->op_targ, TRUE);
6475 if (!SvOBJECT(lexname))
6477 fields = (GV**)hv_fetch(SvSTASH(lexname), "FIELDS", 6, FALSE);
6478 if (!fields || !GvHV(*fields))
6480 svp = cSVOPx_svp(((BINOP*)o)->op_last);
6481 key = SvPV(*svp, keylen);
6482 indsvp = hv_fetch(GvHV(*fields), key, keylen, FALSE);
6484 Perl_croak(aTHX_ "No such pseudo-hash field \"%s\" in variable %s of type %s",
6485 key, SvPV(lexname, n_a), HvNAME(SvSTASH(lexname)));
6487 ind = SvIV(*indsvp);
6489 Perl_croak(aTHX_ "Bad index while coercing array into hash");
6490 rop->op_type = OP_RV2AV;
6491 rop->op_ppaddr = PL_ppaddr[OP_RV2AV];
6492 o->op_type = OP_AELEM;
6493 o->op_ppaddr = PL_ppaddr[OP_AELEM];
6495 if (SvREADONLY(*svp))
6497 SvFLAGS(sv) |= (SvFLAGS(*svp)
6498 & (SVs_PADBUSY|SVs_PADTMP|SVs_PADMY));
6508 SV **svp, **indsvp, *sv;
6512 SVOP *first_key_op, *key_op;
6514 o->op_seq = PL_op_seqmax++;
6515 if ((o->op_private & (OPpLVAL_INTRO))
6516 /* I bet there's always a pushmark... */
6517 || ((LISTOP*)o)->op_first->op_sibling->op_type != OP_LIST)
6518 /* hmmm, no optimization if list contains only one key. */
6520 rop = (UNOP*)((LISTOP*)o)->op_last;
6521 if (rop->op_type != OP_RV2HV || rop->op_first->op_type != OP_PADSV)
6523 lexname = *av_fetch(PL_comppad_name, rop->op_first->op_targ, TRUE);
6524 if (!SvOBJECT(lexname))
6526 fields = (GV**)hv_fetch(SvSTASH(lexname), "FIELDS", 6, FALSE);
6527 if (!fields || !GvHV(*fields))
6529 /* Again guessing that the pushmark can be jumped over.... */
6530 first_key_op = (SVOP*)((LISTOP*)((LISTOP*)o)->op_first->op_sibling)
6531 ->op_first->op_sibling;
6532 /* Check that the key list contains only constants. */
6533 for (key_op = first_key_op; key_op;
6534 key_op = (SVOP*)key_op->op_sibling)
6535 if (key_op->op_type != OP_CONST)
6539 rop->op_type = OP_RV2AV;
6540 rop->op_ppaddr = PL_ppaddr[OP_RV2AV];
6541 o->op_type = OP_ASLICE;
6542 o->op_ppaddr = PL_ppaddr[OP_ASLICE];
6543 for (key_op = first_key_op; key_op;
6544 key_op = (SVOP*)key_op->op_sibling) {
6545 svp = cSVOPx_svp(key_op);
6546 key = SvPV(*svp, keylen);
6547 indsvp = hv_fetch(GvHV(*fields), key, keylen, FALSE);
6549 Perl_croak(aTHX_ "No such pseudo-hash field \"%s\" "
6550 "in variable %s of type %s",
6551 key, SvPV(lexname, n_a), HvNAME(SvSTASH(lexname)));
6553 ind = SvIV(*indsvp);
6555 Perl_croak(aTHX_ "Bad index while coercing array into hash");
6557 if (SvREADONLY(*svp))
6559 SvFLAGS(sv) |= (SvFLAGS(*svp)
6560 & (SVs_PADBUSY|SVs_PADTMP|SVs_PADMY));
6569 if (!(o->op_flags & OPf_WANT)
6570 || (o->op_flags & OPf_WANT) == OPf_WANT_LIST)
6574 o->op_seq = PL_op_seqmax++;
6578 if (o->op_next && o->op_next->op_type != OP_LEAVESUBLV) {
6579 o->op_seq = PL_op_seqmax++;
6585 if (last_composite) {
6586 OP *r = last_composite;
6588 while (r->op_sibling)
6591 || (r->op_next->op_type == OP_LIST
6592 && r->op_next->op_next == o))
6594 if (last_composite->op_type == OP_RV2AV)
6595 yyerror("Lvalue subs returning arrays not implemented yet");
6597 yyerror("Lvalue subs returning hashes not implemented yet");
6604 o->op_seq = PL_op_seqmax++;