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 Siglongjmp.
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));
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 || o->op_type == OP_GE) &&
1428 curop == ((BINOP*)o)->op_first ) ||
1429 ((o->op_type == OP_GT || o->op_type == OP_LE) &&
1430 curop == ((BINOP*)o)->op_last ))
1432 /* Allow "$i < 100" and variants to integerize */
1438 o->op_ppaddr = ppaddr[++(o->op_type)];
1445 gen_constant_list(o)
1449 I32 oldtmps_floor = tmps_floor;
1453 return o; /* Don't attempt to run with errors */
1455 op = curop = LINKLIST(o);
1461 tmps_floor = oldtmps_floor;
1463 o->op_type = OP_RV2AV;
1464 o->op_ppaddr = ppaddr[OP_RV2AV];
1465 curop = ((UNOP*)o)->op_first;
1466 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*stack_sp--));
1473 convert(type, flags, op)
1481 if (!op || op->op_type != OP_LIST)
1482 op = newLISTOP(OP_LIST, 0, op, Nullop);
1484 op->op_flags &= ~(OPf_KNOW|OPf_LIST);
1486 if (!(opargs[type] & OA_MARK))
1487 null(cLISTOP->op_first);
1490 op->op_ppaddr = ppaddr[type];
1491 op->op_flags |= flags;
1493 op = CHECKOP(type, op);
1494 if (op->op_type != type)
1497 if (cLISTOP->op_children < 7) {
1498 /* XXX do we really need to do this if we're done appending?? */
1499 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1501 cLISTOP->op_last = last; /* in case check substituted last arg */
1504 return fold_constants(op);
1507 /* List constructors */
1510 append_elem(type, first, last)
1521 if (first->op_type != type || type==OP_LIST && first->op_flags & OPf_PARENS)
1522 return newLISTOP(type, 0, first, last);
1524 if (first->op_flags & OPf_KIDS)
1525 ((LISTOP*)first)->op_last->op_sibling = last;
1527 first->op_flags |= OPf_KIDS;
1528 ((LISTOP*)first)->op_first = last;
1530 ((LISTOP*)first)->op_last = last;
1531 ((LISTOP*)first)->op_children++;
1536 append_list(type, first, last)
1547 if (first->op_type != type)
1548 return prepend_elem(type, (OP*)first, (OP*)last);
1550 if (last->op_type != type)
1551 return append_elem(type, (OP*)first, (OP*)last);
1553 first->op_last->op_sibling = last->op_first;
1554 first->op_last = last->op_last;
1555 first->op_children += last->op_children;
1556 if (first->op_children)
1557 last->op_flags |= OPf_KIDS;
1564 prepend_elem(type, first, last)
1575 if (last->op_type == type) {
1576 if (type == OP_LIST) { /* already a PUSHMARK there */
1577 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
1578 ((LISTOP*)last)->op_first->op_sibling = first;
1581 if (!(last->op_flags & OPf_KIDS)) {
1582 ((LISTOP*)last)->op_last = first;
1583 last->op_flags |= OPf_KIDS;
1585 first->op_sibling = ((LISTOP*)last)->op_first;
1586 ((LISTOP*)last)->op_first = first;
1588 ((LISTOP*)last)->op_children++;
1592 return newLISTOP(type, 0, first, last);
1600 return newOP(OP_STUB, 0);
1607 if (!op || op->op_type != OP_LIST)
1608 op = newLISTOP(OP_LIST, 0, op, Nullop);
1614 newLISTOP(type, flags, first, last)
1622 Newz(1101, listop, 1, LISTOP);
1624 listop->op_type = type;
1625 listop->op_ppaddr = ppaddr[type];
1626 listop->op_children = (first != 0) + (last != 0);
1627 listop->op_flags = flags;
1631 else if (!first && last)
1634 first->op_sibling = last;
1635 listop->op_first = first;
1636 listop->op_last = last;
1637 if (type == OP_LIST) {
1639 pushop = newOP(OP_PUSHMARK, 0);
1640 pushop->op_sibling = first;
1641 listop->op_first = pushop;
1642 listop->op_flags |= OPf_KIDS;
1644 listop->op_last = pushop;
1646 else if (listop->op_children)
1647 listop->op_flags |= OPf_KIDS;
1658 Newz(1101, op, 1, OP);
1660 op->op_ppaddr = ppaddr[type];
1661 op->op_flags = flags;
1664 op->op_private = 0 + (flags >> 8);
1665 if (opargs[type] & OA_RETSCALAR)
1667 if (opargs[type] & OA_TARGET)
1668 op->op_targ = pad_alloc(type, SVs_PADTMP);
1669 return CHECKOP(type, op);
1673 newUNOP(type, flags, first)
1681 first = newOP(OP_STUB, 0);
1682 if (opargs[type] & OA_MARK)
1683 first = force_list(first);
1685 Newz(1101, unop, 1, UNOP);
1686 unop->op_type = type;
1687 unop->op_ppaddr = ppaddr[type];
1688 unop->op_first = first;
1689 unop->op_flags = flags | OPf_KIDS;
1690 unop->op_private = 1 | (flags >> 8);
1692 unop = (UNOP*) CHECKOP(type, unop);
1696 return fold_constants((OP *) unop);
1700 newBINOP(type, flags, first, last)
1707 Newz(1101, binop, 1, BINOP);
1710 first = newOP(OP_NULL, 0);
1712 binop->op_type = type;
1713 binop->op_ppaddr = ppaddr[type];
1714 binop->op_first = first;
1715 binop->op_flags = flags | OPf_KIDS;
1718 binop->op_private = 1 | (flags >> 8);
1721 binop->op_private = 2 | (flags >> 8);
1722 first->op_sibling = last;
1725 binop = (BINOP*)CHECKOP(type, binop);
1729 binop->op_last = last = binop->op_first->op_sibling;
1731 return fold_constants((OP *)binop);
1735 pmtrans(op, expr, repl)
1740 SV *tstr = ((SVOP*)expr)->op_sv;
1741 SV *rstr = ((SVOP*)repl)->op_sv;
1744 register U8 *t = (U8*)SvPV(tstr, tlen);
1745 register U8 *r = (U8*)SvPV(rstr, rlen);
1750 register short *tbl;
1752 tbl = (short*)cPVOP->op_pv;
1753 complement = op->op_private & OPpTRANS_COMPLEMENT;
1754 delete = op->op_private & OPpTRANS_DELETE;
1755 /* squash = op->op_private & OPpTRANS_SQUASH; */
1758 Zero(tbl, 256, short);
1759 for (i = 0; i < tlen; i++)
1761 for (i = 0, j = 0; i < 256; i++) {
1777 if (!rlen && !delete) {
1780 for (i = 0; i < 256; i++)
1782 for (i = 0, j = 0; i < tlen; i++,j++) {
1785 if (tbl[t[i]] == -1)
1791 if (tbl[t[i]] == -1)
1802 newPMOP(type, flags)
1808 Newz(1101, pmop, 1, PMOP);
1809 pmop->op_type = type;
1810 pmop->op_ppaddr = ppaddr[type];
1811 pmop->op_flags = flags;
1812 pmop->op_private = 0 | (flags >> 8);
1814 /* link into pm list */
1815 if (type != OP_TRANS && curstash) {
1816 pmop->op_pmnext = HvPMROOT(curstash);
1817 HvPMROOT(curstash) = pmop;
1824 pmruntime(op, expr, repl)
1832 if (op->op_type == OP_TRANS)
1833 return pmtrans(op, expr, repl);
1837 if (expr->op_type == OP_CONST) {
1839 SV *pat = ((SVOP*)expr)->op_sv;
1840 char *p = SvPV(pat, plen);
1841 if ((op->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
1842 sv_setpvn(pat, "\\s+", 3);
1843 p = SvPV(pat, plen);
1844 pm->op_pmflags |= PMf_SKIPWHITE;
1846 pm->op_pmregexp = pregcomp(p, p + plen, pm);
1847 if (strEQ("\\s+", pm->op_pmregexp->precomp))
1848 pm->op_pmflags |= PMf_WHITE;
1853 if (pm->op_pmflags & PMf_KEEP)
1854 expr = newUNOP(OP_REGCMAYBE,0,expr);
1856 Newz(1101, rcop, 1, LOGOP);
1857 rcop->op_type = OP_REGCOMP;
1858 rcop->op_ppaddr = ppaddr[OP_REGCOMP];
1859 rcop->op_first = scalar(expr);
1860 rcop->op_flags |= OPf_KIDS;
1861 rcop->op_private = 1;
1862 rcop->op_other = op;
1864 /* establish postfix order */
1865 if (pm->op_pmflags & PMf_KEEP) {
1867 rcop->op_next = expr;
1868 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
1871 rcop->op_next = LINKLIST(expr);
1872 expr->op_next = (OP*)rcop;
1875 prepend_elem(op->op_type, scalar((OP*)rcop), op);
1880 if (pm->op_pmflags & PMf_EVAL)
1882 else if (repl->op_type == OP_CONST)
1886 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
1887 if (opargs[curop->op_type] & OA_DANGEROUS) {
1888 if (curop->op_type == OP_GV) {
1889 GV *gv = ((GVOP*)curop)->op_gv;
1890 if (strchr("&`'123456789+", *GvENAME(gv)))
1893 else if (curop->op_type == OP_RV2CV)
1895 else if (curop->op_type == OP_RV2SV ||
1896 curop->op_type == OP_RV2AV ||
1897 curop->op_type == OP_RV2HV ||
1898 curop->op_type == OP_RV2GV) {
1899 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
1902 else if (curop->op_type == OP_PADSV ||
1903 curop->op_type == OP_PADAV ||
1904 curop->op_type == OP_PADHV ||
1905 curop->op_type == OP_PADANY) {
1914 if (curop == repl) {
1915 pm->op_pmflags |= PMf_CONST; /* const for long enough */
1916 pm->op_pmpermflags |= PMf_CONST; /* const for long enough */
1917 prepend_elem(op->op_type, scalar(repl), op);
1920 Newz(1101, rcop, 1, LOGOP);
1921 rcop->op_type = OP_SUBSTCONT;
1922 rcop->op_ppaddr = ppaddr[OP_SUBSTCONT];
1923 rcop->op_first = scalar(repl);
1924 rcop->op_flags |= OPf_KIDS;
1925 rcop->op_private = 1;
1926 rcop->op_other = op;
1928 /* establish postfix order */
1929 rcop->op_next = LINKLIST(repl);
1930 repl->op_next = (OP*)rcop;
1932 pm->op_pmreplroot = scalar((OP*)rcop);
1933 pm->op_pmreplstart = LINKLIST(rcop);
1942 newSVOP(type, flags, sv)
1948 Newz(1101, svop, 1, SVOP);
1949 svop->op_type = type;
1950 svop->op_ppaddr = ppaddr[type];
1952 svop->op_next = (OP*)svop;
1953 svop->op_flags = flags;
1954 if (opargs[type] & OA_RETSCALAR)
1956 if (opargs[type] & OA_TARGET)
1957 svop->op_targ = pad_alloc(type, SVs_PADTMP);
1958 return CHECKOP(type, svop);
1962 newGVOP(type, flags, gv)
1968 Newz(1101, gvop, 1, GVOP);
1969 gvop->op_type = type;
1970 gvop->op_ppaddr = ppaddr[type];
1971 gvop->op_gv = (GV*)SvREFCNT_inc(gv);
1972 gvop->op_next = (OP*)gvop;
1973 gvop->op_flags = flags;
1974 if (opargs[type] & OA_RETSCALAR)
1976 if (opargs[type] & OA_TARGET)
1977 gvop->op_targ = pad_alloc(type, SVs_PADTMP);
1978 return CHECKOP(type, gvop);
1982 newPVOP(type, flags, pv)
1988 Newz(1101, pvop, 1, PVOP);
1989 pvop->op_type = type;
1990 pvop->op_ppaddr = ppaddr[type];
1992 pvop->op_next = (OP*)pvop;
1993 pvop->op_flags = flags;
1994 if (opargs[type] & OA_RETSCALAR)
1996 if (opargs[type] & OA_TARGET)
1997 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
1998 return CHECKOP(type, pvop);
2007 save_hptr(&curstash);
2008 save_item(curstname);
2013 name = SvPV(sv, len);
2014 curstash = gv_stashpv(name,TRUE);
2015 sv_setpvn(curstname, name, len);
2019 sv_setpv(curstname,"<none>");
2027 utilize(aver, floor, id, arg)
2038 if (id->op_type != OP_CONST)
2039 croak("Module name must be constant");
2041 /* Fake up an import/unimport */
2042 if (arg && arg->op_type == OP_STUB)
2043 imop = arg; /* no import on explicit () */
2045 /* Make copy of id so we don't free it twice */
2046 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2048 meth = newSVOP(OP_CONST, 0,
2050 ? newSVpv("import", 6)
2051 : newSVpv("unimport", 8)
2053 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2054 append_elem(OP_LIST,
2055 prepend_elem(OP_LIST, pack, list(arg)),
2056 newUNOP(OP_METHOD, 0, meth)));
2059 /* Fake up a require */
2060 rqop = newUNOP(OP_REQUIRE, 0, id);
2062 /* Fake up the BEGIN {}, which does its thing immediately. */
2064 newSVOP(OP_CONST, 0, newSVpv("BEGIN", 5)),
2066 append_elem(OP_LINESEQ,
2067 newSTATEOP(0, Nullch, rqop),
2068 newSTATEOP(0, Nullch, imop) ));
2075 newSLICEOP(flags, subscript, listval)
2080 return newBINOP(OP_LSLICE, flags,
2081 list(force_list(subscript)),
2082 list(force_list(listval)) );
2092 if (op->op_type == OP_NULL && op->op_flags & OPf_KIDS)
2093 op = cUNOP->op_first;
2095 if (op->op_type == OP_COND_EXPR) {
2096 I32 t = list_assignment(cCONDOP->op_first->op_sibling);
2097 I32 f = list_assignment(cCONDOP->op_first->op_sibling->op_sibling);
2102 yyerror("Assignment to both a list and a scalar");
2106 if (op->op_type == OP_LIST || op->op_flags & OPf_PARENS ||
2107 op->op_type == OP_RV2AV || op->op_type == OP_RV2HV ||
2108 op->op_type == OP_ASLICE || op->op_type == OP_HSLICE)
2111 if (op->op_type == OP_PADAV || op->op_type == OP_PADHV)
2114 if (op->op_type == OP_RV2SV)
2121 newASSIGNOP(flags, left, optype, right)
2130 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN) {
2131 return newLOGOP(optype, 0,
2132 mod(scalar(left), optype),
2133 newUNOP(OP_SASSIGN, 0, scalar(right)));
2136 return newBINOP(optype, OPf_STACKED,
2137 mod(scalar(left), optype), scalar(right));
2141 if (list_assignment(left)) {
2143 eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2144 left = mod(left, OP_AASSIGN);
2152 op = newBINOP(OP_AASSIGN, flags,
2153 list(force_list(right)),
2154 list(force_list(left)) );
2155 op->op_private = 0 | (flags >> 8);
2156 if (!(left->op_private & OPpLVAL_INTRO)) {
2157 static int generation = 100;
2161 for (curop = LINKLIST(op); curop != op; curop = LINKLIST(curop)) {
2162 if (opargs[curop->op_type] & OA_DANGEROUS) {
2163 if (curop->op_type == OP_GV) {
2164 GV *gv = ((GVOP*)curop)->op_gv;
2165 if (gv == defgv || SvCUR(gv) == generation)
2167 SvCUR(gv) = generation;
2169 else if (curop->op_type == OP_PADSV ||
2170 curop->op_type == OP_PADAV ||
2171 curop->op_type == OP_PADHV ||
2172 curop->op_type == OP_PADANY) {
2173 SV **svp = AvARRAY(comppad_name);
2174 SV *sv = svp[curop->op_targ];
2175 if (SvCUR(sv) == generation)
2177 SvCUR(sv) = generation; /* (SvCUR not used any more) */
2179 else if (curop->op_type == OP_RV2CV)
2181 else if (curop->op_type == OP_RV2SV ||
2182 curop->op_type == OP_RV2AV ||
2183 curop->op_type == OP_RV2HV ||
2184 curop->op_type == OP_RV2GV) {
2185 if (lastop->op_type != OP_GV) /* funny deref? */
2194 op->op_private = OPpASSIGN_COMMON;
2196 if (right && right->op_type == OP_SPLIT) {
2198 if ((tmpop = ((LISTOP*)right)->op_first) &&
2199 tmpop->op_type == OP_PUSHRE)
2201 PMOP *pm = (PMOP*)tmpop;
2202 if (left->op_type == OP_RV2AV &&
2203 !(left->op_private & OPpLVAL_INTRO) &&
2204 !(op->op_private & OPpASSIGN_COMMON) )
2206 tmpop = ((UNOP*)left)->op_first;
2207 if (tmpop->op_type == OP_GV && !pm->op_pmreplroot) {
2208 pm->op_pmreplroot = (OP*)((GVOP*)tmpop)->op_gv;
2209 pm->op_pmflags |= PMf_ONCE;
2210 tmpop = ((UNOP*)op)->op_first; /* to list (nulled) */
2211 tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */
2212 tmpop->op_sibling = Nullop; /* don't free split */
2213 right->op_next = tmpop->op_next; /* fix starting loc */
2214 op_free(op); /* blow off assign */
2215 right->op_flags &= ~(OPf_KNOW|OPf_LIST);
2216 /* "I don't know and I don't care." */
2221 if (modcount < 10000 &&
2222 ((LISTOP*)right)->op_last->op_type == OP_CONST)
2224 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
2226 sv_setiv(sv, modcount+1);
2234 right = newOP(OP_UNDEF, 0);
2235 if (right->op_type == OP_READLINE) {
2236 right->op_flags |= OPf_STACKED;
2237 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
2240 eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2241 op = newBINOP(OP_SASSIGN, flags,
2242 scalar(right), mod(scalar(left), OP_SASSIGN) );
2254 newSTATEOP(flags, label, op)
2261 /* Introduce my variables. */
2262 if (min_intro_pending) {
2263 SV **svp = AvARRAY(comppad_name);
2266 for (i = min_intro_pending; i <= max_intro_pending; i++) {
2267 if ((sv = svp[i]) && sv != &sv_undef && !SvIVX(sv)) {
2268 SvIVX(sv) = 999999999; /* Don't know scope end yet. */
2269 SvNVX(sv) = (double)cop_seqmax;
2272 min_intro_pending = 0;
2273 comppad_name_fill = max_intro_pending; /* Needn't search higher */
2276 Newz(1101, cop, 1, COP);
2277 if (perldb && curcop->cop_line && curstash != debstash) {
2278 cop->op_type = OP_DBSTATE;
2279 cop->op_ppaddr = ppaddr[ OP_DBSTATE ];
2282 cop->op_type = OP_NEXTSTATE;
2283 cop->op_ppaddr = ppaddr[ OP_NEXTSTATE ];
2285 cop->op_flags = flags;
2286 cop->op_private = 0 | (flags >> 8);
2287 cop->op_next = (OP*)cop;
2290 cop->cop_label = label;
2291 hints |= HINT_BLOCK_SCOPE;
2293 cop->cop_seq = cop_seqmax++;
2294 cop->cop_arybase = curcop->cop_arybase;
2296 if (copline == NOLINE)
2297 cop->cop_line = curcop->cop_line;
2299 cop->cop_line = copline;
2302 cop->cop_filegv = SvREFCNT_inc(curcop->cop_filegv);
2303 cop->cop_stash = curstash;
2305 if (perldb && curstash != debstash) {
2306 SV **svp = av_fetch(GvAV(curcop->cop_filegv),(I32)cop->cop_line, FALSE);
2307 if (svp && *svp != &sv_undef && !SvIOK(*svp)) {
2308 (void)SvIOK_on(*svp);
2310 SvSTASH(*svp) = (HV*)cop;
2314 return prepend_elem(OP_LINESEQ, (OP*)cop, op);
2318 newLOGOP(type, flags, first, other)
2327 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
2328 return newBINOP(type, flags, scalar(first), scalar(other));
2330 scalarboolean(first);
2331 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
2332 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
2333 if (type == OP_AND || type == OP_OR) {
2339 first = cUNOP->op_first;
2341 first->op_next = op->op_next;
2342 cUNOP->op_first = Nullop;
2346 if (first->op_type == OP_CONST) {
2347 if (dowarn && (first->op_private & OPpCONST_BARE))
2348 warn("Probable precedence problem on %s", op_desc[type]);
2349 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
2358 else if (first->op_type == OP_WANTARRAY) {
2368 if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
2369 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
2371 Newz(1101, logop, 1, LOGOP);
2373 logop->op_type = type;
2374 logop->op_ppaddr = ppaddr[type];
2375 logop->op_first = first;
2376 logop->op_flags = flags | OPf_KIDS;
2377 logop->op_other = LINKLIST(other);
2378 logop->op_private = 1 | (flags >> 8);
2380 /* establish postfix order */
2381 logop->op_next = LINKLIST(first);
2382 first->op_next = (OP*)logop;
2383 first->op_sibling = other;
2385 op = newUNOP(OP_NULL, 0, (OP*)logop);
2386 other->op_next = op;
2392 newCONDOP(flags, first, true, false)
2402 return newLOGOP(OP_AND, 0, first, true);
2404 return newLOGOP(OP_OR, 0, first, false);
2406 scalarboolean(first);
2407 if (first->op_type == OP_CONST) {
2408 if (SvTRUE(((SVOP*)first)->op_sv)) {
2419 else if (first->op_type == OP_WANTARRAY) {
2423 Newz(1101, condop, 1, CONDOP);
2425 condop->op_type = OP_COND_EXPR;
2426 condop->op_ppaddr = ppaddr[OP_COND_EXPR];
2427 condop->op_first = first;
2428 condop->op_flags = flags | OPf_KIDS;
2429 condop->op_true = LINKLIST(true);
2430 condop->op_false = LINKLIST(false);
2431 condop->op_private = 1 | (flags >> 8);
2433 /* establish postfix order */
2434 condop->op_next = LINKLIST(first);
2435 first->op_next = (OP*)condop;
2437 first->op_sibling = true;
2438 true->op_sibling = false;
2439 op = newUNOP(OP_NULL, 0, (OP*)condop);
2442 false->op_next = op;
2448 newRANGE(flags, left, right)
2458 Newz(1101, condop, 1, CONDOP);
2460 condop->op_type = OP_RANGE;
2461 condop->op_ppaddr = ppaddr[OP_RANGE];
2462 condop->op_first = left;
2463 condop->op_flags = OPf_KIDS;
2464 condop->op_true = LINKLIST(left);
2465 condop->op_false = LINKLIST(right);
2466 condop->op_private = 1 | (flags >> 8);
2468 left->op_sibling = right;
2470 condop->op_next = (OP*)condop;
2471 flip = newUNOP(OP_FLIP, flags, (OP*)condop);
2472 flop = newUNOP(OP_FLOP, 0, flip);
2473 op = newUNOP(OP_NULL, 0, flop);
2476 left->op_next = flip;
2477 right->op_next = flop;
2479 condop->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2480 sv_upgrade(PAD_SV(condop->op_targ), SVt_PVNV);
2481 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2482 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
2484 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2485 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2488 if (!flip->op_private || !flop->op_private)
2489 linklist(op); /* blow off optimizer unless constant */
2495 newLOOPOP(flags, debuggable, expr, block)
2503 int once = block && block->op_flags & OPf_SPECIAL &&
2504 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
2507 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
2508 return block; /* do {} while 0 does once */
2509 else if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB)
2510 expr = newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr);
2513 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
2514 op = newLOGOP(OP_AND, 0, expr, listop);
2516 ((LISTOP*)listop)->op_last->op_next = LINKLIST(op);
2518 if (once && op != listop)
2519 op->op_next = ((LOGOP*)cUNOP->op_first)->op_other;
2522 op = newUNOP(OP_NULL, 0, op); /* or do {} while 1 loses outer block */
2524 op->op_flags |= flags;
2526 op->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/
2531 newWHILEOP(flags, debuggable, loop, expr, block, cont)
2545 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB)) {
2546 expr = newUNOP(OP_DEFINED, 0,
2547 newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr) );
2551 block = newOP(OP_NULL, 0);
2554 next = LINKLIST(cont);
2556 cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
2558 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
2559 redo = LINKLIST(listop);
2562 op = newLOGOP(OP_AND, 0, expr, scalar(listop));
2563 if (op == expr && op->op_type == OP_CONST && !SvTRUE(cSVOP->op_sv)) {
2564 op_free(expr); /* oops, it's a while (0) */
2566 return Nullop; /* (listop already freed by newLOGOP) */
2568 ((LISTOP*)listop)->op_last->op_next = condop =
2569 (op == listop ? redo : LINKLIST(op));
2577 Newz(1101,loop,1,LOOP);
2578 loop->op_type = OP_ENTERLOOP;
2579 loop->op_ppaddr = ppaddr[OP_ENTERLOOP];
2580 loop->op_private = 0;
2581 loop->op_next = (OP*)loop;
2584 op = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, op);
2586 loop->op_redoop = redo;
2587 loop->op_lastop = op;
2590 loop->op_nextop = next;
2592 loop->op_nextop = op;
2594 op->op_flags |= flags;
2595 op->op_private |= (flags >> 8);
2600 #ifndef CAN_PROTOTYPE
2601 newFOROP(flags,label,forline,sv,expr,block,cont)
2610 newFOROP(I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
2611 #endif /* CAN_PROTOTYPE */
2619 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
2620 sv->op_type = OP_RV2GV;
2621 sv->op_ppaddr = ppaddr[OP_RV2GV];
2623 else if (sv->op_type == OP_PADSV) { /* private variable */
2624 padoff = sv->op_targ;
2629 croak("Can't use %s for loop variable", op_desc[sv->op_type]);
2632 sv = newGVOP(OP_GV, 0, defgv);
2634 if (expr->op_type == OP_RV2AV) {
2635 expr = scalar(ref(expr, OP_ITER));
2636 iterflags |= OPf_STACKED;
2638 loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
2639 append_elem(OP_LIST, mod(force_list(expr), OP_GREPSTART),
2641 assert(!loop->op_next);
2642 Renew(loop, 1, LOOP);
2643 loop->op_targ = padoff;
2644 return newSTATEOP(0, label, newWHILEOP(flags, 1, loop,
2645 newOP(OP_ITER, 0), block, cont));
2649 newLOOPEX(type, label)
2654 if (type != OP_GOTO || label->op_type == OP_CONST) {
2655 op = newPVOP(type, 0, savepv(
2656 label->op_type == OP_CONST
2657 ? SvPVx(((SVOP*)label)->op_sv, na)
2662 if (label->op_type == OP_ENTERSUB)
2663 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
2664 op = newUNOP(type, OPf_STACKED, label);
2666 hints |= HINT_BLOCK_SCOPE;
2674 if (!CvXSUB(cv) && CvROOT(cv)) {
2676 croak("Can't undef active subroutine");
2683 op_free(CvROOT(cv));
2684 CvROOT(cv) = Nullop;
2687 SvREFCNT_dec(CvGV(cv));
2689 SvREFCNT_dec(CvOUTSIDE(cv));
2690 CvOUTSIDE(cv) = Nullcv;
2691 if (CvPADLIST(cv)) {
2692 I32 i = AvFILL(CvPADLIST(cv));
2694 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
2698 SvREFCNT_dec((SV*)CvPADLIST(cv));
2699 CvPADLIST(cv) = Nullav;
2709 AV* protopadlist = CvPADLIST(proto);
2710 AV* protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
2711 AV* protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
2712 SV** svp = AvARRAY(protopad);
2721 cv = compcv = (CV*)NEWSV(1104,0);
2722 sv_upgrade((SV *)cv, SVt_PVCV);
2725 CvFILEGV(cv) = CvFILEGV(proto);
2726 CvGV(cv) = SvREFCNT_inc(CvGV(proto));
2727 CvSTASH(cv) = CvSTASH(proto);
2728 CvROOT(cv) = CvROOT(proto);
2729 CvSTART(cv) = CvSTART(proto);
2730 if (CvOUTSIDE(proto))
2731 CvOUTSIDE(cv) = (CV*)SvREFCNT_inc((SV*)CvOUTSIDE(proto));
2735 comppadlist = newAV();
2736 AvREAL_off(comppadlist);
2737 av_store(comppadlist, 0, SvREFCNT_inc((SV*)protopad_name));
2738 av_store(comppadlist, 1, (SV*)comppad);
2739 CvPADLIST(cv) = comppadlist;
2740 av_extend(comppad, AvFILL(protopad));
2741 curpad = AvARRAY(comppad);
2743 av = newAV(); /* will be @_ */
2745 av_store(comppad, 0, (SV*)av);
2746 AvFLAGS(av) = AVf_REIFY;
2748 svp = AvARRAY(protopad_name);
2749 for ( ix = AvFILL(protopad); ix > 0; ix--) {
2751 if (svp[ix] != &sv_undef) {
2752 char *name = SvPVX(svp[ix]); /* XXX */
2753 if (SvFLAGS(svp[ix]) & SVf_FAKE) { /* lexical from outside? */
2754 I32 off = pad_findlex(name,ix,curcop->cop_seq, CvOUTSIDE(proto),
2757 croak("panic: cv_clone: %s", name);
2759 else { /* our own lexical */
2761 av_store(comppad, ix, sv = (SV*)newAV());
2762 else if (*name == '%')
2763 av_store(comppad, ix, sv = (SV*)newHV());
2765 av_store(comppad, ix, sv = NEWSV(0,0));
2770 av_store(comppad, ix, sv = NEWSV(0,0));
2780 newSUB(floor,op,proto,block)
2787 char *name = op ? SvPVx(cSVOP->op_sv, na) : "__ANON__";
2788 GV* gv = gv_fetchpv(name, GV_ADDMULTI, SVt_PVCV);
2795 if (cv = GvCV(gv)) {
2797 cv = 0; /* just a cached method */
2798 else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
2799 if (dowarn) { /* already defined (or promised)? */
2800 line_t oldline = curcop->cop_line;
2802 curcop->cop_line = copline;
2803 warn("Subroutine %s redefined",name);
2804 curcop->cop_line = oldline;
2810 if (cv) { /* must reuse cv if autoloaded */
2812 CvOUTSIDE(cv) = CvOUTSIDE(compcv);
2813 CvOUTSIDE(compcv) = 0;
2814 CvPADLIST(cv) = CvPADLIST(compcv);
2815 CvPADLIST(compcv) = 0;
2816 if (SvREFCNT(compcv) > 1) /* XXX Make closures transit through stub. */
2817 CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc((SV*)cv);
2818 SvREFCNT_dec(compcv);
2825 CvFILEGV(cv) = curcop->cop_filegv;
2826 CvGV(cv) = SvREFCNT_inc(gv);
2827 CvSTASH(cv) = curstash;
2830 char *p = SvPVx(((SVOP*)proto)->op_sv, na);
2831 if (SvPOK(cv) && strNE(SvPV((SV*)cv,na), p))
2832 warn("Prototype mismatch: (%s) vs (%s)", SvPV((SV*)cv, na), p);
2833 sv_setpv((SV*)cv, p);
2849 av = newAV(); /* Will be @_ */
2851 av_store(comppad, 0, (SV*)av);
2852 AvFLAGS(av) = AVf_REIFY;
2854 for (ix = AvFILL(comppad); ix > 0; ix--) {
2855 if (!SvPADMY(curpad[ix]))
2856 SvPADTMP_on(curpad[ix]);
2859 if (AvFILL(comppad_name) < AvFILL(comppad))
2860 av_store(comppad_name, AvFILL(comppad), Nullsv);
2862 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
2863 CvSTART(cv) = LINKLIST(CvROOT(cv));
2864 CvROOT(cv)->op_next = 0;
2866 if (s = strrchr(name,':'))
2870 if (strEQ(s, "BEGIN") && !error_count) {
2871 line_t oldline = compiling.cop_line;
2875 SAVESPTR(compiling.cop_filegv);
2879 av_push(beginav, (SV *)cv);
2880 DEBUG_x( dump_sub(gv) );
2881 rs = SvREFCNT_inc(nrs);
2886 curcop = &compiling;
2887 curcop->cop_line = oldline; /* might have recursed to yylex */
2890 else if (strEQ(s, "END") && !error_count) {
2893 av_unshift(endav, 1);
2894 av_store(endav, 0, SvREFCNT_inc(cv));
2896 if (perldb && curstash != debstash) {
2898 SV *tmpstr = sv_newmortal();
2900 sprintf(buf,"%s:%ld",SvPVX(GvSV(curcop->cop_filegv)), (long)subline);
2901 sv = newSVpv(buf,0);
2903 sprintf(buf,"%ld",(long)curcop->cop_line);
2905 gv_efullname(tmpstr,gv);
2906 hv_store(GvHV(DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
2912 GvCV(gv) = 0; /* Will remember in SVOP instead. */
2920 newXSUB(name, ix, subaddr, filename)
2926 CV* cv = newXS(name, (void(*)())subaddr, filename);
2928 CvXSUBANY(cv).any_i32 = ix;
2934 newXS(name, subaddr, filename)
2936 void (*subaddr) _((CV*));
2940 GV *gv = gv_fetchpv((name ? name : "__ANON__"), GV_ADDMULTI, SVt_PVCV);
2945 if (cv = GvCV(gv)) {
2947 cv = 0; /* just a cached method */
2948 else if (CvROOT(cv) || CvXSUB(cv)) { /* already defined? */
2950 line_t oldline = curcop->cop_line;
2952 curcop->cop_line = copline;
2953 warn("Subroutine %s redefined",name);
2954 curcop->cop_line = oldline;
2960 if (cv) { /* must reuse cv if autoloaded */
2961 assert(SvREFCNT(CvGV(cv)) > 1);
2962 SvREFCNT_dec(CvGV(cv));
2965 cv = (CV*)NEWSV(1105,0);
2966 sv_upgrade((SV *)cv, SVt_PVCV);
2969 CvGV(cv) = SvREFCNT_inc(gv);
2971 CvFILEGV(cv) = gv_fetchfile(filename);
2972 CvXSUB(cv) = subaddr;
2975 else if (s = strrchr(name,':'))
2979 if (strEQ(s, "BEGIN")) {
2982 av_push(beginav, SvREFCNT_inc(gv));
2984 else if (strEQ(s, "END")) {
2987 av_unshift(endav, 1);
2988 av_store(endav, 0, SvREFCNT_inc(gv));
2991 GvCV(gv) = 0; /* Will remember elsewhere instead. */
2998 newFORM(floor,op,block)
3009 name = SvPVx(cSVOP->op_sv, na);
3012 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
3014 if (cv = GvFORM(gv)) {
3016 line_t oldline = curcop->cop_line;
3018 curcop->cop_line = copline;
3019 warn("Format %s redefined",name);
3020 curcop->cop_line = oldline;
3026 CvGV(cv) = SvREFCNT_inc(gv);
3027 CvFILEGV(cv) = curcop->cop_filegv;
3029 for (ix = AvFILL(comppad); ix > 0; ix--) {
3030 if (!SvPADMY(curpad[ix]))
3031 SvPADTMP_on(curpad[ix]);
3034 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
3035 CvSTART(cv) = LINKLIST(CvROOT(cv));
3036 CvROOT(cv)->op_next = 0;
3048 return newUNOP(OP_REFGEN, 0,
3049 mod(list(convert(OP_ANONLIST, 0, op)), OP_REFGEN));
3056 return newUNOP(OP_REFGEN, 0,
3057 mod(list(convert(OP_ANONHASH, 0, op)), OP_REFGEN));
3061 newANONSUB(floor, proto, block)
3066 return newUNOP(OP_REFGEN, 0,
3067 newSVOP(OP_ANONCODE, 0, (SV*)newSUB(floor, 0, proto, block)));
3074 switch (o->op_type) {
3076 o->op_type = OP_PADAV;
3077 o->op_ppaddr = ppaddr[OP_PADAV];
3078 return ref(newUNOP(OP_RV2AV, 0, scalar(o)), OP_RV2AV);
3081 o->op_type = OP_RV2AV;
3082 o->op_ppaddr = ppaddr[OP_RV2AV];
3087 warn("oops: oopsAV");
3097 switch (o->op_type) {
3100 o->op_type = OP_PADHV;
3101 o->op_ppaddr = ppaddr[OP_PADHV];
3102 return ref(newUNOP(OP_RV2HV, 0, scalar(o)), OP_RV2HV);
3106 o->op_type = OP_RV2HV;
3107 o->op_ppaddr = ppaddr[OP_RV2HV];
3112 warn("oops: oopsHV");
3122 if (o->op_type == OP_PADANY) {
3123 o->op_type = OP_PADAV;
3124 o->op_ppaddr = ppaddr[OP_PADAV];
3127 return newUNOP(OP_RV2AV, 0, scalar(o));
3135 if (type == OP_MAPSTART)
3136 return newUNOP(OP_NULL, 0, o);
3137 return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
3144 if (o->op_type == OP_PADANY) {
3145 o->op_type = OP_PADHV;
3146 o->op_ppaddr = ppaddr[OP_PADHV];
3149 return newUNOP(OP_RV2HV, 0, scalar(o));
3156 croak("NOT IMPL LINE %d",__LINE__);
3166 return newUNOP(OP_RV2CV, flags, scalar(o));
3173 if (o->op_type == OP_PADANY) {
3174 o->op_type = OP_PADSV;
3175 o->op_ppaddr = ppaddr[OP_PADSV];
3178 return newUNOP(OP_RV2SV, 0, scalar(o));
3181 /* Check routines. */
3187 if (cUNOP->op_first->op_type == OP_CONCAT)
3188 op->op_flags |= OPf_STACKED;
3196 if (op->op_flags & OPf_KIDS) {
3199 op = modkids(ck_fun(op), op->op_type);
3200 kid = cUNOP->op_first;
3201 newop = kUNOP->op_first->op_sibling;
3203 (newop->op_sibling ||
3204 !(opargs[newop->op_type] & OA_RETSCALAR) ||
3205 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
3206 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
3210 op_free(kUNOP->op_first);
3211 kUNOP->op_first = newop;
3213 op->op_ppaddr = ppaddr[++op->op_type];
3222 if (op->op_flags & OPf_KIDS) {
3223 OP *kid = cUNOP->op_first;
3224 if (kid->op_type != OP_HELEM)
3225 croak("%s argument is not a HASH element", op_desc[op->op_type]);
3235 I32 type = op->op_type;
3237 if (op->op_flags & OPf_KIDS) {
3238 if (cLISTOP->op_first->op_type == OP_STUB) {
3240 op = newUNOP(type, OPf_SPECIAL,
3241 newGVOP(OP_GV, 0, gv_fetchpv("main'ARGV", TRUE, SVt_PVAV)));
3252 hints |= HINT_BLOCK_SCOPE;
3253 if (op->op_flags & OPf_KIDS) {
3254 SVOP *kid = (SVOP*)cUNOP->op_first;
3257 op->op_flags &= ~OPf_KIDS;
3260 else if (kid->op_type == OP_LINESEQ) {
3263 kid->op_next = op->op_next;
3264 cUNOP->op_first = 0;
3267 Newz(1101, enter, 1, LOGOP);
3268 enter->op_type = OP_ENTERTRY;
3269 enter->op_ppaddr = ppaddr[OP_ENTERTRY];
3270 enter->op_private = 0;
3272 /* establish postfix order */
3273 enter->op_next = (OP*)enter;
3275 op = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
3276 op->op_type = OP_LEAVETRY;
3277 op->op_ppaddr = ppaddr[OP_LEAVETRY];
3278 enter->op_other = op;
3284 op = newUNOP(OP_ENTEREVAL, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3286 op->op_targ = (PADOFFSET)hints;
3295 if (op->op_flags & OPf_STACKED) {
3297 kid = cUNOP->op_first->op_sibling;
3298 if (kid->op_type == OP_RV2GV)
3310 o = fold_constants(o);
3311 if (o->op_type == OP_CONST)
3320 SVOP *kid = (SVOP*)cUNOP->op_first;
3322 op->op_private |= (hints & HINT_STRICT_REFS);
3323 if (kid->op_type == OP_CONST) {
3324 int iscv = (op->op_type==OP_RV2CV)*2;
3326 kid->op_type = OP_GV;
3327 for (gv = 0; !gv; iscv++) {
3329 * This is a little tricky. We only want to add the symbol if we
3330 * didn't add it in the lexer. Otherwise we get duplicate strict
3331 * warnings. But if we didn't add it in the lexer, we must at
3332 * least pretend like we wanted to add it even if it existed before,
3333 * or we get possible typo warnings. OPpCONST_ENTERED says
3334 * whether the lexer already added THIS instance of this symbol.
3336 gv = gv_fetchpv(SvPVx(kid->op_sv, na),
3337 iscv | !(kid->op_private & OPpCONST_ENTERED),
3340 : op->op_type == OP_RV2SV
3342 : op->op_type == OP_RV2AV
3344 : op->op_type == OP_RV2HV
3348 SvREFCNT_dec(kid->op_sv);
3349 kid->op_sv = SvREFCNT_inc(gv);
3365 I32 type = op->op_type;
3367 if (op->op_flags & OPf_REF)
3370 if (op->op_flags & OPf_KIDS) {
3371 SVOP *kid = (SVOP*)cUNOP->op_first;
3373 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
3374 OP *newop = newGVOP(type, OPf_REF,
3375 gv_fetchpv(SvPVx(kid->op_sv, na), TRUE, SVt_PVIO));
3382 if (type == OP_FTTTY)
3383 return newGVOP(type, OPf_REF, gv_fetchpv("main'STDIN", TRUE,
3386 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3399 int type = op->op_type;
3400 register I32 oa = opargs[type] >> OASHIFT;
3402 if (op->op_flags & OPf_STACKED) {
3403 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
3406 return no_fh_allowed(op);
3409 if (op->op_flags & OPf_KIDS) {
3410 tokid = &cLISTOP->op_first;
3411 kid = cLISTOP->op_first;
3412 if (kid->op_type == OP_PUSHMARK ||
3413 kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK)
3415 tokid = &kid->op_sibling;
3416 kid = kid->op_sibling;
3418 if (!kid && opargs[type] & OA_DEFGV)
3419 *tokid = kid = newSVREF(newGVOP(OP_GV, 0, defgv));
3423 sibl = kid->op_sibling;
3437 if (kid->op_type == OP_CONST &&
3438 (kid->op_private & OPpCONST_BARE)) {
3439 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
3440 OP *newop = newAVREF(newGVOP(OP_GV, 0,
3441 gv_fetchpv(name, TRUE, SVt_PVAV) ));
3443 warn("Array @%s missing the @ in argument %d of %s()",
3444 name, numargs, op_desc[type]);
3447 kid->op_sibling = sibl;
3450 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
3451 bad_type(numargs, "array", op_desc[op->op_type], kid);
3455 if (kid->op_type == OP_CONST &&
3456 (kid->op_private & OPpCONST_BARE)) {
3457 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
3458 OP *newop = newHVREF(newGVOP(OP_GV, 0,
3459 gv_fetchpv(name, TRUE, SVt_PVHV) ));
3461 warn("Hash %%%s missing the %% in argument %d of %s()",
3462 name, numargs, op_desc[type]);
3465 kid->op_sibling = sibl;
3468 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
3469 bad_type(numargs, "hash", op_desc[op->op_type], kid);
3474 OP *newop = newUNOP(OP_NULL, 0, kid);
3475 kid->op_sibling = 0;
3477 newop->op_next = newop;
3479 kid->op_sibling = sibl;
3484 if (kid->op_type != OP_GV) {
3485 if (kid->op_type == OP_CONST &&
3486 (kid->op_private & OPpCONST_BARE)) {
3487 OP *newop = newGVOP(OP_GV, 0,
3488 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, na), TRUE,
3494 kid->op_sibling = 0;
3495 kid = newUNOP(OP_RV2GV, 0, scalar(kid));
3497 kid->op_sibling = sibl;
3503 mod(scalar(kid), type);
3507 tokid = &kid->op_sibling;
3508 kid = kid->op_sibling;
3510 op->op_private |= numargs;
3512 return too_many_arguments(op,op_desc[op->op_type]);
3515 else if (opargs[type] & OA_DEFGV) {
3517 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3521 while (oa & OA_OPTIONAL)
3523 if (oa && oa != OA_LIST)
3524 return too_few_arguments(op,op_desc[op->op_type]);
3533 GV *gv = newGVgen("main");
3535 append_elem(OP_GLOB, op, newGVOP(OP_GV, 0, gv));
3546 OPCODE type = op->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
3548 op->op_ppaddr = ppaddr[OP_GREPSTART];
3549 Newz(1101, gwop, 1, LOGOP);
3551 if (op->op_flags & OPf_STACKED) {
3554 kid = cLISTOP->op_first->op_sibling;
3555 for (k = cLISTOP->op_first->op_sibling->op_next; k; k = k->op_next) {
3558 kid->op_next = (OP*)gwop;
3559 op->op_flags &= ~OPf_STACKED;
3561 kid = cLISTOP->op_first->op_sibling;
3562 if (type == OP_MAPWHILE)
3569 kid = cLISTOP->op_first->op_sibling;
3570 if (kid->op_type != OP_NULL)
3571 croak("panic: ck_grep");
3572 kid = kUNOP->op_first;
3574 gwop->op_type = type;
3575 gwop->op_ppaddr = ppaddr[type];
3576 gwop->op_first = listkids(op);
3577 gwop->op_flags |= OPf_KIDS;
3578 gwop->op_private = 1;
3579 gwop->op_other = LINKLIST(kid);
3580 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
3581 kid->op_next = (OP*)gwop;
3583 kid = cLISTOP->op_first->op_sibling;
3584 if (!kid || !kid->op_sibling)
3585 return too_few_arguments(op,op_desc[op->op_type]);
3586 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
3587 mod(kid, OP_GREPSTART);
3596 if (op->op_flags & OPf_KIDS) {
3597 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3598 if (kid && kid->op_type == OP_CONST)
3599 fbm_compile(((SVOP*)kid)->op_sv, 0);
3608 /* XXX length optimization goes here */
3616 return modkids(ck_fun(op), op->op_type);
3623 return refkids(ck_fun(op), op->op_type);
3632 kid = cLISTOP->op_first;
3634 op = force_list(op);
3635 kid = cLISTOP->op_first;
3637 if (kid->op_type == OP_PUSHMARK)
3638 kid = kid->op_sibling;
3639 if (kid && op->op_flags & OPf_STACKED)
3640 kid = kid->op_sibling;
3641 else if (kid && !kid->op_sibling) { /* print HANDLE; */
3642 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
3643 op->op_flags |= OPf_STACKED; /* make it a filehandle */
3644 kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
3645 cLISTOP->op_first->op_sibling = kid;
3646 cLISTOP->op_last = kid;
3647 kid = kid->op_sibling;
3652 append_elem(op->op_type, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
3654 return listkids(op);
3661 cPMOP->op_pmflags |= PMf_RUNTIME;
3662 cPMOP->op_pmpermflags |= PMf_RUNTIME;
3677 if (cBINOP->op_first->op_flags & OPf_PARENS) {
3678 op->op_private |= OPpREPEAT_DOLIST;
3679 cBINOP->op_first = force_list(cBINOP->op_first);
3690 if (op->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
3691 SVOP *kid = (SVOP*)cUNOP->op_first;
3693 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
3695 for (s = SvPVX(kid->op_sv); *s; s++) {
3696 if (*s == ':' && s[1] == ':') {
3698 Move(s+2, s+1, strlen(s+2)+1, char);
3699 --SvCUR(kid->op_sv);
3702 sv_catpvn(kid->op_sv, ".pm", 3);
3712 croak("NOT IMPL LINE %d",__LINE__);
3722 if (op->op_flags & OPf_KIDS) {
3723 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3724 if (kid && kid->op_sibling) {
3725 op->op_type = OP_SSELECT;
3726 op->op_ppaddr = ppaddr[OP_SSELECT];
3728 return fold_constants(op);
3732 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3733 if (kid && kid->op_type == OP_RV2GV)
3734 kid->op_private &= ~HINT_STRICT_REFS;
3742 I32 type = op->op_type;
3744 if (!(op->op_flags & OPf_KIDS)) {
3746 return newUNOP(type, 0,
3747 scalar(newUNOP(OP_RV2AV, 0,
3748 scalar(newGVOP(OP_GV, 0,
3749 gv_fetchpv((subline ? "_" : "ARGV"), TRUE, SVt_PVAV) )))));
3751 return scalar(modkids(ck_fun(op), type));
3758 if (op->op_flags & OPf_STACKED) {
3759 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3761 kid = kUNOP->op_first; /* get past rv2gv */
3763 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
3765 if (kid->op_type == OP_SCOPE) {
3769 else if (kid->op_type == OP_LEAVE) {
3770 if (op->op_type == OP_SORT) {
3771 null(kid); /* wipe out leave */
3774 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
3775 if (k->op_next == kid)
3780 kid->op_next = 0; /* just disconnect the leave */
3781 k = kLISTOP->op_first;
3785 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3786 null(kid); /* wipe out rv2gv */
3787 if (op->op_type == OP_SORT)
3791 op->op_flags |= OPf_SPECIAL;
3804 if (op->op_flags & OPf_STACKED)
3805 return no_fh_allowed(op);
3807 kid = cLISTOP->op_first;
3808 if (kid->op_type != OP_NULL)
3809 croak("panic: ck_split");
3810 kid = kid->op_sibling;
3811 op_free(cLISTOP->op_first);
3812 cLISTOP->op_first = kid;
3814 cLISTOP->op_first = kid = newSVOP(OP_CONST, 0, newSVpv(" ", 1));
3815 cLISTOP->op_last = kid; /* There was only one element previously */
3818 if (kid->op_type != OP_MATCH) {
3819 OP *sibl = kid->op_sibling;
3820 kid->op_sibling = 0;
3821 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
3822 if (cLISTOP->op_first == cLISTOP->op_last)
3823 cLISTOP->op_last = kid;
3824 cLISTOP->op_first = kid;
3825 kid->op_sibling = sibl;
3828 if (pm->op_pmshort && !(pm->op_pmflags & PMf_ALL)) {
3829 SvREFCNT_dec(pm->op_pmshort); /* can't use substring to optimize */
3833 kid->op_type = OP_PUSHRE;
3834 kid->op_ppaddr = ppaddr[OP_PUSHRE];
3837 if (!kid->op_sibling)
3838 append_elem(OP_SPLIT, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
3840 kid = kid->op_sibling;
3843 if (!kid->op_sibling)
3844 append_elem(OP_SPLIT, op, newSVOP(OP_CONST, 0, newSViv(0)));
3846 kid = kid->op_sibling;
3849 if (kid->op_sibling)
3850 return too_many_arguments(op,op_desc[op->op_type]);
3859 OP *prev = ((cUNOP->op_first->op_sibling)
3860 ? cUNOP : ((UNOP*)cUNOP->op_first))->op_first;
3861 OP *o = prev->op_sibling;
3868 for (cvop = o; cvop->op_sibling; cvop = cvop->op_sibling) ;
3869 if (cvop->op_type == OP_RV2CV) {
3871 op->op_private |= (cvop->op_private & OPpENTERSUB_AMPER);
3872 null(cvop); /* disable rv2cv */
3873 tmpop = (SVOP*)((UNOP*)cvop)->op_first;
3874 if (tmpop->op_type == OP_GV) {
3875 cv = GvCV(tmpop->op_sv);
3876 if (cv && SvPOK(cv) && !(op->op_private & OPpENTERSUB_AMPER))
3877 proto = SvPV((SV*)cv,na);
3880 op->op_private |= (hints & HINT_STRICT_REFS);
3881 if (perldb && curstash != debstash)
3882 op->op_private |= OPpENTERSUB_DB;
3887 return too_many_arguments(op, CvNAME(cv));
3905 if (o->op_type != OP_REFGEN && o->op_type != OP_UNDEF)
3906 bad_type(arg, "block", CvNAME(cv), o);
3911 if (o->op_type == OP_RV2GV)
3915 o = newUNOP(OP_RV2GV, 0, kid);
3916 o->op_sibling = kid->op_sibling;
3917 kid->op_sibling = 0;
3918 prev->op_sibling = o;
3926 if (o->op_type != OP_RV2GV)
3927 bad_type(arg, "symbol", CvNAME(cv), o);
3930 if (o->op_type != OP_RV2CV)
3931 bad_type(arg, "sub", CvNAME(cv), o);
3934 if (o->op_type != OP_RV2SV && o->op_type != OP_PADSV)
3935 bad_type(arg, "scalar", CvNAME(cv), o);
3938 if (o->op_type != OP_RV2AV && o->op_type != OP_PADAV)
3939 bad_type(arg, "array", CvNAME(cv), o);
3942 if (o->op_type != OP_RV2HV && o->op_type != OP_PADHV)
3943 bad_type(arg, "hash", CvNAME(cv), o);
3947 o = newUNOP(OP_REFGEN, 0, kid);
3948 o->op_sibling = kid->op_sibling;
3949 kid->op_sibling = 0;
3950 prev->op_sibling = o;
3958 croak("Malformed prototype for %s: %s",
3959 CvNAME(cv),SvPV((SV*)cv,na));
3964 mod(o, OP_ENTERSUB);
3968 if (proto && !optional && *proto == '$')
3969 return too_few_arguments(op, CvNAME(cv));
3977 SvREADONLY_on(cSVOP->op_sv);
3985 if (op->op_flags & OPf_KIDS) {
3986 SVOP *kid = (SVOP*)cUNOP->op_first;
3988 if (kid->op_type == OP_NULL)
3989 kid = (SVOP*)kid->op_sibling;
3991 kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE))
3992 op->op_flags |= OPf_SPECIAL;
3997 /* A peephole optimizer. We visit the ops in the order they're to execute. */
4003 register OP* oldop = 0;
4004 if (!o || o->op_seq)
4009 for (; o; o = o->op_next) {
4015 switch (o->op_type) {
4018 curcop = ((COP*)o); /* for warnings */
4019 o->op_seq = op_seqmax++;
4030 if (o->op_next->op_type == OP_STRINGIFY)
4032 o->op_seq = op_seqmax++;
4035 if ((o->op_flags & (OPf_KNOW|OPf_LIST)) != (OPf_KNOW|OPf_LIST)) {
4036 o->op_seq = op_seqmax++;
4037 break; /* Scalar stub must produce undef. List stub is noop */
4041 if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE)
4042 curcop = ((COP*)op);
4048 if (oldop && o->op_next) {
4049 oldop->op_next = o->op_next;
4052 o->op_seq = op_seqmax++;
4056 if (o->op_next->op_type == OP_RV2SV) {
4057 if (!(o->op_next->op_private & (OPpDEREF_HV|OPpDEREF_AV))) {
4059 o->op_private |= o->op_next->op_private & OPpLVAL_INTRO;
4060 o->op_next = o->op_next->op_next;
4061 o->op_type = OP_GVSV;
4062 o->op_ppaddr = ppaddr[OP_GVSV];
4065 else if (o->op_next->op_type == OP_RV2AV) {
4066 OP* pop = o->op_next->op_next;
4068 if (pop->op_type == OP_CONST &&
4069 (op = pop->op_next) &&
4070 pop->op_next->op_type == OP_AELEM &&
4071 !(pop->op_next->op_private &
4072 (OPpDEREF_HV|OPpDEREF_AV|OPpLVAL_INTRO)) &&
4073 (i = SvIV(((SVOP*)pop)->op_sv) - compiling.cop_arybase)
4077 SvREFCNT_dec(((SVOP*)pop)->op_sv);
4081 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
4082 o->op_next = pop->op_next->op_next;
4083 o->op_type = OP_AELEMFAST;
4084 o->op_ppaddr = ppaddr[OP_AELEMFAST];
4085 o->op_private = (U8)i;
4086 GvAVn((GV*)(((SVOP*)o)->op_sv));
4089 o->op_seq = op_seqmax++;
4096 o->op_seq = op_seqmax++;
4097 peep(cLOGOP->op_other);
4101 o->op_seq = op_seqmax++;
4102 peep(cCONDOP->op_true);
4103 peep(cCONDOP->op_false);
4107 o->op_seq = op_seqmax++;
4108 peep(cLOOP->op_redoop);
4109 peep(cLOOP->op_nextop);
4110 peep(cLOOP->op_lastop);
4115 o->op_seq = op_seqmax++;
4116 peep(cPMOP->op_pmreplstart);
4120 o->op_seq = op_seqmax++;
4121 if (dowarn && o->op_next && o->op_next->op_type == OP_NEXTSTATE) {
4122 if (o->op_next->op_sibling &&
4123 o->op_next->op_sibling->op_type != OP_DIE) {
4124 line_t oldline = curcop->cop_line;
4126 curcop->cop_line = ((COP*)o->op_next)->cop_line;
4127 warn("Statement unlikely to be reached");
4128 warn("(Maybe you meant system() when you said exec()?)\n");
4129 curcop->cop_line = oldline;
4134 o->op_seq = op_seqmax++;