3 * Copyright (c) 1991-1999, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 * "You see: Mr. Drogo, he married poor Miss Primula Brandybuck. She was
12 * our Mr. Bilbo's first cousin on the mother's side (her mother being the
13 * youngest of the Old Took's daughters); and Mr. Drogo was his second
14 * cousin. So Mr. Frodo is his first *and* second cousin, once removed
15 * either way, as the saying is, if you follow me." --the Gaffer
23 /* #define PL_OP_SLAB_ALLOC */
26 #define OP_REFCNT_LOCK NOOP
27 #define OP_REFCNT_UNLOCK NOOP
28 #define OpREFCNT_set(o,n) NOOP
29 #define OpREFCNT_dec(o) ((o)->op_targ--)
31 #ifdef PL_OP_SLAB_ALLOC
32 #define SLAB_SIZE 8192
33 static char *PL_OpPtr = NULL;
34 static int PL_OpSpace = 0;
35 #define NewOp(m,var,c,type) do { if ((PL_OpSpace -= c*sizeof(type)) >= 0) \
36 var = (type *)(PL_OpPtr -= c*sizeof(type)); \
38 var = (type *) Slab_Alloc(m,c*sizeof(type)); \
42 S_Slab_Alloc(pTHX_ int m, size_t sz)
44 Newz(m,PL_OpPtr,SLAB_SIZE,char);
45 PL_OpSpace = SLAB_SIZE - sz;
46 return PL_OpPtr += PL_OpSpace;
50 #define NewOp(m, var, c, type) Newz(m, var, c, type)
53 * In the following definition, the ", Nullop" is just to make the compiler
54 * think the expression is of the right type: croak actually does a Siglongjmp.
56 #define CHECKOP(type,o) \
57 ((PL_op_mask && PL_op_mask[type]) \
58 ? ( op_free((OP*)o), \
59 Perl_croak(aTHX_ "%s trapped by operation mask", PL_op_desc[type]), \
61 : CALL_FPTR(PL_check[type])(aTHX_ (OP*)o))
63 #define PAD_MAX 999999999
66 S_gv_ename(pTHX_ GV *gv)
69 SV* tmpsv = sv_newmortal();
70 gv_efullname3(tmpsv, gv, Nullch);
71 return SvPV(tmpsv,n_a);
75 S_no_fh_allowed(pTHX_ OP *o)
77 yyerror(Perl_form(aTHX_ "Missing comma after first argument to %s function",
78 PL_op_desc[o->op_type]));
83 S_too_few_arguments(pTHX_ OP *o, char *name)
85 yyerror(Perl_form(aTHX_ "Not enough arguments for %s", name));
90 S_too_many_arguments(pTHX_ OP *o, char *name)
92 yyerror(Perl_form(aTHX_ "Too many arguments for %s", name));
97 S_bad_type(pTHX_ I32 n, char *t, char *name, OP *kid)
99 yyerror(Perl_form(aTHX_ "Type of arg %d to %s must be %s (not %s)",
100 (int)n, name, t, PL_op_desc[kid->op_type]));
104 S_no_bareword_allowed(pTHX_ OP *o)
106 qerror(Perl_mess(aTHX_
107 "Bareword \"%s\" not allowed while \"strict subs\" in use",
108 SvPV_nolen(cSVOPo->op_sv)));
111 /* "register" allocation */
114 Perl_pad_allocmy(pTHX_ char *name)
121 PL_in_my == KEY_our ||
123 (PL_hints & HINT_UTF8 && (name[1] & 0xc0) == 0xc0) ||
124 name[1] == '_' && (int)strlen(name) > 2 ))
126 if (!isPRINT(name[1]) || strchr("\t\n\r\f", name[1])) {
127 /* 1999-02-27 mjd@plover.com */
129 p = strchr(name, '\0');
130 /* The next block assumes the buffer is at least 205 chars
131 long. At present, it's always at least 256 chars. */
133 strcpy(name+200, "...");
139 /* Move everything else down one character */
140 for (; p-name > 2; p--)
142 name[2] = toCTRL(name[1]);
145 yyerror(Perl_form(aTHX_ "Can't use global %s in \"my\"",name));
147 if (ckWARN(WARN_UNSAFE) && AvFILLp(PL_comppad_name) >= 0) {
148 SV **svp = AvARRAY(PL_comppad_name);
149 for (off = AvFILLp(PL_comppad_name); off > PL_comppad_name_floor; off--) {
151 && sv != &PL_sv_undef
152 && (SvIVX(sv) == PAD_MAX || SvIVX(sv) == 0)
153 && strEQ(name, SvPVX(sv)))
155 Perl_warner(aTHX_ WARN_UNSAFE,
156 "\"%s\" variable %s masks earlier declaration in same %s",
157 (PL_in_my == KEY_our ? "our" : "my"),
159 (SvIVX(sv) == PAD_MAX ? "scope" : "statement"));
164 off = pad_alloc(OP_PADSV, SVs_PADMY);
166 sv_upgrade(sv, SVt_PVNV);
168 if (PL_in_my_stash) {
170 yyerror(Perl_form(aTHX_ "Can't declare class for non-scalar %s in \"my\"",
173 (void)SvUPGRADE(sv, SVt_PVMG);
174 SvSTASH(sv) = (HV*)SvREFCNT_inc(PL_in_my_stash);
177 if (PL_in_my == KEY_our)
178 SvFLAGS(sv) |= SVpad_OUR;
179 av_store(PL_comppad_name, off, sv);
180 SvNVX(sv) = (NV)PAD_MAX;
181 SvIVX(sv) = 0; /* Not yet introduced--see newSTATEOP */
182 if (!PL_min_intro_pending)
183 PL_min_intro_pending = off;
184 PL_max_intro_pending = off;
186 av_store(PL_comppad, off, (SV*)newAV());
187 else if (*name == '%')
188 av_store(PL_comppad, off, (SV*)newHV());
189 SvPADMY_on(PL_curpad[off]);
193 #define FINDLEX_NOSEARCH 1 /* don't search outer contexts */
196 S_pad_findlex(pTHX_ char *name, PADOFFSET newoff, U32 seq, CV* startcv,
197 I32 cx_ix, I32 saweval, U32 flags)
204 register PERL_CONTEXT *cx;
206 for (cv = startcv; cv; cv = CvOUTSIDE(cv)) {
207 AV *curlist = CvPADLIST(cv);
208 SV **svp = av_fetch(curlist, 0, FALSE);
211 if (!svp || *svp == &PL_sv_undef)
214 svp = AvARRAY(curname);
215 for (off = AvFILLp(curname); off > 0; off--) {
216 if ((sv = svp[off]) &&
217 sv != &PL_sv_undef &&
219 seq > I_32(SvNVX(sv)) &&
220 strEQ(SvPVX(sv), name))
231 return 0; /* don't clone from inactive stack frame */
235 oldpad = (AV*)*av_fetch(curlist, depth, FALSE);
236 oldsv = *av_fetch(oldpad, off, TRUE);
237 if (!newoff) { /* Not a mere clone operation. */
238 SV *namesv = NEWSV(1103,0);
239 newoff = pad_alloc(OP_PADSV, SVs_PADMY);
240 sv_upgrade(namesv, SVt_PVNV);
241 sv_setpv(namesv, name);
242 av_store(PL_comppad_name, newoff, namesv);
243 SvNVX(namesv) = (NV)PL_curcop->cop_seq;
244 SvIVX(namesv) = PAD_MAX; /* A ref, intro immediately */
245 SvFAKE_on(namesv); /* A ref, not a real var */
246 if (SvFLAGS(sv) & SVpad_OUR)/* An "our" variable */
247 SvFLAGS(namesv) |= SVpad_OUR;
248 if (SvOBJECT(sv)) { /* A typed var */
250 (void)SvUPGRADE(namesv, SVt_PVMG);
251 SvSTASH(namesv) = (HV*)SvREFCNT_inc((SV*)SvSTASH(sv));
254 if (CvANON(PL_compcv) || SvTYPE(PL_compcv) == SVt_PVFM) {
255 /* "It's closures all the way down." */
256 CvCLONE_on(PL_compcv);
258 if (CvANON(PL_compcv))
259 oldsv = Nullsv; /* no need to keep ref */
264 bcv && bcv != cv && !CvCLONE(bcv);
265 bcv = CvOUTSIDE(bcv))
270 if (ckWARN(WARN_CLOSURE)
271 && !CvUNIQUE(bcv) && !CvUNIQUE(cv))
273 Perl_warner(aTHX_ WARN_CLOSURE,
274 "Variable \"%s\" may be unavailable",
282 else if (!CvUNIQUE(PL_compcv)) {
283 if (ckWARN(WARN_CLOSURE) && !SvFAKE(sv) && !CvUNIQUE(cv))
284 Perl_warner(aTHX_ WARN_CLOSURE,
285 "Variable \"%s\" will not stay shared", name);
288 av_store(PL_comppad, newoff, SvREFCNT_inc(oldsv));
294 if (flags & FINDLEX_NOSEARCH)
297 /* Nothing in current lexical context--try eval's context, if any.
298 * This is necessary to let the perldb get at lexically scoped variables.
299 * XXX This will also probably interact badly with eval tree caching.
302 for (i = cx_ix; i >= 0; i--) {
304 switch (CxTYPE(cx)) {
306 if (i == 0 && saweval) {
307 seq = cxstack[saweval].blk_oldcop->cop_seq;
308 return pad_findlex(name, newoff, seq, PL_main_cv, -1, saweval, 0);
312 switch (cx->blk_eval.old_op_type) {
318 /* require must have its own scope */
326 if (PL_debstash && CvSTASH(cv) == PL_debstash) { /* ignore DB'* scope */
327 saweval = i; /* so we know where we were called from */
330 seq = cxstack[saweval].blk_oldcop->cop_seq;
331 return pad_findlex(name, newoff, seq, cv, i-1, saweval,FINDLEX_NOSEARCH);
339 Perl_pad_findmy(pTHX_ char *name)
345 SV **svp = AvARRAY(PL_comppad_name);
346 U32 seq = PL_cop_seqmax;
352 * Special case to get lexical (and hence per-thread) @_.
353 * XXX I need to find out how to tell at parse-time whether use
354 * of @_ should refer to a lexical (from a sub) or defgv (global
355 * scope and maybe weird sub-ish things like formats). See
356 * startsub in perly.y. It's possible that @_ could be lexical
357 * (at least from subs) even in non-threaded perl.
359 if (strEQ(name, "@_"))
360 return 0; /* success. (NOT_IN_PAD indicates failure) */
361 #endif /* USE_THREADS */
363 /* The one we're looking for is probably just before comppad_name_fill. */
364 for (off = AvFILLp(PL_comppad_name); off > 0; off--) {
365 if ((sv = svp[off]) &&
366 sv != &PL_sv_undef &&
369 seq > I_32(SvNVX(sv)))) &&
370 strEQ(SvPVX(sv), name))
372 if (SvIVX(sv) || SvFLAGS(sv) & SVpad_OUR)
373 return (PADOFFSET)off;
374 pendoff = off; /* this pending def. will override import */
378 outside = CvOUTSIDE(PL_compcv);
380 /* Check if if we're compiling an eval'', and adjust seq to be the
381 * eval's seq number. This depends on eval'' having a non-null
382 * CvOUTSIDE() while it is being compiled. The eval'' itself is
383 * identified by CvEVAL being true and CvGV being null. */
384 if (outside && CvEVAL(PL_compcv) && !CvGV(PL_compcv) && cxstack_ix >= 0) {
385 cx = &cxstack[cxstack_ix];
387 seq = cx->blk_oldcop->cop_seq;
390 /* See if it's in a nested scope */
391 off = pad_findlex(name, 0, seq, outside, cxstack_ix, 0, 0);
393 /* If there is a pending local definition, this new alias must die */
395 SvIVX(AvARRAY(PL_comppad_name)[off]) = seq;
396 return off; /* pad_findlex returns 0 for failure...*/
398 return NOT_IN_PAD; /* ...but we return NOT_IN_PAD for failure */
402 Perl_pad_leavemy(pTHX_ I32 fill)
406 SV **svp = AvARRAY(PL_comppad_name);
408 if (PL_min_intro_pending && fill < PL_min_intro_pending) {
409 for (off = PL_max_intro_pending; off >= PL_min_intro_pending; off--) {
410 if ((sv = svp[off]) && sv != &PL_sv_undef && ckWARN_d(WARN_INTERNAL))
411 Perl_warner(aTHX_ WARN_INTERNAL, "%s never introduced", SvPVX(sv));
414 /* "Deintroduce" my variables that are leaving with this scope. */
415 for (off = AvFILLp(PL_comppad_name); off > fill; off--) {
416 if ((sv = svp[off]) && sv != &PL_sv_undef && SvIVX(sv) == PAD_MAX)
417 SvIVX(sv) = PL_cop_seqmax;
422 Perl_pad_alloc(pTHX_ I32 optype, U32 tmptype)
428 if (AvARRAY(PL_comppad) != PL_curpad)
429 Perl_croak(aTHX_ "panic: pad_alloc");
430 if (PL_pad_reset_pending)
432 if (tmptype & SVs_PADMY) {
434 sv = *av_fetch(PL_comppad, AvFILLp(PL_comppad) + 1, TRUE);
435 } while (SvPADBUSY(sv)); /* need a fresh one */
436 retval = AvFILLp(PL_comppad);
439 SV **names = AvARRAY(PL_comppad_name);
440 SSize_t names_fill = AvFILLp(PL_comppad_name);
443 * "foreach" index vars temporarily become aliases to non-"my"
444 * values. Thus we must skip, not just pad values that are
445 * marked as current pad values, but also those with names.
447 if (++PL_padix <= names_fill &&
448 (sv = names[PL_padix]) && sv != &PL_sv_undef)
450 sv = *av_fetch(PL_comppad, PL_padix, TRUE);
451 if (!(SvFLAGS(sv) & (SVs_PADTMP|SVs_PADMY)) && !IS_PADGV(sv))
456 SvFLAGS(sv) |= tmptype;
457 PL_curpad = AvARRAY(PL_comppad);
459 DEBUG_X(PerlIO_printf(Perl_debug_log,
460 "0x%"UVxf" Pad 0x%"UVxf" alloc %ld for %s\n",
461 PTR2UV(thr), PTR2UV(PL_curpad),
462 (long) retval, PL_op_name[optype]));
464 DEBUG_X(PerlIO_printf(Perl_debug_log,
465 "Pad 0x%"UVxf" alloc %ld for %s\n",
467 (long) retval, PL_op_name[optype]));
468 #endif /* USE_THREADS */
469 return (PADOFFSET)retval;
473 Perl_pad_sv(pTHX_ PADOFFSET po)
477 DEBUG_X(PerlIO_printf(Perl_debug_log,
478 "0x%"UVxf" Pad 0x%"UVxf" sv %"IVdf"\n",
479 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
482 Perl_croak(aTHX_ "panic: pad_sv po");
483 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" sv %"IVdf"\n",
484 PTR2UV(PL_curpad), (IV)po));
485 #endif /* USE_THREADS */
486 return PL_curpad[po]; /* eventually we'll turn this into a macro */
490 Perl_pad_free(pTHX_ PADOFFSET po)
495 if (AvARRAY(PL_comppad) != PL_curpad)
496 Perl_croak(aTHX_ "panic: pad_free curpad");
498 Perl_croak(aTHX_ "panic: pad_free po");
500 DEBUG_X(PerlIO_printf(Perl_debug_log,
501 "0x%"UVxf" Pad 0x%"UVxf" free %"IVd"\n",
502 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
504 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" free %"IVdf"\n",
505 PTR2UV(PL_curpad), (IV)po));
506 #endif /* USE_THREADS */
507 if (PL_curpad[po] && PL_curpad[po] != &PL_sv_undef)
508 SvPADTMP_off(PL_curpad[po]);
509 if ((I32)po < PL_padix)
514 Perl_pad_swipe(pTHX_ PADOFFSET po)
517 if (AvARRAY(PL_comppad) != PL_curpad)
518 Perl_croak(aTHX_ "panic: pad_swipe curpad");
520 Perl_croak(aTHX_ "panic: pad_swipe po");
522 DEBUG_X(PerlIO_printf(Perl_debug_log,
523 "0x%"UVxf" Pad 0x%"UVxf" swipe %"IVdf"\n",
524 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
526 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" swipe %"IVdf"\n",
527 PTR2UV(PL_curpad), (IV)po));
528 #endif /* USE_THREADS */
529 SvPADTMP_off(PL_curpad[po]);
530 PL_curpad[po] = NEWSV(1107,0);
531 SvPADTMP_on(PL_curpad[po]);
532 if ((I32)po < PL_padix)
536 /* XXX pad_reset() is currently disabled because it results in serious bugs.
537 * It causes pad temp TARGs to be shared between OPs. Since TARGs are pushed
538 * on the stack by OPs that use them, there are several ways to get an alias
539 * to a shared TARG. Such an alias will change randomly and unpredictably.
540 * We avoid doing this until we can think of a Better Way.
545 #ifdef USE_BROKEN_PAD_RESET
549 if (AvARRAY(PL_comppad) != PL_curpad)
550 Perl_croak(aTHX_ "panic: pad_reset curpad");
552 DEBUG_X(PerlIO_printf(Perl_debug_log,
553 "0x%"UVxf" Pad 0x%"UVxf" reset\n",
554 PTR2UV(thr), PTR2UV(PL_curpad)));
556 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" reset\n",
558 #endif /* USE_THREADS */
559 if (!PL_tainting) { /* Can't mix tainted and non-tainted temporaries. */
560 for (po = AvMAX(PL_comppad); po > PL_padix_floor; po--) {
561 if (PL_curpad[po] && !SvIMMORTAL(PL_curpad[po]))
562 SvPADTMP_off(PL_curpad[po]);
564 PL_padix = PL_padix_floor;
567 PL_pad_reset_pending = FALSE;
571 /* find_threadsv is not reentrant */
573 Perl_find_threadsv(pTHX_ const char *name)
579 /* We currently only handle names of a single character */
580 p = strchr(PL_threadsv_names, *name);
583 key = p - PL_threadsv_names;
584 MUTEX_LOCK(&thr->mutex);
585 svp = av_fetch(thr->threadsv, key, FALSE);
587 MUTEX_UNLOCK(&thr->mutex);
589 SV *sv = NEWSV(0, 0);
590 av_store(thr->threadsv, key, sv);
591 thr->threadsvp = AvARRAY(thr->threadsv);
592 MUTEX_UNLOCK(&thr->mutex);
594 * Some magic variables used to be automagically initialised
595 * in gv_fetchpv. Those which are now per-thread magicals get
596 * initialised here instead.
602 sv_setpv(sv, "\034");
603 sv_magic(sv, 0, 0, name, 1);
608 PL_sawampersand = TRUE;
622 /* XXX %! tied to Errno.pm needs to be added here.
623 * See gv_fetchpv(). */
627 sv_magic(sv, 0, 0, name, 1);
629 DEBUG_S(PerlIO_printf(Perl_error_log,
630 "find_threadsv: new SV %p for $%s%c\n",
631 sv, (*name < 32) ? "^" : "",
632 (*name < 32) ? toCTRL(*name) : *name));
636 #endif /* USE_THREADS */
641 Perl_op_free(pTHX_ OP *o)
643 register OP *kid, *nextkid;
646 if (!o || o->op_seq == (U16)-1)
649 if (o->op_private & OPpREFCOUNTED) {
650 switch (o->op_type) {
658 if (OpREFCNT_dec(o)) {
662 o->op_targ = 0; /* XXXXXX */
670 if (o->op_flags & OPf_KIDS) {
671 for (kid = cUNOPo->op_first; kid; kid = nextkid) {
672 nextkid = kid->op_sibling; /* Get before next freeing kid */
680 /* COP* is not cleared by op_clear() so that we may track line
681 * numbers etc even after null() */
682 if (type == OP_NEXTSTATE || type == OP_SETSTATE || type == OP_DBSTATE)
687 #ifdef PL_OP_SLAB_ALLOC
688 if ((char *) o == PL_OpPtr)
697 S_op_clear(pTHX_ OP *o)
699 switch (o->op_type) {
700 case OP_NULL: /* Was holding old type, if any. */
701 case OP_ENTEREVAL: /* Was holding hints. */
703 case OP_THREADSV: /* Was holding index into thr->threadsv AV. */
709 if (!(o->op_flags & OPf_SPECIAL))
712 #endif /* USE_THREADS */
714 if (!(o->op_flags & OPf_REF)
715 || (PL_check[o->op_type] != MEMBER_TO_FPTR(Perl_ck_ftst)))
722 if (cPADOPo->op_padix > 0) {
725 pad_swipe(cPADOPo->op_padix);
726 /* No GvIN_PAD_off(gv) here, because other references may still
727 * exist on the pad */
730 cPADOPo->op_padix = 0;
733 SvREFCNT_dec(cSVOPo->op_sv);
734 cSVOPo->op_sv = Nullsv;
738 SvREFCNT_dec(cSVOPo->op_sv);
739 cSVOPo->op_sv = Nullsv;
745 if (o->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
749 if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
750 SvREFCNT_dec(cSVOPo->op_sv);
751 cSVOPo->op_sv = Nullsv;
754 Safefree(cPVOPo->op_pv);
755 cPVOPo->op_pv = Nullch;
759 op_free(cPMOPo->op_pmreplroot);
763 if ((PADOFFSET)cPMOPo->op_pmreplroot) {
765 GV *gv = (GV*)PL_curpad[(PADOFFSET)cPMOPo->op_pmreplroot];
766 pad_swipe((PADOFFSET)cPMOPo->op_pmreplroot);
767 /* No GvIN_PAD_off(gv) here, because other references may still
768 * exist on the pad */
773 SvREFCNT_dec((SV*)cPMOPo->op_pmreplroot);
779 cPMOPo->op_pmreplroot = Nullop;
780 ReREFCNT_dec(cPMOPo->op_pmregexp);
781 cPMOPo->op_pmregexp = (REGEXP*)NULL;
785 if (o->op_targ > 0) {
786 pad_free(o->op_targ);
792 S_cop_free(pTHX_ COP* cop)
794 Safefree(cop->cop_label);
796 Safefree(CopFILE(cop)); /* XXXXX share in a pvtable? */
797 Safefree(CopSTASHPV(cop)); /* XXXXX share in a pvtable? */
799 /* NOTE: COP.cop_stash is not refcounted */
800 SvREFCNT_dec(CopFILEGV(cop));
802 if (! specialWARN(cop->cop_warnings))
803 SvREFCNT_dec(cop->cop_warnings);
809 if (o->op_type == OP_NULL)
812 o->op_targ = o->op_type;
813 o->op_type = OP_NULL;
814 o->op_ppaddr = PL_ppaddr[OP_NULL];
817 /* Contextualizers */
819 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
822 Perl_linklist(pTHX_ OP *o)
829 /* establish postfix order */
830 if (cUNOPo->op_first) {
831 o->op_next = LINKLIST(cUNOPo->op_first);
832 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
834 kid->op_next = LINKLIST(kid->op_sibling);
846 Perl_scalarkids(pTHX_ OP *o)
849 if (o && o->op_flags & OPf_KIDS) {
850 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
857 S_scalarboolean(pTHX_ OP *o)
859 if (o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST) {
861 if (ckWARN(WARN_SYNTAX)) {
862 line_t oldline = CopLINE(PL_curcop);
864 if (PL_copline != NOLINE)
865 CopLINE_set(PL_curcop, PL_copline);
866 Perl_warner(aTHX_ WARN_SYNTAX, "Found = in conditional, should be ==");
867 CopLINE_set(PL_curcop, oldline);
874 Perl_scalar(pTHX_ OP *o)
878 /* assumes no premature commitment */
879 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
880 || o->op_type == OP_RETURN)
885 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_SCALAR;
887 switch (o->op_type) {
889 if (o->op_private & OPpREPEAT_DOLIST)
890 null(((LISTOP*)cBINOPo->op_first)->op_first);
891 scalar(cBINOPo->op_first);
896 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
900 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
901 if (!kPMOP->op_pmreplroot)
902 deprecate("implicit split to @_");
910 if (o->op_flags & OPf_KIDS) {
911 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
917 kid = cLISTOPo->op_first;
919 while (kid = kid->op_sibling) {
925 WITH_THR(PL_curcop = &PL_compiling);
930 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
936 WITH_THR(PL_curcop = &PL_compiling);
943 Perl_scalarvoid(pTHX_ OP *o)
950 if (o->op_type == OP_NEXTSTATE
951 || o->op_type == OP_SETSTATE
952 || o->op_type == OP_DBSTATE
953 || (o->op_type == OP_NULL && (o->op_targ == OP_NEXTSTATE
954 || o->op_targ == OP_SETSTATE
955 || o->op_targ == OP_DBSTATE)))
958 PL_curcop = (COP*)o; /* for warning below */
961 /* assumes no premature commitment */
962 want = o->op_flags & OPf_WANT;
963 if ((want && want != OPf_WANT_SCALAR) || PL_error_count
964 || o->op_type == OP_RETURN)
969 if ((o->op_private & OPpTARGET_MY)
970 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
972 return scalar(o); /* As if inside SASSIGN */
975 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_VOID;
977 switch (o->op_type) {
979 if (!(PL_opargs[o->op_type] & OA_FOLDCONST))
983 if (o->op_flags & OPf_STACKED)
987 if (o->op_private == 4)
1029 case OP_GETSOCKNAME:
1030 case OP_GETPEERNAME:
1035 case OP_GETPRIORITY:
1058 if (!(o->op_private & OPpLVAL_INTRO))
1059 useless = PL_op_desc[o->op_type];
1066 if (!(o->op_private & OPpLVAL_INTRO) &&
1067 (!o->op_sibling || o->op_sibling->op_type != OP_READLINE))
1068 useless = "a variable";
1073 if (cSVOPo->op_private & OPpCONST_STRICT)
1074 no_bareword_allowed(o);
1077 if (ckWARN(WARN_VOID)) {
1078 useless = "a constant";
1079 if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
1081 else if (SvPOK(sv)) {
1082 if (strnEQ(SvPVX(sv), "di", 2) ||
1083 strnEQ(SvPVX(sv), "ds", 2) ||
1084 strnEQ(SvPVX(sv), "ig", 2))
1089 null(o); /* don't execute or even remember it */
1093 o->op_type = OP_PREINC; /* pre-increment is faster */
1094 o->op_ppaddr = PL_ppaddr[OP_PREINC];
1098 o->op_type = OP_PREDEC; /* pre-decrement is faster */
1099 o->op_ppaddr = PL_ppaddr[OP_PREDEC];
1105 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1110 if (o->op_flags & OPf_STACKED)
1118 if (!(o->op_flags & OPf_KIDS))
1127 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1134 /* all requires must return a boolean value */
1135 o->op_flags &= ~OPf_WANT;
1138 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
1139 if (!kPMOP->op_pmreplroot)
1140 deprecate("implicit split to @_");
1146 if (ckWARN(WARN_VOID))
1147 Perl_warner(aTHX_ WARN_VOID, "Useless use of %s in void context", useless);
1153 Perl_listkids(pTHX_ OP *o)
1156 if (o && o->op_flags & OPf_KIDS) {
1157 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1164 Perl_list(pTHX_ OP *o)
1168 /* assumes no premature commitment */
1169 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
1170 || o->op_type == OP_RETURN)
1175 if ((o->op_private & OPpTARGET_MY)
1176 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
1178 return o; /* As if inside SASSIGN */
1181 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_LIST;
1183 switch (o->op_type) {
1186 list(cBINOPo->op_first);
1191 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1199 if (!(o->op_flags & OPf_KIDS))
1201 if (!o->op_next && cUNOPo->op_first->op_type == OP_FLOP) {
1202 list(cBINOPo->op_first);
1203 return gen_constant_list(o);
1210 kid = cLISTOPo->op_first;
1212 while (kid = kid->op_sibling) {
1213 if (kid->op_sibling)
1218 WITH_THR(PL_curcop = &PL_compiling);
1222 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
1223 if (kid->op_sibling)
1228 WITH_THR(PL_curcop = &PL_compiling);
1231 /* all requires must return a boolean value */
1232 o->op_flags &= ~OPf_WANT;
1239 Perl_scalarseq(pTHX_ OP *o)
1244 if (o->op_type == OP_LINESEQ ||
1245 o->op_type == OP_SCOPE ||
1246 o->op_type == OP_LEAVE ||
1247 o->op_type == OP_LEAVETRY)
1250 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
1251 if (kid->op_sibling) {
1255 PL_curcop = &PL_compiling;
1257 o->op_flags &= ~OPf_PARENS;
1258 if (PL_hints & HINT_BLOCK_SCOPE)
1259 o->op_flags |= OPf_PARENS;
1262 o = newOP(OP_STUB, 0);
1267 S_modkids(pTHX_ OP *o, I32 type)
1270 if (o && o->op_flags & OPf_KIDS) {
1271 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1278 Perl_mod(pTHX_ OP *o, I32 type)
1285 if (!o || PL_error_count)
1288 if ((o->op_private & OPpTARGET_MY)
1289 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
1294 switch (o->op_type) {
1299 if (!(o->op_private & (OPpCONST_ARYBASE)))
1301 if (PL_eval_start && PL_eval_start->op_type == OP_CONST) {
1302 PL_compiling.cop_arybase = (I32)SvIV(((SVOP*)PL_eval_start)->op_sv);
1306 SAVEI32(PL_compiling.cop_arybase);
1307 PL_compiling.cop_arybase = 0;
1309 else if (type == OP_REFGEN)
1312 Perl_croak(aTHX_ "That use of $[ is unsupported");
1315 if (o->op_flags & OPf_PARENS)
1319 if ((type == OP_UNDEF || type == OP_REFGEN) &&
1320 !(o->op_flags & OPf_STACKED)) {
1321 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1322 o->op_ppaddr = PL_ppaddr[OP_RV2CV];
1323 assert(cUNOPo->op_first->op_type == OP_NULL);
1324 null(((LISTOP*)cUNOPo->op_first)->op_first);/* disable pushmark */
1327 else { /* lvalue subroutine call */
1328 o->op_private |= OPpLVAL_INTRO;
1329 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN) {
1330 /* Backward compatibility mode: */
1331 o->op_private |= OPpENTERSUB_INARGS;
1334 else { /* Compile-time error message: */
1335 OP *kid = cUNOPo->op_first;
1339 if (kid->op_type == OP_PUSHMARK)
1341 if (kid->op_type != OP_NULL || kid->op_targ != OP_LIST)
1343 "panic: unexpected lvalue entersub "
1344 "args: type/targ %ld:%ld",
1345 (long)kid->op_type,kid->op_targ);
1346 kid = kLISTOP->op_first;
1348 while (kid->op_sibling)
1349 kid = kid->op_sibling;
1350 if (!(kid->op_type == OP_NULL && kid->op_targ == OP_RV2CV)) {
1352 if (kid->op_type == OP_METHOD_NAMED
1353 || kid->op_type == OP_METHOD)
1357 if (kid->op_sibling || kid->op_next != kid) {
1358 yyerror("panic: unexpected optree near method call");
1362 NewOp(1101, newop, 1, OP);
1363 newop->op_type = OP_RV2CV;
1364 newop->op_ppaddr = PL_ppaddr[OP_RV2CV];
1365 newop->op_next = newop;
1366 kid->op_sibling = newop;
1367 newop->op_private |= OPpLVAL_INTRO;
1371 if (kid->op_type != OP_RV2CV)
1373 "panic: unexpected lvalue entersub "
1374 "entry via type/targ %ld:%ld",
1375 (long)kid->op_type,kid->op_targ);
1376 kid->op_private |= OPpLVAL_INTRO;
1377 break; /* Postpone until runtime */
1381 kid = kUNOP->op_first;
1382 if (kid->op_type == OP_NULL && kid->op_targ == OP_RV2SV)
1383 kid = kUNOP->op_first;
1384 if (kid->op_type == OP_NULL)
1386 "Unexpected constant lvalue entersub "
1387 "entry via type/targ %ld:%ld",
1388 (long)kid->op_type,kid->op_targ);
1389 if (kid->op_type != OP_GV) {
1390 /* Restore RV2CV to check lvalueness */
1392 if (kid->op_next && kid->op_next != kid) { /* Happens? */
1393 okid->op_next = kid->op_next;
1394 kid->op_next = okid;
1397 okid->op_next = Nullop;
1398 okid->op_type = OP_RV2CV;
1400 okid->op_ppaddr = PL_ppaddr[OP_RV2CV];
1401 okid->op_private |= OPpLVAL_INTRO;
1415 /* grep, foreach, subcalls, refgen */
1416 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
1418 yyerror(Perl_form(aTHX_ "Can't modify %s in %s",
1419 (o->op_type == OP_NULL && (o->op_flags & OPf_SPECIAL)
1421 : (o->op_type == OP_ENTERSUB
1422 ? "non-lvalue subroutine call"
1423 : PL_op_desc[o->op_type])),
1424 type ? PL_op_desc[type] : "local"));
1438 case OP_RIGHT_SHIFT:
1447 if (!(o->op_flags & OPf_STACKED))
1453 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1459 if (!type && cUNOPo->op_first->op_type != OP_GV)
1460 Perl_croak(aTHX_ "Can't localize through a reference");
1461 if (type == OP_REFGEN && o->op_flags & OPf_PARENS) {
1462 PL_modcount = 10000;
1463 return o; /* Treat \(@foo) like ordinary list. */
1467 if (scalar_mod_type(o, type))
1469 ref(cUNOPo->op_first, o->op_type);
1478 PL_modcount = 10000;
1481 if (!type && cUNOPo->op_first->op_type != OP_GV)
1482 Perl_croak(aTHX_ "Can't localize through a reference");
1483 ref(cUNOPo->op_first, o->op_type);
1487 PL_hints |= HINT_BLOCK_SCOPE;
1497 PL_modcount = 10000;
1498 if (type == OP_REFGEN && o->op_flags & OPf_PARENS)
1499 return o; /* Treat \(@foo) like ordinary list. */
1500 if (scalar_mod_type(o, type))
1506 Perl_croak(aTHX_ "Can't localize lexical variable %s",
1507 SvPV(*av_fetch(PL_comppad_name, o->op_targ, 4), n_a));
1512 PL_modcount++; /* XXX ??? */
1514 #endif /* USE_THREADS */
1520 if (type != OP_SASSIGN)
1524 if (o->op_private == 4) /* don't allow 4 arg substr as lvalue */
1530 pad_free(o->op_targ);
1531 o->op_targ = pad_alloc(o->op_type, SVs_PADMY);
1532 assert(SvTYPE(PAD_SV(o->op_targ)) == SVt_NULL);
1533 if (o->op_flags & OPf_KIDS)
1534 mod(cBINOPo->op_first->op_sibling, type);
1539 ref(cBINOPo->op_first, o->op_type);
1540 if (type == OP_ENTERSUB &&
1541 !(o->op_private & (OPpLVAL_INTRO | OPpDEREF)))
1542 o->op_private |= OPpLVAL_DEFER;
1549 if (o->op_flags & OPf_KIDS)
1550 mod(cLISTOPo->op_last, type);
1554 if (o->op_flags & OPf_SPECIAL) /* do BLOCK */
1556 else if (!(o->op_flags & OPf_KIDS))
1558 if (o->op_targ != OP_LIST) {
1559 mod(cBINOPo->op_first, type);
1564 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1568 o->op_flags |= OPf_MOD;
1570 if (type == OP_AASSIGN || type == OP_SASSIGN)
1571 o->op_flags |= OPf_SPECIAL|OPf_REF;
1573 o->op_private |= OPpLVAL_INTRO;
1574 o->op_flags &= ~OPf_SPECIAL;
1575 PL_hints |= HINT_BLOCK_SCOPE;
1577 else if (type != OP_GREPSTART && type != OP_ENTERSUB)
1578 o->op_flags |= OPf_REF;
1583 S_scalar_mod_type(pTHX_ OP *o, I32 type)
1587 if (o->op_type == OP_RV2GV)
1611 case OP_RIGHT_SHIFT:
1630 S_is_handle_constructor(pTHX_ OP *o, I32 argnum)
1632 switch (o->op_type) {
1640 case OP_SELECT: /* XXX c.f. SelectSaver.pm */
1653 Perl_refkids(pTHX_ OP *o, I32 type)
1656 if (o && o->op_flags & OPf_KIDS) {
1657 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1664 Perl_ref(pTHX_ OP *o, I32 type)
1668 if (!o || PL_error_count)
1671 switch (o->op_type) {
1673 if ((type == OP_DEFINED || type == OP_LOCK) &&
1674 !(o->op_flags & OPf_STACKED)) {
1675 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1676 o->op_ppaddr = PL_ppaddr[OP_RV2CV];
1677 assert(cUNOPo->op_first->op_type == OP_NULL);
1678 null(((LISTOP*)cUNOPo->op_first)->op_first); /* disable pushmark */
1679 o->op_flags |= OPf_SPECIAL;
1684 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1688 if (type == OP_DEFINED)
1689 o->op_flags |= OPf_SPECIAL; /* don't create GV */
1690 ref(cUNOPo->op_first, o->op_type);
1693 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1694 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1695 : type == OP_RV2HV ? OPpDEREF_HV
1697 o->op_flags |= OPf_MOD;
1702 o->op_flags |= OPf_MOD; /* XXX ??? */
1707 o->op_flags |= OPf_REF;
1710 if (type == OP_DEFINED)
1711 o->op_flags |= OPf_SPECIAL; /* don't create GV */
1712 ref(cUNOPo->op_first, o->op_type);
1717 o->op_flags |= OPf_REF;
1722 if (!(o->op_flags & OPf_KIDS))
1724 ref(cBINOPo->op_first, type);
1728 ref(cBINOPo->op_first, o->op_type);
1729 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1730 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1731 : type == OP_RV2HV ? OPpDEREF_HV
1733 o->op_flags |= OPf_MOD;
1741 if (!(o->op_flags & OPf_KIDS))
1743 ref(cLISTOPo->op_last, type);
1753 S_dup_attrlist(pTHX_ OP *o)
1757 /* An attrlist is either a simple OP_CONST or an OP_LIST with kids,
1758 * where the first kid is OP_PUSHMARK and the remaining ones
1759 * are OP_CONST. We need to push the OP_CONST values.
1761 if (o->op_type == OP_CONST)
1762 rop = newSVOP(OP_CONST, o->op_flags, SvREFCNT_inc(cSVOPo->op_sv));
1764 assert((o->op_type == OP_LIST) && (o->op_flags & OPf_KIDS));
1765 for (o = cLISTOPo->op_first; o; o=o->op_sibling) {
1766 if (o->op_type == OP_CONST)
1767 rop = append_elem(OP_LIST, rop,
1768 newSVOP(OP_CONST, o->op_flags,
1769 SvREFCNT_inc(cSVOPo->op_sv)));
1776 S_apply_attrs(pTHX_ HV *stash, SV *target, OP *attrs)
1778 OP *modname; /* for 'use' */
1781 /* fake up C<use attributes $pkg,$rv,@attrs> */
1782 ENTER; /* need to protect against side-effects of 'use' */
1784 if (stash && HvNAME(stash))
1785 stashsv = newSVpv(HvNAME(stash), 0);
1787 stashsv = &PL_sv_no;
1788 #define ATTRSMODULE "attributes"
1789 modname = newSVOP(OP_CONST, 0,
1790 newSVpvn(ATTRSMODULE, sizeof(ATTRSMODULE)-1));
1791 modname->op_private |= OPpCONST_BARE;
1792 /* that flag is required to make 'use' work right */
1793 utilize(1, start_subparse(FALSE, 0),
1794 Nullop, /* version */
1796 prepend_elem(OP_LIST,
1797 newSVOP(OP_CONST, 0, stashsv),
1798 prepend_elem(OP_LIST,
1799 newSVOP(OP_CONST, 0, newRV(target)),
1800 dup_attrlist(attrs))));
1805 S_my_kid(pTHX_ OP *o, OP *attrs)
1810 if (!o || PL_error_count)
1814 if (type == OP_LIST) {
1815 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1817 } else if (type == OP_UNDEF) {
1819 } else if (type == OP_RV2SV || /* "our" declaration */
1821 type == OP_RV2HV) { /* XXX does this let anything illegal in? */
1823 } else if (type != OP_PADSV &&
1826 type != OP_PUSHMARK)
1828 yyerror(Perl_form(aTHX_ "Can't declare %s in my", PL_op_desc[o->op_type]));
1831 else if (attrs && type != OP_PUSHMARK) {
1836 /* check for C<my Dog $spot> when deciding package */
1837 namesvp = av_fetch(PL_comppad_name, o->op_targ, FALSE);
1838 if (namesvp && *namesvp && SvOBJECT(*namesvp) && HvNAME(SvSTASH(*namesvp)))
1839 stash = SvSTASH(*namesvp);
1841 stash = PL_curstash;
1842 padsv = PAD_SV(o->op_targ);
1843 apply_attrs(stash, padsv, attrs);
1845 o->op_flags |= OPf_MOD;
1846 o->op_private |= OPpLVAL_INTRO;
1851 Perl_my_attrs(pTHX_ OP *o, OP *attrs)
1853 if (o->op_flags & OPf_PARENS)
1856 PL_in_my_stash = Nullhv;
1859 return my_kid(o, attrs);
1863 Perl_my(pTHX_ OP *o)
1865 return my_kid(o, Nullop);
1869 Perl_sawparens(pTHX_ OP *o)
1872 o->op_flags |= OPf_PARENS;
1877 Perl_bind_match(pTHX_ I32 type, OP *left, OP *right)
1882 if (ckWARN(WARN_UNSAFE) &&
1883 (left->op_type == OP_RV2AV ||
1884 left->op_type == OP_RV2HV ||
1885 left->op_type == OP_PADAV ||
1886 left->op_type == OP_PADHV)) {
1887 char *desc = PL_op_desc[(right->op_type == OP_SUBST ||
1888 right->op_type == OP_TRANS)
1889 ? right->op_type : OP_MATCH];
1890 const char *sample = ((left->op_type == OP_RV2AV ||
1891 left->op_type == OP_PADAV)
1892 ? "@array" : "%hash");
1893 Perl_warner(aTHX_ WARN_UNSAFE,
1894 "Applying %s to %s will act on scalar(%s)",
1895 desc, sample, sample);
1898 if (right->op_type == OP_MATCH ||
1899 right->op_type == OP_SUBST ||
1900 right->op_type == OP_TRANS) {
1901 right->op_flags |= OPf_STACKED;
1902 if (right->op_type != OP_MATCH)
1903 left = mod(left, right->op_type);
1904 if (right->op_type == OP_TRANS)
1905 o = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
1907 o = prepend_elem(right->op_type, scalar(left), right);
1909 return newUNOP(OP_NOT, 0, scalar(o));
1913 return bind_match(type, left,
1914 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
1918 Perl_invert(pTHX_ OP *o)
1922 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
1923 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(o));
1927 Perl_scope(pTHX_ OP *o)
1930 if (o->op_flags & OPf_PARENS || PERLDB_NOOPT || PL_tainting) {
1931 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
1932 o->op_type = OP_LEAVE;
1933 o->op_ppaddr = PL_ppaddr[OP_LEAVE];
1936 if (o->op_type == OP_LINESEQ) {
1938 o->op_type = OP_SCOPE;
1939 o->op_ppaddr = PL_ppaddr[OP_SCOPE];
1940 kid = ((LISTOP*)o)->op_first;
1941 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE)
1945 o = newLISTOP(OP_SCOPE, 0, o, Nullop);
1952 Perl_save_hints(pTHX)
1955 SAVESPTR(GvHV(PL_hintgv));
1956 GvHV(PL_hintgv) = newHVhv(GvHV(PL_hintgv));
1957 SAVEFREESV(GvHV(PL_hintgv));
1961 Perl_block_start(pTHX_ int full)
1964 int retval = PL_savestack_ix;
1966 SAVEI32(PL_comppad_name_floor);
1968 if ((PL_comppad_name_fill = AvFILLp(PL_comppad_name)) > 0)
1969 PL_comppad_name_floor = PL_comppad_name_fill;
1971 PL_comppad_name_floor = 0;
1973 SAVEI32(PL_min_intro_pending);
1974 SAVEI32(PL_max_intro_pending);
1975 PL_min_intro_pending = 0;
1976 SAVEI32(PL_comppad_name_fill);
1977 SAVEI32(PL_padix_floor);
1978 PL_padix_floor = PL_padix;
1979 PL_pad_reset_pending = FALSE;
1981 PL_hints &= ~HINT_BLOCK_SCOPE;
1982 SAVEPPTR(PL_compiling.cop_warnings);
1983 if (! specialWARN(PL_compiling.cop_warnings)) {
1984 PL_compiling.cop_warnings = newSVsv(PL_compiling.cop_warnings) ;
1985 SAVEFREESV(PL_compiling.cop_warnings) ;
1993 Perl_block_end(pTHX_ I32 floor, OP *seq)
1996 int needblockscope = PL_hints & HINT_BLOCK_SCOPE;
1997 OP* retval = scalarseq(seq);
1999 PL_pad_reset_pending = FALSE;
2000 PL_compiling.op_private = PL_hints;
2002 PL_hints |= HINT_BLOCK_SCOPE; /* propagate out */
2003 pad_leavemy(PL_comppad_name_fill);
2012 OP *o = newOP(OP_THREADSV, 0);
2013 o->op_targ = find_threadsv("_");
2016 return newSVREF(newGVOP(OP_GV, 0, PL_defgv));
2017 #endif /* USE_THREADS */
2021 Perl_newPROG(pTHX_ OP *o)
2027 PL_eval_root = newUNOP(OP_LEAVEEVAL,
2028 ((PL_in_eval & EVAL_KEEPERR)
2029 ? OPf_SPECIAL : 0), o);
2030 PL_eval_start = linklist(PL_eval_root);
2031 PL_eval_root->op_private |= OPpREFCOUNTED;
2032 OpREFCNT_set(PL_eval_root, 1);
2033 PL_eval_root->op_next = 0;
2034 peep(PL_eval_start);
2039 PL_main_root = scope(sawparens(scalarvoid(o)));
2040 PL_curcop = &PL_compiling;
2041 PL_main_start = LINKLIST(PL_main_root);
2042 PL_main_root->op_private |= OPpREFCOUNTED;
2043 OpREFCNT_set(PL_main_root, 1);
2044 PL_main_root->op_next = 0;
2045 peep(PL_main_start);
2048 /* Register with debugger */
2050 CV *cv = get_cv("DB::postponed", FALSE);
2054 XPUSHs((SV*)CopFILEGV(&PL_compiling));
2056 call_sv((SV*)cv, G_DISCARD);
2063 Perl_localize(pTHX_ OP *o, I32 lex)
2065 if (o->op_flags & OPf_PARENS)
2069 if (ckWARN(WARN_PARENTHESIS) && PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == ',') {
2071 for (s = PL_bufptr; *s && (isALNUM(*s) || (*s & 0x80) || strchr("@$%, ",*s)); s++) ;
2072 if (*s == ';' || *s == '=')
2073 Perl_warner(aTHX_ WARN_PARENTHESIS, "Parentheses missing around \"%s\" list",
2074 lex ? "my" : "local");
2078 PL_in_my_stash = Nullhv;
2082 return mod(o, OP_NULL); /* a bit kludgey */
2086 Perl_jmaybe(pTHX_ OP *o)
2088 if (o->op_type == OP_LIST) {
2091 o2 = newOP(OP_THREADSV, 0);
2092 o2->op_targ = find_threadsv(";");
2094 o2 = newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
2095 #endif /* USE_THREADS */
2096 o = convert(OP_JOIN, 0, prepend_elem(OP_LIST, o2, o));
2102 Perl_fold_constants(pTHX_ register OP *o)
2106 I32 type = o->op_type;
2109 if (PL_opargs[type] & OA_RETSCALAR)
2111 if (PL_opargs[type] & OA_TARGET && !o->op_targ)
2112 o->op_targ = pad_alloc(type, SVs_PADTMP);
2114 /* integerize op, unless it happens to be C<-foo>.
2115 * XXX should pp_i_negate() do magic string negation instead? */
2116 if ((PL_opargs[type] & OA_OTHERINT) && (PL_hints & HINT_INTEGER)
2117 && !(type == OP_NEGATE && cUNOPo->op_first->op_type == OP_CONST
2118 && (cUNOPo->op_first->op_private & OPpCONST_BARE)))
2120 o->op_ppaddr = PL_ppaddr[type = ++(o->op_type)];
2123 if (!(PL_opargs[type] & OA_FOLDCONST))
2128 /* XXX might want a ck_negate() for this */
2129 cUNOPo->op_first->op_private &= ~OPpCONST_STRICT;
2142 if (o->op_private & OPpLOCALE)
2147 goto nope; /* Don't try to run w/ errors */
2149 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
2150 if ((curop->op_type != OP_CONST ||
2151 (curop->op_private & OPpCONST_BARE)) &&
2152 curop->op_type != OP_LIST &&
2153 curop->op_type != OP_SCALAR &&
2154 curop->op_type != OP_NULL &&
2155 curop->op_type != OP_PUSHMARK)
2161 curop = LINKLIST(o);
2165 sv = *(PL_stack_sp--);
2166 if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
2167 pad_swipe(o->op_targ);
2168 else if (SvTEMP(sv)) { /* grab mortal temp? */
2169 (void)SvREFCNT_inc(sv);
2173 if (type == OP_RV2GV)
2174 return newGVOP(OP_GV, 0, (GV*)sv);
2176 /* try to smush double to int, but don't smush -2.0 to -2 */
2177 if ((SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK)) == SVf_NOK &&
2181 if ((NV)iv == SvNV(sv)) {
2186 SvIOK_off(sv); /* undo SvIV() damage */
2188 return newSVOP(OP_CONST, 0, sv);
2192 if (!(PL_opargs[type] & OA_OTHERINT))
2195 if (!(PL_hints & HINT_INTEGER)) {
2196 if (type == OP_MODULO
2197 || type == OP_DIVIDE
2198 || !(o->op_flags & OPf_KIDS))
2203 for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
2204 if (curop->op_type == OP_CONST) {
2205 if (SvIOK(((SVOP*)curop)->op_sv))
2209 if (PL_opargs[curop->op_type] & OA_RETINTEGER)
2213 o->op_ppaddr = PL_ppaddr[++(o->op_type)];
2220 Perl_gen_constant_list(pTHX_ register OP *o)
2224 I32 oldtmps_floor = PL_tmps_floor;
2228 return o; /* Don't attempt to run with errors */
2230 PL_op = curop = LINKLIST(o);
2236 PL_tmps_floor = oldtmps_floor;
2238 o->op_type = OP_RV2AV;
2239 o->op_ppaddr = PL_ppaddr[OP_RV2AV];
2240 curop = ((UNOP*)o)->op_first;
2241 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*PL_stack_sp--));
2248 Perl_convert(pTHX_ I32 type, I32 flags, OP *o)
2253 if (!o || o->op_type != OP_LIST)
2254 o = newLISTOP(OP_LIST, 0, o, Nullop);
2256 o->op_flags &= ~OPf_WANT;
2258 if (!(PL_opargs[type] & OA_MARK))
2259 null(cLISTOPo->op_first);
2262 o->op_ppaddr = PL_ppaddr[type];
2263 o->op_flags |= flags;
2265 o = CHECKOP(type, o);
2266 if (o->op_type != type)
2269 if (cLISTOPo->op_children < 7) {
2270 /* XXX do we really need to do this if we're done appending?? */
2271 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
2273 cLISTOPo->op_last = last; /* in case check substituted last arg */
2276 return fold_constants(o);
2279 /* List constructors */
2282 Perl_append_elem(pTHX_ I32 type, OP *first, OP *last)
2290 if (first->op_type != type || type==OP_LIST && first->op_flags & OPf_PARENS)
2291 return newLISTOP(type, 0, first, last);
2293 if (first->op_flags & OPf_KIDS)
2294 ((LISTOP*)first)->op_last->op_sibling = last;
2296 first->op_flags |= OPf_KIDS;
2297 ((LISTOP*)first)->op_first = last;
2299 ((LISTOP*)first)->op_last = last;
2300 ((LISTOP*)first)->op_children++;
2305 Perl_append_list(pTHX_ I32 type, LISTOP *first, LISTOP *last)
2313 if (first->op_type != type)
2314 return prepend_elem(type, (OP*)first, (OP*)last);
2316 if (last->op_type != type)
2317 return append_elem(type, (OP*)first, (OP*)last);
2319 first->op_last->op_sibling = last->op_first;
2320 first->op_last = last->op_last;
2321 first->op_children += last->op_children;
2322 if (first->op_children)
2323 first->op_flags |= OPf_KIDS;
2325 #ifdef PL_OP_SLAB_ALLOC
2333 Perl_prepend_elem(pTHX_ I32 type, OP *first, OP *last)
2341 if (last->op_type == type) {
2342 if (type == OP_LIST) { /* already a PUSHMARK there */
2343 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
2344 ((LISTOP*)last)->op_first->op_sibling = first;
2347 if (!(last->op_flags & OPf_KIDS)) {
2348 ((LISTOP*)last)->op_last = first;
2349 last->op_flags |= OPf_KIDS;
2351 first->op_sibling = ((LISTOP*)last)->op_first;
2352 ((LISTOP*)last)->op_first = first;
2354 ((LISTOP*)last)->op_children++;
2358 return newLISTOP(type, 0, first, last);
2364 Perl_newNULLLIST(pTHX)
2366 return newOP(OP_STUB, 0);
2370 Perl_force_list(pTHX_ OP *o)
2372 if (!o || o->op_type != OP_LIST)
2373 o = newLISTOP(OP_LIST, 0, o, Nullop);
2379 Perl_newLISTOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
2383 NewOp(1101, listop, 1, LISTOP);
2385 listop->op_type = type;
2386 listop->op_ppaddr = PL_ppaddr[type];
2387 listop->op_children = (first != 0) + (last != 0);
2388 listop->op_flags = flags;
2392 else if (!first && last)
2395 first->op_sibling = last;
2396 listop->op_first = first;
2397 listop->op_last = last;
2398 if (type == OP_LIST) {
2400 pushop = newOP(OP_PUSHMARK, 0);
2401 pushop->op_sibling = first;
2402 listop->op_first = pushop;
2403 listop->op_flags |= OPf_KIDS;
2405 listop->op_last = pushop;
2407 else if (listop->op_children)
2408 listop->op_flags |= OPf_KIDS;
2414 Perl_newOP(pTHX_ I32 type, I32 flags)
2417 NewOp(1101, o, 1, OP);
2419 o->op_ppaddr = PL_ppaddr[type];
2420 o->op_flags = flags;
2423 o->op_private = 0 + (flags >> 8);
2424 if (PL_opargs[type] & OA_RETSCALAR)
2426 if (PL_opargs[type] & OA_TARGET)
2427 o->op_targ = pad_alloc(type, SVs_PADTMP);
2428 return CHECKOP(type, o);
2432 Perl_newUNOP(pTHX_ I32 type, I32 flags, OP *first)
2437 first = newOP(OP_STUB, 0);
2438 if (PL_opargs[type] & OA_MARK)
2439 first = force_list(first);
2441 NewOp(1101, unop, 1, UNOP);
2442 unop->op_type = type;
2443 unop->op_ppaddr = PL_ppaddr[type];
2444 unop->op_first = first;
2445 unop->op_flags = flags | OPf_KIDS;
2446 unop->op_private = 1 | (flags >> 8);
2447 unop = (UNOP*) CHECKOP(type, unop);
2451 return fold_constants((OP *) unop);
2455 Perl_newBINOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
2458 NewOp(1101, binop, 1, BINOP);
2461 first = newOP(OP_NULL, 0);
2463 binop->op_type = type;
2464 binop->op_ppaddr = PL_ppaddr[type];
2465 binop->op_first = first;
2466 binop->op_flags = flags | OPf_KIDS;
2469 binop->op_private = 1 | (flags >> 8);
2472 binop->op_private = 2 | (flags >> 8);
2473 first->op_sibling = last;
2476 binop = (BINOP*)CHECKOP(type, binop);
2477 if (binop->op_next || binop->op_type != type)
2480 binop->op_last = binop->op_first->op_sibling;
2482 return fold_constants((OP *)binop);
2486 utf8compare(const void *a, const void *b)
2489 for (i = 0; i < 10; i++) {
2490 if ((*(U8**)a)[i] < (*(U8**)b)[i])
2492 if ((*(U8**)a)[i] > (*(U8**)b)[i])
2499 Perl_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
2501 SV *tstr = ((SVOP*)expr)->op_sv;
2502 SV *rstr = ((SVOP*)repl)->op_sv;
2505 register U8 *t = (U8*)SvPV(tstr, tlen);
2506 register U8 *r = (U8*)SvPV(rstr, rlen);
2512 register short *tbl;
2514 complement = o->op_private & OPpTRANS_COMPLEMENT;
2515 del = o->op_private & OPpTRANS_DELETE;
2516 squash = o->op_private & OPpTRANS_SQUASH;
2518 if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
2519 SV* listsv = newSVpvn("# comment\n",10);
2521 U8* tend = t + tlen;
2522 U8* rend = r + rlen;
2538 I32 from_utf = o->op_private & OPpTRANS_FROM_UTF;
2539 I32 to_utf = o->op_private & OPpTRANS_TO_UTF;
2545 New(1109, cp, tlen, U8*);
2547 transv = newSVpvn("",0);
2556 qsort(cp, i, sizeof(U8*), utf8compare);
2557 for (j = 0; j < i; j++) {
2559 UV val = utf8_to_uv(s, &ulen);
2561 diff = val - nextmin;
2563 t = uv_to_utf8(tmpbuf,nextmin);
2564 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2566 t = uv_to_utf8(tmpbuf, val - 1);
2567 sv_catpvn(transv, "\377", 1);
2568 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2572 val = utf8_to_uv(s+1, &ulen);
2576 t = uv_to_utf8(tmpbuf,nextmin);
2577 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2578 t = uv_to_utf8(tmpbuf, 0x7fffffff);
2579 sv_catpvn(transv, "\377", 1);
2580 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2581 t = (U8*)SvPVX(transv);
2582 tlen = SvCUR(transv);
2585 else if (!rlen && !del) {
2586 r = t; rlen = tlen; rend = tend;
2589 if (to_utf && from_utf) { /* only counting characters */
2590 if (t == r || (tlen == rlen && memEQ(t, r, tlen)))
2591 o->op_private |= OPpTRANS_IDENTICAL;
2593 else { /* straight latin-1 translation */
2594 if (tlen == 4 && memEQ(t, "\0\377\303\277", 4) &&
2595 rlen == 4 && memEQ(r, "\0\377\303\277", 4))
2596 o->op_private |= OPpTRANS_IDENTICAL;
2600 while (t < tend || tfirst <= tlast) {
2601 /* see if we need more "t" chars */
2602 if (tfirst > tlast) {
2603 tfirst = (I32)utf8_to_uv(t, &ulen);
2605 if (t < tend && *t == 0xff) { /* illegal utf8 val indicates range */
2606 tlast = (I32)utf8_to_uv(++t, &ulen);
2613 /* now see if we need more "r" chars */
2614 if (rfirst > rlast) {
2616 rfirst = (I32)utf8_to_uv(r, &ulen);
2618 if (r < rend && *r == 0xff) { /* illegal utf8 val indicates range */
2619 rlast = (I32)utf8_to_uv(++r, &ulen);
2628 rfirst = rlast = 0xffffffff;
2632 /* now see which range will peter our first, if either. */
2633 tdiff = tlast - tfirst;
2634 rdiff = rlast - rfirst;
2641 if (rfirst == 0xffffffff) {
2642 diff = tdiff; /* oops, pretend rdiff is infinite */
2644 Perl_sv_catpvf(aTHX_ listsv, "%04x\t%04x\tXXXX\n", tfirst, tlast);
2646 Perl_sv_catpvf(aTHX_ listsv, "%04x\t\tXXXX\n", tfirst);
2650 Perl_sv_catpvf(aTHX_ listsv, "%04x\t%04x\t%04x\n", tfirst, tfirst + diff, rfirst);
2652 Perl_sv_catpvf(aTHX_ listsv, "%04x\t\t%04x\n", tfirst, rfirst);
2654 if (rfirst + diff > max)
2655 max = rfirst + diff;
2660 else if (rfirst <= 0x800)
2661 grows |= (tfirst < 0x80);
2662 else if (rfirst <= 0x10000)
2663 grows |= (tfirst < 0x800);
2664 else if (rfirst <= 0x200000)
2665 grows |= (tfirst < 0x10000);
2666 else if (rfirst <= 0x4000000)
2667 grows |= (tfirst < 0x200000);
2668 else if (rfirst <= 0x80000000)
2669 grows |= (tfirst < 0x4000000);
2681 else if (max > 0xff)
2686 cSVOPo->op_sv = (SV*)swash_init("utf8", "", listsv, bits, none);
2687 SvREFCNT_dec(listsv);
2689 SvREFCNT_dec(transv);
2691 if (!del && havefinal)
2692 (void)hv_store((HV*)SvRV((cSVOPo->op_sv)), "FINAL", 5, newSViv((IV)final), 0);
2694 if (grows && to_utf)
2695 o->op_private |= OPpTRANS_GROWS;
2702 tbl = (short*)cPVOPo->op_pv;
2704 Zero(tbl, 256, short);
2705 for (i = 0; i < tlen; i++)
2707 for (i = 0, j = 0; i < 256; i++) {
2723 if (!rlen && !del) {
2726 o->op_private |= OPpTRANS_IDENTICAL;
2728 for (i = 0; i < 256; i++)
2730 for (i = 0, j = 0; i < tlen; i++,j++) {
2733 if (tbl[t[i]] == -1)
2739 if (tbl[t[i]] == -1)
2750 Perl_newPMOP(pTHX_ I32 type, I32 flags)
2755 NewOp(1101, pmop, 1, PMOP);
2756 pmop->op_type = type;
2757 pmop->op_ppaddr = PL_ppaddr[type];
2758 pmop->op_flags = flags;
2759 pmop->op_private = 0 | (flags >> 8);
2761 if (PL_hints & HINT_RE_TAINT)
2762 pmop->op_pmpermflags |= PMf_RETAINT;
2763 if (PL_hints & HINT_LOCALE)
2764 pmop->op_pmpermflags |= PMf_LOCALE;
2765 pmop->op_pmflags = pmop->op_pmpermflags;
2767 /* link into pm list */
2768 if (type != OP_TRANS && PL_curstash) {
2769 pmop->op_pmnext = HvPMROOT(PL_curstash);
2770 HvPMROOT(PL_curstash) = pmop;
2777 Perl_pmruntime(pTHX_ OP *o, OP *expr, OP *repl)
2782 I32 repl_has_vars = 0;
2784 if (o->op_type == OP_TRANS)
2785 return pmtrans(o, expr, repl);
2787 PL_hints |= HINT_BLOCK_SCOPE;
2790 if (expr->op_type == OP_CONST) {
2792 SV *pat = ((SVOP*)expr)->op_sv;
2793 char *p = SvPV(pat, plen);
2794 if ((o->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
2795 sv_setpvn(pat, "\\s+", 3);
2796 p = SvPV(pat, plen);
2797 pm->op_pmflags |= PMf_SKIPWHITE;
2799 pm->op_pmregexp = CALLREGCOMP(aTHX_ p, p + plen, pm);
2800 if (strEQ("\\s+", pm->op_pmregexp->precomp))
2801 pm->op_pmflags |= PMf_WHITE;
2805 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL))
2806 expr = newUNOP((!(PL_hints & HINT_RE_EVAL)
2808 : OP_REGCMAYBE),0,expr);
2810 NewOp(1101, rcop, 1, LOGOP);
2811 rcop->op_type = OP_REGCOMP;
2812 rcop->op_ppaddr = PL_ppaddr[OP_REGCOMP];
2813 rcop->op_first = scalar(expr);
2814 rcop->op_flags |= ((PL_hints & HINT_RE_EVAL)
2815 ? (OPf_SPECIAL | OPf_KIDS)
2817 rcop->op_private = 1;
2820 /* establish postfix order */
2821 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL)) {
2823 rcop->op_next = expr;
2824 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
2827 rcop->op_next = LINKLIST(expr);
2828 expr->op_next = (OP*)rcop;
2831 prepend_elem(o->op_type, scalar((OP*)rcop), o);
2836 if (pm->op_pmflags & PMf_EVAL) {
2838 if (CopLINE(PL_curcop) < PL_multi_end)
2839 CopLINE_set(PL_curcop, PL_multi_end);
2842 else if (repl->op_type == OP_THREADSV
2843 && strchr("&`'123456789+",
2844 PL_threadsv_names[repl->op_targ]))
2848 #endif /* USE_THREADS */
2849 else if (repl->op_type == OP_CONST)
2853 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
2854 if (PL_opargs[curop->op_type] & OA_DANGEROUS) {
2856 if (curop->op_type == OP_THREADSV) {
2858 if (strchr("&`'123456789+", curop->op_private))
2862 if (curop->op_type == OP_GV) {
2863 GV *gv = cGVOPx(curop);
2865 if (strchr("&`'123456789+", *GvENAME(gv)))
2868 #endif /* USE_THREADS */
2869 else if (curop->op_type == OP_RV2CV)
2871 else if (curop->op_type == OP_RV2SV ||
2872 curop->op_type == OP_RV2AV ||
2873 curop->op_type == OP_RV2HV ||
2874 curop->op_type == OP_RV2GV) {
2875 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
2878 else if (curop->op_type == OP_PADSV ||
2879 curop->op_type == OP_PADAV ||
2880 curop->op_type == OP_PADHV ||
2881 curop->op_type == OP_PADANY) {
2884 else if (curop->op_type == OP_PUSHRE)
2885 ; /* Okay here, dangerous in newASSIGNOP */
2894 && (!pm->op_pmregexp
2895 || pm->op_pmregexp->reganch & ROPT_EVAL_SEEN))) {
2896 pm->op_pmflags |= PMf_CONST; /* const for long enough */
2897 pm->op_pmpermflags |= PMf_CONST; /* const for long enough */
2898 prepend_elem(o->op_type, scalar(repl), o);
2901 if (curop == repl && !pm->op_pmregexp) { /* Has variables. */
2902 pm->op_pmflags |= PMf_MAYBE_CONST;
2903 pm->op_pmpermflags |= PMf_MAYBE_CONST;
2905 NewOp(1101, rcop, 1, LOGOP);
2906 rcop->op_type = OP_SUBSTCONT;
2907 rcop->op_ppaddr = PL_ppaddr[OP_SUBSTCONT];
2908 rcop->op_first = scalar(repl);
2909 rcop->op_flags |= OPf_KIDS;
2910 rcop->op_private = 1;
2913 /* establish postfix order */
2914 rcop->op_next = LINKLIST(repl);
2915 repl->op_next = (OP*)rcop;
2917 pm->op_pmreplroot = scalar((OP*)rcop);
2918 pm->op_pmreplstart = LINKLIST(rcop);
2927 Perl_newSVOP(pTHX_ I32 type, I32 flags, SV *sv)
2930 NewOp(1101, svop, 1, SVOP);
2931 svop->op_type = type;
2932 svop->op_ppaddr = PL_ppaddr[type];
2934 svop->op_next = (OP*)svop;
2935 svop->op_flags = flags;
2936 if (PL_opargs[type] & OA_RETSCALAR)
2938 if (PL_opargs[type] & OA_TARGET)
2939 svop->op_targ = pad_alloc(type, SVs_PADTMP);
2940 return CHECKOP(type, svop);
2944 Perl_newPADOP(pTHX_ I32 type, I32 flags, SV *sv)
2947 NewOp(1101, padop, 1, PADOP);
2948 padop->op_type = type;
2949 padop->op_ppaddr = PL_ppaddr[type];
2950 padop->op_padix = pad_alloc(type, SVs_PADTMP);
2951 PL_curpad[padop->op_padix] = sv;
2952 padop->op_next = (OP*)padop;
2953 padop->op_flags = flags;
2954 if (PL_opargs[type] & OA_RETSCALAR)
2956 if (PL_opargs[type] & OA_TARGET)
2957 padop->op_targ = pad_alloc(type, SVs_PADTMP);
2958 return CHECKOP(type, padop);
2962 Perl_newGVOP(pTHX_ I32 type, I32 flags, GV *gv)
2967 return newPADOP(type, flags, SvREFCNT_inc(gv));
2969 return newSVOP(type, flags, SvREFCNT_inc(gv));
2974 Perl_newPVOP(pTHX_ I32 type, I32 flags, char *pv)
2977 NewOp(1101, pvop, 1, PVOP);
2978 pvop->op_type = type;
2979 pvop->op_ppaddr = PL_ppaddr[type];
2981 pvop->op_next = (OP*)pvop;
2982 pvop->op_flags = flags;
2983 if (PL_opargs[type] & OA_RETSCALAR)
2985 if (PL_opargs[type] & OA_TARGET)
2986 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
2987 return CHECKOP(type, pvop);
2991 Perl_package(pTHX_ OP *o)
2996 save_hptr(&PL_curstash);
2997 save_item(PL_curstname);
3002 name = SvPV(sv, len);
3003 PL_curstash = gv_stashpvn(name,len,TRUE);
3004 sv_setpvn(PL_curstname, name, len);
3008 sv_setpv(PL_curstname,"<none>");
3009 PL_curstash = Nullhv;
3011 PL_hints |= HINT_BLOCK_SCOPE;
3012 PL_copline = NOLINE;
3017 Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *id, OP *arg)
3026 if (id->op_type != OP_CONST)
3027 Perl_croak(aTHX_ "Module name must be constant");
3031 if(version != Nullop) {
3032 SV *vesv = ((SVOP*)version)->op_sv;
3034 if (arg == Nullop && !SvNIOK(vesv)) {
3040 if (version->op_type != OP_CONST || !SvNIOK(vesv))
3041 Perl_croak(aTHX_ "Version number must be constant number");
3043 /* Make copy of id so we don't free it twice */
3044 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
3046 /* Fake up a method call to VERSION */
3047 veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
3048 append_elem(OP_LIST,
3049 prepend_elem(OP_LIST, pack, list(version)),
3050 newSVOP(OP_METHOD_NAMED, 0,
3051 newSVpvn("VERSION", 7))));
3055 /* Fake up an import/unimport */
3056 if (arg && arg->op_type == OP_STUB)
3057 imop = arg; /* no import on explicit () */
3058 else if(SvNIOK(((SVOP*)id)->op_sv)) {
3059 imop = Nullop; /* use 5.0; */
3062 /* Make copy of id so we don't free it twice */
3063 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
3064 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
3065 append_elem(OP_LIST,
3066 prepend_elem(OP_LIST, pack, list(arg)),
3067 newSVOP(OP_METHOD_NAMED, 0,
3068 aver ? newSVpvn("import", 6)
3069 : newSVpvn("unimport", 8))));
3072 /* Fake up a require, handle override, if any */
3073 gv = gv_fetchpv("require", FALSE, SVt_PVCV);
3074 if (!(gv && GvIMPORTED_CV(gv)))
3075 gv = gv_fetchpv("CORE::GLOBAL::require", FALSE, SVt_PVCV);
3077 if (gv && GvIMPORTED_CV(gv)) {
3078 rqop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
3079 append_elem(OP_LIST, id,
3080 scalar(newUNOP(OP_RV2CV, 0,
3085 rqop = newUNOP(OP_REQUIRE, 0, id);
3088 /* Fake up the BEGIN {}, which does its thing immediately. */
3090 newSVOP(OP_CONST, 0, newSVpvn("BEGIN", 5)),
3093 append_elem(OP_LINESEQ,
3094 append_elem(OP_LINESEQ,
3095 newSTATEOP(0, Nullch, rqop),
3096 newSTATEOP(0, Nullch, veop)),
3097 newSTATEOP(0, Nullch, imop) ));
3099 PL_hints |= HINT_BLOCK_SCOPE;
3100 PL_copline = NOLINE;
3105 Perl_dofile(pTHX_ OP *term)
3110 gv = gv_fetchpv("do", FALSE, SVt_PVCV);
3111 if (!(gv && GvIMPORTED_CV(gv)))
3112 gv = gv_fetchpv("CORE::GLOBAL::do", FALSE, SVt_PVCV);
3114 if (gv && GvIMPORTED_CV(gv)) {
3115 doop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
3116 append_elem(OP_LIST, term,
3117 scalar(newUNOP(OP_RV2CV, 0,
3122 doop = newUNOP(OP_DOFILE, 0, scalar(term));
3128 Perl_newSLICEOP(pTHX_ I32 flags, OP *subscript, OP *listval)
3130 return newBINOP(OP_LSLICE, flags,
3131 list(force_list(subscript)),
3132 list(force_list(listval)) );
3136 S_list_assignment(pTHX_ register OP *o)
3141 if (o->op_type == OP_NULL && o->op_flags & OPf_KIDS)
3142 o = cUNOPo->op_first;
3144 if (o->op_type == OP_COND_EXPR) {
3145 I32 t = list_assignment(cLOGOPo->op_first->op_sibling);
3146 I32 f = list_assignment(cLOGOPo->op_first->op_sibling->op_sibling);
3151 yyerror("Assignment to both a list and a scalar");
3155 if (o->op_type == OP_LIST || o->op_flags & OPf_PARENS ||
3156 o->op_type == OP_RV2AV || o->op_type == OP_RV2HV ||
3157 o->op_type == OP_ASLICE || o->op_type == OP_HSLICE)
3160 if (o->op_type == OP_PADAV || o->op_type == OP_PADHV)
3163 if (o->op_type == OP_RV2SV)
3170 Perl_newASSIGNOP(pTHX_ I32 flags, OP *left, I32 optype, OP *right)
3175 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN) {
3176 return newLOGOP(optype, 0,
3177 mod(scalar(left), optype),
3178 newUNOP(OP_SASSIGN, 0, scalar(right)));
3181 return newBINOP(optype, OPf_STACKED,
3182 mod(scalar(left), optype), scalar(right));
3186 if (list_assignment(left)) {
3189 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
3190 left = mod(left, OP_AASSIGN);
3198 o = newBINOP(OP_AASSIGN, flags,
3199 list(force_list(right)),
3200 list(force_list(left)) );
3201 o->op_private = 0 | (flags >> 8);
3202 if (!(left->op_private & OPpLVAL_INTRO)) {
3206 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
3207 if (PL_opargs[curop->op_type] & OA_DANGEROUS) {
3208 if (curop->op_type == OP_GV) {
3209 GV *gv = cGVOPx(curop);
3210 if (gv == PL_defgv || SvCUR(gv) == PL_generation)
3212 SvCUR(gv) = PL_generation;
3214 else if (curop->op_type == OP_PADSV ||
3215 curop->op_type == OP_PADAV ||
3216 curop->op_type == OP_PADHV ||
3217 curop->op_type == OP_PADANY) {
3218 SV **svp = AvARRAY(PL_comppad_name);
3219 SV *sv = svp[curop->op_targ];
3220 if (SvCUR(sv) == PL_generation)
3222 SvCUR(sv) = PL_generation; /* (SvCUR not used any more) */
3224 else if (curop->op_type == OP_RV2CV)
3226 else if (curop->op_type == OP_RV2SV ||
3227 curop->op_type == OP_RV2AV ||
3228 curop->op_type == OP_RV2HV ||
3229 curop->op_type == OP_RV2GV) {
3230 if (lastop->op_type != OP_GV) /* funny deref? */
3233 else if (curop->op_type == OP_PUSHRE) {
3234 if (((PMOP*)curop)->op_pmreplroot) {
3235 GV *gv = (GV*)((PMOP*)curop)->op_pmreplroot;
3236 if (gv == PL_defgv || SvCUR(gv) == PL_generation)
3238 SvCUR(gv) = PL_generation;
3247 o->op_private = OPpASSIGN_COMMON;
3249 if (right && right->op_type == OP_SPLIT) {
3251 if ((tmpop = ((LISTOP*)right)->op_first) &&
3252 tmpop->op_type == OP_PUSHRE)
3254 PMOP *pm = (PMOP*)tmpop;
3255 if (left->op_type == OP_RV2AV &&
3256 !(left->op_private & OPpLVAL_INTRO) &&
3257 !(o->op_private & OPpASSIGN_COMMON) )
3259 tmpop = ((UNOP*)left)->op_first;
3260 if (tmpop->op_type == OP_GV && !pm->op_pmreplroot) {
3262 pm->op_pmreplroot = (OP*)cPADOPx(tmpop)->op_padix;
3263 cPADOPx(tmpop)->op_padix = 0; /* steal it */
3265 pm->op_pmreplroot = (OP*)cSVOPx(tmpop)->op_sv;
3266 cSVOPx(tmpop)->op_sv = Nullsv; /* steal it */
3268 pm->op_pmflags |= PMf_ONCE;
3269 tmpop = cUNOPo->op_first; /* to list (nulled) */
3270 tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */
3271 tmpop->op_sibling = Nullop; /* don't free split */
3272 right->op_next = tmpop->op_next; /* fix starting loc */
3273 op_free(o); /* blow off assign */
3274 right->op_flags &= ~OPf_WANT;
3275 /* "I don't know and I don't care." */
3280 if (PL_modcount < 10000 &&
3281 ((LISTOP*)right)->op_last->op_type == OP_CONST)
3283 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
3285 sv_setiv(sv, PL_modcount+1);
3293 right = newOP(OP_UNDEF, 0);
3294 if (right->op_type == OP_READLINE) {
3295 right->op_flags |= OPf_STACKED;
3296 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
3299 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
3300 o = newBINOP(OP_SASSIGN, flags,
3301 scalar(right), mod(scalar(left), OP_SASSIGN) );
3313 Perl_newSTATEOP(pTHX_ I32 flags, char *label, OP *o)
3316 U32 seq = intro_my();
3319 NewOp(1101, cop, 1, COP);
3320 if (PERLDB_LINE && CopLINE(PL_curcop) && PL_curstash != PL_debstash) {
3321 cop->op_type = OP_DBSTATE;
3322 cop->op_ppaddr = PL_ppaddr[ OP_DBSTATE ];
3325 cop->op_type = OP_NEXTSTATE;
3326 cop->op_ppaddr = PL_ppaddr[ OP_NEXTSTATE ];
3328 cop->op_flags = flags;
3329 cop->op_private = (PL_hints & HINT_UTF8);
3331 cop->op_private |= NATIVE_HINTS;
3333 PL_compiling.op_private = cop->op_private;
3334 cop->op_next = (OP*)cop;
3337 cop->cop_label = label;
3338 PL_hints |= HINT_BLOCK_SCOPE;
3341 cop->cop_arybase = PL_curcop->cop_arybase;
3342 if (specialWARN(PL_curcop->cop_warnings))
3343 cop->cop_warnings = PL_curcop->cop_warnings ;
3345 cop->cop_warnings = newSVsv(PL_curcop->cop_warnings) ;
3348 if (PL_copline == NOLINE)
3349 CopLINE_set(cop, CopLINE(PL_curcop));
3351 CopLINE_set(cop, PL_copline);
3352 PL_copline = NOLINE;
3355 CopFILE_set(cop, CopFILE(PL_curcop)); /* XXXXX share in a pvtable? */
3357 CopFILEGV_set(cop, (GV*)SvREFCNT_inc(CopFILEGV(PL_curcop)));
3359 CopSTASH_set(cop, PL_curstash);
3361 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3362 SV **svp = av_fetch(CopFILEAV(PL_curcop), (I32)CopLINE(cop), FALSE);
3363 if (svp && *svp != &PL_sv_undef && !SvIOK(*svp)) {
3364 (void)SvIOK_on(*svp);
3366 #ifndef USE_ITHREADS
3367 /* XXX This nameless kludge interferes with cloning SVs. :-(
3368 * What's more, it seems entirely redundant when considering
3369 * PL_DBsingle exists to do the same thing */
3370 SvSTASH(*svp) = (HV*)cop;
3375 return prepend_elem(OP_LINESEQ, (OP*)cop, o);
3378 /* "Introduce" my variables to visible status. */
3386 if (! PL_min_intro_pending)
3387 return PL_cop_seqmax;
3389 svp = AvARRAY(PL_comppad_name);
3390 for (i = PL_min_intro_pending; i <= PL_max_intro_pending; i++) {
3391 if ((sv = svp[i]) && sv != &PL_sv_undef && !SvIVX(sv)) {
3392 SvIVX(sv) = PAD_MAX; /* Don't know scope end yet. */
3393 SvNVX(sv) = (NV)PL_cop_seqmax;
3396 PL_min_intro_pending = 0;
3397 PL_comppad_name_fill = PL_max_intro_pending; /* Needn't search higher */
3398 return PL_cop_seqmax++;
3402 Perl_newLOGOP(pTHX_ I32 type, I32 flags, OP *first, OP *other)
3404 return new_logop(type, flags, &first, &other);
3408 S_new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp)
3413 OP *first = *firstp;
3414 OP *other = *otherp;
3416 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
3417 return newBINOP(type, flags, scalar(first), scalar(other));
3419 scalarboolean(first);
3420 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
3421 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
3422 if (type == OP_AND || type == OP_OR) {
3428 first = *firstp = cUNOPo->op_first;
3430 first->op_next = o->op_next;
3431 cUNOPo->op_first = Nullop;
3435 if (first->op_type == OP_CONST) {
3436 if (ckWARN(WARN_PRECEDENCE) && (first->op_private & OPpCONST_BARE))
3437 Perl_warner(aTHX_ WARN_PRECEDENCE, "Probable precedence problem on %s",
3439 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
3450 else if (first->op_type == OP_WANTARRAY) {
3456 else if (ckWARN(WARN_UNSAFE) && (first->op_flags & OPf_KIDS)) {
3457 OP *k1 = ((UNOP*)first)->op_first;
3458 OP *k2 = k1->op_sibling;
3460 switch (first->op_type)
3463 if (k2 && k2->op_type == OP_READLINE
3464 && (k2->op_flags & OPf_STACKED)
3465 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3467 warnop = k2->op_type;
3472 if (k1->op_type == OP_READDIR
3473 || k1->op_type == OP_GLOB
3474 || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
3475 || k1->op_type == OP_EACH)
3477 warnop = ((k1->op_type == OP_NULL)
3478 ? k1->op_targ : k1->op_type);
3483 line_t oldline = CopLINE(PL_curcop);
3484 CopLINE_set(PL_curcop, PL_copline);
3485 Perl_warner(aTHX_ WARN_UNSAFE,
3486 "Value of %s%s can be \"0\"; test with defined()",
3488 ((warnop == OP_READLINE || warnop == OP_GLOB)
3489 ? " construct" : "() operator"));
3490 CopLINE_set(PL_curcop, oldline);
3497 if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
3498 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
3500 NewOp(1101, logop, 1, LOGOP);
3502 logop->op_type = type;
3503 logop->op_ppaddr = PL_ppaddr[type];
3504 logop->op_first = first;
3505 logop->op_flags = flags | OPf_KIDS;
3506 logop->op_other = LINKLIST(other);
3507 logop->op_private = 1 | (flags >> 8);
3509 /* establish postfix order */
3510 logop->op_next = LINKLIST(first);
3511 first->op_next = (OP*)logop;
3512 first->op_sibling = other;
3514 o = newUNOP(OP_NULL, 0, (OP*)logop);
3521 Perl_newCONDOP(pTHX_ I32 flags, OP *first, OP *trueop, OP *falseop)
3529 return newLOGOP(OP_AND, 0, first, trueop);
3531 return newLOGOP(OP_OR, 0, first, falseop);
3533 scalarboolean(first);
3534 if (first->op_type == OP_CONST) {
3535 if (SvTRUE(((SVOP*)first)->op_sv)) {
3546 else if (first->op_type == OP_WANTARRAY) {
3550 NewOp(1101, logop, 1, LOGOP);
3551 logop->op_type = OP_COND_EXPR;
3552 logop->op_ppaddr = PL_ppaddr[OP_COND_EXPR];
3553 logop->op_first = first;
3554 logop->op_flags = flags | OPf_KIDS;
3555 logop->op_private = 1 | (flags >> 8);
3556 logop->op_other = LINKLIST(trueop);
3557 logop->op_next = LINKLIST(falseop);
3560 /* establish postfix order */
3561 start = LINKLIST(first);
3562 first->op_next = (OP*)logop;
3564 first->op_sibling = trueop;
3565 trueop->op_sibling = falseop;
3566 o = newUNOP(OP_NULL, 0, (OP*)logop);
3568 trueop->op_next = falseop->op_next = o;
3575 Perl_newRANGE(pTHX_ I32 flags, OP *left, OP *right)
3584 NewOp(1101, range, 1, LOGOP);
3586 range->op_type = OP_RANGE;
3587 range->op_ppaddr = PL_ppaddr[OP_RANGE];
3588 range->op_first = left;
3589 range->op_flags = OPf_KIDS;
3590 leftstart = LINKLIST(left);
3591 range->op_other = LINKLIST(right);
3592 range->op_private = 1 | (flags >> 8);
3594 left->op_sibling = right;
3596 range->op_next = (OP*)range;
3597 flip = newUNOP(OP_FLIP, flags, (OP*)range);
3598 flop = newUNOP(OP_FLOP, 0, flip);
3599 o = newUNOP(OP_NULL, 0, flop);
3601 range->op_next = leftstart;
3603 left->op_next = flip;
3604 right->op_next = flop;
3606 range->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
3607 sv_upgrade(PAD_SV(range->op_targ), SVt_PVNV);
3608 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
3609 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
3611 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
3612 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
3615 if (!flip->op_private || !flop->op_private)
3616 linklist(o); /* blow off optimizer unless constant */
3622 Perl_newLOOPOP(pTHX_ I32 flags, I32 debuggable, OP *expr, OP *block)
3627 int once = block && block->op_flags & OPf_SPECIAL &&
3628 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
3631 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
3632 return block; /* do {} while 0 does once */
3633 if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
3634 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB)) {
3635 expr = newUNOP(OP_DEFINED, 0,
3636 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
3637 } else if (expr->op_flags & OPf_KIDS) {
3638 OP *k1 = ((UNOP*)expr)->op_first;
3639 OP *k2 = (k1) ? k1->op_sibling : NULL;
3640 switch (expr->op_type) {
3642 if (k2 && k2->op_type == OP_READLINE
3643 && (k2->op_flags & OPf_STACKED)
3644 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3645 expr = newUNOP(OP_DEFINED, 0, expr);
3649 if (k1->op_type == OP_READDIR
3650 || k1->op_type == OP_GLOB
3651 || (k1->op_type == OP_NULL && k1->op_targ == OP_NULL)
3652 || k1->op_type == OP_EACH)
3653 expr = newUNOP(OP_DEFINED, 0, expr);
3659 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
3660 o = new_logop(OP_AND, 0, &expr, &listop);
3663 ((LISTOP*)listop)->op_last->op_next = LINKLIST(o);
3665 if (once && o != listop)
3666 o->op_next = ((LOGOP*)cUNOPo->op_first)->op_other;
3669 o = newUNOP(OP_NULL, 0, o); /* or do {} while 1 loses outer block */
3671 o->op_flags |= flags;
3673 o->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/
3678 Perl_newWHILEOP(pTHX_ I32 flags, I32 debuggable, LOOP *loop, I32 whileline, OP *expr, OP *block, OP *cont)
3687 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
3688 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB))) {
3689 expr = newUNOP(OP_DEFINED, 0,
3690 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
3691 } else if (expr && (expr->op_flags & OPf_KIDS)) {
3692 OP *k1 = ((UNOP*)expr)->op_first;
3693 OP *k2 = (k1) ? k1->op_sibling : NULL;
3694 switch (expr->op_type) {
3696 if (k2 && k2->op_type == OP_READLINE
3697 && (k2->op_flags & OPf_STACKED)
3698 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3699 expr = newUNOP(OP_DEFINED, 0, expr);
3703 if (k1->op_type == OP_READDIR
3704 || k1->op_type == OP_GLOB
3705 || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
3706 || k1->op_type == OP_EACH)
3707 expr = newUNOP(OP_DEFINED, 0, expr);
3713 block = newOP(OP_NULL, 0);
3716 next = LINKLIST(cont);
3718 cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
3719 if ((line_t)whileline != NOLINE) {
3720 PL_copline = whileline;
3721 cont = append_elem(OP_LINESEQ, cont,
3722 newSTATEOP(0, Nullch, Nullop));
3726 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
3727 redo = LINKLIST(listop);
3730 PL_copline = whileline;
3732 o = new_logop(OP_AND, 0, &expr, &listop);
3733 if (o == expr && o->op_type == OP_CONST && !SvTRUE(cSVOPo->op_sv)) {
3734 op_free(expr); /* oops, it's a while (0) */
3736 return Nullop; /* listop already freed by new_logop */
3739 ((LISTOP*)listop)->op_last->op_next = condop =
3740 (o == listop ? redo : LINKLIST(o));
3748 NewOp(1101,loop,1,LOOP);
3749 loop->op_type = OP_ENTERLOOP;
3750 loop->op_ppaddr = PL_ppaddr[OP_ENTERLOOP];
3751 loop->op_private = 0;
3752 loop->op_next = (OP*)loop;
3755 o = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, o);
3757 loop->op_redoop = redo;
3758 loop->op_lastop = o;
3761 loop->op_nextop = next;
3763 loop->op_nextop = o;
3765 o->op_flags |= flags;
3766 o->op_private |= (flags >> 8);
3771 Perl_newFOROP(pTHX_ I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
3780 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
3781 sv->op_type = OP_RV2GV;
3782 sv->op_ppaddr = PL_ppaddr[OP_RV2GV];
3784 else if (sv->op_type == OP_PADSV) { /* private variable */
3785 padoff = sv->op_targ;
3790 else if (sv->op_type == OP_THREADSV) { /* per-thread variable */
3791 padoff = sv->op_targ;
3793 iterflags |= OPf_SPECIAL;
3798 Perl_croak(aTHX_ "Can't use %s for loop variable", PL_op_desc[sv->op_type]);
3802 padoff = find_threadsv("_");
3803 iterflags |= OPf_SPECIAL;
3805 sv = newGVOP(OP_GV, 0, PL_defgv);
3808 if (expr->op_type == OP_RV2AV || expr->op_type == OP_PADAV) {
3809 expr = mod(force_list(scalar(ref(expr, OP_ITER))), OP_GREPSTART);
3810 iterflags |= OPf_STACKED;
3812 else if (expr->op_type == OP_NULL &&
3813 (expr->op_flags & OPf_KIDS) &&
3814 ((BINOP*)expr)->op_first->op_type == OP_FLOP)
3816 /* Basically turn for($x..$y) into the same as for($x,$y), but we
3817 * set the STACKED flag to indicate that these values are to be
3818 * treated as min/max values by 'pp_iterinit'.
3820 UNOP* flip = (UNOP*)((UNOP*)((BINOP*)expr)->op_first)->op_first;
3821 LOGOP* range = (LOGOP*) flip->op_first;
3822 OP* left = range->op_first;
3823 OP* right = left->op_sibling;
3826 range->op_flags &= ~OPf_KIDS;
3827 range->op_first = Nullop;
3829 listop = (LISTOP*)newLISTOP(OP_LIST, 0, left, right);
3830 listop->op_first->op_next = range->op_next;
3831 left->op_next = range->op_other;
3832 right->op_next = (OP*)listop;
3833 listop->op_next = listop->op_first;
3836 expr = (OP*)(listop);
3838 iterflags |= OPf_STACKED;
3841 expr = mod(force_list(expr), OP_GREPSTART);
3845 loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
3846 append_elem(OP_LIST, expr, scalar(sv))));
3847 assert(!loop->op_next);
3848 #ifdef PL_OP_SLAB_ALLOC
3849 NewOp(1234,tmp,1,LOOP);
3850 Copy(loop,tmp,1,LOOP);
3853 Renew(loop, 1, LOOP);
3855 loop->op_targ = padoff;
3856 wop = newWHILEOP(flags, 1, loop, forline, newOP(OP_ITER, 0), block, cont);
3857 PL_copline = forline;
3858 return newSTATEOP(0, label, wop);
3862 Perl_newLOOPEX(pTHX_ I32 type, OP *label)
3868 if (type != OP_GOTO || label->op_type == OP_CONST) {
3869 /* "last()" means "last" */
3870 if (label->op_type == OP_STUB && (label->op_flags & OPf_PARENS))
3871 o = newOP(type, OPf_SPECIAL);
3873 o = newPVOP(type, 0, savepv(label->op_type == OP_CONST
3874 ? SvPVx(((SVOP*)label)->op_sv, n_a)
3880 if (label->op_type == OP_ENTERSUB)
3881 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
3882 o = newUNOP(type, OPf_STACKED, label);
3884 PL_hints |= HINT_BLOCK_SCOPE;
3889 Perl_cv_undef(pTHX_ CV *cv)
3894 MUTEX_DESTROY(CvMUTEXP(cv));
3895 Safefree(CvMUTEXP(cv));
3898 #endif /* USE_THREADS */
3900 if (!CvXSUB(cv) && CvROOT(cv)) {
3902 if (CvDEPTH(cv) || (CvOWNER(cv) && CvOWNER(cv) != thr))
3903 Perl_croak(aTHX_ "Can't undef active subroutine");
3906 Perl_croak(aTHX_ "Can't undef active subroutine");
3907 #endif /* USE_THREADS */
3910 SAVESPTR(PL_curpad);
3914 op_free(CvROOT(cv));
3915 CvROOT(cv) = Nullop;
3918 SvPOK_off((SV*)cv); /* forget prototype */
3920 SvREFCNT_dec(CvGV(cv));
3922 SvREFCNT_dec(CvOUTSIDE(cv));
3923 CvOUTSIDE(cv) = Nullcv;
3924 if (CvPADLIST(cv)) {
3925 /* may be during global destruction */
3926 if (SvREFCNT(CvPADLIST(cv))) {
3927 I32 i = AvFILLp(CvPADLIST(cv));
3929 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
3930 SV* sv = svp ? *svp : Nullsv;
3933 if (sv == (SV*)PL_comppad_name)
3934 PL_comppad_name = Nullav;
3935 else if (sv == (SV*)PL_comppad) {
3936 PL_comppad = Nullav;
3937 PL_curpad = Null(SV**);
3941 SvREFCNT_dec((SV*)CvPADLIST(cv));
3943 CvPADLIST(cv) = Nullav;
3949 S_cv_dump(pTHX_ CV *cv)
3951 CV *outside = CvOUTSIDE(cv);
3952 AV* padlist = CvPADLIST(cv);
3959 PerlIO_printf(Perl_debug_log,
3960 "\tCV=0x%"UVxf" (%s), OUTSIDE=0x%"UVxf" (%s)\n",
3962 (CvANON(cv) ? "ANON"
3963 : (cv == PL_main_cv) ? "MAIN"
3964 : CvUNIQUE(cv) ? "UNIQUE"
3965 : CvGV(cv) ? GvNAME(CvGV(cv)) : "UNDEFINED"),
3968 : CvANON(outside) ? "ANON"
3969 : (outside == PL_main_cv) ? "MAIN"
3970 : CvUNIQUE(outside) ? "UNIQUE"
3971 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
3976 pad_name = (AV*)*av_fetch(padlist, 0, FALSE);
3977 pad = (AV*)*av_fetch(padlist, 1, FALSE);
3978 pname = AvARRAY(pad_name);
3979 ppad = AvARRAY(pad);
3981 for (ix = 1; ix <= AvFILLp(pad_name); ix++) {
3982 if (SvPOK(pname[ix]))
3983 PerlIO_printf(Perl_debug_log,
3984 "\t%4d. 0x%"UVxf" (%s\"%s\" %"IVdf"-%"IVdf")\n",
3985 ix, PTR2UV(ppad[ix]),
3986 SvFAKE(pname[ix]) ? "FAKE " : "",
3988 (IV)I_32(SvNVX(pname[ix])),
3992 #endif /* DEBUGGING */
3995 S_cv_clone2(pTHX_ CV *proto, CV *outside)
4000 AV* protopadlist = CvPADLIST(proto);
4001 AV* protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
4002 AV* protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
4003 SV** pname = AvARRAY(protopad_name);
4004 SV** ppad = AvARRAY(protopad);
4005 I32 fname = AvFILLp(protopad_name);
4006 I32 fpad = AvFILLp(protopad);
4010 assert(!CvUNIQUE(proto));
4013 SAVESPTR(PL_curpad);
4014 SAVESPTR(PL_comppad);
4015 SAVESPTR(PL_comppad_name);
4016 SAVESPTR(PL_compcv);
4018 cv = PL_compcv = (CV*)NEWSV(1104,0);
4019 sv_upgrade((SV *)cv, SvTYPE(proto));
4025 New(666, CvMUTEXP(cv), 1, perl_mutex);
4026 MUTEX_INIT(CvMUTEXP(cv));
4028 #endif /* USE_THREADS */
4029 CvFILE(cv) = CvFILE(proto);
4030 CvGV(cv) = (GV*)SvREFCNT_inc(CvGV(proto));
4031 CvSTASH(cv) = CvSTASH(proto);
4032 CvROOT(cv) = CvROOT(proto);
4033 CvSTART(cv) = CvSTART(proto);
4035 CvOUTSIDE(cv) = (CV*)SvREFCNT_inc(outside);
4038 sv_setpvn((SV*)cv, SvPVX(proto), SvCUR(proto));
4040 PL_comppad_name = newAV();
4041 for (ix = fname; ix >= 0; ix--)
4042 av_store(PL_comppad_name, ix, SvREFCNT_inc(pname[ix]));
4044 PL_comppad = newAV();
4046 comppadlist = newAV();
4047 AvREAL_off(comppadlist);
4048 av_store(comppadlist, 0, (SV*)PL_comppad_name);
4049 av_store(comppadlist, 1, (SV*)PL_comppad);
4050 CvPADLIST(cv) = comppadlist;
4051 av_fill(PL_comppad, AvFILLp(protopad));
4052 PL_curpad = AvARRAY(PL_comppad);
4054 av = newAV(); /* will be @_ */
4056 av_store(PL_comppad, 0, (SV*)av);
4057 AvFLAGS(av) = AVf_REIFY;
4059 for (ix = fpad; ix > 0; ix--) {
4060 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
4061 if (namesv && namesv != &PL_sv_undef) {
4062 char *name = SvPVX(namesv); /* XXX */
4063 if (SvFLAGS(namesv) & SVf_FAKE) { /* lexical from outside? */
4064 I32 off = pad_findlex(name, ix, SvIVX(namesv),
4065 CvOUTSIDE(cv), cxstack_ix, 0, 0);
4067 PL_curpad[ix] = SvREFCNT_inc(ppad[ix]);
4069 Perl_croak(aTHX_ "panic: cv_clone: %s", name);
4071 else { /* our own lexical */
4074 /* anon code -- we'll come back for it */
4075 sv = SvREFCNT_inc(ppad[ix]);
4077 else if (*name == '@')
4079 else if (*name == '%')
4088 else if (IS_PADGV(ppad[ix])) {
4089 PL_curpad[ix] = SvREFCNT_inc(ppad[ix]);
4092 SV* sv = NEWSV(0,0);
4098 /* Now that vars are all in place, clone nested closures. */
4100 for (ix = fpad; ix > 0; ix--) {
4101 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
4103 && namesv != &PL_sv_undef
4104 && !(SvFLAGS(namesv) & SVf_FAKE)
4105 && *SvPVX(namesv) == '&'
4106 && CvCLONE(ppad[ix]))
4108 CV *kid = cv_clone2((CV*)ppad[ix], cv);
4109 SvREFCNT_dec(ppad[ix]);
4112 PL_curpad[ix] = (SV*)kid;
4116 #ifdef DEBUG_CLOSURES
4117 PerlIO_printf(Perl_debug_log, "Cloned inside:\n");
4119 PerlIO_printf(Perl_debug_log, " from:\n");
4121 PerlIO_printf(Perl_debug_log, " to:\n");
4130 Perl_cv_clone(pTHX_ CV *proto)
4133 MUTEX_LOCK(&PL_cred_mutex); /* XXX create separate mutex */
4134 cv = cv_clone2(proto, CvOUTSIDE(proto));
4135 MUTEX_UNLOCK(&PL_cred_mutex); /* XXX create separate mutex */
4140 Perl_cv_ckproto(pTHX_ CV *cv, GV *gv, char *p)
4144 if (((!p != !SvPOK(cv)) || (p && strNE(p, SvPVX(cv)))) && ckWARN_d(WARN_UNSAFE)) {
4145 SV* msg = sv_newmortal();
4149 gv_efullname3(name = sv_newmortal(), gv, Nullch);
4150 sv_setpv(msg, "Prototype mismatch:");
4152 Perl_sv_catpvf(aTHX_ msg, " sub %_", name);
4154 Perl_sv_catpvf(aTHX_ msg, " (%s)", SvPVX(cv));
4155 sv_catpv(msg, " vs ");
4157 Perl_sv_catpvf(aTHX_ msg, "(%s)", p);
4159 sv_catpv(msg, "none");
4160 Perl_warner(aTHX_ WARN_UNSAFE, "%_", msg);
4165 Perl_cv_const_sv(pTHX_ CV *cv)
4167 if (!cv || !SvPOK(cv) || SvCUR(cv))
4169 return op_const_sv(CvSTART(cv), cv);
4173 Perl_op_const_sv(pTHX_ OP *o, CV *cv)
4180 if(o->op_type == OP_LINESEQ && cLISTOPo->op_first)
4181 o = cLISTOPo->op_first->op_sibling;
4183 for (; o; o = o->op_next) {
4184 OPCODE type = o->op_type;
4186 if (sv && o->op_next == o)
4188 if (type == OP_NEXTSTATE || type == OP_NULL || type == OP_PUSHMARK)
4190 if (type == OP_LEAVESUB || type == OP_RETURN)
4194 if (type == OP_CONST)
4196 else if (type == OP_PADSV && cv) {
4197 AV* padav = (AV*)(AvARRAY(CvPADLIST(cv))[1]);
4198 sv = padav ? AvARRAY(padav)[o->op_targ] : Nullsv;
4199 if (!sv || (!SvREADONLY(sv) && SvREFCNT(sv) > 1))
4211 Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
4221 Perl_croak(aTHX_ "\"my sub\" not yet implemented");
4225 Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block)
4227 return Perl_newATTRSUB(aTHX_ floor, o, proto, Nullop, block);
4231 Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
4235 char *name = o ? SvPVx(cSVOPo->op_sv, n_a) : Nullch;
4236 GV *gv = gv_fetchpv(name ? name : "__ANON__",
4237 GV_ADDMULTI | ((block || attrs) ? 0 : GV_NOINIT),
4239 char *ps = proto ? SvPVx(((SVOP*)proto)->op_sv, n_a) : Nullch;
4250 if (SvTYPE(gv) != SVt_PVGV) { /* Maybe prototype now, and had at
4251 maximum a prototype before. */
4252 if (SvTYPE(gv) > SVt_NULL) {
4253 if (!SvPOK((SV*)gv) && !(SvIOK((SV*)gv) && SvIVX((SV*)gv) == -1)
4254 && ckWARN_d(WARN_UNSAFE))
4256 Perl_warner(aTHX_ WARN_UNSAFE, "Runaway prototype");
4258 cv_ckproto((CV*)gv, NULL, ps);
4261 sv_setpv((SV*)gv, ps);
4263 sv_setiv((SV*)gv, -1);
4264 SvREFCNT_dec(PL_compcv);
4265 cv = PL_compcv = NULL;
4266 PL_sub_generation++;
4270 if (!name || GvCVGEN(gv))
4272 else if (cv = GvCV(gv)) {
4273 cv_ckproto(cv, gv, ps);
4274 /* already defined (or promised)? */
4275 if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
4277 bool const_changed = TRUE;
4278 if (!block && !attrs) {
4279 /* just a "sub foo;" when &foo is already defined */
4280 SAVEFREESV(PL_compcv);
4283 /* ahem, death to those who redefine active sort subs */
4284 if (PL_curstackinfo->si_type == PERLSI_SORT && PL_sortcop == CvSTART(cv))
4285 Perl_croak(aTHX_ "Can't redefine active sort subroutine %s", name);
4288 if(const_sv = cv_const_sv(cv))
4289 const_changed = sv_cmp(const_sv, op_const_sv(block, Nullcv));
4290 if ((const_sv && const_changed) || ckWARN(WARN_REDEFINE)
4291 && !(CvGV(cv) && GvSTASH(CvGV(cv))
4292 && HvNAME(GvSTASH(CvGV(cv)))
4293 && strEQ(HvNAME(GvSTASH(CvGV(cv))),
4295 line_t oldline = CopLINE(PL_curcop);
4296 CopLINE_set(PL_curcop, PL_copline);
4297 Perl_warner(aTHX_ WARN_REDEFINE,
4298 const_sv ? "Constant subroutine %s redefined"
4299 : "Subroutine %s redefined", name);
4300 CopLINE_set(PL_curcop, oldline);
4311 /* Need to do a C<use attributes $stash_of_cv,\&cv,@attrs>
4312 * before we clobber PL_compcv.
4316 if (CvGV(cv) && GvSTASH(CvGV(cv)) && HvNAME(GvSTASH(CvGV(cv))))
4317 stash = GvSTASH(CvGV(cv));
4318 else if (CvSTASH(cv) && HvNAME(CvSTASH(cv)))
4319 stash = CvSTASH(cv);
4321 stash = PL_curstash;
4324 /* possibly about to re-define existing subr -- ignore old cv */
4325 rcv = (SV*)PL_compcv;
4326 if (name && GvSTASH(gv) && HvNAME(GvSTASH(gv)))
4327 stash = GvSTASH(gv);
4329 stash = PL_curstash;
4331 apply_attrs(stash, rcv, attrs);
4333 if (cv) { /* must reuse cv if autoloaded */
4335 /* got here with just attrs -- work done, so bug out */
4336 SAVEFREESV(PL_compcv);
4340 CvFLAGS(cv) = CvFLAGS(PL_compcv);
4341 CvOUTSIDE(cv) = CvOUTSIDE(PL_compcv);
4342 CvOUTSIDE(PL_compcv) = 0;
4343 CvPADLIST(cv) = CvPADLIST(PL_compcv);
4344 CvPADLIST(PL_compcv) = 0;
4345 if (SvREFCNT(PL_compcv) > 1) /* XXX Make closures transit through stub. */
4346 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc((SV*)cv);
4347 SvREFCNT_dec(PL_compcv);
4354 PL_sub_generation++;
4357 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4358 CvFILE(cv) = CopFILE(PL_curcop);
4359 CvSTASH(cv) = PL_curstash;
4362 if (!CvMUTEXP(cv)) {
4363 New(666, CvMUTEXP(cv), 1, perl_mutex);
4364 MUTEX_INIT(CvMUTEXP(cv));
4366 #endif /* USE_THREADS */
4369 sv_setpv((SV*)cv, ps);
4371 if (PL_error_count) {
4375 char *s = strrchr(name, ':');
4377 if (strEQ(s, "BEGIN")) {
4379 "BEGIN not safe after errors--compilation aborted";
4380 if (PL_in_eval & EVAL_KEEPERR)
4381 Perl_croak(aTHX_ not_safe);
4383 /* force display of errors found but not reported */
4384 sv_catpv(ERRSV, not_safe);
4385 Perl_croak(aTHX_ "%s", SvPVx(ERRSV, n_a));
4392 PL_copline = NOLINE;
4397 if (AvFILLp(PL_comppad_name) < AvFILLp(PL_comppad))
4398 av_store(PL_comppad_name, AvFILLp(PL_comppad), Nullsv);
4401 SV **namep = AvARRAY(PL_comppad_name);
4402 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4405 if (SvIMMORTAL(PL_curpad[ix]) || IS_PADGV(PL_curpad[ix]))
4408 * The only things that a clonable function needs in its
4409 * pad are references to outer lexicals and anonymous subs.
4410 * The rest are created anew during cloning.
4412 if (!((namesv = namep[ix]) != Nullsv &&
4413 namesv != &PL_sv_undef &&
4415 *SvPVX(namesv) == '&')))
4417 SvREFCNT_dec(PL_curpad[ix]);
4418 PL_curpad[ix] = Nullsv;
4423 AV *av = newAV(); /* Will be @_ */
4425 av_store(PL_comppad, 0, (SV*)av);
4426 AvFLAGS(av) = AVf_REIFY;
4428 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4429 if (SvIMMORTAL(PL_curpad[ix]) || IS_PADGV(PL_curpad[ix]))
4431 if (!SvPADMY(PL_curpad[ix]))
4432 SvPADTMP_on(PL_curpad[ix]);
4437 CvROOT(cv) = newUNOP(OP_LEAVESUBLV, 0, scalarseq(block));
4440 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
4442 CvROOT(cv)->op_private |= OPpREFCOUNTED;
4443 OpREFCNT_set(CvROOT(cv), 1);
4444 CvSTART(cv) = LINKLIST(CvROOT(cv));
4445 CvROOT(cv)->op_next = 0;
4451 if (PERLDB_SUBLINE && PL_curstash != PL_debstash) {
4452 SV *sv = NEWSV(0,0);
4453 SV *tmpstr = sv_newmortal();
4454 GV *db_postponed = gv_fetchpv("DB::postponed", GV_ADDMULTI, SVt_PVHV);
4458 Perl_sv_setpvf(aTHX_ sv, "%_:%ld-%ld",
4459 CopFILESV(PL_curcop),
4460 (long)PL_subline, (long)CopLINE(PL_curcop));
4461 gv_efullname3(tmpstr, gv, Nullch);
4462 hv_store(GvHV(PL_DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
4463 hv = GvHVn(db_postponed);
4464 if (HvFILL(hv) > 0 && hv_exists(hv, SvPVX(tmpstr), SvCUR(tmpstr))
4465 && (cv = GvCV(db_postponed))) {
4470 call_sv((SV*)cv, G_DISCARD);
4474 if ((s = strrchr(name,':')))
4478 if (strEQ(s, "BEGIN")) {
4479 I32 oldscope = PL_scopestack_ix;
4481 SAVECOPFILE(&PL_compiling);
4482 SAVECOPLINE(&PL_compiling);
4484 sv_setsv(PL_rs, PL_nrs);
4487 PL_beginav = newAV();
4488 DEBUG_x( dump_sub(gv) );
4489 av_push(PL_beginav, (SV *)cv);
4491 call_list(oldscope, PL_beginav);
4493 PL_curcop = &PL_compiling;
4494 PL_compiling.op_private = PL_hints;
4497 else if (strEQ(s, "END") && !PL_error_count) {
4500 av_unshift(PL_endav, 1);
4501 av_store(PL_endav, 0, (SV *)cv);
4504 else if (strEQ(s, "STOP") && !PL_error_count) {
4506 PL_stopav = newAV();
4507 av_unshift(PL_stopav, 1);
4508 av_store(PL_stopav, 0, (SV *)cv);
4511 else if (strEQ(s, "INIT") && !PL_error_count) {
4513 PL_initav = newAV();
4514 av_push(PL_initav, SvREFCNT_inc(cv));
4520 PL_copline = NOLINE;
4525 /* XXX unsafe for threads if eval_owner isn't held */
4527 Perl_newCONSTSUB(pTHX_ HV *stash, char *name, SV *sv)
4532 SAVECOPLINE(PL_curcop);
4535 CopLINE_set(PL_curcop, PL_copline);
4536 PL_hints &= ~HINT_BLOCK_SCOPE;
4539 SAVESPTR(PL_curstash);
4540 SAVECOPSTASH(PL_curcop);
4541 PL_curstash = stash;
4543 CopSTASHPV(PL_curcop) = stash ? HvNAME(stash) : Nullch;
4545 CopSTASH(PL_curcop) = stash;
4550 start_subparse(FALSE, 0),
4551 newSVOP(OP_CONST, 0, newSVpv(name,0)),
4552 newSVOP(OP_CONST, 0, &PL_sv_no), /* SvPV(&PL_sv_no) == "" -- GMB */
4554 newSTATEOP(0, Nullch, newSVOP(OP_CONST, 0, sv))
4561 Perl_newXS(pTHX_ char *name, XSUBADDR_t subaddr, char *filename)
4564 GV *gv = gv_fetchpv(name ? name : "__ANON__", GV_ADDMULTI, SVt_PVCV);
4567 if (cv = (name ? GvCV(gv) : Nullcv)) {
4569 /* just a cached method */
4573 else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
4574 /* already defined (or promised) */
4575 if (ckWARN(WARN_REDEFINE) && !(CvGV(cv) && GvSTASH(CvGV(cv))
4576 && HvNAME(GvSTASH(CvGV(cv)))
4577 && strEQ(HvNAME(GvSTASH(CvGV(cv))), "autouse"))) {
4578 line_t oldline = CopLINE(PL_curcop);
4579 if (PL_copline != NOLINE)
4580 CopLINE_set(PL_curcop, PL_copline);
4581 Perl_warner(aTHX_ WARN_REDEFINE, "Subroutine %s redefined",name);
4582 CopLINE_set(PL_curcop, oldline);
4589 if (cv) /* must reuse cv if autoloaded */
4592 cv = (CV*)NEWSV(1105,0);
4593 sv_upgrade((SV *)cv, SVt_PVCV);
4597 PL_sub_generation++;
4600 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4602 New(666, CvMUTEXP(cv), 1, perl_mutex);
4603 MUTEX_INIT(CvMUTEXP(cv));
4605 #endif /* USE_THREADS */
4606 (void)gv_fetchfile(filename);
4607 CvFILE(cv) = filename; /* NOTE: not copied, as it is expected to be
4608 an external constant string */
4609 CvXSUB(cv) = subaddr;
4612 char *s = strrchr(name,':');
4617 if (strEQ(s, "BEGIN")) {
4619 PL_beginav = newAV();
4620 av_push(PL_beginav, (SV *)cv);
4623 else if (strEQ(s, "END")) {
4626 av_unshift(PL_endav, 1);
4627 av_store(PL_endav, 0, (SV *)cv);
4630 else if (strEQ(s, "STOP")) {
4632 PL_stopav = newAV();
4633 av_unshift(PL_stopav, 1);
4634 av_store(PL_stopav, 0, (SV *)cv);
4637 else if (strEQ(s, "INIT")) {
4639 PL_initav = newAV();
4640 av_push(PL_initav, (SV *)cv);
4651 Perl_newFORM(pTHX_ I32 floor, OP *o, OP *block)
4661 name = SvPVx(cSVOPo->op_sv, n_a);
4664 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
4666 if (cv = GvFORM(gv)) {
4667 if (ckWARN(WARN_REDEFINE)) {
4668 line_t oldline = CopLINE(PL_curcop);
4670 CopLINE_set(PL_curcop, PL_copline);
4671 Perl_warner(aTHX_ WARN_REDEFINE, "Format %s redefined",name);
4672 CopLINE_set(PL_curcop, oldline);
4678 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4679 CvFILE(cv) = CopFILE(PL_curcop);
4681 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4682 if (!SvPADMY(PL_curpad[ix]) && !SvIMMORTAL(PL_curpad[ix]))
4683 SvPADTMP_on(PL_curpad[ix]);
4686 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
4687 CvROOT(cv)->op_private |= OPpREFCOUNTED;
4688 OpREFCNT_set(CvROOT(cv), 1);
4689 CvSTART(cv) = LINKLIST(CvROOT(cv));
4690 CvROOT(cv)->op_next = 0;
4693 PL_copline = NOLINE;
4698 Perl_newANONLIST(pTHX_ OP *o)
4700 return newUNOP(OP_REFGEN, 0,
4701 mod(list(convert(OP_ANONLIST, 0, o)), OP_REFGEN));
4705 Perl_newANONHASH(pTHX_ OP *o)
4707 return newUNOP(OP_REFGEN, 0,
4708 mod(list(convert(OP_ANONHASH, 0, o)), OP_REFGEN));
4712 Perl_newANONSUB(pTHX_ I32 floor, OP *proto, OP *block)
4714 return newANONATTRSUB(floor, proto, Nullop, block);
4718 Perl_newANONATTRSUB(pTHX_ I32 floor, OP *proto, OP *attrs, OP *block)
4720 return newUNOP(OP_REFGEN, 0,
4721 newSVOP(OP_ANONCODE, 0,
4722 (SV*)newATTRSUB(floor, 0, proto, attrs, block)));
4726 Perl_oopsAV(pTHX_ OP *o)
4728 switch (o->op_type) {
4730 o->op_type = OP_PADAV;
4731 o->op_ppaddr = PL_ppaddr[OP_PADAV];
4732 return ref(o, OP_RV2AV);
4735 o->op_type = OP_RV2AV;
4736 o->op_ppaddr = PL_ppaddr[OP_RV2AV];
4741 if (ckWARN_d(WARN_INTERNAL))
4742 Perl_warner(aTHX_ WARN_INTERNAL, "oops: oopsAV");
4749 Perl_oopsHV(pTHX_ OP *o)
4753 switch (o->op_type) {
4756 o->op_type = OP_PADHV;
4757 o->op_ppaddr = PL_ppaddr[OP_PADHV];
4758 return ref(o, OP_RV2HV);
4762 o->op_type = OP_RV2HV;
4763 o->op_ppaddr = PL_ppaddr[OP_RV2HV];
4768 if (ckWARN_d(WARN_INTERNAL))
4769 Perl_warner(aTHX_ WARN_INTERNAL, "oops: oopsHV");
4776 Perl_newAVREF(pTHX_ OP *o)
4778 if (o->op_type == OP_PADANY) {
4779 o->op_type = OP_PADAV;
4780 o->op_ppaddr = PL_ppaddr[OP_PADAV];
4783 return newUNOP(OP_RV2AV, 0, scalar(o));
4787 Perl_newGVREF(pTHX_ I32 type, OP *o)
4789 if (type == OP_MAPSTART || type == OP_GREPSTART || type == OP_SORT)
4790 return newUNOP(OP_NULL, 0, o);
4791 return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
4795 Perl_newHVREF(pTHX_ OP *o)
4797 if (o->op_type == OP_PADANY) {
4798 o->op_type = OP_PADHV;
4799 o->op_ppaddr = PL_ppaddr[OP_PADHV];
4802 return newUNOP(OP_RV2HV, 0, scalar(o));
4806 Perl_oopsCV(pTHX_ OP *o)
4808 Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
4814 Perl_newCVREF(pTHX_ I32 flags, OP *o)
4816 return newUNOP(OP_RV2CV, flags, scalar(o));
4820 Perl_newSVREF(pTHX_ OP *o)
4822 if (o->op_type == OP_PADANY) {
4823 o->op_type = OP_PADSV;
4824 o->op_ppaddr = PL_ppaddr[OP_PADSV];
4827 else if (o->op_type == OP_THREADSV && !(o->op_flags & OPpDONE_SVREF)) {
4828 o->op_flags |= OPpDONE_SVREF;
4831 return newUNOP(OP_RV2SV, 0, scalar(o));
4834 /* Check routines. */
4837 Perl_ck_anoncode(pTHX_ OP *o)
4842 name = NEWSV(1106,0);
4843 sv_upgrade(name, SVt_PVNV);
4844 sv_setpvn(name, "&", 1);
4847 ix = pad_alloc(o->op_type, SVs_PADMY);
4848 av_store(PL_comppad_name, ix, name);
4849 av_store(PL_comppad, ix, cSVOPo->op_sv);
4850 SvPADMY_on(cSVOPo->op_sv);
4851 cSVOPo->op_sv = Nullsv;
4852 cSVOPo->op_targ = ix;
4857 Perl_ck_bitop(pTHX_ OP *o)
4859 o->op_private = PL_hints;
4864 Perl_ck_concat(pTHX_ OP *o)
4866 if (cUNOPo->op_first->op_type == OP_CONCAT)
4867 o->op_flags |= OPf_STACKED;
4872 Perl_ck_spair(pTHX_ OP *o)
4874 if (o->op_flags & OPf_KIDS) {
4877 OPCODE type = o->op_type;
4878 o = modkids(ck_fun(o), type);
4879 kid = cUNOPo->op_first;
4880 newop = kUNOP->op_first->op_sibling;
4882 (newop->op_sibling ||
4883 !(PL_opargs[newop->op_type] & OA_RETSCALAR) ||
4884 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
4885 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
4889 op_free(kUNOP->op_first);
4890 kUNOP->op_first = newop;
4892 o->op_ppaddr = PL_ppaddr[++o->op_type];
4897 Perl_ck_delete(pTHX_ OP *o)
4901 if (o->op_flags & OPf_KIDS) {
4902 OP *kid = cUNOPo->op_first;
4903 if (kid->op_type == OP_HSLICE)
4904 o->op_private |= OPpSLICE;
4905 else if (kid->op_type != OP_HELEM)
4906 Perl_croak(aTHX_ "%s argument is not a HASH element or slice",
4907 PL_op_desc[o->op_type]);
4914 Perl_ck_eof(pTHX_ OP *o)
4916 I32 type = o->op_type;
4918 if (o->op_flags & OPf_KIDS) {
4919 if (cLISTOPo->op_first->op_type == OP_STUB) {
4921 o = newUNOP(type, OPf_SPECIAL,
4922 newGVOP(OP_GV, 0, gv_fetchpv("main::ARGV", TRUE, SVt_PVAV)));
4930 Perl_ck_eval(pTHX_ OP *o)
4932 PL_hints |= HINT_BLOCK_SCOPE;
4933 if (o->op_flags & OPf_KIDS) {
4934 SVOP *kid = (SVOP*)cUNOPo->op_first;
4937 o->op_flags &= ~OPf_KIDS;
4940 else if (kid->op_type == OP_LINESEQ) {
4943 kid->op_next = o->op_next;
4944 cUNOPo->op_first = 0;
4947 NewOp(1101, enter, 1, LOGOP);
4948 enter->op_type = OP_ENTERTRY;
4949 enter->op_ppaddr = PL_ppaddr[OP_ENTERTRY];
4950 enter->op_private = 0;
4952 /* establish postfix order */
4953 enter->op_next = (OP*)enter;
4955 o = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
4956 o->op_type = OP_LEAVETRY;
4957 o->op_ppaddr = PL_ppaddr[OP_LEAVETRY];
4958 enter->op_other = o;
4966 o = newUNOP(OP_ENTEREVAL, 0, newDEFSVOP());
4968 o->op_targ = (PADOFFSET)PL_hints;
4973 Perl_ck_exec(pTHX_ OP *o)
4976 if (o->op_flags & OPf_STACKED) {
4978 kid = cUNOPo->op_first->op_sibling;
4979 if (kid->op_type == OP_RV2GV)
4988 Perl_ck_exists(pTHX_ OP *o)
4991 if (o->op_flags & OPf_KIDS) {
4992 OP *kid = cUNOPo->op_first;
4993 if (kid->op_type != OP_HELEM)
4994 Perl_croak(aTHX_ "%s argument is not a HASH element", PL_op_desc[o->op_type]);
5002 Perl_ck_gvconst(pTHX_ register OP *o)
5004 o = fold_constants(o);
5005 if (o->op_type == OP_CONST)
5012 Perl_ck_rvconst(pTHX_ register OP *o)
5015 SVOP *kid = (SVOP*)cUNOPo->op_first;
5017 o->op_private |= (PL_hints & HINT_STRICT_REFS);
5018 if (kid->op_type == OP_CONST) {
5022 SV *kidsv = kid->op_sv;
5025 /* Is it a constant from cv_const_sv()? */
5026 if (SvROK(kidsv) && SvREADONLY(kidsv)) {
5027 SV *rsv = SvRV(kidsv);
5028 int svtype = SvTYPE(rsv);
5029 char *badtype = Nullch;
5031 switch (o->op_type) {
5033 if (svtype > SVt_PVMG)
5034 badtype = "a SCALAR";
5037 if (svtype != SVt_PVAV)
5038 badtype = "an ARRAY";
5041 if (svtype != SVt_PVHV) {
5042 if (svtype == SVt_PVAV) { /* pseudohash? */
5043 SV **ksv = av_fetch((AV*)rsv, 0, FALSE);
5044 if (ksv && SvROK(*ksv)
5045 && SvTYPE(SvRV(*ksv)) == SVt_PVHV)
5054 if (svtype != SVt_PVCV)
5059 Perl_croak(aTHX_ "Constant is not %s reference", badtype);
5062 name = SvPV(kidsv, n_a);
5063 if ((PL_hints & HINT_STRICT_REFS) && (kid->op_private & OPpCONST_BARE)) {
5064 char *badthing = Nullch;
5065 switch (o->op_type) {
5067 badthing = "a SCALAR";
5070 badthing = "an ARRAY";
5073 badthing = "a HASH";
5078 "Can't use bareword (\"%s\") as %s ref while \"strict refs\" in use",
5082 * This is a little tricky. We only want to add the symbol if we
5083 * didn't add it in the lexer. Otherwise we get duplicate strict
5084 * warnings. But if we didn't add it in the lexer, we must at
5085 * least pretend like we wanted to add it even if it existed before,
5086 * or we get possible typo warnings. OPpCONST_ENTERED says
5087 * whether the lexer already added THIS instance of this symbol.
5089 iscv = (o->op_type == OP_RV2CV) * 2;
5091 gv = gv_fetchpv(name,
5092 iscv | !(kid->op_private & OPpCONST_ENTERED),
5095 : o->op_type == OP_RV2SV
5097 : o->op_type == OP_RV2AV
5099 : o->op_type == OP_RV2HV
5102 } while (!gv && !(kid->op_private & OPpCONST_ENTERED) && !iscv++);
5104 kid->op_type = OP_GV;
5105 SvREFCNT_dec(kid->op_sv);
5107 /* XXXXXX hack: dependence on sizeof(PADOP) <= sizeof(SVOP) */
5108 kPADOP->op_padix = pad_alloc(OP_GV, SVs_PADTMP);
5110 PL_curpad[kPADOP->op_padix] = SvREFCNT_inc(gv);
5112 kid->op_sv = SvREFCNT_inc(gv);
5114 kid->op_ppaddr = PL_ppaddr[OP_GV];
5121 Perl_ck_ftst(pTHX_ OP *o)
5124 I32 type = o->op_type;
5126 if (o->op_flags & OPf_REF) {
5129 else if (o->op_flags & OPf_KIDS && cUNOPo->op_first->op_type != OP_STUB) {
5130 SVOP *kid = (SVOP*)cUNOPo->op_first;
5132 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
5134 OP *newop = newGVOP(type, OPf_REF,
5135 gv_fetchpv(SvPVx(kid->op_sv, n_a), TRUE, SVt_PVIO));
5142 if (type == OP_FTTTY)
5143 o = newGVOP(type, OPf_REF, gv_fetchpv("main::STDIN", TRUE,
5146 o = newUNOP(type, 0, newDEFSVOP());
5149 if (type == OP_FTTEXT || type == OP_FTBINARY) {
5151 if (PL_hints & HINT_LOCALE)
5152 o->op_private |= OPpLOCALE;
5159 Perl_ck_fun(pTHX_ OP *o)
5166 int type = o->op_type;
5167 register I32 oa = PL_opargs[type] >> OASHIFT;
5169 if (o->op_flags & OPf_STACKED) {
5170 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
5173 return no_fh_allowed(o);
5176 if (o->op_flags & OPf_KIDS) {
5178 tokid = &cLISTOPo->op_first;
5179 kid = cLISTOPo->op_first;
5180 if (kid->op_type == OP_PUSHMARK ||
5181 kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK)
5183 tokid = &kid->op_sibling;
5184 kid = kid->op_sibling;
5186 if (!kid && PL_opargs[type] & OA_DEFGV)
5187 *tokid = kid = newDEFSVOP();
5191 sibl = kid->op_sibling;
5194 /* list seen where single (scalar) arg expected? */
5195 if (numargs == 1 && !(oa >> 4)
5196 && kid->op_type == OP_LIST && type != OP_SCALAR)
5198 return too_many_arguments(o,PL_op_desc[type]);
5211 if (kid->op_type == OP_CONST &&
5212 (kid->op_private & OPpCONST_BARE))
5214 char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
5215 OP *newop = newAVREF(newGVOP(OP_GV, 0,
5216 gv_fetchpv(name, TRUE, SVt_PVAV) ));
5217 if (ckWARN(WARN_SYNTAX))
5218 Perl_warner(aTHX_ WARN_SYNTAX,
5219 "Array @%s missing the @ in argument %"IVdf" of %s()",
5220 name, (IV)numargs, PL_op_desc[type]);
5223 kid->op_sibling = sibl;
5226 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
5227 bad_type(numargs, "array", PL_op_desc[type], kid);
5231 if (kid->op_type == OP_CONST &&
5232 (kid->op_private & OPpCONST_BARE))
5234 char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
5235 OP *newop = newHVREF(newGVOP(OP_GV, 0,
5236 gv_fetchpv(name, TRUE, SVt_PVHV) ));
5237 if (ckWARN(WARN_SYNTAX))
5238 Perl_warner(aTHX_ WARN_SYNTAX,
5239 "Hash %%%s missing the %% in argument %"IVdf" of %s()",
5240 name, (IV)numargs, PL_op_desc[type]);
5243 kid->op_sibling = sibl;
5246 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
5247 bad_type(numargs, "hash", PL_op_desc[type], kid);
5252 OP *newop = newUNOP(OP_NULL, 0, kid);
5253 kid->op_sibling = 0;
5255 newop->op_next = newop;
5257 kid->op_sibling = sibl;
5262 if (kid->op_type != OP_GV && kid->op_type != OP_RV2GV) {
5263 if (kid->op_type == OP_CONST &&
5264 (kid->op_private & OPpCONST_BARE))
5266 OP *newop = newGVOP(OP_GV, 0,
5267 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, n_a), TRUE,
5272 else if (kid->op_type == OP_READLINE) {
5273 /* neophyte patrol: open(<FH>), close(<FH>) etc. */
5274 bad_type(numargs, "HANDLE", PL_op_desc[o->op_type], kid);
5277 I32 flags = OPf_SPECIAL;
5279 /* is this op a FH constructor? */
5280 if (is_handle_constructor(o,numargs)) {
5282 /* Set a flag to tell rv2gv to vivify
5283 * need to "prove" flag does not mean something
5284 * else already - NI-S 1999/05/07
5288 /* Helps with open($array[$n],...)
5289 but is too simplistic - need to do selectively
5294 kid->op_sibling = 0;
5295 kid = newUNOP(OP_RV2GV, flags, scalar(kid));
5297 kid->op_private |= priv;
5300 kid->op_sibling = sibl;
5306 mod(scalar(kid), type);
5310 tokid = &kid->op_sibling;
5311 kid = kid->op_sibling;
5313 o->op_private |= numargs;
5315 return too_many_arguments(o,PL_op_desc[o->op_type]);
5318 else if (PL_opargs[type] & OA_DEFGV) {
5320 return newUNOP(type, 0, newDEFSVOP());
5324 while (oa & OA_OPTIONAL)
5326 if (oa && oa != OA_LIST)
5327 return too_few_arguments(o,PL_op_desc[o->op_type]);
5333 Perl_ck_glob(pTHX_ OP *o)
5337 if ((o->op_flags & OPf_KIDS) && !cLISTOPo->op_first->op_sibling)
5338 append_elem(OP_GLOB, o, newDEFSVOP());
5340 if (!((gv = gv_fetchpv("glob", FALSE, SVt_PVCV)) && GvIMPORTED_CV(gv)))
5341 gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
5343 #if defined(PERL_INTERNAL_GLOB) && !defined(MINIPERL_BUILD)
5344 /* XXX this can be tightened up and made more failsafe. */
5346 OP *modname = newSVOP(OP_CONST, 0, newSVpvn("File::Glob", 10));
5347 modname->op_private |= OPpCONST_BARE;
5349 utilize(1, start_subparse(FALSE, 0), Nullop, modname,
5350 newSVOP(OP_CONST, 0, newSVpvn("globally", 8)));
5351 gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
5354 #endif /* PERL_INTERNAL_GLOB && !MINIPERL_BUILD */
5356 if (gv && GvIMPORTED_CV(gv)) {
5357 append_elem(OP_GLOB, o,
5358 newSVOP(OP_CONST, 0, newSViv(PL_glob_index++)));
5359 o->op_type = OP_LIST;
5360 o->op_ppaddr = PL_ppaddr[OP_LIST];
5361 cLISTOPo->op_first->op_type = OP_PUSHMARK;
5362 cLISTOPo->op_first->op_ppaddr = PL_ppaddr[OP_PUSHMARK];
5363 o = newUNOP(OP_ENTERSUB, OPf_STACKED,
5364 append_elem(OP_LIST, o,
5365 scalar(newUNOP(OP_RV2CV, 0,
5366 newGVOP(OP_GV, 0, gv)))));
5367 o = newUNOP(OP_NULL, 0, ck_subr(o));
5368 o->op_targ = OP_GLOB; /* hint at what it used to be */
5371 gv = newGVgen("main");
5373 append_elem(OP_GLOB, o, newGVOP(OP_GV, 0, gv));
5379 Perl_ck_grep(pTHX_ OP *o)
5383 OPCODE type = o->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
5385 o->op_ppaddr = PL_ppaddr[OP_GREPSTART];
5386 NewOp(1101, gwop, 1, LOGOP);
5388 if (o->op_flags & OPf_STACKED) {
5391 kid = cLISTOPo->op_first->op_sibling;
5392 for (k = cLISTOPo->op_first->op_sibling->op_next; k; k = k->op_next) {
5395 kid->op_next = (OP*)gwop;
5396 o->op_flags &= ~OPf_STACKED;
5398 kid = cLISTOPo->op_first->op_sibling;
5399 if (type == OP_MAPWHILE)
5406 kid = cLISTOPo->op_first->op_sibling;
5407 if (kid->op_type != OP_NULL)
5408 Perl_croak(aTHX_ "panic: ck_grep");
5409 kid = kUNOP->op_first;
5411 gwop->op_type = type;
5412 gwop->op_ppaddr = PL_ppaddr[type];
5413 gwop->op_first = listkids(o);
5414 gwop->op_flags |= OPf_KIDS;
5415 gwop->op_private = 1;
5416 gwop->op_other = LINKLIST(kid);
5417 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
5418 kid->op_next = (OP*)gwop;
5420 kid = cLISTOPo->op_first->op_sibling;
5421 if (!kid || !kid->op_sibling)
5422 return too_few_arguments(o,PL_op_desc[o->op_type]);
5423 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
5424 mod(kid, OP_GREPSTART);
5430 Perl_ck_index(pTHX_ OP *o)
5432 if (o->op_flags & OPf_KIDS) {
5433 OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5435 kid = kid->op_sibling; /* get past "big" */
5436 if (kid && kid->op_type == OP_CONST)
5437 fbm_compile(((SVOP*)kid)->op_sv, 0);
5443 Perl_ck_lengthconst(pTHX_ OP *o)
5445 /* XXX length optimization goes here */
5450 Perl_ck_lfun(pTHX_ OP *o)
5452 OPCODE type = o->op_type;
5453 return modkids(ck_fun(o), type);
5457 Perl_ck_defined(pTHX_ OP *o) /* 19990527 MJD */
5460 if ((o->op_flags & OPf_KIDS) && ckWARN(WARN_DEPRECATED)) {
5461 switch (cUNOPo->op_first->op_type) {
5463 break; /* Globals via GV can be undef */
5465 case OP_AASSIGN: /* Is this a good idea? */
5466 Perl_warner(aTHX_ WARN_DEPRECATED,
5467 "defined(@array) is deprecated");
5468 Perl_warner(aTHX_ WARN_DEPRECATED,
5469 "(Maybe you should just omit the defined()?)\n");
5472 break; /* Globals via GV can be undef */
5474 Perl_warner(aTHX_ WARN_DEPRECATED,
5475 "defined(%hash) is deprecated");
5476 Perl_warner(aTHX_ WARN_DEPRECATED,
5477 "(Maybe you should just omit the defined()?)\n");
5488 Perl_ck_rfun(pTHX_ OP *o)
5490 OPCODE type = o->op_type;
5491 return refkids(ck_fun(o), type);
5495 Perl_ck_listiob(pTHX_ OP *o)
5499 kid = cLISTOPo->op_first;
5502 kid = cLISTOPo->op_first;
5504 if (kid->op_type == OP_PUSHMARK)
5505 kid = kid->op_sibling;
5506 if (kid && o->op_flags & OPf_STACKED)
5507 kid = kid->op_sibling;
5508 else if (kid && !kid->op_sibling) { /* print HANDLE; */
5509 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
5510 o->op_flags |= OPf_STACKED; /* make it a filehandle */
5511 kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
5512 cLISTOPo->op_first->op_sibling = kid;
5513 cLISTOPo->op_last = kid;
5514 kid = kid->op_sibling;
5519 append_elem(o->op_type, o, newDEFSVOP());
5525 if (PL_hints & HINT_LOCALE)
5526 o->op_private |= OPpLOCALE;
5533 Perl_ck_fun_locale(pTHX_ OP *o)
5539 if (PL_hints & HINT_LOCALE)
5540 o->op_private |= OPpLOCALE;
5547 Perl_ck_sassign(pTHX_ OP *o)
5549 OP *kid = cLISTOPo->op_first;
5550 /* has a disposable target? */
5551 if ((PL_opargs[kid->op_type] & OA_TARGLEX)
5552 && !(kid->op_flags & OPf_STACKED))
5554 OP *kkid = kid->op_sibling;
5556 /* Can just relocate the target. */
5557 if (kkid && kkid->op_type == OP_PADSV
5558 && !(kkid->op_private & OPpLVAL_INTRO))
5560 /* Concat has problems if target is equal to right arg. */
5561 if (kid->op_type == OP_CONCAT) {
5562 if (kLISTOP->op_first->op_sibling->op_type == OP_PADSV
5563 && kLISTOP->op_first->op_sibling->op_targ == kkid->op_targ)
5566 else if (kid->op_type == OP_JOIN) {
5567 /* do_join has problems if the arguments coincide with target.
5568 In fact the second argument *can* safely coincide,
5569 but ignore=pessimize this rare occasion. */
5570 OP *arg = kLISTOP->op_first->op_sibling; /* Skip PUSHMARK */
5573 if (arg->op_type == OP_PADSV
5574 && arg->op_targ == kkid->op_targ)
5576 arg = arg->op_sibling;
5579 else if (kid->op_type == OP_QUOTEMETA) {
5580 /* quotemeta has problems if the argument coincides with target. */
5581 if (kLISTOP->op_first->op_type == OP_PADSV
5582 && kLISTOP->op_first->op_targ == kkid->op_targ)
5585 kid->op_targ = kkid->op_targ;
5587 /* Now we do not need PADSV and SASSIGN. */
5588 kid->op_sibling = o->op_sibling; /* NULL */
5589 cLISTOPo->op_first = NULL;
5592 kid->op_private |= OPpTARGET_MY; /* Used for context settings */
5600 Perl_ck_scmp(pTHX_ OP *o)
5604 if (PL_hints & HINT_LOCALE)
5605 o->op_private |= OPpLOCALE;
5612 Perl_ck_match(pTHX_ OP *o)
5614 o->op_private |= OPpRUNTIME;
5619 Perl_ck_method(pTHX_ OP *o)
5621 OP *kid = cUNOPo->op_first;
5622 if (kid->op_type == OP_CONST) {
5623 SV* sv = kSVOP->op_sv;
5624 if (!(strchr(SvPVX(sv), ':') || strchr(SvPVX(sv), '\''))) {
5626 sv_upgrade(sv, SVt_PVIV);
5628 PERL_HASH(SvUVX(sv), SvPVX(sv), SvCUR(sv));
5629 cmop = newSVOP(OP_METHOD_NAMED, 0, sv);
5630 kSVOP->op_sv = Nullsv;
5639 Perl_ck_null(pTHX_ OP *o)
5645 Perl_ck_repeat(pTHX_ OP *o)
5647 if (cBINOPo->op_first->op_flags & OPf_PARENS) {
5648 o->op_private |= OPpREPEAT_DOLIST;
5649 cBINOPo->op_first = force_list(cBINOPo->op_first);
5657 Perl_ck_require(pTHX_ OP *o)
5659 if (o->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
5660 SVOP *kid = (SVOP*)cUNOPo->op_first;
5662 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
5664 for (s = SvPVX(kid->op_sv); *s; s++) {
5665 if (*s == ':' && s[1] == ':') {
5667 Move(s+2, s+1, strlen(s+2)+1, char);
5668 --SvCUR(kid->op_sv);
5671 sv_catpvn(kid->op_sv, ".pm", 3);
5679 Perl_ck_retarget(pTHX_ OP *o)
5681 Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
5688 Perl_ck_select(pTHX_ OP *o)
5691 if (o->op_flags & OPf_KIDS) {
5692 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5693 if (kid && kid->op_sibling) {
5694 o->op_type = OP_SSELECT;
5695 o->op_ppaddr = PL_ppaddr[OP_SSELECT];
5697 return fold_constants(o);
5701 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5702 if (kid && kid->op_type == OP_RV2GV)
5703 kid->op_private &= ~HINT_STRICT_REFS;
5708 Perl_ck_shift(pTHX_ OP *o)
5710 I32 type = o->op_type;
5712 if (!(o->op_flags & OPf_KIDS)) {
5717 if (!CvUNIQUE(PL_compcv)) {
5718 argop = newOP(OP_PADAV, OPf_REF);
5719 argop->op_targ = 0; /* PL_curpad[0] is @_ */
5722 argop = newUNOP(OP_RV2AV, 0,
5723 scalar(newGVOP(OP_GV, 0,
5724 gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
5727 argop = newUNOP(OP_RV2AV, 0,
5728 scalar(newGVOP(OP_GV, 0, !CvUNIQUE(PL_compcv) ?
5729 PL_defgv : gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
5730 #endif /* USE_THREADS */
5731 return newUNOP(type, 0, scalar(argop));
5733 return scalar(modkids(ck_fun(o), type));
5737 Perl_ck_sort(pTHX_ OP *o)
5741 if (PL_hints & HINT_LOCALE)
5742 o->op_private |= OPpLOCALE;
5745 if (o->op_type == OP_SORT && o->op_flags & OPf_STACKED)
5747 if (o->op_flags & OPf_STACKED) { /* may have been cleared */
5748 OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5750 kid = kUNOP->op_first; /* get past null */
5752 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
5754 if (kid->op_type == OP_SCOPE) {
5758 else if (kid->op_type == OP_LEAVE) {
5759 if (o->op_type == OP_SORT) {
5760 null(kid); /* wipe out leave */
5763 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
5764 if (k->op_next == kid)
5769 kid->op_next = 0; /* just disconnect the leave */
5770 k = kLISTOP->op_first;
5774 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5775 if (o->op_type == OP_SORT)
5779 o->op_flags |= OPf_SPECIAL;
5781 else if (kid->op_type == OP_RV2SV || kid->op_type == OP_PADSV)
5782 null(cLISTOPo->op_first->op_sibling);
5789 S_simplify_sort(pTHX_ OP *o)
5792 register OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5796 if (!(o->op_flags & OPf_STACKED))
5798 GvMULTI_on(gv_fetchpv("a", TRUE, SVt_PV));
5799 GvMULTI_on(gv_fetchpv("b", TRUE, SVt_PV));
5800 kid = kUNOP->op_first; /* get past null */
5801 if (kid->op_type != OP_SCOPE)
5803 kid = kLISTOP->op_last; /* get past scope */
5804 switch(kid->op_type) {
5812 k = kid; /* remember this node*/
5813 if (kBINOP->op_first->op_type != OP_RV2SV)
5815 kid = kBINOP->op_first; /* get past cmp */
5816 if (kUNOP->op_first->op_type != OP_GV)
5818 kid = kUNOP->op_first; /* get past rv2sv */
5820 if (GvSTASH(gv) != PL_curstash)
5822 if (strEQ(GvNAME(gv), "a"))
5824 else if(strEQ(GvNAME(gv), "b"))
5828 kid = k; /* back to cmp */
5829 if (kBINOP->op_last->op_type != OP_RV2SV)
5831 kid = kBINOP->op_last; /* down to 2nd arg */
5832 if (kUNOP->op_first->op_type != OP_GV)
5834 kid = kUNOP->op_first; /* get past rv2sv */
5836 if (GvSTASH(gv) != PL_curstash
5838 ? strNE(GvNAME(gv), "a")
5839 : strNE(GvNAME(gv), "b")))
5841 o->op_flags &= ~(OPf_STACKED | OPf_SPECIAL);
5843 o->op_private |= OPpSORT_REVERSE;
5844 if (k->op_type == OP_NCMP)
5845 o->op_private |= OPpSORT_NUMERIC;
5846 if (k->op_type == OP_I_NCMP)
5847 o->op_private |= OPpSORT_NUMERIC | OPpSORT_INTEGER;
5848 kid = cLISTOPo->op_first->op_sibling;
5849 cLISTOPo->op_first->op_sibling = kid->op_sibling; /* bypass old block */
5850 op_free(kid); /* then delete it */
5851 cLISTOPo->op_children--;
5855 Perl_ck_split(pTHX_ OP *o)
5859 if (o->op_flags & OPf_STACKED)
5860 return no_fh_allowed(o);
5862 kid = cLISTOPo->op_first;
5863 if (kid->op_type != OP_NULL)
5864 Perl_croak(aTHX_ "panic: ck_split");
5865 kid = kid->op_sibling;
5866 op_free(cLISTOPo->op_first);
5867 cLISTOPo->op_first = kid;
5869 cLISTOPo->op_first = kid = newSVOP(OP_CONST, 0, newSVpvn(" ", 1));
5870 cLISTOPo->op_last = kid; /* There was only one element previously */
5873 if (kid->op_type != OP_MATCH) {
5874 OP *sibl = kid->op_sibling;
5875 kid->op_sibling = 0;
5876 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
5877 if (cLISTOPo->op_first == cLISTOPo->op_last)
5878 cLISTOPo->op_last = kid;
5879 cLISTOPo->op_first = kid;
5880 kid->op_sibling = sibl;
5883 kid->op_type = OP_PUSHRE;
5884 kid->op_ppaddr = PL_ppaddr[OP_PUSHRE];
5887 if (!kid->op_sibling)
5888 append_elem(OP_SPLIT, o, newDEFSVOP());
5890 kid = kid->op_sibling;
5893 if (!kid->op_sibling)
5894 append_elem(OP_SPLIT, o, newSVOP(OP_CONST, 0, newSViv(0)));
5896 kid = kid->op_sibling;
5899 if (kid->op_sibling)
5900 return too_many_arguments(o,PL_op_desc[o->op_type]);
5906 Perl_ck_join(pTHX_ OP *o)
5908 if (ckWARN(WARN_SYNTAX)) {
5909 OP *kid = cLISTOPo->op_first->op_sibling;
5910 if (kid && kid->op_type == OP_MATCH) {
5911 char *pmstr = "STRING";
5912 if (kPMOP->op_pmregexp)
5913 pmstr = kPMOP->op_pmregexp->precomp;
5914 Perl_warner(aTHX_ WARN_SYNTAX,
5915 "/%s/ should probably be written as \"%s\"",
5923 Perl_ck_subr(pTHX_ OP *o)
5926 OP *prev = ((cUNOPo->op_first->op_sibling)
5927 ? cUNOPo : ((UNOP*)cUNOPo->op_first))->op_first;
5928 OP *o2 = prev->op_sibling;
5937 o->op_private |= OPpENTERSUB_HASTARG;
5938 for (cvop = o2; cvop->op_sibling; cvop = cvop->op_sibling) ;
5939 if (cvop->op_type == OP_RV2CV) {
5941 o->op_private |= (cvop->op_private & OPpENTERSUB_AMPER);
5942 null(cvop); /* disable rv2cv */
5943 tmpop = (SVOP*)((UNOP*)cvop)->op_first;
5944 if (tmpop->op_type == OP_GV && !(o->op_private & OPpENTERSUB_AMPER)) {
5945 GV *gv = cGVOPx(tmpop);
5948 tmpop->op_private |= OPpEARLY_CV;
5949 else if (SvPOK(cv)) {
5950 namegv = CvANON(cv) ? gv : CvGV(cv);
5951 proto = SvPV((SV*)cv, n_a);
5955 else if (cvop->op_type == OP_METHOD || cvop->op_type == OP_METHOD_NAMED) {
5956 if (o2->op_type == OP_CONST)
5957 o2->op_private &= ~OPpCONST_STRICT;
5958 else if (o2->op_type == OP_LIST) {
5959 OP *o = ((UNOP*)o2)->op_first->op_sibling;
5960 if (o && o->op_type == OP_CONST)
5961 o->op_private &= ~OPpCONST_STRICT;
5964 o->op_private |= (PL_hints & HINT_STRICT_REFS);
5965 if (PERLDB_SUB && PL_curstash != PL_debstash)
5966 o->op_private |= OPpENTERSUB_DB;
5967 while (o2 != cvop) {
5971 return too_many_arguments(o, gv_ename(namegv));
5989 if (o2->op_type != OP_REFGEN && o2->op_type != OP_UNDEF)
5990 bad_type(arg, "block", gv_ename(namegv), o2);
5993 /* '*' allows any scalar type, including bareword */
5996 if (o2->op_type == OP_RV2GV)
5997 goto wrapref; /* autoconvert GLOB -> GLOBref */
5998 else if (o2->op_type == OP_CONST)
5999 o2->op_private &= ~OPpCONST_STRICT;
6000 else if (o2->op_type == OP_ENTERSUB) {
6001 /* accidental subroutine, revert to bareword */
6002 OP *gvop = ((UNOP*)o2)->op_first;
6003 if (gvop && gvop->op_type == OP_NULL) {
6004 gvop = ((UNOP*)gvop)->op_first;
6006 for (; gvop->op_sibling; gvop = gvop->op_sibling)
6009 (gvop->op_private & OPpENTERSUB_NOPAREN) &&
6010 (gvop = ((UNOP*)gvop)->op_first) &&
6011 gvop->op_type == OP_GV)
6013 GV *gv = cGVOPx(gvop);
6014 OP *sibling = o2->op_sibling;
6015 SV *n = newSVpvn("",0);
6017 gv_fullname3(n, gv, "");
6018 if (SvCUR(n)>6 && strnEQ(SvPVX(n),"main::",6))
6019 sv_chop(n, SvPVX(n)+6);
6020 o2 = newSVOP(OP_CONST, 0, n);
6021 prev->op_sibling = o2;
6022 o2->op_sibling = sibling;
6034 if (o2->op_type != OP_RV2GV)
6035 bad_type(arg, "symbol", gv_ename(namegv), o2);
6038 if (o2->op_type != OP_RV2CV)
6039 bad_type(arg, "sub", gv_ename(namegv), o2);
6042 if (o2->op_type != OP_RV2SV
6043 && o2->op_type != OP_PADSV
6044 && o2->op_type != OP_HELEM
6045 && o2->op_type != OP_AELEM
6046 && o2->op_type != OP_THREADSV)
6048 bad_type(arg, "scalar", gv_ename(namegv), o2);
6052 if (o2->op_type != OP_RV2AV && o2->op_type != OP_PADAV)
6053 bad_type(arg, "array", gv_ename(namegv), o2);
6056 if (o2->op_type != OP_RV2HV && o2->op_type != OP_PADHV)
6057 bad_type(arg, "hash", gv_ename(namegv), o2);
6061 OP* sib = kid->op_sibling;
6062 kid->op_sibling = 0;
6063 o2 = newUNOP(OP_REFGEN, 0, kid);
6064 o2->op_sibling = sib;
6065 prev->op_sibling = o2;
6076 Perl_croak(aTHX_ "Malformed prototype for %s: %s",
6077 gv_ename(namegv), SvPV((SV*)cv, n_a));
6082 mod(o2, OP_ENTERSUB);
6084 o2 = o2->op_sibling;
6086 if (proto && !optional &&
6087 (*proto && *proto != '@' && *proto != '%' && *proto != ';'))
6088 return too_few_arguments(o, gv_ename(namegv));
6093 Perl_ck_svconst(pTHX_ OP *o)
6095 SvREADONLY_on(cSVOPo->op_sv);
6100 Perl_ck_trunc(pTHX_ OP *o)
6102 if (o->op_flags & OPf_KIDS) {
6103 SVOP *kid = (SVOP*)cUNOPo->op_first;
6105 if (kid->op_type == OP_NULL)
6106 kid = (SVOP*)kid->op_sibling;
6107 if (kid && kid->op_type == OP_CONST &&
6108 (kid->op_private & OPpCONST_BARE))
6110 o->op_flags |= OPf_SPECIAL;
6111 kid->op_private &= ~OPpCONST_STRICT;
6117 /* A peephole optimizer. We visit the ops in the order they're to execute. */
6120 Perl_peep(pTHX_ register OP *o)
6123 register OP* oldop = 0;
6125 OP *last_composite = Nullop;
6127 if (!o || o->op_seq)
6131 SAVESPTR(PL_curcop);
6132 for (; o; o = o->op_next) {
6138 switch (o->op_type) {
6142 PL_curcop = ((COP*)o); /* for warnings */
6143 o->op_seq = PL_op_seqmax++;
6144 last_composite = Nullop;
6148 if (cSVOPo->op_private & OPpCONST_STRICT)
6149 no_bareword_allowed(o);
6155 if ( o->op_next && o->op_next->op_type == OP_STRINGIFY
6156 && !(o->op_next->op_private & OPpTARGET_MY) )
6158 o->op_seq = PL_op_seqmax++;
6163 if (o->op_next && o->op_next->op_type == OP_STRINGIFY) {
6164 if (o->op_next->op_private & OPpTARGET_MY) {
6165 if ((o->op_flags & OPf_STACKED) /* chained concats */
6166 || (o->op_type == OP_CONCAT
6167 /* Concat has problems if target is equal to right arg. */
6168 && (((LISTOP*)o)->op_first->op_sibling->op_type
6170 && (((LISTOP*)o)->op_first->op_sibling->op_targ
6171 == o->op_next->op_targ)))
6173 goto ignore_optimization;
6176 o->op_targ = o->op_next->op_targ;
6177 o->op_next->op_targ = 0;
6178 o->op_private |= OPpTARGET_MY;
6183 ignore_optimization:
6184 o->op_seq = PL_op_seqmax++;
6187 if ((o->op_flags & OPf_WANT) != OPf_WANT_LIST) {
6188 o->op_seq = PL_op_seqmax++;
6189 break; /* Scalar stub must produce undef. List stub is noop */
6193 if (o->op_targ == OP_NEXTSTATE
6194 || o->op_targ == OP_DBSTATE
6195 || o->op_targ == OP_SETSTATE)
6197 PL_curcop = ((COP*)o);
6204 if (oldop && o->op_next) {
6205 oldop->op_next = o->op_next;
6208 o->op_seq = PL_op_seqmax++;
6212 if (o->op_next->op_type == OP_RV2SV) {
6213 if (!(o->op_next->op_private & OPpDEREF)) {
6215 o->op_private |= o->op_next->op_private & OPpLVAL_INTRO;
6216 o->op_next = o->op_next->op_next;
6217 o->op_type = OP_GVSV;
6218 o->op_ppaddr = PL_ppaddr[OP_GVSV];
6221 else if (o->op_next->op_type == OP_RV2AV) {
6222 OP* pop = o->op_next->op_next;
6224 if (pop->op_type == OP_CONST &&
6225 (PL_op = pop->op_next) &&
6226 pop->op_next->op_type == OP_AELEM &&
6227 !(pop->op_next->op_private &
6228 (OPpLVAL_INTRO|OPpLVAL_DEFER|OPpDEREF)) &&
6229 (i = SvIV(((SVOP*)pop)->op_sv) - PL_compiling.cop_arybase)
6237 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
6238 o->op_next = pop->op_next->op_next;
6239 o->op_type = OP_AELEMFAST;
6240 o->op_ppaddr = PL_ppaddr[OP_AELEMFAST];
6241 o->op_private = (U8)i;
6246 else if ((o->op_private & OPpEARLY_CV) && ckWARN(WARN_UNSAFE)) {
6248 if (SvTYPE(gv) == SVt_PVGV && GvCV(gv) && SvPVX(GvCV(gv))) {
6249 /* XXX could check prototype here instead of just carping */
6250 SV *sv = sv_newmortal();
6251 gv_efullname3(sv, gv, Nullch);
6252 Perl_warner(aTHX_ WARN_UNSAFE,
6253 "%s() called too early to check prototype",
6258 o->op_seq = PL_op_seqmax++;
6269 o->op_seq = PL_op_seqmax++;
6270 while (cLOGOP->op_other->op_type == OP_NULL)
6271 cLOGOP->op_other = cLOGOP->op_other->op_next;
6272 peep(cLOGOP->op_other);
6276 o->op_seq = PL_op_seqmax++;
6277 peep(cLOOP->op_redoop);
6278 peep(cLOOP->op_nextop);
6279 peep(cLOOP->op_lastop);
6285 o->op_seq = PL_op_seqmax++;
6286 peep(cPMOP->op_pmreplstart);
6290 o->op_seq = PL_op_seqmax++;
6291 if (ckWARN(WARN_SYNTAX) && o->op_next
6292 && o->op_next->op_type == OP_NEXTSTATE) {
6293 if (o->op_next->op_sibling &&
6294 o->op_next->op_sibling->op_type != OP_EXIT &&
6295 o->op_next->op_sibling->op_type != OP_WARN &&
6296 o->op_next->op_sibling->op_type != OP_DIE) {
6297 line_t oldline = CopLINE(PL_curcop);
6299 CopLINE_set(PL_curcop, CopLINE((COP*)o->op_next));
6300 Perl_warner(aTHX_ WARN_SYNTAX, "Statement unlikely to be reached");
6301 Perl_warner(aTHX_ WARN_SYNTAX, "(Maybe you meant system() when you said exec()?)\n");
6302 CopLINE_set(PL_curcop, oldline);
6316 if ((o->op_private & (OPpLVAL_INTRO))
6317 || ((BINOP*)o)->op_last->op_type != OP_CONST)
6319 rop = (UNOP*)((BINOP*)o)->op_first;
6320 if (rop->op_type != OP_RV2HV || rop->op_first->op_type != OP_PADSV)
6322 lexname = *av_fetch(PL_comppad_name, rop->op_first->op_targ, TRUE);
6323 if (!SvOBJECT(lexname))
6325 fields = (GV**)hv_fetch(SvSTASH(lexname), "FIELDS", 6, FALSE);
6326 if (!fields || !GvHV(*fields))
6328 svp = &((SVOP*)((BINOP*)o)->op_last)->op_sv;
6329 key = SvPV(*svp, keylen);
6330 indsvp = hv_fetch(GvHV(*fields), key, keylen, FALSE);
6332 Perl_croak(aTHX_ "No such pseudo-hash field \"%s\" in variable %s of type %s",
6333 key, SvPV(lexname, n_a), HvNAME(SvSTASH(lexname)));
6335 ind = SvIV(*indsvp);
6337 Perl_croak(aTHX_ "Bad index while coercing array into hash");
6338 rop->op_type = OP_RV2AV;
6339 rop->op_ppaddr = PL_ppaddr[OP_RV2AV];
6340 o->op_type = OP_AELEM;
6341 o->op_ppaddr = PL_ppaddr[OP_AELEM];
6343 *svp = newSViv(ind);
6349 if (!(o->op_flags & OPf_WANT)
6350 || (o->op_flags & OPf_WANT) == OPf_WANT_LIST)
6354 o->op_seq = PL_op_seqmax++;
6358 if (o->op_next && o->op_next->op_type != OP_LEAVESUBLV) {
6359 o->op_seq = PL_op_seqmax++;
6365 if (last_composite) {
6366 OP *r = last_composite;
6368 while (r->op_sibling)
6371 || (r->op_next->op_type == OP_LIST
6372 && r->op_next->op_next == o))
6374 if (last_composite->op_type == OP_RV2AV)
6375 yyerror("Lvalue subs returning arrays not implemented yet");
6377 yyerror("Lvalue subs returning hashes not implemented yet");
6384 o->op_seq = PL_op_seqmax++;