cd831cb4ad1a692a4894ff1d0e3fe91cc5cac108
[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 #ifdef MACOS_TRADITIONAL
27         MACPERL_DO_ASYNC_TASKS();
28 #endif  
29     }
30
31     TAINT_NOT;
32     return 0;
33 }
34
35 int
36 Perl_runops_debug(pTHX)
37 {
38 #ifdef DEBUGGING
39     dTHR;
40     if (!PL_op) {
41         if (ckWARN_d(WARN_DEBUGGING))
42             Perl_warner(aTHX_ WARN_DEBUGGING, "NULL OP IN RUN");
43         return 0;
44     }
45
46     do {
47 #ifdef MACOS_TRADITIONAL
48         MACPERL_DO_ASYNC_TASKS();
49 #endif  
50         if (PL_debug) {
51             if (PL_watchaddr != 0 && *PL_watchaddr != PL_watchok)
52                 PerlIO_printf(Perl_debug_log,
53                               "WARNING: %"UVxf" changed from %"UVxf" to %"UVxf"\n",
54                               PTR2UV(PL_watchaddr), PTR2UV(PL_watchok), (UV)*PL_watchaddr);
55             DEBUG_s(debstack());
56             DEBUG_t(debop(PL_op));
57             DEBUG_P(debprof(PL_op));
58         }
59     } while ( PL_op = CALL_FPTR(PL_op->op_ppaddr)(aTHX) );
60
61     TAINT_NOT;
62     return 0;
63 #else
64     return runops_standard();
65 #endif  /* DEBUGGING */
66 }
67
68 I32
69 Perl_debop(pTHX_ OP *o)
70 {
71 #ifdef DEBUGGING
72     SV *sv;
73     STRLEN n_a;
74     Perl_deb(aTHX_ "%s", PL_op_name[o->op_type]);
75     switch (o->op_type) {
76     case OP_CONST:
77         PerlIO_printf(Perl_debug_log, "(%s)", SvPEEK(cSVOPo->op_sv));
78         break;
79     case OP_GVSV:
80     case OP_GV:
81         if (cSVOPo->op_sv) {
82             sv = NEWSV(0,0);
83             gv_fullname3(sv, (GV*)cSVOPo->op_sv, Nullch);
84             PerlIO_printf(Perl_debug_log, "(%s)", SvPV(sv, n_a));
85             SvREFCNT_dec(sv);
86         }
87         else
88             PerlIO_printf(Perl_debug_log, "(NULL)");
89         break;
90     default:
91         break;
92     }
93     PerlIO_printf(Perl_debug_log, "\n");
94 #endif  /* DEBUGGING */
95     return 0;
96 }
97
98 void
99 Perl_watch(pTHX_ char **addr)
100 {
101 #ifdef DEBUGGING
102     dTHR;
103     PL_watchaddr = addr;
104     PL_watchok = *addr;
105     PerlIO_printf(Perl_debug_log, "WATCHING, %"UVxf" is currently %"UVxf"\n",
106         PTR2UV(PL_watchaddr), PTR2UV(PL_watchok));
107 #endif  /* DEBUGGING */
108 }
109
110 STATIC void
111 S_debprof(pTHX_ OP *o)
112 {
113 #ifdef DEBUGGING
114     if (!PL_profiledata)
115         Newz(000, PL_profiledata, MAXO, U32);
116     ++PL_profiledata[o->op_type];
117 #endif /* DEBUGGING */
118 }
119
120 void
121 Perl_debprofdump(pTHX)
122 {
123 #ifdef DEBUGGING
124     unsigned i;
125     if (!PL_profiledata)
126         return;
127     for (i = 0; i < MAXO; i++) {
128         if (PL_profiledata[i])
129             PerlIO_printf(Perl_debug_log,
130                           "%5lu %s\n", (unsigned long)PL_profiledata[i],
131                                        PL_op_name[i]);
132     }
133 #endif  /* DEBUGGING */
134 }