[asperl] integrate latest win32 branch
[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 #ifdef PERL_OBJECT
20 #define CALLOP this->*op
21 #else
22 #define CALLOP *op
23 #endif
24
25 int
26 runops_standard(void) {
27     dTHR;
28
29     while ( op = (CALLOP->op_ppaddr)(ARGS) ) ;
30
31     TAINT_NOT;
32     return 0;
33 }
34
35 #ifdef DEBUGGING
36
37 dEXT char **watchaddr = 0;
38 dEXT char *watchok;
39
40 #ifndef PERL_OBJECT
41 static void debprof _((OP*o));
42 #endif
43
44 int
45 runops_debug(void) {
46     dTHR;
47     if (!op) {
48         warn("NULL OP IN RUN");
49         return 0;
50     }
51
52     do {
53         if (debug) {
54             if (watchaddr != 0 && *watchaddr != watchok)
55                 PerlIO_printf(Perl_debug_log, "WARNING: %lx changed from %lx to %lx\n",
56                     (long)watchaddr, (long)watchok, (long)*watchaddr);
57             DEBUG_s(debstack());
58             DEBUG_t(debop(op));
59             DEBUG_P(debprof(op));
60         }
61     } while ( op = (CALLOP->op_ppaddr)(ARGS) );
62
63     TAINT_NOT;
64     return 0;
65 }
66
67 I32
68 debop(OP *o)
69 {
70     SV *sv;
71     deb("%s", op_name[o->op_type]);
72     switch (o->op_type) {
73     case OP_CONST:
74         PerlIO_printf(Perl_debug_log, "(%s)", SvPEEK(cSVOPo->op_sv));
75         break;
76     case OP_GVSV:
77     case OP_GV:
78         if (cGVOPo->op_gv) {
79             sv = NEWSV(0,0);
80             gv_fullname3(sv, cGVOPo->op_gv, Nullch);
81             PerlIO_printf(Perl_debug_log, "(%s)", SvPV(sv, na));
82             SvREFCNT_dec(sv);
83         }
84         else
85             PerlIO_printf(Perl_debug_log, "(NULL)");
86         break;
87     default:
88         break;
89     }
90     PerlIO_printf(Perl_debug_log, "\n");
91     return 0;
92 }
93
94 void
95 watch(char **addr)
96 {
97     watchaddr = addr;
98     watchok = *addr;
99     PerlIO_printf(Perl_debug_log, "WATCHING, %lx is currently %lx\n",
100         (long)watchaddr, (long)watchok);
101 }
102
103 STATIC void
104 debprof(OP *o)
105 {
106     if (!profiledata)
107         New(000, profiledata, MAXO, U32);
108     ++profiledata[o->op_type];
109 }
110
111 void
112 debprofdump(void)
113 {
114     unsigned i;
115     if (!profiledata)
116         return;
117     for (i = 0; i < MAXO; i++) {
118         if (profiledata[i])
119             PerlIO_printf(Perl_debug_log,
120                           "%u\t%lu\n", i, (unsigned long)profiledata[i]);
121     }
122 }
123
124 #endif /* DEBUGGING */
125