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_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 */
327 if (PL_debstash && CvSTASH(cv) == PL_debstash) { /* ignore DB'* scope */
328 saweval = i; /* so we know where we were called from */
331 seq = cxstack[saweval].blk_oldcop->cop_seq;
332 return pad_findlex(name, newoff, seq, cv, i-1, saweval,FINDLEX_NOSEARCH);
340 Perl_pad_findmy(pTHX_ char *name)
346 SV **svp = AvARRAY(PL_comppad_name);
347 U32 seq = PL_cop_seqmax;
353 * Special case to get lexical (and hence per-thread) @_.
354 * XXX I need to find out how to tell at parse-time whether use
355 * of @_ should refer to a lexical (from a sub) or defgv (global
356 * scope and maybe weird sub-ish things like formats). See
357 * startsub in perly.y. It's possible that @_ could be lexical
358 * (at least from subs) even in non-threaded perl.
360 if (strEQ(name, "@_"))
361 return 0; /* success. (NOT_IN_PAD indicates failure) */
362 #endif /* USE_THREADS */
364 /* The one we're looking for is probably just before comppad_name_fill. */
365 for (off = AvFILLp(PL_comppad_name); off > 0; off--) {
366 if ((sv = svp[off]) &&
367 sv != &PL_sv_undef &&
370 seq > I_32(SvNVX(sv)))) &&
371 strEQ(SvPVX(sv), name))
373 if (SvIVX(sv) || SvFLAGS(sv) & SVpad_OUR)
374 return (PADOFFSET)off;
375 pendoff = off; /* this pending def. will override import */
379 outside = CvOUTSIDE(PL_compcv);
381 /* Check if if we're compiling an eval'', and adjust seq to be the
382 * eval's seq number. This depends on eval'' having a non-null
383 * CvOUTSIDE() while it is being compiled. The eval'' itself is
384 * identified by CvEVAL being true and CvGV being null. */
385 if (outside && CvEVAL(PL_compcv) && !CvGV(PL_compcv) && cxstack_ix >= 0) {
386 cx = &cxstack[cxstack_ix];
388 seq = cx->blk_oldcop->cop_seq;
391 /* See if it's in a nested scope */
392 off = pad_findlex(name, 0, seq, outside, cxstack_ix, 0, 0);
394 /* If there is a pending local definition, this new alias must die */
396 SvIVX(AvARRAY(PL_comppad_name)[off]) = seq;
397 return off; /* pad_findlex returns 0 for failure...*/
399 return NOT_IN_PAD; /* ...but we return NOT_IN_PAD for failure */
403 Perl_pad_leavemy(pTHX_ I32 fill)
407 SV **svp = AvARRAY(PL_comppad_name);
409 if (PL_min_intro_pending && fill < PL_min_intro_pending) {
410 for (off = PL_max_intro_pending; off >= PL_min_intro_pending; off--) {
411 if ((sv = svp[off]) && sv != &PL_sv_undef && ckWARN_d(WARN_INTERNAL))
412 Perl_warner(aTHX_ WARN_INTERNAL, "%s never introduced", SvPVX(sv));
415 /* "Deintroduce" my variables that are leaving with this scope. */
416 for (off = AvFILLp(PL_comppad_name); off > fill; off--) {
417 if ((sv = svp[off]) && sv != &PL_sv_undef && SvIVX(sv) == PAD_MAX)
418 SvIVX(sv) = PL_cop_seqmax;
423 Perl_pad_alloc(pTHX_ I32 optype, U32 tmptype)
429 if (AvARRAY(PL_comppad) != PL_curpad)
430 Perl_croak(aTHX_ "panic: pad_alloc");
431 if (PL_pad_reset_pending)
433 if (tmptype & SVs_PADMY) {
435 sv = *av_fetch(PL_comppad, AvFILLp(PL_comppad) + 1, TRUE);
436 } while (SvPADBUSY(sv)); /* need a fresh one */
437 retval = AvFILLp(PL_comppad);
440 SV **names = AvARRAY(PL_comppad_name);
441 SSize_t names_fill = AvFILLp(PL_comppad_name);
444 * "foreach" index vars temporarily become aliases to non-"my"
445 * values. Thus we must skip, not just pad values that are
446 * marked as current pad values, but also those with names.
448 if (++PL_padix <= names_fill &&
449 (sv = names[PL_padix]) && sv != &PL_sv_undef)
451 sv = *av_fetch(PL_comppad, PL_padix, TRUE);
452 if (!(SvFLAGS(sv) & (SVs_PADTMP|SVs_PADMY)) && !IS_PADGV(sv))
457 SvFLAGS(sv) |= tmptype;
458 PL_curpad = AvARRAY(PL_comppad);
460 DEBUG_X(PerlIO_printf(Perl_debug_log,
461 "0x%"UVxf" Pad 0x%"UVxf" alloc %ld for %s\n",
462 PTR2UV(thr), PTR2UV(PL_curpad),
463 (long) retval, PL_op_name[optype]));
465 DEBUG_X(PerlIO_printf(Perl_debug_log,
466 "Pad 0x%"UVxf" alloc %ld for %s\n",
468 (long) retval, PL_op_name[optype]));
469 #endif /* USE_THREADS */
470 return (PADOFFSET)retval;
474 Perl_pad_sv(pTHX_ PADOFFSET po)
478 DEBUG_X(PerlIO_printf(Perl_debug_log,
479 "0x%"UVxf" Pad 0x%"UVxf" sv %"IVdf"\n",
480 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
483 Perl_croak(aTHX_ "panic: pad_sv po");
484 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" sv %"IVdf"\n",
485 PTR2UV(PL_curpad), (IV)po));
486 #endif /* USE_THREADS */
487 return PL_curpad[po]; /* eventually we'll turn this into a macro */
491 Perl_pad_free(pTHX_ PADOFFSET po)
496 if (AvARRAY(PL_comppad) != PL_curpad)
497 Perl_croak(aTHX_ "panic: pad_free curpad");
499 Perl_croak(aTHX_ "panic: pad_free po");
501 DEBUG_X(PerlIO_printf(Perl_debug_log,
502 "0x%"UVxf" Pad 0x%"UVxf" free %"IVdf"\n",
503 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
505 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" free %"IVdf"\n",
506 PTR2UV(PL_curpad), (IV)po));
507 #endif /* USE_THREADS */
508 if (PL_curpad[po] && PL_curpad[po] != &PL_sv_undef)
509 SvPADTMP_off(PL_curpad[po]);
510 if ((I32)po < PL_padix)
515 Perl_pad_swipe(pTHX_ PADOFFSET po)
518 if (AvARRAY(PL_comppad) != PL_curpad)
519 Perl_croak(aTHX_ "panic: pad_swipe curpad");
521 Perl_croak(aTHX_ "panic: pad_swipe po");
523 DEBUG_X(PerlIO_printf(Perl_debug_log,
524 "0x%"UVxf" Pad 0x%"UVxf" swipe %"IVdf"\n",
525 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
527 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" swipe %"IVdf"\n",
528 PTR2UV(PL_curpad), (IV)po));
529 #endif /* USE_THREADS */
530 SvPADTMP_off(PL_curpad[po]);
531 PL_curpad[po] = NEWSV(1107,0);
532 SvPADTMP_on(PL_curpad[po]);
533 if ((I32)po < PL_padix)
537 /* XXX pad_reset() is currently disabled because it results in serious bugs.
538 * It causes pad temp TARGs to be shared between OPs. Since TARGs are pushed
539 * on the stack by OPs that use them, there are several ways to get an alias
540 * to a shared TARG. Such an alias will change randomly and unpredictably.
541 * We avoid doing this until we can think of a Better Way.
546 #ifdef USE_BROKEN_PAD_RESET
550 if (AvARRAY(PL_comppad) != PL_curpad)
551 Perl_croak(aTHX_ "panic: pad_reset curpad");
553 DEBUG_X(PerlIO_printf(Perl_debug_log,
554 "0x%"UVxf" Pad 0x%"UVxf" reset\n",
555 PTR2UV(thr), PTR2UV(PL_curpad)));
557 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" reset\n",
559 #endif /* USE_THREADS */
560 if (!PL_tainting) { /* Can't mix tainted and non-tainted temporaries. */
561 for (po = AvMAX(PL_comppad); po > PL_padix_floor; po--) {
562 if (PL_curpad[po] && !SvIMMORTAL(PL_curpad[po]))
563 SvPADTMP_off(PL_curpad[po]);
565 PL_padix = PL_padix_floor;
568 PL_pad_reset_pending = FALSE;
572 /* find_threadsv is not reentrant */
574 Perl_find_threadsv(pTHX_ const char *name)
580 /* We currently only handle names of a single character */
581 p = strchr(PL_threadsv_names, *name);
584 key = p - PL_threadsv_names;
585 MUTEX_LOCK(&thr->mutex);
586 svp = av_fetch(thr->threadsv, key, FALSE);
588 MUTEX_UNLOCK(&thr->mutex);
590 SV *sv = NEWSV(0, 0);
591 av_store(thr->threadsv, key, sv);
592 thr->threadsvp = AvARRAY(thr->threadsv);
593 MUTEX_UNLOCK(&thr->mutex);
595 * Some magic variables used to be automagically initialised
596 * in gv_fetchpv. Those which are now per-thread magicals get
597 * initialised here instead.
603 sv_setpv(sv, "\034");
604 sv_magic(sv, 0, 0, name, 1);
609 PL_sawampersand = TRUE;
623 /* XXX %! tied to Errno.pm needs to be added here.
624 * See gv_fetchpv(). */
628 sv_magic(sv, 0, 0, name, 1);
630 DEBUG_S(PerlIO_printf(Perl_error_log,
631 "find_threadsv: new SV %p for $%s%c\n",
632 sv, (*name < 32) ? "^" : "",
633 (*name < 32) ? toCTRL(*name) : *name));
637 #endif /* USE_THREADS */
642 Perl_op_free(pTHX_ OP *o)
644 register OP *kid, *nextkid;
647 if (!o || o->op_seq == (U16)-1)
650 if (o->op_private & OPpREFCOUNTED) {
651 switch (o->op_type) {
659 if (OpREFCNT_dec(o)) {
663 o->op_targ = 0; /* XXXXXX */
671 if (o->op_flags & OPf_KIDS) {
672 for (kid = cUNOPo->op_first; kid; kid = nextkid) {
673 nextkid = kid->op_sibling; /* Get before next freeing kid */
681 /* COP* is not cleared by op_clear() so that we may track line
682 * numbers etc even after null() */
683 if (type == OP_NEXTSTATE || type == OP_SETSTATE || type == OP_DBSTATE)
688 #ifdef PL_OP_SLAB_ALLOC
689 if ((char *) o == PL_OpPtr)
698 S_op_clear(pTHX_ OP *o)
700 switch (o->op_type) {
701 case OP_NULL: /* Was holding old type, if any. */
702 case OP_ENTEREVAL: /* Was holding hints. */
704 case OP_THREADSV: /* Was holding index into thr->threadsv AV. */
710 if (!(o->op_flags & OPf_SPECIAL))
713 #endif /* USE_THREADS */
715 if (!(o->op_flags & OPf_REF)
716 || (PL_check[o->op_type] != MEMBER_TO_FPTR(Perl_ck_ftst)))
723 if (cPADOPo->op_padix > 0) {
726 pad_swipe(cPADOPo->op_padix);
727 /* No GvIN_PAD_off(gv) here, because other references may still
728 * exist on the pad */
731 cPADOPo->op_padix = 0;
734 SvREFCNT_dec(cSVOPo->op_sv);
735 cSVOPo->op_sv = Nullsv;
739 SvREFCNT_dec(cSVOPo->op_sv);
740 cSVOPo->op_sv = Nullsv;
746 if (o->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
750 if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
751 SvREFCNT_dec(cSVOPo->op_sv);
752 cSVOPo->op_sv = Nullsv;
755 Safefree(cPVOPo->op_pv);
756 cPVOPo->op_pv = Nullch;
760 op_free(cPMOPo->op_pmreplroot);
764 if ((PADOFFSET)cPMOPo->op_pmreplroot) {
766 GV *gv = (GV*)PL_curpad[(PADOFFSET)cPMOPo->op_pmreplroot];
767 pad_swipe((PADOFFSET)cPMOPo->op_pmreplroot);
768 /* No GvIN_PAD_off(gv) here, because other references may still
769 * exist on the pad */
774 SvREFCNT_dec((SV*)cPMOPo->op_pmreplroot);
780 cPMOPo->op_pmreplroot = Nullop;
781 ReREFCNT_dec(cPMOPo->op_pmregexp);
782 cPMOPo->op_pmregexp = (REGEXP*)NULL;
786 if (o->op_targ > 0) {
787 pad_free(o->op_targ);
793 S_cop_free(pTHX_ COP* cop)
795 Safefree(cop->cop_label);
797 Safefree(CopFILE(cop)); /* XXXXX share in a pvtable? */
798 Safefree(CopSTASHPV(cop)); /* XXXXX share in a pvtable? */
800 /* NOTE: COP.cop_stash is not refcounted */
801 SvREFCNT_dec(CopFILEGV(cop));
803 if (! specialWARN(cop->cop_warnings))
804 SvREFCNT_dec(cop->cop_warnings);
810 if (o->op_type == OP_NULL)
813 o->op_targ = o->op_type;
814 o->op_type = OP_NULL;
815 o->op_ppaddr = PL_ppaddr[OP_NULL];
818 /* Contextualizers */
820 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
823 Perl_linklist(pTHX_ OP *o)
830 /* establish postfix order */
831 if (cUNOPo->op_first) {
832 o->op_next = LINKLIST(cUNOPo->op_first);
833 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
835 kid->op_next = LINKLIST(kid->op_sibling);
847 Perl_scalarkids(pTHX_ OP *o)
850 if (o && o->op_flags & OPf_KIDS) {
851 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
858 S_scalarboolean(pTHX_ OP *o)
860 if (o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST) {
862 if (ckWARN(WARN_SYNTAX)) {
863 line_t oldline = CopLINE(PL_curcop);
865 if (PL_copline != NOLINE)
866 CopLINE_set(PL_curcop, PL_copline);
867 Perl_warner(aTHX_ WARN_SYNTAX, "Found = in conditional, should be ==");
868 CopLINE_set(PL_curcop, oldline);
875 Perl_scalar(pTHX_ OP *o)
879 /* assumes no premature commitment */
880 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
881 || o->op_type == OP_RETURN)
886 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_SCALAR;
888 switch (o->op_type) {
890 if (o->op_private & OPpREPEAT_DOLIST)
891 null(((LISTOP*)cBINOPo->op_first)->op_first);
892 scalar(cBINOPo->op_first);
897 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
901 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
902 if (!kPMOP->op_pmreplroot)
903 deprecate("implicit split to @_");
911 if (o->op_flags & OPf_KIDS) {
912 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
918 kid = cLISTOPo->op_first;
920 while (kid = kid->op_sibling) {
926 WITH_THR(PL_curcop = &PL_compiling);
931 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
937 WITH_THR(PL_curcop = &PL_compiling);
944 Perl_scalarvoid(pTHX_ OP *o)
951 if (o->op_type == OP_NEXTSTATE
952 || o->op_type == OP_SETSTATE
953 || o->op_type == OP_DBSTATE
954 || (o->op_type == OP_NULL && (o->op_targ == OP_NEXTSTATE
955 || o->op_targ == OP_SETSTATE
956 || o->op_targ == OP_DBSTATE)))
959 PL_curcop = (COP*)o; /* for warning below */
962 /* assumes no premature commitment */
963 want = o->op_flags & OPf_WANT;
964 if ((want && want != OPf_WANT_SCALAR) || PL_error_count
965 || o->op_type == OP_RETURN)
970 if ((o->op_private & OPpTARGET_MY)
971 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
973 return scalar(o); /* As if inside SASSIGN */
976 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_VOID;
978 switch (o->op_type) {
980 if (!(PL_opargs[o->op_type] & OA_FOLDCONST))
984 if (o->op_flags & OPf_STACKED)
988 if (o->op_private == 4)
1030 case OP_GETSOCKNAME:
1031 case OP_GETPEERNAME:
1036 case OP_GETPRIORITY:
1059 if (!(o->op_private & OPpLVAL_INTRO))
1060 useless = PL_op_desc[o->op_type];
1067 if (!(o->op_private & OPpLVAL_INTRO) &&
1068 (!o->op_sibling || o->op_sibling->op_type != OP_READLINE))
1069 useless = "a variable";
1074 if (cSVOPo->op_private & OPpCONST_STRICT)
1075 no_bareword_allowed(o);
1078 if (ckWARN(WARN_VOID)) {
1079 useless = "a constant";
1080 if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
1082 else if (SvPOK(sv)) {
1083 if (strnEQ(SvPVX(sv), "di", 2) ||
1084 strnEQ(SvPVX(sv), "ds", 2) ||
1085 strnEQ(SvPVX(sv), "ig", 2))
1090 null(o); /* don't execute or even remember it */
1094 o->op_type = OP_PREINC; /* pre-increment is faster */
1095 o->op_ppaddr = PL_ppaddr[OP_PREINC];
1099 o->op_type = OP_PREDEC; /* pre-decrement is faster */
1100 o->op_ppaddr = PL_ppaddr[OP_PREDEC];
1106 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1111 if (o->op_flags & OPf_STACKED)
1119 if (!(o->op_flags & OPf_KIDS))
1128 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1135 /* all requires must return a boolean value */
1136 o->op_flags &= ~OPf_WANT;
1139 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
1140 if (!kPMOP->op_pmreplroot)
1141 deprecate("implicit split to @_");
1147 if (ckWARN(WARN_VOID))
1148 Perl_warner(aTHX_ WARN_VOID, "Useless use of %s in void context", useless);
1154 Perl_listkids(pTHX_ OP *o)
1157 if (o && o->op_flags & OPf_KIDS) {
1158 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1165 Perl_list(pTHX_ OP *o)
1169 /* assumes no premature commitment */
1170 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
1171 || o->op_type == OP_RETURN)
1176 if ((o->op_private & OPpTARGET_MY)
1177 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
1179 return o; /* As if inside SASSIGN */
1182 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_LIST;
1184 switch (o->op_type) {
1187 list(cBINOPo->op_first);
1192 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1200 if (!(o->op_flags & OPf_KIDS))
1202 if (!o->op_next && cUNOPo->op_first->op_type == OP_FLOP) {
1203 list(cBINOPo->op_first);
1204 return gen_constant_list(o);
1211 kid = cLISTOPo->op_first;
1213 while (kid = kid->op_sibling) {
1214 if (kid->op_sibling)
1219 WITH_THR(PL_curcop = &PL_compiling);
1223 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
1224 if (kid->op_sibling)
1229 WITH_THR(PL_curcop = &PL_compiling);
1232 /* all requires must return a boolean value */
1233 o->op_flags &= ~OPf_WANT;
1240 Perl_scalarseq(pTHX_ OP *o)
1245 if (o->op_type == OP_LINESEQ ||
1246 o->op_type == OP_SCOPE ||
1247 o->op_type == OP_LEAVE ||
1248 o->op_type == OP_LEAVETRY)
1251 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
1252 if (kid->op_sibling) {
1256 PL_curcop = &PL_compiling;
1258 o->op_flags &= ~OPf_PARENS;
1259 if (PL_hints & HINT_BLOCK_SCOPE)
1260 o->op_flags |= OPf_PARENS;
1263 o = newOP(OP_STUB, 0);
1268 S_modkids(pTHX_ OP *o, I32 type)
1271 if (o && o->op_flags & OPf_KIDS) {
1272 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1279 Perl_mod(pTHX_ OP *o, I32 type)
1286 if (!o || PL_error_count)
1289 if ((o->op_private & OPpTARGET_MY)
1290 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
1295 switch (o->op_type) {
1300 if (!(o->op_private & (OPpCONST_ARYBASE)))
1302 if (PL_eval_start && PL_eval_start->op_type == OP_CONST) {
1303 PL_compiling.cop_arybase = (I32)SvIV(cSVOPx(PL_eval_start)->op_sv);
1307 SAVEI32(PL_compiling.cop_arybase);
1308 PL_compiling.cop_arybase = 0;
1310 else if (type == OP_REFGEN)
1313 Perl_croak(aTHX_ "That use of $[ is unsupported");
1316 if (o->op_flags & OPf_PARENS)
1320 if ((type == OP_UNDEF || type == OP_REFGEN) &&
1321 !(o->op_flags & OPf_STACKED)) {
1322 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1323 o->op_ppaddr = PL_ppaddr[OP_RV2CV];
1324 assert(cUNOPo->op_first->op_type == OP_NULL);
1325 null(((LISTOP*)cUNOPo->op_first)->op_first);/* disable pushmark */
1328 else { /* lvalue subroutine call */
1329 o->op_private |= OPpLVAL_INTRO;
1330 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN) {
1331 /* Backward compatibility mode: */
1332 o->op_private |= OPpENTERSUB_INARGS;
1335 else { /* Compile-time error message: */
1336 OP *kid = cUNOPo->op_first;
1340 if (kid->op_type == OP_PUSHMARK)
1342 if (kid->op_type != OP_NULL || kid->op_targ != OP_LIST)
1344 "panic: unexpected lvalue entersub "
1345 "args: type/targ %ld:%ld",
1346 (long)kid->op_type,kid->op_targ);
1347 kid = kLISTOP->op_first;
1349 while (kid->op_sibling)
1350 kid = kid->op_sibling;
1351 if (!(kid->op_type == OP_NULL && kid->op_targ == OP_RV2CV)) {
1353 if (kid->op_type == OP_METHOD_NAMED
1354 || kid->op_type == OP_METHOD)
1358 if (kid->op_sibling || kid->op_next != kid) {
1359 yyerror("panic: unexpected optree near method call");
1363 NewOp(1101, newop, 1, OP);
1364 newop->op_type = OP_RV2CV;
1365 newop->op_ppaddr = PL_ppaddr[OP_RV2CV];
1366 newop->op_next = newop;
1367 kid->op_sibling = newop;
1368 newop->op_private |= OPpLVAL_INTRO;
1372 if (kid->op_type != OP_RV2CV)
1374 "panic: unexpected lvalue entersub "
1375 "entry via type/targ %ld:%ld",
1376 (long)kid->op_type,kid->op_targ);
1377 kid->op_private |= OPpLVAL_INTRO;
1378 break; /* Postpone until runtime */
1382 kid = kUNOP->op_first;
1383 if (kid->op_type == OP_NULL && kid->op_targ == OP_RV2SV)
1384 kid = kUNOP->op_first;
1385 if (kid->op_type == OP_NULL)
1387 "Unexpected constant lvalue entersub "
1388 "entry via type/targ %ld:%ld",
1389 (long)kid->op_type,kid->op_targ);
1390 if (kid->op_type != OP_GV) {
1391 /* Restore RV2CV to check lvalueness */
1393 if (kid->op_next && kid->op_next != kid) { /* Happens? */
1394 okid->op_next = kid->op_next;
1395 kid->op_next = okid;
1398 okid->op_next = Nullop;
1399 okid->op_type = OP_RV2CV;
1401 okid->op_ppaddr = PL_ppaddr[OP_RV2CV];
1402 okid->op_private |= OPpLVAL_INTRO;
1416 /* grep, foreach, subcalls, refgen */
1417 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
1419 yyerror(Perl_form(aTHX_ "Can't modify %s in %s",
1420 (o->op_type == OP_NULL && (o->op_flags & OPf_SPECIAL)
1422 : (o->op_type == OP_ENTERSUB
1423 ? "non-lvalue subroutine call"
1424 : PL_op_desc[o->op_type])),
1425 type ? PL_op_desc[type] : "local"));
1439 case OP_RIGHT_SHIFT:
1448 if (!(o->op_flags & OPf_STACKED))
1454 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1460 if (!type && cUNOPo->op_first->op_type != OP_GV)
1461 Perl_croak(aTHX_ "Can't localize through a reference");
1462 if (type == OP_REFGEN && o->op_flags & OPf_PARENS) {
1463 PL_modcount = 10000;
1464 return o; /* Treat \(@foo) like ordinary list. */
1468 if (scalar_mod_type(o, type))
1470 ref(cUNOPo->op_first, o->op_type);
1479 PL_modcount = 10000;
1482 if (!type && cUNOPo->op_first->op_type != OP_GV)
1483 Perl_croak(aTHX_ "Can't localize through a reference");
1484 ref(cUNOPo->op_first, o->op_type);
1488 PL_hints |= HINT_BLOCK_SCOPE;
1498 PL_modcount = 10000;
1499 if (type == OP_REFGEN && o->op_flags & OPf_PARENS)
1500 return o; /* Treat \(@foo) like ordinary list. */
1501 if (scalar_mod_type(o, type))
1507 Perl_croak(aTHX_ "Can't localize lexical variable %s",
1508 SvPV(*av_fetch(PL_comppad_name, o->op_targ, 4), n_a));
1513 PL_modcount++; /* XXX ??? */
1515 #endif /* USE_THREADS */
1521 if (type != OP_SASSIGN)
1525 if (o->op_private == 4) /* don't allow 4 arg substr as lvalue */
1531 pad_free(o->op_targ);
1532 o->op_targ = pad_alloc(o->op_type, SVs_PADMY);
1533 assert(SvTYPE(PAD_SV(o->op_targ)) == SVt_NULL);
1534 if (o->op_flags & OPf_KIDS)
1535 mod(cBINOPo->op_first->op_sibling, type);
1540 ref(cBINOPo->op_first, o->op_type);
1541 if (type == OP_ENTERSUB &&
1542 !(o->op_private & (OPpLVAL_INTRO | OPpDEREF)))
1543 o->op_private |= OPpLVAL_DEFER;
1550 if (o->op_flags & OPf_KIDS)
1551 mod(cLISTOPo->op_last, type);
1555 if (o->op_flags & OPf_SPECIAL) /* do BLOCK */
1557 else if (!(o->op_flags & OPf_KIDS))
1559 if (o->op_targ != OP_LIST) {
1560 mod(cBINOPo->op_first, type);
1565 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1569 o->op_flags |= OPf_MOD;
1571 if (type == OP_AASSIGN || type == OP_SASSIGN)
1572 o->op_flags |= OPf_SPECIAL|OPf_REF;
1574 o->op_private |= OPpLVAL_INTRO;
1575 o->op_flags &= ~OPf_SPECIAL;
1576 PL_hints |= HINT_BLOCK_SCOPE;
1578 else if (type != OP_GREPSTART && type != OP_ENTERSUB)
1579 o->op_flags |= OPf_REF;
1584 S_scalar_mod_type(pTHX_ OP *o, I32 type)
1588 if (o->op_type == OP_RV2GV)
1612 case OP_RIGHT_SHIFT:
1631 S_is_handle_constructor(pTHX_ OP *o, I32 argnum)
1633 switch (o->op_type) {
1641 case OP_SELECT: /* XXX c.f. SelectSaver.pm */
1654 Perl_refkids(pTHX_ OP *o, I32 type)
1657 if (o && o->op_flags & OPf_KIDS) {
1658 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1665 Perl_ref(pTHX_ OP *o, I32 type)
1669 if (!o || PL_error_count)
1672 switch (o->op_type) {
1674 if ((type == OP_DEFINED || type == OP_LOCK) &&
1675 !(o->op_flags & OPf_STACKED)) {
1676 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1677 o->op_ppaddr = PL_ppaddr[OP_RV2CV];
1678 assert(cUNOPo->op_first->op_type == OP_NULL);
1679 null(((LISTOP*)cUNOPo->op_first)->op_first); /* disable pushmark */
1680 o->op_flags |= OPf_SPECIAL;
1685 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1689 if (type == OP_DEFINED)
1690 o->op_flags |= OPf_SPECIAL; /* don't create GV */
1691 ref(cUNOPo->op_first, o->op_type);
1694 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1695 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1696 : type == OP_RV2HV ? OPpDEREF_HV
1698 o->op_flags |= OPf_MOD;
1703 o->op_flags |= OPf_MOD; /* XXX ??? */
1708 o->op_flags |= OPf_REF;
1711 if (type == OP_DEFINED)
1712 o->op_flags |= OPf_SPECIAL; /* don't create GV */
1713 ref(cUNOPo->op_first, o->op_type);
1718 o->op_flags |= OPf_REF;
1723 if (!(o->op_flags & OPf_KIDS))
1725 ref(cBINOPo->op_first, type);
1729 ref(cBINOPo->op_first, o->op_type);
1730 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1731 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1732 : type == OP_RV2HV ? OPpDEREF_HV
1734 o->op_flags |= OPf_MOD;
1742 if (!(o->op_flags & OPf_KIDS))
1744 ref(cLISTOPo->op_last, type);
1754 S_dup_attrlist(pTHX_ OP *o)
1758 /* An attrlist is either a simple OP_CONST or an OP_LIST with kids,
1759 * where the first kid is OP_PUSHMARK and the remaining ones
1760 * are OP_CONST. We need to push the OP_CONST values.
1762 if (o->op_type == OP_CONST)
1763 rop = newSVOP(OP_CONST, o->op_flags, SvREFCNT_inc(cSVOPo->op_sv));
1765 assert((o->op_type == OP_LIST) && (o->op_flags & OPf_KIDS));
1766 for (o = cLISTOPo->op_first; o; o=o->op_sibling) {
1767 if (o->op_type == OP_CONST)
1768 rop = append_elem(OP_LIST, rop,
1769 newSVOP(OP_CONST, o->op_flags,
1770 SvREFCNT_inc(cSVOPo->op_sv)));
1777 S_apply_attrs(pTHX_ HV *stash, SV *target, OP *attrs)
1779 OP *modname; /* for 'use' */
1782 /* fake up C<use attributes $pkg,$rv,@attrs> */
1783 ENTER; /* need to protect against side-effects of 'use' */
1785 if (stash && HvNAME(stash))
1786 stashsv = newSVpv(HvNAME(stash), 0);
1788 stashsv = &PL_sv_no;
1789 #define ATTRSMODULE "attributes"
1790 modname = newSVOP(OP_CONST, 0,
1791 newSVpvn(ATTRSMODULE, sizeof(ATTRSMODULE)-1));
1792 modname->op_private |= OPpCONST_BARE;
1793 /* that flag is required to make 'use' work right */
1794 utilize(1, start_subparse(FALSE, 0),
1795 Nullop, /* version */
1797 prepend_elem(OP_LIST,
1798 newSVOP(OP_CONST, 0, stashsv),
1799 prepend_elem(OP_LIST,
1800 newSVOP(OP_CONST, 0, newRV(target)),
1801 dup_attrlist(attrs))));
1806 S_my_kid(pTHX_ OP *o, OP *attrs)
1811 if (!o || PL_error_count)
1815 if (type == OP_LIST) {
1816 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1818 } else if (type == OP_UNDEF) {
1820 } else if (type == OP_RV2SV || /* "our" declaration */
1822 type == OP_RV2HV) { /* XXX does this let anything illegal in? */
1824 } else if (type != OP_PADSV &&
1827 type != OP_PUSHMARK)
1829 yyerror(Perl_form(aTHX_ "Can't declare %s in my", PL_op_desc[o->op_type]));
1832 else if (attrs && type != OP_PUSHMARK) {
1837 /* check for C<my Dog $spot> when deciding package */
1838 namesvp = av_fetch(PL_comppad_name, o->op_targ, FALSE);
1839 if (namesvp && *namesvp && SvOBJECT(*namesvp) && HvNAME(SvSTASH(*namesvp)))
1840 stash = SvSTASH(*namesvp);
1842 stash = PL_curstash;
1843 padsv = PAD_SV(o->op_targ);
1844 apply_attrs(stash, padsv, attrs);
1846 o->op_flags |= OPf_MOD;
1847 o->op_private |= OPpLVAL_INTRO;
1852 Perl_my_attrs(pTHX_ OP *o, OP *attrs)
1854 if (o->op_flags & OPf_PARENS)
1857 PL_in_my_stash = Nullhv;
1860 return my_kid(o, attrs);
1864 Perl_my(pTHX_ OP *o)
1866 return my_kid(o, Nullop);
1870 Perl_sawparens(pTHX_ OP *o)
1873 o->op_flags |= OPf_PARENS;
1878 Perl_bind_match(pTHX_ I32 type, OP *left, OP *right)
1883 if (ckWARN(WARN_UNSAFE) &&
1884 (left->op_type == OP_RV2AV ||
1885 left->op_type == OP_RV2HV ||
1886 left->op_type == OP_PADAV ||
1887 left->op_type == OP_PADHV)) {
1888 char *desc = PL_op_desc[(right->op_type == OP_SUBST ||
1889 right->op_type == OP_TRANS)
1890 ? right->op_type : OP_MATCH];
1891 const char *sample = ((left->op_type == OP_RV2AV ||
1892 left->op_type == OP_PADAV)
1893 ? "@array" : "%hash");
1894 Perl_warner(aTHX_ WARN_UNSAFE,
1895 "Applying %s to %s will act on scalar(%s)",
1896 desc, sample, sample);
1899 if (right->op_type == OP_MATCH ||
1900 right->op_type == OP_SUBST ||
1901 right->op_type == OP_TRANS) {
1902 right->op_flags |= OPf_STACKED;
1903 if (right->op_type != OP_MATCH)
1904 left = mod(left, right->op_type);
1905 if (right->op_type == OP_TRANS)
1906 o = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
1908 o = prepend_elem(right->op_type, scalar(left), right);
1910 return newUNOP(OP_NOT, 0, scalar(o));
1914 return bind_match(type, left,
1915 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
1919 Perl_invert(pTHX_ OP *o)
1923 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
1924 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(o));
1928 Perl_scope(pTHX_ OP *o)
1931 if (o->op_flags & OPf_PARENS || PERLDB_NOOPT || PL_tainting) {
1932 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
1933 o->op_type = OP_LEAVE;
1934 o->op_ppaddr = PL_ppaddr[OP_LEAVE];
1937 if (o->op_type == OP_LINESEQ) {
1939 o->op_type = OP_SCOPE;
1940 o->op_ppaddr = PL_ppaddr[OP_SCOPE];
1941 kid = ((LISTOP*)o)->op_first;
1942 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE)
1946 o = newLISTOP(OP_SCOPE, 0, o, Nullop);
1953 Perl_save_hints(pTHX)
1956 SAVESPTR(GvHV(PL_hintgv));
1957 GvHV(PL_hintgv) = newHVhv(GvHV(PL_hintgv));
1958 SAVEFREESV(GvHV(PL_hintgv));
1962 Perl_block_start(pTHX_ int full)
1965 int retval = PL_savestack_ix;
1967 SAVEI32(PL_comppad_name_floor);
1969 if ((PL_comppad_name_fill = AvFILLp(PL_comppad_name)) > 0)
1970 PL_comppad_name_floor = PL_comppad_name_fill;
1972 PL_comppad_name_floor = 0;
1974 SAVEI32(PL_min_intro_pending);
1975 SAVEI32(PL_max_intro_pending);
1976 PL_min_intro_pending = 0;
1977 SAVEI32(PL_comppad_name_fill);
1978 SAVEI32(PL_padix_floor);
1979 PL_padix_floor = PL_padix;
1980 PL_pad_reset_pending = FALSE;
1982 PL_hints &= ~HINT_BLOCK_SCOPE;
1983 SAVESPTR(PL_compiling.cop_warnings);
1984 if (! specialWARN(PL_compiling.cop_warnings)) {
1985 PL_compiling.cop_warnings = newSVsv(PL_compiling.cop_warnings) ;
1986 SAVEFREESV(PL_compiling.cop_warnings) ;
1994 Perl_block_end(pTHX_ I32 floor, OP *seq)
1997 int needblockscope = PL_hints & HINT_BLOCK_SCOPE;
1998 OP* retval = scalarseq(seq);
2000 PL_pad_reset_pending = FALSE;
2001 PL_compiling.op_private = PL_hints;
2003 PL_hints |= HINT_BLOCK_SCOPE; /* propagate out */
2004 pad_leavemy(PL_comppad_name_fill);
2013 OP *o = newOP(OP_THREADSV, 0);
2014 o->op_targ = find_threadsv("_");
2017 return newSVREF(newGVOP(OP_GV, 0, PL_defgv));
2018 #endif /* USE_THREADS */
2022 Perl_newPROG(pTHX_ OP *o)
2028 PL_eval_root = newUNOP(OP_LEAVEEVAL,
2029 ((PL_in_eval & EVAL_KEEPERR)
2030 ? OPf_SPECIAL : 0), o);
2031 PL_eval_start = linklist(PL_eval_root);
2032 PL_eval_root->op_private |= OPpREFCOUNTED;
2033 OpREFCNT_set(PL_eval_root, 1);
2034 PL_eval_root->op_next = 0;
2035 peep(PL_eval_start);
2040 PL_main_root = scope(sawparens(scalarvoid(o)));
2041 PL_curcop = &PL_compiling;
2042 PL_main_start = LINKLIST(PL_main_root);
2043 PL_main_root->op_private |= OPpREFCOUNTED;
2044 OpREFCNT_set(PL_main_root, 1);
2045 PL_main_root->op_next = 0;
2046 peep(PL_main_start);
2049 /* Register with debugger */
2051 CV *cv = get_cv("DB::postponed", FALSE);
2055 XPUSHs((SV*)CopFILEGV(&PL_compiling));
2057 call_sv((SV*)cv, G_DISCARD);
2064 Perl_localize(pTHX_ OP *o, I32 lex)
2066 if (o->op_flags & OPf_PARENS)
2070 if (ckWARN(WARN_PARENTHESIS) && PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == ',') {
2072 for (s = PL_bufptr; *s && (isALNUM(*s) || (*s & 0x80) || strchr("@$%, ",*s)); s++) ;
2073 if (*s == ';' || *s == '=')
2074 Perl_warner(aTHX_ WARN_PARENTHESIS, "Parentheses missing around \"%s\" list",
2075 lex ? "my" : "local");
2079 PL_in_my_stash = Nullhv;
2083 return mod(o, OP_NULL); /* a bit kludgey */
2087 Perl_jmaybe(pTHX_ OP *o)
2089 if (o->op_type == OP_LIST) {
2092 o2 = newOP(OP_THREADSV, 0);
2093 o2->op_targ = find_threadsv(";");
2095 o2 = newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
2096 #endif /* USE_THREADS */
2097 o = convert(OP_JOIN, 0, prepend_elem(OP_LIST, o2, o));
2103 Perl_fold_constants(pTHX_ register OP *o)
2107 I32 type = o->op_type;
2110 if (PL_opargs[type] & OA_RETSCALAR)
2112 if (PL_opargs[type] & OA_TARGET && !o->op_targ)
2113 o->op_targ = pad_alloc(type, SVs_PADTMP);
2115 /* integerize op, unless it happens to be C<-foo>.
2116 * XXX should pp_i_negate() do magic string negation instead? */
2117 if ((PL_opargs[type] & OA_OTHERINT) && (PL_hints & HINT_INTEGER)
2118 && !(type == OP_NEGATE && cUNOPo->op_first->op_type == OP_CONST
2119 && (cUNOPo->op_first->op_private & OPpCONST_BARE)))
2121 o->op_ppaddr = PL_ppaddr[type = ++(o->op_type)];
2124 if (!(PL_opargs[type] & OA_FOLDCONST))
2129 /* XXX might want a ck_negate() for this */
2130 cUNOPo->op_first->op_private &= ~OPpCONST_STRICT;
2143 if (o->op_private & OPpLOCALE)
2148 goto nope; /* Don't try to run w/ errors */
2150 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
2151 if ((curop->op_type != OP_CONST ||
2152 (curop->op_private & OPpCONST_BARE)) &&
2153 curop->op_type != OP_LIST &&
2154 curop->op_type != OP_SCALAR &&
2155 curop->op_type != OP_NULL &&
2156 curop->op_type != OP_PUSHMARK)
2162 curop = LINKLIST(o);
2166 sv = *(PL_stack_sp--);
2167 if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
2168 pad_swipe(o->op_targ);
2169 else if (SvTEMP(sv)) { /* grab mortal temp? */
2170 (void)SvREFCNT_inc(sv);
2174 if (type == OP_RV2GV)
2175 return newGVOP(OP_GV, 0, (GV*)sv);
2177 /* try to smush double to int, but don't smush -2.0 to -2 */
2178 if ((SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK)) == SVf_NOK &&
2182 if ((NV)iv == SvNV(sv)) {
2187 SvIOK_off(sv); /* undo SvIV() damage */
2189 return newSVOP(OP_CONST, 0, sv);
2193 if (!(PL_opargs[type] & OA_OTHERINT))
2196 if (!(PL_hints & HINT_INTEGER)) {
2197 if (type == OP_MODULO
2198 || type == OP_DIVIDE
2199 || !(o->op_flags & OPf_KIDS))
2204 for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
2205 if (curop->op_type == OP_CONST) {
2206 if (SvIOK(((SVOP*)curop)->op_sv))
2210 if (PL_opargs[curop->op_type] & OA_RETINTEGER)
2214 o->op_ppaddr = PL_ppaddr[++(o->op_type)];
2221 Perl_gen_constant_list(pTHX_ register OP *o)
2225 I32 oldtmps_floor = PL_tmps_floor;
2229 return o; /* Don't attempt to run with errors */
2231 PL_op = curop = LINKLIST(o);
2237 PL_tmps_floor = oldtmps_floor;
2239 o->op_type = OP_RV2AV;
2240 o->op_ppaddr = PL_ppaddr[OP_RV2AV];
2241 curop = ((UNOP*)o)->op_first;
2242 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*PL_stack_sp--));
2249 Perl_convert(pTHX_ I32 type, I32 flags, OP *o)
2254 if (!o || o->op_type != OP_LIST)
2255 o = newLISTOP(OP_LIST, 0, o, Nullop);
2257 o->op_flags &= ~OPf_WANT;
2259 if (!(PL_opargs[type] & OA_MARK))
2260 null(cLISTOPo->op_first);
2263 o->op_ppaddr = PL_ppaddr[type];
2264 o->op_flags |= flags;
2266 o = CHECKOP(type, o);
2267 if (o->op_type != type)
2270 if (cLISTOPo->op_children < 7) {
2271 /* XXX do we really need to do this if we're done appending?? */
2272 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
2274 cLISTOPo->op_last = last; /* in case check substituted last arg */
2277 return fold_constants(o);
2280 /* List constructors */
2283 Perl_append_elem(pTHX_ I32 type, OP *first, OP *last)
2291 if (first->op_type != type || type==OP_LIST && first->op_flags & OPf_PARENS)
2292 return newLISTOP(type, 0, first, last);
2294 if (first->op_flags & OPf_KIDS)
2295 ((LISTOP*)first)->op_last->op_sibling = last;
2297 first->op_flags |= OPf_KIDS;
2298 ((LISTOP*)first)->op_first = last;
2300 ((LISTOP*)first)->op_last = last;
2301 ((LISTOP*)first)->op_children++;
2306 Perl_append_list(pTHX_ I32 type, LISTOP *first, LISTOP *last)
2314 if (first->op_type != type)
2315 return prepend_elem(type, (OP*)first, (OP*)last);
2317 if (last->op_type != type)
2318 return append_elem(type, (OP*)first, (OP*)last);
2320 first->op_last->op_sibling = last->op_first;
2321 first->op_last = last->op_last;
2322 first->op_children += last->op_children;
2323 if (first->op_children)
2324 first->op_flags |= OPf_KIDS;
2326 #ifdef PL_OP_SLAB_ALLOC
2334 Perl_prepend_elem(pTHX_ I32 type, OP *first, OP *last)
2342 if (last->op_type == type) {
2343 if (type == OP_LIST) { /* already a PUSHMARK there */
2344 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
2345 ((LISTOP*)last)->op_first->op_sibling = first;
2348 if (!(last->op_flags & OPf_KIDS)) {
2349 ((LISTOP*)last)->op_last = first;
2350 last->op_flags |= OPf_KIDS;
2352 first->op_sibling = ((LISTOP*)last)->op_first;
2353 ((LISTOP*)last)->op_first = first;
2355 ((LISTOP*)last)->op_children++;
2359 return newLISTOP(type, 0, first, last);
2365 Perl_newNULLLIST(pTHX)
2367 return newOP(OP_STUB, 0);
2371 Perl_force_list(pTHX_ OP *o)
2373 if (!o || o->op_type != OP_LIST)
2374 o = newLISTOP(OP_LIST, 0, o, Nullop);
2380 Perl_newLISTOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
2384 NewOp(1101, listop, 1, LISTOP);
2386 listop->op_type = type;
2387 listop->op_ppaddr = PL_ppaddr[type];
2388 listop->op_children = (first != 0) + (last != 0);
2389 listop->op_flags = flags;
2393 else if (!first && last)
2396 first->op_sibling = last;
2397 listop->op_first = first;
2398 listop->op_last = last;
2399 if (type == OP_LIST) {
2401 pushop = newOP(OP_PUSHMARK, 0);
2402 pushop->op_sibling = first;
2403 listop->op_first = pushop;
2404 listop->op_flags |= OPf_KIDS;
2406 listop->op_last = pushop;
2408 else if (listop->op_children)
2409 listop->op_flags |= OPf_KIDS;
2415 Perl_newOP(pTHX_ I32 type, I32 flags)
2418 NewOp(1101, o, 1, OP);
2420 o->op_ppaddr = PL_ppaddr[type];
2421 o->op_flags = flags;
2424 o->op_private = 0 + (flags >> 8);
2425 if (PL_opargs[type] & OA_RETSCALAR)
2427 if (PL_opargs[type] & OA_TARGET)
2428 o->op_targ = pad_alloc(type, SVs_PADTMP);
2429 return CHECKOP(type, o);
2433 Perl_newUNOP(pTHX_ I32 type, I32 flags, OP *first)
2438 first = newOP(OP_STUB, 0);
2439 if (PL_opargs[type] & OA_MARK)
2440 first = force_list(first);
2442 NewOp(1101, unop, 1, UNOP);
2443 unop->op_type = type;
2444 unop->op_ppaddr = PL_ppaddr[type];
2445 unop->op_first = first;
2446 unop->op_flags = flags | OPf_KIDS;
2447 unop->op_private = 1 | (flags >> 8);
2448 unop = (UNOP*) CHECKOP(type, unop);
2452 return fold_constants((OP *) unop);
2456 Perl_newBINOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
2459 NewOp(1101, binop, 1, BINOP);
2462 first = newOP(OP_NULL, 0);
2464 binop->op_type = type;
2465 binop->op_ppaddr = PL_ppaddr[type];
2466 binop->op_first = first;
2467 binop->op_flags = flags | OPf_KIDS;
2470 binop->op_private = 1 | (flags >> 8);
2473 binop->op_private = 2 | (flags >> 8);
2474 first->op_sibling = last;
2477 binop = (BINOP*)CHECKOP(type, binop);
2478 if (binop->op_next || binop->op_type != type)
2481 binop->op_last = binop->op_first->op_sibling;
2483 return fold_constants((OP *)binop);
2487 utf8compare(const void *a, const void *b)
2490 for (i = 0; i < 10; i++) {
2491 if ((*(U8**)a)[i] < (*(U8**)b)[i])
2493 if ((*(U8**)a)[i] > (*(U8**)b)[i])
2500 Perl_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
2502 SV *tstr = ((SVOP*)expr)->op_sv;
2503 SV *rstr = ((SVOP*)repl)->op_sv;
2506 register U8 *t = (U8*)SvPV(tstr, tlen);
2507 register U8 *r = (U8*)SvPV(rstr, rlen);
2513 register short *tbl;
2515 complement = o->op_private & OPpTRANS_COMPLEMENT;
2516 del = o->op_private & OPpTRANS_DELETE;
2517 squash = o->op_private & OPpTRANS_SQUASH;
2519 if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
2520 SV* listsv = newSVpvn("# comment\n",10);
2522 U8* tend = t + tlen;
2523 U8* rend = r + rlen;
2539 I32 from_utf = o->op_private & OPpTRANS_FROM_UTF;
2540 I32 to_utf = o->op_private & OPpTRANS_TO_UTF;
2546 New(1109, cp, tlen, U8*);
2548 transv = newSVpvn("",0);
2557 qsort(cp, i, sizeof(U8*), utf8compare);
2558 for (j = 0; j < i; j++) {
2560 UV val = utf8_to_uv(s, &ulen);
2562 diff = val - nextmin;
2564 t = uv_to_utf8(tmpbuf,nextmin);
2565 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2567 t = uv_to_utf8(tmpbuf, val - 1);
2568 sv_catpvn(transv, "\377", 1);
2569 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2573 val = utf8_to_uv(s+1, &ulen);
2577 t = uv_to_utf8(tmpbuf,nextmin);
2578 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2579 t = uv_to_utf8(tmpbuf, 0x7fffffff);
2580 sv_catpvn(transv, "\377", 1);
2581 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2582 t = (U8*)SvPVX(transv);
2583 tlen = SvCUR(transv);
2586 else if (!rlen && !del) {
2587 r = t; rlen = tlen; rend = tend;
2590 if (to_utf && from_utf) { /* only counting characters */
2591 if (t == r || (tlen == rlen && memEQ(t, r, tlen)))
2592 o->op_private |= OPpTRANS_IDENTICAL;
2594 else { /* straight latin-1 translation */
2595 if (tlen == 4 && memEQ(t, "\0\377\303\277", 4) &&
2596 rlen == 4 && memEQ(r, "\0\377\303\277", 4))
2597 o->op_private |= OPpTRANS_IDENTICAL;
2601 while (t < tend || tfirst <= tlast) {
2602 /* see if we need more "t" chars */
2603 if (tfirst > tlast) {
2604 tfirst = (I32)utf8_to_uv(t, &ulen);
2606 if (t < tend && *t == 0xff) { /* illegal utf8 val indicates range */
2607 tlast = (I32)utf8_to_uv(++t, &ulen);
2614 /* now see if we need more "r" chars */
2615 if (rfirst > rlast) {
2617 rfirst = (I32)utf8_to_uv(r, &ulen);
2619 if (r < rend && *r == 0xff) { /* illegal utf8 val indicates range */
2620 rlast = (I32)utf8_to_uv(++r, &ulen);
2629 rfirst = rlast = 0xffffffff;
2633 /* now see which range will peter our first, if either. */
2634 tdiff = tlast - tfirst;
2635 rdiff = rlast - rfirst;
2642 if (rfirst == 0xffffffff) {
2643 diff = tdiff; /* oops, pretend rdiff is infinite */
2645 Perl_sv_catpvf(aTHX_ listsv, "%04x\t%04x\tXXXX\n", tfirst, tlast);
2647 Perl_sv_catpvf(aTHX_ listsv, "%04x\t\tXXXX\n", tfirst);
2651 Perl_sv_catpvf(aTHX_ listsv, "%04x\t%04x\t%04x\n", tfirst, tfirst + diff, rfirst);
2653 Perl_sv_catpvf(aTHX_ listsv, "%04x\t\t%04x\n", tfirst, rfirst);
2655 if (rfirst + diff > max)
2656 max = rfirst + diff;
2661 else if (rfirst <= 0x800)
2662 grows |= (tfirst < 0x80);
2663 else if (rfirst <= 0x10000)
2664 grows |= (tfirst < 0x800);
2665 else if (rfirst <= 0x200000)
2666 grows |= (tfirst < 0x10000);
2667 else if (rfirst <= 0x4000000)
2668 grows |= (tfirst < 0x200000);
2669 else if (rfirst <= 0x80000000)
2670 grows |= (tfirst < 0x4000000);
2682 else if (max > 0xff)
2687 cSVOPo->op_sv = (SV*)swash_init("utf8", "", listsv, bits, none);
2688 SvREFCNT_dec(listsv);
2690 SvREFCNT_dec(transv);
2692 if (!del && havefinal)
2693 (void)hv_store((HV*)SvRV((cSVOPo->op_sv)), "FINAL", 5, newSViv((IV)final), 0);
2695 if (grows && to_utf)
2696 o->op_private |= OPpTRANS_GROWS;
2703 tbl = (short*)cPVOPo->op_pv;
2705 Zero(tbl, 256, short);
2706 for (i = 0; i < tlen; i++)
2708 for (i = 0, j = 0; i < 256; i++) {
2724 if (!rlen && !del) {
2727 o->op_private |= OPpTRANS_IDENTICAL;
2729 for (i = 0; i < 256; i++)
2731 for (i = 0, j = 0; i < tlen; i++,j++) {
2734 if (tbl[t[i]] == -1)
2740 if (tbl[t[i]] == -1)
2751 Perl_newPMOP(pTHX_ I32 type, I32 flags)
2756 NewOp(1101, pmop, 1, PMOP);
2757 pmop->op_type = type;
2758 pmop->op_ppaddr = PL_ppaddr[type];
2759 pmop->op_flags = flags;
2760 pmop->op_private = 0 | (flags >> 8);
2762 if (PL_hints & HINT_RE_TAINT)
2763 pmop->op_pmpermflags |= PMf_RETAINT;
2764 if (PL_hints & HINT_LOCALE)
2765 pmop->op_pmpermflags |= PMf_LOCALE;
2766 pmop->op_pmflags = pmop->op_pmpermflags;
2768 /* link into pm list */
2769 if (type != OP_TRANS && PL_curstash) {
2770 pmop->op_pmnext = HvPMROOT(PL_curstash);
2771 HvPMROOT(PL_curstash) = pmop;
2778 Perl_pmruntime(pTHX_ OP *o, OP *expr, OP *repl)
2783 I32 repl_has_vars = 0;
2785 if (o->op_type == OP_TRANS)
2786 return pmtrans(o, expr, repl);
2788 PL_hints |= HINT_BLOCK_SCOPE;
2791 if (expr->op_type == OP_CONST) {
2793 SV *pat = ((SVOP*)expr)->op_sv;
2794 char *p = SvPV(pat, plen);
2795 if ((o->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
2796 sv_setpvn(pat, "\\s+", 3);
2797 p = SvPV(pat, plen);
2798 pm->op_pmflags |= PMf_SKIPWHITE;
2800 pm->op_pmregexp = CALLREGCOMP(aTHX_ p, p + plen, pm);
2801 if (strEQ("\\s+", pm->op_pmregexp->precomp))
2802 pm->op_pmflags |= PMf_WHITE;
2806 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL))
2807 expr = newUNOP((!(PL_hints & HINT_RE_EVAL)
2809 : OP_REGCMAYBE),0,expr);
2811 NewOp(1101, rcop, 1, LOGOP);
2812 rcop->op_type = OP_REGCOMP;
2813 rcop->op_ppaddr = PL_ppaddr[OP_REGCOMP];
2814 rcop->op_first = scalar(expr);
2815 rcop->op_flags |= ((PL_hints & HINT_RE_EVAL)
2816 ? (OPf_SPECIAL | OPf_KIDS)
2818 rcop->op_private = 1;
2821 /* establish postfix order */
2822 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL)) {
2824 rcop->op_next = expr;
2825 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
2828 rcop->op_next = LINKLIST(expr);
2829 expr->op_next = (OP*)rcop;
2832 prepend_elem(o->op_type, scalar((OP*)rcop), o);
2837 if (pm->op_pmflags & PMf_EVAL) {
2839 if (CopLINE(PL_curcop) < PL_multi_end)
2840 CopLINE_set(PL_curcop, PL_multi_end);
2843 else if (repl->op_type == OP_THREADSV
2844 && strchr("&`'123456789+",
2845 PL_threadsv_names[repl->op_targ]))
2849 #endif /* USE_THREADS */
2850 else if (repl->op_type == OP_CONST)
2854 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
2855 if (PL_opargs[curop->op_type] & OA_DANGEROUS) {
2857 if (curop->op_type == OP_THREADSV) {
2859 if (strchr("&`'123456789+", curop->op_private))
2863 if (curop->op_type == OP_GV) {
2864 GV *gv = cGVOPx(curop);
2866 if (strchr("&`'123456789+", *GvENAME(gv)))
2869 #endif /* USE_THREADS */
2870 else if (curop->op_type == OP_RV2CV)
2872 else if (curop->op_type == OP_RV2SV ||
2873 curop->op_type == OP_RV2AV ||
2874 curop->op_type == OP_RV2HV ||
2875 curop->op_type == OP_RV2GV) {
2876 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
2879 else if (curop->op_type == OP_PADSV ||
2880 curop->op_type == OP_PADAV ||
2881 curop->op_type == OP_PADHV ||
2882 curop->op_type == OP_PADANY) {
2885 else if (curop->op_type == OP_PUSHRE)
2886 ; /* Okay here, dangerous in newASSIGNOP */
2895 && (!pm->op_pmregexp
2896 || pm->op_pmregexp->reganch & ROPT_EVAL_SEEN))) {
2897 pm->op_pmflags |= PMf_CONST; /* const for long enough */
2898 pm->op_pmpermflags |= PMf_CONST; /* const for long enough */
2899 prepend_elem(o->op_type, scalar(repl), o);
2902 if (curop == repl && !pm->op_pmregexp) { /* Has variables. */
2903 pm->op_pmflags |= PMf_MAYBE_CONST;
2904 pm->op_pmpermflags |= PMf_MAYBE_CONST;
2906 NewOp(1101, rcop, 1, LOGOP);
2907 rcop->op_type = OP_SUBSTCONT;
2908 rcop->op_ppaddr = PL_ppaddr[OP_SUBSTCONT];
2909 rcop->op_first = scalar(repl);
2910 rcop->op_flags |= OPf_KIDS;
2911 rcop->op_private = 1;
2914 /* establish postfix order */
2915 rcop->op_next = LINKLIST(repl);
2916 repl->op_next = (OP*)rcop;
2918 pm->op_pmreplroot = scalar((OP*)rcop);
2919 pm->op_pmreplstart = LINKLIST(rcop);
2928 Perl_newSVOP(pTHX_ I32 type, I32 flags, SV *sv)
2931 NewOp(1101, svop, 1, SVOP);
2932 svop->op_type = type;
2933 svop->op_ppaddr = PL_ppaddr[type];
2935 svop->op_next = (OP*)svop;
2936 svop->op_flags = flags;
2937 if (PL_opargs[type] & OA_RETSCALAR)
2939 if (PL_opargs[type] & OA_TARGET)
2940 svop->op_targ = pad_alloc(type, SVs_PADTMP);
2941 return CHECKOP(type, svop);
2945 Perl_newPADOP(pTHX_ I32 type, I32 flags, SV *sv)
2948 NewOp(1101, padop, 1, PADOP);
2949 padop->op_type = type;
2950 padop->op_ppaddr = PL_ppaddr[type];
2951 padop->op_padix = pad_alloc(type, SVs_PADTMP);
2952 SvREFCNT_dec(PL_curpad[padop->op_padix]);
2953 PL_curpad[padop->op_padix] = sv;
2955 padop->op_next = (OP*)padop;
2956 padop->op_flags = flags;
2957 if (PL_opargs[type] & OA_RETSCALAR)
2959 if (PL_opargs[type] & OA_TARGET)
2960 padop->op_targ = pad_alloc(type, SVs_PADTMP);
2961 return CHECKOP(type, padop);
2965 Perl_newGVOP(pTHX_ I32 type, I32 flags, GV *gv)
2970 return newPADOP(type, flags, SvREFCNT_inc(gv));
2972 return newSVOP(type, flags, SvREFCNT_inc(gv));
2977 Perl_newPVOP(pTHX_ I32 type, I32 flags, char *pv)
2980 NewOp(1101, pvop, 1, PVOP);
2981 pvop->op_type = type;
2982 pvop->op_ppaddr = PL_ppaddr[type];
2984 pvop->op_next = (OP*)pvop;
2985 pvop->op_flags = flags;
2986 if (PL_opargs[type] & OA_RETSCALAR)
2988 if (PL_opargs[type] & OA_TARGET)
2989 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
2990 return CHECKOP(type, pvop);
2994 Perl_package(pTHX_ OP *o)
2999 save_hptr(&PL_curstash);
3000 save_item(PL_curstname);
3005 name = SvPV(sv, len);
3006 PL_curstash = gv_stashpvn(name,len,TRUE);
3007 sv_setpvn(PL_curstname, name, len);
3011 sv_setpv(PL_curstname,"<none>");
3012 PL_curstash = Nullhv;
3014 PL_hints |= HINT_BLOCK_SCOPE;
3015 PL_copline = NOLINE;
3020 Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *id, OP *arg)
3029 if (id->op_type != OP_CONST)
3030 Perl_croak(aTHX_ "Module name must be constant");
3034 if(version != Nullop) {
3035 SV *vesv = ((SVOP*)version)->op_sv;
3037 if (arg == Nullop && !SvNIOK(vesv)) {
3043 if (version->op_type != OP_CONST || !SvNIOK(vesv))
3044 Perl_croak(aTHX_ "Version number must be constant number");
3046 /* Make copy of id so we don't free it twice */
3047 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
3049 /* Fake up a method call to VERSION */
3050 veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
3051 append_elem(OP_LIST,
3052 prepend_elem(OP_LIST, pack, list(version)),
3053 newSVOP(OP_METHOD_NAMED, 0,
3054 newSVpvn("VERSION", 7))));
3058 /* Fake up an import/unimport */
3059 if (arg && arg->op_type == OP_STUB)
3060 imop = arg; /* no import on explicit () */
3061 else if(SvNIOK(((SVOP*)id)->op_sv)) {
3062 imop = Nullop; /* use 5.0; */
3065 /* Make copy of id so we don't free it twice */
3066 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
3067 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
3068 append_elem(OP_LIST,
3069 prepend_elem(OP_LIST, pack, list(arg)),
3070 newSVOP(OP_METHOD_NAMED, 0,
3071 aver ? newSVpvn("import", 6)
3072 : newSVpvn("unimport", 8))));
3075 /* Fake up a require, handle override, if any */
3076 gv = gv_fetchpv("require", FALSE, SVt_PVCV);
3077 if (!(gv && GvIMPORTED_CV(gv)))
3078 gv = gv_fetchpv("CORE::GLOBAL::require", FALSE, SVt_PVCV);
3080 if (gv && GvIMPORTED_CV(gv)) {
3081 rqop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
3082 append_elem(OP_LIST, id,
3083 scalar(newUNOP(OP_RV2CV, 0,
3088 rqop = newUNOP(OP_REQUIRE, 0, id);
3091 /* Fake up the BEGIN {}, which does its thing immediately. */
3093 newSVOP(OP_CONST, 0, newSVpvn("BEGIN", 5)),
3096 append_elem(OP_LINESEQ,
3097 append_elem(OP_LINESEQ,
3098 newSTATEOP(0, Nullch, rqop),
3099 newSTATEOP(0, Nullch, veop)),
3100 newSTATEOP(0, Nullch, imop) ));
3102 PL_hints |= HINT_BLOCK_SCOPE;
3103 PL_copline = NOLINE;
3108 Perl_dofile(pTHX_ OP *term)
3113 gv = gv_fetchpv("do", FALSE, SVt_PVCV);
3114 if (!(gv && GvIMPORTED_CV(gv)))
3115 gv = gv_fetchpv("CORE::GLOBAL::do", FALSE, SVt_PVCV);
3117 if (gv && GvIMPORTED_CV(gv)) {
3118 doop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
3119 append_elem(OP_LIST, term,
3120 scalar(newUNOP(OP_RV2CV, 0,
3125 doop = newUNOP(OP_DOFILE, 0, scalar(term));
3131 Perl_newSLICEOP(pTHX_ I32 flags, OP *subscript, OP *listval)
3133 return newBINOP(OP_LSLICE, flags,
3134 list(force_list(subscript)),
3135 list(force_list(listval)) );
3139 S_list_assignment(pTHX_ register OP *o)
3144 if (o->op_type == OP_NULL && o->op_flags & OPf_KIDS)
3145 o = cUNOPo->op_first;
3147 if (o->op_type == OP_COND_EXPR) {
3148 I32 t = list_assignment(cLOGOPo->op_first->op_sibling);
3149 I32 f = list_assignment(cLOGOPo->op_first->op_sibling->op_sibling);
3154 yyerror("Assignment to both a list and a scalar");
3158 if (o->op_type == OP_LIST || o->op_flags & OPf_PARENS ||
3159 o->op_type == OP_RV2AV || o->op_type == OP_RV2HV ||
3160 o->op_type == OP_ASLICE || o->op_type == OP_HSLICE)
3163 if (o->op_type == OP_PADAV || o->op_type == OP_PADHV)
3166 if (o->op_type == OP_RV2SV)
3173 Perl_newASSIGNOP(pTHX_ I32 flags, OP *left, I32 optype, OP *right)
3178 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN) {
3179 return newLOGOP(optype, 0,
3180 mod(scalar(left), optype),
3181 newUNOP(OP_SASSIGN, 0, scalar(right)));
3184 return newBINOP(optype, OPf_STACKED,
3185 mod(scalar(left), optype), scalar(right));
3189 if (list_assignment(left)) {
3192 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
3193 left = mod(left, OP_AASSIGN);
3201 o = newBINOP(OP_AASSIGN, flags,
3202 list(force_list(right)),
3203 list(force_list(left)) );
3204 o->op_private = 0 | (flags >> 8);
3205 if (!(left->op_private & OPpLVAL_INTRO)) {
3209 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
3210 if (PL_opargs[curop->op_type] & OA_DANGEROUS) {
3211 if (curop->op_type == OP_GV) {
3212 GV *gv = cGVOPx(curop);
3213 if (gv == PL_defgv || SvCUR(gv) == PL_generation)
3215 SvCUR(gv) = PL_generation;
3217 else if (curop->op_type == OP_PADSV ||
3218 curop->op_type == OP_PADAV ||
3219 curop->op_type == OP_PADHV ||
3220 curop->op_type == OP_PADANY) {
3221 SV **svp = AvARRAY(PL_comppad_name);
3222 SV *sv = svp[curop->op_targ];
3223 if (SvCUR(sv) == PL_generation)
3225 SvCUR(sv) = PL_generation; /* (SvCUR not used any more) */
3227 else if (curop->op_type == OP_RV2CV)
3229 else if (curop->op_type == OP_RV2SV ||
3230 curop->op_type == OP_RV2AV ||
3231 curop->op_type == OP_RV2HV ||
3232 curop->op_type == OP_RV2GV) {
3233 if (lastop->op_type != OP_GV) /* funny deref? */
3236 else if (curop->op_type == OP_PUSHRE) {
3237 if (((PMOP*)curop)->op_pmreplroot) {
3238 GV *gv = (GV*)((PMOP*)curop)->op_pmreplroot;
3239 if (gv == PL_defgv || SvCUR(gv) == PL_generation)
3241 SvCUR(gv) = PL_generation;
3250 o->op_private = OPpASSIGN_COMMON;
3252 if (right && right->op_type == OP_SPLIT) {
3254 if ((tmpop = ((LISTOP*)right)->op_first) &&
3255 tmpop->op_type == OP_PUSHRE)
3257 PMOP *pm = (PMOP*)tmpop;
3258 if (left->op_type == OP_RV2AV &&
3259 !(left->op_private & OPpLVAL_INTRO) &&
3260 !(o->op_private & OPpASSIGN_COMMON) )
3262 tmpop = ((UNOP*)left)->op_first;
3263 if (tmpop->op_type == OP_GV && !pm->op_pmreplroot) {
3265 pm->op_pmreplroot = (OP*)cPADOPx(tmpop)->op_padix;
3266 cPADOPx(tmpop)->op_padix = 0; /* steal it */
3268 pm->op_pmreplroot = (OP*)cSVOPx(tmpop)->op_sv;
3269 cSVOPx(tmpop)->op_sv = Nullsv; /* steal it */
3271 pm->op_pmflags |= PMf_ONCE;
3272 tmpop = cUNOPo->op_first; /* to list (nulled) */
3273 tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */
3274 tmpop->op_sibling = Nullop; /* don't free split */
3275 right->op_next = tmpop->op_next; /* fix starting loc */
3276 op_free(o); /* blow off assign */
3277 right->op_flags &= ~OPf_WANT;
3278 /* "I don't know and I don't care." */
3283 if (PL_modcount < 10000 &&
3284 ((LISTOP*)right)->op_last->op_type == OP_CONST)
3286 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
3288 sv_setiv(sv, PL_modcount+1);
3296 right = newOP(OP_UNDEF, 0);
3297 if (right->op_type == OP_READLINE) {
3298 right->op_flags |= OPf_STACKED;
3299 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
3302 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
3303 o = newBINOP(OP_SASSIGN, flags,
3304 scalar(right), mod(scalar(left), OP_SASSIGN) );
3316 Perl_newSTATEOP(pTHX_ I32 flags, char *label, OP *o)
3319 U32 seq = intro_my();
3322 NewOp(1101, cop, 1, COP);
3323 if (PERLDB_LINE && CopLINE(PL_curcop) && PL_curstash != PL_debstash) {
3324 cop->op_type = OP_DBSTATE;
3325 cop->op_ppaddr = PL_ppaddr[ OP_DBSTATE ];
3328 cop->op_type = OP_NEXTSTATE;
3329 cop->op_ppaddr = PL_ppaddr[ OP_NEXTSTATE ];
3331 cop->op_flags = flags;
3332 cop->op_private = (PL_hints & HINT_UTF8);
3334 cop->op_private |= NATIVE_HINTS;
3336 PL_compiling.op_private = cop->op_private;
3337 cop->op_next = (OP*)cop;
3340 cop->cop_label = label;
3341 PL_hints |= HINT_BLOCK_SCOPE;
3344 cop->cop_arybase = PL_curcop->cop_arybase;
3345 if (specialWARN(PL_curcop->cop_warnings))
3346 cop->cop_warnings = PL_curcop->cop_warnings ;
3348 cop->cop_warnings = newSVsv(PL_curcop->cop_warnings) ;
3351 if (PL_copline == NOLINE)
3352 CopLINE_set(cop, CopLINE(PL_curcop));
3354 CopLINE_set(cop, PL_copline);
3355 PL_copline = NOLINE;
3358 CopFILE_set(cop, CopFILE(PL_curcop)); /* XXXXX share in a pvtable? */
3360 CopFILEGV_set(cop, (GV*)SvREFCNT_inc(CopFILEGV(PL_curcop)));
3362 CopSTASH_set(cop, PL_curstash);
3364 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3365 SV **svp = av_fetch(CopFILEAV(PL_curcop), (I32)CopLINE(cop), FALSE);
3366 if (svp && *svp != &PL_sv_undef && !SvIOK(*svp)) {
3367 (void)SvIOK_on(*svp);
3368 SvIVX(*svp) = (IV)cop;
3372 return prepend_elem(OP_LINESEQ, (OP*)cop, o);
3375 /* "Introduce" my variables to visible status. */
3383 if (! PL_min_intro_pending)
3384 return PL_cop_seqmax;
3386 svp = AvARRAY(PL_comppad_name);
3387 for (i = PL_min_intro_pending; i <= PL_max_intro_pending; i++) {
3388 if ((sv = svp[i]) && sv != &PL_sv_undef && !SvIVX(sv)) {
3389 SvIVX(sv) = PAD_MAX; /* Don't know scope end yet. */
3390 SvNVX(sv) = (NV)PL_cop_seqmax;
3393 PL_min_intro_pending = 0;
3394 PL_comppad_name_fill = PL_max_intro_pending; /* Needn't search higher */
3395 return PL_cop_seqmax++;
3399 Perl_newLOGOP(pTHX_ I32 type, I32 flags, OP *first, OP *other)
3401 return new_logop(type, flags, &first, &other);
3405 S_new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp)
3410 OP *first = *firstp;
3411 OP *other = *otherp;
3413 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
3414 return newBINOP(type, flags, scalar(first), scalar(other));
3416 scalarboolean(first);
3417 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
3418 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
3419 if (type == OP_AND || type == OP_OR) {
3425 first = *firstp = cUNOPo->op_first;
3427 first->op_next = o->op_next;
3428 cUNOPo->op_first = Nullop;
3432 if (first->op_type == OP_CONST) {
3433 if (ckWARN(WARN_PRECEDENCE) && (first->op_private & OPpCONST_BARE))
3434 Perl_warner(aTHX_ WARN_PRECEDENCE, "Probable precedence problem on %s",
3436 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
3447 else if (first->op_type == OP_WANTARRAY) {
3453 else if (ckWARN(WARN_UNSAFE) && (first->op_flags & OPf_KIDS)) {
3454 OP *k1 = ((UNOP*)first)->op_first;
3455 OP *k2 = k1->op_sibling;
3457 switch (first->op_type)
3460 if (k2 && k2->op_type == OP_READLINE
3461 && (k2->op_flags & OPf_STACKED)
3462 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3464 warnop = k2->op_type;
3469 if (k1->op_type == OP_READDIR
3470 || k1->op_type == OP_GLOB
3471 || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
3472 || k1->op_type == OP_EACH)
3474 warnop = ((k1->op_type == OP_NULL)
3475 ? k1->op_targ : k1->op_type);
3480 line_t oldline = CopLINE(PL_curcop);
3481 CopLINE_set(PL_curcop, PL_copline);
3482 Perl_warner(aTHX_ WARN_UNSAFE,
3483 "Value of %s%s can be \"0\"; test with defined()",
3485 ((warnop == OP_READLINE || warnop == OP_GLOB)
3486 ? " construct" : "() operator"));
3487 CopLINE_set(PL_curcop, oldline);
3494 if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
3495 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
3497 NewOp(1101, logop, 1, LOGOP);
3499 logop->op_type = type;
3500 logop->op_ppaddr = PL_ppaddr[type];
3501 logop->op_first = first;
3502 logop->op_flags = flags | OPf_KIDS;
3503 logop->op_other = LINKLIST(other);
3504 logop->op_private = 1 | (flags >> 8);
3506 /* establish postfix order */
3507 logop->op_next = LINKLIST(first);
3508 first->op_next = (OP*)logop;
3509 first->op_sibling = other;
3511 o = newUNOP(OP_NULL, 0, (OP*)logop);
3518 Perl_newCONDOP(pTHX_ I32 flags, OP *first, OP *trueop, OP *falseop)
3526 return newLOGOP(OP_AND, 0, first, trueop);
3528 return newLOGOP(OP_OR, 0, first, falseop);
3530 scalarboolean(first);
3531 if (first->op_type == OP_CONST) {
3532 if (SvTRUE(((SVOP*)first)->op_sv)) {
3543 else if (first->op_type == OP_WANTARRAY) {
3547 NewOp(1101, logop, 1, LOGOP);
3548 logop->op_type = OP_COND_EXPR;
3549 logop->op_ppaddr = PL_ppaddr[OP_COND_EXPR];
3550 logop->op_first = first;
3551 logop->op_flags = flags | OPf_KIDS;
3552 logop->op_private = 1 | (flags >> 8);
3553 logop->op_other = LINKLIST(trueop);
3554 logop->op_next = LINKLIST(falseop);
3557 /* establish postfix order */
3558 start = LINKLIST(first);
3559 first->op_next = (OP*)logop;
3561 first->op_sibling = trueop;
3562 trueop->op_sibling = falseop;
3563 o = newUNOP(OP_NULL, 0, (OP*)logop);
3565 trueop->op_next = falseop->op_next = o;
3572 Perl_newRANGE(pTHX_ I32 flags, OP *left, OP *right)
3581 NewOp(1101, range, 1, LOGOP);
3583 range->op_type = OP_RANGE;
3584 range->op_ppaddr = PL_ppaddr[OP_RANGE];
3585 range->op_first = left;
3586 range->op_flags = OPf_KIDS;
3587 leftstart = LINKLIST(left);
3588 range->op_other = LINKLIST(right);
3589 range->op_private = 1 | (flags >> 8);
3591 left->op_sibling = right;
3593 range->op_next = (OP*)range;
3594 flip = newUNOP(OP_FLIP, flags, (OP*)range);
3595 flop = newUNOP(OP_FLOP, 0, flip);
3596 o = newUNOP(OP_NULL, 0, flop);
3598 range->op_next = leftstart;
3600 left->op_next = flip;
3601 right->op_next = flop;
3603 range->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
3604 sv_upgrade(PAD_SV(range->op_targ), SVt_PVNV);
3605 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
3606 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
3608 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
3609 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
3612 if (!flip->op_private || !flop->op_private)
3613 linklist(o); /* blow off optimizer unless constant */
3619 Perl_newLOOPOP(pTHX_ I32 flags, I32 debuggable, OP *expr, OP *block)
3624 int once = block && block->op_flags & OPf_SPECIAL &&
3625 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
3628 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
3629 return block; /* do {} while 0 does once */
3630 if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
3631 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB)) {
3632 expr = newUNOP(OP_DEFINED, 0,
3633 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
3634 } else if (expr->op_flags & OPf_KIDS) {
3635 OP *k1 = ((UNOP*)expr)->op_first;
3636 OP *k2 = (k1) ? k1->op_sibling : NULL;
3637 switch (expr->op_type) {
3639 if (k2 && k2->op_type == OP_READLINE
3640 && (k2->op_flags & OPf_STACKED)
3641 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3642 expr = newUNOP(OP_DEFINED, 0, expr);
3646 if (k1->op_type == OP_READDIR
3647 || k1->op_type == OP_GLOB
3648 || (k1->op_type == OP_NULL && k1->op_targ == OP_NULL)
3649 || k1->op_type == OP_EACH)
3650 expr = newUNOP(OP_DEFINED, 0, expr);
3656 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
3657 o = new_logop(OP_AND, 0, &expr, &listop);
3660 ((LISTOP*)listop)->op_last->op_next = LINKLIST(o);
3662 if (once && o != listop)
3663 o->op_next = ((LOGOP*)cUNOPo->op_first)->op_other;
3666 o = newUNOP(OP_NULL, 0, o); /* or do {} while 1 loses outer block */
3668 o->op_flags |= flags;
3670 o->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/
3675 Perl_newWHILEOP(pTHX_ I32 flags, I32 debuggable, LOOP *loop, I32 whileline, OP *expr, OP *block, OP *cont)
3684 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
3685 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB))) {
3686 expr = newUNOP(OP_DEFINED, 0,
3687 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
3688 } else if (expr && (expr->op_flags & OPf_KIDS)) {
3689 OP *k1 = ((UNOP*)expr)->op_first;
3690 OP *k2 = (k1) ? k1->op_sibling : NULL;
3691 switch (expr->op_type) {
3693 if (k2 && k2->op_type == OP_READLINE
3694 && (k2->op_flags & OPf_STACKED)
3695 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3696 expr = newUNOP(OP_DEFINED, 0, expr);
3700 if (k1->op_type == OP_READDIR
3701 || k1->op_type == OP_GLOB
3702 || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
3703 || k1->op_type == OP_EACH)
3704 expr = newUNOP(OP_DEFINED, 0, expr);
3710 block = newOP(OP_NULL, 0);
3713 next = LINKLIST(cont);
3715 cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
3716 if ((line_t)whileline != NOLINE) {
3717 PL_copline = whileline;
3718 cont = append_elem(OP_LINESEQ, cont,
3719 newSTATEOP(0, Nullch, Nullop));
3723 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
3724 redo = LINKLIST(listop);
3727 PL_copline = whileline;
3729 o = new_logop(OP_AND, 0, &expr, &listop);
3730 if (o == expr && o->op_type == OP_CONST && !SvTRUE(cSVOPo->op_sv)) {
3731 op_free(expr); /* oops, it's a while (0) */
3733 return Nullop; /* listop already freed by new_logop */
3736 ((LISTOP*)listop)->op_last->op_next = condop =
3737 (o == listop ? redo : LINKLIST(o));
3745 NewOp(1101,loop,1,LOOP);
3746 loop->op_type = OP_ENTERLOOP;
3747 loop->op_ppaddr = PL_ppaddr[OP_ENTERLOOP];
3748 loop->op_private = 0;
3749 loop->op_next = (OP*)loop;
3752 o = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, o);
3754 loop->op_redoop = redo;
3755 loop->op_lastop = o;
3758 loop->op_nextop = next;
3760 loop->op_nextop = o;
3762 o->op_flags |= flags;
3763 o->op_private |= (flags >> 8);
3768 Perl_newFOROP(pTHX_ I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
3777 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
3778 sv->op_type = OP_RV2GV;
3779 sv->op_ppaddr = PL_ppaddr[OP_RV2GV];
3781 else if (sv->op_type == OP_PADSV) { /* private variable */
3782 padoff = sv->op_targ;
3787 else if (sv->op_type == OP_THREADSV) { /* per-thread variable */
3788 padoff = sv->op_targ;
3790 iterflags |= OPf_SPECIAL;
3795 Perl_croak(aTHX_ "Can't use %s for loop variable", PL_op_desc[sv->op_type]);
3799 padoff = find_threadsv("_");
3800 iterflags |= OPf_SPECIAL;
3802 sv = newGVOP(OP_GV, 0, PL_defgv);
3805 if (expr->op_type == OP_RV2AV || expr->op_type == OP_PADAV) {
3806 expr = mod(force_list(scalar(ref(expr, OP_ITER))), OP_GREPSTART);
3807 iterflags |= OPf_STACKED;
3809 else if (expr->op_type == OP_NULL &&
3810 (expr->op_flags & OPf_KIDS) &&
3811 ((BINOP*)expr)->op_first->op_type == OP_FLOP)
3813 /* Basically turn for($x..$y) into the same as for($x,$y), but we
3814 * set the STACKED flag to indicate that these values are to be
3815 * treated as min/max values by 'pp_iterinit'.
3817 UNOP* flip = (UNOP*)((UNOP*)((BINOP*)expr)->op_first)->op_first;
3818 LOGOP* range = (LOGOP*) flip->op_first;
3819 OP* left = range->op_first;
3820 OP* right = left->op_sibling;
3823 range->op_flags &= ~OPf_KIDS;
3824 range->op_first = Nullop;
3826 listop = (LISTOP*)newLISTOP(OP_LIST, 0, left, right);
3827 listop->op_first->op_next = range->op_next;
3828 left->op_next = range->op_other;
3829 right->op_next = (OP*)listop;
3830 listop->op_next = listop->op_first;
3833 expr = (OP*)(listop);
3835 iterflags |= OPf_STACKED;
3838 expr = mod(force_list(expr), OP_GREPSTART);
3842 loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
3843 append_elem(OP_LIST, expr, scalar(sv))));
3844 assert(!loop->op_next);
3845 #ifdef PL_OP_SLAB_ALLOC
3846 NewOp(1234,tmp,1,LOOP);
3847 Copy(loop,tmp,1,LOOP);
3850 Renew(loop, 1, LOOP);
3852 loop->op_targ = padoff;
3853 wop = newWHILEOP(flags, 1, loop, forline, newOP(OP_ITER, 0), block, cont);
3854 PL_copline = forline;
3855 return newSTATEOP(0, label, wop);
3859 Perl_newLOOPEX(pTHX_ I32 type, OP *label)
3865 if (type != OP_GOTO || label->op_type == OP_CONST) {
3866 /* "last()" means "last" */
3867 if (label->op_type == OP_STUB && (label->op_flags & OPf_PARENS))
3868 o = newOP(type, OPf_SPECIAL);
3870 o = newPVOP(type, 0, savepv(label->op_type == OP_CONST
3871 ? SvPVx(((SVOP*)label)->op_sv, n_a)
3877 if (label->op_type == OP_ENTERSUB)
3878 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
3879 o = newUNOP(type, OPf_STACKED, label);
3881 PL_hints |= HINT_BLOCK_SCOPE;
3886 Perl_cv_undef(pTHX_ CV *cv)
3891 MUTEX_DESTROY(CvMUTEXP(cv));
3892 Safefree(CvMUTEXP(cv));
3895 #endif /* USE_THREADS */
3897 if (!CvXSUB(cv) && CvROOT(cv)) {
3899 if (CvDEPTH(cv) || (CvOWNER(cv) && CvOWNER(cv) != thr))
3900 Perl_croak(aTHX_ "Can't undef active subroutine");
3903 Perl_croak(aTHX_ "Can't undef active subroutine");
3904 #endif /* USE_THREADS */
3907 SAVEVPTR(PL_curpad);
3911 op_free(CvROOT(cv));
3912 CvROOT(cv) = Nullop;
3915 SvPOK_off((SV*)cv); /* forget prototype */
3917 SvREFCNT_dec(CvGV(cv));
3919 SvREFCNT_dec(CvOUTSIDE(cv));
3920 CvOUTSIDE(cv) = Nullcv;
3921 if (CvPADLIST(cv)) {
3922 /* may be during global destruction */
3923 if (SvREFCNT(CvPADLIST(cv))) {
3924 I32 i = AvFILLp(CvPADLIST(cv));
3926 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
3927 SV* sv = svp ? *svp : Nullsv;
3930 if (sv == (SV*)PL_comppad_name)
3931 PL_comppad_name = Nullav;
3932 else if (sv == (SV*)PL_comppad) {
3933 PL_comppad = Nullav;
3934 PL_curpad = Null(SV**);
3938 SvREFCNT_dec((SV*)CvPADLIST(cv));
3940 CvPADLIST(cv) = Nullav;
3945 S_cv_dump(pTHX_ CV *cv)
3948 CV *outside = CvOUTSIDE(cv);
3949 AV* padlist = CvPADLIST(cv);
3956 PerlIO_printf(Perl_debug_log,
3957 "\tCV=0x%"UVxf" (%s), OUTSIDE=0x%"UVxf" (%s)\n",
3959 (CvANON(cv) ? "ANON"
3960 : (cv == PL_main_cv) ? "MAIN"
3961 : CvUNIQUE(cv) ? "UNIQUE"
3962 : CvGV(cv) ? GvNAME(CvGV(cv)) : "UNDEFINED"),
3965 : CvANON(outside) ? "ANON"
3966 : (outside == PL_main_cv) ? "MAIN"
3967 : CvUNIQUE(outside) ? "UNIQUE"
3968 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
3973 pad_name = (AV*)*av_fetch(padlist, 0, FALSE);
3974 pad = (AV*)*av_fetch(padlist, 1, FALSE);
3975 pname = AvARRAY(pad_name);
3976 ppad = AvARRAY(pad);
3978 for (ix = 1; ix <= AvFILLp(pad_name); ix++) {
3979 if (SvPOK(pname[ix]))
3980 PerlIO_printf(Perl_debug_log,
3981 "\t%4d. 0x%"UVxf" (%s\"%s\" %"IVdf"-%"IVdf")\n",
3982 ix, PTR2UV(ppad[ix]),
3983 SvFAKE(pname[ix]) ? "FAKE " : "",
3985 (IV)I_32(SvNVX(pname[ix])),
3988 #endif /* DEBUGGING */
3992 S_cv_clone2(pTHX_ CV *proto, CV *outside)
3997 AV* protopadlist = CvPADLIST(proto);
3998 AV* protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
3999 AV* protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
4000 SV** pname = AvARRAY(protopad_name);
4001 SV** ppad = AvARRAY(protopad);
4002 I32 fname = AvFILLp(protopad_name);
4003 I32 fpad = AvFILLp(protopad);
4007 assert(!CvUNIQUE(proto));
4010 SAVEVPTR(PL_curpad);
4011 SAVESPTR(PL_comppad);
4012 SAVESPTR(PL_comppad_name);
4013 SAVESPTR(PL_compcv);
4015 cv = PL_compcv = (CV*)NEWSV(1104,0);
4016 sv_upgrade((SV *)cv, SvTYPE(proto));
4022 New(666, CvMUTEXP(cv), 1, perl_mutex);
4023 MUTEX_INIT(CvMUTEXP(cv));
4025 #endif /* USE_THREADS */
4026 CvFILE(cv) = CvFILE(proto);
4027 CvGV(cv) = (GV*)SvREFCNT_inc(CvGV(proto));
4028 CvSTASH(cv) = CvSTASH(proto);
4029 CvROOT(cv) = CvROOT(proto);
4030 CvSTART(cv) = CvSTART(proto);
4032 CvOUTSIDE(cv) = (CV*)SvREFCNT_inc(outside);
4035 sv_setpvn((SV*)cv, SvPVX(proto), SvCUR(proto));
4037 PL_comppad_name = newAV();
4038 for (ix = fname; ix >= 0; ix--)
4039 av_store(PL_comppad_name, ix, SvREFCNT_inc(pname[ix]));
4041 PL_comppad = newAV();
4043 comppadlist = newAV();
4044 AvREAL_off(comppadlist);
4045 av_store(comppadlist, 0, (SV*)PL_comppad_name);
4046 av_store(comppadlist, 1, (SV*)PL_comppad);
4047 CvPADLIST(cv) = comppadlist;
4048 av_fill(PL_comppad, AvFILLp(protopad));
4049 PL_curpad = AvARRAY(PL_comppad);
4051 av = newAV(); /* will be @_ */
4053 av_store(PL_comppad, 0, (SV*)av);
4054 AvFLAGS(av) = AVf_REIFY;
4056 for (ix = fpad; ix > 0; ix--) {
4057 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
4058 if (namesv && namesv != &PL_sv_undef) {
4059 char *name = SvPVX(namesv); /* XXX */
4060 if (SvFLAGS(namesv) & SVf_FAKE) { /* lexical from outside? */
4061 I32 off = pad_findlex(name, ix, SvIVX(namesv),
4062 CvOUTSIDE(cv), cxstack_ix, 0, 0);
4064 PL_curpad[ix] = SvREFCNT_inc(ppad[ix]);
4066 Perl_croak(aTHX_ "panic: cv_clone: %s", name);
4068 else { /* our own lexical */
4071 /* anon code -- we'll come back for it */
4072 sv = SvREFCNT_inc(ppad[ix]);
4074 else if (*name == '@')
4076 else if (*name == '%')
4085 else if (IS_PADGV(ppad[ix]) || IS_PADCONST(ppad[ix])) {
4086 PL_curpad[ix] = SvREFCNT_inc(ppad[ix]);
4089 SV* sv = NEWSV(0,0);
4095 /* Now that vars are all in place, clone nested closures. */
4097 for (ix = fpad; ix > 0; ix--) {
4098 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
4100 && namesv != &PL_sv_undef
4101 && !(SvFLAGS(namesv) & SVf_FAKE)
4102 && *SvPVX(namesv) == '&'
4103 && CvCLONE(ppad[ix]))
4105 CV *kid = cv_clone2((CV*)ppad[ix], cv);
4106 SvREFCNT_dec(ppad[ix]);
4109 PL_curpad[ix] = (SV*)kid;
4113 #ifdef DEBUG_CLOSURES
4114 PerlIO_printf(Perl_debug_log, "Cloned inside:\n");
4116 PerlIO_printf(Perl_debug_log, " from:\n");
4118 PerlIO_printf(Perl_debug_log, " to:\n");
4127 Perl_cv_clone(pTHX_ CV *proto)
4130 MUTEX_LOCK(&PL_cred_mutex); /* XXX create separate mutex */
4131 cv = cv_clone2(proto, CvOUTSIDE(proto));
4132 MUTEX_UNLOCK(&PL_cred_mutex); /* XXX create separate mutex */
4137 Perl_cv_ckproto(pTHX_ CV *cv, GV *gv, char *p)
4141 if (((!p != !SvPOK(cv)) || (p && strNE(p, SvPVX(cv)))) && ckWARN_d(WARN_UNSAFE)) {
4142 SV* msg = sv_newmortal();
4146 gv_efullname3(name = sv_newmortal(), gv, Nullch);
4147 sv_setpv(msg, "Prototype mismatch:");
4149 Perl_sv_catpvf(aTHX_ msg, " sub %_", name);
4151 Perl_sv_catpvf(aTHX_ msg, " (%s)", SvPVX(cv));
4152 sv_catpv(msg, " vs ");
4154 Perl_sv_catpvf(aTHX_ msg, "(%s)", p);
4156 sv_catpv(msg, "none");
4157 Perl_warner(aTHX_ WARN_UNSAFE, "%_", msg);
4162 Perl_cv_const_sv(pTHX_ CV *cv)
4164 if (!cv || !SvPOK(cv) || SvCUR(cv))
4166 return op_const_sv(CvSTART(cv), cv);
4170 Perl_op_const_sv(pTHX_ OP *o, CV *cv)
4177 if(o->op_type == OP_LINESEQ && cLISTOPo->op_first)
4178 o = cLISTOPo->op_first->op_sibling;
4180 for (; o; o = o->op_next) {
4181 OPCODE type = o->op_type;
4183 if (sv && o->op_next == o)
4185 if (type == OP_NEXTSTATE || type == OP_NULL || type == OP_PUSHMARK)
4187 if (type == OP_LEAVESUB || type == OP_RETURN)
4191 if (type == OP_CONST && cSVOPo->op_sv)
4193 else if ((type == OP_PADSV || type == OP_CONST) && cv) {
4194 AV* padav = (AV*)(AvARRAY(CvPADLIST(cv))[1]);
4195 sv = padav ? AvARRAY(padav)[o->op_targ] : Nullsv;
4196 if (!sv || (!SvREADONLY(sv) && SvREFCNT(sv) > 1))
4208 Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
4218 Perl_croak(aTHX_ "\"my sub\" not yet implemented");
4222 Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block)
4224 return Perl_newATTRSUB(aTHX_ floor, o, proto, Nullop, block);
4228 Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
4232 char *name = o ? SvPVx(cSVOPo->op_sv, n_a) : Nullch;
4233 GV *gv = gv_fetchpv(name ? name : "__ANON__",
4234 GV_ADDMULTI | ((block || attrs) ? 0 : GV_NOINIT),
4236 char *ps = proto ? SvPVx(((SVOP*)proto)->op_sv, n_a) : Nullch;
4247 if (SvTYPE(gv) != SVt_PVGV) { /* Maybe prototype now, and had at
4248 maximum a prototype before. */
4249 if (SvTYPE(gv) > SVt_NULL) {
4250 if (!SvPOK((SV*)gv) && !(SvIOK((SV*)gv) && SvIVX((SV*)gv) == -1)
4251 && ckWARN_d(WARN_UNSAFE))
4253 Perl_warner(aTHX_ WARN_UNSAFE, "Runaway prototype");
4255 cv_ckproto((CV*)gv, NULL, ps);
4258 sv_setpv((SV*)gv, ps);
4260 sv_setiv((SV*)gv, -1);
4261 SvREFCNT_dec(PL_compcv);
4262 cv = PL_compcv = NULL;
4263 PL_sub_generation++;
4267 if (!name || GvCVGEN(gv))
4269 else if (cv = GvCV(gv)) {
4270 cv_ckproto(cv, gv, ps);
4271 /* already defined (or promised)? */
4272 if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
4274 bool const_changed = TRUE;
4275 if (!block && !attrs) {
4276 /* just a "sub foo;" when &foo is already defined */
4277 SAVEFREESV(PL_compcv);
4280 /* ahem, death to those who redefine active sort subs */
4281 if (PL_curstackinfo->si_type == PERLSI_SORT && PL_sortcop == CvSTART(cv))
4282 Perl_croak(aTHX_ "Can't redefine active sort subroutine %s", name);
4285 if(const_sv = cv_const_sv(cv))
4286 const_changed = sv_cmp(const_sv, op_const_sv(block, Nullcv));
4287 if ((const_sv && const_changed) || ckWARN(WARN_REDEFINE)
4288 && !(CvGV(cv) && GvSTASH(CvGV(cv))
4289 && HvNAME(GvSTASH(CvGV(cv)))
4290 && strEQ(HvNAME(GvSTASH(CvGV(cv))),
4292 line_t oldline = CopLINE(PL_curcop);
4293 CopLINE_set(PL_curcop, PL_copline);
4294 Perl_warner(aTHX_ WARN_REDEFINE,
4295 const_sv ? "Constant subroutine %s redefined"
4296 : "Subroutine %s redefined", name);
4297 CopLINE_set(PL_curcop, oldline);
4308 /* Need to do a C<use attributes $stash_of_cv,\&cv,@attrs>
4309 * before we clobber PL_compcv.
4313 if (CvGV(cv) && GvSTASH(CvGV(cv)) && HvNAME(GvSTASH(CvGV(cv))))
4314 stash = GvSTASH(CvGV(cv));
4315 else if (CvSTASH(cv) && HvNAME(CvSTASH(cv)))
4316 stash = CvSTASH(cv);
4318 stash = PL_curstash;
4321 /* possibly about to re-define existing subr -- ignore old cv */
4322 rcv = (SV*)PL_compcv;
4323 if (name && GvSTASH(gv) && HvNAME(GvSTASH(gv)))
4324 stash = GvSTASH(gv);
4326 stash = PL_curstash;
4328 apply_attrs(stash, rcv, attrs);
4330 if (cv) { /* must reuse cv if autoloaded */
4332 /* got here with just attrs -- work done, so bug out */
4333 SAVEFREESV(PL_compcv);
4337 CvFLAGS(cv) = CvFLAGS(PL_compcv);
4338 CvOUTSIDE(cv) = CvOUTSIDE(PL_compcv);
4339 CvOUTSIDE(PL_compcv) = 0;
4340 CvPADLIST(cv) = CvPADLIST(PL_compcv);
4341 CvPADLIST(PL_compcv) = 0;
4342 if (SvREFCNT(PL_compcv) > 1) /* XXX Make closures transit through stub. */
4343 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc((SV*)cv);
4344 SvREFCNT_dec(PL_compcv);
4351 PL_sub_generation++;
4354 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4355 CvFILE(cv) = CopFILE(PL_curcop);
4356 CvSTASH(cv) = PL_curstash;
4359 if (!CvMUTEXP(cv)) {
4360 New(666, CvMUTEXP(cv), 1, perl_mutex);
4361 MUTEX_INIT(CvMUTEXP(cv));
4363 #endif /* USE_THREADS */
4366 sv_setpv((SV*)cv, ps);
4368 if (PL_error_count) {
4372 char *s = strrchr(name, ':');
4374 if (strEQ(s, "BEGIN")) {
4376 "BEGIN not safe after errors--compilation aborted";
4377 if (PL_in_eval & EVAL_KEEPERR)
4378 Perl_croak(aTHX_ not_safe);
4380 /* force display of errors found but not reported */
4381 sv_catpv(ERRSV, not_safe);
4382 Perl_croak(aTHX_ "%s", SvPVx(ERRSV, n_a));
4389 PL_copline = NOLINE;
4394 if (AvFILLp(PL_comppad_name) < AvFILLp(PL_comppad))
4395 av_store(PL_comppad_name, AvFILLp(PL_comppad), Nullsv);
4398 CvROOT(cv) = newUNOP(OP_LEAVESUBLV, 0, scalarseq(block));
4401 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
4403 CvROOT(cv)->op_private |= OPpREFCOUNTED;
4404 OpREFCNT_set(CvROOT(cv), 1);
4405 CvSTART(cv) = LINKLIST(CvROOT(cv));
4406 CvROOT(cv)->op_next = 0;
4409 /* now that optimizer has done its work, adjust pad values */
4411 SV **namep = AvARRAY(PL_comppad_name);
4412 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4415 if (SvIMMORTAL(PL_curpad[ix]) || IS_PADGV(PL_curpad[ix]) || IS_PADCONST(PL_curpad[ix]))
4418 * The only things that a clonable function needs in its
4419 * pad are references to outer lexicals and anonymous subs.
4420 * The rest are created anew during cloning.
4422 if (!((namesv = namep[ix]) != Nullsv &&
4423 namesv != &PL_sv_undef &&
4425 *SvPVX(namesv) == '&')))
4427 SvREFCNT_dec(PL_curpad[ix]);
4428 PL_curpad[ix] = Nullsv;
4433 AV *av = newAV(); /* Will be @_ */
4435 av_store(PL_comppad, 0, (SV*)av);
4436 AvFLAGS(av) = AVf_REIFY;
4438 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4439 if (SvIMMORTAL(PL_curpad[ix]) || IS_PADGV(PL_curpad[ix]) || IS_PADCONST(PL_curpad[ix]))
4441 if (!SvPADMY(PL_curpad[ix]))
4442 SvPADTMP_on(PL_curpad[ix]);
4449 if (PERLDB_SUBLINE && PL_curstash != PL_debstash) {
4450 SV *sv = NEWSV(0,0);
4451 SV *tmpstr = sv_newmortal();
4452 GV *db_postponed = gv_fetchpv("DB::postponed", GV_ADDMULTI, SVt_PVHV);
4456 Perl_sv_setpvf(aTHX_ sv, "%s:%ld-%ld",
4458 (long)PL_subline, (long)CopLINE(PL_curcop));
4459 gv_efullname3(tmpstr, gv, Nullch);
4460 hv_store(GvHV(PL_DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
4461 hv = GvHVn(db_postponed);
4462 if (HvFILL(hv) > 0 && hv_exists(hv, SvPVX(tmpstr), SvCUR(tmpstr))
4463 && (cv = GvCV(db_postponed))) {
4468 call_sv((SV*)cv, G_DISCARD);
4472 if ((s = strrchr(name,':')))
4477 if (*s != 'B' && *s != 'E' && *s != 'S' && *s != 'I')
4480 if (strEQ(s, "BEGIN")) {
4481 I32 oldscope = PL_scopestack_ix;
4483 SAVECOPFILE(&PL_compiling);
4484 SAVECOPLINE(&PL_compiling);
4486 sv_setsv(PL_rs, PL_nrs);
4489 PL_beginav = newAV();
4490 DEBUG_x( dump_sub(gv) );
4491 av_push(PL_beginav, SvREFCNT_inc(cv));
4493 call_list(oldscope, PL_beginav);
4495 PL_curcop = &PL_compiling;
4496 PL_compiling.op_private = PL_hints;
4499 else if (strEQ(s, "END") && !PL_error_count) {
4502 DEBUG_x( dump_sub(gv) );
4503 av_unshift(PL_endav, 1);
4504 av_store(PL_endav, 0, SvREFCNT_inc(cv));
4507 else if (strEQ(s, "STOP") && !PL_error_count) {
4509 PL_stopav = newAV();
4510 DEBUG_x( dump_sub(gv) );
4511 av_unshift(PL_stopav, 1);
4512 av_store(PL_stopav, 0, SvREFCNT_inc(cv));
4515 else if (strEQ(s, "INIT") && !PL_error_count) {
4517 PL_initav = newAV();
4518 DEBUG_x( dump_sub(gv) );
4519 av_push(PL_initav, SvREFCNT_inc(cv));
4525 PL_copline = NOLINE;
4530 /* XXX unsafe for threads if eval_owner isn't held */
4532 Perl_newCONSTSUB(pTHX_ HV *stash, char *name, SV *sv)
4537 SAVECOPLINE(PL_curcop);
4540 CopLINE_set(PL_curcop, PL_copline);
4541 PL_hints &= ~HINT_BLOCK_SCOPE;
4544 SAVESPTR(PL_curstash);
4545 SAVECOPSTASH(PL_curcop);
4546 PL_curstash = stash;
4548 CopSTASHPV(PL_curcop) = stash ? HvNAME(stash) : Nullch;
4550 CopSTASH(PL_curcop) = stash;
4555 start_subparse(FALSE, 0),
4556 newSVOP(OP_CONST, 0, newSVpv(name,0)),
4557 newSVOP(OP_CONST, 0, &PL_sv_no), /* SvPV(&PL_sv_no) == "" -- GMB */
4559 newSTATEOP(0, Nullch, newSVOP(OP_CONST, 0, sv))
4566 Perl_newXS(pTHX_ char *name, XSUBADDR_t subaddr, char *filename)
4569 GV *gv = gv_fetchpv(name ? name : "__ANON__", GV_ADDMULTI, SVt_PVCV);
4572 if (cv = (name ? GvCV(gv) : Nullcv)) {
4574 /* just a cached method */
4578 else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
4579 /* already defined (or promised) */
4580 if (ckWARN(WARN_REDEFINE) && !(CvGV(cv) && GvSTASH(CvGV(cv))
4581 && HvNAME(GvSTASH(CvGV(cv)))
4582 && strEQ(HvNAME(GvSTASH(CvGV(cv))), "autouse"))) {
4583 line_t oldline = CopLINE(PL_curcop);
4584 if (PL_copline != NOLINE)
4585 CopLINE_set(PL_curcop, PL_copline);
4586 Perl_warner(aTHX_ WARN_REDEFINE, "Subroutine %s redefined",name);
4587 CopLINE_set(PL_curcop, oldline);
4594 if (cv) /* must reuse cv if autoloaded */
4597 cv = (CV*)NEWSV(1105,0);
4598 sv_upgrade((SV *)cv, SVt_PVCV);
4602 PL_sub_generation++;
4605 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4607 New(666, CvMUTEXP(cv), 1, perl_mutex);
4608 MUTEX_INIT(CvMUTEXP(cv));
4610 #endif /* USE_THREADS */
4611 (void)gv_fetchfile(filename);
4612 CvFILE(cv) = filename; /* NOTE: not copied, as it is expected to be
4613 an external constant string */
4614 CvXSUB(cv) = subaddr;
4617 char *s = strrchr(name,':');
4623 if (*s != 'B' && *s != 'E' && *s != 'S' && *s != 'I')
4626 if (strEQ(s, "BEGIN")) {
4628 PL_beginav = newAV();
4629 av_push(PL_beginav, SvREFCNT_inc(cv));
4632 else if (strEQ(s, "END")) {
4635 av_unshift(PL_endav, 1);
4636 av_store(PL_endav, 0, SvREFCNT_inc(cv));
4639 else if (strEQ(s, "STOP")) {
4641 PL_stopav = newAV();
4642 av_unshift(PL_stopav, 1);
4643 av_store(PL_stopav, 0, SvREFCNT_inc(cv));
4646 else if (strEQ(s, "INIT")) {
4648 PL_initav = newAV();
4649 av_push(PL_initav, SvREFCNT_inc(cv));
4661 Perl_newFORM(pTHX_ I32 floor, OP *o, OP *block)
4671 name = SvPVx(cSVOPo->op_sv, n_a);
4674 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
4676 if (cv = GvFORM(gv)) {
4677 if (ckWARN(WARN_REDEFINE)) {
4678 line_t oldline = CopLINE(PL_curcop);
4680 CopLINE_set(PL_curcop, PL_copline);
4681 Perl_warner(aTHX_ WARN_REDEFINE, "Format %s redefined",name);
4682 CopLINE_set(PL_curcop, oldline);
4688 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4689 CvFILE(cv) = CopFILE(PL_curcop);
4691 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4692 if (!SvPADMY(PL_curpad[ix]) && !SvIMMORTAL(PL_curpad[ix]))
4693 SvPADTMP_on(PL_curpad[ix]);
4696 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
4697 CvROOT(cv)->op_private |= OPpREFCOUNTED;
4698 OpREFCNT_set(CvROOT(cv), 1);
4699 CvSTART(cv) = LINKLIST(CvROOT(cv));
4700 CvROOT(cv)->op_next = 0;
4703 PL_copline = NOLINE;
4708 Perl_newANONLIST(pTHX_ OP *o)
4710 return newUNOP(OP_REFGEN, 0,
4711 mod(list(convert(OP_ANONLIST, 0, o)), OP_REFGEN));
4715 Perl_newANONHASH(pTHX_ OP *o)
4717 return newUNOP(OP_REFGEN, 0,
4718 mod(list(convert(OP_ANONHASH, 0, o)), OP_REFGEN));
4722 Perl_newANONSUB(pTHX_ I32 floor, OP *proto, OP *block)
4724 return newANONATTRSUB(floor, proto, Nullop, block);
4728 Perl_newANONATTRSUB(pTHX_ I32 floor, OP *proto, OP *attrs, OP *block)
4730 return newUNOP(OP_REFGEN, 0,
4731 newSVOP(OP_ANONCODE, 0,
4732 (SV*)newATTRSUB(floor, 0, proto, attrs, block)));
4736 Perl_oopsAV(pTHX_ OP *o)
4738 switch (o->op_type) {
4740 o->op_type = OP_PADAV;
4741 o->op_ppaddr = PL_ppaddr[OP_PADAV];
4742 return ref(o, OP_RV2AV);
4745 o->op_type = OP_RV2AV;
4746 o->op_ppaddr = PL_ppaddr[OP_RV2AV];
4751 if (ckWARN_d(WARN_INTERNAL))
4752 Perl_warner(aTHX_ WARN_INTERNAL, "oops: oopsAV");
4759 Perl_oopsHV(pTHX_ OP *o)
4763 switch (o->op_type) {
4766 o->op_type = OP_PADHV;
4767 o->op_ppaddr = PL_ppaddr[OP_PADHV];
4768 return ref(o, OP_RV2HV);
4772 o->op_type = OP_RV2HV;
4773 o->op_ppaddr = PL_ppaddr[OP_RV2HV];
4778 if (ckWARN_d(WARN_INTERNAL))
4779 Perl_warner(aTHX_ WARN_INTERNAL, "oops: oopsHV");
4786 Perl_newAVREF(pTHX_ OP *o)
4788 if (o->op_type == OP_PADANY) {
4789 o->op_type = OP_PADAV;
4790 o->op_ppaddr = PL_ppaddr[OP_PADAV];
4793 return newUNOP(OP_RV2AV, 0, scalar(o));
4797 Perl_newGVREF(pTHX_ I32 type, OP *o)
4799 if (type == OP_MAPSTART || type == OP_GREPSTART || type == OP_SORT)
4800 return newUNOP(OP_NULL, 0, o);
4801 return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
4805 Perl_newHVREF(pTHX_ OP *o)
4807 if (o->op_type == OP_PADANY) {
4808 o->op_type = OP_PADHV;
4809 o->op_ppaddr = PL_ppaddr[OP_PADHV];
4812 return newUNOP(OP_RV2HV, 0, scalar(o));
4816 Perl_oopsCV(pTHX_ OP *o)
4818 Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
4824 Perl_newCVREF(pTHX_ I32 flags, OP *o)
4826 return newUNOP(OP_RV2CV, flags, scalar(o));
4830 Perl_newSVREF(pTHX_ OP *o)
4832 if (o->op_type == OP_PADANY) {
4833 o->op_type = OP_PADSV;
4834 o->op_ppaddr = PL_ppaddr[OP_PADSV];
4837 else if (o->op_type == OP_THREADSV && !(o->op_flags & OPpDONE_SVREF)) {
4838 o->op_flags |= OPpDONE_SVREF;
4841 return newUNOP(OP_RV2SV, 0, scalar(o));
4844 /* Check routines. */
4847 Perl_ck_anoncode(pTHX_ OP *o)
4852 name = NEWSV(1106,0);
4853 sv_upgrade(name, SVt_PVNV);
4854 sv_setpvn(name, "&", 1);
4857 ix = pad_alloc(o->op_type, SVs_PADMY);
4858 av_store(PL_comppad_name, ix, name);
4859 av_store(PL_comppad, ix, cSVOPo->op_sv);
4860 SvPADMY_on(cSVOPo->op_sv);
4861 cSVOPo->op_sv = Nullsv;
4862 cSVOPo->op_targ = ix;
4867 Perl_ck_bitop(pTHX_ OP *o)
4869 o->op_private = PL_hints;
4874 Perl_ck_concat(pTHX_ OP *o)
4876 if (cUNOPo->op_first->op_type == OP_CONCAT)
4877 o->op_flags |= OPf_STACKED;
4882 Perl_ck_spair(pTHX_ OP *o)
4884 if (o->op_flags & OPf_KIDS) {
4887 OPCODE type = o->op_type;
4888 o = modkids(ck_fun(o), type);
4889 kid = cUNOPo->op_first;
4890 newop = kUNOP->op_first->op_sibling;
4892 (newop->op_sibling ||
4893 !(PL_opargs[newop->op_type] & OA_RETSCALAR) ||
4894 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
4895 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
4899 op_free(kUNOP->op_first);
4900 kUNOP->op_first = newop;
4902 o->op_ppaddr = PL_ppaddr[++o->op_type];
4907 Perl_ck_delete(pTHX_ OP *o)
4911 if (o->op_flags & OPf_KIDS) {
4912 OP *kid = cUNOPo->op_first;
4913 if (kid->op_type == OP_HSLICE)
4914 o->op_private |= OPpSLICE;
4915 else if (kid->op_type != OP_HELEM)
4916 Perl_croak(aTHX_ "%s argument is not a HASH element or slice",
4917 PL_op_desc[o->op_type]);
4924 Perl_ck_eof(pTHX_ OP *o)
4926 I32 type = o->op_type;
4928 if (o->op_flags & OPf_KIDS) {
4929 if (cLISTOPo->op_first->op_type == OP_STUB) {
4931 o = newUNOP(type, OPf_SPECIAL,
4932 newGVOP(OP_GV, 0, gv_fetchpv("main::ARGV", TRUE, SVt_PVAV)));
4940 Perl_ck_eval(pTHX_ OP *o)
4942 PL_hints |= HINT_BLOCK_SCOPE;
4943 if (o->op_flags & OPf_KIDS) {
4944 SVOP *kid = (SVOP*)cUNOPo->op_first;
4947 o->op_flags &= ~OPf_KIDS;
4950 else if (kid->op_type == OP_LINESEQ) {
4953 kid->op_next = o->op_next;
4954 cUNOPo->op_first = 0;
4957 NewOp(1101, enter, 1, LOGOP);
4958 enter->op_type = OP_ENTERTRY;
4959 enter->op_ppaddr = PL_ppaddr[OP_ENTERTRY];
4960 enter->op_private = 0;
4962 /* establish postfix order */
4963 enter->op_next = (OP*)enter;
4965 o = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
4966 o->op_type = OP_LEAVETRY;
4967 o->op_ppaddr = PL_ppaddr[OP_LEAVETRY];
4968 enter->op_other = o;
4976 o = newUNOP(OP_ENTEREVAL, 0, newDEFSVOP());
4978 o->op_targ = (PADOFFSET)PL_hints;
4983 Perl_ck_exec(pTHX_ OP *o)
4986 if (o->op_flags & OPf_STACKED) {
4988 kid = cUNOPo->op_first->op_sibling;
4989 if (kid->op_type == OP_RV2GV)
4998 Perl_ck_exists(pTHX_ OP *o)
5001 if (o->op_flags & OPf_KIDS) {
5002 OP *kid = cUNOPo->op_first;
5003 if (kid->op_type != OP_HELEM)
5004 Perl_croak(aTHX_ "%s argument is not a HASH element", PL_op_desc[o->op_type]);
5012 Perl_ck_gvconst(pTHX_ register OP *o)
5014 o = fold_constants(o);
5015 if (o->op_type == OP_CONST)
5022 Perl_ck_rvconst(pTHX_ register OP *o)
5025 SVOP *kid = (SVOP*)cUNOPo->op_first;
5027 o->op_private |= (PL_hints & HINT_STRICT_REFS);
5028 if (kid->op_type == OP_CONST) {
5032 SV *kidsv = kid->op_sv;
5035 /* Is it a constant from cv_const_sv()? */
5036 if (SvROK(kidsv) && SvREADONLY(kidsv)) {
5037 SV *rsv = SvRV(kidsv);
5038 int svtype = SvTYPE(rsv);
5039 char *badtype = Nullch;
5041 switch (o->op_type) {
5043 if (svtype > SVt_PVMG)
5044 badtype = "a SCALAR";
5047 if (svtype != SVt_PVAV)
5048 badtype = "an ARRAY";
5051 if (svtype != SVt_PVHV) {
5052 if (svtype == SVt_PVAV) { /* pseudohash? */
5053 SV **ksv = av_fetch((AV*)rsv, 0, FALSE);
5054 if (ksv && SvROK(*ksv)
5055 && SvTYPE(SvRV(*ksv)) == SVt_PVHV)
5064 if (svtype != SVt_PVCV)
5069 Perl_croak(aTHX_ "Constant is not %s reference", badtype);
5072 name = SvPV(kidsv, n_a);
5073 if ((PL_hints & HINT_STRICT_REFS) && (kid->op_private & OPpCONST_BARE)) {
5074 char *badthing = Nullch;
5075 switch (o->op_type) {
5077 badthing = "a SCALAR";
5080 badthing = "an ARRAY";
5083 badthing = "a HASH";
5088 "Can't use bareword (\"%s\") as %s ref while \"strict refs\" in use",
5092 * This is a little tricky. We only want to add the symbol if we
5093 * didn't add it in the lexer. Otherwise we get duplicate strict
5094 * warnings. But if we didn't add it in the lexer, we must at
5095 * least pretend like we wanted to add it even if it existed before,
5096 * or we get possible typo warnings. OPpCONST_ENTERED says
5097 * whether the lexer already added THIS instance of this symbol.
5099 iscv = (o->op_type == OP_RV2CV) * 2;
5101 gv = gv_fetchpv(name,
5102 iscv | !(kid->op_private & OPpCONST_ENTERED),
5105 : o->op_type == OP_RV2SV
5107 : o->op_type == OP_RV2AV
5109 : o->op_type == OP_RV2HV
5112 } while (!gv && !(kid->op_private & OPpCONST_ENTERED) && !iscv++);
5114 kid->op_type = OP_GV;
5115 SvREFCNT_dec(kid->op_sv);
5117 /* XXXXXX hack: dependence on sizeof(PADOP) <= sizeof(SVOP) */
5118 kPADOP->op_padix = pad_alloc(OP_GV, SVs_PADTMP);
5120 PL_curpad[kPADOP->op_padix] = SvREFCNT_inc(gv);
5122 kid->op_sv = SvREFCNT_inc(gv);
5124 kid->op_ppaddr = PL_ppaddr[OP_GV];
5131 Perl_ck_ftst(pTHX_ OP *o)
5134 I32 type = o->op_type;
5136 if (o->op_flags & OPf_REF) {
5139 else if (o->op_flags & OPf_KIDS && cUNOPo->op_first->op_type != OP_STUB) {
5140 SVOP *kid = (SVOP*)cUNOPo->op_first;
5142 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
5144 OP *newop = newGVOP(type, OPf_REF,
5145 gv_fetchpv(SvPVx(kid->op_sv, n_a), TRUE, SVt_PVIO));
5152 if (type == OP_FTTTY)
5153 o = newGVOP(type, OPf_REF, gv_fetchpv("main::STDIN", TRUE,
5156 o = newUNOP(type, 0, newDEFSVOP());
5159 if (type == OP_FTTEXT || type == OP_FTBINARY) {
5161 if (PL_hints & HINT_LOCALE)
5162 o->op_private |= OPpLOCALE;
5169 Perl_ck_fun(pTHX_ OP *o)
5176 int type = o->op_type;
5177 register I32 oa = PL_opargs[type] >> OASHIFT;
5179 if (o->op_flags & OPf_STACKED) {
5180 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
5183 return no_fh_allowed(o);
5186 if (o->op_flags & OPf_KIDS) {
5188 tokid = &cLISTOPo->op_first;
5189 kid = cLISTOPo->op_first;
5190 if (kid->op_type == OP_PUSHMARK ||
5191 kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK)
5193 tokid = &kid->op_sibling;
5194 kid = kid->op_sibling;
5196 if (!kid && PL_opargs[type] & OA_DEFGV)
5197 *tokid = kid = newDEFSVOP();
5201 sibl = kid->op_sibling;
5204 /* list seen where single (scalar) arg expected? */
5205 if (numargs == 1 && !(oa >> 4)
5206 && kid->op_type == OP_LIST && type != OP_SCALAR)
5208 return too_many_arguments(o,PL_op_desc[type]);
5221 if (kid->op_type == OP_CONST &&
5222 (kid->op_private & OPpCONST_BARE))
5224 char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
5225 OP *newop = newAVREF(newGVOP(OP_GV, 0,
5226 gv_fetchpv(name, TRUE, SVt_PVAV) ));
5227 if (ckWARN(WARN_SYNTAX))
5228 Perl_warner(aTHX_ WARN_SYNTAX,
5229 "Array @%s missing the @ in argument %"IVdf" of %s()",
5230 name, (IV)numargs, PL_op_desc[type]);
5233 kid->op_sibling = sibl;
5236 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
5237 bad_type(numargs, "array", PL_op_desc[type], kid);
5241 if (kid->op_type == OP_CONST &&
5242 (kid->op_private & OPpCONST_BARE))
5244 char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
5245 OP *newop = newHVREF(newGVOP(OP_GV, 0,
5246 gv_fetchpv(name, TRUE, SVt_PVHV) ));
5247 if (ckWARN(WARN_SYNTAX))
5248 Perl_warner(aTHX_ WARN_SYNTAX,
5249 "Hash %%%s missing the %% in argument %"IVdf" of %s()",
5250 name, (IV)numargs, PL_op_desc[type]);
5253 kid->op_sibling = sibl;
5256 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
5257 bad_type(numargs, "hash", PL_op_desc[type], kid);
5262 OP *newop = newUNOP(OP_NULL, 0, kid);
5263 kid->op_sibling = 0;
5265 newop->op_next = newop;
5267 kid->op_sibling = sibl;
5272 if (kid->op_type != OP_GV && kid->op_type != OP_RV2GV) {
5273 if (kid->op_type == OP_CONST &&
5274 (kid->op_private & OPpCONST_BARE))
5276 OP *newop = newGVOP(OP_GV, 0,
5277 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, n_a), TRUE,
5282 else if (kid->op_type == OP_READLINE) {
5283 /* neophyte patrol: open(<FH>), close(<FH>) etc. */
5284 bad_type(numargs, "HANDLE", PL_op_desc[o->op_type], kid);
5287 I32 flags = OPf_SPECIAL;
5289 /* is this op a FH constructor? */
5290 if (is_handle_constructor(o,numargs)) {
5292 /* Set a flag to tell rv2gv to vivify
5293 * need to "prove" flag does not mean something
5294 * else already - NI-S 1999/05/07
5298 /* Helps with open($array[$n],...)
5299 but is too simplistic - need to do selectively
5304 kid->op_sibling = 0;
5305 kid = newUNOP(OP_RV2GV, flags, scalar(kid));
5307 kid->op_private |= priv;
5310 kid->op_sibling = sibl;
5316 mod(scalar(kid), type);
5320 tokid = &kid->op_sibling;
5321 kid = kid->op_sibling;
5323 o->op_private |= numargs;
5325 return too_many_arguments(o,PL_op_desc[o->op_type]);
5328 else if (PL_opargs[type] & OA_DEFGV) {
5330 return newUNOP(type, 0, newDEFSVOP());
5334 while (oa & OA_OPTIONAL)
5336 if (oa && oa != OA_LIST)
5337 return too_few_arguments(o,PL_op_desc[o->op_type]);
5343 Perl_ck_glob(pTHX_ OP *o)
5347 if ((o->op_flags & OPf_KIDS) && !cLISTOPo->op_first->op_sibling)
5348 append_elem(OP_GLOB, o, newDEFSVOP());
5350 if (!((gv = gv_fetchpv("glob", FALSE, SVt_PVCV)) && GvIMPORTED_CV(gv)))
5351 gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
5353 #if defined(PERL_INTERNAL_GLOB) && !defined(MINIPERL_BUILD)
5354 /* XXX this can be tightened up and made more failsafe. */
5356 OP *modname = newSVOP(OP_CONST, 0, newSVpvn("File::Glob", 10));
5357 modname->op_private |= OPpCONST_BARE;
5359 utilize(1, start_subparse(FALSE, 0), Nullop, modname,
5360 newSVOP(OP_CONST, 0, newSVpvn("globally", 8)));
5361 gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
5364 #endif /* PERL_INTERNAL_GLOB && !MINIPERL_BUILD */
5366 if (gv && GvIMPORTED_CV(gv)) {
5367 append_elem(OP_GLOB, o,
5368 newSVOP(OP_CONST, 0, newSViv(PL_glob_index++)));
5369 o->op_type = OP_LIST;
5370 o->op_ppaddr = PL_ppaddr[OP_LIST];
5371 cLISTOPo->op_first->op_type = OP_PUSHMARK;
5372 cLISTOPo->op_first->op_ppaddr = PL_ppaddr[OP_PUSHMARK];
5373 o = newUNOP(OP_ENTERSUB, OPf_STACKED,
5374 append_elem(OP_LIST, o,
5375 scalar(newUNOP(OP_RV2CV, 0,
5376 newGVOP(OP_GV, 0, gv)))));
5377 o = newUNOP(OP_NULL, 0, ck_subr(o));
5378 o->op_targ = OP_GLOB; /* hint at what it used to be */
5381 gv = newGVgen("main");
5383 append_elem(OP_GLOB, o, newGVOP(OP_GV, 0, gv));
5389 Perl_ck_grep(pTHX_ OP *o)
5393 OPCODE type = o->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
5395 o->op_ppaddr = PL_ppaddr[OP_GREPSTART];
5396 NewOp(1101, gwop, 1, LOGOP);
5398 if (o->op_flags & OPf_STACKED) {
5401 kid = cLISTOPo->op_first->op_sibling;
5402 for (k = cLISTOPo->op_first->op_sibling->op_next; k; k = k->op_next) {
5405 kid->op_next = (OP*)gwop;
5406 o->op_flags &= ~OPf_STACKED;
5408 kid = cLISTOPo->op_first->op_sibling;
5409 if (type == OP_MAPWHILE)
5416 kid = cLISTOPo->op_first->op_sibling;
5417 if (kid->op_type != OP_NULL)
5418 Perl_croak(aTHX_ "panic: ck_grep");
5419 kid = kUNOP->op_first;
5421 gwop->op_type = type;
5422 gwop->op_ppaddr = PL_ppaddr[type];
5423 gwop->op_first = listkids(o);
5424 gwop->op_flags |= OPf_KIDS;
5425 gwop->op_private = 1;
5426 gwop->op_other = LINKLIST(kid);
5427 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
5428 kid->op_next = (OP*)gwop;
5430 kid = cLISTOPo->op_first->op_sibling;
5431 if (!kid || !kid->op_sibling)
5432 return too_few_arguments(o,PL_op_desc[o->op_type]);
5433 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
5434 mod(kid, OP_GREPSTART);
5440 Perl_ck_index(pTHX_ OP *o)
5442 if (o->op_flags & OPf_KIDS) {
5443 OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5445 kid = kid->op_sibling; /* get past "big" */
5446 if (kid && kid->op_type == OP_CONST)
5447 fbm_compile(((SVOP*)kid)->op_sv, 0);
5453 Perl_ck_lengthconst(pTHX_ OP *o)
5455 /* XXX length optimization goes here */
5460 Perl_ck_lfun(pTHX_ OP *o)
5462 OPCODE type = o->op_type;
5463 return modkids(ck_fun(o), type);
5467 Perl_ck_defined(pTHX_ OP *o) /* 19990527 MJD */
5470 if ((o->op_flags & OPf_KIDS) && ckWARN(WARN_DEPRECATED)) {
5471 switch (cUNOPo->op_first->op_type) {
5473 break; /* Globals via GV can be undef */
5475 case OP_AASSIGN: /* Is this a good idea? */
5476 Perl_warner(aTHX_ WARN_DEPRECATED,
5477 "defined(@array) is deprecated");
5478 Perl_warner(aTHX_ WARN_DEPRECATED,
5479 "(Maybe you should just omit the defined()?)\n");
5482 break; /* Globals via GV can be undef */
5484 Perl_warner(aTHX_ WARN_DEPRECATED,
5485 "defined(%hash) is deprecated");
5486 Perl_warner(aTHX_ WARN_DEPRECATED,
5487 "(Maybe you should just omit the defined()?)\n");
5498 Perl_ck_rfun(pTHX_ OP *o)
5500 OPCODE type = o->op_type;
5501 return refkids(ck_fun(o), type);
5505 Perl_ck_listiob(pTHX_ OP *o)
5509 kid = cLISTOPo->op_first;
5512 kid = cLISTOPo->op_first;
5514 if (kid->op_type == OP_PUSHMARK)
5515 kid = kid->op_sibling;
5516 if (kid && o->op_flags & OPf_STACKED)
5517 kid = kid->op_sibling;
5518 else if (kid && !kid->op_sibling) { /* print HANDLE; */
5519 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
5520 o->op_flags |= OPf_STACKED; /* make it a filehandle */
5521 kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
5522 cLISTOPo->op_first->op_sibling = kid;
5523 cLISTOPo->op_last = kid;
5524 kid = kid->op_sibling;
5529 append_elem(o->op_type, o, newDEFSVOP());
5535 if (PL_hints & HINT_LOCALE)
5536 o->op_private |= OPpLOCALE;
5543 Perl_ck_fun_locale(pTHX_ OP *o)
5549 if (PL_hints & HINT_LOCALE)
5550 o->op_private |= OPpLOCALE;
5557 Perl_ck_sassign(pTHX_ OP *o)
5559 OP *kid = cLISTOPo->op_first;
5560 /* has a disposable target? */
5561 if ((PL_opargs[kid->op_type] & OA_TARGLEX)
5562 && !(kid->op_flags & OPf_STACKED))
5564 OP *kkid = kid->op_sibling;
5566 /* Can just relocate the target. */
5567 if (kkid && kkid->op_type == OP_PADSV
5568 && !(kkid->op_private & OPpLVAL_INTRO))
5570 /* Concat has problems if target is equal to right arg. */
5571 if (kid->op_type == OP_CONCAT) {
5572 if (kLISTOP->op_first->op_sibling->op_type == OP_PADSV
5573 && kLISTOP->op_first->op_sibling->op_targ == kkid->op_targ)
5576 else if (kid->op_type == OP_JOIN) {
5577 /* do_join has problems if the arguments coincide with target.
5578 In fact the second argument *can* safely coincide,
5579 but ignore=pessimize this rare occasion. */
5580 OP *arg = kLISTOP->op_first->op_sibling; /* Skip PUSHMARK */
5583 if (arg->op_type == OP_PADSV
5584 && arg->op_targ == kkid->op_targ)
5586 arg = arg->op_sibling;
5589 else if (kid->op_type == OP_QUOTEMETA) {
5590 /* quotemeta has problems if the argument coincides with target. */
5591 if (kLISTOP->op_first->op_type == OP_PADSV
5592 && kLISTOP->op_first->op_targ == kkid->op_targ)
5595 kid->op_targ = kkid->op_targ;
5597 /* Now we do not need PADSV and SASSIGN. */
5598 kid->op_sibling = o->op_sibling; /* NULL */
5599 cLISTOPo->op_first = NULL;
5602 kid->op_private |= OPpTARGET_MY; /* Used for context settings */
5610 Perl_ck_scmp(pTHX_ OP *o)
5614 if (PL_hints & HINT_LOCALE)
5615 o->op_private |= OPpLOCALE;
5622 Perl_ck_match(pTHX_ OP *o)
5624 o->op_private |= OPpRUNTIME;
5629 Perl_ck_method(pTHX_ OP *o)
5631 OP *kid = cUNOPo->op_first;
5632 if (kid->op_type == OP_CONST) {
5633 SV* sv = kSVOP->op_sv;
5634 if (!(strchr(SvPVX(sv), ':') || strchr(SvPVX(sv), '\''))) {
5636 sv_upgrade(sv, SVt_PVIV);
5638 PERL_HASH(SvUVX(sv), SvPVX(sv), SvCUR(sv));
5639 cmop = newSVOP(OP_METHOD_NAMED, 0, sv);
5640 kSVOP->op_sv = Nullsv;
5649 Perl_ck_null(pTHX_ OP *o)
5655 Perl_ck_repeat(pTHX_ OP *o)
5657 if (cBINOPo->op_first->op_flags & OPf_PARENS) {
5658 o->op_private |= OPpREPEAT_DOLIST;
5659 cBINOPo->op_first = force_list(cBINOPo->op_first);
5667 Perl_ck_require(pTHX_ OP *o)
5669 if (o->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
5670 SVOP *kid = (SVOP*)cUNOPo->op_first;
5672 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
5674 for (s = SvPVX(kid->op_sv); *s; s++) {
5675 if (*s == ':' && s[1] == ':') {
5677 Move(s+2, s+1, strlen(s+2)+1, char);
5678 --SvCUR(kid->op_sv);
5681 sv_catpvn(kid->op_sv, ".pm", 3);
5689 Perl_ck_retarget(pTHX_ OP *o)
5691 Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
5698 Perl_ck_select(pTHX_ OP *o)
5701 if (o->op_flags & OPf_KIDS) {
5702 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5703 if (kid && kid->op_sibling) {
5704 o->op_type = OP_SSELECT;
5705 o->op_ppaddr = PL_ppaddr[OP_SSELECT];
5707 return fold_constants(o);
5711 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5712 if (kid && kid->op_type == OP_RV2GV)
5713 kid->op_private &= ~HINT_STRICT_REFS;
5718 Perl_ck_shift(pTHX_ OP *o)
5720 I32 type = o->op_type;
5722 if (!(o->op_flags & OPf_KIDS)) {
5727 if (!CvUNIQUE(PL_compcv)) {
5728 argop = newOP(OP_PADAV, OPf_REF);
5729 argop->op_targ = 0; /* PL_curpad[0] is @_ */
5732 argop = newUNOP(OP_RV2AV, 0,
5733 scalar(newGVOP(OP_GV, 0,
5734 gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
5737 argop = newUNOP(OP_RV2AV, 0,
5738 scalar(newGVOP(OP_GV, 0, !CvUNIQUE(PL_compcv) ?
5739 PL_defgv : gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
5740 #endif /* USE_THREADS */
5741 return newUNOP(type, 0, scalar(argop));
5743 return scalar(modkids(ck_fun(o), type));
5747 Perl_ck_sort(pTHX_ OP *o)
5751 if (PL_hints & HINT_LOCALE)
5752 o->op_private |= OPpLOCALE;
5755 if (o->op_type == OP_SORT && o->op_flags & OPf_STACKED)
5757 if (o->op_flags & OPf_STACKED) { /* may have been cleared */
5758 OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5760 kid = kUNOP->op_first; /* get past null */
5762 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
5764 if (kid->op_type == OP_SCOPE) {
5768 else if (kid->op_type == OP_LEAVE) {
5769 if (o->op_type == OP_SORT) {
5770 null(kid); /* wipe out leave */
5773 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
5774 if (k->op_next == kid)
5779 kid->op_next = 0; /* just disconnect the leave */
5780 k = kLISTOP->op_first;
5784 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5785 if (o->op_type == OP_SORT)
5789 o->op_flags |= OPf_SPECIAL;
5791 else if (kid->op_type == OP_RV2SV || kid->op_type == OP_PADSV)
5792 null(cLISTOPo->op_first->op_sibling);
5799 S_simplify_sort(pTHX_ OP *o)
5802 register OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5806 if (!(o->op_flags & OPf_STACKED))
5808 GvMULTI_on(gv_fetchpv("a", TRUE, SVt_PV));
5809 GvMULTI_on(gv_fetchpv("b", TRUE, SVt_PV));
5810 kid = kUNOP->op_first; /* get past null */
5811 if (kid->op_type != OP_SCOPE)
5813 kid = kLISTOP->op_last; /* get past scope */
5814 switch(kid->op_type) {
5822 k = kid; /* remember this node*/
5823 if (kBINOP->op_first->op_type != OP_RV2SV)
5825 kid = kBINOP->op_first; /* get past cmp */
5826 if (kUNOP->op_first->op_type != OP_GV)
5828 kid = kUNOP->op_first; /* get past rv2sv */
5830 if (GvSTASH(gv) != PL_curstash)
5832 if (strEQ(GvNAME(gv), "a"))
5834 else if(strEQ(GvNAME(gv), "b"))
5838 kid = k; /* back to cmp */
5839 if (kBINOP->op_last->op_type != OP_RV2SV)
5841 kid = kBINOP->op_last; /* down to 2nd arg */
5842 if (kUNOP->op_first->op_type != OP_GV)
5844 kid = kUNOP->op_first; /* get past rv2sv */
5846 if (GvSTASH(gv) != PL_curstash
5848 ? strNE(GvNAME(gv), "a")
5849 : strNE(GvNAME(gv), "b")))
5851 o->op_flags &= ~(OPf_STACKED | OPf_SPECIAL);
5853 o->op_private |= OPpSORT_REVERSE;
5854 if (k->op_type == OP_NCMP)
5855 o->op_private |= OPpSORT_NUMERIC;
5856 if (k->op_type == OP_I_NCMP)
5857 o->op_private |= OPpSORT_NUMERIC | OPpSORT_INTEGER;
5858 kid = cLISTOPo->op_first->op_sibling;
5859 cLISTOPo->op_first->op_sibling = kid->op_sibling; /* bypass old block */
5860 op_free(kid); /* then delete it */
5861 cLISTOPo->op_children--;
5865 Perl_ck_split(pTHX_ OP *o)
5869 if (o->op_flags & OPf_STACKED)
5870 return no_fh_allowed(o);
5872 kid = cLISTOPo->op_first;
5873 if (kid->op_type != OP_NULL)
5874 Perl_croak(aTHX_ "panic: ck_split");
5875 kid = kid->op_sibling;
5876 op_free(cLISTOPo->op_first);
5877 cLISTOPo->op_first = kid;
5879 cLISTOPo->op_first = kid = newSVOP(OP_CONST, 0, newSVpvn(" ", 1));
5880 cLISTOPo->op_last = kid; /* There was only one element previously */
5883 if (kid->op_type != OP_MATCH) {
5884 OP *sibl = kid->op_sibling;
5885 kid->op_sibling = 0;
5886 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
5887 if (cLISTOPo->op_first == cLISTOPo->op_last)
5888 cLISTOPo->op_last = kid;
5889 cLISTOPo->op_first = kid;
5890 kid->op_sibling = sibl;
5893 kid->op_type = OP_PUSHRE;
5894 kid->op_ppaddr = PL_ppaddr[OP_PUSHRE];
5897 if (!kid->op_sibling)
5898 append_elem(OP_SPLIT, o, newDEFSVOP());
5900 kid = kid->op_sibling;
5903 if (!kid->op_sibling)
5904 append_elem(OP_SPLIT, o, newSVOP(OP_CONST, 0, newSViv(0)));
5906 kid = kid->op_sibling;
5909 if (kid->op_sibling)
5910 return too_many_arguments(o,PL_op_desc[o->op_type]);
5916 Perl_ck_join(pTHX_ OP *o)
5918 if (ckWARN(WARN_SYNTAX)) {
5919 OP *kid = cLISTOPo->op_first->op_sibling;
5920 if (kid && kid->op_type == OP_MATCH) {
5921 char *pmstr = "STRING";
5922 if (kPMOP->op_pmregexp)
5923 pmstr = kPMOP->op_pmregexp->precomp;
5924 Perl_warner(aTHX_ WARN_SYNTAX,
5925 "/%s/ should probably be written as \"%s\"",
5933 Perl_ck_subr(pTHX_ OP *o)
5936 OP *prev = ((cUNOPo->op_first->op_sibling)
5937 ? cUNOPo : ((UNOP*)cUNOPo->op_first))->op_first;
5938 OP *o2 = prev->op_sibling;
5947 o->op_private |= OPpENTERSUB_HASTARG;
5948 for (cvop = o2; cvop->op_sibling; cvop = cvop->op_sibling) ;
5949 if (cvop->op_type == OP_RV2CV) {
5951 o->op_private |= (cvop->op_private & OPpENTERSUB_AMPER);
5952 null(cvop); /* disable rv2cv */
5953 tmpop = (SVOP*)((UNOP*)cvop)->op_first;
5954 if (tmpop->op_type == OP_GV && !(o->op_private & OPpENTERSUB_AMPER)) {
5955 GV *gv = cGVOPx(tmpop);
5958 tmpop->op_private |= OPpEARLY_CV;
5959 else if (SvPOK(cv)) {
5960 namegv = CvANON(cv) ? gv : CvGV(cv);
5961 proto = SvPV((SV*)cv, n_a);
5965 else if (cvop->op_type == OP_METHOD || cvop->op_type == OP_METHOD_NAMED) {
5966 if (o2->op_type == OP_CONST)
5967 o2->op_private &= ~OPpCONST_STRICT;
5968 else if (o2->op_type == OP_LIST) {
5969 OP *o = ((UNOP*)o2)->op_first->op_sibling;
5970 if (o && o->op_type == OP_CONST)
5971 o->op_private &= ~OPpCONST_STRICT;
5974 o->op_private |= (PL_hints & HINT_STRICT_REFS);
5975 if (PERLDB_SUB && PL_curstash != PL_debstash)
5976 o->op_private |= OPpENTERSUB_DB;
5977 while (o2 != cvop) {
5981 return too_many_arguments(o, gv_ename(namegv));
5999 if (o2->op_type != OP_REFGEN && o2->op_type != OP_UNDEF)
6000 bad_type(arg, "block", gv_ename(namegv), o2);
6003 /* '*' allows any scalar type, including bareword */
6006 if (o2->op_type == OP_RV2GV)
6007 goto wrapref; /* autoconvert GLOB -> GLOBref */
6008 else if (o2->op_type == OP_CONST)
6009 o2->op_private &= ~OPpCONST_STRICT;
6010 else if (o2->op_type == OP_ENTERSUB) {
6011 /* accidental subroutine, revert to bareword */
6012 OP *gvop = ((UNOP*)o2)->op_first;
6013 if (gvop && gvop->op_type == OP_NULL) {
6014 gvop = ((UNOP*)gvop)->op_first;
6016 for (; gvop->op_sibling; gvop = gvop->op_sibling)
6019 (gvop->op_private & OPpENTERSUB_NOPAREN) &&
6020 (gvop = ((UNOP*)gvop)->op_first) &&
6021 gvop->op_type == OP_GV)
6023 GV *gv = cGVOPx(gvop);
6024 OP *sibling = o2->op_sibling;
6025 SV *n = newSVpvn("",0);
6027 gv_fullname3(n, gv, "");
6028 if (SvCUR(n)>6 && strnEQ(SvPVX(n),"main::",6))
6029 sv_chop(n, SvPVX(n)+6);
6030 o2 = newSVOP(OP_CONST, 0, n);
6031 prev->op_sibling = o2;
6032 o2->op_sibling = sibling;
6044 if (o2->op_type != OP_RV2GV)
6045 bad_type(arg, "symbol", gv_ename(namegv), o2);
6048 if (o2->op_type != OP_RV2CV)
6049 bad_type(arg, "sub", gv_ename(namegv), o2);
6052 if (o2->op_type != OP_RV2SV
6053 && o2->op_type != OP_PADSV
6054 && o2->op_type != OP_HELEM
6055 && o2->op_type != OP_AELEM
6056 && o2->op_type != OP_THREADSV)
6058 bad_type(arg, "scalar", gv_ename(namegv), o2);
6062 if (o2->op_type != OP_RV2AV && o2->op_type != OP_PADAV)
6063 bad_type(arg, "array", gv_ename(namegv), o2);
6066 if (o2->op_type != OP_RV2HV && o2->op_type != OP_PADHV)
6067 bad_type(arg, "hash", gv_ename(namegv), o2);
6071 OP* sib = kid->op_sibling;
6072 kid->op_sibling = 0;
6073 o2 = newUNOP(OP_REFGEN, 0, kid);
6074 o2->op_sibling = sib;
6075 prev->op_sibling = o2;
6086 Perl_croak(aTHX_ "Malformed prototype for %s: %s",
6087 gv_ename(namegv), SvPV((SV*)cv, n_a));
6092 mod(o2, OP_ENTERSUB);
6094 o2 = o2->op_sibling;
6096 if (proto && !optional &&
6097 (*proto && *proto != '@' && *proto != '%' && *proto != ';'))
6098 return too_few_arguments(o, gv_ename(namegv));
6103 Perl_ck_svconst(pTHX_ OP *o)
6105 SvREADONLY_on(cSVOPo->op_sv);
6110 Perl_ck_trunc(pTHX_ OP *o)
6112 if (o->op_flags & OPf_KIDS) {
6113 SVOP *kid = (SVOP*)cUNOPo->op_first;
6115 if (kid->op_type == OP_NULL)
6116 kid = (SVOP*)kid->op_sibling;
6117 if (kid && kid->op_type == OP_CONST &&
6118 (kid->op_private & OPpCONST_BARE))
6120 o->op_flags |= OPf_SPECIAL;
6121 kid->op_private &= ~OPpCONST_STRICT;
6127 /* A peephole optimizer. We visit the ops in the order they're to execute. */
6130 Perl_peep(pTHX_ register OP *o)
6133 register OP* oldop = 0;
6135 OP *last_composite = Nullop;
6137 if (!o || o->op_seq)
6141 SAVEVPTR(PL_curcop);
6142 for (; o; o = o->op_next) {
6148 switch (o->op_type) {
6152 PL_curcop = ((COP*)o); /* for warnings */
6153 o->op_seq = PL_op_seqmax++;
6154 last_composite = Nullop;
6158 if (cSVOPo->op_private & OPpCONST_STRICT)
6159 no_bareword_allowed(o);
6161 /* Relocate sv to the pad for thread safety.
6162 * Despite being a "constant", the SV is written to,
6163 * for reference counts, sv_upgrade() etc. */
6165 PADOFFSET ix = pad_alloc(OP_CONST, SVs_PADTMP);
6166 SvREFCNT_dec(PL_curpad[ix]);
6167 SvPADTMP_on(cSVOPo->op_sv);
6168 PL_curpad[ix] = cSVOPo->op_sv;
6169 cSVOPo->op_sv = Nullsv;
6178 if ( o->op_next && o->op_next->op_type == OP_STRINGIFY
6179 && !(o->op_next->op_private & OPpTARGET_MY) )
6181 o->op_seq = PL_op_seqmax++;
6186 if (o->op_next && o->op_next->op_type == OP_STRINGIFY) {
6187 if (o->op_next->op_private & OPpTARGET_MY) {
6188 if ((o->op_flags & OPf_STACKED) /* chained concats */
6189 || (o->op_type == OP_CONCAT
6190 /* Concat has problems if target is equal to right arg. */
6191 && (((LISTOP*)o)->op_first->op_sibling->op_type
6193 && (((LISTOP*)o)->op_first->op_sibling->op_targ
6194 == o->op_next->op_targ)))
6196 goto ignore_optimization;
6199 o->op_targ = o->op_next->op_targ;
6200 o->op_next->op_targ = 0;
6201 o->op_private |= OPpTARGET_MY;
6206 ignore_optimization:
6207 o->op_seq = PL_op_seqmax++;
6210 if ((o->op_flags & OPf_WANT) != OPf_WANT_LIST) {
6211 o->op_seq = PL_op_seqmax++;
6212 break; /* Scalar stub must produce undef. List stub is noop */
6216 if (o->op_targ == OP_NEXTSTATE
6217 || o->op_targ == OP_DBSTATE
6218 || o->op_targ == OP_SETSTATE)
6220 PL_curcop = ((COP*)o);
6227 if (oldop && o->op_next) {
6228 oldop->op_next = o->op_next;
6231 o->op_seq = PL_op_seqmax++;
6235 if (o->op_next->op_type == OP_RV2SV) {
6236 if (!(o->op_next->op_private & OPpDEREF)) {
6238 o->op_private |= o->op_next->op_private & OPpLVAL_INTRO;
6239 o->op_next = o->op_next->op_next;
6240 o->op_type = OP_GVSV;
6241 o->op_ppaddr = PL_ppaddr[OP_GVSV];
6244 else if (o->op_next->op_type == OP_RV2AV) {
6245 OP* pop = o->op_next->op_next;
6247 if (pop->op_type == OP_CONST &&
6248 (PL_op = pop->op_next) &&
6249 pop->op_next->op_type == OP_AELEM &&
6250 !(pop->op_next->op_private &
6251 (OPpLVAL_INTRO|OPpLVAL_DEFER|OPpDEREF)) &&
6252 (i = SvIV(((SVOP*)pop)->op_sv) - PL_compiling.cop_arybase)
6260 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
6261 o->op_next = pop->op_next->op_next;
6262 o->op_type = OP_AELEMFAST;
6263 o->op_ppaddr = PL_ppaddr[OP_AELEMFAST];
6264 o->op_private = (U8)i;
6269 else if ((o->op_private & OPpEARLY_CV) && ckWARN(WARN_UNSAFE)) {
6271 if (SvTYPE(gv) == SVt_PVGV && GvCV(gv) && SvPVX(GvCV(gv))) {
6272 /* XXX could check prototype here instead of just carping */
6273 SV *sv = sv_newmortal();
6274 gv_efullname3(sv, gv, Nullch);
6275 Perl_warner(aTHX_ WARN_UNSAFE,
6276 "%s() called too early to check prototype",
6281 o->op_seq = PL_op_seqmax++;
6292 o->op_seq = PL_op_seqmax++;
6293 while (cLOGOP->op_other->op_type == OP_NULL)
6294 cLOGOP->op_other = cLOGOP->op_other->op_next;
6295 peep(cLOGOP->op_other);
6299 o->op_seq = PL_op_seqmax++;
6300 peep(cLOOP->op_redoop);
6301 peep(cLOOP->op_nextop);
6302 peep(cLOOP->op_lastop);
6308 o->op_seq = PL_op_seqmax++;
6309 peep(cPMOP->op_pmreplstart);
6313 o->op_seq = PL_op_seqmax++;
6314 if (ckWARN(WARN_SYNTAX) && o->op_next
6315 && o->op_next->op_type == OP_NEXTSTATE) {
6316 if (o->op_next->op_sibling &&
6317 o->op_next->op_sibling->op_type != OP_EXIT &&
6318 o->op_next->op_sibling->op_type != OP_WARN &&
6319 o->op_next->op_sibling->op_type != OP_DIE) {
6320 line_t oldline = CopLINE(PL_curcop);
6322 CopLINE_set(PL_curcop, CopLINE((COP*)o->op_next));
6323 Perl_warner(aTHX_ WARN_SYNTAX, "Statement unlikely to be reached");
6324 Perl_warner(aTHX_ WARN_SYNTAX, "(Maybe you meant system() when you said exec()?)\n");
6325 CopLINE_set(PL_curcop, oldline);
6339 if ((o->op_private & (OPpLVAL_INTRO))
6340 || ((BINOP*)o)->op_last->op_type != OP_CONST)
6342 rop = (UNOP*)((BINOP*)o)->op_first;
6343 if (rop->op_type != OP_RV2HV || rop->op_first->op_type != OP_PADSV)
6345 lexname = *av_fetch(PL_comppad_name, rop->op_first->op_targ, TRUE);
6346 if (!SvOBJECT(lexname))
6348 fields = (GV**)hv_fetch(SvSTASH(lexname), "FIELDS", 6, FALSE);
6349 if (!fields || !GvHV(*fields))
6351 svp = &cSVOPx_sv(((BINOP*)o)->op_last);
6352 key = SvPV(*svp, keylen);
6353 indsvp = hv_fetch(GvHV(*fields), key, keylen, FALSE);
6355 Perl_croak(aTHX_ "No such pseudo-hash field \"%s\" in variable %s of type %s",
6356 key, SvPV(lexname, n_a), HvNAME(SvSTASH(lexname)));
6358 ind = SvIV(*indsvp);
6360 Perl_croak(aTHX_ "Bad index while coercing array into hash");
6361 rop->op_type = OP_RV2AV;
6362 rop->op_ppaddr = PL_ppaddr[OP_RV2AV];
6363 o->op_type = OP_AELEM;
6364 o->op_ppaddr = PL_ppaddr[OP_AELEM];
6366 *svp = newSViv(ind);
6372 if (!(o->op_flags & OPf_WANT)
6373 || (o->op_flags & OPf_WANT) == OPf_WANT_LIST)
6377 o->op_seq = PL_op_seqmax++;
6381 if (o->op_next && o->op_next->op_type != OP_LEAVESUBLV) {
6382 o->op_seq = PL_op_seqmax++;
6388 if (last_composite) {
6389 OP *r = last_composite;
6391 while (r->op_sibling)
6394 || (r->op_next->op_type == OP_LIST
6395 && r->op_next->op_next == o))
6397 if (last_composite->op_type == OP_RV2AV)
6398 yyerror("Lvalue subs returning arrays not implemented yet");
6400 yyerror("Lvalue subs returning hashes not implemented yet");
6407 o->op_seq = PL_op_seqmax++;