cb22561995-10-11Fredrik Hübinette (Hubbe) /*\
06983f1996-09-22Fredrik Hübinette (Hubbe) ||| This file a part of Pike, and is copyright by Fredrik Hubinette ||| Pike is distributed as GPL (General Public License)
cb22561995-10-11Fredrik Hübinette (Hubbe) ||| See the files COPYING and DISCLAIMER for more information. \*/
24ddc71998-03-28Henrik Grubbström (Grubba)  /*
ecb7df1999-04-12Henrik Grubbström (Grubba)  * $Id: interpret.h,v 1.29 1999/04/12 20:00:37 grubba Exp $
24ddc71998-03-28Henrik Grubbström (Grubba)  */
5267b71995-08-09Fredrik Hübinette (Hubbe) #ifndef INTERPRET_H #define INTERPRET_H
442aea1997-01-28Fredrik Hübinette (Hubbe) #include "global.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "program.h"
dfa5b31996-12-05Fredrik Hübinette (Hubbe) #ifndef STRUCT_FRAME_DECLARED #define STRUCT_FRAME_DECLARED #endif
4218011999-01-31Fredrik Hübinette (Hubbe) struct pike_frame
5267b71995-08-09Fredrik Hübinette (Hubbe) {
4218011999-01-31Fredrik Hübinette (Hubbe)  INT32 refs; /* must be first */ INT32 args; INT16 fun; INT16 num_locals; INT16 num_args; INT16 malloced_locals; struct pike_frame *next; struct pike_frame *scope;
5267b71995-08-09Fredrik Hübinette (Hubbe)  unsigned char *pc; struct svalue *locals;
5017631998-06-05Fredrik Hübinette (Hubbe)  struct svalue *expendible;
5267b71995-08-09Fredrik Hübinette (Hubbe)  struct object *current_object; struct inherit context; char *current_storage; };
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
fa382f1996-06-21Fredrik Hübinette (Hubbe) #define debug_check_stack() do{if(sp<evaluator_stack)fatal("Stack error.\n");}while(0)
9649491998-02-27Fredrik Hübinette (Hubbe) #define check__positive(X,Y) if((X)<0) fatal(Y) #include "error.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) #else
9649491998-02-27Fredrik Hübinette (Hubbe) #define check__positive(X,Y)
fa382f1996-06-21Fredrik Hübinette (Hubbe) #define debug_check_stack()
5267b71995-08-09Fredrik Hübinette (Hubbe) #endif
fa382f1996-06-21Fredrik Hübinette (Hubbe) 
7e97c31999-01-21Fredrik Hübinette (Hubbe) #define check_stack(X) do { \ if(sp - evaluator_stack + (X) >= stack_size) \ error("Stack overflow.\n"); \ }while(0) #define check_mark_stack(X) do { \ if(mark_sp - mark_stack + (X) >= stack_size) \ error("Mark stack overflow.\n"); \ }while(0) #define check_c_stack(X) do { \ long x_= ((char *)&x_) + STACK_DIRECTION * (X) - stack_top ; \ x_*=STACK_DIRECTION; \ if(x_>0) \ error("C stack overflow.\n"); \ }while(0)
fa382f1996-06-21Fredrik Hübinette (Hubbe) #define pop_stack() do{ free_svalue(--sp); debug_check_stack(); }while(0)
2d12341997-03-10Fredrik Hübinette (Hubbe) 
9649491998-02-27Fredrik Hübinette (Hubbe) #define pop_n_elems(X) \ do { int x_=(X); if(x_) { \ check__positive(x_,"Popping negative number of args....\n"); \ sp-=x_; debug_check_stack(); \ free_svalues(sp,x_,BIT_MIXED); \ } } while (0)
3c0c281998-01-26Fredrik Hübinette (Hubbe) #define push_program(P) do{ struct program *_=(P); debug_malloc_touch(_); sp->u.program=_; sp++->type=T_PROGRAM; }while(0)
04925b1996-09-29Fredrik Hübinette (Hubbe) #define push_int(I) do{ INT32 _=(I); sp->u.integer=_;sp->type=T_INT;sp++->subtype=NUMBER_NUMBER; }while(0)
3c0c281998-01-26Fredrik Hübinette (Hubbe) #define push_mapping(M) do{ struct mapping *_=(M); debug_malloc_touch(_); sp->u.mapping=_; sp++->type=T_MAPPING; }while(0) #define push_array(A) do{ struct array *_=(A); debug_malloc_touch(_); sp->u.array=_ ;sp++->type=T_ARRAY; }while(0) #define push_multiset(L) do{ struct multiset *_=(L); debug_malloc_touch(_); sp->u.multiset=_; sp++->type=T_MULTISET; }while(0) #define push_string(S) do{ struct pike_string *_=(S); debug_malloc_touch(_); sp->subtype=0; sp->u.string=_; sp++->type=T_STRING; }while(0) #define push_object(O) do{ struct object *_=(O); debug_malloc_touch(_); sp->u.object=_; sp++->type=T_OBJECT; }while(0)
04925b1996-09-29Fredrik Hübinette (Hubbe) #define push_float(F) do{ float _=(F); sp->u.float_number=_; sp++->type=T_FLOAT; }while(0) #define push_text(T) push_string(make_shared_string((T)))
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) #define push_constant_text(T) do{ sp->subtype=0; MAKE_CONSTANT_SHARED_STRING(sp->u.string,T); sp++->type=T_STRING; }while(0)
2d12341997-03-10Fredrik Hübinette (Hubbe) 
3c0c281998-01-26Fredrik Hübinette (Hubbe) #define ref_push_program(P) do{ struct program *_=(P); debug_malloc_touch(_); _->refs++; sp->u.program=_; sp++->type=T_PROGRAM; }while(0) #define ref_push_mapping(M) do{ struct mapping *_=(M); debug_malloc_touch(_); _->refs++; sp->u.mapping=_; sp++->type=T_MAPPING; }while(0) #define ref_push_array(A) do{ struct array *_=(A); debug_malloc_touch(_); _->refs++; sp->u.array=_ ;sp++->type=T_ARRAY; }while(0) #define ref_push_multiset(L) do{ struct multiset *_=(L); debug_malloc_touch(_); _->refs++; sp->u.multiset=_; sp++->type=T_MULTISET; }while(0) #define ref_push_string(S) do{ struct pike_string *_=(S); debug_malloc_touch(_); _->refs++; sp->subtype=0; sp->u.string=_; sp++->type=T_STRING; }while(0) #define ref_push_object(O) do{ struct object *_=(O); debug_malloc_touch(_); _->refs++; sp->u.object=_; sp++->type=T_OBJECT; }while(0)
2d12341997-03-10Fredrik Hübinette (Hubbe) 
04925b1996-09-29Fredrik Hübinette (Hubbe) #define push_svalue(S) do { struct svalue *_=(S); assign_svalue_no_free(sp,_); sp++; }while(0)
5267b71995-08-09Fredrik Hübinette (Hubbe) 
3635bb1998-02-19Fredrik Hübinette (Hubbe) #define stack_dup() push_svalue(sp-1) #define stack_swap() do { struct svalue _=sp[-1]; sp[-1]=sp[-2]; sp[-2]=_; } while(0)
4218011999-01-31Fredrik Hübinette (Hubbe) #define free_pike_frame(F) do{ struct pike_frame *f_=(F); debug_malloc_touch(f_); if(!--f_->refs) really_free_pike_frame(f_); }while(0) #define POP_PIKE_FRAME() do { \
ae95031999-04-07Fredrik Hübinette (Hubbe)  struct pike_frame *tmp_=fp->next; \ if(!--fp->refs) \
4218011999-01-31Fredrik Hübinette (Hubbe)  { \
ae95031999-04-07Fredrik Hübinette (Hubbe)  really_free_pike_frame(fp); \
4218011999-01-31Fredrik Hübinette (Hubbe)  }else{ \
ecb7df1999-04-12Henrik Grubbström (Grubba)  DO_IF_DEBUG(if( fp->locals+fp->num_locals>sp) fatal("Stack failure in POP_PIKE_FRAME!\n")); \
ae95031999-04-07Fredrik Hübinette (Hubbe)  if(fp->num_locals) \
4218011999-01-31Fredrik Hübinette (Hubbe)  { \ struct svalue *s=(struct svalue *)xalloc(sizeof(struct svalue)* \
ae95031999-04-07Fredrik Hübinette (Hubbe)  fp->num_locals); \ assign_svalues_no_free(s,fp->locals,fp->num_locals,BIT_MIXED); \ fp->locals=s; \ fp->malloced_locals=1; \
4218011999-01-31Fredrik Hübinette (Hubbe)  }else{ \
ae95031999-04-07Fredrik Hübinette (Hubbe)  fp->locals=0; \
4218011999-01-31Fredrik Hübinette (Hubbe)  } \
ae95031999-04-07Fredrik Hübinette (Hubbe)  fp->next=0; \
4218011999-01-31Fredrik Hübinette (Hubbe)  } \
ae95031999-04-07Fredrik Hübinette (Hubbe)  fp=tmp_; \
4218011999-01-31Fredrik Hübinette (Hubbe)  }while(0)
3635bb1998-02-19Fredrik Hübinette (Hubbe) 
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) enum apply_type { APPLY_STACK, /* The function is the first argument */ APPLY_SVALUE, /* arg1 points to an svalue containing the function */ APPLY_LOW /* arg1 is the object pointer,(int)arg2 the function */ }; #define apply_low(O,FUN,ARGS) \ mega_apply(APPLY_LOW, (ARGS), (void*)(O),(void*)(FUN)) #define strict_apply_svalue(SVAL,ARGS) \ mega_apply(APPLY_SVALUE, (ARGS), (void*)(SVAL),0)
5267b71995-08-09Fredrik Hübinette (Hubbe) #define APPLY_MASTER(FUN,ARGS) \ do{ \ static int fun_,master_cnt=0; \ struct object *master_ob=master(); \ if(master_cnt != master_ob->prog->id) \ { \ fun_=find_identifier(FUN,master_ob->prog); \ master_cnt = master_ob->prog->id; \ } \ apply_low(master_ob, fun_, ARGS); \ }while(0) #define SAFE_APPLY_MASTER(FUN,ARGS) \ do{ \ static int fun_,master_cnt=0; \ struct object *master_ob=master(); \ if(master_cnt != master_ob->prog->id) \ { \ fun_=find_identifier(FUN,master_ob->prog); \ master_cnt = master_ob->prog->id; \ } \ safe_apply_low(master_ob, fun_, ARGS); \ }while(0)
0a861b1997-09-17Fredrik Hübinette (Hubbe) #define check_threads_etc() \ call_callback(& evaluator_callbacks, (void *)0)
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
c846981997-10-13Fredrik Hübinette (Hubbe) #define fast_check_threads_etc(X) do { \ static int div_; if(d_flag || !(div_++& ((1<<(X))-1))) check_threads_etc(); } while(0) #else
0a861b1997-09-17Fredrik Hübinette (Hubbe) #define fast_check_threads_etc(X) do { \ static int div_; if(!(div_++& ((1<<(X))-1))) check_threads_etc(); } while(0)
c846981997-10-13Fredrik Hübinette (Hubbe) #endif
0a861b1997-09-17Fredrik Hübinette (Hubbe) 
4218011999-01-31Fredrik Hübinette (Hubbe) #include "block_alloc_h.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) /* Prototypes begin here */
be478c1997-08-30Henrik Grubbström (Grubba) void push_sp_mark(void); int pop_sp_mark(void); void init_interpreter(void);
5267b71995-08-09Fredrik Hübinette (Hubbe) void lvalue_to_svalue_no_free(struct svalue *to,struct svalue *lval); void assign_lvalue(struct svalue *lval,struct svalue *from); union anything *get_pointer_if_this_type(struct svalue *lval, TYPE_T t);
be478c1997-08-30Henrik Grubbström (Grubba) void print_return_value(void); void reset_evaluator(void);
5267b71995-08-09Fredrik Hübinette (Hubbe) struct backlog;
5683de1995-11-06Fredrik Hübinette (Hubbe) void dump_backlog(void);
4218011999-01-31Fredrik Hübinette (Hubbe) BLOCK_ALLOC(pike_frame,128) static void restore_creds(struct object *creds);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) void mega_apply(enum apply_type type, INT32 args, void *arg1, void *arg2);
3c0c281998-01-26Fredrik Hübinette (Hubbe) void f_call_function(INT32 args);
5267b71995-08-09Fredrik Hübinette (Hubbe) int apply_low_safe_and_stupid(struct object *o, INT32 offset); void safe_apply_low(struct object *o,int fun,int args);
5683de1995-11-06Fredrik Hübinette (Hubbe) void safe_apply(struct object *o, char *fun ,INT32 args);
b208c11996-08-03Fredrik Hübinette (Hubbe) void apply_lfun(struct object *o, int fun, int args);
5267b71995-08-09Fredrik Hübinette (Hubbe) void apply_shared(struct object *o,
06983f1996-09-22Fredrik Hübinette (Hubbe)  struct pike_string *fun,
5267b71995-08-09Fredrik Hübinette (Hubbe)  int args); void apply(struct object *o, char *fun, int args); void apply_svalue(struct svalue *s, INT32 args);
be478c1997-08-30Henrik Grubbström (Grubba) void slow_check_stack(void); void cleanup_interpret(void);
b660c81999-03-01Fredrik Hübinette (Hubbe) void really_clean_up_interpret(void);
5267b71995-08-09Fredrik Hübinette (Hubbe) /* Prototypes end here */ extern struct svalue *sp; extern struct svalue **mark_sp;
b208c11996-08-03Fredrik Hübinette (Hubbe) extern struct svalue *evaluator_stack; extern struct svalue **mark_stack;
4218011999-01-31Fredrik Hübinette (Hubbe) extern struct pike_frame *fp; /* pike_frame pointer */
4908871998-08-10Fredrik Hübinette (Hubbe) extern char *stack_top;
0f887e1996-08-12Fredrik Hübinette (Hubbe) extern int stack_size;
07513e1996-10-04Fredrik Hübinette (Hubbe) extern int evaluator_stack_malloced, mark_stack_malloced;
a29e021996-10-15Fredrik Hübinette (Hubbe) struct callback;
81b84e1996-12-03Fredrik Hübinette (Hubbe) extern struct callback_list evaluator_callbacks;
b504ed1997-09-21Fredrik Hübinette (Hubbe) extern void call_callback(struct callback_list *, void *);
e132001998-11-19Fredrik Hübinette (Hubbe)  #ifdef PROFILING #ifdef HAVE_GETHRTIME extern long long accounted_time; extern long long time_base; #endif #endif
5267b71995-08-09Fredrik Hübinette (Hubbe) #endif