3 * Copyright (c) 1991-1997, 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
22 #define CHECKCALL this->*check
24 #define CHECKCALL *check
28 * In the following definition, the ", Nullop" is just to make the compiler
29 * think the expression is of the right type: croak actually does a Siglongjmp.
31 #define CHECKOP(type,o) \
32 ((PL_op_mask && PL_op_mask[type]) \
33 ? ( op_free((OP*)o), \
34 croak("%s trapped by operation mask", op_desc[type]), \
36 : (CHECKCALL[type])((OP*)o))
38 static bool scalar_mod_type _((OP *o, I32 type));
40 static I32 list_assignment _((OP *o));
41 static void bad_type _((I32 n, char *t, char *name, OP *kid));
42 static OP *modkids _((OP *o, I32 type));
43 static OP *no_fh_allowed _((OP *o));
44 static OP *scalarboolean _((OP *o));
45 static OP *too_few_arguments _((OP *o, char* name));
46 static OP *too_many_arguments _((OP *o, char* name));
47 static void null _((OP* o));
48 static PADOFFSET pad_findlex _((char* name, PADOFFSET newoff, U32 seq,
49 CV* startcv, I32 cx_ix));
50 static OP *newDEFSVOP _((void));
51 static OP *new_logop _((I32 type, I32 flags, OP **firstp, OP **otherp));
57 SV* tmpsv = sv_newmortal();
58 gv_efullname3(tmpsv, gv, Nullch);
59 return SvPV(tmpsv,PL_na);
65 yyerror(form("Missing comma after first argument to %s function",
66 op_desc[o->op_type]));
71 too_few_arguments(OP *o, char *name)
73 yyerror(form("Not enough arguments for %s", name));
78 too_many_arguments(OP *o, char *name)
80 yyerror(form("Too many arguments for %s", name));
85 bad_type(I32 n, char *t, char *name, OP *kid)
87 yyerror(form("Type of arg %d to %s must be %s (not %s)",
88 (int)n, name, t, op_desc[kid->op_type]));
94 int type = o->op_type;
95 if (type != OP_AELEM && type != OP_HELEM) {
96 yyerror(form("Can't use subscript on %s", op_desc[type]));
97 if (type == OP_ENTERSUB || type == OP_RV2HV || type == OP_PADHV) {
100 newSVpvf("(Did you mean $ or @ instead of %c?)\n",
101 type == OP_ENTERSUB ? '&' : '%'));
105 sv_catsv(GvSV(PL_errgv), msg);
107 PerlIO_write(PerlIO_stderr(), SvPVX(msg), SvCUR(msg));
112 /* "register" allocation */
115 pad_allocmy(char *name)
121 if (!(isALPHA(name[1]) || name[1] == '_' && (int)strlen(name) > 2)) {
122 if (!isPRINT(name[1])) {
124 name[2] = toCTRL(name[1]);
127 croak("Can't use global %s in \"my\"",name);
129 if (PL_dowarn && AvFILLp(PL_comppad_name) >= 0) {
130 SV **svp = AvARRAY(PL_comppad_name);
131 for (off = AvFILLp(PL_comppad_name); off > PL_comppad_name_floor; off--) {
133 && sv != &PL_sv_undef
134 && SvIVX(sv) == 999999999 /* var is in open scope */
135 && strEQ(name, SvPVX(sv)))
137 warn("\"my\" variable %s masks earlier declaration in same scope", name);
142 off = pad_alloc(OP_PADSV, SVs_PADMY);
144 sv_upgrade(sv, SVt_PVNV);
146 if (PL_in_my_stash) {
148 croak("Can't declare class for non-scalar %s in \"my\"",name);
150 (void)SvUPGRADE(sv, SVt_PVMG);
151 SvSTASH(sv) = (HV*)SvREFCNT_inc(PL_in_my_stash);
154 av_store(PL_comppad_name, off, sv);
155 SvNVX(sv) = (double)999999999;
156 SvIVX(sv) = 0; /* Not yet introduced--see newSTATEOP */
157 if (!PL_min_intro_pending)
158 PL_min_intro_pending = off;
159 PL_max_intro_pending = off;
161 av_store(PL_comppad, off, (SV*)newAV());
162 else if (*name == '%')
163 av_store(PL_comppad, off, (SV*)newHV());
164 SvPADMY_on(PL_curpad[off]);
169 pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix)
176 register PERL_CONTEXT *cx;
179 for (cv = startcv; cv; cv = CvOUTSIDE(cv)) {
180 AV *curlist = CvPADLIST(cv);
181 SV **svp = av_fetch(curlist, 0, FALSE);
184 if (!svp || *svp == &PL_sv_undef)
187 svp = AvARRAY(curname);
188 for (off = AvFILLp(curname); off > 0; off--) {
189 if ((sv = svp[off]) &&
190 sv != &PL_sv_undef &&
192 seq > I_32(SvNVX(sv)) &&
193 strEQ(SvPVX(sv), name))
204 return 0; /* don't clone from inactive stack frame */
208 oldpad = (AV*)*av_fetch(curlist, depth, FALSE);
209 oldsv = *av_fetch(oldpad, off, TRUE);
210 if (!newoff) { /* Not a mere clone operation. */
211 SV *namesv = NEWSV(1103,0);
212 newoff = pad_alloc(OP_PADSV, SVs_PADMY);
213 sv_upgrade(namesv, SVt_PVNV);
214 sv_setpv(namesv, name);
215 av_store(PL_comppad_name, newoff, namesv);
216 SvNVX(namesv) = (double)PL_curcop->cop_seq;
217 SvIVX(namesv) = 999999999; /* A ref, intro immediately */
218 SvFAKE_on(namesv); /* A ref, not a real var */
219 if (CvANON(PL_compcv) || SvTYPE(PL_compcv) == SVt_PVFM) {
220 /* "It's closures all the way down." */
221 CvCLONE_on(PL_compcv);
223 if (CvANON(PL_compcv))
224 oldsv = Nullsv; /* no need to keep ref */
229 bcv && bcv != cv && !CvCLONE(bcv);
230 bcv = CvOUTSIDE(bcv)) {
234 if (PL_dowarn && !CvUNIQUE(cv))
236 "Variable \"%s\" may be unavailable",
243 else if (!CvUNIQUE(PL_compcv)) {
244 if (PL_dowarn && !SvFAKE(sv) && !CvUNIQUE(cv))
245 warn("Variable \"%s\" will not stay shared", name);
248 av_store(PL_comppad, newoff, SvREFCNT_inc(oldsv));
254 /* Nothing in current lexical context--try eval's context, if any.
255 * This is necessary to let the perldb get at lexically scoped variables.
256 * XXX This will also probably interact badly with eval tree caching.
260 for (i = cx_ix; i >= 0; i--) {
262 switch (cx->cx_type) {
264 if (i == 0 && saweval) {
265 seq = cxstack[saweval].blk_oldcop->cop_seq;
266 return pad_findlex(name, newoff, seq, PL_main_cv, 0);
270 switch (cx->blk_eval.old_op_type) {
275 /* require must have its own scope */
283 if (PL_debstash && CvSTASH(cv) == PL_debstash) { /* ignore DB'* scope */
284 saweval = i; /* so we know where we were called from */
287 seq = cxstack[saweval].blk_oldcop->cop_seq;
288 return pad_findlex(name, newoff, seq, cv, i-1);
296 pad_findmy(char *name)
302 SV **svp = AvARRAY(PL_comppad_name);
303 U32 seq = PL_cop_seqmax;
307 * Special case to get lexical (and hence per-thread) @_.
308 * XXX I need to find out how to tell at parse-time whether use
309 * of @_ should refer to a lexical (from a sub) or defgv (global
310 * scope and maybe weird sub-ish things like formats). See
311 * startsub in perly.y. It's possible that @_ could be lexical
312 * (at least from subs) even in non-threaded perl.
314 if (strEQ(name, "@_"))
315 return 0; /* success. (NOT_IN_PAD indicates failure) */
316 #endif /* USE_THREADS */
318 /* The one we're looking for is probably just before comppad_name_fill. */
319 for (off = AvFILLp(PL_comppad_name); off > 0; off--) {
320 if ((sv = svp[off]) &&
321 sv != &PL_sv_undef &&
324 seq > I_32(SvNVX(sv)))) &&
325 strEQ(SvPVX(sv), name))
328 return (PADOFFSET)off;
329 pendoff = off; /* this pending def. will override import */
333 /* See if it's in a nested scope */
334 off = pad_findlex(name, 0, seq, CvOUTSIDE(PL_compcv), cxstack_ix);
336 /* If there is a pending local definition, this new alias must die */
338 SvIVX(AvARRAY(PL_comppad_name)[off]) = seq;
339 return off; /* pad_findlex returns 0 for failure...*/
341 return NOT_IN_PAD; /* ...but we return NOT_IN_PAD for failure */
345 pad_leavemy(I32 fill)
348 SV **svp = AvARRAY(PL_comppad_name);
350 if (PL_min_intro_pending && fill < PL_min_intro_pending) {
351 for (off = PL_max_intro_pending; off >= PL_min_intro_pending; off--) {
352 if ((sv = svp[off]) && sv != &PL_sv_undef)
353 warn("%s never introduced", SvPVX(sv));
356 /* "Deintroduce" my variables that are leaving with this scope. */
357 for (off = AvFILLp(PL_comppad_name); off > fill; off--) {
358 if ((sv = svp[off]) && sv != &PL_sv_undef && SvIVX(sv) == 999999999)
359 SvIVX(sv) = PL_cop_seqmax;
364 pad_alloc(I32 optype, U32 tmptype)
370 if (AvARRAY(PL_comppad) != PL_curpad)
371 croak("panic: pad_alloc");
372 if (PL_pad_reset_pending)
374 if (tmptype & SVs_PADMY) {
376 sv = *av_fetch(PL_comppad, AvFILLp(PL_comppad) + 1, TRUE);
377 } while (SvPADBUSY(sv)); /* need a fresh one */
378 retval = AvFILLp(PL_comppad);
381 SV **names = AvARRAY(PL_comppad_name);
382 SSize_t names_fill = AvFILLp(PL_comppad_name);
385 * "foreach" index vars temporarily become aliases to non-"my"
386 * values. Thus we must skip, not just pad values that are
387 * marked as current pad values, but also those with names.
389 if (++PL_padix <= names_fill &&
390 (sv = names[PL_padix]) && sv != &PL_sv_undef)
392 sv = *av_fetch(PL_comppad, PL_padix, TRUE);
393 if (!(SvFLAGS(sv) & (SVs_PADTMP|SVs_PADMY)))
398 SvFLAGS(sv) |= tmptype;
399 PL_curpad = AvARRAY(PL_comppad);
401 DEBUG_X(PerlIO_printf(Perl_debug_log, "0x%lx Pad 0x%lx alloc %ld for %s\n",
402 (unsigned long) thr, (unsigned long) PL_curpad,
403 (long) retval, op_name[optype]));
405 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%lx alloc %ld for %s\n",
406 (unsigned long) PL_curpad,
407 (long) retval, op_name[optype]));
408 #endif /* USE_THREADS */
409 return (PADOFFSET)retval;
417 DEBUG_X(PerlIO_printf(Perl_debug_log, "0x%lx Pad 0x%lx sv %d\n",
418 (unsigned long) thr, (unsigned long) PL_curpad, po));
421 croak("panic: pad_sv po");
422 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%lx sv %d\n",
423 (unsigned long) PL_curpad, po));
424 #endif /* USE_THREADS */
425 return PL_curpad[po]; /* eventually we'll turn this into a macro */
429 pad_free(PADOFFSET po)
434 if (AvARRAY(PL_comppad) != PL_curpad)
435 croak("panic: pad_free curpad");
437 croak("panic: pad_free po");
439 DEBUG_X(PerlIO_printf(Perl_debug_log, "0x%lx Pad 0x%lx free %d\n",
440 (unsigned long) thr, (unsigned long) PL_curpad, po));
442 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%lx free %d\n",
443 (unsigned long) PL_curpad, po));
444 #endif /* USE_THREADS */
445 if (PL_curpad[po] && PL_curpad[po] != &PL_sv_undef)
446 SvPADTMP_off(PL_curpad[po]);
447 if ((I32)po < PL_padix)
452 pad_swipe(PADOFFSET po)
455 if (AvARRAY(PL_comppad) != PL_curpad)
456 croak("panic: pad_swipe curpad");
458 croak("panic: pad_swipe po");
460 DEBUG_X(PerlIO_printf(Perl_debug_log, "0x%lx Pad 0x%lx swipe %d\n",
461 (unsigned long) thr, (unsigned long) PL_curpad, po));
463 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%lx swipe %d\n",
464 (unsigned long) PL_curpad, po));
465 #endif /* USE_THREADS */
466 SvPADTMP_off(PL_curpad[po]);
467 PL_curpad[po] = NEWSV(1107,0);
468 SvPADTMP_on(PL_curpad[po]);
469 if ((I32)po < PL_padix)
473 /* XXX pad_reset() is currently disabled because it results in serious bugs.
474 * It causes pad temp TARGs to be shared between OPs. Since TARGs are pushed
475 * on the stack by OPs that use them, there are several ways to get an alias
476 * to a shared TARG. Such an alias will change randomly and unpredictably.
477 * We avoid doing this until we can think of a Better Way.
482 #ifdef USE_BROKEN_PAD_RESET
486 if (AvARRAY(PL_comppad) != PL_curpad)
487 croak("panic: pad_reset curpad");
489 DEBUG_X(PerlIO_printf(Perl_debug_log, "0x%lx Pad 0x%lx reset\n",
490 (unsigned long) thr, (unsigned long) PL_curpad));
492 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%lx reset\n",
493 (unsigned long) PL_curpad));
494 #endif /* USE_THREADS */
495 if (!PL_tainting) { /* Can't mix tainted and non-tainted temporaries. */
496 for (po = AvMAX(PL_comppad); po > PL_padix_floor; po--) {
497 if (PL_curpad[po] && !SvIMMORTAL(PL_curpad[po]))
498 SvPADTMP_off(PL_curpad[po]);
500 PL_padix = PL_padix_floor;
503 PL_pad_reset_pending = FALSE;
507 /* find_threadsv is not reentrant */
509 find_threadsv(char *name)
515 /* We currently only handle names of a single character */
516 p = strchr(PL_threadsv_names, *name);
519 key = p - PL_threadsv_names;
520 svp = av_fetch(thr->threadsv, key, FALSE);
522 SV *sv = NEWSV(0, 0);
523 av_store(thr->threadsv, key, sv);
524 thr->threadsvp = AvARRAY(thr->threadsv);
526 * Some magic variables used to be automagically initialised
527 * in gv_fetchpv. Those which are now per-thread magicals get
528 * initialised here instead.
534 sv_setpv(sv, "\034");
535 sv_magic(sv, 0, 0, name, 1);
540 PL_sawampersand = TRUE;
544 /* XXX %! tied to Errno.pm needs to be added here.
545 * See gv_fetchpv(). */
549 sv_magic(sv, 0, 0, name, 1);
551 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
552 "find_threadsv: new SV %p for $%s%c\n",
553 sv, (*name < 32) ? "^" : "",
554 (*name < 32) ? toCTRL(*name) : *name));
558 #endif /* USE_THREADS */
565 register OP *kid, *nextkid;
567 if (!o || o->op_seq == (U16)-1)
570 if (o->op_flags & OPf_KIDS) {
571 for (kid = cUNOPo->op_first; kid; kid = nextkid) {
572 nextkid = kid->op_sibling; /* Get before next freeing kid */
577 switch (o->op_type) {
579 o->op_targ = 0; /* Was holding old type, if any. */
582 o->op_targ = 0; /* Was holding hints. */
586 o->op_targ = 0; /* Was holding index into thr->threadsv AV. */
588 #endif /* USE_THREADS */
590 if (!(o->op_flags & OPf_REF)
591 || (check[o->op_type] != FUNC_NAME_TO_PTR(ck_ftst)))
597 SvREFCNT_dec(cGVOPo->op_gv);
601 Safefree(cCOPo->cop_label);
602 SvREFCNT_dec(cCOPo->cop_filegv);
605 SvREFCNT_dec(cSVOPo->op_sv);
611 if (o->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
615 Safefree(cPVOPo->op_pv);
618 op_free(cPMOPo->op_pmreplroot);
623 ReREFCNT_dec(cPMOPo->op_pmregexp);
628 pad_free(o->op_targ);
636 if (o->op_type != OP_NULL && o->op_type != OP_THREADSV && o->op_targ > 0)
637 pad_free(o->op_targ);
638 o->op_targ = o->op_type;
639 o->op_type = OP_NULL;
640 o->op_ppaddr = ppaddr[OP_NULL];
643 /* Contextualizers */
645 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
655 /* establish postfix order */
656 if (cUNOPo->op_first) {
657 o->op_next = LINKLIST(cUNOPo->op_first);
658 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
660 kid->op_next = LINKLIST(kid->op_sibling);
675 if (o && o->op_flags & OPf_KIDS) {
676 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
686 o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST) {
688 line_t oldline = PL_curcop->cop_line;
690 if (PL_copline != NOLINE)
691 PL_curcop->cop_line = PL_copline;
692 warn("Found = in conditional, should be ==");
693 PL_curcop->cop_line = oldline;
703 /* assumes no premature commitment */
704 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
705 || o->op_type == OP_RETURN)
708 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_SCALAR;
710 switch (o->op_type) {
712 if (o->op_private & OPpREPEAT_DOLIST)
713 null(((LISTOP*)cBINOPo->op_first)->op_first);
714 scalar(cBINOPo->op_first);
719 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
723 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
724 if (!kPMOP->op_pmreplroot)
725 deprecate("implicit split to @_");
733 if (o->op_flags & OPf_KIDS) {
734 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
740 kid = cLISTOPo->op_first;
742 while (kid = kid->op_sibling) {
748 WITH_THR(PL_curcop = &PL_compiling);
753 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
759 WITH_THR(PL_curcop = &PL_compiling);
772 /* assumes no premature commitment */
773 if (!o || (o->op_flags & OPf_WANT) == OPf_WANT_LIST || PL_error_count
774 || o->op_type == OP_RETURN)
777 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_VOID;
779 switch (o->op_type) {
781 if (!(opargs[o->op_type] & OA_FOLDCONST))
785 if (o->op_flags & OPf_STACKED)
789 if (o->op_private == 4)
860 if (!(o->op_private & OPpLVAL_INTRO))
861 useless = op_desc[o->op_type];
868 if (!(o->op_private & OPpLVAL_INTRO) &&
869 (!o->op_sibling || o->op_sibling->op_type != OP_READLINE))
870 useless = "a variable";
875 WITH_THR(PL_curcop = ((COP*)o)); /* for warning below */
881 useless = "a constant";
882 if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
884 else if (SvPOK(sv)) {
885 if (strnEQ(SvPVX(sv), "di", 2) ||
886 strnEQ(SvPVX(sv), "ds", 2) ||
887 strnEQ(SvPVX(sv), "ig", 2))
891 null(o); /* don't execute a constant */
892 SvREFCNT_dec(sv); /* don't even remember it */
896 o->op_type = OP_PREINC; /* pre-increment is faster */
897 o->op_ppaddr = ppaddr[OP_PREINC];
901 o->op_type = OP_PREDEC; /* pre-decrement is faster */
902 o->op_ppaddr = ppaddr[OP_PREDEC];
908 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
913 if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE)
914 WITH_THR(PL_curcop = ((COP*)o)); /* for warning below */
915 if (o->op_flags & OPf_STACKED)
921 if (!(o->op_flags & OPf_KIDS))
930 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
937 /* all requires must return a boolean value */
938 o->op_flags &= ~OPf_WANT;
941 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
942 if (!kPMOP->op_pmreplroot)
943 deprecate("implicit split to @_");
947 if (useless && PL_dowarn)
948 warn("Useless use of %s in void context", useless);
956 if (o && o->op_flags & OPf_KIDS) {
957 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
968 /* assumes no premature commitment */
969 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
970 || o->op_type == OP_RETURN)
973 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_LIST;
975 switch (o->op_type) {
978 list(cBINOPo->op_first);
983 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
991 if (!(o->op_flags & OPf_KIDS))
993 if (!o->op_next && cUNOPo->op_first->op_type == OP_FLOP) {
994 list(cBINOPo->op_first);
995 return gen_constant_list(o);
1002 kid = cLISTOPo->op_first;
1004 while (kid = kid->op_sibling) {
1005 if (kid->op_sibling)
1010 WITH_THR(PL_curcop = &PL_compiling);
1014 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
1015 if (kid->op_sibling)
1020 WITH_THR(PL_curcop = &PL_compiling);
1023 /* all requires must return a boolean value */
1024 o->op_flags &= ~OPf_WANT;
1036 if (o->op_type == OP_LINESEQ ||
1037 o->op_type == OP_SCOPE ||
1038 o->op_type == OP_LEAVE ||
1039 o->op_type == OP_LEAVETRY)
1042 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
1043 if (kid->op_sibling) {
1047 PL_curcop = &PL_compiling;
1049 o->op_flags &= ~OPf_PARENS;
1050 if (PL_hints & HINT_BLOCK_SCOPE)
1051 o->op_flags |= OPf_PARENS;
1054 o = newOP(OP_STUB, 0);
1059 modkids(OP *o, I32 type)
1062 if (o && o->op_flags & OPf_KIDS) {
1063 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1070 mod(OP *o, I32 type)
1076 if (!o || PL_error_count)
1079 switch (o->op_type) {
1084 if (!(o->op_private & (OPpCONST_ARYBASE)))
1086 if (PL_eval_start && PL_eval_start->op_type == OP_CONST) {
1087 PL_compiling.cop_arybase = (I32)SvIV(((SVOP*)PL_eval_start)->op_sv);
1091 SAVEI32(PL_compiling.cop_arybase);
1092 PL_compiling.cop_arybase = 0;
1094 else if (type == OP_REFGEN)
1097 croak("That use of $[ is unsupported");
1100 if (o->op_flags & OPf_PARENS)
1104 if ((type == OP_UNDEF || type == OP_REFGEN) &&
1105 !(o->op_flags & OPf_STACKED)) {
1106 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1107 o->op_ppaddr = ppaddr[OP_RV2CV];
1108 assert(cUNOPo->op_first->op_type == OP_NULL);
1109 null(((LISTOP*)cUNOPo->op_first)->op_first);/* disable pushmark */
1115 /* grep, foreach, subcalls, refgen */
1116 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
1118 yyerror(form("Can't modify %s in %s",
1119 op_desc[o->op_type],
1120 type ? op_desc[type] : "local"));
1134 case OP_RIGHT_SHIFT:
1143 if (!(o->op_flags & OPf_STACKED))
1149 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1155 if (!type && cUNOPo->op_first->op_type != OP_GV)
1156 croak("Can't localize through a reference");
1157 if (type == OP_REFGEN && o->op_flags & OPf_PARENS) {
1158 PL_modcount = 10000;
1159 return o; /* Treat \(@foo) like ordinary list. */
1163 if (scalar_mod_type(o, type))
1165 ref(cUNOPo->op_first, o->op_type);
1174 PL_modcount = 10000;
1177 if (!type && cUNOPo->op_first->op_type != OP_GV)
1178 croak("Can't localize through a reference");
1179 ref(cUNOPo->op_first, o->op_type);
1183 PL_hints |= HINT_BLOCK_SCOPE;
1191 PL_modcount = 10000;
1192 if (type == OP_REFGEN && o->op_flags & OPf_PARENS)
1193 return o; /* Treat \(@foo) like ordinary list. */
1194 if (scalar_mod_type(o, type))
1200 croak("Can't localize lexical variable %s",
1201 SvPV(*av_fetch(PL_comppad_name, o->op_targ, 4), PL_na));
1206 PL_modcount++; /* XXX ??? */
1208 #endif /* USE_THREADS */
1214 if (type != OP_SASSIGN)
1218 if (o->op_private == 4) /* don't allow 4 arg substr as lvalue */
1224 pad_free(o->op_targ);
1225 o->op_targ = pad_alloc(o->op_type, SVs_PADMY);
1226 assert(SvTYPE(PAD_SV(o->op_targ)) == SVt_NULL);
1227 if (o->op_flags & OPf_KIDS)
1228 mod(cBINOPo->op_first->op_sibling, type);
1233 ref(cBINOPo->op_first, o->op_type);
1234 if (type == OP_ENTERSUB &&
1235 !(o->op_private & (OPpLVAL_INTRO | OPpDEREF)))
1236 o->op_private |= OPpLVAL_DEFER;
1243 if (o->op_flags & OPf_KIDS)
1244 mod(cLISTOPo->op_last, type);
1248 if (!(o->op_flags & OPf_KIDS))
1250 if (o->op_targ != OP_LIST) {
1251 mod(cBINOPo->op_first, type);
1256 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1260 o->op_flags |= OPf_MOD;
1262 if (type == OP_AASSIGN || type == OP_SASSIGN)
1263 o->op_flags |= OPf_SPECIAL|OPf_REF;
1265 o->op_private |= OPpLVAL_INTRO;
1266 o->op_flags &= ~OPf_SPECIAL;
1267 PL_hints |= HINT_BLOCK_SCOPE;
1269 else if (type != OP_GREPSTART && type != OP_ENTERSUB)
1270 o->op_flags |= OPf_REF;
1275 scalar_mod_type(OP *o, I32 type)
1279 if (o->op_type == OP_RV2GV)
1303 case OP_RIGHT_SHIFT:
1313 case OP_ANDASSIGN: /* may work later */
1314 case OP_ORASSIGN: /* may work later */
1322 refkids(OP *o, I32 type)
1325 if (o && o->op_flags & OPf_KIDS) {
1326 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1333 ref(OP *o, I32 type)
1337 if (!o || PL_error_count)
1340 switch (o->op_type) {
1342 if ((type == OP_DEFINED || type == OP_LOCK) &&
1343 !(o->op_flags & OPf_STACKED)) {
1344 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1345 o->op_ppaddr = ppaddr[OP_RV2CV];
1346 assert(cUNOPo->op_first->op_type == OP_NULL);
1347 null(((LISTOP*)cUNOPo->op_first)->op_first); /* disable pushmark */
1348 o->op_flags |= OPf_SPECIAL;
1353 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1357 ref(cUNOPo->op_first, o->op_type);
1360 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1361 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1362 : type == OP_RV2HV ? OPpDEREF_HV
1364 o->op_flags |= OPf_MOD;
1369 o->op_flags |= OPf_MOD; /* XXX ??? */
1374 o->op_flags |= OPf_REF;
1377 ref(cUNOPo->op_first, o->op_type);
1382 o->op_flags |= OPf_REF;
1387 if (!(o->op_flags & OPf_KIDS))
1389 ref(cBINOPo->op_first, type);
1393 ref(cBINOPo->op_first, o->op_type);
1394 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1395 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1396 : type == OP_RV2HV ? OPpDEREF_HV
1398 o->op_flags |= OPf_MOD;
1406 if (!(o->op_flags & OPf_KIDS))
1408 ref(cLISTOPo->op_last, type);
1423 if (!o || PL_error_count)
1427 if (type == OP_LIST) {
1428 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1430 } else if (type == OP_UNDEF) {
1432 } else if (type != OP_PADSV &&
1435 type != OP_PUSHMARK)
1437 yyerror(form("Can't declare %s in my", op_desc[o->op_type]));
1440 o->op_flags |= OPf_MOD;
1441 o->op_private |= OPpLVAL_INTRO;
1449 o->op_flags |= OPf_PARENS;
1454 bind_match(I32 type, OP *left, OP *right)
1459 (left->op_type == OP_RV2AV ||
1460 left->op_type == OP_RV2HV ||
1461 left->op_type == OP_PADAV ||
1462 left->op_type == OP_PADHV)) {
1463 char *desc = op_desc[(right->op_type == OP_SUBST ||
1464 right->op_type == OP_TRANS)
1465 ? right->op_type : OP_MATCH];
1466 char *sample = ((left->op_type == OP_RV2AV ||
1467 left->op_type == OP_PADAV)
1468 ? "@array" : "%hash");
1469 warn("Applying %s to %s will act on scalar(%s)", desc, sample, sample);
1472 if (right->op_type == OP_MATCH ||
1473 right->op_type == OP_SUBST ||
1474 right->op_type == OP_TRANS) {
1475 right->op_flags |= OPf_STACKED;
1476 if (right->op_type != OP_MATCH)
1477 left = mod(left, right->op_type);
1478 if (right->op_type == OP_TRANS)
1479 o = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
1481 o = prepend_elem(right->op_type, scalar(left), right);
1483 return newUNOP(OP_NOT, 0, scalar(o));
1487 return bind_match(type, left,
1488 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
1496 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
1497 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(o));
1504 if (o->op_flags & OPf_PARENS || PERLDB_NOOPT || PL_tainting) {
1505 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
1506 o->op_type = OP_LEAVE;
1507 o->op_ppaddr = ppaddr[OP_LEAVE];
1510 if (o->op_type == OP_LINESEQ) {
1512 o->op_type = OP_SCOPE;
1513 o->op_ppaddr = ppaddr[OP_SCOPE];
1514 kid = ((LISTOP*)o)->op_first;
1515 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE){
1516 SvREFCNT_dec(((COP*)kid)->cop_filegv);
1521 o = newLISTOP(OP_SCOPE, 0, o, Nullop);
1531 SAVESPTR(GvHV(PL_hintgv));
1532 GvHV(PL_hintgv) = newHVhv(GvHV(PL_hintgv));
1533 SAVEFREESV(GvHV(PL_hintgv));
1537 block_start(int full)
1540 int retval = PL_savestack_ix;
1542 SAVEI32(PL_comppad_name_floor);
1544 if ((PL_comppad_name_fill = AvFILLp(PL_comppad_name)) > 0)
1545 PL_comppad_name_floor = PL_comppad_name_fill;
1547 PL_comppad_name_floor = 0;
1549 SAVEI32(PL_min_intro_pending);
1550 SAVEI32(PL_max_intro_pending);
1551 PL_min_intro_pending = 0;
1552 SAVEI32(PL_comppad_name_fill);
1553 SAVEI32(PL_padix_floor);
1554 PL_padix_floor = PL_padix;
1555 PL_pad_reset_pending = FALSE;
1557 PL_hints &= ~HINT_BLOCK_SCOPE;
1562 block_end(I32 floor, OP *seq)
1565 int needblockscope = PL_hints & HINT_BLOCK_SCOPE;
1566 OP* retval = scalarseq(seq);
1568 PL_pad_reset_pending = FALSE;
1570 PL_hints |= HINT_BLOCK_SCOPE; /* propagate out */
1571 pad_leavemy(PL_comppad_name_fill);
1580 OP *o = newOP(OP_THREADSV, 0);
1581 o->op_targ = find_threadsv("_");
1584 return newSVREF(newGVOP(OP_GV, 0, PL_defgv));
1585 #endif /* USE_THREADS */
1593 PL_eval_root = newUNOP(OP_LEAVEEVAL, ((PL_in_eval & 4) ? OPf_SPECIAL : 0), o);
1594 PL_eval_start = linklist(PL_eval_root);
1595 PL_eval_root->op_next = 0;
1596 peep(PL_eval_start);
1601 PL_main_root = scope(sawparens(scalarvoid(o)));
1602 PL_curcop = &PL_compiling;
1603 PL_main_start = LINKLIST(PL_main_root);
1604 PL_main_root->op_next = 0;
1605 peep(PL_main_start);
1608 /* Register with debugger */
1610 CV *cv = perl_get_cv("DB::postponed", FALSE);
1614 XPUSHs((SV*)PL_compiling.cop_filegv);
1616 perl_call_sv((SV*)cv, G_DISCARD);
1623 localize(OP *o, I32 lex)
1625 if (o->op_flags & OPf_PARENS)
1628 if (PL_dowarn && PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == ',') {
1630 for (s = PL_bufptr; *s && (isALNUM(*s) || strchr("@$%, ",*s)); s++) ;
1631 if (*s == ';' || *s == '=')
1632 warn("Parens missing around \"%s\" list", lex ? "my" : "local");
1636 PL_in_my_stash = Nullhv;
1640 return mod(o, OP_NULL); /* a bit kludgey */
1646 if (o->op_type == OP_LIST) {
1649 o2 = newOP(OP_THREADSV, 0);
1650 o2->op_targ = find_threadsv(";");
1652 o2 = newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
1653 #endif /* USE_THREADS */
1654 o = convert(OP_JOIN, 0, prepend_elem(OP_LIST, o2, o));
1660 fold_constants(register OP *o)
1664 I32 type = o->op_type;
1667 if (opargs[type] & OA_RETSCALAR)
1669 if (opargs[type] & OA_TARGET)
1670 o->op_targ = pad_alloc(type, SVs_PADTMP);
1672 if ((opargs[type] & OA_OTHERINT) && (PL_hints & HINT_INTEGER))
1673 o->op_ppaddr = ppaddr[type = ++(o->op_type)];
1675 if (!(opargs[type] & OA_FOLDCONST))
1690 if (o->op_private & OPpLOCALE)
1695 goto nope; /* Don't try to run w/ errors */
1697 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
1698 if (curop->op_type != OP_CONST &&
1699 curop->op_type != OP_LIST &&
1700 curop->op_type != OP_SCALAR &&
1701 curop->op_type != OP_NULL &&
1702 curop->op_type != OP_PUSHMARK) {
1707 curop = LINKLIST(o);
1711 sv = *(PL_stack_sp--);
1712 if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
1713 pad_swipe(o->op_targ);
1714 else if (SvTEMP(sv)) { /* grab mortal temp? */
1715 (void)SvREFCNT_inc(sv);
1719 if (type == OP_RV2GV)
1720 return newGVOP(OP_GV, 0, (GV*)sv);
1722 /* try to smush double to int, but don't smush -2.0 to -2 */
1723 if ((SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK)) == SVf_NOK &&
1727 if ((double)iv == SvNV(sv)) {
1732 SvIOK_off(sv); /* undo SvIV() damage */
1734 return newSVOP(OP_CONST, 0, sv);
1738 if (!(opargs[type] & OA_OTHERINT))
1741 if (!(PL_hints & HINT_INTEGER)) {
1742 if (type == OP_DIVIDE || !(o->op_flags & OPf_KIDS))
1745 for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
1746 if (curop->op_type == OP_CONST) {
1747 if (SvIOK(((SVOP*)curop)->op_sv))
1751 if (opargs[curop->op_type] & OA_RETINTEGER)
1755 o->op_ppaddr = ppaddr[++(o->op_type)];
1762 gen_constant_list(register OP *o)
1766 I32 oldtmps_floor = PL_tmps_floor;
1770 return o; /* Don't attempt to run with errors */
1772 PL_op = curop = LINKLIST(o);
1778 PL_tmps_floor = oldtmps_floor;
1780 o->op_type = OP_RV2AV;
1781 o->op_ppaddr = ppaddr[OP_RV2AV];
1782 curop = ((UNOP*)o)->op_first;
1783 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*PL_stack_sp--));
1790 convert(I32 type, I32 flags, OP *o)
1795 if (!o || o->op_type != OP_LIST)
1796 o = newLISTOP(OP_LIST, 0, o, Nullop);
1798 o->op_flags &= ~OPf_WANT;
1800 if (!(opargs[type] & OA_MARK))
1801 null(cLISTOPo->op_first);
1804 o->op_ppaddr = ppaddr[type];
1805 o->op_flags |= flags;
1807 o = CHECKOP(type, o);
1808 if (o->op_type != type)
1811 if (cLISTOPo->op_children < 7) {
1812 /* XXX do we really need to do this if we're done appending?? */
1813 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1815 cLISTOPo->op_last = last; /* in case check substituted last arg */
1818 return fold_constants(o);
1821 /* List constructors */
1824 append_elem(I32 type, OP *first, OP *last)
1832 if (first->op_type != type || type==OP_LIST && first->op_flags & OPf_PARENS)
1833 return newLISTOP(type, 0, first, last);
1835 if (first->op_flags & OPf_KIDS)
1836 ((LISTOP*)first)->op_last->op_sibling = last;
1838 first->op_flags |= OPf_KIDS;
1839 ((LISTOP*)first)->op_first = last;
1841 ((LISTOP*)first)->op_last = last;
1842 ((LISTOP*)first)->op_children++;
1847 append_list(I32 type, LISTOP *first, LISTOP *last)
1855 if (first->op_type != type)
1856 return prepend_elem(type, (OP*)first, (OP*)last);
1858 if (last->op_type != type)
1859 return append_elem(type, (OP*)first, (OP*)last);
1861 first->op_last->op_sibling = last->op_first;
1862 first->op_last = last->op_last;
1863 first->op_children += last->op_children;
1864 if (first->op_children)
1865 last->op_flags |= OPf_KIDS;
1872 prepend_elem(I32 type, OP *first, OP *last)
1880 if (last->op_type == type) {
1881 if (type == OP_LIST) { /* already a PUSHMARK there */
1882 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
1883 ((LISTOP*)last)->op_first->op_sibling = first;
1886 if (!(last->op_flags & OPf_KIDS)) {
1887 ((LISTOP*)last)->op_last = first;
1888 last->op_flags |= OPf_KIDS;
1890 first->op_sibling = ((LISTOP*)last)->op_first;
1891 ((LISTOP*)last)->op_first = first;
1893 ((LISTOP*)last)->op_children++;
1897 return newLISTOP(type, 0, first, last);
1905 return newOP(OP_STUB, 0);
1911 if (!o || o->op_type != OP_LIST)
1912 o = newLISTOP(OP_LIST, 0, o, Nullop);
1918 newLISTOP(I32 type, I32 flags, OP *first, OP *last)
1922 Newz(1101, listop, 1, LISTOP);
1924 listop->op_type = type;
1925 listop->op_ppaddr = ppaddr[type];
1926 listop->op_children = (first != 0) + (last != 0);
1927 listop->op_flags = flags;
1931 else if (!first && last)
1934 first->op_sibling = last;
1935 listop->op_first = first;
1936 listop->op_last = last;
1937 if (type == OP_LIST) {
1939 pushop = newOP(OP_PUSHMARK, 0);
1940 pushop->op_sibling = first;
1941 listop->op_first = pushop;
1942 listop->op_flags |= OPf_KIDS;
1944 listop->op_last = pushop;
1946 else if (listop->op_children)
1947 listop->op_flags |= OPf_KIDS;
1953 newOP(I32 type, I32 flags)
1956 Newz(1101, o, 1, OP);
1958 o->op_ppaddr = ppaddr[type];
1959 o->op_flags = flags;
1962 o->op_private = 0 + (flags >> 8);
1963 if (opargs[type] & OA_RETSCALAR)
1965 if (opargs[type] & OA_TARGET)
1966 o->op_targ = pad_alloc(type, SVs_PADTMP);
1967 return CHECKOP(type, o);
1971 newUNOP(I32 type, I32 flags, OP *first)
1976 first = newOP(OP_STUB, 0);
1977 if (opargs[type] & OA_MARK)
1978 first = force_list(first);
1980 Newz(1101, unop, 1, UNOP);
1981 unop->op_type = type;
1982 unop->op_ppaddr = ppaddr[type];
1983 unop->op_first = first;
1984 unop->op_flags = flags | OPf_KIDS;
1985 unop->op_private = 1 | (flags >> 8);
1986 unop = (UNOP*) CHECKOP(type, unop);
1990 return fold_constants((OP *) unop);
1994 newBINOP(I32 type, I32 flags, OP *first, OP *last)
1997 Newz(1101, binop, 1, BINOP);
2000 first = newOP(OP_NULL, 0);
2002 binop->op_type = type;
2003 binop->op_ppaddr = ppaddr[type];
2004 binop->op_first = first;
2005 binop->op_flags = flags | OPf_KIDS;
2008 binop->op_private = 1 | (flags >> 8);
2011 binop->op_private = 2 | (flags >> 8);
2012 first->op_sibling = last;
2015 binop = (BINOP*)CHECKOP(type, binop);
2019 binop->op_last = last = binop->op_first->op_sibling;
2021 return fold_constants((OP *)binop);
2025 pmtrans(OP *o, OP *expr, OP *repl)
2027 SV *tstr = ((SVOP*)expr)->op_sv;
2028 SV *rstr = ((SVOP*)repl)->op_sv;
2031 register U8 *t = (U8*)SvPV(tstr, tlen);
2032 register U8 *r = (U8*)SvPV(rstr, rlen);
2038 register short *tbl;
2040 tbl = (short*)cPVOPo->op_pv;
2041 complement = o->op_private & OPpTRANS_COMPLEMENT;
2042 Delete = o->op_private & OPpTRANS_DELETE;
2043 squash = o->op_private & OPpTRANS_SQUASH;
2046 Zero(tbl, 256, short);
2047 for (i = 0; i < tlen; i++)
2049 for (i = 0, j = 0; i < 256; i++) {
2065 if (!rlen && !Delete) {
2068 o->op_private |= OPpTRANS_COUNTONLY;
2070 for (i = 0; i < 256; i++)
2072 for (i = 0, j = 0; i < tlen; i++,j++) {
2075 if (tbl[t[i]] == -1)
2081 if (tbl[t[i]] == -1)
2092 newPMOP(I32 type, I32 flags)
2097 Newz(1101, pmop, 1, PMOP);
2098 pmop->op_type = type;
2099 pmop->op_ppaddr = ppaddr[type];
2100 pmop->op_flags = flags;
2101 pmop->op_private = 0 | (flags >> 8);
2103 if (PL_hints & HINT_RE_TAINT)
2104 pmop->op_pmpermflags |= PMf_RETAINT;
2105 if (PL_hints & HINT_LOCALE)
2106 pmop->op_pmpermflags |= PMf_LOCALE;
2107 pmop->op_pmflags = pmop->op_pmpermflags;
2109 /* link into pm list */
2110 if (type != OP_TRANS && PL_curstash) {
2111 pmop->op_pmnext = HvPMROOT(PL_curstash);
2112 HvPMROOT(PL_curstash) = pmop;
2119 pmruntime(OP *o, OP *expr, OP *repl)
2124 I32 repl_has_vars = 0;
2126 if (o->op_type == OP_TRANS)
2127 return pmtrans(o, expr, repl);
2129 PL_hints |= HINT_BLOCK_SCOPE;
2132 if (expr->op_type == OP_CONST) {
2134 SV *pat = ((SVOP*)expr)->op_sv;
2135 char *p = SvPV(pat, plen);
2136 if ((o->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
2137 sv_setpvn(pat, "\\s+", 3);
2138 p = SvPV(pat, plen);
2139 pm->op_pmflags |= PMf_SKIPWHITE;
2141 pm->op_pmregexp = CALLREGCOMP(p, p + plen, pm);
2142 if (strEQ("\\s+", pm->op_pmregexp->precomp))
2143 pm->op_pmflags |= PMf_WHITE;
2147 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL))
2148 expr = newUNOP((!(PL_hints & HINT_RE_EVAL)
2150 : OP_REGCMAYBE),0,expr);
2152 Newz(1101, rcop, 1, LOGOP);
2153 rcop->op_type = OP_REGCOMP;
2154 rcop->op_ppaddr = ppaddr[OP_REGCOMP];
2155 rcop->op_first = scalar(expr);
2156 rcop->op_flags |= ((PL_hints & HINT_RE_EVAL)
2157 ? (OPf_SPECIAL | OPf_KIDS)
2159 rcop->op_private = 1;
2162 /* establish postfix order */
2163 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL)) {
2165 rcop->op_next = expr;
2166 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
2169 rcop->op_next = LINKLIST(expr);
2170 expr->op_next = (OP*)rcop;
2173 prepend_elem(o->op_type, scalar((OP*)rcop), o);
2178 if (pm->op_pmflags & PMf_EVAL)
2181 else if (repl->op_type == OP_THREADSV
2182 && strchr("&`'123456789+",
2183 PL_threadsv_names[repl->op_targ]))
2187 #endif /* USE_THREADS */
2188 else if (repl->op_type == OP_CONST)
2192 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
2193 if (opargs[curop->op_type] & OA_DANGEROUS) {
2195 if (curop->op_type == OP_THREADSV) {
2197 if (strchr("&`'123456789+", curop->op_private))
2201 if (curop->op_type == OP_GV) {
2202 GV *gv = ((GVOP*)curop)->op_gv;
2204 if (strchr("&`'123456789+", *GvENAME(gv)))
2207 #endif /* USE_THREADS */
2208 else if (curop->op_type == OP_RV2CV)
2210 else if (curop->op_type == OP_RV2SV ||
2211 curop->op_type == OP_RV2AV ||
2212 curop->op_type == OP_RV2HV ||
2213 curop->op_type == OP_RV2GV) {
2214 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
2217 else if (curop->op_type == OP_PADSV ||
2218 curop->op_type == OP_PADAV ||
2219 curop->op_type == OP_PADHV ||
2220 curop->op_type == OP_PADANY) {
2223 else if (curop->op_type == OP_PUSHRE)
2224 ; /* Okay here, dangerous in newASSIGNOP */
2233 && (!pm->op_pmregexp
2234 || pm->op_pmregexp->reganch & ROPT_EVAL_SEEN))) {
2235 pm->op_pmflags |= PMf_CONST; /* const for long enough */
2236 pm->op_pmpermflags |= PMf_CONST; /* const for long enough */
2237 prepend_elem(o->op_type, scalar(repl), o);
2240 if (curop == repl && !pm->op_pmregexp) { /* Has variables. */
2241 pm->op_pmflags |= PMf_MAYBE_CONST;
2242 pm->op_pmpermflags |= PMf_MAYBE_CONST;
2244 Newz(1101, rcop, 1, LOGOP);
2245 rcop->op_type = OP_SUBSTCONT;
2246 rcop->op_ppaddr = ppaddr[OP_SUBSTCONT];
2247 rcop->op_first = scalar(repl);
2248 rcop->op_flags |= OPf_KIDS;
2249 rcop->op_private = 1;
2252 /* establish postfix order */
2253 rcop->op_next = LINKLIST(repl);
2254 repl->op_next = (OP*)rcop;
2256 pm->op_pmreplroot = scalar((OP*)rcop);
2257 pm->op_pmreplstart = LINKLIST(rcop);
2266 newSVOP(I32 type, I32 flags, SV *sv)
2269 Newz(1101, svop, 1, SVOP);
2270 svop->op_type = type;
2271 svop->op_ppaddr = ppaddr[type];
2273 svop->op_next = (OP*)svop;
2274 svop->op_flags = flags;
2275 if (opargs[type] & OA_RETSCALAR)
2277 if (opargs[type] & OA_TARGET)
2278 svop->op_targ = pad_alloc(type, SVs_PADTMP);
2279 return CHECKOP(type, svop);
2283 newGVOP(I32 type, I32 flags, GV *gv)
2287 Newz(1101, gvop, 1, GVOP);
2288 gvop->op_type = type;
2289 gvop->op_ppaddr = ppaddr[type];
2290 gvop->op_gv = (GV*)SvREFCNT_inc(gv);
2291 gvop->op_next = (OP*)gvop;
2292 gvop->op_flags = flags;
2293 if (opargs[type] & OA_RETSCALAR)
2295 if (opargs[type] & OA_TARGET)
2296 gvop->op_targ = pad_alloc(type, SVs_PADTMP);
2297 return CHECKOP(type, gvop);
2301 newPVOP(I32 type, I32 flags, char *pv)
2304 Newz(1101, pvop, 1, PVOP);
2305 pvop->op_type = type;
2306 pvop->op_ppaddr = ppaddr[type];
2308 pvop->op_next = (OP*)pvop;
2309 pvop->op_flags = flags;
2310 if (opargs[type] & OA_RETSCALAR)
2312 if (opargs[type] & OA_TARGET)
2313 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
2314 return CHECKOP(type, pvop);
2323 save_hptr(&PL_curstash);
2324 save_item(PL_curstname);
2329 name = SvPV(sv, len);
2330 PL_curstash = gv_stashpvn(name,len,TRUE);
2331 sv_setpvn(PL_curstname, name, len);
2335 sv_setpv(PL_curstname,"<none>");
2336 PL_curstash = Nullhv;
2338 PL_copline = NOLINE;
2343 utilize(int aver, I32 floor, OP *version, OP *id, OP *arg)
2351 if (id->op_type != OP_CONST)
2352 croak("Module name must be constant");
2356 if(version != Nullop) {
2357 SV *vesv = ((SVOP*)version)->op_sv;
2359 if (arg == Nullop && !SvNIOK(vesv)) {
2366 if (version->op_type != OP_CONST || !SvNIOK(vesv))
2367 croak("Version number must be constant number");
2369 /* Make copy of id so we don't free it twice */
2370 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2372 /* Fake up a method call to VERSION */
2373 meth = newSVOP(OP_CONST, 0, newSVpv("VERSION", 7));
2374 veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2375 append_elem(OP_LIST,
2376 prepend_elem(OP_LIST, pack, list(version)),
2377 newUNOP(OP_METHOD, 0, meth)));
2381 /* Fake up an import/unimport */
2382 if (arg && arg->op_type == OP_STUB)
2383 imop = arg; /* no import on explicit () */
2384 else if(SvNIOK(((SVOP*)id)->op_sv)) {
2385 imop = Nullop; /* use 5.0; */
2388 /* Make copy of id so we don't free it twice */
2389 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2390 meth = newSVOP(OP_CONST, 0,
2392 ? newSVpv("import", 6)
2393 : newSVpv("unimport", 8)
2395 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2396 append_elem(OP_LIST,
2397 prepend_elem(OP_LIST, pack, list(arg)),
2398 newUNOP(OP_METHOD, 0, meth)));
2401 /* Fake up a require */
2402 rqop = newUNOP(OP_REQUIRE, 0, id);
2404 /* Fake up the BEGIN {}, which does its thing immediately. */
2406 newSVOP(OP_CONST, 0, newSVpv("BEGIN", 5)),
2408 append_elem(OP_LINESEQ,
2409 append_elem(OP_LINESEQ,
2410 newSTATEOP(0, Nullch, rqop),
2411 newSTATEOP(0, Nullch, veop)),
2412 newSTATEOP(0, Nullch, imop) ));
2414 PL_copline = NOLINE;
2419 newSLICEOP(I32 flags, OP *subscript, OP *listval)
2421 return newBINOP(OP_LSLICE, flags,
2422 list(force_list(subscript)),
2423 list(force_list(listval)) );
2427 list_assignment(register OP *o)
2432 if (o->op_type == OP_NULL && o->op_flags & OPf_KIDS)
2433 o = cUNOPo->op_first;
2435 if (o->op_type == OP_COND_EXPR) {
2436 I32 t = list_assignment(cCONDOPo->op_first->op_sibling);
2437 I32 f = list_assignment(cCONDOPo->op_first->op_sibling->op_sibling);
2442 yyerror("Assignment to both a list and a scalar");
2446 if (o->op_type == OP_LIST || o->op_flags & OPf_PARENS ||
2447 o->op_type == OP_RV2AV || o->op_type == OP_RV2HV ||
2448 o->op_type == OP_ASLICE || o->op_type == OP_HSLICE)
2451 if (o->op_type == OP_PADAV || o->op_type == OP_PADHV)
2454 if (o->op_type == OP_RV2SV)
2461 newASSIGNOP(I32 flags, OP *left, I32 optype, OP *right)
2466 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN) {
2467 return newLOGOP(optype, 0,
2468 mod(scalar(left), optype),
2469 newUNOP(OP_SASSIGN, 0, scalar(right)));
2472 return newBINOP(optype, OPf_STACKED,
2473 mod(scalar(left), optype), scalar(right));
2477 if (list_assignment(left)) {
2480 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2481 left = mod(left, OP_AASSIGN);
2489 o = newBINOP(OP_AASSIGN, flags,
2490 list(force_list(right)),
2491 list(force_list(left)) );
2492 o->op_private = 0 | (flags >> 8);
2493 if (!(left->op_private & OPpLVAL_INTRO)) {
2497 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
2498 if (opargs[curop->op_type] & OA_DANGEROUS) {
2499 if (curop->op_type == OP_GV) {
2500 GV *gv = ((GVOP*)curop)->op_gv;
2501 if (gv == PL_defgv || SvCUR(gv) == PL_generation)
2503 SvCUR(gv) = PL_generation;
2505 else if (curop->op_type == OP_PADSV ||
2506 curop->op_type == OP_PADAV ||
2507 curop->op_type == OP_PADHV ||
2508 curop->op_type == OP_PADANY) {
2509 SV **svp = AvARRAY(PL_comppad_name);
2510 SV *sv = svp[curop->op_targ];
2511 if (SvCUR(sv) == PL_generation)
2513 SvCUR(sv) = PL_generation; /* (SvCUR not used any more) */
2515 else if (curop->op_type == OP_RV2CV)
2517 else if (curop->op_type == OP_RV2SV ||
2518 curop->op_type == OP_RV2AV ||
2519 curop->op_type == OP_RV2HV ||
2520 curop->op_type == OP_RV2GV) {
2521 if (lastop->op_type != OP_GV) /* funny deref? */
2524 else if (curop->op_type == OP_PUSHRE) {
2525 if (((PMOP*)curop)->op_pmreplroot) {
2526 GV *gv = (GV*)((PMOP*)curop)->op_pmreplroot;
2527 if (gv == PL_defgv || SvCUR(gv) == PL_generation)
2529 SvCUR(gv) = PL_generation;
2538 o->op_private = OPpASSIGN_COMMON;
2540 if (right && right->op_type == OP_SPLIT) {
2542 if ((tmpop = ((LISTOP*)right)->op_first) &&
2543 tmpop->op_type == OP_PUSHRE)
2545 PMOP *pm = (PMOP*)tmpop;
2546 if (left->op_type == OP_RV2AV &&
2547 !(left->op_private & OPpLVAL_INTRO) &&
2548 !(o->op_private & OPpASSIGN_COMMON) )
2550 tmpop = ((UNOP*)left)->op_first;
2551 if (tmpop->op_type == OP_GV && !pm->op_pmreplroot) {
2552 pm->op_pmreplroot = (OP*)((GVOP*)tmpop)->op_gv;
2553 pm->op_pmflags |= PMf_ONCE;
2554 tmpop = cUNOPo->op_first; /* to list (nulled) */
2555 tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */
2556 tmpop->op_sibling = Nullop; /* don't free split */
2557 right->op_next = tmpop->op_next; /* fix starting loc */
2558 op_free(o); /* blow off assign */
2559 right->op_flags &= ~OPf_WANT;
2560 /* "I don't know and I don't care." */
2565 if (PL_modcount < 10000 &&
2566 ((LISTOP*)right)->op_last->op_type == OP_CONST)
2568 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
2570 sv_setiv(sv, PL_modcount+1);
2578 right = newOP(OP_UNDEF, 0);
2579 if (right->op_type == OP_READLINE) {
2580 right->op_flags |= OPf_STACKED;
2581 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
2584 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2585 o = newBINOP(OP_SASSIGN, flags,
2586 scalar(right), mod(scalar(left), OP_SASSIGN) );
2598 newSTATEOP(I32 flags, char *label, OP *o)
2601 U32 seq = intro_my();
2604 Newz(1101, cop, 1, COP);
2605 if (PERLDB_LINE && PL_curcop->cop_line && PL_curstash != PL_debstash) {
2606 cop->op_type = OP_DBSTATE;
2607 cop->op_ppaddr = ppaddr[ OP_DBSTATE ];
2610 cop->op_type = OP_NEXTSTATE;
2611 cop->op_ppaddr = ppaddr[ OP_NEXTSTATE ];
2613 cop->op_flags = flags;
2614 cop->op_private = 0 | (flags >> 8);
2616 cop->op_private |= NATIVE_HINTS;
2618 cop->op_next = (OP*)cop;
2621 cop->cop_label = label;
2622 PL_hints |= HINT_BLOCK_SCOPE;
2625 cop->cop_arybase = PL_curcop->cop_arybase;
2627 if (PL_copline == NOLINE)
2628 cop->cop_line = PL_curcop->cop_line;
2630 cop->cop_line = PL_copline;
2631 PL_copline = NOLINE;
2633 cop->cop_filegv = (GV*)SvREFCNT_inc(PL_curcop->cop_filegv);
2634 cop->cop_stash = PL_curstash;
2636 if (PERLDB_LINE && PL_curstash != PL_debstash) {
2637 SV **svp = av_fetch(GvAV(PL_curcop->cop_filegv),(I32)cop->cop_line, FALSE);
2638 if (svp && *svp != &PL_sv_undef && !SvIOK(*svp)) {
2639 (void)SvIOK_on(*svp);
2641 SvSTASH(*svp) = (HV*)cop;
2645 return prepend_elem(OP_LINESEQ, (OP*)cop, o);
2648 /* "Introduce" my variables to visible status. */
2656 if (! PL_min_intro_pending)
2657 return PL_cop_seqmax;
2659 svp = AvARRAY(PL_comppad_name);
2660 for (i = PL_min_intro_pending; i <= PL_max_intro_pending; i++) {
2661 if ((sv = svp[i]) && sv != &PL_sv_undef && !SvIVX(sv)) {
2662 SvIVX(sv) = 999999999; /* Don't know scope end yet. */
2663 SvNVX(sv) = (double)PL_cop_seqmax;
2666 PL_min_intro_pending = 0;
2667 PL_comppad_name_fill = PL_max_intro_pending; /* Needn't search higher */
2668 return PL_cop_seqmax++;
2672 newLOGOP(I32 type, I32 flags, OP *first, OP *other)
2674 return new_logop(type, flags, &first, &other);
2678 new_logop(I32 type, I32 flags, OP** firstp, OP** otherp)
2683 OP *first = *firstp;
2684 OP *other = *otherp;
2686 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
2687 return newBINOP(type, flags, scalar(first), scalar(other));
2689 scalarboolean(first);
2690 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
2691 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
2692 if (type == OP_AND || type == OP_OR) {
2698 first = *firstp = cUNOPo->op_first;
2700 first->op_next = o->op_next;
2701 cUNOPo->op_first = Nullop;
2705 if (first->op_type == OP_CONST) {
2706 if (PL_dowarn && (first->op_private & OPpCONST_BARE))
2707 warn("Probable precedence problem on %s", op_desc[type]);
2708 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
2719 else if (first->op_type == OP_WANTARRAY) {
2725 else if (PL_dowarn && (first->op_flags & OPf_KIDS)) {
2726 OP *k1 = ((UNOP*)first)->op_first;
2727 OP *k2 = k1->op_sibling;
2729 switch (first->op_type)
2732 if (k2 && k2->op_type == OP_READLINE
2733 && (k2->op_flags & OPf_STACKED)
2734 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
2735 warnop = k2->op_type;
2739 if (k1->op_type == OP_READDIR
2740 || k1->op_type == OP_GLOB
2741 || k1->op_type == OP_EACH)
2742 warnop = k1->op_type;
2746 line_t oldline = PL_curcop->cop_line;
2747 PL_curcop->cop_line = PL_copline;
2748 warn("Value of %s%s can be \"0\"; test with defined()",
2750 ((warnop == OP_READLINE || warnop == OP_GLOB)
2751 ? " construct" : "() operator"));
2752 PL_curcop->cop_line = oldline;
2759 if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
2760 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
2762 Newz(1101, logop, 1, LOGOP);
2764 logop->op_type = type;
2765 logop->op_ppaddr = ppaddr[type];
2766 logop->op_first = first;
2767 logop->op_flags = flags | OPf_KIDS;
2768 logop->op_other = LINKLIST(other);
2769 logop->op_private = 1 | (flags >> 8);
2771 /* establish postfix order */
2772 logop->op_next = LINKLIST(first);
2773 first->op_next = (OP*)logop;
2774 first->op_sibling = other;
2776 o = newUNOP(OP_NULL, 0, (OP*)logop);
2783 newCONDOP(I32 flags, OP *first, OP *trueop, OP *falseop)
2790 return newLOGOP(OP_AND, 0, first, trueop);
2792 return newLOGOP(OP_OR, 0, first, falseop);
2794 scalarboolean(first);
2795 if (first->op_type == OP_CONST) {
2796 if (SvTRUE(((SVOP*)first)->op_sv)) {
2807 else if (first->op_type == OP_WANTARRAY) {
2811 Newz(1101, condop, 1, CONDOP);
2813 condop->op_type = OP_COND_EXPR;
2814 condop->op_ppaddr = ppaddr[OP_COND_EXPR];
2815 condop->op_first = first;
2816 condop->op_flags = flags | OPf_KIDS;
2817 condop->op_true = LINKLIST(trueop);
2818 condop->op_false = LINKLIST(falseop);
2819 condop->op_private = 1 | (flags >> 8);
2821 /* establish postfix order */
2822 condop->op_next = LINKLIST(first);
2823 first->op_next = (OP*)condop;
2825 first->op_sibling = trueop;
2826 trueop->op_sibling = falseop;
2827 o = newUNOP(OP_NULL, 0, (OP*)condop);
2829 trueop->op_next = o;
2830 falseop->op_next = o;
2836 newRANGE(I32 flags, OP *left, OP *right)
2844 Newz(1101, condop, 1, CONDOP);
2846 condop->op_type = OP_RANGE;
2847 condop->op_ppaddr = ppaddr[OP_RANGE];
2848 condop->op_first = left;
2849 condop->op_flags = OPf_KIDS;
2850 condop->op_true = LINKLIST(left);
2851 condop->op_false = LINKLIST(right);
2852 condop->op_private = 1 | (flags >> 8);
2854 left->op_sibling = right;
2856 condop->op_next = (OP*)condop;
2857 flip = newUNOP(OP_FLIP, flags, (OP*)condop);
2858 flop = newUNOP(OP_FLOP, 0, flip);
2859 o = newUNOP(OP_NULL, 0, flop);
2862 left->op_next = flip;
2863 right->op_next = flop;
2865 condop->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2866 sv_upgrade(PAD_SV(condop->op_targ), SVt_PVNV);
2867 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2868 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
2870 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2871 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2874 if (!flip->op_private || !flop->op_private)
2875 linklist(o); /* blow off optimizer unless constant */
2881 newLOOPOP(I32 flags, I32 debuggable, OP *expr, OP *block)
2886 int once = block && block->op_flags & OPf_SPECIAL &&
2887 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
2890 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
2891 return block; /* do {} while 0 does once */
2892 if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
2893 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB)) {
2894 expr = newUNOP(OP_DEFINED, 0,
2895 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
2896 } else if (expr->op_flags & OPf_KIDS) {
2897 OP *k1 = ((UNOP*)expr)->op_first;
2898 OP *k2 = (k1) ? k1->op_sibling : NULL;
2899 switch (expr->op_type) {
2901 if (k2 && k2->op_type == OP_READLINE
2902 && (k2->op_flags & OPf_STACKED)
2903 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
2904 expr = newUNOP(OP_DEFINED, 0, expr);
2908 if (k1->op_type == OP_READDIR
2909 || k1->op_type == OP_GLOB
2910 || k1->op_type == OP_EACH)
2911 expr = newUNOP(OP_DEFINED, 0, expr);
2917 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
2918 o = new_logop(OP_AND, 0, &expr, &listop);
2921 ((LISTOP*)listop)->op_last->op_next = LINKLIST(o);
2923 if (once && o != listop)
2924 o->op_next = ((LOGOP*)cUNOPo->op_first)->op_other;
2927 o = newUNOP(OP_NULL, 0, o); /* or do {} while 1 loses outer block */
2929 o->op_flags |= flags;
2931 o->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/
2936 newWHILEOP(I32 flags, I32 debuggable, LOOP *loop, I32 whileline, OP *expr, OP *block, OP *cont)
2945 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
2946 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB))) {
2947 expr = newUNOP(OP_DEFINED, 0,
2948 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
2949 } else if (expr && (expr->op_flags & OPf_KIDS)) {
2950 OP *k1 = ((UNOP*)expr)->op_first;
2951 OP *k2 = (k1) ? k1->op_sibling : NULL;
2952 switch (expr->op_type) {
2954 if (k2 && k2->op_type == OP_READLINE
2955 && (k2->op_flags & OPf_STACKED)
2956 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
2957 expr = newUNOP(OP_DEFINED, 0, expr);
2961 if (k1->op_type == OP_READDIR
2962 || k1->op_type == OP_GLOB
2963 || k1->op_type == OP_EACH)
2964 expr = newUNOP(OP_DEFINED, 0, expr);
2970 block = newOP(OP_NULL, 0);
2973 next = LINKLIST(cont);
2975 cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
2976 if ((line_t)whileline != NOLINE) {
2977 PL_copline = whileline;
2978 cont = append_elem(OP_LINESEQ, cont,
2979 newSTATEOP(0, Nullch, Nullop));
2983 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
2984 redo = LINKLIST(listop);
2987 PL_copline = whileline;
2989 o = new_logop(OP_AND, 0, &expr, &listop);
2990 if (o == expr && o->op_type == OP_CONST && !SvTRUE(cSVOPo->op_sv)) {
2991 op_free(expr); /* oops, it's a while (0) */
2993 return Nullop; /* listop already freed by new_logop */
2996 ((LISTOP*)listop)->op_last->op_next = condop =
2997 (o == listop ? redo : LINKLIST(o));
3005 Newz(1101,loop,1,LOOP);
3006 loop->op_type = OP_ENTERLOOP;
3007 loop->op_ppaddr = ppaddr[OP_ENTERLOOP];
3008 loop->op_private = 0;
3009 loop->op_next = (OP*)loop;
3012 o = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, o);
3014 loop->op_redoop = redo;
3015 loop->op_lastop = o;
3018 loop->op_nextop = next;
3020 loop->op_nextop = o;
3022 o->op_flags |= flags;
3023 o->op_private |= (flags >> 8);
3028 newFOROP(I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
3036 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
3037 sv->op_type = OP_RV2GV;
3038 sv->op_ppaddr = ppaddr[OP_RV2GV];
3040 else if (sv->op_type == OP_PADSV) { /* private variable */
3041 padoff = sv->op_targ;
3045 else if (sv->op_type == OP_THREADSV) { /* per-thread variable */
3046 padoff = sv->op_targ;
3047 iterflags |= OPf_SPECIAL;
3052 croak("Can't use %s for loop variable", op_desc[sv->op_type]);
3056 padoff = find_threadsv("_");
3057 iterflags |= OPf_SPECIAL;
3059 sv = newGVOP(OP_GV, 0, PL_defgv);
3062 if (expr->op_type == OP_RV2AV || expr->op_type == OP_PADAV) {
3063 expr = mod(force_list(scalar(ref(expr, OP_ITER))), OP_GREPSTART);
3064 iterflags |= OPf_STACKED;
3066 else if (expr->op_type == OP_NULL &&
3067 (expr->op_flags & OPf_KIDS) &&
3068 ((BINOP*)expr)->op_first->op_type == OP_FLOP)
3070 /* Basically turn for($x..$y) into the same as for($x,$y), but we
3071 * set the STACKED flag to indicate that these values are to be
3072 * treated as min/max values by 'pp_iterinit'.
3074 UNOP* flip = (UNOP*)((UNOP*)((BINOP*)expr)->op_first)->op_first;
3075 CONDOP* range = (CONDOP*) flip->op_first;
3076 OP* left = range->op_first;
3077 OP* right = left->op_sibling;
3080 range->op_flags &= ~OPf_KIDS;
3081 range->op_first = Nullop;
3083 listop = (LISTOP*)newLISTOP(OP_LIST, 0, left, right);
3084 listop->op_first->op_next = range->op_true;
3085 left->op_next = range->op_false;
3086 right->op_next = (OP*)listop;
3087 listop->op_next = listop->op_first;
3090 expr = (OP*)(listop);
3092 iterflags |= OPf_STACKED;
3095 expr = mod(force_list(expr), OP_GREPSTART);
3099 loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
3100 append_elem(OP_LIST, expr, scalar(sv))));
3101 assert(!loop->op_next);
3102 Renew(loop, 1, LOOP);
3103 loop->op_targ = padoff;
3104 wop = newWHILEOP(flags, 1, loop, forline, newOP(OP_ITER, 0), block, cont);
3105 PL_copline = forline;
3106 return newSTATEOP(0, label, wop);
3110 newLOOPEX(I32 type, OP *label)
3114 if (type != OP_GOTO || label->op_type == OP_CONST) {
3115 /* "last()" means "last" */
3116 if (label->op_type == OP_STUB && (label->op_flags & OPf_PARENS))
3117 o = newOP(type, OPf_SPECIAL);
3119 o = newPVOP(type, 0, savepv(label->op_type == OP_CONST
3120 ? SvPVx(((SVOP*)label)->op_sv, PL_na)
3126 if (label->op_type == OP_ENTERSUB)
3127 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
3128 o = newUNOP(type, OPf_STACKED, label);
3130 PL_hints |= HINT_BLOCK_SCOPE;
3140 MUTEX_DESTROY(CvMUTEXP(cv));
3141 Safefree(CvMUTEXP(cv));
3144 #endif /* USE_THREADS */
3146 if (!CvXSUB(cv) && CvROOT(cv)) {
3148 if (CvDEPTH(cv) || (CvOWNER(cv) && CvOWNER(cv) != thr))
3149 croak("Can't undef active subroutine");
3152 croak("Can't undef active subroutine");
3153 #endif /* USE_THREADS */
3156 SAVESPTR(PL_curpad);
3160 op_free(CvROOT(cv));
3161 CvROOT(cv) = Nullop;
3164 SvPOK_off((SV*)cv); /* forget prototype */
3166 SvREFCNT_dec(CvGV(cv));
3168 SvREFCNT_dec(CvOUTSIDE(cv));
3169 CvOUTSIDE(cv) = Nullcv;
3170 if (CvPADLIST(cv)) {
3171 /* may be during global destruction */
3172 if (SvREFCNT(CvPADLIST(cv))) {
3173 I32 i = AvFILLp(CvPADLIST(cv));
3175 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
3176 SV* sv = svp ? *svp : Nullsv;
3179 if (sv == (SV*)PL_comppad_name)
3180 PL_comppad_name = Nullav;
3181 else if (sv == (SV*)PL_comppad) {
3182 PL_comppad = Nullav;
3183 PL_curpad = Null(SV**);
3187 SvREFCNT_dec((SV*)CvPADLIST(cv));
3189 CvPADLIST(cv) = Nullav;
3193 #ifdef DEBUG_CLOSURES
3198 CV *outside = CvOUTSIDE(cv);
3199 AV* padlist = CvPADLIST(cv);
3206 PerlIO_printf(Perl_debug_log, "\tCV=0x%lx (%s), OUTSIDE=0x%lx (%s)\n",
3208 (CvANON(cv) ? "ANON"
3209 : (cv == PL_main_cv) ? "MAIN"
3210 : CvUNIQUE(outside) ? "UNIQUE"
3211 : CvGV(cv) ? GvNAME(CvGV(cv)) : "UNDEFINED"),
3214 : CvANON(outside) ? "ANON"
3215 : (outside == PL_main_cv) ? "MAIN"
3216 : CvUNIQUE(outside) ? "UNIQUE"
3217 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
3222 pad_name = (AV*)*av_fetch(padlist, 0, FALSE);
3223 pad = (AV*)*av_fetch(padlist, 1, FALSE);
3224 pname = AvARRAY(pad_name);
3225 ppad = AvARRAY(pad);
3227 for (ix = 1; ix <= AvFILLp(pad_name); ix++) {
3228 if (SvPOK(pname[ix]))
3229 PerlIO_printf(Perl_debug_log, "\t%4d. 0x%lx (%s\"%s\" %ld-%ld)\n",
3231 SvFAKE(pname[ix]) ? "FAKE " : "",
3233 (long)I_32(SvNVX(pname[ix])),
3234 (long)SvIVX(pname[ix]));
3237 #endif /* DEBUG_CLOSURES */
3240 cv_clone2(CV *proto, CV *outside)
3245 AV* protopadlist = CvPADLIST(proto);
3246 AV* protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
3247 AV* protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
3248 SV** pname = AvARRAY(protopad_name);
3249 SV** ppad = AvARRAY(protopad);
3250 I32 fname = AvFILLp(protopad_name);
3251 I32 fpad = AvFILLp(protopad);
3255 assert(!CvUNIQUE(proto));
3258 SAVESPTR(PL_curpad);
3259 SAVESPTR(PL_comppad);
3260 SAVESPTR(PL_comppad_name);
3261 SAVESPTR(PL_compcv);
3263 cv = PL_compcv = (CV*)NEWSV(1104,0);
3264 sv_upgrade((SV *)cv, SvTYPE(proto));
3270 New(666, CvMUTEXP(cv), 1, perl_mutex);
3271 MUTEX_INIT(CvMUTEXP(cv));
3273 #endif /* USE_THREADS */
3274 CvFILEGV(cv) = CvFILEGV(proto);
3275 CvGV(cv) = (GV*)SvREFCNT_inc(CvGV(proto));
3276 CvSTASH(cv) = CvSTASH(proto);
3277 CvROOT(cv) = CvROOT(proto);
3278 CvSTART(cv) = CvSTART(proto);
3280 CvOUTSIDE(cv) = (CV*)SvREFCNT_inc(outside);
3283 sv_setpvn((SV*)cv, SvPVX(proto), SvCUR(proto));
3285 PL_comppad_name = newAV();
3286 for (ix = fname; ix >= 0; ix--)
3287 av_store(PL_comppad_name, ix, SvREFCNT_inc(pname[ix]));
3289 PL_comppad = newAV();
3291 comppadlist = newAV();
3292 AvREAL_off(comppadlist);
3293 av_store(comppadlist, 0, (SV*)PL_comppad_name);
3294 av_store(comppadlist, 1, (SV*)PL_comppad);
3295 CvPADLIST(cv) = comppadlist;
3296 av_fill(PL_comppad, AvFILLp(protopad));
3297 PL_curpad = AvARRAY(PL_comppad);
3299 av = newAV(); /* will be @_ */
3301 av_store(PL_comppad, 0, (SV*)av);
3302 AvFLAGS(av) = AVf_REIFY;
3304 for (ix = fpad; ix > 0; ix--) {
3305 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
3306 if (namesv && namesv != &PL_sv_undef) {
3307 char *name = SvPVX(namesv); /* XXX */
3308 if (SvFLAGS(namesv) & SVf_FAKE) { /* lexical from outside? */
3309 I32 off = pad_findlex(name, ix, SvIVX(namesv),
3310 CvOUTSIDE(cv), cxstack_ix);
3312 PL_curpad[ix] = SvREFCNT_inc(ppad[ix]);
3314 croak("panic: cv_clone: %s", name);
3316 else { /* our own lexical */
3319 /* anon code -- we'll come back for it */
3320 sv = SvREFCNT_inc(ppad[ix]);
3322 else if (*name == '@')
3324 else if (*name == '%')
3334 SV* sv = NEWSV(0,0);
3340 /* Now that vars are all in place, clone nested closures. */
3342 for (ix = fpad; ix > 0; ix--) {
3343 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
3345 && namesv != &PL_sv_undef
3346 && !(SvFLAGS(namesv) & SVf_FAKE)
3347 && *SvPVX(namesv) == '&'
3348 && CvCLONE(ppad[ix]))
3350 CV *kid = cv_clone2((CV*)ppad[ix], cv);
3351 SvREFCNT_dec(ppad[ix]);
3354 PL_curpad[ix] = (SV*)kid;
3358 #ifdef DEBUG_CLOSURES
3359 PerlIO_printf(Perl_debug_log, "Cloned inside:\n");
3361 PerlIO_printf(Perl_debug_log, " from:\n");
3363 PerlIO_printf(Perl_debug_log, " to:\n");
3374 return cv_clone2(proto, CvOUTSIDE(proto));
3378 cv_ckproto(CV *cv, GV *gv, char *p)
3380 if ((!p != !SvPOK(cv)) || (p && strNE(p, SvPVX(cv)))) {
3381 SV* msg = sv_newmortal();
3385 gv_efullname3(name = sv_newmortal(), gv, Nullch);
3386 sv_setpv(msg, "Prototype mismatch:");
3388 sv_catpvf(msg, " sub %_", name);
3390 sv_catpvf(msg, " (%s)", SvPVX(cv));
3391 sv_catpv(msg, " vs ");
3393 sv_catpvf(msg, "(%s)", p);
3395 sv_catpv(msg, "none");
3403 if (!cv || !SvPOK(cv) || SvCUR(cv))
3405 return op_const_sv(CvSTART(cv), cv);
3409 op_const_sv(OP *o, CV *cv)
3416 if(o->op_type == OP_LINESEQ && cLISTOPo->op_first)
3417 o = cLISTOPo->op_first->op_sibling;
3419 for (; o; o = o->op_next) {
3420 OPCODE type = o->op_type;
3422 if(sv && o->op_next == o)
3424 if (type == OP_NEXTSTATE || type == OP_NULL || type == OP_PUSHMARK)
3426 if (type == OP_LEAVESUB || type == OP_RETURN)
3430 if (type == OP_CONST)
3432 else if (type == OP_PADSV && cv) {
3433 AV* padav = (AV*)(AvARRAY(CvPADLIST(cv))[1]);
3434 sv = padav ? AvARRAY(padav)[o->op_targ] : Nullsv;
3435 if (!sv || (!SvREADONLY(sv) && SvREFCNT(sv) > 1))
3447 newSUB(I32 floor, OP *o, OP *proto, OP *block)
3450 char *name = o ? SvPVx(cSVOPo->op_sv, PL_na) : Nullch;
3451 GV *gv = gv_fetchpv(name ? name : "__ANON__",
3452 GV_ADDMULTI | (block ? 0 : GV_NOINIT), SVt_PVCV);
3453 char *ps = proto ? SvPVx(((SVOP*)proto)->op_sv, PL_na) : Nullch;
3462 if (SvTYPE(gv) != SVt_PVGV) { /* Prototype now, and had
3463 maximum a prototype before. */
3464 if (SvTYPE(gv) > SVt_NULL) {
3465 if (!SvPOK((SV*)gv) && !(SvIOK((SV*)gv) && SvIVX((SV*)gv) == -1))
3466 warn("Runaway prototype");
3467 cv_ckproto((CV*)gv, NULL, ps);
3470 sv_setpv((SV*)gv, ps);
3472 sv_setiv((SV*)gv, -1);
3473 SvREFCNT_dec(PL_compcv);
3474 cv = PL_compcv = NULL;
3475 PL_sub_generation++;
3479 if (!name || GvCVGEN(gv))
3481 else if (cv = GvCV(gv)) {
3482 cv_ckproto(cv, gv, ps);
3483 /* already defined (or promised)? */
3484 if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
3486 bool const_changed = TRUE;
3488 /* just a "sub foo;" when &foo is already defined */
3489 SAVEFREESV(PL_compcv);
3492 /* ahem, death to those who redefine active sort subs */
3493 if (PL_curstackinfo->si_type == PERLSI_SORT && PL_sortcop == CvSTART(cv))
3494 croak("Can't redefine active sort subroutine %s", name);
3495 if(const_sv = cv_const_sv(cv))
3496 const_changed = sv_cmp(const_sv, op_const_sv(block, Nullcv));
3497 if ((const_sv && const_changed) || PL_dowarn && !(CvGV(cv) && GvSTASH(CvGV(cv))
3498 && HvNAME(GvSTASH(CvGV(cv)))
3499 && strEQ(HvNAME(GvSTASH(CvGV(cv))),
3501 line_t oldline = PL_curcop->cop_line;
3502 PL_curcop->cop_line = PL_copline;
3503 warn(const_sv ? "Constant subroutine %s redefined"
3504 : "Subroutine %s redefined", name);
3505 PL_curcop->cop_line = oldline;
3511 if (cv) { /* must reuse cv if autoloaded */
3513 CvFLAGS(cv) = CvFLAGS(PL_compcv);
3514 CvOUTSIDE(cv) = CvOUTSIDE(PL_compcv);
3515 CvOUTSIDE(PL_compcv) = 0;
3516 CvPADLIST(cv) = CvPADLIST(PL_compcv);
3517 CvPADLIST(PL_compcv) = 0;
3518 if (SvREFCNT(PL_compcv) > 1) /* XXX Make closures transit through stub. */
3519 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc((SV*)cv);
3520 SvREFCNT_dec(PL_compcv);
3527 PL_sub_generation++;
3530 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
3531 CvFILEGV(cv) = PL_curcop->cop_filegv;
3532 CvSTASH(cv) = PL_curstash;
3536 New(666, CvMUTEXP(cv), 1, perl_mutex);
3537 MUTEX_INIT(CvMUTEXP(cv));
3538 #endif /* USE_THREADS */
3541 sv_setpv((SV*)cv, ps);
3543 if (PL_error_count) {
3547 char *s = strrchr(name, ':');
3549 if (strEQ(s, "BEGIN")) {
3551 "BEGIN not safe after errors--compilation aborted";
3555 /* force display of errors found but not reported */
3556 sv_catpv(ERRSV, not_safe);
3557 croak("%s", SvPVx(ERRSV, PL_na));
3564 PL_copline = NOLINE;
3569 if (AvFILLp(PL_comppad_name) < AvFILLp(PL_comppad))
3570 av_store(PL_comppad_name, AvFILLp(PL_comppad), Nullsv);
3573 SV **namep = AvARRAY(PL_comppad_name);
3574 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
3577 if (SvIMMORTAL(PL_curpad[ix]))
3580 * The only things that a clonable function needs in its
3581 * pad are references to outer lexicals and anonymous subs.
3582 * The rest are created anew during cloning.
3584 if (!((namesv = namep[ix]) != Nullsv &&
3585 namesv != &PL_sv_undef &&
3587 *SvPVX(namesv) == '&')))
3589 SvREFCNT_dec(PL_curpad[ix]);
3590 PL_curpad[ix] = Nullsv;
3595 AV *av = newAV(); /* Will be @_ */
3597 av_store(PL_comppad, 0, (SV*)av);
3598 AvFLAGS(av) = AVf_REIFY;
3600 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
3601 if (SvIMMORTAL(PL_curpad[ix]))
3603 if (!SvPADMY(PL_curpad[ix]))
3604 SvPADTMP_on(PL_curpad[ix]);
3608 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
3609 CvSTART(cv) = LINKLIST(CvROOT(cv));
3610 CvROOT(cv)->op_next = 0;
3616 if (PERLDB_SUBLINE && PL_curstash != PL_debstash) {
3617 SV *sv = NEWSV(0,0);
3618 SV *tmpstr = sv_newmortal();
3619 GV *db_postponed = gv_fetchpv("DB::postponed", GV_ADDMULTI, SVt_PVHV);
3623 sv_setpvf(sv, "%_:%ld-%ld",
3624 GvSV(PL_curcop->cop_filegv),
3625 (long)PL_subline, (long)PL_curcop->cop_line);
3626 gv_efullname3(tmpstr, gv, Nullch);
3627 hv_store(GvHV(PL_DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
3628 hv = GvHVn(db_postponed);
3629 if (HvFILL(hv) > 0 && hv_exists(hv, SvPVX(tmpstr), SvCUR(tmpstr))
3630 && (cv = GvCV(db_postponed))) {
3635 perl_call_sv((SV*)cv, G_DISCARD);
3639 if ((s = strrchr(name,':')))
3643 if (strEQ(s, "BEGIN")) {
3644 I32 oldscope = PL_scopestack_ix;
3646 SAVESPTR(PL_compiling.cop_filegv);
3647 SAVEI16(PL_compiling.cop_line);
3649 sv_setsv(PL_rs, PL_nrs);
3652 PL_beginav = newAV();
3653 DEBUG_x( dump_sub(gv) );
3654 av_push(PL_beginav, (SV *)cv);
3656 call_list(oldscope, PL_beginav);
3658 PL_curcop = &PL_compiling;
3661 else if (strEQ(s, "END") && !PL_error_count) {
3664 av_unshift(PL_endav, 1);
3665 av_store(PL_endav, 0, (SV *)cv);
3668 else if (strEQ(s, "INIT") && !PL_error_count) {
3670 PL_initav = newAV();
3671 av_push(PL_initav, SvREFCNT_inc(cv));
3676 PL_copline = NOLINE;
3682 newCONSTSUB(HV *stash, char *name, SV *sv)
3685 U32 oldhints = PL_hints;
3686 HV *old_cop_stash = PL_curcop->cop_stash;
3687 HV *old_curstash = PL_curstash;
3688 line_t oldline = PL_curcop->cop_line;
3689 PL_curcop->cop_line = PL_copline;
3691 PL_hints &= ~HINT_BLOCK_SCOPE;
3693 PL_curstash = PL_curcop->cop_stash = stash;
3696 start_subparse(FALSE, 0),
3697 newSVOP(OP_CONST, 0, newSVpv(name,0)),
3698 newSVOP(OP_CONST, 0, &PL_sv_no), /* SvPV(&PL_sv_no) == "" -- GMB */
3699 newSTATEOP(0, Nullch, newSVOP(OP_CONST, 0, sv))
3702 PL_hints = oldhints;
3703 PL_curcop->cop_stash = old_cop_stash;
3704 PL_curstash = old_curstash;
3705 PL_curcop->cop_line = oldline;
3709 newXS(char *name, void (*subaddr) (CV * _CPERLproto), char *filename)
3712 GV *gv = gv_fetchpv(name ? name : "__ANON__", GV_ADDMULTI, SVt_PVCV);
3715 if (cv = (name ? GvCV(gv) : Nullcv)) {
3717 /* just a cached method */
3721 else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
3722 /* already defined (or promised) */
3723 if (PL_dowarn && !(CvGV(cv) && GvSTASH(CvGV(cv))
3724 && HvNAME(GvSTASH(CvGV(cv)))
3725 && strEQ(HvNAME(GvSTASH(CvGV(cv))), "autouse"))) {
3726 line_t oldline = PL_curcop->cop_line;
3727 PL_curcop->cop_line = PL_copline;
3728 warn("Subroutine %s redefined",name);
3729 PL_curcop->cop_line = oldline;
3736 if (cv) /* must reuse cv if autoloaded */
3739 cv = (CV*)NEWSV(1105,0);
3740 sv_upgrade((SV *)cv, SVt_PVCV);
3744 PL_sub_generation++;
3747 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
3749 New(666, CvMUTEXP(cv), 1, perl_mutex);
3750 MUTEX_INIT(CvMUTEXP(cv));
3752 #endif /* USE_THREADS */
3753 CvFILEGV(cv) = gv_fetchfile(filename);
3754 CvXSUB(cv) = subaddr;
3757 char *s = strrchr(name,':');
3762 if (strEQ(s, "BEGIN")) {
3764 PL_beginav = newAV();
3765 av_push(PL_beginav, (SV *)cv);
3768 else if (strEQ(s, "END")) {
3771 av_unshift(PL_endav, 1);
3772 av_store(PL_endav, 0, (SV *)cv);
3775 else if (strEQ(s, "INIT")) {
3777 PL_initav = newAV();
3778 av_push(PL_initav, (SV *)cv);
3788 newFORM(I32 floor, OP *o, OP *block)
3797 name = SvPVx(cSVOPo->op_sv, PL_na);
3800 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
3802 if (cv = GvFORM(gv)) {
3804 line_t oldline = PL_curcop->cop_line;
3806 PL_curcop->cop_line = PL_copline;
3807 warn("Format %s redefined",name);
3808 PL_curcop->cop_line = oldline;
3814 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
3815 CvFILEGV(cv) = PL_curcop->cop_filegv;
3817 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
3818 if (!SvPADMY(PL_curpad[ix]) && !SvIMMORTAL(PL_curpad[ix]))
3819 SvPADTMP_on(PL_curpad[ix]);
3822 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
3823 CvSTART(cv) = LINKLIST(CvROOT(cv));
3824 CvROOT(cv)->op_next = 0;
3827 PL_copline = NOLINE;
3834 return newUNOP(OP_REFGEN, 0,
3835 mod(list(convert(OP_ANONLIST, 0, o)), OP_REFGEN));
3841 return newUNOP(OP_REFGEN, 0,
3842 mod(list(convert(OP_ANONHASH, 0, o)), OP_REFGEN));
3846 newANONSUB(I32 floor, OP *proto, OP *block)
3848 return newUNOP(OP_REFGEN, 0,
3849 newSVOP(OP_ANONCODE, 0, (SV*)newSUB(floor, 0, proto, block)));
3855 switch (o->op_type) {
3857 o->op_type = OP_PADAV;
3858 o->op_ppaddr = ppaddr[OP_PADAV];
3859 return ref(newUNOP(OP_RV2AV, 0, scalar(o)), OP_RV2AV);
3862 o->op_type = OP_RV2AV;
3863 o->op_ppaddr = ppaddr[OP_RV2AV];
3868 warn("oops: oopsAV");
3877 switch (o->op_type) {
3880 o->op_type = OP_PADHV;
3881 o->op_ppaddr = ppaddr[OP_PADHV];
3882 return ref(newUNOP(OP_RV2HV, 0, scalar(o)), OP_RV2HV);
3886 o->op_type = OP_RV2HV;
3887 o->op_ppaddr = ppaddr[OP_RV2HV];
3892 warn("oops: oopsHV");
3901 if (o->op_type == OP_PADANY) {
3902 o->op_type = OP_PADAV;
3903 o->op_ppaddr = ppaddr[OP_PADAV];
3906 return newUNOP(OP_RV2AV, 0, scalar(o));
3910 newGVREF(I32 type, OP *o)
3912 if (type == OP_MAPSTART)
3913 return newUNOP(OP_NULL, 0, o);
3914 return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
3920 if (o->op_type == OP_PADANY) {
3921 o->op_type = OP_PADHV;
3922 o->op_ppaddr = ppaddr[OP_PADHV];
3925 return newUNOP(OP_RV2HV, 0, scalar(o));
3931 croak("NOT IMPL LINE %d",__LINE__);
3937 newCVREF(I32 flags, OP *o)
3939 return newUNOP(OP_RV2CV, flags, scalar(o));
3945 if (o->op_type == OP_PADANY) {
3946 o->op_type = OP_PADSV;
3947 o->op_ppaddr = ppaddr[OP_PADSV];
3950 else if (o->op_type == OP_THREADSV && !(o->op_flags & OPpDONE_SVREF)) {
3951 o->op_flags |= OPpDONE_SVREF;
3954 return newUNOP(OP_RV2SV, 0, scalar(o));
3957 /* Check routines. */
3965 name = NEWSV(1106,0);
3966 sv_upgrade(name, SVt_PVNV);
3967 sv_setpvn(name, "&", 1);
3970 ix = pad_alloc(o->op_type, SVs_PADMY);
3971 av_store(PL_comppad_name, ix, name);
3972 av_store(PL_comppad, ix, cSVOPo->op_sv);
3973 SvPADMY_on(cSVOPo->op_sv);
3974 cSVOPo->op_sv = Nullsv;
3975 cSVOPo->op_targ = ix;
3982 o->op_private = PL_hints;
3989 if (cUNOPo->op_first->op_type == OP_CONCAT)
3990 o->op_flags |= OPf_STACKED;
3997 if (o->op_flags & OPf_KIDS) {
4000 OPCODE type = o->op_type;
4001 o = modkids(ck_fun(o), type);
4002 kid = cUNOPo->op_first;
4003 newop = kUNOP->op_first->op_sibling;
4005 (newop->op_sibling ||
4006 !(opargs[newop->op_type] & OA_RETSCALAR) ||
4007 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
4008 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
4012 op_free(kUNOP->op_first);
4013 kUNOP->op_first = newop;
4015 o->op_ppaddr = ppaddr[++o->op_type];
4024 if (o->op_flags & OPf_KIDS) {
4025 OP *kid = cUNOPo->op_first;
4026 if (kid->op_type == OP_HSLICE)
4027 o->op_private |= OPpSLICE;
4028 else if (kid->op_type != OP_HELEM)
4029 croak("%s argument is not a HASH element or slice",
4030 op_desc[o->op_type]);
4039 I32 type = o->op_type;
4041 if (o->op_flags & OPf_KIDS) {
4042 if (cLISTOPo->op_first->op_type == OP_STUB) {
4044 o = newUNOP(type, OPf_SPECIAL,
4045 newGVOP(OP_GV, 0, gv_fetchpv("main::ARGV", TRUE, SVt_PVAV)));
4055 PL_hints |= HINT_BLOCK_SCOPE;
4056 if (o->op_flags & OPf_KIDS) {
4057 SVOP *kid = (SVOP*)cUNOPo->op_first;
4060 o->op_flags &= ~OPf_KIDS;
4063 else if (kid->op_type == OP_LINESEQ) {
4066 kid->op_next = o->op_next;
4067 cUNOPo->op_first = 0;
4070 Newz(1101, enter, 1, LOGOP);
4071 enter->op_type = OP_ENTERTRY;
4072 enter->op_ppaddr = ppaddr[OP_ENTERTRY];
4073 enter->op_private = 0;
4075 /* establish postfix order */
4076 enter->op_next = (OP*)enter;
4078 o = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
4079 o->op_type = OP_LEAVETRY;
4080 o->op_ppaddr = ppaddr[OP_LEAVETRY];
4081 enter->op_other = o;
4089 o = newUNOP(OP_ENTEREVAL, 0, newDEFSVOP());
4091 o->op_targ = (PADOFFSET)PL_hints;
4099 if (o->op_flags & OPf_STACKED) {
4101 kid = cUNOPo->op_first->op_sibling;
4102 if (kid->op_type == OP_RV2GV)
4114 if (o->op_flags & OPf_KIDS) {
4115 OP *kid = cUNOPo->op_first;
4116 if (kid->op_type != OP_HELEM)
4117 croak("%s argument is not a HASH element", op_desc[o->op_type]);
4124 ck_gvconst(register OP *o)
4126 o = fold_constants(o);
4127 if (o->op_type == OP_CONST)
4133 ck_rvconst(register OP *o)
4136 SVOP *kid = (SVOP*)cUNOPo->op_first;
4138 o->op_private |= (PL_hints & HINT_STRICT_REFS);
4139 if (kid->op_type == OP_CONST) {
4144 name = SvPV(kid->op_sv, PL_na);
4145 if ((PL_hints & HINT_STRICT_REFS) && (kid->op_private & OPpCONST_BARE)) {
4146 char *badthing = Nullch;
4147 switch (o->op_type) {
4149 badthing = "a SCALAR";
4152 badthing = "an ARRAY";
4155 badthing = "a HASH";
4160 "Can't use bareword (\"%s\") as %s ref while \"strict refs\" in use",
4164 * This is a little tricky. We only want to add the symbol if we
4165 * didn't add it in the lexer. Otherwise we get duplicate strict
4166 * warnings. But if we didn't add it in the lexer, we must at
4167 * least pretend like we wanted to add it even if it existed before,
4168 * or we get possible typo warnings. OPpCONST_ENTERED says
4169 * whether the lexer already added THIS instance of this symbol.
4171 iscv = (o->op_type == OP_RV2CV) * 2;
4173 gv = gv_fetchpv(name,
4174 iscv | !(kid->op_private & OPpCONST_ENTERED),
4177 : o->op_type == OP_RV2SV
4179 : o->op_type == OP_RV2AV
4181 : o->op_type == OP_RV2HV
4184 } while (!gv && !(kid->op_private & OPpCONST_ENTERED) && !iscv++);
4186 kid->op_type = OP_GV;
4187 SvREFCNT_dec(kid->op_sv);
4188 kid->op_sv = SvREFCNT_inc(gv);
4198 I32 type = o->op_type;
4200 if (o->op_flags & OPf_REF)
4203 if (o->op_flags & OPf_KIDS && cUNOPo->op_first->op_type != OP_STUB) {
4204 SVOP *kid = (SVOP*)cUNOPo->op_first;
4206 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
4207 OP *newop = newGVOP(type, OPf_REF,
4208 gv_fetchpv(SvPVx(kid->op_sv, PL_na), TRUE, SVt_PVIO));
4215 if (type == OP_FTTTY)
4216 return newGVOP(type, OPf_REF, gv_fetchpv("main::STDIN", TRUE,
4219 return newUNOP(type, 0, newDEFSVOP());
4232 int type = o->op_type;
4233 register I32 oa = opargs[type] >> OASHIFT;
4235 if (o->op_flags & OPf_STACKED) {
4236 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
4239 return no_fh_allowed(o);
4242 if (o->op_flags & OPf_KIDS) {
4243 tokid = &cLISTOPo->op_first;
4244 kid = cLISTOPo->op_first;
4245 if (kid->op_type == OP_PUSHMARK ||
4246 kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK)
4248 tokid = &kid->op_sibling;
4249 kid = kid->op_sibling;
4251 if (!kid && opargs[type] & OA_DEFGV)
4252 *tokid = kid = newDEFSVOP();
4256 sibl = kid->op_sibling;
4270 if (kid->op_type == OP_CONST &&
4271 (kid->op_private & OPpCONST_BARE)) {
4272 char *name = SvPVx(((SVOP*)kid)->op_sv, PL_na);
4273 OP *newop = newAVREF(newGVOP(OP_GV, 0,
4274 gv_fetchpv(name, TRUE, SVt_PVAV) ));
4276 warn("Array @%s missing the @ in argument %ld of %s()",
4277 name, (long)numargs, op_desc[type]);
4280 kid->op_sibling = sibl;
4283 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
4284 bad_type(numargs, "array", op_desc[o->op_type], kid);
4288 if (kid->op_type == OP_CONST &&
4289 (kid->op_private & OPpCONST_BARE)) {
4290 char *name = SvPVx(((SVOP*)kid)->op_sv, PL_na);
4291 OP *newop = newHVREF(newGVOP(OP_GV, 0,
4292 gv_fetchpv(name, TRUE, SVt_PVHV) ));
4294 warn("Hash %%%s missing the %% in argument %ld of %s()",
4295 name, (long)numargs, op_desc[type]);
4298 kid->op_sibling = sibl;
4301 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
4302 bad_type(numargs, "hash", op_desc[o->op_type], kid);
4307 OP *newop = newUNOP(OP_NULL, 0, kid);
4308 kid->op_sibling = 0;
4310 newop->op_next = newop;
4312 kid->op_sibling = sibl;
4317 if (kid->op_type != OP_GV) {
4318 if (kid->op_type == OP_CONST &&
4319 (kid->op_private & OPpCONST_BARE)) {
4320 OP *newop = newGVOP(OP_GV, 0,
4321 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, PL_na), TRUE,
4327 kid->op_sibling = 0;
4328 kid = newUNOP(OP_RV2GV, 0, scalar(kid));
4330 kid->op_sibling = sibl;
4336 mod(scalar(kid), type);
4340 tokid = &kid->op_sibling;
4341 kid = kid->op_sibling;
4343 o->op_private |= numargs;
4345 return too_many_arguments(o,op_desc[o->op_type]);
4348 else if (opargs[type] & OA_DEFGV) {
4350 return newUNOP(type, 0, newDEFSVOP());
4354 while (oa & OA_OPTIONAL)
4356 if (oa && oa != OA_LIST)
4357 return too_few_arguments(o,op_desc[o->op_type]);
4367 if ((o->op_flags & OPf_KIDS) && !cLISTOPo->op_first->op_sibling)
4368 append_elem(OP_GLOB, o, newDEFSVOP());
4370 if (!((gv = gv_fetchpv("glob", FALSE, SVt_PVCV)) && GvIMPORTED_CV(gv)))
4371 gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
4373 if (gv && GvIMPORTED_CV(gv)) {
4374 static int glob_index;
4376 append_elem(OP_GLOB, o,
4377 newSVOP(OP_CONST, 0, newSViv(glob_index++)));
4378 o->op_type = OP_LIST;
4379 o->op_ppaddr = ppaddr[OP_LIST];
4380 cLISTOPo->op_first->op_type = OP_PUSHMARK;
4381 cLISTOPo->op_first->op_ppaddr = ppaddr[OP_PUSHMARK];
4382 o = newUNOP(OP_ENTERSUB, OPf_STACKED,
4383 append_elem(OP_LIST, o,
4384 scalar(newUNOP(OP_RV2CV, 0,
4385 newGVOP(OP_GV, 0, gv)))));
4386 o = newUNOP(OP_NULL, 0, ck_subr(o));
4387 o->op_targ = OP_GLOB; /* hint at what it used to be */
4390 gv = newGVgen("main");
4392 append_elem(OP_GLOB, o, newGVOP(OP_GV, 0, gv));
4402 OPCODE type = o->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
4404 o->op_ppaddr = ppaddr[OP_GREPSTART];
4405 Newz(1101, gwop, 1, LOGOP);
4407 if (o->op_flags & OPf_STACKED) {
4410 kid = cLISTOPo->op_first->op_sibling;
4411 for (k = cLISTOPo->op_first->op_sibling->op_next; k; k = k->op_next) {
4414 kid->op_next = (OP*)gwop;
4415 o->op_flags &= ~OPf_STACKED;
4417 kid = cLISTOPo->op_first->op_sibling;
4418 if (type == OP_MAPWHILE)
4425 kid = cLISTOPo->op_first->op_sibling;
4426 if (kid->op_type != OP_NULL)
4427 croak("panic: ck_grep");
4428 kid = kUNOP->op_first;
4430 gwop->op_type = type;
4431 gwop->op_ppaddr = ppaddr[type];
4432 gwop->op_first = listkids(o);
4433 gwop->op_flags |= OPf_KIDS;
4434 gwop->op_private = 1;
4435 gwop->op_other = LINKLIST(kid);
4436 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
4437 kid->op_next = (OP*)gwop;
4439 kid = cLISTOPo->op_first->op_sibling;
4440 if (!kid || !kid->op_sibling)
4441 return too_few_arguments(o,op_desc[o->op_type]);
4442 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
4443 mod(kid, OP_GREPSTART);
4451 if (o->op_flags & OPf_KIDS) {
4452 OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
4453 if (kid && kid->op_type == OP_CONST)
4454 fbm_compile(((SVOP*)kid)->op_sv, 0);
4460 ck_lengthconst(OP *o)
4462 /* XXX length optimization goes here */
4469 OPCODE type = o->op_type;
4470 return modkids(ck_fun(o), type);
4476 OPCODE type = o->op_type;
4477 return refkids(ck_fun(o), type);
4485 kid = cLISTOPo->op_first;
4488 kid = cLISTOPo->op_first;
4490 if (kid->op_type == OP_PUSHMARK)
4491 kid = kid->op_sibling;
4492 if (kid && o->op_flags & OPf_STACKED)
4493 kid = kid->op_sibling;
4494 else if (kid && !kid->op_sibling) { /* print HANDLE; */
4495 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
4496 o->op_flags |= OPf_STACKED; /* make it a filehandle */
4497 kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
4498 cLISTOPo->op_first->op_sibling = kid;
4499 cLISTOPo->op_last = kid;
4500 kid = kid->op_sibling;
4505 append_elem(o->op_type, o, newDEFSVOP());
4511 if (PL_hints & HINT_LOCALE)
4512 o->op_private |= OPpLOCALE;
4519 ck_fun_locale(OP *o)
4525 if (PL_hints & HINT_LOCALE)
4526 o->op_private |= OPpLOCALE;
4537 if (PL_hints & HINT_LOCALE)
4538 o->op_private |= OPpLOCALE;
4547 o->op_private |= OPpRUNTIME;
4560 if (cBINOPo->op_first->op_flags & OPf_PARENS) {
4561 o->op_private |= OPpREPEAT_DOLIST;
4562 cBINOPo->op_first = force_list(cBINOPo->op_first);
4572 if (o->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
4573 SVOP *kid = (SVOP*)cUNOPo->op_first;
4575 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
4577 for (s = SvPVX(kid->op_sv); *s; s++) {
4578 if (*s == ':' && s[1] == ':') {
4580 Move(s+2, s+1, strlen(s+2)+1, char);
4581 --SvCUR(kid->op_sv);
4584 sv_catpvn(kid->op_sv, ".pm", 3);
4593 croak("NOT IMPL LINE %d",__LINE__);
4602 if (o->op_flags & OPf_KIDS) {
4603 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
4604 if (kid && kid->op_sibling) {
4605 o->op_type = OP_SSELECT;
4606 o->op_ppaddr = ppaddr[OP_SSELECT];
4608 return fold_constants(o);
4612 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
4613 if (kid && kid->op_type == OP_RV2GV)
4614 kid->op_private &= ~HINT_STRICT_REFS;
4621 I32 type = o->op_type;
4623 if (!(o->op_flags & OPf_KIDS)) {
4628 if (!CvUNIQUE(PL_compcv)) {
4629 argop = newOP(OP_PADAV, OPf_REF);
4630 argop->op_targ = 0; /* PL_curpad[0] is @_ */
4633 argop = newUNOP(OP_RV2AV, 0,
4634 scalar(newGVOP(OP_GV, 0,
4635 gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
4638 argop = newUNOP(OP_RV2AV, 0,
4639 scalar(newGVOP(OP_GV, 0, !CvUNIQUE(PL_compcv) ?
4640 PL_defgv : gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
4641 #endif /* USE_THREADS */
4642 return newUNOP(type, 0, scalar(argop));
4644 return scalar(modkids(ck_fun(o), type));
4652 if (PL_hints & HINT_LOCALE)
4653 o->op_private |= OPpLOCALE;
4656 if (o->op_flags & OPf_STACKED) {
4657 OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
4659 kid = kUNOP->op_first; /* get past rv2gv */
4661 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
4663 if (kid->op_type == OP_SCOPE) {
4667 else if (kid->op_type == OP_LEAVE) {
4668 if (o->op_type == OP_SORT) {
4669 null(kid); /* wipe out leave */
4672 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
4673 if (k->op_next == kid)
4678 kid->op_next = 0; /* just disconnect the leave */
4679 k = kLISTOP->op_first;
4683 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
4684 null(kid); /* wipe out rv2gv */
4685 if (o->op_type == OP_SORT)
4689 o->op_flags |= OPf_SPECIAL;
4701 if (o->op_flags & OPf_STACKED)
4702 return no_fh_allowed(o);
4704 kid = cLISTOPo->op_first;
4705 if (kid->op_type != OP_NULL)
4706 croak("panic: ck_split");
4707 kid = kid->op_sibling;
4708 op_free(cLISTOPo->op_first);
4709 cLISTOPo->op_first = kid;
4711 cLISTOPo->op_first = kid = newSVOP(OP_CONST, 0, newSVpv(" ", 1));
4712 cLISTOPo->op_last = kid; /* There was only one element previously */
4715 if (kid->op_type != OP_MATCH) {
4716 OP *sibl = kid->op_sibling;
4717 kid->op_sibling = 0;
4718 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
4719 if (cLISTOPo->op_first == cLISTOPo->op_last)
4720 cLISTOPo->op_last = kid;
4721 cLISTOPo->op_first = kid;
4722 kid->op_sibling = sibl;
4725 kid->op_type = OP_PUSHRE;
4726 kid->op_ppaddr = ppaddr[OP_PUSHRE];
4729 if (!kid->op_sibling)
4730 append_elem(OP_SPLIT, o, newDEFSVOP());
4732 kid = kid->op_sibling;
4735 if (!kid->op_sibling)
4736 append_elem(OP_SPLIT, o, newSVOP(OP_CONST, 0, newSViv(0)));
4738 kid = kid->op_sibling;
4741 if (kid->op_sibling)
4742 return too_many_arguments(o,op_desc[o->op_type]);
4751 OP *prev = ((cUNOPo->op_first->op_sibling)
4752 ? cUNOPo : ((UNOP*)cUNOPo->op_first))->op_first;
4753 OP *o2 = prev->op_sibling;
4761 for (cvop = o2; cvop->op_sibling; cvop = cvop->op_sibling) ;
4762 if (cvop->op_type == OP_RV2CV) {
4764 o->op_private |= (cvop->op_private & OPpENTERSUB_AMPER);
4765 null(cvop); /* disable rv2cv */
4766 tmpop = (SVOP*)((UNOP*)cvop)->op_first;
4767 if (tmpop->op_type == OP_GV) {
4768 cv = GvCVu(tmpop->op_sv);
4769 if (cv && SvPOK(cv) && !(o->op_private & OPpENTERSUB_AMPER)) {
4770 namegv = CvANON(cv) ? (GV*)tmpop->op_sv : CvGV(cv);
4771 proto = SvPV((SV*)cv, PL_na);
4775 o->op_private |= (PL_hints & HINT_STRICT_REFS);
4776 if (PERLDB_SUB && PL_curstash != PL_debstash)
4777 o->op_private |= OPpENTERSUB_DB;
4778 while (o2 != cvop) {
4782 return too_many_arguments(o, gv_ename(namegv));
4800 if (o2->op_type != OP_REFGEN && o2->op_type != OP_UNDEF)
4801 bad_type(arg, "block", gv_ename(namegv), o2);
4806 if (o2->op_type == OP_RV2GV)
4810 OP* sib = kid->op_sibling;
4811 kid->op_sibling = 0;
4812 o2 = newUNOP(OP_RV2GV, 0, kid);
4813 o2->op_sibling = sib;
4814 prev->op_sibling = o2;
4822 if (o2->op_type != OP_RV2GV)
4823 bad_type(arg, "symbol", gv_ename(namegv), o2);
4826 if (o2->op_type != OP_RV2CV)
4827 bad_type(arg, "sub", gv_ename(namegv), o2);
4830 if (o2->op_type != OP_RV2SV && o2->op_type != OP_PADSV)
4831 bad_type(arg, "scalar", gv_ename(namegv), o2);
4834 if (o2->op_type != OP_RV2AV && o2->op_type != OP_PADAV)
4835 bad_type(arg, "array", gv_ename(namegv), o2);
4838 if (o2->op_type != OP_RV2HV && o2->op_type != OP_PADHV)
4839 bad_type(arg, "hash", gv_ename(namegv), o2);
4843 OP* sib = kid->op_sibling;
4844 kid->op_sibling = 0;
4845 o2 = newUNOP(OP_REFGEN, 0, kid);
4846 o2->op_sibling = sib;
4847 prev->op_sibling = o2;
4858 croak("Malformed prototype for %s: %s",
4859 gv_ename(namegv), SvPV((SV*)cv, PL_na));
4864 mod(o2, OP_ENTERSUB);
4866 o2 = o2->op_sibling;
4868 if (proto && !optional &&
4869 (*proto && *proto != '@' && *proto != '%' && *proto != ';'))
4870 return too_few_arguments(o, gv_ename(namegv));
4877 SvREADONLY_on(cSVOPo->op_sv);
4884 if (o->op_flags & OPf_KIDS) {
4885 SVOP *kid = (SVOP*)cUNOPo->op_first;
4887 if (kid->op_type == OP_NULL)
4888 kid = (SVOP*)kid->op_sibling;
4890 kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE))
4891 o->op_flags |= OPf_SPECIAL;
4896 /* A peephole optimizer. We visit the ops in the order they're to execute. */
4899 peep(register OP *o)
4902 register OP* oldop = 0;
4903 if (!o || o->op_seq)
4907 SAVESPTR(PL_curcop);
4908 for (; o; o = o->op_next) {
4914 switch (o->op_type) {
4917 PL_curcop = ((COP*)o); /* for warnings */
4918 o->op_seq = PL_op_seqmax++;
4929 if (o->op_next && o->op_next->op_type == OP_STRINGIFY)
4931 o->op_seq = PL_op_seqmax++;
4934 if ((o->op_flags & OPf_WANT) != OPf_WANT_LIST) {
4935 o->op_seq = PL_op_seqmax++;
4936 break; /* Scalar stub must produce undef. List stub is noop */
4940 if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE)
4941 PL_curcop = ((COP*)o);
4947 if (oldop && o->op_next) {
4948 oldop->op_next = o->op_next;
4951 o->op_seq = PL_op_seqmax++;
4955 if (o->op_next->op_type == OP_RV2SV) {
4956 if (!(o->op_next->op_private & OPpDEREF)) {
4958 o->op_private |= o->op_next->op_private & OPpLVAL_INTRO;
4959 o->op_next = o->op_next->op_next;
4960 o->op_type = OP_GVSV;
4961 o->op_ppaddr = ppaddr[OP_GVSV];
4964 else if (o->op_next->op_type == OP_RV2AV) {
4965 OP* pop = o->op_next->op_next;
4967 if (pop->op_type == OP_CONST &&
4968 (PL_op = pop->op_next) &&
4969 pop->op_next->op_type == OP_AELEM &&
4970 !(pop->op_next->op_private &
4971 (OPpLVAL_INTRO|OPpLVAL_DEFER|OPpDEREF)) &&
4972 (i = SvIV(((SVOP*)pop)->op_sv) - PL_compiling.cop_arybase)
4976 SvREFCNT_dec(((SVOP*)pop)->op_sv);
4980 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
4981 o->op_next = pop->op_next->op_next;
4982 o->op_type = OP_AELEMFAST;
4983 o->op_ppaddr = ppaddr[OP_AELEMFAST];
4984 o->op_private = (U8)i;
4985 GvAVn(((GVOP*)o)->op_gv);
4988 o->op_seq = PL_op_seqmax++;
4992 if (o->op_next->op_type == OP_RV2AV
4993 && (o->op_next->op_flags & OPf_REF))
4996 o->op_next = o->op_next->op_next;
5001 if (o->op_next->op_type == OP_RV2HV
5002 && (o->op_next->op_flags & OPf_REF))
5005 o->op_next = o->op_next->op_next;
5013 o->op_seq = PL_op_seqmax++;
5014 while (cLOGOP->op_other->op_type == OP_NULL)
5015 cLOGOP->op_other = cLOGOP->op_other->op_next;
5016 peep(cLOGOP->op_other);
5020 o->op_seq = PL_op_seqmax++;
5021 peep(cCONDOP->op_true);
5022 peep(cCONDOP->op_false);
5026 o->op_seq = PL_op_seqmax++;
5027 peep(cLOOP->op_redoop);
5028 peep(cLOOP->op_nextop);
5029 peep(cLOOP->op_lastop);
5035 o->op_seq = PL_op_seqmax++;
5036 peep(cPMOP->op_pmreplstart);
5040 o->op_seq = PL_op_seqmax++;
5041 if (PL_dowarn && o->op_next && o->op_next->op_type == OP_NEXTSTATE) {
5042 if (o->op_next->op_sibling &&
5043 o->op_next->op_sibling->op_type != OP_EXIT &&
5044 o->op_next->op_sibling->op_type != OP_WARN &&
5045 o->op_next->op_sibling->op_type != OP_DIE) {
5046 line_t oldline = PL_curcop->cop_line;
5048 PL_curcop->cop_line = ((COP*)o->op_next)->cop_line;
5049 warn("Statement unlikely to be reached");
5050 warn("(Maybe you meant system() when you said exec()?)\n");
5051 PL_curcop->cop_line = oldline;
5065 if (o->op_private & (OPpDEREF_HV|OPpDEREF_AV|OPpLVAL_INTRO)
5066 || ((BINOP*)o)->op_last->op_type != OP_CONST)
5068 rop = (UNOP*)((BINOP*)o)->op_first;
5069 if (rop->op_type != OP_RV2HV || rop->op_first->op_type != OP_PADSV)
5071 lexname = *av_fetch(PL_comppad_name, rop->op_first->op_targ, TRUE);
5072 if (!SvOBJECT(lexname))
5074 fields = (GV**)hv_fetch(SvSTASH(lexname), "FIELDS", 6, FALSE);
5075 if (!fields || !GvHV(*fields))
5077 svp = &((SVOP*)((BINOP*)o)->op_last)->op_sv;
5078 key = SvPV(*svp, keylen);
5079 indsvp = hv_fetch(GvHV(*fields), key, keylen, FALSE);
5081 croak("No such field \"%s\" in variable %s of type %s",
5082 key, SvPV(lexname, PL_na), HvNAME(SvSTASH(lexname)));
5084 ind = SvIV(*indsvp);
5086 croak("Bad index while coercing array into hash");
5087 rop->op_type = OP_RV2AV;
5088 rop->op_ppaddr = ppaddr[OP_RV2AV];
5089 o->op_type = OP_AELEM;
5090 o->op_ppaddr = ppaddr[OP_AELEM];
5092 *svp = newSViv(ind);
5097 o->op_seq = PL_op_seqmax++;