From: xchaos Date: Sun, 27 Jan 2008 18:04:46 +0000 (+0000) Subject: implementation of specificication described in latest documentation changes X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=b3674906486c6b6fd944b4c7ffd280589cf8a165;p=svn%2FCll1h%2F.git implementation of specificication described in latest documentation changes git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@44 4bb87942-c103-4e5a-b51c-0ebff58f8515 --- diff --git a/cll1.h b/cll1.h index 120da95..a12fdff 100644 --- a/cll1.h +++ b/cll1.h @@ -57,8 +57,8 @@ #define then #define MAYBE (int)((RANDOM_SEED?random():(RANDOM_SEED=time(NULL),srandom(RANDOM_SEED),random()))%2) #define WHOKNOWS (int)(srandom(time(NULL)),random()%2) -#define Create_var(ID,TYPE,INIT) TYPE ID=INIT -#define Define_var(ID,TYPE) TYPE ID +#define create_var(ID,TYPE,INIT) TYPE ID=INIT +#define define_var(ID,TYPE) TYPE ID #endif /* .----------------------------------------------------------------------. / 3. C<<1 constants and optional keywords, updated 2008-01-26 xCh. @@ -76,20 +76,20 @@ /* .----------------------------------------------------------------------. / 4. C<<1 data declaration and allocation, updated 2008-01-07 xCh. '----------------------------------------------------------------------- */ -#define Create_str(ID,INIT) char *ID=INIT -#define Define_str(ID) char *ID=NULL -#define Create_mem(ID,...) struct _ARG1(__VA_ARGS__,) *ID=get_mem(__VA_ARGS__) -#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 Create_context(ID) Create_mem(ID,_MAtom) -#define Define_context(ID) Define_mem(ID,_MAtom) +#define create_str(ID,INIT) char *ID=INIT +#define define_str(ID) char *ID=NULL +#define create_mem(ID,...) struct _ARG1(__VA_ARGS__,) *ID=get_mem(__VA_ARGS__) +#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 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 interface(TYPE) struct TYPE *__interface -#define get_mem(...) (struct _ARG1(__VA_ARGS__,)*)_cll1_malloc(sizeof(struct _ARG1(__VA_ARGS__)), _ARG2(__VA_ARGS__,) - 0 ) +#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. @@ -151,13 +151,12 @@ / 8. C<<1 object oriented infrastructure, updated 2008-01-26 '----------------------------------------------------------------------- */ #define define_metaobject(METATYPE,ITYPE) struct METATYPE { struct ITYPE *__interface; }; -#define define_interface(MTYPE,ITYPE) struct ITYPE *__construct_##_##MTYPE##_##ITYPE(void *dummy, ...) { Define_mem(_FACE,IFACE); va_list(ap); _FACE=get_mem(IFACE) __bind_##_##MTYPE##_##ITYPE(_FACE); return _FACE; } void __bind_##_##MTYPE##_##ITYPE(struct IFACE *_FACE) +#define define_interface(MTYPE,ITYPE) struct ITYPE *_construct_##_##MTYPE##_##ITYPE(void *dummy, ...) { define_mem(_FACE,IFACE); va_list(ap); _FACE=get_mem(IFACE) _bind_##_##MTYPE##_##ITYPE(_FACE); return _FACE; } void _bind_##_##MTYPE##_##ITYPE(struct IFACE *_FACE) #define bind_method(METHOD,FUNCTION) _FACE->METHOD=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_interface(MTYPE,...) _construct_##_##MTYPE##_##_ARG1(__VA_ARGS__)((void *)__get_##_##MTYPE##_##__VA_ARGS__) +#define get_object(TYPE,...) (struct TYPE *)_cll1_allocate_object(sizeof(struct TYPE), __VA_ARGS__) #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. '----------------------------------------------------------------------- */ @@ -174,16 +173,17 @@ / 10. C<<1 globals and private macros, updated 2008-01-27 by xCh. '----------------------------------------------------------------------- */ #define _ARG1(ARG1,...) ARG1 -#define _ISTACK struct _IAtom { int I; int _23; list(_IAtom); } *_Iatom,*_Istack=NULL; -#define _SSTACK struct _SAtom { char *S; int _23; list(_SAtom); } *_Satom,*_Sstack=NULL; +#define _ARG2(ARG1,ARG2,...) ARG2 +#define _ISTACK struct _IAtom { int i; int _23; list(_IAtom); } *_Iatom,*_Istack=NULL; +#define _SSTACK struct _SAtom { char *s; int _23; list(_SAtom); } *_Satom,*_Sstack=NULL; #define _FSTACK struct _FAtom { FILE *F; int _23; list(_FAtom); } *_Fatom,*_Fstack=NULL; -#define _MSTACK struct _MAtom { void *M; int _23; list(_MAtom); } *_Matom,*_Mstack=NULL; +#define _MSTACK struct _MAtom { void *ptr; size_t size; int _23; tree(_MAtom); } *_Matom,*_Mstack=NULL; #define _NEW_(ATOM,STACK,TYPE) (ATOM=get_mem(TYPE),ATOM->_23=1,push(ATOM,STACK);ATOM->_23||pop(ATOM,STACK)&&0;ATOM->_23--) #define _NEW_I for _NEW_(_Iatom,_Istack,_IAtom) #define _NEW_S for _NEW_(_Satom,_Sstack,_SAtom) #define _NEW_F for _NEW_(_Fatom,_Fstack,_FAtom) -#define _I (_Iatom->I) -#define _S (_Satom->I) +#define _I (_Iatom->i) +#define _S (_Satom->s) #define _F (_Satom->F) #define _FOR_COLUMNS(A,B,C) _NEW_I for(_I=0,prefix(A,B,C);A;((A!=B)&&prefix(A,B,C)||(A=NULL)),_I++) #define _FOR_VALID_COLUMNS(A,B,C) _NEW_I for(_I=0,prefix(A,B,C);A;((A!=B)&&prefix(A,B,C))||(A=NULL)) if(*A&&++_I) @@ -197,9 +197,9 @@ #ifdef USE_MODULE_CGI #define cgi(MIME) { char *PTR; /***/ recycle_context(_CGI); _CGIdict=NULL; for_split_str(PTR,getenv("QUERY_STRING"),'&') /* _init_cgi */ if(MIME) printf("Content-type: %s\r\n\r\n",MIME); } //todo #define _GETCGI char *getcgi(VAR) { } -#define _CGIDICT Define_context(_CGI); struct _CGIVariable { char *V; dictionary(_CGIVariable); } *_CGIvariable,*_CGIdict; +#define _CGIDICT define_context(_CGI); struct _CGIVariable { char *V; dictionary(_CGIVariable); } *_CGIvariable,*_CGIdict; #else -#define _CGIDICT +#define _CGIDICT #endif /* .----------------------------------------------------------------------. / 12. MySQL infrastructure and wrappers - updated 2007-12-19 by xCh. @@ -274,7 +274,7 @@ obsolete /* .----------------------------------------------------------------------. / 99. We have have done our homework - now let's have some fun: '----------------------------------------------------------------------- */ -#define _DEF_VARIABLES _GLOBALS _ISTACK _SSTACK _FSTACK _MSTACK _SQLCSTACK _SQLRSTACK _CGIDICT +#define _DEF_VARIABLES _GLOBALS _ISTACK _SSTACK _FSTACK _MSTACK //_SQLCSTACK _SQLRSTACK _CGIDICT #define _DEF_FUNCTIONS _MALLOC _ECHO _PRINT _FECHO _FPRINT _IT_INTS _IT_STRS // _GET_STR _GET_MEM #define _DEF_INTERFACE //_CAKE _STD _X #define implement_cll1_library _DEF_VARIABLES _DEF_FUNCTIONS _DEF_INTERFACE diff --git a/demos/lists.c b/demos/lists.c index 99c9e68..5daf1fa 100644 --- a/demos/lists.c +++ b/demos/lists.c @@ -9,7 +9,7 @@ mem Zaznam program { - Define_mems(zaznam,zaznamy,Zaznam); + define_mems(zaznam,zaznamy,Zaznam); print("4x insert(zaznam,zaznamy,order_by,i);"); zaznam=get_mem(Zaznam);