Integrate thrperl 5.003->5.004.
[p5sagit/p5-mst-13.2.git] / run.c
1 /*    run.c
2  *
3  *    Copyright (c) 1991-1997, 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 #include "perl.h"
12
13 /*
14  * "Away now, Shadowfax!  Run, greatheart, run as you have never run before!
15  * Now we are come to the lands where you were foaled, and every stone you
16  * know.  Run now!  Hope is in speed!"  --Gandalf
17  */
18
19 dEXT char **watchaddr = 0;
20 dEXT char *watchok;
21
22 #ifndef DEBUGGING
23
24 int
25 runops() {
26     dTHR;
27     SAVEI32(runlevel);
28     runlevel++;
29
30     while ( op = (*op->op_ppaddr)(ARGS) ) ;
31
32     TAINT_NOT;
33     return 0;
34 }
35
36 #else
37
38 static void debprof _((OP*o));
39
40 int
41 runops() {
42     dTHR;
43     if (!op) {
44         warn("NULL OP IN RUN");
45         return 0;
46     }
47
48     SAVEI32(runlevel);
49     runlevel++;
50
51     do {
52         if (debug) {
53             if (watchaddr != 0 && *watchaddr != watchok)
54                 PerlIO_printf(Perl_debug_log, "WARNING: %lx changed from %lx to %lx\n",
55                     (long)watchaddr, (long)watchok, (long)*watchaddr);
56             DEBUG_s(debstack());
57             DEBUG_t(debop(op));
58             DEBUG_P(debprof(op));
59 #ifdef USE_THREADS
60             DEBUG_L(YIELD());   /* shake up scheduling a bit */
61 #endif /* USE_THREADS */
62         }
63     } while ( op = (*op->op_ppaddr)(ARGS) );
64
65     TAINT_NOT;
66     return 0;
67 }
68
69 I32
70 debop(o)
71 OP *o;
72 {
73     SV *sv;
74     deb("%s", 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 (cGVOPo->op_gv) {
82             sv = NEWSV(0,0);
83             gv_fullname3(sv, cGVOPo->op_gv, Nullch);
84             PerlIO_printf(Perl_debug_log, "(%s)", SvPV(sv, na));
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     return 0;
95 }
96
97 void
98 watch(addr)
99 char **addr;
100 {
101     watchaddr = addr;
102     watchok = *addr;
103     PerlIO_printf(Perl_debug_log, "WATCHING, %lx is currently %lx\n",
104         (long)watchaddr, (long)watchok);
105 }
106
107 static void
108 debprof(o)
109 OP* o;
110 {
111     if (!profiledata)
112         New(000, profiledata, MAXO, U32);
113     ++profiledata[o->op_type];
114 }
115
116 void
117 debprofdump()
118 {
119     unsigned i;
120     if (!profiledata)
121         return;
122     for (i = 0; i < MAXO; i++) {
123         if (profiledata[i])
124             PerlIO_printf(Perl_debug_log,
125                           "%u\t%lu\n", i, (unsigned long)profiledata[i]);
126     }
127 }
128
129 #endif
130