5c8e891995-10-29Fredrik Hübinette (Hubbe) /*
ac87152000-09-25Fredrik Hübinette (Hubbe)  * $Id: compilation.h,v 1.21 2000/09/26 00:17:45 hubbe Exp $
24ddc71998-03-28Henrik Grubbström (Grubba)  *
5c8e891995-10-29Fredrik Hübinette (Hubbe)  * Compilator state push / pop operator construction file * * (Can you tell I like macros?) */ /*
0f39a41999-12-29Martin Stjernholm  * IMEMBER: do not reset this member when pushing
fb2f661998-11-05Fredrik Hübinette (Hubbe)  * DMEMBER: This member should be the same when popping as when pushing.
5c8e891995-10-29Fredrik Hübinette (Hubbe)  * ZMEMBER: reset this member to zero when pushing
fb2f661998-11-05Fredrik Hübinette (Hubbe)  * STACKMEMBER: Like IMEMBER, but is not allowed to become more when popping
5c8e891995-10-29Fredrik Hübinette (Hubbe)  * * defining STRUCT defines the structures * defining DECLARE creates global vars for saving linked list * of these lists... * defining PUSH pushes the selected state(s) on the stack(s) * defining POP pops the selected state(s) from the stack(s) * * define PROGRAM_STATE to select the program state */
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
fb2f661998-11-05Fredrik Hübinette (Hubbe) #define DO_DEBUG_CODE(X) X #else #define DO_DEBUG_CODE(X) #endif
5c8e891995-10-29Fredrik Hübinette (Hubbe) #ifdef STRUCT
bad5162000-06-23Fredrik Hübinette (Hubbe) #define IMEMBER(X,Y,Z) X Y ; #define DMEMBER(X,Y,Z) X Y ; #define STACKMEMBER(X,Y,Z) X Y ; #define IMEMBER2(X,Y,Z,Q) X Y Z ; #define ZMEMBER(X,Y,Z) X Y ; #define ZMEMBER2(X,Y,Z,Q) X Y Z ;
5c8e891995-10-29Fredrik Hübinette (Hubbe) #define SNAME(X,Y) struct X { struct X *previous; #define SEND }; #endif
bad5162000-06-23Fredrik Hübinette (Hubbe) #ifdef EXTERN #define IMEMBER(X,Y,Z) #define DMEMBER(X,Y,Z) #define STACKMEMBER(X,Y,z) #define IMEMBER2(X,Y,Z,Q) #define ZMEMBER(X,Y,Z) #define ZMEMBER2(X,Y,Z,Q) #define SNAME(X,Y) extern struct X * Y;
5c8e891995-10-29Fredrik Hübinette (Hubbe) #define SEND #endif
bad5162000-06-23Fredrik Hübinette (Hubbe) #ifdef DECLARE #define IMEMBER(X,Y,Z) Z, #define DMEMBER(X,Y,Z) Z, #define STACKMEMBER(X,Y,Z) Z, #define IMEMBER2(X,Y,Z,Q) Q, #define ZMEMBER(X,Y,Z) Z, #define ZMEMBER2(X,Y,Z,Q) Q, #define SNAME(X,Y) \ extern struct X PIKE_CONCAT(Y,_base); \ struct X * Y = & PIKE_CONCAT(Y,_base); \ struct X PIKE_CONCAT(Y,_base) = { 0, #define SEND }; #endif
5c8e891995-10-29Fredrik Hübinette (Hubbe) #ifdef PUSH
bad5162000-06-23Fredrik Hübinette (Hubbe) #define IMEMBER(X,Y,Z) MEMCPY((char *)&(nEw->Y), (char *)&(Pike_compiler->Y), sizeof(nEw->Y)); #define DMEMBER(X,Y,Z) IMEMBER(X,Y) #define STACKMEMBER(X,Y,Z) (nEw->Y=Pike_compiler->Y); #define IMEMBER2(X,Y,Z,Q) IMEMBER(X,Y) #define ZMEMBER(X,Y,Z) MEMSET((char *)&(nEw->Y), 0, sizeof(nEw->Y)); #define ZMEMBER2(X,Y,Z,Q) ZMEMBER(X,Y)
5c8e891995-10-29Fredrik Hübinette (Hubbe) #define SNAME(X,Y) { \
bad5162000-06-23Fredrik Hübinette (Hubbe)  struct X *nEw; \ nEw=ALLOC_STRUCT(X); \ nEw->previous=Pike_compiler; #define SEND \ Pike_compiler=nEw; \ }
fb2f661998-11-05Fredrik Hübinette (Hubbe) 
5c8e891995-10-29Fredrik Hübinette (Hubbe) #endif #ifdef POP
bad5162000-06-23Fredrik Hübinette (Hubbe) #define IMEMBER(X,Y,Z) #define IMEMBER2(X,Y,Z,Q) IMEMBER(X,Y) #define ZMEMBER(X,Y,Z) #define ZMEMBER2(X,Y,Z,Q) ZMEMBER(X,Y)
fb2f661998-11-05Fredrik Hübinette (Hubbe) 
bad5162000-06-23Fredrik Hübinette (Hubbe) #define DMEMBER(X,Y,Z) DO_DEBUG_CODE( \ if(MEMCMP((char *)&(Pike_compiler->Y), (char *)&(oLd->Y), sizeof(oLd->Y))) \
fb2f661998-11-05Fredrik Hübinette (Hubbe)  fatal("Variable " #Y " became whacked during compilation.\n"); ) \ IMEMBER(X,Y)
bad5162000-06-23Fredrik Hübinette (Hubbe) #define STACKMEMBER(X,Y,Z) DO_DEBUG_CODE( \ if(Pike_compiler->Y < oLd->Y) \
6f95902000-08-17Henrik Grubbström (Grubba)  fatal("Stack " #Y " shrunk %ld steps compilation, currently: %p.\n", \ PTRDIFF_T_TO_LONG(oLd->Y - Pike_compiler->Y), Pike_compiler->Y); )
fb2f661998-11-05Fredrik Hübinette (Hubbe) 
5c8e891995-10-29Fredrik Hübinette (Hubbe) #define SNAME(X,Y) { \
bad5162000-06-23Fredrik Hübinette (Hubbe)  struct X *oLd=Pike_compiler->previous; #define SEND \ free((char *)Pike_compiler); \ Pike_compiler=oLd; \
5c8e891995-10-29Fredrik Hübinette (Hubbe)  }
bad5162000-06-23Fredrik Hübinette (Hubbe) 
2066df1995-11-15Fredrik Hübinette (Hubbe) #define PCODE(X) X #else #define PCODE(X) #endif
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
de1d7d2000-07-10Henrik Grubbström (Grubba) #define STRMEMBER(X,Y) \ PCODE(if(Pike_compiler->X) fatal("Variable " #X " not deallocated properly.\n");) \ ZMEMBER(struct pike_string *,X,Y)
2066df1995-11-15Fredrik Hübinette (Hubbe) #else
de1d7d2000-07-10Henrik Grubbström (Grubba) #define STRMEMBER(X,Y) \ ZMEMBER(struct pike_string *,X,Y)
5c8e891995-10-29Fredrik Hübinette (Hubbe) #endif
bad5162000-06-23Fredrik Hübinette (Hubbe)  SNAME(program_state,Pike_compiler) ZMEMBER(INT32,last_line,0)
de1d7d2000-07-10Henrik Grubbström (Grubba)  STRMEMBER(last_file,0)
bad5162000-06-23Fredrik Hübinette (Hubbe)  ZMEMBER(struct object *,fake_object,0) ZMEMBER(struct program *,new_program,0) ZMEMBER(struct program *,malloc_size_program,0) ZMEMBER(node *,init_node,0) ZMEMBER(INT32,last_pc,0) ZMEMBER(int,num_parse_error,0) ZMEMBER(struct compiler_frame *,compiler_frame,0) ZMEMBER(INT32,num_used_modules,0) IMEMBER(int,compiler_pass,0) ZMEMBER(int,local_class_counter,0) ZMEMBER(int,catch_level,0)
019b3d2000-07-09Henrik Grubbström (Grubba)  ZMEMBER(INT32,current_modifiers,0)
c3cfe92000-07-10Henrik Grubbström (Grubba)  ZMEMBER(int,varargs,0)
de1d7d2000-07-10Henrik Grubbström (Grubba)  STRMEMBER(last_identifier,0)
bad5162000-06-23Fredrik Hübinette (Hubbe)  ZMEMBER(struct mapping *,module_index_cache,0) STACKMEMBER(unsigned char *,type_stackp,type_stack) STACKMEMBER(unsigned char **,pike_type_mark_stackp,pike_type_mark_stack)
342fef2000-08-23Fredrik Hübinette (Hubbe)  ZMEMBER(INT32,parent_identifier,0)
ac87152000-09-25Fredrik Hübinette (Hubbe)  IMEMBER(int, compat_major, PIKE_MAJOR_VERSION) IMEMBER(int, compat_minor, PIKE_MINOR_VERSION)
5c8e891995-10-29Fredrik Hübinette (Hubbe)  SEND
b8cda21997-01-21Fredrik Hübinette (Hubbe) 
2066df1995-11-15Fredrik Hübinette (Hubbe) #undef PCODE #undef STRMEMBER
5c8e891995-10-29Fredrik Hübinette (Hubbe) #undef IMEMBER
fb2f661998-11-05Fredrik Hübinette (Hubbe) #undef DMEMBER
5c8e891995-10-29Fredrik Hübinette (Hubbe) #undef ZMEMBER
9f44771995-11-20Fredrik Hübinette (Hubbe) #undef IMEMBER2 #undef ZMEMBER2
5c8e891995-10-29Fredrik Hübinette (Hubbe) #undef SNAME #undef SEND
84cb1f1998-11-08Fredrik Hübinette (Hubbe) #undef STACKMEMBER
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
bad5162000-06-23Fredrik Hübinette (Hubbe) #undef EXTERN
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) #undef STRUCT #undef PUSH #undef POP #undef DECLARE
fb2f661998-11-05Fredrik Hübinette (Hubbe) #undef DO_DEBUG_CODE