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));
29 static PADOFFSET pad_findlex _((char* name, PADOFFSET newoff, I32 seq,
30 CV* startcv, I32 cx_ix));
36 sprintf(tokenbuf,"Missing comma after first argument to %s function",
37 op_name[op->op_type]);
46 sprintf(tokenbuf,"Not enough arguments for %s", op_name[op->op_type]);
52 too_many_arguments(op)
55 sprintf(tokenbuf,"Too many arguments for %s", op_name[op->op_type]);
61 bad_type(n, t, op, kid)
67 sprintf(tokenbuf, "Type of arg %d to %s must be %s (not %s)",
68 (int) n, op_name[op->op_type], t, op_name[kid->op_type]);
77 int type = op->op_type;
78 if (type != OP_AELEM && type != OP_HELEM) {
79 sprintf(tokenbuf, "Can't use subscript on %s",
82 if (type == OP_RV2HV || type == OP_ENTERSUB)
83 warn("(Did you mean $ or @ instead of %c?)\n",
84 type == OP_RV2HV ? '%' : '&');
88 /* "register" allocation */
97 if (!(isALPHA(name[1]) || name[1] == '_' && (int)strlen(name) > 2)) {
98 if (!isprint(name[1]))
99 sprintf(name+1, "^%c", name[1] ^ 64); /* XXX is tokenbuf, really */
100 croak("Can't use global %s in \"my\"",name);
102 off = pad_alloc(OP_PADSV, SVs_PADMY);
104 sv_upgrade(sv, SVt_PVNV);
106 av_store(comppad_name, off, sv);
107 SvNVX(sv) = (double)999999999;
108 SvIVX(sv) = 0; /* Not yet introduced--see newSTATEOP */
109 if (!min_intro_pending)
110 min_intro_pending = off;
111 max_intro_pending = off;
113 av_store(comppad, off, (SV*)newAV());
114 else if (*name == '%')
115 av_store(comppad, off, (SV*)newHV());
116 SvPADMY_on(curpad[off]);
121 pad_findlex(name, newoff, seq, startcv, cx_ix)
132 register CONTEXT *cx;
135 for (cv = startcv; cv; cv = CvOUTSIDE(cv)) {
136 AV* curlist = CvPADLIST(cv);
137 SV** svp = av_fetch(curlist, 0, FALSE);
139 if (!svp || *svp == &sv_undef)
142 svp = AvARRAY(curname);
143 for (off = AvFILL(curname); off > 0; off--) {
144 if ((sv = svp[off]) &&
147 seq > (I32)SvNVX(sv) &&
148 strEQ(SvPVX(sv), name))
150 I32 depth = CvDEPTH(cv) ? CvDEPTH(cv) : 1;
151 AV *oldpad = (AV*)*av_fetch(curlist, depth, FALSE);
152 SV *oldsv = *av_fetch(oldpad, off, TRUE);
153 if (!newoff) { /* Not a mere clone operation. */
154 SV *sv = NEWSV(1103,0);
155 newoff = pad_alloc(OP_PADSV, SVs_PADMY);
156 sv_upgrade(sv, SVt_PVNV);
158 av_store(comppad_name, newoff, sv);
159 SvNVX(sv) = (double)curcop->cop_seq;
160 SvIVX(sv) = 999999999; /* A ref, intro immediately */
161 SvFLAGS(sv) |= SVf_FAKE;
163 av_store(comppad, newoff, SvREFCNT_inc(oldsv));
164 SvFLAGS(compcv) |= SVpcv_CLONE;
170 /* Nothing in current lexical context--try eval's context, if any.
171 * This is necessary to let the perldb get at lexically scoped variables.
172 * XXX This will also probably interact badly with eval tree caching.
176 for (i = cx_ix; i >= 0; i--) {
178 switch (cx->cx_type) {
180 if (i == 0 && saweval) {
181 seq = cxstack[saweval].blk_oldcop->cop_seq;
182 return pad_findlex(name, newoff, seq, main_cv, 0);
186 if (cx->blk_eval.old_op_type != OP_ENTEREVAL)
187 return 0; /* require must have its own scope */
194 if (debstash && CvSTASH(cv) == debstash) { /* ignore DB'* scope */
195 saweval = i; /* so we know where we were called from */
198 seq = cxstack[saweval].blk_oldcop->cop_seq;
199 return pad_findlex(name, newoff, seq, cv, i-1);
212 SV **svp = AvARRAY(comppad_name);
213 I32 seq = cop_seqmax;
215 /* The one we're looking for is probably just before comppad_name_fill. */
216 for (off = comppad_name_fill; off > 0; off--) {
217 if ((sv = svp[off]) &&
220 seq > (I32)SvNVX(sv) &&
221 strEQ(SvPVX(sv), name))
223 return (PADOFFSET)off;
227 /* See if it's in a nested scope */
228 off = pad_findlex(name, 0, seq, CvOUTSIDE(compcv), cxstack_ix);
240 SV **svp = AvARRAY(comppad_name);
242 if (min_intro_pending && fill < min_intro_pending) {
243 for (off = max_intro_pending; off >= min_intro_pending; off--) {
244 if ((sv = svp[off]) && sv != &sv_undef)
245 warn("%s never introduced", SvPVX(sv));
248 /* "Deintroduce" my variables that are leaving with this scope. */
249 for (off = AvFILL(comppad_name); off > fill; off--) {
250 if ((sv = svp[off]) && sv != &sv_undef && SvIVX(sv) == 999999999)
251 SvIVX(sv) = cop_seqmax;
256 pad_alloc(optype,tmptype)
263 if (AvARRAY(comppad) != curpad)
264 croak("panic: pad_alloc");
265 if (pad_reset_pending)
267 if (tmptype & SVs_PADMY) {
269 sv = *av_fetch(comppad, AvFILL(comppad) + 1, TRUE);
270 } while (SvPADBUSY(sv)); /* need a fresh one */
271 retval = AvFILL(comppad);
275 sv = *av_fetch(comppad, ++padix, TRUE);
276 } while (SvFLAGS(sv) & (SVs_PADTMP|SVs_PADMY));
279 SvFLAGS(sv) |= tmptype;
280 curpad = AvARRAY(comppad);
281 DEBUG_X(fprintf(stderr, "Pad alloc %ld for %s\n", (long) retval, op_name[optype]));
282 return (PADOFFSET)retval;
286 #ifndef CAN_PROTOTYPE
291 #endif /* CAN_PROTOTYPE */
294 croak("panic: pad_sv po");
295 DEBUG_X(fprintf(stderr, "Pad sv %d\n", po));
296 return curpad[po]; /* eventually we'll turn this into a macro */
300 #ifndef CAN_PROTOTYPE
304 pad_free(PADOFFSET po)
305 #endif /* CAN_PROTOTYPE */
309 if (AvARRAY(comppad) != curpad)
310 croak("panic: pad_free curpad");
312 croak("panic: pad_free po");
313 DEBUG_X(fprintf(stderr, "Pad free %d\n", po));
314 if (curpad[po] && curpad[po] != &sv_undef)
315 SvPADTMP_off(curpad[po]);
321 #ifndef CAN_PROTOTYPE
325 pad_swipe(PADOFFSET po)
326 #endif /* CAN_PROTOTYPE */
328 if (AvARRAY(comppad) != curpad)
329 croak("panic: pad_swipe curpad");
331 croak("panic: pad_swipe po");
332 DEBUG_X(fprintf(stderr, "Pad swipe %d\n", po));
333 SvPADTMP_off(curpad[po]);
334 curpad[po] = NEWSV(1107,0);
335 SvPADTMP_on(curpad[po]);
345 if (AvARRAY(comppad) != curpad)
346 croak("panic: pad_reset curpad");
347 DEBUG_X(fprintf(stderr, "Pad reset\n"));
348 if (!tainting) { /* Can't mix tainted and non-tainted temporaries. */
349 for (po = AvMAX(comppad); po > padix_floor; po--) {
350 if (curpad[po] && curpad[po] != &sv_undef)
351 SvPADTMP_off(curpad[po]);
355 pad_reset_pending = FALSE;
364 register OP *kid, *nextkid;
369 if (op->op_flags & OPf_KIDS) {
370 for (kid = cUNOP->op_first; kid; kid = nextkid) {
371 nextkid = kid->op_sibling; /* Get before next freeing kid */
376 switch (op->op_type) {
378 op->op_targ = 0; /* Was holding old type, if any. */
381 op->op_targ = 0; /* Was holding hints. */
385 SvREFCNT_dec(cGVOP->op_gv);
389 SvREFCNT_dec(cCOP->cop_filegv);
392 SvREFCNT_dec(cSVOP->op_sv);
398 if (op->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
402 Safefree(cPVOP->op_pv);
405 op_free(cPMOP->op_pmreplroot);
409 regfree(cPMOP->op_pmregexp);
410 SvREFCNT_dec(cPMOP->op_pmshort);
417 pad_free(op->op_targ);
426 if (op->op_type != OP_NULL && op->op_targ > 0)
427 pad_free(op->op_targ);
428 op->op_targ = op->op_type;
429 op->op_type = OP_NULL;
430 op->op_ppaddr = ppaddr[OP_NULL];
433 /* Contextualizers */
435 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
446 /* establish postfix order */
447 if (cUNOP->op_first) {
448 op->op_next = LINKLIST(cUNOP->op_first);
449 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
451 kid->op_next = LINKLIST(kid->op_sibling);
467 if (op && op->op_flags & OPf_KIDS) {
468 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
479 op->op_type == OP_SASSIGN && cBINOP->op_first->op_type == OP_CONST) {
480 line_t oldline = curcop->cop_line;
482 if (copline != NOLINE)
483 curcop->cop_line = copline;
484 warn("Found = in conditional, should be ==");
485 curcop->cop_line = oldline;
496 /* assumes no premature commitment */
497 if (!op || (op->op_flags & OPf_KNOW) || error_count)
500 op->op_flags &= ~OPf_LIST;
501 op->op_flags |= OPf_KNOW;
503 switch (op->op_type) {
505 scalar(cBINOP->op_first);
510 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
514 if ((kid = ((LISTOP*)op)->op_first) && kid->op_type == OP_PUSHRE) {
515 if (!kPMOP->op_pmreplroot)
516 deprecate("implicit split to @_");
523 if (op->op_flags & OPf_KIDS) {
524 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling)
530 scalar(cLISTOP->op_first);
535 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
555 if (!op || error_count)
557 if (op->op_flags & OPf_LIST)
560 op->op_flags |= OPf_KNOW;
562 switch (op->op_type) {
564 if (!(opargs[op->op_type] & OA_FOLDCONST))
566 if (op->op_flags & OPf_STACKED)
640 if (!(op->op_private & OPpLVAL_INTRO))
641 useless = op_name[op->op_type];
648 if (!(op->op_private & OPpLVAL_INTRO) &&
649 (!op->op_sibling || op->op_sibling->op_type != OP_READLINE))
650 useless = "a variable";
655 curcop = ((COP*)op); /* for warning below */
661 useless = "a constant";
662 if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
664 else if (SvPOK(sv)) {
665 if (strnEQ(SvPVX(sv), "di", 2) ||
666 strnEQ(SvPVX(sv), "ds", 2) ||
667 strnEQ(SvPVX(sv), "ig", 2))
671 null(op); /* don't execute a constant */
672 SvREFCNT_dec(sv); /* don't even remember it */
676 op->op_type = OP_PREINC; /* pre-increment is faster */
677 op->op_ppaddr = ppaddr[OP_PREINC];
681 op->op_type = OP_PREDEC; /* pre-decrement is faster */
682 op->op_ppaddr = ppaddr[OP_PREDEC];
686 scalarvoid(cBINOP->op_first);
687 useless = op_name[op->op_type];
693 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
697 if (op->op_targ == OP_NEXTSTATE || op->op_targ == OP_DBSTATE)
698 curcop = ((COP*)op); /* for warning below */
699 if (op->op_flags & OPf_STACKED)
704 if (!(op->op_flags & OPf_KIDS))
710 op->op_private |= OPpLEAVE_VOID;
713 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
717 if ((kid = ((LISTOP*)op)->op_first) && kid->op_type == OP_PUSHRE) {
718 if (!kPMOP->op_pmreplroot)
719 deprecate("implicit split to @_");
723 op->op_private |= OPpLEAVE_VOID;
726 if (useless && dowarn)
727 warn("Useless use of %s in void context", useless);
736 if (op && op->op_flags & OPf_KIDS) {
737 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
749 /* assumes no premature commitment */
750 if (!op || (op->op_flags & OPf_KNOW) || error_count)
753 op->op_flags |= (OPf_KNOW | OPf_LIST);
755 switch (op->op_type) {
758 list(cBINOP->op_first);
763 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
770 if (!(op->op_flags & OPf_KIDS))
772 if (!op->op_next && cUNOP->op_first->op_type == OP_FLOP) {
773 list(cBINOP->op_first);
774 return gen_constant_list(op);
781 list(cLISTOP->op_first);
785 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
804 if (op->op_type == OP_LINESEQ ||
805 op->op_type == OP_SCOPE ||
806 op->op_type == OP_LEAVE ||
807 op->op_type == OP_LEAVETRY)
809 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
810 if (kid->op_sibling) {
816 op->op_flags &= ~OPf_PARENS;
817 if (hints & HINT_BLOCK_SCOPE)
818 op->op_flags |= OPf_PARENS;
821 op = newOP(OP_STUB, 0);
831 if (op && op->op_flags & OPf_KIDS) {
832 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
849 if (!op || error_count)
852 switch (op->op_type) {
854 if (!(op->op_private & (OPpCONST_ARYBASE)))
856 if (eval_start && eval_start->op_type == OP_CONST) {
857 compiling.cop_arybase = (I32)SvIV(((SVOP*)eval_start)->op_sv);
861 SAVEI32(compiling.cop_arybase);
862 compiling.cop_arybase = 0;
864 else if (type == OP_REFGEN)
867 croak("That use of $[ is unsupported");
870 if ((type == OP_UNDEF || type == OP_REFGEN) &&
871 !(op->op_flags & OPf_STACKED)) {
872 op->op_type = OP_RV2CV; /* entersub => rv2cv */
873 op->op_ppaddr = ppaddr[OP_RV2CV];
874 assert(cUNOP->op_first->op_type == OP_NULL);
875 null(((LISTOP*)cUNOP->op_first)->op_first); /* disable pushmark */
881 /* grep, foreach, subcalls, refgen */
882 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
884 sprintf(tokenbuf, "Can't modify %s in %s",
885 op_name[op->op_type],
886 type ? op_name[type] : "local");
910 if (!(op->op_flags & OPf_STACKED))
916 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
922 if (type == OP_REFGEN && op->op_flags & OPf_PARENS) {
924 return op; /* Treat \(@foo) like ordinary list. */
928 ref(cUNOP->op_first, op->op_type);
940 ref(cUNOP->op_first, op->op_type);
957 croak("Can't localize lexical variable %s",
958 SvPV(*av_fetch(comppad_name, op->op_targ, 4), na));
973 pad_free(op->op_targ);
974 op->op_targ = pad_alloc(op->op_type, SVs_PADMY);
975 sv = PAD_SV(op->op_targ);
976 sv_upgrade(sv, SVt_PVLV);
977 sv_magic(sv, Nullsv, mtype, Nullch, 0);
978 curpad[op->op_targ] = sv;
979 if (op->op_flags & OPf_KIDS)
980 mod(cBINOP->op_first, type);
985 ref(cBINOP->op_first, op->op_type);
992 if (op->op_flags & OPf_KIDS)
993 mod(cLISTOP->op_last, type);
997 if (!(op->op_flags & OPf_KIDS))
999 if (op->op_targ != OP_LIST) {
1000 mod(cBINOP->op_first, type);
1005 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1009 op->op_flags |= OPf_MOD;
1011 if (type == OP_AASSIGN || type == OP_SASSIGN)
1012 op->op_flags |= OPf_SPECIAL|OPf_REF;
1014 op->op_private |= OPpLVAL_INTRO;
1015 op->op_flags &= ~OPf_SPECIAL;
1017 else if (type != OP_GREPSTART && type != OP_ENTERSUB)
1018 op->op_flags |= OPf_REF;
1028 if (op && op->op_flags & OPf_KIDS) {
1029 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1042 if (!op || error_count)
1045 switch (op->op_type) {
1047 if ((type == OP_DEFINED) &&
1048 !(op->op_flags & OPf_STACKED)) {
1049 op->op_type = OP_RV2CV; /* entersub => rv2cv */
1050 op->op_ppaddr = ppaddr[OP_RV2CV];
1051 assert(cUNOP->op_first->op_type == OP_NULL);
1052 null(((LISTOP*)cUNOP->op_first)->op_first); /* disable pushmark */
1057 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
1061 ref(cUNOP->op_first, op->op_type);
1062 if (type == OP_RV2AV || type == OP_RV2HV) {
1063 op->op_private |= (type == OP_RV2AV ? OPpDEREF_AV : OPpDEREF_HV);
1064 op->op_flags |= OPf_MOD;
1070 op->op_flags |= OPf_REF;
1073 ref(cUNOP->op_first, op->op_type);
1078 op->op_flags |= OPf_REF;
1083 if (!(op->op_flags & OPf_KIDS))
1085 ref(cBINOP->op_first, type);
1089 ref(cBINOP->op_first, op->op_type);
1090 if (type == OP_RV2AV || type == OP_RV2HV) {
1091 op->op_private |= (type == OP_RV2AV ? OPpDEREF_AV : OPpDEREF_HV);
1092 op->op_flags |= OPf_MOD;
1100 if (!(op->op_flags & OPf_KIDS))
1102 ref(cLISTOP->op_last, type);
1118 if (!op || error_count)
1122 if (type == OP_LIST) {
1123 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1126 else if (type != OP_PADSV &&
1129 type != OP_PUSHMARK)
1131 sprintf(tokenbuf, "Can't declare %s in my", op_name[op->op_type]);
1135 op->op_flags |= OPf_MOD;
1136 op->op_private |= OPpLVAL_INTRO;
1145 o->op_flags |= OPf_PARENS;
1150 bind_match(type, left, right)
1157 if (right->op_type == OP_MATCH ||
1158 right->op_type == OP_SUBST ||
1159 right->op_type == OP_TRANS) {
1160 right->op_flags |= OPf_STACKED;
1161 if (right->op_type != OP_MATCH)
1162 left = mod(left, right->op_type);
1163 if (right->op_type == OP_TRANS)
1164 op = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
1166 op = prepend_elem(right->op_type, scalar(left), right);
1168 return newUNOP(OP_NOT, 0, scalar(op));
1172 return bind_match(type, left,
1173 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
1182 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
1183 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(op));
1191 if (o->op_flags & OPf_PARENS || perldb) {
1192 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
1193 o->op_type = OP_LEAVE;
1194 o->op_ppaddr = ppaddr[OP_LEAVE];
1197 if (o->op_type == OP_LINESEQ) {
1199 o->op_type = OP_SCOPE;
1200 o->op_ppaddr = ppaddr[OP_SCOPE];
1201 kid = ((LISTOP*)o)->op_first;
1202 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE){
1203 SvREFCNT_dec(((COP*)kid)->cop_filegv);
1208 o = newLISTOP(OP_SCOPE, 0, o, Nullop);
1217 int retval = savestack_ix;
1218 comppad_name_fill = AvFILL(comppad_name);
1219 SAVEINT(min_intro_pending);
1220 SAVEINT(max_intro_pending);
1221 min_intro_pending = 0;
1222 SAVEINT(comppad_name_fill);
1223 SAVEINT(padix_floor);
1224 padix_floor = padix;
1225 pad_reset_pending = FALSE;
1227 hints &= ~HINT_BLOCK_SCOPE;
1232 block_end(line, floor, seq)
1237 int needblockscope = hints & HINT_BLOCK_SCOPE;
1238 OP* retval = scalarseq(seq);
1239 if (copline > (line_t)line)
1242 pad_reset_pending = FALSE;
1244 hints |= HINT_BLOCK_SCOPE; /* propagate out */
1245 pad_leavemy(comppad_name_fill);
1254 eval_root = newUNOP(OP_LEAVEEVAL, 0, op);
1255 eval_start = linklist(eval_root);
1256 eval_root->op_next = 0;
1264 main_root = scope(sawparens(scalarvoid(op)));
1265 curcop = &compiling;
1266 main_start = LINKLIST(main_root);
1267 main_root->op_next = 0;
1279 if (o->op_flags & OPf_PARENS)
1283 if (dowarn && bufptr > oldbufptr && bufptr[-1] == ',') {
1285 for (s = bufptr; *s && (isALNUM(*s) || strchr("@$%, ",*s)); s++) ;
1286 if (*s == ';' || *s == '=')
1287 warn("Parens missing around \"%s\" list", lex ? "my" : "local");
1294 return mod(o, OP_NULL); /* a bit kludgey */
1301 if (o->op_type == OP_LIST) {
1302 o = convert(OP_JOIN, 0,
1303 prepend_elem(OP_LIST,
1304 newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
1315 I32 type = o->op_type;
1318 if (opargs[type] & OA_RETSCALAR)
1320 if (opargs[type] & OA_TARGET)
1321 o->op_targ = pad_alloc(type, SVs_PADTMP);
1323 if ((opargs[type] & OA_OTHERINT) && (hints & HINT_INTEGER))
1324 o->op_ppaddr = ppaddr[type = ++(o->op_type)];
1326 if (!(opargs[type] & OA_FOLDCONST))
1330 goto nope; /* Don't try to run w/ errors */
1332 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
1333 if (curop->op_type != OP_CONST &&
1334 curop->op_type != OP_LIST &&
1335 curop->op_type != OP_SCALAR &&
1336 curop->op_type != OP_NULL &&
1337 curop->op_type != OP_PUSHMARK) {
1342 curop = LINKLIST(o);
1347 if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
1348 pad_swipe(o->op_targ);
1349 else if (SvTEMP(sv)) { /* grab mortal temp? */
1350 (void)SvREFCNT_inc(sv);
1354 if (type == OP_RV2GV)
1355 return newGVOP(OP_GV, 0, sv);
1357 if ((SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK)) == SVf_NOK) {
1359 if ((double)iv == SvNV(sv)) { /* can we smush double to int */
1364 return newSVOP(OP_CONST, 0, sv);
1368 if (!(opargs[type] & OA_OTHERINT))
1371 if (!(hints & HINT_INTEGER)) {
1372 if (type == OP_DIVIDE || !(o->op_flags & OPf_KIDS))
1375 for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
1376 if (curop->op_type == OP_CONST) {
1377 if (SvIOK(((SVOP*)curop)->op_sv))
1381 if (opargs[curop->op_type] & OA_RETINTEGER)
1385 o->op_ppaddr = ppaddr[++(o->op_type)];
1392 gen_constant_list(o)
1396 I32 oldtmps_floor = tmps_floor;
1400 return o; /* Don't attempt to run with errors */
1402 op = curop = LINKLIST(o);
1408 tmps_floor = oldtmps_floor;
1410 o->op_type = OP_RV2AV;
1411 o->op_ppaddr = ppaddr[OP_RV2AV];
1412 curop = ((UNOP*)o)->op_first;
1413 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*stack_sp--));
1420 convert(type, flags, op)
1428 if (!op || op->op_type != OP_LIST)
1429 op = newLISTOP(OP_LIST, 0, op, Nullop);
1431 op->op_flags &= ~(OPf_KNOW|OPf_LIST);
1433 if (!(opargs[type] & OA_MARK))
1434 null(cLISTOP->op_first);
1437 op->op_ppaddr = ppaddr[type];
1438 op->op_flags |= flags;
1440 op = (*check[type])(op);
1441 if (op->op_type != type)
1444 if (cLISTOP->op_children < 7) {
1445 /* XXX do we really need to do this if we're done appending?? */
1446 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1448 cLISTOP->op_last = last; /* in case check substituted last arg */
1451 return fold_constants(op);
1454 /* List constructors */
1457 append_elem(type, first, last)
1468 if (first->op_type != type || type==OP_LIST && first->op_flags & OPf_PARENS)
1469 return newLISTOP(type, 0, first, last);
1471 if (first->op_flags & OPf_KIDS)
1472 ((LISTOP*)first)->op_last->op_sibling = last;
1474 first->op_flags |= OPf_KIDS;
1475 ((LISTOP*)first)->op_first = last;
1477 ((LISTOP*)first)->op_last = last;
1478 ((LISTOP*)first)->op_children++;
1483 append_list(type, first, last)
1494 if (first->op_type != type)
1495 return prepend_elem(type, (OP*)first, (OP*)last);
1497 if (last->op_type != type)
1498 return append_elem(type, (OP*)first, (OP*)last);
1500 first->op_last->op_sibling = last->op_first;
1501 first->op_last = last->op_last;
1502 first->op_children += last->op_children;
1503 if (first->op_children)
1504 last->op_flags |= OPf_KIDS;
1511 prepend_elem(type, first, last)
1522 if (last->op_type == type) {
1523 if (type == OP_LIST) { /* already a PUSHMARK there */
1524 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
1525 ((LISTOP*)last)->op_first->op_sibling = first;
1528 if (!(last->op_flags & OPf_KIDS)) {
1529 ((LISTOP*)last)->op_last = first;
1530 last->op_flags |= OPf_KIDS;
1532 first->op_sibling = ((LISTOP*)last)->op_first;
1533 ((LISTOP*)last)->op_first = first;
1535 ((LISTOP*)last)->op_children++;
1539 return newLISTOP(type, 0, first, last);
1547 return newOP(OP_STUB, 0);
1554 if (!op || op->op_type != OP_LIST)
1555 op = newLISTOP(OP_LIST, 0, op, Nullop);
1561 newLISTOP(type, flags, first, last)
1569 Newz(1101, listop, 1, LISTOP);
1571 listop->op_type = type;
1572 listop->op_ppaddr = ppaddr[type];
1573 listop->op_children = (first != 0) + (last != 0);
1574 listop->op_flags = flags;
1578 else if (!first && last)
1581 first->op_sibling = last;
1582 listop->op_first = first;
1583 listop->op_last = last;
1584 if (type == OP_LIST) {
1586 pushop = newOP(OP_PUSHMARK, 0);
1587 pushop->op_sibling = first;
1588 listop->op_first = pushop;
1589 listop->op_flags |= OPf_KIDS;
1591 listop->op_last = pushop;
1593 else if (listop->op_children)
1594 listop->op_flags |= OPf_KIDS;
1605 Newz(1101, op, 1, OP);
1607 op->op_ppaddr = ppaddr[type];
1608 op->op_flags = flags;
1611 /* op->op_private = 0; */
1612 if (opargs[type] & OA_RETSCALAR)
1614 if (opargs[type] & OA_TARGET)
1615 op->op_targ = pad_alloc(type, SVs_PADTMP);
1616 return (*check[type])(op);
1620 newUNOP(type, flags, first)
1628 first = newOP(OP_STUB, 0);
1629 if (opargs[type] & OA_MARK)
1630 first = force_list(first);
1632 Newz(1101, unop, 1, UNOP);
1633 unop->op_type = type;
1634 unop->op_ppaddr = ppaddr[type];
1635 unop->op_first = first;
1636 unop->op_flags = flags | OPf_KIDS;
1637 unop->op_private = 1;
1639 unop = (UNOP*)(*check[type])((OP*)unop);
1643 return fold_constants((OP *) unop);
1647 newBINOP(type, flags, first, last)
1654 Newz(1101, binop, 1, BINOP);
1657 first = newOP(OP_NULL, 0);
1659 binop->op_type = type;
1660 binop->op_ppaddr = ppaddr[type];
1661 binop->op_first = first;
1662 binop->op_flags = flags | OPf_KIDS;
1665 binop->op_private = 1;
1668 binop->op_private = 2;
1669 first->op_sibling = last;
1672 binop = (BINOP*)(*check[type])((OP*)binop);
1676 binop->op_last = last = binop->op_first->op_sibling;
1678 return fold_constants((OP *)binop);
1682 pmtrans(op, expr, repl)
1687 SV *tstr = ((SVOP*)expr)->op_sv;
1688 SV *rstr = ((SVOP*)repl)->op_sv;
1691 register char *t = SvPV(tstr, tlen);
1692 register char *r = SvPV(rstr, rlen);
1697 register short *tbl;
1699 tbl = (short*)cPVOP->op_pv;
1700 complement = op->op_private & OPpTRANS_COMPLEMENT;
1701 delete = op->op_private & OPpTRANS_DELETE;
1702 /* squash = op->op_private & OPpTRANS_SQUASH; */
1705 Zero(tbl, 256, short);
1706 for (i = 0; i < tlen; i++)
1707 tbl[t[i] & 0377] = -1;
1708 for (i = 0, j = 0; i < 256; i++) {
1714 tbl[i] = r[j-1] & 0377;
1719 tbl[i] = r[j++] & 0377;
1724 if (!rlen && !delete) {
1727 for (i = 0; i < 256; i++)
1729 for (i = 0, j = 0; i < tlen; i++,j++) {
1732 if (tbl[t[i] & 0377] == -1)
1733 tbl[t[i] & 0377] = -2;
1738 if (tbl[t[i] & 0377] == -1)
1739 tbl[t[i] & 0377] = r[j] & 0377;
1749 newPMOP(type, flags)
1755 Newz(1101, pmop, 1, PMOP);
1756 pmop->op_type = type;
1757 pmop->op_ppaddr = ppaddr[type];
1758 pmop->op_flags = flags;
1759 pmop->op_private = 0;
1761 /* link into pm list */
1762 if (type != OP_TRANS && curstash) {
1763 pmop->op_pmnext = HvPMROOT(curstash);
1764 HvPMROOT(curstash) = pmop;
1771 pmruntime(op, expr, repl)
1779 if (op->op_type == OP_TRANS)
1780 return pmtrans(op, expr, repl);
1784 if (expr->op_type == OP_CONST) {
1786 SV *pat = ((SVOP*)expr)->op_sv;
1787 char *p = SvPV(pat, plen);
1788 if ((op->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
1789 sv_setpvn(pat, "\\s+", 3);
1790 p = SvPV(pat, plen);
1791 pm->op_pmflags |= PMf_SKIPWHITE;
1793 pm->op_pmregexp = regcomp(p, p + plen, pm);
1794 if (strEQ("\\s+", pm->op_pmregexp->precomp))
1795 pm->op_pmflags |= PMf_WHITE;
1800 if (pm->op_pmflags & PMf_KEEP)
1801 expr = newUNOP(OP_REGCMAYBE,0,expr);
1803 Newz(1101, rcop, 1, LOGOP);
1804 rcop->op_type = OP_REGCOMP;
1805 rcop->op_ppaddr = ppaddr[OP_REGCOMP];
1806 rcop->op_first = scalar(expr);
1807 rcop->op_flags |= OPf_KIDS;
1808 rcop->op_private = 1;
1809 rcop->op_other = op;
1811 /* establish postfix order */
1812 if (pm->op_pmflags & PMf_KEEP) {
1814 rcop->op_next = expr;
1815 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
1818 rcop->op_next = LINKLIST(expr);
1819 expr->op_next = (OP*)rcop;
1822 prepend_elem(op->op_type, scalar((OP*)rcop), op);
1827 if (pm->op_pmflags & PMf_EVAL)
1829 else if (repl->op_type == OP_CONST)
1833 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
1834 if (opargs[curop->op_type] & OA_DANGEROUS) {
1835 if (curop->op_type == OP_GV) {
1836 GV *gv = ((GVOP*)curop)->op_gv;
1837 if (strchr("&`'123456789+", *GvENAME(gv)))
1840 else if (curop->op_type == OP_RV2CV)
1842 else if (curop->op_type == OP_RV2SV ||
1843 curop->op_type == OP_RV2AV ||
1844 curop->op_type == OP_RV2HV ||
1845 curop->op_type == OP_RV2GV) {
1846 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
1849 else if (curop->op_type == OP_PADSV ||
1850 curop->op_type == OP_PADAV ||
1851 curop->op_type == OP_PADHV ||
1852 curop->op_type == OP_PADANY) {
1861 if (curop == repl) {
1862 pm->op_pmflags |= PMf_CONST; /* const for long enough */
1863 prepend_elem(op->op_type, scalar(repl), op);
1866 Newz(1101, rcop, 1, LOGOP);
1867 rcop->op_type = OP_SUBSTCONT;
1868 rcop->op_ppaddr = ppaddr[OP_SUBSTCONT];
1869 rcop->op_first = scalar(repl);
1870 rcop->op_flags |= OPf_KIDS;
1871 rcop->op_private = 1;
1872 rcop->op_other = op;
1874 /* establish postfix order */
1875 rcop->op_next = LINKLIST(repl);
1876 repl->op_next = (OP*)rcop;
1878 pm->op_pmreplroot = scalar((OP*)rcop);
1879 pm->op_pmreplstart = LINKLIST(rcop);
1888 newSVOP(type, flags, sv)
1894 Newz(1101, svop, 1, SVOP);
1895 svop->op_type = type;
1896 svop->op_ppaddr = ppaddr[type];
1898 svop->op_next = (OP*)svop;
1899 svop->op_flags = flags;
1900 if (opargs[type] & OA_RETSCALAR)
1902 if (opargs[type] & OA_TARGET)
1903 svop->op_targ = pad_alloc(type, SVs_PADTMP);
1904 return (*check[type])((OP*)svop);
1908 newGVOP(type, flags, gv)
1914 Newz(1101, gvop, 1, GVOP);
1915 gvop->op_type = type;
1916 gvop->op_ppaddr = ppaddr[type];
1917 gvop->op_gv = (GV*)SvREFCNT_inc(gv);
1918 gvop->op_next = (OP*)gvop;
1919 gvop->op_flags = flags;
1920 if (opargs[type] & OA_RETSCALAR)
1922 if (opargs[type] & OA_TARGET)
1923 gvop->op_targ = pad_alloc(type, SVs_PADTMP);
1924 return (*check[type])((OP*)gvop);
1928 newPVOP(type, flags, pv)
1934 Newz(1101, pvop, 1, PVOP);
1935 pvop->op_type = type;
1936 pvop->op_ppaddr = ppaddr[type];
1938 pvop->op_next = (OP*)pvop;
1939 pvop->op_flags = flags;
1940 if (opargs[type] & OA_RETSCALAR)
1942 if (opargs[type] & OA_TARGET)
1943 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
1944 return (*check[type])((OP*)pvop);
1948 newCVOP(type, flags, cv, cont)
1955 Newz(1101, cvop, 1, CVOP);
1956 cvop->op_type = type;
1957 cvop->op_ppaddr = ppaddr[type];
1959 cvop->op_cont = cont;
1960 cvop->op_next = (OP*)cvop;
1961 cvop->op_flags = flags;
1962 if (opargs[type] & OA_RETSCALAR)
1964 if (opargs[type] & OA_TARGET)
1965 cvop->op_targ = pad_alloc(type, SVs_PADTMP);
1966 return (*check[type])((OP*)cvop);
1975 save_hptr(&curstash);
1976 save_item(curstname);
1981 name = SvPV(sv, len);
1982 curstash = gv_stashpv(name,TRUE);
1983 sv_setpvn(curstname, name, len);
1987 sv_setpv(curstname,"<none>");
1995 utilize(aver, id, arg)
2005 if (id->op_type != OP_CONST)
2006 croak("Module name must be constant");
2008 meth = newSVOP(OP_CONST, 0,
2010 ? newSVpv("import", 6)
2011 : newSVpv("unimport", 8)
2014 /* Make copy of id so we don't free it twice */
2015 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2017 /* Fake up a require */
2018 rqop = newUNOP(OP_REQUIRE, 0, id);
2020 /* Fake up an import/unimport */
2021 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2022 append_elem(OP_LIST,
2023 prepend_elem(OP_LIST, pack, list(arg)),
2024 newUNOP(OP_METHOD, 0, meth)));
2026 /* Fake up the BEGIN {}, which does its thing immediately. */
2027 newSUB(start_subparse(),
2028 newSVOP(OP_CONST, 0, newSVpv("BEGIN", 5)),
2029 append_elem(OP_LINESEQ,
2030 newSTATEOP(0, Nullch, rqop),
2031 newSTATEOP(0, Nullch, imop) ));
2038 newSLICEOP(flags, subscript, listval)
2043 return newBINOP(OP_LSLICE, flags,
2044 list(force_list(subscript)),
2045 list(force_list(listval)) );
2055 if (op->op_type == OP_NULL && op->op_flags & OPf_KIDS)
2056 op = cUNOP->op_first;
2058 if (op->op_type == OP_COND_EXPR) {
2059 I32 t = list_assignment(cCONDOP->op_first->op_sibling);
2060 I32 f = list_assignment(cCONDOP->op_first->op_sibling->op_sibling);
2065 yyerror("Assignment to both a list and a scalar");
2069 if (op->op_type == OP_LIST || op->op_flags & OPf_PARENS ||
2070 op->op_type == OP_RV2AV || op->op_type == OP_RV2HV ||
2071 op->op_type == OP_ASLICE || op->op_type == OP_HSLICE)
2074 if (op->op_type == OP_PADAV || op->op_type == OP_PADHV)
2077 if (op->op_type == OP_RV2SV)
2084 newASSIGNOP(flags, left, optype, right)
2093 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN) {
2094 return newLOGOP(optype, 0,
2095 mod(scalar(left), optype),
2096 newUNOP(OP_SASSIGN, 0, scalar(right)));
2099 return newBINOP(optype, OPf_STACKED,
2100 mod(scalar(left), optype), scalar(right));
2104 if (list_assignment(left)) {
2106 eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2107 left = mod(left, OP_AASSIGN);
2115 if (right && right->op_type == OP_SPLIT) {
2116 if ((op = ((LISTOP*)right)->op_first) && op->op_type == OP_PUSHRE) {
2117 PMOP *pm = (PMOP*)op;
2118 if (left->op_type == OP_RV2AV &&
2119 !(left->op_private & OPpLVAL_INTRO) )
2121 op = ((UNOP*)left)->op_first;
2122 if (op->op_type == OP_GV && !pm->op_pmreplroot) {
2123 pm->op_pmreplroot = (OP*)((GVOP*)op)->op_gv;
2124 pm->op_pmflags |= PMf_ONCE;
2130 if (modcount < 10000) {
2131 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
2133 sv_setiv(sv, modcount+1);
2138 op = newBINOP(OP_AASSIGN, flags,
2139 list(force_list(right)),
2140 list(force_list(left)) );
2142 if (!(left->op_private & OPpLVAL_INTRO)) {
2143 static int generation = 100;
2147 for (curop = LINKLIST(op); curop != op; curop = LINKLIST(curop)) {
2148 if (opargs[curop->op_type] & OA_DANGEROUS) {
2149 if (curop->op_type == OP_GV) {
2150 GV *gv = ((GVOP*)curop)->op_gv;
2151 if (gv == defgv || SvCUR(gv) == generation)
2153 SvCUR(gv) = generation;
2155 else if (curop->op_type == OP_PADSV ||
2156 curop->op_type == OP_PADAV ||
2157 curop->op_type == OP_PADHV ||
2158 curop->op_type == OP_PADANY) {
2159 SV **svp = AvARRAY(comppad_name);
2160 SV *sv = svp[curop->op_targ];;
2161 if (SvCUR(sv) == generation)
2163 SvCUR(sv) = generation; /* (SvCUR not used any more) */
2165 else if (curop->op_type == OP_RV2CV)
2167 else if (curop->op_type == OP_RV2SV ||
2168 curop->op_type == OP_RV2AV ||
2169 curop->op_type == OP_RV2HV ||
2170 curop->op_type == OP_RV2GV) {
2171 if (lastop->op_type != OP_GV) /* funny deref? */
2180 op->op_private = OPpASSIGN_COMMON;
2185 right = newOP(OP_UNDEF, 0);
2186 if (right->op_type == OP_READLINE) {
2187 right->op_flags |= OPf_STACKED;
2188 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
2191 eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2192 op = newBINOP(OP_SASSIGN, flags,
2193 scalar(right), mod(scalar(left), OP_SASSIGN) );
2205 newSTATEOP(flags, label, op)
2212 /* Introduce my variables. */
2213 if (min_intro_pending) {
2214 SV **svp = AvARRAY(comppad_name);
2217 for (i = min_intro_pending; i <= max_intro_pending; i++) {
2218 if ((sv = svp[i]) && sv != &sv_undef)
2219 SvIVX(sv) = 999999999; /* Don't know scope end yet. */
2220 SvNVX(sv) = (double)cop_seqmax;
2222 min_intro_pending = 0;
2223 comppad_name_fill = max_intro_pending; /* Needn't search higher */
2226 Newz(1101, cop, 1, COP);
2227 if (perldb && curcop->cop_line && curstash != debstash) {
2228 cop->op_type = OP_DBSTATE;
2229 cop->op_ppaddr = ppaddr[ OP_DBSTATE ];
2232 cop->op_type = OP_NEXTSTATE;
2233 cop->op_ppaddr = ppaddr[ OP_NEXTSTATE ];
2235 cop->op_flags = flags;
2236 cop->op_private = 0;
2237 cop->op_next = (OP*)cop;
2240 cop->cop_label = label;
2241 hints |= HINT_BLOCK_SCOPE;
2243 cop->cop_seq = cop_seqmax++;
2244 cop->cop_arybase = curcop->cop_arybase;
2246 if (copline == NOLINE)
2247 cop->cop_line = curcop->cop_line;
2249 cop->cop_line = copline;
2252 cop->cop_filegv = SvREFCNT_inc(curcop->cop_filegv);
2253 cop->cop_stash = curstash;
2255 if (perldb && curstash != debstash) {
2256 SV **svp = av_fetch(GvAV(curcop->cop_filegv),(I32)cop->cop_line, FALSE);
2257 if (svp && *svp != &sv_undef && !SvIOK(*svp)) {
2259 (void)SvIOK_on(*svp);
2260 SvSTASH(*svp) = (HV*)cop;
2264 return prepend_elem(OP_LINESEQ, (OP*)cop, op);
2268 newLOGOP(type, flags, first, other)
2277 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
2278 return newBINOP(type, flags, scalar(first), scalar(other));
2280 scalarboolean(first);
2281 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
2282 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
2283 if (type == OP_AND || type == OP_OR) {
2289 first = cUNOP->op_first;
2291 first->op_next = op->op_next;
2292 cUNOP->op_first = Nullop;
2296 if (first->op_type == OP_CONST) {
2297 if (dowarn && (first->op_private & OPpCONST_BARE))
2298 warn("Probable precedence problem on %s", op_name[type]);
2299 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
2308 else if (first->op_type == OP_WANTARRAY) {
2318 if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
2319 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
2321 Newz(1101, logop, 1, LOGOP);
2323 logop->op_type = type;
2324 logop->op_ppaddr = ppaddr[type];
2325 logop->op_first = first;
2326 logop->op_flags = flags | OPf_KIDS;
2327 logop->op_other = LINKLIST(other);
2328 logop->op_private = 1;
2330 /* establish postfix order */
2331 logop->op_next = LINKLIST(first);
2332 first->op_next = (OP*)logop;
2333 first->op_sibling = other;
2335 op = newUNOP(OP_NULL, 0, (OP*)logop);
2336 other->op_next = op;
2342 newCONDOP(flags, first, true, false)
2352 return newLOGOP(OP_AND, 0, first, true);
2354 return newLOGOP(OP_OR, 0, first, false);
2356 scalarboolean(first);
2357 if (first->op_type == OP_CONST) {
2358 if (SvTRUE(((SVOP*)first)->op_sv)) {
2369 else if (first->op_type == OP_WANTARRAY) {
2373 Newz(1101, condop, 1, CONDOP);
2375 condop->op_type = OP_COND_EXPR;
2376 condop->op_ppaddr = ppaddr[OP_COND_EXPR];
2377 condop->op_first = first;
2378 condop->op_flags = flags | OPf_KIDS;
2379 condop->op_true = LINKLIST(true);
2380 condop->op_false = LINKLIST(false);
2381 condop->op_private = 1;
2383 /* establish postfix order */
2384 condop->op_next = LINKLIST(first);
2385 first->op_next = (OP*)condop;
2387 first->op_sibling = true;
2388 true->op_sibling = false;
2389 op = newUNOP(OP_NULL, 0, (OP*)condop);
2392 false->op_next = op;
2398 newRANGE(flags, left, right)
2408 Newz(1101, condop, 1, CONDOP);
2410 condop->op_type = OP_RANGE;
2411 condop->op_ppaddr = ppaddr[OP_RANGE];
2412 condop->op_first = left;
2413 condop->op_flags = OPf_KIDS;
2414 condop->op_true = LINKLIST(left);
2415 condop->op_false = LINKLIST(right);
2416 condop->op_private = 1;
2418 left->op_sibling = right;
2420 condop->op_next = (OP*)condop;
2421 flip = newUNOP(OP_FLIP, flags, (OP*)condop);
2422 flop = newUNOP(OP_FLOP, 0, flip);
2423 op = newUNOP(OP_NULL, 0, flop);
2426 left->op_next = flip;
2427 right->op_next = flop;
2429 condop->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2430 sv_upgrade(PAD_SV(condop->op_targ), SVt_PVNV);
2431 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2432 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
2434 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2435 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2438 if (!flip->op_private || !flop->op_private)
2439 linklist(op); /* blow off optimizer unless constant */
2445 newLOOPOP(flags, debuggable, expr, block)
2453 int once = block && block->op_flags & OPf_SPECIAL &&
2454 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
2457 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
2458 return block; /* do {} while 0 does once */
2459 else if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB)
2460 expr = newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr);
2463 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
2464 op = newLOGOP(OP_AND, 0, expr, listop);
2466 ((LISTOP*)listop)->op_last->op_next = LINKLIST(op);
2468 if (once && op != listop)
2469 op->op_next = ((LOGOP*)cUNOP->op_first)->op_other;
2472 op = newUNOP(OP_NULL, 0, op); /* or do {} while 1 loses outer block */
2474 op->op_flags |= flags;
2476 op->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/
2481 newWHILEOP(flags, debuggable, loop, expr, block, cont)
2495 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB)) {
2496 expr = newUNOP(OP_DEFINED, 0,
2497 newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr) );
2501 block = newOP(OP_NULL, 0);
2504 next = LINKLIST(cont);
2506 cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
2508 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
2509 redo = LINKLIST(listop);
2512 op = newLOGOP(OP_AND, 0, expr, scalar(listop));
2513 if (op == expr && op->op_type == OP_CONST && !SvTRUE(cSVOP->op_sv)) {
2514 op_free(expr); /* oops, it's a while (0) */
2516 return Nullop; /* (listop already freed by newLOGOP) */
2518 ((LISTOP*)listop)->op_last->op_next = condop =
2519 (op == listop ? redo : LINKLIST(op));
2527 Newz(1101,loop,1,LOOP);
2528 loop->op_type = OP_ENTERLOOP;
2529 loop->op_ppaddr = ppaddr[OP_ENTERLOOP];
2530 loop->op_private = 0;
2531 loop->op_next = (OP*)loop;
2534 op = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, op);
2536 loop->op_redoop = redo;
2537 loop->op_lastop = op;
2540 loop->op_nextop = next;
2542 loop->op_nextop = op;
2544 op->op_flags |= flags;
2549 #ifndef CAN_PROTOTYPE
2550 newFOROP(flags,label,forline,sv,expr,block,cont)
2559 newFOROP(I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
2560 #endif /* CAN_PROTOTYPE */
2567 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
2568 sv->op_type = OP_RV2GV;
2569 sv->op_ppaddr = ppaddr[OP_RV2GV];
2571 else if (sv->op_type == OP_PADSV) { /* private variable */
2572 padoff = sv->op_targ;
2577 croak("Can't use %s for loop variable", op_name[sv->op_type]);
2580 sv = newGVOP(OP_GV, 0, defgv);
2582 loop = (LOOP*)list(convert(OP_ENTERITER, 0,
2583 append_elem(OP_LIST, mod(force_list(expr), OP_GREPSTART),
2585 assert(!loop->op_next);
2586 Renew(loop, 1, LOOP);
2587 loop->op_targ = padoff;
2588 return newSTATEOP(0, label, newWHILEOP(flags, 1, loop,
2589 newOP(OP_ITER, 0), block, cont));
2593 newLOOPEX(type, label)
2598 if (type != OP_GOTO || label->op_type == OP_CONST) {
2599 op = newPVOP(type, 0, savepv(
2600 label->op_type == OP_CONST
2601 ? SvPVx(((SVOP*)label)->op_sv, na)
2606 if (label->op_type == OP_ENTERSUB)
2607 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
2608 op = newUNOP(type, OPf_STACKED, label);
2610 hints |= HINT_BLOCK_SCOPE;
2618 if (!CvXSUB(cv) && CvROOT(cv)) {
2620 croak("Can't undef active subroutine");
2626 if (!SvFLAGS(cv) & SVpcv_CLONED)
2627 op_free(CvROOT(cv));
2628 CvROOT(cv) = Nullop;
2629 if (CvPADLIST(cv)) {
2630 I32 i = AvFILL(CvPADLIST(cv));
2632 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
2636 SvREFCNT_dec((SV*)CvPADLIST(cv));
2637 CvPADLIST(cv) = Nullav;
2639 SvREFCNT_dec(CvGV(cv));
2651 AV* protopadlist = CvPADLIST(proto);
2652 AV* protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
2653 AV* protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
2654 SV** svp = AvARRAY(protopad);
2663 cv = compcv = (CV*)NEWSV(1104,0);
2664 sv_upgrade((SV *)cv, SVt_PVCV);
2665 SvFLAGS(cv) |= SVpcv_CLONED;
2667 CvFILEGV(cv) = CvFILEGV(proto);
2668 CvGV(cv) = SvREFCNT_inc(CvGV(proto));
2669 CvSTASH(cv) = CvSTASH(proto);
2670 CvROOT(cv) = CvROOT(proto);
2671 CvSTART(cv) = CvSTART(proto);
2672 CvOUTSIDE(cv) = CvOUTSIDE(proto);
2676 comppadlist = newAV();
2677 AvREAL_off(comppadlist);
2678 av_store(comppadlist, 0, SvREFCNT_inc((SV*)protopad_name));
2679 av_store(comppadlist, 1, SvREFCNT_inc((SV*)comppad));
2680 CvPADLIST(cv) = comppadlist;
2681 av_extend(comppad, AvFILL(protopad));
2682 curpad = AvARRAY(comppad);
2684 av = newAV(); /* will be @_ */
2686 av_store(comppad, 0, (SV*)av);
2687 AvFLAGS(av) = AVf_REIFY;
2689 svp = AvARRAY(protopad_name);
2690 for ( ix = AvFILL(protopad); ix > 0; ix--) {
2692 if (svp[ix] != &sv_undef) {
2693 char *name = SvPVX(svp[ix]); /* XXX */
2694 if (SvFLAGS(svp[ix]) & SVf_FAKE) { /* lexical from outside? */
2695 I32 off = pad_findlex(name,ix,curcop->cop_seq, CvOUTSIDE(proto), cxstack_ix);
2697 croak("panic: cv_clone: %s", name);
2699 else { /* our own lexical */
2701 av_store(comppad, ix, sv = (SV*)newAV());
2702 else if (*name == '%')
2703 av_store(comppad, ix, sv = (SV*)newHV());
2705 av_store(comppad, ix, sv = NEWSV(0,0));
2710 av_store(comppad, ix, sv = NEWSV(0,0));
2720 newSUB(floor,op,block)
2726 char *name = op ? SvPVx(cSVOP->op_sv, na) : "__ANON__";
2727 GV *gv = gv_fetchpv(name, GV_ADDMULTI, SVt_PVCV);
2734 if (cv = GvCV(gv)) {
2736 cv = 0; /* just a cached method */
2737 else if (CvROOT(cv) || CvXSUB(cv) || GvFLAGS(gv) & GVf_IMPORTED) {
2738 if (dowarn) { /* already defined (or promised)? */
2739 line_t oldline = curcop->cop_line;
2741 curcop->cop_line = copline;
2742 warn("Subroutine %s redefined",name);
2743 curcop->cop_line = oldline;
2749 if (cv) { /* must reuse cv if autoloaded */
2751 assert(SvREFCNT(CvGV(cv)) > 1);
2752 SvREFCNT_dec(CvGV(cv));
2754 CvOUTSIDE(cv) = CvOUTSIDE(compcv);
2755 CvPADLIST(cv) = CvPADLIST(compcv);
2756 SvREFCNT_dec(compcv);
2763 CvFILEGV(cv) = curcop->cop_filegv;
2764 CvGV(cv) = SvREFCNT_inc(gv);
2765 CvSTASH(cv) = curstash;
2775 av = newAV(); /* Will be @_ */
2777 av_store(comppad, 0, (SV*)av);
2778 AvFLAGS(av) = AVf_REIFY;
2780 for (ix = AvFILL(comppad); ix > 0; ix--) {
2781 if (!SvPADMY(curpad[ix]))
2782 SvPADTMP_on(curpad[ix]);
2785 if (AvFILL(comppad_name) < AvFILL(comppad))
2786 av_store(comppad_name, AvFILL(comppad), Nullsv);
2788 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
2789 CvSTART(cv) = LINKLIST(CvROOT(cv));
2790 CvROOT(cv)->op_next = 0;
2792 if (s = strrchr(name,':'))
2796 if (strEQ(s, "BEGIN")) {
2797 line_t oldline = compiling.cop_line;
2800 SAVESPTR(compiling.cop_filegv);
2804 av_push(beginav, (SV *)cv);
2805 DEBUG_x( dump_sub(gv) );
2809 rspara = (nrslen == 2);
2816 curcop = &compiling;
2817 curcop->cop_line = oldline; /* might have recursed to yylex */
2820 else if (strEQ(s, "END")) {
2823 av_unshift(endav, 1);
2824 av_store(endav, 0, SvREFCNT_inc(cv));
2826 if (perldb && curstash != debstash) {
2828 SV *tmpstr = sv_newmortal();
2830 sprintf(buf,"%s:%ld",SvPVX(GvSV(curcop->cop_filegv)), (long)subline);
2831 sv = newSVpv(buf,0);
2833 sprintf(buf,"%ld",(long)curcop->cop_line);
2835 gv_efullname(tmpstr,gv);
2836 hv_store(GvHV(DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
2842 GvCV(gv) = 0; /* Will remember in SVOP instead. */
2843 SvFLAGS(cv) |= SVpcv_ANON;
2850 newXSUB(name, ix, subaddr, filename)
2856 CV* cv = newXS(name, (void(*)())subaddr, filename);
2857 CvOLDSTYLE(cv) = TRUE;
2858 CvXSUBANY(cv).any_i32 = ix;
2864 newXS(name, subaddr, filename)
2866 void (*subaddr) _((CV*));
2870 GV *gv = gv_fetchpv((name ? name : "__ANON__"), GV_ADDMULTI, SVt_PVCV);
2875 if (cv = GvCV(gv)) {
2877 cv = 0; /* just a cached method */
2878 else if (CvROOT(cv) || CvXSUB(cv)) { /* already defined? */
2880 line_t oldline = curcop->cop_line;
2882 curcop->cop_line = copline;
2883 warn("Subroutine %s redefined",name);
2884 curcop->cop_line = oldline;
2890 if (cv) { /* must reuse cv if autoloaded */
2891 assert(SvREFCNT(CvGV(cv)) > 1);
2892 SvREFCNT_dec(CvGV(cv));
2895 cv = (CV*)NEWSV(1105,0);
2896 sv_upgrade((SV *)cv, SVt_PVCV);
2899 CvGV(cv) = SvREFCNT_inc(gv);
2901 CvFILEGV(cv) = gv_fetchfile(filename);
2902 CvXSUB(cv) = subaddr;
2905 else if (s = strrchr(name,':'))
2909 if (strEQ(s, "BEGIN")) {
2912 av_push(beginav, SvREFCNT_inc(gv));
2914 else if (strEQ(s, "END")) {
2917 av_unshift(endav, 1);
2918 av_store(endav, 0, SvREFCNT_inc(gv));
2921 GvCV(gv) = 0; /* Will remember elsewhere instead. */
2922 SvFLAGS(cv) |= SVpcv_ANON;
2928 newFORM(floor,op,block)
2940 name = SvPVx(cSVOP->op_sv, na);
2943 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
2945 if (cv = GvFORM(gv)) {
2947 line_t oldline = curcop->cop_line;
2949 curcop->cop_line = copline;
2950 warn("Format %s redefined",name);
2951 curcop->cop_line = oldline;
2957 CvGV(cv) = SvREFCNT_inc(gv);
2958 CvFILEGV(cv) = curcop->cop_filegv;
2960 for (ix = AvFILL(comppad); ix > 0; ix--) {
2961 if (!SvPADMY(curpad[ix]))
2962 SvPADTMP_on(curpad[ix]);
2965 CvPADLIST(cv) = av = newAV();
2967 av_store(av, 1, SvREFCNT_inc((SV*)comppad));
2970 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
2971 CvSTART(cv) = LINKLIST(CvROOT(cv));
2972 CvROOT(cv)->op_next = 0;
2986 Newz(1101, mop, 1, LOGOP);
2987 mop->op_type = OP_METHOD;
2988 mop->op_ppaddr = ppaddr[OP_METHOD];
2989 mop->op_first = scalar(ref);
2990 mop->op_flags |= OPf_KIDS;
2991 mop->op_private = 1;
2992 mop->op_other = LINKLIST(name);
2993 mop->op_targ = pad_alloc(OP_METHOD, SVs_PADTMP);
2994 mop->op_next = LINKLIST(ref);
2995 ref->op_next = (OP*)mop;
2996 return scalar((OP*)mop);
3003 return newUNOP(OP_REFGEN, 0,
3004 mod(list(convert(OP_ANONLIST, 0, op)), OP_REFGEN));
3011 return newUNOP(OP_REFGEN, 0,
3012 mod(list(convert(OP_ANONHASH, 0, op)), OP_REFGEN));
3016 newANONSUB(floor, block)
3020 return newUNOP(OP_REFGEN, 0,
3021 newSVOP(OP_ANONCODE, 0, (SV*)newSUB(floor, 0, block)));
3028 switch (o->op_type) {
3030 o->op_type = OP_PADAV;
3031 o->op_ppaddr = ppaddr[OP_PADAV];
3032 return ref(newUNOP(OP_RV2AV, 0, scalar(o)), OP_RV2AV);
3035 o->op_type = OP_RV2AV;
3036 o->op_ppaddr = ppaddr[OP_RV2AV];
3041 warn("oops: oopsAV");
3051 switch (o->op_type) {
3054 o->op_type = OP_PADHV;
3055 o->op_ppaddr = ppaddr[OP_PADHV];
3056 return ref(newUNOP(OP_RV2HV, 0, scalar(o)), OP_RV2HV);
3060 o->op_type = OP_RV2HV;
3061 o->op_ppaddr = ppaddr[OP_RV2HV];
3066 warn("oops: oopsHV");
3076 if (o->op_type == OP_PADANY) {
3077 o->op_type = OP_PADAV;
3078 o->op_ppaddr = ppaddr[OP_PADAV];
3081 return newUNOP(OP_RV2AV, 0, scalar(o));
3089 if (type == OP_MAPSTART)
3090 return newUNOP(OP_NULL, 0, o);
3091 return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
3098 if (o->op_type == OP_PADANY) {
3099 o->op_type = OP_PADHV;
3100 o->op_ppaddr = ppaddr[OP_PADHV];
3103 return newUNOP(OP_RV2HV, 0, scalar(o));
3110 croak("NOT IMPL LINE %d",__LINE__);
3119 return newUNOP(OP_RV2CV, 0, scalar(o));
3126 if (o->op_type == OP_PADANY) {
3127 o->op_type = OP_PADSV;
3128 o->op_ppaddr = ppaddr[OP_PADSV];
3131 return newUNOP(OP_RV2SV, 0, scalar(o));
3134 /* Check routines. */
3140 if (cUNOP->op_first->op_type == OP_CONCAT)
3141 op->op_flags |= OPf_STACKED;
3149 if (op->op_flags & OPf_KIDS) {
3152 op = modkids(ck_fun(op), op->op_type);
3153 kid = cUNOP->op_first;
3154 newop = kUNOP->op_first->op_sibling;
3156 (newop->op_sibling ||
3157 !(opargs[newop->op_type] & OA_RETSCALAR) ||
3158 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
3159 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
3163 op_free(kUNOP->op_first);
3164 kUNOP->op_first = newop;
3166 op->op_ppaddr = ppaddr[++op->op_type];
3175 if (op->op_flags & OPf_KIDS) {
3176 OP *kid = cUNOP->op_first;
3177 if (kid->op_type != OP_HELEM)
3178 croak("%s argument is not a HASH element", op_name[op->op_type]);
3188 I32 type = op->op_type;
3190 if (op->op_flags & OPf_KIDS) {
3191 if (cLISTOP->op_first->op_type == OP_STUB) {
3193 op = newUNOP(type, OPf_SPECIAL,
3194 newGVOP(OP_GV, 0, gv_fetchpv("main'ARGV", TRUE, SVt_PVAV)));
3205 hints |= HINT_BLOCK_SCOPE;
3206 if (op->op_flags & OPf_KIDS) {
3207 SVOP *kid = (SVOP*)cUNOP->op_first;
3210 op->op_flags &= ~OPf_KIDS;
3213 else if (kid->op_type == OP_LINESEQ) {
3216 kid->op_next = op->op_next;
3217 cUNOP->op_first = 0;
3220 Newz(1101, enter, 1, LOGOP);
3221 enter->op_type = OP_ENTERTRY;
3222 enter->op_ppaddr = ppaddr[OP_ENTERTRY];
3223 enter->op_private = 0;
3225 /* establish postfix order */
3226 enter->op_next = (OP*)enter;
3228 op = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
3229 op->op_type = OP_LEAVETRY;
3230 op->op_ppaddr = ppaddr[OP_LEAVETRY];
3231 enter->op_other = op;
3237 op = newUNOP(OP_ENTEREVAL, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3239 op->op_targ = (PADOFFSET)hints;
3248 if (op->op_flags & OPf_STACKED) {
3250 kid = cUNOP->op_first->op_sibling;
3251 if (kid->op_type == OP_RV2GV)
3263 o = fold_constants(o);
3264 if (o->op_type == OP_CONST)
3273 SVOP *kid = (SVOP*)cUNOP->op_first;
3275 op->op_private = (hints & HINT_STRICT_REFS);
3276 if (kid->op_type == OP_CONST) {
3277 int iscv = (op->op_type==OP_RV2CV)*2;
3279 kid->op_type = OP_GV;
3280 for (gv = 0; !gv; iscv++) {
3282 * This is a little tricky. We only want to add the symbol if we
3283 * didn't add it in the lexer. Otherwise we get duplicate strict
3284 * warnings. But if we didn't add it in the lexer, we must at
3285 * least pretend like we wanted to add it even if it existed before,
3286 * or we get possible typo warnings. OPpCONST_ENTERED says
3287 * whether the lexer already added THIS instance of this symbol.
3289 gv = gv_fetchpv(SvPVx(kid->op_sv, na),
3290 iscv | !(kid->op_private & OPpCONST_ENTERED),
3293 : op->op_type == OP_RV2SV
3295 : op->op_type == OP_RV2AV
3297 : op->op_type == OP_RV2HV
3301 SvREFCNT_dec(kid->op_sv);
3302 kid->op_sv = SvREFCNT_inc(gv);
3318 I32 type = op->op_type;
3320 if (op->op_flags & OPf_REF)
3323 if (op->op_flags & OPf_KIDS) {
3324 SVOP *kid = (SVOP*)cUNOP->op_first;
3326 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
3327 OP *newop = newGVOP(type, OPf_REF,
3328 gv_fetchpv(SvPVx(kid->op_sv, na), TRUE, SVt_PVIO));
3335 if (type == OP_FTTTY)
3336 return newGVOP(type, OPf_REF, gv_fetchpv("main'STDIN", TRUE,
3339 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3352 int type = op->op_type;
3353 register I32 oa = opargs[type] >> OASHIFT;
3355 if (op->op_flags & OPf_STACKED) {
3356 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
3359 return no_fh_allowed(op);
3362 if (op->op_flags & OPf_KIDS) {
3363 tokid = &cLISTOP->op_first;
3364 kid = cLISTOP->op_first;
3365 if (kid->op_type == OP_PUSHMARK ||
3366 kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK)
3368 tokid = &kid->op_sibling;
3369 kid = kid->op_sibling;
3371 if (!kid && opargs[type] & OA_DEFGV)
3372 *tokid = kid = newSVREF(newGVOP(OP_GV, 0, defgv));
3376 sibl = kid->op_sibling;
3390 if (kid->op_type == OP_CONST &&
3391 (kid->op_private & OPpCONST_BARE)) {
3392 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
3393 OP *newop = newAVREF(newGVOP(OP_GV, 0,
3394 gv_fetchpv(name, TRUE, SVt_PVAV) ));
3396 warn("Array @%s missing the @ in argument %d of %s()",
3397 name, numargs, op_name[type]);
3400 kid->op_sibling = sibl;
3403 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
3404 bad_type(numargs, "array", op, kid);
3408 if (kid->op_type == OP_CONST &&
3409 (kid->op_private & OPpCONST_BARE)) {
3410 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
3411 OP *newop = newHVREF(newGVOP(OP_GV, 0,
3412 gv_fetchpv(name, TRUE, SVt_PVHV) ));
3414 warn("Hash %%%s missing the %% in argument %d of %s()",
3415 name, numargs, op_name[type]);
3418 kid->op_sibling = sibl;
3421 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
3422 bad_type(numargs, "hash", op, kid);
3427 OP *newop = newUNOP(OP_NULL, 0, kid);
3428 kid->op_sibling = 0;
3430 newop->op_next = newop;
3432 kid->op_sibling = sibl;
3437 if (kid->op_type != OP_GV) {
3438 if (kid->op_type == OP_CONST &&
3439 (kid->op_private & OPpCONST_BARE)) {
3440 OP *newop = newGVOP(OP_GV, 0,
3441 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, na), TRUE,
3447 kid->op_sibling = 0;
3448 kid = newUNOP(OP_RV2GV, 0, scalar(kid));
3450 kid->op_sibling = sibl;
3456 mod(scalar(kid), type);
3460 tokid = &kid->op_sibling;
3461 kid = kid->op_sibling;
3463 op->op_private = numargs;
3465 return too_many_arguments(op);
3468 else if (opargs[type] & OA_DEFGV) {
3470 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3474 while (oa & OA_OPTIONAL)
3476 if (oa && oa != OA_LIST)
3477 return too_few_arguments(op);
3486 GV *gv = newGVgen("main");
3488 append_elem(OP_GLOB, op, newGVOP(OP_GV, 0, gv));
3499 OPCODE type = op->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
3501 op->op_ppaddr = ppaddr[OP_GREPSTART];
3502 Newz(1101, gwop, 1, LOGOP);
3504 if (op->op_flags & OPf_STACKED) {
3507 for (k = cLISTOP->op_first->op_sibling->op_next; k; k = k->op_next) {
3510 kid->op_next = (OP*)gwop;
3511 op->op_flags &= ~OPf_STACKED;
3513 kid = cLISTOP->op_first->op_sibling;
3514 if (type == OP_MAPWHILE)
3521 kid = cLISTOP->op_first->op_sibling;
3522 if (kid->op_type != OP_NULL)
3523 croak("panic: ck_grep");
3524 kid = kUNOP->op_first;
3526 gwop->op_type = type;
3527 gwop->op_ppaddr = ppaddr[type];
3528 gwop->op_first = listkids(op);
3529 gwop->op_flags |= OPf_KIDS;
3530 gwop->op_private = 1;
3531 gwop->op_other = LINKLIST(kid);
3532 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
3533 kid->op_next = (OP*)gwop;
3535 kid = cLISTOP->op_first->op_sibling;
3536 if (!kid || !kid->op_sibling)
3537 return too_few_arguments(op);
3538 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
3539 mod(kid, OP_GREPSTART);
3548 if (op->op_flags & OPf_KIDS) {
3549 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3550 if (kid && kid->op_type == OP_CONST)
3551 fbm_compile(((SVOP*)kid)->op_sv, 0);
3560 /* XXX length optimization goes here */
3568 return modkids(ck_fun(op), op->op_type);
3575 return refkids(ck_fun(op), op->op_type);
3584 kid = cLISTOP->op_first;
3586 op = force_list(op);
3587 kid = cLISTOP->op_first;
3589 if (kid->op_type == OP_PUSHMARK)
3590 kid = kid->op_sibling;
3591 if (kid && op->op_flags & OPf_STACKED)
3592 kid = kid->op_sibling;
3593 else if (kid && !kid->op_sibling) { /* print HANDLE; */
3594 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
3595 op->op_flags |= OPf_STACKED; /* make it a filehandle */
3596 kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
3597 cLISTOP->op_first->op_sibling = kid;
3598 cLISTOP->op_last = kid;
3599 kid = kid->op_sibling;
3604 append_elem(op->op_type, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
3606 return listkids(op);
3613 cPMOP->op_pmflags |= PMf_RUNTIME;
3628 if (cBINOP->op_first->op_flags & OPf_PARENS) {
3629 op->op_private = OPpREPEAT_DOLIST;
3630 cBINOP->op_first = force_list(cBINOP->op_first);
3641 if (op->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
3642 SVOP *kid = (SVOP*)cUNOP->op_first;
3644 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
3646 for (s = SvPVX(kid->op_sv); *s; s++) {
3647 if (*s == ':' && s[1] == ':') {
3649 Move(s+2, s+1, strlen(s+2)+1, char);
3650 --SvCUR(kid->op_sv);
3653 sv_catpvn(kid->op_sv, ".pm", 3);
3663 croak("NOT IMPL LINE %d",__LINE__);
3672 if (op->op_flags & OPf_KIDS) {
3673 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3674 if (kid && kid->op_sibling) {
3675 op->op_type = OP_SSELECT;
3676 op->op_ppaddr = ppaddr[OP_SSELECT];
3678 return fold_constants(op);
3688 I32 type = op->op_type;
3690 if (!(op->op_flags & OPf_KIDS)) {
3692 return newUNOP(type, 0,
3693 scalar(newUNOP(OP_RV2AV, 0,
3694 scalar(newGVOP(OP_GV, 0,
3695 gv_fetchpv((subline ? "_" : "ARGV"), TRUE, SVt_PVAV) )))));
3697 return scalar(modkids(ck_fun(op), type));
3704 if (op->op_flags & OPf_STACKED) {
3705 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3707 kid = kUNOP->op_first; /* get past rv2gv */
3709 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
3711 if (kid->op_type == OP_SCOPE) {
3715 else if (kid->op_type == OP_LEAVE) {
3716 if (op->op_type == OP_SORT) {
3717 null(kid); /* wipe out leave */
3720 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
3721 if (k->op_next == kid)
3726 kid->op_next = 0; /* just disconnect the leave */
3727 k = kLISTOP->op_first;
3731 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3732 null(kid); /* wipe out rv2gv */
3733 if (op->op_type == OP_SORT)
3737 op->op_flags |= OPf_SPECIAL;
3750 if (op->op_flags & OPf_STACKED)
3751 return no_fh_allowed(op);
3753 kid = cLISTOP->op_first;
3754 if (kid->op_type != OP_NULL)
3755 croak("panic: ck_split");
3756 kid = kid->op_sibling;
3757 op_free(cLISTOP->op_first);
3758 cLISTOP->op_first = kid;
3760 cLISTOP->op_first = kid = newSVOP(OP_CONST, 0, newSVpv(" ", 1));
3761 cLISTOP->op_last = kid; /* There was only one element previously */
3764 if (kid->op_type != OP_MATCH) {
3765 OP *sibl = kid->op_sibling;
3766 kid->op_sibling = 0;
3767 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
3768 if (cLISTOP->op_first == cLISTOP->op_last)
3769 cLISTOP->op_last = kid;
3770 cLISTOP->op_first = kid;
3771 kid->op_sibling = sibl;
3774 if (pm->op_pmshort && !(pm->op_pmflags & PMf_ALL)) {
3775 SvREFCNT_dec(pm->op_pmshort); /* can't use substring to optimize */
3779 kid->op_type = OP_PUSHRE;
3780 kid->op_ppaddr = ppaddr[OP_PUSHRE];
3783 if (!kid->op_sibling)
3784 append_elem(OP_SPLIT, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
3786 kid = kid->op_sibling;
3789 if (!kid->op_sibling)
3790 append_elem(OP_SPLIT, op, newSVOP(OP_CONST, 0, newSViv(0)));
3792 kid = kid->op_sibling;
3795 if (kid->op_sibling)
3796 return too_many_arguments(op);
3805 OP *o = ((cUNOP->op_first->op_sibling)
3806 ? cUNOP : ((UNOP*)cUNOP->op_first))->op_first->op_sibling;
3808 if (o->op_type == OP_RV2CV)
3809 null(o); /* disable rv2cv */
3810 op->op_private = (hints & HINT_STRICT_REFS);
3811 if (perldb && curstash != debstash)
3812 op->op_private |= OPpDEREF_DB;
3813 while (o = o->op_sibling)
3814 mod(o, OP_ENTERSUB);
3822 SvREADONLY_on(cSVOP->op_sv);
3830 if (op->op_flags & OPf_KIDS) {
3831 SVOP *kid = (SVOP*)cUNOP->op_first;
3833 if (kid->op_type == OP_NULL)
3834 kid = (SVOP*)kid->op_sibling;
3836 kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE))
3837 op->op_flags |= OPf_SPECIAL;
3842 /* A peephole optimizer. We visit the ops in the order they're to execute. */
3848 register OP* oldop = 0;
3849 if (!o || o->op_seq)
3854 for (; o; o = o->op_next) {
3858 switch (o->op_type) {
3861 curcop = ((COP*)o); /* for warnings */
3862 o->op_seq = ++op_seqmax;
3873 if (o->op_next->op_type == OP_STRINGIFY)
3875 o->op_seq = ++op_seqmax;
3878 if ((o->op_flags & (OPf_KNOW|OPf_LIST)) != (OPf_KNOW|OPf_LIST)) {
3879 o->op_seq = ++op_seqmax;
3880 break; /* Scalar stub must produce undef. List stub is noop */
3884 if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE)
3885 curcop = ((COP*)op);
3891 if (oldop && o->op_next) {
3892 oldop->op_next = o->op_next;
3895 o->op_seq = ++op_seqmax;
3899 if (o->op_next->op_type == OP_RV2SV) {
3900 if (!(o->op_next->op_private & (OPpDEREF_HV|OPpDEREF_AV))) {
3902 o->op_private |= o->op_next->op_private & OPpLVAL_INTRO;
3903 o->op_next = o->op_next->op_next;
3904 o->op_type = OP_GVSV;
3905 o->op_ppaddr = ppaddr[OP_GVSV];
3908 else if (o->op_next->op_type == OP_RV2AV) {
3909 OP* pop = o->op_next->op_next;
3911 if (pop->op_type == OP_CONST &&
3912 (op = pop->op_next) &&
3913 pop->op_next->op_type == OP_AELEM &&
3914 !(pop->op_next->op_private &
3915 (OPpDEREF_HV|OPpDEREF_AV|OPpLVAL_INTRO)) &&
3916 (i = SvIV(((SVOP*)pop)->op_sv) - compiling.cop_arybase)
3920 SvREFCNT_dec(((SVOP*)pop)->op_sv);
3924 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
3925 o->op_next = pop->op_next->op_next;
3926 o->op_type = OP_AELEMFAST;
3927 o->op_ppaddr = ppaddr[OP_AELEMFAST];
3928 o->op_private = (U8)i;
3929 GvAVn((GV*)(((SVOP*)o)->op_sv));
3932 o->op_seq = ++op_seqmax;
3939 o->op_seq = ++op_seqmax;
3940 peep(cLOGOP->op_other);
3944 o->op_seq = ++op_seqmax;
3945 peep(cCONDOP->op_true);
3946 peep(cCONDOP->op_false);
3950 o->op_seq = ++op_seqmax;
3951 peep(cLOOP->op_redoop);
3952 peep(cLOOP->op_nextop);
3953 peep(cLOOP->op_lastop);
3958 o->op_seq = ++op_seqmax;
3959 peep(cPMOP->op_pmreplstart);
3963 o->op_seq = ++op_seqmax;
3964 if (dowarn && o->op_next && o->op_next->op_type == OP_NEXTSTATE) {
3965 if (o->op_next->op_sibling &&
3966 o->op_next->op_sibling->op_type != OP_DIE) {
3967 line_t oldline = curcop->cop_line;
3969 curcop->cop_line = ((COP*)o->op_next)->cop_line;
3970 warn("Statement unlikely to be reached");
3971 warn("(Maybe you meant system() when you said exec()?)\n");
3972 curcop->cop_line = oldline;
3977 o->op_seq = ++op_seqmax;