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