From 9abd9073f7853f2a4cd5f5243152d71ff5e47e11 Mon Sep 17 00:00:00 2001 From: xchaos Date: Tue, 23 Sep 2008 00:24:32 +0000 Subject: [PATCH] def_interface() { } macro git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@91 4bb87942-c103-4e5a-b51c-0ebff58f8515 --- cll1.h | 13 +++++++------ demos/objects/objects-community.c | 4 +--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/cll1.h b/cll1.h index ccef2ef..6f49f72 100644 --- a/cll1.h +++ b/cll1.h @@ -93,11 +93,12 @@ 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_type(TYPE) typedef struct _##TYPE##_struct * TYPE +#define def_mem(TYPE) def_type(TYPE); struct _##TYPE##_struct #define get_mem(TYPE) _GET_MEM(TYPE) #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 size_of_mem(TYPE) sizeof(struct _##TYPE##_struct) +#define copy_of_mem(TYPE,SRC) _cll1_mem_cpy(sizeof(struct _##TYPE##_struct),SRC) #define list(TYPE) TYPE __next #define tree(TYPE) TYPE __next; TYPE __seek #define dict(TYPE) tree(TYPE); str __key @@ -178,8 +179,8 @@ 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 def_interface(TYPE,INTERFACE) def_type(TYPE); def_mem(INTERFACE) +#define def_obj(TYPE) struct _##TYPE##_struct #define interface(TYPE) TYPE __interface #define interface_of(SELF) SELF->__interface #define method(NAME) (*NAME) @@ -237,7 +238,7 @@ extern _DECLARE_STRSTR; #define _CTX (_CTXatom->CTX) #define _ARG1(ARG1,...) ARG1 #define _ASSERT(EXPR) assert(EXPR) /* later... _cll1_assert(EXPR,handler) */ -#define _GET_MEM(TYPE) ((TYPE)malloc(sizeof(struct _##TYPE##_t))) /* later... ((TYPE)_cll1_malloc(sizeof(struct _##TYPE##_t))) */ +#define _GET_MEM(TYPE) ((TYPE)malloc(sizeof(struct _##TYPE##_struct))) /* later... ((TYPE)_cll1_malloc(sizeof(struct _##TYPE##_struct))) */ #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) diff --git a/demos/objects/objects-community.c b/demos/objects/objects-community.c index 5b00563..2ed93ec 100644 --- a/demos/objects/objects-community.c +++ b/demos/objects/objects-community.c @@ -2,9 +2,7 @@ /* This is example of advanced C<<1 object oriented features... */ -def_type(Shape); - -def_mem(Interface) +def_interface(Shape, Interface) { void method(draw) (Shape self); void method(move) (Shape self, int x, int y); -- 2.30.2