Changeset: e755bd07bc8c for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e755bd07bc8c
Modified Files:
monetdb5/mal/mal_debugger.c
monetdb5/mal/mal_resolve.c
Branch: headless
Log Message:
Simplify type analysis
diffs (183 lines):
diff --git a/monetdb5/mal/mal_debugger.c b/monetdb5/mal/mal_debugger.c
--- a/monetdb5/mal/mal_debugger.c
+++ b/monetdb5/mal/mal_debugger.c
@@ -1808,8 +1808,9 @@
}
nmeOnStk = v ? getTypeName(newMALtype(v->vtype)) : GDKstrdup(nme);
/* check for type errors */
- if (strcmp(nmeOnStk, nme) && strncmp(nmeOnStk,"COL",3))
+ if (strcmp(nmeOnStk, nme) && strncmp(nme,":col",4))
mnstr_printf(f,"!%s ",nmeOnStk);
+
mnstr_printf(f, " %s", (isVarConstant(mb,index)? " constant" : ""));
mnstr_printf(f, " %s", (isVarUsed(mb,index) ? "": " not used" ));
mnstr_printf(f, " %s", (isVarTypevar(mb,index) ? " type variable" :
""));
diff --git a/monetdb5/mal/mal_resolve.c b/monetdb5/mal/mal_resolve.c
--- a/monetdb5/mal/mal_resolve.c
+++ b/monetdb5/mal/mal_resolve.c
@@ -77,7 +77,7 @@
#include "mal_namespace.h"
MALtype getPolyType(MALtype t, MALtype *polytype);
-int updateTypeMap(MALtype formal, MALtype actual, MALtype
polytype[MAXTYPEVAR]);
+void updateTypeMap(MALtype formal, MALtype actual, MALtype
polytype[MAXTYPEVAR]);
int typeKind(MalBlkPtr mb, InstrPtr p, int i);
@@ -205,10 +205,7 @@
*/
if (CMPMALtype(formal,actual) )
continue;
- if( updateTypeMap(formal, actual, polytype)){
- unmatched= i;
- break;
- }
+ updateTypeMap(formal, actual, polytype);
formal= getPolyType(formal,polytype);
/*
* Collect the polymorphic types and resolve them.
@@ -486,6 +483,7 @@
*/
int
resolveType(MALtype *ret, MALtype dsttype, MALtype srctype){
+ int tpe;
#ifdef DEBUG_MAL_RESOLVE
if( tracefcn){
mnstr_printf(GDKout,"resolveType dst %s (%d) %s(%d)\n",
@@ -493,46 +491,39 @@
getTypeName(srctype), (int) srctype);
}
#endif
- if( CMPMALtype(dsttype,srctype)){
- *ret = dsttype;
- return 0;
- }
- if( dsttype.type == TYPE_any){
+ if( dsttype.type == TYPE_any && dsttype.col == 0){
*ret= srctype;
return 0;
}
- if( srctype.type == TYPE_any){
- *ret= dsttype;
+ if( srctype.type == TYPE_any && srctype.col == 0){
+ *ret= dsttype;
return 0;
}
- if( dsttype.col && srctype.col ){
- int h1,h2,h3;
- h1= dsttype.type;
- h2= srctype.type;
- if( h1 == h2) h3= h1; else
- if( h1 == TYPE_any) h3= h2; else
- if( h2 == TYPE_any) h3= h1;
- else {
+ if( dsttype.type == TYPE_any && srctype.col == 1)
+ tpe = srctype.type;
+ else
+ if( srctype.type == TYPE_any && dsttype.col == 1)
+ tpe = dsttype.type;
+ else
+ if ( srctype.type == dsttype.type && srctype.col == dsttype.col){
+ *ret= dsttype;
+ return 0;
+ } else {
#ifdef DEBUG_MAL_RESOLVE
if(tracefcn) mnstr_printf(GDKout,"Head can not be
resolved \n");
#endif
return -1;
- }
+ }
+
#ifdef DEBUG_MAL_RESOLVE
if( tracefcn){
- int i1= dsttype.idx;
mnstr_printf(GDKout,"resolved to col[:%s]
col[:%s]->col[%s]\n",
- getTypeName(h1), getTypeName(h2),
getTypeName(h3));
+ getTypeName(dsttype), getTypeName(srctype),
getTypeName(*ret));
}
#endif
- *ret = newMALtype(h3);
- (*ret).col = 1;
- return 0;
- }
-#ifdef DEBUG_MAL_RESOLVE
- if(tracefcn) mnstr_printf(GDKout,"Can not be resolved \n");
-#endif
- return -1;
+ *ret = newMALtype(tpe);
+ (*ret).col = 1;
+ return 0;
}
/*
@@ -764,7 +755,12 @@
*/
inline MALtype
getPolyType(MALtype t, MALtype *polytype){
- return t.idx > 0 ? polytype[t.idx]: t;
+
+ if ( t.idx ){
+ t.type = polytype[t.idx].type;
+ t.idx = 0;
+ }
+ return t;
}
/*
* Each argument is checked for binding of polymorphic arguments.
@@ -772,51 +768,17 @@
* (The parser currently enforces a single digit from 1-9 )
* The polymorphic type 'any', i.e. any_0, does never constraint an operation
* it can match with all polymorphic types.
- * The routine returns the instanciated formal type for subsequent
- * type resolution.
*/
-int updateTypeMap(MALtype formal, MALtype actual, MALtype polytype[MAXTYPEVAR])
+void updateTypeMap(MALtype formal, MALtype actual, MALtype
polytype[MAXTYPEVAR])
{
- int h,t,ret=0;
-
- if( formal.type == TYPE_bat && actual.col ) return 0;
#ifdef DEBUG_MAL_RESOLVE
mnstr_printf(GDKout,"updateTypeMap:");
mnstr_printf(GDKout,"formal %s ", getTypeName(formal));
mnstr_printf(GDKout,"actual %s\n", getTypeName(actual));
#endif
- if( (h=formal.idx) ){
- if( actual.col && !formal.col &&
- (polytype[h].type == TYPE_any || polytype[h].type ==
actual.type)){
- polytype[h]= actual;
- ret=0;
- goto updLabel;
- }
- t= actual.type;
- if( t != polytype[h].type ){
- if( polytype[h].type == TYPE_any ) polytype[h].type= t;
- else {
- ret= -1;
- goto updLabel;
- }
- }
- }
- if( formal.col){
- if( (h = formal.idx) ){
- t= actual.type;
- if( t!= polytype[h].type){
- if( polytype[h].type == TYPE_any)
polytype[h].type = t;
- else {
- ret= -1;
- goto updLabel;
- }
- }
- }
- }
-updLabel:
-#ifdef DEBUG_MAL_RESOLVE
- mnstr_printf(GDKout,"updateTypeMap returns: %d\n",ret);
-#endif
- return ret;
+ /* Set polytype if it was not set */
+ if ( formal.idx && formal.type == TYPE_any &&
polytype[formal.idx].type == TYPE_any )
+ polytype[formal.idx]= actual;
+
}
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list