pike.git / src / interpret_functions.h

version» Context lines:

pike.git/src/interpret_functions.h:1:   /* -  * $Id: interpret_functions.h,v 1.80 2001/07/18 19:07:25 grubba Exp $ +  * $Id: interpret_functions.h,v 1.81 2001/07/26 14:17:13 grubba Exp $    *    * Opcode definitions for the interpreter.    */      #include "global.h"      #undef CJUMP   #undef AUTO_BIGNUM_LOOP_TEST   #undef LOOP   #undef COMPARISON
pike.git/src/interpret_functions.h:87:    if(tmp < 0) \    fast_check_threads_etc(6); \    } while(0)      #endif /* OVERRIDE_JUMPS */         /* 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 +  * However, in these cases it is required to handle break    * properly. -Hubbe    */ -  + #undef DO_JUMP_TO + #define DO_JUMP_TO(NEWPC) { \ +  SET_PROG_COUNTER(NEWPC); \ +  FETCH; \ +  DONE; \ + } +    #undef DO_DUMB_RETURN   #define DO_DUMB_RETURN { \    if(Pike_fp -> flags & PIKE_FRAME_RETURN_INTERNAL) \    { \    int f=Pike_fp->flags; \    low_return(); \    if (t_flag) \    fprintf(stderr, "Returning to 0x%p\n", \    Pike_fp->pc); \ -  SET_PROG_COUNTER(Pike_fp->pc); \ -  FETCH; \ +     if(f & PIKE_FRAME_RETURN_POP) \    pop_stack(); \ -  DONE; \ +  DO_JUMP_TO(Pike_fp->pc); \    } \    if (t_flag) \    fprintf(stderr, "Inter return\n"); \    INTER_RETURN; \   }      #undef DO_RETURN   #ifndef PIKE_DEBUG   #define DO_RETURN DO_DUMB_RETURN   #else
pike.git/src/interpret_functions.h:222:    index_no_free(&tmp, Pike_sp-1, &tmp2);    }    free_svalue(Pike_sp-1);    Pike_sp[-1] = tmp;    print_return_value();   });      OPCODE0(F_FLOAT, "push float", {    /* FIXME, this opcode uses 'PROG_COUNTER' which is not allowed.. */    MEMCPY((void *)&Pike_sp->u.float_number, PROG_COUNTER, sizeof(FLOAT_TYPE)); -  SET_PROG_COUNTER((PIKE_OPCODE_T *)(((FLOAT_TYPE *)PROG_COUNTER) + 1)); -  FETCH; +     Pike_sp->type=PIKE_T_FLOAT;    Pike_sp++; -  +  DO_JUMP_TO((PIKE_OPCODE_T *)(((FLOAT_TYPE *)PROG_COUNTER) + 1));   });      OPCODE1(F_LFUN, "local function", {    Pike_sp->u.object=Pike_fp->current_object;    add_ref(Pike_fp->current_object);    Pike_sp->subtype=arg1+Pike_fp->context.identifier_level;    Pike_sp->type=PIKE_T_FUNCTION;    Pike_sp++;    print_return_value();   });
pike.git/src/interpret_functions.h:1098:    }   });      OPCODE0_JUMP(F_CATCH, "catch", {    switch (o_catch((PIKE_OPCODE_T *)(((INT32 *)PROG_COUNTER)+1)))    {    case 1:    /* There was a return inside the evaluated code */    DO_DUMB_RETURN;    case 2: -  SET_PROG_COUNTER(Pike_fp->pc); +  DO_JUMP_TO(Pike_fp->pc);    break;    default: -  SET_PROG_COUNTER(PROG_COUNTER + GET_JUMP()); +  DO_JUMP_TO(PROG_COUNTER + GET_JUMP());    } -  FETCH; +  /* NOT_REACHED */   });      OPCODE0(F_ESCAPE_CATCH, "escape catch", {    Pike_fp->pc = PROG_COUNTER;    INTER_ESCAPE_CATCH;   });      OPCODE0(F_THROW_ZERO, "throw(0)", {    push_int(0);    f_throw(1);
pike.git/src/interpret_functions.h:1125:      OPCODE1(F_SWITCH, "switch", {    INT32 tmp;    PIKE_OPCODE_T *addr = PROG_COUNTER;    tmp=switch_lookup(Pike_fp->context.prog->    constants[arg1].sval.u.array,Pike_sp-1);    addr = DO_IF_ELSE_COMPUTED_GOTO(addr, (PIKE_OPCODE_T *)    DO_ALIGN(addr,((ptrdiff_t)sizeof(INT32))));    addr = (PIKE_OPCODE_T *)(((INT32 *)addr) + (tmp>=0 ? 1+tmp*2 : 2*~tmp));    if(*(INT32*)addr < 0) fast_check_threads_etc(7); -  SET_PROG_COUNTER(addr + *(INT32*)addr); -  FETCH; +     pop_stack(); -  +  DO_JUMP_TO(addr + *(INT32*)addr);   });      OPCODE1(F_SWITCH_ON_INDEX, "switch on index", {    INT32 tmp;    struct svalue s;    PIKE_OPCODE_T *addr = PROG_COUNTER;    index_no_free(&s,Pike_sp-2,Pike_sp-1);    Pike_sp++[0]=s;       tmp=switch_lookup(Pike_fp->context.prog->    constants[arg1].sval.u.array,Pike_sp-1);    pop_n_elems(3);    addr = DO_IF_ELSE_COMPUTED_GOTO(addr, (PIKE_OPCODE_T *)    DO_ALIGN(addr,((ptrdiff_t)sizeof(INT32))));    addr = (PIKE_OPCODE_T *)(((INT32 *)addr) + (tmp>=0 ? 1+tmp*2 : 2*~tmp));    if(*(INT32*)addr < 0) fast_check_threads_etc(7); -  SET_PROG_COUNTER(addr + *(INT32*)addr); -  FETCH; +  DO_JUMP_TO(addr + *(INT32*)addr);   });      OPCODE2(F_SWITCH_ON_LOCAL, "switch on local", {    INT32 tmp;    PIKE_OPCODE_T *addr = PROG_COUNTER;    tmp=switch_lookup(Pike_fp->context.prog->    constants[arg2].sval.u.array,Pike_fp->locals + arg1);    addr = DO_IF_ELSE_COMPUTED_GOTO(addr, (PIKE_OPCODE_T *)    DO_ALIGN(addr,((ptrdiff_t)sizeof(INT32))));    addr = (PIKE_OPCODE_T *)(((INT32 *)addr) + (tmp>=0 ? 1+tmp*2 : 2*~tmp));    if(*(INT32*)addr < 0) fast_check_threads_etc(7); -  SET_PROG_COUNTER(addr + *(INT32*)addr); -  FETCH; +  DO_JUMP_TO(addr + *(INT32*)addr);   });         #ifdef AUTO_BIGNUM   #define AUTO_BIGNUM_LOOP_TEST(X,Y) INT_TYPE_ADD_OVERFLOW(X,Y)   #else   #define AUTO_BIGNUM_LOOP_TEST(X,Y) 0   #endif       /* FIXME: Does this need bignum tests? /Fixed - Hubbe */
pike.git/src/interpret_functions.h:1700:   OPCODE1(F_SSCANF, "sscanf", {    o_sscanf(arg1);   });      #define MKAPPLY(OP,OPCODE,NAME,TYPE, ARG2, ARG3) \   OP(PIKE_CONCAT(F_,OPCODE),NAME, { \   if(low_mega_apply(TYPE,DO_NOT_WARN((INT32)(Pike_sp - *--Pike_mark_sp)), \    ARG2, ARG3)) \   { \    Pike_fp->next->pc=PROG_COUNTER; \ -  SET_PROG_COUNTER(Pike_fp->pc); \ -  FETCH; \ +     Pike_fp->flags |= PIKE_FRAME_RETURN_INTERNAL; \ -  +  DO_JUMP_TO(Pike_fp->pc); \   } \   }); \    \   OP(PIKE_CONCAT3(F_,OPCODE,_AND_POP),NAME " & pop", { \    if(low_mega_apply(TYPE, DO_NOT_WARN((INT32)(Pike_sp - *--Pike_mark_sp)), \    ARG2, ARG3)) \    { \    Pike_fp->next->pc=PROG_COUNTER; \ -  SET_PROG_COUNTER(Pike_fp->pc); \ -  FETCH; \ +     Pike_fp->flags |= PIKE_FRAME_RETURN_INTERNAL | PIKE_FRAME_RETURN_POP; \ -  +  DO_JUMP_TO(Pike_fp->pc); \    }else{ \    pop_stack(); \    } \   }); \    \   OP(PIKE_CONCAT3(F_,OPCODE,_AND_RETURN),NAME " & return", { \    if(low_mega_apply(TYPE,DO_NOT_WARN((INT32)(Pike_sp - *--Pike_mark_sp)), \    ARG2,ARG3)) \    { \ -  +  PIKE_OPCODE_T *addr = Pike_fp->pc; \    DO_IF_DEBUG(Pike_fp->next->pc=0); \ -  SET_PROG_COUNTER(Pike_fp->pc); \ -  FETCH; \ +     unlink_previous_frame(); \ -  +  DO_JUMP_TO(addr); \    }else{ \    DO_DUMB_RETURN; \    } \   }); \    \   OP(PIKE_CONCAT(F_MARK_,OPCODE),"mark, " NAME, { \    if(low_mega_apply(TYPE,0, \    ARG2, ARG3)) \    { \    Pike_fp->next->pc=PROG_COUNTER; \ -  SET_PROG_COUNTER(Pike_fp->pc); \ -  FETCH; \ +     Pike_fp->flags |= PIKE_FRAME_RETURN_INTERNAL; \ -  +  DO_JUMP_TO(Pike_fp->pc); \    } \   }); \    \   OP(PIKE_CONCAT3(F_MARK_,OPCODE,_AND_POP),"mark, " NAME " & pop", { \    if(low_mega_apply(TYPE, 0, \    ARG2, ARG3)) \    { \    Pike_fp->next->pc=PROG_COUNTER; \ -  SET_PROG_COUNTER(Pike_fp->pc); \ -  FETCH; \ +     Pike_fp->flags |= PIKE_FRAME_RETURN_INTERNAL | PIKE_FRAME_RETURN_POP; \ -  +  DO_JUMP_TO(Pike_fp->pc); \    }else{ \    pop_stack(); \    } \   }); \    \   OP(PIKE_CONCAT3(F_MARK_,OPCODE,_AND_RETURN),"mark, " NAME " & return", { \    if(low_mega_apply(TYPE,0, \    ARG2,ARG3)) \    { \ -  +  PIKE_OPCODE_T *addr = Pike_fp->pc; \    DO_IF_DEBUG(Pike_fp->next->pc=0); \ -  SET_PROG_COUNTER(Pike_fp->pc); \ -  FETCH; \ +     unlink_previous_frame(); \ -  +  DO_JUMP_TO(Pike_fp->pc); \    }else{ \    DO_DUMB_RETURN; \    } \   })         MKAPPLY(OPCODE1,CALL_LFUN,"call lfun",APPLY_LOW,    Pike_fp->current_object,    (void *)(arg1+Pike_fp->context.identifier_level));   
pike.git/src/interpret_functions.h:1866:      /* Assume that the number of arguments is correct */   OPCODE1_JUMP(F_COND_RECUR, "recur if not overloaded", {    /* FIXME:    * this test should actually test if this function is    * overloaded or not. Currently it only tests if    * this context is inherited or not.    */    if(Pike_fp->current_object->prog != Pike_fp->context.prog)    { -  SET_PROG_COUNTER((PIKE_OPCODE_T *)(((INT32 *)PROG_COUNTER) + 1)); +  PIKE_OPCODE_T *addr = (PIKE_OPCODE_T *)(((INT32 *)PROG_COUNTER) + 1);    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=PROG_COUNTER; -  SET_PROG_COUNTER(Pike_fp->pc); -  FETCH; +     Pike_fp->flags |= PIKE_FRAME_RETURN_INTERNAL; -  } else { -  FETCH; +  addr = Pike_fp->pc;    } -  DONE; +  DO_JUMP_TO(addr);    }       /* FALL THROUGH */       /* Assume that the number of arguments is correct */    /* FIXME: Use new recursion stuff */    OPCODE0_TAILJUMP(F_RECUR, "recur", {    PIKE_OPCODE_T *addr;    struct pike_frame *new_frame;   
pike.git/src/interpret_functions.h:1922:    fatal("Wrong number of arguments in F_RECUR %d!=%d\n",    new_frame->num_args,    (ptrdiff_t)addr[-1]);       if(t_flag > 3)    fprintf(stderr,"- Allocating %d extra locals.\n",    new_frame->num_locals - new_frame->num_args);    });       Pike_fp->pc = (PIKE_OPCODE_T *)(((INT32 *)PROG_COUNTER) + 1); -  SET_PROG_COUNTER(addr); -  FETCH; +        clear_svalues(Pike_sp, new_frame->num_locals - new_frame->num_args);    Pike_sp += new_frame->num_locals - new_frame->args;       if(new_frame->scope) add_ref(new_frame->scope);    add_ref(new_frame->current_object);    add_ref(new_frame->context.prog);    if(new_frame->context.parent)    add_ref(new_frame->context.parent);    Pike_fp=new_frame;    new_frame->flags=PIKE_FRAME_RETURN_INTERNAL; -  +  +  DO_JUMP_TO(addr);    });   });      /* Ugly code duplication */   OPCODE0_JUMP(F_RECUR_AND_POP, "recur & pop", {    PIKE_OPCODE_T *addr;    struct pike_frame *new_frame;       fast_check_threads_etc(6);    check_c_stack(8192);
pike.git/src/interpret_functions.h:1975:    fatal("Wrong number of arguments in F_RECUR %d!=%d\n",    new_frame->num_args,    (ptrdiff_t)addr[-1]);       if(t_flag > 3)    fprintf(stderr,"- Allocating %d extra locals.\n",    new_frame->num_locals - new_frame->num_args);    });       Pike_fp->pc = (PIKE_OPCODE_T *)(((INT32 *)PROG_COUNTER) + 1); -  SET_PROG_COUNTER(addr); -  FETCH; +        clear_svalues(Pike_sp, new_frame->num_locals - new_frame->num_args);    Pike_sp += new_frame->num_locals - new_frame->args;       if(new_frame->scope) add_ref(new_frame->scope);    add_ref(new_frame->current_object);    add_ref(new_frame->context.prog);    if(new_frame->context.parent)    add_ref(new_frame->context.parent);    Pike_fp=new_frame;    new_frame->flags=PIKE_FRAME_RETURN_INTERNAL | PIKE_FRAME_RETURN_POP; -  +  +  DO_JUMP_TO(addr);   });         /* Assume that the number of arguments is correct */   /* FIXME: adjust Pike_mark_sp */   OPCODE0_JUMP(F_TAIL_RECUR, "tail recursion", {    int x;    INT32 num_locals;    PIKE_OPCODE_T *addr;    INT32 args = DO_NOT_WARN((INT32)(Pike_sp - *--Pike_mark_sp));
pike.git/src/interpret_functions.h:2023:    DO_IF_DEBUG({    if (Pike_sp < Pike_fp->locals + args)    fatal("Pike_sp (%p) < Pike_fp->locals (%p) + args (%d)\n",    Pike_sp, Pike_fp->locals, args);    });    assign_svalues(Pike_fp->locals, Pike_sp-args, args, BIT_MIXED);    pop_n_elems(Pike_sp - (Pike_fp->locals + args));    }       clear_svalues(Pike_sp, num_locals - args); -  SET_PROG_COUNTER(addr); -  FETCH; +     Pike_sp += num_locals - args;       DO_IF_DEBUG({    if(Pike_sp != Pike_fp->locals + Pike_fp->num_locals)    fatal("Sp whacked!\n");    }); -  +  +  DO_JUMP_TO(addr);   });      OPCODE0(F_BREAKPOINT, "breakpoint", {    extern void o_breakpoint(void); -  SET_PROG_COUNTER(PROG_COUNTER-1); -  FETCH; +     o_breakpoint(); -  +  DO_JUMP_TO(PROG_COUNTER-1);   });      OPCODE0(F_THIS_OBJECT, "this_object", {    if(Pike_fp)    {    ref_push_object(Pike_fp->current_object);    }else{    push_int(0);    }   });