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