new thread should set current interp in TLS
[p5sagit/p5-mst-13.2.git] / run.c
CommitLineData
a0d0e21e 1/* run.c
2 *
4eb8286e 3 * Copyright (c) 1991-1999, 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"
864dbfa3 11#define PERL_IN_RUN_C
79072805 12#include "perl.h"
13
a0d0e21e 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
76e3520e 20#ifdef PERL_OBJECT
4c2891ed 21#define CALLOP this->*PL_op
76e3520e 22#else
533c011a 23#define CALLOP *PL_op
76e3520e 24#endif
79072805 25
a0d0e21e 26int
864dbfa3 27Perl_runops_standard(pTHX)
17c3b450 28{
11343788 29 dTHR;
a0d0e21e 30
66918de8 31 while ( PL_op = (CALLOP->op_ppaddr)(aTHX) ) ;
fd18d308 32
33 TAINT_NOT;
a0d0e21e 34 return 0;
79072805 35}
36
a0d0e21e 37int
864dbfa3 38Perl_runops_debug(pTHX)
35ff7856 39{
40#ifdef DEBUGGING
11343788 41 dTHR;
f248d071 42 if (!PL_op) {
43 if (ckWARN_d(WARN_DEBUGGING))
44 Perl_warner(aTHX_ WARN_DEBUGGING, "NULL OP IN RUN");
a0d0e21e 45 return 0;
79072805 46 }
a0d0e21e 47
79072805 48 do {
3280af22 49 if (PL_debug) {
22c35a8c 50 if (PL_watchaddr != 0 && *PL_watchaddr != PL_watchok)
760ac839 51 PerlIO_printf(Perl_debug_log, "WARNING: %lx changed from %lx to %lx\n",
22c35a8c 52 (long)PL_watchaddr, (long)PL_watchok, (long)*PL_watchaddr);
79072805 53 DEBUG_s(debstack());
533c011a 54 DEBUG_t(debop(PL_op));
55 DEBUG_P(debprof(PL_op));
79072805 56 }
66918de8 57 } while ( PL_op = (CALLOP->op_ppaddr)(aTHX) );
fd18d308 58
59 TAINT_NOT;
a0d0e21e 60 return 0;
35ff7856 61#else
62 return runops_standard();
17c3b450 63#endif /* DEBUGGING */
79072805 64}
65
79072805 66I32
864dbfa3 67Perl_debop(pTHX_ OP *o)
79072805 68{
35ff7856 69#ifdef DEBUGGING
79072805 70 SV *sv;
2d8e6c8d 71 STRLEN n_a;
cea2e8a9 72 Perl_deb(aTHX_ "%s", PL_op_name[o->op_type]);
11343788 73 switch (o->op_type) {
79072805 74 case OP_CONST:
5dc0d613 75 PerlIO_printf(Perl_debug_log, "(%s)", SvPEEK(cSVOPo->op_sv));
79072805 76 break;
77 case OP_GVSV:
78 case OP_GV:
11343788 79 if (cGVOPo->op_gv) {
79072805 80 sv = NEWSV(0,0);
5dc0d613 81 gv_fullname3(sv, cGVOPo->op_gv, Nullch);
2d8e6c8d 82 PerlIO_printf(Perl_debug_log, "(%s)", SvPV(sv, n_a));
8990e307 83 SvREFCNT_dec(sv);
79072805 84 }
85 else
760ac839 86 PerlIO_printf(Perl_debug_log, "(NULL)");
79072805 87 break;
a0d0e21e 88 default:
89 break;
79072805 90 }
760ac839 91 PerlIO_printf(Perl_debug_log, "\n");
17c3b450 92#endif /* DEBUGGING */
79072805 93 return 0;
94}
95
96void
864dbfa3 97Perl_watch(pTHX_ char **addr)
79072805 98{
35ff7856 99#ifdef DEBUGGING
22c35a8c 100 dTHR;
101 PL_watchaddr = addr;
102 PL_watchok = *addr;
760ac839 103 PerlIO_printf(Perl_debug_log, "WATCHING, %lx is currently %lx\n",
22c35a8c 104 (long)PL_watchaddr, (long)PL_watchok);
17c3b450 105#endif /* DEBUGGING */
79072805 106}
a0d0e21e 107
76e3520e 108STATIC void
cea2e8a9 109S_debprof(pTHX_ OP *o)
a0d0e21e 110{
35ff7856 111#ifdef DEBUGGING
3280af22 112 if (!PL_profiledata)
113 Newz(000, PL_profiledata, MAXO, U32);
114 ++PL_profiledata[o->op_type];
35ff7856 115#endif /* DEBUGGING */
a0d0e21e 116}
117
118void
864dbfa3 119Perl_debprofdump(pTHX)
a0d0e21e 120{
35ff7856 121#ifdef DEBUGGING
9607fc9c 122 unsigned i;
3280af22 123 if (!PL_profiledata)
a0d0e21e 124 return;
125 for (i = 0; i < MAXO; i++) {
3280af22 126 if (PL_profiledata[i])
9607fc9c 127 PerlIO_printf(Perl_debug_log,
3280af22 128 "%5lu %s\n", (unsigned long)PL_profiledata[i],
22c35a8c 129 PL_op_name[i]);
a0d0e21e 130 }
17c3b450 131#endif /* DEBUGGING */
35ff7856 132}