3 * Copyright (c) 1991-1997, 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 ? ( op_free((OP*)op), \
31 croak("%s trapped by operation mask", op_desc[type]), \
33 : (*check[type])((OP*)op))
35 #define CHECKOP(type,op) (*check[type])(op)
36 #endif /* USE_OP_MASK */
38 static I32 list_assignment _((OP *op));
39 static OP *bad_type _((I32 n, char *t, char *name, OP *kid));
40 static OP *modkids _((OP *op, I32 type));
41 static OP *no_fh_allowed _((OP *op));
42 static bool scalar_mod_type _((OP *op, I32 type));
43 static OP *scalarboolean _((OP *op));
44 static OP *too_few_arguments _((OP *op, char* name));
45 static OP *too_many_arguments _((OP *op, char* name));
46 static void null _((OP* op));
47 static PADOFFSET pad_findlex _((char* name, PADOFFSET newoff, U32 seq,
48 CV* startcv, I32 cx_ix));
54 SV* tmpsv = sv_newmortal();
55 gv_efullname3(tmpsv, CvGV(cv), Nullch);
56 return SvPV(tmpsv,na);
63 sprintf(tokenbuf,"Missing comma after first argument to %s function",
64 op_desc[op->op_type]);
70 too_few_arguments(op, name)
74 sprintf(tokenbuf,"Not enough arguments for %s", name);
80 too_many_arguments(op, name)
84 sprintf(tokenbuf,"Too many arguments for %s", name);
90 bad_type(n, t, name, kid)
96 sprintf(tokenbuf, "Type of arg %d to %s must be %s (not %s)",
97 (int) n, name, t, op_desc[kid->op_type]);
106 int type = op->op_type;
107 if (type != OP_AELEM && type != OP_HELEM) {
108 sprintf(tokenbuf, "Can't use subscript on %s", op_desc[type]);
110 if (type == OP_ENTERSUB || type == OP_RV2HV || type == OP_PADHV)
111 warn("(Did you mean $ or @ instead of %c?)\n",
112 type == OP_ENTERSUB ? '&' : '%');
116 /* "register" allocation */
125 if (!(isALPHA(name[1]) || name[1] == '_' && (int)strlen(name) > 2)) {
126 if (!isPRINT(name[1]))
127 sprintf(name+1, "^%c", toCTRL(name[1])); /* XXX tokenbuf, really */
128 croak("Can't use global %s in \"my\"",name);
130 if (AvFILL(comppad_name) >= 0) {
131 SV **svp = AvARRAY(comppad_name);
132 for (off = AvFILL(comppad_name); off > comppad_name_floor; off--) {
135 && SvIVX(sv) == 999999999 /* var is in open scope */
136 && strEQ(name, SvPVX(sv)))
138 warn("\"my\" variable %s masks earlier declaration in same scope", name);
143 off = pad_alloc(OP_PADSV, SVs_PADMY);
145 sv_upgrade(sv, SVt_PVNV);
147 av_store(comppad_name, off, sv);
148 SvNVX(sv) = (double)999999999;
149 SvIVX(sv) = 0; /* Not yet introduced--see newSTATEOP */
150 if (!min_intro_pending)
151 min_intro_pending = off;
152 max_intro_pending = off;
154 av_store(comppad, off, (SV*)newAV());
155 else if (*name == '%')
156 av_store(comppad, off, (SV*)newHV());
157 SvPADMY_on(curpad[off]);
162 #ifndef CAN_PROTOTYPE
163 pad_findlex(name, newoff, seq, startcv, cx_ix)
170 pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix)
177 register CONTEXT *cx;
180 for (cv = startcv; cv; cv = CvOUTSIDE(cv)) {
181 AV *curlist = CvPADLIST(cv);
182 SV **svp = av_fetch(curlist, 0, FALSE);
185 if (!svp || *svp == &sv_undef)
188 svp = AvARRAY(curname);
189 for (off = AvFILL(curname); off > 0; off--) {
190 if ((sv = svp[off]) &&
193 seq > I_32(SvNVX(sv)) &&
194 strEQ(SvPVX(sv), name))
205 return 0; /* don't clone from inactive stack frame */
209 oldpad = (AV*)*av_fetch(curlist, depth, FALSE);
210 oldsv = *av_fetch(oldpad, off, TRUE);
211 if (!newoff) { /* Not a mere clone operation. */
212 SV *namesv = NEWSV(1103,0);
213 newoff = pad_alloc(OP_PADSV, SVs_PADMY);
214 sv_upgrade(namesv, SVt_PVNV);
215 sv_setpv(namesv, name);
216 av_store(comppad_name, newoff, namesv);
217 SvNVX(namesv) = (double)curcop->cop_seq;
218 SvIVX(namesv) = 999999999; /* A ref, intro immediately */
219 SvFAKE_on(namesv); /* A ref, not a real var */
220 if (CvANON(compcv) || SvTYPE(compcv) == SVt_PVFM) {
221 /* "It's closures all the way down." */
226 bcv && bcv != cv && !CvCLONE(bcv);
227 bcv = CvOUTSIDE(bcv)) {
231 if (dowarn && !CvUNIQUE(cv))
233 "Variable \"%s\" may be unavailable",
240 else if (!CvUNIQUE(compcv)) {
241 if (dowarn && !SvFAKE(sv) && !CvUNIQUE(cv))
242 warn("Variable \"%s\" will not stay shared", name);
245 av_store(comppad, newoff, SvREFCNT_inc(oldsv));
251 /* Nothing in current lexical context--try eval's context, if any.
252 * This is necessary to let the perldb get at lexically scoped variables.
253 * XXX This will also probably interact badly with eval tree caching.
257 for (i = cx_ix; i >= 0; i--) {
259 switch (cx->cx_type) {
261 if (i == 0 && saweval) {
262 seq = cxstack[saweval].blk_oldcop->cop_seq;
263 return pad_findlex(name, newoff, seq, main_cv, 0);
267 switch (cx->blk_eval.old_op_type) {
272 /* require must have its own scope */
280 if (debstash && CvSTASH(cv) == debstash) { /* ignore DB'* scope */
281 saweval = i; /* so we know where we were called from */
284 seq = cxstack[saweval].blk_oldcop->cop_seq;
285 return pad_findlex(name, newoff, seq, cv, i-1);
298 SV **svp = AvARRAY(comppad_name);
299 U32 seq = cop_seqmax;
301 /* The one we're looking for is probably just before comppad_name_fill. */
302 for (off = AvFILL(comppad_name); off > 0; off--) {
303 if ((sv = svp[off]) &&
306 seq > I_32(SvNVX(sv)) &&
307 strEQ(SvPVX(sv), name))
309 return (PADOFFSET)off;
313 /* See if it's in a nested scope */
314 off = pad_findlex(name, 0, seq, CvOUTSIDE(compcv), cxstack_ix);
326 SV **svp = AvARRAY(comppad_name);
328 if (min_intro_pending && fill < min_intro_pending) {
329 for (off = max_intro_pending; off >= min_intro_pending; off--) {
330 if ((sv = svp[off]) && sv != &sv_undef)
331 warn("%s never introduced", SvPVX(sv));
334 /* "Deintroduce" my variables that are leaving with this scope. */
335 for (off = AvFILL(comppad_name); off > fill; off--) {
336 if ((sv = svp[off]) && sv != &sv_undef && SvIVX(sv) == 999999999)
337 SvIVX(sv) = cop_seqmax;
342 pad_alloc(optype,tmptype)
349 if (AvARRAY(comppad) != curpad)
350 croak("panic: pad_alloc");
351 if (pad_reset_pending)
353 if (tmptype & SVs_PADMY) {
355 sv = *av_fetch(comppad, AvFILL(comppad) + 1, TRUE);
356 } while (SvPADBUSY(sv)); /* need a fresh one */
357 retval = AvFILL(comppad);
360 SV **names = AvARRAY(comppad_name);
361 SSize_t names_fill = AvFILL(comppad_name);
364 * "foreach" index vars temporarily become aliases to non-"my"
365 * values. Thus we must skip, not just pad values that are
366 * marked as current pad values, but also those with names.
368 if (++padix <= names_fill &&
369 (sv = names[padix]) && sv != &sv_undef)
371 sv = *av_fetch(comppad, padix, TRUE);
372 if (!(SvFLAGS(sv) & (SVs_PADTMP|SVs_PADMY)))
377 SvFLAGS(sv) |= tmptype;
378 curpad = AvARRAY(comppad);
379 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad alloc %ld for %s\n", (long) retval, op_name[optype]));
380 return (PADOFFSET)retval;
384 #ifndef CAN_PROTOTYPE
389 #endif /* CAN_PROTOTYPE */
392 croak("panic: pad_sv po");
393 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad sv %lu\n", (unsigned long)po));
394 return curpad[po]; /* eventually we'll turn this into a macro */
398 #ifndef CAN_PROTOTYPE
402 pad_free(PADOFFSET po)
403 #endif /* CAN_PROTOTYPE */
407 if (AvARRAY(comppad) != curpad)
408 croak("panic: pad_free curpad");
410 croak("panic: pad_free po");
411 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad free %lu\n", (unsigned long)po));
412 if (curpad[po] && !SvIMMORTAL(curpad[po]))
413 SvPADTMP_off(curpad[po]);
419 #ifndef CAN_PROTOTYPE
423 pad_swipe(PADOFFSET po)
424 #endif /* CAN_PROTOTYPE */
426 if (AvARRAY(comppad) != curpad)
427 croak("panic: pad_swipe curpad");
429 croak("panic: pad_swipe po");
430 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad swipe %lu\n", (unsigned long)po));
431 SvPADTMP_off(curpad[po]);
432 curpad[po] = NEWSV(1107,0);
433 SvPADTMP_on(curpad[po]);
443 if (AvARRAY(comppad) != curpad)
444 croak("panic: pad_reset curpad");
445 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad reset\n"));
446 if (!tainting) { /* Can't mix tainted and non-tainted temporaries. */
447 for (po = AvMAX(comppad); po > padix_floor; po--) {
448 if (curpad[po] && !SvIMMORTAL(curpad[po]))
449 SvPADTMP_off(curpad[po]);
453 pad_reset_pending = FALSE;
462 register OP *kid, *nextkid;
464 if (!op || op->op_seq == (U16)-1)
467 if (op->op_flags & OPf_KIDS) {
468 for (kid = cUNOP->op_first; kid; kid = nextkid) {
469 nextkid = kid->op_sibling; /* Get before next freeing kid */
474 switch (op->op_type) {
476 op->op_targ = 0; /* Was holding old type, if any. */
479 op->op_targ = 0; /* Was holding hints. */
482 if (!(op->op_flags & OPf_REF) || (check[op->op_type] != ck_ftst))
488 SvREFCNT_dec(cGVOP->op_gv);
492 Safefree(cCOP->cop_label);
493 SvREFCNT_dec(cCOP->cop_filegv);
496 SvREFCNT_dec(cSVOP->op_sv);
502 if (op->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
506 Safefree(cPVOP->op_pv);
509 op_free(cPMOP->op_pmreplroot);
513 pregfree(cPMOP->op_pmregexp);
514 SvREFCNT_dec(cPMOP->op_pmshort);
519 pad_free(op->op_targ);
528 if (op->op_type != OP_NULL && op->op_targ > 0)
529 pad_free(op->op_targ);
530 op->op_targ = op->op_type;
531 op->op_type = OP_NULL;
532 op->op_ppaddr = ppaddr[OP_NULL];
535 /* Contextualizers */
537 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
548 /* establish postfix order */
549 if (cUNOP->op_first) {
550 op->op_next = LINKLIST(cUNOP->op_first);
551 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
553 kid->op_next = LINKLIST(kid->op_sibling);
569 if (op && op->op_flags & OPf_KIDS) {
570 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
581 op->op_type == OP_SASSIGN && cBINOP->op_first->op_type == OP_CONST) {
582 line_t oldline = curcop->cop_line;
584 if (copline != NOLINE)
585 curcop->cop_line = copline;
586 warn("Found = in conditional, should be ==");
587 curcop->cop_line = oldline;
598 /* assumes no premature commitment */
599 if (!op || (op->op_flags & OPf_KNOW) || op->op_type == OP_RETURN
603 op->op_flags &= ~OPf_LIST;
604 op->op_flags |= OPf_KNOW;
606 switch (op->op_type) {
608 if (op->op_private & OPpREPEAT_DOLIST)
609 null(((LISTOP*)cBINOP->op_first)->op_first);
610 scalar(cBINOP->op_first);
615 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
619 if ((kid = ((LISTOP*)op)->op_first) && kid->op_type == OP_PUSHRE) {
620 if (!kPMOP->op_pmreplroot)
621 deprecate("implicit split to @_");
628 if (op->op_flags & OPf_KIDS) {
629 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling)
635 scalar(cLISTOP->op_first);
640 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
660 if (!op || error_count)
662 if (op->op_flags & OPf_LIST)
665 op->op_flags |= OPf_KNOW;
667 switch (op->op_type) {
669 if (!(opargs[op->op_type] & OA_FOLDCONST))
673 if (op->op_flags & OPf_STACKED)
744 if (!(op->op_private & OPpLVAL_INTRO))
745 useless = op_desc[op->op_type];
752 if (!(op->op_private & OPpLVAL_INTRO) &&
753 (!op->op_sibling || op->op_sibling->op_type != OP_READLINE))
754 useless = "a variable";
759 curcop = ((COP*)op); /* for warning below */
765 useless = "a constant";
766 if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
768 else if (SvPOK(sv)) {
769 if (strnEQ(SvPVX(sv), "di", 2) ||
770 strnEQ(SvPVX(sv), "ds", 2) ||
771 strnEQ(SvPVX(sv), "ig", 2))
775 null(op); /* don't execute a constant */
776 SvREFCNT_dec(sv); /* don't even remember it */
780 op->op_type = OP_PREINC; /* pre-increment is faster */
781 op->op_ppaddr = ppaddr[OP_PREINC];
785 op->op_type = OP_PREDEC; /* pre-decrement is faster */
786 op->op_ppaddr = ppaddr[OP_PREDEC];
792 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
796 if (op->op_targ == OP_NEXTSTATE || op->op_targ == OP_DBSTATE)
797 curcop = ((COP*)op); /* for warning below */
798 if (op->op_flags & OPf_STACKED)
803 if (!(op->op_flags & OPf_KIDS))
809 op->op_private |= OPpLEAVE_VOID;
812 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
816 if ((kid = ((LISTOP*)op)->op_first) && kid->op_type == OP_PUSHRE) {
817 if (!kPMOP->op_pmreplroot)
818 deprecate("implicit split to @_");
824 op->op_private |= OPpLEAVE_VOID;
827 if (useless && dowarn)
828 warn("Useless use of %s in void context", useless);
837 if (op && op->op_flags & OPf_KIDS) {
838 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
850 /* assumes no premature commitment */
851 if (!op || (op->op_flags & OPf_KNOW) || op->op_type == OP_RETURN
855 op->op_flags |= (OPf_KNOW | OPf_LIST);
857 switch (op->op_type) {
860 list(cBINOP->op_first);
865 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
872 if (!(op->op_flags & OPf_KIDS))
874 if (!op->op_next && cUNOP->op_first->op_type == OP_FLOP) {
875 list(cBINOP->op_first);
876 return gen_constant_list(op);
883 list(cLISTOP->op_first);
887 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
906 if (op->op_type == OP_LINESEQ ||
907 op->op_type == OP_SCOPE ||
908 op->op_type == OP_LEAVE ||
909 op->op_type == OP_LEAVETRY)
911 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
912 if (kid->op_sibling) {
918 op->op_flags &= ~OPf_PARENS;
919 if (hints & HINT_BLOCK_SCOPE)
920 op->op_flags |= OPf_PARENS;
923 op = newOP(OP_STUB, 0);
933 if (op && op->op_flags & OPf_KIDS) {
934 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
950 if (!op || error_count)
953 switch (op->op_type) {
957 if (!(op->op_private & (OPpCONST_ARYBASE)))
959 if (eval_start && eval_start->op_type == OP_CONST) {
960 compiling.cop_arybase = (I32)SvIV(((SVOP*)eval_start)->op_sv);
964 SAVEI32(compiling.cop_arybase);
965 compiling.cop_arybase = 0;
967 else if (type == OP_REFGEN)
970 croak("That use of $[ is unsupported");
973 if (op->op_flags & OPf_PARENS)
977 if ((type == OP_UNDEF || type == OP_REFGEN) &&
978 !(op->op_flags & OPf_STACKED)) {
979 op->op_type = OP_RV2CV; /* entersub => rv2cv */
980 op->op_ppaddr = ppaddr[OP_RV2CV];
981 assert(cUNOP->op_first->op_type == OP_NULL);
982 null(((LISTOP*)cUNOP->op_first)->op_first); /* disable pushmark */
988 /* grep, foreach, subcalls, refgen */
989 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
991 sprintf(tokenbuf, "Can't modify %s in %s",
992 op_desc[op->op_type],
993 type ? op_desc[type] : "local");
1008 case OP_RIGHT_SHIFT:
1017 if (!(op->op_flags & OPf_STACKED))
1023 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
1029 if (type == OP_REFGEN && op->op_flags & OPf_PARENS) {
1031 return op; /* Treat \(@foo) like ordinary list. */
1035 if (scalar_mod_type(op, type))
1037 ref(cUNOP->op_first, op->op_type);
1049 if (!type && cUNOP->op_first->op_type != OP_GV)
1050 croak("Can't localize a reference");
1051 ref(cUNOP->op_first, op->op_type);
1063 if (type == OP_REFGEN && op->op_flags & OPf_PARENS)
1064 return op; /* Treat \(@foo) like ordinary list. */
1065 if (scalar_mod_type(op, type))
1071 croak("Can't localize lexical variable %s",
1072 SvPV(*av_fetch(comppad_name, op->op_targ, 4), na));
1079 if (type != OP_SASSIGN)
1085 pad_free(op->op_targ);
1086 op->op_targ = pad_alloc(op->op_type, SVs_PADMY);
1087 assert(SvTYPE(PAD_SV(op->op_targ)) == SVt_NULL);
1088 if (op->op_flags & OPf_KIDS)
1089 mod(cBINOP->op_first->op_sibling, type);
1094 ref(cBINOP->op_first, op->op_type);
1095 if (type == OP_ENTERSUB &&
1096 !(op->op_private & (OPpLVAL_INTRO | OPpDEREF)))
1097 op->op_private |= OPpLVAL_DEFER;
1104 if (op->op_flags & OPf_KIDS)
1105 mod(cLISTOP->op_last, type);
1109 if (!(op->op_flags & OPf_KIDS))
1111 if (op->op_targ != OP_LIST) {
1112 mod(cBINOP->op_first, type);
1117 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1121 op->op_flags |= OPf_MOD;
1123 if (type == OP_AASSIGN || type == OP_SASSIGN)
1124 op->op_flags |= OPf_SPECIAL|OPf_REF;
1126 op->op_private |= OPpLVAL_INTRO;
1127 op->op_flags &= ~OPf_SPECIAL;
1129 else if (type != OP_GREPSTART && type != OP_ENTERSUB)
1130 op->op_flags |= OPf_REF;
1135 scalar_mod_type(op, type)
1141 if (op->op_type == OP_RV2GV)
1165 case OP_RIGHT_SHIFT:
1172 case OP_ANDASSIGN: /* may work later */
1173 case OP_ORASSIGN: /* may work later */
1186 if (op && op->op_flags & OPf_KIDS) {
1187 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1200 if (!op || error_count)
1203 switch (op->op_type) {
1205 if ((type == OP_DEFINED) &&
1206 !(op->op_flags & OPf_STACKED)) {
1207 op->op_type = OP_RV2CV; /* entersub => rv2cv */
1208 op->op_ppaddr = ppaddr[OP_RV2CV];
1209 assert(cUNOP->op_first->op_type == OP_NULL);
1210 null(((LISTOP*)cUNOP->op_first)->op_first); /* disable pushmark */
1211 op->op_flags |= OPf_SPECIAL;
1216 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
1220 ref(cUNOP->op_first, op->op_type);
1223 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1224 op->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1225 : type == OP_RV2HV ? OPpDEREF_HV
1227 op->op_flags |= OPf_MOD;
1233 op->op_flags |= OPf_REF;
1236 ref(cUNOP->op_first, op->op_type);
1241 op->op_flags |= OPf_REF;
1246 if (!(op->op_flags & OPf_KIDS))
1248 ref(cBINOP->op_first, type);
1252 ref(cBINOP->op_first, op->op_type);
1253 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1254 op->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1255 : type == OP_RV2HV ? OPpDEREF_HV
1257 op->op_flags |= OPf_MOD;
1265 if (!(op->op_flags & OPf_KIDS))
1267 ref(cLISTOP->op_last, type);
1283 if (!op || error_count)
1287 if (type == OP_LIST) {
1288 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1291 else if (type != OP_PADSV &&
1294 type != OP_PUSHMARK)
1296 sprintf(tokenbuf, "Can't declare %s in my", op_desc[op->op_type]);
1300 op->op_flags |= OPf_MOD;
1301 op->op_private |= OPpLVAL_INTRO;
1310 o->op_flags |= OPf_PARENS;
1315 bind_match(type, left, right)
1323 (left->op_type == OP_RV2AV ||
1324 left->op_type == OP_RV2HV ||
1325 left->op_type == OP_PADAV ||
1326 left->op_type == OP_PADHV)) {
1327 char *desc = op_desc[(right->op_type == OP_SUBST ||
1328 right->op_type == OP_TRANS)
1329 ? right->op_type : OP_MATCH];
1330 char *sample = ((left->op_type == OP_RV2AV ||
1331 left->op_type == OP_PADAV)
1332 ? "@array" : "%hash");
1333 warn("Applying %s to %s will act on scalar(%s)", desc, sample, sample);
1336 if (right->op_type == OP_MATCH ||
1337 right->op_type == OP_SUBST ||
1338 right->op_type == OP_TRANS) {
1339 right->op_flags |= OPf_STACKED;
1340 if (right->op_type != OP_MATCH)
1341 left = mod(left, right->op_type);
1342 if (right->op_type == OP_TRANS)
1343 op = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
1345 op = prepend_elem(right->op_type, scalar(left), right);
1347 return newUNOP(OP_NOT, 0, scalar(op));
1351 return bind_match(type, left,
1352 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
1361 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
1362 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(op));
1370 if (o->op_flags & OPf_PARENS || perldb || tainting) {
1371 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
1372 o->op_type = OP_LEAVE;
1373 o->op_ppaddr = ppaddr[OP_LEAVE];
1376 if (o->op_type == OP_LINESEQ) {
1378 o->op_type = OP_SCOPE;
1379 o->op_ppaddr = ppaddr[OP_SCOPE];
1380 kid = ((LISTOP*)o)->op_first;
1381 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE){
1382 SvREFCNT_dec(((COP*)kid)->cop_filegv);
1387 o = newLISTOP(OP_SCOPE, 0, o, Nullop);
1397 int retval = savestack_ix;
1398 SAVEI32(comppad_name_floor);
1400 if ((comppad_name_fill = AvFILL(comppad_name)) > 0)
1401 comppad_name_floor = comppad_name_fill;
1403 comppad_name_floor = 0;
1405 SAVEI32(min_intro_pending);
1406 SAVEI32(max_intro_pending);
1407 min_intro_pending = 0;
1408 SAVEI32(comppad_name_fill);
1409 SAVEI32(padix_floor);
1410 padix_floor = padix;
1411 pad_reset_pending = FALSE;
1413 hints &= ~HINT_BLOCK_SCOPE;
1418 block_end(floor, seq)
1422 int needblockscope = hints & HINT_BLOCK_SCOPE;
1423 OP* retval = scalarseq(seq);
1425 pad_reset_pending = FALSE;
1427 hints |= HINT_BLOCK_SCOPE; /* propagate out */
1428 pad_leavemy(comppad_name_fill);
1438 eval_root = newUNOP(OP_LEAVEEVAL, ((in_eval & 4) ? OPf_SPECIAL : 0), op);
1439 eval_start = linklist(eval_root);
1440 eval_root->op_next = 0;
1446 main_root = scope(sawparens(scalarvoid(op)));
1447 curcop = &compiling;
1448 main_start = LINKLIST(main_root);
1449 main_root->op_next = 0;
1453 /* Register with debugger */
1455 CV *cv = perl_get_cv("DB::postponed", FALSE);
1459 XPUSHs((SV*)compiling.cop_filegv);
1461 perl_call_sv((SV*)cv, G_DISCARD);
1472 if (o->op_flags & OPf_PARENS)
1476 if (dowarn && bufptr > oldbufptr && bufptr[-1] == ',') {
1478 for (s = bufptr; *s && (isALNUM(*s) || strchr("@$%, ",*s)); s++) ;
1479 if (*s == ';' || *s == '=')
1480 warn("Parens missing around \"%s\" list", lex ? "my" : "local");
1487 return mod(o, OP_NULL); /* a bit kludgey */
1494 if (o->op_type == OP_LIST) {
1495 o = convert(OP_JOIN, 0,
1496 prepend_elem(OP_LIST,
1497 newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
1508 I32 type = o->op_type;
1511 if (opargs[type] & OA_RETSCALAR)
1513 if (opargs[type] & OA_TARGET)
1514 o->op_targ = pad_alloc(type, SVs_PADTMP);
1516 if ((opargs[type] & OA_OTHERINT) && (hints & HINT_INTEGER))
1517 o->op_ppaddr = ppaddr[type = ++(o->op_type)];
1519 if (!(opargs[type] & OA_FOLDCONST))
1523 goto nope; /* Don't try to run w/ errors */
1525 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
1526 if (curop->op_type != OP_CONST &&
1527 curop->op_type != OP_LIST &&
1528 curop->op_type != OP_SCALAR &&
1529 curop->op_type != OP_NULL &&
1530 curop->op_type != OP_PUSHMARK) {
1535 curop = LINKLIST(o);
1540 if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
1541 pad_swipe(o->op_targ);
1542 else if (SvTEMP(sv)) { /* grab mortal temp? */
1543 (void)SvREFCNT_inc(sv);
1547 if (type == OP_RV2GV)
1548 return newGVOP(OP_GV, 0, (GV*)sv);
1550 if ((SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK)) == SVf_NOK) {
1552 if ((double)iv == SvNV(sv)) { /* can we smush double to int */
1557 SvIOK_off(sv); /* undo SvIV() damage */
1559 return newSVOP(OP_CONST, 0, sv);
1563 if (!(opargs[type] & OA_OTHERINT))
1566 if (!(hints & HINT_INTEGER)) {
1567 if (type == OP_DIVIDE || !(o->op_flags & OPf_KIDS))
1570 for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
1571 if (curop->op_type == OP_CONST) {
1572 if (SvIOK(((SVOP*)curop)->op_sv))
1576 if (opargs[curop->op_type] & OA_RETINTEGER)
1580 o->op_ppaddr = ppaddr[++(o->op_type)];
1587 gen_constant_list(o)
1591 I32 oldtmps_floor = tmps_floor;
1595 return o; /* Don't attempt to run with errors */
1597 op = curop = LINKLIST(o);
1603 tmps_floor = oldtmps_floor;
1605 o->op_type = OP_RV2AV;
1606 o->op_ppaddr = ppaddr[OP_RV2AV];
1607 curop = ((UNOP*)o)->op_first;
1608 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*stack_sp--));
1615 convert(type, flags, op)
1623 if (!op || op->op_type != OP_LIST)
1624 op = newLISTOP(OP_LIST, 0, op, Nullop);
1626 op->op_flags &= ~(OPf_KNOW|OPf_LIST);
1628 if (!(opargs[type] & OA_MARK))
1629 null(cLISTOP->op_first);
1632 op->op_ppaddr = ppaddr[type];
1633 op->op_flags |= flags;
1635 op = CHECKOP(type, op);
1636 if (op->op_type != type)
1639 if (cLISTOP->op_children < 7) {
1640 /* XXX do we really need to do this if we're done appending?? */
1641 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1643 cLISTOP->op_last = last; /* in case check substituted last arg */
1646 return fold_constants(op);
1649 /* List constructors */
1652 append_elem(type, first, last)
1663 if (first->op_type != type || type==OP_LIST && first->op_flags & OPf_PARENS)
1664 return newLISTOP(type, 0, first, last);
1666 if (first->op_flags & OPf_KIDS)
1667 ((LISTOP*)first)->op_last->op_sibling = last;
1669 first->op_flags |= OPf_KIDS;
1670 ((LISTOP*)first)->op_first = last;
1672 ((LISTOP*)first)->op_last = last;
1673 ((LISTOP*)first)->op_children++;
1678 append_list(type, first, last)
1689 if (first->op_type != type)
1690 return prepend_elem(type, (OP*)first, (OP*)last);
1692 if (last->op_type != type)
1693 return append_elem(type, (OP*)first, (OP*)last);
1695 first->op_last->op_sibling = last->op_first;
1696 first->op_last = last->op_last;
1697 first->op_children += last->op_children;
1698 if (first->op_children)
1699 last->op_flags |= OPf_KIDS;
1706 prepend_elem(type, first, last)
1717 if (last->op_type == type) {
1718 if (type == OP_LIST) { /* already a PUSHMARK there */
1719 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
1720 ((LISTOP*)last)->op_first->op_sibling = first;
1723 if (!(last->op_flags & OPf_KIDS)) {
1724 ((LISTOP*)last)->op_last = first;
1725 last->op_flags |= OPf_KIDS;
1727 first->op_sibling = ((LISTOP*)last)->op_first;
1728 ((LISTOP*)last)->op_first = first;
1730 ((LISTOP*)last)->op_children++;
1734 return newLISTOP(type, 0, first, last);
1742 return newOP(OP_STUB, 0);
1749 if (!op || op->op_type != OP_LIST)
1750 op = newLISTOP(OP_LIST, 0, op, Nullop);
1756 newLISTOP(type, flags, first, last)
1764 Newz(1101, listop, 1, LISTOP);
1766 listop->op_type = type;
1767 listop->op_ppaddr = ppaddr[type];
1768 listop->op_children = (first != 0) + (last != 0);
1769 listop->op_flags = flags;
1773 else if (!first && last)
1776 first->op_sibling = last;
1777 listop->op_first = first;
1778 listop->op_last = last;
1779 if (type == OP_LIST) {
1781 pushop = newOP(OP_PUSHMARK, 0);
1782 pushop->op_sibling = first;
1783 listop->op_first = pushop;
1784 listop->op_flags |= OPf_KIDS;
1786 listop->op_last = pushop;
1788 else if (listop->op_children)
1789 listop->op_flags |= OPf_KIDS;
1800 Newz(1101, op, 1, OP);
1802 op->op_ppaddr = ppaddr[type];
1803 op->op_flags = flags;
1806 op->op_private = 0 + (flags >> 8);
1807 if (opargs[type] & OA_RETSCALAR)
1809 if (opargs[type] & OA_TARGET)
1810 op->op_targ = pad_alloc(type, SVs_PADTMP);
1811 return CHECKOP(type, op);
1815 newUNOP(type, flags, first)
1823 first = newOP(OP_STUB, 0);
1824 if (opargs[type] & OA_MARK)
1825 first = force_list(first);
1827 Newz(1101, unop, 1, UNOP);
1828 unop->op_type = type;
1829 unop->op_ppaddr = ppaddr[type];
1830 unop->op_first = first;
1831 unop->op_flags = flags | OPf_KIDS;
1832 unop->op_private = 1 | (flags >> 8);
1834 unop = (UNOP*) CHECKOP(type, unop);
1838 return fold_constants((OP *) unop);
1842 newBINOP(type, flags, first, last)
1849 Newz(1101, binop, 1, BINOP);
1852 first = newOP(OP_NULL, 0);
1854 binop->op_type = type;
1855 binop->op_ppaddr = ppaddr[type];
1856 binop->op_first = first;
1857 binop->op_flags = flags | OPf_KIDS;
1860 binop->op_private = 1 | (flags >> 8);
1863 binop->op_private = 2 | (flags >> 8);
1864 first->op_sibling = last;
1867 binop = (BINOP*)CHECKOP(type, binop);
1871 binop->op_last = last = binop->op_first->op_sibling;
1873 return fold_constants((OP *)binop);
1877 pmtrans(op, expr, repl)
1882 SV *tstr = ((SVOP*)expr)->op_sv;
1883 SV *rstr = ((SVOP*)repl)->op_sv;
1886 register U8 *t = (U8*)SvPV(tstr, tlen);
1887 register U8 *r = (U8*)SvPV(rstr, rlen);
1892 register short *tbl;
1894 tbl = (short*)cPVOP->op_pv;
1895 complement = op->op_private & OPpTRANS_COMPLEMENT;
1896 delete = op->op_private & OPpTRANS_DELETE;
1897 /* squash = op->op_private & OPpTRANS_SQUASH; */
1900 Zero(tbl, 256, short);
1901 for (i = 0; i < tlen; i++)
1903 for (i = 0, j = 0; i < 256; i++) {
1919 if (!rlen && !delete) {
1922 for (i = 0; i < 256; i++)
1924 for (i = 0, j = 0; i < tlen; i++,j++) {
1927 if (tbl[t[i]] == -1)
1933 if (tbl[t[i]] == -1)
1944 newPMOP(type, flags)
1950 Newz(1101, pmop, 1, PMOP);
1951 pmop->op_type = type;
1952 pmop->op_ppaddr = ppaddr[type];
1953 pmop->op_flags = flags;
1954 pmop->op_private = 0 | (flags >> 8);
1956 if (hints & HINT_LOCALE)
1957 pmop->op_pmpermflags = (pmop->op_pmflags |= PMf_LOCALE);
1959 /* link into pm list */
1960 if (type != OP_TRANS && curstash) {
1961 pmop->op_pmnext = HvPMROOT(curstash);
1962 HvPMROOT(curstash) = pmop;
1969 pmruntime(op, expr, repl)
1977 if (op->op_type == OP_TRANS)
1978 return pmtrans(op, expr, repl);
1982 if (expr->op_type == OP_CONST) {
1984 SV *pat = ((SVOP*)expr)->op_sv;
1985 char *p = SvPV(pat, plen);
1986 if ((op->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
1987 sv_setpvn(pat, "\\s+", 3);
1988 p = SvPV(pat, plen);
1989 pm->op_pmflags |= PMf_SKIPWHITE;
1991 pm->op_pmregexp = pregcomp(p, p + plen, pm);
1992 if (strEQ("\\s+", pm->op_pmregexp->precomp))
1993 pm->op_pmflags |= PMf_WHITE;
1998 if (pm->op_pmflags & PMf_KEEP)
1999 expr = newUNOP(OP_REGCMAYBE,0,expr);
2001 Newz(1101, rcop, 1, LOGOP);
2002 rcop->op_type = OP_REGCOMP;
2003 rcop->op_ppaddr = ppaddr[OP_REGCOMP];
2004 rcop->op_first = scalar(expr);
2005 rcop->op_flags |= OPf_KIDS;
2006 rcop->op_private = 1;
2007 rcop->op_other = op;
2009 /* establish postfix order */
2010 if (pm->op_pmflags & PMf_KEEP) {
2012 rcop->op_next = expr;
2013 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
2016 rcop->op_next = LINKLIST(expr);
2017 expr->op_next = (OP*)rcop;
2020 prepend_elem(op->op_type, scalar((OP*)rcop), op);
2025 if (pm->op_pmflags & PMf_EVAL)
2027 else if (repl->op_type == OP_CONST)
2031 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
2032 if (opargs[curop->op_type] & OA_DANGEROUS) {
2033 if (curop->op_type == OP_GV) {
2034 GV *gv = ((GVOP*)curop)->op_gv;
2035 if (strchr("&`'123456789+", *GvENAME(gv)))
2038 else if (curop->op_type == OP_RV2CV)
2040 else if (curop->op_type == OP_RV2SV ||
2041 curop->op_type == OP_RV2AV ||
2042 curop->op_type == OP_RV2HV ||
2043 curop->op_type == OP_RV2GV) {
2044 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
2047 else if (curop->op_type == OP_PADSV ||
2048 curop->op_type == OP_PADAV ||
2049 curop->op_type == OP_PADHV ||
2050 curop->op_type == OP_PADANY) {
2059 if (curop == repl) {
2060 pm->op_pmflags |= PMf_CONST; /* const for long enough */
2061 pm->op_pmpermflags |= PMf_CONST; /* const for long enough */
2062 prepend_elem(op->op_type, scalar(repl), op);
2065 Newz(1101, rcop, 1, LOGOP);
2066 rcop->op_type = OP_SUBSTCONT;
2067 rcop->op_ppaddr = ppaddr[OP_SUBSTCONT];
2068 rcop->op_first = scalar(repl);
2069 rcop->op_flags |= OPf_KIDS;
2070 rcop->op_private = 1;
2071 rcop->op_other = op;
2073 /* establish postfix order */
2074 rcop->op_next = LINKLIST(repl);
2075 repl->op_next = (OP*)rcop;
2077 pm->op_pmreplroot = scalar((OP*)rcop);
2078 pm->op_pmreplstart = LINKLIST(rcop);
2087 newSVOP(type, flags, sv)
2093 Newz(1101, svop, 1, SVOP);
2094 svop->op_type = type;
2095 svop->op_ppaddr = ppaddr[type];
2097 svop->op_next = (OP*)svop;
2098 svop->op_flags = flags;
2099 if (opargs[type] & OA_RETSCALAR)
2101 if (opargs[type] & OA_TARGET)
2102 svop->op_targ = pad_alloc(type, SVs_PADTMP);
2103 return CHECKOP(type, svop);
2107 newGVOP(type, flags, gv)
2113 Newz(1101, gvop, 1, GVOP);
2114 gvop->op_type = type;
2115 gvop->op_ppaddr = ppaddr[type];
2116 gvop->op_gv = (GV*)SvREFCNT_inc(gv);
2117 gvop->op_next = (OP*)gvop;
2118 gvop->op_flags = flags;
2119 if (opargs[type] & OA_RETSCALAR)
2121 if (opargs[type] & OA_TARGET)
2122 gvop->op_targ = pad_alloc(type, SVs_PADTMP);
2123 return CHECKOP(type, gvop);
2127 newPVOP(type, flags, pv)
2133 Newz(1101, pvop, 1, PVOP);
2134 pvop->op_type = type;
2135 pvop->op_ppaddr = ppaddr[type];
2137 pvop->op_next = (OP*)pvop;
2138 pvop->op_flags = flags;
2139 if (opargs[type] & OA_RETSCALAR)
2141 if (opargs[type] & OA_TARGET)
2142 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
2143 return CHECKOP(type, pvop);
2152 save_hptr(&curstash);
2153 save_item(curstname);
2158 name = SvPV(sv, len);
2159 curstash = gv_stashpvn(name,len,TRUE);
2160 sv_setpvn(curstname, name, len);
2164 sv_setpv(curstname,"<none>");
2172 utilize(aver, floor, version, id, arg)
2185 if (id->op_type != OP_CONST)
2186 croak("Module name must be constant");
2190 if(version != Nullop) {
2191 SV *vesv = ((SVOP*)version)->op_sv;
2193 if (arg == Nullop && !SvNIOK(vesv)) {
2200 if (version->op_type != OP_CONST || !SvNIOK(vesv))
2201 croak("Version number must be constant number");
2203 /* Make copy of id so we don't free it twice */
2204 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2206 /* Fake up a method call to VERSION */
2207 meth = newSVOP(OP_CONST, 0, newSVpv("VERSION", 7));
2208 veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2209 append_elem(OP_LIST,
2210 prepend_elem(OP_LIST, pack, list(version)),
2211 newUNOP(OP_METHOD, 0, meth)));
2215 /* Fake up an import/unimport */
2216 if (arg && arg->op_type == OP_STUB)
2217 imop = arg; /* no import on explicit () */
2218 else if(SvNIOK(((SVOP*)id)->op_sv)) {
2219 imop = Nullop; /* use 5.0; */
2222 /* Make copy of id so we don't free it twice */
2223 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2224 meth = newSVOP(OP_CONST, 0,
2226 ? newSVpv("import", 6)
2227 : newSVpv("unimport", 8)
2229 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2230 append_elem(OP_LIST,
2231 prepend_elem(OP_LIST, pack, list(arg)),
2232 newUNOP(OP_METHOD, 0, meth)));
2235 /* Fake up a require */
2236 rqop = newUNOP(OP_REQUIRE, 0, id);
2238 /* Fake up the BEGIN {}, which does its thing immediately. */
2240 newSVOP(OP_CONST, 0, newSVpv("BEGIN", 5)),
2242 append_elem(OP_LINESEQ,
2243 append_elem(OP_LINESEQ,
2244 newSTATEOP(0, Nullch, rqop),
2245 newSTATEOP(0, Nullch, veop)),
2246 newSTATEOP(0, Nullch, imop) ));
2253 newSLICEOP(flags, subscript, listval)
2258 return newBINOP(OP_LSLICE, flags,
2259 list(force_list(subscript)),
2260 list(force_list(listval)) );
2270 if (op->op_type == OP_NULL && op->op_flags & OPf_KIDS)
2271 op = cUNOP->op_first;
2273 if (op->op_type == OP_COND_EXPR) {
2274 I32 t = list_assignment(cCONDOP->op_first->op_sibling);
2275 I32 f = list_assignment(cCONDOP->op_first->op_sibling->op_sibling);
2280 yyerror("Assignment to both a list and a scalar");
2284 if (op->op_type == OP_LIST || op->op_flags & OPf_PARENS ||
2285 op->op_type == OP_RV2AV || op->op_type == OP_RV2HV ||
2286 op->op_type == OP_ASLICE || op->op_type == OP_HSLICE)
2289 if (op->op_type == OP_PADAV || op->op_type == OP_PADHV)
2292 if (op->op_type == OP_RV2SV)
2299 newASSIGNOP(flags, left, optype, right)
2308 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN) {
2309 return newLOGOP(optype, 0,
2310 mod(scalar(left), optype),
2311 newUNOP(OP_SASSIGN, 0, scalar(right)));
2314 return newBINOP(optype, OPf_STACKED,
2315 mod(scalar(left), optype), scalar(right));
2319 if (list_assignment(left)) {
2321 eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2322 left = mod(left, OP_AASSIGN);
2330 op = newBINOP(OP_AASSIGN, flags,
2331 list(force_list(right)),
2332 list(force_list(left)) );
2333 op->op_private = 0 | (flags >> 8);
2334 if (!(left->op_private & OPpLVAL_INTRO)) {
2335 static int generation = 100;
2339 for (curop = LINKLIST(op); curop != op; curop = LINKLIST(curop)) {
2340 if (opargs[curop->op_type] & OA_DANGEROUS) {
2341 if (curop->op_type == OP_GV) {
2342 GV *gv = ((GVOP*)curop)->op_gv;
2343 if (gv == defgv || SvCUR(gv) == generation)
2345 SvCUR(gv) = generation;
2347 else if (curop->op_type == OP_PADSV ||
2348 curop->op_type == OP_PADAV ||
2349 curop->op_type == OP_PADHV ||
2350 curop->op_type == OP_PADANY) {
2351 SV **svp = AvARRAY(comppad_name);
2352 SV *sv = svp[curop->op_targ];
2353 if (SvCUR(sv) == generation)
2355 SvCUR(sv) = generation; /* (SvCUR not used any more) */
2357 else if (curop->op_type == OP_RV2CV)
2359 else if (curop->op_type == OP_RV2SV ||
2360 curop->op_type == OP_RV2AV ||
2361 curop->op_type == OP_RV2HV ||
2362 curop->op_type == OP_RV2GV) {
2363 if (lastop->op_type != OP_GV) /* funny deref? */
2372 op->op_private = OPpASSIGN_COMMON;
2374 if (right && right->op_type == OP_SPLIT) {
2376 if ((tmpop = ((LISTOP*)right)->op_first) &&
2377 tmpop->op_type == OP_PUSHRE)
2379 PMOP *pm = (PMOP*)tmpop;
2380 if (left->op_type == OP_RV2AV &&
2381 !(left->op_private & OPpLVAL_INTRO) &&
2382 !(op->op_private & OPpASSIGN_COMMON) )
2384 tmpop = ((UNOP*)left)->op_first;
2385 if (tmpop->op_type == OP_GV && !pm->op_pmreplroot) {
2386 pm->op_pmreplroot = (OP*)((GVOP*)tmpop)->op_gv;
2387 pm->op_pmflags |= PMf_ONCE;
2388 tmpop = ((UNOP*)op)->op_first; /* to list (nulled) */
2389 tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */
2390 tmpop->op_sibling = Nullop; /* don't free split */
2391 right->op_next = tmpop->op_next; /* fix starting loc */
2392 op_free(op); /* blow off assign */
2393 right->op_flags &= ~(OPf_KNOW|OPf_LIST);
2394 /* "I don't know and I don't care." */
2399 if (modcount < 10000 &&
2400 ((LISTOP*)right)->op_last->op_type == OP_CONST)
2402 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
2404 sv_setiv(sv, modcount+1);
2412 right = newOP(OP_UNDEF, 0);
2413 if (right->op_type == OP_READLINE) {
2414 right->op_flags |= OPf_STACKED;
2415 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
2418 eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2419 op = newBINOP(OP_SASSIGN, flags,
2420 scalar(right), mod(scalar(left), OP_SASSIGN) );
2432 newSTATEOP(flags, label, op)
2437 U32 seq = intro_my();
2440 Newz(1101, cop, 1, COP);
2441 if (perldb && curcop->cop_line && curstash != debstash) {
2442 cop->op_type = OP_DBSTATE;
2443 cop->op_ppaddr = ppaddr[ OP_DBSTATE ];
2446 cop->op_type = OP_NEXTSTATE;
2447 cop->op_ppaddr = ppaddr[ OP_NEXTSTATE ];
2449 cop->op_flags = flags;
2450 cop->op_private = 0 | (flags >> 8);
2452 cop->op_private |= NATIVE_HINTS;
2454 cop->op_next = (OP*)cop;
2457 cop->cop_label = label;
2458 hints |= HINT_BLOCK_SCOPE;
2461 cop->cop_arybase = curcop->cop_arybase;
2463 if (copline == NOLINE)
2464 cop->cop_line = curcop->cop_line;
2466 cop->cop_line = copline;
2469 cop->cop_filegv = (GV*)SvREFCNT_inc(curcop->cop_filegv);
2470 cop->cop_stash = curstash;
2472 if (perldb && curstash != debstash) {
2473 SV **svp = av_fetch(GvAV(curcop->cop_filegv),(I32)cop->cop_line, FALSE);
2474 if (svp && *svp != &sv_undef && !SvIOK(*svp)) {
2475 (void)SvIOK_on(*svp);
2477 SvSTASH(*svp) = (HV*)cop;
2481 return prepend_elem(OP_LINESEQ, (OP*)cop, op);
2484 /* "Introduce" my variables to visible status. */
2492 if (! min_intro_pending)
2495 svp = AvARRAY(comppad_name);
2496 for (i = min_intro_pending; i <= max_intro_pending; i++) {
2497 if ((sv = svp[i]) && sv != &sv_undef && !SvIVX(sv)) {
2498 SvIVX(sv) = 999999999; /* Don't know scope end yet. */
2499 SvNVX(sv) = (double)cop_seqmax;
2502 min_intro_pending = 0;
2503 comppad_name_fill = max_intro_pending; /* Needn't search higher */
2504 return cop_seqmax++;
2508 newLOGOP(type, flags, first, other)
2517 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
2518 return newBINOP(type, flags, scalar(first), scalar(other));
2520 scalarboolean(first);
2521 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
2522 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
2523 if (type == OP_AND || type == OP_OR) {
2529 first = cUNOP->op_first;
2531 first->op_next = op->op_next;
2532 cUNOP->op_first = Nullop;
2536 if (first->op_type == OP_CONST) {
2537 if (dowarn && (first->op_private & OPpCONST_BARE))
2538 warn("Probable precedence problem on %s", op_desc[type]);
2539 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
2548 else if (first->op_type == OP_WANTARRAY) {
2554 else if (dowarn && (first->op_flags & OPf_KIDS)) {
2555 OP *k1 = ((UNOP*)first)->op_first;
2556 OP *k2 = k1->op_sibling;
2558 switch (first->op_type)
2561 if (k2 && k2->op_type == OP_READLINE
2562 && (k2->op_flags & OPf_STACKED)
2563 && (k1->op_type == OP_RV2SV || k1->op_type == OP_PADSV))
2564 warnop = k2->op_type;
2568 if (k1->op_type == OP_READDIR
2569 || k1->op_type == OP_GLOB
2570 || k1->op_type == OP_EACH)
2571 warnop = k1->op_type;
2575 line_t oldline = curcop->cop_line;
2576 curcop->cop_line = copline;
2577 warn("Value of %s%s can be \"0\"; test with defined()",
2579 ((warnop == OP_READLINE || warnop == OP_GLOB)
2580 ? " construct" : "() operator"));
2581 curcop->cop_line = oldline;
2588 if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
2589 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
2591 Newz(1101, logop, 1, LOGOP);
2593 logop->op_type = type;
2594 logop->op_ppaddr = ppaddr[type];
2595 logop->op_first = first;
2596 logop->op_flags = flags | OPf_KIDS;
2597 logop->op_other = LINKLIST(other);
2598 logop->op_private = 1 | (flags >> 8);
2600 /* establish postfix order */
2601 logop->op_next = LINKLIST(first);
2602 first->op_next = (OP*)logop;
2603 first->op_sibling = other;
2605 op = newUNOP(OP_NULL, 0, (OP*)logop);
2606 other->op_next = op;
2612 newCONDOP(flags, first, trueop, falseop)
2622 return newLOGOP(OP_AND, 0, first, trueop);
2624 return newLOGOP(OP_OR, 0, first, falseop);
2626 scalarboolean(first);
2627 if (first->op_type == OP_CONST) {
2628 if (SvTRUE(((SVOP*)first)->op_sv)) {
2639 else if (first->op_type == OP_WANTARRAY) {
2643 Newz(1101, condop, 1, CONDOP);
2645 condop->op_type = OP_COND_EXPR;
2646 condop->op_ppaddr = ppaddr[OP_COND_EXPR];
2647 condop->op_first = first;
2648 condop->op_flags = flags | OPf_KIDS;
2649 condop->op_true = LINKLIST(trueop);
2650 condop->op_false = LINKLIST(falseop);
2651 condop->op_private = 1 | (flags >> 8);
2653 /* establish postfix order */
2654 condop->op_next = LINKLIST(first);
2655 first->op_next = (OP*)condop;
2657 first->op_sibling = trueop;
2658 trueop->op_sibling = falseop;
2659 op = newUNOP(OP_NULL, 0, (OP*)condop);
2661 trueop->op_next = op;
2662 falseop->op_next = op;
2668 newRANGE(flags, left, right)
2678 Newz(1101, condop, 1, CONDOP);
2680 condop->op_type = OP_RANGE;
2681 condop->op_ppaddr = ppaddr[OP_RANGE];
2682 condop->op_first = left;
2683 condop->op_flags = OPf_KIDS;
2684 condop->op_true = LINKLIST(left);
2685 condop->op_false = LINKLIST(right);
2686 condop->op_private = 1 | (flags >> 8);
2688 left->op_sibling = right;
2690 condop->op_next = (OP*)condop;
2691 flip = newUNOP(OP_FLIP, flags, (OP*)condop);
2692 flop = newUNOP(OP_FLOP, 0, flip);
2693 op = newUNOP(OP_NULL, 0, flop);
2696 left->op_next = flip;
2697 right->op_next = flop;
2699 condop->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2700 sv_upgrade(PAD_SV(condop->op_targ), SVt_PVNV);
2701 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2702 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
2704 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2705 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2708 if (!flip->op_private || !flop->op_private)
2709 linklist(op); /* blow off optimizer unless constant */
2715 newLOOPOP(flags, debuggable, expr, block)
2723 int once = block && block->op_flags & OPf_SPECIAL &&
2724 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
2727 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
2728 return block; /* do {} while 0 does once */
2729 if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB) {
2730 expr = newUNOP(OP_DEFINED, 0,
2731 newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr) );
2735 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
2736 op = newLOGOP(OP_AND, 0, expr, listop);
2738 ((LISTOP*)listop)->op_last->op_next = LINKLIST(op);
2740 if (once && op != listop)
2741 op->op_next = ((LOGOP*)cUNOP->op_first)->op_other;
2744 op = newUNOP(OP_NULL, 0, op); /* or do {} while 1 loses outer block */
2746 op->op_flags |= flags;
2748 op->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/
2753 newWHILEOP(flags, debuggable, loop, expr, block, cont)
2767 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB)) {
2768 expr = newUNOP(OP_DEFINED, 0,
2769 newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr) );
2773 block = newOP(OP_NULL, 0);
2776 next = LINKLIST(cont);
2778 cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
2780 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
2781 redo = LINKLIST(listop);
2784 op = newLOGOP(OP_AND, 0, expr, scalar(listop));
2785 if (op == expr && op->op_type == OP_CONST && !SvTRUE(cSVOP->op_sv)) {
2786 op_free(expr); /* oops, it's a while (0) */
2788 return Nullop; /* (listop already freed by newLOGOP) */
2790 ((LISTOP*)listop)->op_last->op_next = condop =
2791 (op == listop ? redo : LINKLIST(op));
2799 Newz(1101,loop,1,LOOP);
2800 loop->op_type = OP_ENTERLOOP;
2801 loop->op_ppaddr = ppaddr[OP_ENTERLOOP];
2802 loop->op_private = 0;
2803 loop->op_next = (OP*)loop;
2806 op = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, op);
2808 loop->op_redoop = redo;
2809 loop->op_lastop = op;
2812 loop->op_nextop = next;
2814 loop->op_nextop = op;
2816 op->op_flags |= flags;
2817 op->op_private |= (flags >> 8);
2822 #ifndef CAN_PROTOTYPE
2823 newFOROP(flags,label,forline,sv,expr,block,cont)
2832 newFOROP(I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
2833 #endif /* CAN_PROTOTYPE */
2841 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
2842 sv->op_type = OP_RV2GV;
2843 sv->op_ppaddr = ppaddr[OP_RV2GV];
2845 else if (sv->op_type == OP_PADSV) { /* private variable */
2846 padoff = sv->op_targ;
2851 croak("Can't use %s for loop variable", op_desc[sv->op_type]);
2854 sv = newGVOP(OP_GV, 0, defgv);
2856 if (expr->op_type == OP_RV2AV || expr->op_type == OP_PADAV) {
2857 expr = scalar(ref(expr, OP_ITER));
2858 iterflags |= OPf_STACKED;
2860 loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
2861 append_elem(OP_LIST, mod(force_list(expr), OP_GREPSTART),
2863 assert(!loop->op_next);
2864 Renew(loop, 1, LOOP);
2865 loop->op_targ = padoff;
2866 return newSTATEOP(0, label, newWHILEOP(flags, 1, loop,
2867 newOP(OP_ITER, 0), block, cont));
2871 newLOOPEX(type, label)
2876 if (type != OP_GOTO || label->op_type == OP_CONST) {
2877 op = newPVOP(type, 0, savepv(
2878 label->op_type == OP_CONST
2879 ? SvPVx(((SVOP*)label)->op_sv, na)
2884 if (label->op_type == OP_ENTERSUB)
2885 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
2886 op = newUNOP(type, OPf_STACKED, label);
2888 hints |= HINT_BLOCK_SCOPE;
2896 if (!CvXSUB(cv) && CvROOT(cv)) {
2898 croak("Can't undef active subroutine");
2905 op_free(CvROOT(cv));
2906 CvROOT(cv) = Nullop;
2910 SvREFCNT_dec(CvGV(cv));
2912 SvREFCNT_dec(CvOUTSIDE(cv));
2913 CvOUTSIDE(cv) = Nullcv;
2914 if (CvPADLIST(cv)) {
2915 /* may be during global destruction */
2916 if (SvREFCNT(CvPADLIST(cv))) {
2917 I32 i = AvFILL(CvPADLIST(cv));
2919 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
2923 SvREFCNT_dec((SV*)CvPADLIST(cv));
2925 CvPADLIST(cv) = Nullav;
2929 #ifdef DEBUG_CLOSURES
2934 CV *outside = CvOUTSIDE(cv);
2935 AV* padlist = CvPADLIST(cv);
2942 PerlIO_printf(Perl_debug_log, "\tCV=0x%p (%s), OUTSIDE=0x%p (%s)\n",
2944 (CvANON(cv) ? "ANON"
2945 : (cv == main_cv) ? "MAIN"
2946 : CvUNIQUE(outside) ? "UNIQUE"
2947 : CvGV(cv) ? GvNAME(CvGV(cv)) : "UNDEFINED"),
2950 : CvANON(outside) ? "ANON"
2951 : (outside == main_cv) ? "MAIN"
2952 : CvUNIQUE(outside) ? "UNIQUE"
2953 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
2958 pad_name = (AV*)*av_fetch(padlist, 0, FALSE);
2959 pad = (AV*)*av_fetch(padlist, 1, FALSE);
2960 pname = AvARRAY(pad_name);
2961 ppad = AvARRAY(pad);
2963 for (ix = 1; ix <= AvFILL(pad_name); ix++) {
2964 if (SvPOK(pname[ix]))
2965 PerlIO_printf(Perl_debug_log, "\t%4d. 0x%p (%s\"%s\" %ld-%ld)\n",
2967 SvFAKE(pname[ix]) ? "FAKE " : "",
2969 (long)I_32(SvNVX(pname[ix])),
2970 (long)SvIVX(pname[ix]));
2973 #endif /* DEBUG_CLOSURES */
2976 cv_clone2(proto, outside)
2982 AV* protopadlist = CvPADLIST(proto);
2983 AV* protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
2984 AV* protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
2985 SV** pname = AvARRAY(protopad_name);
2986 SV** ppad = AvARRAY(protopad);
2987 I32 fname = AvFILL(protopad_name);
2988 I32 fpad = AvFILL(protopad);
2992 assert(!CvUNIQUE(proto));
2999 cv = compcv = (CV*)NEWSV(1104,0);
3000 sv_upgrade((SV *)cv, SvTYPE(proto));
3005 CvFILEGV(cv) = CvFILEGV(proto);
3006 CvGV(cv) = (GV*)SvREFCNT_inc(CvGV(proto));
3007 CvSTASH(cv) = CvSTASH(proto);
3008 CvROOT(cv) = CvROOT(proto);
3009 CvSTART(cv) = CvSTART(proto);
3011 CvOUTSIDE(cv) = (CV*)SvREFCNT_inc(outside);
3014 sv_setpvn((SV*)cv, SvPVX(proto), SvCUR(proto));
3018 comppadlist = newAV();
3019 AvREAL_off(comppadlist);
3020 av_store(comppadlist, 0, SvREFCNT_inc((SV*)protopad_name));
3021 av_store(comppadlist, 1, (SV*)comppad);
3022 CvPADLIST(cv) = comppadlist;
3023 av_fill(comppad, AvFILL(protopad));
3024 curpad = AvARRAY(comppad);
3026 av = newAV(); /* will be @_ */
3028 av_store(comppad, 0, (SV*)av);
3029 AvFLAGS(av) = AVf_REIFY;
3031 for (ix = fpad; ix > 0; ix--) {
3032 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
3033 if (namesv && namesv != &sv_undef) {
3034 char *name = SvPVX(namesv); /* XXX */
3035 if (SvFLAGS(namesv) & SVf_FAKE) { /* lexical from outside? */
3036 I32 off = pad_findlex(name, ix, SvIVX(namesv),
3037 CvOUTSIDE(cv), cxstack_ix);
3039 curpad[ix] = SvREFCNT_inc(ppad[ix]);
3041 croak("panic: cv_clone: %s", name);
3043 else { /* our own lexical */
3046 /* anon code -- we'll come back for it */
3047 sv = SvREFCNT_inc(ppad[ix]);
3049 else if (*name == '@')
3051 else if (*name == '%')
3061 SV* sv = NEWSV(0,0);
3067 /* Now that vars are all in place, clone nested closures. */
3069 for (ix = fpad; ix > 0; ix--) {
3070 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
3072 && namesv != &sv_undef
3073 && !(SvFLAGS(namesv) & SVf_FAKE)
3074 && *SvPVX(namesv) == '&'
3075 && CvCLONE(ppad[ix]))
3077 CV *kid = cv_clone2((CV*)ppad[ix], cv);
3078 SvREFCNT_dec(ppad[ix]);
3081 curpad[ix] = (SV*)kid;
3085 #ifdef DEBUG_CLOSURES
3086 PerlIO_printf(Perl_debug_log, "Cloned inside:\n");
3088 PerlIO_printf(Perl_debug_log, " from:\n");
3090 PerlIO_printf(Perl_debug_log, " to:\n");
3102 return cv_clone2(proto, CvOUTSIDE(proto));
3106 cv_ckproto(cv, gv, p)
3111 if ((!p != !SvPOK(cv)) || (p && strNE(p, SvPVX(cv)))) {
3116 gv_efullname3(name = NEWSV(606, 40), gv, Nullch);
3117 New(607, buf, ((name ? SvCUR(name) : 0)
3118 + (SvPOK(cv) ? SvCUR(cv) : 0)
3119 + (p ? strlen(p) : 0)
3121 strcpy(buf, "Prototype mismatch:");
3123 sprintf(buf + strlen(buf), " sub %s", SvPVX(name));
3127 sprintf(buf + strlen(buf), " (%s)", SvPVX(cv));
3128 strcat(buf, " vs ");
3129 sprintf(buf + strlen(buf), p ? "(%s)" : "none", p);
3142 if(cv && SvPOK(cv) && !SvCUR(cv)) {
3143 for (o = CvSTART(cv); o; o = o->op_next) {
3144 OPCODE type = o->op_type;
3146 if (type == OP_NEXTSTATE || type == OP_NULL || type == OP_PUSHMARK)
3148 if (type == OP_LEAVESUB || type == OP_RETURN)
3150 if (type != OP_CONST || sv)
3153 sv = ((SVOP*)o)->op_sv;
3160 newSUB(floor,op,proto,block)
3166 char *name = op ? SvPVx(cSVOP->op_sv, na) : Nullch;
3167 GV *gv = gv_fetchpv(name ? name : "__ANON__", GV_ADDMULTI, SVt_PVCV);
3168 char *ps = proto ? SvPVx(((SVOP*)proto)->op_sv, na) : Nullch;
3178 if (!name || GvCVGEN(gv))
3180 else if (cv = GvCV(gv)) {
3181 cv_ckproto(cv, gv, ps);
3182 /* already defined (or promised)? */
3183 if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
3186 /* just a "sub foo;" when &foo is already defined */
3190 const_sv = cv_const_sv(cv);
3191 if (const_sv || dowarn) {
3192 line_t oldline = curcop->cop_line;
3193 curcop->cop_line = copline;
3194 warn(const_sv ? "Constant subroutine %s redefined"
3195 : "Subroutine %s redefined", name);
3196 curcop->cop_line = oldline;
3202 if (cv) { /* must reuse cv if autoloaded */
3204 CvFLAGS(cv) = CvFLAGS(compcv);
3205 CvOUTSIDE(cv) = CvOUTSIDE(compcv);
3206 CvOUTSIDE(compcv) = 0;
3207 CvPADLIST(cv) = CvPADLIST(compcv);
3208 CvPADLIST(compcv) = 0;
3209 if (SvREFCNT(compcv) > 1) /* XXX Make closures transit through stub. */
3210 CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc((SV*)cv);
3211 SvREFCNT_dec(compcv);
3221 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
3222 CvFILEGV(cv) = curcop->cop_filegv;
3223 CvSTASH(cv) = curstash;
3226 sv_setpv((SV*)cv, ps);
3232 char *s = strrchr(name, ':');
3234 if (strEQ(s, "BEGIN"))
3235 croak("BEGIN not safe after errors--compilation aborted");
3244 av = newAV(); /* Will be @_ */
3246 av_store(comppad, 0, (SV*)av);
3247 AvFLAGS(av) = AVf_REIFY;
3249 for (ix = AvFILL(comppad); ix > 0; ix--) {
3250 if (!SvPADMY(curpad[ix]) && !SvIMMORTAL(curpad[ix]))
3251 SvPADTMP_on(curpad[ix]);
3254 if (AvFILL(comppad_name) < AvFILL(comppad))
3255 av_store(comppad_name, AvFILL(comppad), Nullsv);
3257 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
3258 CvSTART(cv) = LINKLIST(CvROOT(cv));
3259 CvROOT(cv)->op_next = 0;
3265 if (perldb && curstash != debstash) {
3267 SV *tmpstr = sv_newmortal();
3268 static GV *db_postponed;
3272 sprintf(buf, "%s:%ld",
3273 SvPVX(GvSV(curcop->cop_filegv)), (long)subline);
3274 sv = newSVpv(buf,0);
3276 sprintf(buf,"%ld",(long)curcop->cop_line);
3278 gv_efullname3(tmpstr, gv, Nullch);
3279 hv_store(GvHV(DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
3280 if (!db_postponed) {
3281 db_postponed = gv_fetchpv("DB::postponed", GV_ADDMULTI, SVt_PVHV);
3283 hv = GvHVn(db_postponed);
3284 if (HvFILL(hv) > 0 && hv_exists(hv, SvPVX(tmpstr), SvCUR(tmpstr))
3285 && (cv = GvCV(db_postponed))) {
3290 perl_call_sv((SV*)cv, G_DISCARD);
3294 if ((s = strrchr(name,':')))
3298 if (strEQ(s, "BEGIN")) {
3299 I32 oldscope = scopestack_ix;
3301 SAVESPTR(compiling.cop_filegv);
3302 SAVEI16(compiling.cop_line);
3309 DEBUG_x( dump_sub(gv) );
3310 av_push(beginav, (SV *)cv);
3312 call_list(oldscope, beginav);
3314 curcop = &compiling;
3317 else if (strEQ(s, "END") && !error_count) {
3320 av_unshift(endav, 1);
3321 av_store(endav, 0, (SV *)cv);
3334 newXSUB(name, ix, subaddr, filename)
3340 CV* cv = newXS(name, (void(*)())subaddr, filename);
3342 CvXSUBANY(cv).any_i32 = ix;
3348 newXS(name, subaddr, filename)
3350 void (*subaddr) _((CV*));
3353 GV *gv = gv_fetchpv(name ? name : "__ANON__", GV_ADDMULTI, SVt_PVCV);
3356 if (cv = (name ? GvCV(gv) : Nullcv)) {
3358 /* just a cached method */
3362 else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
3363 /* already defined (or promised) */
3365 line_t oldline = curcop->cop_line;
3366 curcop->cop_line = copline;
3367 warn("Subroutine %s redefined",name);
3368 curcop->cop_line = oldline;
3375 if (cv) /* must reuse cv if autoloaded */
3378 cv = (CV*)NEWSV(1105,0);
3379 sv_upgrade((SV *)cv, SVt_PVCV);
3386 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
3387 CvFILEGV(cv) = gv_fetchfile(filename);
3388 CvXSUB(cv) = subaddr;
3391 char *s = strrchr(name,':');
3396 if (strEQ(s, "BEGIN")) {
3399 av_push(beginav, (SV *)cv);
3402 else if (strEQ(s, "END")) {
3405 av_unshift(endav, 1);
3406 av_store(endav, 0, (SV *)cv);
3417 newFORM(floor,op,block)
3428 name = SvPVx(cSVOP->op_sv, na);
3431 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
3433 if (cv = GvFORM(gv)) {
3435 line_t oldline = curcop->cop_line;
3437 curcop->cop_line = copline;
3438 warn("Format %s redefined",name);
3439 curcop->cop_line = oldline;
3445 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
3446 CvFILEGV(cv) = curcop->cop_filegv;
3448 for (ix = AvFILL(comppad); ix > 0; ix--) {
3449 if (!SvPADMY(curpad[ix]) && !SvIMMORTAL(curpad[ix]))
3450 SvPADTMP_on(curpad[ix]);
3453 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
3454 CvSTART(cv) = LINKLIST(CvROOT(cv));
3455 CvROOT(cv)->op_next = 0;
3466 return newUNOP(OP_REFGEN, 0,
3467 mod(list(convert(OP_ANONLIST, 0, op)), OP_REFGEN));
3474 return newUNOP(OP_REFGEN, 0,
3475 mod(list(convert(OP_ANONHASH, 0, op)), OP_REFGEN));
3479 newANONSUB(floor, proto, block)
3484 return newUNOP(OP_REFGEN, 0,
3485 newSVOP(OP_ANONCODE, 0, (SV*)newSUB(floor, 0, proto, block)));
3492 switch (o->op_type) {
3494 o->op_type = OP_PADAV;
3495 o->op_ppaddr = ppaddr[OP_PADAV];
3496 return ref(newUNOP(OP_RV2AV, 0, scalar(o)), OP_RV2AV);
3499 o->op_type = OP_RV2AV;
3500 o->op_ppaddr = ppaddr[OP_RV2AV];
3505 warn("oops: oopsAV");
3515 switch (o->op_type) {
3518 o->op_type = OP_PADHV;
3519 o->op_ppaddr = ppaddr[OP_PADHV];
3520 return ref(newUNOP(OP_RV2HV, 0, scalar(o)), OP_RV2HV);
3524 o->op_type = OP_RV2HV;
3525 o->op_ppaddr = ppaddr[OP_RV2HV];
3530 warn("oops: oopsHV");
3540 if (o->op_type == OP_PADANY) {
3541 o->op_type = OP_PADAV;
3542 o->op_ppaddr = ppaddr[OP_PADAV];
3545 return newUNOP(OP_RV2AV, 0, scalar(o));
3553 if (type == OP_MAPSTART)
3554 return newUNOP(OP_NULL, 0, o);
3555 return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
3562 if (o->op_type == OP_PADANY) {
3563 o->op_type = OP_PADHV;
3564 o->op_ppaddr = ppaddr[OP_PADHV];
3567 return newUNOP(OP_RV2HV, 0, scalar(o));
3574 croak("NOT IMPL LINE %d",__LINE__);
3584 return newUNOP(OP_RV2CV, flags, scalar(o));
3591 if (o->op_type == OP_PADANY) {
3592 o->op_type = OP_PADSV;
3593 o->op_ppaddr = ppaddr[OP_PADSV];
3596 return newUNOP(OP_RV2SV, 0, scalar(o));
3599 /* Check routines. */
3608 name = NEWSV(1106,0);
3609 sv_upgrade(name, SVt_PVNV);
3610 sv_setpvn(name, "&", 1);
3613 ix = pad_alloc(op->op_type, SVs_PADMY);
3614 av_store(comppad_name, ix, name);
3615 av_store(comppad, ix, cSVOP->op_sv);
3616 SvPADMY_on(cSVOP->op_sv);
3617 cSVOP->op_sv = Nullsv;
3618 cSVOP->op_targ = ix;
3626 op->op_private = hints;
3634 if (cUNOP->op_first->op_type == OP_CONCAT)
3635 op->op_flags |= OPf_STACKED;
3643 if (op->op_flags & OPf_KIDS) {
3646 OPCODE type = op->op_type;
3647 op = modkids(ck_fun(op), type);
3648 kid = cUNOP->op_first;
3649 newop = kUNOP->op_first->op_sibling;
3651 (newop->op_sibling ||
3652 !(opargs[newop->op_type] & OA_RETSCALAR) ||
3653 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
3654 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
3658 op_free(kUNOP->op_first);
3659 kUNOP->op_first = newop;
3661 op->op_ppaddr = ppaddr[++op->op_type];
3671 if (op->op_flags & OPf_KIDS) {
3672 OP *kid = cUNOP->op_first;
3673 if (kid->op_type == OP_HSLICE)
3674 op->op_private |= OPpSLICE;
3675 else if (kid->op_type != OP_HELEM)
3676 croak("%s argument is not a HASH element or slice",
3677 op_desc[op->op_type]);
3687 I32 type = op->op_type;
3689 if (op->op_flags & OPf_KIDS) {
3690 if (cLISTOP->op_first->op_type == OP_STUB) {
3692 op = newUNOP(type, OPf_SPECIAL,
3693 newGVOP(OP_GV, 0, gv_fetchpv("main'ARGV", TRUE, SVt_PVAV)));
3704 hints |= HINT_BLOCK_SCOPE;
3705 if (op->op_flags & OPf_KIDS) {
3706 SVOP *kid = (SVOP*)cUNOP->op_first;
3709 op->op_flags &= ~OPf_KIDS;
3712 else if (kid->op_type == OP_LINESEQ) {
3715 kid->op_next = op->op_next;
3716 cUNOP->op_first = 0;
3719 Newz(1101, enter, 1, LOGOP);
3720 enter->op_type = OP_ENTERTRY;
3721 enter->op_ppaddr = ppaddr[OP_ENTERTRY];
3722 enter->op_private = 0;
3724 /* establish postfix order */
3725 enter->op_next = (OP*)enter;
3727 op = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
3728 op->op_type = OP_LEAVETRY;
3729 op->op_ppaddr = ppaddr[OP_LEAVETRY];
3730 enter->op_other = op;
3736 op = newUNOP(OP_ENTEREVAL, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3738 op->op_targ = (PADOFFSET)hints;
3747 if (op->op_flags & OPf_STACKED) {
3749 kid = cUNOP->op_first->op_sibling;
3750 if (kid->op_type == OP_RV2GV)
3763 if (op->op_flags & OPf_KIDS) {
3764 OP *kid = cUNOP->op_first;
3765 if (kid->op_type != OP_HELEM)
3766 croak("%s argument is not a HASH element", op_desc[op->op_type]);
3776 o = fold_constants(o);
3777 if (o->op_type == OP_CONST)
3786 SVOP *kid = (SVOP*)cUNOP->op_first;
3788 op->op_private |= (hints & HINT_STRICT_REFS);
3789 if (kid->op_type == OP_CONST) {
3794 name = SvPV(kid->op_sv, na);
3795 if ((hints & HINT_STRICT_REFS) && (kid->op_private & OPpCONST_BARE)) {
3796 char *badthing = Nullch;
3797 switch (op->op_type) {
3799 badthing = "a SCALAR";
3802 badthing = "an ARRAY";
3805 badthing = "a HASH";
3810 "Can't use bareword (\"%s\") as %s ref while \"strict refs\" in use",
3813 kid->op_type = OP_GV;
3814 iscv = (op->op_type == OP_RV2CV) * 2;
3815 for (gv = 0; !gv; iscv++) {
3817 * This is a little tricky. We only want to add the symbol if we
3818 * didn't add it in the lexer. Otherwise we get duplicate strict
3819 * warnings. But if we didn't add it in the lexer, we must at
3820 * least pretend like we wanted to add it even if it existed before,
3821 * or we get possible typo warnings. OPpCONST_ENTERED says
3822 * whether the lexer already added THIS instance of this symbol.
3824 gv = gv_fetchpv(name,
3825 iscv | !(kid->op_private & OPpCONST_ENTERED),
3828 : op->op_type == OP_RV2SV
3830 : op->op_type == OP_RV2AV
3832 : op->op_type == OP_RV2HV
3836 SvREFCNT_dec(kid->op_sv);
3837 kid->op_sv = SvREFCNT_inc(gv);
3846 I32 type = op->op_type;
3848 if (op->op_flags & OPf_REF)
3851 if (op->op_flags & OPf_KIDS) {
3852 SVOP *kid = (SVOP*)cUNOP->op_first;
3854 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
3855 OP *newop = newGVOP(type, OPf_REF,
3856 gv_fetchpv(SvPVx(kid->op_sv, na), TRUE, SVt_PVIO));
3863 if (type == OP_FTTTY)
3864 return newGVOP(type, OPf_REF, gv_fetchpv("main'STDIN", TRUE,
3867 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3880 int type = op->op_type;
3881 register I32 oa = opargs[type] >> OASHIFT;
3883 if (op->op_flags & OPf_STACKED) {
3884 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
3887 return no_fh_allowed(op);
3890 if (op->op_flags & OPf_KIDS) {
3891 tokid = &cLISTOP->op_first;
3892 kid = cLISTOP->op_first;
3893 if (kid->op_type == OP_PUSHMARK ||
3894 kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK)
3896 tokid = &kid->op_sibling;
3897 kid = kid->op_sibling;
3899 if (!kid && opargs[type] & OA_DEFGV)
3900 *tokid = kid = newSVREF(newGVOP(OP_GV, 0, defgv));
3904 sibl = kid->op_sibling;
3918 if (kid->op_type == OP_CONST &&
3919 (kid->op_private & OPpCONST_BARE)) {
3920 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
3921 OP *newop = newAVREF(newGVOP(OP_GV, 0,
3922 gv_fetchpv(name, TRUE, SVt_PVAV) ));
3924 warn("Array @%s missing the @ in argument %ld of %s()",
3925 name, (long)numargs, op_desc[type]);
3928 kid->op_sibling = sibl;
3931 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
3932 bad_type(numargs, "array", op_desc[op->op_type], kid);
3936 if (kid->op_type == OP_CONST &&
3937 (kid->op_private & OPpCONST_BARE)) {
3938 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
3939 OP *newop = newHVREF(newGVOP(OP_GV, 0,
3940 gv_fetchpv(name, TRUE, SVt_PVHV) ));
3942 warn("Hash %%%s missing the %% in argument %ld of %s()",
3943 name, (long)numargs, op_desc[type]);
3946 kid->op_sibling = sibl;
3949 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
3950 bad_type(numargs, "hash", op_desc[op->op_type], kid);
3955 OP *newop = newUNOP(OP_NULL, 0, kid);
3956 kid->op_sibling = 0;
3958 newop->op_next = newop;
3960 kid->op_sibling = sibl;
3965 if (kid->op_type != OP_GV) {
3966 if (kid->op_type == OP_CONST &&
3967 (kid->op_private & OPpCONST_BARE)) {
3968 OP *newop = newGVOP(OP_GV, 0,
3969 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, na), TRUE,
3975 kid->op_sibling = 0;
3976 kid = newUNOP(OP_RV2GV, 0, scalar(kid));
3978 kid->op_sibling = sibl;
3984 mod(scalar(kid), type);
3988 tokid = &kid->op_sibling;
3989 kid = kid->op_sibling;
3991 op->op_private |= numargs;
3993 return too_many_arguments(op,op_desc[op->op_type]);
3996 else if (opargs[type] & OA_DEFGV) {
3998 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
4002 while (oa & OA_OPTIONAL)
4004 if (oa && oa != OA_LIST)
4005 return too_few_arguments(op,op_desc[op->op_type]);
4014 GV *gv = gv_fetchpv("glob", FALSE, SVt_PVCV);
4016 if (gv && GvIMPORTED_CV(gv)) {
4017 op->op_type = OP_LIST;
4018 op->op_ppaddr = ppaddr[OP_LIST];
4019 op = newUNOP(OP_ENTERSUB, OPf_STACKED,
4020 append_elem(OP_LIST, op,
4021 scalar(newUNOP(OP_RV2CV, 0,
4022 newGVOP(OP_GV, 0, gv)))));
4025 if ((op->op_flags & OPf_KIDS) && !cLISTOP->op_first->op_sibling)
4026 append_elem(OP_GLOB, op, newSVREF(newGVOP(OP_GV, 0, defgv)));
4027 gv = newGVgen("main");
4029 append_elem(OP_GLOB, op, newGVOP(OP_GV, 0, gv));
4040 OPCODE type = op->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
4042 op->op_ppaddr = ppaddr[OP_GREPSTART];
4043 Newz(1101, gwop, 1, LOGOP);
4045 if (op->op_flags & OPf_STACKED) {
4048 kid = cLISTOP->op_first->op_sibling;
4049 for (k = cLISTOP->op_first->op_sibling->op_next; k; k = k->op_next) {
4052 kid->op_next = (OP*)gwop;
4053 op->op_flags &= ~OPf_STACKED;
4055 kid = cLISTOP->op_first->op_sibling;
4056 if (type == OP_MAPWHILE)
4063 kid = cLISTOP->op_first->op_sibling;
4064 if (kid->op_type != OP_NULL)
4065 croak("panic: ck_grep");
4066 kid = kUNOP->op_first;
4068 gwop->op_type = type;
4069 gwop->op_ppaddr = ppaddr[type];
4070 gwop->op_first = listkids(op);
4071 gwop->op_flags |= OPf_KIDS;
4072 gwop->op_private = 1;
4073 gwop->op_other = LINKLIST(kid);
4074 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
4075 kid->op_next = (OP*)gwop;
4077 kid = cLISTOP->op_first->op_sibling;
4078 if (!kid || !kid->op_sibling)
4079 return too_few_arguments(op,op_desc[op->op_type]);
4080 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
4081 mod(kid, OP_GREPSTART);
4090 if (op->op_flags & OPf_KIDS) {
4091 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
4092 if (kid && kid->op_type == OP_CONST)
4093 fbm_compile(((SVOP*)kid)->op_sv);
4102 /* XXX length optimization goes here */
4110 OPCODE type = op->op_type;
4111 return modkids(ck_fun(op), type);
4118 OPCODE type = op->op_type;
4119 return refkids(ck_fun(op), type);
4128 kid = cLISTOP->op_first;
4130 op = force_list(op);
4131 kid = cLISTOP->op_first;
4133 if (kid->op_type == OP_PUSHMARK)
4134 kid = kid->op_sibling;
4135 if (kid && op->op_flags & OPf_STACKED)
4136 kid = kid->op_sibling;
4137 else if (kid && !kid->op_sibling) { /* print HANDLE; */
4138 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
4139 op->op_flags |= OPf_STACKED; /* make it a filehandle */
4140 kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
4141 cLISTOP->op_first->op_sibling = kid;
4142 cLISTOP->op_last = kid;
4143 kid = kid->op_sibling;
4148 append_elem(op->op_type, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
4154 if (hints & HINT_LOCALE)
4155 op->op_private |= OPpLOCALE;
4169 if (hints & HINT_LOCALE)
4170 op->op_private |= OPpLOCALE;
4182 if (hints & HINT_LOCALE)
4183 op->op_private |= OPpLOCALE;
4193 cPMOP->op_pmflags |= PMf_RUNTIME;
4194 cPMOP->op_pmpermflags |= PMf_RUNTIME;
4209 if (cBINOP->op_first->op_flags & OPf_PARENS) {
4210 op->op_private |= OPpREPEAT_DOLIST;
4211 cBINOP->op_first = force_list(cBINOP->op_first);
4222 if (op->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
4223 SVOP *kid = (SVOP*)cUNOP->op_first;
4225 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
4227 for (s = SvPVX(kid->op_sv); *s; s++) {
4228 if (*s == ':' && s[1] == ':') {
4230 Move(s+2, s+1, strlen(s+2)+1, char);
4231 --SvCUR(kid->op_sv);
4234 sv_catpvn(kid->op_sv, ".pm", 3);
4244 croak("NOT IMPL LINE %d",__LINE__);
4254 if (op->op_flags & OPf_KIDS) {
4255 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
4256 if (kid && kid->op_sibling) {
4257 op->op_type = OP_SSELECT;
4258 op->op_ppaddr = ppaddr[OP_SSELECT];
4260 return fold_constants(op);
4264 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
4265 if (kid && kid->op_type == OP_RV2GV)
4266 kid->op_private &= ~HINT_STRICT_REFS;
4274 I32 type = op->op_type;
4276 if (!(op->op_flags & OPf_KIDS)) {
4278 return newUNOP(type, 0,
4279 scalar(newUNOP(OP_RV2AV, 0,
4280 scalar(newGVOP(OP_GV, 0, subline
4282 : gv_fetchpv("ARGV", TRUE, SVt_PVAV) )))));
4284 return scalar(modkids(ck_fun(op), type));
4293 if (hints & HINT_LOCALE)
4294 op->op_private |= OPpLOCALE;
4297 if (op->op_flags & OPf_STACKED) {
4298 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
4300 kid = kUNOP->op_first; /* get past rv2gv */
4302 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
4304 if (kid->op_type == OP_SCOPE) {
4308 else if (kid->op_type == OP_LEAVE) {
4309 if (op->op_type == OP_SORT) {
4310 null(kid); /* wipe out leave */
4313 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
4314 if (k->op_next == kid)
4319 kid->op_next = 0; /* just disconnect the leave */
4320 k = kLISTOP->op_first;
4324 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
4325 null(kid); /* wipe out rv2gv */
4326 if (op->op_type == OP_SORT)
4330 op->op_flags |= OPf_SPECIAL;
4344 if (op->op_flags & OPf_STACKED)
4345 return no_fh_allowed(op);
4347 kid = cLISTOP->op_first;
4348 if (kid->op_type != OP_NULL)
4349 croak("panic: ck_split");
4350 kid = kid->op_sibling;
4351 op_free(cLISTOP->op_first);
4352 cLISTOP->op_first = kid;
4354 cLISTOP->op_first = kid = newSVOP(OP_CONST, 0, newSVpv(" ", 1));
4355 cLISTOP->op_last = kid; /* There was only one element previously */
4358 if (kid->op_type != OP_MATCH) {
4359 OP *sibl = kid->op_sibling;
4360 kid->op_sibling = 0;
4361 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
4362 if (cLISTOP->op_first == cLISTOP->op_last)
4363 cLISTOP->op_last = kid;
4364 cLISTOP->op_first = kid;
4365 kid->op_sibling = sibl;
4368 if (pm->op_pmshort && !(pm->op_pmflags & PMf_ALL)) {
4369 SvREFCNT_dec(pm->op_pmshort); /* can't use substring to optimize */
4373 kid->op_type = OP_PUSHRE;
4374 kid->op_ppaddr = ppaddr[OP_PUSHRE];
4377 if (!kid->op_sibling)
4378 append_elem(OP_SPLIT, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
4380 kid = kid->op_sibling;
4383 if (!kid->op_sibling)
4384 append_elem(OP_SPLIT, op, newSVOP(OP_CONST, 0, newSViv(0)));
4386 kid = kid->op_sibling;
4389 if (kid->op_sibling)
4390 return too_many_arguments(op,op_desc[op->op_type]);
4399 OP *prev = ((cUNOP->op_first->op_sibling)
4400 ? cUNOP : ((UNOP*)cUNOP->op_first))->op_first;
4401 OP *o = prev->op_sibling;
4408 for (cvop = o; cvop->op_sibling; cvop = cvop->op_sibling) ;
4409 if (cvop->op_type == OP_RV2CV) {
4411 op->op_private |= (cvop->op_private & OPpENTERSUB_AMPER);
4412 null(cvop); /* disable rv2cv */
4413 tmpop = (SVOP*)((UNOP*)cvop)->op_first;
4414 if (tmpop->op_type == OP_GV) {
4415 cv = GvCVu(tmpop->op_sv);
4416 if (cv && SvPOK(cv) && !(op->op_private & OPpENTERSUB_AMPER))
4417 proto = SvPV((SV*)cv,na);
4420 op->op_private |= (hints & HINT_STRICT_REFS);
4421 if (perldb && curstash != debstash)
4422 op->op_private |= OPpENTERSUB_DB;
4427 return too_many_arguments(op, CvNAME(cv));
4445 if (o->op_type != OP_REFGEN && o->op_type != OP_UNDEF)
4446 bad_type(arg, "block", CvNAME(cv), o);
4451 if (o->op_type == OP_RV2GV)
4455 o = newUNOP(OP_RV2GV, 0, kid);
4456 o->op_sibling = kid->op_sibling;
4457 kid->op_sibling = 0;
4458 prev->op_sibling = o;
4466 if (o->op_type != OP_RV2GV)
4467 bad_type(arg, "symbol", CvNAME(cv), o);
4470 if (o->op_type != OP_RV2CV)
4471 bad_type(arg, "sub", CvNAME(cv), o);
4474 if (o->op_type != OP_RV2SV && o->op_type != OP_PADSV)
4475 bad_type(arg, "scalar", CvNAME(cv), o);
4478 if (o->op_type != OP_RV2AV && o->op_type != OP_PADAV)
4479 bad_type(arg, "array", CvNAME(cv), o);
4482 if (o->op_type != OP_RV2HV && o->op_type != OP_PADHV)
4483 bad_type(arg, "hash", CvNAME(cv), o);
4487 o = newUNOP(OP_REFGEN, 0, kid);
4488 o->op_sibling = kid->op_sibling;
4489 kid->op_sibling = 0;
4490 prev->op_sibling = o;
4501 croak("Malformed prototype for %s: %s",
4502 CvNAME(cv),SvPV((SV*)cv,na));
4507 mod(o, OP_ENTERSUB);
4511 if (proto && !optional && *proto == '$')
4512 return too_few_arguments(op, CvNAME(cv));
4520 SvREADONLY_on(cSVOP->op_sv);
4528 if (op->op_flags & OPf_KIDS) {
4529 SVOP *kid = (SVOP*)cUNOP->op_first;
4531 if (kid->op_type == OP_NULL)
4532 kid = (SVOP*)kid->op_sibling;
4534 kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE))
4535 op->op_flags |= OPf_SPECIAL;
4540 /* A peephole optimizer. We visit the ops in the order they're to execute. */
4546 register OP* oldop = 0;
4547 if (!o || o->op_seq)
4552 for (; o; o = o->op_next) {
4558 switch (o->op_type) {
4561 curcop = ((COP*)o); /* for warnings */
4562 o->op_seq = op_seqmax++;
4573 if (o->op_next->op_type == OP_STRINGIFY)
4575 o->op_seq = op_seqmax++;
4578 if ((o->op_flags & (OPf_KNOW|OPf_LIST)) != (OPf_KNOW|OPf_LIST)) {
4579 o->op_seq = op_seqmax++;
4580 break; /* Scalar stub must produce undef. List stub is noop */
4584 if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE)
4585 curcop = ((COP*)op);
4591 if (oldop && o->op_next) {
4592 oldop->op_next = o->op_next;
4595 o->op_seq = op_seqmax++;
4599 if (o->op_next->op_type == OP_RV2SV) {
4600 if (!(o->op_next->op_private & OPpDEREF)) {
4602 o->op_private |= o->op_next->op_private & OPpLVAL_INTRO;
4603 o->op_next = o->op_next->op_next;
4604 o->op_type = OP_GVSV;
4605 o->op_ppaddr = ppaddr[OP_GVSV];
4608 else if (o->op_next->op_type == OP_RV2AV) {
4609 OP* pop = o->op_next->op_next;
4611 if (pop->op_type == OP_CONST &&
4612 (op = pop->op_next) &&
4613 pop->op_next->op_type == OP_AELEM &&
4614 !(pop->op_next->op_private &
4615 (OPpLVAL_INTRO|OPpLVAL_DEFER|OPpDEREF)) &&
4616 (i = SvIV(((SVOP*)pop)->op_sv) - compiling.cop_arybase)
4620 SvREFCNT_dec(((SVOP*)pop)->op_sv);
4624 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
4625 o->op_next = pop->op_next->op_next;
4626 o->op_type = OP_AELEMFAST;
4627 o->op_ppaddr = ppaddr[OP_AELEMFAST];
4628 o->op_private = (U8)i;
4629 GvAVn(((GVOP*)o)->op_gv);
4632 o->op_seq = op_seqmax++;
4639 o->op_seq = op_seqmax++;
4640 peep(cLOGOP->op_other);
4644 o->op_seq = op_seqmax++;
4645 peep(cCONDOP->op_true);
4646 peep(cCONDOP->op_false);
4650 o->op_seq = op_seqmax++;
4651 peep(cLOOP->op_redoop);
4652 peep(cLOOP->op_nextop);
4653 peep(cLOOP->op_lastop);
4658 o->op_seq = op_seqmax++;
4659 peep(cPMOP->op_pmreplstart);
4663 o->op_seq = op_seqmax++;
4664 if (dowarn && o->op_next && o->op_next->op_type == OP_NEXTSTATE) {
4665 if (o->op_next->op_sibling &&
4666 o->op_next->op_sibling->op_type != OP_DIE) {
4667 line_t oldline = curcop->cop_line;
4669 curcop->cop_line = ((COP*)o->op_next)->cop_line;
4670 warn("Statement unlikely to be reached");
4671 warn("(Maybe you meant system() when you said exec()?)\n");
4672 curcop->cop_line = oldline;
4677 o->op_seq = op_seqmax++;