X-Git-Url: http://git.harvie.cz/?a=blobdiff_plain;f=cll1.h;h=0b404ed04db242adf6eb9be54c63dc99d0b9c308;hb=1a8d78d9e9f1a4a2e8b7c3b740c5516195fbc04b;hp=1f4ddbf695ea70534dd3be656da80fd0460eb616;hpb=b27abb8a41cb8e876112626ef3f5e2c156943bc2;p=svn%2FCll1h%2F.git diff --git a/cll1.h b/cll1.h index 1f4ddbf..0b404ed 100644 --- a/cll1.h +++ b/cll1.h @@ -92,8 +92,8 @@ extern unsigned RANDOM_SEED; / 4. C<<1 data declaration and allocation, updated 2008-01-31 xCh. '----------------------------------------------------------------------- */ #define def_mem(TYPE) typedef struct _##TYPE##_t * TYPE; struct _##TYPE##_t -#define get_mem(...) _GET_MEM(__VA_ARGS__,NULL) -#define Get_mem(ID,...) _ARG1(__VA_ARGS__,) ID=_GET_MEM(__VA_ARGS__,NULL) +#define get_mem(TYPE) _GET_MEM(TYPE) +#define Get_mem(ID,TYPE) TYPE ID=_GET_MEM(TYPE) #define mem_len(TYPE) sizeof(struct _##TYPE##_t) //#define mem_copy #define list(TYPE) TYPE __next @@ -173,24 +173,24 @@ extern unsigned RANDOM_SEED; /* .----------------------------------------------------------------------. / 8. C<<1 object oriented infrastructure, updated 2008-02-04 '----------------------------------------------------------------------- */ -#define def_type(TYPE) typedef struct _##TYPE##_t * TYPE; -#define def_obj(TYPE) struct _##TYPE##_t -#define construct_obj(MEM,INTERFACE) MEM _init_##MEM##_##INTERFACE(INTERFACE i) { Get_mem(o,MEM); o->__interface=i; return o; } -#define anonymous void * -#define I_am(MEM) MEM self=(MEM)community -#define def_community(TYPE,INTERFACE) def_mem(TYPE) { INTERFACE __interface; }; +#define def_type(TYPE) typedef struct _##TYPE##_t * TYPE; +#define def_obj(TYPE) struct _##TYPE##_t #define method(NAME) (*NAME) -#define get_obj(MEM,INTERFACE,INIT) _init_##MEM##_##INTERFACE(INIT) +#define construct(TYPE) _init_##TYPE(TYPE o,void *i) { o->__interface=i; return o; } TYPE __init__##TYPE +#define get_obj(TYPE,INTERFACE,...) __init__##TYPE(_init_##TYPE(get_mem(TYPE),INTERFACE),__VA_ARGS__) #define Get_obj(ID,MEM,INTERFACE) MEM ID=get_obj(MEM,INTERFACE) -#define get_obj_as(COMMUNITY,MEM,INTERFACE) (COMMUNITY)((_PTR=get_mem(MEM),(_PTR?((MEM)_PTR)->__interface=INTERFACE:0),_PTR)) -#define Get_obj_as(ID,COMMUNITY,MEM,INTERFACE) +#define get_obj_as(COMMUNITY,MEM,INTERFACE) (COMMUNITY)get_obj(MEM,INTERFACE) +#define Get_obj_as(ID,COMMUNITY,MEM,INTERFACE) MEM ID=get_obj_as(COMMUNITY,MEM,INTERFACE) #define _(METHOD,...) ( _ASSERT(ARG1(__VA_ARGS__,)), (*( ARG1(__VA_ARGS__,)->__interface->METHOD )) ( __VA_ARGS__ ) ) #define __(METHOD,...) ( _ASSERT(ARG1(__VA_ARGS__,)), (*( __cll1_seekmethod(ARG1(__VA_ARGS__,)->__interface,METHOD) )) ( __VA_ARGS__ ) ) #define call(OBJTYPE,METHOD,...) { int _N=0; OBJTYPE _OBJ; /* <-' */ while( (_OBJ=(OBJTYPE)_cll1_for_ptrs(_N++,__VA_ARGS__,NIL))!=(struct OBJTYPE *)NIL ) _(_OBJ,METHOD); } +#define def_community(TYPE,INTERFACE) def_mem(TYPE) { INTERFACE __interface; }; +#define anonymous void * +#define I_am(MEM) MEM self=(MEM)community /* .----------------------------------------------------------------------. / 9. implementation of C<<1 library functions, updated 2008-01-26 xCh. '----------------------------------------------------------------------- */ -#define _MALLOC void *_cll1_malloc(size_t size,...) { /*temporary solution*/ return malloc(size); } +#define _MALLOC void *_cll1_malloc(size_t size) { /*temporary solution*/ return malloc(size); } #define _CLL1_FPRINT(IOSTREAM) { int ofs=0; va_list ap; /* <-' */ for(va_start(ap,s);s!=NIL;s=va_arg(ap,char *)) { if(ofs)fputs(OFS,IOSTREAM);else ofs=1;/**/fputs(coalesce(s,NIL),IOSTREAM); } va_end(ap); fputs(EOL,IOSTREAM); } #define _DECLARE_PRINT void _cll1_print(char *s,...) #define _PRINT _DECLARE_PRINT _CLL1_FPRINT(stdout) @@ -228,7 +228,7 @@ extern _DECLARE_STRSTR; #define _CTX (_CTXatom->CTX) #define _ARG1(ARG1,...) ARG1 #define _ARG2(ARG1,ARG2,...) ARG2 -#define _GET_MEM(TYPE,CTX) ((TYPE)_cll1_malloc(sizeof(struct _##TYPE##_t),CTX)) +#define _GET_MEM(TYPE) ((TYPE)_cll1_malloc(sizeof(struct _##TYPE##_t))) #define _ANYATOM(TYPE,NAME) def_mem(_##NAME##Atom ) { TYPE NAME; int c; list( _##NAME##Atom ); } #define _FOR_COLUMNS(A,B,C) _NEW(I,0) for( prefix(A,B,C) ; A ; ((A!=B)&&prefix(A,B,C)||(A=NULL) ),_I++ ) #define _FOR_VALID_COLUMNS(A,B,C) _NEW(I,0) for( prefix(A,B,C) ; A ; ((A!=B)&&prefix(A,B,C))||(A=NULL) ) if(*A&&++_I)