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]);
518 SvREADONLY_off(PL_curpad[po]); /* could be a freed constant */
521 if ((I32)po < PL_padix)
526 Perl_pad_swipe(pTHX_ PADOFFSET po)
529 if (AvARRAY(PL_comppad) != PL_curpad)
530 Perl_croak(aTHX_ "panic: pad_swipe curpad");
532 Perl_croak(aTHX_ "panic: pad_swipe po");
534 DEBUG_X(PerlIO_printf(Perl_debug_log,
535 "0x%"UVxf" Pad 0x%"UVxf" swipe %"IVdf"\n",
536 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
538 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" swipe %"IVdf"\n",
539 PTR2UV(PL_curpad), (IV)po));
540 #endif /* USE_THREADS */
541 SvPADTMP_off(PL_curpad[po]);
542 PL_curpad[po] = NEWSV(1107,0);
543 SvPADTMP_on(PL_curpad[po]);
544 if ((I32)po < PL_padix)
548 /* XXX pad_reset() is currently disabled because it results in serious bugs.
549 * It causes pad temp TARGs to be shared between OPs. Since TARGs are pushed
550 * on the stack by OPs that use them, there are several ways to get an alias
551 * to a shared TARG. Such an alias will change randomly and unpredictably.
552 * We avoid doing this until we can think of a Better Way.
557 #ifdef USE_BROKEN_PAD_RESET
561 if (AvARRAY(PL_comppad) != PL_curpad)
562 Perl_croak(aTHX_ "panic: pad_reset curpad");
564 DEBUG_X(PerlIO_printf(Perl_debug_log,
565 "0x%"UVxf" Pad 0x%"UVxf" reset\n",
566 PTR2UV(thr), PTR2UV(PL_curpad)));
568 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" reset\n",
570 #endif /* USE_THREADS */
571 if (!PL_tainting) { /* Can't mix tainted and non-tainted temporaries. */
572 for (po = AvMAX(PL_comppad); po > PL_padix_floor; po--) {
573 if (PL_curpad[po] && !SvIMMORTAL(PL_curpad[po]))
574 SvPADTMP_off(PL_curpad[po]);
576 PL_padix = PL_padix_floor;
579 PL_pad_reset_pending = FALSE;
583 /* find_threadsv is not reentrant */
585 Perl_find_threadsv(pTHX_ const char *name)
591 /* We currently only handle names of a single character */
592 p = strchr(PL_threadsv_names, *name);
595 key = p - PL_threadsv_names;
596 MUTEX_LOCK(&thr->mutex);
597 svp = av_fetch(thr->threadsv, key, FALSE);
599 MUTEX_UNLOCK(&thr->mutex);
601 SV *sv = NEWSV(0, 0);
602 av_store(thr->threadsv, key, sv);
603 thr->threadsvp = AvARRAY(thr->threadsv);
604 MUTEX_UNLOCK(&thr->mutex);
606 * Some magic variables used to be automagically initialised
607 * in gv_fetchpv. Those which are now per-thread magicals get
608 * initialised here instead.
614 sv_setpv(sv, "\034");
615 sv_magic(sv, 0, 0, name, 1);
620 PL_sawampersand = TRUE;
634 /* XXX %! tied to Errno.pm needs to be added here.
635 * See gv_fetchpv(). */
639 sv_magic(sv, 0, 0, name, 1);
641 DEBUG_S(PerlIO_printf(Perl_error_log,
642 "find_threadsv: new SV %p for $%s%c\n",
643 sv, (*name < 32) ? "^" : "",
644 (*name < 32) ? toCTRL(*name) : *name));
648 #endif /* USE_THREADS */
653 Perl_op_free(pTHX_ OP *o)
655 register OP *kid, *nextkid;
658 if (!o || o->op_seq == (U16)-1)
661 if (o->op_private & OPpREFCOUNTED) {
662 switch (o->op_type) {
670 if (OpREFCNT_dec(o)) {
681 if (o->op_flags & OPf_KIDS) {
682 for (kid = cUNOPo->op_first; kid; kid = nextkid) {
683 nextkid = kid->op_sibling; /* Get before next freeing kid */
691 /* COP* is not cleared by op_clear() so that we may track line
692 * numbers etc even after null() */
693 if (type == OP_NEXTSTATE || type == OP_SETSTATE || type == OP_DBSTATE)
698 #ifdef PL_OP_SLAB_ALLOC
699 if ((char *) o == PL_OpPtr)
708 S_op_clear(pTHX_ OP *o)
710 switch (o->op_type) {
711 case OP_NULL: /* Was holding old type, if any. */
712 case OP_ENTEREVAL: /* Was holding hints. */
714 case OP_THREADSV: /* Was holding index into thr->threadsv AV. */
720 if (!(o->op_flags & OPf_SPECIAL))
723 #endif /* USE_THREADS */
725 if (!(o->op_flags & OPf_REF)
726 || (PL_check[o->op_type] != MEMBER_TO_FPTR(Perl_ck_ftst)))
733 if (cPADOPo->op_padix > 0) {
736 pad_swipe(cPADOPo->op_padix);
737 /* No GvIN_PAD_off(gv) here, because other references may still
738 * exist on the pad */
741 cPADOPo->op_padix = 0;
744 SvREFCNT_dec(cSVOPo->op_sv);
745 cSVOPo->op_sv = Nullsv;
749 SvREFCNT_dec(cSVOPo->op_sv);
750 cSVOPo->op_sv = Nullsv;
756 if (o->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
760 if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
761 SvREFCNT_dec(cSVOPo->op_sv);
762 cSVOPo->op_sv = Nullsv;
765 Safefree(cPVOPo->op_pv);
766 cPVOPo->op_pv = Nullch;
770 op_free(cPMOPo->op_pmreplroot);
774 if ((PADOFFSET)cPMOPo->op_pmreplroot) {
776 GV *gv = (GV*)PL_curpad[(PADOFFSET)cPMOPo->op_pmreplroot];
777 pad_swipe((PADOFFSET)cPMOPo->op_pmreplroot);
778 /* No GvIN_PAD_off(gv) here, because other references may still
779 * exist on the pad */
784 SvREFCNT_dec((SV*)cPMOPo->op_pmreplroot);
790 cPMOPo->op_pmreplroot = Nullop;
791 ReREFCNT_dec(cPMOPo->op_pmregexp);
792 cPMOPo->op_pmregexp = (REGEXP*)NULL;
796 if (o->op_targ > 0) {
797 pad_free(o->op_targ);
803 S_cop_free(pTHX_ COP* cop)
805 Safefree(cop->cop_label);
807 Safefree(CopFILE(cop)); /* XXXXX share in a pvtable? */
808 Safefree(CopSTASHPV(cop)); /* XXXXX share in a pvtable? */
810 /* NOTE: COP.cop_stash is not refcounted */
811 SvREFCNT_dec(CopFILEGV(cop));
813 if (! specialWARN(cop->cop_warnings))
814 SvREFCNT_dec(cop->cop_warnings);
820 if (o->op_type == OP_NULL)
823 o->op_targ = o->op_type;
824 o->op_type = OP_NULL;
825 o->op_ppaddr = PL_ppaddr[OP_NULL];
828 /* Contextualizers */
830 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
833 Perl_linklist(pTHX_ OP *o)
840 /* establish postfix order */
841 if (cUNOPo->op_first) {
842 o->op_next = LINKLIST(cUNOPo->op_first);
843 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
845 kid->op_next = LINKLIST(kid->op_sibling);
857 Perl_scalarkids(pTHX_ OP *o)
860 if (o && o->op_flags & OPf_KIDS) {
861 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
868 S_scalarboolean(pTHX_ OP *o)
870 if (o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST) {
872 if (ckWARN(WARN_SYNTAX)) {
873 line_t oldline = CopLINE(PL_curcop);
875 if (PL_copline != NOLINE)
876 CopLINE_set(PL_curcop, PL_copline);
877 Perl_warner(aTHX_ WARN_SYNTAX, "Found = in conditional, should be ==");
878 CopLINE_set(PL_curcop, oldline);
885 Perl_scalar(pTHX_ OP *o)
889 /* assumes no premature commitment */
890 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
891 || o->op_type == OP_RETURN)
896 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_SCALAR;
898 switch (o->op_type) {
900 if (o->op_private & OPpREPEAT_DOLIST)
901 null(((LISTOP*)cBINOPo->op_first)->op_first);
902 scalar(cBINOPo->op_first);
907 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
911 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
912 if (!kPMOP->op_pmreplroot)
913 deprecate("implicit split to @_");
921 if (o->op_flags & OPf_KIDS) {
922 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
928 kid = cLISTOPo->op_first;
930 while (kid = kid->op_sibling) {
936 WITH_THR(PL_curcop = &PL_compiling);
941 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
947 WITH_THR(PL_curcop = &PL_compiling);
954 Perl_scalarvoid(pTHX_ OP *o)
961 if (o->op_type == OP_NEXTSTATE
962 || o->op_type == OP_SETSTATE
963 || o->op_type == OP_DBSTATE
964 || (o->op_type == OP_NULL && (o->op_targ == OP_NEXTSTATE
965 || o->op_targ == OP_SETSTATE
966 || o->op_targ == OP_DBSTATE)))
969 PL_curcop = (COP*)o; /* for warning below */
972 /* assumes no premature commitment */
973 want = o->op_flags & OPf_WANT;
974 if ((want && want != OPf_WANT_SCALAR) || PL_error_count
975 || o->op_type == OP_RETURN)
980 if ((o->op_private & OPpTARGET_MY)
981 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
983 return scalar(o); /* As if inside SASSIGN */
986 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_VOID;
988 switch (o->op_type) {
990 if (!(PL_opargs[o->op_type] & OA_FOLDCONST))
994 if (o->op_flags & OPf_STACKED)
998 if (o->op_private == 4)
1040 case OP_GETSOCKNAME:
1041 case OP_GETPEERNAME:
1046 case OP_GETPRIORITY:
1069 if (!(o->op_private & OPpLVAL_INTRO))
1070 useless = PL_op_desc[o->op_type];
1077 if (!(o->op_private & OPpLVAL_INTRO) &&
1078 (!o->op_sibling || o->op_sibling->op_type != OP_READLINE))
1079 useless = "a variable";
1084 if (cSVOPo->op_private & OPpCONST_STRICT)
1085 no_bareword_allowed(o);
1088 if (ckWARN(WARN_VOID)) {
1089 useless = "a constant";
1090 if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
1092 else if (SvPOK(sv)) {
1093 if (strnEQ(SvPVX(sv), "di", 2) ||
1094 strnEQ(SvPVX(sv), "ds", 2) ||
1095 strnEQ(SvPVX(sv), "ig", 2))
1100 null(o); /* don't execute or even remember it */
1104 o->op_type = OP_PREINC; /* pre-increment is faster */
1105 o->op_ppaddr = PL_ppaddr[OP_PREINC];
1109 o->op_type = OP_PREDEC; /* pre-decrement is faster */
1110 o->op_ppaddr = PL_ppaddr[OP_PREDEC];
1116 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1121 if (o->op_flags & OPf_STACKED)
1129 if (!(o->op_flags & OPf_KIDS))
1138 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1145 /* all requires must return a boolean value */
1146 o->op_flags &= ~OPf_WANT;
1149 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
1150 if (!kPMOP->op_pmreplroot)
1151 deprecate("implicit split to @_");
1157 if (ckWARN(WARN_VOID))
1158 Perl_warner(aTHX_ WARN_VOID, "Useless use of %s in void context", useless);
1164 Perl_listkids(pTHX_ OP *o)
1167 if (o && o->op_flags & OPf_KIDS) {
1168 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1175 Perl_list(pTHX_ OP *o)
1179 /* assumes no premature commitment */
1180 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
1181 || o->op_type == OP_RETURN)
1186 if ((o->op_private & OPpTARGET_MY)
1187 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
1189 return o; /* As if inside SASSIGN */
1192 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_LIST;
1194 switch (o->op_type) {
1197 list(cBINOPo->op_first);
1202 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1210 if (!(o->op_flags & OPf_KIDS))
1212 if (!o->op_next && cUNOPo->op_first->op_type == OP_FLOP) {
1213 list(cBINOPo->op_first);
1214 return gen_constant_list(o);
1221 kid = cLISTOPo->op_first;
1223 while (kid = kid->op_sibling) {
1224 if (kid->op_sibling)
1229 WITH_THR(PL_curcop = &PL_compiling);
1233 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
1234 if (kid->op_sibling)
1239 WITH_THR(PL_curcop = &PL_compiling);
1242 /* all requires must return a boolean value */
1243 o->op_flags &= ~OPf_WANT;
1250 Perl_scalarseq(pTHX_ OP *o)
1255 if (o->op_type == OP_LINESEQ ||
1256 o->op_type == OP_SCOPE ||
1257 o->op_type == OP_LEAVE ||
1258 o->op_type == OP_LEAVETRY)
1261 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
1262 if (kid->op_sibling) {
1266 PL_curcop = &PL_compiling;
1268 o->op_flags &= ~OPf_PARENS;
1269 if (PL_hints & HINT_BLOCK_SCOPE)
1270 o->op_flags |= OPf_PARENS;
1273 o = newOP(OP_STUB, 0);
1278 S_modkids(pTHX_ OP *o, I32 type)
1281 if (o && o->op_flags & OPf_KIDS) {
1282 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1289 Perl_mod(pTHX_ OP *o, I32 type)
1296 if (!o || PL_error_count)
1299 if ((o->op_private & OPpTARGET_MY)
1300 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
1305 switch (o->op_type) {
1310 if (!(o->op_private & (OPpCONST_ARYBASE)))
1312 if (PL_eval_start && PL_eval_start->op_type == OP_CONST) {
1313 PL_compiling.cop_arybase = (I32)SvIV(cSVOPx(PL_eval_start)->op_sv);
1317 SAVEI32(PL_compiling.cop_arybase);
1318 PL_compiling.cop_arybase = 0;
1320 else if (type == OP_REFGEN)
1323 Perl_croak(aTHX_ "That use of $[ is unsupported");
1326 if (o->op_flags & OPf_PARENS)
1330 if ((type == OP_UNDEF || type == OP_REFGEN) &&
1331 !(o->op_flags & OPf_STACKED)) {
1332 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1333 o->op_ppaddr = PL_ppaddr[OP_RV2CV];
1334 assert(cUNOPo->op_first->op_type == OP_NULL);
1335 null(((LISTOP*)cUNOPo->op_first)->op_first);/* disable pushmark */
1338 else { /* lvalue subroutine call */
1339 o->op_private |= OPpLVAL_INTRO;
1340 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN) {
1341 /* Backward compatibility mode: */
1342 o->op_private |= OPpENTERSUB_INARGS;
1345 else { /* Compile-time error message: */
1346 OP *kid = cUNOPo->op_first;
1350 if (kid->op_type == OP_PUSHMARK)
1352 if (kid->op_type != OP_NULL || kid->op_targ != OP_LIST)
1354 "panic: unexpected lvalue entersub "
1355 "args: type/targ %ld:%ld",
1356 (long)kid->op_type,kid->op_targ);
1357 kid = kLISTOP->op_first;
1359 while (kid->op_sibling)
1360 kid = kid->op_sibling;
1361 if (!(kid->op_type == OP_NULL && kid->op_targ == OP_RV2CV)) {
1363 if (kid->op_type == OP_METHOD_NAMED
1364 || kid->op_type == OP_METHOD)
1368 if (kid->op_sibling || kid->op_next != kid) {
1369 yyerror("panic: unexpected optree near method call");
1373 NewOp(1101, newop, 1, OP);
1374 newop->op_type = OP_RV2CV;
1375 newop->op_ppaddr = PL_ppaddr[OP_RV2CV];
1376 newop->op_next = newop;
1377 kid->op_sibling = newop;
1378 newop->op_private |= OPpLVAL_INTRO;
1382 if (kid->op_type != OP_RV2CV)
1384 "panic: unexpected lvalue entersub "
1385 "entry via type/targ %ld:%ld",
1386 (long)kid->op_type,kid->op_targ);
1387 kid->op_private |= OPpLVAL_INTRO;
1388 break; /* Postpone until runtime */
1392 kid = kUNOP->op_first;
1393 if (kid->op_type == OP_NULL && kid->op_targ == OP_RV2SV)
1394 kid = kUNOP->op_first;
1395 if (kid->op_type == OP_NULL)
1397 "Unexpected constant lvalue entersub "
1398 "entry via type/targ %ld:%ld",
1399 (long)kid->op_type,kid->op_targ);
1400 if (kid->op_type != OP_GV) {
1401 /* Restore RV2CV to check lvalueness */
1403 if (kid->op_next && kid->op_next != kid) { /* Happens? */
1404 okid->op_next = kid->op_next;
1405 kid->op_next = okid;
1408 okid->op_next = Nullop;
1409 okid->op_type = OP_RV2CV;
1411 okid->op_ppaddr = PL_ppaddr[OP_RV2CV];
1412 okid->op_private |= OPpLVAL_INTRO;
1416 cv = GvCV(kGVOP_gv);
1426 /* grep, foreach, subcalls, refgen */
1427 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
1429 yyerror(Perl_form(aTHX_ "Can't modify %s in %s",
1430 (o->op_type == OP_NULL && (o->op_flags & OPf_SPECIAL)
1432 : (o->op_type == OP_ENTERSUB
1433 ? "non-lvalue subroutine call"
1434 : PL_op_desc[o->op_type])),
1435 type ? PL_op_desc[type] : "local"));
1449 case OP_RIGHT_SHIFT:
1458 if (!(o->op_flags & OPf_STACKED))
1464 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1470 if (!type && cUNOPo->op_first->op_type != OP_GV)
1471 Perl_croak(aTHX_ "Can't localize through a reference");
1472 if (type == OP_REFGEN && o->op_flags & OPf_PARENS) {
1473 PL_modcount = 10000;
1474 return o; /* Treat \(@foo) like ordinary list. */
1478 if (scalar_mod_type(o, type))
1480 ref(cUNOPo->op_first, o->op_type);
1489 PL_modcount = 10000;
1492 if (!type && cUNOPo->op_first->op_type != OP_GV)
1493 Perl_croak(aTHX_ "Can't localize through a reference");
1494 ref(cUNOPo->op_first, o->op_type);
1498 PL_hints |= HINT_BLOCK_SCOPE;
1508 PL_modcount = 10000;
1509 if (type == OP_REFGEN && o->op_flags & OPf_PARENS)
1510 return o; /* Treat \(@foo) like ordinary list. */
1511 if (scalar_mod_type(o, type))
1517 Perl_croak(aTHX_ "Can't localize lexical variable %s",
1518 SvPV(*av_fetch(PL_comppad_name, o->op_targ, 4), n_a));
1523 PL_modcount++; /* XXX ??? */
1525 #endif /* USE_THREADS */
1531 if (type != OP_SASSIGN)
1535 if (o->op_private == 4) /* don't allow 4 arg substr as lvalue */
1541 pad_free(o->op_targ);
1542 o->op_targ = pad_alloc(o->op_type, SVs_PADMY);
1543 assert(SvTYPE(PAD_SV(o->op_targ)) == SVt_NULL);
1544 if (o->op_flags & OPf_KIDS)
1545 mod(cBINOPo->op_first->op_sibling, type);
1550 ref(cBINOPo->op_first, o->op_type);
1551 if (type == OP_ENTERSUB &&
1552 !(o->op_private & (OPpLVAL_INTRO | OPpDEREF)))
1553 o->op_private |= OPpLVAL_DEFER;
1560 if (o->op_flags & OPf_KIDS)
1561 mod(cLISTOPo->op_last, type);
1565 if (o->op_flags & OPf_SPECIAL) /* do BLOCK */
1567 else if (!(o->op_flags & OPf_KIDS))
1569 if (o->op_targ != OP_LIST) {
1570 mod(cBINOPo->op_first, type);
1575 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1579 o->op_flags |= OPf_MOD;
1581 if (type == OP_AASSIGN || type == OP_SASSIGN)
1582 o->op_flags |= OPf_SPECIAL|OPf_REF;
1584 o->op_private |= OPpLVAL_INTRO;
1585 o->op_flags &= ~OPf_SPECIAL;
1586 PL_hints |= HINT_BLOCK_SCOPE;
1588 else if (type != OP_GREPSTART && type != OP_ENTERSUB)
1589 o->op_flags |= OPf_REF;
1594 S_scalar_mod_type(pTHX_ OP *o, I32 type)
1598 if (o->op_type == OP_RV2GV)
1622 case OP_RIGHT_SHIFT:
1641 S_is_handle_constructor(pTHX_ OP *o, I32 argnum)
1643 switch (o->op_type) {
1651 case OP_SELECT: /* XXX c.f. SelectSaver.pm */
1664 Perl_refkids(pTHX_ OP *o, I32 type)
1667 if (o && o->op_flags & OPf_KIDS) {
1668 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1675 Perl_ref(pTHX_ OP *o, I32 type)
1679 if (!o || PL_error_count)
1682 switch (o->op_type) {
1684 if ((type == OP_DEFINED || type == OP_LOCK) &&
1685 !(o->op_flags & OPf_STACKED)) {
1686 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1687 o->op_ppaddr = PL_ppaddr[OP_RV2CV];
1688 assert(cUNOPo->op_first->op_type == OP_NULL);
1689 null(((LISTOP*)cUNOPo->op_first)->op_first); /* disable pushmark */
1690 o->op_flags |= OPf_SPECIAL;
1695 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1699 if (type == OP_DEFINED)
1700 o->op_flags |= OPf_SPECIAL; /* don't create GV */
1701 ref(cUNOPo->op_first, o->op_type);
1704 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1705 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1706 : type == OP_RV2HV ? OPpDEREF_HV
1708 o->op_flags |= OPf_MOD;
1713 o->op_flags |= OPf_MOD; /* XXX ??? */
1718 o->op_flags |= OPf_REF;
1721 if (type == OP_DEFINED)
1722 o->op_flags |= OPf_SPECIAL; /* don't create GV */
1723 ref(cUNOPo->op_first, o->op_type);
1728 o->op_flags |= OPf_REF;
1733 if (!(o->op_flags & OPf_KIDS))
1735 ref(cBINOPo->op_first, type);
1739 ref(cBINOPo->op_first, o->op_type);
1740 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1741 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1742 : type == OP_RV2HV ? OPpDEREF_HV
1744 o->op_flags |= OPf_MOD;
1752 if (!(o->op_flags & OPf_KIDS))
1754 ref(cLISTOPo->op_last, type);
1764 S_dup_attrlist(pTHX_ OP *o)
1768 /* An attrlist is either a simple OP_CONST or an OP_LIST with kids,
1769 * where the first kid is OP_PUSHMARK and the remaining ones
1770 * are OP_CONST. We need to push the OP_CONST values.
1772 if (o->op_type == OP_CONST)
1773 rop = newSVOP(OP_CONST, o->op_flags, SvREFCNT_inc(cSVOPo->op_sv));
1775 assert((o->op_type == OP_LIST) && (o->op_flags & OPf_KIDS));
1776 for (o = cLISTOPo->op_first; o; o=o->op_sibling) {
1777 if (o->op_type == OP_CONST)
1778 rop = append_elem(OP_LIST, rop,
1779 newSVOP(OP_CONST, o->op_flags,
1780 SvREFCNT_inc(cSVOPo->op_sv)));
1787 S_apply_attrs(pTHX_ HV *stash, SV *target, OP *attrs)
1789 OP *modname; /* for 'use' */
1792 /* fake up C<use attributes $pkg,$rv,@attrs> */
1793 ENTER; /* need to protect against side-effects of 'use' */
1795 if (stash && HvNAME(stash))
1796 stashsv = newSVpv(HvNAME(stash), 0);
1798 stashsv = &PL_sv_no;
1799 #define ATTRSMODULE "attributes"
1800 modname = newSVOP(OP_CONST, 0,
1801 newSVpvn(ATTRSMODULE, sizeof(ATTRSMODULE)-1));
1802 modname->op_private |= OPpCONST_BARE;
1803 /* that flag is required to make 'use' work right */
1804 utilize(1, start_subparse(FALSE, 0),
1805 Nullop, /* version */
1807 prepend_elem(OP_LIST,
1808 newSVOP(OP_CONST, 0, stashsv),
1809 prepend_elem(OP_LIST,
1810 newSVOP(OP_CONST, 0, newRV(target)),
1811 dup_attrlist(attrs))));
1816 S_my_kid(pTHX_ OP *o, OP *attrs)
1821 if (!o || PL_error_count)
1825 if (type == OP_LIST) {
1826 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1828 } else if (type == OP_UNDEF) {
1830 } else if (type == OP_RV2SV || /* "our" declaration */
1832 type == OP_RV2HV) { /* XXX does this let anything illegal in? */
1834 } else if (type != OP_PADSV &&
1837 type != OP_PUSHMARK)
1839 yyerror(Perl_form(aTHX_ "Can't declare %s in my", PL_op_desc[o->op_type]));
1842 else if (attrs && type != OP_PUSHMARK) {
1847 /* check for C<my Dog $spot> when deciding package */
1848 namesvp = av_fetch(PL_comppad_name, o->op_targ, FALSE);
1849 if (namesvp && *namesvp && SvOBJECT(*namesvp) && HvNAME(SvSTASH(*namesvp)))
1850 stash = SvSTASH(*namesvp);
1852 stash = PL_curstash;
1853 padsv = PAD_SV(o->op_targ);
1854 apply_attrs(stash, padsv, attrs);
1856 o->op_flags |= OPf_MOD;
1857 o->op_private |= OPpLVAL_INTRO;
1862 Perl_my_attrs(pTHX_ OP *o, OP *attrs)
1864 if (o->op_flags & OPf_PARENS)
1867 PL_in_my_stash = Nullhv;
1870 return my_kid(o, attrs);
1874 Perl_my(pTHX_ OP *o)
1876 return my_kid(o, Nullop);
1880 Perl_sawparens(pTHX_ OP *o)
1883 o->op_flags |= OPf_PARENS;
1888 Perl_bind_match(pTHX_ I32 type, OP *left, OP *right)
1893 if (ckWARN(WARN_UNSAFE) &&
1894 (left->op_type == OP_RV2AV ||
1895 left->op_type == OP_RV2HV ||
1896 left->op_type == OP_PADAV ||
1897 left->op_type == OP_PADHV)) {
1898 char *desc = PL_op_desc[(right->op_type == OP_SUBST ||
1899 right->op_type == OP_TRANS)
1900 ? right->op_type : OP_MATCH];
1901 const char *sample = ((left->op_type == OP_RV2AV ||
1902 left->op_type == OP_PADAV)
1903 ? "@array" : "%hash");
1904 Perl_warner(aTHX_ WARN_UNSAFE,
1905 "Applying %s to %s will act on scalar(%s)",
1906 desc, sample, sample);
1909 if (right->op_type == OP_MATCH ||
1910 right->op_type == OP_SUBST ||
1911 right->op_type == OP_TRANS) {
1912 right->op_flags |= OPf_STACKED;
1913 if (right->op_type != OP_MATCH)
1914 left = mod(left, right->op_type);
1915 if (right->op_type == OP_TRANS)
1916 o = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
1918 o = prepend_elem(right->op_type, scalar(left), right);
1920 return newUNOP(OP_NOT, 0, scalar(o));
1924 return bind_match(type, left,
1925 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
1929 Perl_invert(pTHX_ OP *o)
1933 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
1934 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(o));
1938 Perl_scope(pTHX_ OP *o)
1941 if (o->op_flags & OPf_PARENS || PERLDB_NOOPT || PL_tainting) {
1942 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
1943 o->op_type = OP_LEAVE;
1944 o->op_ppaddr = PL_ppaddr[OP_LEAVE];
1947 if (o->op_type == OP_LINESEQ) {
1949 o->op_type = OP_SCOPE;
1950 o->op_ppaddr = PL_ppaddr[OP_SCOPE];
1951 kid = ((LISTOP*)o)->op_first;
1952 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE)
1956 o = newLISTOP(OP_SCOPE, 0, o, Nullop);
1963 Perl_save_hints(pTHX)
1966 SAVESPTR(GvHV(PL_hintgv));
1967 GvHV(PL_hintgv) = newHVhv(GvHV(PL_hintgv));
1968 SAVEFREESV(GvHV(PL_hintgv));
1972 Perl_block_start(pTHX_ int full)
1975 int retval = PL_savestack_ix;
1977 SAVEI32(PL_comppad_name_floor);
1979 if ((PL_comppad_name_fill = AvFILLp(PL_comppad_name)) > 0)
1980 PL_comppad_name_floor = PL_comppad_name_fill;
1982 PL_comppad_name_floor = 0;
1984 SAVEI32(PL_min_intro_pending);
1985 SAVEI32(PL_max_intro_pending);
1986 PL_min_intro_pending = 0;
1987 SAVEI32(PL_comppad_name_fill);
1988 SAVEI32(PL_padix_floor);
1989 PL_padix_floor = PL_padix;
1990 PL_pad_reset_pending = FALSE;
1992 PL_hints &= ~HINT_BLOCK_SCOPE;
1993 SAVESPTR(PL_compiling.cop_warnings);
1994 if (! specialWARN(PL_compiling.cop_warnings)) {
1995 PL_compiling.cop_warnings = newSVsv(PL_compiling.cop_warnings) ;
1996 SAVEFREESV(PL_compiling.cop_warnings) ;
2004 Perl_block_end(pTHX_ I32 floor, OP *seq)
2007 int needblockscope = PL_hints & HINT_BLOCK_SCOPE;
2008 OP* retval = scalarseq(seq);
2010 PL_pad_reset_pending = FALSE;
2011 PL_compiling.op_private = PL_hints;
2013 PL_hints |= HINT_BLOCK_SCOPE; /* propagate out */
2014 pad_leavemy(PL_comppad_name_fill);
2023 OP *o = newOP(OP_THREADSV, 0);
2024 o->op_targ = find_threadsv("_");
2027 return newSVREF(newGVOP(OP_GV, 0, PL_defgv));
2028 #endif /* USE_THREADS */
2032 Perl_newPROG(pTHX_ OP *o)
2038 PL_eval_root = newUNOP(OP_LEAVEEVAL,
2039 ((PL_in_eval & EVAL_KEEPERR)
2040 ? OPf_SPECIAL : 0), o);
2041 PL_eval_start = linklist(PL_eval_root);
2042 PL_eval_root->op_private |= OPpREFCOUNTED;
2043 OpREFCNT_set(PL_eval_root, 1);
2044 PL_eval_root->op_next = 0;
2045 peep(PL_eval_start);
2050 PL_main_root = scope(sawparens(scalarvoid(o)));
2051 PL_curcop = &PL_compiling;
2052 PL_main_start = LINKLIST(PL_main_root);
2053 PL_main_root->op_private |= OPpREFCOUNTED;
2054 OpREFCNT_set(PL_main_root, 1);
2055 PL_main_root->op_next = 0;
2056 peep(PL_main_start);
2059 /* Register with debugger */
2061 CV *cv = get_cv("DB::postponed", FALSE);
2065 XPUSHs((SV*)CopFILEGV(&PL_compiling));
2067 call_sv((SV*)cv, G_DISCARD);
2074 Perl_localize(pTHX_ OP *o, I32 lex)
2076 if (o->op_flags & OPf_PARENS)
2080 if (ckWARN(WARN_PARENTHESIS) && PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == ',') {
2082 for (s = PL_bufptr; *s && (isALNUM(*s) || (*s & 0x80) || strchr("@$%, ",*s)); s++) ;
2083 if (*s == ';' || *s == '=')
2084 Perl_warner(aTHX_ WARN_PARENTHESIS, "Parentheses missing around \"%s\" list",
2085 lex ? "my" : "local");
2089 PL_in_my_stash = Nullhv;
2093 return mod(o, OP_NULL); /* a bit kludgey */
2097 Perl_jmaybe(pTHX_ OP *o)
2099 if (o->op_type == OP_LIST) {
2102 o2 = newOP(OP_THREADSV, 0);
2103 o2->op_targ = find_threadsv(";");
2105 o2 = newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
2106 #endif /* USE_THREADS */
2107 o = convert(OP_JOIN, 0, prepend_elem(OP_LIST, o2, o));
2113 Perl_fold_constants(pTHX_ register OP *o)
2117 I32 type = o->op_type;
2120 if (PL_opargs[type] & OA_RETSCALAR)
2122 if (PL_opargs[type] & OA_TARGET && !o->op_targ)
2123 o->op_targ = pad_alloc(type, SVs_PADTMP);
2125 /* integerize op, unless it happens to be C<-foo>.
2126 * XXX should pp_i_negate() do magic string negation instead? */
2127 if ((PL_opargs[type] & OA_OTHERINT) && (PL_hints & HINT_INTEGER)
2128 && !(type == OP_NEGATE && cUNOPo->op_first->op_type == OP_CONST
2129 && (cUNOPo->op_first->op_private & OPpCONST_BARE)))
2131 o->op_ppaddr = PL_ppaddr[type = ++(o->op_type)];
2134 if (!(PL_opargs[type] & OA_FOLDCONST))
2139 /* XXX might want a ck_negate() for this */
2140 cUNOPo->op_first->op_private &= ~OPpCONST_STRICT;
2153 if (o->op_private & OPpLOCALE)
2158 goto nope; /* Don't try to run w/ errors */
2160 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
2161 if ((curop->op_type != OP_CONST ||
2162 (curop->op_private & OPpCONST_BARE)) &&
2163 curop->op_type != OP_LIST &&
2164 curop->op_type != OP_SCALAR &&
2165 curop->op_type != OP_NULL &&
2166 curop->op_type != OP_PUSHMARK)
2172 curop = LINKLIST(o);
2176 sv = *(PL_stack_sp--);
2177 if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
2178 pad_swipe(o->op_targ);
2179 else if (SvTEMP(sv)) { /* grab mortal temp? */
2180 (void)SvREFCNT_inc(sv);
2184 if (type == OP_RV2GV)
2185 return newGVOP(OP_GV, 0, (GV*)sv);
2187 /* try to smush double to int, but don't smush -2.0 to -2 */
2188 if ((SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK)) == SVf_NOK &&
2192 if ((NV)iv == SvNV(sv)) {
2197 SvIOK_off(sv); /* undo SvIV() damage */
2199 return newSVOP(OP_CONST, 0, sv);
2203 if (!(PL_opargs[type] & OA_OTHERINT))
2206 if (!(PL_hints & HINT_INTEGER)) {
2207 if (type == OP_MODULO
2208 || type == OP_DIVIDE
2209 || !(o->op_flags & OPf_KIDS))
2214 for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
2215 if (curop->op_type == OP_CONST) {
2216 if (SvIOK(((SVOP*)curop)->op_sv))
2220 if (PL_opargs[curop->op_type] & OA_RETINTEGER)
2224 o->op_ppaddr = PL_ppaddr[++(o->op_type)];
2231 Perl_gen_constant_list(pTHX_ register OP *o)
2235 I32 oldtmps_floor = PL_tmps_floor;
2239 return o; /* Don't attempt to run with errors */
2241 PL_op = curop = LINKLIST(o);
2248 PL_tmps_floor = oldtmps_floor;
2250 o->op_type = OP_RV2AV;
2251 o->op_ppaddr = PL_ppaddr[OP_RV2AV];
2252 curop = ((UNOP*)o)->op_first;
2253 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*PL_stack_sp--));
2260 Perl_convert(pTHX_ I32 type, I32 flags, OP *o)
2265 if (!o || o->op_type != OP_LIST)
2266 o = newLISTOP(OP_LIST, 0, o, Nullop);
2268 o->op_flags &= ~OPf_WANT;
2270 if (!(PL_opargs[type] & OA_MARK))
2271 null(cLISTOPo->op_first);
2274 o->op_ppaddr = PL_ppaddr[type];
2275 o->op_flags |= flags;
2277 o = CHECKOP(type, o);
2278 if (o->op_type != type)
2281 if (cLISTOPo->op_children < 7) {
2282 /* XXX do we really need to do this if we're done appending?? */
2283 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
2285 cLISTOPo->op_last = last; /* in case check substituted last arg */
2288 return fold_constants(o);
2291 /* List constructors */
2294 Perl_append_elem(pTHX_ I32 type, OP *first, OP *last)
2302 if (first->op_type != type || type==OP_LIST && first->op_flags & OPf_PARENS)
2303 return newLISTOP(type, 0, first, last);
2305 if (first->op_flags & OPf_KIDS)
2306 ((LISTOP*)first)->op_last->op_sibling = last;
2308 first->op_flags |= OPf_KIDS;
2309 ((LISTOP*)first)->op_first = last;
2311 ((LISTOP*)first)->op_last = last;
2312 ((LISTOP*)first)->op_children++;
2317 Perl_append_list(pTHX_ I32 type, LISTOP *first, LISTOP *last)
2325 if (first->op_type != type)
2326 return prepend_elem(type, (OP*)first, (OP*)last);
2328 if (last->op_type != type)
2329 return append_elem(type, (OP*)first, (OP*)last);
2331 first->op_last->op_sibling = last->op_first;
2332 first->op_last = last->op_last;
2333 first->op_children += last->op_children;
2334 if (first->op_children)
2335 first->op_flags |= OPf_KIDS;
2337 #ifdef PL_OP_SLAB_ALLOC
2345 Perl_prepend_elem(pTHX_ I32 type, OP *first, OP *last)
2353 if (last->op_type == type) {
2354 if (type == OP_LIST) { /* already a PUSHMARK there */
2355 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
2356 ((LISTOP*)last)->op_first->op_sibling = first;
2359 if (!(last->op_flags & OPf_KIDS)) {
2360 ((LISTOP*)last)->op_last = first;
2361 last->op_flags |= OPf_KIDS;
2363 first->op_sibling = ((LISTOP*)last)->op_first;
2364 ((LISTOP*)last)->op_first = first;
2366 ((LISTOP*)last)->op_children++;
2370 return newLISTOP(type, 0, first, last);
2376 Perl_newNULLLIST(pTHX)
2378 return newOP(OP_STUB, 0);
2382 Perl_force_list(pTHX_ OP *o)
2384 if (!o || o->op_type != OP_LIST)
2385 o = newLISTOP(OP_LIST, 0, o, Nullop);
2391 Perl_newLISTOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
2395 NewOp(1101, listop, 1, LISTOP);
2397 listop->op_type = type;
2398 listop->op_ppaddr = PL_ppaddr[type];
2399 listop->op_children = (first != 0) + (last != 0);
2400 listop->op_flags = flags;
2404 else if (!first && last)
2407 first->op_sibling = last;
2408 listop->op_first = first;
2409 listop->op_last = last;
2410 if (type == OP_LIST) {
2412 pushop = newOP(OP_PUSHMARK, 0);
2413 pushop->op_sibling = first;
2414 listop->op_first = pushop;
2415 listop->op_flags |= OPf_KIDS;
2417 listop->op_last = pushop;
2419 else if (listop->op_children)
2420 listop->op_flags |= OPf_KIDS;
2426 Perl_newOP(pTHX_ I32 type, I32 flags)
2429 NewOp(1101, o, 1, OP);
2431 o->op_ppaddr = PL_ppaddr[type];
2432 o->op_flags = flags;
2435 o->op_private = 0 + (flags >> 8);
2436 if (PL_opargs[type] & OA_RETSCALAR)
2438 if (PL_opargs[type] & OA_TARGET)
2439 o->op_targ = pad_alloc(type, SVs_PADTMP);
2440 return CHECKOP(type, o);
2444 Perl_newUNOP(pTHX_ I32 type, I32 flags, OP *first)
2449 first = newOP(OP_STUB, 0);
2450 if (PL_opargs[type] & OA_MARK)
2451 first = force_list(first);
2453 NewOp(1101, unop, 1, UNOP);
2454 unop->op_type = type;
2455 unop->op_ppaddr = PL_ppaddr[type];
2456 unop->op_first = first;
2457 unop->op_flags = flags | OPf_KIDS;
2458 unop->op_private = 1 | (flags >> 8);
2459 unop = (UNOP*) CHECKOP(type, unop);
2463 return fold_constants((OP *) unop);
2467 Perl_newBINOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
2470 NewOp(1101, binop, 1, BINOP);
2473 first = newOP(OP_NULL, 0);
2475 binop->op_type = type;
2476 binop->op_ppaddr = PL_ppaddr[type];
2477 binop->op_first = first;
2478 binop->op_flags = flags | OPf_KIDS;
2481 binop->op_private = 1 | (flags >> 8);
2484 binop->op_private = 2 | (flags >> 8);
2485 first->op_sibling = last;
2488 binop = (BINOP*)CHECKOP(type, binop);
2489 if (binop->op_next || binop->op_type != type)
2492 binop->op_last = binop->op_first->op_sibling;
2494 return fold_constants((OP *)binop);
2498 utf8compare(const void *a, const void *b)
2501 for (i = 0; i < 10; i++) {
2502 if ((*(U8**)a)[i] < (*(U8**)b)[i])
2504 if ((*(U8**)a)[i] > (*(U8**)b)[i])
2511 Perl_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
2513 SV *tstr = ((SVOP*)expr)->op_sv;
2514 SV *rstr = ((SVOP*)repl)->op_sv;
2517 register U8 *t = (U8*)SvPV(tstr, tlen);
2518 register U8 *r = (U8*)SvPV(rstr, rlen);
2524 register short *tbl;
2526 complement = o->op_private & OPpTRANS_COMPLEMENT;
2527 del = o->op_private & OPpTRANS_DELETE;
2528 squash = o->op_private & OPpTRANS_SQUASH;
2530 if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
2531 SV* listsv = newSVpvn("# comment\n",10);
2533 U8* tend = t + tlen;
2534 U8* rend = r + rlen;
2550 I32 from_utf = o->op_private & OPpTRANS_FROM_UTF;
2551 I32 to_utf = o->op_private & OPpTRANS_TO_UTF;
2557 New(1109, cp, tlen, U8*);
2559 transv = newSVpvn("",0);
2568 qsort(cp, i, sizeof(U8*), utf8compare);
2569 for (j = 0; j < i; j++) {
2571 UV val = utf8_to_uv(s, &ulen);
2573 diff = val - nextmin;
2575 t = uv_to_utf8(tmpbuf,nextmin);
2576 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2578 t = uv_to_utf8(tmpbuf, val - 1);
2579 sv_catpvn(transv, "\377", 1);
2580 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2584 val = utf8_to_uv(s+1, &ulen);
2588 t = uv_to_utf8(tmpbuf,nextmin);
2589 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2590 t = uv_to_utf8(tmpbuf, 0x7fffffff);
2591 sv_catpvn(transv, "\377", 1);
2592 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2593 t = (U8*)SvPVX(transv);
2594 tlen = SvCUR(transv);
2597 else if (!rlen && !del) {
2598 r = t; rlen = tlen; rend = tend;
2601 if (to_utf && from_utf) { /* only counting characters */
2602 if (t == r || (tlen == rlen && memEQ(t, r, tlen)))
2603 o->op_private |= OPpTRANS_IDENTICAL;
2605 else { /* straight latin-1 translation */
2606 if (tlen == 4 && memEQ(t, "\0\377\303\277", 4) &&
2607 rlen == 4 && memEQ(r, "\0\377\303\277", 4))
2608 o->op_private |= OPpTRANS_IDENTICAL;
2612 while (t < tend || tfirst <= tlast) {
2613 /* see if we need more "t" chars */
2614 if (tfirst > tlast) {
2615 tfirst = (I32)utf8_to_uv(t, &ulen);
2617 if (t < tend && *t == 0xff) { /* illegal utf8 val indicates range */
2618 tlast = (I32)utf8_to_uv(++t, &ulen);
2625 /* now see if we need more "r" chars */
2626 if (rfirst > rlast) {
2628 rfirst = (I32)utf8_to_uv(r, &ulen);
2630 if (r < rend && *r == 0xff) { /* illegal utf8 val indicates range */
2631 rlast = (I32)utf8_to_uv(++r, &ulen);
2640 rfirst = rlast = 0xffffffff;
2644 /* now see which range will peter our first, if either. */
2645 tdiff = tlast - tfirst;
2646 rdiff = rlast - rfirst;
2653 if (rfirst == 0xffffffff) {
2654 diff = tdiff; /* oops, pretend rdiff is infinite */
2656 Perl_sv_catpvf(aTHX_ listsv, "%04x\t%04x\tXXXX\n", tfirst, tlast);
2658 Perl_sv_catpvf(aTHX_ listsv, "%04x\t\tXXXX\n", tfirst);
2662 Perl_sv_catpvf(aTHX_ listsv, "%04x\t%04x\t%04x\n", tfirst, tfirst + diff, rfirst);
2664 Perl_sv_catpvf(aTHX_ listsv, "%04x\t\t%04x\n", tfirst, rfirst);
2666 if (rfirst + diff > max)
2667 max = rfirst + diff;
2672 else if (rfirst <= 0x800)
2673 grows |= (tfirst < 0x80);
2674 else if (rfirst <= 0x10000)
2675 grows |= (tfirst < 0x800);
2676 else if (rfirst <= 0x200000)
2677 grows |= (tfirst < 0x10000);
2678 else if (rfirst <= 0x4000000)
2679 grows |= (tfirst < 0x200000);
2680 else if (rfirst <= 0x80000000)
2681 grows |= (tfirst < 0x4000000);
2693 else if (max > 0xff)
2698 cSVOPo->op_sv = (SV*)swash_init("utf8", "", listsv, bits, none);
2699 SvREFCNT_dec(listsv);
2701 SvREFCNT_dec(transv);
2703 if (!del && havefinal)
2704 (void)hv_store((HV*)SvRV((cSVOPo->op_sv)), "FINAL", 5, newSViv((IV)final), 0);
2706 if (grows && to_utf)
2707 o->op_private |= OPpTRANS_GROWS;
2714 tbl = (short*)cPVOPo->op_pv;
2716 Zero(tbl, 256, short);
2717 for (i = 0; i < tlen; i++)
2719 for (i = 0, j = 0; i < 256; i++) {
2735 if (!rlen && !del) {
2738 o->op_private |= OPpTRANS_IDENTICAL;
2740 for (i = 0; i < 256; i++)
2742 for (i = 0, j = 0; i < tlen; i++,j++) {
2745 if (tbl[t[i]] == -1)
2751 if (tbl[t[i]] == -1)
2762 Perl_newPMOP(pTHX_ I32 type, I32 flags)
2767 NewOp(1101, pmop, 1, PMOP);
2768 pmop->op_type = type;
2769 pmop->op_ppaddr = PL_ppaddr[type];
2770 pmop->op_flags = flags;
2771 pmop->op_private = 0 | (flags >> 8);
2773 if (PL_hints & HINT_RE_TAINT)
2774 pmop->op_pmpermflags |= PMf_RETAINT;
2775 if (PL_hints & HINT_LOCALE)
2776 pmop->op_pmpermflags |= PMf_LOCALE;
2777 pmop->op_pmflags = pmop->op_pmpermflags;
2779 /* link into pm list */
2780 if (type != OP_TRANS && PL_curstash) {
2781 pmop->op_pmnext = HvPMROOT(PL_curstash);
2782 HvPMROOT(PL_curstash) = pmop;
2789 Perl_pmruntime(pTHX_ OP *o, OP *expr, OP *repl)
2794 I32 repl_has_vars = 0;
2796 if (o->op_type == OP_TRANS)
2797 return pmtrans(o, expr, repl);
2799 PL_hints |= HINT_BLOCK_SCOPE;
2802 if (expr->op_type == OP_CONST) {
2804 SV *pat = ((SVOP*)expr)->op_sv;
2805 char *p = SvPV(pat, plen);
2806 if ((o->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
2807 sv_setpvn(pat, "\\s+", 3);
2808 p = SvPV(pat, plen);
2809 pm->op_pmflags |= PMf_SKIPWHITE;
2811 pm->op_pmregexp = CALLREGCOMP(aTHX_ p, p + plen, pm);
2812 if (strEQ("\\s+", pm->op_pmregexp->precomp))
2813 pm->op_pmflags |= PMf_WHITE;
2817 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL))
2818 expr = newUNOP((!(PL_hints & HINT_RE_EVAL)
2820 : OP_REGCMAYBE),0,expr);
2822 NewOp(1101, rcop, 1, LOGOP);
2823 rcop->op_type = OP_REGCOMP;
2824 rcop->op_ppaddr = PL_ppaddr[OP_REGCOMP];
2825 rcop->op_first = scalar(expr);
2826 rcop->op_flags |= ((PL_hints & HINT_RE_EVAL)
2827 ? (OPf_SPECIAL | OPf_KIDS)
2829 rcop->op_private = 1;
2832 /* establish postfix order */
2833 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL)) {
2835 rcop->op_next = expr;
2836 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
2839 rcop->op_next = LINKLIST(expr);
2840 expr->op_next = (OP*)rcop;
2843 prepend_elem(o->op_type, scalar((OP*)rcop), o);
2848 if (pm->op_pmflags & PMf_EVAL) {
2850 if (CopLINE(PL_curcop) < PL_multi_end)
2851 CopLINE_set(PL_curcop, PL_multi_end);
2854 else if (repl->op_type == OP_THREADSV
2855 && strchr("&`'123456789+",
2856 PL_threadsv_names[repl->op_targ]))
2860 #endif /* USE_THREADS */
2861 else if (repl->op_type == OP_CONST)
2865 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
2866 if (PL_opargs[curop->op_type] & OA_DANGEROUS) {
2868 if (curop->op_type == OP_THREADSV) {
2870 if (strchr("&`'123456789+", curop->op_private))
2874 if (curop->op_type == OP_GV) {
2875 GV *gv = cGVOPx_gv(curop);
2877 if (strchr("&`'123456789+", *GvENAME(gv)))
2880 #endif /* USE_THREADS */
2881 else if (curop->op_type == OP_RV2CV)
2883 else if (curop->op_type == OP_RV2SV ||
2884 curop->op_type == OP_RV2AV ||
2885 curop->op_type == OP_RV2HV ||
2886 curop->op_type == OP_RV2GV) {
2887 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
2890 else if (curop->op_type == OP_PADSV ||
2891 curop->op_type == OP_PADAV ||
2892 curop->op_type == OP_PADHV ||
2893 curop->op_type == OP_PADANY) {
2896 else if (curop->op_type == OP_PUSHRE)
2897 ; /* Okay here, dangerous in newASSIGNOP */
2906 && (!pm->op_pmregexp
2907 || pm->op_pmregexp->reganch & ROPT_EVAL_SEEN))) {
2908 pm->op_pmflags |= PMf_CONST; /* const for long enough */
2909 pm->op_pmpermflags |= PMf_CONST; /* const for long enough */
2910 prepend_elem(o->op_type, scalar(repl), o);
2913 if (curop == repl && !pm->op_pmregexp) { /* Has variables. */
2914 pm->op_pmflags |= PMf_MAYBE_CONST;
2915 pm->op_pmpermflags |= PMf_MAYBE_CONST;
2917 NewOp(1101, rcop, 1, LOGOP);
2918 rcop->op_type = OP_SUBSTCONT;
2919 rcop->op_ppaddr = PL_ppaddr[OP_SUBSTCONT];
2920 rcop->op_first = scalar(repl);
2921 rcop->op_flags |= OPf_KIDS;
2922 rcop->op_private = 1;
2925 /* establish postfix order */
2926 rcop->op_next = LINKLIST(repl);
2927 repl->op_next = (OP*)rcop;
2929 pm->op_pmreplroot = scalar((OP*)rcop);
2930 pm->op_pmreplstart = LINKLIST(rcop);
2939 Perl_newSVOP(pTHX_ I32 type, I32 flags, SV *sv)
2942 NewOp(1101, svop, 1, SVOP);
2943 svop->op_type = type;
2944 svop->op_ppaddr = PL_ppaddr[type];
2946 svop->op_next = (OP*)svop;
2947 svop->op_flags = flags;
2948 if (PL_opargs[type] & OA_RETSCALAR)
2950 if (PL_opargs[type] & OA_TARGET)
2951 svop->op_targ = pad_alloc(type, SVs_PADTMP);
2952 return CHECKOP(type, svop);
2956 Perl_newPADOP(pTHX_ I32 type, I32 flags, SV *sv)
2959 NewOp(1101, padop, 1, PADOP);
2960 padop->op_type = type;
2961 padop->op_ppaddr = PL_ppaddr[type];
2962 padop->op_padix = pad_alloc(type, SVs_PADTMP);
2963 SvREFCNT_dec(PL_curpad[padop->op_padix]);
2964 PL_curpad[padop->op_padix] = sv;
2966 padop->op_next = (OP*)padop;
2967 padop->op_flags = flags;
2968 if (PL_opargs[type] & OA_RETSCALAR)
2970 if (PL_opargs[type] & OA_TARGET)
2971 padop->op_targ = pad_alloc(type, SVs_PADTMP);
2972 return CHECKOP(type, padop);
2976 Perl_newGVOP(pTHX_ I32 type, I32 flags, GV *gv)
2981 return newPADOP(type, flags, SvREFCNT_inc(gv));
2983 return newSVOP(type, flags, SvREFCNT_inc(gv));
2988 Perl_newPVOP(pTHX_ I32 type, I32 flags, char *pv)
2991 NewOp(1101, pvop, 1, PVOP);
2992 pvop->op_type = type;
2993 pvop->op_ppaddr = PL_ppaddr[type];
2995 pvop->op_next = (OP*)pvop;
2996 pvop->op_flags = flags;
2997 if (PL_opargs[type] & OA_RETSCALAR)
2999 if (PL_opargs[type] & OA_TARGET)
3000 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
3001 return CHECKOP(type, pvop);
3005 Perl_package(pTHX_ OP *o)
3010 save_hptr(&PL_curstash);
3011 save_item(PL_curstname);
3016 name = SvPV(sv, len);
3017 PL_curstash = gv_stashpvn(name,len,TRUE);
3018 sv_setpvn(PL_curstname, name, len);
3022 sv_setpv(PL_curstname,"<none>");
3023 PL_curstash = Nullhv;
3025 PL_hints |= HINT_BLOCK_SCOPE;
3026 PL_copline = NOLINE;
3031 Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *id, OP *arg)
3040 if (id->op_type != OP_CONST)
3041 Perl_croak(aTHX_ "Module name must be constant");
3045 if(version != Nullop) {
3046 SV *vesv = ((SVOP*)version)->op_sv;
3048 if (arg == Nullop && !SvNIOK(vesv)) {
3054 if (version->op_type != OP_CONST || !SvNIOK(vesv))
3055 Perl_croak(aTHX_ "Version number must be constant number");
3057 /* Make copy of id so we don't free it twice */
3058 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
3060 /* Fake up a method call to VERSION */
3061 veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
3062 append_elem(OP_LIST,
3063 prepend_elem(OP_LIST, pack, list(version)),
3064 newSVOP(OP_METHOD_NAMED, 0,
3065 newSVpvn("VERSION", 7))));
3069 /* Fake up an import/unimport */
3070 if (arg && arg->op_type == OP_STUB)
3071 imop = arg; /* no import on explicit () */
3072 else if(SvNIOK(((SVOP*)id)->op_sv)) {
3073 imop = Nullop; /* use 5.0; */
3076 /* Make copy of id so we don't free it twice */
3077 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
3078 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
3079 append_elem(OP_LIST,
3080 prepend_elem(OP_LIST, pack, list(arg)),
3081 newSVOP(OP_METHOD_NAMED, 0,
3082 aver ? newSVpvn("import", 6)
3083 : newSVpvn("unimport", 8))));
3086 /* Fake up a require, handle override, if any */
3087 gv = gv_fetchpv("require", FALSE, SVt_PVCV);
3088 if (!(gv && GvIMPORTED_CV(gv)))
3089 gv = gv_fetchpv("CORE::GLOBAL::require", FALSE, SVt_PVCV);
3091 if (gv && GvIMPORTED_CV(gv)) {
3092 rqop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
3093 append_elem(OP_LIST, id,
3094 scalar(newUNOP(OP_RV2CV, 0,
3099 rqop = newUNOP(OP_REQUIRE, 0, id);
3102 /* Fake up the BEGIN {}, which does its thing immediately. */
3104 newSVOP(OP_CONST, 0, newSVpvn("BEGIN", 5)),
3107 append_elem(OP_LINESEQ,
3108 append_elem(OP_LINESEQ,
3109 newSTATEOP(0, Nullch, rqop),
3110 newSTATEOP(0, Nullch, veop)),
3111 newSTATEOP(0, Nullch, imop) ));
3113 PL_hints |= HINT_BLOCK_SCOPE;
3114 PL_copline = NOLINE;
3119 Perl_dofile(pTHX_ OP *term)
3124 gv = gv_fetchpv("do", FALSE, SVt_PVCV);
3125 if (!(gv && GvIMPORTED_CV(gv)))
3126 gv = gv_fetchpv("CORE::GLOBAL::do", FALSE, SVt_PVCV);
3128 if (gv && GvIMPORTED_CV(gv)) {
3129 doop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
3130 append_elem(OP_LIST, term,
3131 scalar(newUNOP(OP_RV2CV, 0,
3136 doop = newUNOP(OP_DOFILE, 0, scalar(term));
3142 Perl_newSLICEOP(pTHX_ I32 flags, OP *subscript, OP *listval)
3144 return newBINOP(OP_LSLICE, flags,
3145 list(force_list(subscript)),
3146 list(force_list(listval)) );
3150 S_list_assignment(pTHX_ register OP *o)
3155 if (o->op_type == OP_NULL && o->op_flags & OPf_KIDS)
3156 o = cUNOPo->op_first;
3158 if (o->op_type == OP_COND_EXPR) {
3159 I32 t = list_assignment(cLOGOPo->op_first->op_sibling);
3160 I32 f = list_assignment(cLOGOPo->op_first->op_sibling->op_sibling);
3165 yyerror("Assignment to both a list and a scalar");
3169 if (o->op_type == OP_LIST || o->op_flags & OPf_PARENS ||
3170 o->op_type == OP_RV2AV || o->op_type == OP_RV2HV ||
3171 o->op_type == OP_ASLICE || o->op_type == OP_HSLICE)
3174 if (o->op_type == OP_PADAV || o->op_type == OP_PADHV)
3177 if (o->op_type == OP_RV2SV)
3184 Perl_newASSIGNOP(pTHX_ I32 flags, OP *left, I32 optype, OP *right)
3189 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN) {
3190 return newLOGOP(optype, 0,
3191 mod(scalar(left), optype),
3192 newUNOP(OP_SASSIGN, 0, scalar(right)));
3195 return newBINOP(optype, OPf_STACKED,
3196 mod(scalar(left), optype), scalar(right));
3200 if (list_assignment(left)) {
3203 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
3204 left = mod(left, OP_AASSIGN);
3212 o = newBINOP(OP_AASSIGN, flags,
3213 list(force_list(right)),
3214 list(force_list(left)) );
3215 o->op_private = 0 | (flags >> 8);
3216 if (!(left->op_private & OPpLVAL_INTRO)) {
3220 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
3221 if (PL_opargs[curop->op_type] & OA_DANGEROUS) {
3222 if (curop->op_type == OP_GV) {
3223 GV *gv = cGVOPx_gv(curop);
3224 if (gv == PL_defgv || SvCUR(gv) == PL_generation)
3226 SvCUR(gv) = PL_generation;
3228 else if (curop->op_type == OP_PADSV ||
3229 curop->op_type == OP_PADAV ||
3230 curop->op_type == OP_PADHV ||
3231 curop->op_type == OP_PADANY) {
3232 SV **svp = AvARRAY(PL_comppad_name);
3233 SV *sv = svp[curop->op_targ];
3234 if (SvCUR(sv) == PL_generation)
3236 SvCUR(sv) = PL_generation; /* (SvCUR not used any more) */
3238 else if (curop->op_type == OP_RV2CV)
3240 else if (curop->op_type == OP_RV2SV ||
3241 curop->op_type == OP_RV2AV ||
3242 curop->op_type == OP_RV2HV ||
3243 curop->op_type == OP_RV2GV) {
3244 if (lastop->op_type != OP_GV) /* funny deref? */
3247 else if (curop->op_type == OP_PUSHRE) {
3248 if (((PMOP*)curop)->op_pmreplroot) {
3249 GV *gv = (GV*)((PMOP*)curop)->op_pmreplroot;
3250 if (gv == PL_defgv || SvCUR(gv) == PL_generation)
3252 SvCUR(gv) = PL_generation;
3261 o->op_private = OPpASSIGN_COMMON;
3263 if (right && right->op_type == OP_SPLIT) {
3265 if ((tmpop = ((LISTOP*)right)->op_first) &&
3266 tmpop->op_type == OP_PUSHRE)
3268 PMOP *pm = (PMOP*)tmpop;
3269 if (left->op_type == OP_RV2AV &&
3270 !(left->op_private & OPpLVAL_INTRO) &&
3271 !(o->op_private & OPpASSIGN_COMMON) )
3273 tmpop = ((UNOP*)left)->op_first;
3274 if (tmpop->op_type == OP_GV && !pm->op_pmreplroot) {
3276 pm->op_pmreplroot = (OP*)cPADOPx(tmpop)->op_padix;
3277 cPADOPx(tmpop)->op_padix = 0; /* steal it */
3279 pm->op_pmreplroot = (OP*)cSVOPx(tmpop)->op_sv;
3280 cSVOPx(tmpop)->op_sv = Nullsv; /* steal it */
3282 pm->op_pmflags |= PMf_ONCE;
3283 tmpop = cUNOPo->op_first; /* to list (nulled) */
3284 tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */
3285 tmpop->op_sibling = Nullop; /* don't free split */
3286 right->op_next = tmpop->op_next; /* fix starting loc */
3287 op_free(o); /* blow off assign */
3288 right->op_flags &= ~OPf_WANT;
3289 /* "I don't know and I don't care." */
3294 if (PL_modcount < 10000 &&
3295 ((LISTOP*)right)->op_last->op_type == OP_CONST)
3297 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
3299 sv_setiv(sv, PL_modcount+1);
3307 right = newOP(OP_UNDEF, 0);
3308 if (right->op_type == OP_READLINE) {
3309 right->op_flags |= OPf_STACKED;
3310 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
3313 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
3314 o = newBINOP(OP_SASSIGN, flags,
3315 scalar(right), mod(scalar(left), OP_SASSIGN) );
3327 Perl_newSTATEOP(pTHX_ I32 flags, char *label, OP *o)
3330 U32 seq = intro_my();
3333 NewOp(1101, cop, 1, COP);
3334 if (PERLDB_LINE && CopLINE(PL_curcop) && PL_curstash != PL_debstash) {
3335 cop->op_type = OP_DBSTATE;
3336 cop->op_ppaddr = PL_ppaddr[ OP_DBSTATE ];
3339 cop->op_type = OP_NEXTSTATE;
3340 cop->op_ppaddr = PL_ppaddr[ OP_NEXTSTATE ];
3342 cop->op_flags = flags;
3343 cop->op_private = (PL_hints & HINT_UTF8);
3345 cop->op_private |= NATIVE_HINTS;
3347 PL_compiling.op_private = cop->op_private;
3348 cop->op_next = (OP*)cop;
3351 cop->cop_label = label;
3352 PL_hints |= HINT_BLOCK_SCOPE;
3355 cop->cop_arybase = PL_curcop->cop_arybase;
3356 if (specialWARN(PL_curcop->cop_warnings))
3357 cop->cop_warnings = PL_curcop->cop_warnings ;
3359 cop->cop_warnings = newSVsv(PL_curcop->cop_warnings) ;
3362 if (PL_copline == NOLINE)
3363 CopLINE_set(cop, CopLINE(PL_curcop));
3365 CopLINE_set(cop, PL_copline);
3366 PL_copline = NOLINE;
3369 CopFILE_set(cop, CopFILE(PL_curcop)); /* XXXXX share in a pvtable? */
3371 CopFILEGV_set(cop, (GV*)SvREFCNT_inc(CopFILEGV(PL_curcop)));
3373 CopSTASH_set(cop, PL_curstash);
3375 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3376 SV **svp = av_fetch(CopFILEAV(PL_curcop), (I32)CopLINE(cop), FALSE);
3377 if (svp && *svp != &PL_sv_undef && !SvIOK(*svp)) {
3378 (void)SvIOK_on(*svp);
3379 SvIVX(*svp) = PTR2IV(cop);
3383 return prepend_elem(OP_LINESEQ, (OP*)cop, o);
3386 /* "Introduce" my variables to visible status. */
3394 if (! PL_min_intro_pending)
3395 return PL_cop_seqmax;
3397 svp = AvARRAY(PL_comppad_name);
3398 for (i = PL_min_intro_pending; i <= PL_max_intro_pending; i++) {
3399 if ((sv = svp[i]) && sv != &PL_sv_undef && !SvIVX(sv)) {
3400 SvIVX(sv) = PAD_MAX; /* Don't know scope end yet. */
3401 SvNVX(sv) = (NV)PL_cop_seqmax;
3404 PL_min_intro_pending = 0;
3405 PL_comppad_name_fill = PL_max_intro_pending; /* Needn't search higher */
3406 return PL_cop_seqmax++;
3410 Perl_newLOGOP(pTHX_ I32 type, I32 flags, OP *first, OP *other)
3412 return new_logop(type, flags, &first, &other);
3416 S_new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp)
3421 OP *first = *firstp;
3422 OP *other = *otherp;
3424 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
3425 return newBINOP(type, flags, scalar(first), scalar(other));
3427 scalarboolean(first);
3428 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
3429 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
3430 if (type == OP_AND || type == OP_OR) {
3436 first = *firstp = cUNOPo->op_first;
3438 first->op_next = o->op_next;
3439 cUNOPo->op_first = Nullop;
3443 if (first->op_type == OP_CONST) {
3444 if (ckWARN(WARN_PRECEDENCE) && (first->op_private & OPpCONST_BARE))
3445 Perl_warner(aTHX_ WARN_PRECEDENCE, "Probable precedence problem on %s",
3447 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
3458 else if (first->op_type == OP_WANTARRAY) {
3464 else if (ckWARN(WARN_UNSAFE) && (first->op_flags & OPf_KIDS)) {
3465 OP *k1 = ((UNOP*)first)->op_first;
3466 OP *k2 = k1->op_sibling;
3468 switch (first->op_type)
3471 if (k2 && k2->op_type == OP_READLINE
3472 && (k2->op_flags & OPf_STACKED)
3473 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3475 warnop = k2->op_type;
3480 if (k1->op_type == OP_READDIR
3481 || k1->op_type == OP_GLOB
3482 || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
3483 || k1->op_type == OP_EACH)
3485 warnop = ((k1->op_type == OP_NULL)
3486 ? k1->op_targ : k1->op_type);
3491 line_t oldline = CopLINE(PL_curcop);
3492 CopLINE_set(PL_curcop, PL_copline);
3493 Perl_warner(aTHX_ WARN_UNSAFE,
3494 "Value of %s%s can be \"0\"; test with defined()",
3496 ((warnop == OP_READLINE || warnop == OP_GLOB)
3497 ? " construct" : "() operator"));
3498 CopLINE_set(PL_curcop, oldline);
3505 if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
3506 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
3508 NewOp(1101, logop, 1, LOGOP);
3510 logop->op_type = type;
3511 logop->op_ppaddr = PL_ppaddr[type];
3512 logop->op_first = first;
3513 logop->op_flags = flags | OPf_KIDS;
3514 logop->op_other = LINKLIST(other);
3515 logop->op_private = 1 | (flags >> 8);
3517 /* establish postfix order */
3518 logop->op_next = LINKLIST(first);
3519 first->op_next = (OP*)logop;
3520 first->op_sibling = other;
3522 o = newUNOP(OP_NULL, 0, (OP*)logop);
3529 Perl_newCONDOP(pTHX_ I32 flags, OP *first, OP *trueop, OP *falseop)
3537 return newLOGOP(OP_AND, 0, first, trueop);
3539 return newLOGOP(OP_OR, 0, first, falseop);
3541 scalarboolean(first);
3542 if (first->op_type == OP_CONST) {
3543 if (SvTRUE(((SVOP*)first)->op_sv)) {
3554 else if (first->op_type == OP_WANTARRAY) {
3558 NewOp(1101, logop, 1, LOGOP);
3559 logop->op_type = OP_COND_EXPR;
3560 logop->op_ppaddr = PL_ppaddr[OP_COND_EXPR];
3561 logop->op_first = first;
3562 logop->op_flags = flags | OPf_KIDS;
3563 logop->op_private = 1 | (flags >> 8);
3564 logop->op_other = LINKLIST(trueop);
3565 logop->op_next = LINKLIST(falseop);
3568 /* establish postfix order */
3569 start = LINKLIST(first);
3570 first->op_next = (OP*)logop;
3572 first->op_sibling = trueop;
3573 trueop->op_sibling = falseop;
3574 o = newUNOP(OP_NULL, 0, (OP*)logop);
3576 trueop->op_next = falseop->op_next = o;
3583 Perl_newRANGE(pTHX_ I32 flags, OP *left, OP *right)
3592 NewOp(1101, range, 1, LOGOP);
3594 range->op_type = OP_RANGE;
3595 range->op_ppaddr = PL_ppaddr[OP_RANGE];
3596 range->op_first = left;
3597 range->op_flags = OPf_KIDS;
3598 leftstart = LINKLIST(left);
3599 range->op_other = LINKLIST(right);
3600 range->op_private = 1 | (flags >> 8);
3602 left->op_sibling = right;
3604 range->op_next = (OP*)range;
3605 flip = newUNOP(OP_FLIP, flags, (OP*)range);
3606 flop = newUNOP(OP_FLOP, 0, flip);
3607 o = newUNOP(OP_NULL, 0, flop);
3609 range->op_next = leftstart;
3611 left->op_next = flip;
3612 right->op_next = flop;
3614 range->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
3615 sv_upgrade(PAD_SV(range->op_targ), SVt_PVNV);
3616 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
3617 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
3619 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
3620 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
3623 if (!flip->op_private || !flop->op_private)
3624 linklist(o); /* blow off optimizer unless constant */
3630 Perl_newLOOPOP(pTHX_ I32 flags, I32 debuggable, OP *expr, OP *block)
3635 int once = block && block->op_flags & OPf_SPECIAL &&
3636 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
3639 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
3640 return block; /* do {} while 0 does once */
3641 if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
3642 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB)) {
3643 expr = newUNOP(OP_DEFINED, 0,
3644 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
3645 } else if (expr->op_flags & OPf_KIDS) {
3646 OP *k1 = ((UNOP*)expr)->op_first;
3647 OP *k2 = (k1) ? k1->op_sibling : NULL;
3648 switch (expr->op_type) {
3650 if (k2 && k2->op_type == OP_READLINE
3651 && (k2->op_flags & OPf_STACKED)
3652 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3653 expr = newUNOP(OP_DEFINED, 0, expr);
3657 if (k1->op_type == OP_READDIR
3658 || k1->op_type == OP_GLOB
3659 || (k1->op_type == OP_NULL && k1->op_targ == OP_NULL)
3660 || k1->op_type == OP_EACH)
3661 expr = newUNOP(OP_DEFINED, 0, expr);
3667 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
3668 o = new_logop(OP_AND, 0, &expr, &listop);
3671 ((LISTOP*)listop)->op_last->op_next = LINKLIST(o);
3673 if (once && o != listop)
3674 o->op_next = ((LOGOP*)cUNOPo->op_first)->op_other;
3677 o = newUNOP(OP_NULL, 0, o); /* or do {} while 1 loses outer block */
3679 o->op_flags |= flags;
3681 o->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/
3686 Perl_newWHILEOP(pTHX_ I32 flags, I32 debuggable, LOOP *loop, I32 whileline, OP *expr, OP *block, OP *cont)
3695 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
3696 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB))) {
3697 expr = newUNOP(OP_DEFINED, 0,
3698 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
3699 } else if (expr && (expr->op_flags & OPf_KIDS)) {
3700 OP *k1 = ((UNOP*)expr)->op_first;
3701 OP *k2 = (k1) ? k1->op_sibling : NULL;
3702 switch (expr->op_type) {
3704 if (k2 && k2->op_type == OP_READLINE
3705 && (k2->op_flags & OPf_STACKED)
3706 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3707 expr = newUNOP(OP_DEFINED, 0, expr);
3711 if (k1->op_type == OP_READDIR
3712 || k1->op_type == OP_GLOB
3713 || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
3714 || k1->op_type == OP_EACH)
3715 expr = newUNOP(OP_DEFINED, 0, expr);
3721 block = newOP(OP_NULL, 0);
3724 next = LINKLIST(cont);
3726 cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
3727 if ((line_t)whileline != NOLINE) {
3728 PL_copline = whileline;
3729 cont = append_elem(OP_LINESEQ, cont,
3730 newSTATEOP(0, Nullch, Nullop));
3734 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
3735 redo = LINKLIST(listop);
3738 PL_copline = whileline;
3740 o = new_logop(OP_AND, 0, &expr, &listop);
3741 if (o == expr && o->op_type == OP_CONST && !SvTRUE(cSVOPo->op_sv)) {
3742 op_free(expr); /* oops, it's a while (0) */
3744 return Nullop; /* listop already freed by new_logop */
3747 ((LISTOP*)listop)->op_last->op_next = condop =
3748 (o == listop ? redo : LINKLIST(o));
3756 NewOp(1101,loop,1,LOOP);
3757 loop->op_type = OP_ENTERLOOP;
3758 loop->op_ppaddr = PL_ppaddr[OP_ENTERLOOP];
3759 loop->op_private = 0;
3760 loop->op_next = (OP*)loop;
3763 o = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, o);
3765 loop->op_redoop = redo;
3766 loop->op_lastop = o;
3769 loop->op_nextop = next;
3771 loop->op_nextop = o;
3773 o->op_flags |= flags;
3774 o->op_private |= (flags >> 8);
3779 Perl_newFOROP(pTHX_ I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
3788 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
3789 sv->op_type = OP_RV2GV;
3790 sv->op_ppaddr = PL_ppaddr[OP_RV2GV];
3792 else if (sv->op_type == OP_PADSV) { /* private variable */
3793 padoff = sv->op_targ;
3798 else if (sv->op_type == OP_THREADSV) { /* per-thread variable */
3799 padoff = sv->op_targ;
3801 iterflags |= OPf_SPECIAL;
3806 Perl_croak(aTHX_ "Can't use %s for loop variable", PL_op_desc[sv->op_type]);
3810 padoff = find_threadsv("_");
3811 iterflags |= OPf_SPECIAL;
3813 sv = newGVOP(OP_GV, 0, PL_defgv);
3816 if (expr->op_type == OP_RV2AV || expr->op_type == OP_PADAV) {
3817 expr = mod(force_list(scalar(ref(expr, OP_ITER))), OP_GREPSTART);
3818 iterflags |= OPf_STACKED;
3820 else if (expr->op_type == OP_NULL &&
3821 (expr->op_flags & OPf_KIDS) &&
3822 ((BINOP*)expr)->op_first->op_type == OP_FLOP)
3824 /* Basically turn for($x..$y) into the same as for($x,$y), but we
3825 * set the STACKED flag to indicate that these values are to be
3826 * treated as min/max values by 'pp_iterinit'.
3828 UNOP* flip = (UNOP*)((UNOP*)((BINOP*)expr)->op_first)->op_first;
3829 LOGOP* range = (LOGOP*) flip->op_first;
3830 OP* left = range->op_first;
3831 OP* right = left->op_sibling;
3834 range->op_flags &= ~OPf_KIDS;
3835 range->op_first = Nullop;
3837 listop = (LISTOP*)newLISTOP(OP_LIST, 0, left, right);
3838 listop->op_first->op_next = range->op_next;
3839 left->op_next = range->op_other;
3840 right->op_next = (OP*)listop;
3841 listop->op_next = listop->op_first;
3844 expr = (OP*)(listop);
3846 iterflags |= OPf_STACKED;
3849 expr = mod(force_list(expr), OP_GREPSTART);
3853 loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
3854 append_elem(OP_LIST, expr, scalar(sv))));
3855 assert(!loop->op_next);
3856 #ifdef PL_OP_SLAB_ALLOC
3857 NewOp(1234,tmp,1,LOOP);
3858 Copy(loop,tmp,1,LOOP);
3861 Renew(loop, 1, LOOP);
3863 loop->op_targ = padoff;
3864 wop = newWHILEOP(flags, 1, loop, forline, newOP(OP_ITER, 0), block, cont);
3865 PL_copline = forline;
3866 return newSTATEOP(0, label, wop);
3870 Perl_newLOOPEX(pTHX_ I32 type, OP *label)
3876 if (type != OP_GOTO || label->op_type == OP_CONST) {
3877 /* "last()" means "last" */
3878 if (label->op_type == OP_STUB && (label->op_flags & OPf_PARENS))
3879 o = newOP(type, OPf_SPECIAL);
3881 o = newPVOP(type, 0, savepv(label->op_type == OP_CONST
3882 ? SvPVx(((SVOP*)label)->op_sv, n_a)
3888 if (label->op_type == OP_ENTERSUB)
3889 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
3890 o = newUNOP(type, OPf_STACKED, label);
3892 PL_hints |= HINT_BLOCK_SCOPE;
3897 Perl_cv_undef(pTHX_ CV *cv)
3902 MUTEX_DESTROY(CvMUTEXP(cv));
3903 Safefree(CvMUTEXP(cv));
3906 #endif /* USE_THREADS */
3908 if (!CvXSUB(cv) && CvROOT(cv)) {
3910 if (CvDEPTH(cv) || (CvOWNER(cv) && CvOWNER(cv) != thr))
3911 Perl_croak(aTHX_ "Can't undef active subroutine");
3914 Perl_croak(aTHX_ "Can't undef active subroutine");
3915 #endif /* USE_THREADS */
3918 SAVEVPTR(PL_curpad);
3922 op_free(CvROOT(cv));
3923 CvROOT(cv) = Nullop;
3926 SvPOK_off((SV*)cv); /* forget prototype */
3928 SvREFCNT_dec(CvGV(cv));
3930 SvREFCNT_dec(CvOUTSIDE(cv));
3931 CvOUTSIDE(cv) = Nullcv;
3932 if (CvPADLIST(cv)) {
3933 /* may be during global destruction */
3934 if (SvREFCNT(CvPADLIST(cv))) {
3935 I32 i = AvFILLp(CvPADLIST(cv));
3937 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
3938 SV* sv = svp ? *svp : Nullsv;
3941 if (sv == (SV*)PL_comppad_name)
3942 PL_comppad_name = Nullav;
3943 else if (sv == (SV*)PL_comppad) {
3944 PL_comppad = Nullav;
3945 PL_curpad = Null(SV**);
3949 SvREFCNT_dec((SV*)CvPADLIST(cv));
3951 CvPADLIST(cv) = Nullav;
3956 S_cv_dump(pTHX_ CV *cv)
3959 CV *outside = CvOUTSIDE(cv);
3960 AV* padlist = CvPADLIST(cv);
3967 PerlIO_printf(Perl_debug_log,
3968 "\tCV=0x%"UVxf" (%s), OUTSIDE=0x%"UVxf" (%s)\n",
3970 (CvANON(cv) ? "ANON"
3971 : (cv == PL_main_cv) ? "MAIN"
3972 : CvUNIQUE(cv) ? "UNIQUE"
3973 : CvGV(cv) ? GvNAME(CvGV(cv)) : "UNDEFINED"),
3976 : CvANON(outside) ? "ANON"
3977 : (outside == PL_main_cv) ? "MAIN"
3978 : CvUNIQUE(outside) ? "UNIQUE"
3979 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
3984 pad_name = (AV*)*av_fetch(padlist, 0, FALSE);
3985 pad = (AV*)*av_fetch(padlist, 1, FALSE);
3986 pname = AvARRAY(pad_name);
3987 ppad = AvARRAY(pad);
3989 for (ix = 1; ix <= AvFILLp(pad_name); ix++) {
3990 if (SvPOK(pname[ix]))
3991 PerlIO_printf(Perl_debug_log,
3992 "\t%4d. 0x%"UVxf" (%s\"%s\" %"IVdf"-%"IVdf")\n",
3993 ix, PTR2UV(ppad[ix]),
3994 SvFAKE(pname[ix]) ? "FAKE " : "",
3996 (IV)I_32(SvNVX(pname[ix])),
3999 #endif /* DEBUGGING */
4003 S_cv_clone2(pTHX_ CV *proto, CV *outside)
4008 AV* protopadlist = CvPADLIST(proto);
4009 AV* protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
4010 AV* protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
4011 SV** pname = AvARRAY(protopad_name);
4012 SV** ppad = AvARRAY(protopad);
4013 I32 fname = AvFILLp(protopad_name);
4014 I32 fpad = AvFILLp(protopad);
4018 assert(!CvUNIQUE(proto));
4021 SAVEVPTR(PL_curpad);
4022 SAVESPTR(PL_comppad);
4023 SAVESPTR(PL_comppad_name);
4024 SAVESPTR(PL_compcv);
4026 cv = PL_compcv = (CV*)NEWSV(1104,0);
4027 sv_upgrade((SV *)cv, SvTYPE(proto));
4033 New(666, CvMUTEXP(cv), 1, perl_mutex);
4034 MUTEX_INIT(CvMUTEXP(cv));
4036 #endif /* USE_THREADS */
4037 CvFILE(cv) = CvFILE(proto);
4038 CvGV(cv) = (GV*)SvREFCNT_inc(CvGV(proto));
4039 CvSTASH(cv) = CvSTASH(proto);
4040 CvROOT(cv) = CvROOT(proto);
4041 CvSTART(cv) = CvSTART(proto);
4043 CvOUTSIDE(cv) = (CV*)SvREFCNT_inc(outside);
4046 sv_setpvn((SV*)cv, SvPVX(proto), SvCUR(proto));
4048 PL_comppad_name = newAV();
4049 for (ix = fname; ix >= 0; ix--)
4050 av_store(PL_comppad_name, ix, SvREFCNT_inc(pname[ix]));
4052 PL_comppad = newAV();
4054 comppadlist = newAV();
4055 AvREAL_off(comppadlist);
4056 av_store(comppadlist, 0, (SV*)PL_comppad_name);
4057 av_store(comppadlist, 1, (SV*)PL_comppad);
4058 CvPADLIST(cv) = comppadlist;
4059 av_fill(PL_comppad, AvFILLp(protopad));
4060 PL_curpad = AvARRAY(PL_comppad);
4062 av = newAV(); /* will be @_ */
4064 av_store(PL_comppad, 0, (SV*)av);
4065 AvFLAGS(av) = AVf_REIFY;
4067 for (ix = fpad; ix > 0; ix--) {
4068 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
4069 if (namesv && namesv != &PL_sv_undef) {
4070 char *name = SvPVX(namesv); /* XXX */
4071 if (SvFLAGS(namesv) & SVf_FAKE) { /* lexical from outside? */
4072 I32 off = pad_findlex(name, ix, SvIVX(namesv),
4073 CvOUTSIDE(cv), cxstack_ix, 0, 0);
4075 PL_curpad[ix] = SvREFCNT_inc(ppad[ix]);
4077 Perl_croak(aTHX_ "panic: cv_clone: %s", name);
4079 else { /* our own lexical */
4082 /* anon code -- we'll come back for it */
4083 sv = SvREFCNT_inc(ppad[ix]);
4085 else if (*name == '@')
4087 else if (*name == '%')
4096 else if (IS_PADGV(ppad[ix]) || IS_PADCONST(ppad[ix])) {
4097 PL_curpad[ix] = SvREFCNT_inc(ppad[ix]);
4100 SV* sv = NEWSV(0,0);
4106 /* Now that vars are all in place, clone nested closures. */
4108 for (ix = fpad; ix > 0; ix--) {
4109 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
4111 && namesv != &PL_sv_undef
4112 && !(SvFLAGS(namesv) & SVf_FAKE)
4113 && *SvPVX(namesv) == '&'
4114 && CvCLONE(ppad[ix]))
4116 CV *kid = cv_clone2((CV*)ppad[ix], cv);
4117 SvREFCNT_dec(ppad[ix]);
4120 PL_curpad[ix] = (SV*)kid;
4124 #ifdef DEBUG_CLOSURES
4125 PerlIO_printf(Perl_debug_log, "Cloned inside:\n");
4127 PerlIO_printf(Perl_debug_log, " from:\n");
4129 PerlIO_printf(Perl_debug_log, " to:\n");
4138 Perl_cv_clone(pTHX_ CV *proto)
4141 LOCK_CRED_MUTEX; /* XXX create separate mutex */
4142 cv = cv_clone2(proto, CvOUTSIDE(proto));
4143 UNLOCK_CRED_MUTEX; /* XXX create separate mutex */
4148 Perl_cv_ckproto(pTHX_ CV *cv, GV *gv, char *p)
4152 if (((!p != !SvPOK(cv)) || (p && strNE(p, SvPVX(cv)))) && ckWARN_d(WARN_UNSAFE)) {
4153 SV* msg = sv_newmortal();
4157 gv_efullname3(name = sv_newmortal(), gv, Nullch);
4158 sv_setpv(msg, "Prototype mismatch:");
4160 Perl_sv_catpvf(aTHX_ msg, " sub %_", name);
4162 Perl_sv_catpvf(aTHX_ msg, " (%s)", SvPVX(cv));
4163 sv_catpv(msg, " vs ");
4165 Perl_sv_catpvf(aTHX_ msg, "(%s)", p);
4167 sv_catpv(msg, "none");
4168 Perl_warner(aTHX_ WARN_UNSAFE, "%_", msg);
4173 Perl_cv_const_sv(pTHX_ CV *cv)
4175 if (!cv || !SvPOK(cv) || SvCUR(cv))
4177 return op_const_sv(CvSTART(cv), cv);
4181 Perl_op_const_sv(pTHX_ OP *o, CV *cv)
4188 if(o->op_type == OP_LINESEQ && cLISTOPo->op_first)
4189 o = cLISTOPo->op_first->op_sibling;
4191 for (; o; o = o->op_next) {
4192 OPCODE type = o->op_type;
4194 if (sv && o->op_next == o)
4196 if (type == OP_NEXTSTATE || type == OP_NULL || type == OP_PUSHMARK)
4198 if (type == OP_LEAVESUB || type == OP_RETURN)
4202 if (type == OP_CONST && cSVOPo->op_sv)
4204 else if ((type == OP_PADSV || type == OP_CONST) && cv) {
4205 AV* padav = (AV*)(AvARRAY(CvPADLIST(cv))[1]);
4206 sv = padav ? AvARRAY(padav)[o->op_targ] : Nullsv;
4207 if (!sv || (!SvREADONLY(sv) && SvREFCNT(sv) > 1))
4219 Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
4229 Perl_croak(aTHX_ "\"my sub\" not yet implemented");
4233 Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block)
4235 return Perl_newATTRSUB(aTHX_ floor, o, proto, Nullop, block);
4239 Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
4243 char *name = o ? SvPVx(cSVOPo->op_sv, n_a) : Nullch;
4244 GV *gv = gv_fetchpv(name ? name : "__ANON__",
4245 GV_ADDMULTI | ((block || attrs) ? 0 : GV_NOINIT),
4247 char *ps = proto ? SvPVx(((SVOP*)proto)->op_sv, n_a) : Nullch;
4258 if (SvTYPE(gv) != SVt_PVGV) { /* Maybe prototype now, and had at
4259 maximum a prototype before. */
4260 if (SvTYPE(gv) > SVt_NULL) {
4261 if (!SvPOK((SV*)gv) && !(SvIOK((SV*)gv) && SvIVX((SV*)gv) == -1)
4262 && ckWARN_d(WARN_UNSAFE))
4264 Perl_warner(aTHX_ WARN_UNSAFE, "Runaway prototype");
4266 cv_ckproto((CV*)gv, NULL, ps);
4269 sv_setpv((SV*)gv, ps);
4271 sv_setiv((SV*)gv, -1);
4272 SvREFCNT_dec(PL_compcv);
4273 cv = PL_compcv = NULL;
4274 PL_sub_generation++;
4278 if (!name || GvCVGEN(gv))
4280 else if (cv = GvCV(gv)) {
4281 cv_ckproto(cv, gv, ps);
4282 /* already defined (or promised)? */
4283 if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
4285 bool const_changed = TRUE;
4286 if (!block && !attrs) {
4287 /* just a "sub foo;" when &foo is already defined */
4288 SAVEFREESV(PL_compcv);
4291 /* ahem, death to those who redefine active sort subs */
4292 if (PL_curstackinfo->si_type == PERLSI_SORT && PL_sortcop == CvSTART(cv))
4293 Perl_croak(aTHX_ "Can't redefine active sort subroutine %s", name);
4296 if(const_sv = cv_const_sv(cv))
4297 const_changed = sv_cmp(const_sv, op_const_sv(block, Nullcv));
4298 if ((const_sv && const_changed) || ckWARN(WARN_REDEFINE)
4299 && !(CvGV(cv) && GvSTASH(CvGV(cv))
4300 && HvNAME(GvSTASH(CvGV(cv)))
4301 && strEQ(HvNAME(GvSTASH(CvGV(cv))),
4303 line_t oldline = CopLINE(PL_curcop);
4304 CopLINE_set(PL_curcop, PL_copline);
4305 Perl_warner(aTHX_ WARN_REDEFINE,
4306 const_sv ? "Constant subroutine %s redefined"
4307 : "Subroutine %s redefined", name);
4308 CopLINE_set(PL_curcop, oldline);
4319 /* Need to do a C<use attributes $stash_of_cv,\&cv,@attrs>
4320 * before we clobber PL_compcv.
4324 if (CvGV(cv) && GvSTASH(CvGV(cv)) && HvNAME(GvSTASH(CvGV(cv))))
4325 stash = GvSTASH(CvGV(cv));
4326 else if (CvSTASH(cv) && HvNAME(CvSTASH(cv)))
4327 stash = CvSTASH(cv);
4329 stash = PL_curstash;
4332 /* possibly about to re-define existing subr -- ignore old cv */
4333 rcv = (SV*)PL_compcv;
4334 if (name && GvSTASH(gv) && HvNAME(GvSTASH(gv)))
4335 stash = GvSTASH(gv);
4337 stash = PL_curstash;
4339 apply_attrs(stash, rcv, attrs);
4341 if (cv) { /* must reuse cv if autoloaded */
4343 /* got here with just attrs -- work done, so bug out */
4344 SAVEFREESV(PL_compcv);
4348 CvFLAGS(cv) = CvFLAGS(PL_compcv);
4349 CvOUTSIDE(cv) = CvOUTSIDE(PL_compcv);
4350 CvOUTSIDE(PL_compcv) = 0;
4351 CvPADLIST(cv) = CvPADLIST(PL_compcv);
4352 CvPADLIST(PL_compcv) = 0;
4353 if (SvREFCNT(PL_compcv) > 1) /* XXX Make closures transit through stub. */
4354 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc((SV*)cv);
4355 SvREFCNT_dec(PL_compcv);
4362 PL_sub_generation++;
4365 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4366 CvFILE(cv) = CopFILE(PL_curcop);
4367 CvSTASH(cv) = PL_curstash;
4370 if (!CvMUTEXP(cv)) {
4371 New(666, CvMUTEXP(cv), 1, perl_mutex);
4372 MUTEX_INIT(CvMUTEXP(cv));
4374 #endif /* USE_THREADS */
4377 sv_setpv((SV*)cv, ps);
4379 if (PL_error_count) {
4383 char *s = strrchr(name, ':');
4385 if (strEQ(s, "BEGIN")) {
4387 "BEGIN not safe after errors--compilation aborted";
4388 if (PL_in_eval & EVAL_KEEPERR)
4389 Perl_croak(aTHX_ not_safe);
4391 /* force display of errors found but not reported */
4392 sv_catpv(ERRSV, not_safe);
4393 Perl_croak(aTHX_ "%s", SvPVx(ERRSV, n_a));
4400 PL_copline = NOLINE;
4405 if (AvFILLp(PL_comppad_name) < AvFILLp(PL_comppad))
4406 av_store(PL_comppad_name, AvFILLp(PL_comppad), Nullsv);
4409 CvROOT(cv) = newUNOP(OP_LEAVESUBLV, 0, scalarseq(block));
4412 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
4414 CvROOT(cv)->op_private |= OPpREFCOUNTED;
4415 OpREFCNT_set(CvROOT(cv), 1);
4416 CvSTART(cv) = LINKLIST(CvROOT(cv));
4417 CvROOT(cv)->op_next = 0;
4420 /* now that optimizer has done its work, adjust pad values */
4422 SV **namep = AvARRAY(PL_comppad_name);
4423 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4426 if (SvIMMORTAL(PL_curpad[ix]) || IS_PADGV(PL_curpad[ix]) || IS_PADCONST(PL_curpad[ix]))
4429 * The only things that a clonable function needs in its
4430 * pad are references to outer lexicals and anonymous subs.
4431 * The rest are created anew during cloning.
4433 if (!((namesv = namep[ix]) != Nullsv &&
4434 namesv != &PL_sv_undef &&
4436 *SvPVX(namesv) == '&')))
4438 SvREFCNT_dec(PL_curpad[ix]);
4439 PL_curpad[ix] = Nullsv;
4444 AV *av = newAV(); /* Will be @_ */
4446 av_store(PL_comppad, 0, (SV*)av);
4447 AvFLAGS(av) = AVf_REIFY;
4449 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4450 if (SvIMMORTAL(PL_curpad[ix]) || IS_PADGV(PL_curpad[ix]) || IS_PADCONST(PL_curpad[ix]))
4452 if (!SvPADMY(PL_curpad[ix]))
4453 SvPADTMP_on(PL_curpad[ix]);
4460 if (PERLDB_SUBLINE && PL_curstash != PL_debstash) {
4461 SV *sv = NEWSV(0,0);
4462 SV *tmpstr = sv_newmortal();
4463 GV *db_postponed = gv_fetchpv("DB::postponed", GV_ADDMULTI, SVt_PVHV);
4467 Perl_sv_setpvf(aTHX_ sv, "%s:%ld-%ld",
4469 (long)PL_subline, (long)CopLINE(PL_curcop));
4470 gv_efullname3(tmpstr, gv, Nullch);
4471 hv_store(GvHV(PL_DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
4472 hv = GvHVn(db_postponed);
4473 if (HvFILL(hv) > 0 && hv_exists(hv, SvPVX(tmpstr), SvCUR(tmpstr))
4474 && (cv = GvCV(db_postponed))) {
4479 call_sv((SV*)cv, G_DISCARD);
4483 if ((s = strrchr(name,':')))
4488 if (*s != 'B' && *s != 'E' && *s != 'S' && *s != 'I')
4491 if (strEQ(s, "BEGIN")) {
4492 I32 oldscope = PL_scopestack_ix;
4494 SAVECOPFILE(&PL_compiling);
4495 SAVECOPLINE(&PL_compiling);
4497 sv_setsv(PL_rs, PL_nrs);
4500 PL_beginav = newAV();
4501 DEBUG_x( dump_sub(gv) );
4502 av_push(PL_beginav, SvREFCNT_inc(cv));
4504 call_list(oldscope, PL_beginav);
4506 PL_curcop = &PL_compiling;
4507 PL_compiling.op_private = PL_hints;
4510 else if (strEQ(s, "END") && !PL_error_count) {
4513 DEBUG_x( dump_sub(gv) );
4514 av_unshift(PL_endav, 1);
4515 av_store(PL_endav, 0, SvREFCNT_inc(cv));
4518 else if (strEQ(s, "STOP") && !PL_error_count) {
4520 PL_stopav = newAV();
4521 DEBUG_x( dump_sub(gv) );
4522 av_unshift(PL_stopav, 1);
4523 av_store(PL_stopav, 0, SvREFCNT_inc(cv));
4526 else if (strEQ(s, "INIT") && !PL_error_count) {
4528 PL_initav = newAV();
4529 DEBUG_x( dump_sub(gv) );
4530 av_push(PL_initav, SvREFCNT_inc(cv));
4536 PL_copline = NOLINE;
4541 /* XXX unsafe for threads if eval_owner isn't held */
4543 Perl_newCONSTSUB(pTHX_ HV *stash, char *name, SV *sv)
4548 SAVECOPLINE(PL_curcop);
4551 CopLINE_set(PL_curcop, PL_copline);
4552 PL_hints &= ~HINT_BLOCK_SCOPE;
4555 SAVESPTR(PL_curstash);
4556 SAVECOPSTASH(PL_curcop);
4557 PL_curstash = stash;
4559 CopSTASHPV(PL_curcop) = stash ? HvNAME(stash) : Nullch;
4561 CopSTASH(PL_curcop) = stash;
4566 start_subparse(FALSE, 0),
4567 newSVOP(OP_CONST, 0, newSVpv(name,0)),
4568 newSVOP(OP_CONST, 0, &PL_sv_no), /* SvPV(&PL_sv_no) == "" -- GMB */
4570 newSTATEOP(0, Nullch, newSVOP(OP_CONST, 0, sv))
4577 Perl_newXS(pTHX_ char *name, XSUBADDR_t subaddr, char *filename)
4580 GV *gv = gv_fetchpv(name ? name : "__ANON__", GV_ADDMULTI, SVt_PVCV);
4583 if (cv = (name ? GvCV(gv) : Nullcv)) {
4585 /* just a cached method */
4589 else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
4590 /* already defined (or promised) */
4591 if (ckWARN(WARN_REDEFINE) && !(CvGV(cv) && GvSTASH(CvGV(cv))
4592 && HvNAME(GvSTASH(CvGV(cv)))
4593 && strEQ(HvNAME(GvSTASH(CvGV(cv))), "autouse"))) {
4594 line_t oldline = CopLINE(PL_curcop);
4595 if (PL_copline != NOLINE)
4596 CopLINE_set(PL_curcop, PL_copline);
4597 Perl_warner(aTHX_ WARN_REDEFINE, "Subroutine %s redefined",name);
4598 CopLINE_set(PL_curcop, oldline);
4605 if (cv) /* must reuse cv if autoloaded */
4608 cv = (CV*)NEWSV(1105,0);
4609 sv_upgrade((SV *)cv, SVt_PVCV);
4613 PL_sub_generation++;
4616 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4618 New(666, CvMUTEXP(cv), 1, perl_mutex);
4619 MUTEX_INIT(CvMUTEXP(cv));
4621 #endif /* USE_THREADS */
4622 (void)gv_fetchfile(filename);
4623 CvFILE(cv) = filename; /* NOTE: not copied, as it is expected to be
4624 an external constant string */
4625 CvXSUB(cv) = subaddr;
4628 char *s = strrchr(name,':');
4634 if (*s != 'B' && *s != 'E' && *s != 'S' && *s != 'I')
4637 if (strEQ(s, "BEGIN")) {
4639 PL_beginav = newAV();
4640 av_push(PL_beginav, SvREFCNT_inc(cv));
4643 else if (strEQ(s, "END")) {
4646 av_unshift(PL_endav, 1);
4647 av_store(PL_endav, 0, SvREFCNT_inc(cv));
4650 else if (strEQ(s, "STOP")) {
4652 PL_stopav = newAV();
4653 av_unshift(PL_stopav, 1);
4654 av_store(PL_stopav, 0, SvREFCNT_inc(cv));
4657 else if (strEQ(s, "INIT")) {
4659 PL_initav = newAV();
4660 av_push(PL_initav, SvREFCNT_inc(cv));
4672 Perl_newFORM(pTHX_ I32 floor, OP *o, OP *block)
4682 name = SvPVx(cSVOPo->op_sv, n_a);
4685 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
4687 if (cv = GvFORM(gv)) {
4688 if (ckWARN(WARN_REDEFINE)) {
4689 line_t oldline = CopLINE(PL_curcop);
4691 CopLINE_set(PL_curcop, PL_copline);
4692 Perl_warner(aTHX_ WARN_REDEFINE, "Format %s redefined",name);
4693 CopLINE_set(PL_curcop, oldline);
4699 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4700 CvFILE(cv) = CopFILE(PL_curcop);
4702 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4703 if (!SvPADMY(PL_curpad[ix]) && !SvIMMORTAL(PL_curpad[ix]))
4704 SvPADTMP_on(PL_curpad[ix]);
4707 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
4708 CvROOT(cv)->op_private |= OPpREFCOUNTED;
4709 OpREFCNT_set(CvROOT(cv), 1);
4710 CvSTART(cv) = LINKLIST(CvROOT(cv));
4711 CvROOT(cv)->op_next = 0;
4714 PL_copline = NOLINE;
4719 Perl_newANONLIST(pTHX_ OP *o)
4721 return newUNOP(OP_REFGEN, 0,
4722 mod(list(convert(OP_ANONLIST, 0, o)), OP_REFGEN));
4726 Perl_newANONHASH(pTHX_ OP *o)
4728 return newUNOP(OP_REFGEN, 0,
4729 mod(list(convert(OP_ANONHASH, 0, o)), OP_REFGEN));
4733 Perl_newANONSUB(pTHX_ I32 floor, OP *proto, OP *block)
4735 return newANONATTRSUB(floor, proto, Nullop, block);
4739 Perl_newANONATTRSUB(pTHX_ I32 floor, OP *proto, OP *attrs, OP *block)
4741 return newUNOP(OP_REFGEN, 0,
4742 newSVOP(OP_ANONCODE, 0,
4743 (SV*)newATTRSUB(floor, 0, proto, attrs, block)));
4747 Perl_oopsAV(pTHX_ OP *o)
4749 switch (o->op_type) {
4751 o->op_type = OP_PADAV;
4752 o->op_ppaddr = PL_ppaddr[OP_PADAV];
4753 return ref(o, OP_RV2AV);
4756 o->op_type = OP_RV2AV;
4757 o->op_ppaddr = PL_ppaddr[OP_RV2AV];
4762 if (ckWARN_d(WARN_INTERNAL))
4763 Perl_warner(aTHX_ WARN_INTERNAL, "oops: oopsAV");
4770 Perl_oopsHV(pTHX_ OP *o)
4774 switch (o->op_type) {
4777 o->op_type = OP_PADHV;
4778 o->op_ppaddr = PL_ppaddr[OP_PADHV];
4779 return ref(o, OP_RV2HV);
4783 o->op_type = OP_RV2HV;
4784 o->op_ppaddr = PL_ppaddr[OP_RV2HV];
4789 if (ckWARN_d(WARN_INTERNAL))
4790 Perl_warner(aTHX_ WARN_INTERNAL, "oops: oopsHV");
4797 Perl_newAVREF(pTHX_ OP *o)
4799 if (o->op_type == OP_PADANY) {
4800 o->op_type = OP_PADAV;
4801 o->op_ppaddr = PL_ppaddr[OP_PADAV];
4804 return newUNOP(OP_RV2AV, 0, scalar(o));
4808 Perl_newGVREF(pTHX_ I32 type, OP *o)
4810 if (type == OP_MAPSTART || type == OP_GREPSTART || type == OP_SORT)
4811 return newUNOP(OP_NULL, 0, o);
4812 return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
4816 Perl_newHVREF(pTHX_ OP *o)
4818 if (o->op_type == OP_PADANY) {
4819 o->op_type = OP_PADHV;
4820 o->op_ppaddr = PL_ppaddr[OP_PADHV];
4823 return newUNOP(OP_RV2HV, 0, scalar(o));
4827 Perl_oopsCV(pTHX_ OP *o)
4829 Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
4835 Perl_newCVREF(pTHX_ I32 flags, OP *o)
4837 return newUNOP(OP_RV2CV, flags, scalar(o));
4841 Perl_newSVREF(pTHX_ OP *o)
4843 if (o->op_type == OP_PADANY) {
4844 o->op_type = OP_PADSV;
4845 o->op_ppaddr = PL_ppaddr[OP_PADSV];
4848 else if (o->op_type == OP_THREADSV && !(o->op_flags & OPpDONE_SVREF)) {
4849 o->op_flags |= OPpDONE_SVREF;
4852 return newUNOP(OP_RV2SV, 0, scalar(o));
4855 /* Check routines. */
4858 Perl_ck_anoncode(pTHX_ OP *o)
4863 name = NEWSV(1106,0);
4864 sv_upgrade(name, SVt_PVNV);
4865 sv_setpvn(name, "&", 1);
4868 ix = pad_alloc(o->op_type, SVs_PADMY);
4869 av_store(PL_comppad_name, ix, name);
4870 av_store(PL_comppad, ix, cSVOPo->op_sv);
4871 SvPADMY_on(cSVOPo->op_sv);
4872 cSVOPo->op_sv = Nullsv;
4873 cSVOPo->op_targ = ix;
4878 Perl_ck_bitop(pTHX_ OP *o)
4880 o->op_private = PL_hints;
4885 Perl_ck_concat(pTHX_ OP *o)
4887 if (cUNOPo->op_first->op_type == OP_CONCAT)
4888 o->op_flags |= OPf_STACKED;
4893 Perl_ck_spair(pTHX_ OP *o)
4895 if (o->op_flags & OPf_KIDS) {
4898 OPCODE type = o->op_type;
4899 o = modkids(ck_fun(o), type);
4900 kid = cUNOPo->op_first;
4901 newop = kUNOP->op_first->op_sibling;
4903 (newop->op_sibling ||
4904 !(PL_opargs[newop->op_type] & OA_RETSCALAR) ||
4905 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
4906 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
4910 op_free(kUNOP->op_first);
4911 kUNOP->op_first = newop;
4913 o->op_ppaddr = PL_ppaddr[++o->op_type];
4918 Perl_ck_delete(pTHX_ OP *o)
4922 if (o->op_flags & OPf_KIDS) {
4923 OP *kid = cUNOPo->op_first;
4924 if (kid->op_type == OP_HSLICE)
4925 o->op_private |= OPpSLICE;
4926 else if (kid->op_type != OP_HELEM)
4927 Perl_croak(aTHX_ "%s argument is not a HASH element or slice",
4928 PL_op_desc[o->op_type]);
4935 Perl_ck_eof(pTHX_ OP *o)
4937 I32 type = o->op_type;
4939 if (o->op_flags & OPf_KIDS) {
4940 if (cLISTOPo->op_first->op_type == OP_STUB) {
4942 o = newUNOP(type, OPf_SPECIAL,
4943 newGVOP(OP_GV, 0, gv_fetchpv("main::ARGV", TRUE, SVt_PVAV)));
4951 Perl_ck_eval(pTHX_ OP *o)
4953 PL_hints |= HINT_BLOCK_SCOPE;
4954 if (o->op_flags & OPf_KIDS) {
4955 SVOP *kid = (SVOP*)cUNOPo->op_first;
4958 o->op_flags &= ~OPf_KIDS;
4961 else if (kid->op_type == OP_LINESEQ) {
4964 kid->op_next = o->op_next;
4965 cUNOPo->op_first = 0;
4968 NewOp(1101, enter, 1, LOGOP);
4969 enter->op_type = OP_ENTERTRY;
4970 enter->op_ppaddr = PL_ppaddr[OP_ENTERTRY];
4971 enter->op_private = 0;
4973 /* establish postfix order */
4974 enter->op_next = (OP*)enter;
4976 o = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
4977 o->op_type = OP_LEAVETRY;
4978 o->op_ppaddr = PL_ppaddr[OP_LEAVETRY];
4979 enter->op_other = o;
4987 o = newUNOP(OP_ENTEREVAL, 0, newDEFSVOP());
4989 o->op_targ = (PADOFFSET)PL_hints;
4994 Perl_ck_exec(pTHX_ OP *o)
4997 if (o->op_flags & OPf_STACKED) {
4999 kid = cUNOPo->op_first->op_sibling;
5000 if (kid->op_type == OP_RV2GV)
5009 Perl_ck_exists(pTHX_ OP *o)
5012 if (o->op_flags & OPf_KIDS) {
5013 OP *kid = cUNOPo->op_first;
5014 if (kid->op_type != OP_HELEM)
5015 Perl_croak(aTHX_ "%s argument is not a HASH element", PL_op_desc[o->op_type]);
5023 Perl_ck_gvconst(pTHX_ register OP *o)
5025 o = fold_constants(o);
5026 if (o->op_type == OP_CONST)
5033 Perl_ck_rvconst(pTHX_ register OP *o)
5036 SVOP *kid = (SVOP*)cUNOPo->op_first;
5038 o->op_private |= (PL_hints & HINT_STRICT_REFS);
5039 if (kid->op_type == OP_CONST) {
5043 SV *kidsv = kid->op_sv;
5046 /* Is it a constant from cv_const_sv()? */
5047 if (SvROK(kidsv) && SvREADONLY(kidsv)) {
5048 SV *rsv = SvRV(kidsv);
5049 int svtype = SvTYPE(rsv);
5050 char *badtype = Nullch;
5052 switch (o->op_type) {
5054 if (svtype > SVt_PVMG)
5055 badtype = "a SCALAR";
5058 if (svtype != SVt_PVAV)
5059 badtype = "an ARRAY";
5062 if (svtype != SVt_PVHV) {
5063 if (svtype == SVt_PVAV) { /* pseudohash? */
5064 SV **ksv = av_fetch((AV*)rsv, 0, FALSE);
5065 if (ksv && SvROK(*ksv)
5066 && SvTYPE(SvRV(*ksv)) == SVt_PVHV)
5075 if (svtype != SVt_PVCV)
5080 Perl_croak(aTHX_ "Constant is not %s reference", badtype);
5083 name = SvPV(kidsv, n_a);
5084 if ((PL_hints & HINT_STRICT_REFS) && (kid->op_private & OPpCONST_BARE)) {
5085 char *badthing = Nullch;
5086 switch (o->op_type) {
5088 badthing = "a SCALAR";
5091 badthing = "an ARRAY";
5094 badthing = "a HASH";
5099 "Can't use bareword (\"%s\") as %s ref while \"strict refs\" in use",
5103 * This is a little tricky. We only want to add the symbol if we
5104 * didn't add it in the lexer. Otherwise we get duplicate strict
5105 * warnings. But if we didn't add it in the lexer, we must at
5106 * least pretend like we wanted to add it even if it existed before,
5107 * or we get possible typo warnings. OPpCONST_ENTERED says
5108 * whether the lexer already added THIS instance of this symbol.
5110 iscv = (o->op_type == OP_RV2CV) * 2;
5112 gv = gv_fetchpv(name,
5113 iscv | !(kid->op_private & OPpCONST_ENTERED),
5116 : o->op_type == OP_RV2SV
5118 : o->op_type == OP_RV2AV
5120 : o->op_type == OP_RV2HV
5123 } while (!gv && !(kid->op_private & OPpCONST_ENTERED) && !iscv++);
5125 kid->op_type = OP_GV;
5126 SvREFCNT_dec(kid->op_sv);
5128 /* XXX hack: dependence on sizeof(PADOP) <= sizeof(SVOP) */
5129 kPADOP->op_padix = pad_alloc(OP_GV, SVs_PADTMP);
5131 PL_curpad[kPADOP->op_padix] = SvREFCNT_inc(gv);
5133 kid->op_sv = SvREFCNT_inc(gv);
5135 kid->op_ppaddr = PL_ppaddr[OP_GV];
5142 Perl_ck_ftst(pTHX_ OP *o)
5145 I32 type = o->op_type;
5147 if (o->op_flags & OPf_REF) {
5150 else if (o->op_flags & OPf_KIDS && cUNOPo->op_first->op_type != OP_STUB) {
5151 SVOP *kid = (SVOP*)cUNOPo->op_first;
5153 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
5155 OP *newop = newGVOP(type, OPf_REF,
5156 gv_fetchpv(SvPVx(kid->op_sv, n_a), TRUE, SVt_PVIO));
5163 if (type == OP_FTTTY)
5164 o = newGVOP(type, OPf_REF, gv_fetchpv("main::STDIN", TRUE,
5167 o = newUNOP(type, 0, newDEFSVOP());
5170 if (type == OP_FTTEXT || type == OP_FTBINARY) {
5172 if (PL_hints & HINT_LOCALE)
5173 o->op_private |= OPpLOCALE;
5180 Perl_ck_fun(pTHX_ OP *o)
5187 int type = o->op_type;
5188 register I32 oa = PL_opargs[type] >> OASHIFT;
5190 if (o->op_flags & OPf_STACKED) {
5191 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
5194 return no_fh_allowed(o);
5197 if (o->op_flags & OPf_KIDS) {
5199 tokid = &cLISTOPo->op_first;
5200 kid = cLISTOPo->op_first;
5201 if (kid->op_type == OP_PUSHMARK ||
5202 kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK)
5204 tokid = &kid->op_sibling;
5205 kid = kid->op_sibling;
5207 if (!kid && PL_opargs[type] & OA_DEFGV)
5208 *tokid = kid = newDEFSVOP();
5212 sibl = kid->op_sibling;
5215 /* list seen where single (scalar) arg expected? */
5216 if (numargs == 1 && !(oa >> 4)
5217 && kid->op_type == OP_LIST && type != OP_SCALAR)
5219 return too_many_arguments(o,PL_op_desc[type]);
5232 if (kid->op_type == OP_CONST &&
5233 (kid->op_private & OPpCONST_BARE))
5235 char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
5236 OP *newop = newAVREF(newGVOP(OP_GV, 0,
5237 gv_fetchpv(name, TRUE, SVt_PVAV) ));
5238 if (ckWARN(WARN_SYNTAX))
5239 Perl_warner(aTHX_ WARN_SYNTAX,
5240 "Array @%s missing the @ in argument %"IVdf" of %s()",
5241 name, (IV)numargs, PL_op_desc[type]);
5244 kid->op_sibling = sibl;
5247 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
5248 bad_type(numargs, "array", PL_op_desc[type], kid);
5252 if (kid->op_type == OP_CONST &&
5253 (kid->op_private & OPpCONST_BARE))
5255 char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
5256 OP *newop = newHVREF(newGVOP(OP_GV, 0,
5257 gv_fetchpv(name, TRUE, SVt_PVHV) ));
5258 if (ckWARN(WARN_SYNTAX))
5259 Perl_warner(aTHX_ WARN_SYNTAX,
5260 "Hash %%%s missing the %% in argument %"IVdf" of %s()",
5261 name, (IV)numargs, PL_op_desc[type]);
5264 kid->op_sibling = sibl;
5267 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
5268 bad_type(numargs, "hash", PL_op_desc[type], kid);
5273 OP *newop = newUNOP(OP_NULL, 0, kid);
5274 kid->op_sibling = 0;
5276 newop->op_next = newop;
5278 kid->op_sibling = sibl;
5283 if (kid->op_type != OP_GV && kid->op_type != OP_RV2GV) {
5284 if (kid->op_type == OP_CONST &&
5285 (kid->op_private & OPpCONST_BARE))
5287 OP *newop = newGVOP(OP_GV, 0,
5288 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, n_a), TRUE,
5293 else if (kid->op_type == OP_READLINE) {
5294 /* neophyte patrol: open(<FH>), close(<FH>) etc. */
5295 bad_type(numargs, "HANDLE", PL_op_desc[o->op_type], kid);
5298 I32 flags = OPf_SPECIAL;
5302 /* is this op a FH constructor? */
5303 if (is_handle_constructor(o,numargs)) {
5304 char *name = Nullch;
5308 /* Set a flag to tell rv2gv to vivify
5309 * need to "prove" flag does not mean something
5310 * else already - NI-S 1999/05/07
5313 if (kid->op_type == OP_PADSV) {
5314 SV **namep = av_fetch(PL_comppad_name,
5316 if (namep && *namep)
5317 name = SvPV(*namep, len);
5319 else if (kid->op_type == OP_RV2SV
5320 && kUNOP->op_first->op_type == OP_GV)
5322 GV *gv = cGVOPx_gv(kUNOP->op_first);
5324 len = GvNAMELEN(gv);
5328 targ = pad_alloc(OP_RV2GV, SVs_PADTMP);
5329 namesv = PL_curpad[targ];
5330 SvUPGRADE(namesv, SVt_PV);
5332 sv_setpvn(namesv, "$", 1);
5333 sv_catpvn(namesv, name, len);
5336 kid->op_sibling = 0;
5337 kid = newUNOP(OP_RV2GV, flags, scalar(kid));
5338 kid->op_targ = targ;
5339 kid->op_private |= priv;
5341 kid->op_sibling = sibl;
5347 mod(scalar(kid), type);
5351 tokid = &kid->op_sibling;
5352 kid = kid->op_sibling;
5354 o->op_private |= numargs;
5356 return too_many_arguments(o,PL_op_desc[o->op_type]);
5359 else if (PL_opargs[type] & OA_DEFGV) {
5361 return newUNOP(type, 0, newDEFSVOP());
5365 while (oa & OA_OPTIONAL)
5367 if (oa && oa != OA_LIST)
5368 return too_few_arguments(o,PL_op_desc[o->op_type]);
5374 Perl_ck_glob(pTHX_ OP *o)
5378 if ((o->op_flags & OPf_KIDS) && !cLISTOPo->op_first->op_sibling)
5379 append_elem(OP_GLOB, o, newDEFSVOP());
5381 if (!((gv = gv_fetchpv("glob", FALSE, SVt_PVCV)) && GvIMPORTED_CV(gv)))
5382 gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
5384 #if !defined(PERL_EXTERNAL_GLOB)
5385 /* XXX this can be tightened up and made more failsafe. */
5387 OP *modname = newSVOP(OP_CONST, 0, newSVpvn("File::Glob", 10));
5388 modname->op_private |= OPpCONST_BARE;
5390 utilize(1, start_subparse(FALSE, 0), Nullop, modname,
5391 newSVOP(OP_CONST, 0, newSVpvn(":globally", 9)));
5392 gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
5395 #endif /* PERL_EXTERNAL_GLOB */
5397 if (gv && GvIMPORTED_CV(gv)) {
5398 append_elem(OP_GLOB, o,
5399 newSVOP(OP_CONST, 0, newSViv(PL_glob_index++)));
5400 o->op_type = OP_LIST;
5401 o->op_ppaddr = PL_ppaddr[OP_LIST];
5402 cLISTOPo->op_first->op_type = OP_PUSHMARK;
5403 cLISTOPo->op_first->op_ppaddr = PL_ppaddr[OP_PUSHMARK];
5404 o = newUNOP(OP_ENTERSUB, OPf_STACKED,
5405 append_elem(OP_LIST, o,
5406 scalar(newUNOP(OP_RV2CV, 0,
5407 newGVOP(OP_GV, 0, gv)))));
5408 o = newUNOP(OP_NULL, 0, ck_subr(o));
5409 o->op_targ = OP_GLOB; /* hint at what it used to be */
5412 gv = newGVgen("main");
5414 append_elem(OP_GLOB, o, newGVOP(OP_GV, 0, gv));
5420 Perl_ck_grep(pTHX_ OP *o)
5424 OPCODE type = o->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
5426 o->op_ppaddr = PL_ppaddr[OP_GREPSTART];
5427 NewOp(1101, gwop, 1, LOGOP);
5429 if (o->op_flags & OPf_STACKED) {
5432 kid = cLISTOPo->op_first->op_sibling;
5433 for (k = cLISTOPo->op_first->op_sibling->op_next; k; k = k->op_next) {
5436 kid->op_next = (OP*)gwop;
5437 o->op_flags &= ~OPf_STACKED;
5439 kid = cLISTOPo->op_first->op_sibling;
5440 if (type == OP_MAPWHILE)
5447 kid = cLISTOPo->op_first->op_sibling;
5448 if (kid->op_type != OP_NULL)
5449 Perl_croak(aTHX_ "panic: ck_grep");
5450 kid = kUNOP->op_first;
5452 gwop->op_type = type;
5453 gwop->op_ppaddr = PL_ppaddr[type];
5454 gwop->op_first = listkids(o);
5455 gwop->op_flags |= OPf_KIDS;
5456 gwop->op_private = 1;
5457 gwop->op_other = LINKLIST(kid);
5458 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
5459 kid->op_next = (OP*)gwop;
5461 kid = cLISTOPo->op_first->op_sibling;
5462 if (!kid || !kid->op_sibling)
5463 return too_few_arguments(o,PL_op_desc[o->op_type]);
5464 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
5465 mod(kid, OP_GREPSTART);
5471 Perl_ck_index(pTHX_ OP *o)
5473 if (o->op_flags & OPf_KIDS) {
5474 OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5476 kid = kid->op_sibling; /* get past "big" */
5477 if (kid && kid->op_type == OP_CONST)
5478 fbm_compile(((SVOP*)kid)->op_sv, 0);
5484 Perl_ck_lengthconst(pTHX_ OP *o)
5486 /* XXX length optimization goes here */
5491 Perl_ck_lfun(pTHX_ OP *o)
5493 OPCODE type = o->op_type;
5494 return modkids(ck_fun(o), type);
5498 Perl_ck_defined(pTHX_ OP *o) /* 19990527 MJD */
5501 if ((o->op_flags & OPf_KIDS) && ckWARN(WARN_DEPRECATED)) {
5502 switch (cUNOPo->op_first->op_type) {
5504 break; /* Globals via GV can be undef */
5506 case OP_AASSIGN: /* Is this a good idea? */
5507 Perl_warner(aTHX_ WARN_DEPRECATED,
5508 "defined(@array) is deprecated");
5509 Perl_warner(aTHX_ WARN_DEPRECATED,
5510 "(Maybe you should just omit the defined()?)\n");
5513 break; /* Globals via GV can be undef */
5515 Perl_warner(aTHX_ WARN_DEPRECATED,
5516 "defined(%hash) is deprecated");
5517 Perl_warner(aTHX_ WARN_DEPRECATED,
5518 "(Maybe you should just omit the defined()?)\n");
5529 Perl_ck_rfun(pTHX_ OP *o)
5531 OPCODE type = o->op_type;
5532 return refkids(ck_fun(o), type);
5536 Perl_ck_listiob(pTHX_ OP *o)
5540 kid = cLISTOPo->op_first;
5543 kid = cLISTOPo->op_first;
5545 if (kid->op_type == OP_PUSHMARK)
5546 kid = kid->op_sibling;
5547 if (kid && o->op_flags & OPf_STACKED)
5548 kid = kid->op_sibling;
5549 else if (kid && !kid->op_sibling) { /* print HANDLE; */
5550 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
5551 o->op_flags |= OPf_STACKED; /* make it a filehandle */
5552 kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
5553 cLISTOPo->op_first->op_sibling = kid;
5554 cLISTOPo->op_last = kid;
5555 kid = kid->op_sibling;
5560 append_elem(o->op_type, o, newDEFSVOP());
5566 if (PL_hints & HINT_LOCALE)
5567 o->op_private |= OPpLOCALE;
5574 Perl_ck_fun_locale(pTHX_ OP *o)
5580 if (PL_hints & HINT_LOCALE)
5581 o->op_private |= OPpLOCALE;
5588 Perl_ck_sassign(pTHX_ OP *o)
5590 OP *kid = cLISTOPo->op_first;
5591 /* has a disposable target? */
5592 if ((PL_opargs[kid->op_type] & OA_TARGLEX)
5593 && !(kid->op_flags & OPf_STACKED))
5595 OP *kkid = kid->op_sibling;
5597 /* Can just relocate the target. */
5598 if (kkid && kkid->op_type == OP_PADSV
5599 && !(kkid->op_private & OPpLVAL_INTRO))
5601 kid->op_targ = kkid->op_targ;
5603 /* Now we do not need PADSV and SASSIGN. */
5604 kid->op_sibling = o->op_sibling; /* NULL */
5605 cLISTOPo->op_first = NULL;
5608 kid->op_private |= OPpTARGET_MY; /* Used for context settings */
5616 Perl_ck_scmp(pTHX_ OP *o)
5620 if (PL_hints & HINT_LOCALE)
5621 o->op_private |= OPpLOCALE;
5628 Perl_ck_match(pTHX_ OP *o)
5630 o->op_private |= OPpRUNTIME;
5635 Perl_ck_method(pTHX_ OP *o)
5637 OP *kid = cUNOPo->op_first;
5638 if (kid->op_type == OP_CONST) {
5639 SV* sv = kSVOP->op_sv;
5640 if (!(strchr(SvPVX(sv), ':') || strchr(SvPVX(sv), '\''))) {
5642 sv_upgrade(sv, SVt_PVIV);
5644 PERL_HASH(SvUVX(sv), SvPVX(sv), SvCUR(sv));
5645 cmop = newSVOP(OP_METHOD_NAMED, 0, sv);
5646 kSVOP->op_sv = Nullsv;
5655 Perl_ck_null(pTHX_ OP *o)
5661 Perl_ck_repeat(pTHX_ OP *o)
5663 if (cBINOPo->op_first->op_flags & OPf_PARENS) {
5664 o->op_private |= OPpREPEAT_DOLIST;
5665 cBINOPo->op_first = force_list(cBINOPo->op_first);
5673 Perl_ck_require(pTHX_ OP *o)
5675 if (o->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
5676 SVOP *kid = (SVOP*)cUNOPo->op_first;
5678 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
5680 for (s = SvPVX(kid->op_sv); *s; s++) {
5681 if (*s == ':' && s[1] == ':') {
5683 Move(s+2, s+1, strlen(s+2)+1, char);
5684 --SvCUR(kid->op_sv);
5687 sv_catpvn(kid->op_sv, ".pm", 3);
5695 Perl_ck_retarget(pTHX_ OP *o)
5697 Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
5704 Perl_ck_select(pTHX_ OP *o)
5707 if (o->op_flags & OPf_KIDS) {
5708 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5709 if (kid && kid->op_sibling) {
5710 o->op_type = OP_SSELECT;
5711 o->op_ppaddr = PL_ppaddr[OP_SSELECT];
5713 return fold_constants(o);
5717 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5718 if (kid && kid->op_type == OP_RV2GV)
5719 kid->op_private &= ~HINT_STRICT_REFS;
5724 Perl_ck_shift(pTHX_ OP *o)
5726 I32 type = o->op_type;
5728 if (!(o->op_flags & OPf_KIDS)) {
5733 if (!CvUNIQUE(PL_compcv)) {
5734 argop = newOP(OP_PADAV, OPf_REF);
5735 argop->op_targ = 0; /* PL_curpad[0] is @_ */
5738 argop = newUNOP(OP_RV2AV, 0,
5739 scalar(newGVOP(OP_GV, 0,
5740 gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
5743 argop = newUNOP(OP_RV2AV, 0,
5744 scalar(newGVOP(OP_GV, 0, !CvUNIQUE(PL_compcv) ?
5745 PL_defgv : gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
5746 #endif /* USE_THREADS */
5747 return newUNOP(type, 0, scalar(argop));
5749 return scalar(modkids(ck_fun(o), type));
5753 Perl_ck_sort(pTHX_ OP *o)
5757 if (PL_hints & HINT_LOCALE)
5758 o->op_private |= OPpLOCALE;
5761 if (o->op_type == OP_SORT && o->op_flags & OPf_STACKED)
5763 if (o->op_flags & OPf_STACKED) { /* may have been cleared */
5764 OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5766 kid = kUNOP->op_first; /* get past null */
5768 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
5770 if (kid->op_type == OP_SCOPE) {
5774 else if (kid->op_type == OP_LEAVE) {
5775 if (o->op_type == OP_SORT) {
5776 null(kid); /* wipe out leave */
5779 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
5780 if (k->op_next == kid)
5785 kid->op_next = 0; /* just disconnect the leave */
5786 k = kLISTOP->op_first;
5790 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5791 if (o->op_type == OP_SORT)
5795 o->op_flags |= OPf_SPECIAL;
5797 else if (kid->op_type == OP_RV2SV || kid->op_type == OP_PADSV)
5798 null(cLISTOPo->op_first->op_sibling);
5805 S_simplify_sort(pTHX_ OP *o)
5808 register OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5812 if (!(o->op_flags & OPf_STACKED))
5814 GvMULTI_on(gv_fetchpv("a", TRUE, SVt_PV));
5815 GvMULTI_on(gv_fetchpv("b", TRUE, SVt_PV));
5816 kid = kUNOP->op_first; /* get past null */
5817 if (kid->op_type != OP_SCOPE)
5819 kid = kLISTOP->op_last; /* get past scope */
5820 switch(kid->op_type) {
5828 k = kid; /* remember this node*/
5829 if (kBINOP->op_first->op_type != OP_RV2SV)
5831 kid = kBINOP->op_first; /* get past cmp */
5832 if (kUNOP->op_first->op_type != OP_GV)
5834 kid = kUNOP->op_first; /* get past rv2sv */
5836 if (GvSTASH(gv) != PL_curstash)
5838 if (strEQ(GvNAME(gv), "a"))
5840 else if(strEQ(GvNAME(gv), "b"))
5844 kid = k; /* back to cmp */
5845 if (kBINOP->op_last->op_type != OP_RV2SV)
5847 kid = kBINOP->op_last; /* down to 2nd arg */
5848 if (kUNOP->op_first->op_type != OP_GV)
5850 kid = kUNOP->op_first; /* get past rv2sv */
5852 if (GvSTASH(gv) != PL_curstash
5854 ? strNE(GvNAME(gv), "a")
5855 : strNE(GvNAME(gv), "b")))
5857 o->op_flags &= ~(OPf_STACKED | OPf_SPECIAL);
5859 o->op_private |= OPpSORT_REVERSE;
5860 if (k->op_type == OP_NCMP)
5861 o->op_private |= OPpSORT_NUMERIC;
5862 if (k->op_type == OP_I_NCMP)
5863 o->op_private |= OPpSORT_NUMERIC | OPpSORT_INTEGER;
5864 kid = cLISTOPo->op_first->op_sibling;
5865 cLISTOPo->op_first->op_sibling = kid->op_sibling; /* bypass old block */
5866 op_free(kid); /* then delete it */
5867 cLISTOPo->op_children--;
5871 Perl_ck_split(pTHX_ OP *o)
5875 if (o->op_flags & OPf_STACKED)
5876 return no_fh_allowed(o);
5878 kid = cLISTOPo->op_first;
5879 if (kid->op_type != OP_NULL)
5880 Perl_croak(aTHX_ "panic: ck_split");
5881 kid = kid->op_sibling;
5882 op_free(cLISTOPo->op_first);
5883 cLISTOPo->op_first = kid;
5885 cLISTOPo->op_first = kid = newSVOP(OP_CONST, 0, newSVpvn(" ", 1));
5886 cLISTOPo->op_last = kid; /* There was only one element previously */
5889 if (kid->op_type != OP_MATCH) {
5890 OP *sibl = kid->op_sibling;
5891 kid->op_sibling = 0;
5892 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
5893 if (cLISTOPo->op_first == cLISTOPo->op_last)
5894 cLISTOPo->op_last = kid;
5895 cLISTOPo->op_first = kid;
5896 kid->op_sibling = sibl;
5899 kid->op_type = OP_PUSHRE;
5900 kid->op_ppaddr = PL_ppaddr[OP_PUSHRE];
5903 if (!kid->op_sibling)
5904 append_elem(OP_SPLIT, o, newDEFSVOP());
5906 kid = kid->op_sibling;
5909 if (!kid->op_sibling)
5910 append_elem(OP_SPLIT, o, newSVOP(OP_CONST, 0, newSViv(0)));
5912 kid = kid->op_sibling;
5915 if (kid->op_sibling)
5916 return too_many_arguments(o,PL_op_desc[o->op_type]);
5922 Perl_ck_join(pTHX_ OP *o)
5924 if (ckWARN(WARN_SYNTAX)) {
5925 OP *kid = cLISTOPo->op_first->op_sibling;
5926 if (kid && kid->op_type == OP_MATCH) {
5927 char *pmstr = "STRING";
5928 if (kPMOP->op_pmregexp)
5929 pmstr = kPMOP->op_pmregexp->precomp;
5930 Perl_warner(aTHX_ WARN_SYNTAX,
5931 "/%s/ should probably be written as \"%s\"",
5939 Perl_ck_subr(pTHX_ OP *o)
5942 OP *prev = ((cUNOPo->op_first->op_sibling)
5943 ? cUNOPo : ((UNOP*)cUNOPo->op_first))->op_first;
5944 OP *o2 = prev->op_sibling;
5953 o->op_private |= OPpENTERSUB_HASTARG;
5954 for (cvop = o2; cvop->op_sibling; cvop = cvop->op_sibling) ;
5955 if (cvop->op_type == OP_RV2CV) {
5957 o->op_private |= (cvop->op_private & OPpENTERSUB_AMPER);
5958 null(cvop); /* disable rv2cv */
5959 tmpop = (SVOP*)((UNOP*)cvop)->op_first;
5960 if (tmpop->op_type == OP_GV && !(o->op_private & OPpENTERSUB_AMPER)) {
5961 GV *gv = cGVOPx_gv(tmpop);
5964 tmpop->op_private |= OPpEARLY_CV;
5965 else if (SvPOK(cv)) {
5966 namegv = CvANON(cv) ? gv : CvGV(cv);
5967 proto = SvPV((SV*)cv, n_a);
5971 else if (cvop->op_type == OP_METHOD || cvop->op_type == OP_METHOD_NAMED) {
5972 if (o2->op_type == OP_CONST)
5973 o2->op_private &= ~OPpCONST_STRICT;
5974 else if (o2->op_type == OP_LIST) {
5975 OP *o = ((UNOP*)o2)->op_first->op_sibling;
5976 if (o && o->op_type == OP_CONST)
5977 o->op_private &= ~OPpCONST_STRICT;
5980 o->op_private |= (PL_hints & HINT_STRICT_REFS);
5981 if (PERLDB_SUB && PL_curstash != PL_debstash)
5982 o->op_private |= OPpENTERSUB_DB;
5983 while (o2 != cvop) {
5987 return too_many_arguments(o, gv_ename(namegv));
6005 if (o2->op_type != OP_REFGEN && o2->op_type != OP_UNDEF)
6006 bad_type(arg, "block", gv_ename(namegv), o2);
6009 /* '*' allows any scalar type, including bareword */
6012 if (o2->op_type == OP_RV2GV)
6013 goto wrapref; /* autoconvert GLOB -> GLOBref */
6014 else if (o2->op_type == OP_CONST)
6015 o2->op_private &= ~OPpCONST_STRICT;
6016 else if (o2->op_type == OP_ENTERSUB) {
6017 /* accidental subroutine, revert to bareword */
6018 OP *gvop = ((UNOP*)o2)->op_first;
6019 if (gvop && gvop->op_type == OP_NULL) {
6020 gvop = ((UNOP*)gvop)->op_first;
6022 for (; gvop->op_sibling; gvop = gvop->op_sibling)
6025 (gvop->op_private & OPpENTERSUB_NOPAREN) &&
6026 (gvop = ((UNOP*)gvop)->op_first) &&
6027 gvop->op_type == OP_GV)
6029 GV *gv = cGVOPx_gv(gvop);
6030 OP *sibling = o2->op_sibling;
6031 SV *n = newSVpvn("",0);
6033 gv_fullname3(n, gv, "");
6034 if (SvCUR(n)>6 && strnEQ(SvPVX(n),"main::",6))
6035 sv_chop(n, SvPVX(n)+6);
6036 o2 = newSVOP(OP_CONST, 0, n);
6037 prev->op_sibling = o2;
6038 o2->op_sibling = sibling;
6050 if (o2->op_type != OP_RV2GV)
6051 bad_type(arg, "symbol", gv_ename(namegv), o2);
6054 if (o2->op_type != OP_RV2CV)
6055 bad_type(arg, "sub", gv_ename(namegv), o2);
6058 if (o2->op_type != OP_RV2SV
6059 && o2->op_type != OP_PADSV
6060 && o2->op_type != OP_HELEM
6061 && o2->op_type != OP_AELEM
6062 && o2->op_type != OP_THREADSV)
6064 bad_type(arg, "scalar", gv_ename(namegv), o2);
6068 if (o2->op_type != OP_RV2AV && o2->op_type != OP_PADAV)
6069 bad_type(arg, "array", gv_ename(namegv), o2);
6072 if (o2->op_type != OP_RV2HV && o2->op_type != OP_PADHV)
6073 bad_type(arg, "hash", gv_ename(namegv), o2);
6077 OP* sib = kid->op_sibling;
6078 kid->op_sibling = 0;
6079 o2 = newUNOP(OP_REFGEN, 0, kid);
6080 o2->op_sibling = sib;
6081 prev->op_sibling = o2;
6092 Perl_croak(aTHX_ "Malformed prototype for %s: %s",
6093 gv_ename(namegv), SvPV((SV*)cv, n_a));
6098 mod(o2, OP_ENTERSUB);
6100 o2 = o2->op_sibling;
6102 if (proto && !optional &&
6103 (*proto && *proto != '@' && *proto != '%' && *proto != ';'))
6104 return too_few_arguments(o, gv_ename(namegv));
6109 Perl_ck_svconst(pTHX_ OP *o)
6111 SvREADONLY_on(cSVOPo->op_sv);
6116 Perl_ck_trunc(pTHX_ OP *o)
6118 if (o->op_flags & OPf_KIDS) {
6119 SVOP *kid = (SVOP*)cUNOPo->op_first;
6121 if (kid->op_type == OP_NULL)
6122 kid = (SVOP*)kid->op_sibling;
6123 if (kid && kid->op_type == OP_CONST &&
6124 (kid->op_private & OPpCONST_BARE))
6126 o->op_flags |= OPf_SPECIAL;
6127 kid->op_private &= ~OPpCONST_STRICT;
6133 /* A peephole optimizer. We visit the ops in the order they're to execute. */
6136 Perl_peep(pTHX_ register OP *o)
6139 register OP* oldop = 0;
6141 OP *last_composite = Nullop;
6143 if (!o || o->op_seq)
6147 SAVEVPTR(PL_curcop);
6148 for (; o; o = o->op_next) {
6154 switch (o->op_type) {
6158 PL_curcop = ((COP*)o); /* for warnings */
6159 o->op_seq = PL_op_seqmax++;
6160 last_composite = Nullop;
6164 if (cSVOPo->op_private & OPpCONST_STRICT)
6165 no_bareword_allowed(o);
6167 /* Relocate sv to the pad for thread safety.
6168 * Despite being a "constant", the SV is written to,
6169 * for reference counts, sv_upgrade() etc. */
6171 PADOFFSET ix = pad_alloc(OP_CONST, SVs_PADTMP);
6172 SvREFCNT_dec(PL_curpad[ix]);
6173 SvPADTMP_on(cSVOPo->op_sv);
6174 PL_curpad[ix] = cSVOPo->op_sv;
6175 cSVOPo->op_sv = Nullsv;
6187 if (o->op_next && o->op_next->op_type == OP_STRINGIFY) {
6188 if (o->op_next->op_private & OPpTARGET_MY) {
6189 if (o->op_flags & OPf_STACKED) /* chained concats */
6190 goto ignore_optimization;
6192 o->op_targ = o->op_next->op_targ;
6193 o->op_next->op_targ = 0;
6194 o->op_private |= OPpTARGET_MY;
6199 ignore_optimization:
6200 o->op_seq = PL_op_seqmax++;
6203 if ((o->op_flags & OPf_WANT) != OPf_WANT_LIST) {
6204 o->op_seq = PL_op_seqmax++;
6205 break; /* Scalar stub must produce undef. List stub is noop */
6209 if (o->op_targ == OP_NEXTSTATE
6210 || o->op_targ == OP_DBSTATE
6211 || o->op_targ == OP_SETSTATE)
6213 PL_curcop = ((COP*)o);
6220 if (oldop && o->op_next) {
6221 oldop->op_next = o->op_next;
6224 o->op_seq = PL_op_seqmax++;
6228 if (o->op_next->op_type == OP_RV2SV) {
6229 if (!(o->op_next->op_private & OPpDEREF)) {
6231 o->op_private |= o->op_next->op_private & OPpLVAL_INTRO;
6232 o->op_next = o->op_next->op_next;
6233 o->op_type = OP_GVSV;
6234 o->op_ppaddr = PL_ppaddr[OP_GVSV];
6237 else if (o->op_next->op_type == OP_RV2AV) {
6238 OP* pop = o->op_next->op_next;
6240 if (pop->op_type == OP_CONST &&
6241 (PL_op = pop->op_next) &&
6242 pop->op_next->op_type == OP_AELEM &&
6243 !(pop->op_next->op_private &
6244 (OPpLVAL_INTRO|OPpLVAL_DEFER|OPpDEREF)) &&
6245 (i = SvIV(((SVOP*)pop)->op_sv) - PL_compiling.cop_arybase)
6253 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
6254 o->op_next = pop->op_next->op_next;
6255 o->op_type = OP_AELEMFAST;
6256 o->op_ppaddr = PL_ppaddr[OP_AELEMFAST];
6257 o->op_private = (U8)i;
6262 else if ((o->op_private & OPpEARLY_CV) && ckWARN(WARN_UNSAFE)) {
6264 if (SvTYPE(gv) == SVt_PVGV && GvCV(gv) && SvPVX(GvCV(gv))) {
6265 /* XXX could check prototype here instead of just carping */
6266 SV *sv = sv_newmortal();
6267 gv_efullname3(sv, gv, Nullch);
6268 Perl_warner(aTHX_ WARN_UNSAFE,
6269 "%s() called too early to check prototype",
6274 o->op_seq = PL_op_seqmax++;
6285 o->op_seq = PL_op_seqmax++;
6286 while (cLOGOP->op_other->op_type == OP_NULL)
6287 cLOGOP->op_other = cLOGOP->op_other->op_next;
6288 peep(cLOGOP->op_other);
6292 o->op_seq = PL_op_seqmax++;
6293 peep(cLOOP->op_redoop);
6294 peep(cLOOP->op_nextop);
6295 peep(cLOOP->op_lastop);
6301 o->op_seq = PL_op_seqmax++;
6302 peep(cPMOP->op_pmreplstart);
6306 o->op_seq = PL_op_seqmax++;
6307 if (ckWARN(WARN_SYNTAX) && o->op_next
6308 && o->op_next->op_type == OP_NEXTSTATE) {
6309 if (o->op_next->op_sibling &&
6310 o->op_next->op_sibling->op_type != OP_EXIT &&
6311 o->op_next->op_sibling->op_type != OP_WARN &&
6312 o->op_next->op_sibling->op_type != OP_DIE) {
6313 line_t oldline = CopLINE(PL_curcop);
6315 CopLINE_set(PL_curcop, CopLINE((COP*)o->op_next));
6316 Perl_warner(aTHX_ WARN_SYNTAX, "Statement unlikely to be reached");
6317 Perl_warner(aTHX_ WARN_SYNTAX, "(Maybe you meant system() when you said exec()?)\n");
6318 CopLINE_set(PL_curcop, oldline);
6332 if ((o->op_private & (OPpLVAL_INTRO))
6333 || ((BINOP*)o)->op_last->op_type != OP_CONST)
6335 rop = (UNOP*)((BINOP*)o)->op_first;
6336 if (rop->op_type != OP_RV2HV || rop->op_first->op_type != OP_PADSV)
6338 lexname = *av_fetch(PL_comppad_name, rop->op_first->op_targ, TRUE);
6339 if (!SvOBJECT(lexname))
6341 fields = (GV**)hv_fetch(SvSTASH(lexname), "FIELDS", 6, FALSE);
6342 if (!fields || !GvHV(*fields))
6344 svp = cSVOPx_svp(((BINOP*)o)->op_last);
6345 key = SvPV(*svp, keylen);
6346 indsvp = hv_fetch(GvHV(*fields), key, keylen, FALSE);
6348 Perl_croak(aTHX_ "No such pseudo-hash field \"%s\" in variable %s of type %s",
6349 key, SvPV(lexname, n_a), HvNAME(SvSTASH(lexname)));
6351 ind = SvIV(*indsvp);
6353 Perl_croak(aTHX_ "Bad index while coercing array into hash");
6354 rop->op_type = OP_RV2AV;
6355 rop->op_ppaddr = PL_ppaddr[OP_RV2AV];
6356 o->op_type = OP_AELEM;
6357 o->op_ppaddr = PL_ppaddr[OP_AELEM];
6359 *svp = newSViv(ind);
6365 if (!(o->op_flags & OPf_WANT)
6366 || (o->op_flags & OPf_WANT) == OPf_WANT_LIST)
6370 o->op_seq = PL_op_seqmax++;
6374 if (o->op_next && o->op_next->op_type != OP_LEAVESUBLV) {
6375 o->op_seq = PL_op_seqmax++;
6381 if (last_composite) {
6382 OP *r = last_composite;
6384 while (r->op_sibling)
6387 || (r->op_next->op_type == OP_LIST
6388 && r->op_next->op_next == o))
6390 if (last_composite->op_type == OP_RV2AV)
6391 yyerror("Lvalue subs returning arrays not implemented yet");
6393 yyerror("Lvalue subs returning hashes not implemented yet");
6400 o->op_seq = PL_op_seqmax++;