1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
45
  
46
  
47
  
48
  
49
  
50
  
51
  
52
  
53
  
54
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
69
  
70
  
71
  
72
  
73
  
74
  
75
  
76
  
77
  
78
  
79
  
80
  
81
  
82
  
83
  
84
  
85
  
86
  
87
  
88
  
89
  
90
  
91
  
92
  
93
  
94
  
95
  
96
  
97
  
98
  
99
  
100
  
101
  
102
  
103
  
104
  
105
  
106
  
107
  
108
  
109
  
110
  
111
  
112
  
113
  
114
  
115
  
116
  
117
  
118
  
119
  
120
  
121
  
122
  
123
  
124
  
125
  
126
  
127
  
128
  
129
  
130
  
131
  
132
  
133
  
134
  
135
  
136
  
137
  
138
  
139
  
140
  
141
  
142
  
143
  
144
  
145
  
146
  
147
  
148
  
149
  
150
  
151
  
152
  
153
  
154
  
155
  
156
  
157
  
158
  
159
  
160
  
161
  
162
  
163
  
164
  
165
  
166
  
167
  
168
  
169
  
170
  
171
  
172
  
173
  
174
  
175
  
176
  
177
  
178
  
179
  
180
  
181
  
182
  
183
  
184
  
185
  
186
  
187
  
188
  
189
  
190
  
191
  
192
  
193
  
194
  
195
  
196
  
197
  
198
  
199
  
200
  
201
  
202
  
203
  
204
  
205
  
206
  
207
  
208
  
209
  
210
  
211
  
212
  
213
  
214
  
215
  
216
  
217
  
218
  
219
  
220
  
221
  
222
  
223
  
224
  
225
  
226
  
227
  
228
  
229
  
230
  
231
  
232
  
233
  
234
  
235
  
236
  
237
  
238
  
239
  
240
  
241
  
242
  
243
  
244
  
245
  
246
  
247
  
248
  
249
  
250
  
251
  
252
  
253
  
254
  
255
  
256
  
257
  
258
  
259
  
260
  
261
  
262
  
263
  
264
  
265
  
266
  
267
  
268
  
269
  
270
  
271
  
272
  
273
  
274
  
275
  
276
  
277
  
278
  
279
  
280
  
281
  
282
  
283
  
284
  
285
  
 
#undef GET_ARG 
#undef GET_ARG2 
#undef GET_JUMP 
#undef SKIPJUMP 
#undef DOJUMP 
#undef CASE 
#undef BREAK 
#undef DONE 
 
#ifdef HAVE_COMPUTED_GOTO 
 
#define CASE(OP)      PIKE_CONCAT(LABEL_,OP): 
#ifdef PIKE_DEBUG 
#define DONE                continue 
#else /* !PIKE_DEBUG */ 
#define DONE                goto **(pc++) 
#endif /* PIKE_DEBUG */ 
#define GET_ARG()   ((INT32)*(pc++)) 
#define GET_ARG2()  ((INT32)*(pc++)) 
#define GET_JUMP()  ((INT32)*(pc++)) 
#define SKIPJUMP()  (pc++) 
#else /* !HAVE_COMPUTED_GOTO */ 
 
#define CASE(X) case (X)-F_OFFSET: 
#define DONE break 
 
#ifdef PIKE_DEBUG 
 
#define GET_ARG() (backlog[backlogp].arg=(\ 
  instr=prefix,\ 
  prefix=0,\ 
  instr += (pc++)[0],\ 
  (t_flag>3 ? sprintf(trace_buffer,"-    Arg = %ld\n",(long)instr),write_to_stderr(trace_buffer,strlen(trace_buffer)) : 0),\ 
  instr)) 
 
#define GET_ARG2() (backlog[backlogp].arg2=(\ 
  instr=prefix2,\ 
  prefix2=0,\ 
  instr += (pc++)[0],\ 
  (t_flag>3 ? sprintf(trace_buffer,"-    Arg2 = %ld\n",(long)instr),write_to_stderr(trace_buffer,strlen(trace_buffer)) : 0),\ 
  instr)) 
 
#define GET_JUMP() (backlog[backlogp].arg=(\ 
  (t_flag>3 ? sprintf(trace_buffer,"-    Target = %+ld\n",(long)EXTRACT_INT(pc)),write_to_stderr(trace_buffer,strlen(trace_buffer)) : 0),\ 
  EXTRACT_INT(pc))) 
 
#define SKIPJUMP() (GET_JUMP(), pc+=sizeof(INT32)) 
 
#else 
 
#define GET_ARG() (instr=prefix,prefix=0,instr+(pc++)[0]) 
#define GET_ARG2() (instr=prefix2,prefix2=0,instr+(pc++)[0]) 
#define GET_JUMP() EXTRACT_INT(pc) 
#define SKIPJUMP() pc+=sizeof(INT32) 
 
#endif 
 
#endif /* HAVE_COMPUTED_GOTO */ 
 
#define DOJUMP() do { \ 
    INT32 tmp; \ 
    tmp = GET_JUMP(); \ 
    pc += tmp; \ 
    if(tmp < 0) \ 
      fast_check_threads_etc(6); \ 
  } while(0) 
 
#ifndef STEP_BREAK_LINE 
#define STEP_BREAK_LINE 
#endif 
 
static int eval_instruction(PIKE_OPCODE_T *pc) 
{ 
  unsigned INT32 prefix2=0,prefix=0; 
#ifdef HAVE_COMPUTED_GOTO 
  void *instr; 
#else /* !HAVE_COMPUTED_GOTO */ 
  unsigned INT32 instr; 
#endif /* HAVE_COMPUTED_GOTO */ 
 
  debug_malloc_touch(Pike_fp); 
  while(1) 
  { 
    Pike_fp->pc = pc; 
    instr = (pc++)[0]; 
 
    STEP_BREAK_LINE 
     
#ifdef PIKE_DEBUG 
 
    if(t_flag > 2) 
    { 
      char *file, *f; 
      INT32 linep; 
 
      file = get_line(pc-1,Pike_fp->context.prog,&linep); 
      while((f=STRCHR(file,'/'))) file=f+1; 
      fprintf(stderr,"- %s:%4ld:(%lx): %-25s %4ld %4ld\n", 
              file,(long)linep, 
              DO_NOT_WARN((long)(pc-Pike_fp->context.prog->program-1)), 
#ifdef HAVE_COMPUTED_GOTO 
            get_f_name(instr), 
#else /* !HAVE_COMPUTED_GOTO */ 
            get_f_name(instr + F_OFFSET), 
#endif /* HAVE_COMPUTED_GOTO */ 
            DO_NOT_WARN((long)(Pike_sp-Pike_interpreter.evaluator_stack)), 
              DO_NOT_WARN((long)(Pike_mark_sp-Pike_interpreter.mark_stack))); 
    } 
 
    if(instr + F_OFFSET < F_MAX_OPCODE)  
      ADD_RUNNED(instr + F_OFFSET); 
 
    if(d_flag) 
    { 
      backlogp++; 
      if(backlogp >= BACKLOG) backlogp=0; 
 
      if(backlog[backlogp].program) 
        free_program(backlog[backlogp].program); 
 
      backlog[backlogp].program=Pike_fp->context.prog; 
      add_ref(Pike_fp->context.prog); 
      backlog[backlogp].instruction=instr; 
      backlog[backlogp].pc=pc; 
      backlog[backlogp].stack = Pike_sp - Pike_interpreter.evaluator_stack; 
      backlog[backlogp].mark_stack = Pike_mark_sp - Pike_interpreter.mark_stack; 
#ifdef _REENTRANT 
      backlog[backlogp].thread_id=Pike_interpreter.thread_id; 
#endif 
 
#ifdef _REENTRANT 
      CHECK_INTERPRETER_LOCK(); 
      if(OBJ2THREAD(Pike_interpreter.thread_id)->state.thread_id != 
         Pike_interpreter.thread_id) 
        fatal("Arglebargle glop glyf, thread swap problem!\n"); 
 
      if(d_flag>1 && thread_for_id(th_self()) != Pike_interpreter.thread_id) 
        fatal("thread_for_id() (or Pike_interpreter.thread_id) failed in interpreter.h! %p != %p\n",thread_for_id(th_self()),Pike_interpreter.thread_id); 
#endif 
 
      Pike_sp[0].type=99; /* an invalid type */ 
      Pike_sp[1].type=99; 
      Pike_sp[2].type=99; 
      Pike_sp[3].type=99; 
       
      if(Pike_sp<Pike_interpreter.evaluator_stack || 
         Pike_mark_sp < Pike_interpreter.mark_stack || Pike_fp->locals>Pike_sp) 
        fatal("Stack error (generic) sp=%p/%p mark_sp=%p/%p locals=%p.\n", 
              Pike_sp, 
              Pike_interpreter.evaluator_stack, 
              Pike_mark_sp, 
              Pike_interpreter.mark_stack, 
              Pike_fp->locals); 
       
      if(Pike_mark_sp > Pike_interpreter.mark_stack+Pike_stack_size) 
        fatal("Mark Stack error (overflow).\n"); 
 
 
      if(Pike_mark_sp < Pike_interpreter.mark_stack) 
        fatal("Mark Stack error (underflow).\n"); 
 
      if(Pike_sp > Pike_interpreter.evaluator_stack+Pike_stack_size) 
        fatal("stack error (overflow).\n"); 
       
      if(/* Pike_fp->fun>=0 && */ Pike_fp->current_object->prog && 
         Pike_fp->locals+Pike_fp->num_locals > Pike_sp) 
        fatal("Stack error (stupid!).\n"); 
 
      if(Pike_interpreter.recoveries && 
         (Pike_sp-Pike_interpreter.evaluator_stack < 
          Pike_interpreter.recoveries->stack_pointer)) 
        fatal("Stack error (underflow).\n"); 
 
      if(Pike_mark_sp > Pike_interpreter.mark_stack && 
         Pike_mark_sp[-1] > Pike_sp) 
        fatal("Stack error (underflow?)\n"); 
       
      if(d_flag > 9) do_debug(); 
 
      debug_malloc_touch(Pike_fp->current_object); 
      switch(d_flag) 
      { 
        default: 
        case 3: 
          check_object(Pike_fp->current_object); 
/*      break; */ 
 
        case 2: 
          check_object_context(Pike_fp->current_object, 
                               Pike_fp->context.prog, 
                               CURRENT_STORAGE); 
        case 1: 
        case 0: 
          break; 
      } 
    } 
#endif 
 
#ifdef HAVE_COMPUTED_GOTO 
    goto *instr; 
#else /* !HAVE_COMPUTED_GOTO */ 
    switch(instr) 
    { 
#endif /* HAVE_COMPUTED_GOTO */ 
      /* Support to allow large arguments */ 
      CASE(F_PREFIX_256); prefix+=256; DONE; 
      CASE(F_PREFIX_512); prefix+=512; DONE; 
      CASE(F_PREFIX_768); prefix+=768; DONE; 
      CASE(F_PREFIX_1024); prefix+=1024; DONE; 
      CASE(F_PREFIX_24BITX256); 
        prefix += (pc++)[0]<<24; 
      CASE(F_PREFIX_WORDX256); 
        prefix += (pc++)[0]<<16; 
      CASE(F_PREFIX_CHARX256); 
        prefix += (pc++)[0]<<8; 
      DONE; 
 
      /* Support to allow large arguments */ 
      CASE(F_PREFIX2_256); prefix2+=256; DONE; 
      CASE(F_PREFIX2_512); prefix2+=512; DONE; 
      CASE(F_PREFIX2_768); prefix2+=768; DONE; 
      CASE(F_PREFIX2_1024); prefix2+=1024; DONE; 
      CASE(F_PREFIX2_24BITX256); 
        prefix2 += (pc++)[0]<<24; 
      CASE(F_PREFIX2_WORDX256); 
        prefix2 += (pc++)[0]<<16; 
      CASE(F_PREFIX2_CHARX256); 
        prefix2 += (pc++)[0]<<8; 
      DONE; 
 
 
#define INTERPRETER 
 
#define OPCODE0(OP, DESC, CODE) CASE(OP); CODE; DONE 
#define OPCODE1(OP, DESC, CODE) CASE(OP); { \ 
    INT32 arg1=GET_ARG(); \ 
    CODE; \ 
  } DONE 
 
#define OPCODE2(OP, DESC, CODE) CASE(OP); { \ 
    INT32 arg1=GET_ARG(); \ 
    INT32 arg2=GET_ARG2(); \ 
    CODE; \ 
  } DONE 
 
#define OPCODE0_TAIL(OP, DESC, CODE) CASE(OP); CODE 
#define OPCODE1_TAIL(OP, DESC, CODE) CASE(OP); CODE 
#define OPCODE2_TAIL(OP, DESC, CODE) CASE(OP); CODE 
 
#define OPCODE0_JUMP(OP, DESC, CODE) CASE(OP); CODE; DONE 
#define OPCODE0_TAILJUMP(OP, DESC, CODE) CASE(OP); CODE 
 
/* These are something of a special case as they 
 * requires a POINTER stored explicitly after 
 * the instruction itself. 
 */ 
#define OPCODE1_JUMP(OP, DESC, CODE) CASE(OP); { \ 
    INT32 arg1=GET_ARG(); \ 
    CODE; \ 
  } DONE 
 
#define OPCODE2_JUMP(OP, DESC, CODE) CASE(OP); { \ 
    INT32 arg1=GET_ARG(); \ 
    INT32 arg2=GET_ARG2(); \ 
    CODE; \ 
  } DONE 
 
#define OPCODE1_TAILJUMP(OP, DESC, CODE) CASE(OP); CODE 
#define OPCODE2_TAILJUMP(OP, DESC, CODE) CASE(OP); CODE 
 
#define BREAK         DONE; } 
 
#include "interpret_functions.h" 
 
#ifndef HAVE_COMPUTED_GOTO       
    default: 
      fatal("Strange instruction %ld\n",(long)instr); 
    } 
#endif /* !HAVE_COMPUTED_GOTO */ 
  } 
}