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
56 if (bufptr > oldoldbufptr && bufptr - oldoldbufptr < 200 &&
57 oldoldbufptr != oldbufptr && oldbufptr != bufptr) {
58 while (isSPACE(*oldoldbufptr))
60 cpy7bit(tmp2buf, oldoldbufptr, bufptr - oldoldbufptr);
61 sprintf(tname,"next 2 tokens \"%s\"",tmp2buf);
63 else if (bufptr > oldbufptr && bufptr - oldbufptr < 200 &&
64 oldbufptr != bufptr) {
65 while (isSPACE(*oldbufptr))
67 cpy7bit(tmp2buf, oldbufptr, bufptr - oldbufptr);
68 sprintf(tname,"next token \"%s\"",tmp2buf);
70 else if (yychar > 255)
71 tname = "next token ???";
72 else if (!yychar || (yychar == ';' && !rsfp))
73 (void)strcpy(tname,"at EOF");
74 else if ((yychar & 127) == 127)
75 (void)strcpy(tname,"at end of line");
77 (void)sprintf(tname,"next char ^%c",yychar+64);
79 (void)sprintf(tname,"next char %c",yychar);
80 (void)sprintf(buf, "%s at %s line %d, %s\n",
81 s,SvPV(GvSV(curcop->cop_filegv)),curcop->cop_line,tname);
82 if (curcop->cop_line == multi_end && multi_start < multi_end)
83 sprintf(buf+strlen(buf),
84 " (Might be a runaway multi-line %c%c string starting on line %d)\n",
85 multi_open,multi_close,multi_start);
87 sv_catpv(GvSV(gv_fetchpv("@",TRUE)),buf);
90 if (++error_count >= 10)
91 fatal("%s has too many errors.\n",
92 SvPV(GvSV(curcop->cop_filegv)));
100 sprintf(tokenbuf,"Missing comma after first argument to %s function",
101 op_name[op->op_type]);
107 too_few_arguments(op)
110 sprintf(tokenbuf,"Not enough arguments for %s", op_name[op->op_type]);
116 too_many_arguments(op)
119 sprintf(tokenbuf,"Too many arguments for %s", op_name[op->op_type]);
124 /* "register" allocation */
127 pad_alloc(optype,tmptype)
134 if (AvARRAY(comppad) != curpad)
135 fatal("panic: pad_alloc");
136 if (tmptype == 'M') {
138 sv = *av_fetch(comppad, AvFILL(comppad) + 1, TRUE);
139 } while (SvSTORAGE(sv)); /* need a fresh one */
140 retval = AvFILL(comppad);
144 sv = *av_fetch(comppad, ++padix, TRUE);
145 } while (SvSTORAGE(sv) == 'T' || SvSTORAGE(sv) == 'M');
148 SvSTORAGE(sv) = tmptype;
149 curpad = AvARRAY(comppad);
150 DEBUG_X(fprintf(stderr, "Pad alloc %d for %s\n", retval, op_name[optype]));
151 return (PADOFFSET)retval;
159 fatal("panic: pad_sv po");
160 DEBUG_X(fprintf(stderr, "Pad sv %d\n", po));
161 return curpad[po]; /* eventually we'll turn this into a macro */
168 if (AvARRAY(comppad) != curpad)
169 fatal("panic: pad_free curpad");
171 fatal("panic: pad_free po");
172 DEBUG_X(fprintf(stderr, "Pad free %d\n", po));
174 SvSTORAGE(curpad[po]) = 'F';
183 if (AvARRAY(comppad) != curpad)
184 fatal("panic: pad_swipe curpad");
186 fatal("panic: pad_swipe po");
187 DEBUG_X(fprintf(stderr, "Pad swipe %d\n", po));
188 curpad[po] = NEWSV(0,0);
189 SvSTORAGE(curpad[po]) = 'F';
199 if (AvARRAY(comppad) != curpad)
200 fatal("panic: pad_reset curpad");
201 DEBUG_X(fprintf(stderr, "Pad reset\n"));
202 for (po = AvMAX(comppad); po > 0; po--) {
203 if (curpad[po] && SvSTORAGE(curpad[po]) == 'T')
204 SvSTORAGE(curpad[po]) = 'F';
220 if (op->op_flags & OPf_KIDS) {
221 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling)
226 pad_free(op->op_targ);
228 switch (op->op_type) {
230 /*XXX sv_free(cGVOP->op_gv); */
233 sv_free(cSVOP->op_sv);
240 /* Contextualizers */
242 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist(o))
253 /* establish postfix order */
254 if (cUNOP->op_first) {
255 op->op_next = LINKLIST(cUNOP->op_first);
256 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
258 kid->op_next = LINKLIST(kid->op_sibling);
274 if (op && op->op_flags & OPf_KIDS) {
275 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
287 if (!op || (op->op_flags & OPf_KNOW)) /* assumes no premature commitment */
290 op->op_flags &= ~OPf_LIST;
291 op->op_flags |= OPf_KNOW;
293 switch (op->op_type) {
295 scalar(cBINOP->op_first);
305 if (!(op->op_flags & OPf_KIDS))
311 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
319 op = prepend_elem(OP_LIST, newOP(OP_PUSHMARK, 0), op);
322 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
335 if (op->op_flags & OPf_LIST)
338 op->op_flags |= OPf_KNOW;
340 switch (op->op_type) {
345 op->op_type = OP_NULL; /* don't execute a constant */
346 sv_free(cSVOP->op_sv); /* don't even remember it */
350 op->op_type = OP_PREINC;
351 op->op_ppaddr = ppaddr[OP_PREINC];
355 op->op_type = OP_PREDEC;
356 op->op_ppaddr = ppaddr[OP_PREDEC];
360 scalarvoid(cBINOP->op_first);
365 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
372 if (!(op->op_flags & OPf_KIDS))
377 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
381 op = prepend_elem(OP_LIST, newOP(OP_PUSHMARK, 0), op);
382 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
394 if (op && op->op_flags & OPf_KIDS) {
395 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
407 if (!op || (op->op_flags & OPf_KNOW)) /* assumes no premature commitment */
410 op->op_flags |= (OPf_KNOW | OPf_LIST);
412 switch (op->op_type) {
415 list(cBINOP->op_first);
420 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
427 if (!(op->op_flags & OPf_KIDS))
429 if (!op->op_next && cUNOP->op_first->op_type == OP_FLOP) {
430 list(cBINOP->op_first);
431 return gen_constant_list(op);
439 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
457 (op->op_type == OP_LINESEQ ||
458 op->op_type == OP_LEAVE ||
459 op->op_type == OP_LEAVETRY) )
461 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
475 if (op && op->op_flags & OPf_KIDS) {
476 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
495 switch (op->op_type) {
497 if ((type == OP_DEFINED || type == OP_UNDEF || type == OP_REFGEN) &&
498 !(op->op_flags & OPf_STACKED)) {
499 op->op_type = OP_NULL; /* disable entersubr */
500 op->op_ppaddr = ppaddr[OP_NULL];
501 cLISTOP->op_first->op_type = OP_NULL; /* disable pushmark */
502 cLISTOP->op_first->op_ppaddr = ppaddr[OP_NULL];
507 if (type == OP_DEFINED)
508 return scalar(op); /* ordinary expression, not lvalue */
509 sprintf(tokenbuf, "Can't %s %s in %s",
510 type == OP_REFGEN ? "refer to" : "modify",
511 op_name[op->op_type],
512 type ? op_name[type] : "local");
517 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
524 ref(cUNOP->op_first, type ? type : op->op_type);
548 op->op_targ = pad_alloc(op->op_type,'M');
549 sv = PAD_SV(op->op_targ);
550 sv_upgrade(sv, SVt_PVLV);
551 sv_magic(sv, 0, op->op_type == OP_VEC ? 'v' : 'x', 0, 0);
552 curpad[op->op_targ] = sv;
555 if (!(op->op_flags & OPf_KIDS))
557 ref(cBINOP->op_first, type ? type : op->op_type);
561 ref(cBINOP->op_first, type ? type : op->op_type);
562 op->op_private = type;
567 if (type != OP_RV2HV && type != OP_RV2AV)
569 if (!(op->op_flags & OPf_KIDS))
573 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
577 op->op_flags |= OPf_LVAL;
579 op->op_flags &= ~OPf_SPECIAL;
580 op->op_flags |= OPf_LOCAL;
582 else if (type == OP_AASSIGN || type == OP_SASSIGN)
583 op->op_flags |= OPf_SPECIAL;
592 o->op_flags |= OPf_PARENS;
597 bind_match(type, left, right)
604 if (right->op_type == OP_MATCH ||
605 right->op_type == OP_SUBST ||
606 right->op_type == OP_TRANS) {
607 right->op_flags |= OPf_STACKED;
608 if (right->op_type != OP_MATCH)
609 left = ref(left, right->op_type);
610 if (right->op_type == OP_TRANS)
611 op = newBINOP(OP_NULL, 0, scalar(left), right);
613 op = prepend_elem(right->op_type, scalar(left), right);
615 return newUNOP(OP_NOT, 0, scalar(op));
619 return bind_match(type, left,
620 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
629 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
630 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(op));
638 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
639 o->op_type = OP_LEAVE;
640 o->op_ppaddr = ppaddr[OP_LEAVE];
646 block_head(o, startp)
654 o = scalarseq(scope(o));
655 *startp = LINKLIST(o);
665 if (o->op_flags & OPf_PARENS)
669 return ref(o, Nullop); /* a bit kludgey */
676 if (o->op_type == OP_LIST) {
677 o = convert(OP_JOIN, 0,
678 prepend_elem(OP_LIST,
679 newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE))),
690 I32 type = o->op_type;
693 if (opargs[type] & OA_RETSCALAR)
695 if (opargs[type] & OA_TARGET)
696 o->op_targ = pad_alloc(type,'T');
698 if (!(opargs[type] & OA_FOLDCONST))
701 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
702 if (curop->op_type != OP_CONST && curop->op_type != OP_LIST) {
711 if (o->op_targ && *stack_sp == PAD_SV(o->op_targ))
712 pad_swipe(o->op_targ);
714 if (type == OP_RV2GV)
715 return newGVOP(OP_GV, 0, *(stack_sp--));
717 return newSVOP(OP_CONST, 0, *(stack_sp--));
720 if (!(opargs[type] & OA_OTHERINT))
722 if (!(o->op_flags & OPf_KIDS))
725 for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
726 if (curop->op_type == OP_CONST) {
727 if (SvIOK(((SVOP*)curop)->op_sv))
731 if (opargs[curop->op_type] & OA_RETINTEGER)
736 o->op_ppaddr = ppaddr[++(o->op_type)];
748 I32 oldtmps_floor = tmps_floor;
752 tmpmark = stack_sp - stack_base;
753 anonop = newANONLIST(o);
754 curop = LINKLIST(anonop);
758 tmpsp = stack_sp - stack_base;
759 tmps_floor = oldtmps_floor;
760 stack_sp = stack_base + tmpmark;
762 o->op_type = OP_RV2AV;
763 o->op_ppaddr = ppaddr[OP_RV2AV];
765 curop = ((UNOP*)o)->op_first;
766 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, newSVsv(stack_sp[1]));
768 curop = ((UNOP*)anonop)->op_first;
769 curop = ((UNOP*)curop)->op_first;
770 curop->op_sibling = 0;
778 convert(type, flags, op)
786 if (opargs[type] & OA_MARK)
787 op = prepend_elem(OP_LIST, newOP(OP_PUSHMARK, 0), op);
789 if (!op || op->op_type != OP_LIST)
790 op = newLISTOP(OP_LIST, 0, op, Nullop);
793 op->op_ppaddr = ppaddr[type];
794 op->op_flags |= flags;
796 op = (*check[type])(op);
797 if (op->op_type != type)
800 if (cLISTOP->op_children < 7) {
801 /* XXX do we really need to do this if we're done appending?? */
802 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
804 cLISTOP->op_last = last; /* in case check substituted last arg */
807 return fold_constants(op);
810 /* List constructors */
813 append_elem(type, first, last)
822 else if (first->op_type == type) {
823 if (first->op_flags & OPf_KIDS)
824 ((LISTOP*)first)->op_last->op_sibling = last;
826 first->op_flags |= OPf_KIDS;
827 ((LISTOP*)first)->op_first = last;
829 ((LISTOP*)first)->op_last = last;
830 ((LISTOP*)first)->op_children++;
834 return newLISTOP(type, 0, first, last);
838 append_list(type, first, last)
847 else if (first->op_type != type)
848 return prepend_elem(type, (OP*)first, (OP*)last);
849 else if (last->op_type != type)
850 return append_elem(type, (OP*)first, (OP*)last);
852 first->op_last->op_sibling = last->op_first;
853 first->op_last = last->op_last;
854 first->op_children += last->op_children;
855 if (first->op_children)
856 last->op_flags |= OPf_KIDS;
863 prepend_elem(type, first, last)
872 else if (last->op_type == type) {
873 if (!(last->op_flags & OPf_KIDS)) {
874 ((LISTOP*)last)->op_last = first;
875 last->op_flags |= OPf_KIDS;
877 first->op_sibling = ((LISTOP*)last)->op_first;
878 ((LISTOP*)last)->op_first = first;
879 ((LISTOP*)last)->op_children++;
883 return newLISTOP(type, 0, first, last);
895 newLISTOP(type, flags, first, last)
903 Newz(1101, listop, 1, LISTOP);
905 listop->op_type = type;
906 listop->op_ppaddr = ppaddr[type];
907 listop->op_children = (first != 0) + (last != 0);
908 listop->op_flags = flags;
909 if (listop->op_children)
910 listop->op_flags |= OPf_KIDS;
914 else if (!first && last)
916 listop->op_first = first;
917 listop->op_last = last;
918 if (first && first != last)
919 first->op_sibling = last;
930 Newz(1101, op, 1, OP);
932 op->op_ppaddr = ppaddr[type];
933 op->op_flags = flags;
936 /* op->op_private = 0; */
937 if (opargs[type] & OA_RETSCALAR)
939 if (opargs[type] & OA_TARGET)
940 op->op_targ = pad_alloc(type,'T');
941 return (*check[type])(op);
945 newUNOP(type, flags, first)
952 if (opargs[type] & OA_MARK) {
953 if (first->op_type == OP_LIST)
954 prepend_elem(OP_LIST, newOP(OP_PUSHMARK, 0), first);
956 return newBINOP(type, flags, newOP(OP_PUSHMARK, 0), first);
959 Newz(1101, unop, 1, UNOP);
960 unop->op_type = type;
961 unop->op_ppaddr = ppaddr[type];
962 unop->op_first = first;
963 unop->op_flags = flags | OPf_KIDS;
964 unop->op_private = 1;
966 unop = (UNOP*)(*check[type])((OP*)unop);
970 return fold_constants(unop);
974 newBINOP(type, flags, first, last)
981 Newz(1101, binop, 1, BINOP);
984 first = newOP(OP_NULL, 0);
986 binop->op_type = type;
987 binop->op_ppaddr = ppaddr[type];
988 binop->op_first = first;
989 binop->op_flags = flags | OPf_KIDS;
992 binop->op_private = 1;
995 binop->op_private = 2;
996 first->op_sibling = last;
999 binop = (BINOP*)(*check[type])((OP*)binop);
1003 binop->op_last = last = binop->op_first->op_sibling;
1005 return fold_constants(binop);
1009 pmtrans(op, expr, repl)
1014 PMOP *pm = (PMOP*)op;
1015 SV *tstr = ((SVOP*)expr)->op_sv;
1016 SV *rstr = ((SVOP*)repl)->op_sv;
1017 register char *t = SvPVn(tstr);
1018 register char *r = SvPVn(rstr);
1019 I32 tlen = SvCUR(tstr);
1020 I32 rlen = SvCUR(rstr);
1026 register short *tbl;
1028 tbl = (short*)cPVOP->op_pv;
1029 complement = op->op_private & OPpTRANS_COMPLEMENT;
1030 delete = op->op_private & OPpTRANS_DELETE;
1031 squash = op->op_private & OPpTRANS_SQUASH;
1034 Zero(tbl, 256, short);
1035 for (i = 0; i < tlen; i++)
1036 tbl[t[i] & 0377] = -1;
1037 for (i = 0, j = 0; i < 256; i++) {
1043 tbl[i] = r[j-1] & 0377;
1048 tbl[i] = r[j++] & 0377;
1053 if (!rlen && !delete) {
1056 for (i = 0; i < 256; i++)
1058 for (i = 0, j = 0; i < tlen; i++,j++) {
1061 if (tbl[t[i] & 0377] == -1)
1062 tbl[t[i] & 0377] = -2;
1067 if (tbl[t[i] & 0377] == -1)
1068 tbl[t[i] & 0377] = r[j] & 0377;
1078 newPMOP(type, flags)
1084 Newz(1101, pmop, 1, PMOP);
1085 pmop->op_type = type;
1086 pmop->op_ppaddr = ppaddr[type];
1087 pmop->op_flags = flags;
1088 pmop->op_private = 0;
1090 /* link into pm list */
1091 if (type != OP_TRANS) {
1092 pmop->op_pmnext = HvPMROOT(curstash);
1093 HvPMROOT(curstash) = pmop;
1100 pmruntime(op, expr, repl)
1108 if (op->op_type == OP_TRANS)
1109 return pmtrans(op, expr, repl);
1113 if (expr->op_type == OP_CONST) {
1114 SV *pat = ((SVOP*)expr)->op_sv;
1115 char *p = SvPVn(pat);
1116 if ((op->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
1117 sv_setpv(pat, "\\s+", 3);
1119 pm->op_pmflags |= PMf_SKIPWHITE;
1121 scan_prefix(pm, p, SvCUR(pat));
1122 if (pm->op_pmshort && (pm->op_pmflags & PMf_SCANFIRST))
1123 fbm_compile(pm->op_pmshort, pm->op_pmflags & PMf_FOLD);
1124 pm->op_pmregexp = regcomp(p, p + SvCUR(pat), pm->op_pmflags & PMf_FOLD);
1129 Newz(1101, rcop, 1, LOGOP);
1130 rcop->op_type = OP_REGCOMP;
1131 rcop->op_ppaddr = ppaddr[OP_REGCOMP];
1132 rcop->op_first = scalar(expr);
1133 rcop->op_flags |= OPf_KIDS;
1134 rcop->op_private = 1;
1135 rcop->op_other = op;
1137 /* establish postfix order */
1138 rcop->op_next = LINKLIST(expr);
1139 expr->op_next = (OP*)rcop;
1141 prepend_elem(op->op_type, scalar(rcop), op);
1145 if (repl->op_type == OP_CONST) {
1146 pm->op_pmflags |= PMf_CONST;
1147 prepend_elem(op->op_type, scalar(repl), op);
1152 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
1153 if (opargs[curop->op_type] & OA_DANGEROUS) {
1154 if (curop->op_type == OP_GV) {
1155 GV *gv = ((GVOP*)curop)->op_gv;
1156 if (index("&`'123456789+", *GvENAME(gv)))
1159 else if (curop->op_type == OP_RV2CV)
1161 else if (curop->op_type == OP_RV2SV ||
1162 curop->op_type == OP_RV2AV ||
1163 curop->op_type == OP_RV2HV ||
1164 curop->op_type == OP_RV2GV) {
1165 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
1173 if (curop == repl) {
1174 pm->op_pmflags |= PMf_CONST; /* const for long enough */
1175 prepend_elem(op->op_type, scalar(repl), op);
1178 Newz(1101, rcop, 1, LOGOP);
1179 rcop->op_type = OP_SUBSTCONT;
1180 rcop->op_ppaddr = ppaddr[OP_SUBSTCONT];
1181 rcop->op_first = scalar(repl);
1182 rcop->op_flags |= OPf_KIDS;
1183 rcop->op_private = 1;
1184 rcop->op_other = op;
1186 /* establish postfix order */
1187 rcop->op_next = LINKLIST(repl);
1188 repl->op_next = (OP*)rcop;
1190 pm->op_pmreplroot = scalar(rcop);
1191 pm->op_pmreplstart = LINKLIST(rcop);
1201 newSVOP(type, flags, sv)
1207 Newz(1101, svop, 1, SVOP);
1208 svop->op_type = type;
1209 svop->op_ppaddr = ppaddr[type];
1211 svop->op_next = (OP*)svop;
1212 svop->op_flags = flags;
1213 if (opargs[type] & OA_RETSCALAR)
1215 if (opargs[type] & OA_TARGET)
1216 svop->op_targ = pad_alloc(type,'T');
1217 return (*check[type])((OP*)svop);
1221 newGVOP(type, flags, gv)
1227 Newz(1101, gvop, 1, GVOP);
1228 gvop->op_type = type;
1229 gvop->op_ppaddr = ppaddr[type];
1230 gvop->op_gv = (GV*)sv_ref(gv);
1231 gvop->op_next = (OP*)gvop;
1232 gvop->op_flags = flags;
1233 if (opargs[type] & OA_RETSCALAR)
1235 if (opargs[type] & OA_TARGET)
1236 gvop->op_targ = pad_alloc(type,'T');
1237 return (*check[type])((OP*)gvop);
1241 newPVOP(type, flags, pv)
1247 Newz(1101, pvop, 1, PVOP);
1248 pvop->op_type = type;
1249 pvop->op_ppaddr = ppaddr[type];
1251 pvop->op_next = (OP*)pvop;
1252 pvop->op_flags = flags;
1253 if (opargs[type] & OA_RETSCALAR)
1255 if (opargs[type] & OA_TARGET)
1256 pvop->op_targ = pad_alloc(type,'T');
1257 return (*check[type])((OP*)pvop);
1261 newCVOP(type, flags, cv, cont)
1268 Newz(1101, cvop, 1, CVOP);
1269 cvop->op_type = type;
1270 cvop->op_ppaddr = ppaddr[type];
1272 cvop->op_cont = cont;
1273 cvop->op_next = (OP*)cvop;
1274 cvop->op_flags = flags;
1275 if (opargs[type] & OA_RETSCALAR)
1277 if (opargs[type] & OA_TARGET)
1278 cvop->op_targ = pad_alloc(type,'T');
1279 return (*check[type])((OP*)cvop);
1288 SV *sv = cSVOP->op_sv;
1289 char *name = SvPVn(sv);
1291 save_hptr(&curstash);
1292 save_item(curstname);
1293 sv_setpv(curstname,name);
1294 sprintf(tmpbuf,"'_%s",name);
1295 tmpgv = gv_fetchpv(tmpbuf,TRUE);
1297 GvHV(tmpgv) = newHV(0);
1298 curstash = GvHV(tmpgv);
1299 if (!HvNAME(curstash))
1300 HvNAME(curstash) = savestr(name);
1301 HvCOEFFSIZE(curstash) = 0;
1308 newSLICEOP(flags, subscript, listval)
1313 return newBINOP(OP_LSLICE, flags,
1314 list(prepend_elem(OP_LIST, newOP(OP_PUSHMARK, 0), subscript)),
1315 list(prepend_elem(OP_LIST, newOP(OP_PUSHMARK, 0), listval)) );
1325 if (op->op_type == OP_NULL && op->op_flags & OPf_KIDS)
1326 op = cUNOP->op_first;
1328 if (op->op_type == OP_COND_EXPR) {
1329 I32 t = list_assignment(cCONDOP->op_first->op_sibling);
1330 I32 f = list_assignment(cCONDOP->op_first->op_sibling->op_sibling);
1335 yyerror("Assignment to both a list and a scalar");
1339 if (op->op_type == OP_LIST || op->op_flags & OPf_PARENS ||
1340 op->op_type == OP_RV2AV || op->op_type == OP_RV2HV ||
1341 op->op_type == OP_ASLICE || op->op_type == OP_HSLICE)
1344 if (op->op_type == OP_RV2SV)
1351 newASSIGNOP(flags, left, right)
1358 if (list_assignment(left)) {
1360 left = ref(left, OP_AASSIGN);
1361 if (right && right->op_type == OP_SPLIT) {
1362 if ((op = ((LISTOP*)right)->op_first) && op->op_type == OP_PUSHRE) {
1363 PMOP *pm = (PMOP*)op;
1364 if (left->op_type == OP_RV2AV) {
1365 op = ((UNOP*)left)->op_first;
1366 if (op->op_type == OP_GV && !pm->op_pmreplroot) {
1367 pm->op_pmreplroot = (OP*)((GVOP*)op)->op_gv;
1368 pm->op_pmflags |= PMf_ONCE;
1374 if (refcount < 10000) {
1375 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
1377 sv_setiv(sv, refcount+1);
1382 op = newBINOP(OP_AASSIGN, flags,
1383 list(prepend_elem(OP_LIST, newOP(OP_PUSHMARK, 0), right)),
1384 list(prepend_elem(OP_LIST, newOP(OP_PUSHMARK, 0), left)) );
1386 if (!(left->op_flags & OPf_LOCAL)) {
1387 static int generation = 0;
1391 for (curop = LINKLIST(op); curop != op; curop = LINKLIST(curop)) {
1392 if (opargs[curop->op_type] & OA_DANGEROUS) {
1393 if (curop->op_type == OP_GV) {
1394 GV *gv = ((GVOP*)curop)->op_gv;
1395 if (gv == defgv || SvCUR(gv) == generation)
1397 SvCUR(gv) = generation;
1399 else if (curop->op_type == OP_RV2CV)
1401 else if (curop->op_type == OP_RV2SV ||
1402 curop->op_type == OP_RV2AV ||
1403 curop->op_type == OP_RV2HV ||
1404 curop->op_type == OP_RV2GV) {
1405 if (lastop->op_type != OP_GV) /* funny deref? */
1414 op->op_private = OPpASSIGN_COMMON;
1416 op->op_targ = pad_alloc(OP_AASSIGN, 'T'); /* for scalar context */
1420 right = newOP(OP_UNDEF, 0);
1421 if (right->op_type == OP_READLINE) {
1422 right->op_flags |= OPf_STACKED;
1423 return newBINOP(OP_NULL, flags, ref(scalar(left), OP_SASSIGN), scalar(right));
1426 op = newBINOP(OP_SASSIGN, flags,
1427 scalar(right), ref(scalar(left), OP_SASSIGN) );
1432 newSTATEOP(flags, label, op)
1439 Newz(1101, cop, 1, COP);
1440 cop->op_type = OP_CURCOP;
1441 cop->op_ppaddr = ppaddr[OP_CURCOP];
1442 cop->op_flags = flags;
1443 cop->op_private = 0;
1444 cop->op_next = (OP*)cop;
1446 cop->cop_label = label;
1448 if (copline == NOLINE)
1449 cop->cop_line = curcop->cop_line;
1451 cop->cop_line = copline;
1454 cop->cop_filegv = curcop->cop_filegv;
1455 cop->cop_stash = curstash;
1457 return prepend_elem(OP_LINESEQ, (OP*)cop, op);
1461 newLOGOP(type, flags, first, other)
1471 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
1472 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
1473 if (type == OP_AND || type == OP_OR) {
1479 first = cUNOP->op_first;
1481 first->op_next = op->op_next;
1482 cUNOP->op_first = Nullop;
1486 if (first->op_type == OP_CONST) {
1487 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
1496 else if (first->op_type == OP_WANTARRAY) {
1506 Newz(1101, logop, 1, LOGOP);
1508 logop->op_type = type;
1509 logop->op_ppaddr = ppaddr[type];
1510 logop->op_first = first;
1511 logop->op_flags = flags | OPf_KIDS;
1512 logop->op_other = LINKLIST(other);
1513 logop->op_private = 1;
1515 /* establish postfix order */
1516 logop->op_next = LINKLIST(first);
1517 first->op_next = (OP*)logop;
1518 first->op_sibling = other;
1520 op = newUNOP(OP_NULL, 0, (OP*)logop);
1521 other->op_next = op;
1527 newCONDOP(flags, first, true, false)
1537 return newLOGOP(OP_AND, 0, first, true);
1540 if (first->op_type == OP_CONST) {
1541 if (SvTRUE(((SVOP*)first)->op_sv)) {
1552 else if (first->op_type == OP_WANTARRAY) {
1556 Newz(1101, condop, 1, CONDOP);
1558 condop->op_type = OP_COND_EXPR;
1559 condop->op_ppaddr = ppaddr[OP_COND_EXPR];
1560 condop->op_first = first;
1561 condop->op_flags = flags | OPf_KIDS;
1562 condop->op_true = LINKLIST(true);
1563 condop->op_false = LINKLIST(false);
1564 condop->op_private = 1;
1566 /* establish postfix order */
1567 condop->op_next = LINKLIST(first);
1568 first->op_next = (OP*)condop;
1570 first->op_sibling = true;
1571 true->op_sibling = false;
1572 op = newUNOP(OP_NULL, 0, (OP*)condop);
1575 false->op_next = op;
1581 newRANGE(flags, left, right)
1591 Newz(1101, condop, 1, CONDOP);
1593 condop->op_type = OP_RANGE;
1594 condop->op_ppaddr = ppaddr[OP_RANGE];
1595 condop->op_first = left;
1596 condop->op_flags = OPf_KIDS;
1597 condop->op_true = LINKLIST(left);
1598 condop->op_false = LINKLIST(right);
1599 condop->op_private = 1;
1601 left->op_sibling = right;
1603 condop->op_next = (OP*)condop;
1604 flip = newUNOP(OP_FLIP, flags, (OP*)condop);
1605 flop = newUNOP(OP_FLOP, 0, flip);
1606 op = newUNOP(OP_NULL, 0, flop);
1609 left->op_next = flip;
1610 right->op_next = flop;
1612 condop->op_targ = pad_alloc(OP_RANGE, 'M');
1613 sv_upgrade(PAD_SV(condop->op_targ), SVt_PVNV);
1614 flip->op_targ = pad_alloc(OP_RANGE, 'M');
1615 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
1617 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
1618 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
1621 if (!flip->op_private || !flop->op_private)
1622 linklist(op); /* blow off optimizer unless constant */
1628 newLOOPOP(flags, debuggable, expr, block)
1634 OP* listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
1635 OP* op = newLOGOP(OP_AND, 0, expr, listop);
1636 ((LISTOP*)listop)->op_last->op_next = LINKLIST(op);
1638 if (block->op_flags & OPf_SPECIAL && /* skip conditional on do {} ? */
1639 (block->op_type == OP_ENTERSUBR || block->op_type == OP_NULL))
1640 op->op_next = ((LOGOP*)cUNOP->op_first)->op_other;
1642 op->op_flags |= flags;
1647 newWHILEOP(flags, debuggable, loop, expr, block, cont)
1661 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB))
1662 expr = newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), expr);
1665 block = newOP(OP_NULL, 0);
1668 next = LINKLIST(cont);
1670 cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
1672 listop = append_list(OP_LINESEQ, block, cont);
1673 redo = LINKLIST(listop);
1676 op = newLOGOP(OP_AND, 0, expr, scalar(listop));
1677 ((LISTOP*)listop)->op_last->op_next = condop =
1678 (op == listop ? redo : LINKLIST(op));
1686 Newz(1101,loop,1,LOOP);
1687 loop->op_type = OP_ENTERLOOP;
1688 loop->op_ppaddr = ppaddr[OP_ENTERLOOP];
1689 loop->op_private = 0;
1690 loop->op_next = (OP*)loop;
1693 op = newBINOP(OP_LEAVELOOP, 0, loop, op);
1695 loop->op_redoop = redo;
1696 loop->op_lastop = op;
1699 loop->op_nextop = next;
1701 loop->op_nextop = op;
1703 op->op_flags |= flags;
1708 newFOROP(flags,label,forline,sv,expr,block,cont)
1721 if (sv->op_type == OP_RV2SV) {
1723 sv = cUNOP->op_first;
1725 cUNOP->op_first = Nullop;
1729 fatal("Can't use %s for loop variable", op_name[sv->op_type]);
1732 sv = newGVOP(OP_GV, 0, defgv);
1734 loop = (LOOP*)list(convert(OP_ENTERITER, 0,
1735 append_elem(OP_LIST,
1736 prepend_elem(OP_LIST, newOP(OP_PUSHMARK, 0), expr),
1738 return newSTATEOP(0, label, newWHILEOP(flags, 1,
1739 loop, newOP(OP_ITER), block, cont));
1746 if (!CvUSERSUB(cv) && CvROOT(cv)) {
1747 op_free(CvROOT(cv));
1748 CvROOT(cv) = Nullop;
1750 warn("Deleting active subroutine"); /* XXX */
1751 if (CvPADLIST(cv)) {
1752 I32 i = AvFILL(CvPADLIST(cv));
1754 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
1758 av_free(CvPADLIST(cv));
1765 newSUB(floor,op,block)
1771 char *name = SvPVnx(cSVOP->op_sv);
1772 GV *gv = gv_fetchpv(name,TRUE);
1775 if (cv = GvCV(gv)) {
1777 CvDELETED(cv) = TRUE; /* probably an autoloader */
1780 line_t oldline = curcop->cop_line;
1782 curcop->cop_line = copline;
1783 warn("Subroutine %s redefined",name);
1784 curcop->cop_line = oldline;
1790 sv_upgrade(cv, SVt_PVCV);
1792 CvFILEGV(cv) = curcop->cop_filegv;
1796 av_store(av, 1, (SV*)comppad);
1800 CvROOT(cv) = newUNOP(OP_LEAVESUBR, 0, scalarseq(block));
1801 CvSTART(cv) = LINKLIST(CvROOT(cv));
1802 CvROOT(cv)->op_next = 0;
1804 CvDELETED(cv) = FALSE;
1807 SV *tmpstr = sv_mortalcopy(&sv_undef);
1809 sprintf(buf,"%s:%ld",SvPV(GvSV(curcop->cop_filegv)), subline);
1810 sv = newSVpv(buf,0);
1812 sprintf(buf,"%ld",(long)curcop->cop_line);
1814 gv_efullname(tmpstr,gv);
1815 hv_store(GvHV(DBsub), SvPV(tmpstr), SvCUR(tmpstr), sv, 0);
1823 newUSUB(name, ix, subaddr, filename)
1830 GV *gv = gv_fetchpv(name,allgvs);
1832 if (!gv) /* unused function */
1834 if (cv = GvCV(gv)) {
1836 warn("Subroutine %s redefined",name);
1837 if (!CvUSERSUB(cv) && CvROOT(cv)) {
1838 op_free(CvROOT(cv));
1839 CvROOT(cv) = Nullop;
1844 sv_upgrade(cv, SVt_PVCV);
1846 CvFILEGV(cv) = gv_fetchfile(filename);
1847 CvUSERSUB(cv) = subaddr;
1848 CvUSERINDEX(cv) = ix;
1849 CvDELETED(cv) = FALSE;
1853 newFORM(floor,op,block)
1864 name = SvPVnx(cSVOP->op_sv);
1867 gv = gv_fetchpv(name,TRUE);
1868 if (cv = GvFORM(gv)) {
1870 line_t oldline = curcop->cop_line;
1872 curcop->cop_line = copline;
1873 warn("Format %s redefined",name);
1874 curcop->cop_line = oldline;
1879 sv_upgrade(cv, SVt_PVFM);
1881 CvFILEGV(cv) = curcop->cop_filegv;
1883 CvPADLIST(cv) = av = newAV();
1885 av_store(av, 1, (SV*)comppad);
1888 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
1889 CvSTART(cv) = LINKLIST(CvROOT(cv));
1890 CvROOT(cv)->op_next = 0;
1892 CvDELETED(cv) = FALSE;
1905 Newz(1101, mop, 1, LOGOP);
1906 mop->op_type = OP_METHOD;
1907 mop->op_ppaddr = ppaddr[OP_METHOD];
1908 mop->op_first = scalar(ref);
1909 mop->op_flags |= OPf_KIDS;
1910 mop->op_private = 1;
1911 mop->op_other = LINKLIST(name);
1912 mop->op_targ = pad_alloc(OP_METHOD,'T');
1913 mop->op_next = LINKLIST(ref);
1914 ref->op_next = (OP*)mop;
1922 return newUNOP(OP_REFGEN, 0, ref(list(convert(OP_ANONLIST, 0, op))));
1929 return newUNOP(OP_REFGEN, 0, ref(list(convert(OP_ANONHASH, 0, op))));
1936 if (o->op_type == OP_RV2SV) {
1937 o->op_type = OP_RV2AV;
1938 o->op_ppaddr = ppaddr[OP_RV2AV];
1942 warn("oops: oopsAV");
1950 if (o->op_type == OP_RV2SV || o->op_type == OP_RV2AV) {
1951 o->op_type = OP_RV2HV;
1952 o->op_ppaddr = ppaddr[OP_RV2HV];
1956 warn("oops: oopsHV");
1964 return newUNOP(OP_RV2AV, 0, scalar(o));
1971 return newUNOP(OP_RV2GV, 0, scalar(o));
1978 return newUNOP(OP_RV2HV, 0, scalar(o));
1985 fatal("NOT IMPL LINE %d",__LINE__);
1994 return newUNOP(OP_RV2CV, 0, scalar(o));
2001 return newUNOP(OP_RV2SV, 0, scalar(o));
2004 /* Check routines. */
2010 /* XXX need to optimize constant subscript here. */
2018 if (cUNOP->op_first->op_type == OP_CONCAT)
2019 op->op_flags |= OPf_STACKED;
2027 if (op->op_flags & OPf_KIDS) {
2029 op = refkids(ck_fun(op), op->op_type);
2030 if (op->op_private != 1)
2032 newop = cUNOP->op_first->op_sibling;
2033 if (!newop || newop->op_type != OP_RV2SV)
2035 op_free(cUNOP->op_first);
2036 cUNOP->op_first = newop;
2038 op->op_type = OP_SCHOP;
2039 op->op_ppaddr = ppaddr[OP_SCHOP];
2047 I32 type = op->op_type;
2049 if (op->op_flags & OPf_KIDS)
2052 if (op->op_flags & OPf_SPECIAL) {
2054 op = newUNOP(type, 0, newGVOP(OP_GV, 0, gv_fetchpv("main'ARGV", TRUE)));
2063 if (op->op_flags & OPf_KIDS) {
2064 SVOP *kid = (SVOP*)cUNOP->op_first;
2066 if (kid->op_type == OP_CONST) {
2068 op->op_type = OP_EVALONCE;
2069 op->op_ppaddr = ppaddr[OP_EVALONCE];
2072 else if (kid->op_type == OP_LINESEQ) {
2075 kid->op_next = op->op_next;
2076 cUNOP->op_first = 0;
2079 Newz(1101, enter, 1, LOGOP);
2080 enter->op_type = OP_ENTERTRY;
2081 enter->op_ppaddr = ppaddr[OP_ENTERTRY];
2082 enter->op_private = 0;
2084 /* establish postfix order */
2085 enter->op_next = (OP*)enter;
2087 op = prepend_elem(OP_LINESEQ, enter, kid);
2088 op->op_type = OP_LEAVETRY;
2089 op->op_ppaddr = ppaddr[OP_LEAVETRY];
2090 enter->op_other = op;
2096 op = newUNOP(OP_ENTEREVAL, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
2107 if (op->op_flags & OPf_STACKED) {
2108 kid = cUNOP->op_first->op_sibling;
2109 if (kid->op_type == OP_RV2GV) {
2110 kid->op_type = OP_NULL;
2111 kid->op_ppaddr = ppaddr[OP_NULL];
2121 o = fold_constants(o);
2122 if (o->op_type == OP_CONST)
2131 SVOP *kid = (SVOP*)cUNOP->op_first;
2132 if (kid->op_type == OP_CONST) {
2133 kid->op_type = OP_GV;
2134 kid->op_sv = (SV*)gv_fetchpv(SvPVnx(kid->op_sv),
2135 1+(op->op_type==OP_RV2CV));
2151 I32 type = op->op_type;
2153 if (op->op_flags & OPf_SPECIAL)
2156 if (op->op_flags & OPf_KIDS) {
2157 SVOP *kid = (SVOP*)cUNOP->op_first;
2159 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
2160 OP *newop = newGVOP(type, OPf_SPECIAL,
2161 gv_fetchpv(SvPVnx(kid->op_sv), TRUE));
2168 if (type == OP_FTTTY)
2169 return newGVOP(type, OPf_SPECIAL, gv_fetchpv("main'STDIN", TRUE));
2171 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
2184 register I32 oa = opargs[op->op_type] >> 8;
2186 if (op->op_flags & OPf_STACKED) {
2187 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
2190 return no_fh_allowed(op);
2193 if (op->op_flags & OPf_KIDS) {
2194 tokid = &cLISTOP->op_first;
2195 kid = cLISTOP->op_first;
2196 if (kid->op_type == OP_PUSHMARK) {
2197 tokid = &kid->op_sibling;
2198 kid = kid->op_sibling;
2203 sibl = kid->op_sibling;
2217 if (kid->op_type == OP_CONST &&
2218 (kid->op_private & OPpCONST_BARE)) {
2219 OP *newop = newAVREF(newGVOP(OP_GV, 0,
2220 gv_fetchpv(SvPVnx(((SVOP*)kid)->op_sv), TRUE) ));
2223 kid->op_sibling = sibl;
2226 ref(kid, op->op_type);
2229 if (kid->op_type == OP_CONST &&
2230 (kid->op_private & OPpCONST_BARE)) {
2231 OP *newop = newHVREF(newGVOP(OP_GV, 0,
2232 gv_fetchpv(SvPVnx(((SVOP*)kid)->op_sv), TRUE) ));
2235 kid->op_sibling = sibl;
2238 ref(kid, op->op_type);
2242 OP *newop = newUNOP(OP_NULL, 0, scalar(kid));
2243 kid->op_sibling = 0;
2245 newop->op_next = newop;
2247 kid->op_sibling = sibl;
2252 if (kid->op_type != OP_GV) {
2253 if (kid->op_type == OP_CONST &&
2254 (kid->op_private & OPpCONST_BARE)) {
2255 OP *newop = newGVOP(OP_GV, 0,
2256 gv_fetchpv(SvPVnx(((SVOP*)kid)->op_sv), TRUE) );
2261 kid->op_sibling = 0;
2262 kid = newUNOP(OP_RV2GV, 0, scalar(kid));
2264 kid->op_sibling = sibl;
2270 ref(scalar(kid), op->op_type);
2274 tokid = &kid->op_sibling;
2275 kid = kid->op_sibling;
2277 op->op_private = numargs;
2279 return too_many_arguments(op);
2283 while (oa & OA_OPTIONAL)
2285 if (oa && oa != OA_LIST)
2286 return too_few_arguments(op);
2295 GV *gv = newGVgen();
2297 append_elem(OP_GLOB, op, newGVOP(OP_GV, 0, gv));
2309 op->op_flags &= ~OPf_STACKED; /* XXX do we need to scope() it? */
2313 kid = cLISTOP->op_first->op_sibling;
2314 if (kid->op_type != OP_NULL)
2315 fatal("panic: ck_grep");
2316 kid = kUNOP->op_first;
2318 Newz(1101, gwop, 1, LOGOP);
2319 gwop->op_type = OP_GREPWHILE;
2320 gwop->op_ppaddr = ppaddr[OP_GREPWHILE];
2321 gwop->op_first = list(op);
2322 gwop->op_flags |= OPf_KIDS;
2323 gwop->op_private = 1;
2324 gwop->op_other = LINKLIST(kid);
2325 gwop->op_targ = pad_alloc(OP_GREPWHILE,'T');
2326 kid->op_next = (OP*)gwop;
2335 if (op->op_flags & OPf_KIDS) {
2336 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
2337 if (kid && kid->op_type == OP_CONST)
2338 fbm_compile(((SVOP*)kid)->op_sv, 0);
2347 /* XXX length optimization goes here */
2355 return refkids(ck_fun(op), op->op_type);
2364 kid = cLISTOP->op_first;
2366 prepend_elem(op->op_type, newOP(OP_PUSHMARK), op);
2367 kid = cLISTOP->op_first;
2369 if (kid->op_type == OP_PUSHMARK)
2370 kid = kid->op_sibling;
2371 if (kid && op->op_flags & OPf_STACKED)
2372 kid = kid->op_sibling;
2373 else if (kid && !kid->op_sibling) { /* print HANDLE; */
2374 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
2375 op->op_flags |= OPf_STACKED; /* make it a filehandle */
2376 kid = newUNOP(OP_RV2GV, 0, scalar(kid));
2377 cLISTOP->op_first->op_sibling = kid;
2378 cLISTOP->op_last = kid;
2379 kid = kid->op_sibling;
2384 append_elem(op->op_type, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
2386 return listkids(op);
2393 cPMOP->op_pmflags |= PMf_RUNTIME;
2408 if (cBINOP->op_first->op_flags & OPf_PARENS) {
2409 op->op_private = OPpREPEAT_DOLIST;
2411 prepend_elem(OP_NULL, newOP(OP_PUSHMARK, 0), cBINOP->op_first);
2422 fatal("NOT IMPL LINE %d",__LINE__);
2431 if (op->op_flags & OPf_KIDS) {
2432 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
2434 op->op_type = OP_SSELECT;
2435 op->op_ppaddr = ppaddr[OP_SSELECT];
2437 return fold_constants(op);
2447 I32 type = op->op_type;
2449 if (!(op->op_flags & OPf_KIDS)) {
2451 return newUNOP(type, 0,
2452 scalar(newUNOP(OP_RV2AV, 0,
2453 scalar(newGVOP(OP_GV, 0,
2454 gv_fetchpv((subline ? "_" : "ARGV"), TRUE) )))));
2456 return scalar(refkids(ck_fun(op), type));
2463 if (op->op_flags & OPf_STACKED) {
2464 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
2465 kid = kUNOP->op_first; /* get past sv2gv */
2466 if (kid->op_type == OP_LEAVE) {
2470 kid->op_type = OP_NULL; /* wipe out leave */
2471 kid->op_ppaddr = ppaddr[OP_NULL];
2474 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
2475 if (k->op_next == kid)
2478 kid->op_type = OP_NULL; /* wipe out enter */
2479 kid->op_ppaddr = ppaddr[OP_NULL];
2481 kid = cLISTOP->op_first->op_sibling;
2482 kid->op_type = OP_NULL; /* wipe out sv2gv */
2483 kid->op_ppaddr = ppaddr[OP_NULL];
2486 op->op_flags |= OPf_SPECIAL;
2498 if (op->op_flags & OPf_STACKED)
2499 return no_fh_allowed(op);
2501 if (!(op->op_flags & OPf_KIDS))
2502 op = prepend_elem(OP_SPLIT,
2504 newPMOP(OP_MATCH, OPf_SPECIAL),
2505 newSVOP(OP_CONST, 0, newSVpv(" ", 1)),
2509 kid = cLISTOP->op_first;
2510 if (kid->op_type == OP_PUSHMARK)
2511 fatal("panic: ck_split");
2513 if (kid->op_type != OP_MATCH) {
2514 OP *sibl = kid->op_sibling;
2515 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
2516 if (cLISTOP->op_first == cLISTOP->op_last)
2517 cLISTOP->op_last = kid;
2518 cLISTOP->op_first = kid;
2519 kid->op_sibling = sibl;
2522 kid->op_type = OP_PUSHRE;
2523 kid->op_ppaddr = ppaddr[OP_PUSHRE];
2526 if (!kid->op_sibling)
2527 append_elem(OP_SPLIT, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
2529 kid = kid->op_sibling;
2532 if (!kid->op_sibling)
2533 append_elem(OP_SPLIT, op, newSVOP(OP_CONST, 0, newSViv(0)));
2535 kid = kid->op_sibling;
2538 if (kid->op_sibling)
2539 return too_many_arguments(op);
2556 if (op->op_flags & OPf_KIDS) {
2557 SVOP *kid = (SVOP*)cUNOP->op_first;
2559 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE))
2560 op->op_flags |= OPf_SPECIAL;
2569 register OP* oldop = 0;
2570 if (!op || op->op_seq)
2572 for (; op; op = op->op_next) {
2575 switch (op->op_type) {
2579 oldop->op_next = op->op_next;
2582 op->op_seq = ++op_seq;
2586 if (op->op_next->op_type == OP_RV2SV) {
2587 op->op_next->op_type = OP_NULL;
2588 op->op_next->op_ppaddr = ppaddr[OP_NULL];
2589 op->op_flags |= op->op_next->op_flags & OPf_LOCAL;
2590 op->op_next = op->op_next->op_next;
2591 op->op_type = OP_GVSV;
2592 op->op_ppaddr = ppaddr[OP_GVSV];
2594 op->op_seq = ++op_seq;
2600 op->op_seq = ++op_seq;
2601 peep(cLOGOP->op_other);
2605 op->op_seq = ++op_seq;
2606 peep(cCONDOP->op_true);
2607 peep(cCONDOP->op_false);
2611 op->op_seq = ++op_seq;
2612 peep(cLOOP->op_redoop);
2613 peep(cLOOP->op_nextop);
2614 peep(cLOOP->op_lastop);
2619 op->op_seq = ++op_seq;
2620 peep(cPMOP->op_pmreplroot);
2624 op->op_seq = ++op_seq;