Changeset: 89d856e979ed for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=89d856e979ed Added Files: monetdb5/mal/mal_resolve.c monetdb5/mal/mal_resolve.h Removed Files: monetdb5/mal/mal_resolve.mx Modified Files: monetdb5/mal/Makefile.ag monetdb5/mal/mal_module.c monetdb5/optimizer/opt_remap.mx Branch: default Log Message:
Merge with Apr2012 branch. diffs (truncated from 1385 to 300 lines): diff --git a/monetdb5/mal/Makefile.ag b/monetdb5/mal/Makefile.ag --- a/monetdb5/mal/Makefile.ag +++ b/monetdb5/mal/Makefile.ag @@ -49,7 +49,7 @@ lib_mal = { mal_properties.c mal_properties.h \ mal_readline.c mal_readline.h \ mal_recycle.c mal_recycle.h \ - mal_resolve.mx \ + mal_resolve.c mal_resolve.h \ mal_sabaoth.c mal_sabaoth.h \ mal_scenario.c mal_scenario.h \ mal_session.c mal_session.h \ diff --git a/monetdb5/mal/mal_module.c b/monetdb5/mal/mal_module.c --- a/monetdb5/mal/mal_module.c +++ b/monetdb5/mal/mal_module.c @@ -214,12 +214,12 @@ void freeModuleList(Module s){ s=t; } } + /* - * @- - * After filling in a structure it is added to the multi-level - * symbol table. We keep a skip list of similar named function - * symbols. This speeds up searching provided the modules adhire - * to the structure group the functions as well. + * After filling in a structure it is added to the multi-level symbol + * table. We keep a skip list of similarly named function symbols. + * This speeds up searching provided the modules adhere to the + * structure and group the functions as well. */ void insertSymbol(Module scope, Symbol prg){ InstrPtr sig; diff --git a/monetdb5/mal/mal_resolve.mx b/monetdb5/mal/mal_resolve.c rename from monetdb5/mal/mal_resolve.mx rename to monetdb5/mal/mal_resolve.c --- a/monetdb5/mal/mal_resolve.mx +++ b/monetdb5/mal/mal_resolve.c @@ -1,23 +1,22 @@ -@/ -The contents of this file are subject to the MonetDB Public License -Version 1.1 (the "License"); you may not use this file except in -compliance with the License. You may obtain a copy of the License at -http://www.monetdb.org/Legal/MonetDBLicense +/* + * The contents of this file are subject to the MonetDB Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.monetdb.org/Legal/MonetDBLicense + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is the MonetDB Database System. + * + * The Initial Developer of the Original Code is CWI. + * Portions created by CWI are Copyright (C) 1997-July 2008 CWI. + * Copyright August 2008-2012 MonetDB B.V. + * All Rights Reserved. + */ -Software distributed under the License is distributed on an "AS IS" -basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the -License for the specific language governing rights and limitations -under the License. - -The Original Code is the MonetDB Database System. - -The Initial Developer of the Original Code is CWI. -Portions created by CWI are Copyright (C) 1997-July 2008 CWI. -Copyright August 2008-2012 MonetDB B.V. -All Rights Reserved. -@ - -@c /* * @a M. Kersten * @v 1.0 @@ -40,7 +39,7 @@ All Rights Reserved. * y := io.print(val); * end sample; * @end example - * @- + * * The function definition is polymorphic typed on the 2nd argument, * it becomes a concrete type upon invocation. The system could attempt * a type check, but quickly runs into assumptions that generally do not hold. @@ -76,31 +75,6 @@ All Rights Reserved. * TYPE_RESOLVED implies that the type of the instruction is fully * resolved, it is marked TYPE_DYNAMIC otherwise. */ -@h -#ifndef _MAL_RESOLVE_H -#define _MAL_RESOLVE_H - -#include "mal_exception.h" -#include "mal_function.h" -#include "mal_listing.h" -#include "mal_exception.h" - -/* -#define DEBUG_MAL_RESOLVE 1 -*/ -#define MAXTYPEVAR 10 - -mal_export void chkProgram(stream *out, Module s, MalBlkPtr mb); -mal_export void chkInstruction(stream *out, Module s, MalBlkPtr mb, InstrPtr p); -mal_export void chkTypes(stream *out, Module s, MalBlkPtr mb, int silent); -mal_export void typeChecker(stream *out, Module scope, MalBlkPtr mb, InstrPtr p, int silent); -mal_export int fcnBinder(stream *out, Module scope, MalBlkPtr mb, InstrPtr p); - -extern str traceFcnName; -mal_export void expandMacro(MalBlkPtr mb, InstrPtr p, MalBlkPtr mc); - -#endif /* _MAL_RESOLVE_H*/ -@c /* * @- Function call resolution * Search the first definition of the operator in the current module @@ -119,16 +93,88 @@ int typeKind(MalBlkPtr mb, InstrPtr p, i #define MAXMALARG 256 -str traceFcnName= "____"; +str traceFcnName = "____"; int tracefcn; int polyVector[MAXTYPEVAR]; #if 0 -void polyInit(void){ +void +polyInit(void) +{ int i; - for(i=0;i<MAXTYPEVAR;i++) polyVector[i]= TYPE_any; + for (i = 0; i < MAXTYPEVAR; i++) + polyVector[i] = TYPE_any; } #endif +/* + * We found the proper function. Copy some properties. In particular, + * determine the calling strategy, i.e. FCNcall, CMDcall, FACcall, PATcall + * Beware that polymorphic functions may produce type-incorrect clones. + * This piece of code may be shared by the separate binder + */ +#define bindFunction(s, p, mb, out) \ + do { \ + if (s->def->errors) { \ + p->typechk = TYPE_UNKNOWN; \ + mb->errors++; \ + goto wrapup; \ + } \ + if (p->token == ASSIGNsymbol) { \ + switch (getSignature(s)->token) { \ + case COMMANDsymbol: \ + p->token = CMDcall; \ + p->fcn = getSignature(s)->fcn; /* C implementation mandatory */ \ + if (p->fcn == NULL) { \ + showScriptException(out, mb, getPC(mb, p), TYPE, \ + "object code for command %s.%s missing", \ + p->modname, p->fcnname); \ + p->typechk = TYPE_UNKNOWN; \ + mb->errors++; \ + goto wrapup; \ + } \ + break; \ + case PATTERNsymbol: \ + p->token = PATcall; \ + p->fcn = getSignature(s)->fcn; /* C implementation optional */ \ + break; \ + case FACTORYsymbol: \ + p->token = FACcall; \ + p->fcn = getSignature(s)->fcn; /* C implementation optional */ \ + break; \ + case FUNCTIONsymbol: \ + p->token = FCNcall; \ + if (getSignature(s)->fcn) \ + p->fcn = getSignature(s)->fcn; /* C implementation optional */ \ + break; \ + default: { \ + if (!silent) \ + showScriptException(out, mb, getPC(mb, p), MAL, \ + "MALresolve: unexpected token type"); \ + mb->errors++; \ + goto wrapup; \ + } \ + } \ + p->blk = s->def; \ + } \ + } while (0) + +/* + * Since we now know the storage type of the receiving variable, we can + * set the garbage collection flag. + */ +#define prepostProcess(tp, p, b, mb) \ + do { \ + if (findGDKtype(tp) == TYPE_bat || \ + isaBatType(tp) || \ + findGDKtype(tp) == TYPE_str || \ + (!isPolyType(tp) && tp < TYPE_any && \ + tp >= 0 && ATOMextern(tp))) { \ + getInstrPtr(mb, 0)->gc |= GARBAGECONTROL; \ + setVarCleanup(mb, getArg(p, b)); \ + p->gc |= GARBAGECONTROL; \ + } \ + } while (0) + static malType findFunctionType(stream *out, Module scope, MalBlkPtr mb, InstrPtr p, int silent) { @@ -136,11 +182,10 @@ findFunctionType(stream *out, Module sco Symbol s; InstrPtr sig; int i, k, unmatched = 0, s1; - /* int foundbutwrong=0;*/ + /* int foundbutwrong=0; */ int polytype[MAXTYPEVAR]; - int *returntype= NULL; + int *returntype = NULL; /* - * @- * Within a module find the subscope to locate the element in its list * of symbols. A skiplist is used to speed up the search for the * definition of the function. @@ -157,32 +202,36 @@ findFunctionType(stream *out, Module sco * Simplify polytype using a map into the concrete argument table. */ m = scope; - s = m->subscope[(int)(getSubScope(getFunctionId(p)))]; - if (s == 0) return -1; + s = m->subscope[(int) (getSubScope(getFunctionId(p)))]; + if (s == 0) + return -1; - returntype= (int*) GDKzalloc(p->retc * sizeof(int)); - if ( returntype == 0) return -1; + returntype = (int *) GDKzalloc(p->retc * sizeof(int)); + if (returntype == 0) + return -1; - while (s != NULL) { /* single scope element check */ + while (s != NULL) { /* single scope element check */ if (getFunctionId(p) != s->name) { - s = s->skip; continue; + s = s->skip; + continue; } /* - * @- - * Perform a strong type-check on the actual arguments. If it turns - * out to be a polymorphic MAL function, we have to clone it. - * Provided the actual/formal parameters are compliant throughout - * the function call. + * Perform a strong type-check on the actual arguments. If it + * turns out to be a polymorphic MAL function, we have to + * clone it. Provided the actual/formal parameters are + * compliant throughout the function call. * - * Also look out for variable argument lists. This means that we - * have to keep two iterators, one for the caller (i) and one for - * the callee (k). Since a variable argument only occurs as the last one, - * we simple avoid an increment when running out of formal arguments. + * Also look out for variable argument lists. This means that + * we have to keep two iterators, one for the caller (i) and + * one for the callee (k). Since a variable argument only + * occurs as the last one, we simple avoid an increment when + * running out of formal arguments. * - * A call of the form (X1,..., Xi) := f(Y1,....,Yn) can be matched against - * the function signature (B1,...,Bk):= f(A1,...,Am) where i==k , n<=m - * and type(Ai)=type(Yi). Furthermore, the variables Xi obtain their type - * from Bi (or type(Bi)==type(Xi)). + * A call of the form (X1,..., Xi) := f(Y1,....,Yn) can be + * matched against the function signature (B1,...,Bk):= + * f(A1,...,Am) where i==k , n<=m and + * type(Ai)=type(Yi). Furthermore, the variables Xi obtain + * their type from Bi (or type(Bi)==type(Xi)). */ sig = getSignature(s); unmatched = 0; @@ -197,23 +246,24 @@ findFunctionType(stream *out, Module sco } #endif /* - * @- - * The simple case could be taken care of separately to speedup processing - * However, it turned out not to make a big difference. - * The first time we encounter a polymorphic argument in the + * The simple case could be taken care of separately to + * speedup processing + * However, it turned out not to make a big difference. The + * first time we encounter a polymorphic argument in the * signature. * Subsequently, the polymorphic arguments update this table - * and check for any type mismatches that might occur. - * There are at most 2 type variables involved per argument - * due to the limited type nesting permitted. _______________________________________________ Checkin-list mailing list Checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list