pike.git / src / interpret_functions.h

version» Context lines:

pike.git/src/interpret_functions.h:1:   /* -  * $Id: interpret_functions.h,v 1.71 2001/07/08 19:35:37 grubba Exp $ +  * $Id: interpret_functions.h,v 1.72 2001/07/09 11:37:20 grubba Exp $    *    * Opcode definitions for the interpreter.    */      #include "global.h"      #undef CJUMP   #undef AUTO_BIGNUM_LOOP_TEST   #undef LOOP   #undef COMPARISON   #undef MKAPPLY   #undef DO_CALL_BUILTIN      #undef DO_IF_BIGNUM   #ifdef AUTO_BIGNUM   #define DO_IF_BIGNUM(CODE) CODE   #else /* !AUTO_BIGNUM */   #define DO_IF_BIGNUM(CODE)   #endif /* AUTO_BIGNUM */    -  + #undef DO_IF_ELSE_COMPUTED_GOTO + #ifdef HAVE_COMPUTED_GOTO + #define DO_IF_ELSE_COMPUTED_GOTO(A, B) (A) + #else /* !HAVE_COMPUTED_GOTO */ + #define DO_IF_ELSE_COMPUTED_GOTO(A, B) (B) + #endif /* HAVE_COMPUTED_GOTO */ +    #ifdef GEN_PROTOS   /* Used to generate the interpret_protos.h file. */   #define OPCODE0(A, B, C) OPCODE0(A, B) C   #define OPCODE1(A, B, C) OPCODE1(A, B) C   #define OPCODE2(A, B, C) OPCODE2(A, B) C   #define OPCODE0_TAIL(A, B, C) OPCODE0_TAIL(A, B) C   #define OPCODE1_TAIL(A, B, C) OPCODE1_TAIL(A, B) C   #define OPCODE2_TAIL(A, B, C) OPCODE2_TAIL(A, B) C   #define OPCODE0_JUMP(A, B, C) OPCODE0_JUMP(A, B) C   #define OPCODE1_JUMP(A, B, C) OPCODE1_JUMP(A, B) C
pike.git/src/interpret_functions.h:565:   });      OPCODE0(F_INC, "++x", {    union anything *u=get_pointer_if_this_type(Pike_sp-2, PIKE_T_INT);    if(u    DO_IF_BIGNUM(    && !INT_TYPE_ADD_OVERFLOW(u->integer, 1)    )    )    { -  instr=++ u->integer; +  INT32 val = ++u->integer;    pop_n_elems(2); -  push_int(instr); +  push_int(val);    } else {    lvalue_to_svalue_no_free(Pike_sp, Pike_sp-2); Pike_sp++;    push_int(1);    f_add(2);    assign_lvalue(Pike_sp-3, Pike_sp-1);    stack_unlink(2);    }   });      OPCODE0(F_DEC, "--x", {    union anything *u=get_pointer_if_this_type(Pike_sp-2, PIKE_T_INT);    if(u    DO_IF_BIGNUM(    && !INT_TYPE_SUB_OVERFLOW(u->integer, 1)    )    )    { -  instr=-- u->integer; +  INT32 val = --u->integer;    pop_n_elems(2); -  push_int(instr); +  push_int(val);    } else {    lvalue_to_svalue_no_free(Pike_sp, Pike_sp-2); Pike_sp++;    push_int(1);    o_subtract();    assign_lvalue(Pike_sp-3, Pike_sp-1);    stack_unlink(2);    }   });      OPCODE0(F_DEC_AND_POP, "x-- and pop", {    union anything *u=get_pointer_if_this_type(Pike_sp-2, PIKE_T_INT);    if(u    DO_IF_BIGNUM(    && !INT_TYPE_SUB_OVERFLOW(u->integer, 1)    )   )    { -  -- u->integer; +  --u->integer;    pop_n_elems(2);    }else{    lvalue_to_svalue_no_free(Pike_sp, Pike_sp-2); Pike_sp++;    push_int(1);    o_subtract();    assign_lvalue(Pike_sp-3, Pike_sp-1);    pop_n_elems(3);    }   });      OPCODE0(F_INC_AND_POP, "x++ and pop", {    union anything *u=get_pointer_if_this_type(Pike_sp-2, PIKE_T_INT);    if(u    DO_IF_BIGNUM(    && !INT_TYPE_ADD_OVERFLOW(u->integer, 1)    )    )    { -  instr=++ u->integer; +  ++u->integer;    pop_n_elems(2);    } else {    lvalue_to_svalue_no_free(Pike_sp, Pike_sp-2); Pike_sp++;    push_int(1);    f_add(2);    assign_lvalue(Pike_sp-3, Pike_sp-1);    pop_n_elems(3);    }   });      OPCODE0(F_POST_INC, "x++", {    union anything *u=get_pointer_if_this_type(Pike_sp-2, PIKE_T_INT);    if(u    DO_IF_BIGNUM(    && !INT_TYPE_ADD_OVERFLOW(u->integer, 1)    )    )    { -  instr=u->integer ++; +  INT32 val = u->integer++;    pop_n_elems(2); -  push_int(instr); +  push_int(val);    } else {    lvalue_to_svalue_no_free(Pike_sp, Pike_sp-2); Pike_sp++;    stack_dup();    push_int(1);    f_add(2);    assign_lvalue(Pike_sp-4, Pike_sp-1);    pop_stack();    stack_unlink(2);    print_return_value();    }   });      OPCODE0(F_POST_DEC, "x--", {    union anything *u=get_pointer_if_this_type(Pike_sp-2, PIKE_T_INT);    if(u    DO_IF_BIGNUM(    && !INT_TYPE_SUB_OVERFLOW(u->integer, 1)    )    )    { -  instr=u->integer --; +  INT32 val = u->integer--;    pop_n_elems(2); -  push_int(instr); +  push_int(val);    } else {    lvalue_to_svalue_no_free(Pike_sp, Pike_sp-2); Pike_sp++;    stack_dup();    push_int(1);    o_subtract();    assign_lvalue(Pike_sp-4, Pike_sp-1);    pop_stack();    stack_unlink(2);    print_return_value();    }
pike.git/src/interpret_functions.h:981:    pop_n_elems(2);    SKIPJUMP();    }else{    pop_n_elems(2);    push_int(0);    DOJUMP();    }   });      OPCODE0_JUMP(F_CATCH, "catch", { -  switch (o_catch(pc+sizeof(INT32))) { +  switch (o_catch(pc+DO_IF_ELSE_COMPUTED_GOTO(1, sizeof(INT32)))) +  {    case 1:    /* There was a return inside the evaluated code */    goto do_dumb_return;    case 2:    pc = Pike_fp->pc;    break;    default: -  pc+=GET_JUMP(); +  pc += GET_JUMP();    }   });      OPCODE0(F_ESCAPE_CATCH, "escape catch", {    Pike_fp->pc = pc;    return -2;   });      OPCODE0(F_THROW_ZERO, "throw(0)", {    push_int(0);    f_throw(1);   });      OPCODE1(F_SWITCH, "switch", {    INT32 tmp;    tmp=switch_lookup(Pike_fp->context.prog->    constants[arg1].sval.u.array,Pike_sp-1); -  pc=(unsigned char *)DO_ALIGN(pc,((ptrdiff_t)sizeof(INT32))); -  pc+=(tmp>=0 ? 1+tmp*2 : 2*~tmp) * sizeof(INT32); +  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) * +  DO_IF_ELSE_COMPUTED_GOTO(1, sizeof(INT32));    if(*(INT32*)pc < 0) fast_check_threads_etc(7); -  pc+=*(INT32*)pc; +  pc += *(INT32*)pc;    pop_stack();   });      OPCODE1(F_SWITCH_ON_INDEX, "switch on index", {    INT32 tmp;    struct svalue s;    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); -  pc=(unsigned char *)DO_ALIGN(pc,((ptrdiff_t)sizeof(INT32))); -  pc+=(tmp>=0 ? 1+tmp*2 : 2*~tmp) * sizeof(INT32); +  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) * +  DO_IF_ELSE_COMPUTED_GOTO(1, sizeof(INT32));    if(*(INT32*)pc < 0) fast_check_threads_etc(7);    pc+=*(INT32*)pc;   });      OPCODE2(F_SWITCH_ON_LOCAL, "switch on local", {    INT32 tmp;    tmp=switch_lookup(Pike_fp->context.prog->    constants[arg2].sval.u.array,Pike_fp->locals + arg1); -  pc=(unsigned char *)DO_ALIGN(pc,((ptrdiff_t)sizeof(INT32))); -  pc+=(tmp>=0 ? 1+tmp*2 : 2*~tmp) * sizeof(INT32); +  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) * +  DO_IF_ELSE_COMPUTED_GOTO(1, sizeof(INT32));    if(*(INT32*)pc < 0) fast_check_threads_etc(7);    pc+=*(INT32*)pc;   });         #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
pike.git/src/interpret_functions.h:1141:    {    fast_check_threads_etc(10);    pc+=GET_JUMP();    }else{    SKIPJUMP();    }   });          CASE(F_RETURN_LOCAL); -  instr=GET_ARG(); +  { +  INT32 val = GET_ARG();   #if defined(PIKE_DEBUG) && defined(GC2)    /* 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    */    if(d_flag>3) do_gc();    if(d_flag>4) do_debug();    check_threads_etc();   #endif -  if(Pike_fp->expendible <= Pike_fp->locals+instr) +  if(Pike_fp->expendible <= Pike_fp->locals + val)    { -  pop_n_elems(Pike_sp-1 - (Pike_fp->locals+instr)); +  pop_n_elems(Pike_sp-1 - (Pike_fp->locals + val));    }else{ -  push_svalue(Pike_fp->locals+instr); +  push_svalue(Pike_fp->locals + val);    }    print_return_value();    goto do_dumb_return; -  +  }       CASE(F_RETURN_IF_TRUE);    if(!IS_ZERO(Pike_sp-1)) goto do_return;    pop_stack();    break;       CASE(F_RETURN_1);    push_int(1);    goto do_return;   
pike.git/src/interpret_functions.h:1257:   OPCODE0(F_LSH, "<<", {    o_lsh();   });      OPCODE0(F_RSH, ">>", {    o_rsh();   });      #define COMPARISON(ID,DESC,EXPR) \    OPCODE0(ID, DESC, { \ -  instr = EXPR; \ +  INT32 val = EXPR; \    pop_n_elems(2); \ -  push_int(instr); \ +  push_int(val); \    })      COMPARISON(F_EQ, "==", is_eq(Pike_sp-2,Pike_sp-1));   COMPARISON(F_NE, "!=", !is_eq(Pike_sp-2,Pike_sp-1));   COMPARISON(F_GT, ">", is_gt(Pike_sp-2,Pike_sp-1));   COMPARISON(F_GE, ">=", !is_lt(Pike_sp-2,Pike_sp-1));   COMPARISON(F_LT, "<", is_lt(Pike_sp-2,Pike_sp-1));   COMPARISON(F_LE, "<=", !is_gt(Pike_sp-2,Pike_sp-1));      OPCODE0(F_ADD, "+", {
pike.git/src/interpret_functions.h:1579:    ((struct string_assignment_storage *)o->storage)->lval[0]=Pike_sp[-2];    ((struct string_assignment_storage *)o->storage)->lval[1]=Pike_sp[-1];    ((struct string_assignment_storage *)o->storage)->s=s.u.string;    Pike_sp-=2;    push_object(o);    }    print_return_value();   });      OPCODE0(F_SIZEOF, "sizeof", { -  instr=pike_sizeof(Pike_sp-1); +  INT32 val = pike_sizeof(Pike_sp-1);    pop_stack(); -  push_int(instr); +  push_int(val);   });      OPCODE1(F_SIZEOF_LOCAL, "sizeof local", {    push_int(pike_sizeof(Pike_fp->locals+arg1));   });      OPCODE1(F_SSCANF, "sscanf", {    o_sscanf(arg1);   });   
pike.git/src/interpret_functions.h:1758:      /* 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)    { -  pc+=sizeof(INT32); +  pc += sizeof(INT32)/sizeof(PIKE_OPCODE_T);    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;    Pike_fp->flags |= PIKE_FRAME_RETURN_INTERNAL;    pc=Pike_fp->pc;    }    DONE;    }       /* FALL THROUGH */       /* Assume that the number of arguments is correct */    /* FIXME: Use new recursion stuff */    OPCODE0_TAILJUMP(F_RECUR, "recur", {    OPCODE0_TAILJUMP(F_RECUR_AND_POP, "recur & pop", { -  int opcode = instr; -  unsigned char *addr; +  PIKE_OPCODE_T opcode = instr; +  PIKE_OPCODE_T *addr;    struct pike_frame *new_frame;       fast_check_threads_etc(6);    check_c_stack(8192);    check_stack(256);       new_frame=alloc_pike_frame();    new_frame[0]=Pike_fp[0];       new_frame->refs=1;
pike.git/src/interpret_functions.h:1823:       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->pc=pc+sizeof(INT32);    Pike_fp=new_frame;    pc=addr;    new_frame->flags=PIKE_FRAME_RETURN_INTERNAL; -  if (opcode == F_RECUR_AND_POP-F_OFFSET) +  if (opcode == DO_IF_ELSE_COMPUTED_GOTO(&&LABEL_F_RECUR_AND_POP, +  F_RECUR_AND_POP-F_OFFSET))    new_frame->flags|=PIKE_FRAME_RETURN_POP;    });    });   });      /* 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; -  unsigned char *addr; +  PIKE_OPCODE_T *addr;    INT32 args = DO_NOT_WARN((INT32)(Pike_sp - *--Pike_mark_sp));       fast_check_threads_etc(6);       addr=pc+GET_JUMP();    num_locals=EXTRACT_UCHAR(addr-2);          DO_IF_DEBUG({    if(args != EXTRACT_UCHAR(addr-1))