23 #ifndef NEWGEN_GENERIC_FUNCTION_INCLUDED
24 #define NEWGEN_GENERIC_FUNCTION_INCLUDED
28 #define GENERIC_STATIC_OBJECT(PREFIX, name, type) \
29 static type name##_object = type##_undefined; \
30 PREFIX bool __attribute__ ((unused)) name##_undefined_p(void) { \
31 return name##_object==type##_undefined; \
33 PREFIX void __attribute__ ((unused)) reset_##name(void) { \
34 message_assert("must reset sg defined", !name##_undefined_p()); \
35 name##_object=type##_undefined; \
37 PREFIX void __attribute__ ((unused)) error_reset_##name(void) { \
38 name##_object=type##_undefined; \
40 PREFIX void __attribute__ ((unused)) set_##name(type o) { \
41 message_assert("must set sg undefined", name##_undefined_p()); \
44 PREFIX type __attribute__ ((unused)) get_##name(void) { \
45 message_assert("must get sg defined", !name##_undefined_p()); \
46 return name##_object; \
49 #define GENERIC_STATIC_STATUS(PREFIX, name, type, init, cloze) \
50 GENERIC_STATIC_OBJECT(PREFIX, name, type) \
51 PREFIX void __attribute__ ((unused)) init_##name(void) { \
52 message_assert("must initialize sg undefined", name##_undefined_p()); \
53 name##_object = init; \
55 PREFIX void __attribute__ ((unused)) close_##name(void) { \
56 message_assert("must close sg defined", !name##_undefined_p()); \
57 cloze(name##_object); name##_object = type##_undefined; \
72 #define GENERIC_FUNCTION(PREFIX, name, type) \
73 GENERIC_STATIC_STATUS(PREFIX, name, type, make_##type(), free_##type) \
74 PREFIX void __attribute__ ((unused)) store_##name(type##_key_type k, type##_value_type v) { \
75 extend_##type(name##_object, k, v); \
77 PREFIX void __attribute__ ((unused)) update_##name(type##_key_type k, type##_value_type v) { \
78 update_##type(name##_object, k, v); \
80 PREFIX type##_value_type __attribute__ ((unused)) load_##name(type##_key_type k) { \
81 return(apply_##type(name##_object, k)); \
83 PREFIX type##_value_type __attribute__ ((unused)) delete_##name(type##_key_type k) { \
84 return(delete_##type(name##_object, k)); \
86 PREFIX bool __attribute__ ((unused)) bound_##name##_p(type##_key_type k) { \
87 return(bound_##type##_p(name##_object, k)); \
89 PREFIX void __attribute__ ((unused)) store_or_update_##name(type##_key_type k, type##_value_type v) { \
90 if (bound_##name##_p(k)) \
91 update_##name(k, v); \
96 #define GENERIC_LOCAL_FUNCTION(name, type)\
97 GENERIC_FUNCTION(static, name, type)
99 #define GENERIC_GLOBAL_FUNCTION(name, type)\
100 GENERIC_FUNCTION(extern, name, type)