This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
posix-bc hints tweak (via private mail from Thomas Dorner
[perl5.git] / 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 #define PERL_IN_RUN_C
12 #include "perl.h"
13
14 /*
15  * "Away now, Shadowfax!  Run, greatheart, run as you have never run before!
16  * Now we are come to the lands where you were foaled, and every stone you
17  * know.  Run now!  Hope is in speed!"  --Gandalf
18  */
19
20 #ifdef PERL_OBJECT
21 #define CALLOP this->*PL_op
22 #else
23 #define CALLOP *PL_op
24 #endif
25
26 int
27 Perl_runops_standard(pTHX)
28 {
29     dTHR;
30
31     while ( PL_op = (CALLOP->op_ppaddr)(aTHX) ) ;
32
33     TAINT_NOT;
34     return 0;
35 }
36
37 int
38 Perl_runops_debug(pTHX)
39 {
40 #ifdef DEBUGGING
41     dTHR;
42     if (!PL_op) {
43         if (ckWARN_d(WARN_DEBUGGING))
44             Perl_warner(aTHX_ WARN_DEBUGGING, "NULL OP IN RUN");
45         return 0;
46     }
47
48     do {
49         if (PL_debug) {
50             if (PL_watchaddr != 0 && *PL_watchaddr != PL_watchok)
51                 PerlIO_printf(Perl_debug_log, "WARNING: %lx changed from %lx to %lx\n",
52                     (long)PL_watchaddr, (long)PL_watchok, (long)*PL_watchaddr);
53             DEBUG_s(debstack());
54             DEBUG_t(debop(PL_op));
55             DEBUG_P(debprof(PL_op));
56         }
57     } while ( PL_op = (CALLOP->op_ppaddr)(aTHX) );
58
59     TAINT_NOT;
60     return 0;
61 #else
62     return runops_standard();
63 #endif  /* DEBUGGING */
64 }
65
66 I32
67 Perl_debop(pTHX_ OP *o)
68 {
69 #ifdef DEBUGGING
70     SV *sv;
71     STRLEN n_a;
72     Perl_deb(aTHX_ "%s", PL_op_name[o->op_type]);
73     switch (o->op_type) {
74     case OP_CONST:
75         PerlIO_printf(Perl_debug_log, "(%s)", SvPEEK(cSVOPo->op_sv));
76         break;
77     case OP_GVSV:
78     case OP_GV:
79         if (cGVOPo->op_gv) {
80             sv = NEWSV(0,0);
81             gv_fullname3(sv, cGVOPo->op_gv, Nullch);
82             PerlIO_printf(Perl_debug_log, "(%s)", SvPV(sv, n_a));
83             SvREFCNT_dec(sv);
84         }
85         else
86             PerlIO_printf(Perl_debug_log, "(NULL)");
87         break;
88     default:
89         break;
90     }
91     PerlIO_printf(Perl_debug_log, "\n");
92 #endif  /* DEBUGGING */
93     return 0;
94 }
95
96 void
97 Perl_watch(pTHX_ char **addr)
98 {
99 #ifdef DEBUGGING
100     dTHR;
101     PL_watchaddr = addr;
102     PL_watchok = *addr;
103     PerlIO_printf(Perl_debug_log, "WATCHING, %lx is currently %lx\n",
104         (long)PL_watchaddr, (long)PL_watchok);
105 #endif  /* DEBUGGING */
106 }
107
108 STATIC void
109 S_debprof(pTHX_ OP *o)
110 {
111 #ifdef DEBUGGING
112     if (!PL_profiledata)
113         Newz(000, PL_profiledata, MAXO, U32);
114     ++PL_profiledata[o->op_type];
115 #endif /* DEBUGGING */
116 }
117
118 void
119 Perl_debprofdump(pTHX)
120 {
121 #ifdef DEBUGGING
122     unsigned i;
123     if (!PL_profiledata)
124         return;
125     for (i = 0; i < MAXO; i++) {
126         if (PL_profiledata[i])
127             PerlIO_printf(Perl_debug_log,
128                           "%5lu %s\n", (unsigned long)PL_profiledata[i],
129                                        PL_op_name[i]);
130     }
131 #endif  /* DEBUGGING */
132 }