From e0467a3b7ccda77d1a75405e21c9723c72d33002 Mon Sep 17 00:00:00 2001 From: xchaos Date: Mon, 18 Aug 2008 10:14:08 +0000 Subject: [PATCH] #3 refining of object macros git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@80 4bb87942-c103-4e5a-b51c-0ebff58f8515 --- cll1.h | 3 ++- demos/objects/objects-sample.c | 36 +++++++++++++++++----------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/cll1.h b/cll1.h index d38f2cd..0ad5db9 100644 --- a/cll1.h +++ b/cll1.h @@ -85,6 +85,7 @@ extern unsigned RANDOM_SEED; #define or || #define TRUE 1 #define FALSE 0 +#define PI 3.141592654 #define WEIRDINT (1<<(sizeof(int)*8-1)) #define btoa(EXPR) ((EXPR)?"TRUE":"FALSE") #define coalesce(VAR,EXPR) (VAR?VAR:(EXPR)) @@ -192,7 +193,7 @@ extern unsigned RANDOM_SEED; /* 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 +#define I_am(SELF,MEM) MEM SELF=(MEM)community /* .----------------------------------------------------------------------. / 9. implementation of C<<1 library functions, updated 2008-01-26 xCh. '----------------------------------------------------------------------- */ diff --git a/demos/objects/objects-sample.c b/demos/objects/objects-sample.c index f0a800a..5b00563 100644 --- a/demos/objects/objects-sample.c +++ b/demos/objects/objects-sample.c @@ -56,7 +56,7 @@ def_mem(Object_list) void drawTri(Shape community) { - I_am(Tri); + I_am(self, Tri); printf("Drawing %s: %d,%d - %d,%d - %d,%d .\n", self->name, self->x1, self->y1, self->x2, self->y2, self->x3, self->y3); @@ -64,7 +64,7 @@ void drawTri(Shape community) void drawRect(Shape community) { - I_am(Rect); + I_am(self, Rect); printf("Drawing %s: %d,%d - %d,%d .\n", self->desc, self->x1, self->y1, self->x2, self->y2); @@ -72,7 +72,7 @@ void drawRect(Shape community) void drawCirc(Shape community) { - I_am(Circ); + I_am(self, Circ); printf("Drawing %s: %d,%d - r=%d .\n", self->comment, self->x1, self->y1, self->r); @@ -80,7 +80,7 @@ void drawCirc(Shape community) void moveTri(Shape community, int x, int y) { - I_am(Tri); + I_am(self, Tri); self->x1 += x; self->y1 += y; @@ -92,7 +92,7 @@ void moveTri(Shape community, int x, int y) void moveRect(Shape community, int x, int y) { - I_am(Rect); + I_am(self, Rect); self->x1 += x; self->y1 += y; @@ -102,7 +102,7 @@ void moveRect(Shape community, int x, int y) void moveCirc(Shape community, int x, int y) { - I_am(Circ); + I_am(self, Circ); self->x1 += x; self->y1 += y; @@ -110,49 +110,49 @@ void moveCirc(Shape community, int x, int y) str descTri(Shape community) { - I_am(Tri); + I_am(self, Tri); return self->name; } str descRect(Shape community) { - I_am(Rect); + I_am(self, Rect); return self->desc; } str descCirc(Shape community) { - I_am(Circ); + I_am(self, Circ); return self->comment; } float calcAreaTri(Shape community) { - I_am(Tri); + I_am(self, Tri); return 0; } float calcAreaRect(Shape community) { - I_am(Rect); + I_am(self, Rect); - return (self->x2-self->x1)*(self->y2-self->y1); + return (self->x2 - self->x1)*(self->y2 - self->y1); } float calcAreaCirc(Shape community) { - I_am(Circ); + I_am(self, Circ); - return 3.14159*self->r*self->r; + return PI * self->r * self->r; } void setTri(Shape community, int x1, int y1, int x2, int y2, int x3, int y3) { - I_am(Tri); + I_am(self, Tri); self->x1 = x1; self->y1 = y1; @@ -164,7 +164,7 @@ void setTri(Shape community, int x1, int y1, int x2, int y2, int x3, int y3) void setRect(Shape community, int x1, int y1, int x2, int y2, int dummy1, int dummy2) { - I_am(Rect); + I_am(self, Rect); self->x1 = x1; self->y1 = y1; @@ -174,7 +174,7 @@ void setRect(Shape community, int x1, int y1, int x2, int y2, int dummy1, int du void setCirc(Shape community, int x1, int y1, int r, int dummy1, int dummy2, int dummy3) { - I_am(Circ); + I_am(self, Circ); self->x1 = x1; self->y1 = y1; @@ -183,7 +183,7 @@ void setCirc(Shape community, int x1, int y1, int r, int dummy1, int dummy2, int void nameRect(Shape community, str name) { - I_am(Rect); + I_am(self, Rect); self->desc = name; } -- 2.30.2