Update of /cvsroot/monetdb/MonetDB5/src/mal
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv13193/src/mal

Modified Files:
        mal_debugger.mx mal_function.mx mal_instruction.mx 
        mal_parser.mx mal_properties.mx mal_resolve.mx 
Log Message:
implemented a new property scheme


Index: mal_parser.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/mal/mal_parser.mx,v
retrieving revision 1.205
retrieving revision 1.206
diff -u -d -r1.205 -r1.206
--- mal_parser.mx       22 Oct 2007 10:36:02 -0000      1.205
+++ mal_parser.mx       9 Dec 2007 16:21:06 -0000       1.206
@@ -1166,23 +1166,23 @@
                        if(l==0) 
                                break;
                        pname= idCopy(cntxt,l);
-                       if( curBlk->[EMAIL PROTECTED]>props== NULL)
-                                curBlk->[EMAIL PROTECTED]>props= 
newPropertySet();
                        /* localize value , simplified version */
                        lo= operatorLength(cntxt);
                        if( lo > 0) 
                                opname= operatorCopy(cntxt,lo);
-                       else opname= GDKstrdup("");
-                       if((i= cstToken(cntxt,&cst))){
+                       else 
+                               opname= GDKstrdup("");
+                       if ((i= cstToken(cntxt,&cst))){
                                int csttpe;
                                advance(cntxt,i);
                                if( currChar(cntxt)==':') {
                                        csttpe = simpleTypeId(cntxt);
                                        convertConstant(csttpe,&cst);
                                } 
-                               setVarProperty(curBlk,@1, pname, opname, &cst);
-                       } else 
-                               setVarProperty(curBlk,@1, pname, NULL, NULL);
+                               varSetProperty(curBlk,@1, pname, opname, &cst);
+                       } else {
+                               varSetProperty(curBlk,@1, pname, NULL, NULL);
+                       }
                        GDKfree(pname); 
                        GDKfree(opname); 
                } while( keyphrase1(cntxt,","));

Index: mal_properties.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/mal/mal_properties.mx,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- mal_properties.mx   19 May 2007 10:39:45 -0000      1.45
+++ mal_properties.mx   9 Dec 2007 16:21:06 -0000       1.46
@@ -282,304 +282,109 @@
 @tab data can be appended
 @end multitable
 @-
[EMAIL PROTECTED]
-The code base supports multiple property sets.
-Not used right now.
 @h
 #ifndef _MAL_PROPERTIES_
 #define _MAL_PROPERTIES_
 #include "mal.h"
 #include "mal_namespace.h"
 
-#define MAXPROPLIST 3
-
-typedef struct PROPrecord {
-       str nme;
-       str operator;
-       ValRecord val;
-       struct PROPrecord *nxt;
-} *Property;
-
-typedef struct PROPSET {
-       int refcount;
-       int maxlist;
-       Property prop[MAXPROPLIST];
-} *PropertySet;
+typedef struct MalProp {
+       bte idx;
+       bte op;
+       short var;
+} *MalPropPtr, MalProp;
 
-mal_export PropertySet newPropertySet(void);
-mal_export void freePropertySet(PropertySet ps);
-mal_export PropertySet cpyPropertySet(PropertySet old);
-mal_export Property cpyProperty(PropertySet * target, Property src);
-mal_export Property fndProperty(PropertySet ps, str nme);
-mal_export Property fndPropertyIndexed(PropertySet ps, int first, int last, 
str nme);
-mal_export Property setProperty(PropertySet ps, str nme, str op, int tpe, ptr 
val);
-mal_export void delProperty(PropertySet ps, str nme);
-mal_export ptr getPropertyValue(PropertySet ps, str nme);
-mal_export ptr getPropertyTypedValue(PropertySet ps, str nme, int type);
-mal_export int getPropertyType(PropertySet ps, str nme);
-mal_export int setPropertyType(PropertySet ps, str nme, int type);
-mal_export str propertySet2str(PropertySet ps);
-mal_export int isPropertyDefined(PropertySet ps, str nme);
+typedef enum prop_op_t {
+       op_lt = 0,
+       op_lte = 1,
+       op_eq = 2,
+       op_gte = 3,
+       op_gt = 4,
+       op_ne = 5
+} prop_op_t;
 
-#define getProps(M,Y) M->var[Y]->props
-#define fndArgProperty(M,P,I,NME) fndProperty(getProps(M,getArg(P,I)),NME)
-#define setArgProperty(M,P,I,NME,OP,T,V) {if(getProps(M,getArg(P,I))== 0) \
-               getProps(M,getArg(P,I))= newPropertySet();\
-               setProperty(getProps(M,getArg(P,I)),NME,OP,T,V);}
-#define addProperty(M,V,NME) { if(getProps(M,V)== 0) \
-                       getProps(M,V)= newPropertySet();\
-               { int v=1; setProperty(getProps(M,V),NME,"=",TYPE_bit,&v);}}
+mal_export sht PropertyIndex(str name);
+mal_export str PropertyName(sht idx);
+mal_export prop_op_t PropertyOperator( str s );
+mal_export str PropertyOperatorString( prop_op_t op );
 
 #endif
+
[EMAIL PROTECTED]
 @c
 #include "mal_config.h"
 #include "mal_properties.h"
 #include "mal_type.h"          /* for idcmp() */
 
-PropertySet
-newPropertySet()
-{
-       PropertySet ps;
-
-       ps = (PropertySet) GDKzalloc(sizeof(struct PROPSET));
-       ps->refcount = 0;
-       ps->maxlist = MAXPROPLIST;
-       return ps;
-}
-
-Property
-cpyProperty(PropertySet * target, Property src)
-{
-       if (*target == 0)
-               *target = newPropertySet();
-       return setProperty(*target, src->nme, 
-                       src->operator, src->val.vtype, VALptr(&src->val));
-}
-
-PropertySet
-cpyPropertySet(PropertySet old)
-{
-       PropertySet ps;
-       Property pr;
-       int i;
-
-       ps = newPropertySet();
-       for(i=0; i< MAXPROPLIST; i++){
-               pr = old->prop[i];
-               while(pr){
-                       cpyProperty(&ps, pr);
-                       pr= pr->nxt;
-               }
-       }
-       return ps;
-}
-
-void
-freePropertySet(PropertySet ps)
-{
-       Property p1, p2;
-       int i;
-
-       for (i = 0; i < MAXPROPLIST; i++) {
-               p1 = ps->prop[i];
-               while(p1){
-                       p2 = p1->nxt;
-                       GDKfree(p1);
-                       p1= p2;
-               }
-       }
-       GDKfree(ps);
-}
+static str *properties = NULL;
+static int nr_properties = 0;
+static int max_properties = 0;
 
-Property
-fndProperty(PropertySet ps, str nme)
+sht 
+PropertyIndex(str name)
 {
-       Property pr;
-       int i;
-
-       if (ps == NULL || nme== NULL)
-               return NULL;
-       nme= getName(nme,strlen(nme));
-       for (i = 0; i < MAXPROPLIST; i++) {
-               pr = ps->prop[i];
-               while (pr) {
-                       if (pr->nme== nme)
-                               return pr;
-                       pr = pr->nxt;
-               }
+       int i=0;
+       for (i=0; i<nr_properties; i++) {
+               if (strcmp(properties[i], name) == 0)
+                       return i;
        }
-       return 0;
-}
-
-Property
-fndPropertyIndexed(PropertySet ps, int first, int last, str nme)
-{
-       Property pr;
-       int i;
-
-       if (ps == NULL)
-               return NULL;
-       nme= getName(nme,strlen(nme));
-       for (i = first; i < last; i++) {
-               pr = ps->prop[i];
-               while (pr) {
-                       if (pr->nme== nme)
-                               return pr;
-                       pr = pr->nxt;
+       mal_set_lock(mal_contextLock,"propertyIndex");
+       /* small change its allready added */
+       for (i=0; i<nr_properties; i++) {
+               if (strcmp(properties[i], name) == 0) {
+                       mal_unset_lock(mal_contextLock,"propertyIndex");
+                       return i;
                }
        }
-       return 0;
-}
-
-int
-isPropertyDefined(PropertySet ps, str nme){
-       Property pr;
-       if( ps == NULL || nme== NULL) return FALSE;
-       pr = fndProperty(ps,nme);
-       return pr != NULL;
-}
[EMAIL PROTECTED]
-A property is assigned to a specific property list.
[EMAIL PROTECTED]
-Property
-setPropertyIndexed(PropertySet ps, int idx, str nme, str op, int tpe, ptr val)
-{
-       Property pr;
-
-       pr = fndPropertyIndexed(ps, idx, idx + 1, nme);
-       if (pr == 0) {
-               pr = (Property) GDKmalloc(sizeof(struct PROPrecord));
-               pr->nxt = ps->prop[idx];
-               ps->prop[idx] = pr;
-               pr->nme = putName(nme,strlen(nme));
-       }
-       if (val)
-               VALset(&pr->val, tpe, val);
-       pr->operator= putName(op,strlen(op));
-       return pr;
-}
-
-Property
-setProperty(PropertySet ps, str nme, str op, int tpe, ptr val)
-{
-       return setPropertyIndexed(ps, 0, nme, op, tpe, val);
-}
-void
-delProperty(PropertySet ps, str nme){
-       Property pr, po;
-       pr = fndPropertyIndexed(ps, 0, 1, nme);
-       if( pr){
-               if( pr->nxt){
-                       po= pr->nxt;
-                       *pr = *pr->nxt;
-                       GDKfree(po);
-               } else
-                       pr->nme= NULL;
-       }
-}
-
[EMAIL PROTECTED]
-The users of properties need a simple scheme to localize a
-property.
[EMAIL PROTECTED]
-ptr
-getPropertyValue(PropertySet ps, str nme)
-{
-       Property pr;
-
-       pr = fndProperty(ps, nme);
-       if (pr)
-               return VALptr(&pr->val);
-       return NULL;
-}
-
-ptr
-getPropertyTypedValue(PropertySet ps, str nme, int type)
-{
-       Property pr;
-
-       pr = fndProperty(ps, nme);
-       if (pr) {
-               if (pr->val.vtype != type)
-                       VALconvert(type, &pr->val);
-               if (pr->val.vtype != type)
-                       return NULL;
-               return VALptr(&pr->val);
+       if (i >= max_properties) {
+               max_properties += 256;
+               properties = GDKrealloc(properties, max_properties * 
sizeof(str));
        }
-       return NULL;
+       properties[nr_properties] = GDKstrdup(name);
+       mal_unset_lock(mal_contextLock,"propertyIndex");
+       return nr_properties++;
 }
 
-int
-getPropertyType(PropertySet ps, str nme)
+str 
+PropertyName(sht idx)
 {
-       Property pr;
-
-       pr = fndProperty(ps, nme);
-       if (pr)
-               return pr->val.vtype;
-       return TYPE_void;
+       if (idx < nr_properties)
+               return properties[idx];
+       return "None";
 }
 
-int
-setPropertyType(PropertySet ps, str nme, int type)
+prop_op_t
+PropertyOperator( str s )
 {
-       Property pr;
-
-       pr = fndProperty(ps, nme);
-       if (pr) {
-               if (pr->val.vtype != type)
-                       VALconvert(type, &pr->val);
-               return pr->val.vtype;
-       }
-       return TYPE_void;
+       if (!s || !*s)
+               return op_eq;
+       if (*s == '<') {
+               if (*(s+1) == '=')
+                       return op_lte;
+               return op_lt;
+       } else if (*s == '>') {
+               if (*(s+1) == '=')
+                       return op_gte;
+               return op_gt;
+       } else if (*s == '=')
+               return op_eq;
+       else if (*s == '!' && *(s+1) == '=')
+               return op_ne;
+       return op_eq;
 }
 
[EMAIL PROTECTED]
-For debugging purposes we should be able to convert any property set
-back into a string. We simple assume the space required is limited.
[EMAIL PROTECTED]
 str
-propertySet2str(PropertySet ps)
+PropertyOperatorString( prop_op_t op )
 {
-       char buf[128 * 1024];
-       str s = buf, t = 0;
-       Property pr;
-       int i,first=0;
-
-       if (ps == NULL )
-               return GDKstrdup("");
-       pr = ps->prop[0];
-       *s++ = '{';
-       for(i=0; i<MAXPROPLIST; i++){
-               pr = ps->prop[i];
-               while(pr){
-                       t = 0;
-                       if (first++ )
-                               *s++ = ',';
-                       ATOMformat(pr->val.vtype, VALget(&pr->val), &t);
-                       if (pr->operator && * pr->operator) {
-                               switch(pr->val.vtype){
-                               case TYPE_lng:
-                                       sprintf(s, "%s%s%s:lng", pr->nme, 
pr->operator, t);
-                                       break;
-                               case TYPE_sht:
-                                       sprintf(s, "%s%s%s:sht", pr->nme, 
pr->operator, t);
-                                       break;
-                               default:
-                                       sprintf(s, "%s%s%s", pr->nme, 
pr->operator, t);
-                               }
-                       } else
-                               sprintf(s, "%s", pr->nme);
-                       while (*s)
-                               s++;
-                       pr= pr->nxt;
-                       if (t)
-                       GDKfree(t);
-               }
+       switch(op) {
+       case op_lt: return "<";
+       case op_lte: return "<=";
+       case op_eq: return "=";
+       case op_gte: return ">=";
+       case op_gt: return ">";
+       case op_ne: return "!=";
        }
-       *s++ = '}';
-       *s = 0;
-       return GDKstrdup(buf);
+       return "=";
 }
 
 @}

Index: mal_function.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/mal/mal_function.mx,v
retrieving revision 1.146
retrieving revision 1.147
diff -u -d -r1.146 -r1.147
--- mal_function.mx     16 Jul 2007 15:44:35 -0000      1.146
+++ mal_function.mx     9 Dec 2007 16:21:05 -0000       1.147
@@ -975,7 +975,6 @@
 showFlowDetails(MalBlkPtr mb, MalStkPtr stk, InstrPtr p, int pc, stream *f)
 {
        str s, msg;
-       PropertySet ps;
        int i;
 
        (void) stk;             /* fool the compiler */
@@ -986,23 +985,23 @@
                        stream_printf(f, "\\\"");
                else
                        stream_printf(f, "%c", *s);
+       GDKfree(msg);
        for(i=0;i<p->retc; i++){
+               char *ps = NULL;
                stream_printf(f, "\\n%s",getArgName(mb,p,i));
                stream_printf(f,":%s", 
s=getTypeName(getVarType(mb,getArg(p,i))));
                GDKfree(s);
 
-               ps = getProps(mb,getArg(p,i));
-               if( ps == 0) continue;
-               s= propertySet2str(ps);
+               ps = s = varGetPropStr(mb, getArg(p, i));
                for (; s && *s; s++)
                        if (*s == '"')
                                stream_printf(f, "\\\"");
                        else
                                stream_printf(f, "%c", *s);
+               GDKfree(ps);
        }
        /* later: add BAT runtime properties */
        stream_printf(f, "\"];\n");
-       GDKfree(msg);
 }
 
 void

Index: mal_resolve.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/mal/mal_resolve.mx,v
retrieving revision 1.129
retrieving revision 1.130
diff -u -d -r1.129 -r1.130
--- mal_resolve.mx      8 Apr 2007 20:06:25 -0000       1.129
+++ mal_resolve.mx      9 Dec 2007 16:21:06 -0000       1.130
@@ -223,9 +223,9 @@
 implementation.
 In all other cases the type should apply to all remaining arguments.
 @c
-               if( formal == actual)
+               if (formal == actual)
                        continue;
-               if( isPolyType(formal) && getVar(mb,getArg(p,i))->props){
+               if (isPolyType(formal)){
                        /* printf("perform union type check\n");*/
                }
                if( updateTypeMap(formal, actual, polytype)){

Index: mal_instruction.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/mal/mal_instruction.mx,v
retrieving revision 1.287
retrieving revision 1.288
diff -u -d -r1.287 -r1.288
--- mal_instruction.mx  31 Oct 2007 07:15:24 -0000      1.287
+++ mal_instruction.mx  9 Dec 2007 16:21:05 -0000       1.288
@@ -328,8 +328,10 @@
        int tmpindex;           /* temporary variable */
        short scope;            /* block id where it is declared */
        short beginLifespan, endLifespan, lastUpdate;   /* for optimizers */
-       PropertySet props;      /* private list of (name,value) pairs */
        ValRecord value;
+
+       short propc, maxprop;   /* proc count and max number of properties */
+       short prps[];           /* property array */
 } *VarPtr, VarRecord;
 
 /* type check status is kept around to improve type checking efficiency */
@@ -392,7 +394,6 @@
 typedef struct MALBLK {
        str binding;            /* related C-function */
        str help;               /* supportive commentary */
-       PropertySet props;      /* private */
        struct MALBLK *alternative;
        int vtop;               /* next free slot */
        int vsize;              /* size of variable arena */
@@ -400,6 +401,9 @@
        int stop;               /* next free slot */
        int ssize;              /* byte size of arena */
        InstrPtr *stmt;         /* Instruction location */
+       int ptop;               /* next free slot */
+       int psize;              /* byte size of arena */
+       MalProp *prps;          /* property table */
        int errors;             /* left over errors */
        int typefixed;          /* no undetermined instruction */
        int flowfixed;          /* all flow instructions are fixed */
@@ -438,7 +442,6 @@
 #define getVarType(M,I)     ((M)->var[I]->type)
 #define getVarGDKType(M,I)      ((M)->var[I]->gdktype)
 #define getVarScope(M,I)   ((M)->var[I]->scope)
-#define getVarProperties(M,I)   ((M)->var[I]->props)
 
 #define isFixed(M,I)        ((M)->var[I]->fixtype)
 #define freezeVarType(M,I) getVar(M,I)->isudftype = 1;
@@ -517,6 +520,12 @@
 mal_export int fndConstant(MalBlkPtr mb, ValPtr cst);
 mal_export int convertConstant(malType type, ValPtr vr);
 
+#define varSetProperty(mb, var, name, opname, cst) \
+       varSetProp(mb, var, PropertyIndex(name), PropertyOperator(opname), cst)
+mal_export void varSetProp(MalBlkPtr mb, int var, int prop, int op, ValPtr 
cst);
+mal_export str  varGetPropStr( MalBlkPtr mb, int var );
+mal_export VarPtr varGetProp(MalBlkPtr mb, int var, int prop);
+
 mal_export void pushInstruction(MalBlkPtr mb, InstrPtr p);
 mal_export InstrPtr pushArgument(MalBlkPtr mb, InstrPtr p, int varid);
 mal_export InstrPtr setArgument(MalBlkPtr mb, InstrPtr p, int idx, int varid);
@@ -529,7 +538,6 @@
 mal_export void setReturnArgument(InstrPtr p, int varid);
 mal_export malType destinationType(MalBlkPtr mb, InstrPtr p);
 mal_export void setPolymorphic(InstrPtr p, int tpe, int force);
-mal_export void setVarProperty(MalBlkPtr mb, int i, str name, str op, ValPtr 
cst);
 mal_export str fcnClass(InstrPtr p);
 mal_export str fcnDefinition(MalBlkPtr mb, InstrPtr p, str s, int flg);
 mal_export void printInstruction(stream *fd, MalBlkPtr mb, InstrPtr p, int 
flg);
@@ -640,7 +648,6 @@
        mb->vsize = maxvars;
        mb->help = mb->binding = NULL;
        mb->errors = 0;
-       mb->props = NULL;
        mb->alternative = NULL;
        mb->history = NULL;
        mb->keephistory = 0;
@@ -649,6 +656,8 @@
        mb->typefixed = 0;
        mb->flowfixed = 0;
        mb->profiler = NULL;
+       mb->ptop = mb->psize = 0;
+       mb->prps = NULL;
        return mb;
 }
 
@@ -672,21 +681,25 @@
        int i;
 
        for (i = 0; i < mb->ssize; i++) 
-       if( mb->stmt[i]){
-               freeInstruction(mb->stmt[i]);
-               mb->stmt[i] = NULL;
-       }
+               if( mb->stmt[i]){
+                       freeInstruction(mb->stmt[i]);
+                       mb->stmt[i] = NULL;
+               }
        mb->stop = 0;
        for (i = 0; i < mb->vsize; i++)
-       if( mb->var[i]){
-               freeVariable(mb, i);
-               mb->var[i]=0;
-       }
+               if( mb->var[i]){
+                       freeVariable(mb, i);
+                       mb->var[i]=0;
+               }
        mb->vtop = 0;
        GDKfree(mb->stmt);
        mb->stmt = 0;
        GDKfree(mb->var);
        mb->var = 0;
+       if (mb->prps)
+               GDKfree(mb->prps);
+       mb->ptop = mb->psize = 0;
+       mb->prps = NULL;
 
        if( mb->history)
                freeMalBlk(mb->history);
@@ -696,9 +709,6 @@
        if (mb->help)
                GDKfree(mb->help);
        mb->help = 0;
-       if (mb->props)
-               GDKfree(mb->props);
-       mb->props = NULL;
        if (mb->profiler)
                GDKfree(mb->profiler);
        mb->profiler = NULL;
@@ -718,7 +728,6 @@
        mb = (MalBlkPtr) GDKzalloc(sizeof(MalBlkRecord));
        if (mb == NULL)
                GDKfatal("newMalBlk:could not get storage\n");
-       mb->props = old->props;
        mb->alternative = old->alternative;
        mb->history = NULL;
        mb->keephistory= old->keephistory;
@@ -753,10 +762,17 @@
        mb->typefixed = old->typefixed;
        mb->flowfixed = old->flowfixed;
        mb->maxarg= old->maxarg;
-       /* copy the properties as well */
-       if (mb->props)
-               mb->props = cpyPropertySet(old->props);
        mb->profiler = NULL;
+
+       mb->ptop = mb->psize = 0;
+       mb->prps = NULL;
+       if (old->prps) {
+               mb->prps = (MalProp*) GDKzalloc(old->psize * sizeof(MalProp));
+               mb->psize = old->psize;
+               mb->ptop = old->ptop;
+               for (i=0; i<old->ptop; i++)
+                       mb->prps[i] = old->prps[i]; 
+       }
        return mb;
 }
 
@@ -1321,27 +1337,26 @@
        if( mb->vtop >= (1<<15)-2 ){
                mb->vtop = (1<<15)-2 ;
                GDKerror("newVariable: too many variables\n");
-       } else
-       if( mb->vtop >= mb->vsize){
+       } else if (mb->vtop >= mb->vsize){
                VarPtr *new;
-        int s= mb->vtop + MAXVARS;
+               int s= mb->vtop + MAXVARS;
 
                if (mb->vtop >mb->vsize)
                        GDKfatal("newVariable:variable administration\n");
 
-        new= (VarPtr *) GDKzalloc(s * sizeof(VarPtr));
-        /*printf("generate new variable block %d\n",s);*/
-        if( new== NULL ){
-            mb->errors++;
-            showScriptException(mb,0,MAL,"newMalBlk:no storage left\n");
-            return mb->vtop;
-        }
-        memcpy((char*)new, (char*)mb->var, sizeof(VarPtr) * mb->vtop);
-        GDKfree((str)mb->var);
-        mb->vsize= s;
-        mb->var= new;
-        mb->var[mb->vtop-1]->gdktype= TYPE_void;
-    }
+               new= (VarPtr *) GDKzalloc(s * sizeof(VarPtr));
+               /*printf("generate new variable block %d\n",s);*/
+               if( new== NULL ){
+                       mb->errors++;
+                       showScriptException(mb,0,MAL,"newMalBlk:no storage 
left\n");
+                       return mb->vtop;
+               }
+               memcpy((char*)new, (char*)mb->var, sizeof(VarPtr) * mb->vtop);
+               GDKfree((str)mb->var);
+               mb->vsize= s;
+               mb->var= new;
+               mb->var[mb->vtop-1]->gdktype= TYPE_void;
+       }
 @c
 int
 newVariable(MalBlkPtr mb, str name, malType type)
@@ -1364,9 +1379,10 @@
                }
        }
        n = mb->vtop;
-       getVar(mb, n) = (VarPtr) GDKzalloc(sizeof(VarRecord));
+       getVar(mb, n) = (VarPtr) GDKzalloc(sizeof(VarRecord) + 2*MAXARG * 
sizeof(short));
        mb->var[n]->name = name;
-       mb->var[n]->props = NULL;
+       mb->var[n]->propc = 0;
+       mb->var[n]->maxprop = 2*MAXARG;
 
        setVarType(mb, n, type);
        isConstant(mb, n) = 0;
@@ -1411,10 +1427,9 @@
        @:makeVarSpace@
        n = mb->vtop;
        if (getVar(mb, n) == NULL)
-               getVar(mb, n) = (VarPtr) GDKzalloc(sizeof(VarRecord));
+               getVar(mb, n) = (VarPtr) GDKzalloc(sizeof(VarRecord) + 2*MAXARG 
* sizeof(short));
 /* already captured by memset
     mb->var[n]->name = 0;
-    mb->var[n]->props = NULL;
     isConstant(mb,n) = 0;
     setVarCleanup(mb,n) = FALSE;
        getVar(mb,n)->isudftype= 0;
@@ -1422,6 +1437,8 @@
 */
        getVarTmp(mb, n) = n;
        setVarType(mb, n, type);
+       mb->var[n]->propc = 0;
+       mb->var[n]->maxprop = 2*MAXARG;
        mb->vtop++;
        return n;
 }
@@ -1462,10 +1479,11 @@
 void
 copyVariable(MalBlkPtr dst, MalBlkPtr src, VarPtr v)
 {
+       int i;
        VarPtr w;
 
        (void) src;             /* fool the compiler */
-       w = (VarPtr) GDKzalloc(sizeof(VarRecord));
+       w = (VarPtr) GDKzalloc(sizeof(VarRecord) + v->maxprop * sizeof(short));
        w->name = v->name ? GDKstrdup(v->name) : 0;
        w->type = v->type;
        w->gdktype = v->gdktype;
@@ -1477,11 +1495,13 @@
        w->isatypevar = v->isatypevar;
        w->tmpindex = v->tmpindex;
        w->scope = v->scope;
+       w->propc = v->propc;
+       w->maxprop = v->maxprop;
+       for (i=0; i<v->propc; i++)
+               w->prps[i] = v->prps[i];
 
        VALcopy(&w->value, &v->value);
        dst->var[dst->vtop] = w;
-       if( v->props )
-               w->props = cpyPropertySet(v->props);
 }
 
 @-
@@ -1522,9 +1542,6 @@
                GDKfree(v->name);
        if (v->isaconstant)
                VALclear(&v->value);
-       if (v->props)
-               freePropertySet(v->props);
-       v->props= NULL;
        v->name = 0;
        v->type = 0;
        v->gdktype = 0;
@@ -1536,8 +1553,7 @@
        v->isatypevar = 0;
        v->tmpindex = 0;
        v->scope = 0;
-
-       /* the above version is faster memset((char*)v, 0, sizeof(VarRecord)); 
*/
+       v->propc = 0;
 }
 
 void
@@ -2100,24 +2116,6 @@
        pushInstruction(mb, p);
 }
 
[EMAIL PROTECTED]
-Property value setting.
[EMAIL PROTECTED]
-void
-setVarProperty(MalBlkPtr mb, int i, str name, str op, ValPtr cst)
-{
-       bit t = TRUE;
-
-       if (getProps(mb,i) == NULL)
-               getProps(mb,i) = newPropertySet();
-
-       if (cst == NULL)
-               setProperty(getProps(mb,i), name, "", TYPE_bit, &t);
-
-       else
-               setProperty(getProps(mb,i), name, op, cst->vtype, VALget(cst));
-}
-
 @+ Reverse programming
 Since MAL programs can be created on the fly by linked-in query
 compilers, or transformed by optimizers, it becomes
@@ -2249,10 +2247,10 @@
 
 @= showParam
         tpe= getTypeName(getArgType(mb,p,i));
-               if( flg & LIST_MAL_PROPS ){
-                       ps= getProps(mb,getArg(p,i));
-                       pstring= propertySet2str(ps);
-               } else pstring= GDKstrdup("");
+       if (flg & LIST_MAL_PROPS)
+               pstring = varGetPropStr(mb, getArg(p,i));
+       else
+               pstring = GDKstrdup("");
         advance(t);
         sprintf(t,"%s:%s%s",getArgName(mb,p,i),tpe,pstring);
         advance(t);
@@ -2271,10 +2269,8 @@
 {
        int i;
        str t, tpe, pstring;
-       PropertySet ps = 0;
 
-       ps = getProps(mb,getArg(p, 0));
-       pstring = propertySet2str(ps);
+       pstring = varGetPropStr(mb, getArg(p,0));
        t = s;
        sprintf(t, "%s%s ", (flg ? "" : "#"), fcnClass(p));
 
@@ -2286,9 +2282,11 @@
        advance(t);
        if( pstring )
                sprintf(t, "%s%s(", getFunctionId(p),pstring);
-       else sprintf(t, "%s(", getFunctionId(p));
+       else 
+               sprintf(t, "%s(", getFunctionId(p));
        for (i = p->retc; i < p->argc; i++) {
-       @:showParam(argc)@}
+               @:showParam(argc)@
+       }
        advance(t);
        if (p->varargs & VARARGS)
                sprintf(t, "...");
@@ -2326,20 +2324,6 @@
        return s;
 }
 
[EMAIL PROTECTED]
[EMAIL PROTECTED] tabulate
-    for(;tab>0;tab--) *t++= ' ';
-    *t= 0;
-    advance(t);
[EMAIL PROTECTED]
-Variables and MAL blocks, and instructions can be associated with a
-property list. At least for debugging purposes, the latest known value
-should be displayed.
[EMAIL PROTECTED] propertyList
-    {char *tmp= propertySet2str(ps); strcat(t,tmp); GDKfree(tmp);}
-    advance(t);
[EMAIL PROTECTED]
-
 str
 operatorName(int i)
 {
@@ -2385,7 +2369,6 @@
        str s, t, nme;
        int low, high;
        char nmebuf[PATHLENGTH];
-       PropertySet ps = 0;
        str pstring = 0;
 
        len = 8196;
@@ -2428,12 +2411,19 @@
                        p->barrier == RETURNsymbol || 
                        p->barrier == YIELDsymbol || 
                        p->barrier == RAISEsymbol) {
-                       @:tabulate@
+                       for(;tab>0;tab--) 
+                               *t++= ' ';
+                       *t= 0;
+                       advance(t);
                }
                sprintf(t, "%s ", operatorName(p->barrier));
                advance(t);
-       } else if (!functionStart(p) && !functionExit(p))
-               @:tabulate@
+       } else if (!functionStart(p) && !functionExit(p)) {
+               for(;tab>0;tab--) 
+                       *t++= ' ';
+               *t= 0;
+               advance(t);
+       }
        switch (p->token<0?-p->token:p->token) {
        case NOOPsymbol:
        case FCNcall:
@@ -2442,11 +2432,10 @@
        case CMDcall:
        case ASSIGNsymbol:
                if (p->argc <= 1 && getFunctionId(p) == NULL) {
-                       if( flg & LIST_MAL_PROPS ){
-                               ps = getProps(mb,getArg(p, 0));
-                               pstring = propertySet2str(ps);
-                       } else pstring = GDKstrdup("");
-
+                       if (flg & LIST_MAL_PROPS)
+                               pstring = varGetPropStr(mb, getArg(p, 0));
+                       else 
+                               pstring = GDKstrdup("");
                        if (getVar(mb, getArg(p, 0))->isudftype) {
                                str tpe = getTypeName(getVarType(mb, getArg(p, 
0)));
 
@@ -2469,10 +2458,10 @@
                                *t++ = '(';
 
                        for (i = 0; i < p->retc; i++) {
-                               if( flg & LIST_MAL_PROPS ){
-                                       ps = getProps(mb,getArg(p, i));
-                                       pstring = propertySet2str(ps);
-                               } else pstring= GDKstrdup("");
+                               if (flg & LIST_MAL_PROPS)
+                                       pstring = varGetPropStr(mb, getArg(p, 
i));
+                               else 
+                                       pstring = GDKstrdup("");
                                if (getVar(mb, getArg(p, i))->isudftype) {
                                        str tpe = getTypeName(getVarType(mb, 
getArg(p, i)));
 
@@ -2696,4 +2685,124 @@
                        GDKfree(msg);
                } 
 }
+
+void
+varSetProp(MalBlkPtr mb, int var, int prop, int op, ValPtr cst)
+{
+       VarPtr v = getVar(mb, var);
+       int i, propid = -1, reset = 0;
+
+       for(i=0; i<v->propc; i++){
+               MalProp *p = mb->prps+v->prps[i];
+
+               if (p->idx == prop) {
+                       propid = v->prps[i]; 
+                       reset = 1;
+                       break;
+               }
+       }
+       if (propid < 0) {
+               if (mb->ptop >= (1<<15)-2 ){
+                       mb->ptop = (1<<15)-2;
+                       GDKerror("varSetProp: too many properties\n");
+                       assert(0);
+               } else if (mb->ptop >= mb->psize){
+                       mb->psize += MAXVARS;
+                       mb->prps = (MalProp*) GDKrealloc(mb->prps, mb->psize * 
sizeof(MalProp));
+                       if (mb->prps == NULL) {
+                               mb->errors++;
+                               assert(0);
+                               showScriptException(mb, 0, MAL, "varSetProp: no 
storage left\n");
+                       }
+               }
+               propid = mb->ptop++;
+       }
+
+       mb->prps[propid].var = 0;
+       if (cst != NULL) 
+               mb->prps[propid].var = defConstant(mb, cst->vtype, cst);
+       mb->prps[propid].idx = prop;
+       mb->prps[propid].op = op;
+
+       /* here we need to add the new property to the variable */
+       if (!reset) {
+               assert(v->propc < v->maxprop); /* Hard limit for now */
+               v->prps[v->propc++] = propid;
+       }
+}
+
+str
+varGetPropStr( MalBlkPtr mb, int var )
+{
+       char buf[BUFSIZ], *s = buf;
+       VarPtr v = getVar(mb, var);
+       int i, first = 1;
+
+       if (v->propc == 0)
+               return GDKstrdup("");
+
+       *s++ = '{';
+       for(i=0; i<v->propc; i++){
+               char *t = NULL;
+               MalProp *p = mb->prps+v->prps[i];
+               char *nme = PropertyName(p->idx);
+
+               if (!first)
+                       *s++ = ',';
+               if (p->var) {
+                       VarPtr v = getVar(mb, p->var);
+                       char *op = PropertyOperatorString(p->op); 
+       
+                       ATOMformat(v->type, VALget(&v->value), &t);
+                       switch(v->type) {
+                       case TYPE_oid:
+                               sprintf(s, "%s%s%s:oid", nme, op, t);
+                               break;
+                       case TYPE_lng:
+                               sprintf(s, "%s%s%s:lng", nme, op, t);
+                               break;
+                       case TYPE_sht:
+                               sprintf(s, "%s%s%s:sht", nme, op, t);
+                               break;
+                       default:
+                               sprintf(s, "%s%s%s", nme, op, t);
+                       }
+                       if (t)
+                               GDKfree(t);
+               } else {
+                       sprintf(s, "%s", nme);
+               }
+               while (*s)
+                       s++;
+               first = 0;
+       }
+       *s++ = '}';
+       *s = 0;
+       return GDKstrdup(buf);
+}
+
+static VarRecord varTrue;
+
+VarPtr
+varGetProp( MalBlkPtr mb, int var, int prop )
+{
+       VarPtr v = getVar(mb, var);
+       int i;
+
+       for(i=0; i<v->propc; i++){
+               MalProp *p = mb->prps+v->prps[i];
+
+               if (p->idx == prop) {
+                       if (p->var) {
+                               return getVar(mb, p->var);
+                       } else {
+                               bit t = TRUE;
+                               VALset(&varTrue.value, TYPE_bit, &t);
+                               varTrue.gdktype = varTrue.type = TYPE_bit;
+                               return &varTrue;
+                       }
+               }
+       }
+       return NULL;
+}
 @}

Index: mal_debugger.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/mal/mal_debugger.mx,v
retrieving revision 1.212
retrieving revision 1.213
diff -u -d -r1.212 -r1.213
--- mal_debugger.mx     7 Nov 2007 11:59:58 -0000       1.212
+++ mal_debugger.mx     9 Dec 2007 16:21:05 -0000       1.213
@@ -476,7 +476,6 @@
 mal_export void mdbStep(Client cntxt, MalBlkPtr mb, MalStkPtr stk, int pc);
 mal_export void mdbDump(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
 mal_export void mdbHelp(stream *f);
-mal_export void printStackElm(stream *f, MalBlkPtr mb, VarPtr n, ValPtr v, int 
index, size_t cnt, int first, int lifespan);
 mal_export void printBATelm(stream *f, int i, size_t cnt, size_t first);
 mal_export void printStack(stream *f, MalBlkPtr mb, MalStkPtr s, int lifespan);
 mal_export void printBatInfo(stream *f, VarPtr n, ValPtr v);
@@ -510,6 +509,9 @@
 #define skipBlanc(c,X)    while(*(X) && isspace((int)*X)){ X++; }
 #define skipNonBlanc(c,X) while(*(X) && !isspace((int) *X)){ X++; }
 #define skipWord(c,X)    while(*(X) && isalnum((int) *X)){X++;} skipBlanc(c,X);
+
+static void printStackElm(stream *f, MalBlkPtr mb, ValPtr v, int index, size_t 
cnt, int first, int lifespan);
+
 @-
 Each client has its own breakpoint administration, kept in a global table.
 Although a little space consumptive, it is the easiest to maintain
@@ -1274,7 +1276,7 @@
                                        stream_printf(out, "%s Symbol not 
found\n", "#mdb ");
                                continue;
                        }
-                       printStackElm(out, mb, getVar(mb, i), stk->stk + i, i, 
size, first,0);
+                       printStackElm(out, mb, stk->stk + i, i, size, first,0);
                        continue;
                }
                case 'S':
@@ -1533,10 +1535,10 @@
                stream_printf(f, "#Stack '%s' size=%d top=%d\n",
                                getInstrPtr(mb, 0)->fcnname, s->stksize, 
s->stktop);
                for (; i < mb->vtop; i++)
-                       printStackElm(f, mb, getVar(mb, i), s->stk + i, i, 0, 
0,lifespan);
+                       printStackElm(f, mb, s->stk + i, i, 0, 0,lifespan);
        } else
                for (; i < mb->vtop; i++)
-                       printStackElm(f, mb, getVar(mb, i), 0, i, 0, 
0,lifespan);
+                       printStackElm(f, mb, 0, i, 0, 0,lifespan);
 }
 
 void
@@ -1578,10 +1580,11 @@
 }
 
 void
-printStackElm(stream *f, MalBlkPtr mb, VarPtr n, ValPtr v, int index, size_t 
cnt, int first, int lifespan)
+printStackElm(stream *f, MalBlkPtr mb, ValPtr v, int index, size_t cnt, int 
first, int lifespan)
 {
        str nme, nmeOnStk;
        char nmebuf[PATHLENGTH];
+       VarPtr n = getVar(mb, index);
 
        (void) mb;              /* fool the compiler */
        if (n->tmpindex) {
@@ -1663,8 +1666,8 @@
                        BBPunfix(b->batCacheid);
                }
        } 
-       if( n->props){
-               nme= propertySet2str(n->props);
+       if (n->propc){
+               nme = varGetPropStr(mb, index);
                stream_printf(f,"%s",nme);
                GDKfree(nme);
        }


-------------------------------------------------------------------------
SF.Net email is sponsored by: 
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Monetdb-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-checkins

Reply via email to