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, gv, Nullch);
56 return SvPV(tmpsv,na);
63 yyerror(form("Missing comma after first argument to %s function",
64 op_desc[op->op_type]));
69 too_few_arguments(op, name)
73 yyerror(form("Not enough arguments for %s", name));
78 too_many_arguments(op, name)
82 yyerror(form("Too many arguments for %s", name));
87 bad_type(n, t, name, kid)
93 yyerror(form("Type of arg %d to %s must be %s (not %s)",
94 (int)n, name, t, op_desc[kid->op_type]));
102 int type = op->op_type;
103 if (type != OP_AELEM && type != OP_HELEM) {
104 yyerror(form("Can't use subscript on %s", op_desc[type]));
105 if (type == OP_ENTERSUB || type == OP_RV2HV || type == OP_PADHV)
106 warn("(Did you mean $ or @ instead of %c?)\n",
107 type == OP_ENTERSUB ? '&' : '%');
111 /* "register" allocation */
120 if (!(isALPHA(name[1]) || name[1] == '_' && (int)strlen(name) > 2)) {
121 if (!isPRINT(name[1])) {
123 name[2] = toCTRL(name[1]);
126 croak("Can't use global %s in \"my\"",name);
128 if (AvFILL(comppad_name) >= 0) {
129 SV **svp = AvARRAY(comppad_name);
130 for (off = AvFILL(comppad_name); off > comppad_name_floor; off--) {
133 && SvIVX(sv) == 999999999 /* var is in open scope */
134 && strEQ(name, SvPVX(sv)))
136 warn("\"my\" variable %s masks earlier declaration in same scope", name);
141 off = pad_alloc(OP_PADSV, SVs_PADMY);
143 sv_upgrade(sv, SVt_PVNV);
145 av_store(comppad_name, off, sv);
146 SvNVX(sv) = (double)999999999;
147 SvIVX(sv) = 0; /* Not yet introduced--see newSTATEOP */
148 if (!min_intro_pending)
149 min_intro_pending = off;
150 max_intro_pending = off;
152 av_store(comppad, off, (SV*)newAV());
153 else if (*name == '%')
154 av_store(comppad, off, (SV*)newHV());
155 SvPADMY_on(curpad[off]);
160 #ifndef CAN_PROTOTYPE
161 pad_findlex(name, newoff, seq, startcv, cx_ix)
168 pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix)
175 register CONTEXT *cx;
178 for (cv = startcv; cv; cv = CvOUTSIDE(cv)) {
179 AV *curlist = CvPADLIST(cv);
180 SV **svp = av_fetch(curlist, 0, FALSE);
183 if (!svp || *svp == &sv_undef)
186 svp = AvARRAY(curname);
187 for (off = AvFILL(curname); off > 0; off--) {
188 if ((sv = svp[off]) &&
191 seq > I_32(SvNVX(sv)) &&
192 strEQ(SvPVX(sv), name))
203 return 0; /* don't clone from inactive stack frame */
207 oldpad = (AV*)*av_fetch(curlist, depth, FALSE);
208 oldsv = *av_fetch(oldpad, off, TRUE);
209 if (!newoff) { /* Not a mere clone operation. */
210 SV *namesv = NEWSV(1103,0);
211 newoff = pad_alloc(OP_PADSV, SVs_PADMY);
212 sv_upgrade(namesv, SVt_PVNV);
213 sv_setpv(namesv, name);
214 av_store(comppad_name, newoff, namesv);
215 SvNVX(namesv) = (double)curcop->cop_seq;
216 SvIVX(namesv) = 999999999; /* A ref, intro immediately */
217 SvFAKE_on(namesv); /* A ref, not a real var */
218 if (CvANON(compcv) || SvTYPE(compcv) == SVt_PVFM) {
219 /* "It's closures all the way down." */
223 oldsv = Nullsv; /* no need to keep ref */
228 bcv && bcv != cv && !CvCLONE(bcv);
229 bcv = CvOUTSIDE(bcv)) {
233 if (dowarn && !CvUNIQUE(cv))
235 "Variable \"%s\" may be unavailable",
242 else if (!CvUNIQUE(compcv)) {
243 if (dowarn && !SvFAKE(sv) && !CvUNIQUE(cv))
244 warn("Variable \"%s\" will not stay shared", name);
247 av_store(comppad, newoff, SvREFCNT_inc(oldsv));
253 /* Nothing in current lexical context--try eval's context, if any.
254 * This is necessary to let the perldb get at lexically scoped variables.
255 * XXX This will also probably interact badly with eval tree caching.
259 for (i = cx_ix; i >= 0; i--) {
261 switch (cx->cx_type) {
263 if (i == 0 && saweval) {
264 seq = cxstack[saweval].blk_oldcop->cop_seq;
265 return pad_findlex(name, newoff, seq, main_cv, 0);
269 switch (cx->blk_eval.old_op_type) {
274 /* require must have its own scope */
282 if (debstash && CvSTASH(cv) == debstash) { /* ignore DB'* scope */
283 saweval = i; /* so we know where we were called from */
286 seq = cxstack[saweval].blk_oldcop->cop_seq;
287 return pad_findlex(name, newoff, seq, cv, i-1);
301 SV **svp = AvARRAY(comppad_name);
302 U32 seq = cop_seqmax;
304 /* The one we're looking for is probably just before comppad_name_fill. */
305 for (off = AvFILL(comppad_name); off > 0; off--) {
306 if ((sv = svp[off]) &&
310 seq > I_32(SvNVX(sv)))) &&
311 strEQ(SvPVX(sv), name))
314 return (PADOFFSET)off;
315 pendoff = off; /* this pending def. will override import */
319 /* See if it's in a nested scope */
320 off = pad_findlex(name, 0, seq, CvOUTSIDE(compcv), cxstack_ix);
322 /* If there is a pending local definition, this new alias must die */
324 SvIVX(AvARRAY(comppad_name)[off]) = seq;
336 SV **svp = AvARRAY(comppad_name);
338 if (min_intro_pending && fill < min_intro_pending) {
339 for (off = max_intro_pending; off >= min_intro_pending; off--) {
340 if ((sv = svp[off]) && sv != &sv_undef)
341 warn("%s never introduced", SvPVX(sv));
344 /* "Deintroduce" my variables that are leaving with this scope. */
345 for (off = AvFILL(comppad_name); off > fill; off--) {
346 if ((sv = svp[off]) && sv != &sv_undef && SvIVX(sv) == 999999999)
347 SvIVX(sv) = cop_seqmax;
352 pad_alloc(optype,tmptype)
359 if (AvARRAY(comppad) != curpad)
360 croak("panic: pad_alloc");
361 if (pad_reset_pending)
363 if (tmptype & SVs_PADMY) {
365 sv = *av_fetch(comppad, AvFILL(comppad) + 1, TRUE);
366 } while (SvPADBUSY(sv)); /* need a fresh one */
367 retval = AvFILL(comppad);
370 SV **names = AvARRAY(comppad_name);
371 SSize_t names_fill = AvFILL(comppad_name);
374 * "foreach" index vars temporarily become aliases to non-"my"
375 * values. Thus we must skip, not just pad values that are
376 * marked as current pad values, but also those with names.
378 if (++padix <= names_fill &&
379 (sv = names[padix]) && sv != &sv_undef)
381 sv = *av_fetch(comppad, padix, TRUE);
382 if (!(SvFLAGS(sv) & (SVs_PADTMP|SVs_PADMY)))
387 SvFLAGS(sv) |= tmptype;
388 curpad = AvARRAY(comppad);
389 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad alloc %ld for %s\n", (long) retval, op_name[optype]));
390 return (PADOFFSET)retval;
394 #ifndef CAN_PROTOTYPE
399 #endif /* CAN_PROTOTYPE */
402 croak("panic: pad_sv po");
403 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad sv %lu\n", (unsigned long)po));
404 return curpad[po]; /* eventually we'll turn this into a macro */
408 #ifndef CAN_PROTOTYPE
412 pad_free(PADOFFSET po)
413 #endif /* CAN_PROTOTYPE */
417 if (AvARRAY(comppad) != curpad)
418 croak("panic: pad_free curpad");
420 croak("panic: pad_free po");
421 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad free %lu\n", (unsigned long)po));
422 if (curpad[po] && !SvIMMORTAL(curpad[po]))
423 SvPADTMP_off(curpad[po]);
429 #ifndef CAN_PROTOTYPE
433 pad_swipe(PADOFFSET po)
434 #endif /* CAN_PROTOTYPE */
436 if (AvARRAY(comppad) != curpad)
437 croak("panic: pad_swipe curpad");
439 croak("panic: pad_swipe po");
440 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad swipe %lu\n", (unsigned long)po));
441 SvPADTMP_off(curpad[po]);
442 curpad[po] = NEWSV(1107,0);
443 SvPADTMP_on(curpad[po]);
453 if (AvARRAY(comppad) != curpad)
454 croak("panic: pad_reset curpad");
455 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad reset\n"));
456 if (!tainting) { /* Can't mix tainted and non-tainted temporaries. */
457 for (po = AvMAX(comppad); po > padix_floor; po--) {
458 if (curpad[po] && !SvIMMORTAL(curpad[po]))
459 SvPADTMP_off(curpad[po]);
463 pad_reset_pending = FALSE;
472 register OP *kid, *nextkid;
474 if (!op || op->op_seq == (U16)-1)
477 if (op->op_flags & OPf_KIDS) {
478 for (kid = cUNOP->op_first; kid; kid = nextkid) {
479 nextkid = kid->op_sibling; /* Get before next freeing kid */
484 switch (op->op_type) {
486 op->op_targ = 0; /* Was holding old type, if any. */
489 op->op_targ = 0; /* Was holding hints. */
492 if (!(op->op_flags & OPf_REF) || (check[op->op_type] != ck_ftst))
498 SvREFCNT_dec(cGVOP->op_gv);
502 Safefree(cCOP->cop_label);
503 SvREFCNT_dec(cCOP->cop_filegv);
506 SvREFCNT_dec(cSVOP->op_sv);
512 if (op->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
516 Safefree(cPVOP->op_pv);
519 op_free(cPMOP->op_pmreplroot);
523 pregfree(cPMOP->op_pmregexp);
524 SvREFCNT_dec(cPMOP->op_pmshort);
529 pad_free(op->op_targ);
538 if (op->op_type != OP_NULL && op->op_targ > 0)
539 pad_free(op->op_targ);
540 op->op_targ = op->op_type;
541 op->op_type = OP_NULL;
542 op->op_ppaddr = ppaddr[OP_NULL];
545 /* Contextualizers */
547 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
558 /* establish postfix order */
559 if (cUNOP->op_first) {
560 op->op_next = LINKLIST(cUNOP->op_first);
561 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
563 kid->op_next = LINKLIST(kid->op_sibling);
579 if (op && op->op_flags & OPf_KIDS) {
580 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
591 op->op_type == OP_SASSIGN && cBINOP->op_first->op_type == OP_CONST) {
592 line_t oldline = curcop->cop_line;
594 if (copline != NOLINE)
595 curcop->cop_line = copline;
596 warn("Found = in conditional, should be ==");
597 curcop->cop_line = oldline;
608 /* assumes no premature commitment */
609 if (!op || (op->op_flags & OPf_WANT) || error_count
610 || op->op_type == OP_RETURN)
613 op->op_flags = (op->op_flags & ~OPf_WANT) | OPf_WANT_SCALAR;
615 switch (op->op_type) {
617 if (op->op_private & OPpREPEAT_DOLIST)
618 null(((LISTOP*)cBINOP->op_first)->op_first);
619 scalar(cBINOP->op_first);
624 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
628 if ((kid = ((LISTOP*)op)->op_first) && kid->op_type == OP_PUSHRE) {
629 if (!kPMOP->op_pmreplroot)
630 deprecate("implicit split to @_");
637 if (op->op_flags & OPf_KIDS) {
638 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling)
644 kid = cLISTOP->op_first;
646 while (kid = kid->op_sibling) {
657 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
677 /* assumes no premature commitment */
678 if (!op || (op->op_flags & OPf_WANT) == OPf_WANT_LIST || error_count
679 || op->op_type == OP_RETURN)
682 op->op_flags = (op->op_flags & ~OPf_WANT) | OPf_WANT_VOID;
684 switch (op->op_type) {
686 if (!(opargs[op->op_type] & OA_FOLDCONST))
690 if (op->op_flags & OPf_STACKED)
761 if (!(op->op_private & OPpLVAL_INTRO))
762 useless = op_desc[op->op_type];
769 if (!(op->op_private & OPpLVAL_INTRO) &&
770 (!op->op_sibling || op->op_sibling->op_type != OP_READLINE))
771 useless = "a variable";
776 curcop = ((COP*)op); /* for warning below */
782 useless = "a constant";
783 if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
785 else if (SvPOK(sv)) {
786 if (strnEQ(SvPVX(sv), "di", 2) ||
787 strnEQ(SvPVX(sv), "ds", 2) ||
788 strnEQ(SvPVX(sv), "ig", 2))
792 null(op); /* don't execute a constant */
793 SvREFCNT_dec(sv); /* don't even remember it */
797 op->op_type = OP_PREINC; /* pre-increment is faster */
798 op->op_ppaddr = ppaddr[OP_PREINC];
802 op->op_type = OP_PREDEC; /* pre-decrement is faster */
803 op->op_ppaddr = ppaddr[OP_PREDEC];
809 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
814 if (op->op_targ == OP_NEXTSTATE || op->op_targ == OP_DBSTATE)
815 curcop = ((COP*)op); /* for warning below */
816 if (op->op_flags & OPf_STACKED)
822 if (!(op->op_flags & OPf_KIDS))
831 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
838 /* all requires must return a boolean value */
839 op->op_flags &= ~OPf_WANT;
842 if ((kid = ((LISTOP*)op)->op_first) && kid->op_type == OP_PUSHRE) {
843 if (!kPMOP->op_pmreplroot)
844 deprecate("implicit split to @_");
848 if (useless && dowarn)
849 warn("Useless use of %s in void context", useless);
858 if (op && op->op_flags & OPf_KIDS) {
859 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
871 /* assumes no premature commitment */
872 if (!op || (op->op_flags & OPf_WANT) || error_count
873 || op->op_type == OP_RETURN)
876 op->op_flags = (op->op_flags & ~OPf_WANT) | OPf_WANT_LIST;
878 switch (op->op_type) {
881 list(cBINOP->op_first);
886 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
893 if (!(op->op_flags & OPf_KIDS))
895 if (!op->op_next && cUNOP->op_first->op_type == OP_FLOP) {
896 list(cBINOP->op_first);
897 return gen_constant_list(op);
904 kid = cLISTOP->op_first;
906 while (kid = kid->op_sibling) {
916 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
925 /* all requires must return a boolean value */
926 op->op_flags &= ~OPf_WANT;
939 if (op->op_type == OP_LINESEQ ||
940 op->op_type == OP_SCOPE ||
941 op->op_type == OP_LEAVE ||
942 op->op_type == OP_LEAVETRY)
944 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
945 if (kid->op_sibling) {
951 op->op_flags &= ~OPf_PARENS;
952 if (hints & HINT_BLOCK_SCOPE)
953 op->op_flags |= OPf_PARENS;
956 op = newOP(OP_STUB, 0);
966 if (op && op->op_flags & OPf_KIDS) {
967 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
983 if (!op || error_count)
986 switch (op->op_type) {
990 if (!(op->op_private & (OPpCONST_ARYBASE)))
992 if (eval_start && eval_start->op_type == OP_CONST) {
993 compiling.cop_arybase = (I32)SvIV(((SVOP*)eval_start)->op_sv);
997 SAVEI32(compiling.cop_arybase);
998 compiling.cop_arybase = 0;
1000 else if (type == OP_REFGEN)
1003 croak("That use of $[ is unsupported");
1006 if (op->op_flags & OPf_PARENS)
1010 if ((type == OP_UNDEF || type == OP_REFGEN) &&
1011 !(op->op_flags & OPf_STACKED)) {
1012 op->op_type = OP_RV2CV; /* entersub => rv2cv */
1013 op->op_ppaddr = ppaddr[OP_RV2CV];
1014 assert(cUNOP->op_first->op_type == OP_NULL);
1015 null(((LISTOP*)cUNOP->op_first)->op_first); /* disable pushmark */
1021 /* grep, foreach, subcalls, refgen */
1022 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
1024 yyerror(form("Can't modify %s in %s",
1025 op_desc[op->op_type],
1026 type ? op_desc[type] : "local"));
1040 case OP_RIGHT_SHIFT:
1049 if (!(op->op_flags & OPf_STACKED))
1055 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
1061 if (type == OP_REFGEN && op->op_flags & OPf_PARENS) {
1063 return op; /* Treat \(@foo) like ordinary list. */
1067 if (scalar_mod_type(op, type))
1069 ref(cUNOP->op_first, op->op_type);
1081 if (!type && cUNOP->op_first->op_type != OP_GV)
1082 croak("Can't localize a reference");
1083 ref(cUNOP->op_first, op->op_type);
1095 if (type == OP_REFGEN && op->op_flags & OPf_PARENS)
1096 return op; /* Treat \(@foo) like ordinary list. */
1097 if (scalar_mod_type(op, type))
1103 croak("Can't localize lexical variable %s",
1104 SvPV(*av_fetch(comppad_name, op->op_targ, 4), na));
1111 if (type != OP_SASSIGN)
1117 pad_free(op->op_targ);
1118 op->op_targ = pad_alloc(op->op_type, SVs_PADMY);
1119 assert(SvTYPE(PAD_SV(op->op_targ)) == SVt_NULL);
1120 if (op->op_flags & OPf_KIDS)
1121 mod(cBINOP->op_first->op_sibling, type);
1126 ref(cBINOP->op_first, op->op_type);
1127 if (type == OP_ENTERSUB &&
1128 !(op->op_private & (OPpLVAL_INTRO | OPpDEREF)))
1129 op->op_private |= OPpLVAL_DEFER;
1136 if (op->op_flags & OPf_KIDS)
1137 mod(cLISTOP->op_last, type);
1141 if (!(op->op_flags & OPf_KIDS))
1143 if (op->op_targ != OP_LIST) {
1144 mod(cBINOP->op_first, type);
1149 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1153 op->op_flags |= OPf_MOD;
1155 if (type == OP_AASSIGN || type == OP_SASSIGN)
1156 op->op_flags |= OPf_SPECIAL|OPf_REF;
1158 op->op_private |= OPpLVAL_INTRO;
1159 op->op_flags &= ~OPf_SPECIAL;
1161 else if (type != OP_GREPSTART && type != OP_ENTERSUB)
1162 op->op_flags |= OPf_REF;
1167 scalar_mod_type(op, type)
1173 if (op->op_type == OP_RV2GV)
1197 case OP_RIGHT_SHIFT:
1204 case OP_ANDASSIGN: /* may work later */
1205 case OP_ORASSIGN: /* may work later */
1218 if (op && op->op_flags & OPf_KIDS) {
1219 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1232 if (!op || error_count)
1235 switch (op->op_type) {
1237 if ((type == OP_DEFINED) &&
1238 !(op->op_flags & OPf_STACKED)) {
1239 op->op_type = OP_RV2CV; /* entersub => rv2cv */
1240 op->op_ppaddr = ppaddr[OP_RV2CV];
1241 assert(cUNOP->op_first->op_type == OP_NULL);
1242 null(((LISTOP*)cUNOP->op_first)->op_first); /* disable pushmark */
1243 op->op_flags |= OPf_SPECIAL;
1248 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
1252 ref(cUNOP->op_first, op->op_type);
1255 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1256 op->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1257 : type == OP_RV2HV ? OPpDEREF_HV
1259 op->op_flags |= OPf_MOD;
1265 op->op_flags |= OPf_REF;
1268 ref(cUNOP->op_first, op->op_type);
1273 op->op_flags |= OPf_REF;
1278 if (!(op->op_flags & OPf_KIDS))
1280 ref(cBINOP->op_first, type);
1284 ref(cBINOP->op_first, op->op_type);
1285 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1286 op->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1287 : type == OP_RV2HV ? OPpDEREF_HV
1289 op->op_flags |= OPf_MOD;
1297 if (!(op->op_flags & OPf_KIDS))
1299 ref(cLISTOP->op_last, type);
1315 if (!op || error_count)
1319 if (type == OP_LIST) {
1320 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1323 else if (type != OP_PADSV &&
1326 type != OP_PUSHMARK)
1328 yyerror(form("Can't declare %s in my", op_desc[op->op_type]));
1331 op->op_flags |= OPf_MOD;
1332 op->op_private |= OPpLVAL_INTRO;
1341 o->op_flags |= OPf_PARENS;
1346 bind_match(type, left, right)
1354 (left->op_type == OP_RV2AV ||
1355 left->op_type == OP_RV2HV ||
1356 left->op_type == OP_PADAV ||
1357 left->op_type == OP_PADHV)) {
1358 char *desc = op_desc[(right->op_type == OP_SUBST ||
1359 right->op_type == OP_TRANS)
1360 ? right->op_type : OP_MATCH];
1361 char *sample = ((left->op_type == OP_RV2AV ||
1362 left->op_type == OP_PADAV)
1363 ? "@array" : "%hash");
1364 warn("Applying %s to %s will act on scalar(%s)", desc, sample, sample);
1367 if (right->op_type == OP_MATCH ||
1368 right->op_type == OP_SUBST ||
1369 right->op_type == OP_TRANS) {
1370 right->op_flags |= OPf_STACKED;
1371 if (right->op_type != OP_MATCH)
1372 left = mod(left, right->op_type);
1373 if (right->op_type == OP_TRANS)
1374 op = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
1376 op = prepend_elem(right->op_type, scalar(left), right);
1378 return newUNOP(OP_NOT, 0, scalar(op));
1382 return bind_match(type, left,
1383 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
1392 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
1393 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(op));
1401 if (o->op_flags & OPf_PARENS || perldb || tainting) {
1402 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
1403 o->op_type = OP_LEAVE;
1404 o->op_ppaddr = ppaddr[OP_LEAVE];
1407 if (o->op_type == OP_LINESEQ) {
1409 o->op_type = OP_SCOPE;
1410 o->op_ppaddr = ppaddr[OP_SCOPE];
1411 kid = ((LISTOP*)o)->op_first;
1412 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE){
1413 SvREFCNT_dec(((COP*)kid)->cop_filegv);
1418 o = newLISTOP(OP_SCOPE, 0, o, Nullop);
1428 int retval = savestack_ix;
1429 SAVEI32(comppad_name_floor);
1431 if ((comppad_name_fill = AvFILL(comppad_name)) > 0)
1432 comppad_name_floor = comppad_name_fill;
1434 comppad_name_floor = 0;
1436 SAVEI32(min_intro_pending);
1437 SAVEI32(max_intro_pending);
1438 min_intro_pending = 0;
1439 SAVEI32(comppad_name_fill);
1440 SAVEI32(padix_floor);
1441 padix_floor = padix;
1442 pad_reset_pending = FALSE;
1444 hints &= ~HINT_BLOCK_SCOPE;
1449 block_end(floor, seq)
1453 int needblockscope = hints & HINT_BLOCK_SCOPE;
1454 OP* retval = scalarseq(seq);
1456 pad_reset_pending = FALSE;
1458 hints |= HINT_BLOCK_SCOPE; /* propagate out */
1459 pad_leavemy(comppad_name_fill);
1469 eval_root = newUNOP(OP_LEAVEEVAL, ((in_eval & 4) ? OPf_SPECIAL : 0), op);
1470 eval_start = linklist(eval_root);
1471 eval_root->op_next = 0;
1477 main_root = scope(sawparens(scalarvoid(op)));
1478 curcop = &compiling;
1479 main_start = LINKLIST(main_root);
1480 main_root->op_next = 0;
1484 /* Register with debugger */
1486 CV *cv = perl_get_cv("DB::postponed", FALSE);
1490 XPUSHs((SV*)compiling.cop_filegv);
1492 perl_call_sv((SV*)cv, G_DISCARD);
1503 if (o->op_flags & OPf_PARENS)
1507 if (dowarn && bufptr > oldbufptr && bufptr[-1] == ',') {
1509 for (s = bufptr; *s && (isALNUM(*s) || strchr("@$%, ",*s)); s++) ;
1510 if (*s == ';' || *s == '=')
1511 warn("Parens missing around \"%s\" list", lex ? "my" : "local");
1518 return mod(o, OP_NULL); /* a bit kludgey */
1525 if (o->op_type == OP_LIST) {
1526 o = convert(OP_JOIN, 0,
1527 prepend_elem(OP_LIST,
1528 newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
1539 I32 type = o->op_type;
1542 if (opargs[type] & OA_RETSCALAR)
1544 if (opargs[type] & OA_TARGET)
1545 o->op_targ = pad_alloc(type, SVs_PADTMP);
1547 if ((opargs[type] & OA_OTHERINT) && (hints & HINT_INTEGER))
1548 o->op_ppaddr = ppaddr[type = ++(o->op_type)];
1550 if (!(opargs[type] & OA_FOLDCONST))
1554 goto nope; /* Don't try to run w/ errors */
1556 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
1557 if (curop->op_type != OP_CONST &&
1558 curop->op_type != OP_LIST &&
1559 curop->op_type != OP_SCALAR &&
1560 curop->op_type != OP_NULL &&
1561 curop->op_type != OP_PUSHMARK) {
1566 curop = LINKLIST(o);
1571 if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
1572 pad_swipe(o->op_targ);
1573 else if (SvTEMP(sv)) { /* grab mortal temp? */
1574 (void)SvREFCNT_inc(sv);
1578 if (type == OP_RV2GV)
1579 return newGVOP(OP_GV, 0, (GV*)sv);
1581 if ((SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK)) == SVf_NOK) {
1583 if ((double)iv == SvNV(sv)) { /* can we smush double to int */
1588 SvIOK_off(sv); /* undo SvIV() damage */
1590 return newSVOP(OP_CONST, 0, sv);
1594 if (!(opargs[type] & OA_OTHERINT))
1597 if (!(hints & HINT_INTEGER)) {
1598 if (type == OP_DIVIDE || !(o->op_flags & OPf_KIDS))
1601 for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
1602 if (curop->op_type == OP_CONST) {
1603 if (SvIOK(((SVOP*)curop)->op_sv))
1607 if (opargs[curop->op_type] & OA_RETINTEGER)
1611 o->op_ppaddr = ppaddr[++(o->op_type)];
1618 gen_constant_list(o)
1622 I32 oldtmps_floor = tmps_floor;
1626 return o; /* Don't attempt to run with errors */
1628 op = curop = LINKLIST(o);
1634 tmps_floor = oldtmps_floor;
1636 o->op_type = OP_RV2AV;
1637 o->op_ppaddr = ppaddr[OP_RV2AV];
1638 curop = ((UNOP*)o)->op_first;
1639 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*stack_sp--));
1646 convert(type, flags, op)
1654 if (!op || op->op_type != OP_LIST)
1655 op = newLISTOP(OP_LIST, 0, op, Nullop);
1657 op->op_flags &= ~OPf_WANT;
1659 if (!(opargs[type] & OA_MARK))
1660 null(cLISTOP->op_first);
1663 op->op_ppaddr = ppaddr[type];
1664 op->op_flags |= flags;
1666 op = CHECKOP(type, op);
1667 if (op->op_type != type)
1670 if (cLISTOP->op_children < 7) {
1671 /* XXX do we really need to do this if we're done appending?? */
1672 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1674 cLISTOP->op_last = last; /* in case check substituted last arg */
1677 return fold_constants(op);
1680 /* List constructors */
1683 append_elem(type, first, last)
1694 if (first->op_type != type || type==OP_LIST && first->op_flags & OPf_PARENS)
1695 return newLISTOP(type, 0, first, last);
1697 if (first->op_flags & OPf_KIDS)
1698 ((LISTOP*)first)->op_last->op_sibling = last;
1700 first->op_flags |= OPf_KIDS;
1701 ((LISTOP*)first)->op_first = last;
1703 ((LISTOP*)first)->op_last = last;
1704 ((LISTOP*)first)->op_children++;
1709 append_list(type, first, last)
1720 if (first->op_type != type)
1721 return prepend_elem(type, (OP*)first, (OP*)last);
1723 if (last->op_type != type)
1724 return append_elem(type, (OP*)first, (OP*)last);
1726 first->op_last->op_sibling = last->op_first;
1727 first->op_last = last->op_last;
1728 first->op_children += last->op_children;
1729 if (first->op_children)
1730 last->op_flags |= OPf_KIDS;
1737 prepend_elem(type, first, last)
1748 if (last->op_type == type) {
1749 if (type == OP_LIST) { /* already a PUSHMARK there */
1750 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
1751 ((LISTOP*)last)->op_first->op_sibling = first;
1754 if (!(last->op_flags & OPf_KIDS)) {
1755 ((LISTOP*)last)->op_last = first;
1756 last->op_flags |= OPf_KIDS;
1758 first->op_sibling = ((LISTOP*)last)->op_first;
1759 ((LISTOP*)last)->op_first = first;
1761 ((LISTOP*)last)->op_children++;
1765 return newLISTOP(type, 0, first, last);
1773 return newOP(OP_STUB, 0);
1780 if (!op || op->op_type != OP_LIST)
1781 op = newLISTOP(OP_LIST, 0, op, Nullop);
1787 newLISTOP(type, flags, first, last)
1795 Newz(1101, listop, 1, LISTOP);
1797 listop->op_type = type;
1798 listop->op_ppaddr = ppaddr[type];
1799 listop->op_children = (first != 0) + (last != 0);
1800 listop->op_flags = flags;
1804 else if (!first && last)
1807 first->op_sibling = last;
1808 listop->op_first = first;
1809 listop->op_last = last;
1810 if (type == OP_LIST) {
1812 pushop = newOP(OP_PUSHMARK, 0);
1813 pushop->op_sibling = first;
1814 listop->op_first = pushop;
1815 listop->op_flags |= OPf_KIDS;
1817 listop->op_last = pushop;
1819 else if (listop->op_children)
1820 listop->op_flags |= OPf_KIDS;
1831 Newz(1101, op, 1, OP);
1833 op->op_ppaddr = ppaddr[type];
1834 op->op_flags = flags;
1837 op->op_private = 0 + (flags >> 8);
1838 if (opargs[type] & OA_RETSCALAR)
1840 if (opargs[type] & OA_TARGET)
1841 op->op_targ = pad_alloc(type, SVs_PADTMP);
1842 return CHECKOP(type, op);
1846 newUNOP(type, flags, first)
1854 first = newOP(OP_STUB, 0);
1855 if (opargs[type] & OA_MARK)
1856 first = force_list(first);
1858 Newz(1101, unop, 1, UNOP);
1859 unop->op_type = type;
1860 unop->op_ppaddr = ppaddr[type];
1861 unop->op_first = first;
1862 unop->op_flags = flags | OPf_KIDS;
1863 unop->op_private = 1 | (flags >> 8);
1865 unop = (UNOP*) CHECKOP(type, unop);
1869 return fold_constants((OP *) unop);
1873 newBINOP(type, flags, first, last)
1880 Newz(1101, binop, 1, BINOP);
1883 first = newOP(OP_NULL, 0);
1885 binop->op_type = type;
1886 binop->op_ppaddr = ppaddr[type];
1887 binop->op_first = first;
1888 binop->op_flags = flags | OPf_KIDS;
1891 binop->op_private = 1 | (flags >> 8);
1894 binop->op_private = 2 | (flags >> 8);
1895 first->op_sibling = last;
1898 binop = (BINOP*)CHECKOP(type, binop);
1902 binop->op_last = last = binop->op_first->op_sibling;
1904 return fold_constants((OP *)binop);
1908 pmtrans(op, expr, repl)
1913 SV *tstr = ((SVOP*)expr)->op_sv;
1914 SV *rstr = ((SVOP*)repl)->op_sv;
1917 register U8 *t = (U8*)SvPV(tstr, tlen);
1918 register U8 *r = (U8*)SvPV(rstr, rlen);
1923 register short *tbl;
1925 tbl = (short*)cPVOP->op_pv;
1926 complement = op->op_private & OPpTRANS_COMPLEMENT;
1927 delete = op->op_private & OPpTRANS_DELETE;
1928 /* squash = op->op_private & OPpTRANS_SQUASH; */
1931 Zero(tbl, 256, short);
1932 for (i = 0; i < tlen; i++)
1934 for (i = 0, j = 0; i < 256; i++) {
1950 if (!rlen && !delete) {
1953 for (i = 0; i < 256; i++)
1955 for (i = 0, j = 0; i < tlen; i++,j++) {
1958 if (tbl[t[i]] == -1)
1964 if (tbl[t[i]] == -1)
1975 newPMOP(type, flags)
1981 Newz(1101, pmop, 1, PMOP);
1982 pmop->op_type = type;
1983 pmop->op_ppaddr = ppaddr[type];
1984 pmop->op_flags = flags;
1985 pmop->op_private = 0 | (flags >> 8);
1987 if (hints & HINT_LOCALE)
1988 pmop->op_pmpermflags = (pmop->op_pmflags |= PMf_LOCALE);
1990 /* link into pm list */
1991 if (type != OP_TRANS && curstash) {
1992 pmop->op_pmnext = HvPMROOT(curstash);
1993 HvPMROOT(curstash) = pmop;
2000 pmruntime(op, expr, repl)
2008 if (op->op_type == OP_TRANS)
2009 return pmtrans(op, expr, repl);
2013 if (expr->op_type == OP_CONST) {
2015 SV *pat = ((SVOP*)expr)->op_sv;
2016 char *p = SvPV(pat, plen);
2017 if ((op->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
2018 sv_setpvn(pat, "\\s+", 3);
2019 p = SvPV(pat, plen);
2020 pm->op_pmflags |= PMf_SKIPWHITE;
2022 pm->op_pmregexp = pregcomp(p, p + plen, pm);
2023 if (strEQ("\\s+", pm->op_pmregexp->precomp))
2024 pm->op_pmflags |= PMf_WHITE;
2029 if (pm->op_pmflags & PMf_KEEP)
2030 expr = newUNOP(OP_REGCMAYBE,0,expr);
2032 Newz(1101, rcop, 1, LOGOP);
2033 rcop->op_type = OP_REGCOMP;
2034 rcop->op_ppaddr = ppaddr[OP_REGCOMP];
2035 rcop->op_first = scalar(expr);
2036 rcop->op_flags |= OPf_KIDS;
2037 rcop->op_private = 1;
2038 rcop->op_other = op;
2040 /* establish postfix order */
2041 if (pm->op_pmflags & PMf_KEEP) {
2043 rcop->op_next = expr;
2044 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
2047 rcop->op_next = LINKLIST(expr);
2048 expr->op_next = (OP*)rcop;
2051 prepend_elem(op->op_type, scalar((OP*)rcop), op);
2056 if (pm->op_pmflags & PMf_EVAL)
2058 else if (repl->op_type == OP_CONST)
2062 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
2063 if (opargs[curop->op_type] & OA_DANGEROUS) {
2064 if (curop->op_type == OP_GV) {
2065 GV *gv = ((GVOP*)curop)->op_gv;
2066 if (strchr("&`'123456789+", *GvENAME(gv)))
2069 else if (curop->op_type == OP_RV2CV)
2071 else if (curop->op_type == OP_RV2SV ||
2072 curop->op_type == OP_RV2AV ||
2073 curop->op_type == OP_RV2HV ||
2074 curop->op_type == OP_RV2GV) {
2075 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
2078 else if (curop->op_type == OP_PADSV ||
2079 curop->op_type == OP_PADAV ||
2080 curop->op_type == OP_PADHV ||
2081 curop->op_type == OP_PADANY) {
2090 if (curop == repl) {
2091 pm->op_pmflags |= PMf_CONST; /* const for long enough */
2092 pm->op_pmpermflags |= PMf_CONST; /* const for long enough */
2093 prepend_elem(op->op_type, scalar(repl), op);
2096 Newz(1101, rcop, 1, LOGOP);
2097 rcop->op_type = OP_SUBSTCONT;
2098 rcop->op_ppaddr = ppaddr[OP_SUBSTCONT];
2099 rcop->op_first = scalar(repl);
2100 rcop->op_flags |= OPf_KIDS;
2101 rcop->op_private = 1;
2102 rcop->op_other = op;
2104 /* establish postfix order */
2105 rcop->op_next = LINKLIST(repl);
2106 repl->op_next = (OP*)rcop;
2108 pm->op_pmreplroot = scalar((OP*)rcop);
2109 pm->op_pmreplstart = LINKLIST(rcop);
2118 newSVOP(type, flags, sv)
2124 Newz(1101, svop, 1, SVOP);
2125 svop->op_type = type;
2126 svop->op_ppaddr = ppaddr[type];
2128 svop->op_next = (OP*)svop;
2129 svop->op_flags = flags;
2130 if (opargs[type] & OA_RETSCALAR)
2132 if (opargs[type] & OA_TARGET)
2133 svop->op_targ = pad_alloc(type, SVs_PADTMP);
2134 return CHECKOP(type, svop);
2138 newGVOP(type, flags, gv)
2144 Newz(1101, gvop, 1, GVOP);
2145 gvop->op_type = type;
2146 gvop->op_ppaddr = ppaddr[type];
2147 gvop->op_gv = (GV*)SvREFCNT_inc(gv);
2148 gvop->op_next = (OP*)gvop;
2149 gvop->op_flags = flags;
2150 if (opargs[type] & OA_RETSCALAR)
2152 if (opargs[type] & OA_TARGET)
2153 gvop->op_targ = pad_alloc(type, SVs_PADTMP);
2154 return CHECKOP(type, gvop);
2158 newPVOP(type, flags, pv)
2164 Newz(1101, pvop, 1, PVOP);
2165 pvop->op_type = type;
2166 pvop->op_ppaddr = ppaddr[type];
2168 pvop->op_next = (OP*)pvop;
2169 pvop->op_flags = flags;
2170 if (opargs[type] & OA_RETSCALAR)
2172 if (opargs[type] & OA_TARGET)
2173 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
2174 return CHECKOP(type, pvop);
2183 save_hptr(&curstash);
2184 save_item(curstname);
2189 name = SvPV(sv, len);
2190 curstash = gv_stashpvn(name,len,TRUE);
2191 sv_setpvn(curstname, name, len);
2195 sv_setpv(curstname,"<none>");
2203 utilize(aver, floor, version, id, arg)
2216 if (id->op_type != OP_CONST)
2217 croak("Module name must be constant");
2221 if(version != Nullop) {
2222 SV *vesv = ((SVOP*)version)->op_sv;
2224 if (arg == Nullop && !SvNIOK(vesv)) {
2231 if (version->op_type != OP_CONST || !SvNIOK(vesv))
2232 croak("Version number must be constant number");
2234 /* Make copy of id so we don't free it twice */
2235 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2237 /* Fake up a method call to VERSION */
2238 meth = newSVOP(OP_CONST, 0, newSVpv("VERSION", 7));
2239 veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2240 append_elem(OP_LIST,
2241 prepend_elem(OP_LIST, pack, list(version)),
2242 newUNOP(OP_METHOD, 0, meth)));
2246 /* Fake up an import/unimport */
2247 if (arg && arg->op_type == OP_STUB)
2248 imop = arg; /* no import on explicit () */
2249 else if(SvNIOK(((SVOP*)id)->op_sv)) {
2250 imop = Nullop; /* use 5.0; */
2253 /* Make copy of id so we don't free it twice */
2254 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2255 meth = newSVOP(OP_CONST, 0,
2257 ? newSVpv("import", 6)
2258 : newSVpv("unimport", 8)
2260 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2261 append_elem(OP_LIST,
2262 prepend_elem(OP_LIST, pack, list(arg)),
2263 newUNOP(OP_METHOD, 0, meth)));
2266 /* Fake up a require */
2267 rqop = newUNOP(OP_REQUIRE, 0, id);
2269 /* Fake up the BEGIN {}, which does its thing immediately. */
2271 newSVOP(OP_CONST, 0, newSVpv("BEGIN", 5)),
2273 append_elem(OP_LINESEQ,
2274 append_elem(OP_LINESEQ,
2275 newSTATEOP(0, Nullch, rqop),
2276 newSTATEOP(0, Nullch, veop)),
2277 newSTATEOP(0, Nullch, imop) ));
2284 newSLICEOP(flags, subscript, listval)
2289 return newBINOP(OP_LSLICE, flags,
2290 list(force_list(subscript)),
2291 list(force_list(listval)) );
2301 if (op->op_type == OP_NULL && op->op_flags & OPf_KIDS)
2302 op = cUNOP->op_first;
2304 if (op->op_type == OP_COND_EXPR) {
2305 I32 t = list_assignment(cCONDOP->op_first->op_sibling);
2306 I32 f = list_assignment(cCONDOP->op_first->op_sibling->op_sibling);
2311 yyerror("Assignment to both a list and a scalar");
2315 if (op->op_type == OP_LIST || op->op_flags & OPf_PARENS ||
2316 op->op_type == OP_RV2AV || op->op_type == OP_RV2HV ||
2317 op->op_type == OP_ASLICE || op->op_type == OP_HSLICE)
2320 if (op->op_type == OP_PADAV || op->op_type == OP_PADHV)
2323 if (op->op_type == OP_RV2SV)
2330 newASSIGNOP(flags, left, optype, right)
2339 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN) {
2340 return newLOGOP(optype, 0,
2341 mod(scalar(left), optype),
2342 newUNOP(OP_SASSIGN, 0, scalar(right)));
2345 return newBINOP(optype, OPf_STACKED,
2346 mod(scalar(left), optype), scalar(right));
2350 if (list_assignment(left)) {
2352 eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2353 left = mod(left, OP_AASSIGN);
2361 op = newBINOP(OP_AASSIGN, flags,
2362 list(force_list(right)),
2363 list(force_list(left)) );
2364 op->op_private = 0 | (flags >> 8);
2365 if (!(left->op_private & OPpLVAL_INTRO)) {
2366 static int generation = 100;
2370 for (curop = LINKLIST(op); curop != op; curop = LINKLIST(curop)) {
2371 if (opargs[curop->op_type] & OA_DANGEROUS) {
2372 if (curop->op_type == OP_GV) {
2373 GV *gv = ((GVOP*)curop)->op_gv;
2374 if (gv == defgv || SvCUR(gv) == generation)
2376 SvCUR(gv) = generation;
2378 else if (curop->op_type == OP_PADSV ||
2379 curop->op_type == OP_PADAV ||
2380 curop->op_type == OP_PADHV ||
2381 curop->op_type == OP_PADANY) {
2382 SV **svp = AvARRAY(comppad_name);
2383 SV *sv = svp[curop->op_targ];
2384 if (SvCUR(sv) == generation)
2386 SvCUR(sv) = generation; /* (SvCUR not used any more) */
2388 else if (curop->op_type == OP_RV2CV)
2390 else if (curop->op_type == OP_RV2SV ||
2391 curop->op_type == OP_RV2AV ||
2392 curop->op_type == OP_RV2HV ||
2393 curop->op_type == OP_RV2GV) {
2394 if (lastop->op_type != OP_GV) /* funny deref? */
2403 op->op_private = OPpASSIGN_COMMON;
2405 if (right && right->op_type == OP_SPLIT) {
2407 if ((tmpop = ((LISTOP*)right)->op_first) &&
2408 tmpop->op_type == OP_PUSHRE)
2410 PMOP *pm = (PMOP*)tmpop;
2411 if (left->op_type == OP_RV2AV &&
2412 !(left->op_private & OPpLVAL_INTRO) &&
2413 !(op->op_private & OPpASSIGN_COMMON) )
2415 tmpop = ((UNOP*)left)->op_first;
2416 if (tmpop->op_type == OP_GV && !pm->op_pmreplroot) {
2417 pm->op_pmreplroot = (OP*)((GVOP*)tmpop)->op_gv;
2418 pm->op_pmflags |= PMf_ONCE;
2419 tmpop = ((UNOP*)op)->op_first; /* to list (nulled) */
2420 tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */
2421 tmpop->op_sibling = Nullop; /* don't free split */
2422 right->op_next = tmpop->op_next; /* fix starting loc */
2423 op_free(op); /* blow off assign */
2424 right->op_flags &= ~OPf_WANT;
2425 /* "I don't know and I don't care." */
2430 if (modcount < 10000 &&
2431 ((LISTOP*)right)->op_last->op_type == OP_CONST)
2433 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
2435 sv_setiv(sv, modcount+1);
2443 right = newOP(OP_UNDEF, 0);
2444 if (right->op_type == OP_READLINE) {
2445 right->op_flags |= OPf_STACKED;
2446 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
2449 eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2450 op = newBINOP(OP_SASSIGN, flags,
2451 scalar(right), mod(scalar(left), OP_SASSIGN) );
2463 newSTATEOP(flags, label, op)
2468 U32 seq = intro_my();
2471 Newz(1101, cop, 1, COP);
2472 if (perldb && curcop->cop_line && curstash != debstash) {
2473 cop->op_type = OP_DBSTATE;
2474 cop->op_ppaddr = ppaddr[ OP_DBSTATE ];
2477 cop->op_type = OP_NEXTSTATE;
2478 cop->op_ppaddr = ppaddr[ OP_NEXTSTATE ];
2480 cop->op_flags = flags;
2481 cop->op_private = 0 | (flags >> 8);
2483 cop->op_private |= NATIVE_HINTS;
2485 cop->op_next = (OP*)cop;
2488 cop->cop_label = label;
2489 hints |= HINT_BLOCK_SCOPE;
2492 cop->cop_arybase = curcop->cop_arybase;
2494 if (copline == NOLINE)
2495 cop->cop_line = curcop->cop_line;
2497 cop->cop_line = copline;
2500 cop->cop_filegv = (GV*)SvREFCNT_inc(curcop->cop_filegv);
2501 cop->cop_stash = curstash;
2503 if (perldb && curstash != debstash) {
2504 SV **svp = av_fetch(GvAV(curcop->cop_filegv),(I32)cop->cop_line, FALSE);
2505 if (svp && *svp != &sv_undef && !SvIOK(*svp)) {
2506 (void)SvIOK_on(*svp);
2508 SvSTASH(*svp) = (HV*)cop;
2512 return prepend_elem(OP_LINESEQ, (OP*)cop, op);
2515 /* "Introduce" my variables to visible status. */
2523 if (! min_intro_pending)
2526 svp = AvARRAY(comppad_name);
2527 for (i = min_intro_pending; i <= max_intro_pending; i++) {
2528 if ((sv = svp[i]) && sv != &sv_undef && !SvIVX(sv)) {
2529 SvIVX(sv) = 999999999; /* Don't know scope end yet. */
2530 SvNVX(sv) = (double)cop_seqmax;
2533 min_intro_pending = 0;
2534 comppad_name_fill = max_intro_pending; /* Needn't search higher */
2535 return cop_seqmax++;
2539 newLOGOP(type, flags, first, other)
2548 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
2549 return newBINOP(type, flags, scalar(first), scalar(other));
2551 scalarboolean(first);
2552 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
2553 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
2554 if (type == OP_AND || type == OP_OR) {
2560 first = cUNOP->op_first;
2562 first->op_next = op->op_next;
2563 cUNOP->op_first = Nullop;
2567 if (first->op_type == OP_CONST) {
2568 if (dowarn && (first->op_private & OPpCONST_BARE))
2569 warn("Probable precedence problem on %s", op_desc[type]);
2570 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
2579 else if (first->op_type == OP_WANTARRAY) {
2585 else if (dowarn && (first->op_flags & OPf_KIDS)) {
2586 OP *k1 = ((UNOP*)first)->op_first;
2587 OP *k2 = k1->op_sibling;
2589 switch (first->op_type)
2592 if (k2 && k2->op_type == OP_READLINE
2593 && (k2->op_flags & OPf_STACKED)
2594 && (k1->op_type == OP_RV2SV || k1->op_type == OP_PADSV))
2595 warnop = k2->op_type;
2599 if (k1->op_type == OP_READDIR
2600 || k1->op_type == OP_GLOB
2601 || k1->op_type == OP_EACH)
2602 warnop = k1->op_type;
2606 line_t oldline = curcop->cop_line;
2607 curcop->cop_line = copline;
2608 warn("Value of %s%s can be \"0\"; test with defined()",
2610 ((warnop == OP_READLINE || warnop == OP_GLOB)
2611 ? " construct" : "() operator"));
2612 curcop->cop_line = oldline;
2619 if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
2620 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
2622 Newz(1101, logop, 1, LOGOP);
2624 logop->op_type = type;
2625 logop->op_ppaddr = ppaddr[type];
2626 logop->op_first = first;
2627 logop->op_flags = flags | OPf_KIDS;
2628 logop->op_other = LINKLIST(other);
2629 logop->op_private = 1 | (flags >> 8);
2631 /* establish postfix order */
2632 logop->op_next = LINKLIST(first);
2633 first->op_next = (OP*)logop;
2634 first->op_sibling = other;
2636 op = newUNOP(OP_NULL, 0, (OP*)logop);
2637 other->op_next = op;
2643 newCONDOP(flags, first, trueop, falseop)
2653 return newLOGOP(OP_AND, 0, first, trueop);
2655 return newLOGOP(OP_OR, 0, first, falseop);
2657 scalarboolean(first);
2658 if (first->op_type == OP_CONST) {
2659 if (SvTRUE(((SVOP*)first)->op_sv)) {
2670 else if (first->op_type == OP_WANTARRAY) {
2674 Newz(1101, condop, 1, CONDOP);
2676 condop->op_type = OP_COND_EXPR;
2677 condop->op_ppaddr = ppaddr[OP_COND_EXPR];
2678 condop->op_first = first;
2679 condop->op_flags = flags | OPf_KIDS;
2680 condop->op_true = LINKLIST(trueop);
2681 condop->op_false = LINKLIST(falseop);
2682 condop->op_private = 1 | (flags >> 8);
2684 /* establish postfix order */
2685 condop->op_next = LINKLIST(first);
2686 first->op_next = (OP*)condop;
2688 first->op_sibling = trueop;
2689 trueop->op_sibling = falseop;
2690 op = newUNOP(OP_NULL, 0, (OP*)condop);
2692 trueop->op_next = op;
2693 falseop->op_next = op;
2699 newRANGE(flags, left, right)
2709 Newz(1101, condop, 1, CONDOP);
2711 condop->op_type = OP_RANGE;
2712 condop->op_ppaddr = ppaddr[OP_RANGE];
2713 condop->op_first = left;
2714 condop->op_flags = OPf_KIDS;
2715 condop->op_true = LINKLIST(left);
2716 condop->op_false = LINKLIST(right);
2717 condop->op_private = 1 | (flags >> 8);
2719 left->op_sibling = right;
2721 condop->op_next = (OP*)condop;
2722 flip = newUNOP(OP_FLIP, flags, (OP*)condop);
2723 flop = newUNOP(OP_FLOP, 0, flip);
2724 op = newUNOP(OP_NULL, 0, flop);
2727 left->op_next = flip;
2728 right->op_next = flop;
2730 condop->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2731 sv_upgrade(PAD_SV(condop->op_targ), SVt_PVNV);
2732 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2733 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
2735 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2736 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2739 if (!flip->op_private || !flop->op_private)
2740 linklist(op); /* blow off optimizer unless constant */
2746 newLOOPOP(flags, debuggable, expr, block)
2754 int once = block && block->op_flags & OPf_SPECIAL &&
2755 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
2758 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
2759 return block; /* do {} while 0 does once */
2760 if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB) {
2761 expr = newUNOP(OP_DEFINED, 0,
2762 newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr) );
2766 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
2767 op = newLOGOP(OP_AND, 0, expr, listop);
2769 ((LISTOP*)listop)->op_last->op_next = LINKLIST(op);
2771 if (once && op != listop)
2772 op->op_next = ((LOGOP*)cUNOP->op_first)->op_other;
2775 op = newUNOP(OP_NULL, 0, op); /* or do {} while 1 loses outer block */
2777 op->op_flags |= flags;
2779 op->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/
2784 newWHILEOP(flags, debuggable, loop, expr, block, cont)
2798 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB)) {
2799 expr = newUNOP(OP_DEFINED, 0,
2800 newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr) );
2804 block = newOP(OP_NULL, 0);
2807 next = LINKLIST(cont);
2809 cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
2811 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
2812 redo = LINKLIST(listop);
2815 op = newLOGOP(OP_AND, 0, expr, scalar(listop));
2816 if (op == expr && op->op_type == OP_CONST && !SvTRUE(cSVOP->op_sv)) {
2817 op_free(expr); /* oops, it's a while (0) */
2819 return Nullop; /* (listop already freed by newLOGOP) */
2821 ((LISTOP*)listop)->op_last->op_next = condop =
2822 (op == listop ? redo : LINKLIST(op));
2830 Newz(1101,loop,1,LOOP);
2831 loop->op_type = OP_ENTERLOOP;
2832 loop->op_ppaddr = ppaddr[OP_ENTERLOOP];
2833 loop->op_private = 0;
2834 loop->op_next = (OP*)loop;
2837 op = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, op);
2839 loop->op_redoop = redo;
2840 loop->op_lastop = op;
2843 loop->op_nextop = next;
2845 loop->op_nextop = op;
2847 op->op_flags |= flags;
2848 op->op_private |= (flags >> 8);
2853 #ifndef CAN_PROTOTYPE
2854 newFOROP(flags,label,forline,sv,expr,block,cont)
2863 newFOROP(I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
2864 #endif /* CAN_PROTOTYPE */
2872 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
2873 sv->op_type = OP_RV2GV;
2874 sv->op_ppaddr = ppaddr[OP_RV2GV];
2876 else if (sv->op_type == OP_PADSV) { /* private variable */
2877 padoff = sv->op_targ;
2882 croak("Can't use %s for loop variable", op_desc[sv->op_type]);
2885 sv = newGVOP(OP_GV, 0, defgv);
2887 if (expr->op_type == OP_RV2AV || expr->op_type == OP_PADAV) {
2888 expr = scalar(ref(expr, OP_ITER));
2889 iterflags |= OPf_STACKED;
2891 loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
2892 append_elem(OP_LIST, mod(force_list(expr), OP_GREPSTART),
2894 assert(!loop->op_next);
2895 Renew(loop, 1, LOOP);
2896 loop->op_targ = padoff;
2897 return newSTATEOP(0, label, newWHILEOP(flags, 1, loop,
2898 newOP(OP_ITER, 0), block, cont));
2902 newLOOPEX(type, label)
2907 if (type != OP_GOTO || label->op_type == OP_CONST) {
2908 op = newPVOP(type, 0, savepv(
2909 label->op_type == OP_CONST
2910 ? SvPVx(((SVOP*)label)->op_sv, na)
2915 if (label->op_type == OP_ENTERSUB)
2916 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
2917 op = newUNOP(type, OPf_STACKED, label);
2919 hints |= HINT_BLOCK_SCOPE;
2927 if (!CvXSUB(cv) && CvROOT(cv)) {
2929 croak("Can't undef active subroutine");
2936 op_free(CvROOT(cv));
2937 CvROOT(cv) = Nullop;
2940 SvPOK_off((SV*)cv); /* forget prototype */
2942 SvREFCNT_dec(CvGV(cv));
2944 SvREFCNT_dec(CvOUTSIDE(cv));
2945 CvOUTSIDE(cv) = Nullcv;
2946 if (CvPADLIST(cv)) {
2947 /* may be during global destruction */
2948 if (SvREFCNT(CvPADLIST(cv))) {
2949 I32 i = AvFILL(CvPADLIST(cv));
2951 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
2952 SV* sv = svp ? *svp : Nullsv;
2955 if (sv == (SV*)comppad_name)
2956 comppad_name = Nullav;
2957 else if (sv == (SV*)comppad) {
2959 curpad = Null(SV**);
2963 SvREFCNT_dec((SV*)CvPADLIST(cv));
2965 CvPADLIST(cv) = Nullav;
2969 #ifdef DEBUG_CLOSURES
2974 CV *outside = CvOUTSIDE(cv);
2975 AV* padlist = CvPADLIST(cv);
2982 PerlIO_printf(Perl_debug_log, "\tCV=0x%p (%s), OUTSIDE=0x%p (%s)\n",
2984 (CvANON(cv) ? "ANON"
2985 : (cv == main_cv) ? "MAIN"
2986 : CvUNIQUE(outside) ? "UNIQUE"
2987 : CvGV(cv) ? GvNAME(CvGV(cv)) : "UNDEFINED"),
2990 : CvANON(outside) ? "ANON"
2991 : (outside == main_cv) ? "MAIN"
2992 : CvUNIQUE(outside) ? "UNIQUE"
2993 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
2998 pad_name = (AV*)*av_fetch(padlist, 0, FALSE);
2999 pad = (AV*)*av_fetch(padlist, 1, FALSE);
3000 pname = AvARRAY(pad_name);
3001 ppad = AvARRAY(pad);
3003 for (ix = 1; ix <= AvFILL(pad_name); ix++) {
3004 if (SvPOK(pname[ix]))
3005 PerlIO_printf(Perl_debug_log, "\t%4d. 0x%p (%s\"%s\" %ld-%ld)\n",
3007 SvFAKE(pname[ix]) ? "FAKE " : "",
3009 (long)I_32(SvNVX(pname[ix])),
3010 (long)SvIVX(pname[ix]));
3013 #endif /* DEBUG_CLOSURES */
3016 cv_clone2(proto, outside)
3022 AV* protopadlist = CvPADLIST(proto);
3023 AV* protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
3024 AV* protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
3025 SV** pname = AvARRAY(protopad_name);
3026 SV** ppad = AvARRAY(protopad);
3027 I32 fname = AvFILL(protopad_name);
3028 I32 fpad = AvFILL(protopad);
3032 assert(!CvUNIQUE(proto));
3037 SAVESPTR(comppad_name);
3040 cv = compcv = (CV*)NEWSV(1104,0);
3041 sv_upgrade((SV *)cv, SvTYPE(proto));
3046 CvFILEGV(cv) = CvFILEGV(proto);
3047 CvGV(cv) = (GV*)SvREFCNT_inc(CvGV(proto));
3048 CvSTASH(cv) = CvSTASH(proto);
3049 CvROOT(cv) = CvROOT(proto);
3050 CvSTART(cv) = CvSTART(proto);
3052 CvOUTSIDE(cv) = (CV*)SvREFCNT_inc(outside);
3055 sv_setpvn((SV*)cv, SvPVX(proto), SvCUR(proto));
3057 comppad_name = newAV();
3058 for (ix = fname; ix >= 0; ix--)
3059 av_store(comppad_name, ix, SvREFCNT_inc(pname[ix]));
3063 comppadlist = newAV();
3064 AvREAL_off(comppadlist);
3065 av_store(comppadlist, 0, (SV*)comppad_name);
3066 av_store(comppadlist, 1, (SV*)comppad);
3067 CvPADLIST(cv) = comppadlist;
3068 av_fill(comppad, AvFILL(protopad));
3069 curpad = AvARRAY(comppad);
3071 av = newAV(); /* will be @_ */
3073 av_store(comppad, 0, (SV*)av);
3074 AvFLAGS(av) = AVf_REIFY;
3076 for (ix = fpad; ix > 0; ix--) {
3077 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
3078 if (namesv && namesv != &sv_undef) {
3079 char *name = SvPVX(namesv); /* XXX */
3080 if (SvFLAGS(namesv) & SVf_FAKE) { /* lexical from outside? */
3081 I32 off = pad_findlex(name, ix, SvIVX(namesv),
3082 CvOUTSIDE(cv), cxstack_ix);
3084 curpad[ix] = SvREFCNT_inc(ppad[ix]);
3086 croak("panic: cv_clone: %s", name);
3088 else { /* our own lexical */
3091 /* anon code -- we'll come back for it */
3092 sv = SvREFCNT_inc(ppad[ix]);
3094 else if (*name == '@')
3096 else if (*name == '%')
3106 SV* sv = NEWSV(0,0);
3112 /* Now that vars are all in place, clone nested closures. */
3114 for (ix = fpad; ix > 0; ix--) {
3115 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
3117 && namesv != &sv_undef
3118 && !(SvFLAGS(namesv) & SVf_FAKE)
3119 && *SvPVX(namesv) == '&'
3120 && CvCLONE(ppad[ix]))
3122 CV *kid = cv_clone2((CV*)ppad[ix], cv);
3123 SvREFCNT_dec(ppad[ix]);
3126 curpad[ix] = (SV*)kid;
3130 #ifdef DEBUG_CLOSURES
3131 PerlIO_printf(Perl_debug_log, "Cloned inside:\n");
3133 PerlIO_printf(Perl_debug_log, " from:\n");
3135 PerlIO_printf(Perl_debug_log, " to:\n");
3147 return cv_clone2(proto, CvOUTSIDE(proto));
3151 cv_ckproto(cv, gv, p)
3156 if ((!p != !SvPOK(cv)) || (p && strNE(p, SvPVX(cv)))) {
3157 SV* msg = sv_newmortal();
3161 gv_efullname3(name = sv_newmortal(), gv, Nullch);
3162 sv_setpv(msg, "Prototype mismatch:");
3164 sv_catpvf(msg, " sub %_", name);
3166 sv_catpvf(msg, " (%s)", SvPVX(cv));
3167 sv_catpv(msg, " vs ");
3169 sv_catpvf(msg, "(%s)", p);
3171 sv_catpv(msg, "none");
3183 if (!cv || !SvPOK(cv) || SvCUR(cv))
3187 for (o = CvSTART(cv); o; o = o->op_next) {
3188 OPCODE type = o->op_type;
3190 if (type == OP_NEXTSTATE || type == OP_NULL || type == OP_PUSHMARK)
3192 if (type == OP_LEAVESUB || type == OP_RETURN)
3196 if (type == OP_CONST)
3197 sv = ((SVOP*)o)->op_sv;
3198 else if (type == OP_PADSV) {
3199 AV* pad = (AV*)(AvARRAY(CvPADLIST(cv))[1]);
3200 sv = pad ? AvARRAY(pad)[o->op_targ] : Nullsv;
3201 if (!sv || (!SvREADONLY(sv) && SvREFCNT(sv) > 1))
3213 newSUB(floor,op,proto,block)
3219 char *name = op ? SvPVx(cSVOP->op_sv, na) : Nullch;
3220 GV *gv = gv_fetchpv(name ? name : "__ANON__", GV_ADDMULTI, SVt_PVCV);
3221 char *ps = proto ? SvPVx(((SVOP*)proto)->op_sv, na) : Nullch;
3230 if (!name || GvCVGEN(gv))
3232 else if (cv = GvCV(gv)) {
3233 cv_ckproto(cv, gv, ps);
3234 /* already defined (or promised)? */
3235 if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
3238 /* just a "sub foo;" when &foo is already defined */
3242 /* ahem, death to those who redefine active sort subs */
3243 if (curstack == sortstack && sortcop == CvSTART(cv))
3244 croak("Can't redefine active sort subroutine %s", name);
3245 const_sv = cv_const_sv(cv);
3246 if (const_sv || dowarn) {
3247 line_t oldline = curcop->cop_line;
3248 curcop->cop_line = copline;
3249 warn(const_sv ? "Constant subroutine %s redefined"
3250 : "Subroutine %s redefined", name);
3251 curcop->cop_line = oldline;
3257 if (cv) { /* must reuse cv if autoloaded */
3259 CvFLAGS(cv) = CvFLAGS(compcv);
3260 CvOUTSIDE(cv) = CvOUTSIDE(compcv);
3261 CvOUTSIDE(compcv) = 0;
3262 CvPADLIST(cv) = CvPADLIST(compcv);
3263 CvPADLIST(compcv) = 0;
3264 if (SvREFCNT(compcv) > 1) /* XXX Make closures transit through stub. */
3265 CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc((SV*)cv);
3266 SvREFCNT_dec(compcv);
3276 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
3277 CvFILEGV(cv) = curcop->cop_filegv;
3278 CvSTASH(cv) = curstash;
3281 sv_setpv((SV*)cv, ps);
3287 char *s = strrchr(name, ':');
3289 if (strEQ(s, "BEGIN")) {
3291 "BEGIN not safe after errors--compilation aborted";
3295 /* force display of errors found but not reported */
3296 sv_catpv(GvSV(errgv), not_safe);
3297 croak("%s", SvPVx(GvSV(errgv), na));
3308 if (AvFILL(comppad_name) < AvFILL(comppad))
3309 av_store(comppad_name, AvFILL(comppad), Nullsv);
3312 SV **namep = AvARRAY(comppad_name);
3313 for (ix = AvFILL(comppad); ix > 0; ix--) {
3316 if (SvIMMORTAL(curpad[ix]))
3319 * The only things that a clonable function needs in its
3320 * pad are references to outer lexicals and anonymous subs.
3321 * The rest are created anew during cloning.
3323 if (!((namesv = namep[ix]) != Nullsv &&
3324 namesv != &sv_undef &&
3326 *SvPVX(namesv) == '&')))
3328 SvREFCNT_dec(curpad[ix]);
3329 curpad[ix] = Nullsv;
3334 AV *av = newAV(); /* Will be @_ */
3336 av_store(comppad, 0, (SV*)av);
3337 AvFLAGS(av) = AVf_REIFY;
3339 for (ix = AvFILL(comppad); ix > 0; ix--) {
3340 if (SvIMMORTAL(curpad[ix]))
3342 if (!SvPADMY(curpad[ix]))
3343 SvPADTMP_on(curpad[ix]);
3347 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
3348 CvSTART(cv) = LINKLIST(CvROOT(cv));
3349 CvROOT(cv)->op_next = 0;
3355 if (perldb && curstash != debstash) {
3356 SV *sv = NEWSV(0,0);
3357 SV *tmpstr = sv_newmortal();
3358 static GV *db_postponed;
3362 sv_setpvf(sv, "%_:%ld-%ld",
3363 GvSV(curcop->cop_filegv),
3364 (long)subline, (long)curcop->cop_line);
3365 gv_efullname3(tmpstr, gv, Nullch);
3366 hv_store(GvHV(DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
3367 if (!db_postponed) {
3368 db_postponed = gv_fetchpv("DB::postponed", GV_ADDMULTI, SVt_PVHV);
3370 hv = GvHVn(db_postponed);
3371 if (HvFILL(hv) > 0 && hv_exists(hv, SvPVX(tmpstr), SvCUR(tmpstr))
3372 && (cv = GvCV(db_postponed))) {
3377 perl_call_sv((SV*)cv, G_DISCARD);
3381 if ((s = strrchr(name,':')))
3385 if (strEQ(s, "BEGIN")) {
3386 I32 oldscope = scopestack_ix;
3388 SAVESPTR(compiling.cop_filegv);
3389 SAVEI16(compiling.cop_line);
3396 DEBUG_x( dump_sub(gv) );
3397 av_push(beginav, (SV *)cv);
3399 call_list(oldscope, beginav);
3401 curcop = &compiling;
3404 else if (strEQ(s, "END") && !error_count) {
3407 av_unshift(endav, 1);
3408 av_store(endav, 0, (SV *)cv);
3421 newXSUB(name, ix, subaddr, filename)
3427 CV* cv = newXS(name, (void(*)())subaddr, filename);
3429 CvXSUBANY(cv).any_i32 = ix;
3435 newXS(name, subaddr, filename)
3437 void (*subaddr) _((CV*));
3440 GV *gv = gv_fetchpv(name ? name : "__ANON__", GV_ADDMULTI, SVt_PVCV);
3443 if (cv = (name ? GvCV(gv) : Nullcv)) {
3445 /* just a cached method */
3449 else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
3450 /* already defined (or promised) */
3452 line_t oldline = curcop->cop_line;
3453 curcop->cop_line = copline;
3454 warn("Subroutine %s redefined",name);
3455 curcop->cop_line = oldline;
3462 if (cv) /* must reuse cv if autoloaded */
3465 cv = (CV*)NEWSV(1105,0);
3466 sv_upgrade((SV *)cv, SVt_PVCV);
3473 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
3474 CvFILEGV(cv) = gv_fetchfile(filename);
3475 CvXSUB(cv) = subaddr;
3478 char *s = strrchr(name,':');
3483 if (strEQ(s, "BEGIN")) {
3486 av_push(beginav, (SV *)cv);
3489 else if (strEQ(s, "END")) {
3492 av_unshift(endav, 1);
3493 av_store(endav, 0, (SV *)cv);
3504 newFORM(floor,op,block)
3515 name = SvPVx(cSVOP->op_sv, na);
3518 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
3520 if (cv = GvFORM(gv)) {
3522 line_t oldline = curcop->cop_line;
3524 curcop->cop_line = copline;
3525 warn("Format %s redefined",name);
3526 curcop->cop_line = oldline;
3532 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
3533 CvFILEGV(cv) = curcop->cop_filegv;
3535 for (ix = AvFILL(comppad); ix > 0; ix--) {
3536 if (!SvPADMY(curpad[ix]) && !SvIMMORTAL(curpad[ix]))
3537 SvPADTMP_on(curpad[ix]);
3540 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
3541 CvSTART(cv) = LINKLIST(CvROOT(cv));
3542 CvROOT(cv)->op_next = 0;
3553 return newUNOP(OP_REFGEN, 0,
3554 mod(list(convert(OP_ANONLIST, 0, op)), OP_REFGEN));
3561 return newUNOP(OP_REFGEN, 0,
3562 mod(list(convert(OP_ANONHASH, 0, op)), OP_REFGEN));
3566 newANONSUB(floor, proto, block)
3571 return newUNOP(OP_REFGEN, 0,
3572 newSVOP(OP_ANONCODE, 0, (SV*)newSUB(floor, 0, proto, block)));
3579 switch (o->op_type) {
3581 o->op_type = OP_PADAV;
3582 o->op_ppaddr = ppaddr[OP_PADAV];
3583 return ref(newUNOP(OP_RV2AV, 0, scalar(o)), OP_RV2AV);
3586 o->op_type = OP_RV2AV;
3587 o->op_ppaddr = ppaddr[OP_RV2AV];
3592 warn("oops: oopsAV");
3602 switch (o->op_type) {
3605 o->op_type = OP_PADHV;
3606 o->op_ppaddr = ppaddr[OP_PADHV];
3607 return ref(newUNOP(OP_RV2HV, 0, scalar(o)), OP_RV2HV);
3611 o->op_type = OP_RV2HV;
3612 o->op_ppaddr = ppaddr[OP_RV2HV];
3617 warn("oops: oopsHV");
3627 if (o->op_type == OP_PADANY) {
3628 o->op_type = OP_PADAV;
3629 o->op_ppaddr = ppaddr[OP_PADAV];
3632 return newUNOP(OP_RV2AV, 0, scalar(o));
3640 if (type == OP_MAPSTART)
3641 return newUNOP(OP_NULL, 0, o);
3642 return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
3649 if (o->op_type == OP_PADANY) {
3650 o->op_type = OP_PADHV;
3651 o->op_ppaddr = ppaddr[OP_PADHV];
3654 return newUNOP(OP_RV2HV, 0, scalar(o));
3661 croak("NOT IMPL LINE %d",__LINE__);
3671 return newUNOP(OP_RV2CV, flags, scalar(o));
3678 if (o->op_type == OP_PADANY) {
3679 o->op_type = OP_PADSV;
3680 o->op_ppaddr = ppaddr[OP_PADSV];
3683 return newUNOP(OP_RV2SV, 0, scalar(o));
3686 /* Check routines. */
3695 name = NEWSV(1106,0);
3696 sv_upgrade(name, SVt_PVNV);
3697 sv_setpvn(name, "&", 1);
3700 ix = pad_alloc(op->op_type, SVs_PADMY);
3701 av_store(comppad_name, ix, name);
3702 av_store(comppad, ix, cSVOP->op_sv);
3703 SvPADMY_on(cSVOP->op_sv);
3704 cSVOP->op_sv = Nullsv;
3705 cSVOP->op_targ = ix;
3713 op->op_private = hints;
3721 if (cUNOP->op_first->op_type == OP_CONCAT)
3722 op->op_flags |= OPf_STACKED;
3730 if (op->op_flags & OPf_KIDS) {
3733 OPCODE type = op->op_type;
3734 op = modkids(ck_fun(op), type);
3735 kid = cUNOP->op_first;
3736 newop = kUNOP->op_first->op_sibling;
3738 (newop->op_sibling ||
3739 !(opargs[newop->op_type] & OA_RETSCALAR) ||
3740 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
3741 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
3745 op_free(kUNOP->op_first);
3746 kUNOP->op_first = newop;
3748 op->op_ppaddr = ppaddr[++op->op_type];
3758 if (op->op_flags & OPf_KIDS) {
3759 OP *kid = cUNOP->op_first;
3760 if (kid->op_type == OP_HSLICE)
3761 op->op_private |= OPpSLICE;
3762 else if (kid->op_type != OP_HELEM)
3763 croak("%s argument is not a HASH element or slice",
3764 op_desc[op->op_type]);
3774 I32 type = op->op_type;
3776 if (op->op_flags & OPf_KIDS) {
3777 if (cLISTOP->op_first->op_type == OP_STUB) {
3779 op = newUNOP(type, OPf_SPECIAL,
3780 newGVOP(OP_GV, 0, gv_fetchpv("main'ARGV", TRUE, SVt_PVAV)));
3791 hints |= HINT_BLOCK_SCOPE;
3792 if (op->op_flags & OPf_KIDS) {
3793 SVOP *kid = (SVOP*)cUNOP->op_first;
3796 op->op_flags &= ~OPf_KIDS;
3799 else if (kid->op_type == OP_LINESEQ) {
3802 kid->op_next = op->op_next;
3803 cUNOP->op_first = 0;
3806 Newz(1101, enter, 1, LOGOP);
3807 enter->op_type = OP_ENTERTRY;
3808 enter->op_ppaddr = ppaddr[OP_ENTERTRY];
3809 enter->op_private = 0;
3811 /* establish postfix order */
3812 enter->op_next = (OP*)enter;
3814 op = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
3815 op->op_type = OP_LEAVETRY;
3816 op->op_ppaddr = ppaddr[OP_LEAVETRY];
3817 enter->op_other = op;
3823 op = newUNOP(OP_ENTEREVAL, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3825 op->op_targ = (PADOFFSET)hints;
3834 if (op->op_flags & OPf_STACKED) {
3836 kid = cUNOP->op_first->op_sibling;
3837 if (kid->op_type == OP_RV2GV)
3850 if (op->op_flags & OPf_KIDS) {
3851 OP *kid = cUNOP->op_first;
3852 if (kid->op_type != OP_HELEM)
3853 croak("%s argument is not a HASH element", op_desc[op->op_type]);
3863 o = fold_constants(o);
3864 if (o->op_type == OP_CONST)
3873 SVOP *kid = (SVOP*)cUNOP->op_first;
3875 op->op_private |= (hints & HINT_STRICT_REFS);
3876 if (kid->op_type == OP_CONST) {
3881 name = SvPV(kid->op_sv, na);
3882 if ((hints & HINT_STRICT_REFS) && (kid->op_private & OPpCONST_BARE)) {
3883 char *badthing = Nullch;
3884 switch (op->op_type) {
3886 badthing = "a SCALAR";
3889 badthing = "an ARRAY";
3892 badthing = "a HASH";
3897 "Can't use bareword (\"%s\") as %s ref while \"strict refs\" in use",
3900 kid->op_type = OP_GV;
3901 iscv = (op->op_type == OP_RV2CV) * 2;
3902 for (gv = 0; !gv; iscv++) {
3904 * This is a little tricky. We only want to add the symbol if we
3905 * didn't add it in the lexer. Otherwise we get duplicate strict
3906 * warnings. But if we didn't add it in the lexer, we must at
3907 * least pretend like we wanted to add it even if it existed before,
3908 * or we get possible typo warnings. OPpCONST_ENTERED says
3909 * whether the lexer already added THIS instance of this symbol.
3911 gv = gv_fetchpv(name,
3912 iscv | !(kid->op_private & OPpCONST_ENTERED),
3915 : op->op_type == OP_RV2SV
3917 : op->op_type == OP_RV2AV
3919 : op->op_type == OP_RV2HV
3923 SvREFCNT_dec(kid->op_sv);
3924 kid->op_sv = SvREFCNT_inc(gv);
3933 I32 type = op->op_type;
3935 if (op->op_flags & OPf_REF)
3938 if (op->op_flags & OPf_KIDS) {
3939 SVOP *kid = (SVOP*)cUNOP->op_first;
3941 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
3942 OP *newop = newGVOP(type, OPf_REF,
3943 gv_fetchpv(SvPVx(kid->op_sv, na), TRUE, SVt_PVIO));
3950 if (type == OP_FTTTY)
3951 return newGVOP(type, OPf_REF, gv_fetchpv("main'STDIN", TRUE,
3954 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3967 int type = op->op_type;
3968 register I32 oa = opargs[type] >> OASHIFT;
3970 if (op->op_flags & OPf_STACKED) {
3971 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
3974 return no_fh_allowed(op);
3977 if (op->op_flags & OPf_KIDS) {
3978 tokid = &cLISTOP->op_first;
3979 kid = cLISTOP->op_first;
3980 if (kid->op_type == OP_PUSHMARK ||
3981 kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK)
3983 tokid = &kid->op_sibling;
3984 kid = kid->op_sibling;
3986 if (!kid && opargs[type] & OA_DEFGV)
3987 *tokid = kid = newSVREF(newGVOP(OP_GV, 0, defgv));
3991 sibl = kid->op_sibling;
4005 if (kid->op_type == OP_CONST &&
4006 (kid->op_private & OPpCONST_BARE)) {
4007 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
4008 OP *newop = newAVREF(newGVOP(OP_GV, 0,
4009 gv_fetchpv(name, TRUE, SVt_PVAV) ));
4011 warn("Array @%s missing the @ in argument %ld of %s()",
4012 name, (long)numargs, op_desc[type]);
4015 kid->op_sibling = sibl;
4018 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
4019 bad_type(numargs, "array", op_desc[op->op_type], kid);
4023 if (kid->op_type == OP_CONST &&
4024 (kid->op_private & OPpCONST_BARE)) {
4025 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
4026 OP *newop = newHVREF(newGVOP(OP_GV, 0,
4027 gv_fetchpv(name, TRUE, SVt_PVHV) ));
4029 warn("Hash %%%s missing the %% in argument %ld of %s()",
4030 name, (long)numargs, op_desc[type]);
4033 kid->op_sibling = sibl;
4036 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
4037 bad_type(numargs, "hash", op_desc[op->op_type], kid);
4042 OP *newop = newUNOP(OP_NULL, 0, kid);
4043 kid->op_sibling = 0;
4045 newop->op_next = newop;
4047 kid->op_sibling = sibl;
4052 if (kid->op_type != OP_GV) {
4053 if (kid->op_type == OP_CONST &&
4054 (kid->op_private & OPpCONST_BARE)) {
4055 OP *newop = newGVOP(OP_GV, 0,
4056 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, na), TRUE,
4062 kid->op_sibling = 0;
4063 kid = newUNOP(OP_RV2GV, 0, scalar(kid));
4065 kid->op_sibling = sibl;
4071 mod(scalar(kid), type);
4075 tokid = &kid->op_sibling;
4076 kid = kid->op_sibling;
4078 op->op_private |= numargs;
4080 return too_many_arguments(op,op_desc[op->op_type]);
4083 else if (opargs[type] & OA_DEFGV) {
4085 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
4089 while (oa & OA_OPTIONAL)
4091 if (oa && oa != OA_LIST)
4092 return too_few_arguments(op,op_desc[op->op_type]);
4101 GV *gv = gv_fetchpv("glob", FALSE, SVt_PVCV);
4103 if (gv && GvIMPORTED_CV(gv)) {
4104 static int glob_index;
4106 append_elem(OP_GLOB, op,
4107 newSVOP(OP_CONST, 0, newSViv(glob_index++)));
4108 op->op_type = OP_LIST;
4109 op->op_ppaddr = ppaddr[OP_LIST];
4110 ((LISTOP*)op)->op_first->op_type = OP_PUSHMARK;
4111 ((LISTOP*)op)->op_first->op_ppaddr = ppaddr[OP_PUSHMARK];
4112 op = newUNOP(OP_ENTERSUB, OPf_STACKED,
4113 append_elem(OP_LIST, op,
4114 scalar(newUNOP(OP_RV2CV, 0,
4115 newGVOP(OP_GV, 0, gv)))));
4118 if ((op->op_flags & OPf_KIDS) && !cLISTOP->op_first->op_sibling)
4119 append_elem(OP_GLOB, op, newSVREF(newGVOP(OP_GV, 0, defgv)));
4120 gv = newGVgen("main");
4122 append_elem(OP_GLOB, op, newGVOP(OP_GV, 0, gv));
4133 OPCODE type = op->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
4135 op->op_ppaddr = ppaddr[OP_GREPSTART];
4136 Newz(1101, gwop, 1, LOGOP);
4138 if (op->op_flags & OPf_STACKED) {
4141 kid = cLISTOP->op_first->op_sibling;
4142 for (k = cLISTOP->op_first->op_sibling->op_next; k; k = k->op_next) {
4145 kid->op_next = (OP*)gwop;
4146 op->op_flags &= ~OPf_STACKED;
4148 kid = cLISTOP->op_first->op_sibling;
4149 if (type == OP_MAPWHILE)
4156 kid = cLISTOP->op_first->op_sibling;
4157 if (kid->op_type != OP_NULL)
4158 croak("panic: ck_grep");
4159 kid = kUNOP->op_first;
4161 gwop->op_type = type;
4162 gwop->op_ppaddr = ppaddr[type];
4163 gwop->op_first = listkids(op);
4164 gwop->op_flags |= OPf_KIDS;
4165 gwop->op_private = 1;
4166 gwop->op_other = LINKLIST(kid);
4167 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
4168 kid->op_next = (OP*)gwop;
4170 kid = cLISTOP->op_first->op_sibling;
4171 if (!kid || !kid->op_sibling)
4172 return too_few_arguments(op,op_desc[op->op_type]);
4173 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
4174 mod(kid, OP_GREPSTART);
4183 if (op->op_flags & OPf_KIDS) {
4184 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
4185 if (kid && kid->op_type == OP_CONST)
4186 fbm_compile(((SVOP*)kid)->op_sv);
4195 /* XXX length optimization goes here */
4203 OPCODE type = op->op_type;
4204 return modkids(ck_fun(op), type);
4211 OPCODE type = op->op_type;
4212 return refkids(ck_fun(op), type);
4221 kid = cLISTOP->op_first;
4223 op = force_list(op);
4224 kid = cLISTOP->op_first;
4226 if (kid->op_type == OP_PUSHMARK)
4227 kid = kid->op_sibling;
4228 if (kid && op->op_flags & OPf_STACKED)
4229 kid = kid->op_sibling;
4230 else if (kid && !kid->op_sibling) { /* print HANDLE; */
4231 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
4232 op->op_flags |= OPf_STACKED; /* make it a filehandle */
4233 kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
4234 cLISTOP->op_first->op_sibling = kid;
4235 cLISTOP->op_last = kid;
4236 kid = kid->op_sibling;
4241 append_elem(op->op_type, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
4247 if (hints & HINT_LOCALE)
4248 op->op_private |= OPpLOCALE;
4262 if (hints & HINT_LOCALE)
4263 op->op_private |= OPpLOCALE;
4275 if (hints & HINT_LOCALE)
4276 op->op_private |= OPpLOCALE;
4286 op->op_private |= OPpRUNTIME;
4301 if (cBINOP->op_first->op_flags & OPf_PARENS) {
4302 op->op_private |= OPpREPEAT_DOLIST;
4303 cBINOP->op_first = force_list(cBINOP->op_first);
4314 if (op->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
4315 SVOP *kid = (SVOP*)cUNOP->op_first;
4317 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
4319 for (s = SvPVX(kid->op_sv); *s; s++) {
4320 if (*s == ':' && s[1] == ':') {
4322 Move(s+2, s+1, strlen(s+2)+1, char);
4323 --SvCUR(kid->op_sv);
4326 sv_catpvn(kid->op_sv, ".pm", 3);
4336 croak("NOT IMPL LINE %d",__LINE__);
4346 if (op->op_flags & OPf_KIDS) {
4347 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
4348 if (kid && kid->op_sibling) {
4349 op->op_type = OP_SSELECT;
4350 op->op_ppaddr = ppaddr[OP_SSELECT];
4352 return fold_constants(op);
4356 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
4357 if (kid && kid->op_type == OP_RV2GV)
4358 kid->op_private &= ~HINT_STRICT_REFS;
4366 I32 type = op->op_type;
4368 if (!(op->op_flags & OPf_KIDS)) {
4370 return newUNOP(type, 0,
4371 scalar(newUNOP(OP_RV2AV, 0,
4372 scalar(newGVOP(OP_GV, 0, subline
4374 : gv_fetchpv("ARGV", TRUE, SVt_PVAV) )))));
4376 return scalar(modkids(ck_fun(op), type));
4385 if (hints & HINT_LOCALE)
4386 op->op_private |= OPpLOCALE;
4389 if (op->op_flags & OPf_STACKED) {
4390 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
4392 kid = kUNOP->op_first; /* get past rv2gv */
4394 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
4396 if (kid->op_type == OP_SCOPE) {
4400 else if (kid->op_type == OP_LEAVE) {
4401 if (op->op_type == OP_SORT) {
4402 null(kid); /* wipe out leave */
4405 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
4406 if (k->op_next == kid)
4411 kid->op_next = 0; /* just disconnect the leave */
4412 k = kLISTOP->op_first;
4416 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
4417 null(kid); /* wipe out rv2gv */
4418 if (op->op_type == OP_SORT)
4422 op->op_flags |= OPf_SPECIAL;
4436 if (op->op_flags & OPf_STACKED)
4437 return no_fh_allowed(op);
4439 kid = cLISTOP->op_first;
4440 if (kid->op_type != OP_NULL)
4441 croak("panic: ck_split");
4442 kid = kid->op_sibling;
4443 op_free(cLISTOP->op_first);
4444 cLISTOP->op_first = kid;
4446 cLISTOP->op_first = kid = newSVOP(OP_CONST, 0, newSVpv(" ", 1));
4447 cLISTOP->op_last = kid; /* There was only one element previously */
4450 if (kid->op_type != OP_MATCH) {
4451 OP *sibl = kid->op_sibling;
4452 kid->op_sibling = 0;
4453 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
4454 if (cLISTOP->op_first == cLISTOP->op_last)
4455 cLISTOP->op_last = kid;
4456 cLISTOP->op_first = kid;
4457 kid->op_sibling = sibl;
4460 if (pm->op_pmshort && !(pm->op_pmflags & PMf_ALL)) {
4461 SvREFCNT_dec(pm->op_pmshort); /* can't use substring to optimize */
4465 kid->op_type = OP_PUSHRE;
4466 kid->op_ppaddr = ppaddr[OP_PUSHRE];
4469 if (!kid->op_sibling)
4470 append_elem(OP_SPLIT, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
4472 kid = kid->op_sibling;
4475 if (!kid->op_sibling)
4476 append_elem(OP_SPLIT, op, newSVOP(OP_CONST, 0, newSViv(0)));
4478 kid = kid->op_sibling;
4481 if (kid->op_sibling)
4482 return too_many_arguments(op,op_desc[op->op_type]);
4491 OP *prev = ((cUNOP->op_first->op_sibling)
4492 ? cUNOP : ((UNOP*)cUNOP->op_first))->op_first;
4493 OP *o = prev->op_sibling;
4501 for (cvop = o; cvop->op_sibling; cvop = cvop->op_sibling) ;
4502 if (cvop->op_type == OP_RV2CV) {
4504 op->op_private |= (cvop->op_private & OPpENTERSUB_AMPER);
4505 null(cvop); /* disable rv2cv */
4506 tmpop = (SVOP*)((UNOP*)cvop)->op_first;
4507 if (tmpop->op_type == OP_GV) {
4508 cv = GvCVu(tmpop->op_sv);
4509 if (cv && SvPOK(cv) && !(op->op_private & OPpENTERSUB_AMPER)) {
4510 namegv = CvANON(cv) ? (GV*)tmpop->op_sv : CvGV(cv);
4511 proto = SvPV((SV*)cv, na);
4515 op->op_private |= (hints & HINT_STRICT_REFS);
4516 if (perldb && curstash != debstash)
4517 op->op_private |= OPpENTERSUB_DB;
4522 return too_many_arguments(op, gv_ename(namegv));
4540 if (o->op_type != OP_REFGEN && o->op_type != OP_UNDEF)
4541 bad_type(arg, "block", gv_ename(namegv), o);
4546 if (o->op_type == OP_RV2GV)
4550 o = newUNOP(OP_RV2GV, 0, kid);
4551 o->op_sibling = kid->op_sibling;
4552 kid->op_sibling = 0;
4553 prev->op_sibling = o;
4561 if (o->op_type != OP_RV2GV)
4562 bad_type(arg, "symbol", gv_ename(namegv), o);
4565 if (o->op_type != OP_RV2CV)
4566 bad_type(arg, "sub", gv_ename(namegv), o);
4569 if (o->op_type != OP_RV2SV && o->op_type != OP_PADSV)
4570 bad_type(arg, "scalar", gv_ename(namegv), o);
4573 if (o->op_type != OP_RV2AV && o->op_type != OP_PADAV)
4574 bad_type(arg, "array", gv_ename(namegv), o);
4577 if (o->op_type != OP_RV2HV && o->op_type != OP_PADHV)
4578 bad_type(arg, "hash", gv_ename(namegv), o);
4582 o = newUNOP(OP_REFGEN, 0, kid);
4583 o->op_sibling = kid->op_sibling;
4584 kid->op_sibling = 0;
4585 prev->op_sibling = o;
4596 croak("Malformed prototype for %s: %s",
4597 gv_ename(namegv), SvPV((SV*)cv, na));
4602 mod(o, OP_ENTERSUB);
4606 if (proto && !optional && *proto == '$')
4607 return too_few_arguments(op, gv_ename(namegv));
4615 SvREADONLY_on(cSVOP->op_sv);
4623 if (op->op_flags & OPf_KIDS) {
4624 SVOP *kid = (SVOP*)cUNOP->op_first;
4626 if (kid->op_type == OP_NULL)
4627 kid = (SVOP*)kid->op_sibling;
4629 kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE))
4630 op->op_flags |= OPf_SPECIAL;
4635 /* A peephole optimizer. We visit the ops in the order they're to execute. */
4641 register OP* oldop = 0;
4642 if (!o || o->op_seq)
4647 for (; o; o = o->op_next) {
4653 switch (o->op_type) {
4656 curcop = ((COP*)o); /* for warnings */
4657 o->op_seq = op_seqmax++;
4668 if (o->op_next->op_type == OP_STRINGIFY)
4670 o->op_seq = op_seqmax++;
4673 if ((o->op_flags & OPf_WANT) != OPf_WANT_LIST) {
4674 o->op_seq = op_seqmax++;
4675 break; /* Scalar stub must produce undef. List stub is noop */
4679 if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE)
4680 curcop = ((COP*)op);
4686 if (oldop && o->op_next) {
4687 oldop->op_next = o->op_next;
4690 o->op_seq = op_seqmax++;
4694 if (o->op_next->op_type == OP_RV2SV) {
4695 if (!(o->op_next->op_private & OPpDEREF)) {
4697 o->op_private |= o->op_next->op_private & OPpLVAL_INTRO;
4698 o->op_next = o->op_next->op_next;
4699 o->op_type = OP_GVSV;
4700 o->op_ppaddr = ppaddr[OP_GVSV];
4703 else if (o->op_next->op_type == OP_RV2AV) {
4704 OP* pop = o->op_next->op_next;
4706 if (pop->op_type == OP_CONST &&
4707 (op = pop->op_next) &&
4708 pop->op_next->op_type == OP_AELEM &&
4709 !(pop->op_next->op_private &
4710 (OPpLVAL_INTRO|OPpLVAL_DEFER|OPpDEREF)) &&
4711 (i = SvIV(((SVOP*)pop)->op_sv) - compiling.cop_arybase)
4715 SvREFCNT_dec(((SVOP*)pop)->op_sv);
4719 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
4720 o->op_next = pop->op_next->op_next;
4721 o->op_type = OP_AELEMFAST;
4722 o->op_ppaddr = ppaddr[OP_AELEMFAST];
4723 o->op_private = (U8)i;
4724 GvAVn(((GVOP*)o)->op_gv);
4727 o->op_seq = op_seqmax++;
4734 o->op_seq = op_seqmax++;
4735 peep(cLOGOP->op_other);
4739 o->op_seq = op_seqmax++;
4740 peep(cCONDOP->op_true);
4741 peep(cCONDOP->op_false);
4745 o->op_seq = op_seqmax++;
4746 peep(cLOOP->op_redoop);
4747 peep(cLOOP->op_nextop);
4748 peep(cLOOP->op_lastop);
4753 o->op_seq = op_seqmax++;
4754 peep(cPMOP->op_pmreplstart);
4758 o->op_seq = op_seqmax++;
4759 if (dowarn && o->op_next && o->op_next->op_type == OP_NEXTSTATE) {
4760 if (o->op_next->op_sibling &&
4761 o->op_next->op_sibling->op_type != OP_DIE) {
4762 line_t oldline = curcop->cop_line;
4764 curcop->cop_line = ((COP*)o->op_next)->cop_line;
4765 warn("Statement unlikely to be reached");
4766 warn("(Maybe you meant system() when you said exec()?)\n");
4767 curcop->cop_line = oldline;
4772 o->op_seq = op_seqmax++;