This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
clean up some stray "global" symbols
[perl5.git] / run.c
CommitLineData
a0d0e21e
LW
1/* run.c
2 *
4eb8286e 3 * Copyright (c) 1991-1999, Larry Wall
a0d0e21e
LW
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
79072805
LW
10#include "EXTERN.h"
11#include "perl.h"
12
a0d0e21e
LW
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
76e3520e 19#ifdef PERL_OBJECT
4c2891ed 20#define CALLOP this->*PL_op
76e3520e 21#else
533c011a 22#define CALLOP *PL_op
76e3520e 23#endif
79072805 24
a0d0e21e 25int
17c3b450
GS
26runops_standard(void)
27{
11343788 28 dTHR;
a0d0e21e 29
533c011a 30 while ( PL_op = (CALLOP->op_ppaddr)(ARGS) ) ;
fd18d308
CS
31
32 TAINT_NOT;
a0d0e21e 33 return 0;
79072805
LW
34}
35
2ddcc7aa 36#ifdef DEBUGGING
76e3520e 37#ifndef PERL_OBJECT
20ce7b12 38static void debprof (OP*o);
76e3520e 39#endif
a0d0e21e 40
17c3b450
GS
41#endif /* DEBUGGING */
42
a0d0e21e 43int
35ff7856
GS
44runops_debug(void)
45{
46#ifdef DEBUGGING
11343788 47 dTHR;
533c011a 48 if (!PL_op) {
79072805 49 warn("NULL OP IN RUN");
a0d0e21e 50 return 0;
79072805 51 }
a0d0e21e 52
79072805 53 do {
3280af22 54 if (PL_debug) {
22c35a8c 55 if (PL_watchaddr != 0 && *PL_watchaddr != PL_watchok)
760ac839 56 PerlIO_printf(Perl_debug_log, "WARNING: %lx changed from %lx to %lx\n",
22c35a8c 57 (long)PL_watchaddr, (long)PL_watchok, (long)*PL_watchaddr);
79072805 58 DEBUG_s(debstack());
533c011a
NIS
59 DEBUG_t(debop(PL_op));
60 DEBUG_P(debprof(PL_op));
79072805 61 }
533c011a 62 } while ( PL_op = (CALLOP->op_ppaddr)(ARGS) );
fd18d308
CS
63
64 TAINT_NOT;
a0d0e21e 65 return 0;
35ff7856
GS
66#else
67 return runops_standard();
17c3b450 68#endif /* DEBUGGING */
79072805
LW
69}
70
79072805 71I32
8ac85365 72debop(OP *o)
79072805 73{
35ff7856 74#ifdef DEBUGGING
79072805 75 SV *sv;
2d8e6c8d 76 STRLEN n_a;
22c35a8c 77 deb("%s", PL_op_name[o->op_type]);
11343788 78 switch (o->op_type) {
79072805 79 case OP_CONST:
5dc0d613 80 PerlIO_printf(Perl_debug_log, "(%s)", SvPEEK(cSVOPo->op_sv));
79072805
LW
81 break;
82 case OP_GVSV:
83 case OP_GV:
11343788 84 if (cGVOPo->op_gv) {
79072805 85 sv = NEWSV(0,0);
5dc0d613 86 gv_fullname3(sv, cGVOPo->op_gv, Nullch);
2d8e6c8d 87 PerlIO_printf(Perl_debug_log, "(%s)", SvPV(sv, n_a));
8990e307 88 SvREFCNT_dec(sv);
79072805
LW
89 }
90 else
760ac839 91 PerlIO_printf(Perl_debug_log, "(NULL)");
79072805 92 break;
a0d0e21e
LW
93 default:
94 break;
79072805 95 }
760ac839 96 PerlIO_printf(Perl_debug_log, "\n");
17c3b450 97#endif /* DEBUGGING */
79072805
LW
98 return 0;
99}
100
101void
8ac85365 102watch(char **addr)
79072805 103{
35ff7856 104#ifdef DEBUGGING
22c35a8c
GS
105 dTHR;
106 PL_watchaddr = addr;
107 PL_watchok = *addr;
760ac839 108 PerlIO_printf(Perl_debug_log, "WATCHING, %lx is currently %lx\n",
22c35a8c 109 (long)PL_watchaddr, (long)PL_watchok);
17c3b450 110#endif /* DEBUGGING */
79072805 111}
a0d0e21e 112
76e3520e 113STATIC void
8ac85365 114debprof(OP *o)
a0d0e21e 115{
35ff7856 116#ifdef DEBUGGING
3280af22
NIS
117 if (!PL_profiledata)
118 Newz(000, PL_profiledata, MAXO, U32);
119 ++PL_profiledata[o->op_type];
35ff7856 120#endif /* DEBUGGING */
a0d0e21e
LW
121}
122
123void
8ac85365 124debprofdump(void)
a0d0e21e 125{
35ff7856 126#ifdef DEBUGGING
9607fc9c 127 unsigned i;
3280af22 128 if (!PL_profiledata)
a0d0e21e
LW
129 return;
130 for (i = 0; i < MAXO; i++) {
3280af22 131 if (PL_profiledata[i])
9607fc9c 132 PerlIO_printf(Perl_debug_log,
3280af22 133 "%5lu %s\n", (unsigned long)PL_profiledata[i],
22c35a8c 134 PL_op_name[i]);
a0d0e21e 135 }
17c3b450 136#endif /* DEBUGGING */
35ff7856 137}