Changeset: 0cad023de625 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/0cad023de625 Modified Files: monetdb5/mal/mal_instruction.c monetdb5/mal/mal_module.c monetdb5/mal/mal_prelude.c monetdb5/mal/mal_resolve.c monetdb5/mal/mal_session.c monetdb5/mal/mel.h monetdb5/modules/mal/manual.c monetdb5/optimizer/opt_remap.c sql/backends/monet5/sql_gencode.c sql/backends/monet5/sql_scenario.c Branch: no_type_bat Log Message:
split mal function definitions and c-level function definitions. For the later the mel_func is used (ie no double administration anymore) diffs (truncated from 882 to 300 lines): diff --git a/monetdb5/mal/mal_instruction.c b/monetdb5/mal/mal_instruction.c --- a/monetdb5/mal/mal_instruction.c +++ b/monetdb5/mal/mal_instruction.c @@ -55,10 +55,12 @@ newSymbol(const char *nme, int kind) } cur->kind = kind; cur->peer = NULL; - cur->def = newMalBlk(kind == FUNCTIONsymbol ? STMT_INCREMENT : 2); - if (cur->def == NULL) { - GDKfree(cur); - return NULL; + if (kind == FUNCTIONsymbol) { + cur->def = newMalBlk(STMT_INCREMENT); + if (cur->def == NULL) { + GDKfree(cur); + return NULL; + } } return cur; } @@ -72,6 +74,7 @@ freeSymbol(Symbol s) freeMalBlk(s->def); s->def = NULL; } + /* TODO free s->func */ GDKfree(s); } 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 @@ -288,13 +288,11 @@ freeModule(Module m) if (m == NULL) return; if ((s = findSymbolInModule(m, "epilogue")) != NULL) { - InstrPtr pci = getInstrPtr(s->def, 0); - if (pci && pci->token == COMMANDsymbol && pci->argc == 1) { + if (s->kind == COMMANDsymbol && s->func->argc == 1) { int status = 0; str ret = MAL_SUCCEED; - assert(pci->fcn != NULL); - ret = (*(str (*)(int *)) pci->fcn) (&status); + ret = (*(str (*)(int *)) s->func->imp) (&status); freeException(ret); (void) status; } @@ -317,24 +315,11 @@ freeModule(Module m) void insertSymbol(Module scope, Symbol prg) { - InstrPtr sig; int t; - Module c; assert(scope); - sig = getSignature(prg); - if (getModuleId(sig) && getModuleId(sig) != scope->name) { - assert(0); - /* move the definition to the proper place */ - /* default scope is the last resort */ - c = findModule(scope, getModuleId(sig)); - if (c) - scope = c; - } - t = getSymbolIndex(getFunctionId(sig)); - if (scope->space[t] == prg) { - /* already known, last inserted */ - } else { + t = getSymbolIndex(prg->name); + if (scope->space[t] != prg) { prg->peer = scope->space[t]; scope->space[t] = prg; if (prg->peer && idcmp(prg->name, prg->peer->name) == 0) diff --git a/monetdb5/mal/mal_prelude.c b/monetdb5/mal/mal_prelude.c --- a/monetdb5/mal/mal_prelude.c +++ b/monetdb5/mal/mal_prelude.c @@ -91,17 +91,15 @@ initModule(Client c, const char *name, c Symbol s = findSymbolInModule(m, prelude); if (s) { - InstrPtr pci = getInstrPtr(s->def, 0); - - if (pci && pci->token == COMMANDsymbol && pci->argc == 1) { + if (s && s->kind == COMMANDsymbol && s->func && s->func->argc == 1) { int ret = 0; - assert(pci->fcn != NULL); - msg = (*(str (*)(int *)) pci->fcn) (&ret); + assert(s->func != NULL); + msg = (*(str (*)(int *)) s->func->imp) (&ret); (void) ret; - } else if (pci && pci->token == PATTERNsymbol) { + } else if (s && s->kind == PATTERNsymbol) { void *mb = NULL; - assert(pci->fcn != NULL); + assert(s->func->fcn != NULL); if (strcmp(name, "sql") == 0) { /* HACK ALERT: temporarily use sqlcontext to pass * the initial password to the prelude function */ @@ -111,8 +109,7 @@ initModule(Client c, const char *name, c * string in order to check that in the callee */ mb = (void *) mercurial_revision(); } - msg = (*(str (*)(Client, MalBlkPtr, MalStkPtr, InstrPtr)) pci-> - fcn) (c, mb, NULL, NULL); + msg = (*(str (*)(Client, MalBlkPtr, MalStkPtr, InstrPtr)) s->func->pimp) (c, mb, NULL, NULL); } } } @@ -179,31 +176,36 @@ addAtom(mel_atom *atoms) return MAL_SUCCEED; } -static str -makeArgument(MalBlkPtr mb, /*const*/ mel_arg *a, int *idx) +static malType +makeMalType(mel_arg *a) { - int tpe = TYPE_any; + malType tpe = TYPE_any; - if ( !a->type[0]) { + if (!a->type[0]) { + a->typeid = tpe; if (a->isbat) tpe = newBatType(tpe); if (a->nr > 0) setTypeIndex(tpe, a->nr); } else { - int mask = 0; - a->typeid = tpe = getAtomIndex(a->type, strlen(a->type), -1); + tpe = getAtomIndex(a->type, strlen(a->type), -1); + a->typeid = tpe; if (a->isbat) - tpe = newBatType(tpe) | mask; + tpe = newBatType(tpe); } - *idx = newTmpVariable(mb, tpe); - if (*idx < 0) { - char *msg = mb->errors; - mb->errors = NULL; - if (msg) - return msg; - throw(LOADER, __func__, SQLSTATE(HY013) MAL_MALLOC_FAIL); - } - return MAL_SUCCEED; + return tpe; +} + +static void +setPoly(mel_func *f, malType tpe) +{ + int any = isAnyExpression(tpe) || tpe == TYPE_any, index = 0; + if (!any) + return; + if (getTypeIndex(tpe) > 0) + index = getTypeIndex(tpe); + if (any && (index + 1) >= f->poly) + f->poly = index + 1; } //static int max_index = 0; @@ -212,11 +214,8 @@ addFunctions(mel_func *fcn) { str msg = MAL_SUCCEED; const char *mod; - int idx; Module c; Symbol s; - MalBlkPtr mb; - InstrPtr sig; for (; fcn && fcn->mod[0]; fcn++) { assert(fcn->mod); @@ -227,149 +226,51 @@ addFunctions(mel_func *fcn) if (c == NULL && (c = globalModule(mod)) == NULL) throw(LOADER, __func__, "Module %s can not be created", fcn->mod); - s = newSymbol(fcn->fcn, (fcn->kind == FK_CMD) ? COMMANDsymbol : PATTERNsymbol); + s = newSymbol(fcn->fcn, (fcn->command) ? COMMANDsymbol : PATTERNsymbol); if (s == NULL) - throw(LOADER, __func__, - "Can not create symbol for %s.%s missing", fcn->mod, + throw(LOADER, __func__, "Can not create symbol for %s.%s missing", fcn->mod, fcn->fcn); - mb = s->def; + s->def = NULL; s->func = fcn; - assert(mb); /* if this is NULL, s should have been NULL */ - - if (fcn->cname && fcn->cname[0]) - strcpy_len(mb->binding, fcn->cname, sizeof(mb->binding)); - /* keep the comment around, setting the static avoids freeing - * the string accidentally, saving on duplicate documentation in - * the code. */ - mb->statichelp = mb->help = fcn->comment; - - sig = newInstructionArgs(mb, mod, putName(fcn->fcn), - fcn->argc + (fcn->retc == 0)); - if (sig == NULL) { - freeSymbol(s); - throw(LOADER, __func__, SQLSTATE(HY013) MAL_MALLOC_FAIL); - } - sig->retc = 0; - sig->argc = 0; - sig->token = (fcn->kind == FK_CMD) ? COMMANDsymbol : PATTERNsymbol; - sig->fcn = fcn->imp; - if (fcn->unsafe) - mb->unsafeProp = 1; /* add the return variables */ - if (fcn->retc == 0) { - int idx = newTmpVariable(mb, TYPE_void); - if (idx < 0) { - freeInstruction(sig); - freeSymbol(s); - throw(LOADER, __func__, MAL_MALLOC_FAIL); - } - sig = pushReturn(mb, sig, idx); - } int i; for (i = 0; i < fcn->retc; i++) { - /*const*/ mel_arg *a = fcn->args + i; - msg = makeArgument(mb, a, &idx); - if (msg) { - freeInstruction(sig); - freeSymbol(s); - return msg; - } - sig = pushReturn(mb, sig, idx); - int tpe = getVarType(mb, idx); - if (a->nr > 0) { - /* - if (a->nr > max_index) { - max_index=a->nr; - printf("%s %d \n", fcn->fcn, a->nr); - } - */ - setPolymorphic(sig, tpe, TRUE); - fcn->poly = sig->polymorphic; - } + mel_arg *a = fcn->args + i; + malType tpe = makeMalType(a); + if (a->nr > 0) + setPoly(fcn, tpe); if (a->vargs) { - sig->varargs |= VARRETS; - fcn->vargs = true; - setPolymorphic(sig, TYPE_any, TRUE); - fcn->poly = sig->polymorphic; + fcn->vrets = true; + setPoly(fcn, TYPE_any); } } /* add the arguments */ for (i = fcn->retc; i < fcn->argc; i++) { - /*const*/ mel_arg *a = fcn->args + i; - msg = makeArgument(mb, a, &idx); - if (msg) { - freeInstruction(sig); - freeSymbol(s); - return msg; - } - sig = pushArgument(mb, sig, idx); - int tpe = getVarType(mb, idx); - if (a->nr > 0) { - /* - if (a->nr > max_index) { - max_index=a->nr; - printf("%s %d \n", fcn->fcn, a->nr); - } - */ - setPolymorphic(sig, tpe, TRUE); - fcn->poly = sig->polymorphic; - } + mel_arg *a = fcn->args + i; + malType tpe = makeMalType(a); + + if (a->nr > 0) + setPoly(fcn, tpe); if (a->vargs) { - sig->varargs |= VARARGS; fcn->vargs = true; - setPolymorphic(sig, TYPE_any, TRUE); - fcn->poly = sig->polymorphic; + setPoly(fcn, TYPE_any); } } - if (mb->errors) { - freeInstruction(sig); - freeSymbol(s); - msg = mb->errors; - mb->errors = NULL; - return msg; - } - assert(sig->retc > 0); - pushInstruction(mb, sig); - if (mb->errors) { - freeSymbol(s); _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org