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.66 1998/02/01 04:01:32 hubbe Exp $"); + RCSID("$Id: interpret.c,v 1.67 1998/02/03 05:29:25 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:339:    return 0;    }   }      #ifdef DEBUG   void print_return_value(void)   {    if(t_flag>3)    {    char *s; -  int nonblock; +     -  if((nonblock=query_nonblocking(2))) -  set_nonblocking(2,0); -  +     init_buf();    describe_svalue(sp-1,0,0);    s=simple_free_buf();    if((long)strlen(s) > (long)TRACE_LEN)    {    s[TRACE_LEN]=0;    s[TRACE_LEN-1]='.';    s[TRACE_LEN-2]='.';    s[TRACE_LEN-2]='.';    }    fprintf(stderr,"- value: %s\n",s);    free(s); -  -  if(nonblock) -  set_nonblocking(2,1); +     }   }   #else   #define print_return_value()   #endif         void pop_n_elems(INT32 x)   {    if(!x) return;
pike.git/src/interpret.c:553: Inside #if defined(DEBUG)
   backlog[backlogp].program=fp->context.prog;    fp->context.prog->refs++;    backlog[backlogp].instruction=instr;    backlog[backlogp].arg=0;    backlog[backlogp].pc=pc;    }       if(t_flag > 2)    {    char *file, *f; -  INT32 linep, nonblock; -  if((nonblock=query_nonblocking(2))) -  set_nonblocking(2,0); +  INT32 linep;       file=get_line(pc-1,fp->context.prog,&linep);    while((f=STRCHR(file,'/'))) file=f+1;    fprintf(stderr,"- %s:%4ld:(%lx): %-25s %4ld %4ld\n",    file,(long)linep,    (long)(pc-fp->context.prog->program-1),    get_f_name(instr + F_OFFSET),    (long)(sp-evaluator_stack),    (long)(mark_sp-mark_stack)); -  if(nonblock) -  set_nonblocking(2,1); +     }       if(instr + F_OFFSET < F_MAX_OPCODE)    ADD_RUNNED(instr + F_OFFSET);   #endif       switch(instr)    {    /* Support to allow large arguments */    CASE(F_PREFIX_256); prefix+=256; break;
pike.git/src/interpret.c:1493:    }    return args;    }       default:    fatal("Strange instruction %ld\n",(long)instr);    }    }   }    + static void trace_return_value(void) + { +  char *s; +  +  init_buf(); +  my_strcat("Return: "); +  describe_svalue(sp-1,0,0); +  s=simple_free_buf(); +  if((long)strlen(s) > (long)TRACE_LEN) +  { +  s[TRACE_LEN]=0; +  s[TRACE_LEN-1]='.'; +  s[TRACE_LEN-2]='.'; +  s[TRACE_LEN-2]='.'; +  } +  fprintf(stderr,"%-*s%s\n",4,"-",s); +  free(s); + } +  + static void do_trace_call(INT32 args) + { +  char *file,*s; +  INT32 linep,e; +  my_strcat("("); +  for(e=0;e<args;e++) +  { +  if(e) my_strcat(","); +  describe_svalue(sp-args+e,0,0); +  } +  my_strcat(")"); +  s=simple_free_buf(); +  if((long)strlen(s) > (long)TRACE_LEN) +  { +  s[TRACE_LEN]=0; +  s[TRACE_LEN-1]='.'; +  s[TRACE_LEN-2]='.'; +  s[TRACE_LEN-2]='.'; +  } +  if(fp && fp->pc) +  { +  char *f; +  file=get_line(fp->pc,fp->context.prog,&linep); +  while((f=STRCHR(file,'/'))) file=f+1; +  }else{ +  linep=0; +  file="-"; +  } +  fprintf(stderr,"- %s:%4ld: %s\n",file,(long)linep,s); +  free(s); + } +  +    void mega_apply(enum apply_type type, INT32 args, void *arg1, void *arg2)   {    struct object *o;    int fun, tailrecurse=-1;    struct svalue *save_sp=sp-args;       switch(type)    {    case APPLY_STACK:    apply_stack:
pike.git/src/interpret.c:1543:    error("Attempt to call the string \"%s\"\n", s->u.string->str);    }    case T_MAPPING:    error("Attempt to call a mapping\n");    default:    error("Call to non-function value type:%d.\n", s->type);       case T_FUNCTION:    if(s->subtype == FUNCTION_BUILTIN)    { + #ifdef 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 +  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 +  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;    }
pike.git/src/interpret.c:1636:    new_frame.locals = sp - args;    new_frame.args = args;    new_frame.fun = fun;    new_frame.current_storage = o->storage+new_frame.context.storage_offset;    new_frame.pc = 0;       new_frame.current_object->refs++;    new_frame.context.prog->refs++;    if(new_frame.context.parent) new_frame.context.parent->refs++;    - #ifdef DEBUG +     if(t_flag)    { -  char *file, *f; -  INT32 linep,e,nonblock; -  char buf[50],*s; -  -  if((nonblock=query_nonblocking(2))) -  set_nonblocking(2,0); -  -  if(fp && fp->pc) -  { -  file=get_line(fp->pc,fp->context.prog,&linep); -  while((f=STRCHR(file,'/'))) file=f+1; -  }else{ -  linep=0; -  file="-"; -  } -  +  char buf[50];    init_buf();    sprintf(buf,"%lx->",(long)o);    my_strcat(buf);    my_strcat(function->name->str); -  my_strcat("("); -  for(e=0;e<args;e++) -  { -  if(e) my_strcat(","); -  describe_svalue(sp-args+e,0,0); +  do_trace_call(args);    } -  my_strcat(")"); -  s=simple_free_buf(); -  if((long)strlen(s) > (long)TRACE_LEN) -  { -  s[TRACE_LEN]=0; -  s[TRACE_LEN-1]='.'; -  s[TRACE_LEN-2]='.'; -  s[TRACE_LEN-2]='.'; -  } -  fprintf(stderr,"- %s:%4ld: %s\n",file,(long)linep,s); -  free(s); +     -  if(nonblock) -  set_nonblocking(2,1); -  } - #endif -  +     fp = &new_frame;       if(function->func.offset == -1)    error("Calling undefined function '%s'.\n",function->name->str);       tailrecurse=-1;    switch(function->identifier_flags & (IDENTIFIER_FUNCTION | IDENTIFIER_CONSTANT))    {    case IDENTIFIER_C_FUNCTION:    fp->num_args=args;
pike.git/src/interpret.c:1801:    free_program(new_frame.context.prog);       fp = new_frame.parent_frame;       if(tailrecurse>=0)    {    args=tailrecurse;    goto apply_stack;    }    - #ifdef DEBUG -  if(t_flag) -  { -  char *s; -  int nonblock; -  -  if((nonblock=query_nonblocking(2))) -  set_nonblocking(2,0); -  -  init_buf(); -  my_strcat("Return: "); -  describe_svalue(sp-1,0,0); -  s=simple_free_buf(); -  if((long)strlen(s) > (long)TRACE_LEN) -  { -  s[TRACE_LEN]=0; -  s[TRACE_LEN-1]='.'; -  s[TRACE_LEN-2]='.'; -  s[TRACE_LEN-2]='.'; +     } -  fprintf(stderr,"%-*s%s\n",4,"-",s); -  free(s); -  -  if(nonblock) -  set_nonblocking(2,1); +     } - #endif -  } -  } +        if(save_sp+1 < sp)    {    assign_svalue(save_sp,sp-1);    pop_n_elems(sp-save_sp-1);    }       if(save_sp+1 > sp && type != APPLY_SVALUE) -  +  {    push_int(0); -  +  }else{ +  if(t_flag) trace_return_value();    } -  + }         /* Put catch outside of eval_instruction, so    * the setjmp won't affect the optimization of    * eval_instruction    */   static int o_catch(unsigned char *pc)   {    JMP_BUF tmp;    if(SETJMP(tmp))