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