3 * Copyright (c) 1991-2001, 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 */
25 #ifdef PL_OP_SLAB_ALLOC
26 #define SLAB_SIZE 8192
27 static char *PL_OpPtr = NULL;
28 static int PL_OpSpace = 0;
29 #define NewOp(m,var,c,type) do { if ((PL_OpSpace -= c*sizeof(type)) >= 0) \
30 var = (type *)(PL_OpPtr -= c*sizeof(type)); \
32 var = (type *) Slab_Alloc(m,c*sizeof(type)); \
36 S_Slab_Alloc(pTHX_ int m, size_t sz)
38 Newz(m,PL_OpPtr,SLAB_SIZE,char);
39 PL_OpSpace = SLAB_SIZE - sz;
40 return PL_OpPtr += PL_OpSpace;
44 #define NewOp(m, var, c, type) Newz(m, var, c, type)
47 * In the following definition, the ", Nullop" is just to make the compiler
48 * think the expression is of the right type: croak actually does a Siglongjmp.
50 #define CHECKOP(type,o) \
51 ((PL_op_mask && PL_op_mask[type]) \
52 ? ( op_free((OP*)o), \
53 Perl_croak(aTHX_ "%s trapped by operation mask", PL_op_desc[type]), \
55 : CALL_FPTR(PL_check[type])(aTHX_ (OP*)o))
57 #define PAD_MAX 999999999
58 #define RETURN_UNLIMITED_NUMBER (PERL_INT_MAX / 2)
61 S_gv_ename(pTHX_ GV *gv)
64 SV* tmpsv = sv_newmortal();
65 gv_efullname3(tmpsv, gv, Nullch);
66 return SvPV(tmpsv,n_a);
70 S_no_fh_allowed(pTHX_ OP *o)
72 yyerror(Perl_form(aTHX_ "Missing comma after first argument to %s function",
73 PL_op_desc[o->op_type]));
78 S_too_few_arguments(pTHX_ OP *o, char *name)
80 yyerror(Perl_form(aTHX_ "Not enough arguments for %s", name));
85 S_too_many_arguments(pTHX_ OP *o, char *name)
87 yyerror(Perl_form(aTHX_ "Too many arguments for %s", name));
92 S_bad_type(pTHX_ I32 n, char *t, char *name, OP *kid)
94 yyerror(Perl_form(aTHX_ "Type of arg %d to %s must be %s (not %s)",
95 (int)n, name, t, PL_op_desc[kid->op_type]));
99 S_no_bareword_allowed(pTHX_ OP *o)
101 qerror(Perl_mess(aTHX_
102 "Bareword \"%s\" not allowed while \"strict subs\" in use",
103 SvPV_nolen(cSVOPo_sv)));
106 /* "register" allocation */
109 Perl_pad_allocmy(pTHX_ char *name)
114 if (!(PL_in_my == KEY_our ||
116 (PL_hints & HINT_UTF8 && UTF8_IS_START(name[1])) ||
117 (name[1] == '_' && (int)strlen(name) > 2)))
119 if (!isPRINT(name[1]) || strchr("\t\n\r\f", name[1])) {
120 /* 1999-02-27 mjd@plover.com */
122 p = strchr(name, '\0');
123 /* The next block assumes the buffer is at least 205 chars
124 long. At present, it's always at least 256 chars. */
126 strcpy(name+200, "...");
132 /* Move everything else down one character */
133 for (; p-name > 2; p--)
135 name[2] = toCTRL(name[1]);
138 yyerror(Perl_form(aTHX_ "Can't use global %s in \"my\"",name));
140 if (ckWARN(WARN_MISC) && AvFILLp(PL_comppad_name) >= 0) {
141 SV **svp = AvARRAY(PL_comppad_name);
142 HV *ourstash = (PL_curstash ? PL_curstash : PL_defstash);
143 PADOFFSET top = AvFILLp(PL_comppad_name);
144 for (off = top; off > PL_comppad_name_floor; off--) {
146 && sv != &PL_sv_undef
147 && (SvIVX(sv) == PAD_MAX || SvIVX(sv) == 0)
148 && (PL_in_my != KEY_our
149 || ((SvFLAGS(sv) & SVpad_OUR) && GvSTASH(sv) == ourstash))
150 && strEQ(name, SvPVX(sv)))
152 Perl_warner(aTHX_ WARN_MISC,
153 "\"%s\" variable %s masks earlier declaration in same %s",
154 (PL_in_my == KEY_our ? "our" : "my"),
156 (SvIVX(sv) == PAD_MAX ? "scope" : "statement"));
161 if (PL_in_my == KEY_our) {
164 && sv != &PL_sv_undef
165 && (SvIVX(sv) == PAD_MAX || SvIVX(sv) == 0)
166 && ((SvFLAGS(sv) & SVpad_OUR) && GvSTASH(sv) == ourstash)
167 && strEQ(name, SvPVX(sv)))
169 Perl_warner(aTHX_ WARN_MISC,
170 "\"our\" variable %s redeclared", name);
171 Perl_warner(aTHX_ WARN_MISC,
172 "\t(Did you mean \"local\" instead of \"our\"?)\n");
175 } while ( off-- > 0 );
178 off = pad_alloc(OP_PADSV, SVs_PADMY);
180 sv_upgrade(sv, SVt_PVNV);
182 if (PL_in_my_stash) {
184 yyerror(Perl_form(aTHX_ "Can't declare class for non-scalar %s in \"%s\"",
185 name, PL_in_my == KEY_our ? "our" : "my"));
186 SvFLAGS(sv) |= SVpad_TYPED;
187 (void)SvUPGRADE(sv, SVt_PVMG);
188 SvSTASH(sv) = (HV*)SvREFCNT_inc(PL_in_my_stash);
190 if (PL_in_my == KEY_our) {
191 (void)SvUPGRADE(sv, SVt_PVGV);
192 GvSTASH(sv) = (HV*)SvREFCNT_inc(PL_curstash ? (SV*)PL_curstash : (SV*)PL_defstash);
193 SvFLAGS(sv) |= SVpad_OUR;
195 av_store(PL_comppad_name, off, sv);
196 SvNVX(sv) = (NV)PAD_MAX;
197 SvIVX(sv) = 0; /* Not yet introduced--see newSTATEOP */
198 if (!PL_min_intro_pending)
199 PL_min_intro_pending = off;
200 PL_max_intro_pending = off;
202 av_store(PL_comppad, off, (SV*)newAV());
203 else if (*name == '%')
204 av_store(PL_comppad, off, (SV*)newHV());
205 SvPADMY_on(PL_curpad[off]);
210 S_pad_addlex(pTHX_ SV *proto_namesv)
212 SV *namesv = NEWSV(1103,0);
213 PADOFFSET newoff = pad_alloc(OP_PADSV, SVs_PADMY);
214 sv_upgrade(namesv, SVt_PVNV);
215 sv_setpv(namesv, SvPVX(proto_namesv));
216 av_store(PL_comppad_name, newoff, namesv);
217 SvNVX(namesv) = (NV)PL_curcop->cop_seq;
218 SvIVX(namesv) = PAD_MAX; /* A ref, intro immediately */
219 SvFAKE_on(namesv); /* A ref, not a real var */
220 if (SvFLAGS(proto_namesv) & SVpad_OUR) { /* An "our" variable */
221 SvFLAGS(namesv) |= SVpad_OUR;
222 (void)SvUPGRADE(namesv, SVt_PVGV);
223 GvSTASH(namesv) = (HV*)SvREFCNT_inc((SV*)GvSTASH(proto_namesv));
225 if (SvFLAGS(proto_namesv) & SVpad_TYPED) { /* A typed lexical */
226 SvFLAGS(namesv) |= SVpad_TYPED;
227 (void)SvUPGRADE(namesv, SVt_PVMG);
228 SvSTASH(namesv) = (HV*)SvREFCNT_inc((SV*)SvSTASH(proto_namesv));
233 #define FINDLEX_NOSEARCH 1 /* don't search outer contexts */
236 S_pad_findlex(pTHX_ char *name, PADOFFSET newoff, U32 seq, CV* startcv,
237 I32 cx_ix, I32 saweval, U32 flags)
243 register PERL_CONTEXT *cx;
245 for (cv = startcv; cv; cv = CvOUTSIDE(cv)) {
246 AV *curlist = CvPADLIST(cv);
247 SV **svp = av_fetch(curlist, 0, FALSE);
250 if (!svp || *svp == &PL_sv_undef)
253 svp = AvARRAY(curname);
254 for (off = AvFILLp(curname); off > 0; off--) {
255 if ((sv = svp[off]) &&
256 sv != &PL_sv_undef &&
258 seq > I_32(SvNVX(sv)) &&
259 strEQ(SvPVX(sv), name))
270 return 0; /* don't clone from inactive stack frame */
274 oldpad = (AV*)AvARRAY(curlist)[depth];
275 oldsv = *av_fetch(oldpad, off, TRUE);
276 if (!newoff) { /* Not a mere clone operation. */
277 newoff = pad_addlex(sv);
278 if (CvANON(PL_compcv) || SvTYPE(PL_compcv) == SVt_PVFM) {
279 /* "It's closures all the way down." */
280 CvCLONE_on(PL_compcv);
282 if (CvANON(PL_compcv))
283 oldsv = Nullsv; /* no need to keep ref */
288 bcv && bcv != cv && !CvCLONE(bcv);
289 bcv = CvOUTSIDE(bcv))
292 /* install the missing pad entry in intervening
293 * nested subs and mark them cloneable.
294 * XXX fix pad_foo() to not use globals */
295 AV *ocomppad_name = PL_comppad_name;
296 AV *ocomppad = PL_comppad;
297 SV **ocurpad = PL_curpad;
298 AV *padlist = CvPADLIST(bcv);
299 PL_comppad_name = (AV*)AvARRAY(padlist)[0];
300 PL_comppad = (AV*)AvARRAY(padlist)[1];
301 PL_curpad = AvARRAY(PL_comppad);
303 PL_comppad_name = ocomppad_name;
304 PL_comppad = ocomppad;
309 if (ckWARN(WARN_CLOSURE)
310 && !CvUNIQUE(bcv) && !CvUNIQUE(cv))
312 Perl_warner(aTHX_ WARN_CLOSURE,
313 "Variable \"%s\" may be unavailable",
321 else if (!CvUNIQUE(PL_compcv)) {
322 if (ckWARN(WARN_CLOSURE) && !SvFAKE(sv) && !CvUNIQUE(cv)
323 && !(SvFLAGS(sv) & SVpad_OUR))
325 Perl_warner(aTHX_ WARN_CLOSURE,
326 "Variable \"%s\" will not stay shared", name);
330 av_store(PL_comppad, newoff, SvREFCNT_inc(oldsv));
336 if (flags & FINDLEX_NOSEARCH)
339 /* Nothing in current lexical context--try eval's context, if any.
340 * This is necessary to let the perldb get at lexically scoped variables.
341 * XXX This will also probably interact badly with eval tree caching.
344 for (i = cx_ix; i >= 0; i--) {
346 switch (CxTYPE(cx)) {
348 if (i == 0 && saweval) {
349 return pad_findlex(name, newoff, seq, PL_main_cv, -1, saweval, 0);
353 switch (cx->blk_eval.old_op_type) {
355 if (CxREALEVAL(cx)) {
358 seq = cxstack[i].blk_oldcop->cop_seq;
359 startcv = cxstack[i].blk_eval.cv;
360 if (startcv && CvOUTSIDE(startcv)) {
361 off = pad_findlex(name, newoff, seq, CvOUTSIDE(startcv),
363 if (off) /* continue looking if not found here */
370 /* require/do must have their own scope */
379 if (PL_debstash && CvSTASH(cv) == PL_debstash) { /* ignore DB'* scope */
380 saweval = i; /* so we know where we were called from */
381 seq = cxstack[i].blk_oldcop->cop_seq;
384 return pad_findlex(name, newoff, seq, cv, i-1, saweval,FINDLEX_NOSEARCH);
392 Perl_pad_findmy(pTHX_ char *name)
397 SV **svp = AvARRAY(PL_comppad_name);
398 U32 seq = PL_cop_seqmax;
404 * Special case to get lexical (and hence per-thread) @_.
405 * XXX I need to find out how to tell at parse-time whether use
406 * of @_ should refer to a lexical (from a sub) or defgv (global
407 * scope and maybe weird sub-ish things like formats). See
408 * startsub in perly.y. It's possible that @_ could be lexical
409 * (at least from subs) even in non-threaded perl.
411 if (strEQ(name, "@_"))
412 return 0; /* success. (NOT_IN_PAD indicates failure) */
413 #endif /* USE_THREADS */
415 /* The one we're looking for is probably just before comppad_name_fill. */
416 for (off = AvFILLp(PL_comppad_name); off > 0; off--) {
417 if ((sv = svp[off]) &&
418 sv != &PL_sv_undef &&
421 seq > I_32(SvNVX(sv)))) &&
422 strEQ(SvPVX(sv), name))
424 if (SvIVX(sv) || SvFLAGS(sv) & SVpad_OUR)
425 return (PADOFFSET)off;
426 pendoff = off; /* this pending def. will override import */
430 outside = CvOUTSIDE(PL_compcv);
432 /* Check if if we're compiling an eval'', and adjust seq to be the
433 * eval's seq number. This depends on eval'' having a non-null
434 * CvOUTSIDE() while it is being compiled. The eval'' itself is
435 * identified by CvEVAL being true and CvGV being null. */
436 if (outside && CvEVAL(PL_compcv) && !CvGV(PL_compcv) && cxstack_ix >= 0) {
437 cx = &cxstack[cxstack_ix];
439 seq = cx->blk_oldcop->cop_seq;
442 /* See if it's in a nested scope */
443 off = pad_findlex(name, 0, seq, outside, cxstack_ix, 0, 0);
445 /* If there is a pending local definition, this new alias must die */
447 SvIVX(AvARRAY(PL_comppad_name)[off]) = seq;
448 return off; /* pad_findlex returns 0 for failure...*/
450 return NOT_IN_PAD; /* ...but we return NOT_IN_PAD for failure */
454 Perl_pad_leavemy(pTHX_ I32 fill)
457 SV **svp = AvARRAY(PL_comppad_name);
459 if (PL_min_intro_pending && fill < PL_min_intro_pending) {
460 for (off = PL_max_intro_pending; off >= PL_min_intro_pending; off--) {
461 if ((sv = svp[off]) && sv != &PL_sv_undef && ckWARN_d(WARN_INTERNAL))
462 Perl_warner(aTHX_ WARN_INTERNAL, "%s never introduced", SvPVX(sv));
465 /* "Deintroduce" my variables that are leaving with this scope. */
466 for (off = AvFILLp(PL_comppad_name); off > fill; off--) {
467 if ((sv = svp[off]) && sv != &PL_sv_undef && SvIVX(sv) == PAD_MAX)
468 SvIVX(sv) = PL_cop_seqmax;
473 Perl_pad_alloc(pTHX_ I32 optype, U32 tmptype)
478 if (AvARRAY(PL_comppad) != PL_curpad)
479 Perl_croak(aTHX_ "panic: pad_alloc");
480 if (PL_pad_reset_pending)
482 if (tmptype & SVs_PADMY) {
484 sv = *av_fetch(PL_comppad, AvFILLp(PL_comppad) + 1, TRUE);
485 } while (SvPADBUSY(sv)); /* need a fresh one */
486 retval = AvFILLp(PL_comppad);
489 SV **names = AvARRAY(PL_comppad_name);
490 SSize_t names_fill = AvFILLp(PL_comppad_name);
493 * "foreach" index vars temporarily become aliases to non-"my"
494 * values. Thus we must skip, not just pad values that are
495 * marked as current pad values, but also those with names.
497 if (++PL_padix <= names_fill &&
498 (sv = names[PL_padix]) && sv != &PL_sv_undef)
500 sv = *av_fetch(PL_comppad, PL_padix, TRUE);
501 if (!(SvFLAGS(sv) & (SVs_PADTMP|SVs_PADMY)) &&
502 !IS_PADGV(sv) && !IS_PADCONST(sv))
507 SvFLAGS(sv) |= tmptype;
508 PL_curpad = AvARRAY(PL_comppad);
510 DEBUG_X(PerlIO_printf(Perl_debug_log,
511 "0x%"UVxf" Pad 0x%"UVxf" alloc %ld for %s\n",
512 PTR2UV(thr), PTR2UV(PL_curpad),
513 (long) retval, PL_op_name[optype]));
515 DEBUG_X(PerlIO_printf(Perl_debug_log,
516 "Pad 0x%"UVxf" alloc %ld for %s\n",
518 (long) retval, PL_op_name[optype]));
519 #endif /* USE_THREADS */
520 return (PADOFFSET)retval;
524 Perl_pad_sv(pTHX_ PADOFFSET po)
527 DEBUG_X(PerlIO_printf(Perl_debug_log,
528 "0x%"UVxf" Pad 0x%"UVxf" sv %"IVdf"\n",
529 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
532 Perl_croak(aTHX_ "panic: pad_sv po");
533 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" sv %"IVdf"\n",
534 PTR2UV(PL_curpad), (IV)po));
535 #endif /* USE_THREADS */
536 return PL_curpad[po]; /* eventually we'll turn this into a macro */
540 Perl_pad_free(pTHX_ PADOFFSET po)
544 if (AvARRAY(PL_comppad) != PL_curpad)
545 Perl_croak(aTHX_ "panic: pad_free curpad");
547 Perl_croak(aTHX_ "panic: pad_free po");
549 DEBUG_X(PerlIO_printf(Perl_debug_log,
550 "0x%"UVxf" Pad 0x%"UVxf" free %"IVdf"\n",
551 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
553 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" free %"IVdf"\n",
554 PTR2UV(PL_curpad), (IV)po));
555 #endif /* USE_THREADS */
556 if (PL_curpad[po] && PL_curpad[po] != &PL_sv_undef) {
557 SvPADTMP_off(PL_curpad[po]);
559 SvREADONLY_off(PL_curpad[po]); /* could be a freed constant */
562 if ((I32)po < PL_padix)
567 Perl_pad_swipe(pTHX_ PADOFFSET po)
569 if (AvARRAY(PL_comppad) != PL_curpad)
570 Perl_croak(aTHX_ "panic: pad_swipe curpad");
572 Perl_croak(aTHX_ "panic: pad_swipe po");
574 DEBUG_X(PerlIO_printf(Perl_debug_log,
575 "0x%"UVxf" Pad 0x%"UVxf" swipe %"IVdf"\n",
576 PTR2UV(thr), PTR2UV(PL_curpad), (IV)po));
578 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" swipe %"IVdf"\n",
579 PTR2UV(PL_curpad), (IV)po));
580 #endif /* USE_THREADS */
581 SvPADTMP_off(PL_curpad[po]);
582 PL_curpad[po] = NEWSV(1107,0);
583 SvPADTMP_on(PL_curpad[po]);
584 if ((I32)po < PL_padix)
588 /* XXX pad_reset() is currently disabled because it results in serious bugs.
589 * It causes pad temp TARGs to be shared between OPs. Since TARGs are pushed
590 * on the stack by OPs that use them, there are several ways to get an alias
591 * to a shared TARG. Such an alias will change randomly and unpredictably.
592 * We avoid doing this until we can think of a Better Way.
597 #ifdef USE_BROKEN_PAD_RESET
600 if (AvARRAY(PL_comppad) != PL_curpad)
601 Perl_croak(aTHX_ "panic: pad_reset curpad");
603 DEBUG_X(PerlIO_printf(Perl_debug_log,
604 "0x%"UVxf" Pad 0x%"UVxf" reset\n",
605 PTR2UV(thr), PTR2UV(PL_curpad)));
607 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%"UVxf" reset\n",
609 #endif /* USE_THREADS */
610 if (!PL_tainting) { /* Can't mix tainted and non-tainted temporaries. */
611 for (po = AvMAX(PL_comppad); po > PL_padix_floor; po--) {
612 if (PL_curpad[po] && !SvIMMORTAL(PL_curpad[po]))
613 SvPADTMP_off(PL_curpad[po]);
615 PL_padix = PL_padix_floor;
618 PL_pad_reset_pending = FALSE;
622 /* find_threadsv is not reentrant */
624 Perl_find_threadsv(pTHX_ const char *name)
629 /* We currently only handle names of a single character */
630 p = strchr(PL_threadsv_names, *name);
633 key = p - PL_threadsv_names;
634 MUTEX_LOCK(&thr->mutex);
635 svp = av_fetch(thr->threadsv, key, FALSE);
637 MUTEX_UNLOCK(&thr->mutex);
639 SV *sv = NEWSV(0, 0);
640 av_store(thr->threadsv, key, sv);
641 thr->threadsvp = AvARRAY(thr->threadsv);
642 MUTEX_UNLOCK(&thr->mutex);
644 * Some magic variables used to be automagically initialised
645 * in gv_fetchpv. Those which are now per-thread magicals get
646 * initialised here instead.
652 sv_setpv(sv, "\034");
653 sv_magic(sv, 0, PERL_MAGIC_sv, name, 1);
658 PL_sawampersand = TRUE;
672 /* XXX %! tied to Errno.pm needs to be added here.
673 * See gv_fetchpv(). */
677 sv_magic(sv, 0, PERL_MAGIC_sv, name, 1);
679 DEBUG_S(PerlIO_printf(Perl_error_log,
680 "find_threadsv: new SV %p for $%s%c\n",
681 sv, (*name < 32) ? "^" : "",
682 (*name < 32) ? toCTRL(*name) : *name));
686 #endif /* USE_THREADS */
691 Perl_op_free(pTHX_ OP *o)
693 register OP *kid, *nextkid;
696 if (!o || o->op_seq == (U16)-1)
699 if (o->op_private & OPpREFCOUNTED) {
700 switch (o->op_type) {
708 if (OpREFCNT_dec(o)) {
719 if (o->op_flags & OPf_KIDS) {
720 for (kid = cUNOPo->op_first; kid; kid = nextkid) {
721 nextkid = kid->op_sibling; /* Get before next freeing kid */
729 /* COP* is not cleared by op_clear() so that we may track line
730 * numbers etc even after null() */
731 if (type == OP_NEXTSTATE || type == OP_SETSTATE || type == OP_DBSTATE)
736 #ifdef PL_OP_SLAB_ALLOC
737 if ((char *) o == PL_OpPtr)
746 Perl_op_clear(pTHX_ OP *o)
748 switch (o->op_type) {
749 case OP_NULL: /* Was holding old type, if any. */
750 case OP_ENTEREVAL: /* Was holding hints. */
752 case OP_THREADSV: /* Was holding index into thr->threadsv AV. */
758 if (!(o->op_flags & OPf_SPECIAL))
761 #endif /* USE_THREADS */
763 if (!(o->op_flags & OPf_REF)
764 || (PL_check[o->op_type] != MEMBER_TO_FPTR(Perl_ck_ftst)))
771 if (cPADOPo->op_padix > 0) {
774 pad_swipe(cPADOPo->op_padix);
775 /* No GvIN_PAD_off(gv) here, because other references may still
776 * exist on the pad */
779 cPADOPo->op_padix = 0;
782 SvREFCNT_dec(cSVOPo->op_sv);
783 cSVOPo->op_sv = Nullsv;
786 case OP_METHOD_NAMED:
788 SvREFCNT_dec(cSVOPo->op_sv);
789 cSVOPo->op_sv = Nullsv;
795 if (o->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
799 if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
800 SvREFCNT_dec(cSVOPo->op_sv);
801 cSVOPo->op_sv = Nullsv;
804 Safefree(cPVOPo->op_pv);
805 cPVOPo->op_pv = Nullch;
809 op_free(cPMOPo->op_pmreplroot);
813 if ((PADOFFSET)cPMOPo->op_pmreplroot) {
815 GV *gv = (GV*)PL_curpad[(PADOFFSET)cPMOPo->op_pmreplroot];
816 pad_swipe((PADOFFSET)cPMOPo->op_pmreplroot);
817 /* No GvIN_PAD_off(gv) here, because other references may still
818 * exist on the pad */
823 SvREFCNT_dec((SV*)cPMOPo->op_pmreplroot);
830 HV *pmstash = PmopSTASH(cPMOPo);
831 if (pmstash && SvREFCNT(pmstash)) {
832 PMOP *pmop = HvPMROOT(pmstash);
833 PMOP *lastpmop = NULL;
835 if (cPMOPo == pmop) {
837 lastpmop->op_pmnext = pmop->op_pmnext;
839 HvPMROOT(pmstash) = pmop->op_pmnext;
843 pmop = pmop->op_pmnext;
847 Safefree(PmopSTASHPV(cPMOPo));
849 /* NOTE: PMOP.op_pmstash is not refcounted */
852 cPMOPo->op_pmreplroot = Nullop;
853 ReREFCNT_dec(PM_GETRE(cPMOPo));
854 PM_SETRE(cPMOPo, (REGEXP*)NULL);
858 if (o->op_targ > 0) {
859 pad_free(o->op_targ);
865 S_cop_free(pTHX_ COP* cop)
867 Safefree(cop->cop_label);
869 Safefree(CopFILE(cop)); /* XXX share in a pvtable? */
870 Safefree(CopSTASHPV(cop)); /* XXX share in a pvtable? */
872 /* NOTE: COP.cop_stash is not refcounted */
873 SvREFCNT_dec(CopFILEGV(cop));
875 if (! specialWARN(cop->cop_warnings))
876 SvREFCNT_dec(cop->cop_warnings);
877 if (! specialCopIO(cop->cop_io))
878 SvREFCNT_dec(cop->cop_io);
882 Perl_op_null(pTHX_ OP *o)
884 if (o->op_type == OP_NULL)
887 o->op_targ = o->op_type;
888 o->op_type = OP_NULL;
889 o->op_ppaddr = PL_ppaddr[OP_NULL];
892 /* Contextualizers */
894 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
897 Perl_linklist(pTHX_ OP *o)
904 /* establish postfix order */
905 if (cUNOPo->op_first) {
906 o->op_next = LINKLIST(cUNOPo->op_first);
907 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
909 kid->op_next = LINKLIST(kid->op_sibling);
921 Perl_scalarkids(pTHX_ OP *o)
924 if (o && o->op_flags & OPf_KIDS) {
925 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
932 S_scalarboolean(pTHX_ OP *o)
934 if (o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST) {
935 if (ckWARN(WARN_SYNTAX)) {
936 line_t oldline = CopLINE(PL_curcop);
938 if (PL_copline != NOLINE)
939 CopLINE_set(PL_curcop, PL_copline);
940 Perl_warner(aTHX_ WARN_SYNTAX, "Found = in conditional, should be ==");
941 CopLINE_set(PL_curcop, oldline);
948 Perl_scalar(pTHX_ OP *o)
952 /* assumes no premature commitment */
953 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
954 || o->op_type == OP_RETURN)
959 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_SCALAR;
961 switch (o->op_type) {
963 scalar(cBINOPo->op_first);
968 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
972 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
973 if (!kPMOP->op_pmreplroot)
974 deprecate("implicit split to @_");
982 if (o->op_flags & OPf_KIDS) {
983 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
989 kid = cLISTOPo->op_first;
991 while ((kid = kid->op_sibling)) {
997 WITH_THR(PL_curcop = &PL_compiling);
1002 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
1003 if (kid->op_sibling)
1008 WITH_THR(PL_curcop = &PL_compiling);
1015 Perl_scalarvoid(pTHX_ OP *o)
1022 if (o->op_type == OP_NEXTSTATE
1023 || o->op_type == OP_SETSTATE
1024 || o->op_type == OP_DBSTATE
1025 || (o->op_type == OP_NULL && (o->op_targ == OP_NEXTSTATE
1026 || o->op_targ == OP_SETSTATE
1027 || o->op_targ == OP_DBSTATE)))
1028 PL_curcop = (COP*)o; /* for warning below */
1030 /* assumes no premature commitment */
1031 want = o->op_flags & OPf_WANT;
1032 if ((want && want != OPf_WANT_SCALAR) || PL_error_count
1033 || o->op_type == OP_RETURN)
1038 if ((o->op_private & OPpTARGET_MY)
1039 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
1041 return scalar(o); /* As if inside SASSIGN */
1044 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_VOID;
1046 switch (o->op_type) {
1048 if (!(PL_opargs[o->op_type] & OA_FOLDCONST))
1052 if (o->op_flags & OPf_STACKED)
1056 if (o->op_private == 4)
1098 case OP_GETSOCKNAME:
1099 case OP_GETPEERNAME:
1104 case OP_GETPRIORITY:
1127 if (!(o->op_private & (OPpLVAL_INTRO|OPpOUR_INTRO)))
1128 useless = PL_op_desc[o->op_type];
1135 if (!(o->op_private & (OPpLVAL_INTRO|OPpOUR_INTRO)) &&
1136 (!o->op_sibling || o->op_sibling->op_type != OP_READLINE))
1137 useless = "a variable";
1142 if (cSVOPo->op_private & OPpCONST_STRICT)
1143 no_bareword_allowed(o);
1145 if (ckWARN(WARN_VOID)) {
1146 useless = "a constant";
1147 /* the constants 0 and 1 are permitted as they are
1148 conventionally used as dummies in constructs like
1149 1 while some_condition_with_side_effects; */
1150 if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
1152 else if (SvPOK(sv)) {
1153 /* perl4's way of mixing documentation and code
1154 (before the invention of POD) was based on a
1155 trick to mix nroff and perl code. The trick was
1156 built upon these three nroff macros being used in
1157 void context. The pink camel has the details in
1158 the script wrapman near page 319. */
1159 if (strnEQ(SvPVX(sv), "di", 2) ||
1160 strnEQ(SvPVX(sv), "ds", 2) ||
1161 strnEQ(SvPVX(sv), "ig", 2))
1166 op_null(o); /* don't execute or even remember it */
1170 o->op_type = OP_PREINC; /* pre-increment is faster */
1171 o->op_ppaddr = PL_ppaddr[OP_PREINC];
1175 o->op_type = OP_PREDEC; /* pre-decrement is faster */
1176 o->op_ppaddr = PL_ppaddr[OP_PREDEC];
1182 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1187 if (o->op_flags & OPf_STACKED)
1194 if (!(o->op_flags & OPf_KIDS))
1203 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1210 /* all requires must return a boolean value */
1211 o->op_flags &= ~OPf_WANT;
1216 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
1217 if (!kPMOP->op_pmreplroot)
1218 deprecate("implicit split to @_");
1222 if (useless && ckWARN(WARN_VOID))
1223 Perl_warner(aTHX_ WARN_VOID, "Useless use of %s in void context", useless);
1228 Perl_listkids(pTHX_ OP *o)
1231 if (o && o->op_flags & OPf_KIDS) {
1232 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1239 Perl_list(pTHX_ OP *o)
1243 /* assumes no premature commitment */
1244 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
1245 || o->op_type == OP_RETURN)
1250 if ((o->op_private & OPpTARGET_MY)
1251 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
1253 return o; /* As if inside SASSIGN */
1256 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_LIST;
1258 switch (o->op_type) {
1261 list(cBINOPo->op_first);
1266 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1274 if (!(o->op_flags & OPf_KIDS))
1276 if (!o->op_next && cUNOPo->op_first->op_type == OP_FLOP) {
1277 list(cBINOPo->op_first);
1278 return gen_constant_list(o);
1285 kid = cLISTOPo->op_first;
1287 while ((kid = kid->op_sibling)) {
1288 if (kid->op_sibling)
1293 WITH_THR(PL_curcop = &PL_compiling);
1297 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
1298 if (kid->op_sibling)
1303 WITH_THR(PL_curcop = &PL_compiling);
1306 /* all requires must return a boolean value */
1307 o->op_flags &= ~OPf_WANT;
1314 Perl_scalarseq(pTHX_ OP *o)
1319 if (o->op_type == OP_LINESEQ ||
1320 o->op_type == OP_SCOPE ||
1321 o->op_type == OP_LEAVE ||
1322 o->op_type == OP_LEAVETRY)
1324 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
1325 if (kid->op_sibling) {
1329 PL_curcop = &PL_compiling;
1331 o->op_flags &= ~OPf_PARENS;
1332 if (PL_hints & HINT_BLOCK_SCOPE)
1333 o->op_flags |= OPf_PARENS;
1336 o = newOP(OP_STUB, 0);
1341 S_modkids(pTHX_ OP *o, I32 type)
1344 if (o && o->op_flags & OPf_KIDS) {
1345 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1352 Perl_mod(pTHX_ OP *o, I32 type)
1357 if (!o || PL_error_count)
1360 if ((o->op_private & OPpTARGET_MY)
1361 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
1366 switch (o->op_type) {
1371 if (!(o->op_private & (OPpCONST_ARYBASE)))
1373 if (PL_eval_start && PL_eval_start->op_type == OP_CONST) {
1374 PL_compiling.cop_arybase = (I32)SvIV(cSVOPx(PL_eval_start)->op_sv);
1378 SAVEI32(PL_compiling.cop_arybase);
1379 PL_compiling.cop_arybase = 0;
1381 else if (type == OP_REFGEN)
1384 Perl_croak(aTHX_ "That use of $[ is unsupported");
1387 if (o->op_flags & OPf_PARENS)
1391 if ((type == OP_UNDEF || type == OP_REFGEN) &&
1392 !(o->op_flags & OPf_STACKED)) {
1393 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1394 o->op_ppaddr = PL_ppaddr[OP_RV2CV];
1395 assert(cUNOPo->op_first->op_type == OP_NULL);
1396 op_null(((LISTOP*)cUNOPo->op_first)->op_first);/* disable pushmark */
1399 else { /* lvalue subroutine call */
1400 o->op_private |= OPpLVAL_INTRO;
1401 PL_modcount = RETURN_UNLIMITED_NUMBER;
1402 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN) {
1403 /* Backward compatibility mode: */
1404 o->op_private |= OPpENTERSUB_INARGS;
1407 else { /* Compile-time error message: */
1408 OP *kid = cUNOPo->op_first;
1412 if (kid->op_type == OP_PUSHMARK)
1414 if (kid->op_type != OP_NULL || kid->op_targ != OP_LIST)
1416 "panic: unexpected lvalue entersub "
1417 "args: type/targ %ld:%ld",
1418 (long)kid->op_type,kid->op_targ);
1419 kid = kLISTOP->op_first;
1421 while (kid->op_sibling)
1422 kid = kid->op_sibling;
1423 if (!(kid->op_type == OP_NULL && kid->op_targ == OP_RV2CV)) {
1425 if (kid->op_type == OP_METHOD_NAMED
1426 || kid->op_type == OP_METHOD)
1430 if (kid->op_sibling || kid->op_next != kid) {
1431 yyerror("panic: unexpected optree near method call");
1435 NewOp(1101, newop, 1, UNOP);
1436 newop->op_type = OP_RV2CV;
1437 newop->op_ppaddr = PL_ppaddr[OP_RV2CV];
1438 newop->op_first = Nullop;
1439 newop->op_next = (OP*)newop;
1440 kid->op_sibling = (OP*)newop;
1441 newop->op_private |= OPpLVAL_INTRO;
1445 if (kid->op_type != OP_RV2CV)
1447 "panic: unexpected lvalue entersub "
1448 "entry via type/targ %ld:%ld",
1449 (long)kid->op_type,kid->op_targ);
1450 kid->op_private |= OPpLVAL_INTRO;
1451 break; /* Postpone until runtime */
1455 kid = kUNOP->op_first;
1456 if (kid->op_type == OP_NULL && kid->op_targ == OP_RV2SV)
1457 kid = kUNOP->op_first;
1458 if (kid->op_type == OP_NULL)
1460 "Unexpected constant lvalue entersub "
1461 "entry via type/targ %ld:%ld",
1462 (long)kid->op_type,kid->op_targ);
1463 if (kid->op_type != OP_GV) {
1464 /* Restore RV2CV to check lvalueness */
1466 if (kid->op_next && kid->op_next != kid) { /* Happens? */
1467 okid->op_next = kid->op_next;
1468 kid->op_next = okid;
1471 okid->op_next = Nullop;
1472 okid->op_type = OP_RV2CV;
1474 okid->op_ppaddr = PL_ppaddr[OP_RV2CV];
1475 okid->op_private |= OPpLVAL_INTRO;
1479 cv = GvCV(kGVOP_gv);
1489 /* grep, foreach, subcalls, refgen */
1490 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
1492 yyerror(Perl_form(aTHX_ "Can't modify %s in %s",
1493 (o->op_type == OP_NULL && (o->op_flags & OPf_SPECIAL)
1495 : (o->op_type == OP_ENTERSUB
1496 ? "non-lvalue subroutine call"
1497 : PL_op_desc[o->op_type])),
1498 type ? PL_op_desc[type] : "local"));
1512 case OP_RIGHT_SHIFT:
1521 if (!(o->op_flags & OPf_STACKED))
1527 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1533 if (!type && cUNOPo->op_first->op_type != OP_GV)
1534 Perl_croak(aTHX_ "Can't localize through a reference");
1535 if (type == OP_REFGEN && o->op_flags & OPf_PARENS) {
1536 PL_modcount = RETURN_UNLIMITED_NUMBER;
1537 return o; /* Treat \(@foo) like ordinary list. */
1541 if (scalar_mod_type(o, type))
1543 ref(cUNOPo->op_first, o->op_type);
1547 if (type == OP_LEAVESUBLV)
1548 o->op_private |= OPpMAYBE_LVSUB;
1554 PL_modcount = RETURN_UNLIMITED_NUMBER;
1557 if (!type && cUNOPo->op_first->op_type != OP_GV)
1558 Perl_croak(aTHX_ "Can't localize through a reference");
1559 ref(cUNOPo->op_first, o->op_type);
1563 PL_hints |= HINT_BLOCK_SCOPE;
1573 PL_modcount = RETURN_UNLIMITED_NUMBER;
1574 if (type == OP_REFGEN && o->op_flags & OPf_PARENS)
1575 return o; /* Treat \(@foo) like ordinary list. */
1576 if (scalar_mod_type(o, type))
1578 if (type == OP_LEAVESUBLV)
1579 o->op_private |= OPpMAYBE_LVSUB;
1584 Perl_croak(aTHX_ "Can't localize lexical variable %s",
1585 SvPV(*av_fetch(PL_comppad_name, o->op_targ, 4), n_a));
1590 PL_modcount++; /* XXX ??? */
1592 #endif /* USE_THREADS */
1598 if (type != OP_SASSIGN)
1602 if (o->op_private == 4) /* don't allow 4 arg substr as lvalue */
1607 if (type == OP_LEAVESUBLV)
1608 o->op_private |= OPpMAYBE_LVSUB;
1610 pad_free(o->op_targ);
1611 o->op_targ = pad_alloc(o->op_type, SVs_PADMY);
1612 assert(SvTYPE(PAD_SV(o->op_targ)) == SVt_NULL);
1613 if (o->op_flags & OPf_KIDS)
1614 mod(cBINOPo->op_first->op_sibling, type);
1619 ref(cBINOPo->op_first, o->op_type);
1620 if (type == OP_ENTERSUB &&
1621 !(o->op_private & (OPpLVAL_INTRO | OPpDEREF)))
1622 o->op_private |= OPpLVAL_DEFER;
1623 if (type == OP_LEAVESUBLV)
1624 o->op_private |= OPpMAYBE_LVSUB;
1632 if (o->op_flags & OPf_KIDS)
1633 mod(cLISTOPo->op_last, type);
1637 if (o->op_flags & OPf_SPECIAL) /* do BLOCK */
1639 else if (!(o->op_flags & OPf_KIDS))
1641 if (o->op_targ != OP_LIST) {
1642 mod(cBINOPo->op_first, type);
1647 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1652 if (type != OP_LEAVESUBLV)
1654 break; /* mod()ing was handled by ck_return() */
1656 if (type != OP_LEAVESUBLV)
1657 o->op_flags |= OPf_MOD;
1659 if (type == OP_AASSIGN || type == OP_SASSIGN)
1660 o->op_flags |= OPf_SPECIAL|OPf_REF;
1662 o->op_private |= OPpLVAL_INTRO;
1663 o->op_flags &= ~OPf_SPECIAL;
1664 PL_hints |= HINT_BLOCK_SCOPE;
1666 else if (type != OP_GREPSTART && type != OP_ENTERSUB
1667 && type != OP_LEAVESUBLV)
1668 o->op_flags |= OPf_REF;
1673 S_scalar_mod_type(pTHX_ OP *o, I32 type)
1677 if (o->op_type == OP_RV2GV)
1701 case OP_RIGHT_SHIFT:
1720 S_is_handle_constructor(pTHX_ OP *o, I32 argnum)
1722 switch (o->op_type) {
1730 case OP_SELECT: /* XXX c.f. SelectSaver.pm */
1743 Perl_refkids(pTHX_ OP *o, I32 type)
1746 if (o && o->op_flags & OPf_KIDS) {
1747 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1754 Perl_ref(pTHX_ OP *o, I32 type)
1758 if (!o || PL_error_count)
1761 switch (o->op_type) {
1763 if ((type == OP_EXISTS || type == OP_DEFINED || type == OP_LOCK) &&
1764 !(o->op_flags & OPf_STACKED)) {
1765 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1766 o->op_ppaddr = PL_ppaddr[OP_RV2CV];
1767 assert(cUNOPo->op_first->op_type == OP_NULL);
1768 op_null(((LISTOP*)cUNOPo->op_first)->op_first); /* disable pushmark */
1769 o->op_flags |= OPf_SPECIAL;
1774 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1778 if (type == OP_DEFINED)
1779 o->op_flags |= OPf_SPECIAL; /* don't create GV */
1780 ref(cUNOPo->op_first, o->op_type);
1783 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1784 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1785 : type == OP_RV2HV ? OPpDEREF_HV
1787 o->op_flags |= OPf_MOD;
1792 o->op_flags |= OPf_MOD; /* XXX ??? */
1797 o->op_flags |= OPf_REF;
1800 if (type == OP_DEFINED)
1801 o->op_flags |= OPf_SPECIAL; /* don't create GV */
1802 ref(cUNOPo->op_first, o->op_type);
1807 o->op_flags |= OPf_REF;
1812 if (!(o->op_flags & OPf_KIDS))
1814 ref(cBINOPo->op_first, type);
1818 ref(cBINOPo->op_first, o->op_type);
1819 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1820 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1821 : type == OP_RV2HV ? OPpDEREF_HV
1823 o->op_flags |= OPf_MOD;
1831 if (!(o->op_flags & OPf_KIDS))
1833 ref(cLISTOPo->op_last, type);
1843 S_dup_attrlist(pTHX_ OP *o)
1847 /* An attrlist is either a simple OP_CONST or an OP_LIST with kids,
1848 * where the first kid is OP_PUSHMARK and the remaining ones
1849 * are OP_CONST. We need to push the OP_CONST values.
1851 if (o->op_type == OP_CONST)
1852 rop = newSVOP(OP_CONST, o->op_flags, SvREFCNT_inc(cSVOPo->op_sv));
1854 assert((o->op_type == OP_LIST) && (o->op_flags & OPf_KIDS));
1855 for (o = cLISTOPo->op_first; o; o=o->op_sibling) {
1856 if (o->op_type == OP_CONST)
1857 rop = append_elem(OP_LIST, rop,
1858 newSVOP(OP_CONST, o->op_flags,
1859 SvREFCNT_inc(cSVOPo->op_sv)));
1866 S_apply_attrs(pTHX_ HV *stash, SV *target, OP *attrs)
1870 /* fake up C<use attributes $pkg,$rv,@attrs> */
1871 ENTER; /* need to protect against side-effects of 'use' */
1874 stashsv = newSVpv(HvNAME(stash), 0);
1876 stashsv = &PL_sv_no;
1878 #define ATTRSMODULE "attributes"
1880 Perl_load_module(aTHX_ PERL_LOADMOD_IMPORT_OPS,
1881 newSVpvn(ATTRSMODULE, sizeof(ATTRSMODULE)-1),
1883 prepend_elem(OP_LIST,
1884 newSVOP(OP_CONST, 0, stashsv),
1885 prepend_elem(OP_LIST,
1886 newSVOP(OP_CONST, 0,
1888 dup_attrlist(attrs))));
1893 Perl_apply_attrs_string(pTHX_ char *stashpv, CV *cv,
1894 char *attrstr, STRLEN len)
1899 len = strlen(attrstr);
1903 for (; isSPACE(*attrstr) && len; --len, ++attrstr) ;
1905 char *sstr = attrstr;
1906 for (; !isSPACE(*attrstr) && len; --len, ++attrstr) ;
1907 attrs = append_elem(OP_LIST, attrs,
1908 newSVOP(OP_CONST, 0,
1909 newSVpvn(sstr, attrstr-sstr)));
1913 Perl_load_module(aTHX_ PERL_LOADMOD_IMPORT_OPS,
1914 newSVpvn(ATTRSMODULE, sizeof(ATTRSMODULE)-1),
1915 Nullsv, prepend_elem(OP_LIST,
1916 newSVOP(OP_CONST, 0, newSVpv(stashpv,0)),
1917 prepend_elem(OP_LIST,
1918 newSVOP(OP_CONST, 0,
1924 S_my_kid(pTHX_ OP *o, OP *attrs)
1929 if (!o || PL_error_count)
1933 if (type == OP_LIST) {
1934 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1936 } else if (type == OP_UNDEF) {
1938 } else if (type == OP_RV2SV || /* "our" declaration */
1940 type == OP_RV2HV) { /* XXX does this let anything illegal in? */
1942 GV *gv = cGVOPx_gv(cUNOPo->op_first);
1944 PL_in_my_stash = Nullhv;
1945 apply_attrs(GvSTASH(gv),
1946 (type == OP_RV2SV ? GvSV(gv) :
1947 type == OP_RV2AV ? (SV*)GvAV(gv) :
1948 type == OP_RV2HV ? (SV*)GvHV(gv) : (SV*)gv),
1951 o->op_private |= OPpOUR_INTRO;
1953 } else if (type != OP_PADSV &&
1956 type != OP_PUSHMARK)
1958 yyerror(Perl_form(aTHX_ "Can't declare %s in \"%s\"",
1959 PL_op_desc[o->op_type],
1960 PL_in_my == KEY_our ? "our" : "my"));
1963 else if (attrs && type != OP_PUSHMARK) {
1969 PL_in_my_stash = Nullhv;
1971 /* check for C<my Dog $spot> when deciding package */
1972 namesvp = av_fetch(PL_comppad_name, o->op_targ, FALSE);
1973 if (namesvp && *namesvp && (SvFLAGS(*namesvp) & SVpad_TYPED))
1974 stash = SvSTASH(*namesvp);
1976 stash = PL_curstash;
1977 padsv = PAD_SV(o->op_targ);
1978 apply_attrs(stash, padsv, attrs);
1980 o->op_flags |= OPf_MOD;
1981 o->op_private |= OPpLVAL_INTRO;
1986 Perl_my_attrs(pTHX_ OP *o, OP *attrs)
1988 if (o->op_flags & OPf_PARENS)
1992 o = my_kid(o, attrs);
1994 PL_in_my_stash = Nullhv;
1999 Perl_my(pTHX_ OP *o)
2001 return my_kid(o, Nullop);
2005 Perl_sawparens(pTHX_ OP *o)
2008 o->op_flags |= OPf_PARENS;
2013 Perl_bind_match(pTHX_ I32 type, OP *left, OP *right)
2017 if (ckWARN(WARN_MISC) &&
2018 (left->op_type == OP_RV2AV ||
2019 left->op_type == OP_RV2HV ||
2020 left->op_type == OP_PADAV ||
2021 left->op_type == OP_PADHV)) {
2022 char *desc = PL_op_desc[(right->op_type == OP_SUBST ||
2023 right->op_type == OP_TRANS)
2024 ? right->op_type : OP_MATCH];
2025 const char *sample = ((left->op_type == OP_RV2AV ||
2026 left->op_type == OP_PADAV)
2027 ? "@array" : "%hash");
2028 Perl_warner(aTHX_ WARN_MISC,
2029 "Applying %s to %s will act on scalar(%s)",
2030 desc, sample, sample);
2033 if (!(right->op_flags & OPf_STACKED) &&
2034 (right->op_type == OP_MATCH ||
2035 right->op_type == OP_SUBST ||
2036 right->op_type == OP_TRANS)) {
2037 right->op_flags |= OPf_STACKED;
2038 if ((right->op_type != OP_MATCH &&
2039 ! (right->op_type == OP_TRANS &&
2040 right->op_private & OPpTRANS_IDENTICAL)) ||
2041 /* if SV has magic, then match on original SV, not on its copy.
2042 see note in pp_helem() */
2043 (right->op_type == OP_MATCH &&
2044 (left->op_type == OP_AELEM ||
2045 left->op_type == OP_HELEM ||
2046 left->op_type == OP_AELEMFAST)))
2047 left = mod(left, right->op_type);
2048 if (right->op_type == OP_TRANS)
2049 o = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
2051 o = prepend_elem(right->op_type, scalar(left), right);
2053 return newUNOP(OP_NOT, 0, scalar(o));
2057 return bind_match(type, left,
2058 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
2062 Perl_invert(pTHX_ OP *o)
2066 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
2067 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(o));
2071 Perl_scope(pTHX_ OP *o)
2074 if (o->op_flags & OPf_PARENS || PERLDB_NOOPT || PL_tainting) {
2075 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
2076 o->op_type = OP_LEAVE;
2077 o->op_ppaddr = PL_ppaddr[OP_LEAVE];
2080 if (o->op_type == OP_LINESEQ) {
2082 o->op_type = OP_SCOPE;
2083 o->op_ppaddr = PL_ppaddr[OP_SCOPE];
2084 kid = ((LISTOP*)o)->op_first;
2085 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE)
2089 o = newLISTOP(OP_SCOPE, 0, o, Nullop);
2096 Perl_save_hints(pTHX)
2099 SAVESPTR(GvHV(PL_hintgv));
2100 GvHV(PL_hintgv) = newHVhv(GvHV(PL_hintgv));
2101 SAVEFREESV(GvHV(PL_hintgv));
2105 Perl_block_start(pTHX_ int full)
2107 int retval = PL_savestack_ix;
2109 SAVEI32(PL_comppad_name_floor);
2110 PL_comppad_name_floor = AvFILLp(PL_comppad_name);
2112 PL_comppad_name_fill = PL_comppad_name_floor;
2113 if (PL_comppad_name_floor < 0)
2114 PL_comppad_name_floor = 0;
2115 SAVEI32(PL_min_intro_pending);
2116 SAVEI32(PL_max_intro_pending);
2117 PL_min_intro_pending = 0;
2118 SAVEI32(PL_comppad_name_fill);
2119 SAVEI32(PL_padix_floor);
2120 PL_padix_floor = PL_padix;
2121 PL_pad_reset_pending = FALSE;
2123 PL_hints &= ~HINT_BLOCK_SCOPE;
2124 SAVESPTR(PL_compiling.cop_warnings);
2125 if (! specialWARN(PL_compiling.cop_warnings)) {
2126 PL_compiling.cop_warnings = newSVsv(PL_compiling.cop_warnings) ;
2127 SAVEFREESV(PL_compiling.cop_warnings) ;
2129 SAVESPTR(PL_compiling.cop_io);
2130 if (! specialCopIO(PL_compiling.cop_io)) {
2131 PL_compiling.cop_io = newSVsv(PL_compiling.cop_io) ;
2132 SAVEFREESV(PL_compiling.cop_io) ;
2138 Perl_block_end(pTHX_ I32 floor, OP *seq)
2140 int needblockscope = PL_hints & HINT_BLOCK_SCOPE;
2141 OP* retval = scalarseq(seq);
2143 PL_pad_reset_pending = FALSE;
2144 PL_compiling.op_private = PL_hints;
2146 PL_hints |= HINT_BLOCK_SCOPE; /* propagate out */
2147 pad_leavemy(PL_comppad_name_fill);
2156 OP *o = newOP(OP_THREADSV, 0);
2157 o->op_targ = find_threadsv("_");
2160 return newSVREF(newGVOP(OP_GV, 0, PL_defgv));
2161 #endif /* USE_THREADS */
2165 Perl_newPROG(pTHX_ OP *o)
2170 PL_eval_root = newUNOP(OP_LEAVEEVAL,
2171 ((PL_in_eval & EVAL_KEEPERR)
2172 ? OPf_SPECIAL : 0), o);
2173 PL_eval_start = linklist(PL_eval_root);
2174 PL_eval_root->op_private |= OPpREFCOUNTED;
2175 OpREFCNT_set(PL_eval_root, 1);
2176 PL_eval_root->op_next = 0;
2177 peep(PL_eval_start);
2182 PL_main_root = scope(sawparens(scalarvoid(o)));
2183 PL_curcop = &PL_compiling;
2184 PL_main_start = LINKLIST(PL_main_root);
2185 PL_main_root->op_private |= OPpREFCOUNTED;
2186 OpREFCNT_set(PL_main_root, 1);
2187 PL_main_root->op_next = 0;
2188 peep(PL_main_start);
2191 /* Register with debugger */
2193 CV *cv = get_cv("DB::postponed", FALSE);
2197 XPUSHs((SV*)CopFILEGV(&PL_compiling));
2199 call_sv((SV*)cv, G_DISCARD);
2206 Perl_localize(pTHX_ OP *o, I32 lex)
2208 if (o->op_flags & OPf_PARENS)
2211 if (ckWARN(WARN_PARENTHESIS) && PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == ',') {
2213 for (s = PL_bufptr; *s && (isALNUM(*s) || UTF8_IS_CONTINUED(*s) || strchr("@$%, ",*s)); s++) ;
2214 if (*s == ';' || *s == '=')
2215 Perl_warner(aTHX_ WARN_PARENTHESIS,
2216 "Parentheses missing around \"%s\" list",
2217 lex ? (PL_in_my == KEY_our ? "our" : "my") : "local");
2223 o = mod(o, OP_NULL); /* a bit kludgey */
2225 PL_in_my_stash = Nullhv;
2230 Perl_jmaybe(pTHX_ OP *o)
2232 if (o->op_type == OP_LIST) {
2235 o2 = newOP(OP_THREADSV, 0);
2236 o2->op_targ = find_threadsv(";");
2238 o2 = newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
2239 #endif /* USE_THREADS */
2240 o = convert(OP_JOIN, 0, prepend_elem(OP_LIST, o2, o));
2246 Perl_fold_constants(pTHX_ register OP *o)
2249 I32 type = o->op_type;
2252 if (PL_opargs[type] & OA_RETSCALAR)
2254 if (PL_opargs[type] & OA_TARGET && !o->op_targ)
2255 o->op_targ = pad_alloc(type, SVs_PADTMP);
2257 /* integerize op, unless it happens to be C<-foo>.
2258 * XXX should pp_i_negate() do magic string negation instead? */
2259 if ((PL_opargs[type] & OA_OTHERINT) && (PL_hints & HINT_INTEGER)
2260 && !(type == OP_NEGATE && cUNOPo->op_first->op_type == OP_CONST
2261 && (cUNOPo->op_first->op_private & OPpCONST_BARE)))
2263 o->op_ppaddr = PL_ppaddr[type = ++(o->op_type)];
2266 if (!(PL_opargs[type] & OA_FOLDCONST))
2271 /* XXX might want a ck_negate() for this */
2272 cUNOPo->op_first->op_private &= ~OPpCONST_STRICT;
2284 /* XXX what about the numeric ops? */
2285 if (PL_hints & HINT_LOCALE)
2290 goto nope; /* Don't try to run w/ errors */
2292 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
2293 if ((curop->op_type != OP_CONST ||
2294 (curop->op_private & OPpCONST_BARE)) &&
2295 curop->op_type != OP_LIST &&
2296 curop->op_type != OP_SCALAR &&
2297 curop->op_type != OP_NULL &&
2298 curop->op_type != OP_PUSHMARK)
2304 curop = LINKLIST(o);
2308 sv = *(PL_stack_sp--);
2309 if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
2310 pad_swipe(o->op_targ);
2311 else if (SvTEMP(sv)) { /* grab mortal temp? */
2312 (void)SvREFCNT_inc(sv);
2316 if (type == OP_RV2GV)
2317 return newGVOP(OP_GV, 0, (GV*)sv);
2319 /* try to smush double to int, but don't smush -2.0 to -2 */
2320 if ((SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK)) == SVf_NOK &&
2323 #ifdef PERL_PRESERVE_IVUV
2324 /* Only bother to attempt to fold to IV if
2325 most operators will benefit */
2329 o = newSVOP(OP_CONST, 0, sv);
2330 /* We don't want folded constants to trigger OCTMODE warnings,
2331 so we cheat a bit and mark them OCTAL. AMS 20010709 */
2332 o->op_private |= OPpCONST_OCTAL;
2337 if (!(PL_opargs[type] & OA_OTHERINT))
2340 if (!(PL_hints & HINT_INTEGER)) {
2341 if (type == OP_MODULO
2342 || type == OP_DIVIDE
2343 || !(o->op_flags & OPf_KIDS))
2348 for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
2349 if (curop->op_type == OP_CONST) {
2350 if (SvIOK(((SVOP*)curop)->op_sv))
2354 if (PL_opargs[curop->op_type] & OA_RETINTEGER)
2358 o->op_ppaddr = PL_ppaddr[++(o->op_type)];
2365 Perl_gen_constant_list(pTHX_ register OP *o)
2368 I32 oldtmps_floor = PL_tmps_floor;
2372 return o; /* Don't attempt to run with errors */
2374 PL_op = curop = LINKLIST(o);
2381 PL_tmps_floor = oldtmps_floor;
2383 o->op_type = OP_RV2AV;
2384 o->op_ppaddr = PL_ppaddr[OP_RV2AV];
2385 curop = ((UNOP*)o)->op_first;
2386 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*PL_stack_sp--));
2393 Perl_convert(pTHX_ I32 type, I32 flags, OP *o)
2395 if (!o || o->op_type != OP_LIST)
2396 o = newLISTOP(OP_LIST, 0, o, Nullop);
2398 o->op_flags &= ~OPf_WANT;
2400 if (!(PL_opargs[type] & OA_MARK))
2401 op_null(cLISTOPo->op_first);
2404 o->op_ppaddr = PL_ppaddr[type];
2405 o->op_flags |= flags;
2407 o = CHECKOP(type, o);
2408 if (o->op_type != type)
2411 return fold_constants(o);
2414 /* List constructors */
2417 Perl_append_elem(pTHX_ I32 type, OP *first, OP *last)
2425 if (first->op_type != type
2426 || (type == OP_LIST && (first->op_flags & OPf_PARENS)))
2428 return newLISTOP(type, 0, first, last);
2431 if (first->op_flags & OPf_KIDS)
2432 ((LISTOP*)first)->op_last->op_sibling = last;
2434 first->op_flags |= OPf_KIDS;
2435 ((LISTOP*)first)->op_first = last;
2437 ((LISTOP*)first)->op_last = last;
2442 Perl_append_list(pTHX_ I32 type, LISTOP *first, LISTOP *last)
2450 if (first->op_type != type)
2451 return prepend_elem(type, (OP*)first, (OP*)last);
2453 if (last->op_type != type)
2454 return append_elem(type, (OP*)first, (OP*)last);
2456 first->op_last->op_sibling = last->op_first;
2457 first->op_last = last->op_last;
2458 first->op_flags |= (last->op_flags & OPf_KIDS);
2460 #ifdef PL_OP_SLAB_ALLOC
2468 Perl_prepend_elem(pTHX_ I32 type, OP *first, OP *last)
2476 if (last->op_type == type) {
2477 if (type == OP_LIST) { /* already a PUSHMARK there */
2478 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
2479 ((LISTOP*)last)->op_first->op_sibling = first;
2480 if (!(first->op_flags & OPf_PARENS))
2481 last->op_flags &= ~OPf_PARENS;
2484 if (!(last->op_flags & OPf_KIDS)) {
2485 ((LISTOP*)last)->op_last = first;
2486 last->op_flags |= OPf_KIDS;
2488 first->op_sibling = ((LISTOP*)last)->op_first;
2489 ((LISTOP*)last)->op_first = first;
2491 last->op_flags |= OPf_KIDS;
2495 return newLISTOP(type, 0, first, last);
2501 Perl_newNULLLIST(pTHX)
2503 return newOP(OP_STUB, 0);
2507 Perl_force_list(pTHX_ OP *o)
2509 if (!o || o->op_type != OP_LIST)
2510 o = newLISTOP(OP_LIST, 0, o, Nullop);
2516 Perl_newLISTOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
2520 NewOp(1101, listop, 1, LISTOP);
2522 listop->op_type = type;
2523 listop->op_ppaddr = PL_ppaddr[type];
2526 listop->op_flags = flags;
2530 else if (!first && last)
2533 first->op_sibling = last;
2534 listop->op_first = first;
2535 listop->op_last = last;
2536 if (type == OP_LIST) {
2538 pushop = newOP(OP_PUSHMARK, 0);
2539 pushop->op_sibling = first;
2540 listop->op_first = pushop;
2541 listop->op_flags |= OPf_KIDS;
2543 listop->op_last = pushop;
2550 Perl_newOP(pTHX_ I32 type, I32 flags)
2553 NewOp(1101, o, 1, OP);
2555 o->op_ppaddr = PL_ppaddr[type];
2556 o->op_flags = flags;
2559 o->op_private = 0 + (flags >> 8);
2560 if (PL_opargs[type] & OA_RETSCALAR)
2562 if (PL_opargs[type] & OA_TARGET)
2563 o->op_targ = pad_alloc(type, SVs_PADTMP);
2564 return CHECKOP(type, o);
2568 Perl_newUNOP(pTHX_ I32 type, I32 flags, OP *first)
2573 first = newOP(OP_STUB, 0);
2574 if (PL_opargs[type] & OA_MARK)
2575 first = force_list(first);
2577 NewOp(1101, unop, 1, UNOP);
2578 unop->op_type = type;
2579 unop->op_ppaddr = PL_ppaddr[type];
2580 unop->op_first = first;
2581 unop->op_flags = flags | OPf_KIDS;
2582 unop->op_private = 1 | (flags >> 8);
2583 unop = (UNOP*) CHECKOP(type, unop);
2587 return fold_constants((OP *) unop);
2591 Perl_newBINOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
2594 NewOp(1101, binop, 1, BINOP);
2597 first = newOP(OP_NULL, 0);
2599 binop->op_type = type;
2600 binop->op_ppaddr = PL_ppaddr[type];
2601 binop->op_first = first;
2602 binop->op_flags = flags | OPf_KIDS;
2605 binop->op_private = 1 | (flags >> 8);
2608 binop->op_private = 2 | (flags >> 8);
2609 first->op_sibling = last;
2612 binop = (BINOP*)CHECKOP(type, binop);
2613 if (binop->op_next || binop->op_type != type)
2616 binop->op_last = binop->op_first->op_sibling;
2618 return fold_constants((OP *)binop);
2622 uvcompare(const void *a, const void *b)
2624 if (*((UV *)a) < (*(UV *)b))
2626 if (*((UV *)a) > (*(UV *)b))
2628 if (*((UV *)a+1) < (*(UV *)b+1))
2630 if (*((UV *)a+1) > (*(UV *)b+1))
2636 Perl_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
2638 SV *tstr = ((SVOP*)expr)->op_sv;
2639 SV *rstr = ((SVOP*)repl)->op_sv;
2642 U8 *t = (U8*)SvPV(tstr, tlen);
2643 U8 *r = (U8*)SvPV(rstr, rlen);
2650 register short *tbl;
2652 PL_hints |= HINT_BLOCK_SCOPE;
2653 complement = o->op_private & OPpTRANS_COMPLEMENT;
2654 del = o->op_private & OPpTRANS_DELETE;
2655 squash = o->op_private & OPpTRANS_SQUASH;
2658 o->op_private |= OPpTRANS_FROM_UTF;
2661 o->op_private |= OPpTRANS_TO_UTF;
2663 if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
2664 SV* listsv = newSVpvn("# comment\n",10);
2666 U8* tend = t + tlen;
2667 U8* rend = r + rlen;
2681 I32 from_utf = o->op_private & OPpTRANS_FROM_UTF;
2682 I32 to_utf = o->op_private & OPpTRANS_TO_UTF;
2688 tsave = t = bytes_to_utf8(t, &len);
2691 if (!to_utf && rlen) {
2693 rsave = r = bytes_to_utf8(r, &len);
2697 /* There are several snags with this code on EBCDIC:
2698 1. 0xFF is a legal UTF-EBCDIC byte (there are no illegal bytes).
2699 2. scan_const() in toke.c has encoded chars in native encoding which makes
2700 ranges at least in EBCDIC 0..255 range the bottom odd.
2704 U8 tmpbuf[UTF8_MAXLEN+1];
2707 New(1109, cp, 2*tlen, UV);
2709 transv = newSVpvn("",0);
2711 cp[2*i] = utf8n_to_uvuni(t, tend-t, &ulen, 0);
2713 if (t < tend && NATIVE_TO_UTF(*t) == 0xff) {
2715 cp[2*i+1] = utf8n_to_uvuni(t, tend-t, &ulen, 0);
2719 cp[2*i+1] = cp[2*i];
2723 qsort(cp, i, 2*sizeof(UV), uvcompare);
2724 for (j = 0; j < i; j++) {
2726 diff = val - nextmin;
2728 t = uvuni_to_utf8(tmpbuf,nextmin);
2729 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2731 U8 range_mark = UTF_TO_NATIVE(0xff);
2732 t = uvuni_to_utf8(tmpbuf, val - 1);
2733 sv_catpvn(transv, (char *)&range_mark, 1);
2734 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2741 t = uvuni_to_utf8(tmpbuf,nextmin);
2742 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2744 U8 range_mark = UTF_TO_NATIVE(0xff);
2745 sv_catpvn(transv, (char *)&range_mark, 1);
2747 t = uvuni_to_utf8(tmpbuf, 0x7fffffff);
2748 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2749 t = (U8*)SvPVX(transv);
2750 tlen = SvCUR(transv);
2754 else if (!rlen && !del) {
2755 r = t; rlen = tlen; rend = tend;
2758 if ((!rlen && !del) || t == r ||
2759 (tlen == rlen && memEQ((char *)t, (char *)r, tlen)))
2761 o->op_private |= OPpTRANS_IDENTICAL;
2765 while (t < tend || tfirst <= tlast) {
2766 /* see if we need more "t" chars */
2767 if (tfirst > tlast) {
2768 tfirst = (I32)utf8n_to_uvuni(t, tend - t, &ulen, 0);
2770 if (t < tend && NATIVE_TO_UTF(*t) == 0xff) { /* illegal utf8 val indicates range */
2772 tlast = (I32)utf8n_to_uvuni(t, tend - t, &ulen, 0);
2779 /* now see if we need more "r" chars */
2780 if (rfirst > rlast) {
2782 rfirst = (I32)utf8n_to_uvuni(r, rend - r, &ulen, 0);
2784 if (r < rend && NATIVE_TO_UTF(*r) == 0xff) { /* illegal utf8 val indicates range */
2786 rlast = (I32)utf8n_to_uvuni(r, rend - r, &ulen, 0);
2795 rfirst = rlast = 0xffffffff;
2799 /* now see which range will peter our first, if either. */
2800 tdiff = tlast - tfirst;
2801 rdiff = rlast - rfirst;
2808 if (rfirst == 0xffffffff) {
2809 diff = tdiff; /* oops, pretend rdiff is infinite */
2811 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t%04lx\tXXXX\n",
2812 (long)tfirst, (long)tlast);
2814 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t\tXXXX\n", (long)tfirst);
2818 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t%04lx\t%04lx\n",
2819 (long)tfirst, (long)(tfirst + diff),
2822 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t\t%04lx\n",
2823 (long)tfirst, (long)rfirst);
2825 if (rfirst + diff > max)
2826 max = rfirst + diff;
2828 grows = (tfirst < rfirst &&
2829 UNISKIP(tfirst) < UNISKIP(rfirst + diff));
2841 else if (max > 0xff)
2846 Safefree(cPVOPo->op_pv);
2847 cSVOPo->op_sv = (SV*)swash_init("utf8", "", listsv, bits, none);
2848 SvREFCNT_dec(listsv);
2850 SvREFCNT_dec(transv);
2852 if (!del && havefinal && rlen)
2853 (void)hv_store((HV*)SvRV((cSVOPo->op_sv)), "FINAL", 5,
2854 newSVuv((UV)final), 0);
2857 o->op_private |= OPpTRANS_GROWS;
2869 tbl = (short*)cPVOPo->op_pv;
2871 Zero(tbl, 256, short);
2872 for (i = 0; i < tlen; i++)
2874 for (i = 0, j = 0; i < 256; i++) {
2885 if (i < 128 && r[j] >= 128)
2895 o->op_private |= OPpTRANS_IDENTICAL;
2900 cPVOPo->op_pv = (char*)Renew(tbl, 0x101+rlen-j, short);
2901 tbl[0x100] = rlen - j;
2902 for (i=0; i < rlen - j; i++)
2903 tbl[0x101+i] = r[j+i];
2907 if (!rlen && !del) {
2910 o->op_private |= OPpTRANS_IDENTICAL;
2912 for (i = 0; i < 256; i++)
2914 for (i = 0, j = 0; i < tlen; i++,j++) {
2917 if (tbl[t[i]] == -1)
2923 if (tbl[t[i]] == -1) {
2924 if (t[i] < 128 && r[j] >= 128)
2931 o->op_private |= OPpTRANS_GROWS;
2939 Perl_newPMOP(pTHX_ I32 type, I32 flags)
2943 NewOp(1101, pmop, 1, PMOP);
2944 pmop->op_type = type;
2945 pmop->op_ppaddr = PL_ppaddr[type];
2946 pmop->op_flags = flags;
2947 pmop->op_private = 0 | (flags >> 8);
2949 if (PL_hints & HINT_RE_TAINT)
2950 pmop->op_pmpermflags |= PMf_RETAINT;
2951 if (PL_hints & HINT_LOCALE)
2952 pmop->op_pmpermflags |= PMf_LOCALE;
2953 pmop->op_pmflags = pmop->op_pmpermflags;
2957 SV* repointer = newSViv(0);
2958 av_push(PL_regex_padav,repointer);
2959 pmop->op_pmoffset = av_len(PL_regex_padav);
2960 PL_regex_pad = AvARRAY(PL_regex_padav);
2964 /* link into pm list */
2965 if (type != OP_TRANS && PL_curstash) {
2966 pmop->op_pmnext = HvPMROOT(PL_curstash);
2967 HvPMROOT(PL_curstash) = pmop;
2968 PmopSTASH_set(pmop,PL_curstash);
2975 Perl_pmruntime(pTHX_ OP *o, OP *expr, OP *repl)
2979 I32 repl_has_vars = 0;
2981 if (o->op_type == OP_TRANS)
2982 return pmtrans(o, expr, repl);
2984 PL_hints |= HINT_BLOCK_SCOPE;
2987 if (expr->op_type == OP_CONST) {
2989 SV *pat = ((SVOP*)expr)->op_sv;
2990 char *p = SvPV(pat, plen);
2991 if ((o->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
2992 sv_setpvn(pat, "\\s+", 3);
2993 p = SvPV(pat, plen);
2994 pm->op_pmflags |= PMf_SKIPWHITE;
2996 if ((PL_hints & HINT_UTF8) || DO_UTF8(pat))
2997 pm->op_pmdynflags |= PMdf_UTF8;
2998 PM_SETRE(pm, CALLREGCOMP(aTHX_ p, p + plen, pm));
2999 if (strEQ("\\s+", PM_GETRE(pm)->precomp))
3000 pm->op_pmflags |= PMf_WHITE;
3004 if (PL_hints & HINT_UTF8)
3005 pm->op_pmdynflags |= PMdf_UTF8;
3006 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL))
3007 expr = newUNOP((!(PL_hints & HINT_RE_EVAL)
3009 : OP_REGCMAYBE),0,expr);
3011 NewOp(1101, rcop, 1, LOGOP);
3012 rcop->op_type = OP_REGCOMP;
3013 rcop->op_ppaddr = PL_ppaddr[OP_REGCOMP];
3014 rcop->op_first = scalar(expr);
3015 rcop->op_flags |= ((PL_hints & HINT_RE_EVAL)
3016 ? (OPf_SPECIAL | OPf_KIDS)
3018 rcop->op_private = 1;
3021 /* establish postfix order */
3022 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL)) {
3024 rcop->op_next = expr;
3025 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
3028 rcop->op_next = LINKLIST(expr);
3029 expr->op_next = (OP*)rcop;
3032 prepend_elem(o->op_type, scalar((OP*)rcop), o);
3037 if (pm->op_pmflags & PMf_EVAL) {
3039 if (CopLINE(PL_curcop) < PL_multi_end)
3040 CopLINE_set(PL_curcop, PL_multi_end);
3043 else if (repl->op_type == OP_THREADSV
3044 && strchr("&`'123456789+",
3045 PL_threadsv_names[repl->op_targ]))
3049 #endif /* USE_THREADS */
3050 else if (repl->op_type == OP_CONST)
3054 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
3055 if (PL_opargs[curop->op_type] & OA_DANGEROUS) {
3057 if (curop->op_type == OP_THREADSV) {
3059 if (strchr("&`'123456789+", curop->op_private))
3063 if (curop->op_type == OP_GV) {
3064 GV *gv = cGVOPx_gv(curop);
3066 if (strchr("&`'123456789+", *GvENAME(gv)))
3069 #endif /* USE_THREADS */
3070 else if (curop->op_type == OP_RV2CV)
3072 else if (curop->op_type == OP_RV2SV ||
3073 curop->op_type == OP_RV2AV ||
3074 curop->op_type == OP_RV2HV ||
3075 curop->op_type == OP_RV2GV) {
3076 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
3079 else if (curop->op_type == OP_PADSV ||
3080 curop->op_type == OP_PADAV ||
3081 curop->op_type == OP_PADHV ||
3082 curop->op_type == OP_PADANY) {
3085 else if (curop->op_type == OP_PUSHRE)
3086 ; /* Okay here, dangerous in newASSIGNOP */
3096 || PM_GETRE(pm)->reganch & ROPT_EVAL_SEEN))) {
3097 pm->op_pmflags |= PMf_CONST; /* const for long enough */
3098 pm->op_pmpermflags |= PMf_CONST; /* const for long enough */
3099 prepend_elem(o->op_type, scalar(repl), o);
3102 if (curop == repl && !PM_GETRE(pm)) { /* Has variables. */
3103 pm->op_pmflags |= PMf_MAYBE_CONST;
3104 pm->op_pmpermflags |= PMf_MAYBE_CONST;
3106 NewOp(1101, rcop, 1, LOGOP);
3107 rcop->op_type = OP_SUBSTCONT;
3108 rcop->op_ppaddr = PL_ppaddr[OP_SUBSTCONT];
3109 rcop->op_first = scalar(repl);
3110 rcop->op_flags |= OPf_KIDS;
3111 rcop->op_private = 1;
3114 /* establish postfix order */
3115 rcop->op_next = LINKLIST(repl);
3116 repl->op_next = (OP*)rcop;
3118 pm->op_pmreplroot = scalar((OP*)rcop);
3119 pm->op_pmreplstart = LINKLIST(rcop);
3128 Perl_newSVOP(pTHX_ I32 type, I32 flags, SV *sv)
3131 NewOp(1101, svop, 1, SVOP);
3132 svop->op_type = type;
3133 svop->op_ppaddr = PL_ppaddr[type];
3135 svop->op_next = (OP*)svop;
3136 svop->op_flags = flags;
3137 if (PL_opargs[type] & OA_RETSCALAR)
3139 if (PL_opargs[type] & OA_TARGET)
3140 svop->op_targ = pad_alloc(type, SVs_PADTMP);
3141 return CHECKOP(type, svop);
3145 Perl_newPADOP(pTHX_ I32 type, I32 flags, SV *sv)
3148 NewOp(1101, padop, 1, PADOP);
3149 padop->op_type = type;
3150 padop->op_ppaddr = PL_ppaddr[type];
3151 padop->op_padix = pad_alloc(type, SVs_PADTMP);
3152 SvREFCNT_dec(PL_curpad[padop->op_padix]);
3153 PL_curpad[padop->op_padix] = sv;
3155 padop->op_next = (OP*)padop;
3156 padop->op_flags = flags;
3157 if (PL_opargs[type] & OA_RETSCALAR)
3159 if (PL_opargs[type] & OA_TARGET)
3160 padop->op_targ = pad_alloc(type, SVs_PADTMP);
3161 return CHECKOP(type, padop);
3165 Perl_newGVOP(pTHX_ I32 type, I32 flags, GV *gv)
3169 return newPADOP(type, flags, SvREFCNT_inc(gv));
3171 return newSVOP(type, flags, SvREFCNT_inc(gv));
3176 Perl_newPVOP(pTHX_ I32 type, I32 flags, char *pv)
3179 NewOp(1101, pvop, 1, PVOP);
3180 pvop->op_type = type;
3181 pvop->op_ppaddr = PL_ppaddr[type];
3183 pvop->op_next = (OP*)pvop;
3184 pvop->op_flags = flags;
3185 if (PL_opargs[type] & OA_RETSCALAR)
3187 if (PL_opargs[type] & OA_TARGET)
3188 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
3189 return CHECKOP(type, pvop);
3193 Perl_package(pTHX_ OP *o)
3197 save_hptr(&PL_curstash);
3198 save_item(PL_curstname);
3203 name = SvPV(sv, len);
3204 PL_curstash = gv_stashpvn(name,len,TRUE);
3205 sv_setpvn(PL_curstname, name, len);
3209 deprecate("\"package\" with no arguments");
3210 sv_setpv(PL_curstname,"<none>");
3211 PL_curstash = Nullhv;
3213 PL_hints |= HINT_BLOCK_SCOPE;
3214 PL_copline = NOLINE;
3219 Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *id, OP *arg)
3225 if (id->op_type != OP_CONST)
3226 Perl_croak(aTHX_ "Module name must be constant");
3230 if (version != Nullop) {
3231 SV *vesv = ((SVOP*)version)->op_sv;
3233 if (arg == Nullop && !SvNIOKp(vesv)) {
3240 if (version->op_type != OP_CONST || !SvNIOKp(vesv))
3241 Perl_croak(aTHX_ "Version number must be constant number");
3243 /* Make copy of id so we don't free it twice */
3244 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
3246 /* Fake up a method call to VERSION */
3247 meth = newSVpvn("VERSION",7);
3248 sv_upgrade(meth, SVt_PVIV);
3249 (void)SvIOK_on(meth);
3250 PERL_HASH(SvUVX(meth), SvPVX(meth), SvCUR(meth));
3251 veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
3252 append_elem(OP_LIST,
3253 prepend_elem(OP_LIST, pack, list(version)),
3254 newSVOP(OP_METHOD_NAMED, 0, meth)));
3258 /* Fake up an import/unimport */
3259 if (arg && arg->op_type == OP_STUB)
3260 imop = arg; /* no import on explicit () */
3261 else if (SvNIOKp(((SVOP*)id)->op_sv)) {
3262 imop = Nullop; /* use 5.0; */
3267 /* Make copy of id so we don't free it twice */
3268 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
3270 /* Fake up a method call to import/unimport */
3271 meth = aver ? newSVpvn("import",6) : newSVpvn("unimport", 8);;
3272 sv_upgrade(meth, SVt_PVIV);
3273 (void)SvIOK_on(meth);
3274 PERL_HASH(SvUVX(meth), SvPVX(meth), SvCUR(meth));
3275 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
3276 append_elem(OP_LIST,
3277 prepend_elem(OP_LIST, pack, list(arg)),
3278 newSVOP(OP_METHOD_NAMED, 0, meth)));
3281 /* Fake up the BEGIN {}, which does its thing immediately. */
3283 newSVOP(OP_CONST, 0, newSVpvn("BEGIN", 5)),
3286 append_elem(OP_LINESEQ,
3287 append_elem(OP_LINESEQ,
3288 newSTATEOP(0, Nullch, newUNOP(OP_REQUIRE, 0, id)),
3289 newSTATEOP(0, Nullch, veop)),
3290 newSTATEOP(0, Nullch, imop) ));
3292 PL_hints |= HINT_BLOCK_SCOPE;
3293 PL_copline = NOLINE;
3298 =for apidoc load_module
3300 Loads the module whose name is pointed to by the string part of name.
3301 Note that the actual module name, not its filename, should be given.
3302 Eg, "Foo::Bar" instead of "Foo/Bar.pm". flags can be any of
3303 PERL_LOADMOD_DENY, PERL_LOADMOD_NOIMPORT, or PERL_LOADMOD_IMPORT_OPS
3304 (or 0 for no flags). ver, if specified, provides version semantics
3305 similar to C<use Foo::Bar VERSION>. The optional trailing SV*
3306 arguments can be used to specify arguments to the module's import()
3307 method, similar to C<use Foo::Bar VERSION LIST>.
3312 Perl_load_module(pTHX_ U32 flags, SV *name, SV *ver, ...)
3315 va_start(args, ver);
3316 vload_module(flags, name, ver, &args);
3320 #ifdef PERL_IMPLICIT_CONTEXT
3322 Perl_load_module_nocontext(U32 flags, SV *name, SV *ver, ...)
3326 va_start(args, ver);
3327 vload_module(flags, name, ver, &args);
3333 Perl_vload_module(pTHX_ U32 flags, SV *name, SV *ver, va_list *args)
3335 OP *modname, *veop, *imop;
3337 modname = newSVOP(OP_CONST, 0, name);
3338 modname->op_private |= OPpCONST_BARE;
3340 veop = newSVOP(OP_CONST, 0, ver);
3344 if (flags & PERL_LOADMOD_NOIMPORT) {
3345 imop = sawparens(newNULLLIST());
3347 else if (flags & PERL_LOADMOD_IMPORT_OPS) {
3348 imop = va_arg(*args, OP*);
3353 sv = va_arg(*args, SV*);
3355 imop = append_elem(OP_LIST, imop, newSVOP(OP_CONST, 0, sv));
3356 sv = va_arg(*args, SV*);
3360 line_t ocopline = PL_copline;
3361 int oexpect = PL_expect;
3363 utilize(!(flags & PERL_LOADMOD_DENY), start_subparse(FALSE, 0),
3364 veop, modname, imop);
3365 PL_expect = oexpect;
3366 PL_copline = ocopline;
3371 Perl_dofile(pTHX_ OP *term)
3376 gv = gv_fetchpv("do", FALSE, SVt_PVCV);
3377 if (!(gv && GvIMPORTED_CV(gv)))
3378 gv = gv_fetchpv("CORE::GLOBAL::do", FALSE, SVt_PVCV);
3380 if (gv && GvIMPORTED_CV(gv)) {
3381 doop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
3382 append_elem(OP_LIST, term,
3383 scalar(newUNOP(OP_RV2CV, 0,
3388 doop = newUNOP(OP_DOFILE, 0, scalar(term));
3394 Perl_newSLICEOP(pTHX_ I32 flags, OP *subscript, OP *listval)
3396 return newBINOP(OP_LSLICE, flags,
3397 list(force_list(subscript)),
3398 list(force_list(listval)) );
3402 S_list_assignment(pTHX_ register OP *o)
3407 if (o->op_type == OP_NULL && o->op_flags & OPf_KIDS)
3408 o = cUNOPo->op_first;
3410 if (o->op_type == OP_COND_EXPR) {
3411 I32 t = list_assignment(cLOGOPo->op_first->op_sibling);
3412 I32 f = list_assignment(cLOGOPo->op_first->op_sibling->op_sibling);
3417 yyerror("Assignment to both a list and a scalar");
3421 if (o->op_type == OP_LIST || o->op_flags & OPf_PARENS ||
3422 o->op_type == OP_RV2AV || o->op_type == OP_RV2HV ||
3423 o->op_type == OP_ASLICE || o->op_type == OP_HSLICE)
3426 if (o->op_type == OP_PADAV || o->op_type == OP_PADHV)
3429 if (o->op_type == OP_RV2SV)
3436 Perl_newASSIGNOP(pTHX_ I32 flags, OP *left, I32 optype, OP *right)
3441 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN) {
3442 return newLOGOP(optype, 0,
3443 mod(scalar(left), optype),
3444 newUNOP(OP_SASSIGN, 0, scalar(right)));
3447 return newBINOP(optype, OPf_STACKED,
3448 mod(scalar(left), optype), scalar(right));
3452 if (list_assignment(left)) {
3456 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
3457 left = mod(left, OP_AASSIGN);
3465 curop = list(force_list(left));
3466 o = newBINOP(OP_AASSIGN, flags, list(force_list(right)), curop);
3467 o->op_private = 0 | (flags >> 8);
3468 for (curop = ((LISTOP*)curop)->op_first;
3469 curop; curop = curop->op_sibling)
3471 if (curop->op_type == OP_RV2HV &&
3472 ((UNOP*)curop)->op_first->op_type != OP_GV) {
3473 o->op_private |= OPpASSIGN_HASH;
3477 if (!(left->op_private & OPpLVAL_INTRO)) {
3480 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
3481 if (PL_opargs[curop->op_type] & OA_DANGEROUS) {
3482 if (curop->op_type == OP_GV) {
3483 GV *gv = cGVOPx_gv(curop);
3484 if (gv == PL_defgv || SvCUR(gv) == PL_generation)
3486 SvCUR(gv) = PL_generation;
3488 else if (curop->op_type == OP_PADSV ||
3489 curop->op_type == OP_PADAV ||
3490 curop->op_type == OP_PADHV ||
3491 curop->op_type == OP_PADANY) {
3492 SV **svp = AvARRAY(PL_comppad_name);
3493 SV *sv = svp[curop->op_targ];
3494 if (SvCUR(sv) == PL_generation)
3496 SvCUR(sv) = PL_generation; /* (SvCUR not used any more) */
3498 else if (curop->op_type == OP_RV2CV)
3500 else if (curop->op_type == OP_RV2SV ||
3501 curop->op_type == OP_RV2AV ||
3502 curop->op_type == OP_RV2HV ||
3503 curop->op_type == OP_RV2GV) {
3504 if (lastop->op_type != OP_GV) /* funny deref? */
3507 else if (curop->op_type == OP_PUSHRE) {
3508 if (((PMOP*)curop)->op_pmreplroot) {
3510 GV *gv = (GV*)PL_curpad[(PADOFFSET)((PMOP*)curop)->op_pmreplroot];
3512 GV *gv = (GV*)((PMOP*)curop)->op_pmreplroot;
3514 if (gv == PL_defgv || SvCUR(gv) == PL_generation)
3516 SvCUR(gv) = PL_generation;
3525 o->op_private |= OPpASSIGN_COMMON;
3527 if (right && right->op_type == OP_SPLIT) {
3529 if ((tmpop = ((LISTOP*)right)->op_first) &&
3530 tmpop->op_type == OP_PUSHRE)
3532 PMOP *pm = (PMOP*)tmpop;
3533 if (left->op_type == OP_RV2AV &&
3534 !(left->op_private & OPpLVAL_INTRO) &&
3535 !(o->op_private & OPpASSIGN_COMMON) )
3537 tmpop = ((UNOP*)left)->op_first;
3538 if (tmpop->op_type == OP_GV && !pm->op_pmreplroot) {
3540 pm->op_pmreplroot = (OP*)cPADOPx(tmpop)->op_padix;
3541 cPADOPx(tmpop)->op_padix = 0; /* steal it */
3543 pm->op_pmreplroot = (OP*)cSVOPx(tmpop)->op_sv;
3544 cSVOPx(tmpop)->op_sv = Nullsv; /* steal it */
3546 pm->op_pmflags |= PMf_ONCE;
3547 tmpop = cUNOPo->op_first; /* to list (nulled) */
3548 tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */
3549 tmpop->op_sibling = Nullop; /* don't free split */
3550 right->op_next = tmpop->op_next; /* fix starting loc */
3551 op_free(o); /* blow off assign */
3552 right->op_flags &= ~OPf_WANT;
3553 /* "I don't know and I don't care." */
3558 if (PL_modcount < RETURN_UNLIMITED_NUMBER &&
3559 ((LISTOP*)right)->op_last->op_type == OP_CONST)
3561 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
3563 sv_setiv(sv, PL_modcount+1);
3571 right = newOP(OP_UNDEF, 0);
3572 if (right->op_type == OP_READLINE) {
3573 right->op_flags |= OPf_STACKED;
3574 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
3577 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
3578 o = newBINOP(OP_SASSIGN, flags,
3579 scalar(right), mod(scalar(left), OP_SASSIGN) );
3591 Perl_newSTATEOP(pTHX_ I32 flags, char *label, OP *o)
3593 U32 seq = intro_my();
3596 NewOp(1101, cop, 1, COP);
3597 if (PERLDB_LINE && CopLINE(PL_curcop) && PL_curstash != PL_debstash) {
3598 cop->op_type = OP_DBSTATE;
3599 cop->op_ppaddr = PL_ppaddr[ OP_DBSTATE ];
3602 cop->op_type = OP_NEXTSTATE;
3603 cop->op_ppaddr = PL_ppaddr[ OP_NEXTSTATE ];
3605 cop->op_flags = flags;
3606 cop->op_private = (PL_hints & HINT_PRIVATE_MASK);
3608 cop->op_private |= NATIVE_HINTS;
3610 PL_compiling.op_private = cop->op_private;
3611 cop->op_next = (OP*)cop;
3614 cop->cop_label = label;
3615 PL_hints |= HINT_BLOCK_SCOPE;
3618 cop->cop_arybase = PL_curcop->cop_arybase;
3619 if (specialWARN(PL_curcop->cop_warnings))
3620 cop->cop_warnings = PL_curcop->cop_warnings ;
3622 cop->cop_warnings = newSVsv(PL_curcop->cop_warnings) ;
3623 if (specialCopIO(PL_curcop->cop_io))
3624 cop->cop_io = PL_curcop->cop_io;
3626 cop->cop_io = newSVsv(PL_curcop->cop_io) ;
3629 if (PL_copline == NOLINE)
3630 CopLINE_set(cop, CopLINE(PL_curcop));
3632 CopLINE_set(cop, PL_copline);
3633 PL_copline = NOLINE;
3636 CopFILE_set(cop, CopFILE(PL_curcop)); /* XXX share in a pvtable? */
3638 CopFILEGV_set(cop, CopFILEGV(PL_curcop));
3640 CopSTASH_set(cop, PL_curstash);
3642 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3643 SV **svp = av_fetch(CopFILEAV(PL_curcop), (I32)CopLINE(cop), FALSE);
3644 if (svp && *svp != &PL_sv_undef && !SvIOK(*svp)) {
3645 (void)SvIOK_on(*svp);
3646 SvIVX(*svp) = PTR2IV(cop);
3650 return prepend_elem(OP_LINESEQ, (OP*)cop, o);
3653 /* "Introduce" my variables to visible status. */
3661 if (! PL_min_intro_pending)
3662 return PL_cop_seqmax;
3664 svp = AvARRAY(PL_comppad_name);
3665 for (i = PL_min_intro_pending; i <= PL_max_intro_pending; i++) {
3666 if ((sv = svp[i]) && sv != &PL_sv_undef && !SvIVX(sv)) {
3667 SvIVX(sv) = PAD_MAX; /* Don't know scope end yet. */
3668 SvNVX(sv) = (NV)PL_cop_seqmax;
3671 PL_min_intro_pending = 0;
3672 PL_comppad_name_fill = PL_max_intro_pending; /* Needn't search higher */
3673 return PL_cop_seqmax++;
3677 Perl_newLOGOP(pTHX_ I32 type, I32 flags, OP *first, OP *other)
3679 return new_logop(type, flags, &first, &other);
3683 S_new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp)
3687 OP *first = *firstp;
3688 OP *other = *otherp;
3690 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
3691 return newBINOP(type, flags, scalar(first), scalar(other));
3693 scalarboolean(first);
3694 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
3695 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
3696 if (type == OP_AND || type == OP_OR) {
3702 first = *firstp = cUNOPo->op_first;
3704 first->op_next = o->op_next;
3705 cUNOPo->op_first = Nullop;
3709 if (first->op_type == OP_CONST) {
3710 if (ckWARN(WARN_BAREWORD) && (first->op_private & OPpCONST_BARE))
3711 Perl_warner(aTHX_ WARN_BAREWORD, "Bareword found in conditional");
3712 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
3723 else if (first->op_type == OP_WANTARRAY) {
3729 else if (ckWARN(WARN_MISC) && (first->op_flags & OPf_KIDS)) {
3730 OP *k1 = ((UNOP*)first)->op_first;
3731 OP *k2 = k1->op_sibling;
3733 switch (first->op_type)
3736 if (k2 && k2->op_type == OP_READLINE
3737 && (k2->op_flags & OPf_STACKED)
3738 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3740 warnop = k2->op_type;
3745 if (k1->op_type == OP_READDIR
3746 || k1->op_type == OP_GLOB
3747 || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
3748 || k1->op_type == OP_EACH)
3750 warnop = ((k1->op_type == OP_NULL)
3751 ? k1->op_targ : k1->op_type);
3756 line_t oldline = CopLINE(PL_curcop);
3757 CopLINE_set(PL_curcop, PL_copline);
3758 Perl_warner(aTHX_ WARN_MISC,
3759 "Value of %s%s can be \"0\"; test with defined()",
3761 ((warnop == OP_READLINE || warnop == OP_GLOB)
3762 ? " construct" : "() operator"));
3763 CopLINE_set(PL_curcop, oldline);
3770 if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
3771 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
3773 NewOp(1101, logop, 1, LOGOP);
3775 logop->op_type = type;
3776 logop->op_ppaddr = PL_ppaddr[type];
3777 logop->op_first = first;
3778 logop->op_flags = flags | OPf_KIDS;
3779 logop->op_other = LINKLIST(other);
3780 logop->op_private = 1 | (flags >> 8);
3782 /* establish postfix order */
3783 logop->op_next = LINKLIST(first);
3784 first->op_next = (OP*)logop;
3785 first->op_sibling = other;
3787 o = newUNOP(OP_NULL, 0, (OP*)logop);
3794 Perl_newCONDOP(pTHX_ I32 flags, OP *first, OP *trueop, OP *falseop)
3801 return newLOGOP(OP_AND, 0, first, trueop);
3803 return newLOGOP(OP_OR, 0, first, falseop);
3805 scalarboolean(first);
3806 if (first->op_type == OP_CONST) {
3807 if (SvTRUE(((SVOP*)first)->op_sv)) {
3818 else if (first->op_type == OP_WANTARRAY) {
3822 NewOp(1101, logop, 1, LOGOP);
3823 logop->op_type = OP_COND_EXPR;
3824 logop->op_ppaddr = PL_ppaddr[OP_COND_EXPR];
3825 logop->op_first = first;
3826 logop->op_flags = flags | OPf_KIDS;
3827 logop->op_private = 1 | (flags >> 8);
3828 logop->op_other = LINKLIST(trueop);
3829 logop->op_next = LINKLIST(falseop);
3832 /* establish postfix order */
3833 start = LINKLIST(first);
3834 first->op_next = (OP*)logop;
3836 first->op_sibling = trueop;
3837 trueop->op_sibling = falseop;
3838 o = newUNOP(OP_NULL, 0, (OP*)logop);
3840 trueop->op_next = falseop->op_next = o;
3847 Perl_newRANGE(pTHX_ I32 flags, OP *left, OP *right)
3855 NewOp(1101, range, 1, LOGOP);
3857 range->op_type = OP_RANGE;
3858 range->op_ppaddr = PL_ppaddr[OP_RANGE];
3859 range->op_first = left;
3860 range->op_flags = OPf_KIDS;
3861 leftstart = LINKLIST(left);
3862 range->op_other = LINKLIST(right);
3863 range->op_private = 1 | (flags >> 8);
3865 left->op_sibling = right;
3867 range->op_next = (OP*)range;
3868 flip = newUNOP(OP_FLIP, flags, (OP*)range);
3869 flop = newUNOP(OP_FLOP, 0, flip);
3870 o = newUNOP(OP_NULL, 0, flop);
3872 range->op_next = leftstart;
3874 left->op_next = flip;
3875 right->op_next = flop;
3877 range->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
3878 sv_upgrade(PAD_SV(range->op_targ), SVt_PVNV);
3879 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
3880 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
3882 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
3883 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
3886 if (!flip->op_private || !flop->op_private)
3887 linklist(o); /* blow off optimizer unless constant */
3893 Perl_newLOOPOP(pTHX_ I32 flags, I32 debuggable, OP *expr, OP *block)
3897 int once = block && block->op_flags & OPf_SPECIAL &&
3898 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
3901 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
3902 return block; /* do {} while 0 does once */
3903 if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
3904 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB)) {
3905 expr = newUNOP(OP_DEFINED, 0,
3906 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
3907 } else if (expr->op_flags & OPf_KIDS) {
3908 OP *k1 = ((UNOP*)expr)->op_first;
3909 OP *k2 = (k1) ? k1->op_sibling : NULL;
3910 switch (expr->op_type) {
3912 if (k2 && k2->op_type == OP_READLINE
3913 && (k2->op_flags & OPf_STACKED)
3914 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3915 expr = newUNOP(OP_DEFINED, 0, expr);
3919 if (k1->op_type == OP_READDIR
3920 || k1->op_type == OP_GLOB
3921 || (k1->op_type == OP_NULL && k1->op_targ == OP_NULL)
3922 || k1->op_type == OP_EACH)
3923 expr = newUNOP(OP_DEFINED, 0, expr);
3929 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
3930 o = new_logop(OP_AND, 0, &expr, &listop);
3933 ((LISTOP*)listop)->op_last->op_next = LINKLIST(o);
3935 if (once && o != listop)
3936 o->op_next = ((LOGOP*)cUNOPo->op_first)->op_other;
3939 o = newUNOP(OP_NULL, 0, o); /* or do {} while 1 loses outer block */
3941 o->op_flags |= flags;
3943 o->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/
3948 Perl_newWHILEOP(pTHX_ I32 flags, I32 debuggable, LOOP *loop, I32 whileline, OP *expr, OP *block, OP *cont)
3956 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
3957 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB))) {
3958 expr = newUNOP(OP_DEFINED, 0,
3959 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
3960 } else if (expr && (expr->op_flags & OPf_KIDS)) {
3961 OP *k1 = ((UNOP*)expr)->op_first;
3962 OP *k2 = (k1) ? k1->op_sibling : NULL;
3963 switch (expr->op_type) {
3965 if (k2 && k2->op_type == OP_READLINE
3966 && (k2->op_flags & OPf_STACKED)
3967 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3968 expr = newUNOP(OP_DEFINED, 0, expr);
3972 if (k1->op_type == OP_READDIR
3973 || k1->op_type == OP_GLOB
3974 || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
3975 || k1->op_type == OP_EACH)
3976 expr = newUNOP(OP_DEFINED, 0, expr);
3982 block = newOP(OP_NULL, 0);
3984 block = scope(block);
3988 next = LINKLIST(cont);
3991 OP *unstack = newOP(OP_UNSTACK, 0);
3994 cont = append_elem(OP_LINESEQ, cont, unstack);
3995 if ((line_t)whileline != NOLINE) {
3996 PL_copline = whileline;
3997 cont = append_elem(OP_LINESEQ, cont,
3998 newSTATEOP(0, Nullch, Nullop));
4002 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
4003 redo = LINKLIST(listop);
4006 PL_copline = whileline;
4008 o = new_logop(OP_AND, 0, &expr, &listop);
4009 if (o == expr && o->op_type == OP_CONST && !SvTRUE(cSVOPo->op_sv)) {
4010 op_free(expr); /* oops, it's a while (0) */
4012 return Nullop; /* listop already freed by new_logop */
4015 ((LISTOP*)listop)->op_last->op_next =
4016 (o == listop ? redo : LINKLIST(o));
4022 NewOp(1101,loop,1,LOOP);
4023 loop->op_type = OP_ENTERLOOP;
4024 loop->op_ppaddr = PL_ppaddr[OP_ENTERLOOP];
4025 loop->op_private = 0;
4026 loop->op_next = (OP*)loop;
4029 o = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, o);
4031 loop->op_redoop = redo;
4032 loop->op_lastop = o;
4033 o->op_private |= loopflags;
4036 loop->op_nextop = next;
4038 loop->op_nextop = o;
4040 o->op_flags |= flags;
4041 o->op_private |= (flags >> 8);
4046 Perl_newFOROP(pTHX_ I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
4054 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
4055 sv->op_type = OP_RV2GV;
4056 sv->op_ppaddr = PL_ppaddr[OP_RV2GV];
4058 else if (sv->op_type == OP_PADSV) { /* private variable */
4059 padoff = sv->op_targ;
4064 else if (sv->op_type == OP_THREADSV) { /* per-thread variable */
4065 padoff = sv->op_targ;
4067 iterflags |= OPf_SPECIAL;
4072 Perl_croak(aTHX_ "Can't use %s for loop variable", PL_op_desc[sv->op_type]);
4076 padoff = find_threadsv("_");
4077 iterflags |= OPf_SPECIAL;
4079 sv = newGVOP(OP_GV, 0, PL_defgv);
4082 if (expr->op_type == OP_RV2AV || expr->op_type == OP_PADAV) {
4083 expr = mod(force_list(scalar(ref(expr, OP_ITER))), OP_GREPSTART);
4084 iterflags |= OPf_STACKED;
4086 else if (expr->op_type == OP_NULL &&
4087 (expr->op_flags & OPf_KIDS) &&
4088 ((BINOP*)expr)->op_first->op_type == OP_FLOP)
4090 /* Basically turn for($x..$y) into the same as for($x,$y), but we
4091 * set the STACKED flag to indicate that these values are to be
4092 * treated as min/max values by 'pp_iterinit'.
4094 UNOP* flip = (UNOP*)((UNOP*)((BINOP*)expr)->op_first)->op_first;
4095 LOGOP* range = (LOGOP*) flip->op_first;
4096 OP* left = range->op_first;
4097 OP* right = left->op_sibling;
4100 range->op_flags &= ~OPf_KIDS;
4101 range->op_first = Nullop;
4103 listop = (LISTOP*)newLISTOP(OP_LIST, 0, left, right);
4104 listop->op_first->op_next = range->op_next;
4105 left->op_next = range->op_other;
4106 right->op_next = (OP*)listop;
4107 listop->op_next = listop->op_first;
4110 expr = (OP*)(listop);
4112 iterflags |= OPf_STACKED;
4115 expr = mod(force_list(expr), OP_GREPSTART);
4119 loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
4120 append_elem(OP_LIST, expr, scalar(sv))));
4121 assert(!loop->op_next);
4122 #ifdef PL_OP_SLAB_ALLOC
4125 NewOp(1234,tmp,1,LOOP);
4126 Copy(loop,tmp,1,LOOP);
4130 Renew(loop, 1, LOOP);
4132 loop->op_targ = padoff;
4133 wop = newWHILEOP(flags, 1, loop, forline, newOP(OP_ITER, 0), block, cont);
4134 PL_copline = forline;
4135 return newSTATEOP(0, label, wop);
4139 Perl_newLOOPEX(pTHX_ I32 type, OP *label)
4144 if (type != OP_GOTO || label->op_type == OP_CONST) {
4145 /* "last()" means "last" */
4146 if (label->op_type == OP_STUB && (label->op_flags & OPf_PARENS))
4147 o = newOP(type, OPf_SPECIAL);
4149 o = newPVOP(type, 0, savepv(label->op_type == OP_CONST
4150 ? SvPVx(((SVOP*)label)->op_sv, n_a)
4156 if (label->op_type == OP_ENTERSUB)
4157 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
4158 o = newUNOP(type, OPf_STACKED, label);
4160 PL_hints |= HINT_BLOCK_SCOPE;
4165 Perl_cv_undef(pTHX_ CV *cv)
4169 MUTEX_DESTROY(CvMUTEXP(cv));
4170 Safefree(CvMUTEXP(cv));
4173 #endif /* USE_THREADS */
4176 if (CvFILE(cv) && !CvXSUB(cv)) {
4177 /* for XSUBs CvFILE point directly to static memory; __FILE__ */
4178 Safefree(CvFILE(cv));
4183 if (!CvXSUB(cv) && CvROOT(cv)) {
4185 if (CvDEPTH(cv) || (CvOWNER(cv) && CvOWNER(cv) != thr))
4186 Perl_croak(aTHX_ "Can't undef active subroutine");
4189 Perl_croak(aTHX_ "Can't undef active subroutine");
4190 #endif /* USE_THREADS */
4193 SAVEVPTR(PL_curpad);
4196 op_free(CvROOT(cv));
4197 CvROOT(cv) = Nullop;
4200 SvPOK_off((SV*)cv); /* forget prototype */
4202 /* Since closure prototypes have the same lifetime as the containing
4203 * CV, they don't hold a refcount on the outside CV. This avoids
4204 * the refcount loop between the outer CV (which keeps a refcount to
4205 * the closure prototype in the pad entry for pp_anoncode()) and the
4206 * closure prototype, and the ensuing memory leak. This does not
4207 * apply to closures generated within eval"", since eval"" CVs are
4208 * ephemeral. --GSAR */
4209 if (!CvANON(cv) || CvCLONED(cv)
4210 || (CvOUTSIDE(cv) && SvTYPE(CvOUTSIDE(cv)) == SVt_PVCV
4211 && CvEVAL(CvOUTSIDE(cv)) && !CvGV(CvOUTSIDE(cv))))
4213 SvREFCNT_dec(CvOUTSIDE(cv));
4215 CvOUTSIDE(cv) = Nullcv;
4217 SvREFCNT_dec((SV*)CvXSUBANY(cv).any_ptr);
4220 if (CvPADLIST(cv)) {
4221 /* may be during global destruction */
4222 if (SvREFCNT(CvPADLIST(cv))) {
4223 I32 i = AvFILLp(CvPADLIST(cv));
4225 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
4226 SV* sv = svp ? *svp : Nullsv;
4229 if (sv == (SV*)PL_comppad_name)
4230 PL_comppad_name = Nullav;
4231 else if (sv == (SV*)PL_comppad) {
4232 PL_comppad = Nullav;
4233 PL_curpad = Null(SV**);
4237 SvREFCNT_dec((SV*)CvPADLIST(cv));
4239 CvPADLIST(cv) = Nullav;
4247 #ifdef DEBUG_CLOSURES
4249 S_cv_dump(pTHX_ CV *cv)
4252 CV *outside = CvOUTSIDE(cv);
4253 AV* padlist = CvPADLIST(cv);
4260 PerlIO_printf(Perl_debug_log,
4261 "\tCV=0x%"UVxf" (%s), OUTSIDE=0x%"UVxf" (%s)\n",
4263 (CvANON(cv) ? "ANON"
4264 : (cv == PL_main_cv) ? "MAIN"
4265 : CvUNIQUE(cv) ? "UNIQUE"
4266 : CvGV(cv) ? GvNAME(CvGV(cv)) : "UNDEFINED"),
4269 : CvANON(outside) ? "ANON"
4270 : (outside == PL_main_cv) ? "MAIN"
4271 : CvUNIQUE(outside) ? "UNIQUE"
4272 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
4277 pad_name = (AV*)*av_fetch(padlist, 0, FALSE);
4278 pad = (AV*)*av_fetch(padlist, 1, FALSE);
4279 pname = AvARRAY(pad_name);
4280 ppad = AvARRAY(pad);
4282 for (ix = 1; ix <= AvFILLp(pad_name); ix++) {
4283 if (SvPOK(pname[ix]))
4284 PerlIO_printf(Perl_debug_log,
4285 "\t%4d. 0x%"UVxf" (%s\"%s\" %"IVdf"-%"IVdf")\n",
4286 (int)ix, PTR2UV(ppad[ix]),
4287 SvFAKE(pname[ix]) ? "FAKE " : "",
4289 (IV)I_32(SvNVX(pname[ix])),
4292 #endif /* DEBUGGING */
4294 #endif /* DEBUG_CLOSURES */
4297 S_cv_clone2(pTHX_ CV *proto, CV *outside)
4301 AV* protopadlist = CvPADLIST(proto);
4302 AV* protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
4303 AV* protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
4304 SV** pname = AvARRAY(protopad_name);
4305 SV** ppad = AvARRAY(protopad);
4306 I32 fname = AvFILLp(protopad_name);
4307 I32 fpad = AvFILLp(protopad);
4311 assert(!CvUNIQUE(proto));
4315 SAVESPTR(PL_comppad_name);
4316 SAVESPTR(PL_compcv);
4318 cv = PL_compcv = (CV*)NEWSV(1104,0);
4319 sv_upgrade((SV *)cv, SvTYPE(proto));
4320 CvFLAGS(cv) = CvFLAGS(proto) & ~CVf_CLONE;
4324 New(666, CvMUTEXP(cv), 1, perl_mutex);
4325 MUTEX_INIT(CvMUTEXP(cv));
4327 #endif /* USE_THREADS */
4329 CvFILE(cv) = CvXSUB(proto) ? CvFILE(proto)
4330 : savepv(CvFILE(proto));
4332 CvFILE(cv) = CvFILE(proto);
4334 CvGV(cv) = CvGV(proto);
4335 CvSTASH(cv) = CvSTASH(proto);
4336 CvROOT(cv) = OpREFCNT_inc(CvROOT(proto));
4337 CvSTART(cv) = CvSTART(proto);
4339 CvOUTSIDE(cv) = (CV*)SvREFCNT_inc(outside);
4342 sv_setpvn((SV*)cv, SvPVX(proto), SvCUR(proto));
4344 PL_comppad_name = newAV();
4345 for (ix = fname; ix >= 0; ix--)
4346 av_store(PL_comppad_name, ix, SvREFCNT_inc(pname[ix]));
4348 PL_comppad = newAV();
4350 comppadlist = newAV();
4351 AvREAL_off(comppadlist);
4352 av_store(comppadlist, 0, (SV*)PL_comppad_name);
4353 av_store(comppadlist, 1, (SV*)PL_comppad);
4354 CvPADLIST(cv) = comppadlist;
4355 av_fill(PL_comppad, AvFILLp(protopad));
4356 PL_curpad = AvARRAY(PL_comppad);
4358 av = newAV(); /* will be @_ */
4360 av_store(PL_comppad, 0, (SV*)av);
4361 AvFLAGS(av) = AVf_REIFY;
4363 for (ix = fpad; ix > 0; ix--) {
4364 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
4365 if (namesv && namesv != &PL_sv_undef) {
4366 char *name = SvPVX(namesv); /* XXX */
4367 if (SvFLAGS(namesv) & SVf_FAKE) { /* lexical from outside? */
4368 I32 off = pad_findlex(name, ix, SvIVX(namesv),
4369 CvOUTSIDE(cv), cxstack_ix, 0, 0);
4371 PL_curpad[ix] = SvREFCNT_inc(ppad[ix]);
4373 Perl_croak(aTHX_ "panic: cv_clone: %s", name);
4375 else { /* our own lexical */
4378 /* anon code -- we'll come back for it */
4379 sv = SvREFCNT_inc(ppad[ix]);
4381 else if (*name == '@')
4383 else if (*name == '%')
4392 else if (IS_PADGV(ppad[ix]) || IS_PADCONST(ppad[ix])) {
4393 PL_curpad[ix] = SvREFCNT_inc(ppad[ix]);
4396 SV* sv = NEWSV(0,0);
4402 /* Now that vars are all in place, clone nested closures. */
4404 for (ix = fpad; ix > 0; ix--) {
4405 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
4407 && namesv != &PL_sv_undef
4408 && !(SvFLAGS(namesv) & SVf_FAKE)
4409 && *SvPVX(namesv) == '&'
4410 && CvCLONE(ppad[ix]))
4412 CV *kid = cv_clone2((CV*)ppad[ix], cv);
4413 SvREFCNT_dec(ppad[ix]);
4416 PL_curpad[ix] = (SV*)kid;
4420 #ifdef DEBUG_CLOSURES
4421 PerlIO_printf(Perl_debug_log, "Cloned inside:\n");
4423 PerlIO_printf(Perl_debug_log, " from:\n");
4425 PerlIO_printf(Perl_debug_log, " to:\n");
4432 SV* const_sv = op_const_sv(CvSTART(cv), cv);
4434 /* constant sub () { $x } closing over $x - see lib/constant.pm */
4436 cv = newCONSTSUB(CvSTASH(proto), 0, const_sv);
4443 Perl_cv_clone(pTHX_ CV *proto)
4446 LOCK_CRED_MUTEX; /* XXX create separate mutex */
4447 cv = cv_clone2(proto, CvOUTSIDE(proto));
4448 UNLOCK_CRED_MUTEX; /* XXX create separate mutex */
4453 Perl_cv_ckproto(pTHX_ CV *cv, GV *gv, char *p)
4455 if (((!p != !SvPOK(cv)) || (p && strNE(p, SvPVX(cv)))) && ckWARN_d(WARN_PROTOTYPE)) {
4456 SV* msg = sv_newmortal();
4460 gv_efullname3(name = sv_newmortal(), gv, Nullch);
4461 sv_setpv(msg, "Prototype mismatch:");
4463 Perl_sv_catpvf(aTHX_ msg, " sub %"SVf, name);
4465 Perl_sv_catpvf(aTHX_ msg, " (%s)", SvPVX(cv));
4466 sv_catpv(msg, " vs ");
4468 Perl_sv_catpvf(aTHX_ msg, "(%s)", p);
4470 sv_catpv(msg, "none");
4471 Perl_warner(aTHX_ WARN_PROTOTYPE, "%"SVf, msg);
4475 static void const_sv_xsub(pTHXo_ CV* cv);
4478 =for apidoc cv_const_sv
4480 If C<cv> is a constant sub eligible for inlining. returns the constant
4481 value returned by the sub. Otherwise, returns NULL.
4483 Constant subs can be created with C<newCONSTSUB> or as described in
4484 L<perlsub/"Constant Functions">.
4489 Perl_cv_const_sv(pTHX_ CV *cv)
4491 if (!cv || !CvCONST(cv))
4493 return (SV*)CvXSUBANY(cv).any_ptr;
4497 Perl_op_const_sv(pTHX_ OP *o, CV *cv)
4504 if (o->op_type == OP_LINESEQ && cLISTOPo->op_first)
4505 o = cLISTOPo->op_first->op_sibling;
4507 for (; o; o = o->op_next) {
4508 OPCODE type = o->op_type;
4510 if (sv && o->op_next == o)
4512 if (o->op_next != o) {
4513 if (type == OP_NEXTSTATE || type == OP_NULL || type == OP_PUSHMARK)
4515 if (type == OP_DBSTATE)
4518 if (type == OP_LEAVESUB || type == OP_RETURN)
4522 if (type == OP_CONST && cSVOPo->op_sv)
4524 else if ((type == OP_PADSV || type == OP_CONST) && cv) {
4525 AV* padav = (AV*)(AvARRAY(CvPADLIST(cv))[1]);
4526 sv = padav ? AvARRAY(padav)[o->op_targ] : Nullsv;
4530 /* We get here only from cv_clone2() while creating a closure.
4531 Copy the const value here instead of in cv_clone2 so that
4532 SvREADONLY_on doesn't lead to problems when leaving
4537 if (!SvREADONLY(sv) && SvREFCNT(sv) > 1)
4549 Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
4559 Perl_croak(aTHX_ "\"my sub\" not yet implemented");
4563 Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block)
4565 return Perl_newATTRSUB(aTHX_ floor, o, proto, Nullop, block);
4569 Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
4575 char *ps = proto ? SvPVx(((SVOP*)proto)->op_sv, n_a) : Nullch;
4580 name = o ? SvPVx(cSVOPo->op_sv, n_a) : Nullch;
4581 if (!name && PERLDB_NAMEANON && CopLINE(PL_curcop)) {
4582 SV *sv = sv_newmortal();
4583 Perl_sv_setpvf(aTHX_ sv, "__ANON__[%s:%"IVdf"]",
4584 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
4589 gv = gv_fetchpv(name ? name : (aname ? aname : "__ANON__"),
4590 GV_ADDMULTI | ((block || attrs) ? 0 : GV_NOINIT),
4600 if (SvTYPE(gv) != SVt_PVGV) { /* Maybe prototype now, and had at
4601 maximum a prototype before. */
4602 if (SvTYPE(gv) > SVt_NULL) {
4603 if (!SvPOK((SV*)gv) && !(SvIOK((SV*)gv) && SvIVX((SV*)gv) == -1)
4604 && ckWARN_d(WARN_PROTOTYPE))
4606 Perl_warner(aTHX_ WARN_PROTOTYPE, "Runaway prototype");
4608 cv_ckproto((CV*)gv, NULL, ps);
4611 sv_setpv((SV*)gv, ps);
4613 sv_setiv((SV*)gv, -1);
4614 SvREFCNT_dec(PL_compcv);
4615 cv = PL_compcv = NULL;
4616 PL_sub_generation++;
4620 cv = (!name || GvCVGEN(gv)) ? Nullcv : GvCV(gv);
4622 #ifdef GV_UNIQUE_CHECK
4623 if (cv && GvUNIQUE(gv) && SvREADONLY(cv)) {
4624 Perl_croak(aTHX_ "Can't define subroutine %s (GV is unique)", name);
4628 if (!block || !ps || *ps || attrs)
4631 const_sv = op_const_sv(block, Nullcv);
4634 bool exists = CvROOT(cv) || CvXSUB(cv);
4636 #ifdef GV_UNIQUE_CHECK
4637 if (exists && GvUNIQUE(gv)) {
4638 Perl_croak(aTHX_ "Can't redefine unique subroutine %s", name);
4642 /* if the subroutine doesn't exist and wasn't pre-declared
4643 * with a prototype, assume it will be AUTOLOADed,
4644 * skipping the prototype check
4646 if (exists || SvPOK(cv))
4647 cv_ckproto(cv, gv, ps);
4648 /* already defined (or promised)? */
4649 if (exists || GvASSUMECV(gv)) {
4650 if (!block && !attrs) {
4651 /* just a "sub foo;" when &foo is already defined */
4652 SAVEFREESV(PL_compcv);
4655 /* ahem, death to those who redefine active sort subs */
4656 if (PL_curstackinfo->si_type == PERLSI_SORT && PL_sortcop == CvSTART(cv))
4657 Perl_croak(aTHX_ "Can't redefine active sort subroutine %s", name);
4659 if (ckWARN(WARN_REDEFINE)
4661 && (!const_sv || sv_cmp(cv_const_sv(cv), const_sv))))
4663 line_t oldline = CopLINE(PL_curcop);
4664 CopLINE_set(PL_curcop, PL_copline);
4665 Perl_warner(aTHX_ WARN_REDEFINE,
4666 CvCONST(cv) ? "Constant subroutine %s redefined"
4667 : "Subroutine %s redefined", name);
4668 CopLINE_set(PL_curcop, oldline);
4676 SvREFCNT_inc(const_sv);
4678 assert(!CvROOT(cv) && !CvCONST(cv));
4679 sv_setpv((SV*)cv, ""); /* prototype is "" */
4680 CvXSUBANY(cv).any_ptr = const_sv;
4681 CvXSUB(cv) = const_sv_xsub;
4686 cv = newCONSTSUB(NULL, name, const_sv);
4689 SvREFCNT_dec(PL_compcv);
4691 PL_sub_generation++;
4698 /* Need to do a C<use attributes $stash_of_cv,\&cv,@attrs>
4699 * before we clobber PL_compcv.
4703 if (CvGV(cv) && GvSTASH(CvGV(cv)))
4704 stash = GvSTASH(CvGV(cv));
4705 else if (CvSTASH(cv))
4706 stash = CvSTASH(cv);
4708 stash = PL_curstash;
4711 /* possibly about to re-define existing subr -- ignore old cv */
4712 rcv = (SV*)PL_compcv;
4713 if (name && GvSTASH(gv))
4714 stash = GvSTASH(gv);
4716 stash = PL_curstash;
4718 apply_attrs(stash, rcv, attrs);
4720 if (cv) { /* must reuse cv if autoloaded */
4722 /* got here with just attrs -- work done, so bug out */
4723 SAVEFREESV(PL_compcv);
4727 CvFLAGS(cv) = CvFLAGS(PL_compcv);
4728 CvOUTSIDE(cv) = CvOUTSIDE(PL_compcv);
4729 CvOUTSIDE(PL_compcv) = 0;
4730 CvPADLIST(cv) = CvPADLIST(PL_compcv);
4731 CvPADLIST(PL_compcv) = 0;
4732 /* inner references to PL_compcv must be fixed up ... */
4734 AV *padlist = CvPADLIST(cv);
4735 AV *comppad_name = (AV*)AvARRAY(padlist)[0];
4736 AV *comppad = (AV*)AvARRAY(padlist)[1];
4737 SV **namepad = AvARRAY(comppad_name);
4738 SV **curpad = AvARRAY(comppad);
4739 for (ix = AvFILLp(comppad_name); ix > 0; ix--) {
4740 SV *namesv = namepad[ix];
4741 if (namesv && namesv != &PL_sv_undef
4742 && *SvPVX(namesv) == '&')
4744 CV *innercv = (CV*)curpad[ix];
4745 if (CvOUTSIDE(innercv) == PL_compcv) {
4746 CvOUTSIDE(innercv) = cv;
4747 if (!CvANON(innercv) || CvCLONED(innercv)) {
4748 (void)SvREFCNT_inc(cv);
4749 SvREFCNT_dec(PL_compcv);
4755 /* ... before we throw it away */
4756 SvREFCNT_dec(PL_compcv);
4763 PL_sub_generation++;
4767 CvFILE_set_from_cop(cv, PL_curcop);
4768 CvSTASH(cv) = PL_curstash;
4771 if (!CvMUTEXP(cv)) {
4772 New(666, CvMUTEXP(cv), 1, perl_mutex);
4773 MUTEX_INIT(CvMUTEXP(cv));
4775 #endif /* USE_THREADS */
4778 sv_setpv((SV*)cv, ps);
4780 if (PL_error_count) {
4784 char *s = strrchr(name, ':');
4786 if (strEQ(s, "BEGIN")) {
4788 "BEGIN not safe after errors--compilation aborted";
4789 if (PL_in_eval & EVAL_KEEPERR)
4790 Perl_croak(aTHX_ not_safe);
4792 /* force display of errors found but not reported */
4793 sv_catpv(ERRSV, not_safe);
4794 Perl_croak(aTHX_ "%s", SvPVx(ERRSV, n_a));
4802 if (AvFILLp(PL_comppad_name) < AvFILLp(PL_comppad))
4803 av_store(PL_comppad_name, AvFILLp(PL_comppad), Nullsv);
4806 CvROOT(cv) = newUNOP(OP_LEAVESUBLV, 0,
4807 mod(scalarseq(block), OP_LEAVESUBLV));
4810 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
4812 CvROOT(cv)->op_private |= OPpREFCOUNTED;
4813 OpREFCNT_set(CvROOT(cv), 1);
4814 CvSTART(cv) = LINKLIST(CvROOT(cv));
4815 CvROOT(cv)->op_next = 0;
4818 /* now that optimizer has done its work, adjust pad values */
4820 SV **namep = AvARRAY(PL_comppad_name);
4821 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4824 if (SvIMMORTAL(PL_curpad[ix]) || IS_PADGV(PL_curpad[ix]) || IS_PADCONST(PL_curpad[ix]))
4827 * The only things that a clonable function needs in its
4828 * pad are references to outer lexicals and anonymous subs.
4829 * The rest are created anew during cloning.
4831 if (!((namesv = namep[ix]) != Nullsv &&
4832 namesv != &PL_sv_undef &&
4834 *SvPVX(namesv) == '&')))
4836 SvREFCNT_dec(PL_curpad[ix]);
4837 PL_curpad[ix] = Nullsv;
4840 assert(!CvCONST(cv));
4841 if (ps && !*ps && op_const_sv(block, cv))
4845 AV *av = newAV(); /* Will be @_ */
4847 av_store(PL_comppad, 0, (SV*)av);
4848 AvFLAGS(av) = AVf_REIFY;
4850 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4851 if (SvIMMORTAL(PL_curpad[ix]) || IS_PADGV(PL_curpad[ix]) || IS_PADCONST(PL_curpad[ix]))
4853 if (!SvPADMY(PL_curpad[ix]))
4854 SvPADTMP_on(PL_curpad[ix]);
4858 /* If a potential closure prototype, don't keep a refcount on
4859 * outer CV, unless the latter happens to be a passing eval"".
4860 * This is okay as the lifetime of the prototype is tied to the
4861 * lifetime of the outer CV. Avoids memory leak due to reference
4863 if (!name && CvOUTSIDE(cv)
4864 && !(SvTYPE(CvOUTSIDE(cv)) == SVt_PVCV
4865 && CvEVAL(CvOUTSIDE(cv)) && !CvGV(CvOUTSIDE(cv))))
4867 SvREFCNT_dec(CvOUTSIDE(cv));
4870 if (name || aname) {
4872 char *tname = (name ? name : aname);
4874 if (PERLDB_SUBLINE && PL_curstash != PL_debstash) {
4875 SV *sv = NEWSV(0,0);
4876 SV *tmpstr = sv_newmortal();
4877 GV *db_postponed = gv_fetchpv("DB::postponed", GV_ADDMULTI, SVt_PVHV);
4881 Perl_sv_setpvf(aTHX_ sv, "%s:%ld-%ld",
4883 (long)PL_subline, (long)CopLINE(PL_curcop));
4884 gv_efullname3(tmpstr, gv, Nullch);
4885 hv_store(GvHV(PL_DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
4886 hv = GvHVn(db_postponed);
4887 if (HvFILL(hv) > 0 && hv_exists(hv, SvPVX(tmpstr), SvCUR(tmpstr))
4888 && (pcv = GvCV(db_postponed)))
4894 call_sv((SV*)pcv, G_DISCARD);
4898 if ((s = strrchr(tname,':')))
4903 if (*s != 'B' && *s != 'E' && *s != 'C' && *s != 'I')
4906 if (strEQ(s, "BEGIN")) {
4907 I32 oldscope = PL_scopestack_ix;
4909 SAVECOPFILE(&PL_compiling);
4910 SAVECOPLINE(&PL_compiling);
4912 sv_setsv(PL_rs, PL_nrs);
4915 PL_beginav = newAV();
4916 DEBUG_x( dump_sub(gv) );
4917 av_push(PL_beginav, (SV*)cv);
4918 GvCV(gv) = 0; /* cv has been hijacked */
4919 call_list(oldscope, PL_beginav);
4921 PL_curcop = &PL_compiling;
4922 PL_compiling.op_private = PL_hints;
4925 else if (strEQ(s, "END") && !PL_error_count) {
4928 DEBUG_x( dump_sub(gv) );
4929 av_unshift(PL_endav, 1);
4930 av_store(PL_endav, 0, (SV*)cv);
4931 GvCV(gv) = 0; /* cv has been hijacked */
4933 else if (strEQ(s, "CHECK") && !PL_error_count) {
4935 PL_checkav = newAV();
4936 DEBUG_x( dump_sub(gv) );
4937 if (PL_main_start && ckWARN(WARN_VOID))
4938 Perl_warner(aTHX_ WARN_VOID, "Too late to run CHECK block");
4939 av_unshift(PL_checkav, 1);
4940 av_store(PL_checkav, 0, (SV*)cv);
4941 GvCV(gv) = 0; /* cv has been hijacked */
4943 else if (strEQ(s, "INIT") && !PL_error_count) {
4945 PL_initav = newAV();
4946 DEBUG_x( dump_sub(gv) );
4947 if (PL_main_start && ckWARN(WARN_VOID))
4948 Perl_warner(aTHX_ WARN_VOID, "Too late to run INIT block");
4949 av_push(PL_initav, (SV*)cv);
4950 GvCV(gv) = 0; /* cv has been hijacked */
4955 PL_copline = NOLINE;
4960 /* XXX unsafe for threads if eval_owner isn't held */
4962 =for apidoc newCONSTSUB
4964 Creates a constant sub equivalent to Perl C<sub FOO () { 123 }> which is
4965 eligible for inlining at compile-time.
4971 Perl_newCONSTSUB(pTHX_ HV *stash, char *name, SV *sv)
4977 SAVECOPLINE(PL_curcop);
4978 CopLINE_set(PL_curcop, PL_copline);
4981 PL_hints &= ~HINT_BLOCK_SCOPE;
4984 SAVESPTR(PL_curstash);
4985 SAVECOPSTASH(PL_curcop);
4986 PL_curstash = stash;
4988 CopSTASHPV(PL_curcop) = stash ? HvNAME(stash) : Nullch;
4990 CopSTASH(PL_curcop) = stash;
4994 cv = newXS(name, const_sv_xsub, __FILE__);
4995 CvXSUBANY(cv).any_ptr = sv;
4997 sv_setpv((SV*)cv, ""); /* prototype is "" */
5005 =for apidoc U||newXS
5007 Used by C<xsubpp> to hook up XSUBs as Perl subs.
5013 Perl_newXS(pTHX_ char *name, XSUBADDR_t subaddr, char *filename)
5015 GV *gv = gv_fetchpv(name ? name : "__ANON__", GV_ADDMULTI, SVt_PVCV);
5018 if ((cv = (name ? GvCV(gv) : Nullcv))) {
5020 /* just a cached method */
5024 else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
5025 /* already defined (or promised) */
5026 if (ckWARN(WARN_REDEFINE) && !(CvGV(cv) && GvSTASH(CvGV(cv))
5027 && strEQ(HvNAME(GvSTASH(CvGV(cv))), "autouse"))) {
5028 line_t oldline = CopLINE(PL_curcop);
5029 if (PL_copline != NOLINE)
5030 CopLINE_set(PL_curcop, PL_copline);
5031 Perl_warner(aTHX_ WARN_REDEFINE,
5032 CvCONST(cv) ? "Constant subroutine %s redefined"
5033 : "Subroutine %s redefined"
5035 CopLINE_set(PL_curcop, oldline);
5042 if (cv) /* must reuse cv if autoloaded */
5045 cv = (CV*)NEWSV(1105,0);
5046 sv_upgrade((SV *)cv, SVt_PVCV);
5050 PL_sub_generation++;
5055 New(666, CvMUTEXP(cv), 1, perl_mutex);
5056 MUTEX_INIT(CvMUTEXP(cv));
5058 #endif /* USE_THREADS */
5059 (void)gv_fetchfile(filename);
5060 CvFILE(cv) = filename; /* NOTE: not copied, as it is expected to be
5061 an external constant string */
5062 CvXSUB(cv) = subaddr;
5065 char *s = strrchr(name,':');
5071 if (*s != 'B' && *s != 'E' && *s != 'C' && *s != 'I')
5074 if (strEQ(s, "BEGIN")) {
5076 PL_beginav = newAV();
5077 av_push(PL_beginav, (SV*)cv);
5078 GvCV(gv) = 0; /* cv has been hijacked */
5080 else if (strEQ(s, "END")) {
5083 av_unshift(PL_endav, 1);
5084 av_store(PL_endav, 0, (SV*)cv);
5085 GvCV(gv) = 0; /* cv has been hijacked */
5087 else if (strEQ(s, "CHECK")) {
5089 PL_checkav = newAV();
5090 if (PL_main_start && ckWARN(WARN_VOID))
5091 Perl_warner(aTHX_ WARN_VOID, "Too late to run CHECK block");
5092 av_unshift(PL_checkav, 1);
5093 av_store(PL_checkav, 0, (SV*)cv);
5094 GvCV(gv) = 0; /* cv has been hijacked */
5096 else if (strEQ(s, "INIT")) {
5098 PL_initav = newAV();
5099 if (PL_main_start && ckWARN(WARN_VOID))
5100 Perl_warner(aTHX_ WARN_VOID, "Too late to run INIT block");
5101 av_push(PL_initav, (SV*)cv);
5102 GvCV(gv) = 0; /* cv has been hijacked */
5113 Perl_newFORM(pTHX_ I32 floor, OP *o, OP *block)
5122 name = SvPVx(cSVOPo->op_sv, n_a);
5125 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
5126 #ifdef GV_UNIQUE_CHECK
5128 Perl_croak(aTHX_ "Bad symbol for form (GV is unique)");
5132 if ((cv = GvFORM(gv))) {
5133 if (ckWARN(WARN_REDEFINE)) {
5134 line_t oldline = CopLINE(PL_curcop);
5136 CopLINE_set(PL_curcop, PL_copline);
5137 Perl_warner(aTHX_ WARN_REDEFINE, "Format %s redefined",name);
5138 CopLINE_set(PL_curcop, oldline);
5145 CvFILE_set_from_cop(cv, PL_curcop);
5147 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
5148 if (!SvPADMY(PL_curpad[ix]) && !SvIMMORTAL(PL_curpad[ix]))
5149 SvPADTMP_on(PL_curpad[ix]);
5152 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
5153 CvROOT(cv)->op_private |= OPpREFCOUNTED;
5154 OpREFCNT_set(CvROOT(cv), 1);
5155 CvSTART(cv) = LINKLIST(CvROOT(cv));
5156 CvROOT(cv)->op_next = 0;
5159 PL_copline = NOLINE;
5164 Perl_newANONLIST(pTHX_ OP *o)
5166 return newUNOP(OP_REFGEN, 0,
5167 mod(list(convert(OP_ANONLIST, 0, o)), OP_REFGEN));
5171 Perl_newANONHASH(pTHX_ OP *o)
5173 return newUNOP(OP_REFGEN, 0,
5174 mod(list(convert(OP_ANONHASH, 0, o)), OP_REFGEN));
5178 Perl_newANONSUB(pTHX_ I32 floor, OP *proto, OP *block)
5180 return newANONATTRSUB(floor, proto, Nullop, block);
5184 Perl_newANONATTRSUB(pTHX_ I32 floor, OP *proto, OP *attrs, OP *block)
5186 return newUNOP(OP_REFGEN, 0,
5187 newSVOP(OP_ANONCODE, 0,
5188 (SV*)newATTRSUB(floor, 0, proto, attrs, block)));
5192 Perl_oopsAV(pTHX_ OP *o)
5194 switch (o->op_type) {
5196 o->op_type = OP_PADAV;
5197 o->op_ppaddr = PL_ppaddr[OP_PADAV];
5198 return ref(o, OP_RV2AV);
5201 o->op_type = OP_RV2AV;
5202 o->op_ppaddr = PL_ppaddr[OP_RV2AV];
5207 if (ckWARN_d(WARN_INTERNAL))
5208 Perl_warner(aTHX_ WARN_INTERNAL, "oops: oopsAV");
5215 Perl_oopsHV(pTHX_ OP *o)
5217 switch (o->op_type) {
5220 o->op_type = OP_PADHV;
5221 o->op_ppaddr = PL_ppaddr[OP_PADHV];
5222 return ref(o, OP_RV2HV);
5226 o->op_type = OP_RV2HV;
5227 o->op_ppaddr = PL_ppaddr[OP_RV2HV];
5232 if (ckWARN_d(WARN_INTERNAL))
5233 Perl_warner(aTHX_ WARN_INTERNAL, "oops: oopsHV");
5240 Perl_newAVREF(pTHX_ OP *o)
5242 if (o->op_type == OP_PADANY) {
5243 o->op_type = OP_PADAV;
5244 o->op_ppaddr = PL_ppaddr[OP_PADAV];
5247 else if ((o->op_type == OP_RV2AV || o->op_type == OP_PADAV)
5248 && ckWARN(WARN_DEPRECATED)) {
5249 Perl_warner(aTHX_ WARN_DEPRECATED,
5250 "Using an array as a reference is deprecated");
5252 return newUNOP(OP_RV2AV, 0, scalar(o));
5256 Perl_newGVREF(pTHX_ I32 type, OP *o)
5258 if (type == OP_MAPSTART || type == OP_GREPSTART || type == OP_SORT)
5259 return newUNOP(OP_NULL, 0, o);
5260 return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
5264 Perl_newHVREF(pTHX_ OP *o)
5266 if (o->op_type == OP_PADANY) {
5267 o->op_type = OP_PADHV;
5268 o->op_ppaddr = PL_ppaddr[OP_PADHV];
5271 else if ((o->op_type == OP_RV2HV || o->op_type == OP_PADHV)
5272 && ckWARN(WARN_DEPRECATED)) {
5273 Perl_warner(aTHX_ WARN_DEPRECATED,
5274 "Using a hash as a reference is deprecated");
5276 return newUNOP(OP_RV2HV, 0, scalar(o));
5280 Perl_oopsCV(pTHX_ OP *o)
5282 Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
5288 Perl_newCVREF(pTHX_ I32 flags, OP *o)
5290 return newUNOP(OP_RV2CV, flags, scalar(o));
5294 Perl_newSVREF(pTHX_ OP *o)
5296 if (o->op_type == OP_PADANY) {
5297 o->op_type = OP_PADSV;
5298 o->op_ppaddr = PL_ppaddr[OP_PADSV];
5301 else if (o->op_type == OP_THREADSV && !(o->op_flags & OPpDONE_SVREF)) {
5302 o->op_flags |= OPpDONE_SVREF;
5305 return newUNOP(OP_RV2SV, 0, scalar(o));
5308 /* Check routines. */
5311 Perl_ck_anoncode(pTHX_ OP *o)
5316 name = NEWSV(1106,0);
5317 sv_upgrade(name, SVt_PVNV);
5318 sv_setpvn(name, "&", 1);
5321 ix = pad_alloc(o->op_type, SVs_PADMY);
5322 av_store(PL_comppad_name, ix, name);
5323 av_store(PL_comppad, ix, cSVOPo->op_sv);
5324 SvPADMY_on(cSVOPo->op_sv);
5325 cSVOPo->op_sv = Nullsv;
5326 cSVOPo->op_targ = ix;
5331 Perl_ck_bitop(pTHX_ OP *o)
5333 o->op_private = PL_hints;
5338 Perl_ck_concat(pTHX_ OP *o)
5340 if (cUNOPo->op_first->op_type == OP_CONCAT)
5341 o->op_flags |= OPf_STACKED;
5346 Perl_ck_spair(pTHX_ OP *o)
5348 if (o->op_flags & OPf_KIDS) {
5351 OPCODE type = o->op_type;
5352 o = modkids(ck_fun(o), type);
5353 kid = cUNOPo->op_first;
5354 newop = kUNOP->op_first->op_sibling;
5356 (newop->op_sibling ||
5357 !(PL_opargs[newop->op_type] & OA_RETSCALAR) ||
5358 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
5359 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
5363 op_free(kUNOP->op_first);
5364 kUNOP->op_first = newop;
5366 o->op_ppaddr = PL_ppaddr[++o->op_type];
5371 Perl_ck_delete(pTHX_ OP *o)
5375 if (o->op_flags & OPf_KIDS) {
5376 OP *kid = cUNOPo->op_first;
5377 switch (kid->op_type) {
5379 o->op_flags |= OPf_SPECIAL;
5382 o->op_private |= OPpSLICE;
5385 o->op_flags |= OPf_SPECIAL;
5390 Perl_croak(aTHX_ "%s argument is not a HASH or ARRAY element or slice",
5391 PL_op_desc[o->op_type]);
5399 Perl_ck_eof(pTHX_ OP *o)
5401 I32 type = o->op_type;
5403 if (o->op_flags & OPf_KIDS) {
5404 if (cLISTOPo->op_first->op_type == OP_STUB) {
5406 o = newUNOP(type, OPf_SPECIAL,
5407 newGVOP(OP_GV, 0, gv_fetchpv("main::ARGV", TRUE, SVt_PVAV)));
5415 Perl_ck_eval(pTHX_ OP *o)
5417 PL_hints |= HINT_BLOCK_SCOPE;
5418 if (o->op_flags & OPf_KIDS) {
5419 SVOP *kid = (SVOP*)cUNOPo->op_first;
5422 o->op_flags &= ~OPf_KIDS;
5425 else if (kid->op_type == OP_LINESEQ) {
5428 kid->op_next = o->op_next;
5429 cUNOPo->op_first = 0;
5432 NewOp(1101, enter, 1, LOGOP);
5433 enter->op_type = OP_ENTERTRY;
5434 enter->op_ppaddr = PL_ppaddr[OP_ENTERTRY];
5435 enter->op_private = 0;
5437 /* establish postfix order */
5438 enter->op_next = (OP*)enter;
5440 o = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
5441 o->op_type = OP_LEAVETRY;
5442 o->op_ppaddr = PL_ppaddr[OP_LEAVETRY];
5443 enter->op_other = o;
5451 o = newUNOP(OP_ENTEREVAL, 0, newDEFSVOP());
5453 o->op_targ = (PADOFFSET)PL_hints;
5458 Perl_ck_exit(pTHX_ OP *o)
5461 HV *table = GvHV(PL_hintgv);
5463 SV **svp = hv_fetch(table, "vmsish_exit", 11, FALSE);
5464 if (svp && *svp && SvTRUE(*svp))
5465 o->op_private |= OPpEXIT_VMSISH;
5472 Perl_ck_exec(pTHX_ OP *o)
5475 if (o->op_flags & OPf_STACKED) {
5477 kid = cUNOPo->op_first->op_sibling;
5478 if (kid->op_type == OP_RV2GV)
5487 Perl_ck_exists(pTHX_ OP *o)
5490 if (o->op_flags & OPf_KIDS) {
5491 OP *kid = cUNOPo->op_first;
5492 if (kid->op_type == OP_ENTERSUB) {
5493 (void) ref(kid, o->op_type);
5494 if (kid->op_type != OP_RV2CV && !PL_error_count)
5495 Perl_croak(aTHX_ "%s argument is not a subroutine name",
5496 PL_op_desc[o->op_type]);
5497 o->op_private |= OPpEXISTS_SUB;
5499 else if (kid->op_type == OP_AELEM)
5500 o->op_flags |= OPf_SPECIAL;
5501 else if (kid->op_type != OP_HELEM)
5502 Perl_croak(aTHX_ "%s argument is not a HASH or ARRAY element",
5503 PL_op_desc[o->op_type]);
5511 Perl_ck_gvconst(pTHX_ register OP *o)
5513 o = fold_constants(o);
5514 if (o->op_type == OP_CONST)
5521 Perl_ck_rvconst(pTHX_ register OP *o)
5523 SVOP *kid = (SVOP*)cUNOPo->op_first;
5525 o->op_private |= (PL_hints & HINT_STRICT_REFS);
5526 if (kid->op_type == OP_CONST) {
5530 SV *kidsv = kid->op_sv;
5533 /* Is it a constant from cv_const_sv()? */
5534 if (SvROK(kidsv) && SvREADONLY(kidsv)) {
5535 SV *rsv = SvRV(kidsv);
5536 int svtype = SvTYPE(rsv);
5537 char *badtype = Nullch;
5539 switch (o->op_type) {
5541 if (svtype > SVt_PVMG)
5542 badtype = "a SCALAR";
5545 if (svtype != SVt_PVAV)
5546 badtype = "an ARRAY";
5549 if (svtype != SVt_PVHV) {
5550 if (svtype == SVt_PVAV) { /* pseudohash? */
5551 SV **ksv = av_fetch((AV*)rsv, 0, FALSE);
5552 if (ksv && SvROK(*ksv)
5553 && SvTYPE(SvRV(*ksv)) == SVt_PVHV)
5562 if (svtype != SVt_PVCV)
5567 Perl_croak(aTHX_ "Constant is not %s reference", badtype);
5570 name = SvPV(kidsv, n_a);
5571 if ((PL_hints & HINT_STRICT_REFS) && (kid->op_private & OPpCONST_BARE)) {
5572 char *badthing = Nullch;
5573 switch (o->op_type) {
5575 badthing = "a SCALAR";
5578 badthing = "an ARRAY";
5581 badthing = "a HASH";
5586 "Can't use bareword (\"%s\") as %s ref while \"strict refs\" in use",
5590 * This is a little tricky. We only want to add the symbol if we
5591 * didn't add it in the lexer. Otherwise we get duplicate strict
5592 * warnings. But if we didn't add it in the lexer, we must at
5593 * least pretend like we wanted to add it even if it existed before,
5594 * or we get possible typo warnings. OPpCONST_ENTERED says
5595 * whether the lexer already added THIS instance of this symbol.
5597 iscv = (o->op_type == OP_RV2CV) * 2;
5599 gv = gv_fetchpv(name,
5600 iscv | !(kid->op_private & OPpCONST_ENTERED),
5603 : o->op_type == OP_RV2SV
5605 : o->op_type == OP_RV2AV
5607 : o->op_type == OP_RV2HV
5610 } while (!gv && !(kid->op_private & OPpCONST_ENTERED) && !iscv++);
5612 kid->op_type = OP_GV;
5613 SvREFCNT_dec(kid->op_sv);
5615 /* XXX hack: dependence on sizeof(PADOP) <= sizeof(SVOP) */
5616 kPADOP->op_padix = pad_alloc(OP_GV, SVs_PADTMP);
5617 SvREFCNT_dec(PL_curpad[kPADOP->op_padix]);
5619 PL_curpad[kPADOP->op_padix] = SvREFCNT_inc(gv);
5621 kid->op_sv = SvREFCNT_inc(gv);
5623 kid->op_private = 0;
5624 kid->op_ppaddr = PL_ppaddr[OP_GV];
5631 Perl_ck_ftst(pTHX_ OP *o)
5633 I32 type = o->op_type;
5635 if (o->op_flags & OPf_REF) {
5638 else if (o->op_flags & OPf_KIDS && cUNOPo->op_first->op_type != OP_STUB) {
5639 SVOP *kid = (SVOP*)cUNOPo->op_first;
5641 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
5643 OP *newop = newGVOP(type, OPf_REF,
5644 gv_fetchpv(SvPVx(kid->op_sv, n_a), TRUE, SVt_PVIO));
5651 if (type == OP_FTTTY)
5652 o = newGVOP(type, OPf_REF, gv_fetchpv("main::STDIN", TRUE,
5655 o = newUNOP(type, 0, newDEFSVOP());
5661 Perl_ck_fun(pTHX_ OP *o)
5667 int type = o->op_type;
5668 register I32 oa = PL_opargs[type] >> OASHIFT;
5670 if (o->op_flags & OPf_STACKED) {
5671 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
5674 return no_fh_allowed(o);
5677 if (o->op_flags & OPf_KIDS) {
5679 tokid = &cLISTOPo->op_first;
5680 kid = cLISTOPo->op_first;
5681 if (kid->op_type == OP_PUSHMARK ||
5682 (kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK))
5684 tokid = &kid->op_sibling;
5685 kid = kid->op_sibling;
5687 if (!kid && PL_opargs[type] & OA_DEFGV)
5688 *tokid = kid = newDEFSVOP();
5692 sibl = kid->op_sibling;
5695 /* list seen where single (scalar) arg expected? */
5696 if (numargs == 1 && !(oa >> 4)
5697 && kid->op_type == OP_LIST && type != OP_SCALAR)
5699 return too_many_arguments(o,PL_op_desc[type]);
5712 if ((type == OP_PUSH || type == OP_UNSHIFT)
5713 && !kid->op_sibling && ckWARN(WARN_SYNTAX))
5714 Perl_warner(aTHX_ WARN_SYNTAX,
5715 "Useless use of %s with no values",
5718 if (kid->op_type == OP_CONST &&
5719 (kid->op_private & OPpCONST_BARE))
5721 char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
5722 OP *newop = newAVREF(newGVOP(OP_GV, 0,
5723 gv_fetchpv(name, TRUE, SVt_PVAV) ));
5724 if (ckWARN(WARN_DEPRECATED))
5725 Perl_warner(aTHX_ WARN_DEPRECATED,
5726 "Array @%s missing the @ in argument %"IVdf" of %s()",
5727 name, (IV)numargs, PL_op_desc[type]);
5730 kid->op_sibling = sibl;
5733 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
5734 bad_type(numargs, "array", PL_op_desc[type], kid);
5738 if (kid->op_type == OP_CONST &&
5739 (kid->op_private & OPpCONST_BARE))
5741 char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
5742 OP *newop = newHVREF(newGVOP(OP_GV, 0,
5743 gv_fetchpv(name, TRUE, SVt_PVHV) ));
5744 if (ckWARN(WARN_DEPRECATED))
5745 Perl_warner(aTHX_ WARN_DEPRECATED,
5746 "Hash %%%s missing the %% in argument %"IVdf" of %s()",
5747 name, (IV)numargs, PL_op_desc[type]);
5750 kid->op_sibling = sibl;
5753 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
5754 bad_type(numargs, "hash", PL_op_desc[type], kid);
5759 OP *newop = newUNOP(OP_NULL, 0, kid);
5760 kid->op_sibling = 0;
5762 newop->op_next = newop;
5764 kid->op_sibling = sibl;
5769 if (kid->op_type != OP_GV && kid->op_type != OP_RV2GV) {
5770 if (kid->op_type == OP_CONST &&
5771 (kid->op_private & OPpCONST_BARE))
5773 OP *newop = newGVOP(OP_GV, 0,
5774 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, n_a), TRUE,
5779 else if (kid->op_type == OP_READLINE) {
5780 /* neophyte patrol: open(<FH>), close(<FH>) etc. */
5781 bad_type(numargs, "HANDLE", PL_op_desc[o->op_type], kid);
5784 I32 flags = OPf_SPECIAL;
5788 /* is this op a FH constructor? */
5789 if (is_handle_constructor(o,numargs)) {
5790 char *name = Nullch;
5794 /* Set a flag to tell rv2gv to vivify
5795 * need to "prove" flag does not mean something
5796 * else already - NI-S 1999/05/07
5799 if (kid->op_type == OP_PADSV) {
5800 SV **namep = av_fetch(PL_comppad_name,
5802 if (namep && *namep)
5803 name = SvPV(*namep, len);
5805 else if (kid->op_type == OP_RV2SV
5806 && kUNOP->op_first->op_type == OP_GV)
5808 GV *gv = cGVOPx_gv(kUNOP->op_first);
5810 len = GvNAMELEN(gv);
5812 else if (kid->op_type == OP_AELEM
5813 || kid->op_type == OP_HELEM)
5815 name = "__ANONIO__";
5821 targ = pad_alloc(OP_RV2GV, SVs_PADTMP);
5822 namesv = PL_curpad[targ];
5823 (void)SvUPGRADE(namesv, SVt_PV);
5825 sv_setpvn(namesv, "$", 1);
5826 sv_catpvn(namesv, name, len);
5829 kid->op_sibling = 0;
5830 kid = newUNOP(OP_RV2GV, flags, scalar(kid));
5831 kid->op_targ = targ;
5832 kid->op_private |= priv;
5834 kid->op_sibling = sibl;
5840 mod(scalar(kid), type);
5844 tokid = &kid->op_sibling;
5845 kid = kid->op_sibling;
5847 o->op_private |= numargs;
5849 return too_many_arguments(o,PL_op_desc[o->op_type]);
5852 else if (PL_opargs[type] & OA_DEFGV) {
5854 return newUNOP(type, 0, newDEFSVOP());
5858 while (oa & OA_OPTIONAL)
5860 if (oa && oa != OA_LIST)
5861 return too_few_arguments(o,PL_op_desc[o->op_type]);
5867 Perl_ck_glob(pTHX_ OP *o)
5872 if ((o->op_flags & OPf_KIDS) && !cLISTOPo->op_first->op_sibling)
5873 append_elem(OP_GLOB, o, newDEFSVOP());
5875 if (!((gv = gv_fetchpv("glob", FALSE, SVt_PVCV)) && GvIMPORTED_CV(gv)))
5876 gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
5878 #if !defined(PERL_EXTERNAL_GLOB)
5879 /* XXX this can be tightened up and made more failsafe. */
5883 Perl_load_module(aTHX_ PERL_LOADMOD_NOIMPORT, newSVpvn("File::Glob", 10), Nullsv,
5885 gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
5886 glob_gv = gv_fetchpv("File::Glob::csh_glob", FALSE, SVt_PVCV);
5887 GvCV(gv) = GvCV(glob_gv);
5888 SvREFCNT_inc((SV*)GvCV(gv));
5889 GvIMPORTED_CV_on(gv);
5892 #endif /* PERL_EXTERNAL_GLOB */
5894 if (gv && GvIMPORTED_CV(gv)) {
5895 append_elem(OP_GLOB, o,
5896 newSVOP(OP_CONST, 0, newSViv(PL_glob_index++)));
5897 o->op_type = OP_LIST;
5898 o->op_ppaddr = PL_ppaddr[OP_LIST];
5899 cLISTOPo->op_first->op_type = OP_PUSHMARK;
5900 cLISTOPo->op_first->op_ppaddr = PL_ppaddr[OP_PUSHMARK];
5901 o = newUNOP(OP_ENTERSUB, OPf_STACKED,
5902 append_elem(OP_LIST, o,
5903 scalar(newUNOP(OP_RV2CV, 0,
5904 newGVOP(OP_GV, 0, gv)))));
5905 o = newUNOP(OP_NULL, 0, ck_subr(o));
5906 o->op_targ = OP_GLOB; /* hint at what it used to be */
5909 gv = newGVgen("main");
5911 append_elem(OP_GLOB, o, newGVOP(OP_GV, 0, gv));
5917 Perl_ck_grep(pTHX_ OP *o)
5921 OPCODE type = o->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
5923 o->op_ppaddr = PL_ppaddr[OP_GREPSTART];
5924 NewOp(1101, gwop, 1, LOGOP);
5926 if (o->op_flags & OPf_STACKED) {
5929 kid = cLISTOPo->op_first->op_sibling;
5930 for (k = cLISTOPo->op_first->op_sibling->op_next; k; k = k->op_next) {
5933 kid->op_next = (OP*)gwop;
5934 o->op_flags &= ~OPf_STACKED;
5936 kid = cLISTOPo->op_first->op_sibling;
5937 if (type == OP_MAPWHILE)
5944 kid = cLISTOPo->op_first->op_sibling;
5945 if (kid->op_type != OP_NULL)
5946 Perl_croak(aTHX_ "panic: ck_grep");
5947 kid = kUNOP->op_first;
5949 gwop->op_type = type;
5950 gwop->op_ppaddr = PL_ppaddr[type];
5951 gwop->op_first = listkids(o);
5952 gwop->op_flags |= OPf_KIDS;
5953 gwop->op_private = 1;
5954 gwop->op_other = LINKLIST(kid);
5955 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
5956 kid->op_next = (OP*)gwop;
5958 kid = cLISTOPo->op_first->op_sibling;
5959 if (!kid || !kid->op_sibling)
5960 return too_few_arguments(o,PL_op_desc[o->op_type]);
5961 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
5962 mod(kid, OP_GREPSTART);
5968 Perl_ck_index(pTHX_ OP *o)
5970 if (o->op_flags & OPf_KIDS) {
5971 OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5973 kid = kid->op_sibling; /* get past "big" */
5974 if (kid && kid->op_type == OP_CONST)
5975 fbm_compile(((SVOP*)kid)->op_sv, 0);
5981 Perl_ck_lengthconst(pTHX_ OP *o)
5983 /* XXX length optimization goes here */
5988 Perl_ck_lfun(pTHX_ OP *o)
5990 OPCODE type = o->op_type;
5991 return modkids(ck_fun(o), type);
5995 Perl_ck_defined(pTHX_ OP *o) /* 19990527 MJD */
5997 if ((o->op_flags & OPf_KIDS) && ckWARN(WARN_DEPRECATED)) {
5998 switch (cUNOPo->op_first->op_type) {
6000 /* This is needed for
6001 if (defined %stash::)
6002 to work. Do not break Tk.
6004 break; /* Globals via GV can be undef */
6006 case OP_AASSIGN: /* Is this a good idea? */
6007 Perl_warner(aTHX_ WARN_DEPRECATED,
6008 "defined(@array) is deprecated");
6009 Perl_warner(aTHX_ WARN_DEPRECATED,
6010 "\t(Maybe you should just omit the defined()?)\n");
6013 /* This is needed for
6014 if (defined %stash::)
6015 to work. Do not break Tk.
6017 break; /* Globals via GV can be undef */
6019 Perl_warner(aTHX_ WARN_DEPRECATED,
6020 "defined(%%hash) is deprecated");
6021 Perl_warner(aTHX_ WARN_DEPRECATED,
6022 "\t(Maybe you should just omit the defined()?)\n");
6033 Perl_ck_rfun(pTHX_ OP *o)
6035 OPCODE type = o->op_type;
6036 return refkids(ck_fun(o), type);
6040 Perl_ck_listiob(pTHX_ OP *o)
6044 kid = cLISTOPo->op_first;
6047 kid = cLISTOPo->op_first;
6049 if (kid->op_type == OP_PUSHMARK)
6050 kid = kid->op_sibling;
6051 if (kid && o->op_flags & OPf_STACKED)
6052 kid = kid->op_sibling;
6053 else if (kid && !kid->op_sibling) { /* print HANDLE; */
6054 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
6055 o->op_flags |= OPf_STACKED; /* make it a filehandle */
6056 kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
6057 cLISTOPo->op_first->op_sibling = kid;
6058 cLISTOPo->op_last = kid;
6059 kid = kid->op_sibling;
6064 append_elem(o->op_type, o, newDEFSVOP());
6070 Perl_ck_sassign(pTHX_ OP *o)
6072 OP *kid = cLISTOPo->op_first;
6073 /* has a disposable target? */
6074 if ((PL_opargs[kid->op_type] & OA_TARGLEX)
6075 && !(kid->op_flags & OPf_STACKED)
6076 /* Cannot steal the second time! */
6077 && !(kid->op_private & OPpTARGET_MY))
6079 OP *kkid = kid->op_sibling;
6081 /* Can just relocate the target. */
6082 if (kkid && kkid->op_type == OP_PADSV
6083 && !(kkid->op_private & OPpLVAL_INTRO))
6085 kid->op_targ = kkid->op_targ;
6087 /* Now we do not need PADSV and SASSIGN. */
6088 kid->op_sibling = o->op_sibling; /* NULL */
6089 cLISTOPo->op_first = NULL;
6092 kid->op_private |= OPpTARGET_MY; /* Used for context settings */
6100 Perl_ck_match(pTHX_ OP *o)
6102 o->op_private |= OPpRUNTIME;
6107 Perl_ck_method(pTHX_ OP *o)
6109 OP *kid = cUNOPo->op_first;
6110 if (kid->op_type == OP_CONST) {
6111 SV* sv = kSVOP->op_sv;
6112 if (!(strchr(SvPVX(sv), ':') || strchr(SvPVX(sv), '\''))) {
6114 if (!SvREADONLY(sv) || !SvFAKE(sv)) {
6115 sv = newSVpvn_share(SvPVX(sv), SvCUR(sv), 0);
6118 kSVOP->op_sv = Nullsv;
6120 cmop = newSVOP(OP_METHOD_NAMED, 0, sv);
6129 Perl_ck_null(pTHX_ OP *o)
6135 Perl_ck_octmode(pTHX_ OP *o)
6139 if ((ckWARN(WARN_OCTMODE)
6140 /* Add WARN_MKDIR instead of getting rid of WARN_{CHMOD,UMASK}.
6141 Backwards compatibility and consistency are terrible things.
6143 || (o->op_type == OP_CHMOD && ckWARN(WARN_CHMOD))
6144 || (o->op_type == OP_UMASK && ckWARN(WARN_UMASK))
6145 || (o->op_type == OP_MKDIR && ckWARN(WARN_MKDIR)))
6146 && o->op_flags & OPf_KIDS)
6148 if (o->op_type == OP_MKDIR)
6149 p = cLISTOPo->op_last; /* mkdir $foo, 0777 */
6150 else if (o->op_type == OP_CHMOD)
6151 p = cLISTOPo->op_first->op_sibling; /* chmod 0777, $foo */
6153 p = cUNOPo->op_first; /* umask 0222 */
6155 if (p->op_type == OP_CONST && !(p->op_private & OPpCONST_OCTAL)) {
6156 int mode = SvIV(cSVOPx_sv(p));
6158 Perl_warner(aTHX_ WARN_OCTMODE,
6159 "Non-octal literal mode (%d) specified", mode);
6160 Perl_warner(aTHX_ WARN_OCTMODE,
6161 "\t(Did you mean 0%d instead?)\n", mode);
6168 Perl_ck_open(pTHX_ OP *o)
6170 HV *table = GvHV(PL_hintgv);
6174 svp = hv_fetch(table, "open_IN", 7, FALSE);
6176 mode = mode_from_discipline(*svp);
6177 if (mode & O_BINARY)
6178 o->op_private |= OPpOPEN_IN_RAW;
6179 else if (mode & O_TEXT)
6180 o->op_private |= OPpOPEN_IN_CRLF;
6183 svp = hv_fetch(table, "open_OUT", 8, FALSE);
6185 mode = mode_from_discipline(*svp);
6186 if (mode & O_BINARY)
6187 o->op_private |= OPpOPEN_OUT_RAW;
6188 else if (mode & O_TEXT)
6189 o->op_private |= OPpOPEN_OUT_CRLF;
6192 if (o->op_type == OP_BACKTICK)
6198 Perl_ck_repeat(pTHX_ OP *o)
6200 if (cBINOPo->op_first->op_flags & OPf_PARENS) {
6201 o->op_private |= OPpREPEAT_DOLIST;
6202 cBINOPo->op_first = force_list(cBINOPo->op_first);
6210 Perl_ck_require(pTHX_ OP *o)
6214 if (o->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
6215 SVOP *kid = (SVOP*)cUNOPo->op_first;
6217 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
6219 for (s = SvPVX(kid->op_sv); *s; s++) {
6220 if (*s == ':' && s[1] == ':') {
6222 Move(s+2, s+1, strlen(s+2)+1, char);
6223 --SvCUR(kid->op_sv);
6226 if (SvREADONLY(kid->op_sv)) {
6227 SvREADONLY_off(kid->op_sv);
6228 sv_catpvn(kid->op_sv, ".pm", 3);
6229 SvREADONLY_on(kid->op_sv);
6232 sv_catpvn(kid->op_sv, ".pm", 3);
6236 /* handle override, if any */
6237 gv = gv_fetchpv("require", FALSE, SVt_PVCV);
6238 if (!(gv && GvIMPORTED_CV(gv)))
6239 gv = gv_fetchpv("CORE::GLOBAL::require", FALSE, SVt_PVCV);
6241 if (gv && GvIMPORTED_CV(gv)) {
6242 OP *kid = cUNOPo->op_first;
6243 cUNOPo->op_first = 0;
6245 return ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
6246 append_elem(OP_LIST, kid,
6247 scalar(newUNOP(OP_RV2CV, 0,
6256 Perl_ck_return(pTHX_ OP *o)
6259 if (CvLVALUE(PL_compcv)) {
6260 for (kid = cLISTOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
6261 mod(kid, OP_LEAVESUBLV);
6268 Perl_ck_retarget(pTHX_ OP *o)
6270 Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
6277 Perl_ck_select(pTHX_ OP *o)
6280 if (o->op_flags & OPf_KIDS) {
6281 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
6282 if (kid && kid->op_sibling) {
6283 o->op_type = OP_SSELECT;
6284 o->op_ppaddr = PL_ppaddr[OP_SSELECT];
6286 return fold_constants(o);
6290 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
6291 if (kid && kid->op_type == OP_RV2GV)
6292 kid->op_private &= ~HINT_STRICT_REFS;
6297 Perl_ck_shift(pTHX_ OP *o)
6299 I32 type = o->op_type;
6301 if (!(o->op_flags & OPf_KIDS)) {
6306 if (!CvUNIQUE(PL_compcv)) {
6307 argop = newOP(OP_PADAV, OPf_REF);
6308 argop->op_targ = 0; /* PL_curpad[0] is @_ */
6311 argop = newUNOP(OP_RV2AV, 0,
6312 scalar(newGVOP(OP_GV, 0,
6313 gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
6316 argop = newUNOP(OP_RV2AV, 0,
6317 scalar(newGVOP(OP_GV, 0, !CvUNIQUE(PL_compcv) ?
6318 PL_defgv : gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
6319 #endif /* USE_THREADS */
6320 return newUNOP(type, 0, scalar(argop));
6322 return scalar(modkids(ck_fun(o), type));
6326 Perl_ck_sort(pTHX_ OP *o)
6330 if (o->op_type == OP_SORT && o->op_flags & OPf_STACKED)
6332 firstkid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
6333 if (o->op_flags & OPf_STACKED) { /* may have been cleared */
6335 OP *kid = cUNOPx(firstkid)->op_first; /* get past null */
6337 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
6339 if (kid->op_type == OP_SCOPE) {
6343 else if (kid->op_type == OP_LEAVE) {
6344 if (o->op_type == OP_SORT) {
6345 op_null(kid); /* wipe out leave */
6348 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
6349 if (k->op_next == kid)
6351 /* don't descend into loops */
6352 else if (k->op_type == OP_ENTERLOOP
6353 || k->op_type == OP_ENTERITER)
6355 k = cLOOPx(k)->op_lastop;
6360 kid->op_next = 0; /* just disconnect the leave */
6361 k = kLISTOP->op_first;
6366 if (o->op_type == OP_SORT) {
6367 /* provide scalar context for comparison function/block */
6373 o->op_flags |= OPf_SPECIAL;
6375 else if (kid->op_type == OP_RV2SV || kid->op_type == OP_PADSV)
6378 firstkid = firstkid->op_sibling;
6381 /* provide list context for arguments */
6382 if (o->op_type == OP_SORT)
6389 S_simplify_sort(pTHX_ OP *o)
6391 register OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
6395 if (!(o->op_flags & OPf_STACKED))
6397 GvMULTI_on(gv_fetchpv("a", TRUE, SVt_PV));
6398 GvMULTI_on(gv_fetchpv("b", TRUE, SVt_PV));
6399 kid = kUNOP->op_first; /* get past null */
6400 if (kid->op_type != OP_SCOPE)
6402 kid = kLISTOP->op_last; /* get past scope */
6403 switch(kid->op_type) {
6411 k = kid; /* remember this node*/
6412 if (kBINOP->op_first->op_type != OP_RV2SV)
6414 kid = kBINOP->op_first; /* get past cmp */
6415 if (kUNOP->op_first->op_type != OP_GV)
6417 kid = kUNOP->op_first; /* get past rv2sv */
6419 if (GvSTASH(gv) != PL_curstash)
6421 if (strEQ(GvNAME(gv), "a"))
6423 else if (strEQ(GvNAME(gv), "b"))
6427 kid = k; /* back to cmp */
6428 if (kBINOP->op_last->op_type != OP_RV2SV)
6430 kid = kBINOP->op_last; /* down to 2nd arg */
6431 if (kUNOP->op_first->op_type != OP_GV)
6433 kid = kUNOP->op_first; /* get past rv2sv */
6435 if (GvSTASH(gv) != PL_curstash
6437 ? strNE(GvNAME(gv), "a")
6438 : strNE(GvNAME(gv), "b")))
6440 o->op_flags &= ~(OPf_STACKED | OPf_SPECIAL);
6442 o->op_private |= OPpSORT_REVERSE;
6443 if (k->op_type == OP_NCMP)
6444 o->op_private |= OPpSORT_NUMERIC;
6445 if (k->op_type == OP_I_NCMP)
6446 o->op_private |= OPpSORT_NUMERIC | OPpSORT_INTEGER;
6447 kid = cLISTOPo->op_first->op_sibling;
6448 cLISTOPo->op_first->op_sibling = kid->op_sibling; /* bypass old block */
6449 op_free(kid); /* then delete it */
6453 Perl_ck_split(pTHX_ OP *o)
6457 if (o->op_flags & OPf_STACKED)
6458 return no_fh_allowed(o);
6460 kid = cLISTOPo->op_first;
6461 if (kid->op_type != OP_NULL)
6462 Perl_croak(aTHX_ "panic: ck_split");
6463 kid = kid->op_sibling;
6464 op_free(cLISTOPo->op_first);
6465 cLISTOPo->op_first = kid;
6467 cLISTOPo->op_first = kid = newSVOP(OP_CONST, 0, newSVpvn(" ", 1));
6468 cLISTOPo->op_last = kid; /* There was only one element previously */
6471 if (kid->op_type != OP_MATCH || kid->op_flags & OPf_STACKED) {
6472 OP *sibl = kid->op_sibling;
6473 kid->op_sibling = 0;
6474 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
6475 if (cLISTOPo->op_first == cLISTOPo->op_last)
6476 cLISTOPo->op_last = kid;
6477 cLISTOPo->op_first = kid;
6478 kid->op_sibling = sibl;
6481 kid->op_type = OP_PUSHRE;
6482 kid->op_ppaddr = PL_ppaddr[OP_PUSHRE];
6485 if (!kid->op_sibling)
6486 append_elem(OP_SPLIT, o, newDEFSVOP());
6488 kid = kid->op_sibling;
6491 if (!kid->op_sibling)
6492 append_elem(OP_SPLIT, o, newSVOP(OP_CONST, 0, newSViv(0)));
6494 kid = kid->op_sibling;
6497 if (kid->op_sibling)
6498 return too_many_arguments(o,PL_op_desc[o->op_type]);
6504 Perl_ck_join(pTHX_ OP *o)
6506 if (ckWARN(WARN_SYNTAX)) {
6507 OP *kid = cLISTOPo->op_first->op_sibling;
6508 if (kid && kid->op_type == OP_MATCH) {
6509 char *pmstr = "STRING";
6510 if (PM_GETRE(kPMOP))
6511 pmstr = PM_GETRE(kPMOP)->precomp;
6512 Perl_warner(aTHX_ WARN_SYNTAX,
6513 "/%s/ should probably be written as \"%s\"",
6521 Perl_ck_subr(pTHX_ OP *o)
6523 OP *prev = ((cUNOPo->op_first->op_sibling)
6524 ? cUNOPo : ((UNOP*)cUNOPo->op_first))->op_first;
6525 OP *o2 = prev->op_sibling;
6534 o->op_private |= OPpENTERSUB_HASTARG;
6535 for (cvop = o2; cvop->op_sibling; cvop = cvop->op_sibling) ;
6536 if (cvop->op_type == OP_RV2CV) {
6538 o->op_private |= (cvop->op_private & OPpENTERSUB_AMPER);
6539 op_null(cvop); /* disable rv2cv */
6540 tmpop = (SVOP*)((UNOP*)cvop)->op_first;
6541 if (tmpop->op_type == OP_GV && !(o->op_private & OPpENTERSUB_AMPER)) {
6542 GV *gv = cGVOPx_gv(tmpop);
6545 tmpop->op_private |= OPpEARLY_CV;
6546 else if (SvPOK(cv)) {
6547 namegv = CvANON(cv) ? gv : CvGV(cv);
6548 proto = SvPV((SV*)cv, n_a);
6552 else if (cvop->op_type == OP_METHOD || cvop->op_type == OP_METHOD_NAMED) {
6553 if (o2->op_type == OP_CONST)
6554 o2->op_private &= ~OPpCONST_STRICT;
6555 else if (o2->op_type == OP_LIST) {
6556 OP *o = ((UNOP*)o2)->op_first->op_sibling;
6557 if (o && o->op_type == OP_CONST)
6558 o->op_private &= ~OPpCONST_STRICT;
6561 o->op_private |= (PL_hints & HINT_STRICT_REFS);
6562 if (PERLDB_SUB && PL_curstash != PL_debstash)
6563 o->op_private |= OPpENTERSUB_DB;
6564 while (o2 != cvop) {
6568 return too_many_arguments(o, gv_ename(namegv));
6586 if (o2->op_type != OP_REFGEN && o2->op_type != OP_UNDEF)
6588 arg == 1 ? "block or sub {}" : "sub {}",
6589 gv_ename(namegv), o2);
6592 /* '*' allows any scalar type, including bareword */
6595 if (o2->op_type == OP_RV2GV)
6596 goto wrapref; /* autoconvert GLOB -> GLOBref */
6597 else if (o2->op_type == OP_CONST)
6598 o2->op_private &= ~OPpCONST_STRICT;
6599 else if (o2->op_type == OP_ENTERSUB) {
6600 /* accidental subroutine, revert to bareword */
6601 OP *gvop = ((UNOP*)o2)->op_first;
6602 if (gvop && gvop->op_type == OP_NULL) {
6603 gvop = ((UNOP*)gvop)->op_first;
6605 for (; gvop->op_sibling; gvop = gvop->op_sibling)
6608 (gvop->op_private & OPpENTERSUB_NOPAREN) &&
6609 (gvop = ((UNOP*)gvop)->op_first) &&
6610 gvop->op_type == OP_GV)
6612 GV *gv = cGVOPx_gv(gvop);
6613 OP *sibling = o2->op_sibling;
6614 SV *n = newSVpvn("",0);
6616 gv_fullname3(n, gv, "");
6617 if (SvCUR(n)>6 && strnEQ(SvPVX(n),"main::",6))
6618 sv_chop(n, SvPVX(n)+6);
6619 o2 = newSVOP(OP_CONST, 0, n);
6620 prev->op_sibling = o2;
6621 o2->op_sibling = sibling;
6633 if (o2->op_type != OP_RV2GV)
6634 bad_type(arg, "symbol", gv_ename(namegv), o2);
6637 if (o2->op_type != OP_ENTERSUB)
6638 bad_type(arg, "subroutine entry", gv_ename(namegv), o2);
6641 if (o2->op_type != OP_RV2SV
6642 && o2->op_type != OP_PADSV
6643 && o2->op_type != OP_HELEM
6644 && o2->op_type != OP_AELEM
6645 && o2->op_type != OP_THREADSV)
6647 bad_type(arg, "scalar", gv_ename(namegv), o2);
6651 if (o2->op_type != OP_RV2AV && o2->op_type != OP_PADAV)
6652 bad_type(arg, "array", gv_ename(namegv), o2);
6655 if (o2->op_type != OP_RV2HV && o2->op_type != OP_PADHV)
6656 bad_type(arg, "hash", gv_ename(namegv), o2);
6660 OP* sib = kid->op_sibling;
6661 kid->op_sibling = 0;
6662 o2 = newUNOP(OP_REFGEN, 0, kid);
6663 o2->op_sibling = sib;
6664 prev->op_sibling = o2;
6675 Perl_croak(aTHX_ "Malformed prototype for %s: %s",
6676 gv_ename(namegv), SvPV((SV*)cv, n_a));
6681 mod(o2, OP_ENTERSUB);
6683 o2 = o2->op_sibling;
6685 if (proto && !optional &&
6686 (*proto && *proto != '@' && *proto != '%' && *proto != ';'))
6687 return too_few_arguments(o, gv_ename(namegv));
6692 Perl_ck_svconst(pTHX_ OP *o)
6694 SvREADONLY_on(cSVOPo->op_sv);
6699 Perl_ck_trunc(pTHX_ OP *o)
6701 if (o->op_flags & OPf_KIDS) {
6702 SVOP *kid = (SVOP*)cUNOPo->op_first;
6704 if (kid->op_type == OP_NULL)
6705 kid = (SVOP*)kid->op_sibling;
6706 if (kid && kid->op_type == OP_CONST &&
6707 (kid->op_private & OPpCONST_BARE))
6709 o->op_flags |= OPf_SPECIAL;
6710 kid->op_private &= ~OPpCONST_STRICT;
6717 Perl_ck_substr(pTHX_ OP *o)
6720 if ((o->op_flags & OPf_KIDS) && o->op_private == 4) {
6721 OP *kid = cLISTOPo->op_first;
6723 if (kid->op_type == OP_NULL)
6724 kid = kid->op_sibling;
6726 kid->op_flags |= OPf_MOD;
6732 /* A peephole optimizer. We visit the ops in the order they're to execute. */
6735 Perl_peep(pTHX_ register OP *o)
6737 register OP* oldop = 0;
6740 if (!o || o->op_seq)
6744 SAVEVPTR(PL_curcop);
6745 for (; o; o = o->op_next) {
6751 switch (o->op_type) {
6755 PL_curcop = ((COP*)o); /* for warnings */
6756 o->op_seq = PL_op_seqmax++;
6760 if (cSVOPo->op_private & OPpCONST_STRICT)
6761 no_bareword_allowed(o);
6763 /* Relocate sv to the pad for thread safety.
6764 * Despite being a "constant", the SV is written to,
6765 * for reference counts, sv_upgrade() etc. */
6767 PADOFFSET ix = pad_alloc(OP_CONST, SVs_PADTMP);
6768 if (SvPADTMP(cSVOPo->op_sv)) {
6769 /* If op_sv is already a PADTMP then it is being used by
6770 * some pad, so make a copy. */
6771 sv_setsv(PL_curpad[ix],cSVOPo->op_sv);
6772 SvREADONLY_on(PL_curpad[ix]);
6773 SvREFCNT_dec(cSVOPo->op_sv);
6776 SvREFCNT_dec(PL_curpad[ix]);
6777 SvPADTMP_on(cSVOPo->op_sv);
6778 PL_curpad[ix] = cSVOPo->op_sv;
6779 /* XXX I don't know how this isn't readonly already. */
6780 SvREADONLY_on(PL_curpad[ix]);
6782 cSVOPo->op_sv = Nullsv;
6786 o->op_seq = PL_op_seqmax++;
6790 if (o->op_next && o->op_next->op_type == OP_STRINGIFY) {
6791 if (o->op_next->op_private & OPpTARGET_MY) {
6792 if (o->op_flags & OPf_STACKED) /* chained concats */
6793 goto ignore_optimization;
6795 /* assert(PL_opargs[o->op_type] & OA_TARGLEX); */
6796 o->op_targ = o->op_next->op_targ;
6797 o->op_next->op_targ = 0;
6798 o->op_private |= OPpTARGET_MY;
6801 op_null(o->op_next);
6803 ignore_optimization:
6804 o->op_seq = PL_op_seqmax++;
6807 if ((o->op_flags & OPf_WANT) != OPf_WANT_LIST) {
6808 o->op_seq = PL_op_seqmax++;
6809 break; /* Scalar stub must produce undef. List stub is noop */
6813 if (o->op_targ == OP_NEXTSTATE
6814 || o->op_targ == OP_DBSTATE
6815 || o->op_targ == OP_SETSTATE)
6817 PL_curcop = ((COP*)o);
6824 if (oldop && o->op_next) {
6825 oldop->op_next = o->op_next;
6828 o->op_seq = PL_op_seqmax++;
6832 if (o->op_next->op_type == OP_RV2SV) {
6833 if (!(o->op_next->op_private & OPpDEREF)) {
6834 op_null(o->op_next);
6835 o->op_private |= o->op_next->op_private & (OPpLVAL_INTRO
6837 o->op_next = o->op_next->op_next;
6838 o->op_type = OP_GVSV;
6839 o->op_ppaddr = PL_ppaddr[OP_GVSV];
6842 else if (o->op_next->op_type == OP_RV2AV) {
6843 OP* pop = o->op_next->op_next;
6845 if (pop->op_type == OP_CONST &&
6846 (PL_op = pop->op_next) &&
6847 pop->op_next->op_type == OP_AELEM &&
6848 !(pop->op_next->op_private &
6849 (OPpLVAL_INTRO|OPpLVAL_DEFER|OPpDEREF|OPpMAYBE_LVSUB)) &&
6850 (i = SvIV(((SVOP*)pop)->op_sv) - PL_curcop->cop_arybase)
6855 op_null(o->op_next);
6856 op_null(pop->op_next);
6858 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
6859 o->op_next = pop->op_next->op_next;
6860 o->op_type = OP_AELEMFAST;
6861 o->op_ppaddr = PL_ppaddr[OP_AELEMFAST];
6862 o->op_private = (U8)i;
6867 else if ((o->op_private & OPpEARLY_CV) && ckWARN(WARN_PROTOTYPE)) {
6869 if (SvTYPE(gv) == SVt_PVGV && GvCV(gv) && SvPVX(GvCV(gv))) {
6870 /* XXX could check prototype here instead of just carping */
6871 SV *sv = sv_newmortal();
6872 gv_efullname3(sv, gv, Nullch);
6873 Perl_warner(aTHX_ WARN_PROTOTYPE,
6874 "%s() called too early to check prototype",
6879 o->op_seq = PL_op_seqmax++;
6890 o->op_seq = PL_op_seqmax++;
6891 while (cLOGOP->op_other->op_type == OP_NULL)
6892 cLOGOP->op_other = cLOGOP->op_other->op_next;
6893 peep(cLOGOP->op_other);
6898 o->op_seq = PL_op_seqmax++;
6899 while (cLOOP->op_redoop->op_type == OP_NULL)
6900 cLOOP->op_redoop = cLOOP->op_redoop->op_next;
6901 peep(cLOOP->op_redoop);
6902 while (cLOOP->op_nextop->op_type == OP_NULL)
6903 cLOOP->op_nextop = cLOOP->op_nextop->op_next;
6904 peep(cLOOP->op_nextop);
6905 while (cLOOP->op_lastop->op_type == OP_NULL)
6906 cLOOP->op_lastop = cLOOP->op_lastop->op_next;
6907 peep(cLOOP->op_lastop);
6913 o->op_seq = PL_op_seqmax++;
6914 while (cPMOP->op_pmreplstart &&
6915 cPMOP->op_pmreplstart->op_type == OP_NULL)
6916 cPMOP->op_pmreplstart = cPMOP->op_pmreplstart->op_next;
6917 peep(cPMOP->op_pmreplstart);
6921 o->op_seq = PL_op_seqmax++;
6922 if (ckWARN(WARN_SYNTAX) && o->op_next
6923 && o->op_next->op_type == OP_NEXTSTATE) {
6924 if (o->op_next->op_sibling &&
6925 o->op_next->op_sibling->op_type != OP_EXIT &&
6926 o->op_next->op_sibling->op_type != OP_WARN &&
6927 o->op_next->op_sibling->op_type != OP_DIE) {
6928 line_t oldline = CopLINE(PL_curcop);
6930 CopLINE_set(PL_curcop, CopLINE((COP*)o->op_next));
6931 Perl_warner(aTHX_ WARN_EXEC,
6932 "Statement unlikely to be reached");
6933 Perl_warner(aTHX_ WARN_EXEC,
6934 "\t(Maybe you meant system() when you said exec()?)\n");
6935 CopLINE_set(PL_curcop, oldline);
6944 SV **svp, **indsvp, *sv;
6949 o->op_seq = PL_op_seqmax++;
6951 if (((BINOP*)o)->op_last->op_type != OP_CONST)
6954 /* Make the CONST have a shared SV */
6955 svp = cSVOPx_svp(((BINOP*)o)->op_last);
6956 if ((!SvFAKE(sv = *svp) || !SvREADONLY(sv)) && !IS_PADCONST(sv)) {
6957 key = SvPV(sv, keylen);
6958 lexname = newSVpvn_share(key,
6959 SvUTF8(sv) ? -(I32)keylen : keylen,
6965 if ((o->op_private & (OPpLVAL_INTRO)))
6968 rop = (UNOP*)((BINOP*)o)->op_first;
6969 if (rop->op_type != OP_RV2HV || rop->op_first->op_type != OP_PADSV)
6971 lexname = *av_fetch(PL_comppad_name, rop->op_first->op_targ, TRUE);
6972 if (!(SvFLAGS(lexname) & SVpad_TYPED))
6974 fields = (GV**)hv_fetch(SvSTASH(lexname), "FIELDS", 6, FALSE);
6975 if (!fields || !GvHV(*fields))
6977 key = SvPV(*svp, keylen);
6978 indsvp = hv_fetch(GvHV(*fields), key,
6979 SvUTF8(*svp) ? -(I32)keylen : keylen, FALSE);
6981 Perl_croak(aTHX_ "No such pseudo-hash field \"%s\" in variable %s of type %s",
6982 key, SvPV(lexname, n_a), HvNAME(SvSTASH(lexname)));
6984 ind = SvIV(*indsvp);
6986 Perl_croak(aTHX_ "Bad index while coercing array into hash");
6987 rop->op_type = OP_RV2AV;
6988 rop->op_ppaddr = PL_ppaddr[OP_RV2AV];
6989 o->op_type = OP_AELEM;
6990 o->op_ppaddr = PL_ppaddr[OP_AELEM];
6992 if (SvREADONLY(*svp))
6994 SvFLAGS(sv) |= (SvFLAGS(*svp)
6995 & (SVs_PADBUSY|SVs_PADTMP|SVs_PADMY));
7005 SV **svp, **indsvp, *sv;
7009 SVOP *first_key_op, *key_op;
7011 o->op_seq = PL_op_seqmax++;
7012 if ((o->op_private & (OPpLVAL_INTRO))
7013 /* I bet there's always a pushmark... */
7014 || ((LISTOP*)o)->op_first->op_sibling->op_type != OP_LIST)
7015 /* hmmm, no optimization if list contains only one key. */
7017 rop = (UNOP*)((LISTOP*)o)->op_last;
7018 if (rop->op_type != OP_RV2HV || rop->op_first->op_type != OP_PADSV)
7020 lexname = *av_fetch(PL_comppad_name, rop->op_first->op_targ, TRUE);
7021 if (!(SvFLAGS(lexname) & SVpad_TYPED))
7023 fields = (GV**)hv_fetch(SvSTASH(lexname), "FIELDS", 6, FALSE);
7024 if (!fields || !GvHV(*fields))
7026 /* Again guessing that the pushmark can be jumped over.... */
7027 first_key_op = (SVOP*)((LISTOP*)((LISTOP*)o)->op_first->op_sibling)
7028 ->op_first->op_sibling;
7029 /* Check that the key list contains only constants. */
7030 for (key_op = first_key_op; key_op;
7031 key_op = (SVOP*)key_op->op_sibling)
7032 if (key_op->op_type != OP_CONST)
7036 rop->op_type = OP_RV2AV;
7037 rop->op_ppaddr = PL_ppaddr[OP_RV2AV];
7038 o->op_type = OP_ASLICE;
7039 o->op_ppaddr = PL_ppaddr[OP_ASLICE];
7040 for (key_op = first_key_op; key_op;
7041 key_op = (SVOP*)key_op->op_sibling) {
7042 svp = cSVOPx_svp(key_op);
7043 key = SvPV(*svp, keylen);
7044 indsvp = hv_fetch(GvHV(*fields), key,
7045 SvUTF8(*svp) ? -(I32)keylen : keylen, FALSE);
7047 Perl_croak(aTHX_ "No such pseudo-hash field \"%s\" "
7048 "in variable %s of type %s",
7049 key, SvPV(lexname, n_a), HvNAME(SvSTASH(lexname)));
7051 ind = SvIV(*indsvp);
7053 Perl_croak(aTHX_ "Bad index while coercing array into hash");
7055 if (SvREADONLY(*svp))
7057 SvFLAGS(sv) |= (SvFLAGS(*svp)
7058 & (SVs_PADBUSY|SVs_PADTMP|SVs_PADMY));
7066 o->op_seq = PL_op_seqmax++;
7076 /* Efficient sub that returns a constant scalar value. */
7078 const_sv_xsub(pTHXo_ CV* cv)
7083 Perl_croak(aTHX_ "usage: %s::%s()",
7084 HvNAME(GvSTASH(CvGV(cv))), GvNAME(CvGV(cv)));
7088 ST(0) = (SV*)XSANY.any_ptr;