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 static I32 list_assignment _((OP *op));
22 static OP *bad_type _((I32 n, char *t, OP *op, OP *kid));
23 static OP *modkids _((OP *op, I32 type));
24 static OP *no_fh_allowed _((OP *op));
25 static OP *scalarboolean _((OP *op));
26 static OP *too_few_arguments _((OP *op));
27 static OP *too_many_arguments _((OP *op));
28 static void null _((OP* op));
29 static PADOFFSET pad_findlex _((char* name, PADOFFSET newoff, I32 seq,
30 CV* startcv, I32 cx_ix));
36 sprintf(tokenbuf,"Missing comma after first argument to %s function",
37 op_name[op->op_type]);
46 sprintf(tokenbuf,"Not enough arguments for %s", op_name[op->op_type]);
52 too_many_arguments(op)
55 sprintf(tokenbuf,"Too many arguments for %s", op_name[op->op_type]);
61 bad_type(n, t, op, kid)
67 sprintf(tokenbuf, "Type of arg %d to %s must be %s (not %s)",
68 (int) n, op_name[op->op_type], t, op_name[kid->op_type]);
77 int type = op->op_type;
78 if (type != OP_AELEM && type != OP_HELEM) {
79 sprintf(tokenbuf, "Can't use subscript on %s",
82 if (type == OP_RV2HV || type == OP_ENTERSUB)
83 warn("(Did you mean $ or @ instead of %c?)\n",
84 type == OP_RV2HV ? '%' : '&');
88 /* "register" allocation */
97 if (!(isALPHA(name[1]) || name[1] == '_' && (int)strlen(name) > 2)) {
98 if (!isprint(name[1]))
99 sprintf(name+1, "^%c", name[1] ^ 64); /* XXX is tokenbuf, really */
100 croak("Can't use global %s in \"my\"",name);
102 off = pad_alloc(OP_PADSV, SVs_PADMY);
104 sv_upgrade(sv, SVt_PVNV);
106 av_store(comppad_name, off, sv);
107 SvNVX(sv) = (double)999999999;
108 SvIVX(sv) = 0; /* Not yet introduced--see newSTATEOP */
109 if (!min_intro_pending)
110 min_intro_pending = off;
111 max_intro_pending = off;
113 av_store(comppad, off, (SV*)newAV());
114 else if (*name == '%')
115 av_store(comppad, off, (SV*)newHV());
116 SvPADMY_on(curpad[off]);
121 #ifndef CAN_PROTOTYPE
122 pad_findlex(name, newoff, seq, startcv, cx_ix)
129 pad_findlex(char *name, PADOFFSET newoff, I32 seq, CV* startcv, I32 cx_ix)
136 register CONTEXT *cx;
139 for (cv = startcv; cv; cv = CvOUTSIDE(cv)) {
140 AV* curlist = CvPADLIST(cv);
141 SV** svp = av_fetch(curlist, 0, FALSE);
143 if (!svp || *svp == &sv_undef)
146 svp = AvARRAY(curname);
147 for (off = AvFILL(curname); off > 0; off--) {
148 if ((sv = svp[off]) &&
151 seq > (I32)SvNVX(sv) &&
152 strEQ(SvPVX(sv), name))
154 I32 depth = CvDEPTH(cv) ? CvDEPTH(cv) : 1;
155 AV *oldpad = (AV*)*av_fetch(curlist, depth, FALSE);
156 SV *oldsv = *av_fetch(oldpad, off, TRUE);
157 if (!newoff) { /* Not a mere clone operation. */
158 SV *sv = NEWSV(1103,0);
159 newoff = pad_alloc(OP_PADSV, SVs_PADMY);
160 sv_upgrade(sv, SVt_PVNV);
162 av_store(comppad_name, newoff, sv);
163 SvNVX(sv) = (double)curcop->cop_seq;
164 SvIVX(sv) = 999999999; /* A ref, intro immediately */
165 SvFLAGS(sv) |= SVf_FAKE;
167 av_store(comppad, newoff, SvREFCNT_inc(oldsv));
168 SvFLAGS(compcv) |= SVpcv_CLONE;
174 /* Nothing in current lexical context--try eval's context, if any.
175 * This is necessary to let the perldb get at lexically scoped variables.
176 * XXX This will also probably interact badly with eval tree caching.
180 for (i = cx_ix; i >= 0; i--) {
182 switch (cx->cx_type) {
184 if (i == 0 && saweval) {
185 seq = cxstack[saweval].blk_oldcop->cop_seq;
186 return pad_findlex(name, newoff, seq, main_cv, 0);
190 if (cx->blk_eval.old_op_type != OP_ENTEREVAL)
191 return 0; /* require must have its own scope */
198 if (debstash && CvSTASH(cv) == debstash) { /* ignore DB'* scope */
199 saweval = i; /* so we know where we were called from */
202 seq = cxstack[saweval].blk_oldcop->cop_seq;
203 return pad_findlex(name, newoff, seq, cv, i-1);
216 SV **svp = AvARRAY(comppad_name);
217 I32 seq = cop_seqmax;
219 /* The one we're looking for is probably just before comppad_name_fill. */
220 for (off = comppad_name_fill; off > 0; off--) {
221 if ((sv = svp[off]) &&
224 seq > (I32)SvNVX(sv) &&
225 strEQ(SvPVX(sv), name))
227 return (PADOFFSET)off;
231 /* See if it's in a nested scope */
232 off = pad_findlex(name, 0, seq, CvOUTSIDE(compcv), cxstack_ix);
244 SV **svp = AvARRAY(comppad_name);
246 if (min_intro_pending && fill < min_intro_pending) {
247 for (off = max_intro_pending; off >= min_intro_pending; off--) {
248 if ((sv = svp[off]) && sv != &sv_undef)
249 warn("%s never introduced", SvPVX(sv));
252 /* "Deintroduce" my variables that are leaving with this scope. */
253 for (off = AvFILL(comppad_name); off > fill; off--) {
254 if ((sv = svp[off]) && sv != &sv_undef && SvIVX(sv) == 999999999)
255 SvIVX(sv) = cop_seqmax;
260 pad_alloc(optype,tmptype)
267 if (AvARRAY(comppad) != curpad)
268 croak("panic: pad_alloc");
269 if (pad_reset_pending)
271 if (tmptype & SVs_PADMY) {
273 sv = *av_fetch(comppad, AvFILL(comppad) + 1, TRUE);
274 } while (SvPADBUSY(sv)); /* need a fresh one */
275 retval = AvFILL(comppad);
279 sv = *av_fetch(comppad, ++padix, TRUE);
280 } while (SvFLAGS(sv) & (SVs_PADTMP|SVs_PADMY));
283 SvFLAGS(sv) |= tmptype;
284 curpad = AvARRAY(comppad);
285 DEBUG_X(fprintf(stderr, "Pad alloc %ld for %s\n", (long) retval, op_name[optype]));
286 return (PADOFFSET)retval;
290 #ifndef CAN_PROTOTYPE
295 #endif /* CAN_PROTOTYPE */
298 croak("panic: pad_sv po");
299 DEBUG_X(fprintf(stderr, "Pad sv %d\n", po));
300 return curpad[po]; /* eventually we'll turn this into a macro */
304 #ifndef CAN_PROTOTYPE
308 pad_free(PADOFFSET po)
309 #endif /* CAN_PROTOTYPE */
313 if (AvARRAY(comppad) != curpad)
314 croak("panic: pad_free curpad");
316 croak("panic: pad_free po");
317 DEBUG_X(fprintf(stderr, "Pad free %d\n", po));
318 if (curpad[po] && curpad[po] != &sv_undef)
319 SvPADTMP_off(curpad[po]);
325 #ifndef CAN_PROTOTYPE
329 pad_swipe(PADOFFSET po)
330 #endif /* CAN_PROTOTYPE */
332 if (AvARRAY(comppad) != curpad)
333 croak("panic: pad_swipe curpad");
335 croak("panic: pad_swipe po");
336 DEBUG_X(fprintf(stderr, "Pad swipe %d\n", po));
337 SvPADTMP_off(curpad[po]);
338 curpad[po] = NEWSV(1107,0);
339 SvPADTMP_on(curpad[po]);
349 if (AvARRAY(comppad) != curpad)
350 croak("panic: pad_reset curpad");
351 DEBUG_X(fprintf(stderr, "Pad reset\n"));
352 if (!tainting) { /* Can't mix tainted and non-tainted temporaries. */
353 for (po = AvMAX(comppad); po > padix_floor; po--) {
354 if (curpad[po] && curpad[po] != &sv_undef)
355 SvPADTMP_off(curpad[po]);
359 pad_reset_pending = FALSE;
368 register OP *kid, *nextkid;
373 if (op->op_flags & OPf_KIDS) {
374 for (kid = cUNOP->op_first; kid; kid = nextkid) {
375 nextkid = kid->op_sibling; /* Get before next freeing kid */
380 switch (op->op_type) {
382 op->op_targ = 0; /* Was holding old type, if any. */
385 op->op_targ = 0; /* Was holding hints. */
389 SvREFCNT_dec(cGVOP->op_gv);
393 SvREFCNT_dec(cCOP->cop_filegv);
396 SvREFCNT_dec(cSVOP->op_sv);
402 if (op->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
406 Safefree(cPVOP->op_pv);
409 op_free(cPMOP->op_pmreplroot);
413 regfree(cPMOP->op_pmregexp);
414 SvREFCNT_dec(cPMOP->op_pmshort);
421 pad_free(op->op_targ);
430 if (op->op_type != OP_NULL && op->op_targ > 0)
431 pad_free(op->op_targ);
432 op->op_targ = op->op_type;
433 op->op_type = OP_NULL;
434 op->op_ppaddr = ppaddr[OP_NULL];
437 /* Contextualizers */
439 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
450 /* establish postfix order */
451 if (cUNOP->op_first) {
452 op->op_next = LINKLIST(cUNOP->op_first);
453 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
455 kid->op_next = LINKLIST(kid->op_sibling);
471 if (op && op->op_flags & OPf_KIDS) {
472 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
483 op->op_type == OP_SASSIGN && cBINOP->op_first->op_type == OP_CONST) {
484 line_t oldline = curcop->cop_line;
486 if (copline != NOLINE)
487 curcop->cop_line = copline;
488 warn("Found = in conditional, should be ==");
489 curcop->cop_line = oldline;
500 /* assumes no premature commitment */
501 if (!op || (op->op_flags & OPf_KNOW) || error_count)
504 op->op_flags &= ~OPf_LIST;
505 op->op_flags |= OPf_KNOW;
507 switch (op->op_type) {
509 scalar(cBINOP->op_first);
514 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
518 if ((kid = ((LISTOP*)op)->op_first) && kid->op_type == OP_PUSHRE) {
519 if (!kPMOP->op_pmreplroot)
520 deprecate("implicit split to @_");
527 if (op->op_flags & OPf_KIDS) {
528 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling)
534 scalar(cLISTOP->op_first);
539 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
559 if (!op || error_count)
561 if (op->op_flags & OPf_LIST)
564 op->op_flags |= OPf_KNOW;
566 switch (op->op_type) {
568 if (!(opargs[op->op_type] & OA_FOLDCONST))
570 if (op->op_flags & OPf_STACKED)
644 if (!(op->op_private & OPpLVAL_INTRO))
645 useless = op_name[op->op_type];
652 if (!(op->op_private & OPpLVAL_INTRO) &&
653 (!op->op_sibling || op->op_sibling->op_type != OP_READLINE))
654 useless = "a variable";
659 curcop = ((COP*)op); /* for warning below */
665 useless = "a constant";
666 if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
668 else if (SvPOK(sv)) {
669 if (strnEQ(SvPVX(sv), "di", 2) ||
670 strnEQ(SvPVX(sv), "ds", 2) ||
671 strnEQ(SvPVX(sv), "ig", 2))
675 null(op); /* don't execute a constant */
676 SvREFCNT_dec(sv); /* don't even remember it */
680 op->op_type = OP_PREINC; /* pre-increment is faster */
681 op->op_ppaddr = ppaddr[OP_PREINC];
685 op->op_type = OP_PREDEC; /* pre-decrement is faster */
686 op->op_ppaddr = ppaddr[OP_PREDEC];
690 scalarvoid(cBINOP->op_first);
691 useless = op_name[op->op_type];
697 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
701 if (op->op_targ == OP_NEXTSTATE || op->op_targ == OP_DBSTATE)
702 curcop = ((COP*)op); /* for warning below */
703 if (op->op_flags & OPf_STACKED)
708 if (!(op->op_flags & OPf_KIDS))
714 op->op_private |= OPpLEAVE_VOID;
717 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
721 if ((kid = ((LISTOP*)op)->op_first) && kid->op_type == OP_PUSHRE) {
722 if (!kPMOP->op_pmreplroot)
723 deprecate("implicit split to @_");
727 op->op_private |= OPpLEAVE_VOID;
730 if (useless && dowarn)
731 warn("Useless use of %s in void context", useless);
740 if (op && op->op_flags & OPf_KIDS) {
741 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
753 /* assumes no premature commitment */
754 if (!op || (op->op_flags & OPf_KNOW) || error_count)
757 op->op_flags |= (OPf_KNOW | OPf_LIST);
759 switch (op->op_type) {
762 list(cBINOP->op_first);
767 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
774 if (!(op->op_flags & OPf_KIDS))
776 if (!op->op_next && cUNOP->op_first->op_type == OP_FLOP) {
777 list(cBINOP->op_first);
778 return gen_constant_list(op);
785 list(cLISTOP->op_first);
789 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
808 if (op->op_type == OP_LINESEQ ||
809 op->op_type == OP_SCOPE ||
810 op->op_type == OP_LEAVE ||
811 op->op_type == OP_LEAVETRY)
813 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
814 if (kid->op_sibling) {
820 op->op_flags &= ~OPf_PARENS;
821 if (hints & HINT_BLOCK_SCOPE)
822 op->op_flags |= OPf_PARENS;
825 op = newOP(OP_STUB, 0);
835 if (op && op->op_flags & OPf_KIDS) {
836 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
853 if (!op || error_count)
856 switch (op->op_type) {
858 if (!(op->op_private & (OPpCONST_ARYBASE)))
860 if (eval_start && eval_start->op_type == OP_CONST) {
861 compiling.cop_arybase = (I32)SvIV(((SVOP*)eval_start)->op_sv);
865 SAVEI32(compiling.cop_arybase);
866 compiling.cop_arybase = 0;
868 else if (type == OP_REFGEN)
871 croak("That use of $[ is unsupported");
874 if ((type == OP_UNDEF || type == OP_REFGEN) &&
875 !(op->op_flags & OPf_STACKED)) {
876 op->op_type = OP_RV2CV; /* entersub => rv2cv */
877 op->op_ppaddr = ppaddr[OP_RV2CV];
878 assert(cUNOP->op_first->op_type == OP_NULL);
879 null(((LISTOP*)cUNOP->op_first)->op_first); /* disable pushmark */
885 /* grep, foreach, subcalls, refgen */
886 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
888 sprintf(tokenbuf, "Can't modify %s in %s",
889 op_name[op->op_type],
890 type ? op_name[type] : "local");
914 if (!(op->op_flags & OPf_STACKED))
920 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
926 if (type == OP_REFGEN && op->op_flags & OPf_PARENS) {
928 return op; /* Treat \(@foo) like ordinary list. */
932 ref(cUNOP->op_first, op->op_type);
944 ref(cUNOP->op_first, op->op_type);
961 croak("Can't localize lexical variable %s",
962 SvPV(*av_fetch(comppad_name, op->op_targ, 4), na));
977 pad_free(op->op_targ);
978 op->op_targ = pad_alloc(op->op_type, SVs_PADMY);
979 sv = PAD_SV(op->op_targ);
980 sv_upgrade(sv, SVt_PVLV);
981 sv_magic(sv, Nullsv, mtype, Nullch, 0);
982 curpad[op->op_targ] = sv;
983 if (op->op_flags & OPf_KIDS)
984 mod(cBINOP->op_first, type);
989 ref(cBINOP->op_first, op->op_type);
996 if (op->op_flags & OPf_KIDS)
997 mod(cLISTOP->op_last, type);
1001 if (!(op->op_flags & OPf_KIDS))
1003 if (op->op_targ != OP_LIST) {
1004 mod(cBINOP->op_first, type);
1009 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1013 op->op_flags |= OPf_MOD;
1015 if (type == OP_AASSIGN || type == OP_SASSIGN)
1016 op->op_flags |= OPf_SPECIAL|OPf_REF;
1018 op->op_private |= OPpLVAL_INTRO;
1019 op->op_flags &= ~OPf_SPECIAL;
1021 else if (type != OP_GREPSTART && type != OP_ENTERSUB)
1022 op->op_flags |= OPf_REF;
1032 if (op && op->op_flags & OPf_KIDS) {
1033 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1046 if (!op || error_count)
1049 switch (op->op_type) {
1051 if ((type == OP_DEFINED) &&
1052 !(op->op_flags & OPf_STACKED)) {
1053 op->op_type = OP_RV2CV; /* entersub => rv2cv */
1054 op->op_ppaddr = ppaddr[OP_RV2CV];
1055 assert(cUNOP->op_first->op_type == OP_NULL);
1056 null(((LISTOP*)cUNOP->op_first)->op_first); /* disable pushmark */
1061 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
1065 ref(cUNOP->op_first, op->op_type);
1066 if (type == OP_RV2AV || type == OP_RV2HV) {
1067 op->op_private |= (type == OP_RV2AV ? OPpDEREF_AV : OPpDEREF_HV);
1068 op->op_flags |= OPf_MOD;
1074 op->op_flags |= OPf_REF;
1077 ref(cUNOP->op_first, op->op_type);
1082 op->op_flags |= OPf_REF;
1087 if (!(op->op_flags & OPf_KIDS))
1089 ref(cBINOP->op_first, type);
1093 ref(cBINOP->op_first, op->op_type);
1094 if (type == OP_RV2AV || type == OP_RV2HV) {
1095 op->op_private |= (type == OP_RV2AV ? OPpDEREF_AV : OPpDEREF_HV);
1096 op->op_flags |= OPf_MOD;
1104 if (!(op->op_flags & OPf_KIDS))
1106 ref(cLISTOP->op_last, type);
1122 if (!op || error_count)
1126 if (type == OP_LIST) {
1127 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1130 else if (type != OP_PADSV &&
1133 type != OP_PUSHMARK)
1135 sprintf(tokenbuf, "Can't declare %s in my", op_name[op->op_type]);
1139 op->op_flags |= OPf_MOD;
1140 op->op_private |= OPpLVAL_INTRO;
1149 o->op_flags |= OPf_PARENS;
1154 bind_match(type, left, right)
1161 if (right->op_type == OP_MATCH ||
1162 right->op_type == OP_SUBST ||
1163 right->op_type == OP_TRANS) {
1164 right->op_flags |= OPf_STACKED;
1165 if (right->op_type != OP_MATCH)
1166 left = mod(left, right->op_type);
1167 if (right->op_type == OP_TRANS)
1168 op = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
1170 op = prepend_elem(right->op_type, scalar(left), right);
1172 return newUNOP(OP_NOT, 0, scalar(op));
1176 return bind_match(type, left,
1177 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
1186 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
1187 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(op));
1195 if (o->op_flags & OPf_PARENS || perldb) {
1196 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
1197 o->op_type = OP_LEAVE;
1198 o->op_ppaddr = ppaddr[OP_LEAVE];
1201 if (o->op_type == OP_LINESEQ) {
1203 o->op_type = OP_SCOPE;
1204 o->op_ppaddr = ppaddr[OP_SCOPE];
1205 kid = ((LISTOP*)o)->op_first;
1206 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE){
1207 SvREFCNT_dec(((COP*)kid)->cop_filegv);
1212 o = newLISTOP(OP_SCOPE, 0, o, Nullop);
1221 int retval = savestack_ix;
1222 comppad_name_fill = AvFILL(comppad_name);
1223 SAVEINT(min_intro_pending);
1224 SAVEINT(max_intro_pending);
1225 min_intro_pending = 0;
1226 SAVEINT(comppad_name_fill);
1227 SAVEINT(padix_floor);
1228 padix_floor = padix;
1229 pad_reset_pending = FALSE;
1231 hints &= ~HINT_BLOCK_SCOPE;
1236 block_end(line, floor, seq)
1241 int needblockscope = hints & HINT_BLOCK_SCOPE;
1242 OP* retval = scalarseq(seq);
1243 if (copline > (line_t)line)
1246 pad_reset_pending = FALSE;
1248 hints |= HINT_BLOCK_SCOPE; /* propagate out */
1249 pad_leavemy(comppad_name_fill);
1258 eval_root = newUNOP(OP_LEAVEEVAL, 0, op);
1259 eval_start = linklist(eval_root);
1260 eval_root->op_next = 0;
1268 main_root = scope(sawparens(scalarvoid(op)));
1269 curcop = &compiling;
1270 main_start = LINKLIST(main_root);
1271 main_root->op_next = 0;
1283 if (o->op_flags & OPf_PARENS)
1287 if (dowarn && bufptr > oldbufptr && bufptr[-1] == ',') {
1289 for (s = bufptr; *s && (isALNUM(*s) || strchr("@$%, ",*s)); s++) ;
1290 if (*s == ';' || *s == '=')
1291 warn("Parens missing around \"%s\" list", lex ? "my" : "local");
1298 return mod(o, OP_NULL); /* a bit kludgey */
1305 if (o->op_type == OP_LIST) {
1306 o = convert(OP_JOIN, 0,
1307 prepend_elem(OP_LIST,
1308 newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
1319 I32 type = o->op_type;
1322 if (opargs[type] & OA_RETSCALAR)
1324 if (opargs[type] & OA_TARGET)
1325 o->op_targ = pad_alloc(type, SVs_PADTMP);
1327 if ((opargs[type] & OA_OTHERINT) && (hints & HINT_INTEGER))
1328 o->op_ppaddr = ppaddr[type = ++(o->op_type)];
1330 if (!(opargs[type] & OA_FOLDCONST))
1334 goto nope; /* Don't try to run w/ errors */
1336 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
1337 if (curop->op_type != OP_CONST &&
1338 curop->op_type != OP_LIST &&
1339 curop->op_type != OP_SCALAR &&
1340 curop->op_type != OP_NULL &&
1341 curop->op_type != OP_PUSHMARK) {
1346 curop = LINKLIST(o);
1351 if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
1352 pad_swipe(o->op_targ);
1353 else if (SvTEMP(sv)) { /* grab mortal temp? */
1354 (void)SvREFCNT_inc(sv);
1358 if (type == OP_RV2GV)
1359 return newGVOP(OP_GV, 0, sv);
1361 if ((SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK)) == SVf_NOK) {
1363 if ((double)iv == SvNV(sv)) { /* can we smush double to int */
1368 return newSVOP(OP_CONST, 0, sv);
1372 if (!(opargs[type] & OA_OTHERINT))
1375 if (!(hints & HINT_INTEGER)) {
1376 if (type == OP_DIVIDE || !(o->op_flags & OPf_KIDS))
1379 for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
1380 if (curop->op_type == OP_CONST) {
1381 if (SvIOK(((SVOP*)curop)->op_sv))
1385 if (opargs[curop->op_type] & OA_RETINTEGER)
1389 o->op_ppaddr = ppaddr[++(o->op_type)];
1396 gen_constant_list(o)
1400 I32 oldtmps_floor = tmps_floor;
1404 return o; /* Don't attempt to run with errors */
1406 op = curop = LINKLIST(o);
1412 tmps_floor = oldtmps_floor;
1414 o->op_type = OP_RV2AV;
1415 o->op_ppaddr = ppaddr[OP_RV2AV];
1416 curop = ((UNOP*)o)->op_first;
1417 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*stack_sp--));
1424 convert(type, flags, op)
1432 if (!op || op->op_type != OP_LIST)
1433 op = newLISTOP(OP_LIST, 0, op, Nullop);
1435 op->op_flags &= ~(OPf_KNOW|OPf_LIST);
1437 if (!(opargs[type] & OA_MARK))
1438 null(cLISTOP->op_first);
1441 op->op_ppaddr = ppaddr[type];
1442 op->op_flags |= flags;
1444 op = (*check[type])(op);
1445 if (op->op_type != type)
1448 if (cLISTOP->op_children < 7) {
1449 /* XXX do we really need to do this if we're done appending?? */
1450 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1452 cLISTOP->op_last = last; /* in case check substituted last arg */
1455 return fold_constants(op);
1458 /* List constructors */
1461 append_elem(type, first, last)
1472 if (first->op_type != type || type==OP_LIST && first->op_flags & OPf_PARENS)
1473 return newLISTOP(type, 0, first, last);
1475 if (first->op_flags & OPf_KIDS)
1476 ((LISTOP*)first)->op_last->op_sibling = last;
1478 first->op_flags |= OPf_KIDS;
1479 ((LISTOP*)first)->op_first = last;
1481 ((LISTOP*)first)->op_last = last;
1482 ((LISTOP*)first)->op_children++;
1487 append_list(type, first, last)
1498 if (first->op_type != type)
1499 return prepend_elem(type, (OP*)first, (OP*)last);
1501 if (last->op_type != type)
1502 return append_elem(type, (OP*)first, (OP*)last);
1504 first->op_last->op_sibling = last->op_first;
1505 first->op_last = last->op_last;
1506 first->op_children += last->op_children;
1507 if (first->op_children)
1508 last->op_flags |= OPf_KIDS;
1515 prepend_elem(type, first, last)
1526 if (last->op_type == type) {
1527 if (type == OP_LIST) { /* already a PUSHMARK there */
1528 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
1529 ((LISTOP*)last)->op_first->op_sibling = first;
1532 if (!(last->op_flags & OPf_KIDS)) {
1533 ((LISTOP*)last)->op_last = first;
1534 last->op_flags |= OPf_KIDS;
1536 first->op_sibling = ((LISTOP*)last)->op_first;
1537 ((LISTOP*)last)->op_first = first;
1539 ((LISTOP*)last)->op_children++;
1543 return newLISTOP(type, 0, first, last);
1551 return newOP(OP_STUB, 0);
1558 if (!op || op->op_type != OP_LIST)
1559 op = newLISTOP(OP_LIST, 0, op, Nullop);
1565 newLISTOP(type, flags, first, last)
1573 Newz(1101, listop, 1, LISTOP);
1575 listop->op_type = type;
1576 listop->op_ppaddr = ppaddr[type];
1577 listop->op_children = (first != 0) + (last != 0);
1578 listop->op_flags = flags;
1582 else if (!first && last)
1585 first->op_sibling = last;
1586 listop->op_first = first;
1587 listop->op_last = last;
1588 if (type == OP_LIST) {
1590 pushop = newOP(OP_PUSHMARK, 0);
1591 pushop->op_sibling = first;
1592 listop->op_first = pushop;
1593 listop->op_flags |= OPf_KIDS;
1595 listop->op_last = pushop;
1597 else if (listop->op_children)
1598 listop->op_flags |= OPf_KIDS;
1609 Newz(1101, op, 1, OP);
1611 op->op_ppaddr = ppaddr[type];
1612 op->op_flags = flags;
1615 /* op->op_private = 0; */
1616 if (opargs[type] & OA_RETSCALAR)
1618 if (opargs[type] & OA_TARGET)
1619 op->op_targ = pad_alloc(type, SVs_PADTMP);
1620 return (*check[type])(op);
1624 newUNOP(type, flags, first)
1632 first = newOP(OP_STUB, 0);
1633 if (opargs[type] & OA_MARK)
1634 first = force_list(first);
1636 Newz(1101, unop, 1, UNOP);
1637 unop->op_type = type;
1638 unop->op_ppaddr = ppaddr[type];
1639 unop->op_first = first;
1640 unop->op_flags = flags | OPf_KIDS;
1641 unop->op_private = 1;
1643 unop = (UNOP*)(*check[type])((OP*)unop);
1647 return fold_constants((OP *) unop);
1651 newBINOP(type, flags, first, last)
1658 Newz(1101, binop, 1, BINOP);
1661 first = newOP(OP_NULL, 0);
1663 binop->op_type = type;
1664 binop->op_ppaddr = ppaddr[type];
1665 binop->op_first = first;
1666 binop->op_flags = flags | OPf_KIDS;
1669 binop->op_private = 1;
1672 binop->op_private = 2;
1673 first->op_sibling = last;
1676 binop = (BINOP*)(*check[type])((OP*)binop);
1680 binop->op_last = last = binop->op_first->op_sibling;
1682 return fold_constants((OP *)binop);
1686 pmtrans(op, expr, repl)
1691 SV *tstr = ((SVOP*)expr)->op_sv;
1692 SV *rstr = ((SVOP*)repl)->op_sv;
1695 register char *t = SvPV(tstr, tlen);
1696 register char *r = SvPV(rstr, rlen);
1701 register short *tbl;
1703 tbl = (short*)cPVOP->op_pv;
1704 complement = op->op_private & OPpTRANS_COMPLEMENT;
1705 delete = op->op_private & OPpTRANS_DELETE;
1706 /* squash = op->op_private & OPpTRANS_SQUASH; */
1709 Zero(tbl, 256, short);
1710 for (i = 0; i < tlen; i++)
1711 tbl[t[i] & 0377] = -1;
1712 for (i = 0, j = 0; i < 256; i++) {
1718 tbl[i] = r[j-1] & 0377;
1723 tbl[i] = r[j++] & 0377;
1728 if (!rlen && !delete) {
1731 for (i = 0; i < 256; i++)
1733 for (i = 0, j = 0; i < tlen; i++,j++) {
1736 if (tbl[t[i] & 0377] == -1)
1737 tbl[t[i] & 0377] = -2;
1742 if (tbl[t[i] & 0377] == -1)
1743 tbl[t[i] & 0377] = r[j] & 0377;
1753 newPMOP(type, flags)
1759 Newz(1101, pmop, 1, PMOP);
1760 pmop->op_type = type;
1761 pmop->op_ppaddr = ppaddr[type];
1762 pmop->op_flags = flags;
1763 pmop->op_private = 0;
1765 /* link into pm list */
1766 if (type != OP_TRANS && curstash) {
1767 pmop->op_pmnext = HvPMROOT(curstash);
1768 HvPMROOT(curstash) = pmop;
1775 pmruntime(op, expr, repl)
1783 if (op->op_type == OP_TRANS)
1784 return pmtrans(op, expr, repl);
1788 if (expr->op_type == OP_CONST) {
1790 SV *pat = ((SVOP*)expr)->op_sv;
1791 char *p = SvPV(pat, plen);
1792 if ((op->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
1793 sv_setpvn(pat, "\\s+", 3);
1794 p = SvPV(pat, plen);
1795 pm->op_pmflags |= PMf_SKIPWHITE;
1797 pm->op_pmregexp = regcomp(p, p + plen, pm);
1798 if (strEQ("\\s+", pm->op_pmregexp->precomp))
1799 pm->op_pmflags |= PMf_WHITE;
1804 if (pm->op_pmflags & PMf_KEEP)
1805 expr = newUNOP(OP_REGCMAYBE,0,expr);
1807 Newz(1101, rcop, 1, LOGOP);
1808 rcop->op_type = OP_REGCOMP;
1809 rcop->op_ppaddr = ppaddr[OP_REGCOMP];
1810 rcop->op_first = scalar(expr);
1811 rcop->op_flags |= OPf_KIDS;
1812 rcop->op_private = 1;
1813 rcop->op_other = op;
1815 /* establish postfix order */
1816 if (pm->op_pmflags & PMf_KEEP) {
1818 rcop->op_next = expr;
1819 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
1822 rcop->op_next = LINKLIST(expr);
1823 expr->op_next = (OP*)rcop;
1826 prepend_elem(op->op_type, scalar((OP*)rcop), op);
1831 if (pm->op_pmflags & PMf_EVAL)
1833 else if (repl->op_type == OP_CONST)
1837 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
1838 if (opargs[curop->op_type] & OA_DANGEROUS) {
1839 if (curop->op_type == OP_GV) {
1840 GV *gv = ((GVOP*)curop)->op_gv;
1841 if (strchr("&`'123456789+", *GvENAME(gv)))
1844 else if (curop->op_type == OP_RV2CV)
1846 else if (curop->op_type == OP_RV2SV ||
1847 curop->op_type == OP_RV2AV ||
1848 curop->op_type == OP_RV2HV ||
1849 curop->op_type == OP_RV2GV) {
1850 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
1853 else if (curop->op_type == OP_PADSV ||
1854 curop->op_type == OP_PADAV ||
1855 curop->op_type == OP_PADHV ||
1856 curop->op_type == OP_PADANY) {
1865 if (curop == repl) {
1866 pm->op_pmflags |= PMf_CONST; /* const for long enough */
1867 prepend_elem(op->op_type, scalar(repl), op);
1870 Newz(1101, rcop, 1, LOGOP);
1871 rcop->op_type = OP_SUBSTCONT;
1872 rcop->op_ppaddr = ppaddr[OP_SUBSTCONT];
1873 rcop->op_first = scalar(repl);
1874 rcop->op_flags |= OPf_KIDS;
1875 rcop->op_private = 1;
1876 rcop->op_other = op;
1878 /* establish postfix order */
1879 rcop->op_next = LINKLIST(repl);
1880 repl->op_next = (OP*)rcop;
1882 pm->op_pmreplroot = scalar((OP*)rcop);
1883 pm->op_pmreplstart = LINKLIST(rcop);
1892 newSVOP(type, flags, sv)
1898 Newz(1101, svop, 1, SVOP);
1899 svop->op_type = type;
1900 svop->op_ppaddr = ppaddr[type];
1902 svop->op_next = (OP*)svop;
1903 svop->op_flags = flags;
1904 if (opargs[type] & OA_RETSCALAR)
1906 if (opargs[type] & OA_TARGET)
1907 svop->op_targ = pad_alloc(type, SVs_PADTMP);
1908 return (*check[type])((OP*)svop);
1912 newGVOP(type, flags, gv)
1918 Newz(1101, gvop, 1, GVOP);
1919 gvop->op_type = type;
1920 gvop->op_ppaddr = ppaddr[type];
1921 gvop->op_gv = (GV*)SvREFCNT_inc(gv);
1922 gvop->op_next = (OP*)gvop;
1923 gvop->op_flags = flags;
1924 if (opargs[type] & OA_RETSCALAR)
1926 if (opargs[type] & OA_TARGET)
1927 gvop->op_targ = pad_alloc(type, SVs_PADTMP);
1928 return (*check[type])((OP*)gvop);
1932 newPVOP(type, flags, pv)
1938 Newz(1101, pvop, 1, PVOP);
1939 pvop->op_type = type;
1940 pvop->op_ppaddr = ppaddr[type];
1942 pvop->op_next = (OP*)pvop;
1943 pvop->op_flags = flags;
1944 if (opargs[type] & OA_RETSCALAR)
1946 if (opargs[type] & OA_TARGET)
1947 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
1948 return (*check[type])((OP*)pvop);
1952 newCVOP(type, flags, cv, cont)
1959 Newz(1101, cvop, 1, CVOP);
1960 cvop->op_type = type;
1961 cvop->op_ppaddr = ppaddr[type];
1963 cvop->op_cont = cont;
1964 cvop->op_next = (OP*)cvop;
1965 cvop->op_flags = flags;
1966 if (opargs[type] & OA_RETSCALAR)
1968 if (opargs[type] & OA_TARGET)
1969 cvop->op_targ = pad_alloc(type, SVs_PADTMP);
1970 return (*check[type])((OP*)cvop);
1979 save_hptr(&curstash);
1980 save_item(curstname);
1985 name = SvPV(sv, len);
1986 curstash = gv_stashpv(name,TRUE);
1987 sv_setpvn(curstname, name, len);
1991 sv_setpv(curstname,"<none>");
1999 utilize(aver, id, arg)
2009 if (id->op_type != OP_CONST)
2010 croak("Module name must be constant");
2012 meth = newSVOP(OP_CONST, 0,
2014 ? newSVpv("import", 6)
2015 : newSVpv("unimport", 8)
2018 /* Make copy of id so we don't free it twice */
2019 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2021 /* Fake up a require */
2022 rqop = newUNOP(OP_REQUIRE, 0, id);
2024 /* Fake up an import/unimport */
2025 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2026 append_elem(OP_LIST,
2027 prepend_elem(OP_LIST, pack, list(arg)),
2028 newUNOP(OP_METHOD, 0, meth)));
2030 /* Fake up the BEGIN {}, which does its thing immediately. */
2031 newSUB(start_subparse(),
2032 newSVOP(OP_CONST, 0, newSVpv("BEGIN", 5)),
2033 append_elem(OP_LINESEQ,
2034 newSTATEOP(0, Nullch, rqop),
2035 newSTATEOP(0, Nullch, imop) ));
2042 newSLICEOP(flags, subscript, listval)
2047 return newBINOP(OP_LSLICE, flags,
2048 list(force_list(subscript)),
2049 list(force_list(listval)) );
2059 if (op->op_type == OP_NULL && op->op_flags & OPf_KIDS)
2060 op = cUNOP->op_first;
2062 if (op->op_type == OP_COND_EXPR) {
2063 I32 t = list_assignment(cCONDOP->op_first->op_sibling);
2064 I32 f = list_assignment(cCONDOP->op_first->op_sibling->op_sibling);
2069 yyerror("Assignment to both a list and a scalar");
2073 if (op->op_type == OP_LIST || op->op_flags & OPf_PARENS ||
2074 op->op_type == OP_RV2AV || op->op_type == OP_RV2HV ||
2075 op->op_type == OP_ASLICE || op->op_type == OP_HSLICE)
2078 if (op->op_type == OP_PADAV || op->op_type == OP_PADHV)
2081 if (op->op_type == OP_RV2SV)
2088 newASSIGNOP(flags, left, optype, right)
2097 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN) {
2098 return newLOGOP(optype, 0,
2099 mod(scalar(left), optype),
2100 newUNOP(OP_SASSIGN, 0, scalar(right)));
2103 return newBINOP(optype, OPf_STACKED,
2104 mod(scalar(left), optype), scalar(right));
2108 if (list_assignment(left)) {
2110 eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2111 left = mod(left, OP_AASSIGN);
2119 if (right && right->op_type == OP_SPLIT) {
2120 if ((op = ((LISTOP*)right)->op_first) && op->op_type == OP_PUSHRE) {
2121 PMOP *pm = (PMOP*)op;
2122 if (left->op_type == OP_RV2AV &&
2123 !(left->op_private & OPpLVAL_INTRO) )
2125 op = ((UNOP*)left)->op_first;
2126 if (op->op_type == OP_GV && !pm->op_pmreplroot) {
2127 pm->op_pmreplroot = (OP*)((GVOP*)op)->op_gv;
2128 pm->op_pmflags |= PMf_ONCE;
2134 if (modcount < 10000) {
2135 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
2137 sv_setiv(sv, modcount+1);
2142 op = newBINOP(OP_AASSIGN, flags,
2143 list(force_list(right)),
2144 list(force_list(left)) );
2146 if (!(left->op_private & OPpLVAL_INTRO)) {
2147 static int generation = 100;
2151 for (curop = LINKLIST(op); curop != op; curop = LINKLIST(curop)) {
2152 if (opargs[curop->op_type] & OA_DANGEROUS) {
2153 if (curop->op_type == OP_GV) {
2154 GV *gv = ((GVOP*)curop)->op_gv;
2155 if (gv == defgv || SvCUR(gv) == generation)
2157 SvCUR(gv) = generation;
2159 else if (curop->op_type == OP_PADSV ||
2160 curop->op_type == OP_PADAV ||
2161 curop->op_type == OP_PADHV ||
2162 curop->op_type == OP_PADANY) {
2163 SV **svp = AvARRAY(comppad_name);
2164 SV *sv = svp[curop->op_targ];;
2165 if (SvCUR(sv) == generation)
2167 SvCUR(sv) = generation; /* (SvCUR not used any more) */
2169 else if (curop->op_type == OP_RV2CV)
2171 else if (curop->op_type == OP_RV2SV ||
2172 curop->op_type == OP_RV2AV ||
2173 curop->op_type == OP_RV2HV ||
2174 curop->op_type == OP_RV2GV) {
2175 if (lastop->op_type != OP_GV) /* funny deref? */
2184 op->op_private = OPpASSIGN_COMMON;
2189 right = newOP(OP_UNDEF, 0);
2190 if (right->op_type == OP_READLINE) {
2191 right->op_flags |= OPf_STACKED;
2192 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
2195 eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2196 op = newBINOP(OP_SASSIGN, flags,
2197 scalar(right), mod(scalar(left), OP_SASSIGN) );
2209 newSTATEOP(flags, label, op)
2216 /* Introduce my variables. */
2217 if (min_intro_pending) {
2218 SV **svp = AvARRAY(comppad_name);
2221 for (i = min_intro_pending; i <= max_intro_pending; i++) {
2222 if ((sv = svp[i]) && sv != &sv_undef)
2223 SvIVX(sv) = 999999999; /* Don't know scope end yet. */
2224 SvNVX(sv) = (double)cop_seqmax;
2226 min_intro_pending = 0;
2227 comppad_name_fill = max_intro_pending; /* Needn't search higher */
2230 Newz(1101, cop, 1, COP);
2231 if (perldb && curcop->cop_line && curstash != debstash) {
2232 cop->op_type = OP_DBSTATE;
2233 cop->op_ppaddr = ppaddr[ OP_DBSTATE ];
2236 cop->op_type = OP_NEXTSTATE;
2237 cop->op_ppaddr = ppaddr[ OP_NEXTSTATE ];
2239 cop->op_flags = flags;
2240 cop->op_private = 0;
2241 cop->op_next = (OP*)cop;
2244 cop->cop_label = label;
2245 hints |= HINT_BLOCK_SCOPE;
2247 cop->cop_seq = cop_seqmax++;
2248 cop->cop_arybase = curcop->cop_arybase;
2250 if (copline == NOLINE)
2251 cop->cop_line = curcop->cop_line;
2253 cop->cop_line = copline;
2256 cop->cop_filegv = SvREFCNT_inc(curcop->cop_filegv);
2257 cop->cop_stash = curstash;
2259 if (perldb && curstash != debstash) {
2260 SV **svp = av_fetch(GvAV(curcop->cop_filegv),(I32)cop->cop_line, FALSE);
2261 if (svp && *svp != &sv_undef && !SvIOK(*svp)) {
2263 (void)SvIOK_on(*svp);
2264 SvSTASH(*svp) = (HV*)cop;
2268 return prepend_elem(OP_LINESEQ, (OP*)cop, op);
2272 newLOGOP(type, flags, first, other)
2281 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
2282 return newBINOP(type, flags, scalar(first), scalar(other));
2284 scalarboolean(first);
2285 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
2286 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
2287 if (type == OP_AND || type == OP_OR) {
2293 first = cUNOP->op_first;
2295 first->op_next = op->op_next;
2296 cUNOP->op_first = Nullop;
2300 if (first->op_type == OP_CONST) {
2301 if (dowarn && (first->op_private & OPpCONST_BARE))
2302 warn("Probable precedence problem on %s", op_name[type]);
2303 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
2312 else if (first->op_type == OP_WANTARRAY) {
2322 if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
2323 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
2325 Newz(1101, logop, 1, LOGOP);
2327 logop->op_type = type;
2328 logop->op_ppaddr = ppaddr[type];
2329 logop->op_first = first;
2330 logop->op_flags = flags | OPf_KIDS;
2331 logop->op_other = LINKLIST(other);
2332 logop->op_private = 1;
2334 /* establish postfix order */
2335 logop->op_next = LINKLIST(first);
2336 first->op_next = (OP*)logop;
2337 first->op_sibling = other;
2339 op = newUNOP(OP_NULL, 0, (OP*)logop);
2340 other->op_next = op;
2346 newCONDOP(flags, first, true, false)
2356 return newLOGOP(OP_AND, 0, first, true);
2358 return newLOGOP(OP_OR, 0, first, false);
2360 scalarboolean(first);
2361 if (first->op_type == OP_CONST) {
2362 if (SvTRUE(((SVOP*)first)->op_sv)) {
2373 else if (first->op_type == OP_WANTARRAY) {
2377 Newz(1101, condop, 1, CONDOP);
2379 condop->op_type = OP_COND_EXPR;
2380 condop->op_ppaddr = ppaddr[OP_COND_EXPR];
2381 condop->op_first = first;
2382 condop->op_flags = flags | OPf_KIDS;
2383 condop->op_true = LINKLIST(true);
2384 condop->op_false = LINKLIST(false);
2385 condop->op_private = 1;
2387 /* establish postfix order */
2388 condop->op_next = LINKLIST(first);
2389 first->op_next = (OP*)condop;
2391 first->op_sibling = true;
2392 true->op_sibling = false;
2393 op = newUNOP(OP_NULL, 0, (OP*)condop);
2396 false->op_next = op;
2402 newRANGE(flags, left, right)
2412 Newz(1101, condop, 1, CONDOP);
2414 condop->op_type = OP_RANGE;
2415 condop->op_ppaddr = ppaddr[OP_RANGE];
2416 condop->op_first = left;
2417 condop->op_flags = OPf_KIDS;
2418 condop->op_true = LINKLIST(left);
2419 condop->op_false = LINKLIST(right);
2420 condop->op_private = 1;
2422 left->op_sibling = right;
2424 condop->op_next = (OP*)condop;
2425 flip = newUNOP(OP_FLIP, flags, (OP*)condop);
2426 flop = newUNOP(OP_FLOP, 0, flip);
2427 op = newUNOP(OP_NULL, 0, flop);
2430 left->op_next = flip;
2431 right->op_next = flop;
2433 condop->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2434 sv_upgrade(PAD_SV(condop->op_targ), SVt_PVNV);
2435 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2436 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
2438 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2439 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2442 if (!flip->op_private || !flop->op_private)
2443 linklist(op); /* blow off optimizer unless constant */
2449 newLOOPOP(flags, debuggable, expr, block)
2457 int once = block && block->op_flags & OPf_SPECIAL &&
2458 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
2461 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
2462 return block; /* do {} while 0 does once */
2463 else if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB)
2464 expr = newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr);
2467 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
2468 op = newLOGOP(OP_AND, 0, expr, listop);
2470 ((LISTOP*)listop)->op_last->op_next = LINKLIST(op);
2472 if (once && op != listop)
2473 op->op_next = ((LOGOP*)cUNOP->op_first)->op_other;
2476 op = newUNOP(OP_NULL, 0, op); /* or do {} while 1 loses outer block */
2478 op->op_flags |= flags;
2480 op->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/
2485 newWHILEOP(flags, debuggable, loop, expr, block, cont)
2499 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB)) {
2500 expr = newUNOP(OP_DEFINED, 0,
2501 newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr) );
2505 block = newOP(OP_NULL, 0);
2508 next = LINKLIST(cont);
2510 cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
2512 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
2513 redo = LINKLIST(listop);
2516 op = newLOGOP(OP_AND, 0, expr, scalar(listop));
2517 if (op == expr && op->op_type == OP_CONST && !SvTRUE(cSVOP->op_sv)) {
2518 op_free(expr); /* oops, it's a while (0) */
2520 return Nullop; /* (listop already freed by newLOGOP) */
2522 ((LISTOP*)listop)->op_last->op_next = condop =
2523 (op == listop ? redo : LINKLIST(op));
2531 Newz(1101,loop,1,LOOP);
2532 loop->op_type = OP_ENTERLOOP;
2533 loop->op_ppaddr = ppaddr[OP_ENTERLOOP];
2534 loop->op_private = 0;
2535 loop->op_next = (OP*)loop;
2538 op = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, op);
2540 loop->op_redoop = redo;
2541 loop->op_lastop = op;
2544 loop->op_nextop = next;
2546 loop->op_nextop = op;
2548 op->op_flags |= flags;
2553 #ifndef CAN_PROTOTYPE
2554 newFOROP(flags,label,forline,sv,expr,block,cont)
2563 newFOROP(I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
2564 #endif /* CAN_PROTOTYPE */
2571 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
2572 sv->op_type = OP_RV2GV;
2573 sv->op_ppaddr = ppaddr[OP_RV2GV];
2575 else if (sv->op_type == OP_PADSV) { /* private variable */
2576 padoff = sv->op_targ;
2581 croak("Can't use %s for loop variable", op_name[sv->op_type]);
2584 sv = newGVOP(OP_GV, 0, defgv);
2586 loop = (LOOP*)list(convert(OP_ENTERITER, 0,
2587 append_elem(OP_LIST, mod(force_list(expr), OP_GREPSTART),
2589 assert(!loop->op_next);
2590 Renew(loop, 1, LOOP);
2591 loop->op_targ = padoff;
2592 return newSTATEOP(0, label, newWHILEOP(flags, 1, loop,
2593 newOP(OP_ITER, 0), block, cont));
2597 newLOOPEX(type, label)
2602 if (type != OP_GOTO || label->op_type == OP_CONST) {
2603 op = newPVOP(type, 0, savepv(
2604 label->op_type == OP_CONST
2605 ? SvPVx(((SVOP*)label)->op_sv, na)
2610 if (label->op_type == OP_ENTERSUB)
2611 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
2612 op = newUNOP(type, OPf_STACKED, label);
2614 hints |= HINT_BLOCK_SCOPE;
2622 if (!CvXSUB(cv) && CvROOT(cv)) {
2624 croak("Can't undef active subroutine");
2630 if (!SvFLAGS(cv) & SVpcv_CLONED)
2631 op_free(CvROOT(cv));
2632 CvROOT(cv) = Nullop;
2633 if (CvPADLIST(cv)) {
2634 I32 i = AvFILL(CvPADLIST(cv));
2636 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
2640 SvREFCNT_dec((SV*)CvPADLIST(cv));
2641 CvPADLIST(cv) = Nullav;
2643 SvREFCNT_dec(CvGV(cv));
2645 SvREFCNT_dec(CvOUTSIDE(cv));
2646 CvOUTSIDE(cv) = Nullcv;
2657 AV* protopadlist = CvPADLIST(proto);
2658 AV* protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
2659 AV* protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
2660 SV** svp = AvARRAY(protopad);
2669 cv = compcv = (CV*)NEWSV(1104,0);
2670 sv_upgrade((SV *)cv, SVt_PVCV);
2671 SvFLAGS(cv) |= SVpcv_CLONED;
2673 CvFILEGV(cv) = CvFILEGV(proto);
2674 CvGV(cv) = SvREFCNT_inc(CvGV(proto));
2675 CvSTASH(cv) = CvSTASH(proto);
2676 CvROOT(cv) = CvROOT(proto);
2677 CvSTART(cv) = CvSTART(proto);
2678 if (CvOUTSIDE(proto))
2679 CvOUTSIDE(cv) = (CV*)SvREFCNT_inc((SV*)CvOUTSIDE(proto));
2683 comppadlist = newAV();
2684 AvREAL_off(comppadlist);
2685 av_store(comppadlist, 0, SvREFCNT_inc((SV*)protopad_name));
2686 av_store(comppadlist, 1, (SV*)comppad);
2687 CvPADLIST(cv) = comppadlist;
2688 av_extend(comppad, AvFILL(protopad));
2689 curpad = AvARRAY(comppad);
2691 av = newAV(); /* will be @_ */
2693 av_store(comppad, 0, (SV*)av);
2694 AvFLAGS(av) = AVf_REIFY;
2696 svp = AvARRAY(protopad_name);
2697 for ( ix = AvFILL(protopad); ix > 0; ix--) {
2699 if (svp[ix] != &sv_undef) {
2700 char *name = SvPVX(svp[ix]); /* XXX */
2701 if (SvFLAGS(svp[ix]) & SVf_FAKE) { /* lexical from outside? */
2702 I32 off = pad_findlex(name,ix,curcop->cop_seq, CvOUTSIDE(proto), cxstack_ix);
2704 croak("panic: cv_clone: %s", name);
2706 else { /* our own lexical */
2708 av_store(comppad, ix, sv = (SV*)newAV());
2709 else if (*name == '%')
2710 av_store(comppad, ix, sv = (SV*)newHV());
2712 av_store(comppad, ix, sv = NEWSV(0,0));
2717 av_store(comppad, ix, sv = NEWSV(0,0));
2727 newSUB(floor,op,block)
2733 char *name = op ? SvPVx(cSVOP->op_sv, na) : "__ANON__";
2734 GV *gv = gv_fetchpv(name, GV_ADDMULTI, SVt_PVCV);
2741 if (cv = GvCV(gv)) {
2743 cv = 0; /* just a cached method */
2744 else if (CvROOT(cv) || CvXSUB(cv) || GvFLAGS(gv) & GVf_IMPORTED) {
2745 if (dowarn) { /* already defined (or promised)? */
2746 line_t oldline = curcop->cop_line;
2748 curcop->cop_line = copline;
2749 warn("Subroutine %s redefined",name);
2750 curcop->cop_line = oldline;
2756 if (cv) { /* must reuse cv if autoloaded */
2758 assert(SvREFCNT(CvGV(cv)) > 1);
2759 SvREFCNT_dec(CvGV(cv));
2761 CvOUTSIDE(cv) = CvOUTSIDE(compcv);
2762 CvOUTSIDE(compcv) = 0;
2763 CvPADLIST(cv) = CvPADLIST(compcv);
2764 SvREFCNT_dec(compcv);
2771 CvFILEGV(cv) = curcop->cop_filegv;
2772 CvGV(cv) = SvREFCNT_inc(gv);
2773 CvSTASH(cv) = curstash;
2783 av = newAV(); /* Will be @_ */
2785 av_store(comppad, 0, (SV*)av);
2786 AvFLAGS(av) = AVf_REIFY;
2788 for (ix = AvFILL(comppad); ix > 0; ix--) {
2789 if (!SvPADMY(curpad[ix]))
2790 SvPADTMP_on(curpad[ix]);
2793 if (AvFILL(comppad_name) < AvFILL(comppad))
2794 av_store(comppad_name, AvFILL(comppad), Nullsv);
2796 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
2797 CvSTART(cv) = LINKLIST(CvROOT(cv));
2798 CvROOT(cv)->op_next = 0;
2800 if (s = strrchr(name,':'))
2804 if (strEQ(s, "BEGIN")) {
2805 line_t oldline = compiling.cop_line;
2808 SAVESPTR(compiling.cop_filegv);
2812 av_push(beginav, (SV *)cv);
2813 DEBUG_x( dump_sub(gv) );
2817 rspara = (nrslen == 2);
2824 curcop = &compiling;
2825 curcop->cop_line = oldline; /* might have recursed to yylex */
2828 else if (strEQ(s, "END")) {
2831 av_unshift(endav, 1);
2832 av_store(endav, 0, SvREFCNT_inc(cv));
2834 if (perldb && curstash != debstash) {
2836 SV *tmpstr = sv_newmortal();
2838 sprintf(buf,"%s:%ld",SvPVX(GvSV(curcop->cop_filegv)), (long)subline);
2839 sv = newSVpv(buf,0);
2841 sprintf(buf,"%ld",(long)curcop->cop_line);
2843 gv_efullname(tmpstr,gv);
2844 hv_store(GvHV(DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
2850 GvCV(gv) = 0; /* Will remember in SVOP instead. */
2851 SvFLAGS(cv) |= SVpcv_ANON;
2858 newXSUB(name, ix, subaddr, filename)
2864 CV* cv = newXS(name, (void(*)())subaddr, filename);
2865 CvOLDSTYLE(cv) = TRUE;
2866 CvXSUBANY(cv).any_i32 = ix;
2872 newXS(name, subaddr, filename)
2874 void (*subaddr) _((CV*));
2878 GV *gv = gv_fetchpv((name ? name : "__ANON__"), GV_ADDMULTI, SVt_PVCV);
2883 if (cv = GvCV(gv)) {
2885 cv = 0; /* just a cached method */
2886 else if (CvROOT(cv) || CvXSUB(cv)) { /* already defined? */
2888 line_t oldline = curcop->cop_line;
2890 curcop->cop_line = copline;
2891 warn("Subroutine %s redefined",name);
2892 curcop->cop_line = oldline;
2898 if (cv) { /* must reuse cv if autoloaded */
2899 assert(SvREFCNT(CvGV(cv)) > 1);
2900 SvREFCNT_dec(CvGV(cv));
2903 cv = (CV*)NEWSV(1105,0);
2904 sv_upgrade((SV *)cv, SVt_PVCV);
2907 CvGV(cv) = SvREFCNT_inc(gv);
2909 CvFILEGV(cv) = gv_fetchfile(filename);
2910 CvXSUB(cv) = subaddr;
2913 else if (s = strrchr(name,':'))
2917 if (strEQ(s, "BEGIN")) {
2920 av_push(beginav, SvREFCNT_inc(gv));
2922 else if (strEQ(s, "END")) {
2925 av_unshift(endav, 1);
2926 av_store(endav, 0, SvREFCNT_inc(gv));
2929 GvCV(gv) = 0; /* Will remember elsewhere instead. */
2930 SvFLAGS(cv) |= SVpcv_ANON;
2936 newFORM(floor,op,block)
2948 name = SvPVx(cSVOP->op_sv, na);
2951 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
2953 if (cv = GvFORM(gv)) {
2955 line_t oldline = curcop->cop_line;
2957 curcop->cop_line = copline;
2958 warn("Format %s redefined",name);
2959 curcop->cop_line = oldline;
2965 CvGV(cv) = SvREFCNT_inc(gv);
2966 CvFILEGV(cv) = curcop->cop_filegv;
2968 for (ix = AvFILL(comppad); ix > 0; ix--) {
2969 if (!SvPADMY(curpad[ix]))
2970 SvPADTMP_on(curpad[ix]);
2973 CvPADLIST(cv) = av = newAV();
2975 av_store(av, 1, SvREFCNT_inc((SV*)comppad));
2978 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
2979 CvSTART(cv) = LINKLIST(CvROOT(cv));
2980 CvROOT(cv)->op_next = 0;
2994 Newz(1101, mop, 1, LOGOP);
2995 mop->op_type = OP_METHOD;
2996 mop->op_ppaddr = ppaddr[OP_METHOD];
2997 mop->op_first = scalar(ref);
2998 mop->op_flags |= OPf_KIDS;
2999 mop->op_private = 1;
3000 mop->op_other = LINKLIST(name);
3001 mop->op_targ = pad_alloc(OP_METHOD, SVs_PADTMP);
3002 mop->op_next = LINKLIST(ref);
3003 ref->op_next = (OP*)mop;
3004 return scalar((OP*)mop);
3011 return newUNOP(OP_REFGEN, 0,
3012 mod(list(convert(OP_ANONLIST, 0, op)), OP_REFGEN));
3019 return newUNOP(OP_REFGEN, 0,
3020 mod(list(convert(OP_ANONHASH, 0, op)), OP_REFGEN));
3024 newANONSUB(floor, block)
3028 return newUNOP(OP_REFGEN, 0,
3029 newSVOP(OP_ANONCODE, 0, (SV*)newSUB(floor, 0, block)));
3036 switch (o->op_type) {
3038 o->op_type = OP_PADAV;
3039 o->op_ppaddr = ppaddr[OP_PADAV];
3040 return ref(newUNOP(OP_RV2AV, 0, scalar(o)), OP_RV2AV);
3043 o->op_type = OP_RV2AV;
3044 o->op_ppaddr = ppaddr[OP_RV2AV];
3049 warn("oops: oopsAV");
3059 switch (o->op_type) {
3062 o->op_type = OP_PADHV;
3063 o->op_ppaddr = ppaddr[OP_PADHV];
3064 return ref(newUNOP(OP_RV2HV, 0, scalar(o)), OP_RV2HV);
3068 o->op_type = OP_RV2HV;
3069 o->op_ppaddr = ppaddr[OP_RV2HV];
3074 warn("oops: oopsHV");
3084 if (o->op_type == OP_PADANY) {
3085 o->op_type = OP_PADAV;
3086 o->op_ppaddr = ppaddr[OP_PADAV];
3089 return newUNOP(OP_RV2AV, 0, scalar(o));
3097 if (type == OP_MAPSTART)
3098 return newUNOP(OP_NULL, 0, o);
3099 return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
3106 if (o->op_type == OP_PADANY) {
3107 o->op_type = OP_PADHV;
3108 o->op_ppaddr = ppaddr[OP_PADHV];
3111 return newUNOP(OP_RV2HV, 0, scalar(o));
3118 croak("NOT IMPL LINE %d",__LINE__);
3127 return newUNOP(OP_RV2CV, 0, scalar(o));
3134 if (o->op_type == OP_PADANY) {
3135 o->op_type = OP_PADSV;
3136 o->op_ppaddr = ppaddr[OP_PADSV];
3139 return newUNOP(OP_RV2SV, 0, scalar(o));
3142 /* Check routines. */
3148 if (cUNOP->op_first->op_type == OP_CONCAT)
3149 op->op_flags |= OPf_STACKED;
3157 if (op->op_flags & OPf_KIDS) {
3160 op = modkids(ck_fun(op), op->op_type);
3161 kid = cUNOP->op_first;
3162 newop = kUNOP->op_first->op_sibling;
3164 (newop->op_sibling ||
3165 !(opargs[newop->op_type] & OA_RETSCALAR) ||
3166 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
3167 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
3171 op_free(kUNOP->op_first);
3172 kUNOP->op_first = newop;
3174 op->op_ppaddr = ppaddr[++op->op_type];
3183 if (op->op_flags & OPf_KIDS) {
3184 OP *kid = cUNOP->op_first;
3185 if (kid->op_type != OP_HELEM)
3186 croak("%s argument is not a HASH element", op_name[op->op_type]);
3196 I32 type = op->op_type;
3198 if (op->op_flags & OPf_KIDS) {
3199 if (cLISTOP->op_first->op_type == OP_STUB) {
3201 op = newUNOP(type, OPf_SPECIAL,
3202 newGVOP(OP_GV, 0, gv_fetchpv("main'ARGV", TRUE, SVt_PVAV)));
3213 hints |= HINT_BLOCK_SCOPE;
3214 if (op->op_flags & OPf_KIDS) {
3215 SVOP *kid = (SVOP*)cUNOP->op_first;
3218 op->op_flags &= ~OPf_KIDS;
3221 else if (kid->op_type == OP_LINESEQ) {
3224 kid->op_next = op->op_next;
3225 cUNOP->op_first = 0;
3228 Newz(1101, enter, 1, LOGOP);
3229 enter->op_type = OP_ENTERTRY;
3230 enter->op_ppaddr = ppaddr[OP_ENTERTRY];
3231 enter->op_private = 0;
3233 /* establish postfix order */
3234 enter->op_next = (OP*)enter;
3236 op = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
3237 op->op_type = OP_LEAVETRY;
3238 op->op_ppaddr = ppaddr[OP_LEAVETRY];
3239 enter->op_other = op;
3245 op = newUNOP(OP_ENTEREVAL, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3247 op->op_targ = (PADOFFSET)hints;
3256 if (op->op_flags & OPf_STACKED) {
3258 kid = cUNOP->op_first->op_sibling;
3259 if (kid->op_type == OP_RV2GV)
3271 o = fold_constants(o);
3272 if (o->op_type == OP_CONST)
3281 SVOP *kid = (SVOP*)cUNOP->op_first;
3283 op->op_private = (hints & HINT_STRICT_REFS);
3284 if (kid->op_type == OP_CONST) {
3285 int iscv = (op->op_type==OP_RV2CV)*2;
3287 kid->op_type = OP_GV;
3288 for (gv = 0; !gv; iscv++) {
3290 * This is a little tricky. We only want to add the symbol if we
3291 * didn't add it in the lexer. Otherwise we get duplicate strict
3292 * warnings. But if we didn't add it in the lexer, we must at
3293 * least pretend like we wanted to add it even if it existed before,
3294 * or we get possible typo warnings. OPpCONST_ENTERED says
3295 * whether the lexer already added THIS instance of this symbol.
3297 gv = gv_fetchpv(SvPVx(kid->op_sv, na),
3298 iscv | !(kid->op_private & OPpCONST_ENTERED),
3301 : op->op_type == OP_RV2SV
3303 : op->op_type == OP_RV2AV
3305 : op->op_type == OP_RV2HV
3309 SvREFCNT_dec(kid->op_sv);
3310 kid->op_sv = SvREFCNT_inc(gv);
3326 I32 type = op->op_type;
3328 if (op->op_flags & OPf_REF)
3331 if (op->op_flags & OPf_KIDS) {
3332 SVOP *kid = (SVOP*)cUNOP->op_first;
3334 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
3335 OP *newop = newGVOP(type, OPf_REF,
3336 gv_fetchpv(SvPVx(kid->op_sv, na), TRUE, SVt_PVIO));
3343 if (type == OP_FTTTY)
3344 return newGVOP(type, OPf_REF, gv_fetchpv("main'STDIN", TRUE,
3347 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3360 int type = op->op_type;
3361 register I32 oa = opargs[type] >> OASHIFT;
3363 if (op->op_flags & OPf_STACKED) {
3364 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
3367 return no_fh_allowed(op);
3370 if (op->op_flags & OPf_KIDS) {
3371 tokid = &cLISTOP->op_first;
3372 kid = cLISTOP->op_first;
3373 if (kid->op_type == OP_PUSHMARK ||
3374 kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK)
3376 tokid = &kid->op_sibling;
3377 kid = kid->op_sibling;
3379 if (!kid && opargs[type] & OA_DEFGV)
3380 *tokid = kid = newSVREF(newGVOP(OP_GV, 0, defgv));
3384 sibl = kid->op_sibling;
3398 if (kid->op_type == OP_CONST &&
3399 (kid->op_private & OPpCONST_BARE)) {
3400 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
3401 OP *newop = newAVREF(newGVOP(OP_GV, 0,
3402 gv_fetchpv(name, TRUE, SVt_PVAV) ));
3404 warn("Array @%s missing the @ in argument %d of %s()",
3405 name, numargs, op_name[type]);
3408 kid->op_sibling = sibl;
3411 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
3412 bad_type(numargs, "array", op, kid);
3416 if (kid->op_type == OP_CONST &&
3417 (kid->op_private & OPpCONST_BARE)) {
3418 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
3419 OP *newop = newHVREF(newGVOP(OP_GV, 0,
3420 gv_fetchpv(name, TRUE, SVt_PVHV) ));
3422 warn("Hash %%%s missing the %% in argument %d of %s()",
3423 name, numargs, op_name[type]);
3426 kid->op_sibling = sibl;
3429 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
3430 bad_type(numargs, "hash", op, kid);
3435 OP *newop = newUNOP(OP_NULL, 0, kid);
3436 kid->op_sibling = 0;
3438 newop->op_next = newop;
3440 kid->op_sibling = sibl;
3445 if (kid->op_type != OP_GV) {
3446 if (kid->op_type == OP_CONST &&
3447 (kid->op_private & OPpCONST_BARE)) {
3448 OP *newop = newGVOP(OP_GV, 0,
3449 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, na), TRUE,
3455 kid->op_sibling = 0;
3456 kid = newUNOP(OP_RV2GV, 0, scalar(kid));
3458 kid->op_sibling = sibl;
3464 mod(scalar(kid), type);
3468 tokid = &kid->op_sibling;
3469 kid = kid->op_sibling;
3471 op->op_private = numargs;
3473 return too_many_arguments(op);
3476 else if (opargs[type] & OA_DEFGV) {
3478 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3482 while (oa & OA_OPTIONAL)
3484 if (oa && oa != OA_LIST)
3485 return too_few_arguments(op);
3494 GV *gv = newGVgen("main");
3496 append_elem(OP_GLOB, op, newGVOP(OP_GV, 0, gv));
3507 OPCODE type = op->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
3509 op->op_ppaddr = ppaddr[OP_GREPSTART];
3510 Newz(1101, gwop, 1, LOGOP);
3512 if (op->op_flags & OPf_STACKED) {
3515 for (k = cLISTOP->op_first->op_sibling->op_next; k; k = k->op_next) {
3518 kid->op_next = (OP*)gwop;
3519 op->op_flags &= ~OPf_STACKED;
3521 kid = cLISTOP->op_first->op_sibling;
3522 if (type == OP_MAPWHILE)
3529 kid = cLISTOP->op_first->op_sibling;
3530 if (kid->op_type != OP_NULL)
3531 croak("panic: ck_grep");
3532 kid = kUNOP->op_first;
3534 gwop->op_type = type;
3535 gwop->op_ppaddr = ppaddr[type];
3536 gwop->op_first = listkids(op);
3537 gwop->op_flags |= OPf_KIDS;
3538 gwop->op_private = 1;
3539 gwop->op_other = LINKLIST(kid);
3540 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
3541 kid->op_next = (OP*)gwop;
3543 kid = cLISTOP->op_first->op_sibling;
3544 if (!kid || !kid->op_sibling)
3545 return too_few_arguments(op);
3546 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
3547 mod(kid, OP_GREPSTART);
3556 if (op->op_flags & OPf_KIDS) {
3557 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3558 if (kid && kid->op_type == OP_CONST)
3559 fbm_compile(((SVOP*)kid)->op_sv, 0);
3568 /* XXX length optimization goes here */
3576 return modkids(ck_fun(op), op->op_type);
3583 return refkids(ck_fun(op), op->op_type);
3592 kid = cLISTOP->op_first;
3594 op = force_list(op);
3595 kid = cLISTOP->op_first;
3597 if (kid->op_type == OP_PUSHMARK)
3598 kid = kid->op_sibling;
3599 if (kid && op->op_flags & OPf_STACKED)
3600 kid = kid->op_sibling;
3601 else if (kid && !kid->op_sibling) { /* print HANDLE; */
3602 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
3603 op->op_flags |= OPf_STACKED; /* make it a filehandle */
3604 kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
3605 cLISTOP->op_first->op_sibling = kid;
3606 cLISTOP->op_last = kid;
3607 kid = kid->op_sibling;
3612 append_elem(op->op_type, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
3614 return listkids(op);
3621 cPMOP->op_pmflags |= PMf_RUNTIME;
3636 if (cBINOP->op_first->op_flags & OPf_PARENS) {
3637 op->op_private = OPpREPEAT_DOLIST;
3638 cBINOP->op_first = force_list(cBINOP->op_first);
3649 if (op->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
3650 SVOP *kid = (SVOP*)cUNOP->op_first;
3652 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
3654 for (s = SvPVX(kid->op_sv); *s; s++) {
3655 if (*s == ':' && s[1] == ':') {
3657 Move(s+2, s+1, strlen(s+2)+1, char);
3658 --SvCUR(kid->op_sv);
3661 sv_catpvn(kid->op_sv, ".pm", 3);
3671 croak("NOT IMPL LINE %d",__LINE__);
3680 if (op->op_flags & OPf_KIDS) {
3681 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3682 if (kid && kid->op_sibling) {
3683 op->op_type = OP_SSELECT;
3684 op->op_ppaddr = ppaddr[OP_SSELECT];
3686 return fold_constants(op);
3696 I32 type = op->op_type;
3698 if (!(op->op_flags & OPf_KIDS)) {
3700 return newUNOP(type, 0,
3701 scalar(newUNOP(OP_RV2AV, 0,
3702 scalar(newGVOP(OP_GV, 0,
3703 gv_fetchpv((subline ? "_" : "ARGV"), TRUE, SVt_PVAV) )))));
3705 return scalar(modkids(ck_fun(op), type));
3712 if (op->op_flags & OPf_STACKED) {
3713 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3715 kid = kUNOP->op_first; /* get past rv2gv */
3717 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
3719 if (kid->op_type == OP_SCOPE) {
3723 else if (kid->op_type == OP_LEAVE) {
3724 if (op->op_type == OP_SORT) {
3725 null(kid); /* wipe out leave */
3728 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
3729 if (k->op_next == kid)
3734 kid->op_next = 0; /* just disconnect the leave */
3735 k = kLISTOP->op_first;
3739 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3740 null(kid); /* wipe out rv2gv */
3741 if (op->op_type == OP_SORT)
3745 op->op_flags |= OPf_SPECIAL;
3758 if (op->op_flags & OPf_STACKED)
3759 return no_fh_allowed(op);
3761 kid = cLISTOP->op_first;
3762 if (kid->op_type != OP_NULL)
3763 croak("panic: ck_split");
3764 kid = kid->op_sibling;
3765 op_free(cLISTOP->op_first);
3766 cLISTOP->op_first = kid;
3768 cLISTOP->op_first = kid = newSVOP(OP_CONST, 0, newSVpv(" ", 1));
3769 cLISTOP->op_last = kid; /* There was only one element previously */
3772 if (kid->op_type != OP_MATCH) {
3773 OP *sibl = kid->op_sibling;
3774 kid->op_sibling = 0;
3775 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
3776 if (cLISTOP->op_first == cLISTOP->op_last)
3777 cLISTOP->op_last = kid;
3778 cLISTOP->op_first = kid;
3779 kid->op_sibling = sibl;
3782 if (pm->op_pmshort && !(pm->op_pmflags & PMf_ALL)) {
3783 SvREFCNT_dec(pm->op_pmshort); /* can't use substring to optimize */
3787 kid->op_type = OP_PUSHRE;
3788 kid->op_ppaddr = ppaddr[OP_PUSHRE];
3791 if (!kid->op_sibling)
3792 append_elem(OP_SPLIT, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
3794 kid = kid->op_sibling;
3797 if (!kid->op_sibling)
3798 append_elem(OP_SPLIT, op, newSVOP(OP_CONST, 0, newSViv(0)));
3800 kid = kid->op_sibling;
3803 if (kid->op_sibling)
3804 return too_many_arguments(op);
3813 OP *o = ((cUNOP->op_first->op_sibling)
3814 ? cUNOP : ((UNOP*)cUNOP->op_first))->op_first->op_sibling;
3816 if (o->op_type == OP_RV2CV)
3817 null(o); /* disable rv2cv */
3818 op->op_private = (hints & HINT_STRICT_REFS);
3819 if (perldb && curstash != debstash)
3820 op->op_private |= OPpDEREF_DB;
3821 while (o = o->op_sibling)
3822 mod(o, OP_ENTERSUB);
3830 SvREADONLY_on(cSVOP->op_sv);
3838 if (op->op_flags & OPf_KIDS) {
3839 SVOP *kid = (SVOP*)cUNOP->op_first;
3841 if (kid->op_type == OP_NULL)
3842 kid = (SVOP*)kid->op_sibling;
3844 kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE))
3845 op->op_flags |= OPf_SPECIAL;
3850 /* A peephole optimizer. We visit the ops in the order they're to execute. */
3856 register OP* oldop = 0;
3857 if (!o || o->op_seq)
3862 for (; o; o = o->op_next) {
3866 switch (o->op_type) {
3869 curcop = ((COP*)o); /* for warnings */
3870 o->op_seq = ++op_seqmax;
3881 if (o->op_next->op_type == OP_STRINGIFY)
3883 o->op_seq = ++op_seqmax;
3886 if ((o->op_flags & (OPf_KNOW|OPf_LIST)) != (OPf_KNOW|OPf_LIST)) {
3887 o->op_seq = ++op_seqmax;
3888 break; /* Scalar stub must produce undef. List stub is noop */
3892 if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE)
3893 curcop = ((COP*)op);
3899 if (oldop && o->op_next) {
3900 oldop->op_next = o->op_next;
3903 o->op_seq = ++op_seqmax;
3907 if (o->op_next->op_type == OP_RV2SV) {
3908 if (!(o->op_next->op_private & (OPpDEREF_HV|OPpDEREF_AV))) {
3910 o->op_private |= o->op_next->op_private & OPpLVAL_INTRO;
3911 o->op_next = o->op_next->op_next;
3912 o->op_type = OP_GVSV;
3913 o->op_ppaddr = ppaddr[OP_GVSV];
3916 else if (o->op_next->op_type == OP_RV2AV) {
3917 OP* pop = o->op_next->op_next;
3919 if (pop->op_type == OP_CONST &&
3920 (op = pop->op_next) &&
3921 pop->op_next->op_type == OP_AELEM &&
3922 !(pop->op_next->op_private &
3923 (OPpDEREF_HV|OPpDEREF_AV|OPpLVAL_INTRO)) &&
3924 (i = SvIV(((SVOP*)pop)->op_sv) - compiling.cop_arybase)
3928 SvREFCNT_dec(((SVOP*)pop)->op_sv);
3932 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
3933 o->op_next = pop->op_next->op_next;
3934 o->op_type = OP_AELEMFAST;
3935 o->op_ppaddr = ppaddr[OP_AELEMFAST];
3936 o->op_private = (U8)i;
3937 GvAVn((GV*)(((SVOP*)o)->op_sv));
3940 o->op_seq = ++op_seqmax;
3947 o->op_seq = ++op_seqmax;
3948 peep(cLOGOP->op_other);
3952 o->op_seq = ++op_seqmax;
3953 peep(cCONDOP->op_true);
3954 peep(cCONDOP->op_false);
3958 o->op_seq = ++op_seqmax;
3959 peep(cLOOP->op_redoop);
3960 peep(cLOOP->op_nextop);
3961 peep(cLOOP->op_lastop);
3966 o->op_seq = ++op_seqmax;
3967 peep(cPMOP->op_pmreplstart);
3971 o->op_seq = ++op_seqmax;
3972 if (dowarn && o->op_next && o->op_next->op_type == OP_NEXTSTATE) {
3973 if (o->op_next->op_sibling &&
3974 o->op_next->op_sibling->op_type != OP_DIE) {
3975 line_t oldline = curcop->cop_line;
3977 curcop->cop_line = ((COP*)o->op_next)->cop_line;
3978 warn("Statement unlikely to be reached");
3979 warn("(Maybe you meant system() when you said exec()?)\n");
3980 curcop->cop_line = oldline;
3985 o->op_seq = ++op_seqmax;