45 #define GEN_HEADER (1)
46 #define GEN_HEADER_SIZE (sizeof(gen_chunk)*GEN_HEADER)
74 #define gen_chunk_undefined ((gen_chunk *)(-16))
75 #define gen_chunk_undefined_p(c) ((c)==gen_chunk_undefined)
79 #define chunk_undefined gen_chunk_undefined
80 #define chunk_undefined_p(c) gen_chunk_undefined_p(c)
82 #define UNIT(x) "You don't want to take the value of a unit type, do you?"
83 #define BOOL(x) ((x).b)
84 #define CHAR(x) ((x).c)
85 #define INT(x) ((x).i)
86 #define FLOAT(x) ((x).f)
87 #define STRING(x) ((x).s)
88 #define CONSP(x) ((x).l)
89 #define SETP(x) ((x).t)
90 #define CHUNK(x) ((x).p)
91 #define HASH(x) ((x).h)
92 #define CHUNKP(x) ((x).p)
93 #define LIST(x) ((x).l)
94 #define SET(x) ((x).t)
95 #define VOID_STAR(x) ((x).e)
99 #define UNIT_TYPE "You don't want a unit type, do you?"
100 #define BOOL_TYPE bool
101 #define CHAR_TYPE char
103 #define FLOAT_TYPE float
104 #define STRING_TYPE string
105 #define VOID_STAR_TYPE void *
107 #define bool_TYPE bool
108 #define char_TYPE char
110 #define float_TYPE float
111 #define string_TYPE string
113 #define BOOL_CAST(x) BOOL(x)
114 #define CHAR_CAST(x) CHAR(x)
115 #define INT_CAST(x) INT(x)
116 #define FLOAT_CAST(x) FLOAT(x)
117 #define STRING_CAST(x) STRING(x)
118 #define VOID_STAR_CAST(x) VOID_STAR(x)
120 #define bool_CAST(x) BOOL(x)
121 #define char_CAST(x) CHAR(x)
122 #define int_CAST(x) INT(x)
123 #define float_CAST(x) FLOAT(x)
124 #define string_CAST(x) STRING(x)
126 #define CONSP_TYPE list
127 #define LIST_TYPE list
128 #define SETP_TYPE set
130 #define CHUNK_TYPE gen_chunkp
131 #define CHUNKP_TYPE gen_chunkp
132 #define HASH_TYPE hash_table
134 #define consp_TYPE list
135 #define list_TYPE list
136 #define setp_TYPE set
138 #define chunk_TYPE gen_chunkp
139 #define chunkp_TYPE gen_chunkp
140 #define hash_TYPE hash_table
142 #define CONSP_CAST(x) LIST(x)
143 #define LIST_CAST(x) LIST(x)
144 #define SETP_CAST(x) SET(x)
145 #define SET_CAST(x) SET(x)
146 #define CHUNK_CAST(x) CHUNK(x)
147 #define CHUNKP_CAST(x) CHUNKP(x)
148 #define HASH_CAST(x) HASH_TABLE(x)
150 #define consp_CAST(x) LIST(x)
151 #define list_CAST(x) LIST(x)
152 #define setp_CAST(x) SET(x)
153 #define set_CAST(x) SET(x)
154 #define chunk_CAST(x) CHUNK(x)
155 #define chunkp_CAST(x) CHUNKP(x)
156 #define hash_CAST(x) HASH_TABLE(x)
174 #define BOOL_NEWGEN_DOMAIN (bool_domain)
175 #define CHAR_NEWGEN_DOMAIN (char_domain)
176 #define INT_NEWGEN_DOMAIN (int_domain)
177 #define FLOAT_NEWGEN_DOMAIN (float_domain)
178 #define STRING_NEWGEN_DOMAIN (string_domain)
180 #define bool_NEWGEN_DOMAIN (bool_domain)
181 #define char_NEWGEN_DOMAIN (char_domain)
182 #define int_NEWGEN_DOMAIN (int_domain)
183 #define float_NEWGEN_DOMAIN (float_domain)
184 #define string_NEWGEN_DOMAIN (string_domain)
186 #define LIST_NEWGEN_DOMAIN (-1)
197 #define GEN_DBG_TRAV_LEAF 1
198 #define GEN_DBG_TRAV_SIMPLE 2
199 #define GEN_DBG_TRAV_OBJECT 4
200 #define GEN_DBG_CHECK 8
201 #define GEN_DBG_RECURSE 16
203 #define GEN_DBG_TRAV \
204 (GEN_DBG_TRAV_LEAF|GEN_DBG_TRAV_SIMPLE|GEN_DBG_TRAV_OBJECT)
227 void*(*)(FILE*,
int(*)(
void)),
228 void (*)(FILE*,
void*),
263 void (*
rwt)(
void *));
265 bool (*flt)(
void *,
void *
context),
276 #define gen_get_ancestor_type(i,o) gen_get_ancestor(i,o)
279 #define gen_start_recurse_ancestor_tracking()
280 #define gen_stop_recurse_ancestor_tracking()
283 #define gen_recurse(start,domain_number,flt,rwt)\
284 gen_recurse((start),(domain_number),((bool (*)(void*))(flt)),((void (*)(void*))(rwt)))
285 #define gen_context_recurse(start,ctxt,domain_number,flt,rwt)\
286 gen_context_recurse((start),(ctxt),(domain_number),((bool (*)(void*,void*))(flt)),((void (*)(void*,void*))(rwt)))
292 #ifndef MEMORY_INCLUDED
294 #define MEMORY_INCLUDED
297 #define gen_equal(lhs,rhs) (memcmp((lhs),(rhs))==0)
303 #define GEN_CHECK(e,t) (gen_check((e),(t)),e)
304 #define GEN_CHECK_ALLOC 1
306 #define GEN_CHECK(e,t) (e)
307 #define GEN_CHECK_ALLOC 0
313 #define NEWGEN_CHECK_TYPE(dom, item) \
315 _int __type = dom, __itype; \
316 void * __item = (void *) item; \
317 message_assert("valid required domaine number", \
318 __type>0 && __type<MAX_DOMAIN); \
319 if (Domains[__type].domain && \
320 Domains[__type].domain->co.type==CONSTRUCTED_DT) { \
321 message_assert("some item", __item!=NULL); \
322 message_assert("item is defined", __item!=gen_chunk_undefined); \
323 __itype = ((gen_chunk*) __item)->i; \
324 if (__itype!=__type) { \
325 message_assert("valid item domain number", \
326 __itype>0 && __itype<MAX_DOMAIN); \
327 fprintf(stderr, "type error: expecting %s, got %s\n", \
328 Domains[__type].name, Domains[__itype].name); \
329 message_assert("check type", __itype==__type); \
char * alloc(int size)
ALLOC is an "iron-clad" version of malloc(3).
int current_shared_obj_table_size(void)
for debug
void gen_free GEN_PROTO((gen_chunk *))
recursion and utilities
int gen_debug
Function interface for user applications.
#define gen_context_recurse(start, ctxt, domain_number, flt, rwt)
union gen_chunk gen_chunk
A gen_chunk is used to store every object.
internal_type
some other macros need the domain number to keep track of the type.
@ unit_domain
Should start at 1 to be able to iterate on them with gen_recurse() functions.
void *() gen_extract_func_t(const gen_chunk)
#define gen_recurse(start, domain_number, flt, rwt)
union gen_chunk * gen_chunkp
void gen_free(gen_chunk *obj)
version without shared_pointers.
gen_chunk * gen_alloc(int size, int gen_check_p, int dom,...)
allocates something in newgen.
int gen_write_tabulated(FILE *fd, int domain)
GEN_WRITE_TABULATED writes the tabulated object TABLE on FD.
string gen_domain_name(int t)
GEN_DOMAIN_NAME returns the domain name, and may be used for debug purposes.
int gen_type_translation_old_to_actual(int n)
forwards conversion
void gen_type_translation_reset(void)
int gen_read_tabulated(FILE *file, int create_p)
GEN_READ_TABULATED reads FILE to update the Gen_tabulated_ table.
void gen_type_translation_write(string filename)
int gen_consistent_p(gen_chunk *obj)
GEN_CONSISTENT_P dynamically checks the type correctness of OBJ.
bool gen_sharing_p(gen_chunk *obj1, gen_chunk *obj2)
int gen_defined_p(gen_chunk *obj)
gen_chunk * gen_copy_tree_with_sharing(gen_chunk *obj)
for re-entry only in gen_copy_tree...
gen_chunk * gen_check(gen_chunk *obj, int t)
GEN_CHECK checks that the gen_chunk received OBJ is of the appropriate TYPE.
int gen_free_tabulated(int domain)
free tabulated elements of this domain.
gen_chunk * gen_make_array(num)
GEN_MAKE_ARRAY allocates an initialized array of NUM gen_chunks.
void gen_init_external(int which, void *(*read)(FILE *, int(*)(void)), void(*write)(FILE *, void *), void(*free)(void *), void *(*copy)(void *), int(*allocated_memory)(void *))
GEN_INIT_EXTERNAL defines entry points for free, read and write functions of external types.
int gen_type(gen_chunk *obj)
GEN_TYPE returns the domain number for the object in argument.
gen_chunk * gen_read(FILE *file)
GEN_READ reads any object from the FILE stream.
int gen_type_translation_actual_to_old(int n)
backwards conversion
void gen_read_spec(char *spec,...)
gen_chunk * gen_copy_tree(gen_chunk *obj)
int gen_allocated_memory(gen_chunk *obj)
re-entry is automatic for this function.
int gen_tabulated_consistent_p(int domain)
void gen_type_translation_default(void)
void gen_write(FILE *fd, gen_chunk *obj)
GEN_WRITE writes the OBJect on the stream FD.
void gen_type_translation_read(string filename)
set current type translation table according to file
static char start[1024]
The name of the variable from which to start counting domain numbers.
void gen_recurse_stop(void *obj)
Tells the recursion not to go in this object.
void gen_full_recurse(void *o, void *context,...)
Full multi-recursion with context function visitor.
void gen_multi_recurse(void *o,...)
Multi recursion visitor function.
void gen_context_multi_recurse(void *o, void *context,...)
Multi-recursion with context function visitor.
gen_chunk * gen_get_recurse_previous_visited_object(void)
Get the previously visited object.
gen_chunk * gen_get_current_ancestor(int)
Return current object of that type...
gen_chunk * gen_get_current_object(void)
return the current visited object, or NULL if not in a recursion.
gen_chunk * gen_get_ancestor(int, const void *)
return the first ancestor object found of the given type.
gen_chunk * gen_get_recurse_ancestor(const void *)
Get the first ancestor object encountered during the recursion for the given object.
gen_chunk * gen_get_recurse_current_ancestor(void)
Get the ancestor of the current object.
void * gen_NULL(__attribute__((unused)) void *unused)
idem with a void* return
void gen_null2(__attribute__((unused)) void *u1, __attribute__((unused)) void *u2)
idem with 2 args, to please overpeaky compiler checks
void * gen_core_NULL(__attribute__((unused)) void *p)
bool gen_false(__attribute__((unused)) gen_chunk *unused)
Return false and ignore the argument.
void gen_core(__attribute__((unused)) void *p)
Abort when called.
void * gen_NULL2(__attribute__((unused)) void *u1, __attribute__((unused)) void *u2)
idem with 2 args, to please overpeaky compiler checks
bool gen_true2(__attribute__((unused)) gen_chunk *u1, __attribute__((unused)) void *u2)
void gen_null(__attribute__((unused)) void *unused)
Ignore the argument.
bool gen_false2(__attribute__((unused)) gen_chunk *u1, __attribute__((unused)) void *u2)
bool gen_true(__attribute__((unused)) gen_chunk *unused)
Return true and ignore the argument.
FI: I do not understand why the type is duplicated at the set level.
The structure used to build lists in NewGen.
void gen_clear_tabulated_element(gen_chunk *obj)
GEN_CLEAR_TABULATED_ELEMENT only clears the entry for object OBJ in the gen_tabulated_ and gen_tabula...
int gen_read_and_check_tabulated(FILE *file, int create_p)
A gen_chunk is used to store every object.
void * e
For externals (foreign objects)
struct cons * l
A pointer to a list element.