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
21 #define USE_OP_MASK /* Turned on by default in 5.002beta1h */
25 * In the following definition, the ", (OP *) op" is just to make the compiler
26 * think the expression is of the right type: croak actually does a Siglongjmp.
28 #define CHECKOP(type,op) \
29 ((op_mask && op_mask[type]) \
30 ? ( op_free((OP*)op), \
31 croak("%s trapped by operation mask", op_desc[type]), \
33 : (*check[type])((OP*)op))
35 #define CHECKOP(type,op) (*check[type])(op)
36 #endif /* USE_OP_MASK */
38 static I32 list_assignment _((OP *op));
39 static OP *bad_type _((I32 n, char *t, char *name, OP *kid));
40 static OP *modkids _((OP *op, I32 type));
41 static OP *no_fh_allowed _((OP *op));
42 static OP *scalarboolean _((OP *op));
43 static OP *too_few_arguments _((OP *op, char* name));
44 static OP *too_many_arguments _((OP *op, char* name));
45 static void null _((OP* op));
46 static PADOFFSET pad_findlex _((char* name, PADOFFSET newoff, U32 seq,
47 CV* startcv, I32 cx_ix));
53 SV* tmpsv = sv_newmortal();
54 gv_efullname3(tmpsv, CvGV(cv), Nullch);
55 return SvPV(tmpsv,na);
62 sprintf(tokenbuf,"Missing comma after first argument to %s function",
63 op_desc[op->op_type]);
69 too_few_arguments(op, name)
73 sprintf(tokenbuf,"Not enough arguments for %s", name);
79 too_many_arguments(op, name)
83 sprintf(tokenbuf,"Too many arguments for %s", name);
89 bad_type(n, t, name, kid)
95 sprintf(tokenbuf, "Type of arg %d to %s must be %s (not %s)",
96 (int) n, name, t, op_desc[kid->op_type]);
105 int type = op->op_type;
106 if (type != OP_AELEM && type != OP_HELEM) {
107 sprintf(tokenbuf, "Can't use subscript on %s", op_desc[type]);
109 if (type == OP_ENTERSUB || type == OP_RV2HV || type == OP_PADHV)
110 warn("(Did you mean $ or @ instead of %c?)\n",
111 type == OP_ENTERSUB ? '&' : '%');
115 /* "register" allocation */
124 if (!(isALPHA(name[1]) || name[1] == '_' && (int)strlen(name) > 2)) {
125 if (!isPRINT(name[1]))
126 sprintf(name+1, "^%c", toCTRL(name[1])); /* XXX tokenbuf, really */
127 croak("Can't use global %s in \"my\"",name);
129 if (AvFILL(comppad_name) >= 0) {
130 SV **svp = AvARRAY(comppad_name);
131 for (off = AvFILL(comppad_name); off > comppad_name_floor; off--) {
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 av_store(comppad_name, off, sv);
147 SvNVX(sv) = (double)999999999;
148 SvIVX(sv) = 0; /* Not yet introduced--see newSTATEOP */
149 if (!min_intro_pending)
150 min_intro_pending = off;
151 max_intro_pending = off;
153 av_store(comppad, off, (SV*)newAV());
154 else if (*name == '%')
155 av_store(comppad, off, (SV*)newHV());
156 SvPADMY_on(curpad[off]);
161 #ifndef CAN_PROTOTYPE
162 pad_findlex(name, newoff, seq, startcv, cx_ix)
169 pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix)
176 register 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 == &sv_undef)
187 svp = AvARRAY(curname);
188 for (off = AvFILL(curname); off > 0; off--) {
189 if ((sv = svp[off]) &&
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(comppad_name, newoff, namesv);
216 SvNVX(namesv) = (double)curcop->cop_seq;
217 SvIVX(namesv) = 999999999; /* A ref, intro immediately */
218 SvFAKE_on(namesv); /* A ref, not a real var */
219 if (CvANON(compcv) || SvTYPE(compcv) == SVt_PVFM) {
220 /* "It's closures all the way down." */
225 bcv && bcv != cv && !CvCLONE(bcv);
226 bcv = CvOUTSIDE(bcv)) {
230 if (dowarn && !CvUNIQUE(cv))
232 "Variable \"%s\" may be unavailable",
239 else if (!CvUNIQUE(compcv)) {
240 if (dowarn && !SvFAKE(sv) && !CvUNIQUE(cv))
241 warn("Variable \"%s\" will not stay shared", name);
244 av_store(comppad, newoff, SvREFCNT_inc(oldsv));
250 /* Nothing in current lexical context--try eval's context, if any.
251 * This is necessary to let the perldb get at lexically scoped variables.
252 * XXX This will also probably interact badly with eval tree caching.
256 for (i = cx_ix; i >= 0; i--) {
258 switch (cx->cx_type) {
260 if (i == 0 && saweval) {
261 seq = cxstack[saweval].blk_oldcop->cop_seq;
262 return pad_findlex(name, newoff, seq, main_cv, 0);
266 switch (cx->blk_eval.old_op_type) {
271 /* require must have its own scope */
279 if (debstash && CvSTASH(cv) == debstash) { /* ignore DB'* scope */
280 saweval = i; /* so we know where we were called from */
283 seq = cxstack[saweval].blk_oldcop->cop_seq;
284 return pad_findlex(name, newoff, seq, cv, i-1);
297 SV **svp = AvARRAY(comppad_name);
298 U32 seq = cop_seqmax;
300 /* The one we're looking for is probably just before comppad_name_fill. */
301 for (off = AvFILL(comppad_name); off > 0; off--) {
302 if ((sv = svp[off]) &&
305 seq > I_32(SvNVX(sv)) &&
306 strEQ(SvPVX(sv), name))
308 return (PADOFFSET)off;
312 /* See if it's in a nested scope */
313 off = pad_findlex(name, 0, seq, CvOUTSIDE(compcv), cxstack_ix);
325 SV **svp = AvARRAY(comppad_name);
327 if (min_intro_pending && fill < min_intro_pending) {
328 for (off = max_intro_pending; off >= min_intro_pending; off--) {
329 if ((sv = svp[off]) && sv != &sv_undef)
330 warn("%s never introduced", SvPVX(sv));
333 /* "Deintroduce" my variables that are leaving with this scope. */
334 for (off = AvFILL(comppad_name); off > fill; off--) {
335 if ((sv = svp[off]) && sv != &sv_undef && SvIVX(sv) == 999999999)
336 SvIVX(sv) = cop_seqmax;
341 pad_alloc(optype,tmptype)
348 if (AvARRAY(comppad) != curpad)
349 croak("panic: pad_alloc");
350 if (pad_reset_pending)
352 if (tmptype & SVs_PADMY) {
354 sv = *av_fetch(comppad, AvFILL(comppad) + 1, TRUE);
355 } while (SvPADBUSY(sv)); /* need a fresh one */
356 retval = AvFILL(comppad);
359 SV **names = AvARRAY(comppad_name);
360 SSize_t names_fill = AvFILL(comppad_name);
363 * "foreach" index vars temporarily become aliases to non-"my"
364 * values. Thus we must skip, not just pad values that are
365 * marked as current pad values, but also those with names.
367 if (++padix <= names_fill &&
368 (sv = names[padix]) && sv != &sv_undef)
370 sv = *av_fetch(comppad, padix, TRUE);
371 if (!(SvFLAGS(sv) & (SVs_PADTMP|SVs_PADMY)))
376 SvFLAGS(sv) |= tmptype;
377 curpad = AvARRAY(comppad);
378 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad alloc %ld for %s\n", (long) retval, op_name[optype]));
379 return (PADOFFSET)retval;
383 #ifndef CAN_PROTOTYPE
388 #endif /* CAN_PROTOTYPE */
391 croak("panic: pad_sv po");
392 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad sv %lu\n", (unsigned long)po));
393 return curpad[po]; /* eventually we'll turn this into a macro */
397 #ifndef CAN_PROTOTYPE
401 pad_free(PADOFFSET po)
402 #endif /* CAN_PROTOTYPE */
406 if (AvARRAY(comppad) != curpad)
407 croak("panic: pad_free curpad");
409 croak("panic: pad_free po");
410 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad free %lu\n", (unsigned long)po));
411 if (curpad[po] && !SvIMMORTAL(curpad[po]))
412 SvPADTMP_off(curpad[po]);
418 #ifndef CAN_PROTOTYPE
422 pad_swipe(PADOFFSET po)
423 #endif /* CAN_PROTOTYPE */
425 if (AvARRAY(comppad) != curpad)
426 croak("panic: pad_swipe curpad");
428 croak("panic: pad_swipe po");
429 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad swipe %lu\n", (unsigned long)po));
430 SvPADTMP_off(curpad[po]);
431 curpad[po] = NEWSV(1107,0);
432 SvPADTMP_on(curpad[po]);
442 if (AvARRAY(comppad) != curpad)
443 croak("panic: pad_reset curpad");
444 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad reset\n"));
445 if (!tainting) { /* Can't mix tainted and non-tainted temporaries. */
446 for (po = AvMAX(comppad); po > padix_floor; po--) {
447 if (curpad[po] && !SvIMMORTAL(curpad[po]))
448 SvPADTMP_off(curpad[po]);
452 pad_reset_pending = FALSE;
461 register OP *kid, *nextkid;
463 if (!op || op->op_seq == (U16)-1)
466 if (op->op_flags & OPf_KIDS) {
467 for (kid = cUNOP->op_first; kid; kid = nextkid) {
468 nextkid = kid->op_sibling; /* Get before next freeing kid */
473 switch (op->op_type) {
475 op->op_targ = 0; /* Was holding old type, if any. */
478 op->op_targ = 0; /* Was holding hints. */
481 if (!(op->op_flags & OPf_REF) || (check[op->op_type] != ck_ftst))
487 SvREFCNT_dec(cGVOP->op_gv);
491 Safefree(cCOP->cop_label);
492 SvREFCNT_dec(cCOP->cop_filegv);
495 SvREFCNT_dec(cSVOP->op_sv);
501 if (op->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
505 Safefree(cPVOP->op_pv);
508 op_free(cPMOP->op_pmreplroot);
512 pregfree(cPMOP->op_pmregexp);
513 SvREFCNT_dec(cPMOP->op_pmshort);
518 pad_free(op->op_targ);
527 if (op->op_type != OP_NULL && op->op_targ > 0)
528 pad_free(op->op_targ);
529 op->op_targ = op->op_type;
530 op->op_type = OP_NULL;
531 op->op_ppaddr = ppaddr[OP_NULL];
534 /* Contextualizers */
536 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
547 /* establish postfix order */
548 if (cUNOP->op_first) {
549 op->op_next = LINKLIST(cUNOP->op_first);
550 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
552 kid->op_next = LINKLIST(kid->op_sibling);
568 if (op && op->op_flags & OPf_KIDS) {
569 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
580 op->op_type == OP_SASSIGN && cBINOP->op_first->op_type == OP_CONST) {
581 line_t oldline = curcop->cop_line;
583 if (copline != NOLINE)
584 curcop->cop_line = copline;
585 warn("Found = in conditional, should be ==");
586 curcop->cop_line = oldline;
597 /* assumes no premature commitment */
598 if (!op || (op->op_flags & OPf_KNOW) || op->op_type == OP_RETURN
602 op->op_flags &= ~OPf_LIST;
603 op->op_flags |= OPf_KNOW;
605 switch (op->op_type) {
607 if (op->op_private & OPpREPEAT_DOLIST)
608 null(((LISTOP*)cBINOP->op_first)->op_first);
609 scalar(cBINOP->op_first);
614 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
618 if ((kid = ((LISTOP*)op)->op_first) && kid->op_type == OP_PUSHRE) {
619 if (!kPMOP->op_pmreplroot)
620 deprecate("implicit split to @_");
627 if (op->op_flags & OPf_KIDS) {
628 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling)
634 scalar(cLISTOP->op_first);
639 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
659 if (!op || error_count)
661 if (op->op_flags & OPf_LIST)
664 op->op_flags |= OPf_KNOW;
666 switch (op->op_type) {
668 if (!(opargs[op->op_type] & OA_FOLDCONST))
672 if (op->op_flags & OPf_STACKED)
743 if (!(op->op_private & OPpLVAL_INTRO))
744 useless = op_desc[op->op_type];
751 if (!(op->op_private & OPpLVAL_INTRO) &&
752 (!op->op_sibling || op->op_sibling->op_type != OP_READLINE))
753 useless = "a variable";
758 curcop = ((COP*)op); /* for warning below */
764 useless = "a constant";
765 if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
767 else if (SvPOK(sv)) {
768 if (strnEQ(SvPVX(sv), "di", 2) ||
769 strnEQ(SvPVX(sv), "ds", 2) ||
770 strnEQ(SvPVX(sv), "ig", 2))
774 null(op); /* don't execute a constant */
775 SvREFCNT_dec(sv); /* don't even remember it */
779 op->op_type = OP_PREINC; /* pre-increment is faster */
780 op->op_ppaddr = ppaddr[OP_PREINC];
784 op->op_type = OP_PREDEC; /* pre-decrement is faster */
785 op->op_ppaddr = ppaddr[OP_PREDEC];
791 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
795 if (op->op_targ == OP_NEXTSTATE || op->op_targ == OP_DBSTATE)
796 curcop = ((COP*)op); /* for warning below */
797 if (op->op_flags & OPf_STACKED)
802 if (!(op->op_flags & OPf_KIDS))
808 op->op_private |= OPpLEAVE_VOID;
811 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
815 if ((kid = ((LISTOP*)op)->op_first) && kid->op_type == OP_PUSHRE) {
816 if (!kPMOP->op_pmreplroot)
817 deprecate("implicit split to @_");
823 op->op_private |= OPpLEAVE_VOID;
826 if (useless && dowarn)
827 warn("Useless use of %s in void context", useless);
836 if (op && op->op_flags & OPf_KIDS) {
837 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
849 /* assumes no premature commitment */
850 if (!op || (op->op_flags & OPf_KNOW) || op->op_type == OP_RETURN
854 op->op_flags |= (OPf_KNOW | OPf_LIST);
856 switch (op->op_type) {
859 list(cBINOP->op_first);
864 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
871 if (!(op->op_flags & OPf_KIDS))
873 if (!op->op_next && cUNOP->op_first->op_type == OP_FLOP) {
874 list(cBINOP->op_first);
875 return gen_constant_list(op);
882 list(cLISTOP->op_first);
886 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
905 if (op->op_type == OP_LINESEQ ||
906 op->op_type == OP_SCOPE ||
907 op->op_type == OP_LEAVE ||
908 op->op_type == OP_LEAVETRY)
910 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
911 if (kid->op_sibling) {
917 op->op_flags &= ~OPf_PARENS;
918 if (hints & HINT_BLOCK_SCOPE)
919 op->op_flags |= OPf_PARENS;
922 op = newOP(OP_STUB, 0);
932 if (op && op->op_flags & OPf_KIDS) {
933 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
949 if (!op || error_count)
952 switch (op->op_type) {
956 if (!(op->op_private & (OPpCONST_ARYBASE)))
958 if (eval_start && eval_start->op_type == OP_CONST) {
959 compiling.cop_arybase = (I32)SvIV(((SVOP*)eval_start)->op_sv);
963 SAVEI32(compiling.cop_arybase);
964 compiling.cop_arybase = 0;
966 else if (type == OP_REFGEN)
969 croak("That use of $[ is unsupported");
972 if (op->op_flags & OPf_PARENS)
976 if ((type == OP_UNDEF || type == OP_REFGEN) &&
977 !(op->op_flags & OPf_STACKED)) {
978 op->op_type = OP_RV2CV; /* entersub => rv2cv */
979 op->op_ppaddr = ppaddr[OP_RV2CV];
980 assert(cUNOP->op_first->op_type == OP_NULL);
981 null(((LISTOP*)cUNOP->op_first)->op_first); /* disable pushmark */
987 /* grep, foreach, subcalls, refgen */
988 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
990 sprintf(tokenbuf, "Can't modify %s in %s",
991 op_desc[op->op_type],
992 type ? op_desc[type] : "local");
1007 case OP_RIGHT_SHIFT:
1016 if (!(op->op_flags & OPf_STACKED))
1022 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
1028 if (type == OP_REFGEN && op->op_flags & OPf_PARENS) {
1030 return op; /* Treat \(@foo) like ordinary list. */
1034 ref(cUNOP->op_first, op->op_type);
1046 if (!type && cUNOP->op_first->op_type != OP_GV)
1047 croak("Can't localize a reference");
1048 ref(cUNOP->op_first, op->op_type);
1060 if (type == OP_REFGEN && op->op_flags & OPf_PARENS)
1061 return op; /* Treat \(@foo) like ordinary list. */
1066 croak("Can't localize lexical variable %s",
1067 SvPV(*av_fetch(comppad_name, op->op_targ, 4), na));
1074 if (type != OP_SASSIGN)
1080 pad_free(op->op_targ);
1081 op->op_targ = pad_alloc(op->op_type, SVs_PADMY);
1082 assert(SvTYPE(PAD_SV(op->op_targ)) == SVt_NULL);
1083 if (op->op_flags & OPf_KIDS)
1084 mod(cBINOP->op_first->op_sibling, type);
1089 ref(cBINOP->op_first, op->op_type);
1090 if (type == OP_ENTERSUB &&
1091 !(op->op_private & (OPpLVAL_INTRO | OPpDEREF)))
1092 op->op_private |= OPpLVAL_DEFER;
1099 if (op->op_flags & OPf_KIDS)
1100 mod(cLISTOP->op_last, type);
1104 if (!(op->op_flags & OPf_KIDS))
1106 if (op->op_targ != OP_LIST) {
1107 mod(cBINOP->op_first, type);
1112 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1116 op->op_flags |= OPf_MOD;
1118 if (type == OP_AASSIGN || type == OP_SASSIGN)
1119 op->op_flags |= OPf_SPECIAL|OPf_REF;
1121 op->op_private |= OPpLVAL_INTRO;
1122 op->op_flags &= ~OPf_SPECIAL;
1124 else if (type != OP_GREPSTART && type != OP_ENTERSUB)
1125 op->op_flags |= OPf_REF;
1135 if (op && op->op_flags & OPf_KIDS) {
1136 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1149 if (!op || error_count)
1152 switch (op->op_type) {
1154 if ((type == OP_DEFINED) &&
1155 !(op->op_flags & OPf_STACKED)) {
1156 op->op_type = OP_RV2CV; /* entersub => rv2cv */
1157 op->op_ppaddr = ppaddr[OP_RV2CV];
1158 assert(cUNOP->op_first->op_type == OP_NULL);
1159 null(((LISTOP*)cUNOP->op_first)->op_first); /* disable pushmark */
1160 op->op_flags |= OPf_SPECIAL;
1165 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
1169 ref(cUNOP->op_first, op->op_type);
1172 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1173 op->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1174 : type == OP_RV2HV ? OPpDEREF_HV
1176 op->op_flags |= OPf_MOD;
1182 op->op_flags |= OPf_REF;
1185 ref(cUNOP->op_first, op->op_type);
1190 op->op_flags |= OPf_REF;
1195 if (!(op->op_flags & OPf_KIDS))
1197 ref(cBINOP->op_first, type);
1201 ref(cBINOP->op_first, op->op_type);
1202 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1203 op->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1204 : type == OP_RV2HV ? OPpDEREF_HV
1206 op->op_flags |= OPf_MOD;
1214 if (!(op->op_flags & OPf_KIDS))
1216 ref(cLISTOP->op_last, type);
1232 if (!op || error_count)
1236 if (type == OP_LIST) {
1237 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1240 else if (type != OP_PADSV &&
1243 type != OP_PUSHMARK)
1245 sprintf(tokenbuf, "Can't declare %s in my", op_desc[op->op_type]);
1249 op->op_flags |= OPf_MOD;
1250 op->op_private |= OPpLVAL_INTRO;
1259 o->op_flags |= OPf_PARENS;
1264 bind_match(type, left, right)
1272 (left->op_type == OP_RV2AV ||
1273 left->op_type == OP_RV2HV ||
1274 left->op_type == OP_PADAV ||
1275 left->op_type == OP_PADHV)) {
1276 char *desc = op_desc[(right->op_type == OP_SUBST ||
1277 right->op_type == OP_TRANS)
1278 ? right->op_type : OP_MATCH];
1279 char *sample = ((left->op_type == OP_RV2AV ||
1280 left->op_type == OP_PADAV)
1281 ? "@array" : "%hash");
1282 warn("Applying %s to %s will act on scalar(%s)", desc, sample, sample);
1285 if (right->op_type == OP_MATCH ||
1286 right->op_type == OP_SUBST ||
1287 right->op_type == OP_TRANS) {
1288 right->op_flags |= OPf_STACKED;
1289 if (right->op_type != OP_MATCH)
1290 left = mod(left, right->op_type);
1291 if (right->op_type == OP_TRANS)
1292 op = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
1294 op = prepend_elem(right->op_type, scalar(left), right);
1296 return newUNOP(OP_NOT, 0, scalar(op));
1300 return bind_match(type, left,
1301 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
1310 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
1311 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(op));
1319 if (o->op_flags & OPf_PARENS || perldb || tainting) {
1320 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
1321 o->op_type = OP_LEAVE;
1322 o->op_ppaddr = ppaddr[OP_LEAVE];
1325 if (o->op_type == OP_LINESEQ) {
1327 o->op_type = OP_SCOPE;
1328 o->op_ppaddr = ppaddr[OP_SCOPE];
1329 kid = ((LISTOP*)o)->op_first;
1330 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE){
1331 SvREFCNT_dec(((COP*)kid)->cop_filegv);
1336 o = newLISTOP(OP_SCOPE, 0, o, Nullop);
1346 int retval = savestack_ix;
1347 SAVEI32(comppad_name_floor);
1349 if ((comppad_name_fill = AvFILL(comppad_name)) > 0)
1350 comppad_name_floor = comppad_name_fill;
1352 comppad_name_floor = 0;
1354 SAVEI32(min_intro_pending);
1355 SAVEI32(max_intro_pending);
1356 min_intro_pending = 0;
1357 SAVEI32(comppad_name_fill);
1358 SAVEI32(padix_floor);
1359 padix_floor = padix;
1360 pad_reset_pending = FALSE;
1362 hints &= ~HINT_BLOCK_SCOPE;
1367 block_end(floor, seq)
1371 int needblockscope = hints & HINT_BLOCK_SCOPE;
1372 OP* retval = scalarseq(seq);
1374 pad_reset_pending = FALSE;
1376 hints |= HINT_BLOCK_SCOPE; /* propagate out */
1377 pad_leavemy(comppad_name_fill);
1387 eval_root = newUNOP(OP_LEAVEEVAL, ((in_eval & 4) ? OPf_SPECIAL : 0), op);
1388 eval_start = linklist(eval_root);
1389 eval_root->op_next = 0;
1395 main_root = scope(sawparens(scalarvoid(op)));
1396 curcop = &compiling;
1397 main_start = LINKLIST(main_root);
1398 main_root->op_next = 0;
1402 /* Register with debugger */
1404 CV *cv = perl_get_cv("DB::postponed", FALSE);
1408 XPUSHs((SV*)compiling.cop_filegv);
1410 perl_call_sv((SV*)cv, G_DISCARD);
1421 if (o->op_flags & OPf_PARENS)
1425 if (dowarn && bufptr > oldbufptr && bufptr[-1] == ',') {
1427 for (s = bufptr; *s && (isALNUM(*s) || strchr("@$%, ",*s)); s++) ;
1428 if (*s == ';' || *s == '=')
1429 warn("Parens missing around \"%s\" list", lex ? "my" : "local");
1436 return mod(o, OP_NULL); /* a bit kludgey */
1443 if (o->op_type == OP_LIST) {
1444 o = convert(OP_JOIN, 0,
1445 prepend_elem(OP_LIST,
1446 newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
1457 I32 type = o->op_type;
1460 if (opargs[type] & OA_RETSCALAR)
1462 if (opargs[type] & OA_TARGET)
1463 o->op_targ = pad_alloc(type, SVs_PADTMP);
1465 if ((opargs[type] & OA_OTHERINT) && (hints & HINT_INTEGER))
1466 o->op_ppaddr = ppaddr[type = ++(o->op_type)];
1468 if (!(opargs[type] & OA_FOLDCONST))
1472 goto nope; /* Don't try to run w/ errors */
1474 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
1475 if (curop->op_type != OP_CONST &&
1476 curop->op_type != OP_LIST &&
1477 curop->op_type != OP_SCALAR &&
1478 curop->op_type != OP_NULL &&
1479 curop->op_type != OP_PUSHMARK) {
1484 curop = LINKLIST(o);
1489 if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
1490 pad_swipe(o->op_targ);
1491 else if (SvTEMP(sv)) { /* grab mortal temp? */
1492 (void)SvREFCNT_inc(sv);
1496 if (type == OP_RV2GV)
1497 return newGVOP(OP_GV, 0, (GV*)sv);
1499 if ((SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK)) == SVf_NOK) {
1501 if ((double)iv == SvNV(sv)) { /* can we smush double to int */
1506 SvIOK_off(sv); /* undo SvIV() damage */
1508 return newSVOP(OP_CONST, 0, sv);
1512 if (!(opargs[type] & OA_OTHERINT))
1515 if (!(hints & HINT_INTEGER)) {
1516 if (type == OP_DIVIDE || !(o->op_flags & OPf_KIDS))
1519 for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
1520 if (curop->op_type == OP_CONST) {
1521 if (SvIOK(((SVOP*)curop)->op_sv))
1525 if (opargs[curop->op_type] & OA_RETINTEGER)
1529 o->op_ppaddr = ppaddr[++(o->op_type)];
1536 gen_constant_list(o)
1540 I32 oldtmps_floor = tmps_floor;
1544 return o; /* Don't attempt to run with errors */
1546 op = curop = LINKLIST(o);
1552 tmps_floor = oldtmps_floor;
1554 o->op_type = OP_RV2AV;
1555 o->op_ppaddr = ppaddr[OP_RV2AV];
1556 curop = ((UNOP*)o)->op_first;
1557 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*stack_sp--));
1564 convert(type, flags, op)
1572 if (!op || op->op_type != OP_LIST)
1573 op = newLISTOP(OP_LIST, 0, op, Nullop);
1575 op->op_flags &= ~(OPf_KNOW|OPf_LIST);
1577 if (!(opargs[type] & OA_MARK))
1578 null(cLISTOP->op_first);
1581 op->op_ppaddr = ppaddr[type];
1582 op->op_flags |= flags;
1584 op = CHECKOP(type, op);
1585 if (op->op_type != type)
1588 if (cLISTOP->op_children < 7) {
1589 /* XXX do we really need to do this if we're done appending?? */
1590 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1592 cLISTOP->op_last = last; /* in case check substituted last arg */
1595 return fold_constants(op);
1598 /* List constructors */
1601 append_elem(type, first, last)
1612 if (first->op_type != type || type==OP_LIST && first->op_flags & OPf_PARENS)
1613 return newLISTOP(type, 0, first, last);
1615 if (first->op_flags & OPf_KIDS)
1616 ((LISTOP*)first)->op_last->op_sibling = last;
1618 first->op_flags |= OPf_KIDS;
1619 ((LISTOP*)first)->op_first = last;
1621 ((LISTOP*)first)->op_last = last;
1622 ((LISTOP*)first)->op_children++;
1627 append_list(type, first, last)
1638 if (first->op_type != type)
1639 return prepend_elem(type, (OP*)first, (OP*)last);
1641 if (last->op_type != type)
1642 return append_elem(type, (OP*)first, (OP*)last);
1644 first->op_last->op_sibling = last->op_first;
1645 first->op_last = last->op_last;
1646 first->op_children += last->op_children;
1647 if (first->op_children)
1648 last->op_flags |= OPf_KIDS;
1655 prepend_elem(type, first, last)
1666 if (last->op_type == type) {
1667 if (type == OP_LIST) { /* already a PUSHMARK there */
1668 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
1669 ((LISTOP*)last)->op_first->op_sibling = first;
1672 if (!(last->op_flags & OPf_KIDS)) {
1673 ((LISTOP*)last)->op_last = first;
1674 last->op_flags |= OPf_KIDS;
1676 first->op_sibling = ((LISTOP*)last)->op_first;
1677 ((LISTOP*)last)->op_first = first;
1679 ((LISTOP*)last)->op_children++;
1683 return newLISTOP(type, 0, first, last);
1691 return newOP(OP_STUB, 0);
1698 if (!op || op->op_type != OP_LIST)
1699 op = newLISTOP(OP_LIST, 0, op, Nullop);
1705 newLISTOP(type, flags, first, last)
1713 Newz(1101, listop, 1, LISTOP);
1715 listop->op_type = type;
1716 listop->op_ppaddr = ppaddr[type];
1717 listop->op_children = (first != 0) + (last != 0);
1718 listop->op_flags = flags;
1722 else if (!first && last)
1725 first->op_sibling = last;
1726 listop->op_first = first;
1727 listop->op_last = last;
1728 if (type == OP_LIST) {
1730 pushop = newOP(OP_PUSHMARK, 0);
1731 pushop->op_sibling = first;
1732 listop->op_first = pushop;
1733 listop->op_flags |= OPf_KIDS;
1735 listop->op_last = pushop;
1737 else if (listop->op_children)
1738 listop->op_flags |= OPf_KIDS;
1749 Newz(1101, op, 1, OP);
1751 op->op_ppaddr = ppaddr[type];
1752 op->op_flags = flags;
1755 op->op_private = 0 + (flags >> 8);
1756 if (opargs[type] & OA_RETSCALAR)
1758 if (opargs[type] & OA_TARGET)
1759 op->op_targ = pad_alloc(type, SVs_PADTMP);
1760 return CHECKOP(type, op);
1764 newUNOP(type, flags, first)
1772 first = newOP(OP_STUB, 0);
1773 if (opargs[type] & OA_MARK)
1774 first = force_list(first);
1776 Newz(1101, unop, 1, UNOP);
1777 unop->op_type = type;
1778 unop->op_ppaddr = ppaddr[type];
1779 unop->op_first = first;
1780 unop->op_flags = flags | OPf_KIDS;
1781 unop->op_private = 1 | (flags >> 8);
1783 unop = (UNOP*) CHECKOP(type, unop);
1787 return fold_constants((OP *) unop);
1791 newBINOP(type, flags, first, last)
1798 Newz(1101, binop, 1, BINOP);
1801 first = newOP(OP_NULL, 0);
1803 binop->op_type = type;
1804 binop->op_ppaddr = ppaddr[type];
1805 binop->op_first = first;
1806 binop->op_flags = flags | OPf_KIDS;
1809 binop->op_private = 1 | (flags >> 8);
1812 binop->op_private = 2 | (flags >> 8);
1813 first->op_sibling = last;
1816 binop = (BINOP*)CHECKOP(type, binop);
1820 binop->op_last = last = binop->op_first->op_sibling;
1822 return fold_constants((OP *)binop);
1826 pmtrans(op, expr, repl)
1831 SV *tstr = ((SVOP*)expr)->op_sv;
1832 SV *rstr = ((SVOP*)repl)->op_sv;
1835 register U8 *t = (U8*)SvPV(tstr, tlen);
1836 register U8 *r = (U8*)SvPV(rstr, rlen);
1841 register short *tbl;
1843 tbl = (short*)cPVOP->op_pv;
1844 complement = op->op_private & OPpTRANS_COMPLEMENT;
1845 delete = op->op_private & OPpTRANS_DELETE;
1846 /* squash = op->op_private & OPpTRANS_SQUASH; */
1849 Zero(tbl, 256, short);
1850 for (i = 0; i < tlen; i++)
1852 for (i = 0, j = 0; i < 256; i++) {
1868 if (!rlen && !delete) {
1871 for (i = 0; i < 256; i++)
1873 for (i = 0, j = 0; i < tlen; i++,j++) {
1876 if (tbl[t[i]] == -1)
1882 if (tbl[t[i]] == -1)
1893 newPMOP(type, flags)
1899 Newz(1101, pmop, 1, PMOP);
1900 pmop->op_type = type;
1901 pmop->op_ppaddr = ppaddr[type];
1902 pmop->op_flags = flags;
1903 pmop->op_private = 0 | (flags >> 8);
1905 if (hints & HINT_LOCALE)
1906 pmop->op_pmpermflags = (pmop->op_pmflags |= PMf_LOCALE);
1908 /* link into pm list */
1909 if (type != OP_TRANS && curstash) {
1910 pmop->op_pmnext = HvPMROOT(curstash);
1911 HvPMROOT(curstash) = pmop;
1918 pmruntime(op, expr, repl)
1926 if (op->op_type == OP_TRANS)
1927 return pmtrans(op, expr, repl);
1931 if (expr->op_type == OP_CONST) {
1933 SV *pat = ((SVOP*)expr)->op_sv;
1934 char *p = SvPV(pat, plen);
1935 if ((op->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
1936 sv_setpvn(pat, "\\s+", 3);
1937 p = SvPV(pat, plen);
1938 pm->op_pmflags |= PMf_SKIPWHITE;
1940 pm->op_pmregexp = pregcomp(p, p + plen, pm);
1941 if (strEQ("\\s+", pm->op_pmregexp->precomp))
1942 pm->op_pmflags |= PMf_WHITE;
1947 if (pm->op_pmflags & PMf_KEEP)
1948 expr = newUNOP(OP_REGCMAYBE,0,expr);
1950 Newz(1101, rcop, 1, LOGOP);
1951 rcop->op_type = OP_REGCOMP;
1952 rcop->op_ppaddr = ppaddr[OP_REGCOMP];
1953 rcop->op_first = scalar(expr);
1954 rcop->op_flags |= OPf_KIDS;
1955 rcop->op_private = 1;
1956 rcop->op_other = op;
1958 /* establish postfix order */
1959 if (pm->op_pmflags & PMf_KEEP) {
1961 rcop->op_next = expr;
1962 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
1965 rcop->op_next = LINKLIST(expr);
1966 expr->op_next = (OP*)rcop;
1969 prepend_elem(op->op_type, scalar((OP*)rcop), op);
1974 if (pm->op_pmflags & PMf_EVAL)
1976 else if (repl->op_type == OP_CONST)
1980 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
1981 if (opargs[curop->op_type] & OA_DANGEROUS) {
1982 if (curop->op_type == OP_GV) {
1983 GV *gv = ((GVOP*)curop)->op_gv;
1984 if (strchr("&`'123456789+", *GvENAME(gv)))
1987 else if (curop->op_type == OP_RV2CV)
1989 else if (curop->op_type == OP_RV2SV ||
1990 curop->op_type == OP_RV2AV ||
1991 curop->op_type == OP_RV2HV ||
1992 curop->op_type == OP_RV2GV) {
1993 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
1996 else if (curop->op_type == OP_PADSV ||
1997 curop->op_type == OP_PADAV ||
1998 curop->op_type == OP_PADHV ||
1999 curop->op_type == OP_PADANY) {
2008 if (curop == repl) {
2009 pm->op_pmflags |= PMf_CONST; /* const for long enough */
2010 pm->op_pmpermflags |= PMf_CONST; /* const for long enough */
2011 prepend_elem(op->op_type, scalar(repl), op);
2014 Newz(1101, rcop, 1, LOGOP);
2015 rcop->op_type = OP_SUBSTCONT;
2016 rcop->op_ppaddr = ppaddr[OP_SUBSTCONT];
2017 rcop->op_first = scalar(repl);
2018 rcop->op_flags |= OPf_KIDS;
2019 rcop->op_private = 1;
2020 rcop->op_other = op;
2022 /* establish postfix order */
2023 rcop->op_next = LINKLIST(repl);
2024 repl->op_next = (OP*)rcop;
2026 pm->op_pmreplroot = scalar((OP*)rcop);
2027 pm->op_pmreplstart = LINKLIST(rcop);
2036 newSVOP(type, flags, sv)
2042 Newz(1101, svop, 1, SVOP);
2043 svop->op_type = type;
2044 svop->op_ppaddr = ppaddr[type];
2046 svop->op_next = (OP*)svop;
2047 svop->op_flags = flags;
2048 if (opargs[type] & OA_RETSCALAR)
2050 if (opargs[type] & OA_TARGET)
2051 svop->op_targ = pad_alloc(type, SVs_PADTMP);
2052 return CHECKOP(type, svop);
2056 newGVOP(type, flags, gv)
2062 Newz(1101, gvop, 1, GVOP);
2063 gvop->op_type = type;
2064 gvop->op_ppaddr = ppaddr[type];
2065 gvop->op_gv = (GV*)SvREFCNT_inc(gv);
2066 gvop->op_next = (OP*)gvop;
2067 gvop->op_flags = flags;
2068 if (opargs[type] & OA_RETSCALAR)
2070 if (opargs[type] & OA_TARGET)
2071 gvop->op_targ = pad_alloc(type, SVs_PADTMP);
2072 return CHECKOP(type, gvop);
2076 newPVOP(type, flags, pv)
2082 Newz(1101, pvop, 1, PVOP);
2083 pvop->op_type = type;
2084 pvop->op_ppaddr = ppaddr[type];
2086 pvop->op_next = (OP*)pvop;
2087 pvop->op_flags = flags;
2088 if (opargs[type] & OA_RETSCALAR)
2090 if (opargs[type] & OA_TARGET)
2091 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
2092 return CHECKOP(type, pvop);
2101 save_hptr(&curstash);
2102 save_item(curstname);
2107 name = SvPV(sv, len);
2108 curstash = gv_stashpvn(name,len,TRUE);
2109 sv_setpvn(curstname, name, len);
2113 sv_setpv(curstname,"<none>");
2121 utilize(aver, floor, version, id, arg)
2134 if (id->op_type != OP_CONST)
2135 croak("Module name must be constant");
2139 if(version != Nullop) {
2140 SV *vesv = ((SVOP*)version)->op_sv;
2142 if (arg == Nullop && !SvNIOK(vesv)) {
2149 if (version->op_type != OP_CONST || !SvNIOK(vesv))
2150 croak("Version number must be constant number");
2152 /* Make copy of id so we don't free it twice */
2153 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2155 /* Fake up a method call to VERSION */
2156 meth = newSVOP(OP_CONST, 0, newSVpv("VERSION", 7));
2157 veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2158 append_elem(OP_LIST,
2159 prepend_elem(OP_LIST, pack, list(version)),
2160 newUNOP(OP_METHOD, 0, meth)));
2164 /* Fake up an import/unimport */
2165 if (arg && arg->op_type == OP_STUB)
2166 imop = arg; /* no import on explicit () */
2167 else if(SvNIOK(((SVOP*)id)->op_sv)) {
2168 imop = Nullop; /* use 5.0; */
2171 /* Make copy of id so we don't free it twice */
2172 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2173 meth = newSVOP(OP_CONST, 0,
2175 ? newSVpv("import", 6)
2176 : newSVpv("unimport", 8)
2178 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2179 append_elem(OP_LIST,
2180 prepend_elem(OP_LIST, pack, list(arg)),
2181 newUNOP(OP_METHOD, 0, meth)));
2184 /* Fake up a require */
2185 rqop = newUNOP(OP_REQUIRE, 0, id);
2187 /* Fake up the BEGIN {}, which does its thing immediately. */
2189 newSVOP(OP_CONST, 0, newSVpv("BEGIN", 5)),
2191 append_elem(OP_LINESEQ,
2192 append_elem(OP_LINESEQ,
2193 newSTATEOP(0, Nullch, rqop),
2194 newSTATEOP(0, Nullch, veop)),
2195 newSTATEOP(0, Nullch, imop) ));
2202 newSLICEOP(flags, subscript, listval)
2207 return newBINOP(OP_LSLICE, flags,
2208 list(force_list(subscript)),
2209 list(force_list(listval)) );
2219 if (op->op_type == OP_NULL && op->op_flags & OPf_KIDS)
2220 op = cUNOP->op_first;
2222 if (op->op_type == OP_COND_EXPR) {
2223 I32 t = list_assignment(cCONDOP->op_first->op_sibling);
2224 I32 f = list_assignment(cCONDOP->op_first->op_sibling->op_sibling);
2229 yyerror("Assignment to both a list and a scalar");
2233 if (op->op_type == OP_LIST || op->op_flags & OPf_PARENS ||
2234 op->op_type == OP_RV2AV || op->op_type == OP_RV2HV ||
2235 op->op_type == OP_ASLICE || op->op_type == OP_HSLICE)
2238 if (op->op_type == OP_PADAV || op->op_type == OP_PADHV)
2241 if (op->op_type == OP_RV2SV)
2248 newASSIGNOP(flags, left, optype, right)
2257 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN) {
2258 return newLOGOP(optype, 0,
2259 mod(scalar(left), optype),
2260 newUNOP(OP_SASSIGN, 0, scalar(right)));
2263 return newBINOP(optype, OPf_STACKED,
2264 mod(scalar(left), optype), scalar(right));
2268 if (list_assignment(left)) {
2270 eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2271 left = mod(left, OP_AASSIGN);
2279 op = newBINOP(OP_AASSIGN, flags,
2280 list(force_list(right)),
2281 list(force_list(left)) );
2282 op->op_private = 0 | (flags >> 8);
2283 if (!(left->op_private & OPpLVAL_INTRO)) {
2284 static int generation = 100;
2288 for (curop = LINKLIST(op); curop != op; curop = LINKLIST(curop)) {
2289 if (opargs[curop->op_type] & OA_DANGEROUS) {
2290 if (curop->op_type == OP_GV) {
2291 GV *gv = ((GVOP*)curop)->op_gv;
2292 if (gv == defgv || SvCUR(gv) == generation)
2294 SvCUR(gv) = generation;
2296 else if (curop->op_type == OP_PADSV ||
2297 curop->op_type == OP_PADAV ||
2298 curop->op_type == OP_PADHV ||
2299 curop->op_type == OP_PADANY) {
2300 SV **svp = AvARRAY(comppad_name);
2301 SV *sv = svp[curop->op_targ];
2302 if (SvCUR(sv) == generation)
2304 SvCUR(sv) = generation; /* (SvCUR not used any more) */
2306 else if (curop->op_type == OP_RV2CV)
2308 else if (curop->op_type == OP_RV2SV ||
2309 curop->op_type == OP_RV2AV ||
2310 curop->op_type == OP_RV2HV ||
2311 curop->op_type == OP_RV2GV) {
2312 if (lastop->op_type != OP_GV) /* funny deref? */
2321 op->op_private = OPpASSIGN_COMMON;
2323 if (right && right->op_type == OP_SPLIT) {
2325 if ((tmpop = ((LISTOP*)right)->op_first) &&
2326 tmpop->op_type == OP_PUSHRE)
2328 PMOP *pm = (PMOP*)tmpop;
2329 if (left->op_type == OP_RV2AV &&
2330 !(left->op_private & OPpLVAL_INTRO) &&
2331 !(op->op_private & OPpASSIGN_COMMON) )
2333 tmpop = ((UNOP*)left)->op_first;
2334 if (tmpop->op_type == OP_GV && !pm->op_pmreplroot) {
2335 pm->op_pmreplroot = (OP*)((GVOP*)tmpop)->op_gv;
2336 pm->op_pmflags |= PMf_ONCE;
2337 tmpop = ((UNOP*)op)->op_first; /* to list (nulled) */
2338 tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */
2339 tmpop->op_sibling = Nullop; /* don't free split */
2340 right->op_next = tmpop->op_next; /* fix starting loc */
2341 op_free(op); /* blow off assign */
2342 right->op_flags &= ~(OPf_KNOW|OPf_LIST);
2343 /* "I don't know and I don't care." */
2348 if (modcount < 10000 &&
2349 ((LISTOP*)right)->op_last->op_type == OP_CONST)
2351 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
2353 sv_setiv(sv, modcount+1);
2361 right = newOP(OP_UNDEF, 0);
2362 if (right->op_type == OP_READLINE) {
2363 right->op_flags |= OPf_STACKED;
2364 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
2367 eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2368 op = newBINOP(OP_SASSIGN, flags,
2369 scalar(right), mod(scalar(left), OP_SASSIGN) );
2381 newSTATEOP(flags, label, op)
2386 U32 seq = intro_my();
2389 Newz(1101, cop, 1, COP);
2390 if (perldb && curcop->cop_line && curstash != debstash) {
2391 cop->op_type = OP_DBSTATE;
2392 cop->op_ppaddr = ppaddr[ OP_DBSTATE ];
2395 cop->op_type = OP_NEXTSTATE;
2396 cop->op_ppaddr = ppaddr[ OP_NEXTSTATE ];
2398 cop->op_flags = flags;
2399 cop->op_private = 0 | (flags >> 8);
2401 cop->op_private |= NATIVE_HINTS;
2403 cop->op_next = (OP*)cop;
2406 cop->cop_label = label;
2407 hints |= HINT_BLOCK_SCOPE;
2410 cop->cop_arybase = curcop->cop_arybase;
2412 if (copline == NOLINE)
2413 cop->cop_line = curcop->cop_line;
2415 cop->cop_line = copline;
2418 cop->cop_filegv = (GV*)SvREFCNT_inc(curcop->cop_filegv);
2419 cop->cop_stash = curstash;
2421 if (perldb && curstash != debstash) {
2422 SV **svp = av_fetch(GvAV(curcop->cop_filegv),(I32)cop->cop_line, FALSE);
2423 if (svp && *svp != &sv_undef && !SvIOK(*svp)) {
2424 (void)SvIOK_on(*svp);
2426 SvSTASH(*svp) = (HV*)cop;
2430 return prepend_elem(OP_LINESEQ, (OP*)cop, op);
2433 /* "Introduce" my variables to visible status. */
2441 if (! min_intro_pending)
2444 svp = AvARRAY(comppad_name);
2445 for (i = min_intro_pending; i <= max_intro_pending; i++) {
2446 if ((sv = svp[i]) && sv != &sv_undef && !SvIVX(sv)) {
2447 SvIVX(sv) = 999999999; /* Don't know scope end yet. */
2448 SvNVX(sv) = (double)cop_seqmax;
2451 min_intro_pending = 0;
2452 comppad_name_fill = max_intro_pending; /* Needn't search higher */
2453 return cop_seqmax++;
2457 newLOGOP(type, flags, first, other)
2466 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
2467 return newBINOP(type, flags, scalar(first), scalar(other));
2469 scalarboolean(first);
2470 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
2471 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
2472 if (type == OP_AND || type == OP_OR) {
2478 first = cUNOP->op_first;
2480 first->op_next = op->op_next;
2481 cUNOP->op_first = Nullop;
2485 if (first->op_type == OP_CONST) {
2486 if (dowarn && (first->op_private & OPpCONST_BARE))
2487 warn("Probable precedence problem on %s", op_desc[type]);
2488 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
2497 else if (first->op_type == OP_WANTARRAY) {
2503 else if (dowarn && (first->op_flags & OPf_KIDS)) {
2504 OP *k1 = ((UNOP*)first)->op_first;
2505 OP *k2 = k1->op_sibling;
2507 switch (first->op_type)
2510 if (k2 && k2->op_type == OP_READLINE
2511 && (k2->op_flags & OPf_STACKED)
2512 && (k1->op_type == OP_RV2SV || k1->op_type == OP_PADSV))
2513 warnop = k2->op_type;
2517 if (k1->op_type == OP_READDIR
2518 || k1->op_type == OP_GLOB
2519 || k1->op_type == OP_EACH)
2520 warnop = k1->op_type;
2524 line_t oldline = curcop->cop_line;
2525 curcop->cop_line = copline;
2526 warn("Value of %s%s can be \"0\"; test with defined()",
2528 ((warnop == OP_READLINE || warnop == OP_GLOB)
2529 ? " construct" : "() operator"));
2530 curcop->cop_line = oldline;
2537 if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
2538 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
2540 Newz(1101, logop, 1, LOGOP);
2542 logop->op_type = type;
2543 logop->op_ppaddr = ppaddr[type];
2544 logop->op_first = first;
2545 logop->op_flags = flags | OPf_KIDS;
2546 logop->op_other = LINKLIST(other);
2547 logop->op_private = 1 | (flags >> 8);
2549 /* establish postfix order */
2550 logop->op_next = LINKLIST(first);
2551 first->op_next = (OP*)logop;
2552 first->op_sibling = other;
2554 op = newUNOP(OP_NULL, 0, (OP*)logop);
2555 other->op_next = op;
2561 newCONDOP(flags, first, trueop, falseop)
2571 return newLOGOP(OP_AND, 0, first, trueop);
2573 return newLOGOP(OP_OR, 0, first, falseop);
2575 scalarboolean(first);
2576 if (first->op_type == OP_CONST) {
2577 if (SvTRUE(((SVOP*)first)->op_sv)) {
2588 else if (first->op_type == OP_WANTARRAY) {
2592 Newz(1101, condop, 1, CONDOP);
2594 condop->op_type = OP_COND_EXPR;
2595 condop->op_ppaddr = ppaddr[OP_COND_EXPR];
2596 condop->op_first = first;
2597 condop->op_flags = flags | OPf_KIDS;
2598 condop->op_true = LINKLIST(trueop);
2599 condop->op_false = LINKLIST(falseop);
2600 condop->op_private = 1 | (flags >> 8);
2602 /* establish postfix order */
2603 condop->op_next = LINKLIST(first);
2604 first->op_next = (OP*)condop;
2606 first->op_sibling = trueop;
2607 trueop->op_sibling = falseop;
2608 op = newUNOP(OP_NULL, 0, (OP*)condop);
2610 trueop->op_next = op;
2611 falseop->op_next = op;
2617 newRANGE(flags, left, right)
2627 Newz(1101, condop, 1, CONDOP);
2629 condop->op_type = OP_RANGE;
2630 condop->op_ppaddr = ppaddr[OP_RANGE];
2631 condop->op_first = left;
2632 condop->op_flags = OPf_KIDS;
2633 condop->op_true = LINKLIST(left);
2634 condop->op_false = LINKLIST(right);
2635 condop->op_private = 1 | (flags >> 8);
2637 left->op_sibling = right;
2639 condop->op_next = (OP*)condop;
2640 flip = newUNOP(OP_FLIP, flags, (OP*)condop);
2641 flop = newUNOP(OP_FLOP, 0, flip);
2642 op = newUNOP(OP_NULL, 0, flop);
2645 left->op_next = flip;
2646 right->op_next = flop;
2648 condop->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2649 sv_upgrade(PAD_SV(condop->op_targ), SVt_PVNV);
2650 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2651 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
2653 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2654 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2657 if (!flip->op_private || !flop->op_private)
2658 linklist(op); /* blow off optimizer unless constant */
2664 newLOOPOP(flags, debuggable, expr, block)
2672 int once = block && block->op_flags & OPf_SPECIAL &&
2673 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
2676 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
2677 return block; /* do {} while 0 does once */
2678 if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB) {
2679 expr = newUNOP(OP_DEFINED, 0,
2680 newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr) );
2684 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
2685 op = newLOGOP(OP_AND, 0, expr, listop);
2687 ((LISTOP*)listop)->op_last->op_next = LINKLIST(op);
2689 if (once && op != listop)
2690 op->op_next = ((LOGOP*)cUNOP->op_first)->op_other;
2693 op = newUNOP(OP_NULL, 0, op); /* or do {} while 1 loses outer block */
2695 op->op_flags |= flags;
2697 op->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/
2702 newWHILEOP(flags, debuggable, loop, expr, block, cont)
2716 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB)) {
2717 expr = newUNOP(OP_DEFINED, 0,
2718 newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr) );
2722 block = newOP(OP_NULL, 0);
2725 next = LINKLIST(cont);
2727 cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
2729 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
2730 redo = LINKLIST(listop);
2733 op = newLOGOP(OP_AND, 0, expr, scalar(listop));
2734 if (op == expr && op->op_type == OP_CONST && !SvTRUE(cSVOP->op_sv)) {
2735 op_free(expr); /* oops, it's a while (0) */
2737 return Nullop; /* (listop already freed by newLOGOP) */
2739 ((LISTOP*)listop)->op_last->op_next = condop =
2740 (op == listop ? redo : LINKLIST(op));
2748 Newz(1101,loop,1,LOOP);
2749 loop->op_type = OP_ENTERLOOP;
2750 loop->op_ppaddr = ppaddr[OP_ENTERLOOP];
2751 loop->op_private = 0;
2752 loop->op_next = (OP*)loop;
2755 op = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, op);
2757 loop->op_redoop = redo;
2758 loop->op_lastop = op;
2761 loop->op_nextop = next;
2763 loop->op_nextop = op;
2765 op->op_flags |= flags;
2766 op->op_private |= (flags >> 8);
2771 #ifndef CAN_PROTOTYPE
2772 newFOROP(flags,label,forline,sv,expr,block,cont)
2781 newFOROP(I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
2782 #endif /* CAN_PROTOTYPE */
2790 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
2791 sv->op_type = OP_RV2GV;
2792 sv->op_ppaddr = ppaddr[OP_RV2GV];
2794 else if (sv->op_type == OP_PADSV) { /* private variable */
2795 padoff = sv->op_targ;
2800 croak("Can't use %s for loop variable", op_desc[sv->op_type]);
2803 sv = newGVOP(OP_GV, 0, defgv);
2805 if (expr->op_type == OP_RV2AV || expr->op_type == OP_PADAV) {
2806 expr = scalar(ref(expr, OP_ITER));
2807 iterflags |= OPf_STACKED;
2809 loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
2810 append_elem(OP_LIST, mod(force_list(expr), OP_GREPSTART),
2812 assert(!loop->op_next);
2813 Renew(loop, 1, LOOP);
2814 loop->op_targ = padoff;
2815 return newSTATEOP(0, label, newWHILEOP(flags, 1, loop,
2816 newOP(OP_ITER, 0), block, cont));
2820 newLOOPEX(type, label)
2825 if (type != OP_GOTO || label->op_type == OP_CONST) {
2826 op = newPVOP(type, 0, savepv(
2827 label->op_type == OP_CONST
2828 ? SvPVx(((SVOP*)label)->op_sv, na)
2833 if (label->op_type == OP_ENTERSUB)
2834 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
2835 op = newUNOP(type, OPf_STACKED, label);
2837 hints |= HINT_BLOCK_SCOPE;
2845 if (!CvXSUB(cv) && CvROOT(cv)) {
2847 croak("Can't undef active subroutine");
2854 op_free(CvROOT(cv));
2855 CvROOT(cv) = Nullop;
2859 SvREFCNT_dec(CvGV(cv));
2861 SvREFCNT_dec(CvOUTSIDE(cv));
2862 CvOUTSIDE(cv) = Nullcv;
2863 if (CvPADLIST(cv)) {
2864 /* may be during global destruction */
2865 if (SvREFCNT(CvPADLIST(cv))) {
2866 I32 i = AvFILL(CvPADLIST(cv));
2868 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
2872 SvREFCNT_dec((SV*)CvPADLIST(cv));
2874 CvPADLIST(cv) = Nullav;
2878 #ifdef DEBUG_CLOSURES
2883 CV *outside = CvOUTSIDE(cv);
2884 AV* padlist = CvPADLIST(cv);
2891 PerlIO_printf(Perl_debug_log, "\tCV=0x%p (%s), OUTSIDE=0x%p (%s)\n",
2893 (CvANON(cv) ? "ANON"
2894 : (cv == main_cv) ? "MAIN"
2895 : CvUNIQUE(outside) ? "UNIQUE"
2896 : CvGV(cv) ? GvNAME(CvGV(cv)) : "UNDEFINED"),
2899 : CvANON(outside) ? "ANON"
2900 : (outside == main_cv) ? "MAIN"
2901 : CvUNIQUE(outside) ? "UNIQUE"
2902 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
2907 pad_name = (AV*)*av_fetch(padlist, 0, FALSE);
2908 pad = (AV*)*av_fetch(padlist, 1, FALSE);
2909 pname = AvARRAY(pad_name);
2910 ppad = AvARRAY(pad);
2912 for (ix = 1; ix <= AvFILL(pad_name); ix++) {
2913 if (SvPOK(pname[ix]))
2914 PerlIO_printf(Perl_debug_log, "\t%4d. 0x%p (%s\"%s\" %ld-%ld)\n",
2916 SvFAKE(pname[ix]) ? "FAKE " : "",
2918 (long)I_32(SvNVX(pname[ix])),
2919 (long)SvIVX(pname[ix]));
2922 #endif /* DEBUG_CLOSURES */
2925 cv_clone2(proto, outside)
2931 AV* protopadlist = CvPADLIST(proto);
2932 AV* protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
2933 AV* protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
2934 SV** pname = AvARRAY(protopad_name);
2935 SV** ppad = AvARRAY(protopad);
2936 I32 fname = AvFILL(protopad_name);
2937 I32 fpad = AvFILL(protopad);
2941 assert(!CvUNIQUE(proto));
2948 cv = compcv = (CV*)NEWSV(1104,0);
2949 sv_upgrade((SV *)cv, SvTYPE(proto));
2954 CvFILEGV(cv) = CvFILEGV(proto);
2955 CvGV(cv) = (GV*)SvREFCNT_inc(CvGV(proto));
2956 CvSTASH(cv) = CvSTASH(proto);
2957 CvROOT(cv) = CvROOT(proto);
2958 CvSTART(cv) = CvSTART(proto);
2960 CvOUTSIDE(cv) = (CV*)SvREFCNT_inc(outside);
2963 sv_setpvn((SV*)cv, SvPVX(proto), SvCUR(proto));
2967 comppadlist = newAV();
2968 AvREAL_off(comppadlist);
2969 av_store(comppadlist, 0, SvREFCNT_inc((SV*)protopad_name));
2970 av_store(comppadlist, 1, (SV*)comppad);
2971 CvPADLIST(cv) = comppadlist;
2972 av_fill(comppad, AvFILL(protopad));
2973 curpad = AvARRAY(comppad);
2975 av = newAV(); /* will be @_ */
2977 av_store(comppad, 0, (SV*)av);
2978 AvFLAGS(av) = AVf_REIFY;
2980 for (ix = fpad; ix > 0; ix--) {
2981 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
2982 if (namesv && namesv != &sv_undef) {
2983 char *name = SvPVX(namesv); /* XXX */
2984 if (SvFLAGS(namesv) & SVf_FAKE) { /* lexical from outside? */
2985 I32 off = pad_findlex(name, ix, SvIVX(namesv),
2986 CvOUTSIDE(cv), cxstack_ix);
2988 curpad[ix] = SvREFCNT_inc(ppad[ix]);
2990 croak("panic: cv_clone: %s", name);
2992 else { /* our own lexical */
2995 /* anon code -- we'll come back for it */
2996 sv = SvREFCNT_inc(ppad[ix]);
2998 else if (*name == '@')
3000 else if (*name == '%')
3010 SV* sv = NEWSV(0,0);
3016 /* Now that vars are all in place, clone nested closures. */
3018 for (ix = fpad; ix > 0; ix--) {
3019 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
3021 && namesv != &sv_undef
3022 && !(SvFLAGS(namesv) & SVf_FAKE)
3023 && *SvPVX(namesv) == '&'
3024 && CvCLONE(ppad[ix]))
3026 CV *kid = cv_clone2((CV*)ppad[ix], cv);
3027 SvREFCNT_dec(ppad[ix]);
3030 curpad[ix] = (SV*)kid;
3034 #ifdef DEBUG_CLOSURES
3035 PerlIO_printf(Perl_debug_log, "Cloned inside:\n");
3037 PerlIO_printf(Perl_debug_log, " from:\n");
3039 PerlIO_printf(Perl_debug_log, " to:\n");
3051 return cv_clone2(proto, CvOUTSIDE(proto));
3061 if(cv && SvPOK(cv) && !SvCUR(cv)) {
3062 for (o = CvSTART(cv); o; o = o->op_next) {
3063 OPCODE type = o->op_type;
3065 if (type == OP_NEXTSTATE || type == OP_NULL || type == OP_PUSHMARK)
3067 if (type == OP_LEAVESUB || type == OP_RETURN)
3069 if (type != OP_CONST || sv)
3072 sv = ((SVOP*)o)->op_sv;
3079 newSUB(floor,op,proto,block)
3085 char *name = op ? SvPVx(cSVOP->op_sv, na) : Nullch;
3086 GV *gv = gv_fetchpv(name ? name : "__ANON__", GV_ADDMULTI, SVt_PVCV);
3093 if (!name || GvCVGEN(gv))
3095 else if (cv = GvCV(gv)) {
3096 /* prototype mismatch? */
3097 char *p = proto ? SvPVx(((SVOP*)proto)->op_sv, na) : Nullch;
3098 if ((!proto != !SvPOK(cv)) || (p && strNE(p, SvPVX(cv)))) {
3099 warn("Prototype mismatch: (%s) vs (%s)",
3100 SvPOK(cv) ? SvPVX(cv) : "none", p ? p : "none");
3102 /* already defined (or promised)? */
3103 if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
3106 /* just a "sub foo;" when &foo is already defined */
3110 const_sv = cv_const_sv(cv);
3111 if (const_sv || dowarn) {
3112 line_t oldline = curcop->cop_line;
3113 curcop->cop_line = copline;
3114 warn(const_sv ? "Constant subroutine %s redefined"
3115 : "Subroutine %s redefined", name);
3116 curcop->cop_line = oldline;
3122 if (cv) { /* must reuse cv if autoloaded */
3124 CvFLAGS(cv) = CvFLAGS(compcv);
3125 CvOUTSIDE(cv) = CvOUTSIDE(compcv);
3126 CvOUTSIDE(compcv) = 0;
3127 CvPADLIST(cv) = CvPADLIST(compcv);
3128 CvPADLIST(compcv) = 0;
3129 if (SvREFCNT(compcv) > 1) /* XXX Make closures transit through stub. */
3130 CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc((SV*)cv);
3131 SvREFCNT_dec(compcv);
3141 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
3142 CvFILEGV(cv) = curcop->cop_filegv;
3143 CvSTASH(cv) = curstash;
3146 char *p = SvPVx(((SVOP*)proto)->op_sv, na);
3147 sv_setpv((SV*)cv, p);
3155 char *s = strrchr(name, ':');
3157 if (strEQ(s, "BEGIN"))
3158 croak("BEGIN not safe after errors--compilation aborted");
3167 av = newAV(); /* Will be @_ */
3169 av_store(comppad, 0, (SV*)av);
3170 AvFLAGS(av) = AVf_REIFY;
3172 for (ix = AvFILL(comppad); ix > 0; ix--) {
3173 if (!SvPADMY(curpad[ix]) && !SvIMMORTAL(curpad[ix]))
3174 SvPADTMP_on(curpad[ix]);
3177 if (AvFILL(comppad_name) < AvFILL(comppad))
3178 av_store(comppad_name, AvFILL(comppad), Nullsv);
3180 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
3181 CvSTART(cv) = LINKLIST(CvROOT(cv));
3182 CvROOT(cv)->op_next = 0;
3188 if (perldb && curstash != debstash) {
3190 SV *tmpstr = sv_newmortal();
3191 static GV *db_postponed;
3195 sprintf(buf, "%s:%ld",
3196 SvPVX(GvSV(curcop->cop_filegv)), (long)subline);
3197 sv = newSVpv(buf,0);
3199 sprintf(buf,"%ld",(long)curcop->cop_line);
3201 gv_efullname3(tmpstr, gv, Nullch);
3202 hv_store(GvHV(DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
3203 if (!db_postponed) {
3204 db_postponed = gv_fetchpv("DB::postponed", GV_ADDMULTI, SVt_PVHV);
3206 hv = GvHVn(db_postponed);
3207 if (HvFILL(hv) > 0 && hv_exists(hv, SvPVX(tmpstr), SvCUR(tmpstr))
3208 && (cv = GvCV(db_postponed))) {
3213 perl_call_sv((SV*)cv, G_DISCARD);
3217 if ((s = strrchr(name,':')))
3221 if (strEQ(s, "BEGIN")) {
3222 I32 oldscope = scopestack_ix;
3224 SAVESPTR(compiling.cop_filegv);
3225 SAVEI16(compiling.cop_line);
3232 DEBUG_x( dump_sub(gv) );
3233 av_push(beginav, (SV *)cv);
3235 call_list(oldscope, beginav);
3237 curcop = &compiling;
3240 else if (strEQ(s, "END") && !error_count) {
3243 av_unshift(endav, 1);
3244 av_store(endav, 0, (SV *)cv);
3257 newXSUB(name, ix, subaddr, filename)
3263 CV* cv = newXS(name, (void(*)())subaddr, filename);
3265 CvXSUBANY(cv).any_i32 = ix;
3271 newXS(name, subaddr, filename)
3273 void (*subaddr) _((CV*));
3276 GV *gv = gv_fetchpv(name ? name : "__ANON__", GV_ADDMULTI, SVt_PVCV);
3279 if (cv = (name ? GvCV(gv) : Nullcv)) {
3281 /* just a cached method */
3285 else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
3286 /* already defined (or promised) */
3288 line_t oldline = curcop->cop_line;
3289 curcop->cop_line = copline;
3290 warn("Subroutine %s redefined",name);
3291 curcop->cop_line = oldline;
3298 if (cv) /* must reuse cv if autoloaded */
3301 cv = (CV*)NEWSV(1105,0);
3302 sv_upgrade((SV *)cv, SVt_PVCV);
3309 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
3310 CvFILEGV(cv) = gv_fetchfile(filename);
3311 CvXSUB(cv) = subaddr;
3314 char *s = strrchr(name,':');
3319 if (strEQ(s, "BEGIN")) {
3322 av_push(beginav, (SV *)cv);
3325 else if (strEQ(s, "END")) {
3328 av_unshift(endav, 1);
3329 av_store(endav, 0, (SV *)cv);
3340 newFORM(floor,op,block)
3351 name = SvPVx(cSVOP->op_sv, na);
3354 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
3356 if (cv = GvFORM(gv)) {
3358 line_t oldline = curcop->cop_line;
3360 curcop->cop_line = copline;
3361 warn("Format %s redefined",name);
3362 curcop->cop_line = oldline;
3368 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
3369 CvFILEGV(cv) = curcop->cop_filegv;
3371 for (ix = AvFILL(comppad); ix > 0; ix--) {
3372 if (!SvPADMY(curpad[ix]) && !SvIMMORTAL(curpad[ix]))
3373 SvPADTMP_on(curpad[ix]);
3376 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
3377 CvSTART(cv) = LINKLIST(CvROOT(cv));
3378 CvROOT(cv)->op_next = 0;
3389 return newUNOP(OP_REFGEN, 0,
3390 mod(list(convert(OP_ANONLIST, 0, op)), OP_REFGEN));
3397 return newUNOP(OP_REFGEN, 0,
3398 mod(list(convert(OP_ANONHASH, 0, op)), OP_REFGEN));
3402 newANONSUB(floor, proto, block)
3407 return newUNOP(OP_REFGEN, 0,
3408 newSVOP(OP_ANONCODE, 0, (SV*)newSUB(floor, 0, proto, block)));
3415 switch (o->op_type) {
3417 o->op_type = OP_PADAV;
3418 o->op_ppaddr = ppaddr[OP_PADAV];
3419 return ref(newUNOP(OP_RV2AV, 0, scalar(o)), OP_RV2AV);
3422 o->op_type = OP_RV2AV;
3423 o->op_ppaddr = ppaddr[OP_RV2AV];
3428 warn("oops: oopsAV");
3438 switch (o->op_type) {
3441 o->op_type = OP_PADHV;
3442 o->op_ppaddr = ppaddr[OP_PADHV];
3443 return ref(newUNOP(OP_RV2HV, 0, scalar(o)), OP_RV2HV);
3447 o->op_type = OP_RV2HV;
3448 o->op_ppaddr = ppaddr[OP_RV2HV];
3453 warn("oops: oopsHV");
3463 if (o->op_type == OP_PADANY) {
3464 o->op_type = OP_PADAV;
3465 o->op_ppaddr = ppaddr[OP_PADAV];
3468 return newUNOP(OP_RV2AV, 0, scalar(o));
3476 if (type == OP_MAPSTART)
3477 return newUNOP(OP_NULL, 0, o);
3478 return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
3485 if (o->op_type == OP_PADANY) {
3486 o->op_type = OP_PADHV;
3487 o->op_ppaddr = ppaddr[OP_PADHV];
3490 return newUNOP(OP_RV2HV, 0, scalar(o));
3497 croak("NOT IMPL LINE %d",__LINE__);
3507 return newUNOP(OP_RV2CV, flags, scalar(o));
3514 if (o->op_type == OP_PADANY) {
3515 o->op_type = OP_PADSV;
3516 o->op_ppaddr = ppaddr[OP_PADSV];
3519 return newUNOP(OP_RV2SV, 0, scalar(o));
3522 /* Check routines. */
3531 name = NEWSV(1106,0);
3532 sv_upgrade(name, SVt_PVNV);
3533 sv_setpvn(name, "&", 1);
3536 ix = pad_alloc(op->op_type, SVs_PADMY);
3537 av_store(comppad_name, ix, name);
3538 av_store(comppad, ix, cSVOP->op_sv);
3539 SvPADMY_on(cSVOP->op_sv);
3540 cSVOP->op_sv = Nullsv;
3541 cSVOP->op_targ = ix;
3549 op->op_private = hints;
3557 if (cUNOP->op_first->op_type == OP_CONCAT)
3558 op->op_flags |= OPf_STACKED;
3566 if (op->op_flags & OPf_KIDS) {
3569 OPCODE type = op->op_type;
3570 op = modkids(ck_fun(op), type);
3571 kid = cUNOP->op_first;
3572 newop = kUNOP->op_first->op_sibling;
3574 (newop->op_sibling ||
3575 !(opargs[newop->op_type] & OA_RETSCALAR) ||
3576 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
3577 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
3581 op_free(kUNOP->op_first);
3582 kUNOP->op_first = newop;
3584 op->op_ppaddr = ppaddr[++op->op_type];
3594 if (op->op_flags & OPf_KIDS) {
3595 OP *kid = cUNOP->op_first;
3596 if (kid->op_type == OP_HSLICE)
3597 op->op_private |= OPpSLICE;
3598 else if (kid->op_type != OP_HELEM)
3599 croak("%s argument is not a HASH element or slice",
3600 op_desc[op->op_type]);
3610 I32 type = op->op_type;
3612 if (op->op_flags & OPf_KIDS) {
3613 if (cLISTOP->op_first->op_type == OP_STUB) {
3615 op = newUNOP(type, OPf_SPECIAL,
3616 newGVOP(OP_GV, 0, gv_fetchpv("main'ARGV", TRUE, SVt_PVAV)));
3627 hints |= HINT_BLOCK_SCOPE;
3628 if (op->op_flags & OPf_KIDS) {
3629 SVOP *kid = (SVOP*)cUNOP->op_first;
3632 op->op_flags &= ~OPf_KIDS;
3635 else if (kid->op_type == OP_LINESEQ) {
3638 kid->op_next = op->op_next;
3639 cUNOP->op_first = 0;
3642 Newz(1101, enter, 1, LOGOP);
3643 enter->op_type = OP_ENTERTRY;
3644 enter->op_ppaddr = ppaddr[OP_ENTERTRY];
3645 enter->op_private = 0;
3647 /* establish postfix order */
3648 enter->op_next = (OP*)enter;
3650 op = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
3651 op->op_type = OP_LEAVETRY;
3652 op->op_ppaddr = ppaddr[OP_LEAVETRY];
3653 enter->op_other = op;
3659 op = newUNOP(OP_ENTEREVAL, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3661 op->op_targ = (PADOFFSET)hints;
3670 if (op->op_flags & OPf_STACKED) {
3672 kid = cUNOP->op_first->op_sibling;
3673 if (kid->op_type == OP_RV2GV)
3686 if (op->op_flags & OPf_KIDS) {
3687 OP *kid = cUNOP->op_first;
3688 if (kid->op_type != OP_HELEM)
3689 croak("%s argument is not a HASH element", op_desc[op->op_type]);
3699 o = fold_constants(o);
3700 if (o->op_type == OP_CONST)
3709 SVOP *kid = (SVOP*)cUNOP->op_first;
3711 op->op_private |= (hints & HINT_STRICT_REFS);
3712 if (kid->op_type == OP_CONST) {
3717 name = SvPV(kid->op_sv, na);
3718 if ((hints & HINT_STRICT_REFS) && (kid->op_private & OPpCONST_BARE)) {
3719 char *badthing = Nullch;
3720 switch (op->op_type) {
3722 badthing = "a SCALAR";
3725 badthing = "an ARRAY";
3728 badthing = "a HASH";
3733 "Can't use bareword (\"%s\") as %s ref while \"strict refs\" in use",
3736 kid->op_type = OP_GV;
3737 iscv = (op->op_type == OP_RV2CV) * 2;
3738 for (gv = 0; !gv; iscv++) {
3740 * This is a little tricky. We only want to add the symbol if we
3741 * didn't add it in the lexer. Otherwise we get duplicate strict
3742 * warnings. But if we didn't add it in the lexer, we must at
3743 * least pretend like we wanted to add it even if it existed before,
3744 * or we get possible typo warnings. OPpCONST_ENTERED says
3745 * whether the lexer already added THIS instance of this symbol.
3747 gv = gv_fetchpv(name,
3748 iscv | !(kid->op_private & OPpCONST_ENTERED),
3751 : op->op_type == OP_RV2SV
3753 : op->op_type == OP_RV2AV
3755 : op->op_type == OP_RV2HV
3759 SvREFCNT_dec(kid->op_sv);
3760 kid->op_sv = SvREFCNT_inc(gv);
3769 I32 type = op->op_type;
3771 if (op->op_flags & OPf_REF)
3774 if (op->op_flags & OPf_KIDS) {
3775 SVOP *kid = (SVOP*)cUNOP->op_first;
3777 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
3778 OP *newop = newGVOP(type, OPf_REF,
3779 gv_fetchpv(SvPVx(kid->op_sv, na), TRUE, SVt_PVIO));
3786 if (type == OP_FTTTY)
3787 return newGVOP(type, OPf_REF, gv_fetchpv("main'STDIN", TRUE,
3790 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3803 int type = op->op_type;
3804 register I32 oa = opargs[type] >> OASHIFT;
3806 if (op->op_flags & OPf_STACKED) {
3807 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
3810 return no_fh_allowed(op);
3813 if (op->op_flags & OPf_KIDS) {
3814 tokid = &cLISTOP->op_first;
3815 kid = cLISTOP->op_first;
3816 if (kid->op_type == OP_PUSHMARK ||
3817 kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK)
3819 tokid = &kid->op_sibling;
3820 kid = kid->op_sibling;
3822 if (!kid && opargs[type] & OA_DEFGV)
3823 *tokid = kid = newSVREF(newGVOP(OP_GV, 0, defgv));
3827 sibl = kid->op_sibling;
3841 if (kid->op_type == OP_CONST &&
3842 (kid->op_private & OPpCONST_BARE)) {
3843 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
3844 OP *newop = newAVREF(newGVOP(OP_GV, 0,
3845 gv_fetchpv(name, TRUE, SVt_PVAV) ));
3847 warn("Array @%s missing the @ in argument %ld of %s()",
3848 name, (long)numargs, op_desc[type]);
3851 kid->op_sibling = sibl;
3854 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
3855 bad_type(numargs, "array", op_desc[op->op_type], kid);
3859 if (kid->op_type == OP_CONST &&
3860 (kid->op_private & OPpCONST_BARE)) {
3861 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
3862 OP *newop = newHVREF(newGVOP(OP_GV, 0,
3863 gv_fetchpv(name, TRUE, SVt_PVHV) ));
3865 warn("Hash %%%s missing the %% in argument %ld of %s()",
3866 name, (long)numargs, op_desc[type]);
3869 kid->op_sibling = sibl;
3872 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
3873 bad_type(numargs, "hash", op_desc[op->op_type], kid);
3878 OP *newop = newUNOP(OP_NULL, 0, kid);
3879 kid->op_sibling = 0;
3881 newop->op_next = newop;
3883 kid->op_sibling = sibl;
3888 if (kid->op_type != OP_GV) {
3889 if (kid->op_type == OP_CONST &&
3890 (kid->op_private & OPpCONST_BARE)) {
3891 OP *newop = newGVOP(OP_GV, 0,
3892 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, na), TRUE,
3898 kid->op_sibling = 0;
3899 kid = newUNOP(OP_RV2GV, 0, scalar(kid));
3901 kid->op_sibling = sibl;
3907 mod(scalar(kid), type);
3911 tokid = &kid->op_sibling;
3912 kid = kid->op_sibling;
3914 op->op_private |= numargs;
3916 return too_many_arguments(op,op_desc[op->op_type]);
3919 else if (opargs[type] & OA_DEFGV) {
3921 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3925 while (oa & OA_OPTIONAL)
3927 if (oa && oa != OA_LIST)
3928 return too_few_arguments(op,op_desc[op->op_type]);
3937 GV *gv = gv_fetchpv("glob", FALSE, SVt_PVCV);
3939 if (gv && GvIMPORTED_CV(gv)) {
3940 op->op_type = OP_LIST;
3941 op->op_ppaddr = ppaddr[OP_LIST];
3942 op = newUNOP(OP_ENTERSUB, OPf_STACKED,
3943 append_elem(OP_LIST, op,
3944 scalar(newUNOP(OP_RV2CV, 0,
3945 newGVOP(OP_GV, 0, gv)))));
3948 if ((op->op_flags & OPf_KIDS) && !cLISTOP->op_first->op_sibling)
3949 append_elem(OP_GLOB, op, newSVREF(newGVOP(OP_GV, 0, defgv)));
3950 gv = newGVgen("main");
3952 append_elem(OP_GLOB, op, newGVOP(OP_GV, 0, gv));
3963 OPCODE type = op->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
3965 op->op_ppaddr = ppaddr[OP_GREPSTART];
3966 Newz(1101, gwop, 1, LOGOP);
3968 if (op->op_flags & OPf_STACKED) {
3971 kid = cLISTOP->op_first->op_sibling;
3972 for (k = cLISTOP->op_first->op_sibling->op_next; k; k = k->op_next) {
3975 kid->op_next = (OP*)gwop;
3976 op->op_flags &= ~OPf_STACKED;
3978 kid = cLISTOP->op_first->op_sibling;
3979 if (type == OP_MAPWHILE)
3986 kid = cLISTOP->op_first->op_sibling;
3987 if (kid->op_type != OP_NULL)
3988 croak("panic: ck_grep");
3989 kid = kUNOP->op_first;
3991 gwop->op_type = type;
3992 gwop->op_ppaddr = ppaddr[type];
3993 gwop->op_first = listkids(op);
3994 gwop->op_flags |= OPf_KIDS;
3995 gwop->op_private = 1;
3996 gwop->op_other = LINKLIST(kid);
3997 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
3998 kid->op_next = (OP*)gwop;
4000 kid = cLISTOP->op_first->op_sibling;
4001 if (!kid || !kid->op_sibling)
4002 return too_few_arguments(op,op_desc[op->op_type]);
4003 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
4004 mod(kid, OP_GREPSTART);
4013 if (op->op_flags & OPf_KIDS) {
4014 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
4015 if (kid && kid->op_type == OP_CONST)
4016 fbm_compile(((SVOP*)kid)->op_sv);
4025 /* XXX length optimization goes here */
4033 OPCODE type = op->op_type;
4034 return modkids(ck_fun(op), type);
4041 OPCODE type = op->op_type;
4042 return refkids(ck_fun(op), type);
4051 kid = cLISTOP->op_first;
4053 op = force_list(op);
4054 kid = cLISTOP->op_first;
4056 if (kid->op_type == OP_PUSHMARK)
4057 kid = kid->op_sibling;
4058 if (kid && op->op_flags & OPf_STACKED)
4059 kid = kid->op_sibling;
4060 else if (kid && !kid->op_sibling) { /* print HANDLE; */
4061 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
4062 op->op_flags |= OPf_STACKED; /* make it a filehandle */
4063 kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
4064 cLISTOP->op_first->op_sibling = kid;
4065 cLISTOP->op_last = kid;
4066 kid = kid->op_sibling;
4071 append_elem(op->op_type, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
4077 if (hints & HINT_LOCALE)
4078 op->op_private |= OPpLOCALE;
4092 if (hints & HINT_LOCALE)
4093 op->op_private |= OPpLOCALE;
4105 if (hints & HINT_LOCALE)
4106 op->op_private |= OPpLOCALE;
4116 cPMOP->op_pmflags |= PMf_RUNTIME;
4117 cPMOP->op_pmpermflags |= PMf_RUNTIME;
4132 if (cBINOP->op_first->op_flags & OPf_PARENS) {
4133 op->op_private |= OPpREPEAT_DOLIST;
4134 cBINOP->op_first = force_list(cBINOP->op_first);
4145 if (op->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
4146 SVOP *kid = (SVOP*)cUNOP->op_first;
4148 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
4150 for (s = SvPVX(kid->op_sv); *s; s++) {
4151 if (*s == ':' && s[1] == ':') {
4153 Move(s+2, s+1, strlen(s+2)+1, char);
4154 --SvCUR(kid->op_sv);
4157 sv_catpvn(kid->op_sv, ".pm", 3);
4167 croak("NOT IMPL LINE %d",__LINE__);
4177 if (op->op_flags & OPf_KIDS) {
4178 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
4179 if (kid && kid->op_sibling) {
4180 op->op_type = OP_SSELECT;
4181 op->op_ppaddr = ppaddr[OP_SSELECT];
4183 return fold_constants(op);
4187 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
4188 if (kid && kid->op_type == OP_RV2GV)
4189 kid->op_private &= ~HINT_STRICT_REFS;
4197 I32 type = op->op_type;
4199 if (!(op->op_flags & OPf_KIDS)) {
4201 return newUNOP(type, 0,
4202 scalar(newUNOP(OP_RV2AV, 0,
4203 scalar(newGVOP(OP_GV, 0, subline
4205 : gv_fetchpv("ARGV", TRUE, SVt_PVAV) )))));
4207 return scalar(modkids(ck_fun(op), type));
4216 if (hints & HINT_LOCALE)
4217 op->op_private |= OPpLOCALE;
4220 if (op->op_flags & OPf_STACKED) {
4221 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
4223 kid = kUNOP->op_first; /* get past rv2gv */
4225 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
4227 if (kid->op_type == OP_SCOPE) {
4231 else if (kid->op_type == OP_LEAVE) {
4232 if (op->op_type == OP_SORT) {
4233 null(kid); /* wipe out leave */
4236 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
4237 if (k->op_next == kid)
4242 kid->op_next = 0; /* just disconnect the leave */
4243 k = kLISTOP->op_first;
4247 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
4248 null(kid); /* wipe out rv2gv */
4249 if (op->op_type == OP_SORT)
4253 op->op_flags |= OPf_SPECIAL;
4267 if (op->op_flags & OPf_STACKED)
4268 return no_fh_allowed(op);
4270 kid = cLISTOP->op_first;
4271 if (kid->op_type != OP_NULL)
4272 croak("panic: ck_split");
4273 kid = kid->op_sibling;
4274 op_free(cLISTOP->op_first);
4275 cLISTOP->op_first = kid;
4277 cLISTOP->op_first = kid = newSVOP(OP_CONST, 0, newSVpv(" ", 1));
4278 cLISTOP->op_last = kid; /* There was only one element previously */
4281 if (kid->op_type != OP_MATCH) {
4282 OP *sibl = kid->op_sibling;
4283 kid->op_sibling = 0;
4284 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
4285 if (cLISTOP->op_first == cLISTOP->op_last)
4286 cLISTOP->op_last = kid;
4287 cLISTOP->op_first = kid;
4288 kid->op_sibling = sibl;
4291 if (pm->op_pmshort && !(pm->op_pmflags & PMf_ALL)) {
4292 SvREFCNT_dec(pm->op_pmshort); /* can't use substring to optimize */
4296 kid->op_type = OP_PUSHRE;
4297 kid->op_ppaddr = ppaddr[OP_PUSHRE];
4300 if (!kid->op_sibling)
4301 append_elem(OP_SPLIT, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
4303 kid = kid->op_sibling;
4306 if (!kid->op_sibling)
4307 append_elem(OP_SPLIT, op, newSVOP(OP_CONST, 0, newSViv(0)));
4309 kid = kid->op_sibling;
4312 if (kid->op_sibling)
4313 return too_many_arguments(op,op_desc[op->op_type]);
4322 OP *prev = ((cUNOP->op_first->op_sibling)
4323 ? cUNOP : ((UNOP*)cUNOP->op_first))->op_first;
4324 OP *o = prev->op_sibling;
4331 for (cvop = o; cvop->op_sibling; cvop = cvop->op_sibling) ;
4332 if (cvop->op_type == OP_RV2CV) {
4334 op->op_private |= (cvop->op_private & OPpENTERSUB_AMPER);
4335 null(cvop); /* disable rv2cv */
4336 tmpop = (SVOP*)((UNOP*)cvop)->op_first;
4337 if (tmpop->op_type == OP_GV) {
4338 cv = GvCVu(tmpop->op_sv);
4339 if (cv && SvPOK(cv) && !(op->op_private & OPpENTERSUB_AMPER))
4340 proto = SvPV((SV*)cv,na);
4343 op->op_private |= (hints & HINT_STRICT_REFS);
4344 if (perldb && curstash != debstash)
4345 op->op_private |= OPpENTERSUB_DB;
4350 return too_many_arguments(op, CvNAME(cv));
4368 if (o->op_type != OP_REFGEN && o->op_type != OP_UNDEF)
4369 bad_type(arg, "block", CvNAME(cv), o);
4374 if (o->op_type == OP_RV2GV)
4378 o = newUNOP(OP_RV2GV, 0, kid);
4379 o->op_sibling = kid->op_sibling;
4380 kid->op_sibling = 0;
4381 prev->op_sibling = o;
4389 if (o->op_type != OP_RV2GV)
4390 bad_type(arg, "symbol", CvNAME(cv), o);
4393 if (o->op_type != OP_RV2CV)
4394 bad_type(arg, "sub", CvNAME(cv), o);
4397 if (o->op_type != OP_RV2SV && o->op_type != OP_PADSV)
4398 bad_type(arg, "scalar", CvNAME(cv), o);
4401 if (o->op_type != OP_RV2AV && o->op_type != OP_PADAV)
4402 bad_type(arg, "array", CvNAME(cv), o);
4405 if (o->op_type != OP_RV2HV && o->op_type != OP_PADHV)
4406 bad_type(arg, "hash", CvNAME(cv), o);
4410 o = newUNOP(OP_REFGEN, 0, kid);
4411 o->op_sibling = kid->op_sibling;
4412 kid->op_sibling = 0;
4413 prev->op_sibling = o;
4424 croak("Malformed prototype for %s: %s",
4425 CvNAME(cv),SvPV((SV*)cv,na));
4430 mod(o, OP_ENTERSUB);
4434 if (proto && !optional && *proto == '$')
4435 return too_few_arguments(op, CvNAME(cv));
4443 SvREADONLY_on(cSVOP->op_sv);
4451 if (op->op_flags & OPf_KIDS) {
4452 SVOP *kid = (SVOP*)cUNOP->op_first;
4454 if (kid->op_type == OP_NULL)
4455 kid = (SVOP*)kid->op_sibling;
4457 kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE))
4458 op->op_flags |= OPf_SPECIAL;
4463 /* A peephole optimizer. We visit the ops in the order they're to execute. */
4469 register OP* oldop = 0;
4470 if (!o || o->op_seq)
4475 for (; o; o = o->op_next) {
4481 switch (o->op_type) {
4484 curcop = ((COP*)o); /* for warnings */
4485 o->op_seq = op_seqmax++;
4496 if (o->op_next->op_type == OP_STRINGIFY)
4498 o->op_seq = op_seqmax++;
4501 if ((o->op_flags & (OPf_KNOW|OPf_LIST)) != (OPf_KNOW|OPf_LIST)) {
4502 o->op_seq = op_seqmax++;
4503 break; /* Scalar stub must produce undef. List stub is noop */
4507 if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE)
4508 curcop = ((COP*)op);
4514 if (oldop && o->op_next) {
4515 oldop->op_next = o->op_next;
4518 o->op_seq = op_seqmax++;
4522 if (o->op_next->op_type == OP_RV2SV) {
4523 if (!(o->op_next->op_private & OPpDEREF)) {
4525 o->op_private |= o->op_next->op_private & OPpLVAL_INTRO;
4526 o->op_next = o->op_next->op_next;
4527 o->op_type = OP_GVSV;
4528 o->op_ppaddr = ppaddr[OP_GVSV];
4531 else if (o->op_next->op_type == OP_RV2AV) {
4532 OP* pop = o->op_next->op_next;
4534 if (pop->op_type == OP_CONST &&
4535 (op = pop->op_next) &&
4536 pop->op_next->op_type == OP_AELEM &&
4537 !(pop->op_next->op_private &
4538 (OPpLVAL_INTRO|OPpLVAL_DEFER|OPpDEREF)) &&
4539 (i = SvIV(((SVOP*)pop)->op_sv) - compiling.cop_arybase)
4543 SvREFCNT_dec(((SVOP*)pop)->op_sv);
4547 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
4548 o->op_next = pop->op_next->op_next;
4549 o->op_type = OP_AELEMFAST;
4550 o->op_ppaddr = ppaddr[OP_AELEMFAST];
4551 o->op_private = (U8)i;
4552 GvAVn(((GVOP*)o)->op_gv);
4555 o->op_seq = op_seqmax++;
4562 o->op_seq = op_seqmax++;
4563 peep(cLOGOP->op_other);
4567 o->op_seq = op_seqmax++;
4568 peep(cCONDOP->op_true);
4569 peep(cCONDOP->op_false);
4573 o->op_seq = op_seqmax++;
4574 peep(cLOOP->op_redoop);
4575 peep(cLOOP->op_nextop);
4576 peep(cLOOP->op_lastop);
4581 o->op_seq = op_seqmax++;
4582 peep(cPMOP->op_pmreplstart);
4586 o->op_seq = op_seqmax++;
4587 if (dowarn && o->op_next && o->op_next->op_type == OP_NEXTSTATE) {
4588 if (o->op_next->op_sibling &&
4589 o->op_next->op_sibling->op_type != OP_DIE) {
4590 line_t oldline = curcop->cop_line;
4592 curcop->cop_line = ((COP*)o->op_next)->cop_line;
4593 warn("Statement unlikely to be reached");
4594 warn("(Maybe you meant system() when you said exec()?)\n");
4595 curcop->cop_line = oldline;
4600 o->op_seq = op_seqmax++;