3 * Copyright (c) 1991-1994, 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 static I32 list_assignment _((OP *op));
22 static OP *bad_type _((I32 n, char *t, OP *op, OP *kid));
23 static OP *modkids _((OP *op, I32 type));
24 static OP *no_fh_allowed _((OP *op));
25 static OP *scalarboolean _((OP *op));
26 static OP *too_few_arguments _((OP *op));
27 static OP *too_many_arguments _((OP *op));
28 static void null _((OP* op));
34 sprintf(tokenbuf,"Missing comma after first argument to %s function",
35 op_name[op->op_type]);
44 sprintf(tokenbuf,"Not enough arguments for %s", op_name[op->op_type]);
50 too_many_arguments(op)
53 sprintf(tokenbuf,"Too many arguments for %s", op_name[op->op_type]);
59 bad_type(n, t, op, kid)
65 sprintf(tokenbuf, "Type of arg %d to %s must be %s (not %s)",
66 (int) n, op_name[op->op_type], t, op_name[kid->op_type]);
75 int type = op->op_type;
76 if (type != OP_AELEM && type != OP_HELEM) {
77 sprintf(tokenbuf, "Can't use %s as left arg of implicit ->",
80 if (type == OP_RV2HV || type == OP_ENTERSUB)
81 warn("(Did you mean $ instead of %c?)\n",
82 type == OP_RV2HV ? '%' : '&');
86 /* "register" allocation */
95 if (!(isALPHA(name[1]) || name[1] == '_' && (int)strlen(name) > 2)) {
96 if (!isprint(name[1]))
97 sprintf(name+1, "^%c", name[1] ^ 64); /* XXX is tokenbuf, really */
98 croak("Can't use global %s in \"my\"",name);
100 off = pad_alloc(OP_PADSV, SVs_PADMY);
102 sv_upgrade(sv, SVt_PVNV);
104 av_store(comppad_name, off, sv);
105 SvNVX(sv) = (double)cop_seqmax;
106 SvIVX(sv) = 0; /* Not yet introduced--see newSTATEOP */
107 if (!min_intro_pending)
108 min_intro_pending = off;
109 max_intro_pending = off;
111 av_store(comppad, off, (SV*)newAV());
112 else if (*name == '%')
113 av_store(comppad, off, (SV*)newHV());
114 SvPADMY_on(curpad[off]);
124 SV **svp = AvARRAY(comppad_name);
126 register CONTEXT *cx;
131 I32 seq = cop_seqmax;
133 /* The one we're looking for is probably just before comppad_name_fill. */
134 for (off = comppad_name_fill; off > 0; off--) {
135 if ((sv = svp[off]) &&
138 seq > (I32)SvNVX(sv) &&
139 strEQ(SvPVX(sv), name))
141 return (PADOFFSET)off;
145 /* Nothing in current lexical context--try eval's context, if any.
146 * This is necessary to let the perldb get at lexically scoped variables.
147 * XXX This will also probably interact badly with eval tree caching.
151 for (i = cxstack_ix; i >= 0; i--) {
153 switch (cx->cx_type) {
163 if (debstash && CvSTASH(cv) == debstash) /* ignore DB'* scope */
165 seq = cxstack[saweval].blk_oldcop->cop_seq;
166 curlist = CvPADLIST(cv);
167 curname = (AV*)*av_fetch(curlist, 0, FALSE);
168 svp = AvARRAY(curname);
169 for (off = AvFILL(curname); off > 0; off--) {
170 if ((sv = svp[off]) &&
173 seq > (I32)SvNVX(sv) &&
174 strEQ(SvPVX(sv), name))
176 PADOFFSET newoff = pad_alloc(OP_PADSV, SVs_PADMY);
177 AV *oldpad = (AV*)*av_fetch(curlist, CvDEPTH(cv), FALSE);
178 SV *oldsv = *av_fetch(oldpad, off, TRUE);
179 SV *sv = NEWSV(1103,0);
180 sv_upgrade(sv, SVt_PVNV);
182 av_store(comppad_name, newoff, sv);
183 SvNVX(sv) = (double)curcop->cop_seq;
184 SvIVX(sv) = 999999999; /* A ref, intro immediately */
185 av_store(comppad, newoff, SvREFCNT_inc(oldsv));
196 /* It's stupid to dup this code. main should be stored in a CV. */
197 seq = cxstack[saweval].blk_oldcop->cop_seq;
198 svp = AvARRAY(padname);
199 for (off = AvFILL(padname); off > 0; off--) {
200 if ((sv = svp[off]) &&
203 seq > (I32)SvNVX(sv) &&
204 strEQ(SvPVX(sv), name))
206 PADOFFSET newoff = pad_alloc(OP_PADSV, SVs_PADMY);
207 SV *oldsv = *av_fetch(pad, off, TRUE);
208 SV *sv = NEWSV(1103,0);
209 sv_upgrade(sv, SVt_PVNV);
211 av_store(comppad_name, newoff, sv);
212 SvNVX(sv) = (double)curcop->cop_seq;
213 SvIVX(sv) = 999999999; /* A ref, intro immediately */
214 av_store(comppad, newoff, SvREFCNT_inc(oldsv));
226 SV **svp = AvARRAY(comppad_name);
228 if (min_intro_pending && fill < min_intro_pending) {
229 for (off = max_intro_pending; off >= min_intro_pending; off--) {
230 if ((sv = svp[off]) && sv != &sv_undef)
231 warn("%s never introduced", SvPVX(sv));
234 /* "Deintroduce" my variables that are leaving with this scope. */
235 for (off = AvFILL(comppad_name); off > fill; off--) {
236 if ((sv = svp[off]) && sv != &sv_undef)
237 SvIVX(sv) = cop_seqmax;
242 pad_alloc(optype,tmptype)
249 if (AvARRAY(comppad) != curpad)
250 croak("panic: pad_alloc");
251 if (pad_reset_pending)
253 if (tmptype & SVs_PADMY) {
255 sv = *av_fetch(comppad, AvFILL(comppad) + 1, TRUE);
256 } while (SvPADBUSY(sv)); /* need a fresh one */
257 retval = AvFILL(comppad);
261 sv = *av_fetch(comppad, ++padix, TRUE);
262 } while (SvFLAGS(sv) & (SVs_PADTMP|SVs_PADMY));
265 SvFLAGS(sv) |= tmptype;
266 curpad = AvARRAY(comppad);
267 DEBUG_X(fprintf(stderr, "Pad alloc %ld for %s\n", (long) retval, op_name[optype]));
268 return (PADOFFSET)retval;
272 #ifndef CAN_PROTOTYPE
277 #endif /* CAN_PROTOTYPE */
280 croak("panic: pad_sv po");
281 DEBUG_X(fprintf(stderr, "Pad sv %d\n", po));
282 return curpad[po]; /* eventually we'll turn this into a macro */
286 #ifndef CAN_PROTOTYPE
290 pad_free(PADOFFSET po)
291 #endif /* CAN_PROTOTYPE */
295 if (AvARRAY(comppad) != curpad)
296 croak("panic: pad_free curpad");
298 croak("panic: pad_free po");
299 DEBUG_X(fprintf(stderr, "Pad free %d\n", po));
300 if (curpad[po] && curpad[po] != &sv_undef)
301 SvPADTMP_off(curpad[po]);
307 #ifndef CAN_PROTOTYPE
311 pad_swipe(PADOFFSET po)
312 #endif /* CAN_PROTOTYPE */
314 if (AvARRAY(comppad) != curpad)
315 croak("panic: pad_swipe curpad");
317 croak("panic: pad_swipe po");
318 DEBUG_X(fprintf(stderr, "Pad swipe %d\n", po));
319 SvPADTMP_off(curpad[po]);
320 curpad[po] = NEWSV(1107,0);
321 SvPADTMP_on(curpad[po]);
331 if (AvARRAY(comppad) != curpad)
332 croak("panic: pad_reset curpad");
333 DEBUG_X(fprintf(stderr, "Pad reset\n"));
334 for (po = AvMAX(comppad); po > padix_floor; po--) {
335 if (curpad[po] && curpad[po] != &sv_undef)
336 SvPADTMP_off(curpad[po]);
339 pad_reset_pending = FALSE;
348 register OP *kid, *nextkid;
353 if (op->op_flags & OPf_KIDS) {
354 for (kid = cUNOP->op_first; kid; kid = nextkid) {
355 nextkid = kid->op_sibling; /* Get before next freeing kid */
361 switch (op->op_type) {
363 op->op_targ = 0; /* Was holding old type, if any. */
366 op->op_targ = 0; /* Was holding hints. */
370 SvREFCNT_dec(cGVOP->op_gv);
374 SvREFCNT_dec(cCOP->cop_filegv);
377 SvREFCNT_dec(cSVOP->op_sv);
380 Safefree(cPVOP->op_pv);
383 op_free(cPMOP->op_pmreplroot);
386 regfree(cPMOP->op_pmregexp);
393 pad_free(op->op_targ);
402 if (op->op_type != OP_NULL && op->op_targ > 0)
403 pad_free(op->op_targ);
404 op->op_targ = op->op_type;
405 op->op_type = OP_NULL;
406 op->op_ppaddr = ppaddr[OP_NULL];
409 /* Contextualizers */
411 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
422 /* establish postfix order */
423 if (cUNOP->op_first) {
424 op->op_next = LINKLIST(cUNOP->op_first);
425 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
427 kid->op_next = LINKLIST(kid->op_sibling);
443 if (op && op->op_flags & OPf_KIDS) {
444 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
455 op->op_type == OP_SASSIGN && cBINOP->op_first->op_type == OP_CONST) {
456 line_t oldline = curcop->cop_line;
458 if (copline != NOLINE)
459 curcop->cop_line = copline;
460 warn("Found = in conditional, should be ==");
461 curcop->cop_line = oldline;
472 /* assumes no premature commitment */
473 if (!op || (op->op_flags & OPf_KNOW) || error_count)
476 op->op_flags &= ~OPf_LIST;
477 op->op_flags |= OPf_KNOW;
479 switch (op->op_type) {
481 scalar(cBINOP->op_first);
486 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
490 if ((kid = ((LISTOP*)op)->op_first) && kid->op_type == OP_PUSHRE) {
491 if (!kPMOP->op_pmreplroot)
492 deprecate("implicit split to @_");
499 if (op->op_flags & OPf_KIDS) {
500 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling)
509 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
529 if (!op || error_count)
531 if (op->op_flags & OPf_LIST)
534 op->op_flags |= OPf_KNOW;
536 switch (op->op_type) {
538 if (!(opargs[op->op_type] & OA_FOLDCONST))
540 if (op->op_flags & OPf_STACKED)
614 if (!(op->op_private & OPpLVAL_INTRO))
615 useless = op_name[op->op_type];
622 if (!(op->op_private & OPpLVAL_INTRO) &&
623 (!op->op_sibling || op->op_sibling->op_type != OP_READLINE))
624 useless = "a variable";
629 curcop = ((COP*)op); /* for warning above */
635 useless = "a constant";
636 if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
638 else if (SvPOK(sv)) {
639 if (strnEQ(SvPVX(sv), "di", 2) ||
640 strnEQ(SvPVX(sv), "ds", 2) ||
641 strnEQ(SvPVX(sv), "ig", 2))
645 null(op); /* don't execute a constant */
646 SvREFCNT_dec(sv); /* don't even remember it */
650 op->op_type = OP_PREINC; /* pre-increment is faster */
651 op->op_ppaddr = ppaddr[OP_PREINC];
655 op->op_type = OP_PREDEC; /* pre-decrement is faster */
656 op->op_ppaddr = ppaddr[OP_PREDEC];
660 scalarvoid(cBINOP->op_first);
661 useless = op_name[op->op_type];
667 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
671 if (op->op_flags & OPf_STACKED)
676 if (!(op->op_flags & OPf_KIDS))
682 op->op_private |= OPpLEAVE_VOID;
685 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
689 if ((kid = ((LISTOP*)op)->op_first) && kid->op_type == OP_PUSHRE) {
690 if (!kPMOP->op_pmreplroot)
691 deprecate("implicit split to @_");
695 if (useless && dowarn)
696 warn("Useless use of %s in void context", useless);
705 if (op && op->op_flags & OPf_KIDS) {
706 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
718 /* assumes no premature commitment */
719 if (!op || (op->op_flags & OPf_KNOW) || error_count)
722 op->op_flags |= (OPf_KNOW | OPf_LIST);
724 switch (op->op_type) {
727 list(cBINOP->op_first);
732 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
739 if (!(op->op_flags & OPf_KIDS))
741 if (!op->op_next && cUNOP->op_first->op_type == OP_FLOP) {
742 list(cBINOP->op_first);
743 return gen_constant_list(op);
752 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
771 if (op->op_type == OP_LINESEQ ||
772 op->op_type == OP_SCOPE ||
773 op->op_type == OP_LEAVE ||
774 op->op_type == OP_LEAVETRY)
776 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
777 if (kid->op_sibling) {
783 op->op_flags &= ~OPf_PARENS;
784 if (hints & HINT_BLOCK_SCOPE)
785 op->op_flags |= OPf_PARENS;
788 op = newOP(OP_STUB, 0);
798 if (op && op->op_flags & OPf_KIDS) {
799 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
816 if (!op || error_count)
819 switch (op->op_type) {
821 if (!(op->op_flags & (OPf_SPECIAL|OPf_MOD)))
823 if (eval_start && eval_start->op_type == OP_CONST) {
824 compiling.cop_arybase = (I32)SvIV(((SVOP*)eval_start)->op_sv);
828 SAVEI32(compiling.cop_arybase);
830 else if (type == OP_REFGEN)
833 croak("That use of $[ is unsupported");
836 if ((type == OP_UNDEF || type == OP_REFGEN) &&
837 !(op->op_flags & OPf_STACKED)) {
838 op->op_type = OP_RV2CV; /* entersub => rv2cv */
839 op->op_ppaddr = ppaddr[OP_RV2CV];
840 assert(cUNOP->op_first->op_type == OP_NULL);
841 null(((LISTOP*)cUNOP->op_first)->op_first); /* disable pushmark */
847 /* grep, foreach, subcalls, refgen */
848 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
850 sprintf(tokenbuf, "Can't modify %s in %s",
851 op_name[op->op_type],
852 type ? op_name[type] : "local");
876 if (!(op->op_flags & OPf_STACKED))
882 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
889 ref(cUNOP->op_first, op->op_type);
903 ref(cUNOP->op_first, op->op_type);
927 pad_free(op->op_targ);
928 op->op_targ = pad_alloc(op->op_type, SVs_PADMY);
929 sv = PAD_SV(op->op_targ);
930 sv_upgrade(sv, SVt_PVLV);
931 sv_magic(sv, Nullsv, mtype, Nullch, 0);
932 curpad[op->op_targ] = sv;
933 if (op->op_flags & OPf_KIDS)
934 mod(cBINOP->op_first, type);
939 ref(cBINOP->op_first, op->op_type);
946 if (op->op_flags & OPf_KIDS)
947 mod(cLISTOP->op_last, type);
951 if (!(op->op_flags & OPf_KIDS))
953 if (op->op_targ != OP_LIST) {
954 mod(cBINOP->op_first, type);
959 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
963 op->op_flags |= OPf_MOD;
965 if (type == OP_AASSIGN || type == OP_SASSIGN)
966 op->op_flags |= OPf_SPECIAL|OPf_REF;
968 op->op_private |= OPpLVAL_INTRO;
969 op->op_flags &= ~OPf_SPECIAL;
971 else if (type != OP_GREPSTART && type != OP_ENTERSUB)
972 op->op_flags |= OPf_REF;
982 if (op && op->op_flags & OPf_KIDS) {
983 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
996 if (!op || error_count)
999 switch (op->op_type) {
1001 if ((type == OP_DEFINED) &&
1002 !(op->op_flags & OPf_STACKED)) {
1003 op->op_type = OP_RV2CV; /* entersub => rv2cv */
1004 op->op_ppaddr = ppaddr[OP_RV2CV];
1005 assert(cUNOP->op_first->op_type == OP_NULL);
1006 null(((LISTOP*)cUNOP->op_first)->op_first); /* disable pushmark */
1011 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
1015 ref(cUNOP->op_first, op->op_type);
1016 if (type == OP_RV2AV || type == OP_RV2HV) {
1017 op->op_private |= (type == OP_RV2AV ? OPpDEREF_AV : OPpDEREF_HV);
1018 op->op_flags |= OPf_MOD;
1024 op->op_flags |= OPf_REF;
1027 ref(cUNOP->op_first, op->op_type);
1032 op->op_flags |= OPf_REF;
1037 if (!(op->op_flags & OPf_KIDS))
1039 ref(cBINOP->op_first, type);
1043 ref(cBINOP->op_first, op->op_type);
1044 if (type == OP_RV2AV || type == OP_RV2HV) {
1045 op->op_private |= (type == OP_RV2AV ? OPpDEREF_AV : OPpDEREF_HV);
1046 op->op_flags |= OPf_MOD;
1054 if (!(op->op_flags & OPf_KIDS))
1056 ref(cLISTOP->op_last, type);
1072 if (!op || error_count)
1076 if (type == OP_LIST) {
1077 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1080 else if (type != OP_PADSV &&
1083 type != OP_PUSHMARK)
1085 sprintf(tokenbuf, "Can't declare %s in my", op_name[op->op_type]);
1089 op->op_flags |= OPf_MOD;
1090 op->op_private |= OPpLVAL_INTRO;
1099 o->op_flags |= OPf_PARENS;
1104 bind_match(type, left, right)
1111 if (right->op_type == OP_MATCH ||
1112 right->op_type == OP_SUBST ||
1113 right->op_type == OP_TRANS) {
1114 right->op_flags |= OPf_STACKED;
1115 if (right->op_type != OP_MATCH)
1116 left = mod(left, right->op_type);
1117 if (right->op_type == OP_TRANS)
1118 op = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
1120 op = prepend_elem(right->op_type, scalar(left), right);
1122 return newUNOP(OP_NOT, 0, scalar(op));
1126 return bind_match(type, left,
1127 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
1136 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
1137 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(op));
1145 if (o->op_flags & OPf_PARENS || perldb) {
1146 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
1147 o->op_type = OP_LEAVE;
1148 o->op_ppaddr = ppaddr[OP_LEAVE];
1151 if (o->op_type == OP_LINESEQ) {
1153 o->op_type = OP_SCOPE;
1154 o->op_ppaddr = ppaddr[OP_SCOPE];
1155 kid = ((LISTOP*)o)->op_first;
1156 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE)
1160 o = newUNOP(OP_SCOPE, 0, o);
1169 int retval = savestack_ix;
1170 comppad_name_fill = AvFILL(comppad_name);
1171 SAVEINT(min_intro_pending);
1172 SAVEINT(max_intro_pending);
1173 min_intro_pending = 0;
1174 SAVEINT(comppad_name_fill);
1175 SAVEINT(padix_floor);
1176 padix_floor = padix;
1177 pad_reset_pending = FALSE;
1179 hints &= ~HINT_BLOCK_SCOPE;
1184 block_end(line, floor, seq)
1189 int needblockscope = hints & HINT_BLOCK_SCOPE;
1190 OP* retval = scalarseq(seq);
1191 if (copline > (line_t)line)
1194 pad_reset_pending = FALSE;
1196 hints |= HINT_BLOCK_SCOPE; /* propagate out */
1197 pad_leavemy(comppad_name_fill);
1206 eval_root = newUNOP(OP_LEAVEEVAL, 0, op);
1207 eval_start = linklist(eval_root);
1208 eval_root->op_next = 0;
1216 main_root = scope(sawparens(scalarvoid(op)));
1217 curcop = &compiling;
1218 main_start = LINKLIST(main_root);
1219 main_root->op_next = 0;
1229 if (o->op_flags & OPf_PARENS)
1233 if (dowarn && bufptr > oldbufptr && bufptr[-1] == ',') {
1235 for (s = bufptr; *s && (isALNUM(*s) || strchr("@$%, ",*s)); s++) ;
1236 if (*s == ';' || *s == '=')
1237 warn("Parens missing around \"%s\" list", lex ? "my" : "local");
1244 return mod(o, OP_NULL); /* a bit kludgey */
1251 if (o->op_type == OP_LIST) {
1252 o = convert(OP_JOIN, 0,
1253 prepend_elem(OP_LIST,
1254 newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
1265 I32 type = o->op_type;
1267 if (opargs[type] & OA_RETSCALAR)
1269 if (opargs[type] & OA_TARGET)
1270 o->op_targ = pad_alloc(type, SVs_PADTMP);
1272 if ((opargs[type] & OA_OTHERINT) && (hints & HINT_INTEGER))
1273 o->op_ppaddr = ppaddr[type = ++(o->op_type)];
1275 if (!(opargs[type] & OA_FOLDCONST))
1279 goto nope; /* Don't try to run w/ errors */
1281 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
1282 if (curop->op_type != OP_CONST &&
1283 curop->op_type != OP_LIST &&
1284 curop->op_type != OP_SCALAR &&
1285 curop->op_type != OP_NULL &&
1286 curop->op_type != OP_PUSHMARK) {
1291 curop = LINKLIST(o);
1295 if (o->op_targ && *stack_sp == PAD_SV(o->op_targ)) /* grab pad temp? */
1296 pad_swipe(o->op_targ);
1297 else if (SvTEMP(*stack_sp)) { /* grab mortal temp? */
1298 (void)SvREFCNT_inc(*stack_sp);
1299 SvTEMP_off(*stack_sp);
1302 if (type == OP_RV2GV)
1303 return newGVOP(OP_GV, 0, *(stack_sp--));
1305 return newSVOP(OP_CONST, 0, *(stack_sp--));
1308 if (!(opargs[type] & OA_OTHERINT))
1311 if (!(hints & HINT_INTEGER)) {
1312 if (type == OP_DIVIDE || !(o->op_flags & OPf_KIDS))
1315 for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
1316 if (curop->op_type == OP_CONST) {
1317 if (SvIOK(((SVOP*)curop)->op_sv))
1321 if (opargs[curop->op_type] & OA_RETINTEGER)
1325 o->op_ppaddr = ppaddr[++(o->op_type)];
1332 gen_constant_list(o)
1336 I32 oldtmps_floor = tmps_floor;
1340 return o; /* Don't attempt to run with errors */
1342 op = curop = LINKLIST(o);
1348 tmps_floor = oldtmps_floor;
1350 o->op_type = OP_RV2AV;
1351 o->op_ppaddr = ppaddr[OP_RV2AV];
1352 curop = ((UNOP*)o)->op_first;
1353 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*stack_sp--));
1360 convert(type, flags, op)
1368 if (!op || op->op_type != OP_LIST)
1369 op = newLISTOP(OP_LIST, 0, op, Nullop);
1371 if (!(opargs[type] & OA_MARK))
1372 null(cLISTOP->op_first);
1375 op->op_ppaddr = ppaddr[type];
1376 op->op_flags |= flags;
1378 op = (*check[type])(op);
1379 if (op->op_type != type)
1382 if (cLISTOP->op_children < 7) {
1383 /* XXX do we really need to do this if we're done appending?? */
1384 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1386 cLISTOP->op_last = last; /* in case check substituted last arg */
1389 return fold_constants(op);
1392 /* List constructors */
1395 append_elem(type, first, last)
1406 if (first->op_type != type || type==OP_LIST && first->op_flags & OPf_PARENS)
1407 return newLISTOP(type, 0, first, last);
1409 if (first->op_flags & OPf_KIDS)
1410 ((LISTOP*)first)->op_last->op_sibling = last;
1412 first->op_flags |= OPf_KIDS;
1413 ((LISTOP*)first)->op_first = last;
1415 ((LISTOP*)first)->op_last = last;
1416 ((LISTOP*)first)->op_children++;
1421 append_list(type, first, last)
1432 if (first->op_type != type)
1433 return prepend_elem(type, (OP*)first, (OP*)last);
1435 if (last->op_type != type)
1436 return append_elem(type, (OP*)first, (OP*)last);
1438 first->op_last->op_sibling = last->op_first;
1439 first->op_last = last->op_last;
1440 first->op_children += last->op_children;
1441 if (first->op_children)
1442 last->op_flags |= OPf_KIDS;
1449 prepend_elem(type, first, last)
1460 if (last->op_type == type) {
1461 if (type == OP_LIST) { /* already a PUSHMARK there */
1462 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
1463 ((LISTOP*)last)->op_first->op_sibling = first;
1466 if (!(last->op_flags & OPf_KIDS)) {
1467 ((LISTOP*)last)->op_last = first;
1468 last->op_flags |= OPf_KIDS;
1470 first->op_sibling = ((LISTOP*)last)->op_first;
1471 ((LISTOP*)last)->op_first = first;
1473 ((LISTOP*)last)->op_children++;
1477 return newLISTOP(type, 0, first, last);
1485 return newOP(OP_STUB, 0);
1492 if (!op || op->op_type != OP_LIST)
1493 op = newLISTOP(OP_LIST, 0, op, Nullop);
1499 newLISTOP(type, flags, first, last)
1507 Newz(1101, listop, 1, LISTOP);
1509 listop->op_type = type;
1510 listop->op_ppaddr = ppaddr[type];
1511 listop->op_children = (first != 0) + (last != 0);
1512 listop->op_flags = flags;
1516 else if (!first && last)
1519 first->op_sibling = last;
1520 listop->op_first = first;
1521 listop->op_last = last;
1522 if (type == OP_LIST) {
1524 pushop = newOP(OP_PUSHMARK, 0);
1525 pushop->op_sibling = first;
1526 listop->op_first = pushop;
1527 listop->op_flags |= OPf_KIDS;
1529 listop->op_last = pushop;
1531 else if (listop->op_children)
1532 listop->op_flags |= OPf_KIDS;
1543 Newz(1101, op, 1, OP);
1545 op->op_ppaddr = ppaddr[type];
1546 op->op_flags = flags;
1549 /* op->op_private = 0; */
1550 if (opargs[type] & OA_RETSCALAR)
1552 if (opargs[type] & OA_TARGET)
1553 op->op_targ = pad_alloc(type, SVs_PADTMP);
1554 return (*check[type])(op);
1558 newUNOP(type, flags, first)
1566 first = newOP(OP_STUB, 0);
1567 if (opargs[type] & OA_MARK)
1568 first = force_list(first);
1570 Newz(1101, unop, 1, UNOP);
1571 unop->op_type = type;
1572 unop->op_ppaddr = ppaddr[type];
1573 unop->op_first = first;
1574 unop->op_flags = flags | OPf_KIDS;
1575 unop->op_private = 1;
1577 unop = (UNOP*)(*check[type])((OP*)unop);
1581 return fold_constants((OP *) unop);
1585 newBINOP(type, flags, first, last)
1592 Newz(1101, binop, 1, BINOP);
1595 first = newOP(OP_NULL, 0);
1597 binop->op_type = type;
1598 binop->op_ppaddr = ppaddr[type];
1599 binop->op_first = first;
1600 binop->op_flags = flags | OPf_KIDS;
1603 binop->op_private = 1;
1606 binop->op_private = 2;
1607 first->op_sibling = last;
1610 binop = (BINOP*)(*check[type])((OP*)binop);
1614 binop->op_last = last = binop->op_first->op_sibling;
1616 return fold_constants((OP *)binop);
1620 pmtrans(op, expr, repl)
1625 SV *tstr = ((SVOP*)expr)->op_sv;
1626 SV *rstr = ((SVOP*)repl)->op_sv;
1629 register char *t = SvPV(tstr, tlen);
1630 register char *r = SvPV(rstr, rlen);
1636 register short *tbl;
1638 tbl = (short*)cPVOP->op_pv;
1639 complement = op->op_private & OPpTRANS_COMPLEMENT;
1640 delete = op->op_private & OPpTRANS_DELETE;
1641 squash = op->op_private & OPpTRANS_SQUASH;
1644 Zero(tbl, 256, short);
1645 for (i = 0; i < tlen; i++)
1646 tbl[t[i] & 0377] = -1;
1647 for (i = 0, j = 0; i < 256; i++) {
1653 tbl[i] = r[j-1] & 0377;
1658 tbl[i] = r[j++] & 0377;
1663 if (!rlen && !delete) {
1666 for (i = 0; i < 256; i++)
1668 for (i = 0, j = 0; i < tlen; i++,j++) {
1671 if (tbl[t[i] & 0377] == -1)
1672 tbl[t[i] & 0377] = -2;
1677 if (tbl[t[i] & 0377] == -1)
1678 tbl[t[i] & 0377] = r[j] & 0377;
1688 newPMOP(type, flags)
1694 Newz(1101, pmop, 1, PMOP);
1695 pmop->op_type = type;
1696 pmop->op_ppaddr = ppaddr[type];
1697 pmop->op_flags = flags;
1698 pmop->op_private = 0;
1700 /* link into pm list */
1701 if (type != OP_TRANS && curstash) {
1702 pmop->op_pmnext = HvPMROOT(curstash);
1703 HvPMROOT(curstash) = pmop;
1710 pmruntime(op, expr, repl)
1718 if (op->op_type == OP_TRANS)
1719 return pmtrans(op, expr, repl);
1723 if (expr->op_type == OP_CONST) {
1725 SV *pat = ((SVOP*)expr)->op_sv;
1726 char *p = SvPV(pat, plen);
1727 if ((op->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
1728 sv_setpvn(pat, "\\s+", 3);
1729 p = SvPV(pat, plen);
1730 pm->op_pmflags |= PMf_SKIPWHITE;
1733 scan_prefix(pm, p, plen);
1734 if (pm->op_pmshort && (pm->op_pmflags & PMf_SCANFIRST))
1735 fbm_compile(pm->op_pmshort, pm->op_pmflags & PMf_FOLD);
1737 pm->op_pmregexp = regcomp(p, p + plen, pm);
1738 if (strEQ("\\s+", pm->op_pmregexp->precomp))
1739 pm->op_pmflags |= PMf_WHITE;
1744 if (pm->op_pmflags & PMf_KEEP)
1745 expr = newUNOP(OP_REGCMAYBE,0,expr);
1747 Newz(1101, rcop, 1, LOGOP);
1748 rcop->op_type = OP_REGCOMP;
1749 rcop->op_ppaddr = ppaddr[OP_REGCOMP];
1750 rcop->op_first = scalar(expr);
1751 rcop->op_flags |= OPf_KIDS;
1752 rcop->op_private = 1;
1753 rcop->op_other = op;
1755 /* establish postfix order */
1756 if (pm->op_pmflags & PMf_KEEP) {
1758 rcop->op_next = expr;
1759 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
1762 rcop->op_next = LINKLIST(expr);
1763 expr->op_next = (OP*)rcop;
1766 prepend_elem(op->op_type, scalar((OP*)rcop), op);
1770 if (repl->op_type == OP_CONST) {
1771 pm->op_pmflags |= PMf_CONST;
1772 prepend_elem(op->op_type, scalar(repl), op);
1777 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
1778 if (opargs[curop->op_type] & OA_DANGEROUS) {
1779 if (curop->op_type == OP_GV) {
1780 GV *gv = ((GVOP*)curop)->op_gv;
1781 if (strchr("&`'123456789+", *GvENAME(gv)))
1784 else if (curop->op_type == OP_RV2CV)
1786 else if (curop->op_type == OP_RV2SV ||
1787 curop->op_type == OP_RV2AV ||
1788 curop->op_type == OP_RV2HV ||
1789 curop->op_type == OP_RV2GV) {
1790 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
1798 if (curop == repl) {
1799 pm->op_pmflags |= PMf_CONST; /* const for long enough */
1800 prepend_elem(op->op_type, scalar(repl), op);
1803 Newz(1101, rcop, 1, LOGOP);
1804 rcop->op_type = OP_SUBSTCONT;
1805 rcop->op_ppaddr = ppaddr[OP_SUBSTCONT];
1806 rcop->op_first = scalar(repl);
1807 rcop->op_flags |= OPf_KIDS;
1808 rcop->op_private = 1;
1809 rcop->op_other = op;
1811 /* establish postfix order */
1812 rcop->op_next = LINKLIST(repl);
1813 repl->op_next = (OP*)rcop;
1815 pm->op_pmreplroot = scalar((OP*)rcop);
1816 pm->op_pmreplstart = LINKLIST(rcop);
1826 newSVOP(type, flags, sv)
1832 Newz(1101, svop, 1, SVOP);
1833 svop->op_type = type;
1834 svop->op_ppaddr = ppaddr[type];
1836 svop->op_next = (OP*)svop;
1837 svop->op_flags = flags;
1838 if (opargs[type] & OA_RETSCALAR)
1840 if (opargs[type] & OA_TARGET)
1841 svop->op_targ = pad_alloc(type, SVs_PADTMP);
1842 return (*check[type])((OP*)svop);
1846 newGVOP(type, flags, gv)
1852 Newz(1101, gvop, 1, GVOP);
1853 gvop->op_type = type;
1854 gvop->op_ppaddr = ppaddr[type];
1855 gvop->op_gv = (GV*)SvREFCNT_inc(gv);
1856 gvop->op_next = (OP*)gvop;
1857 gvop->op_flags = flags;
1858 if (opargs[type] & OA_RETSCALAR)
1860 if (opargs[type] & OA_TARGET)
1861 gvop->op_targ = pad_alloc(type, SVs_PADTMP);
1862 return (*check[type])((OP*)gvop);
1866 newPVOP(type, flags, pv)
1872 Newz(1101, pvop, 1, PVOP);
1873 pvop->op_type = type;
1874 pvop->op_ppaddr = ppaddr[type];
1876 pvop->op_next = (OP*)pvop;
1877 pvop->op_flags = flags;
1878 if (opargs[type] & OA_RETSCALAR)
1880 if (opargs[type] & OA_TARGET)
1881 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
1882 return (*check[type])((OP*)pvop);
1886 newCVOP(type, flags, cv, cont)
1893 Newz(1101, cvop, 1, CVOP);
1894 cvop->op_type = type;
1895 cvop->op_ppaddr = ppaddr[type];
1897 cvop->op_cont = cont;
1898 cvop->op_next = (OP*)cvop;
1899 cvop->op_flags = flags;
1900 if (opargs[type] & OA_RETSCALAR)
1902 if (opargs[type] & OA_TARGET)
1903 cvop->op_targ = pad_alloc(type, SVs_PADTMP);
1904 return (*check[type])((OP*)cvop);
1913 save_hptr(&curstash);
1914 save_item(curstname);
1919 name = SvPV(sv, len);
1920 curstash = gv_stashpv(name,TRUE);
1921 sv_setpvn(curstname, name, len);
1925 sv_setpv(curstname,"<none>");
1933 utilize(aver, id, arg)
1943 if (id->op_type != OP_CONST)
1944 croak("Module name must be constant");
1946 meth = newSVOP(OP_CONST, 0,
1948 ? newSVpv("import", 6)
1949 : newSVpv("unimport", 8)
1952 /* Make copy of id so we don't free it twice */
1953 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
1955 /* Fake up a require */
1956 rqop = newUNOP(OP_REQUIRE, 0, id);
1958 /* Fake up an import/unimport */
1959 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
1960 append_elem(OP_LIST,
1961 prepend_elem(OP_LIST, pack, list(arg)),
1962 newUNOP(OP_METHOD, 0, meth)));
1964 /* Fake up the BEGIN {}, which does its thing immediately. */
1965 newSUB(start_subparse(),
1966 newSVOP(OP_CONST, 0, newSVpv("BEGIN", 5)),
1967 append_elem(OP_LINESEQ,
1968 newSTATEOP(0, Nullch, rqop),
1969 newSTATEOP(0, Nullch, imop) ));
1976 newSLICEOP(flags, subscript, listval)
1981 return newBINOP(OP_LSLICE, flags,
1982 list(force_list(subscript)),
1983 list(force_list(listval)) );
1993 if (op->op_type == OP_NULL && op->op_flags & OPf_KIDS)
1994 op = cUNOP->op_first;
1996 if (op->op_type == OP_COND_EXPR) {
1997 I32 t = list_assignment(cCONDOP->op_first->op_sibling);
1998 I32 f = list_assignment(cCONDOP->op_first->op_sibling->op_sibling);
2003 yyerror("Assignment to both a list and a scalar");
2007 if (op->op_type == OP_LIST || op->op_flags & OPf_PARENS ||
2008 op->op_type == OP_RV2AV || op->op_type == OP_RV2HV ||
2009 op->op_type == OP_ASLICE || op->op_type == OP_HSLICE)
2012 if (op->op_type == OP_PADAV || op->op_type == OP_PADHV)
2015 if (op->op_type == OP_RV2SV)
2022 newASSIGNOP(flags, left, optype, right)
2031 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN) {
2032 return newLOGOP(optype, 0,
2033 mod(scalar(left), optype),
2034 newUNOP(OP_SASSIGN, 0, scalar(right)));
2037 return newBINOP(optype, OPf_STACKED,
2038 mod(scalar(left), optype), scalar(right));
2042 if (list_assignment(left)) {
2044 eval_start = right; /* Grandfathering $[ assignment here. Bletch. */
2045 left = mod(left, OP_AASSIGN);
2051 if (right && right->op_type == OP_SPLIT) {
2052 if ((op = ((LISTOP*)right)->op_first) && op->op_type == OP_PUSHRE) {
2053 PMOP *pm = (PMOP*)op;
2054 if (left->op_type == OP_RV2AV &&
2055 !(left->op_private & OPpLVAL_INTRO) )
2057 op = ((UNOP*)left)->op_first;
2058 if (op->op_type == OP_GV && !pm->op_pmreplroot) {
2059 pm->op_pmreplroot = (OP*)((GVOP*)op)->op_gv;
2060 pm->op_pmflags |= PMf_ONCE;
2066 if (modcount < 10000) {
2067 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
2069 sv_setiv(sv, modcount+1);
2074 op = newBINOP(OP_AASSIGN, flags,
2075 list(force_list(right)),
2076 list(force_list(left)) );
2078 if (!(left->op_private & OPpLVAL_INTRO)) {
2079 static int generation = 0;
2083 for (curop = LINKLIST(op); curop != op; curop = LINKLIST(curop)) {
2084 if (opargs[curop->op_type] & OA_DANGEROUS) {
2085 if (curop->op_type == OP_GV) {
2086 GV *gv = ((GVOP*)curop)->op_gv;
2087 if (gv == defgv || SvCUR(gv) == generation)
2089 SvCUR(gv) = generation;
2091 else if (curop->op_type == OP_RV2CV)
2093 else if (curop->op_type == OP_RV2SV ||
2094 curop->op_type == OP_RV2AV ||
2095 curop->op_type == OP_RV2HV ||
2096 curop->op_type == OP_RV2GV) {
2097 if (lastop->op_type != OP_GV) /* funny deref? */
2106 op->op_private = OPpASSIGN_COMMON;
2111 right = newOP(OP_UNDEF, 0);
2112 if (right->op_type == OP_READLINE) {
2113 right->op_flags |= OPf_STACKED;
2114 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
2117 eval_start = right; /* Grandfathering $[ assignment here. Bletch. */
2118 op = newBINOP(OP_SASSIGN, flags,
2119 scalar(right), mod(scalar(left), OP_SASSIGN) );
2129 newSTATEOP(flags, label, op)
2136 /* Introduce my variables. */
2137 if (min_intro_pending) {
2138 SV **svp = AvARRAY(comppad_name);
2141 for (i = min_intro_pending; i <= max_intro_pending; i++) {
2142 if ((sv = svp[i]) && sv != &sv_undef)
2143 SvIVX(sv) = 999999999; /* Don't know scope end yet. */
2145 min_intro_pending = 0;
2146 comppad_name_fill = max_intro_pending; /* Needn't search higher */
2149 Newz(1101, cop, 1, COP);
2150 if (perldb && curcop->cop_line && curstash != debstash) {
2151 cop->op_type = OP_DBSTATE;
2152 cop->op_ppaddr = ppaddr[ OP_DBSTATE ];
2155 cop->op_type = OP_NEXTSTATE;
2156 cop->op_ppaddr = ppaddr[ OP_NEXTSTATE ];
2158 cop->op_flags = flags;
2159 cop->op_private = 0;
2160 cop->op_next = (OP*)cop;
2163 cop->cop_label = label;
2164 hints |= HINT_BLOCK_SCOPE;
2166 cop->cop_seq = cop_seqmax++;
2167 cop->cop_arybase = curcop->cop_arybase;
2169 if (copline == NOLINE)
2170 cop->cop_line = curcop->cop_line;
2172 cop->cop_line = copline;
2175 cop->cop_filegv = SvREFCNT_inc(curcop->cop_filegv);
2176 cop->cop_stash = curstash;
2178 if (perldb && curstash != debstash) {
2179 SV **svp = av_fetch(GvAV(curcop->cop_filegv),(I32)cop->cop_line, FALSE);
2180 if (svp && *svp != &sv_undef && !SvIOK(*svp)) {
2182 (void)SvIOK_on(*svp);
2183 SvSTASH(*svp) = (HV*)cop;
2187 return prepend_elem(OP_LINESEQ, (OP*)cop, op);
2191 newLOGOP(type, flags, first, other)
2200 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
2201 return newBINOP(type, flags, scalar(first), scalar(other));
2203 scalarboolean(first);
2204 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
2205 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
2206 if (type == OP_AND || type == OP_OR) {
2212 first = cUNOP->op_first;
2214 first->op_next = op->op_next;
2215 cUNOP->op_first = Nullop;
2219 if (first->op_type == OP_CONST) {
2220 if (dowarn && (first->op_private & OPpCONST_BARE))
2221 warn("Probable precedence problem on %s", op_name[type]);
2222 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
2231 else if (first->op_type == OP_WANTARRAY) {
2241 if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
2242 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
2244 Newz(1101, logop, 1, LOGOP);
2246 logop->op_type = type;
2247 logop->op_ppaddr = ppaddr[type];
2248 logop->op_first = first;
2249 logop->op_flags = flags | OPf_KIDS;
2250 logop->op_other = LINKLIST(other);
2251 logop->op_private = 1;
2253 /* establish postfix order */
2254 logop->op_next = LINKLIST(first);
2255 first->op_next = (OP*)logop;
2256 first->op_sibling = other;
2258 op = newUNOP(OP_NULL, 0, (OP*)logop);
2259 other->op_next = op;
2265 newCONDOP(flags, first, true, false)
2275 return newLOGOP(OP_AND, 0, first, true);
2277 return newLOGOP(OP_OR, 0, first, false);
2279 scalarboolean(first);
2280 if (first->op_type == OP_CONST) {
2281 if (SvTRUE(((SVOP*)first)->op_sv)) {
2292 else if (first->op_type == OP_WANTARRAY) {
2296 Newz(1101, condop, 1, CONDOP);
2298 condop->op_type = OP_COND_EXPR;
2299 condop->op_ppaddr = ppaddr[OP_COND_EXPR];
2300 condop->op_first = first;
2301 condop->op_flags = flags | OPf_KIDS;
2302 condop->op_true = LINKLIST(true);
2303 condop->op_false = LINKLIST(false);
2304 condop->op_private = 1;
2306 /* establish postfix order */
2307 condop->op_next = LINKLIST(first);
2308 first->op_next = (OP*)condop;
2310 first->op_sibling = true;
2311 true->op_sibling = false;
2312 op = newUNOP(OP_NULL, 0, (OP*)condop);
2315 false->op_next = op;
2321 newRANGE(flags, left, right)
2331 Newz(1101, condop, 1, CONDOP);
2333 condop->op_type = OP_RANGE;
2334 condop->op_ppaddr = ppaddr[OP_RANGE];
2335 condop->op_first = left;
2336 condop->op_flags = OPf_KIDS;
2337 condop->op_true = LINKLIST(left);
2338 condop->op_false = LINKLIST(right);
2339 condop->op_private = 1;
2341 left->op_sibling = right;
2343 condop->op_next = (OP*)condop;
2344 flip = newUNOP(OP_FLIP, flags, (OP*)condop);
2345 flop = newUNOP(OP_FLOP, 0, flip);
2346 op = newUNOP(OP_NULL, 0, flop);
2349 left->op_next = flip;
2350 right->op_next = flop;
2352 condop->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2353 sv_upgrade(PAD_SV(condop->op_targ), SVt_PVNV);
2354 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2355 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
2357 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2358 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2361 if (!flip->op_private || !flop->op_private)
2362 linklist(op); /* blow off optimizer unless constant */
2368 newLOOPOP(flags, debuggable, expr, block)
2376 int once = block && block->op_flags & OPf_SPECIAL &&
2377 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
2380 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
2381 return block; /* do {} while 0 does once */
2382 else if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB)
2383 expr = newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr);
2386 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
2387 op = newLOGOP(OP_AND, 0, expr, listop);
2389 ((LISTOP*)listop)->op_last->op_next = LINKLIST(op);
2391 if (once && op != listop)
2392 op->op_next = ((LOGOP*)cUNOP->op_first)->op_other;
2394 op->op_flags |= flags;
2396 op->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration */
2401 newWHILEOP(flags, debuggable, loop, expr, block, cont)
2415 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB))
2416 expr = newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr);
2419 block = newOP(OP_NULL, 0);
2422 next = LINKLIST(cont);
2424 cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
2426 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
2427 redo = LINKLIST(listop);
2430 op = newLOGOP(OP_AND, 0, expr, scalar(listop));
2431 if (op == expr && op->op_type == OP_CONST && !SvTRUE(cSVOP->op_sv)) {
2432 op_free(expr); /* oops, it's a while (0) */
2434 return Nullop; /* (listop already freed by newLOGOP) */
2436 ((LISTOP*)listop)->op_last->op_next = condop =
2437 (op == listop ? redo : LINKLIST(op));
2445 Newz(1101,loop,1,LOOP);
2446 loop->op_type = OP_ENTERLOOP;
2447 loop->op_ppaddr = ppaddr[OP_ENTERLOOP];
2448 loop->op_private = 0;
2449 loop->op_next = (OP*)loop;
2452 op = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, op);
2454 loop->op_redoop = redo;
2455 loop->op_lastop = op;
2458 loop->op_nextop = next;
2460 loop->op_nextop = op;
2462 op->op_flags |= flags;
2467 #ifndef CAN_PROTOTYPE
2468 newFOROP(flags,label,forline,sv,expr,block,cont)
2477 newFOROP(I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
2478 #endif /* CAN_PROTOTYPE */
2485 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
2487 sv = cUNOP->op_first;
2489 cUNOP->op_first = Nullop;
2492 else if (sv->op_type == OP_PADSV) { /* private variable */
2493 padoff = sv->op_targ;
2498 croak("Can't use %s for loop variable", op_name[sv->op_type]);
2501 sv = newGVOP(OP_GV, 0, defgv);
2503 loop = (LOOP*)list(convert(OP_ENTERITER, 0,
2504 append_elem(OP_LIST, mod(force_list(expr), OP_GREPSTART),
2506 assert(!loop->op_next);
2507 Renew(loop, 1, LOOP);
2508 loop->op_targ = padoff;
2509 return newSTATEOP(0, label, newWHILEOP(flags, 1, loop,
2510 newOP(OP_ITER, 0), block, cont));
2514 newLOOPEX(type, label)
2519 if (type != OP_GOTO || label->op_type == OP_CONST) {
2520 op = newPVOP(type, 0, savepv(
2521 label->op_type == OP_CONST
2522 ? SvPVx(((SVOP*)label)->op_sv, na)
2527 if (label->op_type == OP_ENTERSUB)
2528 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
2529 op = newUNOP(type, OPf_STACKED, label);
2531 hints |= HINT_BLOCK_SCOPE;
2539 if (!CvXSUB(cv) && CvROOT(cv)) {
2541 croak("Can't undef active subroutine");
2547 op_free(CvROOT(cv));
2548 CvROOT(cv) = Nullop;
2549 if (CvPADLIST(cv)) {
2550 I32 i = AvFILL(CvPADLIST(cv));
2552 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
2556 SvREFCNT_dec((SV*)CvPADLIST(cv));
2558 SvREFCNT_dec(CvGV(cv));
2564 newSUB(floor,op,block)
2570 char *name = op ? SvPVx(cSVOP->op_sv, na) : "__ANON__";
2571 GV *gv = gv_fetchpv(name, GV_ADDMULTI, SVt_PVCV);
2578 if (cv = GvCV(gv)) {
2580 cv = 0; /* just a cached method */
2581 else if (CvROOT(cv)) { /* already defined? */
2583 line_t oldline = curcop->cop_line;
2585 curcop->cop_line = copline;
2586 warn("Subroutine %s redefined",name);
2587 curcop->cop_line = oldline;
2593 if (cv) { /* must reuse cv if autoloaded */
2594 assert(SvREFCNT(CvGV(cv)) > 1);
2595 SvREFCNT_dec(CvGV(cv));
2598 cv = (CV*)NEWSV(1104,0);
2599 sv_upgrade((SV *)cv, SVt_PVCV);
2603 CvFILEGV(cv) = curcop->cop_filegv;
2604 CvGV(cv) = SvREFCNT_inc(gv);
2605 CvSTASH(cv) = curstash;
2615 av = newAV(); /* Will be @_ */
2617 av_store(comppad, 0, (SV*)av);
2618 AvFLAGS(av) = AVf_REIFY;
2620 for (ix = AvFILL(comppad); ix > 0; ix--) {
2621 if (!SvPADMY(curpad[ix]))
2622 SvPADTMP_on(curpad[ix]);
2627 if (AvFILL(comppad_name) < AvFILL(comppad))
2628 av_store(comppad_name, AvFILL(comppad), Nullsv);
2629 av_store(av, 0, SvREFCNT_inc((SV*)comppad_name));
2630 av_store(av, 1, SvREFCNT_inc((SV*)comppad));
2634 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
2635 CvSTART(cv) = LINKLIST(CvROOT(cv));
2636 CvROOT(cv)->op_next = 0;
2638 if (s = strrchr(name,':'))
2642 if (strEQ(s, "BEGIN")) {
2643 line_t oldline = compiling.cop_line;
2646 SAVESPTR(compiling.cop_filegv);
2650 av_push(beginav, (SV *)cv);
2651 DEBUG_x( dump_sub(gv) );
2655 rspara = (nrslen == 2);
2662 curcop = &compiling;
2663 curcop->cop_line = oldline; /* might have recursed to yylex */
2666 else if (strEQ(s, "END")) {
2669 av_unshift(endav, 1);
2670 av_store(endav, 0, SvREFCNT_inc(cv));
2672 if (perldb && curstash != debstash) {
2674 SV *tmpstr = sv_newmortal();
2676 sprintf(buf,"%s:%ld",SvPVX(GvSV(curcop->cop_filegv)), (long)subline);
2677 sv = newSVpv(buf,0);
2679 sprintf(buf,"%ld",(long)curcop->cop_line);
2681 gv_efullname(tmpstr,gv);
2682 hv_store(GvHV(DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
2688 GvCV(gv) = 0; /* Will remember in SVOP instead. */
2694 newXSUB(name, ix, subaddr, filename)
2700 CV* cv = newXS(name, (void(*)())subaddr, filename);
2701 CvOLDSTYLE(cv) = TRUE;
2702 CvXSUBANY(cv).any_i32 = ix;
2708 newXS(name, subaddr, filename)
2710 void (*subaddr) _((CV*));
2714 GV *gv = gv_fetchpv((name ? name : "__ANON__"), GV_ADDMULTI, SVt_PVCV);
2719 if (cv = GvCV(gv)) {
2721 cv = 0; /* just a cached method */
2722 else if (CvROOT(cv)) { /* already defined? */
2724 line_t oldline = curcop->cop_line;
2726 curcop->cop_line = copline;
2727 warn("Subroutine %s redefined",name);
2728 curcop->cop_line = oldline;
2734 if (cv) { /* must reuse cv if autoloaded */
2735 assert(SvREFCNT(CvGV(cv)) > 1);
2736 SvREFCNT_dec(CvGV(cv));
2739 cv = (CV*)NEWSV(1105,0);
2740 sv_upgrade((SV *)cv, SVt_PVCV);
2743 CvGV(cv) = SvREFCNT_inc(gv);
2745 CvFILEGV(cv) = gv_fetchfile(filename);
2746 CvXSUB(cv) = subaddr;
2749 else if (s = strrchr(name,':'))
2753 if (strEQ(s, "BEGIN")) {
2756 av_push(beginav, SvREFCNT_inc(gv));
2758 else if (strEQ(s, "END")) {
2761 av_unshift(endav, 1);
2762 av_store(endav, 0, SvREFCNT_inc(gv));
2765 GvCV(gv) = 0; /* Will remember elsewhere instead. */
2770 newFORM(floor,op,block)
2782 name = SvPVx(cSVOP->op_sv, na);
2785 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
2787 if (cv = GvFORM(gv)) {
2789 line_t oldline = curcop->cop_line;
2791 curcop->cop_line = copline;
2792 warn("Format %s redefined",name);
2793 curcop->cop_line = oldline;
2797 cv = (CV*)NEWSV(1106,0);
2798 sv_upgrade((SV *)cv, SVt_PVFM);
2800 CvGV(cv) = SvREFCNT_inc(gv);
2801 CvFILEGV(cv) = curcop->cop_filegv;
2803 for (ix = AvFILL(comppad); ix > 0; ix--) {
2804 if (!SvPADMY(curpad[ix]))
2805 SvPADTMP_on(curpad[ix]);
2808 CvPADLIST(cv) = av = newAV();
2810 av_store(av, 1, SvREFCNT_inc((SV*)comppad));
2813 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
2814 CvSTART(cv) = LINKLIST(CvROOT(cv));
2815 CvROOT(cv)->op_next = 0;
2829 Newz(1101, mop, 1, LOGOP);
2830 mop->op_type = OP_METHOD;
2831 mop->op_ppaddr = ppaddr[OP_METHOD];
2832 mop->op_first = scalar(ref);
2833 mop->op_flags |= OPf_KIDS;
2834 mop->op_private = 1;
2835 mop->op_other = LINKLIST(name);
2836 mop->op_targ = pad_alloc(OP_METHOD, SVs_PADTMP);
2837 mop->op_next = LINKLIST(ref);
2838 ref->op_next = (OP*)mop;
2839 return scalar((OP*)mop);
2846 return newUNOP(OP_REFGEN, 0,
2847 mod(list(convert(OP_ANONLIST, 0, op)), OP_REFGEN));
2854 return newUNOP(OP_REFGEN, 0,
2855 mod(list(convert(OP_ANONHASH, 0, op)), OP_REFGEN));
2859 newANONSUB(floor, block)
2863 return newUNOP(OP_REFGEN, 0,
2864 newSVOP(OP_ANONCODE, 0, (SV*)newSUB(floor, 0, block)));
2871 switch (o->op_type) {
2873 o->op_type = OP_PADAV;
2874 o->op_ppaddr = ppaddr[OP_PADAV];
2875 return ref(newUNOP(OP_RV2AV, 0, scalar(o)), OP_RV2AV);
2878 o->op_type = OP_RV2AV;
2879 o->op_ppaddr = ppaddr[OP_RV2AV];
2884 warn("oops: oopsAV");
2894 switch (o->op_type) {
2897 o->op_type = OP_PADHV;
2898 o->op_ppaddr = ppaddr[OP_PADHV];
2899 return ref(newUNOP(OP_RV2HV, 0, scalar(o)), OP_RV2HV);
2903 o->op_type = OP_RV2HV;
2904 o->op_ppaddr = ppaddr[OP_RV2HV];
2909 warn("oops: oopsHV");
2919 if (o->op_type == OP_PADANY) {
2920 o->op_type = OP_PADAV;
2921 o->op_ppaddr = ppaddr[OP_PADAV];
2924 return newUNOP(OP_RV2AV, 0, scalar(o));
2932 if (type == OP_MAPSTART)
2933 return newUNOP(OP_NULL, 0, o);
2934 return newUNOP(OP_RV2GV, 0, o);
2941 if (o->op_type == OP_PADANY) {
2942 o->op_type = OP_PADHV;
2943 o->op_ppaddr = ppaddr[OP_PADHV];
2946 return newUNOP(OP_RV2HV, 0, scalar(o));
2953 croak("NOT IMPL LINE %d",__LINE__);
2962 return newUNOP(OP_RV2CV, 0, scalar(o));
2969 if (o->op_type == OP_PADANY) {
2970 o->op_type = OP_PADSV;
2971 o->op_ppaddr = ppaddr[OP_PADSV];
2974 return newUNOP(OP_RV2SV, 0, scalar(o));
2977 /* Check routines. */
2983 if (cUNOP->op_first->op_type == OP_CONCAT)
2984 op->op_flags |= OPf_STACKED;
2992 if (op->op_flags & OPf_KIDS) {
2995 op = modkids(ck_fun(op), op->op_type);
2996 kid = cUNOP->op_first;
2997 newop = kUNOP->op_first->op_sibling;
2999 (newop->op_sibling ||
3000 !(opargs[newop->op_type] & OA_RETSCALAR) ||
3001 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
3002 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
3006 op_free(kUNOP->op_first);
3007 kUNOP->op_first = newop;
3009 op->op_ppaddr = ppaddr[++op->op_type];
3018 if (op->op_flags & OPf_KIDS) {
3019 OP *kid = cUNOP->op_first;
3020 if (kid->op_type != OP_HELEM)
3021 croak("%s argument is not a HASH element", op_name[op->op_type]);
3031 I32 type = op->op_type;
3033 if (op->op_flags & OPf_KIDS) {
3034 if (cLISTOP->op_first->op_type == OP_STUB) {
3036 op = newUNOP(type, OPf_SPECIAL,
3037 newGVOP(OP_GV, 0, gv_fetchpv("main'ARGV", TRUE, SVt_PVAV)));
3048 hints |= HINT_BLOCK_SCOPE;
3049 if (op->op_flags & OPf_KIDS) {
3050 SVOP *kid = (SVOP*)cUNOP->op_first;
3053 op->op_flags &= ~OPf_KIDS;
3056 else if (kid->op_type == OP_LINESEQ) {
3059 kid->op_next = op->op_next;
3060 cUNOP->op_first = 0;
3063 Newz(1101, enter, 1, LOGOP);
3064 enter->op_type = OP_ENTERTRY;
3065 enter->op_ppaddr = ppaddr[OP_ENTERTRY];
3066 enter->op_private = 0;
3068 /* establish postfix order */
3069 enter->op_next = (OP*)enter;
3071 op = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
3072 op->op_type = OP_LEAVETRY;
3073 op->op_ppaddr = ppaddr[OP_LEAVETRY];
3074 enter->op_other = op;
3080 op = newUNOP(OP_ENTEREVAL, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3082 op->op_targ = (PADOFFSET)hints;
3091 if (op->op_flags & OPf_STACKED) {
3093 kid = cUNOP->op_first->op_sibling;
3094 if (kid->op_type == OP_RV2GV)
3106 o = fold_constants(o);
3107 if (o->op_type == OP_CONST)
3116 SVOP *kid = (SVOP*)cUNOP->op_first;
3117 int iscv = (op->op_type==OP_RV2CV)*2;
3119 op->op_private = (hints & HINT_STRICT_REFS);
3120 if (kid->op_type == OP_CONST) {
3122 kid->op_type = OP_GV;
3123 for (gv = 0; !gv; iscv++) {
3124 gv = gv_fetchpv(SvPVx(kid->op_sv, na),
3128 : op->op_type == OP_RV2SV
3130 : op->op_type == OP_RV2AV
3132 : op->op_type == OP_RV2HV
3136 SvREFCNT_dec(kid->op_sv);
3137 kid->op_sv = SvREFCNT_inc(gv);
3153 I32 type = op->op_type;
3155 if (op->op_flags & OPf_REF)
3158 if (op->op_flags & OPf_KIDS) {
3159 SVOP *kid = (SVOP*)cUNOP->op_first;
3161 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
3162 OP *newop = newGVOP(type, OPf_REF,
3163 gv_fetchpv(SvPVx(kid->op_sv, na), TRUE, SVt_PVIO));
3170 if (type == OP_FTTTY)
3171 return newGVOP(type, OPf_REF, gv_fetchpv("main'STDIN", TRUE,
3174 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3187 int type = op->op_type;
3188 register I32 oa = opargs[type] >> OASHIFT;
3190 if (op->op_flags & OPf_STACKED) {
3191 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
3194 return no_fh_allowed(op);
3197 if (op->op_flags & OPf_KIDS) {
3198 tokid = &cLISTOP->op_first;
3199 kid = cLISTOP->op_first;
3200 if (kid->op_type == OP_PUSHMARK ||
3201 kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK)
3203 tokid = &kid->op_sibling;
3204 kid = kid->op_sibling;
3206 if (!kid && opargs[type] & OA_DEFGV)
3207 *tokid = kid = newSVREF(newGVOP(OP_GV, 0, defgv));
3211 sibl = kid->op_sibling;
3225 if (kid->op_type == OP_CONST &&
3226 (kid->op_private & OPpCONST_BARE)) {
3227 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
3228 OP *newop = newAVREF(newGVOP(OP_GV, 0,
3229 gv_fetchpv(name, TRUE, SVt_PVAV) ));
3231 warn("Array @%s missing the @ in argument %d of %s()",
3232 name, numargs, op_name[type]);
3235 kid->op_sibling = sibl;
3238 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
3239 bad_type(numargs, "array", op, kid);
3243 if (kid->op_type == OP_CONST &&
3244 (kid->op_private & OPpCONST_BARE)) {
3245 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
3246 OP *newop = newHVREF(newGVOP(OP_GV, 0,
3247 gv_fetchpv(name, TRUE, SVt_PVHV) ));
3249 warn("Hash %%%s missing the %% in argument %d of %s()",
3250 name, numargs, op_name[type]);
3253 kid->op_sibling = sibl;
3256 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
3257 bad_type(numargs, "hash", op, kid);
3262 OP *newop = newUNOP(OP_NULL, 0, kid);
3263 kid->op_sibling = 0;
3265 newop->op_next = newop;
3267 kid->op_sibling = sibl;
3272 if (kid->op_type != OP_GV) {
3273 if (kid->op_type == OP_CONST &&
3274 (kid->op_private & OPpCONST_BARE)) {
3275 OP *newop = newGVOP(OP_GV, 0,
3276 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, na), TRUE,
3282 kid->op_sibling = 0;
3283 kid = newUNOP(OP_RV2GV, 0, scalar(kid));
3285 kid->op_sibling = sibl;
3291 mod(scalar(kid), type);
3295 tokid = &kid->op_sibling;
3296 kid = kid->op_sibling;
3298 op->op_private = numargs;
3300 return too_many_arguments(op);
3303 else if (opargs[type] & OA_DEFGV) {
3305 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3309 while (oa & OA_OPTIONAL)
3311 if (oa && oa != OA_LIST)
3312 return too_few_arguments(op);
3321 GV *gv = newGVgen("main");
3323 append_elem(OP_GLOB, op, newGVOP(OP_GV, 0, gv));
3334 OPCODE type = op->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
3336 op->op_ppaddr = ppaddr[OP_GREPSTART];
3337 Newz(1101, gwop, 1, LOGOP);
3339 if (op->op_flags & OPf_STACKED) {
3342 for (k = cLISTOP->op_first->op_sibling->op_next; k; k = k->op_next) {
3345 kid->op_next = (OP*)gwop;
3346 op->op_flags &= ~OPf_STACKED;
3348 kid = cLISTOP->op_first->op_sibling;
3349 if (type == OP_MAPWHILE)
3356 kid = cLISTOP->op_first->op_sibling;
3357 if (kid->op_type != OP_NULL)
3358 croak("panic: ck_grep");
3359 kid = kUNOP->op_first;
3361 gwop->op_type = type;
3362 gwop->op_ppaddr = ppaddr[type];
3363 gwop->op_first = listkids(op);
3364 gwop->op_flags |= OPf_KIDS;
3365 gwop->op_private = 1;
3366 gwop->op_other = LINKLIST(kid);
3367 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
3368 kid->op_next = (OP*)gwop;
3370 kid = cLISTOP->op_first->op_sibling;
3371 if (!kid || !kid->op_sibling)
3372 return too_few_arguments(op);
3373 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
3374 mod(kid, OP_GREPSTART);
3383 if (op->op_flags & OPf_KIDS) {
3384 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3385 if (kid && kid->op_type == OP_CONST)
3386 fbm_compile(((SVOP*)kid)->op_sv, 0);
3395 /* XXX length optimization goes here */
3403 return modkids(ck_fun(op), op->op_type);
3410 return refkids(ck_fun(op), op->op_type);
3419 kid = cLISTOP->op_first;
3421 op = force_list(op);
3422 kid = cLISTOP->op_first;
3424 if (kid->op_type == OP_PUSHMARK)
3425 kid = kid->op_sibling;
3426 if (kid && op->op_flags & OPf_STACKED)
3427 kid = kid->op_sibling;
3428 else if (kid && !kid->op_sibling) { /* print HANDLE; */
3429 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
3430 op->op_flags |= OPf_STACKED; /* make it a filehandle */
3431 kid = newUNOP(OP_RV2GV, 0, scalar(kid));
3432 cLISTOP->op_first->op_sibling = kid;
3433 cLISTOP->op_last = kid;
3434 kid = kid->op_sibling;
3439 append_elem(op->op_type, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
3441 return listkids(op);
3448 cPMOP->op_pmflags |= PMf_RUNTIME;
3463 if (cBINOP->op_first->op_flags & OPf_PARENS) {
3464 op->op_private = OPpREPEAT_DOLIST;
3465 cBINOP->op_first = force_list(cBINOP->op_first);
3476 if (op->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
3477 SVOP *kid = (SVOP*)cUNOP->op_first;
3479 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
3481 for (s = SvPVX(kid->op_sv); *s; s++) {
3482 if (*s == ':' && s[1] == ':') {
3484 strcpy(s+1,s+2); /* known to be okay here */
3485 --SvCUR(kid->op_sv);
3488 sv_catpvn(kid->op_sv, ".pm", 3);
3498 croak("NOT IMPL LINE %d",__LINE__);
3507 if (op->op_flags & OPf_KIDS) {
3508 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3509 if (kid && kid->op_sibling) {
3510 op->op_type = OP_SSELECT;
3511 op->op_ppaddr = ppaddr[OP_SSELECT];
3513 return fold_constants(op);
3523 I32 type = op->op_type;
3525 if (!(op->op_flags & OPf_KIDS)) {
3527 return newUNOP(type, 0,
3528 scalar(newUNOP(OP_RV2AV, 0,
3529 scalar(newGVOP(OP_GV, 0,
3530 gv_fetchpv((subline ? "_" : "ARGV"), TRUE, SVt_PVAV) )))));
3532 return scalar(modkids(ck_fun(op), type));
3539 if (op->op_flags & OPf_STACKED) {
3540 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3542 kid = kUNOP->op_first; /* get past rv2gv */
3544 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
3546 if (kid->op_type == OP_SCOPE) {
3550 else if (kid->op_type == OP_LEAVE) {
3551 null(kid); /* wipe out leave */
3554 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
3555 if (k->op_next == kid)
3558 k = kLISTOP->op_first;
3562 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3563 null(kid); /* wipe out rv2gv */
3564 if (op->op_type == OP_SORT)
3568 op->op_flags |= OPf_SPECIAL;
3581 if (op->op_flags & OPf_STACKED)
3582 return no_fh_allowed(op);
3584 kid = cLISTOP->op_first;
3585 if (kid->op_type != OP_NULL)
3586 croak("panic: ck_split");
3587 kid = kid->op_sibling;
3588 op_free(cLISTOP->op_first);
3589 cLISTOP->op_first = kid;
3591 cLISTOP->op_first = kid = newSVOP(OP_CONST, 0, newSVpv(" ", 1));
3592 cLISTOP->op_last = kid; /* There was only one element previously */
3595 if (kid->op_type != OP_MATCH) {
3596 OP *sibl = kid->op_sibling;
3597 kid->op_sibling = 0;
3598 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
3599 if (cLISTOP->op_first == cLISTOP->op_last)
3600 cLISTOP->op_last = kid;
3601 cLISTOP->op_first = kid;
3602 kid->op_sibling = sibl;
3605 if (pm->op_pmshort && !(pm->op_pmflags & PMf_ALL)) {
3606 SvREFCNT_dec(pm->op_pmshort); /* can't use substring to optimize */
3610 kid->op_type = OP_PUSHRE;
3611 kid->op_ppaddr = ppaddr[OP_PUSHRE];
3614 if (!kid->op_sibling)
3615 append_elem(OP_SPLIT, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
3617 kid = kid->op_sibling;
3620 if (!kid->op_sibling)
3621 append_elem(OP_SPLIT, op, newSVOP(OP_CONST, 0, newSViv(0)));
3623 kid = kid->op_sibling;
3626 if (kid->op_sibling)
3627 return too_many_arguments(op);
3636 OP *o = ((cUNOP->op_first->op_sibling)
3637 ? cUNOP : ((UNOP*)cUNOP->op_first))->op_first->op_sibling;
3639 if (o->op_type == OP_RV2CV)
3640 null(o); /* disable rv2cv */
3641 op->op_private = (hints & HINT_STRICT_REFS);
3642 if (perldb && curstash != debstash)
3643 op->op_private |= OPpDEREF_DB;
3644 while (o = o->op_sibling)
3645 mod(o, OP_ENTERSUB);
3653 SvREADONLY_on(cSVOP->op_sv);
3661 if (op->op_flags & OPf_KIDS) {
3662 SVOP *kid = (SVOP*)cUNOP->op_first;
3664 if (kid->op_type == OP_NULL)
3665 kid = (SVOP*)kid->op_sibling;
3667 kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE))
3668 op->op_flags |= OPf_SPECIAL;
3673 /* A peephole optimizer. We visit the ops in the order they're to execute. */
3679 register OP* oldop = 0;
3680 if (!o || o->op_seq)
3685 for (; o; o = o->op_next) {
3689 switch (o->op_type) {
3692 curcop = ((COP*)o); /* for warnings */
3703 if (o->op_next->op_type == OP_STRINGIFY)
3705 o->op_seq = ++op_seqmax;
3708 if ((o->op_flags & (OPf_KNOW|OPf_LIST)) != (OPf_KNOW|OPf_LIST)) {
3709 o->op_seq = ++op_seqmax;
3710 break; /* Scalar stub must produce undef. List stub is noop */
3717 if (oldop && o->op_next) {
3718 oldop->op_next = o->op_next;
3721 o->op_seq = ++op_seqmax;
3725 if (o->op_next->op_type == OP_RV2SV) {
3726 if (!(o->op_next->op_private & (OPpDEREF_HV|OPpDEREF_AV))) {
3728 o->op_private |= o->op_next->op_private & OPpLVAL_INTRO;
3729 o->op_next = o->op_next->op_next;
3730 o->op_type = OP_GVSV;
3731 o->op_ppaddr = ppaddr[OP_GVSV];
3734 else if (o->op_next->op_type == OP_RV2AV) {
3735 OP* pop = o->op_next->op_next;
3737 if (pop->op_type == OP_CONST &&
3738 (op = pop->op_next) &&
3739 pop->op_next->op_type == OP_AELEM &&
3740 !(pop->op_next->op_private &
3741 (OPpDEREF_HV|OPpDEREF_AV|OPpLVAL_INTRO)) &&
3742 (i = SvIV(((SVOP*)pop)->op_sv) - compiling.cop_arybase)
3749 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
3750 o->op_next = pop->op_next->op_next;
3751 o->op_type = OP_AELEMFAST;
3752 o->op_ppaddr = ppaddr[OP_AELEMFAST];
3753 o->op_private = (U8)i;
3754 GvAVn((GV*)(((SVOP*)o)->op_sv));
3757 o->op_seq = ++op_seqmax;
3764 o->op_seq = ++op_seqmax;
3765 peep(cLOGOP->op_other);
3769 o->op_seq = ++op_seqmax;
3770 peep(cCONDOP->op_true);
3771 peep(cCONDOP->op_false);
3775 o->op_seq = ++op_seqmax;
3776 peep(cLOOP->op_redoop);
3777 peep(cLOOP->op_nextop);
3778 peep(cLOOP->op_lastop);
3783 o->op_seq = ++op_seqmax;
3784 peep(cPMOP->op_pmreplstart);
3788 o->op_seq = ++op_seqmax;
3789 if (dowarn && o->op_next && o->op_next->op_type == OP_NEXTSTATE) {
3790 if (o->op_next->op_sibling &&
3791 o->op_next->op_sibling->op_type != OP_DIE) {
3792 line_t oldline = curcop->cop_line;
3794 curcop->cop_line = ((COP*)o->op_next)->cop_line;
3795 warn("Statement unlikely to be reached");
3796 warn("(Maybe you meant system() when you said exec()?)\n");
3797 curcop->cop_line = oldline;
3802 o->op_seq = ++op_seqmax;