Changeset: 70f7749beb9f for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=70f7749beb9f
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
Branch: Apr2012
Log Message:
Convert mal_resolve.mx to .c file.
diffs (truncated from 626 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_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
@@ -129,6 +103,75 @@ void polyInit(void){
}
#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)
{
@@ -140,7 +183,6 @@ findFunctionType(stream *out, Module sco
int polytype[MAXTYPEVAR];
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.
@@ -168,7 +210,6 @@ findFunctionType(stream *out, Module sco
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
@@ -197,7 +238,6 @@ 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
@@ -224,7 +264,6 @@ findFunctionType(stream *out, Module sco
for (k = 0; k < limit; k++) polytype[k] = TYPE_any;
/*
- * @-
* Most polymorphic functions don;t have a variable
argument
* list. So we save some instructions factoring this
caise out.
* Be careful, the variable number of return arguments
should
@@ -238,7 +277,6 @@ findFunctionType(stream *out, Module sco
if (k == sig->argc - 1 && sig->varargs &
VARARGS)
k--;
/*
- * @-
* Take care of variable argument lists.
* They are allowed as the last in the
signature only.
* Furthermore, for patterns if the formal type
is 'any' then all remaining arguments
@@ -254,7 +292,6 @@ findFunctionType(stream *out, Module sco
}
formal = getPolyType(formal, polytype);
/*
- * @-
* Collect the polymorphic types and resolve
them.
* If it fails, we know this isn;t the function
we are
* looking for.
@@ -265,7 +302,6 @@ findFunctionType(stream *out, Module sco
}
}
/*
- * @-
* The last argument/result type could be a polymorphic
variable list.
* It should only be allowed for patterns, where it can
deal with the stack.
* If the type is specified as :any then any mix of
arguments is allowed.
@@ -296,7 +332,6 @@ findFunctionType(stream *out, Module sco
}
} else {
/*
- * @-
* We have to check the argument types to determine a
* possible match for the non-polymorphic case.
*/
@@ -319,7 +354,6 @@ findFunctionType(stream *out, Module sco
}
}
/*
- * @-
* It is possible that you may have to coerce the value to another type.
* We assume that coercions are explicit at the MAL
* level. (e.g. var2:= var0:int). This avoids repeated type analysis
@@ -349,7 +383,6 @@ findFunctionType(stream *out, Module sco
s = s->peer; continue;
}
/*
- * @-
* At this stage we know all arguments are type compatible with
the
* signature.
* We should assure that also the target variables have the
proper types
@@ -398,7 +431,6 @@ findFunctionType(stream *out, Module sco
s = s->peer; continue;
}
/*
- * @-
* If the return types are correct, copy them in place.
* Beware that signatures should be left untouched, which
* means that we may not overwrite any formal argument.
@@ -420,10 +452,9 @@ findFunctionType(stream *out, Module sco
setVarType(mb, getArg(p, i), ts);
setVarFixed(mb, getArg(p, i));
}
- @:prepostProcess(ts,i,mb)@
+ prepostProcess(ts, p, i, mb);
}
/*
- * @-
* Also the arguments may contain constants
* to be garbage collected.
*/
@@ -437,7 +468,6 @@ findFunctionType(stream *out, Module sco
p->gc |= GARBAGECONTROL;
}
/*
- * @-
* It may happen that an argument was still untyped and as a
result of
* the polymorphism matching became strongly typed. This should
be
* reflected in the symbol table.
@@ -445,7 +475,6 @@ findFunctionType(stream *out, Module sco
s1 = returntype[0]; /* for those interested */
/* foundbutwrong = 0;*/
/*
- * @-
* If the call refers to a polymorphic function, we
* clone it to arrive at a bounded instance. Polymorphic
patterns and
* commands are responsible for type resolution themselves.
@@ -465,76 +494,8 @@ findFunctionType(stream *out, Module sco
goto wrapup;
}
}
-/*
- * @-
- * We found the proper function. Copy some properties. In particular,
- * determine the calling strategy, i.e. FCNcall, CMDcall, FACcall, PATcall
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list