Commit | Line | Data |
a0d0e21e |
1 | /* run.c |
2 | * |
3 | * Copyright (c) 1991-1994, 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 | |
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 | |
4633a7c4 |
19 | dEXT char **watchaddr = 0; |
20 | dEXT char *watchok; |
79072805 |
21 | |
22 | #ifndef DEBUGGING |
23 | |
a0d0e21e |
24 | int |
8da795c6 |
25 | runops() { |
11343788 |
26 | dTHR; |
a0d0e21e |
27 | SAVEI32(runlevel); |
28 | runlevel++; |
29 | |
11343788 |
30 | while ( op = (*op->op_ppaddr)(ARGS) ) ; |
a0d0e21e |
31 | return 0; |
79072805 |
32 | } |
33 | |
34 | #else |
35 | |
11343788 |
36 | static void debprof _((OP*o)); |
a0d0e21e |
37 | |
38 | int |
8da795c6 |
39 | runops() { |
11343788 |
40 | dTHR; |
79072805 |
41 | if (!op) { |
42 | warn("NULL OP IN RUN"); |
a0d0e21e |
43 | return 0; |
79072805 |
44 | } |
a0d0e21e |
45 | |
46 | SAVEI32(runlevel); |
47 | runlevel++; |
48 | |
79072805 |
49 | do { |
50 | if (debug) { |
51 | if (watchaddr != 0 && *watchaddr != watchok) |
52 | fprintf(stderr, "WARNING: %lx changed from %lx to %lx\n", |
a0d0e21e |
53 | (long)watchaddr, (long)watchok, (long)*watchaddr); |
79072805 |
54 | DEBUG_s(debstack()); |
55 | DEBUG_t(debop(op)); |
a0d0e21e |
56 | DEBUG_P(debprof(op)); |
11343788 |
57 | #ifdef USE_THREADS |
58 | DEBUG_L(pthread_yield()); /* shake up scheduling a bit */ |
59 | #endif /* USE_THREADS */ |
79072805 |
60 | } |
11343788 |
61 | } while ( op = (*op->op_ppaddr)(ARGS) ); |
a0d0e21e |
62 | return 0; |
79072805 |
63 | } |
64 | |
79072805 |
65 | I32 |
11343788 |
66 | debop(o) |
67 | OP *o; |
79072805 |
68 | { |
69 | SV *sv; |
11343788 |
70 | deb("%s", op_name[o->op_type]); |
71 | switch (o->op_type) { |
79072805 |
72 | case OP_CONST: |
11343788 |
73 | fprintf(stderr, "(%s)", SvPEEK(cSVOPo->op_sv)); |
79072805 |
74 | break; |
75 | case OP_GVSV: |
76 | case OP_GV: |
11343788 |
77 | if (cGVOPo->op_gv) { |
79072805 |
78 | sv = NEWSV(0,0); |
11343788 |
79 | gv_fullname(sv, cGVOPo->op_gv); |
463ee0b2 |
80 | fprintf(stderr, "(%s)", SvPV(sv, na)); |
8990e307 |
81 | SvREFCNT_dec(sv); |
79072805 |
82 | } |
83 | else |
84 | fprintf(stderr, "(NULL)"); |
85 | break; |
a0d0e21e |
86 | default: |
87 | break; |
79072805 |
88 | } |
89 | fprintf(stderr, "\n"); |
90 | return 0; |
91 | } |
92 | |
93 | void |
94 | watch(addr) |
95 | char **addr; |
96 | { |
97 | watchaddr = addr; |
98 | watchok = *addr; |
99 | fprintf(stderr, "WATCHING, %lx is currently %lx\n", |
a0d0e21e |
100 | (long)watchaddr, (long)watchok); |
79072805 |
101 | } |
a0d0e21e |
102 | |
103 | static void |
11343788 |
104 | debprof(o) |
105 | OP* o; |
a0d0e21e |
106 | { |
107 | if (!profiledata) |
108 | New(000, profiledata, MAXO, U32); |
11343788 |
109 | ++profiledata[o->op_type]; |
a0d0e21e |
110 | } |
111 | |
112 | void |
113 | debprofdump() |
114 | { |
115 | U32 i; |
116 | if (!profiledata) |
117 | return; |
118 | for (i = 0; i < MAXO; i++) { |
119 | if (profiledata[i]) |
120 | fprintf(stderr, "%d\t%lu\n", i, profiledata[i]); |
121 | } |
122 | } |
123 | |
124 | #endif |
125 | |