From 8db501a078e67a152fc186cbee4ab168170b844e Mon Sep 17 00:00:00 2001 From: xchaos Date: Sun, 27 Jan 2008 11:30:07 +0000 Subject: [PATCH] some work git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@43 4bb87942-c103-4e5a-b51c-0ebff58f8515 --- cll1.h | 88 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 42 insertions(+), 46 deletions(-) diff --git a/cll1.h b/cll1.h index 48066c5..120da95 100644 --- a/cll1.h +++ b/cll1.h @@ -72,7 +72,6 @@ #define FALSE 0 #define coalesce(VAR,NOTNULL) (VAR?VAR:(NOTNULL)) #define mem struct -#define construct struct #define _GLOBALS time_t RANDOM_SEED=0; char *EOL="\n", *OFS=" ", *IFS=" \t\n", *NIL="NULL"; /* .----------------------------------------------------------------------. / 4. C<<1 data declaration and allocation, updated 2008-01-07 xCh. @@ -83,13 +82,14 @@ #define Define_mem(ID,TYPE) struct TYPE *ID=NULL #define Define_mems(ID1,ID2,TYPE) Define_mem(ID1,TYPE); Define_mem(ID2,TYPE) #define Create_list(ID1,I2,TYPE) Create_mem(ID1,TYPE); struct TYPE *ID2=((ID1->__next=NULL),ID1) -#define Define_var(ID,TYPE) TYPE ID +#define Create_context(ID) Create_mem(ID,_MAtom) +#define Define_context(ID) Define_mem(ID,_MAtom) #define list(TYPE) struct TYPE *__next -#define tree(TYPE) struct TYPE *__next;struct TYPE *__seek -#define dictionary(TYPE) tree(TYPE);char *__key -#define array(TYPE) tree(TYPE);int __key +#define tree(TYPE) struct TYPE *__next; struct TYPE *__seek +#define dictionary(TYPE) tree(TYPE); char *__key +#define array(TYPE) tree(TYPE); int __key #define interface(TYPE) struct TYPE *__interface -#define get_mem(...) (struct _ARG1(__VA_ARGS__,)*)_cll1_malloc(sizeof(struct _ARG1(__VA_ARGS__,)),NULL) +#define get_mem(...) (struct _ARG1(__VA_ARGS__,)*)_cll1_malloc(sizeof(struct _ARG1(__VA_ARGS__)), _ARG2(__VA_ARGS__,) - 0 ) #define get_str(...) (char *)_cll1_get_str(__VA_ARGS__,(void *)&_cll1_get_str) /* .----------------------------------------------------------------------. / 5. C<<1 string manipulation, updated 2008-01-26 xCh. @@ -104,7 +104,7 @@ #define file_echo(...) _cll1_fecho(_F,__VA_ARGS__,(void *)&_cll1_fecho) #define suffix(A,B,C) (((A=strrchr(B,C))&&!(*(A++)=0))||(A=B)) #define prefix(A,B,C) ((A=B),((B=strchr(B,C))&&!(*(B++)=0)||(B=A))) -#define for_split(A,B,C) for(prefix(A,B,C);A;(A!=B)&&prefix(A,B,C)||(A=NULL)) +#define for_split_str(A,B,C) for(prefix(A,B,C);A;(A!=B)&&prefix(A,B,C)||(A=NULL)) #define for_valid_split(A,B,C) for_split_str(A,B,C) if(*A) #define switch_for_columns(A,B,C) _FOR_COLUMNS(A,B,C) switch(__I) #define switch_for_valid_columns(A,B,C) _FOR_VALID_COLUMNS(A,B,C) switch (_I) @@ -148,9 +148,19 @@ #define next_arg ((_I+1METHOD=FUNCTION +#define construct_interface(MTYPE,...) __construct_##_##MTYPE##_##_ARG1(__VA_ARGS__)((void *)__get_##_##MTYPE##_##__VA_ARGS__) +#define get_object(TYPE,...) (struct TYPE *)__cll1_allocate_object(sizeof(struct TYPE), _ARG2(__VA_ARGS__) - 0) +#define construct_object(TYPE,...) +//#define _(OBJECT,...) (_ASSERT(OBJECT),/**/(*(OBJECT->interface->_ARG1(__VA_ARGS__,)))/**/(OBJECT,OBJECT->interface->__VA_ARGS__)/**/) + +/* .----------------------------------------------------------------------. + / 9. implementation of C<<1 library functions, updated 2008-01-26 xCh. '----------------------------------------------------------------------- */ -#define _ARG1(ARG1,...) ARG1 #define _MALLOC void *_cll1_malloc(size_t size,...) { /*temporary solution*/ return malloc(size); } #define _CLL1_FPRINT(IOSTREAM,LASTARG) { int p2=0;char *ofs=coalesce(OFS,"\0");va_list ap; /**/ for(va_start(ap,s);s!=LASTARG;s=va_arg(ap,char *)) { if(p2 && *ofs) fputs(ofs,IOSTREAM); else p2=1; fputs(coalesce(s,NIL),IOSTREAM); } va_end(ap); if(EOL && *EOL) fputs(EOL,IOSTREAM); } #define _PRINT void _cll1_print(char *s,...) _CLL1_FPRINT(stdout,(void *)&_cll1_print) @@ -161,50 +171,51 @@ #define _IT_INTS int _cll1_it_ints(int i, int n, ...) { int j=0;va_list ap; /**/ va_start(ap,n); while(n>=0 && j++