Integrate with Sarathy.
[p5sagit/p5-mst-13.2.git] / run.c
1 /*    run.c
2  *
3  *    Copyright (c) 1991-1999, Larry Wall
4  *
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.
7  *
8  */
9
10 #include "EXTERN.h"
11 #define PERL_IN_RUN_C
12 #include "perl.h"
13
14 /*
15  * "Away now, Shadowfax!  Run, greatheart, run as you have never run before!
16  * Now we are come to the lands where you were foaled, and every stone you
17  * know.  Run now!  Hope is in speed!"  --Gandalf
18  */
19
20 int
21 Perl_runops_standard(pTHX)
22 {
23     dTHR;
24
25     while ( PL_op = CALL_FPTR(PL_op->op_ppaddr)(aTHX) ) {
26         PERL_ASYNC_CHECK();
27     }
28
29     TAINT_NOT;
30     return 0;
31 }
32
33 int
34 Perl_runops_debug(pTHX)
35 {
36 #ifdef DEBUGGING
37     dTHR;
38     if (!PL_op) {
39         if (ckWARN_d(WARN_DEBUGGING))
40             Perl_warner(aTHX_ WARN_DEBUGGING, "NULL OP IN RUN");
41         return 0;
42     }
43
44     do {
45         PERL_ASYNC_CHECK();
46         if (PL_debug) {
47             if (PL_watchaddr != 0 && *PL_watchaddr != PL_watchok)
48                 PerlIO_printf(Perl_debug_log,
49                               "WARNING: %"UVxf" changed from %"UVxf" to %"UVxf"\n",
50                               PTR2UV(PL_watchaddr), PTR2UV(PL_watchok), (UV)*PL_watchaddr);
51             DEBUG_s(debstack());
52             DEBUG_t(debop(PL_op));
53             DEBUG_P(debprof(PL_op));
54         }
55     } while ( PL_op = CALL_FPTR(PL_op->op_ppaddr)(aTHX) );
56
57     TAINT_NOT;
58     return 0;
59 #else
60     return runops_standard();
61 #endif  /* DEBUGGING */
62 }
63
64 I32
65 Perl_debop(pTHX_ OP *o)
66 {
67 #ifdef DEBUGGING
68     SV *sv;
69     STRLEN n_a;
70     Perl_deb(aTHX_ "%s", PL_op_name[o->op_type]);
71     switch (o->op_type) {
72     case OP_CONST:
73         PerlIO_printf(Perl_debug_log, "(%s)", SvPEEK(cSVOPo->op_sv));
74         break;
75     case OP_GVSV:
76     case OP_GV:
77         if (cGVOPo) {
78             sv = NEWSV(0,0);
79             gv_fullname3(sv, cGVOPo, Nullch);
80             PerlIO_printf(Perl_debug_log, "(%s)", SvPV(sv, n_a));
81             SvREFCNT_dec(sv);
82         }
83         else
84             PerlIO_printf(Perl_debug_log, "(NULL)");
85         break;
86     default:
87         break;
88     }
89     PerlIO_printf(Perl_debug_log, "\n");
90 #endif  /* DEBUGGING */
91     return 0;
92 }
93
94 void
95 Perl_watch(pTHX_ char **addr)
96 {
97 #ifdef DEBUGGING
98     dTHR;
99     PL_watchaddr = addr;
100     PL_watchok = *addr;
101     PerlIO_printf(Perl_debug_log, "WATCHING, %"UVxf" is currently %"UVxf"\n",
102         PTR2UV(PL_watchaddr), PTR2UV(PL_watchok));
103 #endif  /* DEBUGGING */
104 }
105
106 STATIC void
107 S_debprof(pTHX_ OP *o)
108 {
109 #ifdef DEBUGGING
110     if (!PL_profiledata)
111         Newz(000, PL_profiledata, MAXO, U32);
112     ++PL_profiledata[o->op_type];
113 #endif /* DEBUGGING */
114 }
115
116 void
117 Perl_debprofdump(pTHX)
118 {
119 #ifdef DEBUGGING
120     unsigned i;
121     if (!PL_profiledata)
122         return;
123     for (i = 0; i < MAXO; i++) {
124         if (PL_profiledata[i])
125             PerlIO_printf(Perl_debug_log,
126                           "%5lu %s\n", (unsigned long)PL_profiledata[i],
127                                        PL_op_name[i]);
128     }
129 #endif  /* DEBUGGING */
130 }