3 * Copyright (c) 1991-1994, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 * "You see: Mr. Drogo, he married poor Miss Primula Brandybuck. She was
12 * our Mr. Bilbo's first cousin on the mother's side (her mother being the
13 * youngest of the Old Took's daughters); and Mr. Drogo was his second
14 * cousin. So Mr. Frodo is his first *and* second cousin, once removed
15 * either way, as the saying is, if you follow me." --the Gaffer
21 #define USE_OP_MASK /* Turned on by default in 5.002beta1h */
25 * In the following definition, the ", (OP *) op" is just to make the compiler
26 * think the expression is of the right type: croak actually does a Siglongjmp.
28 #define CHECKOP(type,op) \
29 ((op_mask && op_mask[type]) \
30 ? (croak("%s trapped by operation mask", op_desc[type]), (OP*)op) \
31 : (*check[type])((OP*)op))
33 #define CHECKOP(type,op) (*check[type])(op)
34 #endif /* USE_OP_MASK */
36 static I32 list_assignment _((OP *op));
37 static OP *bad_type _((I32 n, char *t, char *name, OP *kid));
38 static OP *modkids _((OP *op, I32 type));
39 static OP *no_fh_allowed _((OP *op));
40 static OP *scalarboolean _((OP *op));
41 static OP *too_few_arguments _((OP *op, char* name));
42 static OP *too_many_arguments _((OP *op, char* name));
43 static void null _((OP* op));
44 static PADOFFSET pad_findlex _((char* name, PADOFFSET newoff, U32 seq,
45 CV* startcv, I32 cx_ix));
51 SV* tmpsv = sv_newmortal();
52 gv_efullname3(tmpsv, CvGV(cv), Nullch);
53 return SvPV(tmpsv,na);
60 sprintf(tokenbuf,"Missing comma after first argument to %s function",
61 op_desc[op->op_type]);
67 too_few_arguments(op, name)
71 sprintf(tokenbuf,"Not enough arguments for %s", name);
77 too_many_arguments(op, name)
81 sprintf(tokenbuf,"Too many arguments for %s", name);
87 bad_type(n, t, name, kid)
93 sprintf(tokenbuf, "Type of arg %d to %s must be %s (not %s)",
94 (int) n, name, t, op_desc[kid->op_type]);
103 int type = op->op_type;
104 if (type != OP_AELEM && type != OP_HELEM) {
105 sprintf(tokenbuf, "Can't use subscript on %s", op_desc[type]);
107 if (type == OP_RV2HV || type == OP_ENTERSUB)
108 warn("(Did you mean $ or @ instead of %c?)\n",
109 type == OP_RV2HV ? '%' : '&');
113 /* "register" allocation */
122 if (!(isALPHA(name[1]) || name[1] == '_' && (int)strlen(name) > 2)) {
123 if (!isPRINT(name[1]))
124 sprintf(name+1, "^%c", toCTRL(name[1])); /* XXX tokenbuf, really */
125 croak("Can't use global %s in \"my\"",name);
127 if (AvFILL(comppad_name) >= 0) {
128 SV **svp = AvARRAY(comppad_name);
129 for (off = AvFILL(comppad_name); off > comppad_name_floor; off--) {
132 && SvIVX(sv) == 999999999 /* var is in open scope */
133 && strEQ(name, SvPVX(sv)))
135 warn("\"my\" variable %s masks earlier declaration in same scope", name);
140 off = pad_alloc(OP_PADSV, SVs_PADMY);
142 sv_upgrade(sv, SVt_PVNV);
144 av_store(comppad_name, off, sv);
145 SvNVX(sv) = (double)999999999;
146 SvIVX(sv) = 0; /* Not yet introduced--see newSTATEOP */
147 if (!min_intro_pending)
148 min_intro_pending = off;
149 max_intro_pending = off;
151 av_store(comppad, off, (SV*)newAV());
152 else if (*name == '%')
153 av_store(comppad, off, (SV*)newHV());
154 SvPADMY_on(curpad[off]);
159 #ifndef CAN_PROTOTYPE
160 pad_findlex(name, newoff, seq, startcv, cx_ix)
167 pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix)
174 register CONTEXT *cx;
177 for (cv = startcv; cv; cv = CvOUTSIDE(cv)) {
178 AV* curlist = CvPADLIST(cv);
179 SV** svp = av_fetch(curlist, 0, FALSE);
181 if (!svp || *svp == &sv_undef)
184 svp = AvARRAY(curname);
185 for (off = AvFILL(curname); off > 0; off--) {
186 if ((sv = svp[off]) &&
189 seq > (I32)SvNVX(sv) &&
190 strEQ(SvPVX(sv), name))
192 I32 depth = CvDEPTH(cv) ? CvDEPTH(cv) : 1;
193 AV *oldpad = (AV*)*av_fetch(curlist, depth, FALSE);
194 SV *oldsv = *av_fetch(oldpad, off, TRUE);
195 if (!newoff) { /* Not a mere clone operation. */
196 SV *sv = NEWSV(1103,0);
197 newoff = pad_alloc(OP_PADSV, SVs_PADMY);
198 sv_upgrade(sv, SVt_PVNV);
200 av_store(comppad_name, newoff, sv);
201 SvNVX(sv) = (double)curcop->cop_seq;
202 SvIVX(sv) = 999999999; /* A ref, intro immediately */
203 SvFLAGS(sv) |= SVf_FAKE;
205 av_store(comppad, newoff, SvREFCNT_inc(oldsv));
212 /* Nothing in current lexical context--try eval's context, if any.
213 * This is necessary to let the perldb get at lexically scoped variables.
214 * XXX This will also probably interact badly with eval tree caching.
218 for (i = cx_ix; i >= 0; i--) {
220 switch (cx->cx_type) {
222 if (i == 0 && saweval) {
223 seq = cxstack[saweval].blk_oldcop->cop_seq;
224 return pad_findlex(name, newoff, seq, main_cv, 0);
228 if (cx->blk_eval.old_op_type != OP_ENTEREVAL &&
229 cx->blk_eval.old_op_type != OP_ENTERTRY)
230 return 0; /* require must have its own scope */
237 if (debstash && CvSTASH(cv) == debstash) { /* ignore DB'* scope */
238 saweval = i; /* so we know where we were called from */
241 seq = cxstack[saweval].blk_oldcop->cop_seq;
242 return pad_findlex(name, newoff, seq, cv, i-1);
255 SV **svp = AvARRAY(comppad_name);
256 U32 seq = cop_seqmax;
258 /* The one we're looking for is probably just before comppad_name_fill. */
259 for (off = AvFILL(comppad_name); off > 0; off--) {
260 if ((sv = svp[off]) &&
263 seq > (I32)SvNVX(sv) &&
264 strEQ(SvPVX(sv), name))
266 return (PADOFFSET)off;
270 /* See if it's in a nested scope */
271 off = pad_findlex(name, 0, seq, CvOUTSIDE(compcv), cxstack_ix);
283 SV **svp = AvARRAY(comppad_name);
285 if (min_intro_pending && fill < min_intro_pending) {
286 for (off = max_intro_pending; off >= min_intro_pending; off--) {
287 if ((sv = svp[off]) && sv != &sv_undef)
288 warn("%s never introduced", SvPVX(sv));
291 /* "Deintroduce" my variables that are leaving with this scope. */
292 for (off = AvFILL(comppad_name); off > fill; off--) {
293 if ((sv = svp[off]) && sv != &sv_undef && SvIVX(sv) == 999999999)
294 SvIVX(sv) = cop_seqmax;
299 pad_alloc(optype,tmptype)
306 if (AvARRAY(comppad) != curpad)
307 croak("panic: pad_alloc");
308 if (pad_reset_pending)
310 if (tmptype & SVs_PADMY) {
312 sv = *av_fetch(comppad, AvFILL(comppad) + 1, TRUE);
313 } while (SvPADBUSY(sv)); /* need a fresh one */
314 retval = AvFILL(comppad);
317 SV **names = AvARRAY(comppad_name);
318 SSize_t names_fill = AvFILL(comppad_name);
321 * "foreach" index vars temporarily become aliases to non-"my"
322 * values. Thus we must skip, not just pad values that are
323 * marked as current pad values, but also those with names.
325 if (++padix <= names_fill &&
326 (sv = names[padix]) && sv != &sv_undef)
328 sv = *av_fetch(comppad, padix, TRUE);
329 if (!(SvFLAGS(sv) & (SVs_PADTMP|SVs_PADMY)))
334 SvFLAGS(sv) |= tmptype;
335 curpad = AvARRAY(comppad);
336 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad alloc %ld for %s\n", (long) retval, op_name[optype]));
337 return (PADOFFSET)retval;
341 #ifndef CAN_PROTOTYPE
346 #endif /* CAN_PROTOTYPE */
349 croak("panic: pad_sv po");
350 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad sv %d\n", po));
351 return curpad[po]; /* eventually we'll turn this into a macro */
355 #ifndef CAN_PROTOTYPE
359 pad_free(PADOFFSET po)
360 #endif /* CAN_PROTOTYPE */
364 if (AvARRAY(comppad) != curpad)
365 croak("panic: pad_free curpad");
367 croak("panic: pad_free po");
368 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad free %d\n", po));
369 if (curpad[po] && curpad[po] != &sv_undef)
370 SvPADTMP_off(curpad[po]);
376 #ifndef CAN_PROTOTYPE
380 pad_swipe(PADOFFSET po)
381 #endif /* CAN_PROTOTYPE */
383 if (AvARRAY(comppad) != curpad)
384 croak("panic: pad_swipe curpad");
386 croak("panic: pad_swipe po");
387 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad swipe %d\n", po));
388 SvPADTMP_off(curpad[po]);
389 curpad[po] = NEWSV(1107,0);
390 SvPADTMP_on(curpad[po]);
400 if (AvARRAY(comppad) != curpad)
401 croak("panic: pad_reset curpad");
402 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad reset\n"));
403 if (!tainting) { /* Can't mix tainted and non-tainted temporaries. */
404 for (po = AvMAX(comppad); po > padix_floor; po--) {
405 if (curpad[po] && curpad[po] != &sv_undef)
406 SvPADTMP_off(curpad[po]);
410 pad_reset_pending = FALSE;
419 register OP *kid, *nextkid;
421 if (!op || op->op_seq == (U16)-1)
424 if (op->op_flags & OPf_KIDS) {
425 for (kid = cUNOP->op_first; kid; kid = nextkid) {
426 nextkid = kid->op_sibling; /* Get before next freeing kid */
431 switch (op->op_type) {
433 op->op_targ = 0; /* Was holding old type, if any. */
436 op->op_targ = 0; /* Was holding hints. */
440 SvREFCNT_dec(cGVOP->op_gv);
444 SvREFCNT_dec(cCOP->cop_filegv);
446 /* case OP_ANONCODE: XXX breaks eval of anon subs in closures (cf. Opcode) */
448 SvREFCNT_dec(cSVOP->op_sv);
454 if (op->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
458 Safefree(cPVOP->op_pv);
461 op_free(cPMOP->op_pmreplroot);
465 pregfree(cPMOP->op_pmregexp);
466 SvREFCNT_dec(cPMOP->op_pmshort);
473 pad_free(op->op_targ);
482 if (op->op_type != OP_NULL && op->op_targ > 0)
483 pad_free(op->op_targ);
484 op->op_targ = op->op_type;
485 op->op_type = OP_NULL;
486 op->op_ppaddr = ppaddr[OP_NULL];
489 /* Contextualizers */
491 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
502 /* establish postfix order */
503 if (cUNOP->op_first) {
504 op->op_next = LINKLIST(cUNOP->op_first);
505 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
507 kid->op_next = LINKLIST(kid->op_sibling);
523 if (op && op->op_flags & OPf_KIDS) {
524 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
535 op->op_type == OP_SASSIGN && cBINOP->op_first->op_type == OP_CONST) {
536 line_t oldline = curcop->cop_line;
538 if (copline != NOLINE)
539 curcop->cop_line = copline;
540 warn("Found = in conditional, should be ==");
541 curcop->cop_line = oldline;
552 /* assumes no premature commitment */
553 if (!op || (op->op_flags & OPf_KNOW) || error_count)
556 op->op_flags &= ~OPf_LIST;
557 op->op_flags |= OPf_KNOW;
559 switch (op->op_type) {
561 if (op->op_private & OPpREPEAT_DOLIST)
562 null(((LISTOP*)cBINOP->op_first)->op_first);
563 scalar(cBINOP->op_first);
568 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
572 if ((kid = ((LISTOP*)op)->op_first) && kid->op_type == OP_PUSHRE) {
573 if (!kPMOP->op_pmreplroot)
574 deprecate("implicit split to @_");
581 if (op->op_flags & OPf_KIDS) {
582 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling)
588 scalar(cLISTOP->op_first);
593 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
613 if (!op || error_count)
615 if (op->op_flags & OPf_LIST)
618 op->op_flags |= OPf_KNOW;
620 switch (op->op_type) {
622 if (!(opargs[op->op_type] & OA_FOLDCONST))
624 if (op->op_flags & OPf_STACKED)
697 if (!(op->op_private & OPpLVAL_INTRO))
698 useless = op_desc[op->op_type];
705 if (!(op->op_private & OPpLVAL_INTRO) &&
706 (!op->op_sibling || op->op_sibling->op_type != OP_READLINE))
707 useless = "a variable";
712 curcop = ((COP*)op); /* for warning below */
718 useless = "a constant";
719 if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
721 else if (SvPOK(sv)) {
722 if (strnEQ(SvPVX(sv), "di", 2) ||
723 strnEQ(SvPVX(sv), "ds", 2) ||
724 strnEQ(SvPVX(sv), "ig", 2))
728 null(op); /* don't execute a constant */
729 SvREFCNT_dec(sv); /* don't even remember it */
733 op->op_type = OP_PREINC; /* pre-increment is faster */
734 op->op_ppaddr = ppaddr[OP_PREINC];
738 op->op_type = OP_PREDEC; /* pre-decrement is faster */
739 op->op_ppaddr = ppaddr[OP_PREDEC];
743 scalarvoid(cBINOP->op_first);
744 useless = op_desc[op->op_type];
750 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
754 if (op->op_targ == OP_NEXTSTATE || op->op_targ == OP_DBSTATE)
755 curcop = ((COP*)op); /* for warning below */
756 if (op->op_flags & OPf_STACKED)
761 if (!(op->op_flags & OPf_KIDS))
767 op->op_private |= OPpLEAVE_VOID;
770 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
774 if ((kid = ((LISTOP*)op)->op_first) && kid->op_type == OP_PUSHRE) {
775 if (!kPMOP->op_pmreplroot)
776 deprecate("implicit split to @_");
780 op->op_private |= OPpLEAVE_VOID;
783 if (useless && dowarn)
784 warn("Useless use of %s in void context", useless);
793 if (op && op->op_flags & OPf_KIDS) {
794 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
806 /* assumes no premature commitment */
807 if (!op || (op->op_flags & OPf_KNOW) || error_count)
810 op->op_flags |= (OPf_KNOW | OPf_LIST);
812 switch (op->op_type) {
815 list(cBINOP->op_first);
820 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
827 if (!(op->op_flags & OPf_KIDS))
829 if (!op->op_next && cUNOP->op_first->op_type == OP_FLOP) {
830 list(cBINOP->op_first);
831 return gen_constant_list(op);
838 list(cLISTOP->op_first);
842 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
861 if (op->op_type == OP_LINESEQ ||
862 op->op_type == OP_SCOPE ||
863 op->op_type == OP_LEAVE ||
864 op->op_type == OP_LEAVETRY)
866 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
867 if (kid->op_sibling) {
873 op->op_flags &= ~OPf_PARENS;
874 if (hints & HINT_BLOCK_SCOPE)
875 op->op_flags |= OPf_PARENS;
878 op = newOP(OP_STUB, 0);
888 if (op && op->op_flags & OPf_KIDS) {
889 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
906 if (!op || error_count)
909 switch (op->op_type) {
911 if (!(op->op_private & (OPpCONST_ARYBASE)))
913 if (eval_start && eval_start->op_type == OP_CONST) {
914 compiling.cop_arybase = (I32)SvIV(((SVOP*)eval_start)->op_sv);
918 SAVEI32(compiling.cop_arybase);
919 compiling.cop_arybase = 0;
921 else if (type == OP_REFGEN)
924 croak("That use of $[ is unsupported");
927 if ((type == OP_UNDEF || type == OP_REFGEN) &&
928 !(op->op_flags & OPf_STACKED)) {
929 op->op_type = OP_RV2CV; /* entersub => rv2cv */
930 op->op_ppaddr = ppaddr[OP_RV2CV];
931 assert(cUNOP->op_first->op_type == OP_NULL);
932 null(((LISTOP*)cUNOP->op_first)->op_first); /* disable pushmark */
938 /* grep, foreach, subcalls, refgen */
939 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
941 sprintf(tokenbuf, "Can't modify %s in %s",
942 op_desc[op->op_type],
943 type ? op_desc[type] : "local");
967 if (!(op->op_flags & OPf_STACKED))
973 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
979 if (type == OP_REFGEN && op->op_flags & OPf_PARENS) {
981 return op; /* Treat \(@foo) like ordinary list. */
985 ref(cUNOP->op_first, op->op_type);
997 if (!type && cUNOP->op_first->op_type != OP_GV)
998 croak("Can't localize a reference");
999 ref(cUNOP->op_first, op->op_type);
1012 if (type == OP_REFGEN && op->op_flags & OPf_PARENS)
1013 return op; /* Treat \(@foo) like ordinary list. */
1018 croak("Can't localize lexical variable %s",
1019 SvPV(*av_fetch(comppad_name, op->op_targ, 4), na));
1026 if (type != OP_SASSIGN)
1039 pad_free(op->op_targ);
1040 op->op_targ = pad_alloc(op->op_type, SVs_PADMY);
1041 sv = PAD_SV(op->op_targ);
1042 sv_upgrade(sv, SVt_PVLV);
1043 sv_magic(sv, Nullsv, mtype, Nullch, 0);
1044 curpad[op->op_targ] = sv;
1045 if (op->op_flags & OPf_KIDS)
1046 mod(cBINOP->op_first->op_sibling, type);
1051 ref(cBINOP->op_first, op->op_type);
1058 if (op->op_flags & OPf_KIDS)
1059 mod(cLISTOP->op_last, type);
1063 if (!(op->op_flags & OPf_KIDS))
1065 if (op->op_targ != OP_LIST) {
1066 mod(cBINOP->op_first, type);
1071 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1075 op->op_flags |= OPf_MOD;
1077 if (type == OP_AASSIGN || type == OP_SASSIGN)
1078 op->op_flags |= OPf_SPECIAL|OPf_REF;
1080 op->op_private |= OPpLVAL_INTRO;
1081 op->op_flags &= ~OPf_SPECIAL;
1083 else if (type != OP_GREPSTART && type != OP_ENTERSUB)
1084 op->op_flags |= OPf_REF;
1094 if (op && op->op_flags & OPf_KIDS) {
1095 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1108 if (!op || error_count)
1111 switch (op->op_type) {
1113 if ((type == OP_DEFINED) &&
1114 !(op->op_flags & OPf_STACKED)) {
1115 op->op_type = OP_RV2CV; /* entersub => rv2cv */
1116 op->op_ppaddr = ppaddr[OP_RV2CV];
1117 assert(cUNOP->op_first->op_type == OP_NULL);
1118 null(((LISTOP*)cUNOP->op_first)->op_first); /* disable pushmark */
1119 op->op_flags |= OPf_SPECIAL;
1124 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
1128 ref(cUNOP->op_first, op->op_type);
1131 if (type == OP_RV2AV || type == OP_RV2HV) {
1132 op->op_private |= (type == OP_RV2AV ? OPpDEREF_AV : OPpDEREF_HV);
1133 op->op_flags |= OPf_MOD;
1139 op->op_flags |= OPf_REF;
1142 ref(cUNOP->op_first, op->op_type);
1147 op->op_flags |= OPf_REF;
1152 if (!(op->op_flags & OPf_KIDS))
1154 ref(cBINOP->op_first, type);
1158 ref(cBINOP->op_first, op->op_type);
1159 if (type == OP_RV2AV || type == OP_RV2HV) {
1160 op->op_private |= (type == OP_RV2AV ? OPpDEREF_AV : OPpDEREF_HV);
1161 op->op_flags |= OPf_MOD;
1169 if (!(op->op_flags & OPf_KIDS))
1171 ref(cLISTOP->op_last, type);
1187 if (!op || error_count)
1191 if (type == OP_LIST) {
1192 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1195 else if (type != OP_PADSV &&
1198 type != OP_PUSHMARK)
1200 sprintf(tokenbuf, "Can't declare %s in my", op_desc[op->op_type]);
1204 op->op_flags |= OPf_MOD;
1205 op->op_private |= OPpLVAL_INTRO;
1214 o->op_flags |= OPf_PARENS;
1219 bind_match(type, left, right)
1226 if (right->op_type == OP_MATCH ||
1227 right->op_type == OP_SUBST ||
1228 right->op_type == OP_TRANS) {
1229 right->op_flags |= OPf_STACKED;
1230 if (right->op_type != OP_MATCH)
1231 left = mod(left, right->op_type);
1232 if (right->op_type == OP_TRANS)
1233 op = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
1235 op = prepend_elem(right->op_type, scalar(left), right);
1237 return newUNOP(OP_NOT, 0, scalar(op));
1241 return bind_match(type, left,
1242 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
1251 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
1252 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(op));
1260 if (o->op_flags & OPf_PARENS || perldb || tainting) {
1261 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
1262 o->op_type = OP_LEAVE;
1263 o->op_ppaddr = ppaddr[OP_LEAVE];
1266 if (o->op_type == OP_LINESEQ) {
1268 o->op_type = OP_SCOPE;
1269 o->op_ppaddr = ppaddr[OP_SCOPE];
1270 kid = ((LISTOP*)o)->op_first;
1271 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE){
1272 SvREFCNT_dec(((COP*)kid)->cop_filegv);
1277 o = newLISTOP(OP_SCOPE, 0, o, Nullop);
1287 int retval = savestack_ix;
1288 SAVEI32(comppad_name_floor);
1290 if ((comppad_name_fill = AvFILL(comppad_name)) > 0)
1291 comppad_name_floor = comppad_name_fill;
1293 comppad_name_floor = 0;
1295 SAVEI32(min_intro_pending);
1296 SAVEI32(max_intro_pending);
1297 min_intro_pending = 0;
1298 SAVEI32(comppad_name_fill);
1299 SAVEI32(padix_floor);
1300 padix_floor = padix;
1301 pad_reset_pending = FALSE;
1303 hints &= ~HINT_BLOCK_SCOPE;
1308 block_end(line, floor, seq)
1313 int needblockscope = hints & HINT_BLOCK_SCOPE;
1314 OP* retval = scalarseq(seq);
1315 if (copline > (line_t)line)
1318 pad_reset_pending = FALSE;
1320 hints |= HINT_BLOCK_SCOPE; /* propagate out */
1321 pad_leavemy(comppad_name_fill);
1331 eval_root = newUNOP(OP_LEAVEEVAL, ((in_eval & 4) ? OPf_SPECIAL : 0), op);
1332 eval_start = linklist(eval_root);
1333 eval_root->op_next = 0;
1341 main_root = scope(sawparens(scalarvoid(op)));
1342 curcop = &compiling;
1343 main_start = LINKLIST(main_root);
1344 main_root->op_next = 0;
1356 if (o->op_flags & OPf_PARENS)
1360 if (dowarn && bufptr > oldbufptr && bufptr[-1] == ',') {
1362 for (s = bufptr; *s && (isALNUM(*s) || strchr("@$%, ",*s)); s++) ;
1363 if (*s == ';' || *s == '=')
1364 warn("Parens missing around \"%s\" list", lex ? "my" : "local");
1371 return mod(o, OP_NULL); /* a bit kludgey */
1378 if (o->op_type == OP_LIST) {
1379 o = convert(OP_JOIN, 0,
1380 prepend_elem(OP_LIST,
1381 newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
1392 I32 type = o->op_type;
1395 if (opargs[type] & OA_RETSCALAR)
1397 if (opargs[type] & OA_TARGET)
1398 o->op_targ = pad_alloc(type, SVs_PADTMP);
1400 if ((opargs[type] & OA_OTHERINT) && (hints & HINT_INTEGER))
1401 o->op_ppaddr = ppaddr[type = ++(o->op_type)];
1403 if (!(opargs[type] & OA_FOLDCONST))
1407 goto nope; /* Don't try to run w/ errors */
1409 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
1410 if (curop->op_type != OP_CONST &&
1411 curop->op_type != OP_LIST &&
1412 curop->op_type != OP_SCALAR &&
1413 curop->op_type != OP_NULL &&
1414 curop->op_type != OP_PUSHMARK) {
1419 curop = LINKLIST(o);
1424 if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
1425 pad_swipe(o->op_targ);
1426 else if (SvTEMP(sv)) { /* grab mortal temp? */
1427 (void)SvREFCNT_inc(sv);
1431 if (type == OP_RV2GV)
1432 return newGVOP(OP_GV, 0, (GV*)sv);
1434 if ((SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK)) == SVf_NOK) {
1436 if ((double)iv == SvNV(sv)) { /* can we smush double to int */
1441 SvIOK_off(sv); /* undo SvIV() damage */
1443 return newSVOP(OP_CONST, 0, sv);
1447 if (!(opargs[type] & OA_OTHERINT))
1450 if (!(hints & HINT_INTEGER)) {
1451 if (type == OP_DIVIDE || !(o->op_flags & OPf_KIDS))
1454 for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
1455 if (curop->op_type == OP_CONST) {
1456 if (SvIOK(((SVOP*)curop)->op_sv))
1460 if (opargs[curop->op_type] & OA_RETINTEGER)
1464 o->op_ppaddr = ppaddr[++(o->op_type)];
1471 gen_constant_list(o)
1475 I32 oldtmps_floor = tmps_floor;
1479 return o; /* Don't attempt to run with errors */
1481 op = curop = LINKLIST(o);
1487 tmps_floor = oldtmps_floor;
1489 o->op_type = OP_RV2AV;
1490 o->op_ppaddr = ppaddr[OP_RV2AV];
1491 curop = ((UNOP*)o)->op_first;
1492 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*stack_sp--));
1499 convert(type, flags, op)
1507 if (!op || op->op_type != OP_LIST)
1508 op = newLISTOP(OP_LIST, 0, op, Nullop);
1510 op->op_flags &= ~(OPf_KNOW|OPf_LIST);
1512 if (!(opargs[type] & OA_MARK))
1513 null(cLISTOP->op_first);
1516 op->op_ppaddr = ppaddr[type];
1517 op->op_flags |= flags;
1519 op = CHECKOP(type, op);
1520 if (op->op_type != type)
1523 if (cLISTOP->op_children < 7) {
1524 /* XXX do we really need to do this if we're done appending?? */
1525 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1527 cLISTOP->op_last = last; /* in case check substituted last arg */
1530 return fold_constants(op);
1533 /* List constructors */
1536 append_elem(type, first, last)
1547 if (first->op_type != type || type==OP_LIST && first->op_flags & OPf_PARENS)
1548 return newLISTOP(type, 0, first, last);
1550 if (first->op_flags & OPf_KIDS)
1551 ((LISTOP*)first)->op_last->op_sibling = last;
1553 first->op_flags |= OPf_KIDS;
1554 ((LISTOP*)first)->op_first = last;
1556 ((LISTOP*)first)->op_last = last;
1557 ((LISTOP*)first)->op_children++;
1562 append_list(type, first, last)
1573 if (first->op_type != type)
1574 return prepend_elem(type, (OP*)first, (OP*)last);
1576 if (last->op_type != type)
1577 return append_elem(type, (OP*)first, (OP*)last);
1579 first->op_last->op_sibling = last->op_first;
1580 first->op_last = last->op_last;
1581 first->op_children += last->op_children;
1582 if (first->op_children)
1583 last->op_flags |= OPf_KIDS;
1590 prepend_elem(type, first, last)
1601 if (last->op_type == type) {
1602 if (type == OP_LIST) { /* already a PUSHMARK there */
1603 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
1604 ((LISTOP*)last)->op_first->op_sibling = first;
1607 if (!(last->op_flags & OPf_KIDS)) {
1608 ((LISTOP*)last)->op_last = first;
1609 last->op_flags |= OPf_KIDS;
1611 first->op_sibling = ((LISTOP*)last)->op_first;
1612 ((LISTOP*)last)->op_first = first;
1614 ((LISTOP*)last)->op_children++;
1618 return newLISTOP(type, 0, first, last);
1626 return newOP(OP_STUB, 0);
1633 if (!op || op->op_type != OP_LIST)
1634 op = newLISTOP(OP_LIST, 0, op, Nullop);
1640 newLISTOP(type, flags, first, last)
1648 Newz(1101, listop, 1, LISTOP);
1650 listop->op_type = type;
1651 listop->op_ppaddr = ppaddr[type];
1652 listop->op_children = (first != 0) + (last != 0);
1653 listop->op_flags = flags;
1657 else if (!first && last)
1660 first->op_sibling = last;
1661 listop->op_first = first;
1662 listop->op_last = last;
1663 if (type == OP_LIST) {
1665 pushop = newOP(OP_PUSHMARK, 0);
1666 pushop->op_sibling = first;
1667 listop->op_first = pushop;
1668 listop->op_flags |= OPf_KIDS;
1670 listop->op_last = pushop;
1672 else if (listop->op_children)
1673 listop->op_flags |= OPf_KIDS;
1684 Newz(1101, op, 1, OP);
1686 op->op_ppaddr = ppaddr[type];
1687 op->op_flags = flags;
1690 op->op_private = 0 + (flags >> 8);
1691 if (opargs[type] & OA_RETSCALAR)
1693 if (opargs[type] & OA_TARGET)
1694 op->op_targ = pad_alloc(type, SVs_PADTMP);
1695 return CHECKOP(type, op);
1699 newUNOP(type, flags, first)
1707 first = newOP(OP_STUB, 0);
1708 if (opargs[type] & OA_MARK)
1709 first = force_list(first);
1711 Newz(1101, unop, 1, UNOP);
1712 unop->op_type = type;
1713 unop->op_ppaddr = ppaddr[type];
1714 unop->op_first = first;
1715 unop->op_flags = flags | OPf_KIDS;
1716 unop->op_private = 1 | (flags >> 8);
1718 unop = (UNOP*) CHECKOP(type, unop);
1722 return fold_constants((OP *) unop);
1726 newBINOP(type, flags, first, last)
1733 Newz(1101, binop, 1, BINOP);
1736 first = newOP(OP_NULL, 0);
1738 binop->op_type = type;
1739 binop->op_ppaddr = ppaddr[type];
1740 binop->op_first = first;
1741 binop->op_flags = flags | OPf_KIDS;
1744 binop->op_private = 1 | (flags >> 8);
1747 binop->op_private = 2 | (flags >> 8);
1748 first->op_sibling = last;
1751 binop = (BINOP*)CHECKOP(type, binop);
1755 binop->op_last = last = binop->op_first->op_sibling;
1757 return fold_constants((OP *)binop);
1761 pmtrans(op, expr, repl)
1766 SV *tstr = ((SVOP*)expr)->op_sv;
1767 SV *rstr = ((SVOP*)repl)->op_sv;
1770 register U8 *t = (U8*)SvPV(tstr, tlen);
1771 register U8 *r = (U8*)SvPV(rstr, rlen);
1776 register short *tbl;
1778 tbl = (short*)cPVOP->op_pv;
1779 complement = op->op_private & OPpTRANS_COMPLEMENT;
1780 delete = op->op_private & OPpTRANS_DELETE;
1781 /* squash = op->op_private & OPpTRANS_SQUASH; */
1784 Zero(tbl, 256, short);
1785 for (i = 0; i < tlen; i++)
1787 for (i = 0, j = 0; i < 256; i++) {
1803 if (!rlen && !delete) {
1806 for (i = 0; i < 256; i++)
1808 for (i = 0, j = 0; i < tlen; i++,j++) {
1811 if (tbl[t[i]] == -1)
1817 if (tbl[t[i]] == -1)
1828 newPMOP(type, flags)
1834 Newz(1101, pmop, 1, PMOP);
1835 pmop->op_type = type;
1836 pmop->op_ppaddr = ppaddr[type];
1837 pmop->op_flags = flags;
1838 pmop->op_private = 0 | (flags >> 8);
1840 /* link into pm list */
1841 if (type != OP_TRANS && curstash) {
1842 pmop->op_pmnext = HvPMROOT(curstash);
1843 HvPMROOT(curstash) = pmop;
1850 pmruntime(op, expr, repl)
1858 if (op->op_type == OP_TRANS)
1859 return pmtrans(op, expr, repl);
1863 if (expr->op_type == OP_CONST) {
1865 SV *pat = ((SVOP*)expr)->op_sv;
1866 char *p = SvPV(pat, plen);
1867 if ((op->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
1868 sv_setpvn(pat, "\\s+", 3);
1869 p = SvPV(pat, plen);
1870 pm->op_pmflags |= PMf_SKIPWHITE;
1872 pm->op_pmregexp = pregcomp(p, p + plen, pm);
1873 if (strEQ("\\s+", pm->op_pmregexp->precomp))
1874 pm->op_pmflags |= PMf_WHITE;
1879 if (pm->op_pmflags & PMf_KEEP)
1880 expr = newUNOP(OP_REGCMAYBE,0,expr);
1882 Newz(1101, rcop, 1, LOGOP);
1883 rcop->op_type = OP_REGCOMP;
1884 rcop->op_ppaddr = ppaddr[OP_REGCOMP];
1885 rcop->op_first = scalar(expr);
1886 rcop->op_flags |= OPf_KIDS;
1887 rcop->op_private = 1;
1888 rcop->op_other = op;
1890 /* establish postfix order */
1891 if (pm->op_pmflags & PMf_KEEP) {
1893 rcop->op_next = expr;
1894 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
1897 rcop->op_next = LINKLIST(expr);
1898 expr->op_next = (OP*)rcop;
1901 prepend_elem(op->op_type, scalar((OP*)rcop), op);
1906 if (pm->op_pmflags & PMf_EVAL)
1908 else if (repl->op_type == OP_CONST)
1912 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
1913 if (opargs[curop->op_type] & OA_DANGEROUS) {
1914 if (curop->op_type == OP_GV) {
1915 GV *gv = ((GVOP*)curop)->op_gv;
1916 if (strchr("&`'123456789+", *GvENAME(gv)))
1919 else if (curop->op_type == OP_RV2CV)
1921 else if (curop->op_type == OP_RV2SV ||
1922 curop->op_type == OP_RV2AV ||
1923 curop->op_type == OP_RV2HV ||
1924 curop->op_type == OP_RV2GV) {
1925 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
1928 else if (curop->op_type == OP_PADSV ||
1929 curop->op_type == OP_PADAV ||
1930 curop->op_type == OP_PADHV ||
1931 curop->op_type == OP_PADANY) {
1940 if (curop == repl) {
1941 pm->op_pmflags |= PMf_CONST; /* const for long enough */
1942 pm->op_pmpermflags |= PMf_CONST; /* const for long enough */
1943 prepend_elem(op->op_type, scalar(repl), op);
1946 Newz(1101, rcop, 1, LOGOP);
1947 rcop->op_type = OP_SUBSTCONT;
1948 rcop->op_ppaddr = ppaddr[OP_SUBSTCONT];
1949 rcop->op_first = scalar(repl);
1950 rcop->op_flags |= OPf_KIDS;
1951 rcop->op_private = 1;
1952 rcop->op_other = op;
1954 /* establish postfix order */
1955 rcop->op_next = LINKLIST(repl);
1956 repl->op_next = (OP*)rcop;
1958 pm->op_pmreplroot = scalar((OP*)rcop);
1959 pm->op_pmreplstart = LINKLIST(rcop);
1968 newSVOP(type, flags, sv)
1974 Newz(1101, svop, 1, SVOP);
1975 svop->op_type = type;
1976 svop->op_ppaddr = ppaddr[type];
1978 svop->op_next = (OP*)svop;
1979 svop->op_flags = flags;
1980 if (opargs[type] & OA_RETSCALAR)
1982 if (opargs[type] & OA_TARGET)
1983 svop->op_targ = pad_alloc(type, SVs_PADTMP);
1984 return CHECKOP(type, svop);
1988 newGVOP(type, flags, gv)
1994 Newz(1101, gvop, 1, GVOP);
1995 gvop->op_type = type;
1996 gvop->op_ppaddr = ppaddr[type];
1997 gvop->op_gv = (GV*)SvREFCNT_inc(gv);
1998 gvop->op_next = (OP*)gvop;
1999 gvop->op_flags = flags;
2000 if (opargs[type] & OA_RETSCALAR)
2002 if (opargs[type] & OA_TARGET)
2003 gvop->op_targ = pad_alloc(type, SVs_PADTMP);
2004 return CHECKOP(type, gvop);
2008 newPVOP(type, flags, pv)
2014 Newz(1101, pvop, 1, PVOP);
2015 pvop->op_type = type;
2016 pvop->op_ppaddr = ppaddr[type];
2018 pvop->op_next = (OP*)pvop;
2019 pvop->op_flags = flags;
2020 if (opargs[type] & OA_RETSCALAR)
2022 if (opargs[type] & OA_TARGET)
2023 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
2024 return CHECKOP(type, pvop);
2033 save_hptr(&curstash);
2034 save_item(curstname);
2039 name = SvPV(sv, len);
2040 curstash = gv_stashpvn(name,len,TRUE);
2041 sv_setpvn(curstname, name, len);
2045 sv_setpv(curstname,"<none>");
2053 utilize(aver, floor, version, id, arg)
2066 if (id->op_type != OP_CONST)
2067 croak("Module name must be constant");
2071 if(version != Nullop) {
2072 SV *vesv = ((SVOP*)version)->op_sv;
2074 if (arg == Nullop && !SvNIOK(vesv)) {
2081 if (version->op_type != OP_CONST || !SvNIOK(vesv))
2082 croak("Version number must be constant number");
2084 /* Make copy of id so we don't free it twice */
2085 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2087 /* Fake up a method call to VERSION */
2088 meth = newSVOP(OP_CONST, 0, newSVpv("VERSION", 7));
2089 veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2090 append_elem(OP_LIST,
2091 prepend_elem(OP_LIST, pack, list(version)),
2092 newUNOP(OP_METHOD, 0, meth)));
2096 /* Fake up an import/unimport */
2097 if (arg && arg->op_type == OP_STUB)
2098 imop = arg; /* no import on explicit () */
2099 else if(SvNIOK(((SVOP*)id)->op_sv)) {
2100 imop = Nullop; /* use 5.0; */
2103 /* Make copy of id so we don't free it twice */
2104 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2105 meth = newSVOP(OP_CONST, 0,
2107 ? newSVpv("import", 6)
2108 : newSVpv("unimport", 8)
2110 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2111 append_elem(OP_LIST,
2112 prepend_elem(OP_LIST, pack, list(arg)),
2113 newUNOP(OP_METHOD, 0, meth)));
2116 /* Fake up a require */
2117 rqop = newUNOP(OP_REQUIRE, 0, id);
2119 /* Fake up the BEGIN {}, which does its thing immediately. */
2121 newSVOP(OP_CONST, 0, newSVpv("BEGIN", 5)),
2123 append_elem(OP_LINESEQ,
2124 append_elem(OP_LINESEQ,
2125 newSTATEOP(0, Nullch, rqop),
2126 newSTATEOP(0, Nullch, veop)),
2127 newSTATEOP(0, Nullch, imop) ));
2134 newSLICEOP(flags, subscript, listval)
2139 return newBINOP(OP_LSLICE, flags,
2140 list(force_list(subscript)),
2141 list(force_list(listval)) );
2151 if (op->op_type == OP_NULL && op->op_flags & OPf_KIDS)
2152 op = cUNOP->op_first;
2154 if (op->op_type == OP_COND_EXPR) {
2155 I32 t = list_assignment(cCONDOP->op_first->op_sibling);
2156 I32 f = list_assignment(cCONDOP->op_first->op_sibling->op_sibling);
2161 yyerror("Assignment to both a list and a scalar");
2165 if (op->op_type == OP_LIST || op->op_flags & OPf_PARENS ||
2166 op->op_type == OP_RV2AV || op->op_type == OP_RV2HV ||
2167 op->op_type == OP_ASLICE || op->op_type == OP_HSLICE)
2170 if (op->op_type == OP_PADAV || op->op_type == OP_PADHV)
2173 if (op->op_type == OP_RV2SV)
2180 newASSIGNOP(flags, left, optype, right)
2189 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN) {
2190 return newLOGOP(optype, 0,
2191 mod(scalar(left), optype),
2192 newUNOP(OP_SASSIGN, 0, scalar(right)));
2195 return newBINOP(optype, OPf_STACKED,
2196 mod(scalar(left), optype), scalar(right));
2200 if (list_assignment(left)) {
2202 eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2203 left = mod(left, OP_AASSIGN);
2211 op = newBINOP(OP_AASSIGN, flags,
2212 list(force_list(right)),
2213 list(force_list(left)) );
2214 op->op_private = 0 | (flags >> 8);
2215 if (!(left->op_private & OPpLVAL_INTRO)) {
2216 static int generation = 100;
2220 for (curop = LINKLIST(op); curop != op; curop = LINKLIST(curop)) {
2221 if (opargs[curop->op_type] & OA_DANGEROUS) {
2222 if (curop->op_type == OP_GV) {
2223 GV *gv = ((GVOP*)curop)->op_gv;
2224 if (gv == defgv || SvCUR(gv) == generation)
2226 SvCUR(gv) = generation;
2228 else if (curop->op_type == OP_PADSV ||
2229 curop->op_type == OP_PADAV ||
2230 curop->op_type == OP_PADHV ||
2231 curop->op_type == OP_PADANY) {
2232 SV **svp = AvARRAY(comppad_name);
2233 SV *sv = svp[curop->op_targ];
2234 if (SvCUR(sv) == generation)
2236 SvCUR(sv) = generation; /* (SvCUR not used any more) */
2238 else if (curop->op_type == OP_RV2CV)
2240 else if (curop->op_type == OP_RV2SV ||
2241 curop->op_type == OP_RV2AV ||
2242 curop->op_type == OP_RV2HV ||
2243 curop->op_type == OP_RV2GV) {
2244 if (lastop->op_type != OP_GV) /* funny deref? */
2253 op->op_private = OPpASSIGN_COMMON;
2255 if (right && right->op_type == OP_SPLIT) {
2257 if ((tmpop = ((LISTOP*)right)->op_first) &&
2258 tmpop->op_type == OP_PUSHRE)
2260 PMOP *pm = (PMOP*)tmpop;
2261 if (left->op_type == OP_RV2AV &&
2262 !(left->op_private & OPpLVAL_INTRO) &&
2263 !(op->op_private & OPpASSIGN_COMMON) )
2265 tmpop = ((UNOP*)left)->op_first;
2266 if (tmpop->op_type == OP_GV && !pm->op_pmreplroot) {
2267 pm->op_pmreplroot = (OP*)((GVOP*)tmpop)->op_gv;
2268 pm->op_pmflags |= PMf_ONCE;
2269 tmpop = ((UNOP*)op)->op_first; /* to list (nulled) */
2270 tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */
2271 tmpop->op_sibling = Nullop; /* don't free split */
2272 right->op_next = tmpop->op_next; /* fix starting loc */
2273 op_free(op); /* blow off assign */
2274 right->op_flags &= ~(OPf_KNOW|OPf_LIST);
2275 /* "I don't know and I don't care." */
2280 if (modcount < 10000 &&
2281 ((LISTOP*)right)->op_last->op_type == OP_CONST)
2283 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
2285 sv_setiv(sv, modcount+1);
2293 right = newOP(OP_UNDEF, 0);
2294 if (right->op_type == OP_READLINE) {
2295 right->op_flags |= OPf_STACKED;
2296 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
2299 eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2300 op = newBINOP(OP_SASSIGN, flags,
2301 scalar(right), mod(scalar(left), OP_SASSIGN) );
2313 newSTATEOP(flags, label, op)
2318 U32 seq = intro_my();
2321 Newz(1101, cop, 1, COP);
2322 if (perldb && curcop->cop_line && curstash != debstash) {
2323 cop->op_type = OP_DBSTATE;
2324 cop->op_ppaddr = ppaddr[ OP_DBSTATE ];
2327 cop->op_type = OP_NEXTSTATE;
2328 cop->op_ppaddr = ppaddr[ OP_NEXTSTATE ];
2330 cop->op_flags = flags;
2331 cop->op_private = 0 | (flags >> 8);
2332 cop->op_next = (OP*)cop;
2335 cop->cop_label = label;
2336 hints |= HINT_BLOCK_SCOPE;
2339 cop->cop_arybase = curcop->cop_arybase;
2341 if (copline == NOLINE)
2342 cop->cop_line = curcop->cop_line;
2344 cop->cop_line = copline;
2347 cop->cop_filegv = GvREFCNT_inc(curcop->cop_filegv);
2348 cop->cop_stash = curstash;
2350 if (perldb && curstash != debstash) {
2351 SV **svp = av_fetch(GvAV(curcop->cop_filegv),(I32)cop->cop_line, FALSE);
2352 if (svp && *svp != &sv_undef && !SvIOK(*svp)) {
2353 (void)SvIOK_on(*svp);
2355 SvSTASH(*svp) = (HV*)cop;
2359 return prepend_elem(OP_LINESEQ, (OP*)cop, op);
2362 /* "Introduce" my variables to visible status. */
2370 if (! min_intro_pending)
2373 svp = AvARRAY(comppad_name);
2374 for (i = min_intro_pending; i <= max_intro_pending; i++) {
2375 if ((sv = svp[i]) && sv != &sv_undef && !SvIVX(sv)) {
2376 SvIVX(sv) = 999999999; /* Don't know scope end yet. */
2377 SvNVX(sv) = (double)cop_seqmax;
2380 min_intro_pending = 0;
2381 comppad_name_fill = max_intro_pending; /* Needn't search higher */
2382 return cop_seqmax++;
2386 newLOGOP(type, flags, first, other)
2395 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
2396 return newBINOP(type, flags, scalar(first), scalar(other));
2398 scalarboolean(first);
2399 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
2400 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
2401 if (type == OP_AND || type == OP_OR) {
2407 first = cUNOP->op_first;
2409 first->op_next = op->op_next;
2410 cUNOP->op_first = Nullop;
2414 if (first->op_type == OP_CONST) {
2415 if (dowarn && (first->op_private & OPpCONST_BARE))
2416 warn("Probable precedence problem on %s", op_desc[type]);
2417 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
2426 else if (first->op_type == OP_WANTARRAY) {
2436 if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
2437 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
2439 Newz(1101, logop, 1, LOGOP);
2441 logop->op_type = type;
2442 logop->op_ppaddr = ppaddr[type];
2443 logop->op_first = first;
2444 logop->op_flags = flags | OPf_KIDS;
2445 logop->op_other = LINKLIST(other);
2446 logop->op_private = 1 | (flags >> 8);
2448 /* establish postfix order */
2449 logop->op_next = LINKLIST(first);
2450 first->op_next = (OP*)logop;
2451 first->op_sibling = other;
2453 op = newUNOP(OP_NULL, 0, (OP*)logop);
2454 other->op_next = op;
2460 newCONDOP(flags, first, trueop, falseop)
2470 return newLOGOP(OP_AND, 0, first, trueop);
2472 return newLOGOP(OP_OR, 0, first, falseop);
2474 scalarboolean(first);
2475 if (first->op_type == OP_CONST) {
2476 if (SvTRUE(((SVOP*)first)->op_sv)) {
2487 else if (first->op_type == OP_WANTARRAY) {
2491 Newz(1101, condop, 1, CONDOP);
2493 condop->op_type = OP_COND_EXPR;
2494 condop->op_ppaddr = ppaddr[OP_COND_EXPR];
2495 condop->op_first = first;
2496 condop->op_flags = flags | OPf_KIDS;
2497 condop->op_true = LINKLIST(trueop);
2498 condop->op_false = LINKLIST(falseop);
2499 condop->op_private = 1 | (flags >> 8);
2501 /* establish postfix order */
2502 condop->op_next = LINKLIST(first);
2503 first->op_next = (OP*)condop;
2505 first->op_sibling = trueop;
2506 trueop->op_sibling = falseop;
2507 op = newUNOP(OP_NULL, 0, (OP*)condop);
2509 trueop->op_next = op;
2510 falseop->op_next = op;
2516 newRANGE(flags, left, right)
2526 Newz(1101, condop, 1, CONDOP);
2528 condop->op_type = OP_RANGE;
2529 condop->op_ppaddr = ppaddr[OP_RANGE];
2530 condop->op_first = left;
2531 condop->op_flags = OPf_KIDS;
2532 condop->op_true = LINKLIST(left);
2533 condop->op_false = LINKLIST(right);
2534 condop->op_private = 1 | (flags >> 8);
2536 left->op_sibling = right;
2538 condop->op_next = (OP*)condop;
2539 flip = newUNOP(OP_FLIP, flags, (OP*)condop);
2540 flop = newUNOP(OP_FLOP, 0, flip);
2541 op = newUNOP(OP_NULL, 0, flop);
2544 left->op_next = flip;
2545 right->op_next = flop;
2547 condop->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2548 sv_upgrade(PAD_SV(condop->op_targ), SVt_PVNV);
2549 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2550 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
2552 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2553 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2556 if (!flip->op_private || !flop->op_private)
2557 linklist(op); /* blow off optimizer unless constant */
2563 newLOOPOP(flags, debuggable, expr, block)
2571 int once = block && block->op_flags & OPf_SPECIAL &&
2572 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
2575 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
2576 return block; /* do {} while 0 does once */
2577 else if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB)
2578 expr = newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr);
2581 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
2582 op = newLOGOP(OP_AND, 0, expr, listop);
2584 ((LISTOP*)listop)->op_last->op_next = LINKLIST(op);
2586 if (once && op != listop)
2587 op->op_next = ((LOGOP*)cUNOP->op_first)->op_other;
2590 op = newUNOP(OP_NULL, 0, op); /* or do {} while 1 loses outer block */
2592 op->op_flags |= flags;
2594 op->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/
2599 newWHILEOP(flags, debuggable, loop, expr, block, cont)
2613 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB)) {
2614 expr = newUNOP(OP_DEFINED, 0,
2615 newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr) );
2619 block = newOP(OP_NULL, 0);
2622 next = LINKLIST(cont);
2624 cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
2626 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
2627 redo = LINKLIST(listop);
2630 op = newLOGOP(OP_AND, 0, expr, scalar(listop));
2631 if (op == expr && op->op_type == OP_CONST && !SvTRUE(cSVOP->op_sv)) {
2632 op_free(expr); /* oops, it's a while (0) */
2634 return Nullop; /* (listop already freed by newLOGOP) */
2636 ((LISTOP*)listop)->op_last->op_next = condop =
2637 (op == listop ? redo : LINKLIST(op));
2645 Newz(1101,loop,1,LOOP);
2646 loop->op_type = OP_ENTERLOOP;
2647 loop->op_ppaddr = ppaddr[OP_ENTERLOOP];
2648 loop->op_private = 0;
2649 loop->op_next = (OP*)loop;
2652 op = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, op);
2654 loop->op_redoop = redo;
2655 loop->op_lastop = op;
2658 loop->op_nextop = next;
2660 loop->op_nextop = op;
2662 op->op_flags |= flags;
2663 op->op_private |= (flags >> 8);
2668 #ifndef CAN_PROTOTYPE
2669 newFOROP(flags,label,forline,sv,expr,block,cont)
2678 newFOROP(I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
2679 #endif /* CAN_PROTOTYPE */
2687 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
2688 sv->op_type = OP_RV2GV;
2689 sv->op_ppaddr = ppaddr[OP_RV2GV];
2691 else if (sv->op_type == OP_PADSV) { /* private variable */
2692 padoff = sv->op_targ;
2697 croak("Can't use %s for loop variable", op_desc[sv->op_type]);
2700 sv = newGVOP(OP_GV, 0, defgv);
2702 if (expr->op_type == OP_RV2AV) {
2703 expr = scalar(ref(expr, OP_ITER));
2704 iterflags |= OPf_STACKED;
2706 loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
2707 append_elem(OP_LIST, mod(force_list(expr), OP_GREPSTART),
2709 assert(!loop->op_next);
2710 Renew(loop, 1, LOOP);
2711 loop->op_targ = padoff;
2712 return newSTATEOP(0, label, newWHILEOP(flags, 1, loop,
2713 newOP(OP_ITER, 0), block, cont));
2717 newLOOPEX(type, label)
2722 if (type != OP_GOTO || label->op_type == OP_CONST) {
2723 op = newPVOP(type, 0, savepv(
2724 label->op_type == OP_CONST
2725 ? SvPVx(((SVOP*)label)->op_sv, na)
2730 if (label->op_type == OP_ENTERSUB)
2731 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
2732 op = newUNOP(type, OPf_STACKED, label);
2734 hints |= HINT_BLOCK_SCOPE;
2742 if (!CvXSUB(cv) && CvROOT(cv)) {
2744 croak("Can't undef active subroutine");
2751 op_free(CvROOT(cv));
2752 CvROOT(cv) = Nullop;
2755 SvREFCNT_dec(CvGV(cv));
2757 SvREFCNT_dec(CvOUTSIDE(cv));
2758 CvOUTSIDE(cv) = Nullcv;
2759 if (CvPADLIST(cv)) {
2760 I32 i = AvFILL(CvPADLIST(cv));
2762 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
2766 SvREFCNT_dec((SV*)CvPADLIST(cv));
2767 CvPADLIST(cv) = Nullav;
2777 AV* protopadlist = CvPADLIST(proto);
2778 AV* protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
2779 AV* protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
2780 SV** svp = AvARRAY(protopad);
2789 cv = compcv = (CV*)NEWSV(1104,0);
2790 sv_upgrade((SV *)cv, SVt_PVCV);
2793 CvFILEGV(cv) = CvFILEGV(proto);
2794 CvGV(cv) = GvREFCNT_inc(CvGV(proto));
2795 CvSTASH(cv) = CvSTASH(proto);
2796 CvROOT(cv) = CvROOT(proto);
2797 CvSTART(cv) = CvSTART(proto);
2798 if (CvOUTSIDE(proto))
2799 CvOUTSIDE(cv) = (CV*)SvREFCNT_inc((SV*)CvOUTSIDE(proto));
2803 comppadlist = newAV();
2804 AvREAL_off(comppadlist);
2805 av_store(comppadlist, 0, SvREFCNT_inc((SV*)protopad_name));
2806 av_store(comppadlist, 1, (SV*)comppad);
2807 CvPADLIST(cv) = comppadlist;
2808 av_extend(comppad, AvFILL(protopad));
2809 curpad = AvARRAY(comppad);
2811 av = newAV(); /* will be @_ */
2813 av_store(comppad, 0, (SV*)av);
2814 AvFLAGS(av) = AVf_REIFY;
2816 svp = AvARRAY(protopad_name);
2817 for ( ix = AvFILL(protopad); ix > 0; ix--) {
2819 if (svp[ix] != &sv_undef) {
2820 char *name = SvPVX(svp[ix]); /* XXX */
2821 if (SvFLAGS(svp[ix]) & SVf_FAKE) { /* lexical from outside? */
2822 I32 off = pad_findlex(name,ix,curcop->cop_seq, CvOUTSIDE(proto),
2825 croak("panic: cv_clone: %s", name);
2827 else { /* our own lexical */
2829 av_store(comppad, ix, sv = (SV*)newAV());
2830 else if (*name == '%')
2831 av_store(comppad, ix, sv = (SV*)newHV());
2833 av_store(comppad, ix, sv = NEWSV(0,0));
2838 av_store(comppad, ix, sv = NEWSV(0,0));
2854 if(cv && SvPOK(cv) && !SvCUR(cv)) {
2855 for (o = CvSTART(cv); o; o = o->op_next) {
2856 OPCODE type = o->op_type;
2858 if (type == OP_NEXTSTATE || type == OP_NULL || type == OP_PUSHMARK)
2860 if (type == OP_LEAVESUB || type == OP_RETURN)
2862 if (type != OP_CONST || sv)
2865 sv = ((SVOP*)o)->op_sv;
2872 newSUB(floor,op,proto,block)
2879 char *name = op ? SvPVx(cSVOP->op_sv, na) : "__ANON__";
2880 GV* gv = gv_fetchpv(name, GV_ADDMULTI, SVt_PVCV);
2887 if (cv = GvCV(gv)) {
2889 cv = 0; /* just a cached method */
2890 else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
2891 SV* const_sv = cv_const_sv(cv);
2893 char *p = proto ? SvPVx(((SVOP*)proto)->op_sv, na) : Nullch;
2895 if((!proto != !SvPOK(cv)) || (p && strNE(SvPV((SV*)cv,na), p))) {
2896 warn("Prototype mismatch: (%s) vs (%s)",
2897 SvPOK(cv) ? SvPV((SV*)cv,na) : "none",
2901 if ((const_sv || dowarn) && strNE(name, "BEGIN")) {/* already defined (or promised)? */
2902 line_t oldline = curcop->cop_line;
2904 curcop->cop_line = copline;
2905 warn(const_sv ? "Constant subroutine %s redefined"
2906 : "Subroutine %s redefined",name);
2907 curcop->cop_line = oldline;
2913 if (cv) { /* must reuse cv if autoloaded */
2915 CvOUTSIDE(cv) = CvOUTSIDE(compcv);
2916 CvOUTSIDE(compcv) = 0;
2917 CvPADLIST(cv) = CvPADLIST(compcv);
2918 CvPADLIST(compcv) = 0;
2919 if (SvREFCNT(compcv) > 1) /* XXX Make closures transit through stub. */
2920 CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc((SV*)cv);
2921 SvREFCNT_dec(compcv);
2928 CvFILEGV(cv) = curcop->cop_filegv;
2929 CvGV(cv) = GvREFCNT_inc(gv);
2930 CvSTASH(cv) = curstash;
2933 char *p = SvPVx(((SVOP*)proto)->op_sv, na);
2934 sv_setpv((SV*)cv, p);
2950 av = newAV(); /* Will be @_ */
2952 av_store(comppad, 0, (SV*)av);
2953 AvFLAGS(av) = AVf_REIFY;
2955 for (ix = AvFILL(comppad); ix > 0; ix--) {
2956 if (!SvPADMY(curpad[ix]))
2957 SvPADTMP_on(curpad[ix]);
2960 if (AvFILL(comppad_name) < AvFILL(comppad))
2961 av_store(comppad_name, AvFILL(comppad), Nullsv);
2963 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
2964 CvSTART(cv) = LINKLIST(CvROOT(cv));
2965 CvROOT(cv)->op_next = 0;
2967 if (s = strrchr(name,':'))
2971 if (strEQ(s, "BEGIN") && !error_count) {
2972 line_t oldline = compiling.cop_line;
2976 SAVESPTR(compiling.cop_filegv);
2980 av_push(beginav, (SV *)cv);
2981 DEBUG_x( dump_sub(gv) );
2982 rs = SvREFCNT_inc(nrs);
2985 if (GvCV(gv) == cv) { /* Detach it. */
2987 GvCV(gv) = 0; /* Was above calllist, why? IZ */
2991 curcop = &compiling;
2992 curcop->cop_line = oldline; /* might have recursed to yylex */
2995 else if (strEQ(s, "END") && !error_count) {
2998 av_unshift(endav, 1);
2999 av_store(endav, 0, SvREFCNT_inc(cv));
3001 if (perldb && curstash != debstash) {
3003 SV *tmpstr = sv_newmortal();
3004 static GV *db_postponed;
3008 sprintf(buf,"%s:%ld",SvPVX(GvSV(curcop->cop_filegv)), (long)subline);
3009 sv = newSVpv(buf,0);
3011 sprintf(buf,"%ld",(long)curcop->cop_line);
3013 gv_efullname3(tmpstr, gv, Nullch);
3014 hv_store(GvHV(DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
3015 if (!db_postponed) {
3016 db_postponed = gv_fetchpv("DB::postponed", TRUE, SVt_PVHV);
3018 hv = GvHVn(db_postponed);
3019 if (HvFILL(hv) >= 0 && hv_exists(hv, SvPVX(tmpstr), SvCUR(tmpstr))
3020 && (cv = GvCV(db_postponed))) {
3025 perl_call_sv((SV*)cv, G_DISCARD);
3032 GvCV(gv) = 0; /* Will remember in SVOP instead. */
3040 newXSUB(name, ix, subaddr, filename)
3046 CV* cv = newXS(name, (void(*)())subaddr, filename);
3048 CvXSUBANY(cv).any_i32 = ix;
3054 newXS(name, subaddr, filename)
3056 void (*subaddr) _((CV*));
3060 GV *gv = gv_fetchpv((name ? name : "__ANON__"), GV_ADDMULTI, SVt_PVCV);
3065 if (cv = GvCV(gv)) {
3067 cv = 0; /* just a cached method */
3068 else if (CvROOT(cv) || CvXSUB(cv)) { /* already defined? */
3070 line_t oldline = curcop->cop_line;
3072 curcop->cop_line = copline;
3073 warn("Subroutine %s redefined",name);
3074 curcop->cop_line = oldline;
3080 if (cv) { /* must reuse cv if autoloaded */
3081 assert(SvREFCNT(CvGV(cv)) > 1);
3082 SvREFCNT_dec(CvGV(cv));
3085 cv = (CV*)NEWSV(1105,0);
3086 sv_upgrade((SV *)cv, SVt_PVCV);
3089 CvGV(cv) = GvREFCNT_inc(gv);
3091 CvFILEGV(cv) = gv_fetchfile(filename);
3092 CvXSUB(cv) = subaddr;
3095 else if (s = strrchr(name,':'))
3099 if (strEQ(s, "BEGIN")) {
3102 av_push(beginav, SvREFCNT_inc(gv));
3104 else if (strEQ(s, "END")) {
3107 av_unshift(endav, 1);
3108 av_store(endav, 0, SvREFCNT_inc(gv));
3111 GvCV(gv) = 0; /* Will remember elsewhere instead. */
3118 newFORM(floor,op,block)
3129 name = SvPVx(cSVOP->op_sv, na);
3132 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
3134 if (cv = GvFORM(gv)) {
3136 line_t oldline = curcop->cop_line;
3138 curcop->cop_line = copline;
3139 warn("Format %s redefined",name);
3140 curcop->cop_line = oldline;
3146 CvGV(cv) = GvREFCNT_inc(gv);
3147 CvFILEGV(cv) = curcop->cop_filegv;
3149 for (ix = AvFILL(comppad); ix > 0; ix--) {
3150 if (!SvPADMY(curpad[ix]))
3151 SvPADTMP_on(curpad[ix]);
3154 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
3155 CvSTART(cv) = LINKLIST(CvROOT(cv));
3156 CvROOT(cv)->op_next = 0;
3168 return newUNOP(OP_REFGEN, 0,
3169 mod(list(convert(OP_ANONLIST, 0, op)), OP_REFGEN));
3176 return newUNOP(OP_REFGEN, 0,
3177 mod(list(convert(OP_ANONHASH, 0, op)), OP_REFGEN));
3181 newANONSUB(floor, proto, block)
3186 return newUNOP(OP_REFGEN, 0,
3187 newSVOP(OP_ANONCODE, 0, (SV*)newSUB(floor, 0, proto, block)));
3194 switch (o->op_type) {
3196 o->op_type = OP_PADAV;
3197 o->op_ppaddr = ppaddr[OP_PADAV];
3198 return ref(newUNOP(OP_RV2AV, 0, scalar(o)), OP_RV2AV);
3201 o->op_type = OP_RV2AV;
3202 o->op_ppaddr = ppaddr[OP_RV2AV];
3207 warn("oops: oopsAV");
3217 switch (o->op_type) {
3220 o->op_type = OP_PADHV;
3221 o->op_ppaddr = ppaddr[OP_PADHV];
3222 return ref(newUNOP(OP_RV2HV, 0, scalar(o)), OP_RV2HV);
3226 o->op_type = OP_RV2HV;
3227 o->op_ppaddr = ppaddr[OP_RV2HV];
3232 warn("oops: oopsHV");
3242 if (o->op_type == OP_PADANY) {
3243 o->op_type = OP_PADAV;
3244 o->op_ppaddr = ppaddr[OP_PADAV];
3247 return newUNOP(OP_RV2AV, 0, scalar(o));
3255 if (type == OP_MAPSTART)
3256 return newUNOP(OP_NULL, 0, o);
3257 return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
3264 if (o->op_type == OP_PADANY) {
3265 o->op_type = OP_PADHV;
3266 o->op_ppaddr = ppaddr[OP_PADHV];
3269 return newUNOP(OP_RV2HV, 0, scalar(o));
3276 croak("NOT IMPL LINE %d",__LINE__);
3286 return newUNOP(OP_RV2CV, flags, scalar(o));
3293 if (o->op_type == OP_PADANY) {
3294 o->op_type = OP_PADSV;
3295 o->op_ppaddr = ppaddr[OP_PADSV];
3298 return newUNOP(OP_RV2SV, 0, scalar(o));
3301 /* Check routines. */
3307 op->op_private = hints;
3315 if (cUNOP->op_first->op_type == OP_CONCAT)
3316 op->op_flags |= OPf_STACKED;
3324 if (op->op_flags & OPf_KIDS) {
3327 op = modkids(ck_fun(op), op->op_type);
3328 kid = cUNOP->op_first;
3329 newop = kUNOP->op_first->op_sibling;
3331 (newop->op_sibling ||
3332 !(opargs[newop->op_type] & OA_RETSCALAR) ||
3333 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
3334 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
3338 op_free(kUNOP->op_first);
3339 kUNOP->op_first = newop;
3341 op->op_ppaddr = ppaddr[++op->op_type];
3350 if (op->op_flags & OPf_KIDS) {
3351 OP *kid = cUNOP->op_first;
3352 if (kid->op_type != OP_HELEM)
3353 croak("%s argument is not a HASH element", op_desc[op->op_type]);
3363 I32 type = op->op_type;
3365 if (op->op_flags & OPf_KIDS) {
3366 if (cLISTOP->op_first->op_type == OP_STUB) {
3368 op = newUNOP(type, OPf_SPECIAL,
3369 newGVOP(OP_GV, 0, gv_fetchpv("main'ARGV", TRUE, SVt_PVAV)));
3380 hints |= HINT_BLOCK_SCOPE;
3381 if (op->op_flags & OPf_KIDS) {
3382 SVOP *kid = (SVOP*)cUNOP->op_first;
3385 op->op_flags &= ~OPf_KIDS;
3388 else if (kid->op_type == OP_LINESEQ) {
3391 kid->op_next = op->op_next;
3392 cUNOP->op_first = 0;
3395 Newz(1101, enter, 1, LOGOP);
3396 enter->op_type = OP_ENTERTRY;
3397 enter->op_ppaddr = ppaddr[OP_ENTERTRY];
3398 enter->op_private = 0;
3400 /* establish postfix order */
3401 enter->op_next = (OP*)enter;
3403 op = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
3404 op->op_type = OP_LEAVETRY;
3405 op->op_ppaddr = ppaddr[OP_LEAVETRY];
3406 enter->op_other = op;
3412 op = newUNOP(OP_ENTEREVAL, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3414 op->op_targ = (PADOFFSET)hints;
3423 if (op->op_flags & OPf_STACKED) {
3425 kid = cUNOP->op_first->op_sibling;
3426 if (kid->op_type == OP_RV2GV)
3438 o = fold_constants(o);
3439 if (o->op_type == OP_CONST)
3448 SVOP *kid = (SVOP*)cUNOP->op_first;
3450 op->op_private |= (hints & HINT_STRICT_REFS);
3451 if (kid->op_type == OP_CONST) {
3452 int iscv = (op->op_type==OP_RV2CV)*2;
3454 kid->op_type = OP_GV;
3455 for (gv = 0; !gv; iscv++) {
3457 * This is a little tricky. We only want to add the symbol if we
3458 * didn't add it in the lexer. Otherwise we get duplicate strict
3459 * warnings. But if we didn't add it in the lexer, we must at
3460 * least pretend like we wanted to add it even if it existed before,
3461 * or we get possible typo warnings. OPpCONST_ENTERED says
3462 * whether the lexer already added THIS instance of this symbol.
3464 gv = gv_fetchpv(SvPVx(kid->op_sv, na),
3465 iscv | !(kid->op_private & OPpCONST_ENTERED),
3468 : op->op_type == OP_RV2SV
3470 : op->op_type == OP_RV2AV
3472 : op->op_type == OP_RV2HV
3476 SvREFCNT_dec(kid->op_sv);
3477 kid->op_sv = SvREFCNT_inc(gv);
3486 I32 type = op->op_type;
3488 if (op->op_flags & OPf_REF)
3491 if (op->op_flags & OPf_KIDS) {
3492 SVOP *kid = (SVOP*)cUNOP->op_first;
3494 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
3495 OP *newop = newGVOP(type, OPf_REF,
3496 gv_fetchpv(SvPVx(kid->op_sv, na), TRUE, SVt_PVIO));
3503 if (type == OP_FTTTY)
3504 return newGVOP(type, OPf_REF, gv_fetchpv("main'STDIN", TRUE,
3507 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3520 int type = op->op_type;
3521 register I32 oa = opargs[type] >> OASHIFT;
3523 if (op->op_flags & OPf_STACKED) {
3524 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
3527 return no_fh_allowed(op);
3530 if (op->op_flags & OPf_KIDS) {
3531 tokid = &cLISTOP->op_first;
3532 kid = cLISTOP->op_first;
3533 if (kid->op_type == OP_PUSHMARK ||
3534 kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK)
3536 tokid = &kid->op_sibling;
3537 kid = kid->op_sibling;
3539 if (!kid && opargs[type] & OA_DEFGV)
3540 *tokid = kid = newSVREF(newGVOP(OP_GV, 0, defgv));
3544 sibl = kid->op_sibling;
3558 if (kid->op_type == OP_CONST &&
3559 (kid->op_private & OPpCONST_BARE)) {
3560 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
3561 OP *newop = newAVREF(newGVOP(OP_GV, 0,
3562 gv_fetchpv(name, TRUE, SVt_PVAV) ));
3564 warn("Array @%s missing the @ in argument %d of %s()",
3565 name, numargs, op_desc[type]);
3568 kid->op_sibling = sibl;
3571 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
3572 bad_type(numargs, "array", op_desc[op->op_type], kid);
3576 if (kid->op_type == OP_CONST &&
3577 (kid->op_private & OPpCONST_BARE)) {
3578 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
3579 OP *newop = newHVREF(newGVOP(OP_GV, 0,
3580 gv_fetchpv(name, TRUE, SVt_PVHV) ));
3582 warn("Hash %%%s missing the %% in argument %d of %s()",
3583 name, numargs, op_desc[type]);
3586 kid->op_sibling = sibl;
3589 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
3590 bad_type(numargs, "hash", op_desc[op->op_type], kid);
3595 OP *newop = newUNOP(OP_NULL, 0, kid);
3596 kid->op_sibling = 0;
3598 newop->op_next = newop;
3600 kid->op_sibling = sibl;
3605 if (kid->op_type != OP_GV) {
3606 if (kid->op_type == OP_CONST &&
3607 (kid->op_private & OPpCONST_BARE)) {
3608 OP *newop = newGVOP(OP_GV, 0,
3609 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, na), TRUE,
3615 kid->op_sibling = 0;
3616 kid = newUNOP(OP_RV2GV, 0, scalar(kid));
3618 kid->op_sibling = sibl;
3624 mod(scalar(kid), type);
3628 tokid = &kid->op_sibling;
3629 kid = kid->op_sibling;
3631 op->op_private |= numargs;
3633 return too_many_arguments(op,op_desc[op->op_type]);
3636 else if (opargs[type] & OA_DEFGV) {
3638 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3642 while (oa & OA_OPTIONAL)
3644 if (oa && oa != OA_LIST)
3645 return too_few_arguments(op,op_desc[op->op_type]);
3654 GV *gv = gv_fetchpv("glob", FALSE, SVt_PVCV);
3656 if (gv && GvIMPORTED_CV(gv)) {
3657 op->op_type = OP_LIST;
3658 op->op_ppaddr = ppaddr[OP_LIST];
3659 op = newUNOP(OP_ENTERSUB, OPf_STACKED,
3660 append_elem(OP_LIST, op,
3661 scalar(newUNOP(OP_RV2CV, 0,
3662 newGVOP(OP_GV, 0, gv)))));
3665 gv = newGVgen("main");
3667 append_elem(OP_GLOB, op, newGVOP(OP_GV, 0, gv));
3678 OPCODE type = op->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
3680 op->op_ppaddr = ppaddr[OP_GREPSTART];
3681 Newz(1101, gwop, 1, LOGOP);
3683 if (op->op_flags & OPf_STACKED) {
3686 kid = cLISTOP->op_first->op_sibling;
3687 for (k = cLISTOP->op_first->op_sibling->op_next; k; k = k->op_next) {
3690 kid->op_next = (OP*)gwop;
3691 op->op_flags &= ~OPf_STACKED;
3693 kid = cLISTOP->op_first->op_sibling;
3694 if (type == OP_MAPWHILE)
3701 kid = cLISTOP->op_first->op_sibling;
3702 if (kid->op_type != OP_NULL)
3703 croak("panic: ck_grep");
3704 kid = kUNOP->op_first;
3706 gwop->op_type = type;
3707 gwop->op_ppaddr = ppaddr[type];
3708 gwop->op_first = listkids(op);
3709 gwop->op_flags |= OPf_KIDS;
3710 gwop->op_private = 1;
3711 gwop->op_other = LINKLIST(kid);
3712 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
3713 kid->op_next = (OP*)gwop;
3715 kid = cLISTOP->op_first->op_sibling;
3716 if (!kid || !kid->op_sibling)
3717 return too_few_arguments(op,op_desc[op->op_type]);
3718 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
3719 mod(kid, OP_GREPSTART);
3728 if (op->op_flags & OPf_KIDS) {
3729 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3730 if (kid && kid->op_type == OP_CONST)
3731 fbm_compile(((SVOP*)kid)->op_sv);
3740 /* XXX length optimization goes here */
3748 return modkids(ck_fun(op), op->op_type);
3755 return refkids(ck_fun(op), op->op_type);
3764 kid = cLISTOP->op_first;
3766 op = force_list(op);
3767 kid = cLISTOP->op_first;
3769 if (kid->op_type == OP_PUSHMARK)
3770 kid = kid->op_sibling;
3771 if (kid && op->op_flags & OPf_STACKED)
3772 kid = kid->op_sibling;
3773 else if (kid && !kid->op_sibling) { /* print HANDLE; */
3774 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
3775 op->op_flags |= OPf_STACKED; /* make it a filehandle */
3776 kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
3777 cLISTOP->op_first->op_sibling = kid;
3778 cLISTOP->op_last = kid;
3779 kid = kid->op_sibling;
3784 append_elem(op->op_type, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
3789 #ifdef HAS_SETLOCALE
3790 if (hints & HINT_LOCALE)
3791 op->op_private |= OPpLOCALE;
3804 #ifdef HAS_SETLOCALE
3805 if (hints & HINT_LOCALE)
3806 op->op_private |= OPpLOCALE;
3818 if (hints & HINT_LOCALE)
3819 op->op_private |= OPpLOCALE;
3828 cPMOP->op_pmflags |= PMf_RUNTIME;
3829 cPMOP->op_pmpermflags |= PMf_RUNTIME;
3844 if (cBINOP->op_first->op_flags & OPf_PARENS) {
3845 op->op_private |= OPpREPEAT_DOLIST;
3846 cBINOP->op_first = force_list(cBINOP->op_first);
3857 if (op->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
3858 SVOP *kid = (SVOP*)cUNOP->op_first;
3860 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
3862 for (s = SvPVX(kid->op_sv); *s; s++) {
3863 if (*s == ':' && s[1] == ':') {
3865 Move(s+2, s+1, strlen(s+2)+1, char);
3866 --SvCUR(kid->op_sv);
3869 sv_catpvn(kid->op_sv, ".pm", 3);
3879 croak("NOT IMPL LINE %d",__LINE__);
3889 if (op->op_flags & OPf_KIDS) {
3890 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3891 if (kid && kid->op_sibling) {
3892 op->op_type = OP_SSELECT;
3893 op->op_ppaddr = ppaddr[OP_SSELECT];
3895 return fold_constants(op);
3899 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3900 if (kid && kid->op_type == OP_RV2GV)
3901 kid->op_private &= ~HINT_STRICT_REFS;
3909 I32 type = op->op_type;
3911 if (!(op->op_flags & OPf_KIDS)) {
3913 return newUNOP(type, 0,
3914 scalar(newUNOP(OP_RV2AV, 0,
3915 scalar(newGVOP(OP_GV, 0, subline
3917 : gv_fetchpv("ARGV", TRUE, SVt_PVAV) )))));
3919 return scalar(modkids(ck_fun(op), type));
3928 if (hints & HINT_LOCALE)
3929 op->op_private |= OPpLOCALE;
3932 if (op->op_flags & OPf_STACKED) {
3933 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3935 kid = kUNOP->op_first; /* get past rv2gv */
3937 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
3939 if (kid->op_type == OP_SCOPE) {
3943 else if (kid->op_type == OP_LEAVE) {
3944 if (op->op_type == OP_SORT) {
3945 null(kid); /* wipe out leave */
3948 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
3949 if (k->op_next == kid)
3954 kid->op_next = 0; /* just disconnect the leave */
3955 k = kLISTOP->op_first;
3959 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3960 null(kid); /* wipe out rv2gv */
3961 if (op->op_type == OP_SORT)
3965 op->op_flags |= OPf_SPECIAL;
3979 if (op->op_flags & OPf_STACKED)
3980 return no_fh_allowed(op);
3982 kid = cLISTOP->op_first;
3983 if (kid->op_type != OP_NULL)
3984 croak("panic: ck_split");
3985 kid = kid->op_sibling;
3986 op_free(cLISTOP->op_first);
3987 cLISTOP->op_first = kid;
3989 cLISTOP->op_first = kid = newSVOP(OP_CONST, 0, newSVpv(" ", 1));
3990 cLISTOP->op_last = kid; /* There was only one element previously */
3993 if (kid->op_type != OP_MATCH) {
3994 OP *sibl = kid->op_sibling;
3995 kid->op_sibling = 0;
3996 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
3997 if (cLISTOP->op_first == cLISTOP->op_last)
3998 cLISTOP->op_last = kid;
3999 cLISTOP->op_first = kid;
4000 kid->op_sibling = sibl;
4003 if (pm->op_pmshort && !(pm->op_pmflags & PMf_ALL)) {
4004 SvREFCNT_dec(pm->op_pmshort); /* can't use substring to optimize */
4008 kid->op_type = OP_PUSHRE;
4009 kid->op_ppaddr = ppaddr[OP_PUSHRE];
4012 if (!kid->op_sibling)
4013 append_elem(OP_SPLIT, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
4015 kid = kid->op_sibling;
4018 if (!kid->op_sibling)
4019 append_elem(OP_SPLIT, op, newSVOP(OP_CONST, 0, newSViv(0)));
4021 kid = kid->op_sibling;
4024 if (kid->op_sibling)
4025 return too_many_arguments(op,op_desc[op->op_type]);
4034 OP *prev = ((cUNOP->op_first->op_sibling)
4035 ? cUNOP : ((UNOP*)cUNOP->op_first))->op_first;
4036 OP *o = prev->op_sibling;
4043 for (cvop = o; cvop->op_sibling; cvop = cvop->op_sibling) ;
4044 if (cvop->op_type == OP_RV2CV) {
4046 op->op_private |= (cvop->op_private & OPpENTERSUB_AMPER);
4047 null(cvop); /* disable rv2cv */
4048 tmpop = (SVOP*)((UNOP*)cvop)->op_first;
4049 if (tmpop->op_type == OP_GV) {
4050 cv = GvCV(tmpop->op_sv);
4051 if (cv && SvPOK(cv) && !(op->op_private & OPpENTERSUB_AMPER))
4052 proto = SvPV((SV*)cv,na);
4055 op->op_private |= (hints & HINT_STRICT_REFS);
4056 if (perldb && curstash != debstash)
4057 op->op_private |= OPpENTERSUB_DB;
4062 return too_many_arguments(op, CvNAME(cv));
4080 if (o->op_type != OP_REFGEN && o->op_type != OP_UNDEF)
4081 bad_type(arg, "block", CvNAME(cv), o);
4086 if (o->op_type == OP_RV2GV)
4090 o = newUNOP(OP_RV2GV, 0, kid);
4091 o->op_sibling = kid->op_sibling;
4092 kid->op_sibling = 0;
4093 prev->op_sibling = o;
4101 if (o->op_type != OP_RV2GV)
4102 bad_type(arg, "symbol", CvNAME(cv), o);
4105 if (o->op_type != OP_RV2CV)
4106 bad_type(arg, "sub", CvNAME(cv), o);
4109 if (o->op_type != OP_RV2SV && o->op_type != OP_PADSV)
4110 bad_type(arg, "scalar", CvNAME(cv), o);
4113 if (o->op_type != OP_RV2AV && o->op_type != OP_PADAV)
4114 bad_type(arg, "array", CvNAME(cv), o);
4117 if (o->op_type != OP_RV2HV && o->op_type != OP_PADHV)
4118 bad_type(arg, "hash", CvNAME(cv), o);
4122 o = newUNOP(OP_REFGEN, 0, kid);
4123 o->op_sibling = kid->op_sibling;
4124 kid->op_sibling = 0;
4125 prev->op_sibling = o;
4136 croak("Malformed prototype for %s: %s",
4137 CvNAME(cv),SvPV((SV*)cv,na));
4142 mod(o, OP_ENTERSUB);
4146 if (proto && !optional && *proto == '$')
4147 return too_few_arguments(op, CvNAME(cv));
4155 SvREADONLY_on(cSVOP->op_sv);
4163 if (op->op_flags & OPf_KIDS) {
4164 SVOP *kid = (SVOP*)cUNOP->op_first;
4166 if (kid->op_type == OP_NULL)
4167 kid = (SVOP*)kid->op_sibling;
4169 kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE))
4170 op->op_flags |= OPf_SPECIAL;
4175 /* A peephole optimizer. We visit the ops in the order they're to execute. */
4181 register OP* oldop = 0;
4182 if (!o || o->op_seq)
4187 for (; o; o = o->op_next) {
4193 switch (o->op_type) {
4196 curcop = ((COP*)o); /* for warnings */
4197 o->op_seq = op_seqmax++;
4208 if (o->op_next->op_type == OP_STRINGIFY)
4210 o->op_seq = op_seqmax++;
4213 if ((o->op_flags & (OPf_KNOW|OPf_LIST)) != (OPf_KNOW|OPf_LIST)) {
4214 o->op_seq = op_seqmax++;
4215 break; /* Scalar stub must produce undef. List stub is noop */
4219 if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE)
4220 curcop = ((COP*)op);
4226 if (oldop && o->op_next) {
4227 oldop->op_next = o->op_next;
4230 o->op_seq = op_seqmax++;
4234 if (o->op_next->op_type == OP_RV2SV) {
4235 if (!(o->op_next->op_private & (OPpDEREF_HV|OPpDEREF_AV))) {
4237 o->op_private |= o->op_next->op_private & OPpLVAL_INTRO;
4238 o->op_next = o->op_next->op_next;
4239 o->op_type = OP_GVSV;
4240 o->op_ppaddr = ppaddr[OP_GVSV];
4243 else if (o->op_next->op_type == OP_RV2AV) {
4244 OP* pop = o->op_next->op_next;
4246 if (pop->op_type == OP_CONST &&
4247 (op = pop->op_next) &&
4248 pop->op_next->op_type == OP_AELEM &&
4249 !(pop->op_next->op_private &
4250 (OPpDEREF_HV|OPpDEREF_AV|OPpLVAL_INTRO)) &&
4251 (i = SvIV(((SVOP*)pop)->op_sv) - compiling.cop_arybase)
4255 SvREFCNT_dec(((SVOP*)pop)->op_sv);
4259 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
4260 o->op_next = pop->op_next->op_next;
4261 o->op_type = OP_AELEMFAST;
4262 o->op_ppaddr = ppaddr[OP_AELEMFAST];
4263 o->op_private = (U8)i;
4264 GvAVn((GV*)(((SVOP*)o)->op_sv));
4267 o->op_seq = op_seqmax++;
4274 o->op_seq = op_seqmax++;
4275 peep(cLOGOP->op_other);
4279 o->op_seq = op_seqmax++;
4280 peep(cCONDOP->op_true);
4281 peep(cCONDOP->op_false);
4285 o->op_seq = op_seqmax++;
4286 peep(cLOOP->op_redoop);
4287 peep(cLOOP->op_nextop);
4288 peep(cLOOP->op_lastop);
4293 o->op_seq = op_seqmax++;
4294 peep(cPMOP->op_pmreplstart);
4298 o->op_seq = op_seqmax++;
4299 if (dowarn && o->op_next && o->op_next->op_type == OP_NEXTSTATE) {
4300 if (o->op_next->op_sibling &&
4301 o->op_next->op_sibling->op_type != OP_DIE) {
4302 line_t oldline = curcop->cop_line;
4304 curcop->cop_line = ((COP*)o->op_next)->cop_line;
4305 warn("Statement unlikely to be reached");
4306 warn("(Maybe you meant system() when you said exec()?)\n");
4307 curcop->cop_line = oldline;
4312 o->op_seq = op_seqmax++;