1 /* $RCSfile: cmd.h,v $$Revision: 4.1 $$Date: 92/08/07 17:19:19 $
3 * Copyright (c) 1991, 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.
16 /* Lowest byte of opargs */
18 #define OA_FOLDCONST 2
19 #define OA_RETSCALAR 4
21 #define OA_RETINTEGER 16
22 #define OA_OTHERINT 32
23 #define OA_DANGEROUS 64
25 /* Remaining nybbles of opargs */
32 #define OA_SCALARREF 7
54 if (bufptr > oldoldbufptr && bufptr - oldoldbufptr < 200 &&
55 oldoldbufptr != oldbufptr && oldbufptr != bufptr) {
56 while (isSPACE(*oldoldbufptr))
58 cpy7bit(tmp2buf, oldoldbufptr, bufptr - oldoldbufptr);
59 sprintf(tname,"next 2 tokens \"%s\"",tmp2buf);
61 else if (bufptr > oldbufptr && bufptr - oldbufptr < 200 &&
62 oldbufptr != bufptr) {
63 while (isSPACE(*oldbufptr))
65 cpy7bit(tmp2buf, oldbufptr, bufptr - oldbufptr);
66 sprintf(tname,"next token \"%s\"",tmp2buf);
68 else if (yychar > 255)
69 tname = "next token ???";
70 else if (!yychar || (yychar == ';' && !rsfp))
71 (void)strcpy(tname,"at EOF");
72 else if ((yychar & 127) == 127)
73 (void)strcpy(tname,"at end of line");
75 (void)sprintf(tname,"next char ^%c",yychar+64);
77 (void)sprintf(tname,"next char %c",yychar);
78 (void)sprintf(buf, "%s at %s line %d, %s\n",
79 s,SvPV(GvSV(curcop->cop_filegv)),curcop->cop_line,tname);
80 if (curcop->cop_line == multi_end && multi_start < multi_end)
81 sprintf(buf+strlen(buf),
82 " (Might be a runaway multi-line %c%c string starting on line %d)\n",
83 multi_open,multi_close,multi_start);
85 sv_catpv(GvSV(gv_fetchpv("@",TRUE)),buf);
88 if (++error_count >= 10)
89 fatal("%s has too many errors.\n",
90 SvPV(GvSV(curcop->cop_filegv)));
98 sprintf(tokenbuf,"Missing comma after first argument to %s function",
99 op_name[op->op_type]);
105 too_few_arguments(op)
108 sprintf(tokenbuf,"Not enough arguments for %s", op_name[op->op_type]);
114 too_many_arguments(op)
117 sprintf(tokenbuf,"Too many arguments for %s", op_name[op->op_type]);
122 /* "register" allocation */
128 PADOFFSET off = pad_alloc(OP_PADSV, 'M');
130 sv_upgrade(sv, SVt_PVNV);
132 av_store(comppadname, off, sv);
133 SvNV(sv) = (double)cop_seq;
136 av_store(comppad, off, newAV());
137 else if (*name == '%')
138 av_store(comppad, off, newHV(COEFFSIZE));
148 SV **svp = AvARRAY(comppadname);
150 register CONTEXT *cx;
157 for (off = comppadnamefill; off > 0; off--) {
158 if ((sv = svp[off]) &&
160 seq > (I32)SvNV(sv) &&
161 strEQ(SvPV(sv), name))
163 return (PADOFFSET)off;
167 /* Nothing in current lexical context--try eval's context, if any.
168 * This is necessary to let the perldb get at lexically scoped variables.
169 * XXX This will also probably interact badly with eval tree caching.
173 for (i = cxstack_ix; i >= 0; i--) {
175 switch (cx->cx_type) {
185 if (debstash && CvSTASH(cv) == debstash) /* ignore DB'* scope */
187 seq = cxstack[i+1].blk_oldcop->cop_seq;
188 curlist = CvPADLIST(cv);
189 curname = (AV*)*av_fetch(curlist, 0, FALSE);
190 svp = AvARRAY(curname);
191 for (off = AvFILL(curname); off > 0; off--) {
192 if ((sv = svp[off]) &&
194 seq > (I32)SvNV(sv) &&
195 strEQ(SvPV(sv), name))
197 PADOFFSET newoff = pad_alloc(OP_PADSV, 'M');
198 AV *oldpad = (AV*)*av_fetch(curlist, CvDEPTH(cv), FALSE);
199 SV *oldsv = *av_fetch(oldpad, off, TRUE);
201 sv_upgrade(sv, SVt_PVNV);
203 av_store(comppadname, newoff, sv);
204 SvNV(sv) = (double)curcop->cop_seq;
206 av_store(comppad, newoff, sv_ref(oldsv));
222 SV **svp = AvARRAY(comppadname);
224 for (off = AvFILL(comppadname); off > fill; off--) {
231 pad_alloc(optype,tmptype)
238 if (AvARRAY(comppad) != curpad)
239 fatal("panic: pad_alloc");
240 if (tmptype == 'M') {
242 sv = *av_fetch(comppad, AvFILL(comppad) + 1, TRUE);
243 } while (SvSTORAGE(sv)); /* need a fresh one */
244 retval = AvFILL(comppad);
248 sv = *av_fetch(comppad, ++padix, TRUE);
249 } while (SvSTORAGE(sv) == 'T' || SvSTORAGE(sv) == 'M');
252 SvSTORAGE(sv) = tmptype;
253 curpad = AvARRAY(comppad);
254 DEBUG_X(fprintf(stderr, "Pad alloc %d for %s\n", retval, op_name[optype]));
255 return (PADOFFSET)retval;
263 fatal("panic: pad_sv po");
264 DEBUG_X(fprintf(stderr, "Pad sv %d\n", po));
265 return curpad[po]; /* eventually we'll turn this into a macro */
272 if (AvARRAY(comppad) != curpad)
273 fatal("panic: pad_free curpad");
275 fatal("panic: pad_free po");
276 DEBUG_X(fprintf(stderr, "Pad free %d\n", po));
278 SvSTORAGE(curpad[po]) = 'F';
287 if (AvARRAY(comppad) != curpad)
288 fatal("panic: pad_swipe curpad");
290 fatal("panic: pad_swipe po");
291 DEBUG_X(fprintf(stderr, "Pad swipe %d\n", po));
292 curpad[po] = NEWSV(0,0);
293 SvSTORAGE(curpad[po]) = 'F';
303 if (AvARRAY(comppad) != curpad)
304 fatal("panic: pad_reset curpad");
305 DEBUG_X(fprintf(stderr, "Pad reset\n"));
306 for (po = AvMAX(comppad); po > 0; po--) {
307 if (curpad[po] && SvSTORAGE(curpad[po]) == 'T')
308 SvSTORAGE(curpad[po]) = 'F';
324 if (op->op_flags & OPf_KIDS) {
325 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling)
330 pad_free(op->op_targ);
332 switch (op->op_type) {
334 /*XXX sv_free(cGVOP->op_gv); */
337 sv_free(cSVOP->op_sv);
344 /* Contextualizers */
346 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist(o))
357 /* establish postfix order */
358 if (cUNOP->op_first) {
359 op->op_next = LINKLIST(cUNOP->op_first);
360 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
362 kid->op_next = LINKLIST(kid->op_sibling);
378 if (op && op->op_flags & OPf_KIDS) {
379 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
391 if (!op || (op->op_flags & OPf_KNOW)) /* assumes no premature commitment */
394 op->op_flags &= ~OPf_LIST;
395 op->op_flags |= OPf_KNOW;
397 switch (op->op_type) {
399 scalar(cBINOP->op_first);
409 if (!(op->op_flags & OPf_KIDS))
415 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
424 op = prepend_elem(OP_LIST, newOP(OP_PUSHMARK, 0), op);
427 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
440 if (op->op_flags & OPf_LIST)
443 op->op_flags |= OPf_KNOW;
445 switch (op->op_type) {
447 if (dowarn && (opargs[op->op_type] & OA_FOLDCONST))
448 warn("Useless use of %s", op_name[op->op_type]);
452 curcop = ((COP*)op); /* for warning above */
456 op->op_type = OP_NULL; /* don't execute a constant */
457 sv_free(cSVOP->op_sv); /* don't even remember it */
461 op->op_type = OP_PREINC;
462 op->op_ppaddr = ppaddr[OP_PREINC];
466 op->op_type = OP_PREDEC;
467 op->op_ppaddr = ppaddr[OP_PREDEC];
471 scalarvoid(cBINOP->op_first);
476 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
483 if (!(op->op_flags & OPf_KIDS))
488 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
492 op = prepend_elem(OP_LIST, newOP(OP_PUSHMARK, 0), op);
493 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
505 if (op && op->op_flags & OPf_KIDS) {
506 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
518 if (!op || (op->op_flags & OPf_KNOW)) /* assumes no premature commitment */
521 op->op_flags |= (OPf_KNOW | OPf_LIST);
523 switch (op->op_type) {
526 list(cBINOP->op_first);
531 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
538 if (!(op->op_flags & OPf_KIDS))
540 if (!op->op_next && cUNOP->op_first->op_type == OP_FLOP) {
541 list(cBINOP->op_first);
542 return gen_constant_list(op);
550 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
569 (op->op_type == OP_LINESEQ ||
570 op->op_type == OP_LEAVE ||
571 op->op_type == OP_LEAVETRY) )
573 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
588 if (op && op->op_flags & OPf_KIDS) {
589 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
608 switch (op->op_type) {
610 if ((type == OP_DEFINED || type == OP_UNDEF || type == OP_REFGEN) &&
611 !(op->op_flags & OPf_STACKED)) {
612 op->op_type = OP_RV2CV; /* entersubr => rv2cv */
613 op->op_ppaddr = ppaddr[OP_RV2CV];
614 cUNOP->op_first->op_type = OP_NULL; /* disable pushmark */
615 cUNOP->op_first->op_ppaddr = ppaddr[OP_NULL];
620 if (type == OP_DEFINED)
621 return scalar(op); /* ordinary expression, not lvalue */
622 sprintf(tokenbuf, "Can't %s %s in %s",
623 type == OP_REFGEN ? "refer to" : "modify",
624 op_name[op->op_type],
625 type ? op_name[type] : "local");
630 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
637 ref(cUNOP->op_first, op->op_type);
665 op->op_targ = pad_alloc(op->op_type,'M');
666 sv = PAD_SV(op->op_targ);
667 sv_upgrade(sv, SVt_PVLV);
668 sv_magic(sv, 0, op->op_type == OP_VEC ? 'v' : 'x', 0, 0);
669 curpad[op->op_targ] = sv;
672 if (!(op->op_flags & OPf_KIDS))
674 ref(cBINOP->op_first, type ? type : op->op_type);
678 ref(cBINOP->op_first, type ? type : op->op_type);
679 if (type == OP_RV2AV || type == OP_RV2HV)
680 op->op_private = type;
685 if (type != OP_RV2HV && type != OP_RV2AV)
687 if (!(op->op_flags & OPf_KIDS))
691 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
695 op->op_flags |= OPf_LVAL;
697 op->op_flags &= ~OPf_SPECIAL;
698 op->op_flags |= OPf_INTRO;
700 else if (type == OP_AASSIGN || type == OP_SASSIGN)
701 op->op_flags |= OPf_SPECIAL;
717 if (type == OP_LIST) {
718 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
721 else if (type != OP_PADSV &&
726 sprintf(tokenbuf, "Can't declare %s in my", op_name[op->op_type]);
730 op->op_flags |= OPf_LVAL|OPf_INTRO;
739 o->op_flags |= OPf_PARENS;
744 bind_match(type, left, right)
751 if (right->op_type == OP_MATCH ||
752 right->op_type == OP_SUBST ||
753 right->op_type == OP_TRANS) {
754 right->op_flags |= OPf_STACKED;
755 if (right->op_type != OP_MATCH)
756 left = ref(left, right->op_type);
757 if (right->op_type == OP_TRANS)
758 op = newBINOP(OP_NULL, 0, scalar(left), right);
760 op = prepend_elem(right->op_type, scalar(left), right);
762 return newUNOP(OP_NOT, 0, scalar(op));
766 return bind_match(type, left,
767 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
776 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
777 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(op));
785 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
786 o->op_type = OP_LEAVE;
787 o->op_ppaddr = ppaddr[OP_LEAVE];
793 block_head(o, startp)
801 o = scalarseq(scope(o));
802 *startp = LINKLIST(o);
813 if (o->op_flags & OPf_PARENS)
821 return ref(o, OP_NULL); /* a bit kludgey */
828 if (o->op_type == OP_LIST) {
829 o = convert(OP_JOIN, 0,
830 prepend_elem(OP_LIST,
831 newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE))),
842 I32 type = o->op_type;
845 if (opargs[type] & OA_RETSCALAR)
847 if (opargs[type] & OA_TARGET)
848 o->op_targ = pad_alloc(type,'T');
850 if (!(opargs[type] & OA_FOLDCONST))
853 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
854 if (curop->op_type != OP_CONST &&
855 curop->op_type != OP_LIST &&
856 curop->op_type != OP_SCALAR &&
857 curop->op_type != OP_PUSHMARK) {
866 if (o->op_targ && *stack_sp == PAD_SV(o->op_targ))
867 pad_swipe(o->op_targ);
869 if (type == OP_RV2GV)
870 return newGVOP(OP_GV, 0, *(stack_sp--));
872 return newSVOP(OP_CONST, 0, *(stack_sp--));
875 if (!(opargs[type] & OA_OTHERINT))
877 if (!(o->op_flags & OPf_KIDS))
880 for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
881 if (curop->op_type == OP_CONST) {
882 if (SvIOK(((SVOP*)curop)->op_sv))
886 if (opargs[curop->op_type] & OA_RETINTEGER)
891 o->op_ppaddr = ppaddr[++(o->op_type)];
903 I32 oldtmps_floor = tmps_floor;
907 tmpmark = stack_sp - stack_base;
908 anonop = newANONLIST(o);
909 curop = LINKLIST(anonop);
913 tmpsp = stack_sp - stack_base;
914 tmps_floor = oldtmps_floor;
915 stack_sp = stack_base + tmpmark;
917 o->op_type = OP_RV2AV;
918 o->op_ppaddr = ppaddr[OP_RV2AV];
920 curop = ((UNOP*)o)->op_first;
921 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, newSVsv(stack_sp[1]));
923 curop = ((UNOP*)anonop)->op_first;
924 curop = ((UNOP*)curop)->op_first;
925 curop->op_sibling = 0;
933 convert(type, flags, op)
941 if (opargs[type] & OA_MARK)
942 op = prepend_elem(OP_LIST, newOP(OP_PUSHMARK, 0), op);
944 if (!op || op->op_type != OP_LIST)
945 op = newLISTOP(OP_LIST, 0, op, Nullop);
948 op->op_ppaddr = ppaddr[type];
949 op->op_flags |= flags;
951 op = (*check[type])(op);
952 if (op->op_type != type)
955 if (cLISTOP->op_children < 7) {
956 /* XXX do we really need to do this if we're done appending?? */
957 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
959 cLISTOP->op_last = last; /* in case check substituted last arg */
962 return fold_constants(op);
965 /* List constructors */
968 append_elem(type, first, last)
977 else if (first->op_type == type) {
978 if (first->op_flags & OPf_KIDS)
979 ((LISTOP*)first)->op_last->op_sibling = last;
981 first->op_flags |= OPf_KIDS;
982 ((LISTOP*)first)->op_first = last;
984 ((LISTOP*)first)->op_last = last;
985 ((LISTOP*)first)->op_children++;
989 return newLISTOP(type, 0, first, last);
993 append_list(type, first, last)
1002 else if (first->op_type != type)
1003 return prepend_elem(type, (OP*)first, (OP*)last);
1004 else if (last->op_type != type)
1005 return append_elem(type, (OP*)first, (OP*)last);
1007 first->op_last->op_sibling = last->op_first;
1008 first->op_last = last->op_last;
1009 first->op_children += last->op_children;
1010 if (first->op_children)
1011 last->op_flags |= OPf_KIDS;
1018 prepend_elem(type, first, last)
1027 else if (last->op_type == type) {
1028 if (!(last->op_flags & OPf_KIDS)) {
1029 ((LISTOP*)last)->op_last = first;
1030 last->op_flags |= OPf_KIDS;
1032 first->op_sibling = ((LISTOP*)last)->op_first;
1033 ((LISTOP*)last)->op_first = first;
1034 ((LISTOP*)last)->op_children++;
1038 return newLISTOP(type, 0, first, last);
1050 newLISTOP(type, flags, first, last)
1058 Newz(1101, listop, 1, LISTOP);
1060 listop->op_type = type;
1061 listop->op_ppaddr = ppaddr[type];
1062 listop->op_children = (first != 0) + (last != 0);
1063 listop->op_flags = flags;
1064 if (listop->op_children)
1065 listop->op_flags |= OPf_KIDS;
1069 else if (!first && last)
1071 listop->op_first = first;
1072 listop->op_last = last;
1073 if (first && first != last)
1074 first->op_sibling = last;
1085 Newz(1101, op, 1, OP);
1087 op->op_ppaddr = ppaddr[type];
1088 op->op_flags = flags;
1091 /* op->op_private = 0; */
1092 if (opargs[type] & OA_RETSCALAR)
1094 if (opargs[type] & OA_TARGET)
1095 op->op_targ = pad_alloc(type,'T');
1096 return (*check[type])(op);
1100 newUNOP(type, flags, first)
1107 if (opargs[type] & OA_MARK) {
1108 if (first->op_type == OP_LIST)
1109 prepend_elem(OP_LIST, newOP(OP_PUSHMARK, 0), first);
1111 return newBINOP(type, flags, newOP(OP_PUSHMARK, 0), first);
1115 first = newOP(OP_STUB, 0);
1117 Newz(1101, unop, 1, UNOP);
1118 unop->op_type = type;
1119 unop->op_ppaddr = ppaddr[type];
1120 unop->op_first = first;
1121 unop->op_flags = flags | OPf_KIDS;
1122 unop->op_private = 1;
1124 unop = (UNOP*)(*check[type])((OP*)unop);
1128 return fold_constants(unop);
1132 newBINOP(type, flags, first, last)
1139 Newz(1101, binop, 1, BINOP);
1142 first = newOP(OP_NULL, 0);
1144 binop->op_type = type;
1145 binop->op_ppaddr = ppaddr[type];
1146 binop->op_first = first;
1147 binop->op_flags = flags | OPf_KIDS;
1150 binop->op_private = 1;
1153 binop->op_private = 2;
1154 first->op_sibling = last;
1157 binop = (BINOP*)(*check[type])((OP*)binop);
1161 binop->op_last = last = binop->op_first->op_sibling;
1163 return fold_constants(binop);
1167 pmtrans(op, expr, repl)
1172 PMOP *pm = (PMOP*)op;
1173 SV *tstr = ((SVOP*)expr)->op_sv;
1174 SV *rstr = ((SVOP*)repl)->op_sv;
1175 register char *t = SvPVn(tstr);
1176 register char *r = SvPVn(rstr);
1177 I32 tlen = SvCUR(tstr);
1178 I32 rlen = SvCUR(rstr);
1184 register short *tbl;
1186 tbl = (short*)cPVOP->op_pv;
1187 complement = op->op_private & OPpTRANS_COMPLEMENT;
1188 delete = op->op_private & OPpTRANS_DELETE;
1189 squash = op->op_private & OPpTRANS_SQUASH;
1192 Zero(tbl, 256, short);
1193 for (i = 0; i < tlen; i++)
1194 tbl[t[i] & 0377] = -1;
1195 for (i = 0, j = 0; i < 256; i++) {
1201 tbl[i] = r[j-1] & 0377;
1206 tbl[i] = r[j++] & 0377;
1211 if (!rlen && !delete) {
1214 for (i = 0; i < 256; i++)
1216 for (i = 0, j = 0; i < tlen; i++,j++) {
1219 if (tbl[t[i] & 0377] == -1)
1220 tbl[t[i] & 0377] = -2;
1225 if (tbl[t[i] & 0377] == -1)
1226 tbl[t[i] & 0377] = r[j] & 0377;
1236 newPMOP(type, flags)
1242 Newz(1101, pmop, 1, PMOP);
1243 pmop->op_type = type;
1244 pmop->op_ppaddr = ppaddr[type];
1245 pmop->op_flags = flags;
1246 pmop->op_private = 0;
1248 /* link into pm list */
1249 if (type != OP_TRANS) {
1250 pmop->op_pmnext = HvPMROOT(curstash);
1251 HvPMROOT(curstash) = pmop;
1258 pmruntime(op, expr, repl)
1266 if (op->op_type == OP_TRANS)
1267 return pmtrans(op, expr, repl);
1271 if (expr->op_type == OP_CONST) {
1272 SV *pat = ((SVOP*)expr)->op_sv;
1273 char *p = SvPVn(pat);
1274 if ((op->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
1275 sv_setpvn(pat, "\\s+", 3);
1277 pm->op_pmflags |= PMf_SKIPWHITE;
1279 scan_prefix(pm, p, SvCUR(pat));
1280 if (pm->op_pmshort && (pm->op_pmflags & PMf_SCANFIRST))
1281 fbm_compile(pm->op_pmshort, pm->op_pmflags & PMf_FOLD);
1282 pm->op_pmregexp = regcomp(p, p + SvCUR(pat), pm->op_pmflags & PMf_FOLD);
1287 Newz(1101, rcop, 1, LOGOP);
1288 rcop->op_type = OP_REGCOMP;
1289 rcop->op_ppaddr = ppaddr[OP_REGCOMP];
1290 rcop->op_first = scalar(expr);
1291 rcop->op_flags |= OPf_KIDS;
1292 rcop->op_private = 1;
1293 rcop->op_other = op;
1295 /* establish postfix order */
1296 rcop->op_next = LINKLIST(expr);
1297 expr->op_next = (OP*)rcop;
1299 prepend_elem(op->op_type, scalar(rcop), op);
1303 if (repl->op_type == OP_CONST) {
1304 pm->op_pmflags |= PMf_CONST;
1305 prepend_elem(op->op_type, scalar(repl), op);
1310 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
1311 if (opargs[curop->op_type] & OA_DANGEROUS) {
1312 if (curop->op_type == OP_GV) {
1313 GV *gv = ((GVOP*)curop)->op_gv;
1314 if (strchr("&`'123456789+", *GvENAME(gv)))
1317 else if (curop->op_type == OP_RV2CV)
1319 else if (curop->op_type == OP_RV2SV ||
1320 curop->op_type == OP_RV2AV ||
1321 curop->op_type == OP_RV2HV ||
1322 curop->op_type == OP_RV2GV) {
1323 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
1331 if (curop == repl) {
1332 pm->op_pmflags |= PMf_CONST; /* const for long enough */
1333 prepend_elem(op->op_type, scalar(repl), op);
1336 Newz(1101, rcop, 1, LOGOP);
1337 rcop->op_type = OP_SUBSTCONT;
1338 rcop->op_ppaddr = ppaddr[OP_SUBSTCONT];
1339 rcop->op_first = scalar(repl);
1340 rcop->op_flags |= OPf_KIDS;
1341 rcop->op_private = 1;
1342 rcop->op_other = op;
1344 /* establish postfix order */
1345 rcop->op_next = LINKLIST(repl);
1346 repl->op_next = (OP*)rcop;
1348 pm->op_pmreplroot = scalar(rcop);
1349 pm->op_pmreplstart = LINKLIST(rcop);
1359 newSVOP(type, flags, sv)
1365 Newz(1101, svop, 1, SVOP);
1366 svop->op_type = type;
1367 svop->op_ppaddr = ppaddr[type];
1369 svop->op_next = (OP*)svop;
1370 svop->op_flags = flags;
1371 if (opargs[type] & OA_RETSCALAR)
1373 if (opargs[type] & OA_TARGET)
1374 svop->op_targ = pad_alloc(type,'T');
1375 return (*check[type])((OP*)svop);
1379 newGVOP(type, flags, gv)
1385 Newz(1101, gvop, 1, GVOP);
1386 gvop->op_type = type;
1387 gvop->op_ppaddr = ppaddr[type];
1388 gvop->op_gv = (GV*)sv_ref(gv);
1389 gvop->op_next = (OP*)gvop;
1390 gvop->op_flags = flags;
1391 if (opargs[type] & OA_RETSCALAR)
1393 if (opargs[type] & OA_TARGET)
1394 gvop->op_targ = pad_alloc(type,'T');
1395 return (*check[type])((OP*)gvop);
1399 newPVOP(type, flags, pv)
1405 Newz(1101, pvop, 1, PVOP);
1406 pvop->op_type = type;
1407 pvop->op_ppaddr = ppaddr[type];
1409 pvop->op_next = (OP*)pvop;
1410 pvop->op_flags = flags;
1411 if (opargs[type] & OA_RETSCALAR)
1413 if (opargs[type] & OA_TARGET)
1414 pvop->op_targ = pad_alloc(type,'T');
1415 return (*check[type])((OP*)pvop);
1419 newCVOP(type, flags, cv, cont)
1426 Newz(1101, cvop, 1, CVOP);
1427 cvop->op_type = type;
1428 cvop->op_ppaddr = ppaddr[type];
1430 cvop->op_cont = cont;
1431 cvop->op_next = (OP*)cvop;
1432 cvop->op_flags = flags;
1433 if (opargs[type] & OA_RETSCALAR)
1435 if (opargs[type] & OA_TARGET)
1436 cvop->op_targ = pad_alloc(type,'T');
1437 return (*check[type])((OP*)cvop);
1449 save_hptr(&curstash);
1450 save_item(curstname);
1454 sv_setpv(curstname,name);
1455 sprintf(tmpbuf,"'_%s",name);
1456 tmpgv = gv_fetchpv(tmpbuf,TRUE);
1458 GvHV(tmpgv) = newHV(0);
1459 curstash = GvHV(tmpgv);
1460 if (!HvNAME(curstash))
1461 HvNAME(curstash) = savestr(name);
1462 HvCOEFFSIZE(curstash) = 0;
1466 sv_setpv(curstname,"<none>");
1474 newSLICEOP(flags, subscript, listval)
1479 return newBINOP(OP_LSLICE, flags,
1480 list(prepend_elem(OP_LIST, newOP(OP_PUSHMARK, 0), subscript)),
1481 list(prepend_elem(OP_LIST, newOP(OP_PUSHMARK, 0), listval)) );
1491 if (op->op_type == OP_NULL && op->op_flags & OPf_KIDS)
1492 op = cUNOP->op_first;
1494 if (op->op_type == OP_COND_EXPR) {
1495 I32 t = list_assignment(cCONDOP->op_first->op_sibling);
1496 I32 f = list_assignment(cCONDOP->op_first->op_sibling->op_sibling);
1501 yyerror("Assignment to both a list and a scalar");
1505 if (op->op_type == OP_LIST || op->op_flags & OPf_PARENS ||
1506 op->op_type == OP_RV2AV || op->op_type == OP_RV2HV ||
1507 op->op_type == OP_ASLICE || op->op_type == OP_HSLICE)
1510 if (op->op_type == OP_PADAV || op->op_type == OP_PADHV)
1513 if (op->op_type == OP_RV2SV)
1520 newASSIGNOP(flags, left, right)
1527 if (list_assignment(left)) {
1529 left = ref(left, OP_AASSIGN);
1530 if (right && right->op_type == OP_SPLIT) {
1531 if ((op = ((LISTOP*)right)->op_first) && op->op_type == OP_PUSHRE) {
1532 PMOP *pm = (PMOP*)op;
1533 if (left->op_type == OP_RV2AV) {
1534 op = ((UNOP*)left)->op_first;
1535 if (op->op_type == OP_GV && !pm->op_pmreplroot) {
1536 pm->op_pmreplroot = (OP*)((GVOP*)op)->op_gv;
1537 pm->op_pmflags |= PMf_ONCE;
1543 if (refcount < 10000) {
1544 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
1546 sv_setiv(sv, refcount+1);
1551 op = newBINOP(OP_AASSIGN, flags,
1552 list(prepend_elem(OP_LIST, newOP(OP_PUSHMARK, 0), right)),
1553 list(prepend_elem(OP_LIST, newOP(OP_PUSHMARK, 0), left)) );
1555 if (!(left->op_flags & OPf_INTRO)) {
1556 static int generation = 0;
1560 for (curop = LINKLIST(op); curop != op; curop = LINKLIST(curop)) {
1561 if (opargs[curop->op_type] & OA_DANGEROUS) {
1562 if (curop->op_type == OP_GV) {
1563 GV *gv = ((GVOP*)curop)->op_gv;
1564 if (gv == defgv || SvCUR(gv) == generation)
1566 SvCUR(gv) = generation;
1568 else if (curop->op_type == OP_RV2CV)
1570 else if (curop->op_type == OP_RV2SV ||
1571 curop->op_type == OP_RV2AV ||
1572 curop->op_type == OP_RV2HV ||
1573 curop->op_type == OP_RV2GV) {
1574 if (lastop->op_type != OP_GV) /* funny deref? */
1583 op->op_private = OPpASSIGN_COMMON;
1585 op->op_targ = pad_alloc(OP_AASSIGN, 'T'); /* for scalar context */
1589 right = newOP(OP_UNDEF, 0);
1590 if (right->op_type == OP_READLINE) {
1591 right->op_flags |= OPf_STACKED;
1592 return newBINOP(OP_NULL, flags, ref(scalar(left), OP_SASSIGN), scalar(right));
1595 op = newBINOP(OP_SASSIGN, flags,
1596 scalar(right), ref(scalar(left), OP_SASSIGN) );
1601 newSTATEOP(flags, label, op)
1608 comppadnamefill = AvFILL(comppadname); /* introduce my variables */
1610 Newz(1101, cop, 1, COP);
1611 cop->op_type = OP_NEXTSTATE;
1612 cop->op_ppaddr = ppaddr[ perldb ? OP_DBSTATE : OP_NEXTSTATE ];
1613 cop->op_flags = flags;
1614 cop->op_private = 0;
1615 cop->op_next = (OP*)cop;
1617 cop->cop_label = label;
1618 cop->cop_seq = cop_seq++;
1620 if (copline == NOLINE)
1621 cop->cop_line = curcop->cop_line;
1623 cop->cop_line = copline;
1626 cop->cop_filegv = curcop->cop_filegv;
1627 cop->cop_stash = curstash;
1630 SV **svp = av_fetch(GvAV(curcop->cop_filegv),(I32)cop->cop_line, FALSE);
1631 if (svp && *svp != &sv_undef && !SvIOK(*svp)) {
1634 SvSTASH(*svp) = (HV*)cop;
1638 return prepend_elem(OP_LINESEQ, (OP*)cop, op);
1642 newLOGOP(type, flags, first, other)
1652 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
1653 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
1654 if (type == OP_AND || type == OP_OR) {
1660 first = cUNOP->op_first;
1662 first->op_next = op->op_next;
1663 cUNOP->op_first = Nullop;
1667 if (first->op_type == OP_CONST) {
1668 if (dowarn && (first->op_private & OPpCONST_BARE))
1669 warn("Probable precedence problem on %s", op_name[type]);
1670 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
1679 else if (first->op_type == OP_WANTARRAY) {
1689 Newz(1101, logop, 1, LOGOP);
1691 logop->op_type = type;
1692 logop->op_ppaddr = ppaddr[type];
1693 logop->op_first = first;
1694 logop->op_flags = flags | OPf_KIDS;
1695 logop->op_other = LINKLIST(other);
1696 logop->op_private = 1;
1698 /* establish postfix order */
1699 logop->op_next = LINKLIST(first);
1700 first->op_next = (OP*)logop;
1701 first->op_sibling = other;
1703 op = newUNOP(OP_NULL, 0, (OP*)logop);
1704 other->op_next = op;
1710 newCONDOP(flags, first, true, false)
1720 return newLOGOP(OP_AND, 0, first, true);
1723 if (first->op_type == OP_CONST) {
1724 if (SvTRUE(((SVOP*)first)->op_sv)) {
1735 else if (first->op_type == OP_WANTARRAY) {
1739 Newz(1101, condop, 1, CONDOP);
1741 condop->op_type = OP_COND_EXPR;
1742 condop->op_ppaddr = ppaddr[OP_COND_EXPR];
1743 condop->op_first = first;
1744 condop->op_flags = flags | OPf_KIDS;
1745 condop->op_true = LINKLIST(true);
1746 condop->op_false = LINKLIST(false);
1747 condop->op_private = 1;
1749 /* establish postfix order */
1750 condop->op_next = LINKLIST(first);
1751 first->op_next = (OP*)condop;
1753 first->op_sibling = true;
1754 true->op_sibling = false;
1755 op = newUNOP(OP_NULL, 0, (OP*)condop);
1758 false->op_next = op;
1764 newRANGE(flags, left, right)
1774 Newz(1101, condop, 1, CONDOP);
1776 condop->op_type = OP_RANGE;
1777 condop->op_ppaddr = ppaddr[OP_RANGE];
1778 condop->op_first = left;
1779 condop->op_flags = OPf_KIDS;
1780 condop->op_true = LINKLIST(left);
1781 condop->op_false = LINKLIST(right);
1782 condop->op_private = 1;
1784 left->op_sibling = right;
1786 condop->op_next = (OP*)condop;
1787 flip = newUNOP(OP_FLIP, flags, (OP*)condop);
1788 flop = newUNOP(OP_FLOP, 0, flip);
1789 op = newUNOP(OP_NULL, 0, flop);
1792 left->op_next = flip;
1793 right->op_next = flop;
1795 condop->op_targ = pad_alloc(OP_RANGE, 'M');
1796 sv_upgrade(PAD_SV(condop->op_targ), SVt_PVNV);
1797 flip->op_targ = pad_alloc(OP_RANGE, 'M');
1798 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
1800 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
1801 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
1804 if (!flip->op_private || !flop->op_private)
1805 linklist(op); /* blow off optimizer unless constant */
1811 newLOOPOP(flags, debuggable, expr, block)
1817 OP* listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
1820 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB))
1821 expr = newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), expr);
1823 op = newLOGOP(OP_AND, 0, expr, listop);
1824 ((LISTOP*)listop)->op_last->op_next = LINKLIST(op);
1826 if (block->op_flags & OPf_SPECIAL && /* skip conditional on do {} ? */
1827 (block->op_type == OP_ENTERSUBR || block->op_type == OP_NULL))
1828 op->op_next = ((LOGOP*)cUNOP->op_first)->op_other;
1830 op->op_flags |= flags;
1835 newWHILEOP(flags, debuggable, loop, expr, block, cont)
1849 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB))
1850 expr = newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), expr);
1853 block = newOP(OP_NULL, 0);
1856 next = LINKLIST(cont);
1858 cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
1860 listop = append_list(OP_LINESEQ, block, cont);
1861 redo = LINKLIST(listop);
1864 op = newLOGOP(OP_AND, 0, expr, scalar(listop));
1865 ((LISTOP*)listop)->op_last->op_next = condop =
1866 (op == listop ? redo : LINKLIST(op));
1874 Newz(1101,loop,1,LOOP);
1875 loop->op_type = OP_ENTERLOOP;
1876 loop->op_ppaddr = ppaddr[OP_ENTERLOOP];
1877 loop->op_private = 0;
1878 loop->op_next = (OP*)loop;
1881 op = newBINOP(OP_LEAVELOOP, 0, loop, op);
1883 loop->op_redoop = redo;
1884 loop->op_lastop = op;
1887 loop->op_nextop = next;
1889 loop->op_nextop = op;
1891 op->op_flags |= flags;
1896 newFOROP(flags,label,forline,sv,expr,block,cont)
1909 if (sv->op_type == OP_RV2SV) {
1911 sv = cUNOP->op_first;
1913 cUNOP->op_first = Nullop;
1917 fatal("Can't use %s for loop variable", op_name[sv->op_type]);
1920 sv = newGVOP(OP_GV, 0, defgv);
1922 loop = (LOOP*)list(convert(OP_ENTERITER, 0,
1923 append_elem(OP_LIST,
1924 prepend_elem(OP_LIST, newOP(OP_PUSHMARK, 0), expr),
1926 return newSTATEOP(0, label, newWHILEOP(flags, 1,
1927 loop, newOP(OP_ITER, 0), block, cont));
1934 if (!CvUSERSUB(cv) && CvROOT(cv)) {
1935 op_free(CvROOT(cv));
1936 CvROOT(cv) = Nullop;
1938 warn("Deleting active subroutine"); /* XXX */
1939 if (CvPADLIST(cv)) {
1940 I32 i = AvFILL(CvPADLIST(cv));
1942 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
1946 av_free(CvPADLIST(cv));
1953 newSUB(floor,op,block)
1959 char *name = SvPVnx(cSVOP->op_sv);
1960 GV *gv = gv_fetchpv(name,TRUE);
1963 if (cv = GvCV(gv)) {
1965 CvDELETED(cv) = TRUE; /* probably an autoloader */
1967 if (dowarn && CvROOT(cv)) {
1968 line_t oldline = curcop->cop_line;
1970 curcop->cop_line = copline;
1971 warn("Subroutine %s redefined",name);
1972 curcop->cop_line = oldline;
1978 sv_upgrade(cv, SVt_PVCV);
1980 CvFILEGV(cv) = curcop->cop_filegv;
1984 if (AvFILL(comppadname) < AvFILL(comppad))
1985 av_store(comppadname, AvFILL(comppad), Nullsv);
1986 av_store(av, 0, (SV*)comppadname);
1987 av_store(av, 1, (SV*)comppad);
1990 comppadname = newAV();
1999 CvROOT(cv) = newUNOP(OP_LEAVESUBR, 0, scalarseq(block));
2000 CvSTART(cv) = LINKLIST(CvROOT(cv));
2001 CvROOT(cv)->op_next = 0;
2002 CvSTASH(cv) = curstash;
2004 CvDELETED(cv) = FALSE;
2005 if (strEQ(name, "BEGIN")) {
2006 line_t oldline = curcop->cop_line;
2007 GV* oldfile = curcop->cop_filegv;
2011 av_push(beginav, sv_ref(gv));
2012 DEBUG_x( dump_sub(gv) );
2016 rspara = (nrslen == 2);
2024 curcop = &compiling;
2025 curcop->cop_line = oldline; /* might have compiled something */
2026 curcop->cop_filegv = oldfile; /* recursively, clobbering these */
2028 else if (strEQ(name, "END")) {
2031 av_unshift(endav, 1);
2032 av_store(endav, 0, sv_ref(gv));
2036 SV *tmpstr = sv_mortalcopy(&sv_undef);
2038 sprintf(buf,"%s:%ld",SvPV(GvSV(curcop->cop_filegv)), subline);
2039 sv = newSVpv(buf,0);
2041 sprintf(buf,"%ld",(long)curcop->cop_line);
2043 gv_efullname(tmpstr,gv);
2044 hv_store(GvHV(DBsub), SvPV(tmpstr), SvCUR(tmpstr), sv, 0);
2052 newUSUB(name, ix, subaddr, filename)
2059 GV *gv = gv_fetchpv(name,allgvs);
2061 if (!gv) /* unused function */
2063 if (cv = GvCV(gv)) {
2065 warn("Subroutine %s redefined",name);
2066 if (!CvUSERSUB(cv) && CvROOT(cv)) {
2067 op_free(CvROOT(cv));
2068 CvROOT(cv) = Nullop;
2073 sv_upgrade(cv, SVt_PVCV);
2075 CvFILEGV(cv) = gv_fetchfile(filename);
2076 CvUSERSUB(cv) = subaddr;
2077 CvUSERINDEX(cv) = ix;
2078 CvDELETED(cv) = FALSE;
2079 if (strEQ(name, "BEGIN")) {
2082 av_push(beginav, sv_ref(gv));
2084 else if (strEQ(name, "END")) {
2087 av_unshift(endav, 1);
2088 av_store(endav, 0, sv_ref(gv));
2093 newFORM(floor,op,block)
2104 name = SvPVnx(cSVOP->op_sv);
2107 gv = gv_fetchpv(name,TRUE);
2108 if (cv = GvFORM(gv)) {
2110 line_t oldline = curcop->cop_line;
2112 curcop->cop_line = copline;
2113 warn("Format %s redefined",name);
2114 curcop->cop_line = oldline;
2119 sv_upgrade(cv, SVt_PVFM);
2121 CvFILEGV(cv) = curcop->cop_filegv;
2123 CvPADLIST(cv) = av = newAV();
2125 av_store(av, 1, (SV*)comppad);
2128 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
2129 CvSTART(cv) = LINKLIST(CvROOT(cv));
2130 CvROOT(cv)->op_next = 0;
2132 CvDELETED(cv) = FALSE;
2145 Newz(1101, mop, 1, LOGOP);
2146 mop->op_type = OP_METHOD;
2147 mop->op_ppaddr = ppaddr[OP_METHOD];
2148 mop->op_first = scalar(ref);
2149 mop->op_flags |= OPf_KIDS;
2150 mop->op_private = 1;
2151 mop->op_other = LINKLIST(name);
2152 mop->op_targ = pad_alloc(OP_METHOD,'T');
2153 mop->op_next = LINKLIST(ref);
2154 ref->op_next = (OP*)mop;
2162 return newUNOP(OP_REFGEN, 0,
2163 ref(list(convert(OP_ANONLIST, 0, op)), OP_REFGEN));
2170 return newUNOP(OP_REFGEN, 0,
2171 ref(list(convert(OP_ANONHASH, 0, op)), OP_REFGEN));
2178 if (o->op_type == OP_PADAV)
2180 if (o->op_type == OP_RV2SV) {
2181 o->op_type = OP_RV2AV;
2182 o->op_ppaddr = ppaddr[OP_RV2AV];
2186 warn("oops: oopsAV");
2194 if (o->op_type == OP_PADHV)
2196 if (o->op_type == OP_RV2SV || o->op_type == OP_RV2AV) {
2197 o->op_type = OP_RV2HV;
2198 o->op_ppaddr = ppaddr[OP_RV2HV];
2202 warn("oops: oopsHV");
2210 if (o->op_type == OP_PADAV)
2212 return newUNOP(OP_RV2AV, 0, scalar(o));
2219 return newUNOP(OP_RV2GV, 0, scalar(o));
2226 if (o->op_type == OP_PADHV)
2228 return newUNOP(OP_RV2HV, 0, scalar(o));
2235 fatal("NOT IMPL LINE %d",__LINE__);
2244 return newUNOP(OP_RV2CV, 0, scalar(o));
2251 if (o->op_type == OP_PADSV)
2253 return newUNOP(OP_RV2SV, 0, scalar(o));
2256 /* Check routines. */
2262 /* XXX need to optimize constant subscript here. */
2270 if (cUNOP->op_first->op_type == OP_CONCAT)
2271 op->op_flags |= OPf_STACKED;
2279 if (op->op_flags & OPf_KIDS) {
2281 op = refkids(ck_fun(op), op->op_type);
2282 if (op->op_private != 1)
2284 newop = cUNOP->op_first->op_sibling;
2285 if (!newop || newop->op_type != OP_RV2SV)
2287 op_free(cUNOP->op_first);
2288 cUNOP->op_first = newop;
2290 op->op_type = OP_SCHOP;
2291 op->op_ppaddr = ppaddr[OP_SCHOP];
2299 I32 type = op->op_type;
2301 if (op->op_flags & OPf_KIDS)
2304 if (op->op_flags & OPf_SPECIAL) {
2306 op = newUNOP(type, 0, newGVOP(OP_GV, 0, gv_fetchpv("main'ARGV", TRUE)));
2315 if (op->op_flags & OPf_KIDS) {
2316 SVOP *kid = (SVOP*)cUNOP->op_first;
2319 op->op_flags &= ~OPf_KIDS;
2320 op->op_type = OP_NULL;
2321 op->op_ppaddr = ppaddr[OP_NULL];
2323 else if (kid->op_type == OP_LINESEQ) {
2326 kid->op_next = op->op_next;
2327 cUNOP->op_first = 0;
2330 Newz(1101, enter, 1, LOGOP);
2331 enter->op_type = OP_ENTERTRY;
2332 enter->op_ppaddr = ppaddr[OP_ENTERTRY];
2333 enter->op_private = 0;
2335 /* establish postfix order */
2336 enter->op_next = (OP*)enter;
2338 op = prepend_elem(OP_LINESEQ, enter, kid);
2339 op->op_type = OP_LEAVETRY;
2340 op->op_ppaddr = ppaddr[OP_LEAVETRY];
2341 enter->op_other = op;
2347 op = newUNOP(OP_ENTEREVAL, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
2358 if (op->op_flags & OPf_STACKED) {
2359 kid = cUNOP->op_first->op_sibling;
2360 if (kid->op_type == OP_RV2GV) {
2361 kid->op_type = OP_NULL;
2362 kid->op_ppaddr = ppaddr[OP_NULL];
2372 o = fold_constants(o);
2373 if (o->op_type == OP_CONST)
2382 SVOP *kid = (SVOP*)cUNOP->op_first;
2383 if (kid->op_type == OP_CONST) {
2384 kid->op_type = OP_GV;
2385 kid->op_sv = (SV*)gv_fetchpv(SvPVnx(kid->op_sv),
2386 1+(op->op_type==OP_RV2CV));
2402 I32 type = op->op_type;
2404 if (op->op_flags & OPf_SPECIAL)
2407 if (op->op_flags & OPf_KIDS) {
2408 SVOP *kid = (SVOP*)cUNOP->op_first;
2410 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
2411 OP *newop = newGVOP(type, OPf_SPECIAL,
2412 gv_fetchpv(SvPVnx(kid->op_sv), TRUE));
2419 if (type == OP_FTTTY)
2420 return newGVOP(type, OPf_SPECIAL, gv_fetchpv("main'STDIN", TRUE));
2422 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
2435 register I32 oa = opargs[op->op_type] >> 8;
2437 if (op->op_flags & OPf_STACKED) {
2438 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
2441 return no_fh_allowed(op);
2444 if (op->op_flags & OPf_KIDS) {
2445 tokid = &cLISTOP->op_first;
2446 kid = cLISTOP->op_first;
2447 if (kid->op_type == OP_PUSHMARK) {
2448 tokid = &kid->op_sibling;
2449 kid = kid->op_sibling;
2454 sibl = kid->op_sibling;
2468 if (kid->op_type == OP_CONST &&
2469 (kid->op_private & OPpCONST_BARE)) {
2470 OP *newop = newAVREF(newGVOP(OP_GV, 0,
2471 gv_fetchpv(SvPVnx(((SVOP*)kid)->op_sv), TRUE) ));
2474 kid->op_sibling = sibl;
2477 ref(kid, op->op_type);
2480 if (kid->op_type == OP_CONST &&
2481 (kid->op_private & OPpCONST_BARE)) {
2482 OP *newop = newHVREF(newGVOP(OP_GV, 0,
2483 gv_fetchpv(SvPVnx(((SVOP*)kid)->op_sv), TRUE) ));
2486 kid->op_sibling = sibl;
2489 ref(kid, op->op_type);
2493 OP *newop = newUNOP(OP_NULL, 0, scalar(kid));
2494 kid->op_sibling = 0;
2496 newop->op_next = newop;
2498 kid->op_sibling = sibl;
2503 if (kid->op_type != OP_GV) {
2504 if (kid->op_type == OP_CONST &&
2505 (kid->op_private & OPpCONST_BARE)) {
2506 OP *newop = newGVOP(OP_GV, 0,
2507 gv_fetchpv(SvPVnx(((SVOP*)kid)->op_sv), TRUE) );
2512 kid->op_sibling = 0;
2513 kid = newUNOP(OP_RV2GV, 0, scalar(kid));
2515 kid->op_sibling = sibl;
2521 ref(scalar(kid), op->op_type);
2525 tokid = &kid->op_sibling;
2526 kid = kid->op_sibling;
2528 op->op_private = numargs;
2530 return too_many_arguments(op);
2534 while (oa & OA_OPTIONAL)
2536 if (oa && oa != OA_LIST)
2537 return too_few_arguments(op);
2546 GV *gv = newGVgen();
2548 append_elem(OP_GLOB, op, newGVOP(OP_GV, 0, gv));
2560 if (op->op_flags & OPf_STACKED) {
2562 op->op_flags &= ~OPf_STACKED;
2567 kid = cLISTOP->op_first->op_sibling;
2568 if (kid->op_type != OP_NULL)
2569 fatal("panic: ck_grep");
2570 kid = kUNOP->op_first;
2572 Newz(1101, gwop, 1, LOGOP);
2573 gwop->op_type = OP_GREPWHILE;
2574 gwop->op_ppaddr = ppaddr[OP_GREPWHILE];
2575 gwop->op_first = list(op);
2576 gwop->op_flags |= OPf_KIDS;
2577 gwop->op_private = 1;
2578 gwop->op_other = LINKLIST(kid);
2579 gwop->op_targ = pad_alloc(OP_GREPWHILE,'T');
2580 kid->op_next = (OP*)gwop;
2589 if (op->op_flags & OPf_KIDS) {
2590 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
2591 if (kid && kid->op_type == OP_CONST)
2592 fbm_compile(((SVOP*)kid)->op_sv, 0);
2601 /* XXX length optimization goes here */
2609 return refkids(ck_fun(op), op->op_type);
2618 kid = cLISTOP->op_first;
2620 prepend_elem(op->op_type, newOP(OP_PUSHMARK, 0), op);
2621 kid = cLISTOP->op_first;
2623 if (kid->op_type == OP_PUSHMARK)
2624 kid = kid->op_sibling;
2625 if (kid && op->op_flags & OPf_STACKED)
2626 kid = kid->op_sibling;
2627 else if (kid && !kid->op_sibling) { /* print HANDLE; */
2628 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
2629 op->op_flags |= OPf_STACKED; /* make it a filehandle */
2630 kid = newUNOP(OP_RV2GV, 0, scalar(kid));
2631 cLISTOP->op_first->op_sibling = kid;
2632 cLISTOP->op_last = kid;
2633 kid = kid->op_sibling;
2638 append_elem(op->op_type, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
2640 return listkids(op);
2647 cPMOP->op_pmflags |= PMf_RUNTIME;
2662 if (cBINOP->op_first->op_flags & OPf_PARENS) {
2663 op->op_private = OPpREPEAT_DOLIST;
2665 prepend_elem(OP_NULL, newOP(OP_PUSHMARK, 0), cBINOP->op_first);
2676 fatal("NOT IMPL LINE %d",__LINE__);
2685 if (op->op_flags & OPf_KIDS) {
2686 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
2688 op->op_type = OP_SSELECT;
2689 op->op_ppaddr = ppaddr[OP_SSELECT];
2691 return fold_constants(op);
2701 I32 type = op->op_type;
2703 if (!(op->op_flags & OPf_KIDS)) {
2705 return newUNOP(type, 0,
2706 scalar(newUNOP(OP_RV2AV, 0,
2707 scalar(newGVOP(OP_GV, 0,
2708 gv_fetchpv((subline ? "_" : "ARGV"), TRUE) )))));
2710 return scalar(refkids(ck_fun(op), type));
2717 if (op->op_flags & OPf_STACKED) {
2718 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
2719 kid = kUNOP->op_first; /* get past sv2gv */
2720 if (kid->op_type == OP_LEAVE) {
2724 kid->op_type = OP_NULL; /* wipe out leave */
2725 kid->op_ppaddr = ppaddr[OP_NULL];
2728 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
2729 if (k->op_next == kid)
2732 kid->op_type = OP_NULL; /* wipe out enter */
2733 kid->op_ppaddr = ppaddr[OP_NULL];
2735 kid = cLISTOP->op_first->op_sibling;
2736 kid->op_type = OP_NULL; /* wipe out sv2gv */
2737 kid->op_ppaddr = ppaddr[OP_NULL];
2740 op->op_flags |= OPf_SPECIAL;
2752 if (op->op_flags & OPf_STACKED)
2753 return no_fh_allowed(op);
2755 if (!(op->op_flags & OPf_KIDS))
2756 op = prepend_elem(OP_SPLIT,
2758 newPMOP(OP_MATCH, OPf_SPECIAL),
2759 newSVOP(OP_CONST, 0, newSVpv(" ", 1)),
2763 kid = cLISTOP->op_first;
2764 if (kid->op_type == OP_PUSHMARK)
2765 fatal("panic: ck_split");
2767 if (kid->op_type != OP_MATCH) {
2768 OP *sibl = kid->op_sibling;
2769 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
2770 if (cLISTOP->op_first == cLISTOP->op_last)
2771 cLISTOP->op_last = kid;
2772 cLISTOP->op_first = kid;
2773 kid->op_sibling = sibl;
2776 kid->op_type = OP_PUSHRE;
2777 kid->op_ppaddr = ppaddr[OP_PUSHRE];
2780 if (!kid->op_sibling)
2781 append_elem(OP_SPLIT, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
2783 kid = kid->op_sibling;
2786 if (!kid->op_sibling)
2787 append_elem(OP_SPLIT, op, newSVOP(OP_CONST, 0, newSViv(0)));
2789 kid = kid->op_sibling;
2792 if (kid->op_sibling)
2793 return too_many_arguments(op);
2802 OP *o = ((cUNOP->op_first->op_sibling)
2803 ? cUNOP : ((UNOP*)cUNOP->op_first))->op_first->op_sibling;
2805 if (o->op_type == OP_RV2CV) {
2806 o->op_type = OP_NULL; /* disable rv2cv */
2807 o->op_ppaddr = ppaddr[OP_NULL];
2811 op->op_private |= OPpSUBR_DB;
2819 if (op->op_flags & OPf_KIDS) {
2820 SVOP *kid = (SVOP*)cUNOP->op_first;
2822 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE))
2823 op->op_flags |= OPf_SPECIAL;
2832 register OP* oldop = 0;
2833 if (!op || op->op_seq)
2835 for (; op; op = op->op_next) {
2838 switch (op->op_type) {
2843 oldop->op_next = op->op_next;
2846 op->op_seq = ++op_seq;
2850 if (op->op_next->op_type == OP_RV2SV) {
2851 op->op_next->op_type = OP_NULL;
2852 op->op_next->op_ppaddr = ppaddr[OP_NULL];
2853 op->op_flags |= op->op_next->op_flags & OPf_INTRO;
2854 op->op_next = op->op_next->op_next;
2855 op->op_type = OP_GVSV;
2856 op->op_ppaddr = ppaddr[OP_GVSV];
2858 op->op_seq = ++op_seq;
2864 op->op_seq = ++op_seq;
2865 peep(cLOGOP->op_other);
2869 op->op_seq = ++op_seq;
2870 peep(cCONDOP->op_true);
2871 peep(cCONDOP->op_false);
2875 op->op_seq = ++op_seq;
2876 peep(cLOOP->op_redoop);
2877 peep(cLOOP->op_nextop);
2878 peep(cLOOP->op_lastop);
2883 op->op_seq = ++op_seq;
2884 peep(cPMOP->op_pmreplroot);
2888 op->op_seq = ++op_seq;