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);
133 croak("Can't declare class for non-scalar %s in \"my\"",name);
135 (void)SvUPGRADE(sv, SVt_PVMG);
136 SvSTASH(sv) = (HV*)SvREFCNT_inc(in_my_stash);
139 av_store(comppad_name, off, sv);
140 SvNVX(sv) = (double)999999999;
141 SvIVX(sv) = 0; /* Not yet introduced--see newSTATEOP */
142 if (!min_intro_pending)
143 min_intro_pending = off;
144 max_intro_pending = off;
146 av_store(comppad, off, (SV*)newAV());
147 else if (*name == '%')
148 av_store(comppad, off, (SV*)newHV());
149 SvPADMY_on(curpad[off]);
154 #ifndef CAN_PROTOTYPE
155 pad_findlex(name, newoff, seq, startcv, cx_ix)
162 pad_findlex(char *name, PADOFFSET newoff, I32 seq, CV* startcv, I32 cx_ix)
169 register CONTEXT *cx;
172 for (cv = startcv; cv; cv = CvOUTSIDE(cv)) {
173 AV* curlist = CvPADLIST(cv);
174 SV** svp = av_fetch(curlist, 0, FALSE);
176 if (!svp || *svp == &sv_undef)
179 svp = AvARRAY(curname);
180 for (off = AvFILL(curname); off > 0; off--) {
181 if ((sv = svp[off]) &&
184 seq > (I32)SvNVX(sv) &&
185 strEQ(SvPVX(sv), name))
187 I32 depth = CvDEPTH(cv) ? CvDEPTH(cv) : 1;
188 AV *oldpad = (AV*)*av_fetch(curlist, depth, FALSE);
189 SV *oldsv = *av_fetch(oldpad, off, TRUE);
190 if (!newoff) { /* Not a mere clone operation. */
191 SV *sv = NEWSV(1103,0);
192 newoff = pad_alloc(OP_PADSV, SVs_PADMY);
193 sv_upgrade(sv, SVt_PVNV);
195 av_store(comppad_name, newoff, sv);
196 SvNVX(sv) = (double)curcop->cop_seq;
197 SvIVX(sv) = 999999999; /* A ref, intro immediately */
198 SvFLAGS(sv) |= SVf_FAKE;
200 av_store(comppad, newoff, SvREFCNT_inc(oldsv));
207 /* Nothing in current lexical context--try eval's context, if any.
208 * This is necessary to let the perldb get at lexically scoped variables.
209 * XXX This will also probably interact badly with eval tree caching.
213 for (i = cx_ix; i >= 0; i--) {
215 switch (cx->cx_type) {
217 if (i == 0 && saweval) {
218 seq = cxstack[saweval].blk_oldcop->cop_seq;
219 return pad_findlex(name, newoff, seq, main_cv, 0);
223 if (cx->blk_eval.old_op_type != OP_ENTEREVAL &&
224 cx->blk_eval.old_op_type != OP_ENTERTRY)
225 return 0; /* require must have its own scope */
232 if (debstash && CvSTASH(cv) == debstash) { /* ignore DB'* scope */
233 saweval = i; /* so we know where we were called from */
236 seq = cxstack[saweval].blk_oldcop->cop_seq;
237 return pad_findlex(name, newoff, seq, cv, i-1);
250 SV **svp = AvARRAY(comppad_name);
251 I32 seq = cop_seqmax;
253 /* The one we're looking for is probably just before comppad_name_fill. */
254 for (off = AvFILL(comppad_name); off > 0; off--) {
255 if ((sv = svp[off]) &&
258 seq > (I32)SvNVX(sv) &&
259 strEQ(SvPVX(sv), name))
261 return (PADOFFSET)off;
265 /* See if it's in a nested scope */
266 off = pad_findlex(name, 0, seq, CvOUTSIDE(compcv), cxstack_ix);
278 SV **svp = AvARRAY(comppad_name);
280 if (min_intro_pending && fill < min_intro_pending) {
281 for (off = max_intro_pending; off >= min_intro_pending; off--) {
282 if ((sv = svp[off]) && sv != &sv_undef)
283 warn("%s never introduced", SvPVX(sv));
286 /* "Deintroduce" my variables that are leaving with this scope. */
287 for (off = AvFILL(comppad_name); off > fill; off--) {
288 if ((sv = svp[off]) && sv != &sv_undef && SvIVX(sv) == 999999999)
289 SvIVX(sv) = cop_seqmax;
294 pad_alloc(optype,tmptype)
301 if (AvARRAY(comppad) != curpad)
302 croak("panic: pad_alloc");
303 if (pad_reset_pending)
305 if (tmptype & SVs_PADMY) {
307 sv = *av_fetch(comppad, AvFILL(comppad) + 1, TRUE);
308 } while (SvPADBUSY(sv)); /* need a fresh one */
309 retval = AvFILL(comppad);
313 sv = *av_fetch(comppad, ++padix, TRUE);
314 } while (SvFLAGS(sv) & (SVs_PADTMP|SVs_PADMY));
317 SvFLAGS(sv) |= tmptype;
318 curpad = AvARRAY(comppad);
319 DEBUG_X(fprintf(stderr, "Pad alloc %ld for %s\n", (long) retval, op_name[optype]));
320 return (PADOFFSET)retval;
324 #ifndef CAN_PROTOTYPE
329 #endif /* CAN_PROTOTYPE */
332 croak("panic: pad_sv po");
333 DEBUG_X(fprintf(stderr, "Pad sv %d\n", po));
334 return curpad[po]; /* eventually we'll turn this into a macro */
338 #ifndef CAN_PROTOTYPE
342 pad_free(PADOFFSET po)
343 #endif /* CAN_PROTOTYPE */
347 if (AvARRAY(comppad) != curpad)
348 croak("panic: pad_free curpad");
350 croak("panic: pad_free po");
351 DEBUG_X(fprintf(stderr, "Pad free %d\n", po));
352 if (curpad[po] && curpad[po] != &sv_undef)
353 SvPADTMP_off(curpad[po]);
359 #ifndef CAN_PROTOTYPE
363 pad_swipe(PADOFFSET po)
364 #endif /* CAN_PROTOTYPE */
366 if (AvARRAY(comppad) != curpad)
367 croak("panic: pad_swipe curpad");
369 croak("panic: pad_swipe po");
370 DEBUG_X(fprintf(stderr, "Pad swipe %d\n", po));
371 SvPADTMP_off(curpad[po]);
372 curpad[po] = NEWSV(1107,0);
373 SvPADTMP_on(curpad[po]);
383 if (AvARRAY(comppad) != curpad)
384 croak("panic: pad_reset curpad");
385 DEBUG_X(fprintf(stderr, "Pad reset\n"));
386 if (!tainting) { /* Can't mix tainted and non-tainted temporaries. */
387 for (po = AvMAX(comppad); po > padix_floor; po--) {
388 if (curpad[po] && curpad[po] != &sv_undef)
389 SvPADTMP_off(curpad[po]);
393 pad_reset_pending = FALSE;
402 register OP *kid, *nextkid;
407 if (op->op_flags & OPf_KIDS) {
408 for (kid = cUNOP->op_first; kid; kid = nextkid) {
409 nextkid = kid->op_sibling; /* Get before next freeing kid */
414 switch (op->op_type) {
416 op->op_targ = 0; /* Was holding old type, if any. */
419 op->op_targ = 0; /* Was holding hints. */
423 SvREFCNT_dec(cGVOP->op_gv);
427 SvREFCNT_dec(cCOP->cop_filegv);
430 SvREFCNT_dec(cSVOP->op_sv);
436 if (op->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
440 Safefree(cPVOP->op_pv);
443 op_free(cPMOP->op_pmreplroot);
447 pregfree(cPMOP->op_pmregexp);
448 SvREFCNT_dec(cPMOP->op_pmshort);
455 pad_free(op->op_targ);
464 if (op->op_type != OP_NULL && op->op_targ > 0)
465 pad_free(op->op_targ);
466 op->op_targ = op->op_type;
467 op->op_type = OP_NULL;
468 op->op_ppaddr = ppaddr[OP_NULL];
471 /* Contextualizers */
473 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
484 /* establish postfix order */
485 if (cUNOP->op_first) {
486 op->op_next = LINKLIST(cUNOP->op_first);
487 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
489 kid->op_next = LINKLIST(kid->op_sibling);
505 if (op && op->op_flags & OPf_KIDS) {
506 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
517 op->op_type == OP_SASSIGN && cBINOP->op_first->op_type == OP_CONST) {
518 line_t oldline = curcop->cop_line;
520 if (copline != NOLINE)
521 curcop->cop_line = copline;
522 warn("Found = in conditional, should be ==");
523 curcop->cop_line = oldline;
534 /* assumes no premature commitment */
535 if (!op || (op->op_flags & OPf_KNOW) || error_count)
538 op->op_flags &= ~OPf_LIST;
539 op->op_flags |= OPf_KNOW;
541 switch (op->op_type) {
543 if (op->op_private & OPpREPEAT_DOLIST)
544 null(((LISTOP*)cBINOP->op_first)->op_first);
545 scalar(cBINOP->op_first);
550 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
554 if ((kid = ((LISTOP*)op)->op_first) && kid->op_type == OP_PUSHRE) {
555 if (!kPMOP->op_pmreplroot)
556 deprecate("implicit split to @_");
563 if (op->op_flags & OPf_KIDS) {
564 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling)
570 scalar(cLISTOP->op_first);
575 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
595 if (!op || error_count)
597 if (op->op_flags & OPf_LIST)
600 op->op_flags |= OPf_KNOW;
602 switch (op->op_type) {
604 if (!(opargs[op->op_type] & OA_FOLDCONST))
606 if (op->op_flags & OPf_STACKED)
679 if (!(op->op_private & OPpLVAL_INTRO))
680 useless = op_desc[op->op_type];
687 if (!(op->op_private & OPpLVAL_INTRO) &&
688 (!op->op_sibling || op->op_sibling->op_type != OP_READLINE))
689 useless = "a variable";
694 curcop = ((COP*)op); /* for warning below */
700 useless = "a constant";
701 if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
703 else if (SvPOK(sv)) {
704 if (strnEQ(SvPVX(sv), "di", 2) ||
705 strnEQ(SvPVX(sv), "ds", 2) ||
706 strnEQ(SvPVX(sv), "ig", 2))
710 null(op); /* don't execute a constant */
711 SvREFCNT_dec(sv); /* don't even remember it */
715 op->op_type = OP_PREINC; /* pre-increment is faster */
716 op->op_ppaddr = ppaddr[OP_PREINC];
720 op->op_type = OP_PREDEC; /* pre-decrement is faster */
721 op->op_ppaddr = ppaddr[OP_PREDEC];
725 scalarvoid(cBINOP->op_first);
726 useless = op_desc[op->op_type];
732 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
736 if (op->op_targ == OP_NEXTSTATE || op->op_targ == OP_DBSTATE)
737 curcop = ((COP*)op); /* for warning below */
738 if (op->op_flags & OPf_STACKED)
743 if (!(op->op_flags & OPf_KIDS))
749 op->op_private |= OPpLEAVE_VOID;
752 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
756 if ((kid = ((LISTOP*)op)->op_first) && kid->op_type == OP_PUSHRE) {
757 if (!kPMOP->op_pmreplroot)
758 deprecate("implicit split to @_");
762 op->op_private |= OPpLEAVE_VOID;
765 if (useless && dowarn)
766 warn("Useless use of %s in void context", useless);
775 if (op && op->op_flags & OPf_KIDS) {
776 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
788 /* assumes no premature commitment */
789 if (!op || (op->op_flags & OPf_KNOW) || error_count)
792 op->op_flags |= (OPf_KNOW | OPf_LIST);
794 switch (op->op_type) {
797 list(cBINOP->op_first);
802 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
809 if (!(op->op_flags & OPf_KIDS))
811 if (!op->op_next && cUNOP->op_first->op_type == OP_FLOP) {
812 list(cBINOP->op_first);
813 return gen_constant_list(op);
820 list(cLISTOP->op_first);
824 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
843 if (op->op_type == OP_LINESEQ ||
844 op->op_type == OP_SCOPE ||
845 op->op_type == OP_LEAVE ||
846 op->op_type == OP_LEAVETRY)
848 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
849 if (kid->op_sibling) {
855 op->op_flags &= ~OPf_PARENS;
856 if (hints & HINT_BLOCK_SCOPE)
857 op->op_flags |= OPf_PARENS;
860 op = newOP(OP_STUB, 0);
870 if (op && op->op_flags & OPf_KIDS) {
871 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
888 if (!op || error_count)
891 switch (op->op_type) {
893 if (!(op->op_private & (OPpCONST_ARYBASE)))
895 if (eval_start && eval_start->op_type == OP_CONST) {
896 compiling.cop_arybase = (I32)SvIV(((SVOP*)eval_start)->op_sv);
900 SAVEI32(compiling.cop_arybase);
901 compiling.cop_arybase = 0;
903 else if (type == OP_REFGEN)
906 croak("That use of $[ is unsupported");
909 if ((type == OP_UNDEF || type == OP_REFGEN) &&
910 !(op->op_flags & OPf_STACKED)) {
911 op->op_type = OP_RV2CV; /* entersub => rv2cv */
912 op->op_ppaddr = ppaddr[OP_RV2CV];
913 assert(cUNOP->op_first->op_type == OP_NULL);
914 null(((LISTOP*)cUNOP->op_first)->op_first); /* disable pushmark */
920 /* grep, foreach, subcalls, refgen */
921 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
923 sprintf(tokenbuf, "Can't modify %s in %s",
924 op_desc[op->op_type],
925 type ? op_desc[type] : "local");
949 if (!(op->op_flags & OPf_STACKED))
955 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
961 if (type == OP_REFGEN && op->op_flags & OPf_PARENS) {
963 return op; /* Treat \(@foo) like ordinary list. */
967 ref(cUNOP->op_first, op->op_type);
979 if (!type && cUNOP->op_first->op_type != OP_GV)
980 croak("Can't localize a reference");
981 ref(cUNOP->op_first, op->op_type);
998 croak("Can't localize lexical variable %s",
999 SvPV(*av_fetch(comppad_name, op->op_targ, 4), na));
1014 pad_free(op->op_targ);
1015 op->op_targ = pad_alloc(op->op_type, SVs_PADMY);
1016 sv = PAD_SV(op->op_targ);
1017 sv_upgrade(sv, SVt_PVLV);
1018 sv_magic(sv, Nullsv, mtype, Nullch, 0);
1019 curpad[op->op_targ] = sv;
1020 if (op->op_flags & OPf_KIDS)
1021 mod(cBINOP->op_first->op_sibling, type);
1026 ref(cBINOP->op_first, op->op_type);
1033 if (op->op_flags & OPf_KIDS)
1034 mod(cLISTOP->op_last, type);
1038 if (!(op->op_flags & OPf_KIDS))
1040 if (op->op_targ != OP_LIST) {
1041 mod(cBINOP->op_first, type);
1046 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1050 op->op_flags |= OPf_MOD;
1052 if (type == OP_AASSIGN || type == OP_SASSIGN)
1053 op->op_flags |= OPf_SPECIAL|OPf_REF;
1055 op->op_private |= OPpLVAL_INTRO;
1056 op->op_flags &= ~OPf_SPECIAL;
1058 else if (type != OP_GREPSTART && type != OP_ENTERSUB)
1059 op->op_flags |= OPf_REF;
1069 if (op && op->op_flags & OPf_KIDS) {
1070 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1083 if (!op || error_count)
1086 switch (op->op_type) {
1088 if ((type == OP_DEFINED) &&
1089 !(op->op_flags & OPf_STACKED)) {
1090 op->op_type = OP_RV2CV; /* entersub => rv2cv */
1091 op->op_ppaddr = ppaddr[OP_RV2CV];
1092 assert(cUNOP->op_first->op_type == OP_NULL);
1093 null(((LISTOP*)cUNOP->op_first)->op_first); /* disable pushmark */
1094 op->op_flags |= OPf_SPECIAL;
1099 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
1103 ref(cUNOP->op_first, op->op_type);
1106 if (type == OP_RV2AV || type == OP_RV2HV) {
1107 op->op_private |= (type == OP_RV2AV ? OPpDEREF_AV : OPpDEREF_HV);
1108 op->op_flags |= OPf_MOD;
1114 op->op_flags |= OPf_REF;
1117 ref(cUNOP->op_first, op->op_type);
1122 op->op_flags |= OPf_REF;
1127 if (!(op->op_flags & OPf_KIDS))
1129 ref(cBINOP->op_first, type);
1133 ref(cBINOP->op_first, op->op_type);
1134 if (type == OP_RV2AV || type == OP_RV2HV) {
1135 op->op_private |= (type == OP_RV2AV ? OPpDEREF_AV : OPpDEREF_HV);
1136 op->op_flags |= OPf_MOD;
1144 if (!(op->op_flags & OPf_KIDS))
1146 ref(cLISTOP->op_last, type);
1162 if (!op || error_count)
1166 if (type == OP_LIST) {
1167 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1170 else if (type != OP_PADSV &&
1173 type != OP_PUSHMARK)
1175 sprintf(tokenbuf, "Can't declare %s in my", op_desc[op->op_type]);
1179 op->op_flags |= OPf_MOD;
1180 op->op_private |= OPpLVAL_INTRO;
1189 o->op_flags |= OPf_PARENS;
1194 bind_match(type, left, right)
1201 if (right->op_type == OP_MATCH ||
1202 right->op_type == OP_SUBST ||
1203 right->op_type == OP_TRANS) {
1204 right->op_flags |= OPf_STACKED;
1205 if (right->op_type != OP_MATCH)
1206 left = mod(left, right->op_type);
1207 if (right->op_type == OP_TRANS)
1208 op = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
1210 op = prepend_elem(right->op_type, scalar(left), right);
1212 return newUNOP(OP_NOT, 0, scalar(op));
1216 return bind_match(type, left,
1217 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
1226 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
1227 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(op));
1235 if (o->op_flags & OPf_PARENS || perldb || tainting) {
1236 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
1237 o->op_type = OP_LEAVE;
1238 o->op_ppaddr = ppaddr[OP_LEAVE];
1241 if (o->op_type == OP_LINESEQ) {
1243 o->op_type = OP_SCOPE;
1244 o->op_ppaddr = ppaddr[OP_SCOPE];
1245 kid = ((LISTOP*)o)->op_first;
1246 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE){
1247 SvREFCNT_dec(((COP*)kid)->cop_filegv);
1252 o = newLISTOP(OP_SCOPE, 0, o, Nullop);
1261 int retval = savestack_ix;
1262 comppad_name_fill = AvFILL(comppad_name);
1263 SAVEINT(min_intro_pending);
1264 SAVEINT(max_intro_pending);
1265 min_intro_pending = 0;
1266 SAVEINT(comppad_name_fill);
1267 SAVEINT(padix_floor);
1268 padix_floor = padix;
1269 pad_reset_pending = FALSE;
1271 hints &= ~HINT_BLOCK_SCOPE;
1276 block_end(line, floor, seq)
1281 int needblockscope = hints & HINT_BLOCK_SCOPE;
1282 OP* retval = scalarseq(seq);
1283 if (copline > (line_t)line)
1286 pad_reset_pending = FALSE;
1288 hints |= HINT_BLOCK_SCOPE; /* propagate out */
1289 pad_leavemy(comppad_name_fill);
1298 eval_root = newUNOP(OP_LEAVEEVAL, 0, op);
1299 eval_start = linklist(eval_root);
1300 eval_root->op_next = 0;
1308 main_root = scope(sawparens(scalarvoid(op)));
1309 curcop = &compiling;
1310 main_start = LINKLIST(main_root);
1311 main_root->op_next = 0;
1323 if (o->op_flags & OPf_PARENS)
1327 if (dowarn && bufptr > oldbufptr && bufptr[-1] == ',') {
1329 for (s = bufptr; *s && (isALNUM(*s) || strchr("@$%, ",*s)); s++) ;
1330 if (*s == ';' || *s == '=')
1331 warn("Parens missing around \"%s\" list", lex ? "my" : "local");
1335 in_my_stash = Nullhv;
1339 return mod(o, OP_NULL); /* a bit kludgey */
1346 if (o->op_type == OP_LIST) {
1347 o = convert(OP_JOIN, 0,
1348 prepend_elem(OP_LIST,
1349 newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
1360 I32 type = o->op_type;
1363 if (opargs[type] & OA_RETSCALAR)
1365 if (opargs[type] & OA_TARGET)
1366 o->op_targ = pad_alloc(type, SVs_PADTMP);
1368 if ((opargs[type] & OA_OTHERINT) && (hints & HINT_INTEGER))
1369 o->op_ppaddr = ppaddr[type = ++(o->op_type)];
1371 if (!(opargs[type] & OA_FOLDCONST))
1375 goto nope; /* Don't try to run w/ errors */
1377 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
1378 if (curop->op_type != OP_CONST &&
1379 curop->op_type != OP_LIST &&
1380 curop->op_type != OP_SCALAR &&
1381 curop->op_type != OP_NULL &&
1382 curop->op_type != OP_PUSHMARK) {
1387 curop = LINKLIST(o);
1392 if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
1393 pad_swipe(o->op_targ);
1394 else if (SvTEMP(sv)) { /* grab mortal temp? */
1395 (void)SvREFCNT_inc(sv);
1399 if (type == OP_RV2GV)
1400 return newGVOP(OP_GV, 0, sv);
1402 if ((SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK)) == SVf_NOK) {
1404 if ((double)iv == SvNV(sv)) { /* can we smush double to int */
1409 return newSVOP(OP_CONST, 0, sv);
1413 if (!(opargs[type] & OA_OTHERINT))
1416 if (!(hints & HINT_INTEGER)) {
1419 if (type == OP_DIVIDE || !(o->op_flags & OPf_KIDS))
1422 for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
1423 if (curop->op_type == OP_CONST) {
1424 if (SvIOK(((SVOP*)curop)->op_sv)) {
1425 if (SvIVX(((SVOP*)curop)->op_sv) <= 0 && vars++)
1426 return o; /* negatives truncate wrong way, alas */
1431 if (opargs[curop->op_type] & OA_RETINTEGER)
1433 if (curop->op_type == OP_PADSV || curop->op_type == OP_RV2SV) {
1436 if (((o->op_type == OP_LT || o->op_type == OP_GE) &&
1437 curop == ((BINOP*)o)->op_first ) ||
1438 ((o->op_type == OP_GT || o->op_type == OP_LE) &&
1439 curop == ((BINOP*)o)->op_last ))
1441 /* Allow "$i < 100" and variants to integerize */
1447 o->op_ppaddr = ppaddr[++(o->op_type)];
1454 gen_constant_list(o)
1458 I32 oldtmps_floor = tmps_floor;
1462 return o; /* Don't attempt to run with errors */
1464 op = curop = LINKLIST(o);
1470 tmps_floor = oldtmps_floor;
1472 o->op_type = OP_RV2AV;
1473 o->op_ppaddr = ppaddr[OP_RV2AV];
1474 curop = ((UNOP*)o)->op_first;
1475 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*stack_sp--));
1482 convert(type, flags, op)
1490 if (!op || op->op_type != OP_LIST)
1491 op = newLISTOP(OP_LIST, 0, op, Nullop);
1493 op->op_flags &= ~(OPf_KNOW|OPf_LIST);
1495 if (!(opargs[type] & OA_MARK))
1496 null(cLISTOP->op_first);
1499 op->op_ppaddr = ppaddr[type];
1500 op->op_flags |= flags;
1502 op = CHECKOP(type, op);
1503 if (op->op_type != type)
1506 if (cLISTOP->op_children < 7) {
1507 /* XXX do we really need to do this if we're done appending?? */
1508 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1510 cLISTOP->op_last = last; /* in case check substituted last arg */
1513 return fold_constants(op);
1516 /* List constructors */
1519 append_elem(type, first, last)
1530 if (first->op_type != type || type==OP_LIST && first->op_flags & OPf_PARENS)
1531 return newLISTOP(type, 0, first, last);
1533 if (first->op_flags & OPf_KIDS)
1534 ((LISTOP*)first)->op_last->op_sibling = last;
1536 first->op_flags |= OPf_KIDS;
1537 ((LISTOP*)first)->op_first = last;
1539 ((LISTOP*)first)->op_last = last;
1540 ((LISTOP*)first)->op_children++;
1545 append_list(type, first, last)
1556 if (first->op_type != type)
1557 return prepend_elem(type, (OP*)first, (OP*)last);
1559 if (last->op_type != type)
1560 return append_elem(type, (OP*)first, (OP*)last);
1562 first->op_last->op_sibling = last->op_first;
1563 first->op_last = last->op_last;
1564 first->op_children += last->op_children;
1565 if (first->op_children)
1566 last->op_flags |= OPf_KIDS;
1573 prepend_elem(type, first, last)
1584 if (last->op_type == type) {
1585 if (type == OP_LIST) { /* already a PUSHMARK there */
1586 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
1587 ((LISTOP*)last)->op_first->op_sibling = first;
1590 if (!(last->op_flags & OPf_KIDS)) {
1591 ((LISTOP*)last)->op_last = first;
1592 last->op_flags |= OPf_KIDS;
1594 first->op_sibling = ((LISTOP*)last)->op_first;
1595 ((LISTOP*)last)->op_first = first;
1597 ((LISTOP*)last)->op_children++;
1601 return newLISTOP(type, 0, first, last);
1609 return newOP(OP_STUB, 0);
1616 if (!op || op->op_type != OP_LIST)
1617 op = newLISTOP(OP_LIST, 0, op, Nullop);
1623 newLISTOP(type, flags, first, last)
1631 Newz(1101, listop, 1, LISTOP);
1633 listop->op_type = type;
1634 listop->op_ppaddr = ppaddr[type];
1635 listop->op_children = (first != 0) + (last != 0);
1636 listop->op_flags = flags;
1640 else if (!first && last)
1643 first->op_sibling = last;
1644 listop->op_first = first;
1645 listop->op_last = last;
1646 if (type == OP_LIST) {
1648 pushop = newOP(OP_PUSHMARK, 0);
1649 pushop->op_sibling = first;
1650 listop->op_first = pushop;
1651 listop->op_flags |= OPf_KIDS;
1653 listop->op_last = pushop;
1655 else if (listop->op_children)
1656 listop->op_flags |= OPf_KIDS;
1667 Newz(1101, op, 1, OP);
1669 op->op_ppaddr = ppaddr[type];
1670 op->op_flags = flags;
1673 op->op_private = 0 + (flags >> 8);
1674 if (opargs[type] & OA_RETSCALAR)
1676 if (opargs[type] & OA_TARGET)
1677 op->op_targ = pad_alloc(type, SVs_PADTMP);
1678 return CHECKOP(type, op);
1682 newUNOP(type, flags, first)
1690 first = newOP(OP_STUB, 0);
1691 if (opargs[type] & OA_MARK)
1692 first = force_list(first);
1694 Newz(1101, unop, 1, UNOP);
1695 unop->op_type = type;
1696 unop->op_ppaddr = ppaddr[type];
1697 unop->op_first = first;
1698 unop->op_flags = flags | OPf_KIDS;
1699 unop->op_private = 1 | (flags >> 8);
1701 unop = (UNOP*) CHECKOP(type, unop);
1705 return fold_constants((OP *) unop);
1709 newBINOP(type, flags, first, last)
1716 Newz(1101, binop, 1, BINOP);
1719 first = newOP(OP_NULL, 0);
1721 binop->op_type = type;
1722 binop->op_ppaddr = ppaddr[type];
1723 binop->op_first = first;
1724 binop->op_flags = flags | OPf_KIDS;
1727 binop->op_private = 1 | (flags >> 8);
1730 binop->op_private = 2 | (flags >> 8);
1731 first->op_sibling = last;
1734 binop = (BINOP*)CHECKOP(type, binop);
1738 binop->op_last = last = binop->op_first->op_sibling;
1740 return fold_constants((OP *)binop);
1744 pmtrans(op, expr, repl)
1749 SV *tstr = ((SVOP*)expr)->op_sv;
1750 SV *rstr = ((SVOP*)repl)->op_sv;
1753 register U8 *t = (U8*)SvPV(tstr, tlen);
1754 register U8 *r = (U8*)SvPV(rstr, rlen);
1759 register short *tbl;
1761 tbl = (short*)cPVOP->op_pv;
1762 complement = op->op_private & OPpTRANS_COMPLEMENT;
1763 delete = op->op_private & OPpTRANS_DELETE;
1764 /* squash = op->op_private & OPpTRANS_SQUASH; */
1767 Zero(tbl, 256, short);
1768 for (i = 0; i < tlen; i++)
1770 for (i = 0, j = 0; i < 256; i++) {
1786 if (!rlen && !delete) {
1789 for (i = 0; i < 256; i++)
1791 for (i = 0, j = 0; i < tlen; i++,j++) {
1794 if (tbl[t[i]] == -1)
1800 if (tbl[t[i]] == -1)
1811 newPMOP(type, flags)
1817 Newz(1101, pmop, 1, PMOP);
1818 pmop->op_type = type;
1819 pmop->op_ppaddr = ppaddr[type];
1820 pmop->op_flags = flags;
1821 pmop->op_private = 0 | (flags >> 8);
1823 /* link into pm list */
1824 if (type != OP_TRANS && curstash) {
1825 pmop->op_pmnext = HvPMROOT(curstash);
1826 HvPMROOT(curstash) = pmop;
1833 pmruntime(op, expr, repl)
1841 if (op->op_type == OP_TRANS)
1842 return pmtrans(op, expr, repl);
1846 if (expr->op_type == OP_CONST) {
1848 SV *pat = ((SVOP*)expr)->op_sv;
1849 char *p = SvPV(pat, plen);
1850 if ((op->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
1851 sv_setpvn(pat, "\\s+", 3);
1852 p = SvPV(pat, plen);
1853 pm->op_pmflags |= PMf_SKIPWHITE;
1855 pm->op_pmregexp = pregcomp(p, p + plen, pm);
1856 if (strEQ("\\s+", pm->op_pmregexp->precomp))
1857 pm->op_pmflags |= PMf_WHITE;
1862 if (pm->op_pmflags & PMf_KEEP)
1863 expr = newUNOP(OP_REGCMAYBE,0,expr);
1865 Newz(1101, rcop, 1, LOGOP);
1866 rcop->op_type = OP_REGCOMP;
1867 rcop->op_ppaddr = ppaddr[OP_REGCOMP];
1868 rcop->op_first = scalar(expr);
1869 rcop->op_flags |= OPf_KIDS;
1870 rcop->op_private = 1;
1871 rcop->op_other = op;
1873 /* establish postfix order */
1874 if (pm->op_pmflags & PMf_KEEP) {
1876 rcop->op_next = expr;
1877 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
1880 rcop->op_next = LINKLIST(expr);
1881 expr->op_next = (OP*)rcop;
1884 prepend_elem(op->op_type, scalar((OP*)rcop), op);
1889 if (pm->op_pmflags & PMf_EVAL)
1891 else if (repl->op_type == OP_CONST)
1895 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
1896 if (opargs[curop->op_type] & OA_DANGEROUS) {
1897 if (curop->op_type == OP_GV) {
1898 GV *gv = ((GVOP*)curop)->op_gv;
1899 if (strchr("&`'123456789+", *GvENAME(gv)))
1902 else if (curop->op_type == OP_RV2CV)
1904 else if (curop->op_type == OP_RV2SV ||
1905 curop->op_type == OP_RV2AV ||
1906 curop->op_type == OP_RV2HV ||
1907 curop->op_type == OP_RV2GV) {
1908 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
1911 else if (curop->op_type == OP_PADSV ||
1912 curop->op_type == OP_PADAV ||
1913 curop->op_type == OP_PADHV ||
1914 curop->op_type == OP_PADANY) {
1923 if (curop == repl) {
1924 pm->op_pmflags |= PMf_CONST; /* const for long enough */
1925 pm->op_pmpermflags |= PMf_CONST; /* const for long enough */
1926 prepend_elem(op->op_type, scalar(repl), op);
1929 Newz(1101, rcop, 1, LOGOP);
1930 rcop->op_type = OP_SUBSTCONT;
1931 rcop->op_ppaddr = ppaddr[OP_SUBSTCONT];
1932 rcop->op_first = scalar(repl);
1933 rcop->op_flags |= OPf_KIDS;
1934 rcop->op_private = 1;
1935 rcop->op_other = op;
1937 /* establish postfix order */
1938 rcop->op_next = LINKLIST(repl);
1939 repl->op_next = (OP*)rcop;
1941 pm->op_pmreplroot = scalar((OP*)rcop);
1942 pm->op_pmreplstart = LINKLIST(rcop);
1951 newSVOP(type, flags, sv)
1957 Newz(1101, svop, 1, SVOP);
1958 svop->op_type = type;
1959 svop->op_ppaddr = ppaddr[type];
1961 svop->op_next = (OP*)svop;
1962 svop->op_flags = flags;
1963 if (opargs[type] & OA_RETSCALAR)
1965 if (opargs[type] & OA_TARGET)
1966 svop->op_targ = pad_alloc(type, SVs_PADTMP);
1967 return CHECKOP(type, svop);
1971 newGVOP(type, flags, gv)
1977 Newz(1101, gvop, 1, GVOP);
1978 gvop->op_type = type;
1979 gvop->op_ppaddr = ppaddr[type];
1980 gvop->op_gv = (GV*)SvREFCNT_inc(gv);
1981 gvop->op_next = (OP*)gvop;
1982 gvop->op_flags = flags;
1983 if (opargs[type] & OA_RETSCALAR)
1985 if (opargs[type] & OA_TARGET)
1986 gvop->op_targ = pad_alloc(type, SVs_PADTMP);
1987 return CHECKOP(type, gvop);
1991 newPVOP(type, flags, pv)
1997 Newz(1101, pvop, 1, PVOP);
1998 pvop->op_type = type;
1999 pvop->op_ppaddr = ppaddr[type];
2001 pvop->op_next = (OP*)pvop;
2002 pvop->op_flags = flags;
2003 if (opargs[type] & OA_RETSCALAR)
2005 if (opargs[type] & OA_TARGET)
2006 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
2007 return CHECKOP(type, pvop);
2016 save_hptr(&curstash);
2017 save_item(curstname);
2022 name = SvPV(sv, len);
2023 curstash = gv_stashpv(name,TRUE);
2024 sv_setpvn(curstname, name, len);
2028 sv_setpv(curstname,"<none>");
2036 utilize(aver, floor, id, arg)
2047 if (id->op_type != OP_CONST)
2048 croak("Module name must be constant");
2050 /* Fake up an import/unimport */
2051 if (arg && arg->op_type == OP_STUB)
2052 imop = arg; /* no import on explicit () */
2054 /* Make copy of id so we don't free it twice */
2055 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2057 meth = newSVOP(OP_CONST, 0,
2059 ? newSVpv("import", 6)
2060 : newSVpv("unimport", 8)
2062 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2063 append_elem(OP_LIST,
2064 prepend_elem(OP_LIST, pack, list(arg)),
2065 newUNOP(OP_METHOD, 0, meth)));
2068 /* Fake up a require */
2069 rqop = newUNOP(OP_REQUIRE, 0, id);
2071 /* Fake up the BEGIN {}, which does its thing immediately. */
2073 newSVOP(OP_CONST, 0, newSVpv("BEGIN", 5)),
2075 append_elem(OP_LINESEQ,
2076 newSTATEOP(0, Nullch, rqop),
2077 newSTATEOP(0, Nullch, imop) ));
2084 newSLICEOP(flags, subscript, listval)
2089 return newBINOP(OP_LSLICE, flags,
2090 list(force_list(subscript)),
2091 list(force_list(listval)) );
2101 if (op->op_type == OP_NULL && op->op_flags & OPf_KIDS)
2102 op = cUNOP->op_first;
2104 if (op->op_type == OP_COND_EXPR) {
2105 I32 t = list_assignment(cCONDOP->op_first->op_sibling);
2106 I32 f = list_assignment(cCONDOP->op_first->op_sibling->op_sibling);
2111 yyerror("Assignment to both a list and a scalar");
2115 if (op->op_type == OP_LIST || op->op_flags & OPf_PARENS ||
2116 op->op_type == OP_RV2AV || op->op_type == OP_RV2HV ||
2117 op->op_type == OP_ASLICE || op->op_type == OP_HSLICE)
2120 if (op->op_type == OP_PADAV || op->op_type == OP_PADHV)
2123 if (op->op_type == OP_RV2SV)
2130 newASSIGNOP(flags, left, optype, right)
2139 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN) {
2140 return newLOGOP(optype, 0,
2141 mod(scalar(left), optype),
2142 newUNOP(OP_SASSIGN, 0, scalar(right)));
2145 return newBINOP(optype, OPf_STACKED,
2146 mod(scalar(left), optype), scalar(right));
2150 if (list_assignment(left)) {
2152 eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2153 left = mod(left, OP_AASSIGN);
2161 op = newBINOP(OP_AASSIGN, flags,
2162 list(force_list(right)),
2163 list(force_list(left)) );
2164 op->op_private = 0 | (flags >> 8);
2165 if (!(left->op_private & OPpLVAL_INTRO)) {
2166 static int generation = 100;
2170 for (curop = LINKLIST(op); curop != op; curop = LINKLIST(curop)) {
2171 if (opargs[curop->op_type] & OA_DANGEROUS) {
2172 if (curop->op_type == OP_GV) {
2173 GV *gv = ((GVOP*)curop)->op_gv;
2174 if (gv == defgv || SvCUR(gv) == generation)
2176 SvCUR(gv) = generation;
2178 else if (curop->op_type == OP_PADSV ||
2179 curop->op_type == OP_PADAV ||
2180 curop->op_type == OP_PADHV ||
2181 curop->op_type == OP_PADANY) {
2182 SV **svp = AvARRAY(comppad_name);
2183 SV *sv = svp[curop->op_targ];
2184 if (SvCUR(sv) == generation)
2186 SvCUR(sv) = generation; /* (SvCUR not used any more) */
2188 else if (curop->op_type == OP_RV2CV)
2190 else if (curop->op_type == OP_RV2SV ||
2191 curop->op_type == OP_RV2AV ||
2192 curop->op_type == OP_RV2HV ||
2193 curop->op_type == OP_RV2GV) {
2194 if (lastop->op_type != OP_GV) /* funny deref? */
2203 op->op_private = OPpASSIGN_COMMON;
2205 if (right && right->op_type == OP_SPLIT) {
2207 if ((tmpop = ((LISTOP*)right)->op_first) &&
2208 tmpop->op_type == OP_PUSHRE)
2210 PMOP *pm = (PMOP*)tmpop;
2211 if (left->op_type == OP_RV2AV &&
2212 !(left->op_private & OPpLVAL_INTRO) &&
2213 !(op->op_private & OPpASSIGN_COMMON) )
2215 tmpop = ((UNOP*)left)->op_first;
2216 if (tmpop->op_type == OP_GV && !pm->op_pmreplroot) {
2217 pm->op_pmreplroot = (OP*)((GVOP*)tmpop)->op_gv;
2218 pm->op_pmflags |= PMf_ONCE;
2219 tmpop = ((UNOP*)op)->op_first; /* to list (nulled) */
2220 tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */
2221 tmpop->op_sibling = Nullop; /* don't free split */
2222 right->op_next = tmpop->op_next; /* fix starting loc */
2223 op_free(op); /* blow off assign */
2224 right->op_flags &= ~(OPf_KNOW|OPf_LIST);
2225 /* "I don't know and I don't care." */
2230 if (modcount < 10000 &&
2231 ((LISTOP*)right)->op_last->op_type == OP_CONST)
2233 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
2235 sv_setiv(sv, modcount+1);
2243 right = newOP(OP_UNDEF, 0);
2244 if (right->op_type == OP_READLINE) {
2245 right->op_flags |= OPf_STACKED;
2246 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
2249 eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2250 op = newBINOP(OP_SASSIGN, flags,
2251 scalar(right), mod(scalar(left), OP_SASSIGN) );
2263 newSTATEOP(flags, label, op)
2270 /* Introduce my variables. */
2271 if (min_intro_pending) {
2272 SV **svp = AvARRAY(comppad_name);
2275 for (i = min_intro_pending; i <= max_intro_pending; i++) {
2276 if ((sv = svp[i]) && sv != &sv_undef && !SvIVX(sv)) {
2277 SvIVX(sv) = 999999999; /* Don't know scope end yet. */
2278 SvNVX(sv) = (double)cop_seqmax;
2281 min_intro_pending = 0;
2282 comppad_name_fill = max_intro_pending; /* Needn't search higher */
2285 Newz(1101, cop, 1, COP);
2286 if (perldb && curcop->cop_line && curstash != debstash) {
2287 cop->op_type = OP_DBSTATE;
2288 cop->op_ppaddr = ppaddr[ OP_DBSTATE ];
2291 cop->op_type = OP_NEXTSTATE;
2292 cop->op_ppaddr = ppaddr[ OP_NEXTSTATE ];
2294 cop->op_flags = flags;
2295 cop->op_private = 0 | (flags >> 8);
2296 cop->op_next = (OP*)cop;
2299 cop->cop_label = label;
2300 hints |= HINT_BLOCK_SCOPE;
2302 cop->cop_seq = cop_seqmax++;
2303 cop->cop_arybase = curcop->cop_arybase;
2305 if (copline == NOLINE)
2306 cop->cop_line = curcop->cop_line;
2308 cop->cop_line = copline;
2311 cop->cop_filegv = SvREFCNT_inc(curcop->cop_filegv);
2312 cop->cop_stash = curstash;
2314 if (perldb && curstash != debstash) {
2315 SV **svp = av_fetch(GvAV(curcop->cop_filegv),(I32)cop->cop_line, FALSE);
2316 if (svp && *svp != &sv_undef && !SvIOK(*svp)) {
2317 (void)SvIOK_on(*svp);
2319 SvSTASH(*svp) = (HV*)cop;
2323 return prepend_elem(OP_LINESEQ, (OP*)cop, op);
2327 newLOGOP(type, flags, first, other)
2336 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
2337 return newBINOP(type, flags, scalar(first), scalar(other));
2339 scalarboolean(first);
2340 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
2341 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
2342 if (type == OP_AND || type == OP_OR) {
2348 first = cUNOP->op_first;
2350 first->op_next = op->op_next;
2351 cUNOP->op_first = Nullop;
2355 if (first->op_type == OP_CONST) {
2356 if (dowarn && (first->op_private & OPpCONST_BARE))
2357 warn("Probable precedence problem on %s", op_desc[type]);
2358 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
2367 else if (first->op_type == OP_WANTARRAY) {
2377 if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
2378 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
2380 Newz(1101, logop, 1, LOGOP);
2382 logop->op_type = type;
2383 logop->op_ppaddr = ppaddr[type];
2384 logop->op_first = first;
2385 logop->op_flags = flags | OPf_KIDS;
2386 logop->op_other = LINKLIST(other);
2387 logop->op_private = 1 | (flags >> 8);
2389 /* establish postfix order */
2390 logop->op_next = LINKLIST(first);
2391 first->op_next = (OP*)logop;
2392 first->op_sibling = other;
2394 op = newUNOP(OP_NULL, 0, (OP*)logop);
2395 other->op_next = op;
2401 newCONDOP(flags, first, true, false)
2411 return newLOGOP(OP_AND, 0, first, true);
2413 return newLOGOP(OP_OR, 0, first, false);
2415 scalarboolean(first);
2416 if (first->op_type == OP_CONST) {
2417 if (SvTRUE(((SVOP*)first)->op_sv)) {
2428 else if (first->op_type == OP_WANTARRAY) {
2432 Newz(1101, condop, 1, CONDOP);
2434 condop->op_type = OP_COND_EXPR;
2435 condop->op_ppaddr = ppaddr[OP_COND_EXPR];
2436 condop->op_first = first;
2437 condop->op_flags = flags | OPf_KIDS;
2438 condop->op_true = LINKLIST(true);
2439 condop->op_false = LINKLIST(false);
2440 condop->op_private = 1 | (flags >> 8);
2442 /* establish postfix order */
2443 condop->op_next = LINKLIST(first);
2444 first->op_next = (OP*)condop;
2446 first->op_sibling = true;
2447 true->op_sibling = false;
2448 op = newUNOP(OP_NULL, 0, (OP*)condop);
2451 false->op_next = op;
2457 newRANGE(flags, left, right)
2467 Newz(1101, condop, 1, CONDOP);
2469 condop->op_type = OP_RANGE;
2470 condop->op_ppaddr = ppaddr[OP_RANGE];
2471 condop->op_first = left;
2472 condop->op_flags = OPf_KIDS;
2473 condop->op_true = LINKLIST(left);
2474 condop->op_false = LINKLIST(right);
2475 condop->op_private = 1 | (flags >> 8);
2477 left->op_sibling = right;
2479 condop->op_next = (OP*)condop;
2480 flip = newUNOP(OP_FLIP, flags, (OP*)condop);
2481 flop = newUNOP(OP_FLOP, 0, flip);
2482 op = newUNOP(OP_NULL, 0, flop);
2485 left->op_next = flip;
2486 right->op_next = flop;
2488 condop->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2489 sv_upgrade(PAD_SV(condop->op_targ), SVt_PVNV);
2490 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2491 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
2493 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2494 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2497 if (!flip->op_private || !flop->op_private)
2498 linklist(op); /* blow off optimizer unless constant */
2504 newLOOPOP(flags, debuggable, expr, block)
2512 int once = block && block->op_flags & OPf_SPECIAL &&
2513 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
2516 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
2517 return block; /* do {} while 0 does once */
2518 else if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB)
2519 expr = newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr);
2522 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
2523 op = newLOGOP(OP_AND, 0, expr, listop);
2525 ((LISTOP*)listop)->op_last->op_next = LINKLIST(op);
2527 if (once && op != listop)
2528 op->op_next = ((LOGOP*)cUNOP->op_first)->op_other;
2531 op = newUNOP(OP_NULL, 0, op); /* or do {} while 1 loses outer block */
2533 op->op_flags |= flags;
2535 op->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/
2540 newWHILEOP(flags, debuggable, loop, expr, block, cont)
2554 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB)) {
2555 expr = newUNOP(OP_DEFINED, 0,
2556 newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr) );
2560 block = newOP(OP_NULL, 0);
2563 next = LINKLIST(cont);
2565 cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
2567 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
2568 redo = LINKLIST(listop);
2571 op = newLOGOP(OP_AND, 0, expr, scalar(listop));
2572 if (op == expr && op->op_type == OP_CONST && !SvTRUE(cSVOP->op_sv)) {
2573 op_free(expr); /* oops, it's a while (0) */
2575 return Nullop; /* (listop already freed by newLOGOP) */
2577 ((LISTOP*)listop)->op_last->op_next = condop =
2578 (op == listop ? redo : LINKLIST(op));
2586 Newz(1101,loop,1,LOOP);
2587 loop->op_type = OP_ENTERLOOP;
2588 loop->op_ppaddr = ppaddr[OP_ENTERLOOP];
2589 loop->op_private = 0;
2590 loop->op_next = (OP*)loop;
2593 op = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, op);
2595 loop->op_redoop = redo;
2596 loop->op_lastop = op;
2599 loop->op_nextop = next;
2601 loop->op_nextop = op;
2603 op->op_flags |= flags;
2604 op->op_private |= (flags >> 8);
2609 #ifndef CAN_PROTOTYPE
2610 newFOROP(flags,label,forline,sv,expr,block,cont)
2619 newFOROP(I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
2620 #endif /* CAN_PROTOTYPE */
2628 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
2629 sv->op_type = OP_RV2GV;
2630 sv->op_ppaddr = ppaddr[OP_RV2GV];
2632 else if (sv->op_type == OP_PADSV) { /* private variable */
2633 padoff = sv->op_targ;
2638 croak("Can't use %s for loop variable", op_desc[sv->op_type]);
2641 sv = newGVOP(OP_GV, 0, defgv);
2643 if (expr->op_type == OP_RV2AV) {
2644 expr = scalar(ref(expr, OP_ITER));
2645 iterflags |= OPf_STACKED;
2647 loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
2648 append_elem(OP_LIST, mod(force_list(expr), OP_GREPSTART),
2650 assert(!loop->op_next);
2651 Renew(loop, 1, LOOP);
2652 loop->op_targ = padoff;
2653 return newSTATEOP(0, label, newWHILEOP(flags, 1, loop,
2654 newOP(OP_ITER, 0), block, cont));
2658 newLOOPEX(type, label)
2663 if (type != OP_GOTO || label->op_type == OP_CONST) {
2664 op = newPVOP(type, 0, savepv(
2665 label->op_type == OP_CONST
2666 ? SvPVx(((SVOP*)label)->op_sv, na)
2671 if (label->op_type == OP_ENTERSUB)
2672 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
2673 op = newUNOP(type, OPf_STACKED, label);
2675 hints |= HINT_BLOCK_SCOPE;
2683 if (!CvXSUB(cv) && CvROOT(cv)) {
2685 croak("Can't undef active subroutine");
2692 op_free(CvROOT(cv));
2693 CvROOT(cv) = Nullop;
2696 SvREFCNT_dec(CvGV(cv));
2698 SvREFCNT_dec(CvOUTSIDE(cv));
2699 CvOUTSIDE(cv) = Nullcv;
2700 if (CvPADLIST(cv)) {
2701 I32 i = AvFILL(CvPADLIST(cv));
2703 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
2707 SvREFCNT_dec((SV*)CvPADLIST(cv));
2708 CvPADLIST(cv) = Nullav;
2718 AV* protopadlist = CvPADLIST(proto);
2719 AV* protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
2720 AV* protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
2721 SV** svp = AvARRAY(protopad);
2730 cv = compcv = (CV*)NEWSV(1104,0);
2731 sv_upgrade((SV *)cv, SVt_PVCV);
2734 CvFILEGV(cv) = CvFILEGV(proto);
2735 CvGV(cv) = SvREFCNT_inc(CvGV(proto));
2736 CvSTASH(cv) = CvSTASH(proto);
2737 CvROOT(cv) = CvROOT(proto);
2738 CvSTART(cv) = CvSTART(proto);
2739 if (CvOUTSIDE(proto))
2740 CvOUTSIDE(cv) = (CV*)SvREFCNT_inc((SV*)CvOUTSIDE(proto));
2744 comppadlist = newAV();
2745 AvREAL_off(comppadlist);
2746 av_store(comppadlist, 0, SvREFCNT_inc((SV*)protopad_name));
2747 av_store(comppadlist, 1, (SV*)comppad);
2748 CvPADLIST(cv) = comppadlist;
2749 av_extend(comppad, AvFILL(protopad));
2750 curpad = AvARRAY(comppad);
2752 av = newAV(); /* will be @_ */
2754 av_store(comppad, 0, (SV*)av);
2755 AvFLAGS(av) = AVf_REIFY;
2757 svp = AvARRAY(protopad_name);
2758 for ( ix = AvFILL(protopad); ix > 0; ix--) {
2760 if (svp[ix] != &sv_undef) {
2761 char *name = SvPVX(svp[ix]); /* XXX */
2762 if (SvFLAGS(svp[ix]) & SVf_FAKE) { /* lexical from outside? */
2763 I32 off = pad_findlex(name,ix,curcop->cop_seq, CvOUTSIDE(proto),
2766 croak("panic: cv_clone: %s", name);
2768 else { /* our own lexical */
2770 av_store(comppad, ix, sv = (SV*)newAV());
2771 else if (*name == '%')
2772 av_store(comppad, ix, sv = (SV*)newHV());
2774 av_store(comppad, ix, sv = NEWSV(0,0));
2779 av_store(comppad, ix, sv = NEWSV(0,0));
2789 newSUB(floor,op,proto,block)
2796 char *name = op ? SvPVx(cSVOP->op_sv, na) : "__ANON__";
2797 GV* gv = gv_fetchpv(name, GV_ADDMULTI, SVt_PVCV);
2804 if (cv = GvCV(gv)) {
2806 cv = 0; /* just a cached method */
2807 else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
2808 if (dowarn) { /* already defined (or promised)? */
2809 line_t oldline = curcop->cop_line;
2811 curcop->cop_line = copline;
2812 warn("Subroutine %s redefined",name);
2813 curcop->cop_line = oldline;
2819 if (cv) { /* must reuse cv if autoloaded */
2821 CvOUTSIDE(cv) = CvOUTSIDE(compcv);
2822 CvOUTSIDE(compcv) = 0;
2823 CvPADLIST(cv) = CvPADLIST(compcv);
2824 CvPADLIST(compcv) = 0;
2825 if (SvREFCNT(compcv) > 1) /* XXX Make closures transit through stub. */
2826 CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc((SV*)cv);
2827 SvREFCNT_dec(compcv);
2834 CvFILEGV(cv) = curcop->cop_filegv;
2835 CvGV(cv) = SvREFCNT_inc(gv);
2836 CvSTASH(cv) = curstash;
2839 char *p = SvPVx(((SVOP*)proto)->op_sv, na);
2840 if (SvPOK(cv) && strNE(SvPV((SV*)cv,na), p))
2841 warn("Prototype mismatch: (%s) vs (%s)", SvPV((SV*)cv, na), p);
2842 sv_setpv((SV*)cv, p);
2858 av = newAV(); /* Will be @_ */
2860 av_store(comppad, 0, (SV*)av);
2861 AvFLAGS(av) = AVf_REIFY;
2863 for (ix = AvFILL(comppad); ix > 0; ix--) {
2864 if (!SvPADMY(curpad[ix]))
2865 SvPADTMP_on(curpad[ix]);
2868 if (AvFILL(comppad_name) < AvFILL(comppad))
2869 av_store(comppad_name, AvFILL(comppad), Nullsv);
2871 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
2872 CvSTART(cv) = LINKLIST(CvROOT(cv));
2873 CvROOT(cv)->op_next = 0;
2875 if (s = strrchr(name,':'))
2879 if (strEQ(s, "BEGIN") && !error_count) {
2880 line_t oldline = compiling.cop_line;
2884 SAVESPTR(compiling.cop_filegv);
2888 av_push(beginav, (SV *)cv);
2889 DEBUG_x( dump_sub(gv) );
2890 rs = SvREFCNT_inc(nrs);
2895 curcop = &compiling;
2896 curcop->cop_line = oldline; /* might have recursed to yylex */
2899 else if (strEQ(s, "END") && !error_count) {
2902 av_unshift(endav, 1);
2903 av_store(endav, 0, SvREFCNT_inc(cv));
2905 else if (strEQ(s, "RESTART") && !error_count) {
2907 restartav = newAV();
2908 av_push(restartav, SvREFCNT_inc(cv));
2910 if (perldb && curstash != debstash) {
2912 SV *tmpstr = sv_newmortal();
2914 sprintf(buf,"%s:%ld",SvPVX(GvSV(curcop->cop_filegv)), (long)subline);
2915 sv = newSVpv(buf,0);
2917 sprintf(buf,"%ld",(long)curcop->cop_line);
2919 gv_efullname(tmpstr,gv);
2920 hv_store(GvHV(DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
2926 GvCV(gv) = 0; /* Will remember in SVOP instead. */
2934 newXSUB(name, ix, subaddr, filename)
2940 CV* cv = newXS(name, (void(*)())subaddr, filename);
2942 CvXSUBANY(cv).any_i32 = ix;
2948 newXS(name, subaddr, filename)
2950 void (*subaddr) _((CV*));
2954 GV *gv = gv_fetchpv((name ? name : "__ANON__"), GV_ADDMULTI, SVt_PVCV);
2959 if (cv = GvCV(gv)) {
2961 cv = 0; /* just a cached method */
2962 else if (CvROOT(cv) || CvXSUB(cv)) { /* already defined? */
2964 line_t oldline = curcop->cop_line;
2966 curcop->cop_line = copline;
2967 warn("Subroutine %s redefined",name);
2968 curcop->cop_line = oldline;
2974 if (cv) { /* must reuse cv if autoloaded */
2975 assert(SvREFCNT(CvGV(cv)) > 1);
2976 SvREFCNT_dec(CvGV(cv));
2979 cv = (CV*)NEWSV(1105,0);
2980 sv_upgrade((SV *)cv, SVt_PVCV);
2983 CvGV(cv) = SvREFCNT_inc(gv);
2985 CvFILEGV(cv) = gv_fetchfile(filename);
2986 CvXSUB(cv) = subaddr;
2989 else if (s = strrchr(name,':'))
2993 if (strEQ(s, "BEGIN")) {
2996 av_push(beginav, SvREFCNT_inc(gv));
2998 else if (strEQ(s, "END")) {
3001 av_unshift(endav, 1);
3002 av_store(endav, 0, SvREFCNT_inc(gv));
3004 else if (strEQ(s, "RESTART")) {
3006 restartav = newAV();
3007 av_push(restartav, SvREFCNT_inc(gv));
3010 GvCV(gv) = 0; /* Will remember elsewhere instead. */
3017 newFORM(floor,op,block)
3028 name = SvPVx(cSVOP->op_sv, na);
3031 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
3033 if (cv = GvFORM(gv)) {
3035 line_t oldline = curcop->cop_line;
3037 curcop->cop_line = copline;
3038 warn("Format %s redefined",name);
3039 curcop->cop_line = oldline;
3045 CvGV(cv) = SvREFCNT_inc(gv);
3046 CvFILEGV(cv) = curcop->cop_filegv;
3048 for (ix = AvFILL(comppad); ix > 0; ix--) {
3049 if (!SvPADMY(curpad[ix]))
3050 SvPADTMP_on(curpad[ix]);
3053 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
3054 CvSTART(cv) = LINKLIST(CvROOT(cv));
3055 CvROOT(cv)->op_next = 0;
3067 return newUNOP(OP_REFGEN, 0,
3068 mod(list(convert(OP_ANONLIST, 0, op)), OP_REFGEN));
3075 return newUNOP(OP_REFGEN, 0,
3076 mod(list(convert(OP_ANONHASH, 0, op)), OP_REFGEN));
3080 newANONSUB(floor, proto, block)
3085 return newUNOP(OP_REFGEN, 0,
3086 newSVOP(OP_ANONCODE, 0, (SV*)newSUB(floor, 0, proto, block)));
3093 switch (o->op_type) {
3095 o->op_type = OP_PADAV;
3096 o->op_ppaddr = ppaddr[OP_PADAV];
3097 return ref(newUNOP(OP_RV2AV, 0, scalar(o)), OP_RV2AV);
3100 o->op_type = OP_RV2AV;
3101 o->op_ppaddr = ppaddr[OP_RV2AV];
3106 warn("oops: oopsAV");
3116 switch (o->op_type) {
3119 o->op_type = OP_PADHV;
3120 o->op_ppaddr = ppaddr[OP_PADHV];
3121 return ref(newUNOP(OP_RV2HV, 0, scalar(o)), OP_RV2HV);
3125 o->op_type = OP_RV2HV;
3126 o->op_ppaddr = ppaddr[OP_RV2HV];
3131 warn("oops: oopsHV");
3141 if (o->op_type == OP_PADANY) {
3142 o->op_type = OP_PADAV;
3143 o->op_ppaddr = ppaddr[OP_PADAV];
3146 return newUNOP(OP_RV2AV, 0, scalar(o));
3154 if (type == OP_MAPSTART)
3155 return newUNOP(OP_NULL, 0, o);
3156 return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
3163 if (o->op_type == OP_PADANY) {
3164 o->op_type = OP_PADHV;
3165 o->op_ppaddr = ppaddr[OP_PADHV];
3168 return newUNOP(OP_RV2HV, 0, scalar(o));
3175 croak("NOT IMPL LINE %d",__LINE__);
3185 return newUNOP(OP_RV2CV, flags, scalar(o));
3192 if (o->op_type == OP_PADANY) {
3193 o->op_type = OP_PADSV;
3194 o->op_ppaddr = ppaddr[OP_PADSV];
3197 return newUNOP(OP_RV2SV, 0, scalar(o));
3200 /* Check routines. */
3206 if (cUNOP->op_first->op_type == OP_CONCAT)
3207 op->op_flags |= OPf_STACKED;
3215 if (op->op_flags & OPf_KIDS) {
3218 op = modkids(ck_fun(op), op->op_type);
3219 kid = cUNOP->op_first;
3220 newop = kUNOP->op_first->op_sibling;
3222 (newop->op_sibling ||
3223 !(opargs[newop->op_type] & OA_RETSCALAR) ||
3224 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
3225 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
3229 op_free(kUNOP->op_first);
3230 kUNOP->op_first = newop;
3232 op->op_ppaddr = ppaddr[++op->op_type];
3241 if (op->op_flags & OPf_KIDS) {
3242 OP *kid = cUNOP->op_first;
3243 if (kid->op_type != OP_HELEM)
3244 croak("%s argument is not a HASH element", op_desc[op->op_type]);
3254 I32 type = op->op_type;
3256 if (op->op_flags & OPf_KIDS) {
3257 if (cLISTOP->op_first->op_type == OP_STUB) {
3259 op = newUNOP(type, OPf_SPECIAL,
3260 newGVOP(OP_GV, 0, gv_fetchpv("main'ARGV", TRUE, SVt_PVAV)));
3271 hints |= HINT_BLOCK_SCOPE;
3272 if (op->op_flags & OPf_KIDS) {
3273 SVOP *kid = (SVOP*)cUNOP->op_first;
3276 op->op_flags &= ~OPf_KIDS;
3279 else if (kid->op_type == OP_LINESEQ) {
3282 kid->op_next = op->op_next;
3283 cUNOP->op_first = 0;
3286 Newz(1101, enter, 1, LOGOP);
3287 enter->op_type = OP_ENTERTRY;
3288 enter->op_ppaddr = ppaddr[OP_ENTERTRY];
3289 enter->op_private = 0;
3291 /* establish postfix order */
3292 enter->op_next = (OP*)enter;
3294 op = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
3295 op->op_type = OP_LEAVETRY;
3296 op->op_ppaddr = ppaddr[OP_LEAVETRY];
3297 enter->op_other = op;
3303 op = newUNOP(OP_ENTEREVAL, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3305 op->op_targ = (PADOFFSET)hints;
3314 if (op->op_flags & OPf_STACKED) {
3316 kid = cUNOP->op_first->op_sibling;
3317 if (kid->op_type == OP_RV2GV)
3329 o = fold_constants(o);
3330 if (o->op_type == OP_CONST)
3339 SVOP *kid = (SVOP*)cUNOP->op_first;
3341 op->op_private |= (hints & HINT_STRICT_REFS);
3342 if (kid->op_type == OP_CONST) {
3343 int iscv = (op->op_type==OP_RV2CV)*2;
3345 kid->op_type = OP_GV;
3346 for (gv = 0; !gv; iscv++) {
3348 * This is a little tricky. We only want to add the symbol if we
3349 * didn't add it in the lexer. Otherwise we get duplicate strict
3350 * warnings. But if we didn't add it in the lexer, we must at
3351 * least pretend like we wanted to add it even if it existed before,
3352 * or we get possible typo warnings. OPpCONST_ENTERED says
3353 * whether the lexer already added THIS instance of this symbol.
3355 gv = gv_fetchpv(SvPVx(kid->op_sv, na),
3356 iscv | !(kid->op_private & OPpCONST_ENTERED),
3359 : op->op_type == OP_RV2SV
3361 : op->op_type == OP_RV2AV
3363 : op->op_type == OP_RV2HV
3367 SvREFCNT_dec(kid->op_sv);
3368 kid->op_sv = SvREFCNT_inc(gv);
3384 I32 type = op->op_type;
3386 if (op->op_flags & OPf_REF)
3389 if (op->op_flags & OPf_KIDS) {
3390 SVOP *kid = (SVOP*)cUNOP->op_first;
3392 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
3393 OP *newop = newGVOP(type, OPf_REF,
3394 gv_fetchpv(SvPVx(kid->op_sv, na), TRUE, SVt_PVIO));
3401 if (type == OP_FTTTY)
3402 return newGVOP(type, OPf_REF, gv_fetchpv("main'STDIN", TRUE,
3405 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3418 int type = op->op_type;
3419 register I32 oa = opargs[type] >> OASHIFT;
3421 if (op->op_flags & OPf_STACKED) {
3422 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
3425 return no_fh_allowed(op);
3428 if (op->op_flags & OPf_KIDS) {
3429 tokid = &cLISTOP->op_first;
3430 kid = cLISTOP->op_first;
3431 if (kid->op_type == OP_PUSHMARK ||
3432 kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK)
3434 tokid = &kid->op_sibling;
3435 kid = kid->op_sibling;
3437 if (!kid && opargs[type] & OA_DEFGV)
3438 *tokid = kid = newSVREF(newGVOP(OP_GV, 0, defgv));
3442 sibl = kid->op_sibling;
3456 if (kid->op_type == OP_CONST &&
3457 (kid->op_private & OPpCONST_BARE)) {
3458 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
3459 OP *newop = newAVREF(newGVOP(OP_GV, 0,
3460 gv_fetchpv(name, TRUE, SVt_PVAV) ));
3462 warn("Array @%s missing the @ in argument %d of %s()",
3463 name, numargs, op_desc[type]);
3466 kid->op_sibling = sibl;
3469 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
3470 bad_type(numargs, "array", op_desc[op->op_type], kid);
3474 if (kid->op_type == OP_CONST &&
3475 (kid->op_private & OPpCONST_BARE)) {
3476 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
3477 OP *newop = newHVREF(newGVOP(OP_GV, 0,
3478 gv_fetchpv(name, TRUE, SVt_PVHV) ));
3480 warn("Hash %%%s missing the %% in argument %d of %s()",
3481 name, numargs, op_desc[type]);
3484 kid->op_sibling = sibl;
3487 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
3488 bad_type(numargs, "hash", op_desc[op->op_type], kid);
3493 OP *newop = newUNOP(OP_NULL, 0, kid);
3494 kid->op_sibling = 0;
3496 newop->op_next = newop;
3498 kid->op_sibling = sibl;
3503 if (kid->op_type != OP_GV) {
3504 if (kid->op_type == OP_CONST &&
3505 (kid->op_private & OPpCONST_BARE)) {
3506 OP *newop = newGVOP(OP_GV, 0,
3507 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, na), TRUE,
3513 kid->op_sibling = 0;
3514 kid = newUNOP(OP_RV2GV, 0, scalar(kid));
3516 kid->op_sibling = sibl;
3522 mod(scalar(kid), type);
3526 tokid = &kid->op_sibling;
3527 kid = kid->op_sibling;
3529 op->op_private |= numargs;
3531 return too_many_arguments(op,op_desc[op->op_type]);
3534 else if (opargs[type] & OA_DEFGV) {
3536 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3540 while (oa & OA_OPTIONAL)
3542 if (oa && oa != OA_LIST)
3543 return too_few_arguments(op,op_desc[op->op_type]);
3552 GV *gv = newGVgen("main");
3554 append_elem(OP_GLOB, op, newGVOP(OP_GV, 0, gv));
3565 OPCODE type = op->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
3567 op->op_ppaddr = ppaddr[OP_GREPSTART];
3568 Newz(1101, gwop, 1, LOGOP);
3570 if (op->op_flags & OPf_STACKED) {
3573 kid = cLISTOP->op_first->op_sibling;
3574 for (k = cLISTOP->op_first->op_sibling->op_next; k; k = k->op_next) {
3577 kid->op_next = (OP*)gwop;
3578 op->op_flags &= ~OPf_STACKED;
3580 kid = cLISTOP->op_first->op_sibling;
3581 if (type == OP_MAPWHILE)
3588 kid = cLISTOP->op_first->op_sibling;
3589 if (kid->op_type != OP_NULL)
3590 croak("panic: ck_grep");
3591 kid = kUNOP->op_first;
3593 gwop->op_type = type;
3594 gwop->op_ppaddr = ppaddr[type];
3595 gwop->op_first = listkids(op);
3596 gwop->op_flags |= OPf_KIDS;
3597 gwop->op_private = 1;
3598 gwop->op_other = LINKLIST(kid);
3599 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
3600 kid->op_next = (OP*)gwop;
3602 kid = cLISTOP->op_first->op_sibling;
3603 if (!kid || !kid->op_sibling)
3604 return too_few_arguments(op,op_desc[op->op_type]);
3605 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
3606 mod(kid, OP_GREPSTART);
3615 if (op->op_flags & OPf_KIDS) {
3616 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3617 if (kid && kid->op_type == OP_CONST)
3618 fbm_compile(((SVOP*)kid)->op_sv, 0);
3627 /* XXX length optimization goes here */
3635 return modkids(ck_fun(op), op->op_type);
3642 return refkids(ck_fun(op), op->op_type);
3651 kid = cLISTOP->op_first;
3653 op = force_list(op);
3654 kid = cLISTOP->op_first;
3656 if (kid->op_type == OP_PUSHMARK)
3657 kid = kid->op_sibling;
3658 if (kid && op->op_flags & OPf_STACKED)
3659 kid = kid->op_sibling;
3660 else if (kid && !kid->op_sibling) { /* print HANDLE; */
3661 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
3662 op->op_flags |= OPf_STACKED; /* make it a filehandle */
3663 kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
3664 cLISTOP->op_first->op_sibling = kid;
3665 cLISTOP->op_last = kid;
3666 kid = kid->op_sibling;
3671 append_elem(op->op_type, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
3673 return listkids(op);
3680 cPMOP->op_pmflags |= PMf_RUNTIME;
3681 cPMOP->op_pmpermflags |= PMf_RUNTIME;
3696 if (cBINOP->op_first->op_flags & OPf_PARENS) {
3697 op->op_private |= OPpREPEAT_DOLIST;
3698 cBINOP->op_first = force_list(cBINOP->op_first);
3709 if (op->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
3710 SVOP *kid = (SVOP*)cUNOP->op_first;
3712 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
3714 for (s = SvPVX(kid->op_sv); *s; s++) {
3715 if (*s == ':' && s[1] == ':') {
3717 Move(s+2, s+1, strlen(s+2)+1, char);
3718 --SvCUR(kid->op_sv);
3721 sv_catpvn(kid->op_sv, ".pm", 3);
3731 croak("NOT IMPL LINE %d",__LINE__);
3741 if (op->op_flags & OPf_KIDS) {
3742 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3743 if (kid && kid->op_sibling) {
3744 op->op_type = OP_SSELECT;
3745 op->op_ppaddr = ppaddr[OP_SSELECT];
3747 return fold_constants(op);
3751 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3752 if (kid && kid->op_type == OP_RV2GV)
3753 kid->op_private &= ~HINT_STRICT_REFS;
3761 I32 type = op->op_type;
3763 if (!(op->op_flags & OPf_KIDS)) {
3765 return newUNOP(type, 0,
3766 scalar(newUNOP(OP_RV2AV, 0,
3767 scalar(newGVOP(OP_GV, 0,
3768 gv_fetchpv((subline ? "_" : "ARGV"), TRUE, SVt_PVAV) )))));
3770 return scalar(modkids(ck_fun(op), type));
3777 if (op->op_flags & OPf_STACKED) {
3778 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3780 kid = kUNOP->op_first; /* get past rv2gv */
3782 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
3784 if (kid->op_type == OP_SCOPE) {
3788 else if (kid->op_type == OP_LEAVE) {
3789 if (op->op_type == OP_SORT) {
3790 null(kid); /* wipe out leave */
3793 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
3794 if (k->op_next == kid)
3799 kid->op_next = 0; /* just disconnect the leave */
3800 k = kLISTOP->op_first;
3804 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3805 null(kid); /* wipe out rv2gv */
3806 if (op->op_type == OP_SORT)
3810 op->op_flags |= OPf_SPECIAL;
3823 if (op->op_flags & OPf_STACKED)
3824 return no_fh_allowed(op);
3826 kid = cLISTOP->op_first;
3827 if (kid->op_type != OP_NULL)
3828 croak("panic: ck_split");
3829 kid = kid->op_sibling;
3830 op_free(cLISTOP->op_first);
3831 cLISTOP->op_first = kid;
3833 cLISTOP->op_first = kid = newSVOP(OP_CONST, 0, newSVpv(" ", 1));
3834 cLISTOP->op_last = kid; /* There was only one element previously */
3837 if (kid->op_type != OP_MATCH) {
3838 OP *sibl = kid->op_sibling;
3839 kid->op_sibling = 0;
3840 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
3841 if (cLISTOP->op_first == cLISTOP->op_last)
3842 cLISTOP->op_last = kid;
3843 cLISTOP->op_first = kid;
3844 kid->op_sibling = sibl;
3847 if (pm->op_pmshort && !(pm->op_pmflags & PMf_ALL)) {
3848 SvREFCNT_dec(pm->op_pmshort); /* can't use substring to optimize */
3852 kid->op_type = OP_PUSHRE;
3853 kid->op_ppaddr = ppaddr[OP_PUSHRE];
3856 if (!kid->op_sibling)
3857 append_elem(OP_SPLIT, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
3859 kid = kid->op_sibling;
3862 if (!kid->op_sibling)
3863 append_elem(OP_SPLIT, op, newSVOP(OP_CONST, 0, newSViv(0)));
3865 kid = kid->op_sibling;
3868 if (kid->op_sibling)
3869 return too_many_arguments(op,op_desc[op->op_type]);
3878 OP *prev = ((cUNOP->op_first->op_sibling)
3879 ? cUNOP : ((UNOP*)cUNOP->op_first))->op_first;
3880 OP *o = prev->op_sibling;
3887 for (cvop = o; cvop->op_sibling; cvop = cvop->op_sibling) ;
3888 if (cvop->op_type == OP_RV2CV) {
3890 op->op_private |= (cvop->op_private & OPpENTERSUB_AMPER);
3891 null(cvop); /* disable rv2cv */
3892 tmpop = (SVOP*)((UNOP*)cvop)->op_first;
3893 if (tmpop->op_type == OP_GV) {
3894 cv = GvCV(tmpop->op_sv);
3895 if (cv && SvPOK(cv) && !(op->op_private & OPpENTERSUB_AMPER))
3896 proto = SvPV((SV*)cv,na);
3899 op->op_private |= (hints & HINT_STRICT_REFS);
3900 if (perldb && curstash != debstash)
3901 op->op_private |= OPpENTERSUB_DB;
3906 return too_many_arguments(op, CvNAME(cv));
3924 if (o->op_type != OP_REFGEN && o->op_type != OP_UNDEF)
3925 bad_type(arg, "block", CvNAME(cv), o);
3930 if (o->op_type == OP_RV2GV)
3934 o = newUNOP(OP_RV2GV, 0, kid);
3935 o->op_sibling = kid->op_sibling;
3936 kid->op_sibling = 0;
3937 prev->op_sibling = o;
3945 if (o->op_type != OP_RV2GV)
3946 bad_type(arg, "symbol", CvNAME(cv), o);
3949 if (o->op_type != OP_RV2CV)
3950 bad_type(arg, "sub", CvNAME(cv), o);
3953 if (o->op_type != OP_RV2SV && o->op_type != OP_PADSV)
3954 bad_type(arg, "scalar", CvNAME(cv), o);
3957 if (o->op_type != OP_RV2AV && o->op_type != OP_PADAV)
3958 bad_type(arg, "array", CvNAME(cv), o);
3961 if (o->op_type != OP_RV2HV && o->op_type != OP_PADHV)
3962 bad_type(arg, "hash", CvNAME(cv), o);
3966 o = newUNOP(OP_REFGEN, 0, kid);
3967 o->op_sibling = kid->op_sibling;
3968 kid->op_sibling = 0;
3969 prev->op_sibling = o;
3977 croak("Malformed prototype for %s: %s",
3978 CvNAME(cv),SvPV((SV*)cv,na));
3983 mod(o, OP_ENTERSUB);
3987 if (proto && !optional && *proto == '$')
3988 return too_few_arguments(op, CvNAME(cv));
3996 SvREADONLY_on(cSVOP->op_sv);
4004 if (op->op_flags & OPf_KIDS) {
4005 SVOP *kid = (SVOP*)cUNOP->op_first;
4007 if (kid->op_type == OP_NULL)
4008 kid = (SVOP*)kid->op_sibling;
4010 kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE))
4011 op->op_flags |= OPf_SPECIAL;
4016 /* A peephole optimizer. We visit the ops in the order they're to execute. */
4022 register OP* oldop = 0;
4023 if (!o || o->op_seq)
4028 for (; o; o = o->op_next) {
4034 switch (o->op_type) {
4037 curcop = ((COP*)o); /* for warnings */
4038 o->op_seq = op_seqmax++;
4049 if (o->op_next->op_type == OP_STRINGIFY)
4051 o->op_seq = op_seqmax++;
4054 if ((o->op_flags & (OPf_KNOW|OPf_LIST)) != (OPf_KNOW|OPf_LIST)) {
4055 o->op_seq = op_seqmax++;
4056 break; /* Scalar stub must produce undef. List stub is noop */
4060 if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE)
4061 curcop = ((COP*)op);
4067 if (oldop && o->op_next) {
4068 oldop->op_next = o->op_next;
4071 o->op_seq = op_seqmax++;
4075 if (o->op_next->op_type == OP_RV2SV) {
4076 if (!(o->op_next->op_private & (OPpDEREF_HV|OPpDEREF_AV))) {
4078 o->op_private |= o->op_next->op_private & OPpLVAL_INTRO;
4079 o->op_next = o->op_next->op_next;
4080 o->op_type = OP_GVSV;
4081 o->op_ppaddr = ppaddr[OP_GVSV];
4084 else if (o->op_next->op_type == OP_RV2AV) {
4085 OP* pop = o->op_next->op_next;
4087 if (pop->op_type == OP_CONST &&
4088 (op = pop->op_next) &&
4089 pop->op_next->op_type == OP_AELEM &&
4090 !(pop->op_next->op_private &
4091 (OPpDEREF_HV|OPpDEREF_AV|OPpLVAL_INTRO)) &&
4092 (i = SvIV(((SVOP*)pop)->op_sv) - compiling.cop_arybase)
4096 SvREFCNT_dec(((SVOP*)pop)->op_sv);
4100 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
4101 o->op_next = pop->op_next->op_next;
4102 o->op_type = OP_AELEMFAST;
4103 o->op_ppaddr = ppaddr[OP_AELEMFAST];
4104 o->op_private = (U8)i;
4105 GvAVn((GV*)(((SVOP*)o)->op_sv));
4108 o->op_seq = op_seqmax++;
4115 o->op_seq = op_seqmax++;
4116 peep(cLOGOP->op_other);
4120 o->op_seq = op_seqmax++;
4121 peep(cCONDOP->op_true);
4122 peep(cCONDOP->op_false);
4126 o->op_seq = op_seqmax++;
4127 peep(cLOOP->op_redoop);
4128 peep(cLOOP->op_nextop);
4129 peep(cLOOP->op_lastop);
4134 o->op_seq = op_seqmax++;
4135 peep(cPMOP->op_pmreplstart);
4139 o->op_seq = op_seqmax++;
4140 if (dowarn && o->op_next && o->op_next->op_type == OP_NEXTSTATE) {
4141 if (o->op_next->op_sibling &&
4142 o->op_next->op_sibling->op_type != OP_DIE) {
4143 line_t oldline = curcop->cop_line;
4145 curcop->cop_line = ((COP*)o->op_next)->cop_line;
4146 warn("Statement unlikely to be reached");
4147 warn("(Maybe you meant system() when you said exec()?)\n");
4148 curcop->cop_line = oldline;
4162 if (o->op_private & (OPpDEREF_HV|OPpDEREF_AV|OPpLVAL_INTRO)
4163 || ((BINOP*)o)->op_last->op_type != OP_CONST)
4165 rop = (UNOP*)((BINOP*)o)->op_first;
4166 if (rop->op_type != OP_RV2HV || rop->op_first->op_type != OP_PADSV)
4168 lexname = *av_fetch(comppad_name, rop->op_first->op_targ, TRUE);
4169 if (!SvOBJECT(lexname))
4171 fields = hv_fetch(SvSTASH(lexname), "FIELDS", 6, FALSE);
4172 if (!fields || !GvHV(*fields))
4174 svp = &((SVOP*)((BINOP*)o)->op_last)->op_sv;
4175 key = SvPV(*svp, keylen);
4176 indsvp = hv_fetch(GvHV(*fields), key, keylen, FALSE);
4178 croak("No such field \"%s\" in variable %s of type %s",
4179 key, SvPV(lexname, na), HvNAME(SvSTASH(lexname)));
4181 ind = SvIV(*indsvp);
4183 croak("Bad index while coercing array into hash");
4184 rop->op_type = OP_RV2AV;
4185 rop->op_ppaddr = ppaddr[OP_RV2AV];
4186 o->op_type = OP_AELEM;
4187 o->op_ppaddr = ppaddr[OP_AELEM];
4189 *svp = newSViv(ind);
4194 o->op_seq = op_seqmax++;