Initial 3-way merge from (5.001m, thr1m, 5.003) plus fixups.
[p5sagit/p5-mst-13.2.git] / run.c
1 /*    run.c
2  *
3  *    Copyright (c) 1991-1994, 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     return 0;
32 }
33
34 #else
35
36 static void debprof _((OP*o));
37
38 int
39 runops() {
40     dTHR;
41     if (!op) {
42         warn("NULL OP IN RUN");
43         return 0;
44     }
45
46     SAVEI32(runlevel);
47     runlevel++;
48
49     do {
50         if (debug) {
51             if (watchaddr != 0 && *watchaddr != watchok)
52                 fprintf(stderr, "WARNING: %lx changed from %lx to %lx\n",
53                     (long)watchaddr, (long)watchok, (long)*watchaddr);
54             DEBUG_s(debstack());
55             DEBUG_t(debop(op));
56             DEBUG_P(debprof(op));
57 #ifdef USE_THREADS
58             DEBUG_L(pthread_yield());   /* shake up scheduling a bit */
59 #endif /* USE_THREADS */
60         }
61     } while ( op = (*op->op_ppaddr)(ARGS) );
62     return 0;
63 }
64
65 I32
66 debop(o)
67 OP *o;
68 {
69     SV *sv;
70     deb("%s", op_name[o->op_type]);
71     switch (o->op_type) {
72     case OP_CONST:
73         fprintf(stderr, "(%s)", SvPEEK(cSVOPo->op_sv));
74         break;
75     case OP_GVSV:
76     case OP_GV:
77         if (cGVOPo->op_gv) {
78             sv = NEWSV(0,0);
79             gv_fullname(sv, cGVOPo->op_gv);
80             fprintf(stderr, "(%s)", SvPV(sv, na));
81             SvREFCNT_dec(sv);
82         }
83         else
84             fprintf(stderr, "(NULL)");
85         break;
86     default:
87         break;
88     }
89     fprintf(stderr, "\n");
90     return 0;
91 }
92
93 void
94 watch(addr)
95 char **addr;
96 {
97     watchaddr = addr;
98     watchok = *addr;
99     fprintf(stderr, "WATCHING, %lx is currently %lx\n",
100         (long)watchaddr, (long)watchok);
101 }
102
103 static void
104 debprof(o)
105 OP* o;
106 {
107     if (!profiledata)
108         New(000, profiledata, MAXO, U32);
109     ++profiledata[o->op_type];
110 }
111
112 void
113 debprofdump()
114 {
115     U32 i;
116     if (!profiledata)
117         return;
118     for (i = 0; i < MAXO; i++) {
119         if (profiledata[i])
120             fprintf(stderr, "%d\t%lu\n", i, profiledata[i]);
121     }
122 }
123
124 #endif
125