e576bb2002-10-11Martin Nilsson /* || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. */
1b10db2002-10-08Martin Nilsson 
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
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
c5c70a2008-04-10Henrik Grubbström (Grubba)  * of these lists and the start sentinel.
5c8e891995-10-29Fredrik Hübinette (Hubbe)  * 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
c5c70a2008-04-10Henrik Grubbström (Grubba) #define IMEMBER(TYPE, FIELD, VALUE) TYPE FIELD; #define STACKMEMBER(TYPE, FIELD, VALUE) TYPE FIELD; #define ZMEMBER(TYPE, FIELD, VALUE) TYPE FIELD; #define SNAME(STRUCT_TAG, VAR_NAME) \ struct STRUCT_TAG { struct STRUCT_TAG *previous;
5c8e891995-10-29Fredrik Hübinette (Hubbe) #define SEND }; #endif
bad5162000-06-23Fredrik Hübinette (Hubbe) #ifdef EXTERN #define IMEMBER(X,Y,Z) #define STACKMEMBER(X,Y,z) #define ZMEMBER(X,Y,Z)
a5a3342006-07-05Martin Stjernholm #define SNAME(X,Y) PMOD_EXPORT 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,
18cec02014-05-22Per Hedbor #define STACKMEMBER(X,Y,Z) 0,
bad5162000-06-23Fredrik Hübinette (Hubbe) #define ZMEMBER(X,Y,Z) Z, #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
d7f7622009-08-17Henrik Grubbström (Grubba) #define IMEMBER(X,Y,Z) (nEw->Y=Pike_compiler->Y);
bad5162000-06-23Fredrik Hübinette (Hubbe) #define STACKMEMBER(X,Y,Z) (nEw->Y=Pike_compiler->Y);
d7f7622009-08-17Henrik Grubbström (Grubba) #define ZMEMBER(X,Y,Z) /* Zapped by the MEMSET in SNAME() below. */;
5c8e891995-10-29Fredrik Hübinette (Hubbe) #define SNAME(X,Y) { \
bad5162000-06-23Fredrik Hübinette (Hubbe)  struct X *nEw; \ nEw=ALLOC_STRUCT(X); \
d7f7622009-08-17Henrik Grubbström (Grubba)  MEMSET((char *)nEw, 0, sizeof(struct X)); \
bad5162000-06-23Fredrik Hübinette (Hubbe)  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 ZMEMBER(X,Y,Z)
fb2f661998-11-05Fredrik Hübinette (Hubbe) 
bad5162000-06-23Fredrik Hübinette (Hubbe) #define STACKMEMBER(X,Y,Z) DO_DEBUG_CODE( \ if(Pike_compiler->Y < oLd->Y) \
5aad932002-08-15Marcus Comstedt  Pike_fatal("Stack " #Y " shrunk %ld steps compilation, currently: %p.\n", \
6f95902000-08-17Henrik Grubbström (Grubba)  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
e021fe2008-04-14Henrik Grubbström (Grubba) #ifdef INIT
d7f7622009-08-17Henrik Grubbström (Grubba) #define IMEMBER(X,Y,Z) (c->Y=Pike_compiler->Y);
e021fe2008-04-14Henrik Grubbström (Grubba) #define STACKMEMBER(X,Y,Z) (c->Y=Pike_compiler->Y);
d7f7622009-08-17Henrik Grubbström (Grubba) #define ZMEMBER(X,Y,Z) /* Zapped by the MEMSET in SNAME() below. */;
e021fe2008-04-14Henrik Grubbström (Grubba) #define SNAME(X,Y) { \
d7f7622009-08-17Henrik Grubbström (Grubba)  MEMSET(c, 0, sizeof(struct X)); \
e021fe2008-04-14Henrik Grubbström (Grubba)  c->previous = Pike_compiler; #define SEND \ Pike_compiler = c; \ } #endif #ifdef EXIT #define IMEMBER(X,Y,Z) #define ZMEMBER(X,Y,Z) #define STACKMEMBER(X,Y,Z) DO_DEBUG_CODE( \ if(c->Y < oLd->Y) \ Pike_fatal("Stack " #Y " shrunk %ld steps compilation, currently: %p.\n", \ PTRDIFF_T_TO_LONG(oLd->Y - c->Y), c->Y); ) #define SNAME(X,Y) { \ struct X *oLd = c->previous; #define SEND \ if (Pike_compiler == c) { \ Pike_compiler=oLd; \ } else { \ struct program_state *tmp = Pike_compiler; \ while (tmp && (tmp->previous != c)) \ tmp = tmp->previous; \ if (tmp) tmp->previous = oLd; \ else Pike_fatal("Lost track of compiler_state %p\n", c); \ } \ } #undef PCODE #define PCODE(X) X #endif
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
de1d7d2000-07-10Henrik Grubbström (Grubba) #define STRMEMBER(X,Y) \
5aad932002-08-15Marcus Comstedt  PCODE(if(Pike_compiler->X) Pike_fatal("Variable " #X " not deallocated properly.\n");) \
de1d7d2000-07-10Henrik Grubbström (Grubba)  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)
ef24a82012-01-12Henrik Grubbström (Grubba)  ZMEMBER(INT_TYPE,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)
a2af982014-03-01Henrik Grubbström (Grubba)  ZMEMBER(node *,current_attributes,0)
c3cfe92000-07-10Henrik Grubbström (Grubba)  ZMEMBER(int,varargs,0)
ae81d52007-10-05Henrik Grubbström (Grubba)  ZMEMBER(int, num_create_args, 0)
d165152008-05-03Henrik Grubbström (Grubba)  ZMEMBER(int, num_inherits, 0) /* Used during second pass. */
de1d7d2000-07-10Henrik Grubbström (Grubba)  STRMEMBER(last_identifier,0)
bad5162000-06-23Fredrik Hübinette (Hubbe)  ZMEMBER(struct mapping *,module_index_cache,0)
8174c82001-03-03Henrik Grubbström (Grubba)  STACKMEMBER(struct pike_type **,type_stackp,type_stack) STACKMEMBER(struct pike_type ***,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)
cd2be32004-03-13Henrik Grubbström (Grubba)  ZMEMBER(int, flags, 0)
eaa4da2001-10-04Fredrik Hübinette (Hubbe)  ZMEMBER(struct compilation *,compiler,0)
44e3402013-10-09Arne Goedeke  ZMEMBER(struct block_allocator, node_allocator, BA_INIT_PAGES(sizeof(struct node_s), 2))
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 #undef ZMEMBER #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
e021fe2008-04-14Henrik Grubbström (Grubba) #undef EXIT #undef INIT
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) #undef PUSH #undef POP #undef DECLARE
fb2f661998-11-05Fredrik Hübinette (Hubbe) #undef DO_DEBUG_CODE