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 #define USE_OP_MASK /* Turned on by default in 5.002beta1h */
25 * In the following definition, the ", (OP *) op" is just to make the compiler
26 * think the expression is of the right type: croak actually does a longjmp.
28 #define CHECKOP(type,op) \
29 ((op_mask && op_mask[type]) \
30 ? (croak("%s trapped by operation mask", op_desc[type]), (OP*)op) \
31 : (*check[type])((OP*)op))
33 #define CHECKOP(type,op) (*check[type])(op)
34 #endif /* USE_OP_MASK */
36 static I32 list_assignment _((OP *op));
37 static OP *bad_type _((I32 n, char *t, char *name, OP *kid));
38 static OP *modkids _((OP *op, I32 type));
39 static OP *no_fh_allowed _((OP *op));
40 static OP *scalarboolean _((OP *op));
41 static OP *too_few_arguments _((OP *op, char* name));
42 static OP *too_many_arguments _((OP *op, char* name));
43 static void null _((OP* op));
44 static PADOFFSET pad_findlex _((char* name, PADOFFSET newoff, I32 seq,
45 CV* startcv, I32 cx_ix));
51 SV* tmpsv = sv_newmortal();
52 gv_efullname(tmpsv, CvGV(cv));
53 return SvPV(tmpsv,na);
60 sprintf(tokenbuf,"Missing comma after first argument to %s function",
61 op_desc[op->op_type]);
67 too_few_arguments(op, name)
71 sprintf(tokenbuf,"Not enough arguments for %s", name);
77 too_many_arguments(op, name)
81 sprintf(tokenbuf,"Too many arguments for %s", name);
87 bad_type(n, t, name, kid)
93 sprintf(tokenbuf, "Type of arg %d to %s must be %s (not %s)",
94 (int) n, name, t, op_desc[kid->op_type]);
103 int type = op->op_type;
104 if (type != OP_AELEM && type != OP_HELEM) {
105 sprintf(tokenbuf, "Can't use subscript on %s", op_desc[type]);
107 if (type == OP_RV2HV || type == OP_ENTERSUB)
108 warn("(Did you mean $ or @ instead of %c?)\n",
109 type == OP_RV2HV ? '%' : '&');
113 /* "register" allocation */
122 if (!(isALPHA(name[1]) || name[1] == '_' && (int)strlen(name) > 2)) {
123 if (!isprint(name[1]))
124 sprintf(name+1, "^%c", name[1] ^ 64); /* XXX is tokenbuf, really */
125 croak("Can't use global %s in \"my\"",name);
127 off = pad_alloc(OP_PADSV, SVs_PADMY);
129 sv_upgrade(sv, SVt_PVNV);
131 av_store(comppad_name, off, sv);
132 SvNVX(sv) = (double)999999999;
133 SvIVX(sv) = 0; /* Not yet introduced--see newSTATEOP */
134 if (!min_intro_pending)
135 min_intro_pending = off;
136 max_intro_pending = off;
138 av_store(comppad, off, (SV*)newAV());
139 else if (*name == '%')
140 av_store(comppad, off, (SV*)newHV());
141 SvPADMY_on(curpad[off]);
146 #ifndef CAN_PROTOTYPE
147 pad_findlex(name, newoff, seq, startcv, cx_ix)
154 pad_findlex(char *name, PADOFFSET newoff, I32 seq, CV* startcv, I32 cx_ix)
161 register CONTEXT *cx;
164 for (cv = startcv; cv; cv = CvOUTSIDE(cv)) {
165 AV* curlist = CvPADLIST(cv);
166 SV** svp = av_fetch(curlist, 0, FALSE);
168 if (!svp || *svp == &sv_undef)
171 svp = AvARRAY(curname);
172 for (off = AvFILL(curname); off > 0; off--) {
173 if ((sv = svp[off]) &&
176 seq > (I32)SvNVX(sv) &&
177 strEQ(SvPVX(sv), name))
179 I32 depth = CvDEPTH(cv) ? CvDEPTH(cv) : 1;
180 AV *oldpad = (AV*)*av_fetch(curlist, depth, FALSE);
181 SV *oldsv = *av_fetch(oldpad, off, TRUE);
182 if (!newoff) { /* Not a mere clone operation. */
183 SV *sv = NEWSV(1103,0);
184 newoff = pad_alloc(OP_PADSV, SVs_PADMY);
185 sv_upgrade(sv, SVt_PVNV);
187 av_store(comppad_name, newoff, sv);
188 SvNVX(sv) = (double)curcop->cop_seq;
189 SvIVX(sv) = 999999999; /* A ref, intro immediately */
190 SvFLAGS(sv) |= SVf_FAKE;
192 av_store(comppad, newoff, SvREFCNT_inc(oldsv));
193 SvFLAGS(compcv) |= SVpcv_CLONE;
199 /* Nothing in current lexical context--try eval's context, if any.
200 * This is necessary to let the perldb get at lexically scoped variables.
201 * XXX This will also probably interact badly with eval tree caching.
205 for (i = cx_ix; i >= 0; i--) {
207 switch (cx->cx_type) {
209 if (i == 0 && saweval) {
210 seq = cxstack[saweval].blk_oldcop->cop_seq;
211 return pad_findlex(name, newoff, seq, main_cv, 0);
215 if (cx->blk_eval.old_op_type != OP_ENTEREVAL &&
216 cx->blk_eval.old_op_type != OP_ENTERTRY)
217 return 0; /* require must have its own scope */
224 if (debstash && CvSTASH(cv) == debstash) { /* ignore DB'* scope */
225 saweval = i; /* so we know where we were called from */
228 seq = cxstack[saweval].blk_oldcop->cop_seq;
229 return pad_findlex(name, newoff, seq, cv, i-1);
242 SV **svp = AvARRAY(comppad_name);
243 I32 seq = cop_seqmax;
245 /* The one we're looking for is probably just before comppad_name_fill. */
246 for (off = AvFILL(comppad_name); off > 0; off--) {
247 if ((sv = svp[off]) &&
250 seq > (I32)SvNVX(sv) &&
251 strEQ(SvPVX(sv), name))
253 return (PADOFFSET)off;
257 /* See if it's in a nested scope */
258 off = pad_findlex(name, 0, seq, CvOUTSIDE(compcv), cxstack_ix);
270 SV **svp = AvARRAY(comppad_name);
272 if (min_intro_pending && fill < min_intro_pending) {
273 for (off = max_intro_pending; off >= min_intro_pending; off--) {
274 if ((sv = svp[off]) && sv != &sv_undef)
275 warn("%s never introduced", SvPVX(sv));
278 /* "Deintroduce" my variables that are leaving with this scope. */
279 for (off = AvFILL(comppad_name); off > fill; off--) {
280 if ((sv = svp[off]) && sv != &sv_undef && SvIVX(sv) == 999999999)
281 SvIVX(sv) = cop_seqmax;
286 pad_alloc(optype,tmptype)
293 if (AvARRAY(comppad) != curpad)
294 croak("panic: pad_alloc");
295 if (pad_reset_pending)
297 if (tmptype & SVs_PADMY) {
299 sv = *av_fetch(comppad, AvFILL(comppad) + 1, TRUE);
300 } while (SvPADBUSY(sv)); /* need a fresh one */
301 retval = AvFILL(comppad);
305 sv = *av_fetch(comppad, ++padix, TRUE);
306 } while (SvFLAGS(sv) & (SVs_PADTMP|SVs_PADMY));
309 SvFLAGS(sv) |= tmptype;
310 curpad = AvARRAY(comppad);
311 DEBUG_X(fprintf(stderr, "Pad alloc %ld for %s\n", (long) retval, op_name[optype]));
312 return (PADOFFSET)retval;
316 #ifndef CAN_PROTOTYPE
321 #endif /* CAN_PROTOTYPE */
324 croak("panic: pad_sv po");
325 DEBUG_X(fprintf(stderr, "Pad sv %d\n", po));
326 return curpad[po]; /* eventually we'll turn this into a macro */
330 #ifndef CAN_PROTOTYPE
334 pad_free(PADOFFSET po)
335 #endif /* CAN_PROTOTYPE */
339 if (AvARRAY(comppad) != curpad)
340 croak("panic: pad_free curpad");
342 croak("panic: pad_free po");
343 DEBUG_X(fprintf(stderr, "Pad free %d\n", po));
344 if (curpad[po] && curpad[po] != &sv_undef)
345 SvPADTMP_off(curpad[po]);
351 #ifndef CAN_PROTOTYPE
355 pad_swipe(PADOFFSET po)
356 #endif /* CAN_PROTOTYPE */
358 if (AvARRAY(comppad) != curpad)
359 croak("panic: pad_swipe curpad");
361 croak("panic: pad_swipe po");
362 DEBUG_X(fprintf(stderr, "Pad swipe %d\n", po));
363 SvPADTMP_off(curpad[po]);
364 curpad[po] = NEWSV(1107,0);
365 SvPADTMP_on(curpad[po]);
375 if (AvARRAY(comppad) != curpad)
376 croak("panic: pad_reset curpad");
377 DEBUG_X(fprintf(stderr, "Pad reset\n"));
378 if (!tainting) { /* Can't mix tainted and non-tainted temporaries. */
379 for (po = AvMAX(comppad); po > padix_floor; po--) {
380 if (curpad[po] && curpad[po] != &sv_undef)
381 SvPADTMP_off(curpad[po]);
385 pad_reset_pending = FALSE;
394 register OP *kid, *nextkid;
399 if (op->op_flags & OPf_KIDS) {
400 for (kid = cUNOP->op_first; kid; kid = nextkid) {
401 nextkid = kid->op_sibling; /* Get before next freeing kid */
406 switch (op->op_type) {
408 op->op_targ = 0; /* Was holding old type, if any. */
411 op->op_targ = 0; /* Was holding hints. */
415 SvREFCNT_dec(cGVOP->op_gv);
419 SvREFCNT_dec(cCOP->cop_filegv);
422 SvREFCNT_dec(cSVOP->op_sv);
428 if (op->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
432 Safefree(cPVOP->op_pv);
435 op_free(cPMOP->op_pmreplroot);
439 pregfree(cPMOP->op_pmregexp);
440 SvREFCNT_dec(cPMOP->op_pmshort);
447 pad_free(op->op_targ);
456 if (op->op_type != OP_NULL && op->op_targ > 0)
457 pad_free(op->op_targ);
458 op->op_targ = op->op_type;
459 op->op_type = OP_NULL;
460 op->op_ppaddr = ppaddr[OP_NULL];
463 /* Contextualizers */
465 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
476 /* establish postfix order */
477 if (cUNOP->op_first) {
478 op->op_next = LINKLIST(cUNOP->op_first);
479 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
481 kid->op_next = LINKLIST(kid->op_sibling);
497 if (op && op->op_flags & OPf_KIDS) {
498 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
509 op->op_type == OP_SASSIGN && cBINOP->op_first->op_type == OP_CONST) {
510 line_t oldline = curcop->cop_line;
512 if (copline != NOLINE)
513 curcop->cop_line = copline;
514 warn("Found = in conditional, should be ==");
515 curcop->cop_line = oldline;
526 /* assumes no premature commitment */
527 if (!op || (op->op_flags & OPf_KNOW) || error_count)
530 op->op_flags &= ~OPf_LIST;
531 op->op_flags |= OPf_KNOW;
533 switch (op->op_type) {
535 if (op->op_private & OPpREPEAT_DOLIST)
536 null(((LISTOP*)cBINOP->op_first)->op_first);
537 scalar(cBINOP->op_first);
542 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
546 if ((kid = ((LISTOP*)op)->op_first) && kid->op_type == OP_PUSHRE) {
547 if (!kPMOP->op_pmreplroot)
548 deprecate("implicit split to @_");
555 if (op->op_flags & OPf_KIDS) {
556 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling)
562 scalar(cLISTOP->op_first);
567 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
587 if (!op || error_count)
589 if (op->op_flags & OPf_LIST)
592 op->op_flags |= OPf_KNOW;
594 switch (op->op_type) {
596 if (!(opargs[op->op_type] & OA_FOLDCONST))
598 if (op->op_flags & OPf_STACKED)
671 if (!(op->op_private & OPpLVAL_INTRO))
672 useless = op_desc[op->op_type];
679 if (!(op->op_private & OPpLVAL_INTRO) &&
680 (!op->op_sibling || op->op_sibling->op_type != OP_READLINE))
681 useless = "a variable";
686 curcop = ((COP*)op); /* for warning below */
692 useless = "a constant";
693 if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
695 else if (SvPOK(sv)) {
696 if (strnEQ(SvPVX(sv), "di", 2) ||
697 strnEQ(SvPVX(sv), "ds", 2) ||
698 strnEQ(SvPVX(sv), "ig", 2))
702 null(op); /* don't execute a constant */
703 SvREFCNT_dec(sv); /* don't even remember it */
707 op->op_type = OP_PREINC; /* pre-increment is faster */
708 op->op_ppaddr = ppaddr[OP_PREINC];
712 op->op_type = OP_PREDEC; /* pre-decrement is faster */
713 op->op_ppaddr = ppaddr[OP_PREDEC];
717 scalarvoid(cBINOP->op_first);
718 useless = op_desc[op->op_type];
724 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
728 if (op->op_targ == OP_NEXTSTATE || op->op_targ == OP_DBSTATE)
729 curcop = ((COP*)op); /* for warning below */
730 if (op->op_flags & OPf_STACKED)
735 if (!(op->op_flags & OPf_KIDS))
741 op->op_private |= OPpLEAVE_VOID;
744 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
748 if ((kid = ((LISTOP*)op)->op_first) && kid->op_type == OP_PUSHRE) {
749 if (!kPMOP->op_pmreplroot)
750 deprecate("implicit split to @_");
754 op->op_private |= OPpLEAVE_VOID;
757 if (useless && dowarn)
758 warn("Useless use of %s in void context", useless);
767 if (op && op->op_flags & OPf_KIDS) {
768 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
780 /* assumes no premature commitment */
781 if (!op || (op->op_flags & OPf_KNOW) || error_count)
784 op->op_flags |= (OPf_KNOW | OPf_LIST);
786 switch (op->op_type) {
789 list(cBINOP->op_first);
794 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
801 if (!(op->op_flags & OPf_KIDS))
803 if (!op->op_next && cUNOP->op_first->op_type == OP_FLOP) {
804 list(cBINOP->op_first);
805 return gen_constant_list(op);
812 list(cLISTOP->op_first);
816 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
835 if (op->op_type == OP_LINESEQ ||
836 op->op_type == OP_SCOPE ||
837 op->op_type == OP_LEAVE ||
838 op->op_type == OP_LEAVETRY)
840 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
841 if (kid->op_sibling) {
847 op->op_flags &= ~OPf_PARENS;
848 if (hints & HINT_BLOCK_SCOPE)
849 op->op_flags |= OPf_PARENS;
852 op = newOP(OP_STUB, 0);
862 if (op && op->op_flags & OPf_KIDS) {
863 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
880 if (!op || error_count)
883 switch (op->op_type) {
885 if (!(op->op_private & (OPpCONST_ARYBASE)))
887 if (eval_start && eval_start->op_type == OP_CONST) {
888 compiling.cop_arybase = (I32)SvIV(((SVOP*)eval_start)->op_sv);
892 SAVEI32(compiling.cop_arybase);
893 compiling.cop_arybase = 0;
895 else if (type == OP_REFGEN)
898 croak("That use of $[ is unsupported");
901 if ((type == OP_UNDEF || type == OP_REFGEN) &&
902 !(op->op_flags & OPf_STACKED)) {
903 op->op_type = OP_RV2CV; /* entersub => rv2cv */
904 op->op_ppaddr = ppaddr[OP_RV2CV];
905 assert(cUNOP->op_first->op_type == OP_NULL);
906 null(((LISTOP*)cUNOP->op_first)->op_first); /* disable pushmark */
912 /* grep, foreach, subcalls, refgen */
913 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
915 sprintf(tokenbuf, "Can't modify %s in %s",
916 op_desc[op->op_type],
917 type ? op_desc[type] : "local");
941 if (!(op->op_flags & OPf_STACKED))
947 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
953 if (type == OP_REFGEN && op->op_flags & OPf_PARENS) {
955 return op; /* Treat \(@foo) like ordinary list. */
959 ref(cUNOP->op_first, op->op_type);
971 if (!type && cUNOP->op_first->op_type != OP_GV)
972 croak("Can't localize a reference");
973 ref(cUNOP->op_first, op->op_type);
990 croak("Can't localize lexical variable %s",
991 SvPV(*av_fetch(comppad_name, op->op_targ, 4), na));
1006 pad_free(op->op_targ);
1007 op->op_targ = pad_alloc(op->op_type, SVs_PADMY);
1008 sv = PAD_SV(op->op_targ);
1009 sv_upgrade(sv, SVt_PVLV);
1010 sv_magic(sv, Nullsv, mtype, Nullch, 0);
1011 curpad[op->op_targ] = sv;
1012 if (op->op_flags & OPf_KIDS)
1013 mod(cBINOP->op_first->op_sibling, type);
1018 ref(cBINOP->op_first, op->op_type);
1025 if (op->op_flags & OPf_KIDS)
1026 mod(cLISTOP->op_last, type);
1030 if (!(op->op_flags & OPf_KIDS))
1032 if (op->op_targ != OP_LIST) {
1033 mod(cBINOP->op_first, type);
1038 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1042 op->op_flags |= OPf_MOD;
1044 if (type == OP_AASSIGN || type == OP_SASSIGN)
1045 op->op_flags |= OPf_SPECIAL|OPf_REF;
1047 op->op_private |= OPpLVAL_INTRO;
1048 op->op_flags &= ~OPf_SPECIAL;
1050 else if (type != OP_GREPSTART && type != OP_ENTERSUB)
1051 op->op_flags |= OPf_REF;
1061 if (op && op->op_flags & OPf_KIDS) {
1062 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1075 if (!op || error_count)
1078 switch (op->op_type) {
1080 if ((type == OP_DEFINED) &&
1081 !(op->op_flags & OPf_STACKED)) {
1082 op->op_type = OP_RV2CV; /* entersub => rv2cv */
1083 op->op_ppaddr = ppaddr[OP_RV2CV];
1084 assert(cUNOP->op_first->op_type == OP_NULL);
1085 null(((LISTOP*)cUNOP->op_first)->op_first); /* disable pushmark */
1086 op->op_flags |= OPf_SPECIAL;
1091 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
1095 ref(cUNOP->op_first, op->op_type);
1098 if (type == OP_RV2AV || type == OP_RV2HV) {
1099 op->op_private |= (type == OP_RV2AV ? OPpDEREF_AV : OPpDEREF_HV);
1100 op->op_flags |= OPf_MOD;
1106 op->op_flags |= OPf_REF;
1109 ref(cUNOP->op_first, op->op_type);
1114 op->op_flags |= OPf_REF;
1119 if (!(op->op_flags & OPf_KIDS))
1121 ref(cBINOP->op_first, type);
1125 ref(cBINOP->op_first, op->op_type);
1126 if (type == OP_RV2AV || type == OP_RV2HV) {
1127 op->op_private |= (type == OP_RV2AV ? OPpDEREF_AV : OPpDEREF_HV);
1128 op->op_flags |= OPf_MOD;
1136 if (!(op->op_flags & OPf_KIDS))
1138 ref(cLISTOP->op_last, type);
1154 if (!op || error_count)
1158 if (type == OP_LIST) {
1159 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1162 else if (type != OP_PADSV &&
1165 type != OP_PUSHMARK)
1167 sprintf(tokenbuf, "Can't declare %s in my", op_desc[op->op_type]);
1171 op->op_flags |= OPf_MOD;
1172 op->op_private |= OPpLVAL_INTRO;
1181 o->op_flags |= OPf_PARENS;
1186 bind_match(type, left, right)
1193 if (right->op_type == OP_MATCH ||
1194 right->op_type == OP_SUBST ||
1195 right->op_type == OP_TRANS) {
1196 right->op_flags |= OPf_STACKED;
1197 if (right->op_type != OP_MATCH)
1198 left = mod(left, right->op_type);
1199 if (right->op_type == OP_TRANS)
1200 op = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
1202 op = prepend_elem(right->op_type, scalar(left), right);
1204 return newUNOP(OP_NOT, 0, scalar(op));
1208 return bind_match(type, left,
1209 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
1218 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
1219 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(op));
1227 if (o->op_flags & OPf_PARENS || perldb || tainting) {
1228 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
1229 o->op_type = OP_LEAVE;
1230 o->op_ppaddr = ppaddr[OP_LEAVE];
1233 if (o->op_type == OP_LINESEQ) {
1235 o->op_type = OP_SCOPE;
1236 o->op_ppaddr = ppaddr[OP_SCOPE];
1237 kid = ((LISTOP*)o)->op_first;
1238 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE){
1239 SvREFCNT_dec(((COP*)kid)->cop_filegv);
1244 o = newLISTOP(OP_SCOPE, 0, o, Nullop);
1253 int retval = savestack_ix;
1254 comppad_name_fill = AvFILL(comppad_name);
1255 SAVEINT(min_intro_pending);
1256 SAVEINT(max_intro_pending);
1257 min_intro_pending = 0;
1258 SAVEINT(comppad_name_fill);
1259 SAVEINT(padix_floor);
1260 padix_floor = padix;
1261 pad_reset_pending = FALSE;
1263 hints &= ~HINT_BLOCK_SCOPE;
1268 block_end(line, floor, seq)
1273 int needblockscope = hints & HINT_BLOCK_SCOPE;
1274 OP* retval = scalarseq(seq);
1275 if (copline > (line_t)line)
1278 pad_reset_pending = FALSE;
1280 hints |= HINT_BLOCK_SCOPE; /* propagate out */
1281 pad_leavemy(comppad_name_fill);
1290 eval_root = newUNOP(OP_LEAVEEVAL, 0, op);
1291 eval_start = linklist(eval_root);
1292 eval_root->op_next = 0;
1300 main_root = scope(sawparens(scalarvoid(op)));
1301 curcop = &compiling;
1302 main_start = LINKLIST(main_root);
1303 main_root->op_next = 0;
1315 if (o->op_flags & OPf_PARENS)
1319 if (dowarn && bufptr > oldbufptr && bufptr[-1] == ',') {
1321 for (s = bufptr; *s && (isALNUM(*s) || strchr("@$%, ",*s)); s++) ;
1322 if (*s == ';' || *s == '=')
1323 warn("Parens missing around \"%s\" list", lex ? "my" : "local");
1330 return mod(o, OP_NULL); /* a bit kludgey */
1337 if (o->op_type == OP_LIST) {
1338 o = convert(OP_JOIN, 0,
1339 prepend_elem(OP_LIST,
1340 newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
1351 I32 type = o->op_type;
1354 if (opargs[type] & OA_RETSCALAR)
1356 if (opargs[type] & OA_TARGET)
1357 o->op_targ = pad_alloc(type, SVs_PADTMP);
1359 if ((opargs[type] & OA_OTHERINT) && (hints & HINT_INTEGER))
1360 o->op_ppaddr = ppaddr[type = ++(o->op_type)];
1362 if (!(opargs[type] & OA_FOLDCONST))
1366 goto nope; /* Don't try to run w/ errors */
1368 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
1369 if (curop->op_type != OP_CONST &&
1370 curop->op_type != OP_LIST &&
1371 curop->op_type != OP_SCALAR &&
1372 curop->op_type != OP_NULL &&
1373 curop->op_type != OP_PUSHMARK) {
1378 curop = LINKLIST(o);
1383 if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
1384 pad_swipe(o->op_targ);
1385 else if (SvTEMP(sv)) { /* grab mortal temp? */
1386 (void)SvREFCNT_inc(sv);
1390 if (type == OP_RV2GV)
1391 return newGVOP(OP_GV, 0, sv);
1393 if ((SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK)) == SVf_NOK) {
1395 if ((double)iv == SvNV(sv)) { /* can we smush double to int */
1400 return newSVOP(OP_CONST, 0, sv);
1404 if (!(opargs[type] & OA_OTHERINT))
1407 if (!(hints & HINT_INTEGER)) {
1410 if (type == OP_DIVIDE || !(o->op_flags & OPf_KIDS))
1413 for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
1414 if (curop->op_type == OP_CONST) {
1415 if (SvIOK(((SVOP*)curop)->op_sv)) {
1416 if (SvIVX(((SVOP*)curop)->op_sv) < 0 && vars++)
1417 return o; /* negatives truncate wrong way, alas */
1422 if (opargs[curop->op_type] & OA_RETINTEGER)
1424 if (curop->op_type == OP_PADSV || curop->op_type == OP_RV2SV) {
1427 if ((o->op_type == OP_LT && curop == ((BINOP*)o)->op_first) ||
1428 (o->op_type == OP_GT && curop == ((BINOP*)o)->op_last))
1430 /* Allow "$i < 100" and "100 > $i" to integerize */
1436 o->op_ppaddr = ppaddr[++(o->op_type)];
1443 gen_constant_list(o)
1447 I32 oldtmps_floor = tmps_floor;
1451 return o; /* Don't attempt to run with errors */
1453 op = curop = LINKLIST(o);
1459 tmps_floor = oldtmps_floor;
1461 o->op_type = OP_RV2AV;
1462 o->op_ppaddr = ppaddr[OP_RV2AV];
1463 curop = ((UNOP*)o)->op_first;
1464 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*stack_sp--));
1471 convert(type, flags, op)
1479 if (!op || op->op_type != OP_LIST)
1480 op = newLISTOP(OP_LIST, 0, op, Nullop);
1482 op->op_flags &= ~(OPf_KNOW|OPf_LIST);
1484 if (!(opargs[type] & OA_MARK))
1485 null(cLISTOP->op_first);
1488 op->op_ppaddr = ppaddr[type];
1489 op->op_flags |= flags;
1491 op = CHECKOP(type, op);
1492 if (op->op_type != type)
1495 if (cLISTOP->op_children < 7) {
1496 /* XXX do we really need to do this if we're done appending?? */
1497 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1499 cLISTOP->op_last = last; /* in case check substituted last arg */
1502 return fold_constants(op);
1505 /* List constructors */
1508 append_elem(type, first, last)
1519 if (first->op_type != type || type==OP_LIST && first->op_flags & OPf_PARENS)
1520 return newLISTOP(type, 0, first, last);
1522 if (first->op_flags & OPf_KIDS)
1523 ((LISTOP*)first)->op_last->op_sibling = last;
1525 first->op_flags |= OPf_KIDS;
1526 ((LISTOP*)first)->op_first = last;
1528 ((LISTOP*)first)->op_last = last;
1529 ((LISTOP*)first)->op_children++;
1534 append_list(type, first, last)
1545 if (first->op_type != type)
1546 return prepend_elem(type, (OP*)first, (OP*)last);
1548 if (last->op_type != type)
1549 return append_elem(type, (OP*)first, (OP*)last);
1551 first->op_last->op_sibling = last->op_first;
1552 first->op_last = last->op_last;
1553 first->op_children += last->op_children;
1554 if (first->op_children)
1555 last->op_flags |= OPf_KIDS;
1562 prepend_elem(type, first, last)
1573 if (last->op_type == type) {
1574 if (type == OP_LIST) { /* already a PUSHMARK there */
1575 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
1576 ((LISTOP*)last)->op_first->op_sibling = first;
1579 if (!(last->op_flags & OPf_KIDS)) {
1580 ((LISTOP*)last)->op_last = first;
1581 last->op_flags |= OPf_KIDS;
1583 first->op_sibling = ((LISTOP*)last)->op_first;
1584 ((LISTOP*)last)->op_first = first;
1586 ((LISTOP*)last)->op_children++;
1590 return newLISTOP(type, 0, first, last);
1598 return newOP(OP_STUB, 0);
1605 if (!op || op->op_type != OP_LIST)
1606 op = newLISTOP(OP_LIST, 0, op, Nullop);
1612 newLISTOP(type, flags, first, last)
1620 Newz(1101, listop, 1, LISTOP);
1622 listop->op_type = type;
1623 listop->op_ppaddr = ppaddr[type];
1624 listop->op_children = (first != 0) + (last != 0);
1625 listop->op_flags = flags;
1629 else if (!first && last)
1632 first->op_sibling = last;
1633 listop->op_first = first;
1634 listop->op_last = last;
1635 if (type == OP_LIST) {
1637 pushop = newOP(OP_PUSHMARK, 0);
1638 pushop->op_sibling = first;
1639 listop->op_first = pushop;
1640 listop->op_flags |= OPf_KIDS;
1642 listop->op_last = pushop;
1644 else if (listop->op_children)
1645 listop->op_flags |= OPf_KIDS;
1656 Newz(1101, op, 1, OP);
1658 op->op_ppaddr = ppaddr[type];
1659 op->op_flags = flags;
1662 op->op_private = 0 + (flags >> 8);
1663 if (opargs[type] & OA_RETSCALAR)
1665 if (opargs[type] & OA_TARGET)
1666 op->op_targ = pad_alloc(type, SVs_PADTMP);
1667 return CHECKOP(type, op);
1671 newUNOP(type, flags, first)
1679 first = newOP(OP_STUB, 0);
1680 if (opargs[type] & OA_MARK)
1681 first = force_list(first);
1683 Newz(1101, unop, 1, UNOP);
1684 unop->op_type = type;
1685 unop->op_ppaddr = ppaddr[type];
1686 unop->op_first = first;
1687 unop->op_flags = flags | OPf_KIDS;
1688 unop->op_private = 1 | (flags >> 8);
1690 unop = (UNOP*) CHECKOP(type, unop);
1694 return fold_constants((OP *) unop);
1698 newBINOP(type, flags, first, last)
1705 Newz(1101, binop, 1, BINOP);
1708 first = newOP(OP_NULL, 0);
1710 binop->op_type = type;
1711 binop->op_ppaddr = ppaddr[type];
1712 binop->op_first = first;
1713 binop->op_flags = flags | OPf_KIDS;
1716 binop->op_private = 1 | (flags >> 8);
1719 binop->op_private = 2 | (flags >> 8);
1720 first->op_sibling = last;
1723 binop = (BINOP*)CHECKOP(type, binop);
1727 binop->op_last = last = binop->op_first->op_sibling;
1729 return fold_constants((OP *)binop);
1733 pmtrans(op, expr, repl)
1738 SV *tstr = ((SVOP*)expr)->op_sv;
1739 SV *rstr = ((SVOP*)repl)->op_sv;
1742 register U8 *t = (U8*)SvPV(tstr, tlen);
1743 register U8 *r = (U8*)SvPV(rstr, rlen);
1748 register short *tbl;
1750 tbl = (short*)cPVOP->op_pv;
1751 complement = op->op_private & OPpTRANS_COMPLEMENT;
1752 delete = op->op_private & OPpTRANS_DELETE;
1753 /* squash = op->op_private & OPpTRANS_SQUASH; */
1756 Zero(tbl, 256, short);
1757 for (i = 0; i < tlen; i++)
1759 for (i = 0, j = 0; i < 256; i++) {
1775 if (!rlen && !delete) {
1778 for (i = 0; i < 256; i++)
1780 for (i = 0, j = 0; i < tlen; i++,j++) {
1783 if (tbl[t[i]] == -1)
1789 if (tbl[t[i]] == -1)
1800 newPMOP(type, flags)
1806 Newz(1101, pmop, 1, PMOP);
1807 pmop->op_type = type;
1808 pmop->op_ppaddr = ppaddr[type];
1809 pmop->op_flags = flags;
1810 pmop->op_private = 0 | (flags >> 8);
1812 /* link into pm list */
1813 if (type != OP_TRANS && curstash) {
1814 pmop->op_pmnext = HvPMROOT(curstash);
1815 HvPMROOT(curstash) = pmop;
1822 pmruntime(op, expr, repl)
1830 if (op->op_type == OP_TRANS)
1831 return pmtrans(op, expr, repl);
1835 if (expr->op_type == OP_CONST) {
1837 SV *pat = ((SVOP*)expr)->op_sv;
1838 char *p = SvPV(pat, plen);
1839 if ((op->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
1840 sv_setpvn(pat, "\\s+", 3);
1841 p = SvPV(pat, plen);
1842 pm->op_pmflags |= PMf_SKIPWHITE;
1844 pm->op_pmregexp = pregcomp(p, p + plen, pm);
1845 if (strEQ("\\s+", pm->op_pmregexp->precomp))
1846 pm->op_pmflags |= PMf_WHITE;
1851 if (pm->op_pmflags & PMf_KEEP)
1852 expr = newUNOP(OP_REGCMAYBE,0,expr);
1854 Newz(1101, rcop, 1, LOGOP);
1855 rcop->op_type = OP_REGCOMP;
1856 rcop->op_ppaddr = ppaddr[OP_REGCOMP];
1857 rcop->op_first = scalar(expr);
1858 rcop->op_flags |= OPf_KIDS;
1859 rcop->op_private = 1;
1860 rcop->op_other = op;
1862 /* establish postfix order */
1863 if (pm->op_pmflags & PMf_KEEP) {
1865 rcop->op_next = expr;
1866 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
1869 rcop->op_next = LINKLIST(expr);
1870 expr->op_next = (OP*)rcop;
1873 prepend_elem(op->op_type, scalar((OP*)rcop), op);
1878 if (pm->op_pmflags & PMf_EVAL)
1880 else if (repl->op_type == OP_CONST)
1884 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
1885 if (opargs[curop->op_type] & OA_DANGEROUS) {
1886 if (curop->op_type == OP_GV) {
1887 GV *gv = ((GVOP*)curop)->op_gv;
1888 if (strchr("&`'123456789+", *GvENAME(gv)))
1891 else if (curop->op_type == OP_RV2CV)
1893 else if (curop->op_type == OP_RV2SV ||
1894 curop->op_type == OP_RV2AV ||
1895 curop->op_type == OP_RV2HV ||
1896 curop->op_type == OP_RV2GV) {
1897 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
1900 else if (curop->op_type == OP_PADSV ||
1901 curop->op_type == OP_PADAV ||
1902 curop->op_type == OP_PADHV ||
1903 curop->op_type == OP_PADANY) {
1912 if (curop == repl) {
1913 pm->op_pmflags |= PMf_CONST; /* const for long enough */
1914 pm->op_pmpermflags |= PMf_CONST; /* const for long enough */
1915 prepend_elem(op->op_type, scalar(repl), op);
1918 Newz(1101, rcop, 1, LOGOP);
1919 rcop->op_type = OP_SUBSTCONT;
1920 rcop->op_ppaddr = ppaddr[OP_SUBSTCONT];
1921 rcop->op_first = scalar(repl);
1922 rcop->op_flags |= OPf_KIDS;
1923 rcop->op_private = 1;
1924 rcop->op_other = op;
1926 /* establish postfix order */
1927 rcop->op_next = LINKLIST(repl);
1928 repl->op_next = (OP*)rcop;
1930 pm->op_pmreplroot = scalar((OP*)rcop);
1931 pm->op_pmreplstart = LINKLIST(rcop);
1940 newSVOP(type, flags, sv)
1946 Newz(1101, svop, 1, SVOP);
1947 svop->op_type = type;
1948 svop->op_ppaddr = ppaddr[type];
1950 svop->op_next = (OP*)svop;
1951 svop->op_flags = flags;
1952 if (opargs[type] & OA_RETSCALAR)
1954 if (opargs[type] & OA_TARGET)
1955 svop->op_targ = pad_alloc(type, SVs_PADTMP);
1956 return CHECKOP(type, svop);
1960 newGVOP(type, flags, gv)
1966 Newz(1101, gvop, 1, GVOP);
1967 gvop->op_type = type;
1968 gvop->op_ppaddr = ppaddr[type];
1969 gvop->op_gv = (GV*)SvREFCNT_inc(gv);
1970 gvop->op_next = (OP*)gvop;
1971 gvop->op_flags = flags;
1972 if (opargs[type] & OA_RETSCALAR)
1974 if (opargs[type] & OA_TARGET)
1975 gvop->op_targ = pad_alloc(type, SVs_PADTMP);
1976 return CHECKOP(type, gvop);
1980 newPVOP(type, flags, pv)
1986 Newz(1101, pvop, 1, PVOP);
1987 pvop->op_type = type;
1988 pvop->op_ppaddr = ppaddr[type];
1990 pvop->op_next = (OP*)pvop;
1991 pvop->op_flags = flags;
1992 if (opargs[type] & OA_RETSCALAR)
1994 if (opargs[type] & OA_TARGET)
1995 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
1996 return CHECKOP(type, pvop);
2005 save_hptr(&curstash);
2006 save_item(curstname);
2011 name = SvPV(sv, len);
2012 curstash = gv_stashpv(name,TRUE);
2013 sv_setpvn(curstname, name, len);
2017 sv_setpv(curstname,"<none>");
2025 utilize(aver, floor, id, arg)
2036 if (id->op_type != OP_CONST)
2037 croak("Module name must be constant");
2039 /* Fake up an import/unimport */
2040 if (arg && arg->op_type == OP_STUB)
2041 imop = arg; /* no import on explicit () */
2043 /* Make copy of id so we don't free it twice */
2044 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2046 meth = newSVOP(OP_CONST, 0,
2048 ? newSVpv("import", 6)
2049 : newSVpv("unimport", 8)
2051 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2052 append_elem(OP_LIST,
2053 prepend_elem(OP_LIST, pack, list(arg)),
2054 newUNOP(OP_METHOD, 0, meth)));
2057 /* Fake up a require */
2058 rqop = newUNOP(OP_REQUIRE, 0, id);
2060 /* Fake up the BEGIN {}, which does its thing immediately. */
2062 newSVOP(OP_CONST, 0, newSVpv("BEGIN", 5)),
2064 append_elem(OP_LINESEQ,
2065 newSTATEOP(0, Nullch, rqop),
2066 newSTATEOP(0, Nullch, imop) ));
2073 newSLICEOP(flags, subscript, listval)
2078 return newBINOP(OP_LSLICE, flags,
2079 list(force_list(subscript)),
2080 list(force_list(listval)) );
2090 if (op->op_type == OP_NULL && op->op_flags & OPf_KIDS)
2091 op = cUNOP->op_first;
2093 if (op->op_type == OP_COND_EXPR) {
2094 I32 t = list_assignment(cCONDOP->op_first->op_sibling);
2095 I32 f = list_assignment(cCONDOP->op_first->op_sibling->op_sibling);
2100 yyerror("Assignment to both a list and a scalar");
2104 if (op->op_type == OP_LIST || op->op_flags & OPf_PARENS ||
2105 op->op_type == OP_RV2AV || op->op_type == OP_RV2HV ||
2106 op->op_type == OP_ASLICE || op->op_type == OP_HSLICE)
2109 if (op->op_type == OP_PADAV || op->op_type == OP_PADHV)
2112 if (op->op_type == OP_RV2SV)
2119 newASSIGNOP(flags, left, optype, right)
2128 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN) {
2129 return newLOGOP(optype, 0,
2130 mod(scalar(left), optype),
2131 newUNOP(OP_SASSIGN, 0, scalar(right)));
2134 return newBINOP(optype, OPf_STACKED,
2135 mod(scalar(left), optype), scalar(right));
2139 if (list_assignment(left)) {
2141 eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2142 left = mod(left, OP_AASSIGN);
2150 op = newBINOP(OP_AASSIGN, flags,
2151 list(force_list(right)),
2152 list(force_list(left)) );
2153 op->op_private = 0 | (flags >> 8);
2154 if (!(left->op_private & OPpLVAL_INTRO)) {
2155 static int generation = 100;
2159 for (curop = LINKLIST(op); curop != op; curop = LINKLIST(curop)) {
2160 if (opargs[curop->op_type] & OA_DANGEROUS) {
2161 if (curop->op_type == OP_GV) {
2162 GV *gv = ((GVOP*)curop)->op_gv;
2163 if (gv == defgv || SvCUR(gv) == generation)
2165 SvCUR(gv) = generation;
2167 else if (curop->op_type == OP_PADSV ||
2168 curop->op_type == OP_PADAV ||
2169 curop->op_type == OP_PADHV ||
2170 curop->op_type == OP_PADANY) {
2171 SV **svp = AvARRAY(comppad_name);
2172 SV *sv = svp[curop->op_targ];
2173 if (SvCUR(sv) == generation)
2175 SvCUR(sv) = generation; /* (SvCUR not used any more) */
2177 else if (curop->op_type == OP_RV2CV)
2179 else if (curop->op_type == OP_RV2SV ||
2180 curop->op_type == OP_RV2AV ||
2181 curop->op_type == OP_RV2HV ||
2182 curop->op_type == OP_RV2GV) {
2183 if (lastop->op_type != OP_GV) /* funny deref? */
2192 op->op_private = OPpASSIGN_COMMON;
2194 if (right && right->op_type == OP_SPLIT) {
2196 if ((tmpop = ((LISTOP*)right)->op_first) &&
2197 tmpop->op_type == OP_PUSHRE)
2199 PMOP *pm = (PMOP*)tmpop;
2200 if (left->op_type == OP_RV2AV &&
2201 !(left->op_private & OPpLVAL_INTRO) &&
2202 !(op->op_private & OPpASSIGN_COMMON) )
2204 tmpop = ((UNOP*)left)->op_first;
2205 if (tmpop->op_type == OP_GV && !pm->op_pmreplroot) {
2206 pm->op_pmreplroot = (OP*)((GVOP*)tmpop)->op_gv;
2207 pm->op_pmflags |= PMf_ONCE;
2208 tmpop = ((UNOP*)op)->op_first; /* to list (nulled) */
2209 tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */
2210 tmpop->op_sibling = Nullop; /* don't free split */
2211 right->op_next = tmpop->op_next; /* fix starting loc */
2212 op_free(op); /* blow off assign */
2217 if (modcount < 10000 &&
2218 ((LISTOP*)right)->op_last->op_type == OP_CONST)
2220 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
2222 sv_setiv(sv, modcount+1);
2230 right = newOP(OP_UNDEF, 0);
2231 if (right->op_type == OP_READLINE) {
2232 right->op_flags |= OPf_STACKED;
2233 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
2236 eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2237 op = newBINOP(OP_SASSIGN, flags,
2238 scalar(right), mod(scalar(left), OP_SASSIGN) );
2250 newSTATEOP(flags, label, op)
2257 /* Introduce my variables. */
2258 if (min_intro_pending) {
2259 SV **svp = AvARRAY(comppad_name);
2262 for (i = min_intro_pending; i <= max_intro_pending; i++) {
2263 if ((sv = svp[i]) && sv != &sv_undef && !SvIVX(sv)) {
2264 SvIVX(sv) = 999999999; /* Don't know scope end yet. */
2265 SvNVX(sv) = (double)cop_seqmax;
2268 min_intro_pending = 0;
2269 comppad_name_fill = max_intro_pending; /* Needn't search higher */
2272 Newz(1101, cop, 1, COP);
2273 if (perldb && curcop->cop_line && curstash != debstash) {
2274 cop->op_type = OP_DBSTATE;
2275 cop->op_ppaddr = ppaddr[ OP_DBSTATE ];
2278 cop->op_type = OP_NEXTSTATE;
2279 cop->op_ppaddr = ppaddr[ OP_NEXTSTATE ];
2281 cop->op_flags = flags;
2282 cop->op_private = 0 | (flags >> 8);
2283 cop->op_next = (OP*)cop;
2286 cop->cop_label = label;
2287 hints |= HINT_BLOCK_SCOPE;
2289 cop->cop_seq = cop_seqmax++;
2290 cop->cop_arybase = curcop->cop_arybase;
2292 if (copline == NOLINE)
2293 cop->cop_line = curcop->cop_line;
2295 cop->cop_line = copline;
2298 cop->cop_filegv = SvREFCNT_inc(curcop->cop_filegv);
2299 cop->cop_stash = curstash;
2301 if (perldb && curstash != debstash) {
2302 SV **svp = av_fetch(GvAV(curcop->cop_filegv),(I32)cop->cop_line, FALSE);
2303 if (svp && *svp != &sv_undef && !SvIOK(*svp)) {
2305 (void)SvIOK_on(*svp);
2306 SvSTASH(*svp) = (HV*)cop;
2310 return prepend_elem(OP_LINESEQ, (OP*)cop, op);
2314 newLOGOP(type, flags, first, other)
2323 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
2324 return newBINOP(type, flags, scalar(first), scalar(other));
2326 scalarboolean(first);
2327 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
2328 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
2329 if (type == OP_AND || type == OP_OR) {
2335 first = cUNOP->op_first;
2337 first->op_next = op->op_next;
2338 cUNOP->op_first = Nullop;
2342 if (first->op_type == OP_CONST) {
2343 if (dowarn && (first->op_private & OPpCONST_BARE))
2344 warn("Probable precedence problem on %s", op_desc[type]);
2345 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
2354 else if (first->op_type == OP_WANTARRAY) {
2364 if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
2365 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
2367 Newz(1101, logop, 1, LOGOP);
2369 logop->op_type = type;
2370 logop->op_ppaddr = ppaddr[type];
2371 logop->op_first = first;
2372 logop->op_flags = flags | OPf_KIDS;
2373 logop->op_other = LINKLIST(other);
2374 logop->op_private = 1 | (flags >> 8);
2376 /* establish postfix order */
2377 logop->op_next = LINKLIST(first);
2378 first->op_next = (OP*)logop;
2379 first->op_sibling = other;
2381 op = newUNOP(OP_NULL, 0, (OP*)logop);
2382 other->op_next = op;
2388 newCONDOP(flags, first, true, false)
2398 return newLOGOP(OP_AND, 0, first, true);
2400 return newLOGOP(OP_OR, 0, first, false);
2402 scalarboolean(first);
2403 if (first->op_type == OP_CONST) {
2404 if (SvTRUE(((SVOP*)first)->op_sv)) {
2415 else if (first->op_type == OP_WANTARRAY) {
2419 Newz(1101, condop, 1, CONDOP);
2421 condop->op_type = OP_COND_EXPR;
2422 condop->op_ppaddr = ppaddr[OP_COND_EXPR];
2423 condop->op_first = first;
2424 condop->op_flags = flags | OPf_KIDS;
2425 condop->op_true = LINKLIST(true);
2426 condop->op_false = LINKLIST(false);
2427 condop->op_private = 1 | (flags >> 8);
2429 /* establish postfix order */
2430 condop->op_next = LINKLIST(first);
2431 first->op_next = (OP*)condop;
2433 first->op_sibling = true;
2434 true->op_sibling = false;
2435 op = newUNOP(OP_NULL, 0, (OP*)condop);
2438 false->op_next = op;
2444 newRANGE(flags, left, right)
2454 Newz(1101, condop, 1, CONDOP);
2456 condop->op_type = OP_RANGE;
2457 condop->op_ppaddr = ppaddr[OP_RANGE];
2458 condop->op_first = left;
2459 condop->op_flags = OPf_KIDS;
2460 condop->op_true = LINKLIST(left);
2461 condop->op_false = LINKLIST(right);
2462 condop->op_private = 1 | (flags >> 8);
2464 left->op_sibling = right;
2466 condop->op_next = (OP*)condop;
2467 flip = newUNOP(OP_FLIP, flags, (OP*)condop);
2468 flop = newUNOP(OP_FLOP, 0, flip);
2469 op = newUNOP(OP_NULL, 0, flop);
2472 left->op_next = flip;
2473 right->op_next = flop;
2475 condop->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2476 sv_upgrade(PAD_SV(condop->op_targ), SVt_PVNV);
2477 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2478 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
2480 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2481 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2484 if (!flip->op_private || !flop->op_private)
2485 linklist(op); /* blow off optimizer unless constant */
2491 newLOOPOP(flags, debuggable, expr, block)
2499 int once = block && block->op_flags & OPf_SPECIAL &&
2500 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
2503 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
2504 return block; /* do {} while 0 does once */
2505 else if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB)
2506 expr = newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr);
2509 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
2510 op = newLOGOP(OP_AND, 0, expr, listop);
2512 ((LISTOP*)listop)->op_last->op_next = LINKLIST(op);
2514 if (once && op != listop)
2515 op->op_next = ((LOGOP*)cUNOP->op_first)->op_other;
2518 op = newUNOP(OP_NULL, 0, op); /* or do {} while 1 loses outer block */
2520 op->op_flags |= flags;
2522 op->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/
2527 newWHILEOP(flags, debuggable, loop, expr, block, cont)
2541 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB)) {
2542 expr = newUNOP(OP_DEFINED, 0,
2543 newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr) );
2547 block = newOP(OP_NULL, 0);
2550 next = LINKLIST(cont);
2552 cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
2554 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
2555 redo = LINKLIST(listop);
2558 op = newLOGOP(OP_AND, 0, expr, scalar(listop));
2559 if (op == expr && op->op_type == OP_CONST && !SvTRUE(cSVOP->op_sv)) {
2560 op_free(expr); /* oops, it's a while (0) */
2562 return Nullop; /* (listop already freed by newLOGOP) */
2564 ((LISTOP*)listop)->op_last->op_next = condop =
2565 (op == listop ? redo : LINKLIST(op));
2573 Newz(1101,loop,1,LOOP);
2574 loop->op_type = OP_ENTERLOOP;
2575 loop->op_ppaddr = ppaddr[OP_ENTERLOOP];
2576 loop->op_private = 0;
2577 loop->op_next = (OP*)loop;
2580 op = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, op);
2582 loop->op_redoop = redo;
2583 loop->op_lastop = op;
2586 loop->op_nextop = next;
2588 loop->op_nextop = op;
2590 op->op_flags |= flags;
2591 op->op_private |= (flags >> 8);
2596 #ifndef CAN_PROTOTYPE
2597 newFOROP(flags,label,forline,sv,expr,block,cont)
2606 newFOROP(I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
2607 #endif /* CAN_PROTOTYPE */
2615 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
2616 sv->op_type = OP_RV2GV;
2617 sv->op_ppaddr = ppaddr[OP_RV2GV];
2619 else if (sv->op_type == OP_PADSV) { /* private variable */
2620 padoff = sv->op_targ;
2625 croak("Can't use %s for loop variable", op_desc[sv->op_type]);
2628 sv = newGVOP(OP_GV, 0, defgv);
2630 if (expr->op_type == OP_RV2AV) {
2631 expr = scalar(ref(expr, OP_ITER));
2632 iterflags |= OPf_STACKED;
2634 loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
2635 append_elem(OP_LIST, mod(force_list(expr), OP_GREPSTART),
2637 assert(!loop->op_next);
2638 Renew(loop, 1, LOOP);
2639 loop->op_targ = padoff;
2640 return newSTATEOP(0, label, newWHILEOP(flags, 1, loop,
2641 newOP(OP_ITER, 0), block, cont));
2645 newLOOPEX(type, label)
2650 if (type != OP_GOTO || label->op_type == OP_CONST) {
2651 op = newPVOP(type, 0, savepv(
2652 label->op_type == OP_CONST
2653 ? SvPVx(((SVOP*)label)->op_sv, na)
2658 if (label->op_type == OP_ENTERSUB)
2659 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
2660 op = newUNOP(type, OPf_STACKED, label);
2662 hints |= HINT_BLOCK_SCOPE;
2670 if (!CvXSUB(cv) && CvROOT(cv)) {
2672 croak("Can't undef active subroutine");
2678 if (!(SvFLAGS(cv) & SVpcv_CLONED))
2679 op_free(CvROOT(cv));
2680 CvROOT(cv) = Nullop;
2683 SvREFCNT_dec(CvGV(cv));
2685 SvREFCNT_dec(CvOUTSIDE(cv));
2686 CvOUTSIDE(cv) = Nullcv;
2687 if (CvPADLIST(cv)) {
2688 I32 i = AvFILL(CvPADLIST(cv));
2690 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
2694 SvREFCNT_dec((SV*)CvPADLIST(cv));
2695 CvPADLIST(cv) = Nullav;
2705 AV* protopadlist = CvPADLIST(proto);
2706 AV* protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
2707 AV* protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
2708 SV** svp = AvARRAY(protopad);
2717 cv = compcv = (CV*)NEWSV(1104,0);
2718 sv_upgrade((SV *)cv, SVt_PVCV);
2719 SvFLAGS(cv) |= SVpcv_CLONED;
2721 CvFILEGV(cv) = CvFILEGV(proto);
2722 CvGV(cv) = SvREFCNT_inc(CvGV(proto));
2723 CvSTASH(cv) = CvSTASH(proto);
2724 CvROOT(cv) = CvROOT(proto);
2725 CvSTART(cv) = CvSTART(proto);
2726 if (CvOUTSIDE(proto))
2727 CvOUTSIDE(cv) = (CV*)SvREFCNT_inc((SV*)CvOUTSIDE(proto));
2731 comppadlist = newAV();
2732 AvREAL_off(comppadlist);
2733 av_store(comppadlist, 0, SvREFCNT_inc((SV*)protopad_name));
2734 av_store(comppadlist, 1, (SV*)comppad);
2735 CvPADLIST(cv) = comppadlist;
2736 av_extend(comppad, AvFILL(protopad));
2737 curpad = AvARRAY(comppad);
2739 av = newAV(); /* will be @_ */
2741 av_store(comppad, 0, (SV*)av);
2742 AvFLAGS(av) = AVf_REIFY;
2744 svp = AvARRAY(protopad_name);
2745 for ( ix = AvFILL(protopad); ix > 0; ix--) {
2747 if (svp[ix] != &sv_undef) {
2748 char *name = SvPVX(svp[ix]); /* XXX */
2749 if (SvFLAGS(svp[ix]) & SVf_FAKE) { /* lexical from outside? */
2750 I32 off = pad_findlex(name,ix,curcop->cop_seq, CvOUTSIDE(proto),
2753 croak("panic: cv_clone: %s", name);
2755 else { /* our own lexical */
2757 av_store(comppad, ix, sv = (SV*)newAV());
2758 else if (*name == '%')
2759 av_store(comppad, ix, sv = (SV*)newHV());
2761 av_store(comppad, ix, sv = NEWSV(0,0));
2766 av_store(comppad, ix, sv = NEWSV(0,0));
2776 newSUB(floor,op,proto,block)
2783 char *name = op ? SvPVx(cSVOP->op_sv, na) : "__ANON__";
2784 GV* gv = gv_fetchpv(name, GV_ADDMULTI, SVt_PVCV);
2791 if (cv = GvCV(gv)) {
2793 cv = 0; /* just a cached method */
2794 else if (CvROOT(cv) || CvXSUB(cv) || GvFLAGS(gv) & GVf_IMPORTED) {
2795 if (dowarn) { /* already defined (or promised)? */
2796 line_t oldline = curcop->cop_line;
2798 curcop->cop_line = copline;
2799 warn("Subroutine %s redefined",name);
2800 curcop->cop_line = oldline;
2806 if (cv) { /* must reuse cv if autoloaded */
2808 CvOUTSIDE(cv) = CvOUTSIDE(compcv);
2809 CvOUTSIDE(compcv) = 0;
2810 CvPADLIST(cv) = CvPADLIST(compcv);
2811 CvPADLIST(compcv) = 0;
2812 if (SvREFCNT(compcv) > 1) /* XXX Make closures transit through stub. */
2813 CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc((SV*)cv);
2814 SvREFCNT_dec(compcv);
2821 CvFILEGV(cv) = curcop->cop_filegv;
2822 CvGV(cv) = SvREFCNT_inc(gv);
2823 CvSTASH(cv) = curstash;
2826 char *p = SvPVx(((SVOP*)proto)->op_sv, na);
2827 if (SvPOK(cv) && strNE(SvPV((SV*)cv,na), p))
2828 warn("Prototype mismatch: (%s) vs (%s)", SvPV((SV*)cv, na), p);
2829 sv_setpv((SV*)cv, p);
2845 av = newAV(); /* Will be @_ */
2847 av_store(comppad, 0, (SV*)av);
2848 AvFLAGS(av) = AVf_REIFY;
2850 for (ix = AvFILL(comppad); ix > 0; ix--) {
2851 if (!SvPADMY(curpad[ix]))
2852 SvPADTMP_on(curpad[ix]);
2855 if (AvFILL(comppad_name) < AvFILL(comppad))
2856 av_store(comppad_name, AvFILL(comppad), Nullsv);
2858 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
2859 CvSTART(cv) = LINKLIST(CvROOT(cv));
2860 CvROOT(cv)->op_next = 0;
2862 if (s = strrchr(name,':'))
2866 if (strEQ(s, "BEGIN") && !error_count) {
2867 line_t oldline = compiling.cop_line;
2871 SAVESPTR(compiling.cop_filegv);
2875 av_push(beginav, (SV *)cv);
2876 DEBUG_x( dump_sub(gv) );
2877 rs = SvREFCNT_inc(nrs);
2882 curcop = &compiling;
2883 curcop->cop_line = oldline; /* might have recursed to yylex */
2886 else if (strEQ(s, "END") && !error_count) {
2889 av_unshift(endav, 1);
2890 av_store(endav, 0, SvREFCNT_inc(cv));
2892 if (perldb && curstash != debstash) {
2894 SV *tmpstr = sv_newmortal();
2896 sprintf(buf,"%s:%ld",SvPVX(GvSV(curcop->cop_filegv)), (long)subline);
2897 sv = newSVpv(buf,0);
2899 sprintf(buf,"%ld",(long)curcop->cop_line);
2901 gv_efullname(tmpstr,gv);
2902 hv_store(GvHV(DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
2908 GvCV(gv) = 0; /* Will remember in SVOP instead. */
2909 SvFLAGS(cv) |= SVpcv_ANON;
2916 newXSUB(name, ix, subaddr, filename)
2922 CV* cv = newXS(name, (void(*)())subaddr, filename);
2923 CvOLDSTYLE(cv) = TRUE;
2924 CvXSUBANY(cv).any_i32 = ix;
2930 newXS(name, subaddr, filename)
2932 void (*subaddr) _((CV*));
2936 GV *gv = gv_fetchpv((name ? name : "__ANON__"), GV_ADDMULTI, SVt_PVCV);
2941 if (cv = GvCV(gv)) {
2943 cv = 0; /* just a cached method */
2944 else if (CvROOT(cv) || CvXSUB(cv)) { /* already defined? */
2946 line_t oldline = curcop->cop_line;
2948 curcop->cop_line = copline;
2949 warn("Subroutine %s redefined",name);
2950 curcop->cop_line = oldline;
2956 if (cv) { /* must reuse cv if autoloaded */
2957 assert(SvREFCNT(CvGV(cv)) > 1);
2958 SvREFCNT_dec(CvGV(cv));
2961 cv = (CV*)NEWSV(1105,0);
2962 sv_upgrade((SV *)cv, SVt_PVCV);
2965 CvGV(cv) = SvREFCNT_inc(gv);
2967 CvFILEGV(cv) = gv_fetchfile(filename);
2968 CvXSUB(cv) = subaddr;
2971 else if (s = strrchr(name,':'))
2975 if (strEQ(s, "BEGIN")) {
2978 av_push(beginav, SvREFCNT_inc(gv));
2980 else if (strEQ(s, "END")) {
2983 av_unshift(endav, 1);
2984 av_store(endav, 0, SvREFCNT_inc(gv));
2987 GvCV(gv) = 0; /* Will remember elsewhere instead. */
2988 SvFLAGS(cv) |= SVpcv_ANON;
2994 newFORM(floor,op,block)
3005 name = SvPVx(cSVOP->op_sv, na);
3008 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
3010 if (cv = GvFORM(gv)) {
3012 line_t oldline = curcop->cop_line;
3014 curcop->cop_line = copline;
3015 warn("Format %s redefined",name);
3016 curcop->cop_line = oldline;
3022 CvGV(cv) = SvREFCNT_inc(gv);
3023 CvFILEGV(cv) = curcop->cop_filegv;
3025 for (ix = AvFILL(comppad); ix > 0; ix--) {
3026 if (!SvPADMY(curpad[ix]))
3027 SvPADTMP_on(curpad[ix]);
3030 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
3031 CvSTART(cv) = LINKLIST(CvROOT(cv));
3032 CvROOT(cv)->op_next = 0;
3044 return newUNOP(OP_REFGEN, 0,
3045 mod(list(convert(OP_ANONLIST, 0, op)), OP_REFGEN));
3052 return newUNOP(OP_REFGEN, 0,
3053 mod(list(convert(OP_ANONHASH, 0, op)), OP_REFGEN));
3057 newANONSUB(floor, proto, block)
3062 return newUNOP(OP_REFGEN, 0,
3063 newSVOP(OP_ANONCODE, 0, (SV*)newSUB(floor, 0, proto, block)));
3070 switch (o->op_type) {
3072 o->op_type = OP_PADAV;
3073 o->op_ppaddr = ppaddr[OP_PADAV];
3074 return ref(newUNOP(OP_RV2AV, 0, scalar(o)), OP_RV2AV);
3077 o->op_type = OP_RV2AV;
3078 o->op_ppaddr = ppaddr[OP_RV2AV];
3083 warn("oops: oopsAV");
3093 switch (o->op_type) {
3096 o->op_type = OP_PADHV;
3097 o->op_ppaddr = ppaddr[OP_PADHV];
3098 return ref(newUNOP(OP_RV2HV, 0, scalar(o)), OP_RV2HV);
3102 o->op_type = OP_RV2HV;
3103 o->op_ppaddr = ppaddr[OP_RV2HV];
3108 warn("oops: oopsHV");
3118 if (o->op_type == OP_PADANY) {
3119 o->op_type = OP_PADAV;
3120 o->op_ppaddr = ppaddr[OP_PADAV];
3123 return newUNOP(OP_RV2AV, 0, scalar(o));
3131 if (type == OP_MAPSTART)
3132 return newUNOP(OP_NULL, 0, o);
3133 return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
3140 if (o->op_type == OP_PADANY) {
3141 o->op_type = OP_PADHV;
3142 o->op_ppaddr = ppaddr[OP_PADHV];
3145 return newUNOP(OP_RV2HV, 0, scalar(o));
3152 croak("NOT IMPL LINE %d",__LINE__);
3162 return newUNOP(OP_RV2CV, flags, scalar(o));
3169 if (o->op_type == OP_PADANY) {
3170 o->op_type = OP_PADSV;
3171 o->op_ppaddr = ppaddr[OP_PADSV];
3174 return newUNOP(OP_RV2SV, 0, scalar(o));
3177 /* Check routines. */
3183 if (cUNOP->op_first->op_type == OP_CONCAT)
3184 op->op_flags |= OPf_STACKED;
3192 if (op->op_flags & OPf_KIDS) {
3195 op = modkids(ck_fun(op), op->op_type);
3196 kid = cUNOP->op_first;
3197 newop = kUNOP->op_first->op_sibling;
3199 (newop->op_sibling ||
3200 !(opargs[newop->op_type] & OA_RETSCALAR) ||
3201 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
3202 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
3206 op_free(kUNOP->op_first);
3207 kUNOP->op_first = newop;
3209 op->op_ppaddr = ppaddr[++op->op_type];
3218 if (op->op_flags & OPf_KIDS) {
3219 OP *kid = cUNOP->op_first;
3220 if (kid->op_type != OP_HELEM)
3221 croak("%s argument is not a HASH element", op_desc[op->op_type]);
3231 I32 type = op->op_type;
3233 if (op->op_flags & OPf_KIDS) {
3234 if (cLISTOP->op_first->op_type == OP_STUB) {
3236 op = newUNOP(type, OPf_SPECIAL,
3237 newGVOP(OP_GV, 0, gv_fetchpv("main'ARGV", TRUE, SVt_PVAV)));
3248 hints |= HINT_BLOCK_SCOPE;
3249 if (op->op_flags & OPf_KIDS) {
3250 SVOP *kid = (SVOP*)cUNOP->op_first;
3253 op->op_flags &= ~OPf_KIDS;
3256 else if (kid->op_type == OP_LINESEQ) {
3259 kid->op_next = op->op_next;
3260 cUNOP->op_first = 0;
3263 Newz(1101, enter, 1, LOGOP);
3264 enter->op_type = OP_ENTERTRY;
3265 enter->op_ppaddr = ppaddr[OP_ENTERTRY];
3266 enter->op_private = 0;
3268 /* establish postfix order */
3269 enter->op_next = (OP*)enter;
3271 op = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
3272 op->op_type = OP_LEAVETRY;
3273 op->op_ppaddr = ppaddr[OP_LEAVETRY];
3274 enter->op_other = op;
3280 op = newUNOP(OP_ENTEREVAL, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3282 op->op_targ = (PADOFFSET)hints;
3291 if (op->op_flags & OPf_STACKED) {
3293 kid = cUNOP->op_first->op_sibling;
3294 if (kid->op_type == OP_RV2GV)
3306 o = fold_constants(o);
3307 if (o->op_type == OP_CONST)
3316 SVOP *kid = (SVOP*)cUNOP->op_first;
3318 op->op_private |= (hints & HINT_STRICT_REFS);
3319 if (kid->op_type == OP_CONST) {
3320 int iscv = (op->op_type==OP_RV2CV)*2;
3322 kid->op_type = OP_GV;
3323 for (gv = 0; !gv; iscv++) {
3325 * This is a little tricky. We only want to add the symbol if we
3326 * didn't add it in the lexer. Otherwise we get duplicate strict
3327 * warnings. But if we didn't add it in the lexer, we must at
3328 * least pretend like we wanted to add it even if it existed before,
3329 * or we get possible typo warnings. OPpCONST_ENTERED says
3330 * whether the lexer already added THIS instance of this symbol.
3332 gv = gv_fetchpv(SvPVx(kid->op_sv, na),
3333 iscv | !(kid->op_private & OPpCONST_ENTERED),
3336 : op->op_type == OP_RV2SV
3338 : op->op_type == OP_RV2AV
3340 : op->op_type == OP_RV2HV
3344 SvREFCNT_dec(kid->op_sv);
3345 kid->op_sv = SvREFCNT_inc(gv);
3361 I32 type = op->op_type;
3363 if (op->op_flags & OPf_REF)
3366 if (op->op_flags & OPf_KIDS) {
3367 SVOP *kid = (SVOP*)cUNOP->op_first;
3369 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
3370 OP *newop = newGVOP(type, OPf_REF,
3371 gv_fetchpv(SvPVx(kid->op_sv, na), TRUE, SVt_PVIO));
3378 if (type == OP_FTTTY)
3379 return newGVOP(type, OPf_REF, gv_fetchpv("main'STDIN", TRUE,
3382 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3395 int type = op->op_type;
3396 register I32 oa = opargs[type] >> OASHIFT;
3398 if (op->op_flags & OPf_STACKED) {
3399 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
3402 return no_fh_allowed(op);
3405 if (op->op_flags & OPf_KIDS) {
3406 tokid = &cLISTOP->op_first;
3407 kid = cLISTOP->op_first;
3408 if (kid->op_type == OP_PUSHMARK ||
3409 kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK)
3411 tokid = &kid->op_sibling;
3412 kid = kid->op_sibling;
3414 if (!kid && opargs[type] & OA_DEFGV)
3415 *tokid = kid = newSVREF(newGVOP(OP_GV, 0, defgv));
3419 sibl = kid->op_sibling;
3433 if (kid->op_type == OP_CONST &&
3434 (kid->op_private & OPpCONST_BARE)) {
3435 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
3436 OP *newop = newAVREF(newGVOP(OP_GV, 0,
3437 gv_fetchpv(name, TRUE, SVt_PVAV) ));
3439 warn("Array @%s missing the @ in argument %d of %s()",
3440 name, numargs, op_desc[type]);
3443 kid->op_sibling = sibl;
3446 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
3447 bad_type(numargs, "array", op_desc[op->op_type], kid);
3451 if (kid->op_type == OP_CONST &&
3452 (kid->op_private & OPpCONST_BARE)) {
3453 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
3454 OP *newop = newHVREF(newGVOP(OP_GV, 0,
3455 gv_fetchpv(name, TRUE, SVt_PVHV) ));
3457 warn("Hash %%%s missing the %% in argument %d of %s()",
3458 name, numargs, op_desc[type]);
3461 kid->op_sibling = sibl;
3464 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
3465 bad_type(numargs, "hash", op_desc[op->op_type], kid);
3470 OP *newop = newUNOP(OP_NULL, 0, kid);
3471 kid->op_sibling = 0;
3473 newop->op_next = newop;
3475 kid->op_sibling = sibl;
3480 if (kid->op_type != OP_GV) {
3481 if (kid->op_type == OP_CONST &&
3482 (kid->op_private & OPpCONST_BARE)) {
3483 OP *newop = newGVOP(OP_GV, 0,
3484 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, na), TRUE,
3490 kid->op_sibling = 0;
3491 kid = newUNOP(OP_RV2GV, 0, scalar(kid));
3493 kid->op_sibling = sibl;
3499 mod(scalar(kid), type);
3503 tokid = &kid->op_sibling;
3504 kid = kid->op_sibling;
3506 op->op_private |= numargs;
3508 return too_many_arguments(op,op_desc[op->op_type]);
3511 else if (opargs[type] & OA_DEFGV) {
3513 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3517 while (oa & OA_OPTIONAL)
3519 if (oa && oa != OA_LIST)
3520 return too_few_arguments(op,op_desc[op->op_type]);
3529 GV *gv = newGVgen("main");
3531 append_elem(OP_GLOB, op, newGVOP(OP_GV, 0, gv));
3542 OPCODE type = op->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
3544 op->op_ppaddr = ppaddr[OP_GREPSTART];
3545 Newz(1101, gwop, 1, LOGOP);
3547 if (op->op_flags & OPf_STACKED) {
3550 kid = cLISTOP->op_first->op_sibling;
3551 for (k = cLISTOP->op_first->op_sibling->op_next; k; k = k->op_next) {
3554 kid->op_next = (OP*)gwop;
3555 op->op_flags &= ~OPf_STACKED;
3557 kid = cLISTOP->op_first->op_sibling;
3558 if (type == OP_MAPWHILE)
3565 kid = cLISTOP->op_first->op_sibling;
3566 if (kid->op_type != OP_NULL)
3567 croak("panic: ck_grep");
3568 kid = kUNOP->op_first;
3570 gwop->op_type = type;
3571 gwop->op_ppaddr = ppaddr[type];
3572 gwop->op_first = listkids(op);
3573 gwop->op_flags |= OPf_KIDS;
3574 gwop->op_private = 1;
3575 gwop->op_other = LINKLIST(kid);
3576 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
3577 kid->op_next = (OP*)gwop;
3579 kid = cLISTOP->op_first->op_sibling;
3580 if (!kid || !kid->op_sibling)
3581 return too_few_arguments(op,op_desc[op->op_type]);
3582 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
3583 mod(kid, OP_GREPSTART);
3592 if (op->op_flags & OPf_KIDS) {
3593 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3594 if (kid && kid->op_type == OP_CONST)
3595 fbm_compile(((SVOP*)kid)->op_sv, 0);
3604 /* XXX length optimization goes here */
3612 return modkids(ck_fun(op), op->op_type);
3619 return refkids(ck_fun(op), op->op_type);
3628 kid = cLISTOP->op_first;
3630 op = force_list(op);
3631 kid = cLISTOP->op_first;
3633 if (kid->op_type == OP_PUSHMARK)
3634 kid = kid->op_sibling;
3635 if (kid && op->op_flags & OPf_STACKED)
3636 kid = kid->op_sibling;
3637 else if (kid && !kid->op_sibling) { /* print HANDLE; */
3638 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
3639 op->op_flags |= OPf_STACKED; /* make it a filehandle */
3640 kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
3641 cLISTOP->op_first->op_sibling = kid;
3642 cLISTOP->op_last = kid;
3643 kid = kid->op_sibling;
3648 append_elem(op->op_type, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
3650 return listkids(op);
3657 cPMOP->op_pmflags |= PMf_RUNTIME;
3658 cPMOP->op_pmpermflags |= PMf_RUNTIME;
3673 if (cBINOP->op_first->op_flags & OPf_PARENS) {
3674 op->op_private |= OPpREPEAT_DOLIST;
3675 cBINOP->op_first = force_list(cBINOP->op_first);
3686 if (op->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
3687 SVOP *kid = (SVOP*)cUNOP->op_first;
3689 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
3691 for (s = SvPVX(kid->op_sv); *s; s++) {
3692 if (*s == ':' && s[1] == ':') {
3694 Move(s+2, s+1, strlen(s+2)+1, char);
3695 --SvCUR(kid->op_sv);
3698 sv_catpvn(kid->op_sv, ".pm", 3);
3708 croak("NOT IMPL LINE %d",__LINE__);
3718 if (op->op_flags & OPf_KIDS) {
3719 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3720 if (kid && kid->op_sibling) {
3721 op->op_type = OP_SSELECT;
3722 op->op_ppaddr = ppaddr[OP_SSELECT];
3724 return fold_constants(op);
3728 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3729 if (kid && kid->op_type == OP_RV2GV)
3730 kid->op_private &= ~HINT_STRICT_REFS;
3738 I32 type = op->op_type;
3740 if (!(op->op_flags & OPf_KIDS)) {
3742 return newUNOP(type, 0,
3743 scalar(newUNOP(OP_RV2AV, 0,
3744 scalar(newGVOP(OP_GV, 0,
3745 gv_fetchpv((subline ? "_" : "ARGV"), TRUE, SVt_PVAV) )))));
3747 return scalar(modkids(ck_fun(op), type));
3754 if (op->op_flags & OPf_STACKED) {
3755 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3757 kid = kUNOP->op_first; /* get past rv2gv */
3759 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
3761 if (kid->op_type == OP_SCOPE) {
3765 else if (kid->op_type == OP_LEAVE) {
3766 if (op->op_type == OP_SORT) {
3767 null(kid); /* wipe out leave */
3770 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
3771 if (k->op_next == kid)
3776 kid->op_next = 0; /* just disconnect the leave */
3777 k = kLISTOP->op_first;
3781 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3782 null(kid); /* wipe out rv2gv */
3783 if (op->op_type == OP_SORT)
3787 op->op_flags |= OPf_SPECIAL;
3800 if (op->op_flags & OPf_STACKED)
3801 return no_fh_allowed(op);
3803 kid = cLISTOP->op_first;
3804 if (kid->op_type != OP_NULL)
3805 croak("panic: ck_split");
3806 kid = kid->op_sibling;
3807 op_free(cLISTOP->op_first);
3808 cLISTOP->op_first = kid;
3810 cLISTOP->op_first = kid = newSVOP(OP_CONST, 0, newSVpv(" ", 1));
3811 cLISTOP->op_last = kid; /* There was only one element previously */
3814 if (kid->op_type != OP_MATCH) {
3815 OP *sibl = kid->op_sibling;
3816 kid->op_sibling = 0;
3817 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
3818 if (cLISTOP->op_first == cLISTOP->op_last)
3819 cLISTOP->op_last = kid;
3820 cLISTOP->op_first = kid;
3821 kid->op_sibling = sibl;
3824 if (pm->op_pmshort && !(pm->op_pmflags & PMf_ALL)) {
3825 SvREFCNT_dec(pm->op_pmshort); /* can't use substring to optimize */
3829 kid->op_type = OP_PUSHRE;
3830 kid->op_ppaddr = ppaddr[OP_PUSHRE];
3833 if (!kid->op_sibling)
3834 append_elem(OP_SPLIT, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
3836 kid = kid->op_sibling;
3839 if (!kid->op_sibling)
3840 append_elem(OP_SPLIT, op, newSVOP(OP_CONST, 0, newSViv(0)));
3842 kid = kid->op_sibling;
3845 if (kid->op_sibling)
3846 return too_many_arguments(op,op_desc[op->op_type]);
3855 OP *prev = ((cUNOP->op_first->op_sibling)
3856 ? cUNOP : ((UNOP*)cUNOP->op_first))->op_first;
3857 OP *o = prev->op_sibling;
3864 for (cvop = o; cvop->op_sibling; cvop = cvop->op_sibling) ;
3865 if (cvop->op_type == OP_RV2CV) {
3867 op->op_private |= (cvop->op_private & OPpENTERSUB_AMPER);
3868 null(cvop); /* disable rv2cv */
3869 tmpop = (SVOP*)((UNOP*)cvop)->op_first;
3870 if (tmpop->op_type == OP_GV) {
3871 cv = GvCV(tmpop->op_sv);
3872 if (cv && SvPOK(cv) && !(op->op_private & OPpENTERSUB_AMPER))
3873 proto = SvPV((SV*)cv,na);
3876 op->op_private |= (hints & HINT_STRICT_REFS);
3877 if (perldb && curstash != debstash)
3878 op->op_private |= OPpENTERSUB_DB;
3883 return too_many_arguments(op, CvNAME(cv));
3901 if (o->op_type != OP_REFGEN && o->op_type != OP_UNDEF)
3902 bad_type(arg, "block", CvNAME(cv), o);
3907 if (o->op_type == OP_RV2GV)
3911 o = newUNOP(OP_RV2GV, 0, kid);
3912 o->op_sibling = kid->op_sibling;
3913 kid->op_sibling = 0;
3914 prev->op_sibling = o;
3922 if (o->op_type != OP_RV2GV)
3923 bad_type(arg, "symbol", CvNAME(cv), o);
3926 if (o->op_type != OP_RV2CV)
3927 bad_type(arg, "sub", CvNAME(cv), o);
3930 if (o->op_type != OP_RV2SV && o->op_type != OP_PADSV)
3931 bad_type(arg, "scalar", CvNAME(cv), o);
3934 if (o->op_type != OP_RV2AV && o->op_type != OP_PADAV)
3935 bad_type(arg, "array", CvNAME(cv), o);
3938 if (o->op_type != OP_RV2HV && o->op_type != OP_PADHV)
3939 bad_type(arg, "hash", CvNAME(cv), o);
3943 o = newUNOP(OP_REFGEN, 0, kid);
3944 o->op_sibling = kid->op_sibling;
3945 kid->op_sibling = 0;
3946 prev->op_sibling = o;
3954 croak("Malformed prototype for %s: %s",
3955 CvNAME(cv),SvPV((SV*)cv,na));
3960 mod(o, OP_ENTERSUB);
3964 if (proto && !optional && *proto == '$')
3965 return too_few_arguments(op, CvNAME(cv));
3973 SvREADONLY_on(cSVOP->op_sv);
3981 if (op->op_flags & OPf_KIDS) {
3982 SVOP *kid = (SVOP*)cUNOP->op_first;
3984 if (kid->op_type == OP_NULL)
3985 kid = (SVOP*)kid->op_sibling;
3987 kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE))
3988 op->op_flags |= OPf_SPECIAL;
3993 /* A peephole optimizer. We visit the ops in the order they're to execute. */
3999 register OP* oldop = 0;
4000 if (!o || o->op_seq)
4005 for (; o; o = o->op_next) {
4011 switch (o->op_type) {
4014 curcop = ((COP*)o); /* for warnings */
4015 o->op_seq = op_seqmax++;
4026 if (o->op_next->op_type == OP_STRINGIFY)
4028 o->op_seq = op_seqmax++;
4031 if ((o->op_flags & (OPf_KNOW|OPf_LIST)) != (OPf_KNOW|OPf_LIST)) {
4032 o->op_seq = op_seqmax++;
4033 break; /* Scalar stub must produce undef. List stub is noop */
4037 if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE)
4038 curcop = ((COP*)op);
4044 if (oldop && o->op_next) {
4045 oldop->op_next = o->op_next;
4048 o->op_seq = op_seqmax++;
4052 if (o->op_next->op_type == OP_RV2SV) {
4053 if (!(o->op_next->op_private & (OPpDEREF_HV|OPpDEREF_AV))) {
4055 o->op_private |= o->op_next->op_private & OPpLVAL_INTRO;
4056 o->op_next = o->op_next->op_next;
4057 o->op_type = OP_GVSV;
4058 o->op_ppaddr = ppaddr[OP_GVSV];
4061 else if (o->op_next->op_type == OP_RV2AV) {
4062 OP* pop = o->op_next->op_next;
4064 if (pop->op_type == OP_CONST &&
4065 (op = pop->op_next) &&
4066 pop->op_next->op_type == OP_AELEM &&
4067 !(pop->op_next->op_private &
4068 (OPpDEREF_HV|OPpDEREF_AV|OPpLVAL_INTRO)) &&
4069 (i = SvIV(((SVOP*)pop)->op_sv) - compiling.cop_arybase)
4073 SvREFCNT_dec(((SVOP*)pop)->op_sv);
4077 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
4078 o->op_next = pop->op_next->op_next;
4079 o->op_type = OP_AELEMFAST;
4080 o->op_ppaddr = ppaddr[OP_AELEMFAST];
4081 o->op_private = (U8)i;
4082 GvAVn((GV*)(((SVOP*)o)->op_sv));
4085 o->op_seq = op_seqmax++;
4092 o->op_seq = op_seqmax++;
4093 peep(cLOGOP->op_other);
4097 o->op_seq = op_seqmax++;
4098 peep(cCONDOP->op_true);
4099 peep(cCONDOP->op_false);
4103 o->op_seq = op_seqmax++;
4104 peep(cLOOP->op_redoop);
4105 peep(cLOOP->op_nextop);
4106 peep(cLOOP->op_lastop);
4111 o->op_seq = op_seqmax++;
4112 peep(cPMOP->op_pmreplstart);
4116 o->op_seq = op_seqmax++;
4117 if (dowarn && o->op_next && o->op_next->op_type == OP_NEXTSTATE) {
4118 if (o->op_next->op_sibling &&
4119 o->op_next->op_sibling->op_type != OP_DIE) {
4120 line_t oldline = curcop->cop_line;
4122 curcop->cop_line = ((COP*)o->op_next)->cop_line;
4123 warn("Statement unlikely to be reached");
4124 warn("(Maybe you meant system() when you said exec()?)\n");
4125 curcop->cop_line = oldline;
4130 o->op_seq = op_seqmax++;