pike.git / src / interpret.c

version» Context lines:

pike.git/src/interpret.c:1:   /*\   ||| This file a part of Pike, and is copyright by Fredrik Hubinette   ||| Pike is distributed as GPL (General Public License)   ||| See the files COPYING and DISCLAIMER for more information.   \*/   #include "global.h" - RCSID("$Id: interpret.c,v 1.110 1998/11/20 19:01:06 hubbe Exp $"); + RCSID("$Id: interpret.c,v 1.111 1998/11/22 11:02:53 hubbe Exp $");   #include "interpret.h"   #include "object.h"   #include "program.h"   #include "svalue.h"   #include "array.h"   #include "mapping.h"   #include "error.h"   #include "language.h"   #include "stralloc.h"   #include "constants.h"
pike.git/src/interpret.c:76:   #endif      void push_sp_mark(void)   {    if(mark_sp == mark_stack + stack_size)    error("No more mark stack!\n");    *mark_sp++=sp;   }   int pop_sp_mark(void)   { - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(mark_sp < mark_stack)    fatal("Mark stack underflow!\n");   #endif    return sp - *--mark_sp;   }      struct frame *fp; /* frame pointer */    - #ifdef DEBUG + #ifdef PIKE_DEBUG   static void gc_check_stack_callback(struct callback *foo, void *bar, void *gazonk)   {    struct frame *f;    debug_gc_xmark_svalues(evaluator_stack,sp-evaluator_stack-1,"interpreter stack");       for(f=fp;f;f=f->parent_frame)    {    if(f->context.parent)    gc_external_mark(f->context.parent);    gc_external_mark(f->current_object);
pike.git/src/interpret.c:170:    if(!mark_stack)    {    mark_stack=(struct svalue **)xalloc(stack_size*sizeof(struct svalue *));    mark_stack_malloced=1;    }       sp=evaluator_stack;    mark_sp=mark_stack;    fp=0;    - #ifdef DEBUG + #ifdef PIKE_DEBUG    {    static struct callback *spcb;    if(!spcb)    {    spcb=add_gc_callback(gc_check_stack_callback,0,0);    }    }   #endif   #ifdef PROFILING   #ifdef HAVE_GETHRTIME
pike.git/src/interpret.c:368:       default:    if(IS_ZERO(lval))    error("Indexing the NULL value.\n"); /* Per */    else    error("Indexing a basic type.\n");    return 0;    }   }    - #ifdef DEBUG + #ifdef PIKE_DEBUG   void print_return_value(void)   {    if(t_flag>3)    {    char *s;       init_buf();    describe_svalue(sp-1,0,0);    s=simple_free_buf();    if((long)strlen(s) > (long)TRACE_LEN)
pike.git/src/interpret.c:395: Inside #if defined(DEBUG)
   fprintf(stderr,"- value: %s\n",s);    free(s);    }   }   #else   #define print_return_value()   #endif      struct callback_list evaluator_callbacks;    - #ifdef DEBUG + #ifdef PIKE_DEBUG   static char trace_buffer[200];   #define GET_ARG() (backlog[backlogp].arg=(\    instr=prefix,\    prefix=0,\    instr+=EXTRACT_UCHAR(pc++),\    (t_flag>3 ? sprintf(trace_buffer,"- Arg = %ld\n",(long)instr),write_to_stderr(trace_buffer,strlen(trace_buffer)) : 0),\    instr))   #define GET_ARG2() (\    instr=EXTRACT_UCHAR(pc++),\    (t_flag>3 ? sprintf(trace_buffer,"- Arg2= %ld\n",(long)instr),write_to_stderr(trace_buffer,strlen(trace_buffer)) : 0),\
pike.git/src/interpret.c:477:      /*    * reset the stack machine.    */   void reset_evaluator(void)   {    fp=0;    pop_n_elems(sp - evaluator_stack);   }    - #ifdef DEBUG + #ifdef PIKE_DEBUG   #define BACKLOG 512   struct backlog   {    INT32 instruction;    INT32 arg;    struct program *program;    unsigned char *pc;   };      struct backlog backlog[BACKLOG];
pike.git/src/interpret.c:529:   static int o_catch(unsigned char *pc);      static int eval_instruction(unsigned char *pc)   {    unsigned INT32 accumulator=0,instr, prefix=0;    while(1)    {    fp->pc = pc;    instr=EXTRACT_UCHAR(pc++);    - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(d_flag)    {   #if defined(_REENTRANT) && !defined(__NT__)    if(!mt_trylock(& interpreter_lock))    fatal("Interpreter running unlocked!\n");   #endif    sp[0].type=99; /* an invalid type */    sp[1].type=99;    sp[2].type=99;    sp[3].type=99;
pike.git/src/interpret.c:683:       o=fp->current_object;       if(!o)    error("Current object is destructed\n");       while(1)    {    if(inherit->parent_offset)    { - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(t_flag>4)    {    sprintf(trace_buffer,"- Following o->parent (accumulator+=%d)\n",inherit->parent_offset-1);    write_to_stderr(trace_buffer,strlen(trace_buffer));    }   #endif       i=o->parent_identifier;    o=o->parent;    accumulator+=inherit->parent_offset-1;    }else{ - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(t_flag>4)    {    sprintf(trace_buffer,"- Following inherit->parent (accumulator+=%d)\n",inherit->parent_offset-1);    write_to_stderr(trace_buffer,strlen(trace_buffer));    }   #endif    i=inherit->parent_identifier;    o=inherit->parent;    }   
pike.git/src/interpret.c:1456:    CASE(F_RETURN_1);    push_int(1);    goto do_return;       CASE(F_RETURN_0);    push_int(0);    goto do_return;       CASE(F_RETURN);    do_return: - #if defined(DEBUG) && defined(GC2) + #if defined(PIKE_DEBUG) && defined(GC2)    if(d_flag>2) do_gc();    if(d_flag>3) do_debug();    check_threads_etc();   #endif       /* fall through */       CASE(F_DUMB_RETURN);    return -1;   
pike.git/src/interpret.c:1856:    }    case T_MAPPING:    error("Attempt to call a mapping\n");    default:    error("Call to non-function value type:%s.\n",    get_name_of_type(s->type));       case T_FUNCTION:    if(s->subtype == FUNCTION_BUILTIN)    { - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(t_flag>1)    {    init_buf();    describe_svalue(s,0,0);    do_trace_call(args);    }   #endif    (*(s->u.efun->function))(args);    break;    }else{    o=s->u.object;    fun=s->subtype;    goto apply_low;    }    break;       case T_ARRAY: - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(t_flag>1)    {    init_buf();    describe_svalue(s,0,0);    do_trace_call(args);    }   #endif    apply_array(s->u.array,args);    break;       case T_PROGRAM: - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(t_flag>1)    {    init_buf();    describe_svalue(s,0,0);    do_trace_call(args);    }   #endif    push_object(clone_object(s->u.program,args));    break;       case T_OBJECT:    o=s->u.object;    fun=LFUN_CALL;    goto call_lfun;    }    break;    }       call_lfun: - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(fun < 0 || fun >= NUM_LFUNS)    fatal("Apply lfun on illegal value!\n");   #endif    if(!o->prog)    PIKE_ERROR("destructed object", "Apply on destructed object.\n", sp, args);    fun=FIND_LFUN(o->prog,fun);    goto apply_low;          case APPLY_LOW:
pike.git/src/interpret.c:1938:    {    pop_n_elems(sp-save_sp);    push_int(0);    return;    }       check_stack(256);    check_mark_stack(256);    check_c_stack(8192);    - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(d_flag>2) do_debug();   #endif       p=o->prog;    if(!p)    PIKE_ERROR("destructed object->function",    "Cannot call functions in destructed objects.\n", sp, args); - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(fun>=(int)p->num_identifier_references)    {    fprintf(stderr,"Function index out of range. %d >= %d\n",fun,(int)p->num_identifier_references);    fprintf(stderr,"########Program is:\n");    describe(p);    fprintf(stderr,"########Object is:\n");    describe(o);    fatal("Function index out of range.\n");    }   #endif       ref = p->identifier_references + fun; - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(ref->inherit_offset>=p->num_inherits)    fatal("Inherit offset out of range in program.\n");   #endif       /* init a new evaluation frame */    new_frame.parent_frame = fp;    new_frame.current_object = o;    new_frame.context = p->inherits[ ref->inherit_offset ];       function = new_frame.context.prog->identifiers + ref->identifier_offset;
pike.git/src/interpret.c:2082:    if(args > num_args)    {    /* pop excessive */    pop_n_elems(args - num_args);    args=num_args;    }    }       clear_svalues(sp, num_locals - args);    sp += num_locals - args; - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(num_locals < num_args)    fatal("Wrong number of arguments or locals in function def.\n");   #endif    new_frame.num_locals=num_locals;    new_frame.num_args=num_args;       check_threads_etc();       {    struct svalue **save_mark_sp=mark_sp;    tailrecurse=eval_instruction(pc); - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(mark_sp < save_mark_sp)    fatal("Popped below save_mark_sp!\n");   #endif    mark_sp=save_mark_sp;    } - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(sp<evaluator_stack)    fatal("Stack error (also simple).\n");   #endif    break;    }       }   #ifdef PROFILING   #ifdef HAVE_GETHRTIME    {    long long time_passed, time_in_children, self_time;    time_in_children= accounted_time - children_base;    time_passed = gethrtime() - time_base - start_time;    self_time=time_passed - time_in_children;    accounted_time+=self_time; - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(self_time < 0 || children_base <0 || accounted_time <0)    fatal("Time is negative\n self_time=%ld\n time_passed=%ld\n time_in_children=%ld\n children_base=%ld\n accounted_time=%ld!\n time_base=%ld\n start_time=%ld\n",    (long)(self_time/100000),    (long)(time_passed/100000),    (long)(time_in_children/100000),    (long)(children_base/100000),    (long)(accounted_time/100000),    (long)(time_base/100000),    (long)(start_time/100000)    );
pike.git/src/interpret.c:2139: Inside #if defined(PROFILING) and #if defined(HAVE_GETHRTIME)
   function->self_time+=(INT32)( self_time /1000);    }   #endif   #endif      #if 0    if(sp - new_frame.locals > 1)    {    pop_n_elems(sp - new_frame.locals -1);    }else if(sp - new_frame.locals < 1){ - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(sp - new_frame.locals<0) fatal("Frame underflow.\n");   #endif    sp->u.integer = 0;    sp->subtype=NUMBER_NUMBER;    sp->type = T_INT;    sp++;    }   #endif       if(new_frame.context.parent) free_object(new_frame.context.parent);
pike.git/src/interpret.c:2242:    add_ref(new_frame.current_object);    add_ref(new_frame.context.prog);       if(SETJMP(tmp))    {    ret=1;    }else{    int tmp=eval_instruction(o->prog->program + offset);    if(tmp!=-1) mega_apply(APPLY_STACK, tmp, 0,0);    - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(sp<evaluator_stack)    fatal("Stack error (simple).\n");   #endif    ret=0;    }    UNSETJMP(tmp);       free_object(new_frame.current_object);    free_program(new_frame.context.prog);   
pike.git/src/interpret.c:2300:    sp->type = T_INT;    sp++;    }    }    UNSETJMP(recovery);   }         void safe_apply(struct object *o, char *fun ,INT32 args)   { - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(!o->prog) fatal("Apply safe on destructed object.\n");   #endif    safe_apply_low(o, find_identifier(fun, o->prog), args);   }      void apply_lfun(struct object *o, int fun, int args)   { - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(fun < 0 || fun >= NUM_LFUNS)    fatal("Apply lfun on illegal value!\n");   #endif    if(!o->prog)    PIKE_ERROR("destructed object", "Apply on destructed object.\n", sp, args);       apply_low(o, (int)FIND_LFUN(o->prog,fun), args);   }      void apply_shared(struct object *o,
pike.git/src/interpret.c:2349:       strict_apply_svalue(s,args);    if(sp > (expected_stack + evaluator_stack))    {    pop_n_elems(sp-(expected_stack + evaluator_stack));    }    else if(sp < (expected_stack + evaluator_stack))    {    push_int(0);    } - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(sp < (expected_stack + evaluator_stack))    fatal("Stack underflow!\n");   #endif    }   }    - #ifdef DEBUG + #ifdef PIKE_DEBUG   void slow_check_stack(void)   {    struct svalue *s,**m;    struct frame *f;       debug_check_stack();       if(sp > &(evaluator_stack[stack_size]))    fatal("Stack overflow.\n");   
pike.git/src/interpret.c:2404: Inside #if defined(DEBUG)
      if(f->args < 0 || f->args > stack_size)    fatal("FEL FEL FEL! HELP!! (corrupted frame)\n");    }    }   }   #endif      void cleanup_interpret(void)   { - #ifdef DEBUG + #ifdef PIKE_DEBUG    int e;   #endif       while(fp)    {    free_object(fp->current_object);    free_program(fp->context.prog);       fp = fp->parent_frame;    }    - #ifdef DEBUG + #ifdef PIKE_DEBUG    for(e=0;e<BACKLOG;e++)    {    if(backlog[e].program)    {    free_program(backlog[e].program);    backlog[e].program=0;    }    }   #endif    reset_evaluator();