3 * Copyright (c) 1991-1999, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 * "You see: Mr. Drogo, he married poor Miss Primula Brandybuck. She was
12 * our Mr. Bilbo's first cousin on the mother's side (her mother being the
13 * youngest of the Old Took's daughters); and Mr. Drogo was his second
14 * cousin. So Mr. Frodo is his first *and* second cousin, once removed
15 * either way, as the saying is, if you follow me." --the Gaffer
23 /* #define PL_OP_SLAB_ALLOC */
27 # define OP_REFCNT_LOCK NOOP
28 # define OP_REFCNT_UNLOCK NOOP
29 # define OpREFCNT_set(o,n) ((o)->op_targ = (n))
30 # define OpREFCNT_dec(o) (--(o)->op_targ)
32 # define OP_REFCNT_LOCK NOOP
33 # define OP_REFCNT_UNLOCK NOOP
34 # define OpREFCNT_set(o,n) NOOP
35 # define OpREFCNT_dec(o) 0
38 #ifdef PL_OP_SLAB_ALLOC
39 #define SLAB_SIZE 8192
40 static char *PL_OpPtr = NULL;
41 static int PL_OpSpace = 0;
42 #define NewOp(m,var,c,type) do { if ((PL_OpSpace -= c*sizeof(type)) >= 0) \
43 var = (type *)(PL_OpPtr -= c*sizeof(type)); \
45 var = (type *) Slab_Alloc(m,c*sizeof(type)); \
49 S_Slab_Alloc(pTHX_ int m, size_t sz)
51 Newz(m,PL_OpPtr,SLAB_SIZE,char);
52 PL_OpSpace = SLAB_SIZE - sz;
53 return PL_OpPtr += PL_OpSpace;
57 #define NewOp(m, var, c, type) Newz(m, var, c, type)
60 * In the following definition, the ", Nullop" is just to make the compiler
61 * think the expression is of the right type: croak actually does a Siglongjmp.
63 #define CHECKOP(type,o) \
64 ((PL_op_mask && PL_op_mask[type]) \
65 ? ( op_free((OP*)o), \
66 Perl_croak(aTHX_ "%s trapped by operation mask", PL_op_desc[type]), \
68 : CALL_FPTR(PL_check[type])(aTHX_ (OP*)o))
70 #define PAD_MAX 999999999
73 S_gv_ename(pTHX_ GV *gv)
76 SV* tmpsv = sv_newmortal();
77 gv_efullname3(tmpsv, gv, Nullch);
78 return SvPV(tmpsv,n_a);
82 S_no_fh_allowed(pTHX_ OP *o)
84 yyerror(Perl_form(aTHX_ "Missing comma after first argument to %s function",
85 PL_op_desc[o->op_type]));
90 S_too_few_arguments(pTHX_ OP *o, char *name)
92 yyerror(Perl_form(aTHX_ "Not enough arguments for %s", name));
97 S_too_many_arguments(pTHX_ OP *o, char *name)
99 yyerror(Perl_form(aTHX_ "Too many arguments for %s", name));
104 S_bad_type(pTHX_ I32 n, char *t, char *name, OP *kid)
106 yyerror(Perl_form(aTHX_ "Type of arg %d to %s must be %s (not %s)",
107 (int)n, name, t, PL_op_desc[kid->op_type]));
111 S_no_bareword_allowed(pTHX_ OP *o)
113 qerror(Perl_mess(aTHX_
114 "Bareword \"%s\" not allowed while \"strict subs\" in use",
115 SvPV_nolen(cSVOPo_sv)));
118 /* "register" allocation */
121 Perl_pad_allocmy(pTHX_ char *name)
128 PL_in_my == KEY_our ||
130 (PL_hints & HINT_UTF8 && (name[1] & 0xc0) == 0xc0) ||
131 name[1] == '_' && (int)strlen(name) > 2 ))
133 if (!isPRINT(name[1]) || strchr("\t\n\r\f", name[1])) {
134 /* 1999-02-27 mjd@plover.com */
136 p = strchr(name, '\0');
137 /* The next block assumes the buffer is at least 205 chars
138 long. At present, it's always at least 256 chars. */
140 strcpy(name+200, "...");
146 /* Move everything else down one character */
147 for (; p-name > 2; p--)
149 name[2] = toCTRL(name[1]);
152 yyerror(Perl_form(aTHX_ "Can't use global %s in \"my\"",name));
154 if (ckWARN(WARN_UNSAFE) && AvFILLp(PL_comppad_name) >= 0) {
155 SV **svp = AvARRAY(PL_comppad_name);
156 for (off = AvFILLp(PL_comppad_name); off > PL_comppad_name_floor; off--) {
158 && sv != &PL_sv_undef
159 && (SvIVX(sv) == PAD_MAX || SvIVX(sv) == 0)
160 && strEQ(name, SvPVX(sv)))
162 Perl_warner(aTHX_ WARN_UNSAFE,
163 "\"%s\" variable %s masks earlier declaration in same %s",
164 (PL_in_my == KEY_our ? "our" : "my"),
166 (SvIVX(sv) == PAD_MAX ? "scope" : "statement"));
171 off = pad_alloc(OP_PADSV, SVs_PADMY);
173 sv_upgrade(sv, SVt_PVNV);
175 if (PL_in_my_stash) {
177 yyerror(Perl_form(aTHX_ "Can't declare class for non-scalar %s in \"my\"",
180 (void)SvUPGRADE(sv, SVt_PVMG);
181 SvSTASH(sv) = (HV*)SvREFCNT_inc(PL_in_my_stash);
184 if (PL_in_my == KEY_our)
185 SvFLAGS(sv) |= SVpad_OUR;
186 av_store(PL_comppad_name, off, sv);
187 SvNVX(sv) = (NV)PAD_MAX;
188 SvIVX(sv) = 0; /* Not yet introduced--see newSTATEOP */
189 if (!PL_min_intro_pending)
190 PL_min_intro_pending = off;
191 PL_max_intro_pending = off;
193 av_store(PL_comppad, off, (SV*)newAV());
194 else if (*name == '%')
195 av_store(PL_comppad, off, (SV*)newHV());
196 SvPADMY_on(PL_curpad[off]);
200 #define FINDLEX_NOSEARCH 1 /* don't search outer contexts */
203 S_pad_findlex(pTHX_ char *name, PADOFFSET newoff, U32 seq, CV* startcv,
204 I32 cx_ix, I32 saweval, U32 flags)
211 register PERL_CONTEXT *cx;
213 for (cv = startcv; cv; cv = CvOUTSIDE(cv)) {
214 AV *curlist = CvPADLIST(cv);
215 SV **svp = av_fetch(curlist, 0, FALSE);
218 if (!svp || *svp == &PL_sv_undef)
221 svp = AvARRAY(curname);
222 for (off = AvFILLp(curname); off > 0; off--) {
223 if ((sv = svp[off]) &&
224 sv != &PL_sv_undef &&
226 seq > I_32(SvNVX(sv)) &&
227 strEQ(SvPVX(sv), name))
238 return 0; /* don't clone from inactive stack frame */
242 oldpad = (AV*)*av_fetch(curlist, depth, FALSE);
243 oldsv = *av_fetch(oldpad, off, TRUE);
244 if (!newoff) { /* Not a mere clone operation. */
245 SV *namesv = NEWSV(1103,0);
246 newoff = pad_alloc(OP_PADSV, SVs_PADMY);
247 sv_upgrade(namesv, SVt_PVNV);
248 sv_setpv(namesv, name);
249 av_store(PL_comppad_name, newoff, namesv);
250 SvNVX(namesv) = (NV)PL_curcop->cop_seq;
251 SvIVX(namesv) = PAD_MAX; /* A ref, intro immediately */
252 SvFAKE_on(namesv); /* A ref, not a real var */
253 if (SvFLAGS(sv) & SVpad_OUR)/* An "our" variable */
254 SvFLAGS(namesv) |= SVpad_OUR;
255 if (SvOBJECT(sv)) { /* A typed var */
257 (void)SvUPGRADE(namesv, SVt_PVMG);
258 SvSTASH(namesv) = (HV*)SvREFCNT_inc((SV*)SvSTASH(sv));
261 if (CvANON(PL_compcv) || SvTYPE(PL_compcv) == SVt_PVFM) {
262 /* "It's closures all the way down." */
263 CvCLONE_on(PL_compcv);
265 if (CvANON(PL_compcv))
266 oldsv = Nullsv; /* no need to keep ref */
271 bcv && bcv != cv && !CvCLONE(bcv);
272 bcv = CvOUTSIDE(bcv))
277 if (ckWARN(WARN_CLOSURE)
278 && !CvUNIQUE(bcv) && !CvUNIQUE(cv))
280 Perl_warner(aTHX_ WARN_CLOSURE,
281 "Variable \"%s\" may be unavailable",
289 else if (!CvUNIQUE(PL_compcv)) {
290 if (ckWARN(WARN_CLOSURE) && !SvFAKE(sv) && !CvUNIQUE(cv))
291 Perl_warner(aTHX_ WARN_CLOSURE,
292 "Variable \"%s\" will not stay shared", name);
295 av_store(PL_comppad, newoff, SvREFCNT_inc(oldsv));
301 if (flags & FINDLEX_NOSEARCH)
304 /* Nothing in current lexical context--try eval's context, if any.
305 * This is necessary to let the perldb get at lexically scoped variables.
306 * XXX This will also probably interact badly with eval tree caching.
309 for (i = cx_ix; i >= 0; i--) {
311 switch (CxTYPE(cx)) {
313 if (i == 0 && saweval) {
314 seq = cxstack[saweval].blk_oldcop->cop_seq;
315 return pad_findlex(name, newoff, seq, PL_main_cv, -1, saweval, 0);
319 switch (cx->blk_eval.old_op_type) {
325 /* require must have its own scope */
334 if (PL_debstash && CvSTASH(cv) == PL_debstash) { /* ignore DB'* scope */
335 saweval = i; /* so we know where we were called from */
338 seq = cxstack[saweval].blk_oldcop->cop_seq;
339 return pad_findlex(name, newoff, seq, cv, i-1, saweval,FINDLEX_NOSEARCH);
347 Perl_pad_findmy(pTHX_ char *name)
353 SV **svp = AvARRAY(PL_comppad_name);
354 U32 seq = PL_cop_seqmax;
360 * Special case to get lexical (and hence per-thread) @_.
361 * XXX I need to find out how to tell at parse-time whether use
362 * of @_ should refer to a lexical (from a sub) or defgv (global
363 * scope and maybe weird sub-ish things like formats). See
364 * startsub in perly.y. It's possible that @_ could be lexical
365 * (at least from subs) even in non-threaded perl.
367 if (strEQ(name, "@_"))
368 return 0; /* success. (NOT_IN_PAD indicates failure) */
369 #endif /* USE_THREADS */
371 /* The one we're looking for is probably just before comppad_name_fill. */
372 for (off = AvFILLp(PL_comppad_name); off > 0; off--) {
373 if ((sv = svp[off]) &&
374 sv != &PL_sv_undef &&
377 seq > I_32(SvNVX(sv)))) &&
378 strEQ(SvPVX(sv), name))
380 if (SvIVX(sv) || SvFLAGS(sv) & SVpad_OUR)
381 return (PADOFFSET)off;
382 pendoff = off; /* this pending def. will override import */
386 outside = CvOUTSIDE(PL_compcv);
388 /* Check if if we're compiling an eval'', and adjust seq to be the
389 * eval's seq number. This depends on eval'' having a non-null
390 * CvOUTSIDE() while it is being compiled. The eval'' itself is
391 * identified by CvEVAL being true and CvGV being null. */
392 if (outside && CvEVAL(PL_compcv) && !CvGV(PL_compcv) && cxstack_ix >= 0) {
393 cx = &cxstack[cxstack_ix];
395 seq = cx->blk_oldcop->cop_seq;
398 /* See if it's in a nested scope */
399 off = pad_findlex(name, 0, seq, outside, cxstack_ix, 0, 0);
401 /* If there is a pending local definition, this new alias must die */
403 SvIVX(AvARRAY(PL_comppad_name)[off]) = seq;
404 return off; /* pad_findlex returns 0 for failure...*/
406 return NOT_IN_PAD; /* ...but we return NOT_IN_PAD for failure */
410 Perl_pad_leavemy(pTHX_ I32 fill)
414 SV **svp = AvARRAY(PL_comppad_name);
416 if (PL_min_intro_pending && fill < PL_min_intro_pending) {
417 for (off = PL_max_intro_pending; off >= PL_min_intro_pending; off--) {
418 if ((sv = svp[off]) && sv != &PL_sv_undef && ckWARN_d(WARN_INTERNAL))
419 Perl_warner(aTHX_ WARN_INTERNAL, "%s never introduced", SvPVX(sv));
422 /* "Deintroduce" my variables that are leaving with this scope. */
423 for (off = AvFILLp(PL_comppad_name); off > fill; off--) {
424 if ((sv = svp[off]) && sv != &PL_sv_undef && SvIVX(sv) == PAD_MAX)
425 SvIVX(sv) = PL_cop_seqmax;
430 Perl_pad_alloc(pTHX_ I32 optype, U32 tmptype)
436 if (AvARRAY(PL_comppad) != PL_curpad)
437 Perl_croak(aTHX_ "panic: pad_alloc");
438 if (PL_pad_reset_pending)
440 if (tmptype & SVs_PADMY) {
442 sv = *av_fetch(PL_comppad, AvFILLp(PL_comppad) + 1, TRUE);
443 } while (SvPADBUSY(sv)); /* need a fresh one */
444 retval = AvFILLp(PL_comppad);
447 SV **names = AvARRAY(PL_comppad_name);
448 SSize_t names_fill = AvFILLp(PL_comppad_name);
451 * "foreach" index vars temporarily become aliases to non-"my"
452 * values. Thus we must skip, not just pad values that are
453 * marked as current pad values, but also those with names.
455 if (++PL_padix <= names_fill &&
456 (sv = names[PL_padix]) && sv != &PL_sv_undef)
458 sv = *av_fetch(PL_comppad, PL_padix, TRUE);
459 if (!(SvFLAGS(sv) & (SVs_PADTMP|SVs_PADMY)) && !IS_PADGV(sv))
464 SvFLAGS(sv) |= tmptype;
465 PL_curpad = AvARRAY(PL_comppad);
467 DEBUG_X(PerlIO_printf(Perl_debug_log,
468 "0x%"UVxf" Pad 0x%"UVxf" alloc %ld for %s\n",
469 PTR2UV(thr), PTR2UV(PL_curpad),
470 (long) retval, PL_op_name[optype]));
472 DEBUG_X(PerlIO_printf(Perl_debug_log,
473 "Pad 0x%"UVxf" alloc %ld for %s\n",
475 (long) retval, PL_op_name[optype]));
476 #endif /* USE_THREADS */
477 return (PADOFFSET)retval;
481 Perl_pad_sv(pTHX_ PADOFFSET po)
485 DEBUG_X(PerlIO_printf(Perl_debug_log,
486 "0x%"UVxf" Pad 0x%"UVxf" sv %"IVdf"\n",
487 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
490 Perl_croak(aTHX_ "panic: pad_sv po");
491 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" sv %"IVdf"\n",
492 PTR2UV(PL_curpad), (IV)po));
493 #endif /* USE_THREADS */
494 return PL_curpad[po]; /* eventually we'll turn this into a macro */
498 Perl_pad_free(pTHX_ PADOFFSET po)
503 if (AvARRAY(PL_comppad) != PL_curpad)
504 Perl_croak(aTHX_ "panic: pad_free curpad");
506 Perl_croak(aTHX_ "panic: pad_free po");
508 DEBUG_X(PerlIO_printf(Perl_debug_log,
509 "0x%"UVxf" Pad 0x%"UVxf" free %"IVdf"\n",
510 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
512 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" free %"IVdf"\n",
513 PTR2UV(PL_curpad), (IV)po));
514 #endif /* USE_THREADS */
515 if (PL_curpad[po] && PL_curpad[po] != &PL_sv_undef)
516 SvPADTMP_off(PL_curpad[po]);
517 if ((I32)po < PL_padix)
522 Perl_pad_swipe(pTHX_ PADOFFSET po)
525 if (AvARRAY(PL_comppad) != PL_curpad)
526 Perl_croak(aTHX_ "panic: pad_swipe curpad");
528 Perl_croak(aTHX_ "panic: pad_swipe po");
530 DEBUG_X(PerlIO_printf(Perl_debug_log,
531 "0x%"UVxf" Pad 0x%"UVxf" swipe %"IVdf"\n",
532 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
534 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" swipe %"IVdf"\n",
535 PTR2UV(PL_curpad), (IV)po));
536 #endif /* USE_THREADS */
537 SvPADTMP_off(PL_curpad[po]);
538 PL_curpad[po] = NEWSV(1107,0);
539 SvPADTMP_on(PL_curpad[po]);
540 if ((I32)po < PL_padix)
544 /* XXX pad_reset() is currently disabled because it results in serious bugs.
545 * It causes pad temp TARGs to be shared between OPs. Since TARGs are pushed
546 * on the stack by OPs that use them, there are several ways to get an alias
547 * to a shared TARG. Such an alias will change randomly and unpredictably.
548 * We avoid doing this until we can think of a Better Way.
553 #ifdef USE_BROKEN_PAD_RESET
557 if (AvARRAY(PL_comppad) != PL_curpad)
558 Perl_croak(aTHX_ "panic: pad_reset curpad");
560 DEBUG_X(PerlIO_printf(Perl_debug_log,
561 "0x%"UVxf" Pad 0x%"UVxf" reset\n",
562 PTR2UV(thr), PTR2UV(PL_curpad)));
564 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" reset\n",
566 #endif /* USE_THREADS */
567 if (!PL_tainting) { /* Can't mix tainted and non-tainted temporaries. */
568 for (po = AvMAX(PL_comppad); po > PL_padix_floor; po--) {
569 if (PL_curpad[po] && !SvIMMORTAL(PL_curpad[po]))
570 SvPADTMP_off(PL_curpad[po]);
572 PL_padix = PL_padix_floor;
575 PL_pad_reset_pending = FALSE;
579 /* find_threadsv is not reentrant */
581 Perl_find_threadsv(pTHX_ const char *name)
587 /* We currently only handle names of a single character */
588 p = strchr(PL_threadsv_names, *name);
591 key = p - PL_threadsv_names;
592 MUTEX_LOCK(&thr->mutex);
593 svp = av_fetch(thr->threadsv, key, FALSE);
595 MUTEX_UNLOCK(&thr->mutex);
597 SV *sv = NEWSV(0, 0);
598 av_store(thr->threadsv, key, sv);
599 thr->threadsvp = AvARRAY(thr->threadsv);
600 MUTEX_UNLOCK(&thr->mutex);
602 * Some magic variables used to be automagically initialised
603 * in gv_fetchpv. Those which are now per-thread magicals get
604 * initialised here instead.
610 sv_setpv(sv, "\034");
611 sv_magic(sv, 0, 0, name, 1);
616 PL_sawampersand = TRUE;
630 /* XXX %! tied to Errno.pm needs to be added here.
631 * See gv_fetchpv(). */
635 sv_magic(sv, 0, 0, name, 1);
637 DEBUG_S(PerlIO_printf(Perl_error_log,
638 "find_threadsv: new SV %p for $%s%c\n",
639 sv, (*name < 32) ? "^" : "",
640 (*name < 32) ? toCTRL(*name) : *name));
644 #endif /* USE_THREADS */
649 Perl_op_free(pTHX_ OP *o)
651 register OP *kid, *nextkid;
654 if (!o || o->op_seq == (U16)-1)
657 if (o->op_private & OPpREFCOUNTED) {
658 switch (o->op_type) {
666 if (OpREFCNT_dec(o)) {
677 if (o->op_flags & OPf_KIDS) {
678 for (kid = cUNOPo->op_first; kid; kid = nextkid) {
679 nextkid = kid->op_sibling; /* Get before next freeing kid */
687 /* COP* is not cleared by op_clear() so that we may track line
688 * numbers etc even after null() */
689 if (type == OP_NEXTSTATE || type == OP_SETSTATE || type == OP_DBSTATE)
694 #ifdef PL_OP_SLAB_ALLOC
695 if ((char *) o == PL_OpPtr)
704 S_op_clear(pTHX_ OP *o)
706 switch (o->op_type) {
707 case OP_NULL: /* Was holding old type, if any. */
708 case OP_ENTEREVAL: /* Was holding hints. */
710 case OP_THREADSV: /* Was holding index into thr->threadsv AV. */
716 if (!(o->op_flags & OPf_SPECIAL))
719 #endif /* USE_THREADS */
721 if (!(o->op_flags & OPf_REF)
722 || (PL_check[o->op_type] != MEMBER_TO_FPTR(Perl_ck_ftst)))
729 if (cPADOPo->op_padix > 0) {
732 pad_swipe(cPADOPo->op_padix);
733 /* No GvIN_PAD_off(gv) here, because other references may still
734 * exist on the pad */
737 cPADOPo->op_padix = 0;
740 SvREFCNT_dec(cSVOPo->op_sv);
741 cSVOPo->op_sv = Nullsv;
745 SvREFCNT_dec(cSVOPo->op_sv);
746 cSVOPo->op_sv = Nullsv;
752 if (o->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
756 if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
757 SvREFCNT_dec(cSVOPo->op_sv);
758 cSVOPo->op_sv = Nullsv;
761 Safefree(cPVOPo->op_pv);
762 cPVOPo->op_pv = Nullch;
766 op_free(cPMOPo->op_pmreplroot);
770 if ((PADOFFSET)cPMOPo->op_pmreplroot) {
772 GV *gv = (GV*)PL_curpad[(PADOFFSET)cPMOPo->op_pmreplroot];
773 pad_swipe((PADOFFSET)cPMOPo->op_pmreplroot);
774 /* No GvIN_PAD_off(gv) here, because other references may still
775 * exist on the pad */
780 SvREFCNT_dec((SV*)cPMOPo->op_pmreplroot);
786 cPMOPo->op_pmreplroot = Nullop;
787 ReREFCNT_dec(cPMOPo->op_pmregexp);
788 cPMOPo->op_pmregexp = (REGEXP*)NULL;
792 if (o->op_targ > 0) {
793 pad_free(o->op_targ);
799 S_cop_free(pTHX_ COP* cop)
801 Safefree(cop->cop_label);
803 Safefree(CopFILE(cop)); /* XXXXX share in a pvtable? */
804 Safefree(CopSTASHPV(cop)); /* XXXXX share in a pvtable? */
806 /* NOTE: COP.cop_stash is not refcounted */
807 SvREFCNT_dec(CopFILEGV(cop));
809 if (! specialWARN(cop->cop_warnings))
810 SvREFCNT_dec(cop->cop_warnings);
816 if (o->op_type == OP_NULL)
819 o->op_targ = o->op_type;
820 o->op_type = OP_NULL;
821 o->op_ppaddr = PL_ppaddr[OP_NULL];
824 /* Contextualizers */
826 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
829 Perl_linklist(pTHX_ OP *o)
836 /* establish postfix order */
837 if (cUNOPo->op_first) {
838 o->op_next = LINKLIST(cUNOPo->op_first);
839 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
841 kid->op_next = LINKLIST(kid->op_sibling);
853 Perl_scalarkids(pTHX_ OP *o)
856 if (o && o->op_flags & OPf_KIDS) {
857 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
864 S_scalarboolean(pTHX_ OP *o)
866 if (o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST) {
868 if (ckWARN(WARN_SYNTAX)) {
869 line_t oldline = CopLINE(PL_curcop);
871 if (PL_copline != NOLINE)
872 CopLINE_set(PL_curcop, PL_copline);
873 Perl_warner(aTHX_ WARN_SYNTAX, "Found = in conditional, should be ==");
874 CopLINE_set(PL_curcop, oldline);
881 Perl_scalar(pTHX_ OP *o)
885 /* assumes no premature commitment */
886 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
887 || o->op_type == OP_RETURN)
892 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_SCALAR;
894 switch (o->op_type) {
896 if (o->op_private & OPpREPEAT_DOLIST)
897 null(((LISTOP*)cBINOPo->op_first)->op_first);
898 scalar(cBINOPo->op_first);
903 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
907 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
908 if (!kPMOP->op_pmreplroot)
909 deprecate("implicit split to @_");
917 if (o->op_flags & OPf_KIDS) {
918 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
924 kid = cLISTOPo->op_first;
926 while (kid = kid->op_sibling) {
932 WITH_THR(PL_curcop = &PL_compiling);
937 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
943 WITH_THR(PL_curcop = &PL_compiling);
950 Perl_scalarvoid(pTHX_ OP *o)
957 if (o->op_type == OP_NEXTSTATE
958 || o->op_type == OP_SETSTATE
959 || o->op_type == OP_DBSTATE
960 || (o->op_type == OP_NULL && (o->op_targ == OP_NEXTSTATE
961 || o->op_targ == OP_SETSTATE
962 || o->op_targ == OP_DBSTATE)))
965 PL_curcop = (COP*)o; /* for warning below */
968 /* assumes no premature commitment */
969 want = o->op_flags & OPf_WANT;
970 if ((want && want != OPf_WANT_SCALAR) || PL_error_count
971 || o->op_type == OP_RETURN)
976 if ((o->op_private & OPpTARGET_MY)
977 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
979 return scalar(o); /* As if inside SASSIGN */
982 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_VOID;
984 switch (o->op_type) {
986 if (!(PL_opargs[o->op_type] & OA_FOLDCONST))
990 if (o->op_flags & OPf_STACKED)
994 if (o->op_private == 4)
1036 case OP_GETSOCKNAME:
1037 case OP_GETPEERNAME:
1042 case OP_GETPRIORITY:
1065 if (!(o->op_private & OPpLVAL_INTRO))
1066 useless = PL_op_desc[o->op_type];
1073 if (!(o->op_private & OPpLVAL_INTRO) &&
1074 (!o->op_sibling || o->op_sibling->op_type != OP_READLINE))
1075 useless = "a variable";
1080 if (cSVOPo->op_private & OPpCONST_STRICT)
1081 no_bareword_allowed(o);
1084 if (ckWARN(WARN_VOID)) {
1085 useless = "a constant";
1086 if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
1088 else if (SvPOK(sv)) {
1089 if (strnEQ(SvPVX(sv), "di", 2) ||
1090 strnEQ(SvPVX(sv), "ds", 2) ||
1091 strnEQ(SvPVX(sv), "ig", 2))
1096 null(o); /* don't execute or even remember it */
1100 o->op_type = OP_PREINC; /* pre-increment is faster */
1101 o->op_ppaddr = PL_ppaddr[OP_PREINC];
1105 o->op_type = OP_PREDEC; /* pre-decrement is faster */
1106 o->op_ppaddr = PL_ppaddr[OP_PREDEC];
1112 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1117 if (o->op_flags & OPf_STACKED)
1125 if (!(o->op_flags & OPf_KIDS))
1134 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1141 /* all requires must return a boolean value */
1142 o->op_flags &= ~OPf_WANT;
1145 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
1146 if (!kPMOP->op_pmreplroot)
1147 deprecate("implicit split to @_");
1153 if (ckWARN(WARN_VOID))
1154 Perl_warner(aTHX_ WARN_VOID, "Useless use of %s in void context", useless);
1160 Perl_listkids(pTHX_ OP *o)
1163 if (o && o->op_flags & OPf_KIDS) {
1164 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1171 Perl_list(pTHX_ OP *o)
1175 /* assumes no premature commitment */
1176 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
1177 || o->op_type == OP_RETURN)
1182 if ((o->op_private & OPpTARGET_MY)
1183 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
1185 return o; /* As if inside SASSIGN */
1188 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_LIST;
1190 switch (o->op_type) {
1193 list(cBINOPo->op_first);
1198 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1206 if (!(o->op_flags & OPf_KIDS))
1208 if (!o->op_next && cUNOPo->op_first->op_type == OP_FLOP) {
1209 list(cBINOPo->op_first);
1210 return gen_constant_list(o);
1217 kid = cLISTOPo->op_first;
1219 while (kid = kid->op_sibling) {
1220 if (kid->op_sibling)
1225 WITH_THR(PL_curcop = &PL_compiling);
1229 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
1230 if (kid->op_sibling)
1235 WITH_THR(PL_curcop = &PL_compiling);
1238 /* all requires must return a boolean value */
1239 o->op_flags &= ~OPf_WANT;
1246 Perl_scalarseq(pTHX_ OP *o)
1251 if (o->op_type == OP_LINESEQ ||
1252 o->op_type == OP_SCOPE ||
1253 o->op_type == OP_LEAVE ||
1254 o->op_type == OP_LEAVETRY)
1257 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
1258 if (kid->op_sibling) {
1262 PL_curcop = &PL_compiling;
1264 o->op_flags &= ~OPf_PARENS;
1265 if (PL_hints & HINT_BLOCK_SCOPE)
1266 o->op_flags |= OPf_PARENS;
1269 o = newOP(OP_STUB, 0);
1274 S_modkids(pTHX_ OP *o, I32 type)
1277 if (o && o->op_flags & OPf_KIDS) {
1278 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1285 Perl_mod(pTHX_ OP *o, I32 type)
1292 if (!o || PL_error_count)
1295 if ((o->op_private & OPpTARGET_MY)
1296 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
1301 switch (o->op_type) {
1306 if (!(o->op_private & (OPpCONST_ARYBASE)))
1308 if (PL_eval_start && PL_eval_start->op_type == OP_CONST) {
1309 PL_compiling.cop_arybase = (I32)SvIV(cSVOPx(PL_eval_start)->op_sv);
1313 SAVEI32(PL_compiling.cop_arybase);
1314 PL_compiling.cop_arybase = 0;
1316 else if (type == OP_REFGEN)
1319 Perl_croak(aTHX_ "That use of $[ is unsupported");
1322 if (o->op_flags & OPf_PARENS)
1326 if ((type == OP_UNDEF || type == OP_REFGEN) &&
1327 !(o->op_flags & OPf_STACKED)) {
1328 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1329 o->op_ppaddr = PL_ppaddr[OP_RV2CV];
1330 assert(cUNOPo->op_first->op_type == OP_NULL);
1331 null(((LISTOP*)cUNOPo->op_first)->op_first);/* disable pushmark */
1334 else { /* lvalue subroutine call */
1335 o->op_private |= OPpLVAL_INTRO;
1336 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN) {
1337 /* Backward compatibility mode: */
1338 o->op_private |= OPpENTERSUB_INARGS;
1341 else { /* Compile-time error message: */
1342 OP *kid = cUNOPo->op_first;
1346 if (kid->op_type == OP_PUSHMARK)
1348 if (kid->op_type != OP_NULL || kid->op_targ != OP_LIST)
1350 "panic: unexpected lvalue entersub "
1351 "args: type/targ %ld:%ld",
1352 (long)kid->op_type,kid->op_targ);
1353 kid = kLISTOP->op_first;
1355 while (kid->op_sibling)
1356 kid = kid->op_sibling;
1357 if (!(kid->op_type == OP_NULL && kid->op_targ == OP_RV2CV)) {
1359 if (kid->op_type == OP_METHOD_NAMED
1360 || kid->op_type == OP_METHOD)
1364 if (kid->op_sibling || kid->op_next != kid) {
1365 yyerror("panic: unexpected optree near method call");
1369 NewOp(1101, newop, 1, OP);
1370 newop->op_type = OP_RV2CV;
1371 newop->op_ppaddr = PL_ppaddr[OP_RV2CV];
1372 newop->op_next = newop;
1373 kid->op_sibling = newop;
1374 newop->op_private |= OPpLVAL_INTRO;
1378 if (kid->op_type != OP_RV2CV)
1380 "panic: unexpected lvalue entersub "
1381 "entry via type/targ %ld:%ld",
1382 (long)kid->op_type,kid->op_targ);
1383 kid->op_private |= OPpLVAL_INTRO;
1384 break; /* Postpone until runtime */
1388 kid = kUNOP->op_first;
1389 if (kid->op_type == OP_NULL && kid->op_targ == OP_RV2SV)
1390 kid = kUNOP->op_first;
1391 if (kid->op_type == OP_NULL)
1393 "Unexpected constant lvalue entersub "
1394 "entry via type/targ %ld:%ld",
1395 (long)kid->op_type,kid->op_targ);
1396 if (kid->op_type != OP_GV) {
1397 /* Restore RV2CV to check lvalueness */
1399 if (kid->op_next && kid->op_next != kid) { /* Happens? */
1400 okid->op_next = kid->op_next;
1401 kid->op_next = okid;
1404 okid->op_next = Nullop;
1405 okid->op_type = OP_RV2CV;
1407 okid->op_ppaddr = PL_ppaddr[OP_RV2CV];
1408 okid->op_private |= OPpLVAL_INTRO;
1412 cv = GvCV(kGVOP_gv);
1422 /* grep, foreach, subcalls, refgen */
1423 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
1425 yyerror(Perl_form(aTHX_ "Can't modify %s in %s",
1426 (o->op_type == OP_NULL && (o->op_flags & OPf_SPECIAL)
1428 : (o->op_type == OP_ENTERSUB
1429 ? "non-lvalue subroutine call"
1430 : PL_op_desc[o->op_type])),
1431 type ? PL_op_desc[type] : "local"));
1445 case OP_RIGHT_SHIFT:
1454 if (!(o->op_flags & OPf_STACKED))
1460 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1466 if (!type && cUNOPo->op_first->op_type != OP_GV)
1467 Perl_croak(aTHX_ "Can't localize through a reference");
1468 if (type == OP_REFGEN && o->op_flags & OPf_PARENS) {
1469 PL_modcount = 10000;
1470 return o; /* Treat \(@foo) like ordinary list. */
1474 if (scalar_mod_type(o, type))
1476 ref(cUNOPo->op_first, o->op_type);
1485 PL_modcount = 10000;
1488 if (!type && cUNOPo->op_first->op_type != OP_GV)
1489 Perl_croak(aTHX_ "Can't localize through a reference");
1490 ref(cUNOPo->op_first, o->op_type);
1494 PL_hints |= HINT_BLOCK_SCOPE;
1504 PL_modcount = 10000;
1505 if (type == OP_REFGEN && o->op_flags & OPf_PARENS)
1506 return o; /* Treat \(@foo) like ordinary list. */
1507 if (scalar_mod_type(o, type))
1513 Perl_croak(aTHX_ "Can't localize lexical variable %s",
1514 SvPV(*av_fetch(PL_comppad_name, o->op_targ, 4), n_a));
1519 PL_modcount++; /* XXX ??? */
1521 #endif /* USE_THREADS */
1527 if (type != OP_SASSIGN)
1531 if (o->op_private == 4) /* don't allow 4 arg substr as lvalue */
1537 pad_free(o->op_targ);
1538 o->op_targ = pad_alloc(o->op_type, SVs_PADMY);
1539 assert(SvTYPE(PAD_SV(o->op_targ)) == SVt_NULL);
1540 if (o->op_flags & OPf_KIDS)
1541 mod(cBINOPo->op_first->op_sibling, type);
1546 ref(cBINOPo->op_first, o->op_type);
1547 if (type == OP_ENTERSUB &&
1548 !(o->op_private & (OPpLVAL_INTRO | OPpDEREF)))
1549 o->op_private |= OPpLVAL_DEFER;
1556 if (o->op_flags & OPf_KIDS)
1557 mod(cLISTOPo->op_last, type);
1561 if (o->op_flags & OPf_SPECIAL) /* do BLOCK */
1563 else if (!(o->op_flags & OPf_KIDS))
1565 if (o->op_targ != OP_LIST) {
1566 mod(cBINOPo->op_first, type);
1571 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1575 o->op_flags |= OPf_MOD;
1577 if (type == OP_AASSIGN || type == OP_SASSIGN)
1578 o->op_flags |= OPf_SPECIAL|OPf_REF;
1580 o->op_private |= OPpLVAL_INTRO;
1581 o->op_flags &= ~OPf_SPECIAL;
1582 PL_hints |= HINT_BLOCK_SCOPE;
1584 else if (type != OP_GREPSTART && type != OP_ENTERSUB)
1585 o->op_flags |= OPf_REF;
1590 S_scalar_mod_type(pTHX_ OP *o, I32 type)
1594 if (o->op_type == OP_RV2GV)
1618 case OP_RIGHT_SHIFT:
1637 S_is_handle_constructor(pTHX_ OP *o, I32 argnum)
1639 switch (o->op_type) {
1647 case OP_SELECT: /* XXX c.f. SelectSaver.pm */
1660 Perl_refkids(pTHX_ OP *o, I32 type)
1663 if (o && o->op_flags & OPf_KIDS) {
1664 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1671 Perl_ref(pTHX_ OP *o, I32 type)
1675 if (!o || PL_error_count)
1678 switch (o->op_type) {
1680 if ((type == OP_DEFINED || type == OP_LOCK) &&
1681 !(o->op_flags & OPf_STACKED)) {
1682 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1683 o->op_ppaddr = PL_ppaddr[OP_RV2CV];
1684 assert(cUNOPo->op_first->op_type == OP_NULL);
1685 null(((LISTOP*)cUNOPo->op_first)->op_first); /* disable pushmark */
1686 o->op_flags |= OPf_SPECIAL;
1691 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1695 if (type == OP_DEFINED)
1696 o->op_flags |= OPf_SPECIAL; /* don't create GV */
1697 ref(cUNOPo->op_first, o->op_type);
1700 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1701 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1702 : type == OP_RV2HV ? OPpDEREF_HV
1704 o->op_flags |= OPf_MOD;
1709 o->op_flags |= OPf_MOD; /* XXX ??? */
1714 o->op_flags |= OPf_REF;
1717 if (type == OP_DEFINED)
1718 o->op_flags |= OPf_SPECIAL; /* don't create GV */
1719 ref(cUNOPo->op_first, o->op_type);
1724 o->op_flags |= OPf_REF;
1729 if (!(o->op_flags & OPf_KIDS))
1731 ref(cBINOPo->op_first, type);
1735 ref(cBINOPo->op_first, o->op_type);
1736 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1737 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1738 : type == OP_RV2HV ? OPpDEREF_HV
1740 o->op_flags |= OPf_MOD;
1748 if (!(o->op_flags & OPf_KIDS))
1750 ref(cLISTOPo->op_last, type);
1760 S_dup_attrlist(pTHX_ OP *o)
1764 /* An attrlist is either a simple OP_CONST or an OP_LIST with kids,
1765 * where the first kid is OP_PUSHMARK and the remaining ones
1766 * are OP_CONST. We need to push the OP_CONST values.
1768 if (o->op_type == OP_CONST)
1769 rop = newSVOP(OP_CONST, o->op_flags, SvREFCNT_inc(cSVOPo->op_sv));
1771 assert((o->op_type == OP_LIST) && (o->op_flags & OPf_KIDS));
1772 for (o = cLISTOPo->op_first; o; o=o->op_sibling) {
1773 if (o->op_type == OP_CONST)
1774 rop = append_elem(OP_LIST, rop,
1775 newSVOP(OP_CONST, o->op_flags,
1776 SvREFCNT_inc(cSVOPo->op_sv)));
1783 S_apply_attrs(pTHX_ HV *stash, SV *target, OP *attrs)
1785 OP *modname; /* for 'use' */
1788 /* fake up C<use attributes $pkg,$rv,@attrs> */
1789 ENTER; /* need to protect against side-effects of 'use' */
1791 if (stash && HvNAME(stash))
1792 stashsv = newSVpv(HvNAME(stash), 0);
1794 stashsv = &PL_sv_no;
1795 #define ATTRSMODULE "attributes"
1796 modname = newSVOP(OP_CONST, 0,
1797 newSVpvn(ATTRSMODULE, sizeof(ATTRSMODULE)-1));
1798 modname->op_private |= OPpCONST_BARE;
1799 /* that flag is required to make 'use' work right */
1800 utilize(1, start_subparse(FALSE, 0),
1801 Nullop, /* version */
1803 prepend_elem(OP_LIST,
1804 newSVOP(OP_CONST, 0, stashsv),
1805 prepend_elem(OP_LIST,
1806 newSVOP(OP_CONST, 0, newRV(target)),
1807 dup_attrlist(attrs))));
1812 S_my_kid(pTHX_ OP *o, OP *attrs)
1817 if (!o || PL_error_count)
1821 if (type == OP_LIST) {
1822 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1824 } else if (type == OP_UNDEF) {
1826 } else if (type == OP_RV2SV || /* "our" declaration */
1828 type == OP_RV2HV) { /* XXX does this let anything illegal in? */
1830 } else if (type != OP_PADSV &&
1833 type != OP_PUSHMARK)
1835 yyerror(Perl_form(aTHX_ "Can't declare %s in my", PL_op_desc[o->op_type]));
1838 else if (attrs && type != OP_PUSHMARK) {
1843 /* check for C<my Dog $spot> when deciding package */
1844 namesvp = av_fetch(PL_comppad_name, o->op_targ, FALSE);
1845 if (namesvp && *namesvp && SvOBJECT(*namesvp) && HvNAME(SvSTASH(*namesvp)))
1846 stash = SvSTASH(*namesvp);
1848 stash = PL_curstash;
1849 padsv = PAD_SV(o->op_targ);
1850 apply_attrs(stash, padsv, attrs);
1852 o->op_flags |= OPf_MOD;
1853 o->op_private |= OPpLVAL_INTRO;
1858 Perl_my_attrs(pTHX_ OP *o, OP *attrs)
1860 if (o->op_flags & OPf_PARENS)
1863 PL_in_my_stash = Nullhv;
1866 return my_kid(o, attrs);
1870 Perl_my(pTHX_ OP *o)
1872 return my_kid(o, Nullop);
1876 Perl_sawparens(pTHX_ OP *o)
1879 o->op_flags |= OPf_PARENS;
1884 Perl_bind_match(pTHX_ I32 type, OP *left, OP *right)
1889 if (ckWARN(WARN_UNSAFE) &&
1890 (left->op_type == OP_RV2AV ||
1891 left->op_type == OP_RV2HV ||
1892 left->op_type == OP_PADAV ||
1893 left->op_type == OP_PADHV)) {
1894 char *desc = PL_op_desc[(right->op_type == OP_SUBST ||
1895 right->op_type == OP_TRANS)
1896 ? right->op_type : OP_MATCH];
1897 const char *sample = ((left->op_type == OP_RV2AV ||
1898 left->op_type == OP_PADAV)
1899 ? "@array" : "%hash");
1900 Perl_warner(aTHX_ WARN_UNSAFE,
1901 "Applying %s to %s will act on scalar(%s)",
1902 desc, sample, sample);
1905 if (right->op_type == OP_MATCH ||
1906 right->op_type == OP_SUBST ||
1907 right->op_type == OP_TRANS) {
1908 right->op_flags |= OPf_STACKED;
1909 if (right->op_type != OP_MATCH)
1910 left = mod(left, right->op_type);
1911 if (right->op_type == OP_TRANS)
1912 o = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
1914 o = prepend_elem(right->op_type, scalar(left), right);
1916 return newUNOP(OP_NOT, 0, scalar(o));
1920 return bind_match(type, left,
1921 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
1925 Perl_invert(pTHX_ OP *o)
1929 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
1930 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(o));
1934 Perl_scope(pTHX_ OP *o)
1937 if (o->op_flags & OPf_PARENS || PERLDB_NOOPT || PL_tainting) {
1938 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
1939 o->op_type = OP_LEAVE;
1940 o->op_ppaddr = PL_ppaddr[OP_LEAVE];
1943 if (o->op_type == OP_LINESEQ) {
1945 o->op_type = OP_SCOPE;
1946 o->op_ppaddr = PL_ppaddr[OP_SCOPE];
1947 kid = ((LISTOP*)o)->op_first;
1948 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE)
1952 o = newLISTOP(OP_SCOPE, 0, o, Nullop);
1959 Perl_save_hints(pTHX)
1962 SAVESPTR(GvHV(PL_hintgv));
1963 GvHV(PL_hintgv) = newHVhv(GvHV(PL_hintgv));
1964 SAVEFREESV(GvHV(PL_hintgv));
1968 Perl_block_start(pTHX_ int full)
1971 int retval = PL_savestack_ix;
1973 SAVEI32(PL_comppad_name_floor);
1975 if ((PL_comppad_name_fill = AvFILLp(PL_comppad_name)) > 0)
1976 PL_comppad_name_floor = PL_comppad_name_fill;
1978 PL_comppad_name_floor = 0;
1980 SAVEI32(PL_min_intro_pending);
1981 SAVEI32(PL_max_intro_pending);
1982 PL_min_intro_pending = 0;
1983 SAVEI32(PL_comppad_name_fill);
1984 SAVEI32(PL_padix_floor);
1985 PL_padix_floor = PL_padix;
1986 PL_pad_reset_pending = FALSE;
1988 PL_hints &= ~HINT_BLOCK_SCOPE;
1989 SAVESPTR(PL_compiling.cop_warnings);
1990 if (! specialWARN(PL_compiling.cop_warnings)) {
1991 PL_compiling.cop_warnings = newSVsv(PL_compiling.cop_warnings) ;
1992 SAVEFREESV(PL_compiling.cop_warnings) ;
2000 Perl_block_end(pTHX_ I32 floor, OP *seq)
2003 int needblockscope = PL_hints & HINT_BLOCK_SCOPE;
2004 OP* retval = scalarseq(seq);
2006 PL_pad_reset_pending = FALSE;
2007 PL_compiling.op_private = PL_hints;
2009 PL_hints |= HINT_BLOCK_SCOPE; /* propagate out */
2010 pad_leavemy(PL_comppad_name_fill);
2019 OP *o = newOP(OP_THREADSV, 0);
2020 o->op_targ = find_threadsv("_");
2023 return newSVREF(newGVOP(OP_GV, 0, PL_defgv));
2024 #endif /* USE_THREADS */
2028 Perl_newPROG(pTHX_ OP *o)
2034 PL_eval_root = newUNOP(OP_LEAVEEVAL,
2035 ((PL_in_eval & EVAL_KEEPERR)
2036 ? OPf_SPECIAL : 0), o);
2037 PL_eval_start = linklist(PL_eval_root);
2038 PL_eval_root->op_private |= OPpREFCOUNTED;
2039 OpREFCNT_set(PL_eval_root, 1);
2040 PL_eval_root->op_next = 0;
2041 peep(PL_eval_start);
2046 PL_main_root = scope(sawparens(scalarvoid(o)));
2047 PL_curcop = &PL_compiling;
2048 PL_main_start = LINKLIST(PL_main_root);
2049 PL_main_root->op_private |= OPpREFCOUNTED;
2050 OpREFCNT_set(PL_main_root, 1);
2051 PL_main_root->op_next = 0;
2052 peep(PL_main_start);
2055 /* Register with debugger */
2057 CV *cv = get_cv("DB::postponed", FALSE);
2061 XPUSHs((SV*)CopFILEGV(&PL_compiling));
2063 call_sv((SV*)cv, G_DISCARD);
2070 Perl_localize(pTHX_ OP *o, I32 lex)
2072 if (o->op_flags & OPf_PARENS)
2076 if (ckWARN(WARN_PARENTHESIS) && PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == ',') {
2078 for (s = PL_bufptr; *s && (isALNUM(*s) || (*s & 0x80) || strchr("@$%, ",*s)); s++) ;
2079 if (*s == ';' || *s == '=')
2080 Perl_warner(aTHX_ WARN_PARENTHESIS, "Parentheses missing around \"%s\" list",
2081 lex ? "my" : "local");
2085 PL_in_my_stash = Nullhv;
2089 return mod(o, OP_NULL); /* a bit kludgey */
2093 Perl_jmaybe(pTHX_ OP *o)
2095 if (o->op_type == OP_LIST) {
2098 o2 = newOP(OP_THREADSV, 0);
2099 o2->op_targ = find_threadsv(";");
2101 o2 = newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
2102 #endif /* USE_THREADS */
2103 o = convert(OP_JOIN, 0, prepend_elem(OP_LIST, o2, o));
2109 Perl_fold_constants(pTHX_ register OP *o)
2113 I32 type = o->op_type;
2116 if (PL_opargs[type] & OA_RETSCALAR)
2118 if (PL_opargs[type] & OA_TARGET && !o->op_targ)
2119 o->op_targ = pad_alloc(type, SVs_PADTMP);
2121 /* integerize op, unless it happens to be C<-foo>.
2122 * XXX should pp_i_negate() do magic string negation instead? */
2123 if ((PL_opargs[type] & OA_OTHERINT) && (PL_hints & HINT_INTEGER)
2124 && !(type == OP_NEGATE && cUNOPo->op_first->op_type == OP_CONST
2125 && (cUNOPo->op_first->op_private & OPpCONST_BARE)))
2127 o->op_ppaddr = PL_ppaddr[type = ++(o->op_type)];
2130 if (!(PL_opargs[type] & OA_FOLDCONST))
2135 /* XXX might want a ck_negate() for this */
2136 cUNOPo->op_first->op_private &= ~OPpCONST_STRICT;
2149 if (o->op_private & OPpLOCALE)
2154 goto nope; /* Don't try to run w/ errors */
2156 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
2157 if ((curop->op_type != OP_CONST ||
2158 (curop->op_private & OPpCONST_BARE)) &&
2159 curop->op_type != OP_LIST &&
2160 curop->op_type != OP_SCALAR &&
2161 curop->op_type != OP_NULL &&
2162 curop->op_type != OP_PUSHMARK)
2168 curop = LINKLIST(o);
2172 sv = *(PL_stack_sp--);
2173 if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
2174 pad_swipe(o->op_targ);
2175 else if (SvTEMP(sv)) { /* grab mortal temp? */
2176 (void)SvREFCNT_inc(sv);
2180 if (type == OP_RV2GV)
2181 return newGVOP(OP_GV, 0, (GV*)sv);
2183 /* try to smush double to int, but don't smush -2.0 to -2 */
2184 if ((SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK)) == SVf_NOK &&
2188 if ((NV)iv == SvNV(sv)) {
2193 SvIOK_off(sv); /* undo SvIV() damage */
2195 return newSVOP(OP_CONST, 0, sv);
2199 if (!(PL_opargs[type] & OA_OTHERINT))
2202 if (!(PL_hints & HINT_INTEGER)) {
2203 if (type == OP_MODULO
2204 || type == OP_DIVIDE
2205 || !(o->op_flags & OPf_KIDS))
2210 for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
2211 if (curop->op_type == OP_CONST) {
2212 if (SvIOK(((SVOP*)curop)->op_sv))
2216 if (PL_opargs[curop->op_type] & OA_RETINTEGER)
2220 o->op_ppaddr = PL_ppaddr[++(o->op_type)];
2227 Perl_gen_constant_list(pTHX_ register OP *o)
2231 I32 oldtmps_floor = PL_tmps_floor;
2235 return o; /* Don't attempt to run with errors */
2237 PL_op = curop = LINKLIST(o);
2243 PL_tmps_floor = oldtmps_floor;
2245 o->op_type = OP_RV2AV;
2246 o->op_ppaddr = PL_ppaddr[OP_RV2AV];
2247 curop = ((UNOP*)o)->op_first;
2248 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*PL_stack_sp--));
2255 Perl_convert(pTHX_ I32 type, I32 flags, OP *o)
2260 if (!o || o->op_type != OP_LIST)
2261 o = newLISTOP(OP_LIST, 0, o, Nullop);
2263 o->op_flags &= ~OPf_WANT;
2265 if (!(PL_opargs[type] & OA_MARK))
2266 null(cLISTOPo->op_first);
2269 o->op_ppaddr = PL_ppaddr[type];
2270 o->op_flags |= flags;
2272 o = CHECKOP(type, o);
2273 if (o->op_type != type)
2276 if (cLISTOPo->op_children < 7) {
2277 /* XXX do we really need to do this if we're done appending?? */
2278 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
2280 cLISTOPo->op_last = last; /* in case check substituted last arg */
2283 return fold_constants(o);
2286 /* List constructors */
2289 Perl_append_elem(pTHX_ I32 type, OP *first, OP *last)
2297 if (first->op_type != type || type==OP_LIST && first->op_flags & OPf_PARENS)
2298 return newLISTOP(type, 0, first, last);
2300 if (first->op_flags & OPf_KIDS)
2301 ((LISTOP*)first)->op_last->op_sibling = last;
2303 first->op_flags |= OPf_KIDS;
2304 ((LISTOP*)first)->op_first = last;
2306 ((LISTOP*)first)->op_last = last;
2307 ((LISTOP*)first)->op_children++;
2312 Perl_append_list(pTHX_ I32 type, LISTOP *first, LISTOP *last)
2320 if (first->op_type != type)
2321 return prepend_elem(type, (OP*)first, (OP*)last);
2323 if (last->op_type != type)
2324 return append_elem(type, (OP*)first, (OP*)last);
2326 first->op_last->op_sibling = last->op_first;
2327 first->op_last = last->op_last;
2328 first->op_children += last->op_children;
2329 if (first->op_children)
2330 first->op_flags |= OPf_KIDS;
2332 #ifdef PL_OP_SLAB_ALLOC
2340 Perl_prepend_elem(pTHX_ I32 type, OP *first, OP *last)
2348 if (last->op_type == type) {
2349 if (type == OP_LIST) { /* already a PUSHMARK there */
2350 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
2351 ((LISTOP*)last)->op_first->op_sibling = first;
2354 if (!(last->op_flags & OPf_KIDS)) {
2355 ((LISTOP*)last)->op_last = first;
2356 last->op_flags |= OPf_KIDS;
2358 first->op_sibling = ((LISTOP*)last)->op_first;
2359 ((LISTOP*)last)->op_first = first;
2361 ((LISTOP*)last)->op_children++;
2365 return newLISTOP(type, 0, first, last);
2371 Perl_newNULLLIST(pTHX)
2373 return newOP(OP_STUB, 0);
2377 Perl_force_list(pTHX_ OP *o)
2379 if (!o || o->op_type != OP_LIST)
2380 o = newLISTOP(OP_LIST, 0, o, Nullop);
2386 Perl_newLISTOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
2390 NewOp(1101, listop, 1, LISTOP);
2392 listop->op_type = type;
2393 listop->op_ppaddr = PL_ppaddr[type];
2394 listop->op_children = (first != 0) + (last != 0);
2395 listop->op_flags = flags;
2399 else if (!first && last)
2402 first->op_sibling = last;
2403 listop->op_first = first;
2404 listop->op_last = last;
2405 if (type == OP_LIST) {
2407 pushop = newOP(OP_PUSHMARK, 0);
2408 pushop->op_sibling = first;
2409 listop->op_first = pushop;
2410 listop->op_flags |= OPf_KIDS;
2412 listop->op_last = pushop;
2414 else if (listop->op_children)
2415 listop->op_flags |= OPf_KIDS;
2421 Perl_newOP(pTHX_ I32 type, I32 flags)
2424 NewOp(1101, o, 1, OP);
2426 o->op_ppaddr = PL_ppaddr[type];
2427 o->op_flags = flags;
2430 o->op_private = 0 + (flags >> 8);
2431 if (PL_opargs[type] & OA_RETSCALAR)
2433 if (PL_opargs[type] & OA_TARGET)
2434 o->op_targ = pad_alloc(type, SVs_PADTMP);
2435 return CHECKOP(type, o);
2439 Perl_newUNOP(pTHX_ I32 type, I32 flags, OP *first)
2444 first = newOP(OP_STUB, 0);
2445 if (PL_opargs[type] & OA_MARK)
2446 first = force_list(first);
2448 NewOp(1101, unop, 1, UNOP);
2449 unop->op_type = type;
2450 unop->op_ppaddr = PL_ppaddr[type];
2451 unop->op_first = first;
2452 unop->op_flags = flags | OPf_KIDS;
2453 unop->op_private = 1 | (flags >> 8);
2454 unop = (UNOP*) CHECKOP(type, unop);
2458 return fold_constants((OP *) unop);
2462 Perl_newBINOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
2465 NewOp(1101, binop, 1, BINOP);
2468 first = newOP(OP_NULL, 0);
2470 binop->op_type = type;
2471 binop->op_ppaddr = PL_ppaddr[type];
2472 binop->op_first = first;
2473 binop->op_flags = flags | OPf_KIDS;
2476 binop->op_private = 1 | (flags >> 8);
2479 binop->op_private = 2 | (flags >> 8);
2480 first->op_sibling = last;
2483 binop = (BINOP*)CHECKOP(type, binop);
2484 if (binop->op_next || binop->op_type != type)
2487 binop->op_last = binop->op_first->op_sibling;
2489 return fold_constants((OP *)binop);
2493 utf8compare(const void *a, const void *b)
2496 for (i = 0; i < 10; i++) {
2497 if ((*(U8**)a)[i] < (*(U8**)b)[i])
2499 if ((*(U8**)a)[i] > (*(U8**)b)[i])
2506 Perl_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
2508 SV *tstr = ((SVOP*)expr)->op_sv;
2509 SV *rstr = ((SVOP*)repl)->op_sv;
2512 register U8 *t = (U8*)SvPV(tstr, tlen);
2513 register U8 *r = (U8*)SvPV(rstr, rlen);
2519 register short *tbl;
2521 complement = o->op_private & OPpTRANS_COMPLEMENT;
2522 del = o->op_private & OPpTRANS_DELETE;
2523 squash = o->op_private & OPpTRANS_SQUASH;
2525 if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
2526 SV* listsv = newSVpvn("# comment\n",10);
2528 U8* tend = t + tlen;
2529 U8* rend = r + rlen;
2545 I32 from_utf = o->op_private & OPpTRANS_FROM_UTF;
2546 I32 to_utf = o->op_private & OPpTRANS_TO_UTF;
2552 New(1109, cp, tlen, U8*);
2554 transv = newSVpvn("",0);
2563 qsort(cp, i, sizeof(U8*), utf8compare);
2564 for (j = 0; j < i; j++) {
2566 UV val = utf8_to_uv(s, &ulen);
2568 diff = val - nextmin;
2570 t = uv_to_utf8(tmpbuf,nextmin);
2571 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2573 t = uv_to_utf8(tmpbuf, val - 1);
2574 sv_catpvn(transv, "\377", 1);
2575 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2579 val = utf8_to_uv(s+1, &ulen);
2583 t = uv_to_utf8(tmpbuf,nextmin);
2584 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2585 t = uv_to_utf8(tmpbuf, 0x7fffffff);
2586 sv_catpvn(transv, "\377", 1);
2587 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2588 t = (U8*)SvPVX(transv);
2589 tlen = SvCUR(transv);
2592 else if (!rlen && !del) {
2593 r = t; rlen = tlen; rend = tend;
2596 if (to_utf && from_utf) { /* only counting characters */
2597 if (t == r || (tlen == rlen && memEQ(t, r, tlen)))
2598 o->op_private |= OPpTRANS_IDENTICAL;
2600 else { /* straight latin-1 translation */
2601 if (tlen == 4 && memEQ(t, "\0\377\303\277", 4) &&
2602 rlen == 4 && memEQ(r, "\0\377\303\277", 4))
2603 o->op_private |= OPpTRANS_IDENTICAL;
2607 while (t < tend || tfirst <= tlast) {
2608 /* see if we need more "t" chars */
2609 if (tfirst > tlast) {
2610 tfirst = (I32)utf8_to_uv(t, &ulen);
2612 if (t < tend && *t == 0xff) { /* illegal utf8 val indicates range */
2613 tlast = (I32)utf8_to_uv(++t, &ulen);
2620 /* now see if we need more "r" chars */
2621 if (rfirst > rlast) {
2623 rfirst = (I32)utf8_to_uv(r, &ulen);
2625 if (r < rend && *r == 0xff) { /* illegal utf8 val indicates range */
2626 rlast = (I32)utf8_to_uv(++r, &ulen);
2635 rfirst = rlast = 0xffffffff;
2639 /* now see which range will peter our first, if either. */
2640 tdiff = tlast - tfirst;
2641 rdiff = rlast - rfirst;
2648 if (rfirst == 0xffffffff) {
2649 diff = tdiff; /* oops, pretend rdiff is infinite */
2651 Perl_sv_catpvf(aTHX_ listsv, "%04x\t%04x\tXXXX\n", tfirst, tlast);
2653 Perl_sv_catpvf(aTHX_ listsv, "%04x\t\tXXXX\n", tfirst);
2657 Perl_sv_catpvf(aTHX_ listsv, "%04x\t%04x\t%04x\n", tfirst, tfirst + diff, rfirst);
2659 Perl_sv_catpvf(aTHX_ listsv, "%04x\t\t%04x\n", tfirst, rfirst);
2661 if (rfirst + diff > max)
2662 max = rfirst + diff;
2667 else if (rfirst <= 0x800)
2668 grows |= (tfirst < 0x80);
2669 else if (rfirst <= 0x10000)
2670 grows |= (tfirst < 0x800);
2671 else if (rfirst <= 0x200000)
2672 grows |= (tfirst < 0x10000);
2673 else if (rfirst <= 0x4000000)
2674 grows |= (tfirst < 0x200000);
2675 else if (rfirst <= 0x80000000)
2676 grows |= (tfirst < 0x4000000);
2688 else if (max > 0xff)
2693 cSVOPo->op_sv = (SV*)swash_init("utf8", "", listsv, bits, none);
2694 SvREFCNT_dec(listsv);
2696 SvREFCNT_dec(transv);
2698 if (!del && havefinal)
2699 (void)hv_store((HV*)SvRV((cSVOPo->op_sv)), "FINAL", 5, newSViv((IV)final), 0);
2701 if (grows && to_utf)
2702 o->op_private |= OPpTRANS_GROWS;
2709 tbl = (short*)cPVOPo->op_pv;
2711 Zero(tbl, 256, short);
2712 for (i = 0; i < tlen; i++)
2714 for (i = 0, j = 0; i < 256; i++) {
2730 if (!rlen && !del) {
2733 o->op_private |= OPpTRANS_IDENTICAL;
2735 for (i = 0; i < 256; i++)
2737 for (i = 0, j = 0; i < tlen; i++,j++) {
2740 if (tbl[t[i]] == -1)
2746 if (tbl[t[i]] == -1)
2757 Perl_newPMOP(pTHX_ I32 type, I32 flags)
2762 NewOp(1101, pmop, 1, PMOP);
2763 pmop->op_type = type;
2764 pmop->op_ppaddr = PL_ppaddr[type];
2765 pmop->op_flags = flags;
2766 pmop->op_private = 0 | (flags >> 8);
2768 if (PL_hints & HINT_RE_TAINT)
2769 pmop->op_pmpermflags |= PMf_RETAINT;
2770 if (PL_hints & HINT_LOCALE)
2771 pmop->op_pmpermflags |= PMf_LOCALE;
2772 pmop->op_pmflags = pmop->op_pmpermflags;
2774 /* link into pm list */
2775 if (type != OP_TRANS && PL_curstash) {
2776 pmop->op_pmnext = HvPMROOT(PL_curstash);
2777 HvPMROOT(PL_curstash) = pmop;
2784 Perl_pmruntime(pTHX_ OP *o, OP *expr, OP *repl)
2789 I32 repl_has_vars = 0;
2791 if (o->op_type == OP_TRANS)
2792 return pmtrans(o, expr, repl);
2794 PL_hints |= HINT_BLOCK_SCOPE;
2797 if (expr->op_type == OP_CONST) {
2799 SV *pat = ((SVOP*)expr)->op_sv;
2800 char *p = SvPV(pat, plen);
2801 if ((o->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
2802 sv_setpvn(pat, "\\s+", 3);
2803 p = SvPV(pat, plen);
2804 pm->op_pmflags |= PMf_SKIPWHITE;
2806 pm->op_pmregexp = CALLREGCOMP(aTHX_ p, p + plen, pm);
2807 if (strEQ("\\s+", pm->op_pmregexp->precomp))
2808 pm->op_pmflags |= PMf_WHITE;
2812 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL))
2813 expr = newUNOP((!(PL_hints & HINT_RE_EVAL)
2815 : OP_REGCMAYBE),0,expr);
2817 NewOp(1101, rcop, 1, LOGOP);
2818 rcop->op_type = OP_REGCOMP;
2819 rcop->op_ppaddr = PL_ppaddr[OP_REGCOMP];
2820 rcop->op_first = scalar(expr);
2821 rcop->op_flags |= ((PL_hints & HINT_RE_EVAL)
2822 ? (OPf_SPECIAL | OPf_KIDS)
2824 rcop->op_private = 1;
2827 /* establish postfix order */
2828 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL)) {
2830 rcop->op_next = expr;
2831 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
2834 rcop->op_next = LINKLIST(expr);
2835 expr->op_next = (OP*)rcop;
2838 prepend_elem(o->op_type, scalar((OP*)rcop), o);
2843 if (pm->op_pmflags & PMf_EVAL) {
2845 if (CopLINE(PL_curcop) < PL_multi_end)
2846 CopLINE_set(PL_curcop, PL_multi_end);
2849 else if (repl->op_type == OP_THREADSV
2850 && strchr("&`'123456789+",
2851 PL_threadsv_names[repl->op_targ]))
2855 #endif /* USE_THREADS */
2856 else if (repl->op_type == OP_CONST)
2860 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
2861 if (PL_opargs[curop->op_type] & OA_DANGEROUS) {
2863 if (curop->op_type == OP_THREADSV) {
2865 if (strchr("&`'123456789+", curop->op_private))
2869 if (curop->op_type == OP_GV) {
2870 GV *gv = cGVOPx_gv(curop);
2872 if (strchr("&`'123456789+", *GvENAME(gv)))
2875 #endif /* USE_THREADS */
2876 else if (curop->op_type == OP_RV2CV)
2878 else if (curop->op_type == OP_RV2SV ||
2879 curop->op_type == OP_RV2AV ||
2880 curop->op_type == OP_RV2HV ||
2881 curop->op_type == OP_RV2GV) {
2882 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
2885 else if (curop->op_type == OP_PADSV ||
2886 curop->op_type == OP_PADAV ||
2887 curop->op_type == OP_PADHV ||
2888 curop->op_type == OP_PADANY) {
2891 else if (curop->op_type == OP_PUSHRE)
2892 ; /* Okay here, dangerous in newASSIGNOP */
2901 && (!pm->op_pmregexp
2902 || pm->op_pmregexp->reganch & ROPT_EVAL_SEEN))) {
2903 pm->op_pmflags |= PMf_CONST; /* const for long enough */
2904 pm->op_pmpermflags |= PMf_CONST; /* const for long enough */
2905 prepend_elem(o->op_type, scalar(repl), o);
2908 if (curop == repl && !pm->op_pmregexp) { /* Has variables. */
2909 pm->op_pmflags |= PMf_MAYBE_CONST;
2910 pm->op_pmpermflags |= PMf_MAYBE_CONST;
2912 NewOp(1101, rcop, 1, LOGOP);
2913 rcop->op_type = OP_SUBSTCONT;
2914 rcop->op_ppaddr = PL_ppaddr[OP_SUBSTCONT];
2915 rcop->op_first = scalar(repl);
2916 rcop->op_flags |= OPf_KIDS;
2917 rcop->op_private = 1;
2920 /* establish postfix order */
2921 rcop->op_next = LINKLIST(repl);
2922 repl->op_next = (OP*)rcop;
2924 pm->op_pmreplroot = scalar((OP*)rcop);
2925 pm->op_pmreplstart = LINKLIST(rcop);
2934 Perl_newSVOP(pTHX_ I32 type, I32 flags, SV *sv)
2937 NewOp(1101, svop, 1, SVOP);
2938 svop->op_type = type;
2939 svop->op_ppaddr = PL_ppaddr[type];
2941 svop->op_next = (OP*)svop;
2942 svop->op_flags = flags;
2943 if (PL_opargs[type] & OA_RETSCALAR)
2945 if (PL_opargs[type] & OA_TARGET)
2946 svop->op_targ = pad_alloc(type, SVs_PADTMP);
2947 return CHECKOP(type, svop);
2951 Perl_newPADOP(pTHX_ I32 type, I32 flags, SV *sv)
2954 NewOp(1101, padop, 1, PADOP);
2955 padop->op_type = type;
2956 padop->op_ppaddr = PL_ppaddr[type];
2957 padop->op_padix = pad_alloc(type, SVs_PADTMP);
2958 SvREFCNT_dec(PL_curpad[padop->op_padix]);
2959 PL_curpad[padop->op_padix] = sv;
2961 padop->op_next = (OP*)padop;
2962 padop->op_flags = flags;
2963 if (PL_opargs[type] & OA_RETSCALAR)
2965 if (PL_opargs[type] & OA_TARGET)
2966 padop->op_targ = pad_alloc(type, SVs_PADTMP);
2967 return CHECKOP(type, padop);
2971 Perl_newGVOP(pTHX_ I32 type, I32 flags, GV *gv)
2976 return newPADOP(type, flags, SvREFCNT_inc(gv));
2978 return newSVOP(type, flags, SvREFCNT_inc(gv));
2983 Perl_newPVOP(pTHX_ I32 type, I32 flags, char *pv)
2986 NewOp(1101, pvop, 1, PVOP);
2987 pvop->op_type = type;
2988 pvop->op_ppaddr = PL_ppaddr[type];
2990 pvop->op_next = (OP*)pvop;
2991 pvop->op_flags = flags;
2992 if (PL_opargs[type] & OA_RETSCALAR)
2994 if (PL_opargs[type] & OA_TARGET)
2995 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
2996 return CHECKOP(type, pvop);
3000 Perl_package(pTHX_ OP *o)
3005 save_hptr(&PL_curstash);
3006 save_item(PL_curstname);
3011 name = SvPV(sv, len);
3012 PL_curstash = gv_stashpvn(name,len,TRUE);
3013 sv_setpvn(PL_curstname, name, len);
3017 sv_setpv(PL_curstname,"<none>");
3018 PL_curstash = Nullhv;
3020 PL_hints |= HINT_BLOCK_SCOPE;
3021 PL_copline = NOLINE;
3026 Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *id, OP *arg)
3035 if (id->op_type != OP_CONST)
3036 Perl_croak(aTHX_ "Module name must be constant");
3040 if(version != Nullop) {
3041 SV *vesv = ((SVOP*)version)->op_sv;
3043 if (arg == Nullop && !SvNIOK(vesv)) {
3049 if (version->op_type != OP_CONST || !SvNIOK(vesv))
3050 Perl_croak(aTHX_ "Version number must be constant number");
3052 /* Make copy of id so we don't free it twice */
3053 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
3055 /* Fake up a method call to VERSION */
3056 veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
3057 append_elem(OP_LIST,
3058 prepend_elem(OP_LIST, pack, list(version)),
3059 newSVOP(OP_METHOD_NAMED, 0,
3060 newSVpvn("VERSION", 7))));
3064 /* Fake up an import/unimport */
3065 if (arg && arg->op_type == OP_STUB)
3066 imop = arg; /* no import on explicit () */
3067 else if(SvNIOK(((SVOP*)id)->op_sv)) {
3068 imop = Nullop; /* use 5.0; */
3071 /* Make copy of id so we don't free it twice */
3072 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
3073 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
3074 append_elem(OP_LIST,
3075 prepend_elem(OP_LIST, pack, list(arg)),
3076 newSVOP(OP_METHOD_NAMED, 0,
3077 aver ? newSVpvn("import", 6)
3078 : newSVpvn("unimport", 8))));
3081 /* Fake up a require, handle override, if any */
3082 gv = gv_fetchpv("require", FALSE, SVt_PVCV);
3083 if (!(gv && GvIMPORTED_CV(gv)))
3084 gv = gv_fetchpv("CORE::GLOBAL::require", FALSE, SVt_PVCV);
3086 if (gv && GvIMPORTED_CV(gv)) {
3087 rqop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
3088 append_elem(OP_LIST, id,
3089 scalar(newUNOP(OP_RV2CV, 0,
3094 rqop = newUNOP(OP_REQUIRE, 0, id);
3097 /* Fake up the BEGIN {}, which does its thing immediately. */
3099 newSVOP(OP_CONST, 0, newSVpvn("BEGIN", 5)),
3102 append_elem(OP_LINESEQ,
3103 append_elem(OP_LINESEQ,
3104 newSTATEOP(0, Nullch, rqop),
3105 newSTATEOP(0, Nullch, veop)),
3106 newSTATEOP(0, Nullch, imop) ));
3108 PL_hints |= HINT_BLOCK_SCOPE;
3109 PL_copline = NOLINE;
3114 Perl_dofile(pTHX_ OP *term)
3119 gv = gv_fetchpv("do", FALSE, SVt_PVCV);
3120 if (!(gv && GvIMPORTED_CV(gv)))
3121 gv = gv_fetchpv("CORE::GLOBAL::do", FALSE, SVt_PVCV);
3123 if (gv && GvIMPORTED_CV(gv)) {
3124 doop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
3125 append_elem(OP_LIST, term,
3126 scalar(newUNOP(OP_RV2CV, 0,
3131 doop = newUNOP(OP_DOFILE, 0, scalar(term));
3137 Perl_newSLICEOP(pTHX_ I32 flags, OP *subscript, OP *listval)
3139 return newBINOP(OP_LSLICE, flags,
3140 list(force_list(subscript)),
3141 list(force_list(listval)) );
3145 S_list_assignment(pTHX_ register OP *o)
3150 if (o->op_type == OP_NULL && o->op_flags & OPf_KIDS)
3151 o = cUNOPo->op_first;
3153 if (o->op_type == OP_COND_EXPR) {
3154 I32 t = list_assignment(cLOGOPo->op_first->op_sibling);
3155 I32 f = list_assignment(cLOGOPo->op_first->op_sibling->op_sibling);
3160 yyerror("Assignment to both a list and a scalar");
3164 if (o->op_type == OP_LIST || o->op_flags & OPf_PARENS ||
3165 o->op_type == OP_RV2AV || o->op_type == OP_RV2HV ||
3166 o->op_type == OP_ASLICE || o->op_type == OP_HSLICE)
3169 if (o->op_type == OP_PADAV || o->op_type == OP_PADHV)
3172 if (o->op_type == OP_RV2SV)
3179 Perl_newASSIGNOP(pTHX_ I32 flags, OP *left, I32 optype, OP *right)
3184 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN) {
3185 return newLOGOP(optype, 0,
3186 mod(scalar(left), optype),
3187 newUNOP(OP_SASSIGN, 0, scalar(right)));
3190 return newBINOP(optype, OPf_STACKED,
3191 mod(scalar(left), optype), scalar(right));
3195 if (list_assignment(left)) {
3198 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
3199 left = mod(left, OP_AASSIGN);
3207 o = newBINOP(OP_AASSIGN, flags,
3208 list(force_list(right)),
3209 list(force_list(left)) );
3210 o->op_private = 0 | (flags >> 8);
3211 if (!(left->op_private & OPpLVAL_INTRO)) {
3215 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
3216 if (PL_opargs[curop->op_type] & OA_DANGEROUS) {
3217 if (curop->op_type == OP_GV) {
3218 GV *gv = cGVOPx_gv(curop);
3219 if (gv == PL_defgv || SvCUR(gv) == PL_generation)
3221 SvCUR(gv) = PL_generation;
3223 else if (curop->op_type == OP_PADSV ||
3224 curop->op_type == OP_PADAV ||
3225 curop->op_type == OP_PADHV ||
3226 curop->op_type == OP_PADANY) {
3227 SV **svp = AvARRAY(PL_comppad_name);
3228 SV *sv = svp[curop->op_targ];
3229 if (SvCUR(sv) == PL_generation)
3231 SvCUR(sv) = PL_generation; /* (SvCUR not used any more) */
3233 else if (curop->op_type == OP_RV2CV)
3235 else if (curop->op_type == OP_RV2SV ||
3236 curop->op_type == OP_RV2AV ||
3237 curop->op_type == OP_RV2HV ||
3238 curop->op_type == OP_RV2GV) {
3239 if (lastop->op_type != OP_GV) /* funny deref? */
3242 else if (curop->op_type == OP_PUSHRE) {
3243 if (((PMOP*)curop)->op_pmreplroot) {
3244 GV *gv = (GV*)((PMOP*)curop)->op_pmreplroot;
3245 if (gv == PL_defgv || SvCUR(gv) == PL_generation)
3247 SvCUR(gv) = PL_generation;
3256 o->op_private = OPpASSIGN_COMMON;
3258 if (right && right->op_type == OP_SPLIT) {
3260 if ((tmpop = ((LISTOP*)right)->op_first) &&
3261 tmpop->op_type == OP_PUSHRE)
3263 PMOP *pm = (PMOP*)tmpop;
3264 if (left->op_type == OP_RV2AV &&
3265 !(left->op_private & OPpLVAL_INTRO) &&
3266 !(o->op_private & OPpASSIGN_COMMON) )
3268 tmpop = ((UNOP*)left)->op_first;
3269 if (tmpop->op_type == OP_GV && !pm->op_pmreplroot) {
3271 pm->op_pmreplroot = (OP*)cPADOPx(tmpop)->op_padix;
3272 cPADOPx(tmpop)->op_padix = 0; /* steal it */
3274 pm->op_pmreplroot = (OP*)cSVOPx(tmpop)->op_sv;
3275 cSVOPx(tmpop)->op_sv = Nullsv; /* steal it */
3277 pm->op_pmflags |= PMf_ONCE;
3278 tmpop = cUNOPo->op_first; /* to list (nulled) */
3279 tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */
3280 tmpop->op_sibling = Nullop; /* don't free split */
3281 right->op_next = tmpop->op_next; /* fix starting loc */
3282 op_free(o); /* blow off assign */
3283 right->op_flags &= ~OPf_WANT;
3284 /* "I don't know and I don't care." */
3289 if (PL_modcount < 10000 &&
3290 ((LISTOP*)right)->op_last->op_type == OP_CONST)
3292 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
3294 sv_setiv(sv, PL_modcount+1);
3302 right = newOP(OP_UNDEF, 0);
3303 if (right->op_type == OP_READLINE) {
3304 right->op_flags |= OPf_STACKED;
3305 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
3308 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
3309 o = newBINOP(OP_SASSIGN, flags,
3310 scalar(right), mod(scalar(left), OP_SASSIGN) );
3322 Perl_newSTATEOP(pTHX_ I32 flags, char *label, OP *o)
3325 U32 seq = intro_my();
3328 NewOp(1101, cop, 1, COP);
3329 if (PERLDB_LINE && CopLINE(PL_curcop) && PL_curstash != PL_debstash) {
3330 cop->op_type = OP_DBSTATE;
3331 cop->op_ppaddr = PL_ppaddr[ OP_DBSTATE ];
3334 cop->op_type = OP_NEXTSTATE;
3335 cop->op_ppaddr = PL_ppaddr[ OP_NEXTSTATE ];
3337 cop->op_flags = flags;
3338 cop->op_private = (PL_hints & HINT_UTF8);
3340 cop->op_private |= NATIVE_HINTS;
3342 PL_compiling.op_private = cop->op_private;
3343 cop->op_next = (OP*)cop;
3346 cop->cop_label = label;
3347 PL_hints |= HINT_BLOCK_SCOPE;
3350 cop->cop_arybase = PL_curcop->cop_arybase;
3351 if (specialWARN(PL_curcop->cop_warnings))
3352 cop->cop_warnings = PL_curcop->cop_warnings ;
3354 cop->cop_warnings = newSVsv(PL_curcop->cop_warnings) ;
3357 if (PL_copline == NOLINE)
3358 CopLINE_set(cop, CopLINE(PL_curcop));
3360 CopLINE_set(cop, PL_copline);
3361 PL_copline = NOLINE;
3364 CopFILE_set(cop, CopFILE(PL_curcop)); /* XXXXX share in a pvtable? */
3366 CopFILEGV_set(cop, (GV*)SvREFCNT_inc(CopFILEGV(PL_curcop)));
3368 CopSTASH_set(cop, PL_curstash);
3370 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3371 SV **svp = av_fetch(CopFILEAV(PL_curcop), (I32)CopLINE(cop), FALSE);
3372 if (svp && *svp != &PL_sv_undef && !SvIOK(*svp)) {
3373 (void)SvIOK_on(*svp);
3374 SvIVX(*svp) = PTR2IV(cop);
3378 return prepend_elem(OP_LINESEQ, (OP*)cop, o);
3381 /* "Introduce" my variables to visible status. */
3389 if (! PL_min_intro_pending)
3390 return PL_cop_seqmax;
3392 svp = AvARRAY(PL_comppad_name);
3393 for (i = PL_min_intro_pending; i <= PL_max_intro_pending; i++) {
3394 if ((sv = svp[i]) && sv != &PL_sv_undef && !SvIVX(sv)) {
3395 SvIVX(sv) = PAD_MAX; /* Don't know scope end yet. */
3396 SvNVX(sv) = (NV)PL_cop_seqmax;
3399 PL_min_intro_pending = 0;
3400 PL_comppad_name_fill = PL_max_intro_pending; /* Needn't search higher */
3401 return PL_cop_seqmax++;
3405 Perl_newLOGOP(pTHX_ I32 type, I32 flags, OP *first, OP *other)
3407 return new_logop(type, flags, &first, &other);
3411 S_new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp)
3416 OP *first = *firstp;
3417 OP *other = *otherp;
3419 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
3420 return newBINOP(type, flags, scalar(first), scalar(other));
3422 scalarboolean(first);
3423 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
3424 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
3425 if (type == OP_AND || type == OP_OR) {
3431 first = *firstp = cUNOPo->op_first;
3433 first->op_next = o->op_next;
3434 cUNOPo->op_first = Nullop;
3438 if (first->op_type == OP_CONST) {
3439 if (ckWARN(WARN_PRECEDENCE) && (first->op_private & OPpCONST_BARE))
3440 Perl_warner(aTHX_ WARN_PRECEDENCE, "Probable precedence problem on %s",
3442 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
3453 else if (first->op_type == OP_WANTARRAY) {
3459 else if (ckWARN(WARN_UNSAFE) && (first->op_flags & OPf_KIDS)) {
3460 OP *k1 = ((UNOP*)first)->op_first;
3461 OP *k2 = k1->op_sibling;
3463 switch (first->op_type)
3466 if (k2 && k2->op_type == OP_READLINE
3467 && (k2->op_flags & OPf_STACKED)
3468 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3470 warnop = k2->op_type;
3475 if (k1->op_type == OP_READDIR
3476 || k1->op_type == OP_GLOB
3477 || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
3478 || k1->op_type == OP_EACH)
3480 warnop = ((k1->op_type == OP_NULL)
3481 ? k1->op_targ : k1->op_type);
3486 line_t oldline = CopLINE(PL_curcop);
3487 CopLINE_set(PL_curcop, PL_copline);
3488 Perl_warner(aTHX_ WARN_UNSAFE,
3489 "Value of %s%s can be \"0\"; test with defined()",
3491 ((warnop == OP_READLINE || warnop == OP_GLOB)
3492 ? " construct" : "() operator"));
3493 CopLINE_set(PL_curcop, oldline);
3500 if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
3501 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
3503 NewOp(1101, logop, 1, LOGOP);
3505 logop->op_type = type;
3506 logop->op_ppaddr = PL_ppaddr[type];
3507 logop->op_first = first;
3508 logop->op_flags = flags | OPf_KIDS;
3509 logop->op_other = LINKLIST(other);
3510 logop->op_private = 1 | (flags >> 8);
3512 /* establish postfix order */
3513 logop->op_next = LINKLIST(first);
3514 first->op_next = (OP*)logop;
3515 first->op_sibling = other;
3517 o = newUNOP(OP_NULL, 0, (OP*)logop);
3524 Perl_newCONDOP(pTHX_ I32 flags, OP *first, OP *trueop, OP *falseop)
3532 return newLOGOP(OP_AND, 0, first, trueop);
3534 return newLOGOP(OP_OR, 0, first, falseop);
3536 scalarboolean(first);
3537 if (first->op_type == OP_CONST) {
3538 if (SvTRUE(((SVOP*)first)->op_sv)) {
3549 else if (first->op_type == OP_WANTARRAY) {
3553 NewOp(1101, logop, 1, LOGOP);
3554 logop->op_type = OP_COND_EXPR;
3555 logop->op_ppaddr = PL_ppaddr[OP_COND_EXPR];
3556 logop->op_first = first;
3557 logop->op_flags = flags | OPf_KIDS;
3558 logop->op_private = 1 | (flags >> 8);
3559 logop->op_other = LINKLIST(trueop);
3560 logop->op_next = LINKLIST(falseop);
3563 /* establish postfix order */
3564 start = LINKLIST(first);
3565 first->op_next = (OP*)logop;
3567 first->op_sibling = trueop;
3568 trueop->op_sibling = falseop;
3569 o = newUNOP(OP_NULL, 0, (OP*)logop);
3571 trueop->op_next = falseop->op_next = o;
3578 Perl_newRANGE(pTHX_ I32 flags, OP *left, OP *right)
3587 NewOp(1101, range, 1, LOGOP);
3589 range->op_type = OP_RANGE;
3590 range->op_ppaddr = PL_ppaddr[OP_RANGE];
3591 range->op_first = left;
3592 range->op_flags = OPf_KIDS;
3593 leftstart = LINKLIST(left);
3594 range->op_other = LINKLIST(right);
3595 range->op_private = 1 | (flags >> 8);
3597 left->op_sibling = right;
3599 range->op_next = (OP*)range;
3600 flip = newUNOP(OP_FLIP, flags, (OP*)range);
3601 flop = newUNOP(OP_FLOP, 0, flip);
3602 o = newUNOP(OP_NULL, 0, flop);
3604 range->op_next = leftstart;
3606 left->op_next = flip;
3607 right->op_next = flop;
3609 range->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
3610 sv_upgrade(PAD_SV(range->op_targ), SVt_PVNV);
3611 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
3612 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
3614 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
3615 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
3618 if (!flip->op_private || !flop->op_private)
3619 linklist(o); /* blow off optimizer unless constant */
3625 Perl_newLOOPOP(pTHX_ I32 flags, I32 debuggable, OP *expr, OP *block)
3630 int once = block && block->op_flags & OPf_SPECIAL &&
3631 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
3634 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
3635 return block; /* do {} while 0 does once */
3636 if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
3637 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB)) {
3638 expr = newUNOP(OP_DEFINED, 0,
3639 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
3640 } else if (expr->op_flags & OPf_KIDS) {
3641 OP *k1 = ((UNOP*)expr)->op_first;
3642 OP *k2 = (k1) ? k1->op_sibling : NULL;
3643 switch (expr->op_type) {
3645 if (k2 && k2->op_type == OP_READLINE
3646 && (k2->op_flags & OPf_STACKED)
3647 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3648 expr = newUNOP(OP_DEFINED, 0, expr);
3652 if (k1->op_type == OP_READDIR
3653 || k1->op_type == OP_GLOB
3654 || (k1->op_type == OP_NULL && k1->op_targ == OP_NULL)
3655 || k1->op_type == OP_EACH)
3656 expr = newUNOP(OP_DEFINED, 0, expr);
3662 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
3663 o = new_logop(OP_AND, 0, &expr, &listop);
3666 ((LISTOP*)listop)->op_last->op_next = LINKLIST(o);
3668 if (once && o != listop)
3669 o->op_next = ((LOGOP*)cUNOPo->op_first)->op_other;
3672 o = newUNOP(OP_NULL, 0, o); /* or do {} while 1 loses outer block */
3674 o->op_flags |= flags;
3676 o->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/
3681 Perl_newWHILEOP(pTHX_ I32 flags, I32 debuggable, LOOP *loop, I32 whileline, OP *expr, OP *block, OP *cont)
3690 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
3691 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB))) {
3692 expr = newUNOP(OP_DEFINED, 0,
3693 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
3694 } else if (expr && (expr->op_flags & OPf_KIDS)) {
3695 OP *k1 = ((UNOP*)expr)->op_first;
3696 OP *k2 = (k1) ? k1->op_sibling : NULL;
3697 switch (expr->op_type) {
3699 if (k2 && k2->op_type == OP_READLINE
3700 && (k2->op_flags & OPf_STACKED)
3701 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3702 expr = newUNOP(OP_DEFINED, 0, expr);
3706 if (k1->op_type == OP_READDIR
3707 || k1->op_type == OP_GLOB
3708 || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
3709 || k1->op_type == OP_EACH)
3710 expr = newUNOP(OP_DEFINED, 0, expr);
3716 block = newOP(OP_NULL, 0);
3719 next = LINKLIST(cont);
3721 cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
3722 if ((line_t)whileline != NOLINE) {
3723 PL_copline = whileline;
3724 cont = append_elem(OP_LINESEQ, cont,
3725 newSTATEOP(0, Nullch, Nullop));
3729 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
3730 redo = LINKLIST(listop);
3733 PL_copline = whileline;
3735 o = new_logop(OP_AND, 0, &expr, &listop);
3736 if (o == expr && o->op_type == OP_CONST && !SvTRUE(cSVOPo->op_sv)) {
3737 op_free(expr); /* oops, it's a while (0) */
3739 return Nullop; /* listop already freed by new_logop */
3742 ((LISTOP*)listop)->op_last->op_next = condop =
3743 (o == listop ? redo : LINKLIST(o));
3751 NewOp(1101,loop,1,LOOP);
3752 loop->op_type = OP_ENTERLOOP;
3753 loop->op_ppaddr = PL_ppaddr[OP_ENTERLOOP];
3754 loop->op_private = 0;
3755 loop->op_next = (OP*)loop;
3758 o = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, o);
3760 loop->op_redoop = redo;
3761 loop->op_lastop = o;
3764 loop->op_nextop = next;
3766 loop->op_nextop = o;
3768 o->op_flags |= flags;
3769 o->op_private |= (flags >> 8);
3774 Perl_newFOROP(pTHX_ I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
3783 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
3784 sv->op_type = OP_RV2GV;
3785 sv->op_ppaddr = PL_ppaddr[OP_RV2GV];
3787 else if (sv->op_type == OP_PADSV) { /* private variable */
3788 padoff = sv->op_targ;
3793 else if (sv->op_type == OP_THREADSV) { /* per-thread variable */
3794 padoff = sv->op_targ;
3796 iterflags |= OPf_SPECIAL;
3801 Perl_croak(aTHX_ "Can't use %s for loop variable", PL_op_desc[sv->op_type]);
3805 padoff = find_threadsv("_");
3806 iterflags |= OPf_SPECIAL;
3808 sv = newGVOP(OP_GV, 0, PL_defgv);
3811 if (expr->op_type == OP_RV2AV || expr->op_type == OP_PADAV) {
3812 expr = mod(force_list(scalar(ref(expr, OP_ITER))), OP_GREPSTART);
3813 iterflags |= OPf_STACKED;
3815 else if (expr->op_type == OP_NULL &&
3816 (expr->op_flags & OPf_KIDS) &&
3817 ((BINOP*)expr)->op_first->op_type == OP_FLOP)
3819 /* Basically turn for($x..$y) into the same as for($x,$y), but we
3820 * set the STACKED flag to indicate that these values are to be
3821 * treated as min/max values by 'pp_iterinit'.
3823 UNOP* flip = (UNOP*)((UNOP*)((BINOP*)expr)->op_first)->op_first;
3824 LOGOP* range = (LOGOP*) flip->op_first;
3825 OP* left = range->op_first;
3826 OP* right = left->op_sibling;
3829 range->op_flags &= ~OPf_KIDS;
3830 range->op_first = Nullop;
3832 listop = (LISTOP*)newLISTOP(OP_LIST, 0, left, right);
3833 listop->op_first->op_next = range->op_next;
3834 left->op_next = range->op_other;
3835 right->op_next = (OP*)listop;
3836 listop->op_next = listop->op_first;
3839 expr = (OP*)(listop);
3841 iterflags |= OPf_STACKED;
3844 expr = mod(force_list(expr), OP_GREPSTART);
3848 loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
3849 append_elem(OP_LIST, expr, scalar(sv))));
3850 assert(!loop->op_next);
3851 #ifdef PL_OP_SLAB_ALLOC
3852 NewOp(1234,tmp,1,LOOP);
3853 Copy(loop,tmp,1,LOOP);
3856 Renew(loop, 1, LOOP);
3858 loop->op_targ = padoff;
3859 wop = newWHILEOP(flags, 1, loop, forline, newOP(OP_ITER, 0), block, cont);
3860 PL_copline = forline;
3861 return newSTATEOP(0, label, wop);
3865 Perl_newLOOPEX(pTHX_ I32 type, OP *label)
3871 if (type != OP_GOTO || label->op_type == OP_CONST) {
3872 /* "last()" means "last" */
3873 if (label->op_type == OP_STUB && (label->op_flags & OPf_PARENS))
3874 o = newOP(type, OPf_SPECIAL);
3876 o = newPVOP(type, 0, savepv(label->op_type == OP_CONST
3877 ? SvPVx(((SVOP*)label)->op_sv, n_a)
3883 if (label->op_type == OP_ENTERSUB)
3884 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
3885 o = newUNOP(type, OPf_STACKED, label);
3887 PL_hints |= HINT_BLOCK_SCOPE;
3892 Perl_cv_undef(pTHX_ CV *cv)
3897 MUTEX_DESTROY(CvMUTEXP(cv));
3898 Safefree(CvMUTEXP(cv));
3901 #endif /* USE_THREADS */
3903 if (!CvXSUB(cv) && CvROOT(cv)) {
3905 if (CvDEPTH(cv) || (CvOWNER(cv) && CvOWNER(cv) != thr))
3906 Perl_croak(aTHX_ "Can't undef active subroutine");
3909 Perl_croak(aTHX_ "Can't undef active subroutine");
3910 #endif /* USE_THREADS */
3913 SAVEVPTR(PL_curpad);
3917 op_free(CvROOT(cv));
3918 CvROOT(cv) = Nullop;
3921 SvPOK_off((SV*)cv); /* forget prototype */
3923 SvREFCNT_dec(CvGV(cv));
3925 SvREFCNT_dec(CvOUTSIDE(cv));
3926 CvOUTSIDE(cv) = Nullcv;
3927 if (CvPADLIST(cv)) {
3928 /* may be during global destruction */
3929 if (SvREFCNT(CvPADLIST(cv))) {
3930 I32 i = AvFILLp(CvPADLIST(cv));
3932 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
3933 SV* sv = svp ? *svp : Nullsv;
3936 if (sv == (SV*)PL_comppad_name)
3937 PL_comppad_name = Nullav;
3938 else if (sv == (SV*)PL_comppad) {
3939 PL_comppad = Nullav;
3940 PL_curpad = Null(SV**);
3944 SvREFCNT_dec((SV*)CvPADLIST(cv));
3946 CvPADLIST(cv) = Nullav;
3951 S_cv_dump(pTHX_ CV *cv)
3954 CV *outside = CvOUTSIDE(cv);
3955 AV* padlist = CvPADLIST(cv);
3962 PerlIO_printf(Perl_debug_log,
3963 "\tCV=0x%"UVxf" (%s), OUTSIDE=0x%"UVxf" (%s)\n",
3965 (CvANON(cv) ? "ANON"
3966 : (cv == PL_main_cv) ? "MAIN"
3967 : CvUNIQUE(cv) ? "UNIQUE"
3968 : CvGV(cv) ? GvNAME(CvGV(cv)) : "UNDEFINED"),
3971 : CvANON(outside) ? "ANON"
3972 : (outside == PL_main_cv) ? "MAIN"
3973 : CvUNIQUE(outside) ? "UNIQUE"
3974 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
3979 pad_name = (AV*)*av_fetch(padlist, 0, FALSE);
3980 pad = (AV*)*av_fetch(padlist, 1, FALSE);
3981 pname = AvARRAY(pad_name);
3982 ppad = AvARRAY(pad);
3984 for (ix = 1; ix <= AvFILLp(pad_name); ix++) {
3985 if (SvPOK(pname[ix]))
3986 PerlIO_printf(Perl_debug_log,
3987 "\t%4d. 0x%"UVxf" (%s\"%s\" %"IVdf"-%"IVdf")\n",
3988 ix, PTR2UV(ppad[ix]),
3989 SvFAKE(pname[ix]) ? "FAKE " : "",
3991 (IV)I_32(SvNVX(pname[ix])),
3994 #endif /* DEBUGGING */
3998 S_cv_clone2(pTHX_ CV *proto, CV *outside)
4003 AV* protopadlist = CvPADLIST(proto);
4004 AV* protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
4005 AV* protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
4006 SV** pname = AvARRAY(protopad_name);
4007 SV** ppad = AvARRAY(protopad);
4008 I32 fname = AvFILLp(protopad_name);
4009 I32 fpad = AvFILLp(protopad);
4013 assert(!CvUNIQUE(proto));
4016 SAVEVPTR(PL_curpad);
4017 SAVESPTR(PL_comppad);
4018 SAVESPTR(PL_comppad_name);
4019 SAVESPTR(PL_compcv);
4021 cv = PL_compcv = (CV*)NEWSV(1104,0);
4022 sv_upgrade((SV *)cv, SvTYPE(proto));
4028 New(666, CvMUTEXP(cv), 1, perl_mutex);
4029 MUTEX_INIT(CvMUTEXP(cv));
4031 #endif /* USE_THREADS */
4032 CvFILE(cv) = CvFILE(proto);
4033 CvGV(cv) = (GV*)SvREFCNT_inc(CvGV(proto));
4034 CvSTASH(cv) = CvSTASH(proto);
4035 CvROOT(cv) = CvROOT(proto);
4036 CvSTART(cv) = CvSTART(proto);
4038 CvOUTSIDE(cv) = (CV*)SvREFCNT_inc(outside);
4041 sv_setpvn((SV*)cv, SvPVX(proto), SvCUR(proto));
4043 PL_comppad_name = newAV();
4044 for (ix = fname; ix >= 0; ix--)
4045 av_store(PL_comppad_name, ix, SvREFCNT_inc(pname[ix]));
4047 PL_comppad = newAV();
4049 comppadlist = newAV();
4050 AvREAL_off(comppadlist);
4051 av_store(comppadlist, 0, (SV*)PL_comppad_name);
4052 av_store(comppadlist, 1, (SV*)PL_comppad);
4053 CvPADLIST(cv) = comppadlist;
4054 av_fill(PL_comppad, AvFILLp(protopad));
4055 PL_curpad = AvARRAY(PL_comppad);
4057 av = newAV(); /* will be @_ */
4059 av_store(PL_comppad, 0, (SV*)av);
4060 AvFLAGS(av) = AVf_REIFY;
4062 for (ix = fpad; ix > 0; ix--) {
4063 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
4064 if (namesv && namesv != &PL_sv_undef) {
4065 char *name = SvPVX(namesv); /* XXX */
4066 if (SvFLAGS(namesv) & SVf_FAKE) { /* lexical from outside? */
4067 I32 off = pad_findlex(name, ix, SvIVX(namesv),
4068 CvOUTSIDE(cv), cxstack_ix, 0, 0);
4070 PL_curpad[ix] = SvREFCNT_inc(ppad[ix]);
4072 Perl_croak(aTHX_ "panic: cv_clone: %s", name);
4074 else { /* our own lexical */
4077 /* anon code -- we'll come back for it */
4078 sv = SvREFCNT_inc(ppad[ix]);
4080 else if (*name == '@')
4082 else if (*name == '%')
4091 else if (IS_PADGV(ppad[ix]) || IS_PADCONST(ppad[ix])) {
4092 PL_curpad[ix] = SvREFCNT_inc(ppad[ix]);
4095 SV* sv = NEWSV(0,0);
4101 /* Now that vars are all in place, clone nested closures. */
4103 for (ix = fpad; ix > 0; ix--) {
4104 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
4106 && namesv != &PL_sv_undef
4107 && !(SvFLAGS(namesv) & SVf_FAKE)
4108 && *SvPVX(namesv) == '&'
4109 && CvCLONE(ppad[ix]))
4111 CV *kid = cv_clone2((CV*)ppad[ix], cv);
4112 SvREFCNT_dec(ppad[ix]);
4115 PL_curpad[ix] = (SV*)kid;
4119 #ifdef DEBUG_CLOSURES
4120 PerlIO_printf(Perl_debug_log, "Cloned inside:\n");
4122 PerlIO_printf(Perl_debug_log, " from:\n");
4124 PerlIO_printf(Perl_debug_log, " to:\n");
4133 Perl_cv_clone(pTHX_ CV *proto)
4136 LOCK_CRED_MUTEX; /* XXX create separate mutex */
4137 cv = cv_clone2(proto, CvOUTSIDE(proto));
4138 UNLOCK_CRED_MUTEX; /* XXX create separate mutex */
4143 Perl_cv_ckproto(pTHX_ CV *cv, GV *gv, char *p)
4147 if (((!p != !SvPOK(cv)) || (p && strNE(p, SvPVX(cv)))) && ckWARN_d(WARN_UNSAFE)) {
4148 SV* msg = sv_newmortal();
4152 gv_efullname3(name = sv_newmortal(), gv, Nullch);
4153 sv_setpv(msg, "Prototype mismatch:");
4155 Perl_sv_catpvf(aTHX_ msg, " sub %_", name);
4157 Perl_sv_catpvf(aTHX_ msg, " (%s)", SvPVX(cv));
4158 sv_catpv(msg, " vs ");
4160 Perl_sv_catpvf(aTHX_ msg, "(%s)", p);
4162 sv_catpv(msg, "none");
4163 Perl_warner(aTHX_ WARN_UNSAFE, "%_", msg);
4168 Perl_cv_const_sv(pTHX_ CV *cv)
4170 if (!cv || !SvPOK(cv) || SvCUR(cv))
4172 return op_const_sv(CvSTART(cv), cv);
4176 Perl_op_const_sv(pTHX_ OP *o, CV *cv)
4183 if(o->op_type == OP_LINESEQ && cLISTOPo->op_first)
4184 o = cLISTOPo->op_first->op_sibling;
4186 for (; o; o = o->op_next) {
4187 OPCODE type = o->op_type;
4189 if (sv && o->op_next == o)
4191 if (type == OP_NEXTSTATE || type == OP_NULL || type == OP_PUSHMARK)
4193 if (type == OP_LEAVESUB || type == OP_RETURN)
4197 if (type == OP_CONST && cSVOPo->op_sv)
4199 else if ((type == OP_PADSV || type == OP_CONST) && cv) {
4200 AV* padav = (AV*)(AvARRAY(CvPADLIST(cv))[1]);
4201 sv = padav ? AvARRAY(padav)[o->op_targ] : Nullsv;
4202 if (!sv || (!SvREADONLY(sv) && SvREFCNT(sv) > 1))
4214 Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
4224 Perl_croak(aTHX_ "\"my sub\" not yet implemented");
4228 Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block)
4230 return Perl_newATTRSUB(aTHX_ floor, o, proto, Nullop, block);
4234 Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
4238 char *name = o ? SvPVx(cSVOPo->op_sv, n_a) : Nullch;
4239 GV *gv = gv_fetchpv(name ? name : "__ANON__",
4240 GV_ADDMULTI | ((block || attrs) ? 0 : GV_NOINIT),
4242 char *ps = proto ? SvPVx(((SVOP*)proto)->op_sv, n_a) : Nullch;
4253 if (SvTYPE(gv) != SVt_PVGV) { /* Maybe prototype now, and had at
4254 maximum a prototype before. */
4255 if (SvTYPE(gv) > SVt_NULL) {
4256 if (!SvPOK((SV*)gv) && !(SvIOK((SV*)gv) && SvIVX((SV*)gv) == -1)
4257 && ckWARN_d(WARN_UNSAFE))
4259 Perl_warner(aTHX_ WARN_UNSAFE, "Runaway prototype");
4261 cv_ckproto((CV*)gv, NULL, ps);
4264 sv_setpv((SV*)gv, ps);
4266 sv_setiv((SV*)gv, -1);
4267 SvREFCNT_dec(PL_compcv);
4268 cv = PL_compcv = NULL;
4269 PL_sub_generation++;
4273 if (!name || GvCVGEN(gv))
4275 else if (cv = GvCV(gv)) {
4276 cv_ckproto(cv, gv, ps);
4277 /* already defined (or promised)? */
4278 if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
4280 bool const_changed = TRUE;
4281 if (!block && !attrs) {
4282 /* just a "sub foo;" when &foo is already defined */
4283 SAVEFREESV(PL_compcv);
4286 /* ahem, death to those who redefine active sort subs */
4287 if (PL_curstackinfo->si_type == PERLSI_SORT && PL_sortcop == CvSTART(cv))
4288 Perl_croak(aTHX_ "Can't redefine active sort subroutine %s", name);
4291 if(const_sv = cv_const_sv(cv))
4292 const_changed = sv_cmp(const_sv, op_const_sv(block, Nullcv));
4293 if ((const_sv && const_changed) || ckWARN(WARN_REDEFINE)
4294 && !(CvGV(cv) && GvSTASH(CvGV(cv))
4295 && HvNAME(GvSTASH(CvGV(cv)))
4296 && strEQ(HvNAME(GvSTASH(CvGV(cv))),
4298 line_t oldline = CopLINE(PL_curcop);
4299 CopLINE_set(PL_curcop, PL_copline);
4300 Perl_warner(aTHX_ WARN_REDEFINE,
4301 const_sv ? "Constant subroutine %s redefined"
4302 : "Subroutine %s redefined", name);
4303 CopLINE_set(PL_curcop, oldline);
4314 /* Need to do a C<use attributes $stash_of_cv,\&cv,@attrs>
4315 * before we clobber PL_compcv.
4319 if (CvGV(cv) && GvSTASH(CvGV(cv)) && HvNAME(GvSTASH(CvGV(cv))))
4320 stash = GvSTASH(CvGV(cv));
4321 else if (CvSTASH(cv) && HvNAME(CvSTASH(cv)))
4322 stash = CvSTASH(cv);
4324 stash = PL_curstash;
4327 /* possibly about to re-define existing subr -- ignore old cv */
4328 rcv = (SV*)PL_compcv;
4329 if (name && GvSTASH(gv) && HvNAME(GvSTASH(gv)))
4330 stash = GvSTASH(gv);
4332 stash = PL_curstash;
4334 apply_attrs(stash, rcv, attrs);
4336 if (cv) { /* must reuse cv if autoloaded */
4338 /* got here with just attrs -- work done, so bug out */
4339 SAVEFREESV(PL_compcv);
4343 CvFLAGS(cv) = CvFLAGS(PL_compcv);
4344 CvOUTSIDE(cv) = CvOUTSIDE(PL_compcv);
4345 CvOUTSIDE(PL_compcv) = 0;
4346 CvPADLIST(cv) = CvPADLIST(PL_compcv);
4347 CvPADLIST(PL_compcv) = 0;
4348 if (SvREFCNT(PL_compcv) > 1) /* XXX Make closures transit through stub. */
4349 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc((SV*)cv);
4350 SvREFCNT_dec(PL_compcv);
4357 PL_sub_generation++;
4360 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4361 CvFILE(cv) = CopFILE(PL_curcop);
4362 CvSTASH(cv) = PL_curstash;
4365 if (!CvMUTEXP(cv)) {
4366 New(666, CvMUTEXP(cv), 1, perl_mutex);
4367 MUTEX_INIT(CvMUTEXP(cv));
4369 #endif /* USE_THREADS */
4372 sv_setpv((SV*)cv, ps);
4374 if (PL_error_count) {
4378 char *s = strrchr(name, ':');
4380 if (strEQ(s, "BEGIN")) {
4382 "BEGIN not safe after errors--compilation aborted";
4383 if (PL_in_eval & EVAL_KEEPERR)
4384 Perl_croak(aTHX_ not_safe);
4386 /* force display of errors found but not reported */
4387 sv_catpv(ERRSV, not_safe);
4388 Perl_croak(aTHX_ "%s", SvPVx(ERRSV, n_a));
4395 PL_copline = NOLINE;
4400 if (AvFILLp(PL_comppad_name) < AvFILLp(PL_comppad))
4401 av_store(PL_comppad_name, AvFILLp(PL_comppad), Nullsv);
4404 CvROOT(cv) = newUNOP(OP_LEAVESUBLV, 0, scalarseq(block));
4407 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
4409 CvROOT(cv)->op_private |= OPpREFCOUNTED;
4410 OpREFCNT_set(CvROOT(cv), 1);
4411 CvSTART(cv) = LINKLIST(CvROOT(cv));
4412 CvROOT(cv)->op_next = 0;
4415 /* now that optimizer has done its work, adjust pad values */
4417 SV **namep = AvARRAY(PL_comppad_name);
4418 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4421 if (SvIMMORTAL(PL_curpad[ix]) || IS_PADGV(PL_curpad[ix]) || IS_PADCONST(PL_curpad[ix]))
4424 * The only things that a clonable function needs in its
4425 * pad are references to outer lexicals and anonymous subs.
4426 * The rest are created anew during cloning.
4428 if (!((namesv = namep[ix]) != Nullsv &&
4429 namesv != &PL_sv_undef &&
4431 *SvPVX(namesv) == '&')))
4433 SvREFCNT_dec(PL_curpad[ix]);
4434 PL_curpad[ix] = Nullsv;
4439 AV *av = newAV(); /* Will be @_ */
4441 av_store(PL_comppad, 0, (SV*)av);
4442 AvFLAGS(av) = AVf_REIFY;
4444 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4445 if (SvIMMORTAL(PL_curpad[ix]) || IS_PADGV(PL_curpad[ix]) || IS_PADCONST(PL_curpad[ix]))
4447 if (!SvPADMY(PL_curpad[ix]))
4448 SvPADTMP_on(PL_curpad[ix]);
4455 if (PERLDB_SUBLINE && PL_curstash != PL_debstash) {
4456 SV *sv = NEWSV(0,0);
4457 SV *tmpstr = sv_newmortal();
4458 GV *db_postponed = gv_fetchpv("DB::postponed", GV_ADDMULTI, SVt_PVHV);
4462 Perl_sv_setpvf(aTHX_ sv, "%s:%ld-%ld",
4464 (long)PL_subline, (long)CopLINE(PL_curcop));
4465 gv_efullname3(tmpstr, gv, Nullch);
4466 hv_store(GvHV(PL_DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
4467 hv = GvHVn(db_postponed);
4468 if (HvFILL(hv) > 0 && hv_exists(hv, SvPVX(tmpstr), SvCUR(tmpstr))
4469 && (cv = GvCV(db_postponed))) {
4474 call_sv((SV*)cv, G_DISCARD);
4478 if ((s = strrchr(name,':')))
4483 if (*s != 'B' && *s != 'E' && *s != 'S' && *s != 'I')
4486 if (strEQ(s, "BEGIN")) {
4487 I32 oldscope = PL_scopestack_ix;
4489 SAVECOPFILE(&PL_compiling);
4490 SAVECOPLINE(&PL_compiling);
4492 sv_setsv(PL_rs, PL_nrs);
4495 PL_beginav = newAV();
4496 DEBUG_x( dump_sub(gv) );
4497 av_push(PL_beginav, SvREFCNT_inc(cv));
4499 call_list(oldscope, PL_beginav);
4501 PL_curcop = &PL_compiling;
4502 PL_compiling.op_private = PL_hints;
4505 else if (strEQ(s, "END") && !PL_error_count) {
4508 DEBUG_x( dump_sub(gv) );
4509 av_unshift(PL_endav, 1);
4510 av_store(PL_endav, 0, SvREFCNT_inc(cv));
4513 else if (strEQ(s, "STOP") && !PL_error_count) {
4515 PL_stopav = newAV();
4516 DEBUG_x( dump_sub(gv) );
4517 av_unshift(PL_stopav, 1);
4518 av_store(PL_stopav, 0, SvREFCNT_inc(cv));
4521 else if (strEQ(s, "INIT") && !PL_error_count) {
4523 PL_initav = newAV();
4524 DEBUG_x( dump_sub(gv) );
4525 av_push(PL_initav, SvREFCNT_inc(cv));
4531 PL_copline = NOLINE;
4536 /* XXX unsafe for threads if eval_owner isn't held */
4538 Perl_newCONSTSUB(pTHX_ HV *stash, char *name, SV *sv)
4543 SAVECOPLINE(PL_curcop);
4546 CopLINE_set(PL_curcop, PL_copline);
4547 PL_hints &= ~HINT_BLOCK_SCOPE;
4550 SAVESPTR(PL_curstash);
4551 SAVECOPSTASH(PL_curcop);
4552 PL_curstash = stash;
4554 CopSTASHPV(PL_curcop) = stash ? HvNAME(stash) : Nullch;
4556 CopSTASH(PL_curcop) = stash;
4561 start_subparse(FALSE, 0),
4562 newSVOP(OP_CONST, 0, newSVpv(name,0)),
4563 newSVOP(OP_CONST, 0, &PL_sv_no), /* SvPV(&PL_sv_no) == "" -- GMB */
4565 newSTATEOP(0, Nullch, newSVOP(OP_CONST, 0, sv))
4572 Perl_newXS(pTHX_ char *name, XSUBADDR_t subaddr, char *filename)
4575 GV *gv = gv_fetchpv(name ? name : "__ANON__", GV_ADDMULTI, SVt_PVCV);
4578 if (cv = (name ? GvCV(gv) : Nullcv)) {
4580 /* just a cached method */
4584 else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
4585 /* already defined (or promised) */
4586 if (ckWARN(WARN_REDEFINE) && !(CvGV(cv) && GvSTASH(CvGV(cv))
4587 && HvNAME(GvSTASH(CvGV(cv)))
4588 && strEQ(HvNAME(GvSTASH(CvGV(cv))), "autouse"))) {
4589 line_t oldline = CopLINE(PL_curcop);
4590 if (PL_copline != NOLINE)
4591 CopLINE_set(PL_curcop, PL_copline);
4592 Perl_warner(aTHX_ WARN_REDEFINE, "Subroutine %s redefined",name);
4593 CopLINE_set(PL_curcop, oldline);
4600 if (cv) /* must reuse cv if autoloaded */
4603 cv = (CV*)NEWSV(1105,0);
4604 sv_upgrade((SV *)cv, SVt_PVCV);
4608 PL_sub_generation++;
4611 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4613 New(666, CvMUTEXP(cv), 1, perl_mutex);
4614 MUTEX_INIT(CvMUTEXP(cv));
4616 #endif /* USE_THREADS */
4617 (void)gv_fetchfile(filename);
4618 CvFILE(cv) = filename; /* NOTE: not copied, as it is expected to be
4619 an external constant string */
4620 CvXSUB(cv) = subaddr;
4623 char *s = strrchr(name,':');
4629 if (*s != 'B' && *s != 'E' && *s != 'S' && *s != 'I')
4632 if (strEQ(s, "BEGIN")) {
4634 PL_beginav = newAV();
4635 av_push(PL_beginav, SvREFCNT_inc(cv));
4638 else if (strEQ(s, "END")) {
4641 av_unshift(PL_endav, 1);
4642 av_store(PL_endav, 0, SvREFCNT_inc(cv));
4645 else if (strEQ(s, "STOP")) {
4647 PL_stopav = newAV();
4648 av_unshift(PL_stopav, 1);
4649 av_store(PL_stopav, 0, SvREFCNT_inc(cv));
4652 else if (strEQ(s, "INIT")) {
4654 PL_initav = newAV();
4655 av_push(PL_initav, SvREFCNT_inc(cv));
4667 Perl_newFORM(pTHX_ I32 floor, OP *o, OP *block)
4677 name = SvPVx(cSVOPo->op_sv, n_a);
4680 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
4682 if (cv = GvFORM(gv)) {
4683 if (ckWARN(WARN_REDEFINE)) {
4684 line_t oldline = CopLINE(PL_curcop);
4686 CopLINE_set(PL_curcop, PL_copline);
4687 Perl_warner(aTHX_ WARN_REDEFINE, "Format %s redefined",name);
4688 CopLINE_set(PL_curcop, oldline);
4694 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4695 CvFILE(cv) = CopFILE(PL_curcop);
4697 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4698 if (!SvPADMY(PL_curpad[ix]) && !SvIMMORTAL(PL_curpad[ix]))
4699 SvPADTMP_on(PL_curpad[ix]);
4702 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
4703 CvROOT(cv)->op_private |= OPpREFCOUNTED;
4704 OpREFCNT_set(CvROOT(cv), 1);
4705 CvSTART(cv) = LINKLIST(CvROOT(cv));
4706 CvROOT(cv)->op_next = 0;
4709 PL_copline = NOLINE;
4714 Perl_newANONLIST(pTHX_ OP *o)
4716 return newUNOP(OP_REFGEN, 0,
4717 mod(list(convert(OP_ANONLIST, 0, o)), OP_REFGEN));
4721 Perl_newANONHASH(pTHX_ OP *o)
4723 return newUNOP(OP_REFGEN, 0,
4724 mod(list(convert(OP_ANONHASH, 0, o)), OP_REFGEN));
4728 Perl_newANONSUB(pTHX_ I32 floor, OP *proto, OP *block)
4730 return newANONATTRSUB(floor, proto, Nullop, block);
4734 Perl_newANONATTRSUB(pTHX_ I32 floor, OP *proto, OP *attrs, OP *block)
4736 return newUNOP(OP_REFGEN, 0,
4737 newSVOP(OP_ANONCODE, 0,
4738 (SV*)newATTRSUB(floor, 0, proto, attrs, block)));
4742 Perl_oopsAV(pTHX_ OP *o)
4744 switch (o->op_type) {
4746 o->op_type = OP_PADAV;
4747 o->op_ppaddr = PL_ppaddr[OP_PADAV];
4748 return ref(o, OP_RV2AV);
4751 o->op_type = OP_RV2AV;
4752 o->op_ppaddr = PL_ppaddr[OP_RV2AV];
4757 if (ckWARN_d(WARN_INTERNAL))
4758 Perl_warner(aTHX_ WARN_INTERNAL, "oops: oopsAV");
4765 Perl_oopsHV(pTHX_ OP *o)
4769 switch (o->op_type) {
4772 o->op_type = OP_PADHV;
4773 o->op_ppaddr = PL_ppaddr[OP_PADHV];
4774 return ref(o, OP_RV2HV);
4778 o->op_type = OP_RV2HV;
4779 o->op_ppaddr = PL_ppaddr[OP_RV2HV];
4784 if (ckWARN_d(WARN_INTERNAL))
4785 Perl_warner(aTHX_ WARN_INTERNAL, "oops: oopsHV");
4792 Perl_newAVREF(pTHX_ OP *o)
4794 if (o->op_type == OP_PADANY) {
4795 o->op_type = OP_PADAV;
4796 o->op_ppaddr = PL_ppaddr[OP_PADAV];
4799 return newUNOP(OP_RV2AV, 0, scalar(o));
4803 Perl_newGVREF(pTHX_ I32 type, OP *o)
4805 if (type == OP_MAPSTART || type == OP_GREPSTART || type == OP_SORT)
4806 return newUNOP(OP_NULL, 0, o);
4807 return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
4811 Perl_newHVREF(pTHX_ OP *o)
4813 if (o->op_type == OP_PADANY) {
4814 o->op_type = OP_PADHV;
4815 o->op_ppaddr = PL_ppaddr[OP_PADHV];
4818 return newUNOP(OP_RV2HV, 0, scalar(o));
4822 Perl_oopsCV(pTHX_ OP *o)
4824 Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
4830 Perl_newCVREF(pTHX_ I32 flags, OP *o)
4832 return newUNOP(OP_RV2CV, flags, scalar(o));
4836 Perl_newSVREF(pTHX_ OP *o)
4838 if (o->op_type == OP_PADANY) {
4839 o->op_type = OP_PADSV;
4840 o->op_ppaddr = PL_ppaddr[OP_PADSV];
4843 else if (o->op_type == OP_THREADSV && !(o->op_flags & OPpDONE_SVREF)) {
4844 o->op_flags |= OPpDONE_SVREF;
4847 return newUNOP(OP_RV2SV, 0, scalar(o));
4850 /* Check routines. */
4853 Perl_ck_anoncode(pTHX_ OP *o)
4858 name = NEWSV(1106,0);
4859 sv_upgrade(name, SVt_PVNV);
4860 sv_setpvn(name, "&", 1);
4863 ix = pad_alloc(o->op_type, SVs_PADMY);
4864 av_store(PL_comppad_name, ix, name);
4865 av_store(PL_comppad, ix, cSVOPo->op_sv);
4866 SvPADMY_on(cSVOPo->op_sv);
4867 cSVOPo->op_sv = Nullsv;
4868 cSVOPo->op_targ = ix;
4873 Perl_ck_bitop(pTHX_ OP *o)
4875 o->op_private = PL_hints;
4880 Perl_ck_concat(pTHX_ OP *o)
4882 if (cUNOPo->op_first->op_type == OP_CONCAT)
4883 o->op_flags |= OPf_STACKED;
4888 Perl_ck_spair(pTHX_ OP *o)
4890 if (o->op_flags & OPf_KIDS) {
4893 OPCODE type = o->op_type;
4894 o = modkids(ck_fun(o), type);
4895 kid = cUNOPo->op_first;
4896 newop = kUNOP->op_first->op_sibling;
4898 (newop->op_sibling ||
4899 !(PL_opargs[newop->op_type] & OA_RETSCALAR) ||
4900 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
4901 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
4905 op_free(kUNOP->op_first);
4906 kUNOP->op_first = newop;
4908 o->op_ppaddr = PL_ppaddr[++o->op_type];
4913 Perl_ck_delete(pTHX_ OP *o)
4917 if (o->op_flags & OPf_KIDS) {
4918 OP *kid = cUNOPo->op_first;
4919 if (kid->op_type == OP_HSLICE)
4920 o->op_private |= OPpSLICE;
4921 else if (kid->op_type != OP_HELEM)
4922 Perl_croak(aTHX_ "%s argument is not a HASH element or slice",
4923 PL_op_desc[o->op_type]);
4930 Perl_ck_eof(pTHX_ OP *o)
4932 I32 type = o->op_type;
4934 if (o->op_flags & OPf_KIDS) {
4935 if (cLISTOPo->op_first->op_type == OP_STUB) {
4937 o = newUNOP(type, OPf_SPECIAL,
4938 newGVOP(OP_GV, 0, gv_fetchpv("main::ARGV", TRUE, SVt_PVAV)));
4946 Perl_ck_eval(pTHX_ OP *o)
4948 PL_hints |= HINT_BLOCK_SCOPE;
4949 if (o->op_flags & OPf_KIDS) {
4950 SVOP *kid = (SVOP*)cUNOPo->op_first;
4953 o->op_flags &= ~OPf_KIDS;
4956 else if (kid->op_type == OP_LINESEQ) {
4959 kid->op_next = o->op_next;
4960 cUNOPo->op_first = 0;
4963 NewOp(1101, enter, 1, LOGOP);
4964 enter->op_type = OP_ENTERTRY;
4965 enter->op_ppaddr = PL_ppaddr[OP_ENTERTRY];
4966 enter->op_private = 0;
4968 /* establish postfix order */
4969 enter->op_next = (OP*)enter;
4971 o = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
4972 o->op_type = OP_LEAVETRY;
4973 o->op_ppaddr = PL_ppaddr[OP_LEAVETRY];
4974 enter->op_other = o;
4982 o = newUNOP(OP_ENTEREVAL, 0, newDEFSVOP());
4984 o->op_targ = (PADOFFSET)PL_hints;
4989 Perl_ck_exec(pTHX_ OP *o)
4992 if (o->op_flags & OPf_STACKED) {
4994 kid = cUNOPo->op_first->op_sibling;
4995 if (kid->op_type == OP_RV2GV)
5004 Perl_ck_exists(pTHX_ OP *o)
5007 if (o->op_flags & OPf_KIDS) {
5008 OP *kid = cUNOPo->op_first;
5009 if (kid->op_type != OP_HELEM)
5010 Perl_croak(aTHX_ "%s argument is not a HASH element", PL_op_desc[o->op_type]);
5018 Perl_ck_gvconst(pTHX_ register OP *o)
5020 o = fold_constants(o);
5021 if (o->op_type == OP_CONST)
5028 Perl_ck_rvconst(pTHX_ register OP *o)
5031 SVOP *kid = (SVOP*)cUNOPo->op_first;
5033 o->op_private |= (PL_hints & HINT_STRICT_REFS);
5034 if (kid->op_type == OP_CONST) {
5038 SV *kidsv = kid->op_sv;
5041 /* Is it a constant from cv_const_sv()? */
5042 if (SvROK(kidsv) && SvREADONLY(kidsv)) {
5043 SV *rsv = SvRV(kidsv);
5044 int svtype = SvTYPE(rsv);
5045 char *badtype = Nullch;
5047 switch (o->op_type) {
5049 if (svtype > SVt_PVMG)
5050 badtype = "a SCALAR";
5053 if (svtype != SVt_PVAV)
5054 badtype = "an ARRAY";
5057 if (svtype != SVt_PVHV) {
5058 if (svtype == SVt_PVAV) { /* pseudohash? */
5059 SV **ksv = av_fetch((AV*)rsv, 0, FALSE);
5060 if (ksv && SvROK(*ksv)
5061 && SvTYPE(SvRV(*ksv)) == SVt_PVHV)
5070 if (svtype != SVt_PVCV)
5075 Perl_croak(aTHX_ "Constant is not %s reference", badtype);
5078 name = SvPV(kidsv, n_a);
5079 if ((PL_hints & HINT_STRICT_REFS) && (kid->op_private & OPpCONST_BARE)) {
5080 char *badthing = Nullch;
5081 switch (o->op_type) {
5083 badthing = "a SCALAR";
5086 badthing = "an ARRAY";
5089 badthing = "a HASH";
5094 "Can't use bareword (\"%s\") as %s ref while \"strict refs\" in use",
5098 * This is a little tricky. We only want to add the symbol if we
5099 * didn't add it in the lexer. Otherwise we get duplicate strict
5100 * warnings. But if we didn't add it in the lexer, we must at
5101 * least pretend like we wanted to add it even if it existed before,
5102 * or we get possible typo warnings. OPpCONST_ENTERED says
5103 * whether the lexer already added THIS instance of this symbol.
5105 iscv = (o->op_type == OP_RV2CV) * 2;
5107 gv = gv_fetchpv(name,
5108 iscv | !(kid->op_private & OPpCONST_ENTERED),
5111 : o->op_type == OP_RV2SV
5113 : o->op_type == OP_RV2AV
5115 : o->op_type == OP_RV2HV
5118 } while (!gv && !(kid->op_private & OPpCONST_ENTERED) && !iscv++);
5120 kid->op_type = OP_GV;
5121 SvREFCNT_dec(kid->op_sv);
5123 /* XXX hack: dependence on sizeof(PADOP) <= sizeof(SVOP) */
5124 kPADOP->op_padix = pad_alloc(OP_GV, SVs_PADTMP);
5126 PL_curpad[kPADOP->op_padix] = SvREFCNT_inc(gv);
5128 kid->op_sv = SvREFCNT_inc(gv);
5130 kid->op_ppaddr = PL_ppaddr[OP_GV];
5137 Perl_ck_ftst(pTHX_ OP *o)
5140 I32 type = o->op_type;
5142 if (o->op_flags & OPf_REF) {
5145 else if (o->op_flags & OPf_KIDS && cUNOPo->op_first->op_type != OP_STUB) {
5146 SVOP *kid = (SVOP*)cUNOPo->op_first;
5148 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
5150 OP *newop = newGVOP(type, OPf_REF,
5151 gv_fetchpv(SvPVx(kid->op_sv, n_a), TRUE, SVt_PVIO));
5158 if (type == OP_FTTTY)
5159 o = newGVOP(type, OPf_REF, gv_fetchpv("main::STDIN", TRUE,
5162 o = newUNOP(type, 0, newDEFSVOP());
5165 if (type == OP_FTTEXT || type == OP_FTBINARY) {
5167 if (PL_hints & HINT_LOCALE)
5168 o->op_private |= OPpLOCALE;
5175 Perl_ck_fun(pTHX_ OP *o)
5182 int type = o->op_type;
5183 register I32 oa = PL_opargs[type] >> OASHIFT;
5185 if (o->op_flags & OPf_STACKED) {
5186 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
5189 return no_fh_allowed(o);
5192 if (o->op_flags & OPf_KIDS) {
5194 tokid = &cLISTOPo->op_first;
5195 kid = cLISTOPo->op_first;
5196 if (kid->op_type == OP_PUSHMARK ||
5197 kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK)
5199 tokid = &kid->op_sibling;
5200 kid = kid->op_sibling;
5202 if (!kid && PL_opargs[type] & OA_DEFGV)
5203 *tokid = kid = newDEFSVOP();
5207 sibl = kid->op_sibling;
5210 /* list seen where single (scalar) arg expected? */
5211 if (numargs == 1 && !(oa >> 4)
5212 && kid->op_type == OP_LIST && type != OP_SCALAR)
5214 return too_many_arguments(o,PL_op_desc[type]);
5227 if (kid->op_type == OP_CONST &&
5228 (kid->op_private & OPpCONST_BARE))
5230 char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
5231 OP *newop = newAVREF(newGVOP(OP_GV, 0,
5232 gv_fetchpv(name, TRUE, SVt_PVAV) ));
5233 if (ckWARN(WARN_SYNTAX))
5234 Perl_warner(aTHX_ WARN_SYNTAX,
5235 "Array @%s missing the @ in argument %"IVdf" of %s()",
5236 name, (IV)numargs, PL_op_desc[type]);
5239 kid->op_sibling = sibl;
5242 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
5243 bad_type(numargs, "array", PL_op_desc[type], kid);
5247 if (kid->op_type == OP_CONST &&
5248 (kid->op_private & OPpCONST_BARE))
5250 char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
5251 OP *newop = newHVREF(newGVOP(OP_GV, 0,
5252 gv_fetchpv(name, TRUE, SVt_PVHV) ));
5253 if (ckWARN(WARN_SYNTAX))
5254 Perl_warner(aTHX_ WARN_SYNTAX,
5255 "Hash %%%s missing the %% in argument %"IVdf" of %s()",
5256 name, (IV)numargs, PL_op_desc[type]);
5259 kid->op_sibling = sibl;
5262 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
5263 bad_type(numargs, "hash", PL_op_desc[type], kid);
5268 OP *newop = newUNOP(OP_NULL, 0, kid);
5269 kid->op_sibling = 0;
5271 newop->op_next = newop;
5273 kid->op_sibling = sibl;
5278 if (kid->op_type != OP_GV && kid->op_type != OP_RV2GV) {
5279 if (kid->op_type == OP_CONST &&
5280 (kid->op_private & OPpCONST_BARE))
5282 OP *newop = newGVOP(OP_GV, 0,
5283 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, n_a), TRUE,
5288 else if (kid->op_type == OP_READLINE) {
5289 /* neophyte patrol: open(<FH>), close(<FH>) etc. */
5290 bad_type(numargs, "HANDLE", PL_op_desc[o->op_type], kid);
5293 I32 flags = OPf_SPECIAL;
5297 /* is this op a FH constructor? */
5298 if (is_handle_constructor(o,numargs)) {
5299 char *name = Nullch;
5303 /* Set a flag to tell rv2gv to vivify
5304 * need to "prove" flag does not mean something
5305 * else already - NI-S 1999/05/07
5308 if (kid->op_type == OP_PADSV) {
5309 SV **namep = av_fetch(PL_comppad_name,
5311 if (namep && *namep)
5312 name = SvPV(*namep, len);
5314 else if (kid->op_type == OP_RV2SV
5315 && kUNOP->op_first->op_type == OP_GV)
5317 GV *gv = cGVOPx_gv(kUNOP->op_first);
5319 len = GvNAMELEN(gv);
5323 targ = pad_alloc(OP_RV2GV, SVs_PADTMP);
5324 namesv = PL_curpad[targ];
5325 SvUPGRADE(namesv, SVt_PV);
5327 sv_setpvn(namesv, "$", 1);
5328 sv_catpvn(namesv, name, len);
5331 kid->op_sibling = 0;
5332 kid = newUNOP(OP_RV2GV, flags, scalar(kid));
5333 kid->op_targ = targ;
5334 kid->op_private |= priv;
5336 kid->op_sibling = sibl;
5342 mod(scalar(kid), type);
5346 tokid = &kid->op_sibling;
5347 kid = kid->op_sibling;
5349 o->op_private |= numargs;
5351 return too_many_arguments(o,PL_op_desc[o->op_type]);
5354 else if (PL_opargs[type] & OA_DEFGV) {
5356 return newUNOP(type, 0, newDEFSVOP());
5360 while (oa & OA_OPTIONAL)
5362 if (oa && oa != OA_LIST)
5363 return too_few_arguments(o,PL_op_desc[o->op_type]);
5369 Perl_ck_glob(pTHX_ OP *o)
5373 if ((o->op_flags & OPf_KIDS) && !cLISTOPo->op_first->op_sibling)
5374 append_elem(OP_GLOB, o, newDEFSVOP());
5376 if (!((gv = gv_fetchpv("glob", FALSE, SVt_PVCV)) && GvIMPORTED_CV(gv)))
5377 gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
5379 #if !defined(PERL_EXTERNAL_GLOB)
5380 /* XXX this can be tightened up and made more failsafe. */
5382 OP *modname = newSVOP(OP_CONST, 0, newSVpvn("File::Glob", 10));
5383 modname->op_private |= OPpCONST_BARE;
5385 utilize(1, start_subparse(FALSE, 0), Nullop, modname,
5386 newSVOP(OP_CONST, 0, newSVpvn(":globally", 9)));
5387 gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
5390 #endif /* PERL_EXTERNAL_GLOB */
5392 if (gv && GvIMPORTED_CV(gv)) {
5393 append_elem(OP_GLOB, o,
5394 newSVOP(OP_CONST, 0, newSViv(PL_glob_index++)));
5395 o->op_type = OP_LIST;
5396 o->op_ppaddr = PL_ppaddr[OP_LIST];
5397 cLISTOPo->op_first->op_type = OP_PUSHMARK;
5398 cLISTOPo->op_first->op_ppaddr = PL_ppaddr[OP_PUSHMARK];
5399 o = newUNOP(OP_ENTERSUB, OPf_STACKED,
5400 append_elem(OP_LIST, o,
5401 scalar(newUNOP(OP_RV2CV, 0,
5402 newGVOP(OP_GV, 0, gv)))));
5403 o = newUNOP(OP_NULL, 0, ck_subr(o));
5404 o->op_targ = OP_GLOB; /* hint at what it used to be */
5407 gv = newGVgen("main");
5409 append_elem(OP_GLOB, o, newGVOP(OP_GV, 0, gv));
5415 Perl_ck_grep(pTHX_ OP *o)
5419 OPCODE type = o->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
5421 o->op_ppaddr = PL_ppaddr[OP_GREPSTART];
5422 NewOp(1101, gwop, 1, LOGOP);
5424 if (o->op_flags & OPf_STACKED) {
5427 kid = cLISTOPo->op_first->op_sibling;
5428 for (k = cLISTOPo->op_first->op_sibling->op_next; k; k = k->op_next) {
5431 kid->op_next = (OP*)gwop;
5432 o->op_flags &= ~OPf_STACKED;
5434 kid = cLISTOPo->op_first->op_sibling;
5435 if (type == OP_MAPWHILE)
5442 kid = cLISTOPo->op_first->op_sibling;
5443 if (kid->op_type != OP_NULL)
5444 Perl_croak(aTHX_ "panic: ck_grep");
5445 kid = kUNOP->op_first;
5447 gwop->op_type = type;
5448 gwop->op_ppaddr = PL_ppaddr[type];
5449 gwop->op_first = listkids(o);
5450 gwop->op_flags |= OPf_KIDS;
5451 gwop->op_private = 1;
5452 gwop->op_other = LINKLIST(kid);
5453 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
5454 kid->op_next = (OP*)gwop;
5456 kid = cLISTOPo->op_first->op_sibling;
5457 if (!kid || !kid->op_sibling)
5458 return too_few_arguments(o,PL_op_desc[o->op_type]);
5459 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
5460 mod(kid, OP_GREPSTART);
5466 Perl_ck_index(pTHX_ OP *o)
5468 if (o->op_flags & OPf_KIDS) {
5469 OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5471 kid = kid->op_sibling; /* get past "big" */
5472 if (kid && kid->op_type == OP_CONST)
5473 fbm_compile(((SVOP*)kid)->op_sv, 0);
5479 Perl_ck_lengthconst(pTHX_ OP *o)
5481 /* XXX length optimization goes here */
5486 Perl_ck_lfun(pTHX_ OP *o)
5488 OPCODE type = o->op_type;
5489 return modkids(ck_fun(o), type);
5493 Perl_ck_defined(pTHX_ OP *o) /* 19990527 MJD */
5496 if ((o->op_flags & OPf_KIDS) && ckWARN(WARN_DEPRECATED)) {
5497 switch (cUNOPo->op_first->op_type) {
5499 break; /* Globals via GV can be undef */
5501 case OP_AASSIGN: /* Is this a good idea? */
5502 Perl_warner(aTHX_ WARN_DEPRECATED,
5503 "defined(@array) is deprecated");
5504 Perl_warner(aTHX_ WARN_DEPRECATED,
5505 "(Maybe you should just omit the defined()?)\n");
5508 break; /* Globals via GV can be undef */
5510 Perl_warner(aTHX_ WARN_DEPRECATED,
5511 "defined(%hash) is deprecated");
5512 Perl_warner(aTHX_ WARN_DEPRECATED,
5513 "(Maybe you should just omit the defined()?)\n");
5524 Perl_ck_rfun(pTHX_ OP *o)
5526 OPCODE type = o->op_type;
5527 return refkids(ck_fun(o), type);
5531 Perl_ck_listiob(pTHX_ OP *o)
5535 kid = cLISTOPo->op_first;
5538 kid = cLISTOPo->op_first;
5540 if (kid->op_type == OP_PUSHMARK)
5541 kid = kid->op_sibling;
5542 if (kid && o->op_flags & OPf_STACKED)
5543 kid = kid->op_sibling;
5544 else if (kid && !kid->op_sibling) { /* print HANDLE; */
5545 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
5546 o->op_flags |= OPf_STACKED; /* make it a filehandle */
5547 kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
5548 cLISTOPo->op_first->op_sibling = kid;
5549 cLISTOPo->op_last = kid;
5550 kid = kid->op_sibling;
5555 append_elem(o->op_type, o, newDEFSVOP());
5561 if (PL_hints & HINT_LOCALE)
5562 o->op_private |= OPpLOCALE;
5569 Perl_ck_fun_locale(pTHX_ OP *o)
5575 if (PL_hints & HINT_LOCALE)
5576 o->op_private |= OPpLOCALE;
5583 Perl_ck_sassign(pTHX_ OP *o)
5585 OP *kid = cLISTOPo->op_first;
5586 /* has a disposable target? */
5587 if ((PL_opargs[kid->op_type] & OA_TARGLEX)
5588 && !(kid->op_flags & OPf_STACKED))
5590 OP *kkid = kid->op_sibling;
5592 /* Can just relocate the target. */
5593 if (kkid && kkid->op_type == OP_PADSV
5594 && !(kkid->op_private & OPpLVAL_INTRO))
5596 /* Concat has problems if target is equal to right arg. */
5597 if (kid->op_type == OP_CONCAT) {
5598 if (kLISTOP->op_first->op_sibling->op_type == OP_PADSV
5599 && kLISTOP->op_first->op_sibling->op_targ == kkid->op_targ)
5602 else if (kid->op_type == OP_JOIN) {
5603 /* do_join has problems if the arguments coincide with target.
5604 In fact the second argument *can* safely coincide,
5605 but ignore=pessimize this rare occasion. */
5606 OP *arg = kLISTOP->op_first->op_sibling; /* Skip PUSHMARK */
5609 if (arg->op_type == OP_PADSV
5610 && arg->op_targ == kkid->op_targ)
5612 arg = arg->op_sibling;
5615 else if (kid->op_type == OP_QUOTEMETA) {
5616 /* quotemeta has problems if the argument coincides with target. */
5617 if (kLISTOP->op_first->op_type == OP_PADSV
5618 && kLISTOP->op_first->op_targ == kkid->op_targ)
5621 kid->op_targ = kkid->op_targ;
5623 /* Now we do not need PADSV and SASSIGN. */
5624 kid->op_sibling = o->op_sibling; /* NULL */
5625 cLISTOPo->op_first = NULL;
5628 kid->op_private |= OPpTARGET_MY; /* Used for context settings */
5636 Perl_ck_scmp(pTHX_ OP *o)
5640 if (PL_hints & HINT_LOCALE)
5641 o->op_private |= OPpLOCALE;
5648 Perl_ck_match(pTHX_ OP *o)
5650 o->op_private |= OPpRUNTIME;
5655 Perl_ck_method(pTHX_ OP *o)
5657 OP *kid = cUNOPo->op_first;
5658 if (kid->op_type == OP_CONST) {
5659 SV* sv = kSVOP->op_sv;
5660 if (!(strchr(SvPVX(sv), ':') || strchr(SvPVX(sv), '\''))) {
5662 sv_upgrade(sv, SVt_PVIV);
5664 PERL_HASH(SvUVX(sv), SvPVX(sv), SvCUR(sv));
5665 cmop = newSVOP(OP_METHOD_NAMED, 0, sv);
5666 kSVOP->op_sv = Nullsv;
5675 Perl_ck_null(pTHX_ OP *o)
5681 Perl_ck_repeat(pTHX_ OP *o)
5683 if (cBINOPo->op_first->op_flags & OPf_PARENS) {
5684 o->op_private |= OPpREPEAT_DOLIST;
5685 cBINOPo->op_first = force_list(cBINOPo->op_first);
5693 Perl_ck_require(pTHX_ OP *o)
5695 if (o->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
5696 SVOP *kid = (SVOP*)cUNOPo->op_first;
5698 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
5700 for (s = SvPVX(kid->op_sv); *s; s++) {
5701 if (*s == ':' && s[1] == ':') {
5703 Move(s+2, s+1, strlen(s+2)+1, char);
5704 --SvCUR(kid->op_sv);
5707 sv_catpvn(kid->op_sv, ".pm", 3);
5715 Perl_ck_retarget(pTHX_ OP *o)
5717 Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
5724 Perl_ck_select(pTHX_ OP *o)
5727 if (o->op_flags & OPf_KIDS) {
5728 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5729 if (kid && kid->op_sibling) {
5730 o->op_type = OP_SSELECT;
5731 o->op_ppaddr = PL_ppaddr[OP_SSELECT];
5733 return fold_constants(o);
5737 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5738 if (kid && kid->op_type == OP_RV2GV)
5739 kid->op_private &= ~HINT_STRICT_REFS;
5744 Perl_ck_shift(pTHX_ OP *o)
5746 I32 type = o->op_type;
5748 if (!(o->op_flags & OPf_KIDS)) {
5753 if (!CvUNIQUE(PL_compcv)) {
5754 argop = newOP(OP_PADAV, OPf_REF);
5755 argop->op_targ = 0; /* PL_curpad[0] is @_ */
5758 argop = newUNOP(OP_RV2AV, 0,
5759 scalar(newGVOP(OP_GV, 0,
5760 gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
5763 argop = newUNOP(OP_RV2AV, 0,
5764 scalar(newGVOP(OP_GV, 0, !CvUNIQUE(PL_compcv) ?
5765 PL_defgv : gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
5766 #endif /* USE_THREADS */
5767 return newUNOP(type, 0, scalar(argop));
5769 return scalar(modkids(ck_fun(o), type));
5773 Perl_ck_sort(pTHX_ OP *o)
5777 if (PL_hints & HINT_LOCALE)
5778 o->op_private |= OPpLOCALE;
5781 if (o->op_type == OP_SORT && o->op_flags & OPf_STACKED)
5783 if (o->op_flags & OPf_STACKED) { /* may have been cleared */
5784 OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5786 kid = kUNOP->op_first; /* get past null */
5788 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
5790 if (kid->op_type == OP_SCOPE) {
5794 else if (kid->op_type == OP_LEAVE) {
5795 if (o->op_type == OP_SORT) {
5796 null(kid); /* wipe out leave */
5799 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
5800 if (k->op_next == kid)
5805 kid->op_next = 0; /* just disconnect the leave */
5806 k = kLISTOP->op_first;
5810 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5811 if (o->op_type == OP_SORT)
5815 o->op_flags |= OPf_SPECIAL;
5817 else if (kid->op_type == OP_RV2SV || kid->op_type == OP_PADSV)
5818 null(cLISTOPo->op_first->op_sibling);
5825 S_simplify_sort(pTHX_ OP *o)
5828 register OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5832 if (!(o->op_flags & OPf_STACKED))
5834 GvMULTI_on(gv_fetchpv("a", TRUE, SVt_PV));
5835 GvMULTI_on(gv_fetchpv("b", TRUE, SVt_PV));
5836 kid = kUNOP->op_first; /* get past null */
5837 if (kid->op_type != OP_SCOPE)
5839 kid = kLISTOP->op_last; /* get past scope */
5840 switch(kid->op_type) {
5848 k = kid; /* remember this node*/
5849 if (kBINOP->op_first->op_type != OP_RV2SV)
5851 kid = kBINOP->op_first; /* get past cmp */
5852 if (kUNOP->op_first->op_type != OP_GV)
5854 kid = kUNOP->op_first; /* get past rv2sv */
5856 if (GvSTASH(gv) != PL_curstash)
5858 if (strEQ(GvNAME(gv), "a"))
5860 else if(strEQ(GvNAME(gv), "b"))
5864 kid = k; /* back to cmp */
5865 if (kBINOP->op_last->op_type != OP_RV2SV)
5867 kid = kBINOP->op_last; /* down to 2nd arg */
5868 if (kUNOP->op_first->op_type != OP_GV)
5870 kid = kUNOP->op_first; /* get past rv2sv */
5872 if (GvSTASH(gv) != PL_curstash
5874 ? strNE(GvNAME(gv), "a")
5875 : strNE(GvNAME(gv), "b")))
5877 o->op_flags &= ~(OPf_STACKED | OPf_SPECIAL);
5879 o->op_private |= OPpSORT_REVERSE;
5880 if (k->op_type == OP_NCMP)
5881 o->op_private |= OPpSORT_NUMERIC;
5882 if (k->op_type == OP_I_NCMP)
5883 o->op_private |= OPpSORT_NUMERIC | OPpSORT_INTEGER;
5884 kid = cLISTOPo->op_first->op_sibling;
5885 cLISTOPo->op_first->op_sibling = kid->op_sibling; /* bypass old block */
5886 op_free(kid); /* then delete it */
5887 cLISTOPo->op_children--;
5891 Perl_ck_split(pTHX_ OP *o)
5895 if (o->op_flags & OPf_STACKED)
5896 return no_fh_allowed(o);
5898 kid = cLISTOPo->op_first;
5899 if (kid->op_type != OP_NULL)
5900 Perl_croak(aTHX_ "panic: ck_split");
5901 kid = kid->op_sibling;
5902 op_free(cLISTOPo->op_first);
5903 cLISTOPo->op_first = kid;
5905 cLISTOPo->op_first = kid = newSVOP(OP_CONST, 0, newSVpvn(" ", 1));
5906 cLISTOPo->op_last = kid; /* There was only one element previously */
5909 if (kid->op_type != OP_MATCH) {
5910 OP *sibl = kid->op_sibling;
5911 kid->op_sibling = 0;
5912 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
5913 if (cLISTOPo->op_first == cLISTOPo->op_last)
5914 cLISTOPo->op_last = kid;
5915 cLISTOPo->op_first = kid;
5916 kid->op_sibling = sibl;
5919 kid->op_type = OP_PUSHRE;
5920 kid->op_ppaddr = PL_ppaddr[OP_PUSHRE];
5923 if (!kid->op_sibling)
5924 append_elem(OP_SPLIT, o, newDEFSVOP());
5926 kid = kid->op_sibling;
5929 if (!kid->op_sibling)
5930 append_elem(OP_SPLIT, o, newSVOP(OP_CONST, 0, newSViv(0)));
5932 kid = kid->op_sibling;
5935 if (kid->op_sibling)
5936 return too_many_arguments(o,PL_op_desc[o->op_type]);
5942 Perl_ck_join(pTHX_ OP *o)
5944 if (ckWARN(WARN_SYNTAX)) {
5945 OP *kid = cLISTOPo->op_first->op_sibling;
5946 if (kid && kid->op_type == OP_MATCH) {
5947 char *pmstr = "STRING";
5948 if (kPMOP->op_pmregexp)
5949 pmstr = kPMOP->op_pmregexp->precomp;
5950 Perl_warner(aTHX_ WARN_SYNTAX,
5951 "/%s/ should probably be written as \"%s\"",
5959 Perl_ck_subr(pTHX_ OP *o)
5962 OP *prev = ((cUNOPo->op_first->op_sibling)
5963 ? cUNOPo : ((UNOP*)cUNOPo->op_first))->op_first;
5964 OP *o2 = prev->op_sibling;
5973 o->op_private |= OPpENTERSUB_HASTARG;
5974 for (cvop = o2; cvop->op_sibling; cvop = cvop->op_sibling) ;
5975 if (cvop->op_type == OP_RV2CV) {
5977 o->op_private |= (cvop->op_private & OPpENTERSUB_AMPER);
5978 null(cvop); /* disable rv2cv */
5979 tmpop = (SVOP*)((UNOP*)cvop)->op_first;
5980 if (tmpop->op_type == OP_GV && !(o->op_private & OPpENTERSUB_AMPER)) {
5981 GV *gv = cGVOPx_gv(tmpop);
5984 tmpop->op_private |= OPpEARLY_CV;
5985 else if (SvPOK(cv)) {
5986 namegv = CvANON(cv) ? gv : CvGV(cv);
5987 proto = SvPV((SV*)cv, n_a);
5991 else if (cvop->op_type == OP_METHOD || cvop->op_type == OP_METHOD_NAMED) {
5992 if (o2->op_type == OP_CONST)
5993 o2->op_private &= ~OPpCONST_STRICT;
5994 else if (o2->op_type == OP_LIST) {
5995 OP *o = ((UNOP*)o2)->op_first->op_sibling;
5996 if (o && o->op_type == OP_CONST)
5997 o->op_private &= ~OPpCONST_STRICT;
6000 o->op_private |= (PL_hints & HINT_STRICT_REFS);
6001 if (PERLDB_SUB && PL_curstash != PL_debstash)
6002 o->op_private |= OPpENTERSUB_DB;
6003 while (o2 != cvop) {
6007 return too_many_arguments(o, gv_ename(namegv));
6025 if (o2->op_type != OP_REFGEN && o2->op_type != OP_UNDEF)
6026 bad_type(arg, "block", gv_ename(namegv), o2);
6029 /* '*' allows any scalar type, including bareword */
6032 if (o2->op_type == OP_RV2GV)
6033 goto wrapref; /* autoconvert GLOB -> GLOBref */
6034 else if (o2->op_type == OP_CONST)
6035 o2->op_private &= ~OPpCONST_STRICT;
6036 else if (o2->op_type == OP_ENTERSUB) {
6037 /* accidental subroutine, revert to bareword */
6038 OP *gvop = ((UNOP*)o2)->op_first;
6039 if (gvop && gvop->op_type == OP_NULL) {
6040 gvop = ((UNOP*)gvop)->op_first;
6042 for (; gvop->op_sibling; gvop = gvop->op_sibling)
6045 (gvop->op_private & OPpENTERSUB_NOPAREN) &&
6046 (gvop = ((UNOP*)gvop)->op_first) &&
6047 gvop->op_type == OP_GV)
6049 GV *gv = cGVOPx_gv(gvop);
6050 OP *sibling = o2->op_sibling;
6051 SV *n = newSVpvn("",0);
6053 gv_fullname3(n, gv, "");
6054 if (SvCUR(n)>6 && strnEQ(SvPVX(n),"main::",6))
6055 sv_chop(n, SvPVX(n)+6);
6056 o2 = newSVOP(OP_CONST, 0, n);
6057 prev->op_sibling = o2;
6058 o2->op_sibling = sibling;
6070 if (o2->op_type != OP_RV2GV)
6071 bad_type(arg, "symbol", gv_ename(namegv), o2);
6074 if (o2->op_type != OP_RV2CV)
6075 bad_type(arg, "sub", gv_ename(namegv), o2);
6078 if (o2->op_type != OP_RV2SV
6079 && o2->op_type != OP_PADSV
6080 && o2->op_type != OP_HELEM
6081 && o2->op_type != OP_AELEM
6082 && o2->op_type != OP_THREADSV)
6084 bad_type(arg, "scalar", gv_ename(namegv), o2);
6088 if (o2->op_type != OP_RV2AV && o2->op_type != OP_PADAV)
6089 bad_type(arg, "array", gv_ename(namegv), o2);
6092 if (o2->op_type != OP_RV2HV && o2->op_type != OP_PADHV)
6093 bad_type(arg, "hash", gv_ename(namegv), o2);
6097 OP* sib = kid->op_sibling;
6098 kid->op_sibling = 0;
6099 o2 = newUNOP(OP_REFGEN, 0, kid);
6100 o2->op_sibling = sib;
6101 prev->op_sibling = o2;
6112 Perl_croak(aTHX_ "Malformed prototype for %s: %s",
6113 gv_ename(namegv), SvPV((SV*)cv, n_a));
6118 mod(o2, OP_ENTERSUB);
6120 o2 = o2->op_sibling;
6122 if (proto && !optional &&
6123 (*proto && *proto != '@' && *proto != '%' && *proto != ';'))
6124 return too_few_arguments(o, gv_ename(namegv));
6129 Perl_ck_svconst(pTHX_ OP *o)
6131 SvREADONLY_on(cSVOPo->op_sv);
6136 Perl_ck_trunc(pTHX_ OP *o)
6138 if (o->op_flags & OPf_KIDS) {
6139 SVOP *kid = (SVOP*)cUNOPo->op_first;
6141 if (kid->op_type == OP_NULL)
6142 kid = (SVOP*)kid->op_sibling;
6143 if (kid && kid->op_type == OP_CONST &&
6144 (kid->op_private & OPpCONST_BARE))
6146 o->op_flags |= OPf_SPECIAL;
6147 kid->op_private &= ~OPpCONST_STRICT;
6153 /* A peephole optimizer. We visit the ops in the order they're to execute. */
6156 Perl_peep(pTHX_ register OP *o)
6159 register OP* oldop = 0;
6161 OP *last_composite = Nullop;
6163 if (!o || o->op_seq)
6167 SAVEVPTR(PL_curcop);
6168 for (; o; o = o->op_next) {
6174 switch (o->op_type) {
6178 PL_curcop = ((COP*)o); /* for warnings */
6179 o->op_seq = PL_op_seqmax++;
6180 last_composite = Nullop;
6184 if (cSVOPo->op_private & OPpCONST_STRICT)
6185 no_bareword_allowed(o);
6187 /* Relocate sv to the pad for thread safety.
6188 * Despite being a "constant", the SV is written to,
6189 * for reference counts, sv_upgrade() etc. */
6191 PADOFFSET ix = pad_alloc(OP_CONST, SVs_PADTMP);
6192 SvREFCNT_dec(PL_curpad[ix]);
6193 SvPADTMP_on(cSVOPo->op_sv);
6194 PL_curpad[ix] = cSVOPo->op_sv;
6195 cSVOPo->op_sv = Nullsv;
6204 if ( o->op_next && o->op_next->op_type == OP_STRINGIFY
6205 && !(o->op_next->op_private & OPpTARGET_MY) )
6207 o->op_seq = PL_op_seqmax++;
6212 if (o->op_next && o->op_next->op_type == OP_STRINGIFY) {
6213 if (o->op_next->op_private & OPpTARGET_MY) {
6214 if ((o->op_flags & OPf_STACKED) /* chained concats */
6215 || (o->op_type == OP_CONCAT
6216 /* Concat has problems if target is equal to right arg. */
6217 && (((LISTOP*)o)->op_first->op_sibling->op_type
6219 && (((LISTOP*)o)->op_first->op_sibling->op_targ
6220 == o->op_next->op_targ)))
6222 goto ignore_optimization;
6225 o->op_targ = o->op_next->op_targ;
6226 o->op_next->op_targ = 0;
6227 o->op_private |= OPpTARGET_MY;
6232 ignore_optimization:
6233 o->op_seq = PL_op_seqmax++;
6236 if ((o->op_flags & OPf_WANT) != OPf_WANT_LIST) {
6237 o->op_seq = PL_op_seqmax++;
6238 break; /* Scalar stub must produce undef. List stub is noop */
6242 if (o->op_targ == OP_NEXTSTATE
6243 || o->op_targ == OP_DBSTATE
6244 || o->op_targ == OP_SETSTATE)
6246 PL_curcop = ((COP*)o);
6253 if (oldop && o->op_next) {
6254 oldop->op_next = o->op_next;
6257 o->op_seq = PL_op_seqmax++;
6261 if (o->op_next->op_type == OP_RV2SV) {
6262 if (!(o->op_next->op_private & OPpDEREF)) {
6264 o->op_private |= o->op_next->op_private & OPpLVAL_INTRO;
6265 o->op_next = o->op_next->op_next;
6266 o->op_type = OP_GVSV;
6267 o->op_ppaddr = PL_ppaddr[OP_GVSV];
6270 else if (o->op_next->op_type == OP_RV2AV) {
6271 OP* pop = o->op_next->op_next;
6273 if (pop->op_type == OP_CONST &&
6274 (PL_op = pop->op_next) &&
6275 pop->op_next->op_type == OP_AELEM &&
6276 !(pop->op_next->op_private &
6277 (OPpLVAL_INTRO|OPpLVAL_DEFER|OPpDEREF)) &&
6278 (i = SvIV(((SVOP*)pop)->op_sv) - PL_compiling.cop_arybase)
6286 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
6287 o->op_next = pop->op_next->op_next;
6288 o->op_type = OP_AELEMFAST;
6289 o->op_ppaddr = PL_ppaddr[OP_AELEMFAST];
6290 o->op_private = (U8)i;
6295 else if ((o->op_private & OPpEARLY_CV) && ckWARN(WARN_UNSAFE)) {
6297 if (SvTYPE(gv) == SVt_PVGV && GvCV(gv) && SvPVX(GvCV(gv))) {
6298 /* XXX could check prototype here instead of just carping */
6299 SV *sv = sv_newmortal();
6300 gv_efullname3(sv, gv, Nullch);
6301 Perl_warner(aTHX_ WARN_UNSAFE,
6302 "%s() called too early to check prototype",
6307 o->op_seq = PL_op_seqmax++;
6318 o->op_seq = PL_op_seqmax++;
6319 while (cLOGOP->op_other->op_type == OP_NULL)
6320 cLOGOP->op_other = cLOGOP->op_other->op_next;
6321 peep(cLOGOP->op_other);
6325 o->op_seq = PL_op_seqmax++;
6326 peep(cLOOP->op_redoop);
6327 peep(cLOOP->op_nextop);
6328 peep(cLOOP->op_lastop);
6334 o->op_seq = PL_op_seqmax++;
6335 peep(cPMOP->op_pmreplstart);
6339 o->op_seq = PL_op_seqmax++;
6340 if (ckWARN(WARN_SYNTAX) && o->op_next
6341 && o->op_next->op_type == OP_NEXTSTATE) {
6342 if (o->op_next->op_sibling &&
6343 o->op_next->op_sibling->op_type != OP_EXIT &&
6344 o->op_next->op_sibling->op_type != OP_WARN &&
6345 o->op_next->op_sibling->op_type != OP_DIE) {
6346 line_t oldline = CopLINE(PL_curcop);
6348 CopLINE_set(PL_curcop, CopLINE((COP*)o->op_next));
6349 Perl_warner(aTHX_ WARN_SYNTAX, "Statement unlikely to be reached");
6350 Perl_warner(aTHX_ WARN_SYNTAX, "(Maybe you meant system() when you said exec()?)\n");
6351 CopLINE_set(PL_curcop, oldline);
6365 if ((o->op_private & (OPpLVAL_INTRO))
6366 || ((BINOP*)o)->op_last->op_type != OP_CONST)
6368 rop = (UNOP*)((BINOP*)o)->op_first;
6369 if (rop->op_type != OP_RV2HV || rop->op_first->op_type != OP_PADSV)
6371 lexname = *av_fetch(PL_comppad_name, rop->op_first->op_targ, TRUE);
6372 if (!SvOBJECT(lexname))
6374 fields = (GV**)hv_fetch(SvSTASH(lexname), "FIELDS", 6, FALSE);
6375 if (!fields || !GvHV(*fields))
6377 svp = cSVOPx_svp(((BINOP*)o)->op_last);
6378 key = SvPV(*svp, keylen);
6379 indsvp = hv_fetch(GvHV(*fields), key, keylen, FALSE);
6381 Perl_croak(aTHX_ "No such pseudo-hash field \"%s\" in variable %s of type %s",
6382 key, SvPV(lexname, n_a), HvNAME(SvSTASH(lexname)));
6384 ind = SvIV(*indsvp);
6386 Perl_croak(aTHX_ "Bad index while coercing array into hash");
6387 rop->op_type = OP_RV2AV;
6388 rop->op_ppaddr = PL_ppaddr[OP_RV2AV];
6389 o->op_type = OP_AELEM;
6390 o->op_ppaddr = PL_ppaddr[OP_AELEM];
6392 *svp = newSViv(ind);
6398 if (!(o->op_flags & OPf_WANT)
6399 || (o->op_flags & OPf_WANT) == OPf_WANT_LIST)
6403 o->op_seq = PL_op_seqmax++;
6407 if (o->op_next && o->op_next->op_type != OP_LEAVESUBLV) {
6408 o->op_seq = PL_op_seqmax++;
6414 if (last_composite) {
6415 OP *r = last_composite;
6417 while (r->op_sibling)
6420 || (r->op_next->op_type == OP_LIST
6421 && r->op_next->op_next == o))
6423 if (last_composite->op_type == OP_RV2AV)
6424 yyerror("Lvalue subs returning arrays not implemented yet");
6426 yyerror("Lvalue subs returning hashes not implemented yet");
6433 o->op_seq = PL_op_seqmax++;