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