diff -r f332b62cd2c1 -r c6aed7e5f070 lib/accessor.h --- a/lib/accessor.h Tue Dec 01 09:03:33 2009 +0100 +++ b/lib/accessor.h Wed Dec 02 16:11:01 2009 +0100 @@ -1,65 +1,64 @@ #ifndef __ACCESSOR_H #define __ACCESSOR_H + // variable declaration macros #define __DECLARE_VAR(type, name)\ - type name; + __IEC_##type##_t name; #define __DECLARE_GLOBAL(type, resource, name)\ - type resource##__##name;\ - static type *GLOBAL__##name = &resource##__##name;\ - type __GET_GLOBAL_##name(void) {return *GLOBAL__##name;}\ - void __SET_GLOBAL_##name(type value) {*GLOBAL__##name = value;} + __IEC_##type##_t resource##__##name;\ + static __IEC_##type##_t *GLOBAL__##name = &resource##__##name; #define __DECLARE_GLOBAL_LOCATION(type, location)\ extern type *location; #define __DECLARE_GLOBAL_LOCATED(type, resource, name)\ - type *resource##__##name;\ - static type *GLOBAL__##name;\ - type __GET_GLOBAL_##name(void) {return *GLOBAL__##name;}\ - void __SET_GLOBAL_##name(type value) {*GLOBAL__##name = value;} + __IEC_##type##_p resource##__##name;\ + static __IEC_##type##_p *GLOBAL__##name; #define __DECLARE_EXTERNAL(type, name)\ - type *name; + __IEC_##type##_p name; #define __DECLARE_LOCATED(type, name)\ - type *name; + __IEC_##type##_p name; // variable initialization macros -#define __INIT_VAR(name, initial)\ - name = initial; -#define __INIT_GLOBAL(name, initial)\ - *GLOBAL__##name = initial; -#define __INIT_GLOBAL_LOCATED(resource, name, location)\ - resource##__##name = location;\ - GLOBAL__##name = location; -#define __INIT_EXTERNAL(type, global, name)\ - {extern type *GLOBAL__##global;\ - name = GLOBAL__##global;} -#define __INIT_LOCATED(type, location, name)\ +#define __INIT_STRUCT(name, initial, retained)\ + name.value = initial;\ + name.flags |= retained?4:0; +#define __INIT_VAR(name, initial, retained)\ + __INIT_STRUCT(name, initial, retained) +#define __INIT_GLOBAL(name, initial, retained)\ + __INIT_STRUCT((*GLOBAL__##name), initial, retained) +#define __INIT_GLOBAL_LOCATED(resource, name, location, retained)\ + __INIT_STRUCT(resource##__##name, location, retained) +#define __INIT_EXTERNAL(type, global, name, retained)\ + {extern __IEC_##type##_t *GLOBAL__##global;\ + __INIT_STRUCT(name, &((*GLOBAL__##global).value), retained)} +#define __INIT_LOCATED(type, location, name, retained)\ {extern type *location;\ - name = location;} + __INIT_STRUCT(name, location, retained)} #define __INIT_LOCATED_VALUE(name, initial)\ - *name = initial; + *(name.value) = initial; // variable getting macros -#define __GET_VAR(name)\ - name +#define __GET_VAR(name, ...)\ + name.value __VA_ARGS__ #define __GET_EXTERNAL(name)\ - __GET_GLOBAL_##name() + name.flags & 2 ? name.fvalue : *(name.value) #define __GET_LOCATED(name)\ - *(name) + name.flags & 2 ? name.fvalue : *(name.value) #define __GET_VAR_BY_REF(name)\ &(name) #define __GET_EXTERNAL_BY_REF(name)\ - GLOBAL__##name + name.value #define __GET_LOCATED_BY_REF(name)\ - name + name.value // variable setting macros -#define __SET_VAR(name, new_value)\ - name = new_value +#define __SET_VAR(name, new_value, ...)\ + if (!(name.flags & 2)) name.value __VA_ARGS__ = new_value #define __SET_EXTERNAL(name, new_value)\ - __SET_GLOBAL_##name(value) + if (!(name.flags & 2)) *(name.value) = new_value #define __SET_LOCATED(name, new_value)\ - *(name) = value + if (!(name.flags & 2)) *(name.value) = new_value #endif //__ACCESSOR_H