From 24cfa6bd1046afbbe6049d9b463cf76c97d5e7d4 Mon Sep 17 00:00:00 2001 From: xchaos Date: Mon, 18 Aug 2008 07:43:20 +0000 Subject: [PATCH] some work on objects and locales (#3 and #5 ?) git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@79 4bb87942-c103-4e5a-b51c-0ebff58f8515 --- cll1.h | 30 +++++++++++++++++------------- demos/eq.c | 4 +++- demos/objects/objects-sample.c | 6 +++--- demos/objects/objects-wiki.c | 2 +- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/cll1.h b/cll1.h index 5693e3c..d38f2cd 100644 --- a/cll1.h +++ b/cll1.h @@ -61,7 +61,7 @@ typedef FILE * file; typedef int bool; extern str NIL,EOL,OFS,IFS; extern unsigned RANDOM_SEED; -#define _EXPORT_GLOBALS str NIL="(null)", EOL="\n", OFS=" ", IFS=" \t\n"; unsigned RANDOM_SEED=0; +#define _EXPORT_GLOBALS str NIL="(null)", EOL="\n", OFS=" ", IFS=" \t\n", LANG=NULL; unsigned RANDOM_SEED=0; /* .----------------------------------------------------------------------. / 1. C<<1 then buddhist section, updated 2008-02-04 xCh. '----------------------------------------------------------------------- */ @@ -91,27 +91,28 @@ 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 def_mem(TYPE) typedef struct _##TYPE##_t * TYPE; struct _##TYPE##_t #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 get_buf(SIZE) (buf)malloc(SIZE) /* temporary solution */ +#define size_of_mem(TYPE) sizeof(struct _##TYPE##_t) +#define copy_of_mem(TYPE,SRC) _cll1_mem_cpy(sizeof(struct _##TYPE##_t),SRC) #define list(TYPE) TYPE __next #define tree(TYPE) TYPE __next; TYPE __seek #define dict(TYPE) tree(TYPE); str __key #define array(TYPE) tree(TYPE); int __key - +/* variable declarators */ +#define Get_mem(ID,TYPE) TYPE ID=get_mem(TYPE) +#define Get_buf(ID,SIZE) buf ID=get_buf(SIZE) /* .----------------------------------------------------------------------. / 5. C<<1 string manipulation, updated 2008-01-26 xCh. '----------------------------------------------------------------------- */ #define get_str(...) _cll1_get_str(__VA_ARGS__,NIL) #define eq(A,B) (!_cll1_str_cmp(A,B)) #define eqi(A,B) (!_cll1_str_cmpi(A,B)) -//#define str_eq(A,B) eq(A,B) ? -//#define str_eqi(A,B) eqi(A,B) #define str_order(A,B) _cll1_str_coll(A,B) #define str_ascii(A,B) _cll1_str_cmp(A,B) -#define str_len(...) _cll1__strlen(__VA_ARGS__,NIL) +#define chars_in_str(...) _cll1_strlen(__VA_ARGS__,NIL) +#define size_of_str(A) mbstowcs(NULL,A,0) #define str_in(A,B) _cll1_str_str(A,B) #define word_in(A,B) _cll1_wordinstr(A,B,0) #define print(...) _cll1_print(__VA_ARGS__,NIL) @@ -123,6 +124,8 @@ extern unsigned RANDOM_SEED; #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 tr(STR,B,C) _NEW(S,STR) while(S && *_S) { if(*_S==B)*_S=C; /* <-' */ _S++; } +/* variable declarators */ +#define Get_str(ID,...) str ID=get_str(__VA_ARGS__) /* .----------------------------------------------------------------------. / 6. C<<1 data container manipulation, updated 2008-01-26 xCh. '----------------------------------------------------------------------- */ @@ -178,16 +181,17 @@ extern unsigned RANDOM_SEED; #define interface(TYPE) TYPE __interface #define interface_of(SELF) SELF->__interface #define method(NAME) (*NAME) -#define construct(TYPE) TYPE _init_##TYPE(TYPE o,void *i) { o->__interface=i; return o; } TYPE __init__##TYPE +#define construct(TYPE,INTERFACE) TYPE _init_##TYPE(TYPE o,INTERFACE 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,...) MEM ID=get_obj(MEM,__VA_ARGS__) #define get_obj_as(COMMUNITY,MEM,INTERFACE,...) (COMMUNITY)get_obj(MEM,INTERFACE,__VA_ARGS__) -#define Get_obj_as(ID,COMMUNITY,MEM,...) MEM ID=get_obj_as(COMMUNITY,MEM,INTERFACE,__VA_ARGS__) #define _(METHOD,...) (((_ARG1(__VA_ARGS__,)) && (_ARG1(__VA_ARGS__,))->__interface->METHOD)?(*( (_ARG1(__VA_ARGS__,))->__interface->METHOD )) ((void *)__VA_ARGS__):0 ) #define __(METHOD,...) ( _ASSERT(ARG1(__VA_ARGS__,)), (*( __cll1_seekmethod(ARG1(__VA_ARGS__,),METHOD) )) ( __VA_ARGS__ ) ) #define call(OBJTYPE,METHOD,...) { int _N=0; OBJTYPE _OBJ; /* <-' */ while( (_OBJ=(OBJTYPE)_cll1_for_ptrs(_N++,__VA_ARGS__,NIL))!=(OBJTYPE)NIL ) _(_OBJ,METHOD); } #define def_community(TYPE,INTERFACE) def_obj(TYPE) { INTERFACE __interface; }; #define anonymous void * +/* variable declarators */ +#define Get_obj(ID,MEM,...) MEM ID=get_obj(MEM,__VA_ARGS__) +#define Get_obj_as(ID,COMMUNITY,MEM,...) MEM ID=get_obj_as(COMMUNITY,MEM,INTERFACE,__VA_ARGS__) #define I_am(MEM) MEM self=(MEM)community /* .----------------------------------------------------------------------. / 9. implementation of C<<1 library functions, updated 2008-01-26 xCh. @@ -355,7 +359,7 @@ obsolete #define _IMPLEMENT_CLL1_LIBRARY _INIT_VARIABLES _IMPL_FUNCTIONS _IMPL_INTERFACE #define _PROGRAM _cll1_program #define _DECLARE_PROGRAM void _PROGRAM(int argc, char **argv) -#define program _IMPLEMENT_CLL1_LIBRARY _DECLARE_PROGRAM; int main(int argc, char **argv) { setlocale(LC_ALL, ""); _PROGRAM(argc,argv); return 0; } _DECLARE_PROGRAM +#define program _IMPLEMENT_CLL1_LIBRARY _DECLARE_PROGRAM; int main(int argc, char **argv) { LANG=setlocale(LC_ALL, ""); _PROGRAM(argc,argv); return 0; } _DECLARE_PROGRAM #ifdef USE_PREPROCESSOR #include "_include.c" #endif diff --git a/demos/eq.c b/demos/eq.c index 10b6104..d3a87ca 100644 --- a/demos/eq.c +++ b/demos/eq.c @@ -3,11 +3,13 @@ program { str a,b; - + + print("Local language (enviroment) is set to:", LANG); a="¾luklý"; b="®LUKLÝ"; printf("str_order(\"%s\",\"%s\") = %d\n",a,b,str_order(a,b)); printf("eq(\"%s\",\"%s\") = %s\n",a,b,btoa(eq(a,b))); + printf("eq(\"%s\",\"%s\") = %s\n",a,a,btoa(eq(a,a))); printf("eqi(\"%s\",\"%s\") = %s\n",a,b,btoa(eqi(a,b))); a="aabc"; b="axyz"; diff --git a/demos/objects/objects-sample.c b/demos/objects/objects-sample.c index 6b222fd..f0a800a 100644 --- a/demos/objects/objects-sample.c +++ b/demos/objects/objects-sample.c @@ -190,7 +190,7 @@ void nameRect(Shape community, str name) /* Example of using object interface methods from inside constructor methods */ -construct(Tri) (Tri self, int x1, int y1, int x2, int y2, int x3, int y3) +construct(Tri,Interface) (Tri self, int x1, int y1, int x2, int y2, int x3, int y3) { self->name = "TRIANGLE"; interface_of(self)->count++; @@ -199,7 +199,7 @@ construct(Tri) (Tri self, int x1, int y1, int x2, int y2, int x3, int y3) return self; } -construct(Rect) (Rect self, int x1, int y1, int x2, int y2) +construct(Rect,Interface) (Rect self, int x1, int y1, int x2, int y2) { self->desc = "rectangle"; interface_of(self)->count++; @@ -208,7 +208,7 @@ construct(Rect) (Rect self, int x1, int y1, int x2, int y2) return self; } -construct(Circ) (Circ self, int x1, int y1, int r) +construct(Circ,Interface) (Circ self, int x1, int y1, int r) { self->comment = "Circle"; interface_of(self)->count++; diff --git a/demos/objects/objects-wiki.c b/demos/objects/objects-wiki.c index f603514..2fbab8f 100644 --- a/demos/objects/objects-wiki.c +++ b/demos/objects/objects-wiki.c @@ -19,7 +19,7 @@ def_obj(Animal) char *name; }; -construct(Animal) (Animal self, str name) +construct(Animal,Actions) (Animal self, str name) { self->name = name; return self; -- 2.30.2