2001-07-15
2001-07-15 23:14:37 by Fredrik Hübinette (Hubbe) <hubbe@hubbe.net>
-
708088d36eb56e62569f9c3ace6f37ae8cd0e7e0
(280 lines)
(+161/-119)
[
Show
| Annotate
]
Branch: 7.9
got rid of all CASE and inter-opcode gotos in interpret_functions.h
Rev: src/interpret_functions.h:1.75
Rev: src/lex.c:1.97
Rev: src/opcodes.h:1.21
1:
/*
- * $Id: interpret_functions.h,v 1.74 2001/07/10 16:52:03 grubba Exp $
+ * $Id: interpret_functions.h,v 1.75 2001/07/15 23:14:36 hubbe Exp $
*
* Opcode definitions for the interpreter.
*/
43:
#define OPCODE2_TAILJUMP(A, B, C) OPCODE2_TAILJUMP(A, B) C
#endif /* GEN_PROTOS */
+
+ #ifndef PROG_COUNTER
+ #define PROG_COUNTER pc
+ #endif
+
+ #ifndef INTER_ESCAPE_CATCH
+ #define INTER_ESCAPE_CATCH return -2
+ #endif
+
+ #ifndef INTER_RETURN
+ #define INTER_RETURN return -1
+ #endif
+
+
+ /* WARNING:
+ * The surgeon general has stated that define code blocks
+ * without do{}while() can be hazardous to your health.
+ * However, in this case it is required to handle break
+ * properly. -Hubbe
+ */
+ #undef DO_DUMB_RETURN
+ #define DO_DUMB_RETURN { \
+ if(Pike_fp -> flags & PIKE_FRAME_RETURN_INTERNAL) \
+ { \
+ int f=Pike_fp->flags; \
+ low_return(); \
+ PROG_COUNTER=Pike_fp->pc; \
+ FETCH; \
+ if(f & PIKE_FRAME_RETURN_POP) \
+ pop_stack(); \
+ DONE; \
+ } \
+ INTER_RETURN; \
+ }
+
+ #undef DO_RETURN
+ #ifndef PIKE_DEBUG
+ #define DO_RETURN DO_DUMB_RETURN
+ #else
+ #define DO_RETURN { \
+ if(d_flag>3) do_gc(); \
+ if(d_flag>4) do_debug(); \
+ check_threads_etc(); \
+ DO_DUMB_RETURN; \
+ }
+ #endif
+
+ #undef DO_INDEX
+ #define DO_INDEX do { \
+ struct svalue s; \
+ index_no_free(&s,Pike_sp-2,Pike_sp-1); \
+ pop_n_elems(2); \
+ *Pike_sp=s; \
+ Pike_sp++; \
+ print_return_value(); \
+ }while(0)
+
+
OPCODE0(F_UNDEFINED, "push UNDEFINED", {
push_int(0);
Pike_sp[-1].subtype=NUMBER_UNDEFINED;
130:
});
OPCODE0(F_FLOAT, "push float", {
- /* FIXME, this opcode uses 'pc' which is not allowed.. */
+ /* FIXME, this opcode uses 'PROG_COUNTER' which is not allowed.. */
Pike_sp->type=PIKE_T_FLOAT;
- MEMCPY((void *)&Pike_sp->u.float_number, pc, sizeof(FLOAT_TYPE));
- pc += DO_IF_ELSE_COMPUTED_GOTO(1, sizeof(FLOAT_TYPE));
+ MEMCPY((void *)&Pike_sp->u.float_number, PROG_COUNTER, sizeof(FLOAT_TYPE));
+ PROG_COUNTER += DO_IF_ELSE_COMPUTED_GOTO(1, sizeof(FLOAT_TYPE));
FETCH;
Pike_sp++;
});
996:
});
OPCODE0_JUMP(F_CATCH, "catch", {
- switch (o_catch(pc+DO_IF_ELSE_COMPUTED_GOTO(1, sizeof(INT32))))
+ switch (o_catch(PROG_COUNTER+DO_IF_ELSE_COMPUTED_GOTO(1, sizeof(INT32))))
{
case 1:
/* There was a return inside the evaluated code */
- goto do_dumb_return;
+ DO_DUMB_RETURN;
case 2:
- pc = Pike_fp->pc;
+ PROG_COUNTER = Pike_fp->pc;
break;
default:
- pc += GET_JUMP();
+ PROG_COUNTER += GET_JUMP();
}
FETCH;
});
OPCODE0(F_ESCAPE_CATCH, "escape catch", {
- Pike_fp->pc = pc;
- return -2;
+ Pike_fp->pc = PROG_COUNTER;
+ INTER_ESCAPE_CATCH;
});
OPCODE0(F_THROW_ZERO, "throw(0)", {
1024:
INT32 tmp;
tmp=switch_lookup(Pike_fp->context.prog->
constants[arg1].sval.u.array,Pike_sp-1);
- pc = DO_IF_ELSE_COMPUTED_GOTO(pc, (PIKE_OPCODE_T *)
- DO_ALIGN(pc,((ptrdiff_t)sizeof(INT32))));
- pc += (tmp>=0 ? 1+tmp*2 : 2*~tmp) *
+ PROG_COUNTER = DO_IF_ELSE_COMPUTED_GOTO(PROG_COUNTER, (PIKE_OPCODE_T *)
+ DO_ALIGN(PROG_COUNTER,((ptrdiff_t)sizeof(INT32))));
+ PROG_COUNTER += (tmp>=0 ? 1+tmp*2 : 2*~tmp) *
DO_IF_ELSE_COMPUTED_GOTO(1, sizeof(INT32));
- if(*(INT32*)pc < 0) fast_check_threads_etc(7);
- pc += *(INT32*)pc;
+ if(*(INT32*)PROG_COUNTER < 0) fast_check_threads_etc(7);
+ PROG_COUNTER += *(INT32*)PROG_COUNTER;
FETCH;
pop_stack();
});
1043:
tmp=switch_lookup(Pike_fp->context.prog->
constants[arg1].sval.u.array,Pike_sp-1);
pop_n_elems(3);
- pc = DO_IF_ELSE_COMPUTED_GOTO(pc, (PIKE_OPCODE_T *)
- DO_ALIGN(pc,((ptrdiff_t)sizeof(INT32))));
- pc += (tmp>=0 ? 1+tmp*2 : 2*~tmp) *
+ PROG_COUNTER = DO_IF_ELSE_COMPUTED_GOTO(PROG_COUNTER, (PIKE_OPCODE_T *)
+ DO_ALIGN(PROG_COUNTER,((ptrdiff_t)sizeof(INT32))));
+ PROG_COUNTER += (tmp>=0 ? 1+tmp*2 : 2*~tmp) *
DO_IF_ELSE_COMPUTED_GOTO(1, sizeof(INT32));
- if(*(INT32*)pc < 0) fast_check_threads_etc(7);
- pc+=*(INT32*)pc;
+ if(*(INT32*)PROG_COUNTER < 0) fast_check_threads_etc(7);
+ PROG_COUNTER+=*(INT32*)PROG_COUNTER;
FETCH;
});
1056:
INT32 tmp;
tmp=switch_lookup(Pike_fp->context.prog->
constants[arg2].sval.u.array,Pike_fp->locals + arg1);
- pc = DO_IF_ELSE_COMPUTED_GOTO(pc, (PIKE_OPCODE_T *)
- DO_ALIGN(pc,((ptrdiff_t)sizeof(INT32))));
- pc += (tmp>=0 ? 1+tmp*2 : 2*~tmp) *
+ PROG_COUNTER = DO_IF_ELSE_COMPUTED_GOTO(PROG_COUNTER, (PIKE_OPCODE_T *)
+ DO_ALIGN(PROG_COUNTER,((ptrdiff_t)sizeof(INT32))));
+ PROG_COUNTER += (tmp>=0 ? 1+tmp*2 : 2*~tmp) *
DO_IF_ELSE_COMPUTED_GOTO(1, sizeof(INT32));
- if(*(INT32*)pc < 0) fast_check_threads_etc(7);
- pc+=*(INT32*)pc;
+ if(*(INT32*)PROG_COUNTER < 0) fast_check_threads_etc(7);
+ PROG_COUNTER+=*(INT32*)PROG_COUNTER;
FETCH;
});
1163:
});
- CASE(F_RETURN_LOCAL);
- {
- INT32 val = GET_ARG();
- #if defined(PIKE_DEBUG) && defined(GC2)
+ OPCODE1(F_RETURN_LOCAL,"return local",{
+ DO_IF_DEBUG(
/* special case! Pike_interpreter.mark_stack may be invalid at the time we
* call return -1, so we must call the callbacks here to
* prevent false alarms! /Hubbe
1174: Inside #if defined(PIKE_DEBUG) && defined(GC2)
if(d_flag>3) do_gc();
if(d_flag>4) do_debug();
check_threads_etc();
- #endif
- if(Pike_fp->expendible <= Pike_fp->locals + val)
+ );
+ if(Pike_fp->expendible <= Pike_fp->locals + arg1)
{
- pop_n_elems(Pike_sp-1 - (Pike_fp->locals + val));
+ pop_n_elems(Pike_sp-1 - (Pike_fp->locals + arg1));
}else{
- push_svalue(Pike_fp->locals + val);
+ push_svalue(Pike_fp->locals + arg1);
}
print_return_value();
- goto do_dumb_return;
- }
+ DO_DUMB_RETURN;
+ });
- CASE(F_RETURN_IF_TRUE);
- if(!IS_ZERO(Pike_sp-1)) goto do_return;
+
+ OPCODE0(F_RETURN_IF_TRUE,"return if true",{
+ if(!IS_ZERO(Pike_sp-1)) DO_RETURN;
pop_stack();
- DONE;
+ });
- CASE(F_RETURN_1);
+ OPCODE0(F_RETURN_1,"return 1",{
push_int(1);
- goto do_return;
+ DO_RETURN;
+ });
- CASE(F_RETURN_0);
+
+ OPCODE0(F_RETURN_0,"return 0",{
push_int(0);
- goto do_return;
+ DO_RETURN;
+ });
- CASE(F_RETURN);
- do_return:
- #if defined(PIKE_DEBUG) && defined(GC2)
- if(d_flag>3) do_gc();
- if(d_flag>4) do_debug();
- check_threads_etc();
- #endif
+
- /* fall through */
+ OPCODE0(F_RETURN, "return", {
+ DO_RETURN;
+ });
- CASE(F_DUMB_RETURN);
- do_dumb_return:
- if(Pike_fp -> flags & PIKE_FRAME_RETURN_INTERNAL)
- {
- int f=Pike_fp->flags;
- low_return();
- pc=Pike_fp->pc;
- FETCH;
- if(f & PIKE_FRAME_RETURN_POP)
- pop_stack();
- DONE;
- }
- return -1;
+ OPCODE0(F_DUMB_RETURN,"dumb return", {
+ DO_DUMB_RETURN;
+ });
OPCODE0(F_NEGATE, "unary minus", {
if(Pike_sp[-1].type == PIKE_T_INT)
1469:
print_return_value();
});
- CASE(F_POS_INT_INDEX);
- push_int(GET_ARG());
- FETCH;
+ OPCODE1(F_POS_INT_INDEX, "int index", {
+ push_int(arg1);
print_return_value();
- goto do_index;
+ DO_INDEX;
+ });
- CASE(F_NEG_INT_INDEX);
- push_int(-(ptrdiff_t)GET_ARG());
+ OPCODE1(F_NEG_INT_INDEX, "-int index", {
+ push_int(-(ptrdiff_t)arg1);
print_return_value();
-
+ DO_INDEX;
+ });
- CASE(F_INDEX);
- do_index:
- {
- struct svalue s;
- index_no_free(&s,Pike_sp-2,Pike_sp-1);
- pop_n_elems(2);
- *Pike_sp=s;
- Pike_sp++;
- }
- print_return_value();
- DONE;
+ OPCODE0(F_INDEX, "index", {
+ DO_INDEX;
+ });
OPCODE2(F_MAGIC_INDEX, "::`[]", {
push_magic_index(magic_index_program, arg2, arg1);
1624:
if(low_mega_apply(TYPE,DO_NOT_WARN((INT32)(Pike_sp - *--Pike_mark_sp)), \
ARG2, ARG3)) \
{ \
- Pike_fp->next->pc=pc; \
- pc=Pike_fp->pc; \
+ Pike_fp->next->pc=PROG_COUNTER; \
+ PROG_COUNTER=Pike_fp->pc; \
FETCH; \
Pike_fp->flags |= PIKE_FRAME_RETURN_INTERNAL; \
} \
1635:
if(low_mega_apply(TYPE, DO_NOT_WARN((INT32)(Pike_sp - *--Pike_mark_sp)), \
ARG2, ARG3)) \
{ \
- Pike_fp->next->pc=pc; \
- pc=Pike_fp->pc; \
+ Pike_fp->next->pc=PROG_COUNTER; \
+ PROG_COUNTER=Pike_fp->pc; \
FETCH; \
Pike_fp->flags |= PIKE_FRAME_RETURN_INTERNAL | PIKE_FRAME_RETURN_POP; \
}else{ \
1649:
ARG2,ARG3)) \
{ \
DO_IF_DEBUG(Pike_fp->next->pc=0); \
- pc=Pike_fp->pc; \
+ PROG_COUNTER=Pike_fp->pc; \
FETCH; \
unlink_previous_frame(); \
}else{ \
- goto do_dumb_return; \
+ DO_DUMB_RETURN; \
} \
}); \
\
1661:
if(low_mega_apply(TYPE,0, \
ARG2, ARG3)) \
{ \
- Pike_fp->next->pc=pc; \
- pc=Pike_fp->pc; \
+ Pike_fp->next->pc=PROG_COUNTER; \
+ PROG_COUNTER=Pike_fp->pc; \
FETCH; \
Pike_fp->flags |= PIKE_FRAME_RETURN_INTERNAL; \
} \
1672:
if(low_mega_apply(TYPE, 0, \
ARG2, ARG3)) \
{ \
- Pike_fp->next->pc=pc; \
- pc=Pike_fp->pc; \
+ Pike_fp->next->pc=PROG_COUNTER; \
+ PROG_COUNTER=Pike_fp->pc; \
FETCH; \
Pike_fp->flags |= PIKE_FRAME_RETURN_INTERNAL | PIKE_FRAME_RETURN_POP; \
}else{ \
1686:
ARG2,ARG3)) \
{ \
DO_IF_DEBUG(Pike_fp->next->pc=0); \
- pc=Pike_fp->pc; \
+ PROG_COUNTER=Pike_fp->pc; \
FETCH; \
unlink_previous_frame(); \
}else{ \
- goto do_dumb_return; \
+ DO_DUMB_RETURN; \
} \
})
1754:
OPCODE1(F_CALL_BUILTIN_AND_RETURN,"call builtin & return", {
DO_CALL_BUILTIN(DO_NOT_WARN((INT32)(Pike_sp - *--Pike_mark_sp)));
- goto do_dumb_return;
+ DO_DUMB_RETURN;
});
1769:
OPCODE1(F_MARK_CALL_BUILTIN_AND_RETURN, "mark, call builtin & return", {
DO_CALL_BUILTIN(0);
- goto do_dumb_return;
+ DO_DUMB_RETURN;
});
1791:
*/
if(Pike_fp->current_object->prog != Pike_fp->context.prog)
{
- pc += DO_IF_ELSE_COMPUTED_GOTO(1, sizeof(INT32));
+ PROG_COUNTER += DO_IF_ELSE_COMPUTED_GOTO(1, sizeof(INT32));
if(low_mega_apply(APPLY_LOW,
DO_NOT_WARN((INT32)(Pike_sp - *--Pike_mark_sp)),
Pike_fp->current_object,
(void *)(arg1+Pike_fp->context.identifier_level)))
{
- Pike_fp->next->pc=pc;
- pc=Pike_fp->pc;
+ Pike_fp->next->pc=PROG_COUNTER;
+ PROG_COUNTER=Pike_fp->pc;
FETCH;
Pike_fp->flags |= PIKE_FRAME_RETURN_INTERNAL;
} else {
1836:
new_frame->save_mark_sp = Pike_mark_sp;
new_frame->mark_sp_base = Pike_mark_sp;
- addr = pc+GET_JUMP();
+ addr = PROG_COUNTER+GET_JUMP();
new_frame->num_locals =
DO_IF_ELSE_COMPUTED_GOTO((ptrdiff_t)addr[-2],
EXTRACT_UCHAR(addr-2));
1855:
new_frame->num_locals - new_frame->num_args);
});
- Pike_fp->pc = pc + DO_IF_ELSE_COMPUTED_GOTO(1, sizeof(INT32));
- pc=addr;
+ Pike_fp->pc = PROG_COUNTER + DO_IF_ELSE_COMPUTED_GOTO(1, sizeof(INT32));
+ PROG_COUNTER=addr;
FETCH;
clear_svalues(Pike_sp, new_frame->num_locals - new_frame->num_args);
1887:
fast_check_threads_etc(6);
- addr=pc+GET_JUMP();
+ addr=PROG_COUNTER+GET_JUMP();
num_locals=EXTRACT_UCHAR(addr-2);
1909:
}
clear_svalues(Pike_sp, num_locals - args);
- pc=addr;
+ PROG_COUNTER=addr;
FETCH;
Pike_sp += num_locals - args;
1921:
OPCODE0(F_BREAKPOINT, "breakpoint", {
extern void o_breakpoint(void);
- pc--;
+ PROG_COUNTER--;
FETCH;
o_breakpoint();
});
1945:
Pike_sp[-1].subtype=NUMBER_NUMBER;
}
});
+
+ #undef PROG_COUNTER