Changeset: a7d81b543e48 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a7d81b543e48 Modified Files: monetdb5/mal/Makefile.ag monetdb5/mal/mal_debugger.mx monetdb5/mal/mal_function.c monetdb5/mal/mal_instruction.mx monetdb5/mal/mal_interpreter.mx monetdb5/mal/mal_listing.c monetdb5/mal/mal_listing.h monetdb5/mal/mal_module.c monetdb5/mal/mal_profiler.mx monetdb5/mal/mal_recycle.c monetdb5/mal/mal_resolve.mx monetdb5/modules/mal/inspect.mx monetdb5/modules/mal/recycle.c monetdb5/modules/mal/remote.c monetdb5/modules/mal/replication.mx monetdb5/optimizer/opt_support.c Branch: default Log Message:
Extract MAL listing operations Backport from the headless. Small step in de-Mx. diffs (truncated from 1725 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 @@ -41,6 +41,7 @@ lib_mal = { mal_instruction.mx \ mal_interpreter.mx \ mal_linker.c mal_linker.h \ + mal_listing.c mal_listing.h \ mal_module.c mal_module.h \ mal_namespace.c mal_namespace.h \ mal_parser.mx \ diff --git a/monetdb5/mal/mal_debugger.mx b/monetdb5/mal/mal_debugger.mx --- a/monetdb5/mal/mal_debugger.mx +++ b/monetdb5/mal/mal_debugger.mx @@ -522,6 +522,7 @@ mal_export void debugLifespan(Client cnt #include "mal_atom.h" /* for showAtoms() */ #include "mal_interpreter.h" /* for getArgReference() */ #include "mal_linker.h" /* for getAddress() */ +#include "mal_listing.h" #include "mal_module.h" /* for showModuleStatistics() */ #include "mal_parser.h" #include "mal_namespace.h" diff --git a/monetdb5/mal/mal_function.c b/monetdb5/mal/mal_function.c --- a/monetdb5/mal/mal_function.c +++ b/monetdb5/mal/mal_function.c @@ -66,6 +66,7 @@ #include "mal_function.h" #include "mal_resolve.h" /* for isPolymorphic() & chkProgram() */ #include "mal_interpreter.h" /* for showErrors() */ +#include "mal_listing.h" #include "mal_namespace.h" Symbol newFunction(str mod, str nme,int kind){ diff --git a/monetdb5/mal/mal_instruction.mx b/monetdb5/mal/mal_instruction.mx --- a/monetdb5/mal/mal_instruction.mx +++ b/monetdb5/mal/mal_instruction.mx @@ -289,13 +289,6 @@ mal_export void setArgType(MalBlkPtr mb, 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 str fcnClass(InstrPtr p); -mal_export str fcnDefinition(MalBlkPtr mb, InstrPtr p, str s, int flg, str base, size_t len); -mal_export void printInstruction(stream *fd, MalBlkPtr mb, MalStkPtr stk, InstrPtr p, int flg); -mal_export str instructionCall(MalBlkPtr mb, InstrPtr p, str s, str base, size_t len); -mal_export void promptInstruction(stream *fd, MalBlkPtr mb, MalStkPtr stk, InstrPtr p, int flg); -mal_export str instruction2str(MalBlkPtr mb, MalStkPtr stl, InstrPtr p, int hidden); -mal_export str function2str(MalBlkPtr mb, int flg); mal_export void pushEndInstruction(MalBlkPtr mb); /* used in src/mal/mal_parser.c */ /* Utility macros to inspect an instruction */ #define functionStart(X) ((X)->token == FUNCTIONsymbol || \ @@ -914,22 +907,6 @@ fly. Then the expensive search is starte It also means that input which does not comply with the intended location of a temporary variable should be flagged as an error. */ -@= chkTemporary - if( isTmpName(name)){ - int j; - i= atol(name+ (*name == TMPMARKER? 1:2)); - /* quick test validity*/ - if( i< mb->vtop && isTmpVar(mb,i) && getVarTmp(mb,i) == i) - return i; - for(j=0; j< mb->vtop; j++) - if( getVarTmp(mb,j)== i && isTmpVar(mb,j)) return j; - return -1; - } -@ -@c -/* -Temporary names are not materialized as strings unless necessary. -*/ inline str getVarName(MalBlkPtr mb, int i) { @@ -982,7 +959,16 @@ findVariable(MalBlkPtr mb, str name) { int i; - @:chkTemporary@ + if( isTmpName(name)){ + int j; + i= atol(name+ (*name == TMPMARKER? 1:2)); + /* quick test validity*/ + if( i< mb->vtop && isTmpVar(mb,i) && getVarTmp(mb,i) == i) + return i; + for(j=0; j< mb->vtop; j++) + if( getVarTmp(mb,j)== i && isTmpVar(mb,j)) return j; + return -1; + } if (name == NULL) return -1; for (i = mb->vtop - 1; i >= 0; i--) @@ -1027,7 +1013,16 @@ findVariableLength(MalBlkPtr mb, str nam return i; } /* most variables are not temporary */ - @:chkTemporary@ + if( isTmpName(name)){ + int j; + i= atol(name+ (*name == TMPMARKER? 1:2)); + /* quick test validity*/ + if( i< mb->vtop && isTmpVar(mb,i) && getVarTmp(mb,i) == i) + return i; + for(j=0; j< mb->vtop; j++) + if( getVarTmp(mb,j)== i && isTmpVar(mb,j)) return j; + return -1; + } return -1; } @@ -1144,25 +1139,25 @@ Beware, the symbol table structure assum cheap to perform a linear search to a variable or constant. */ -@= makeVarSpace +static void +makeVarSpace(MalBlkPtr mb) { if (mb->vtop >= mb->vsize){ VarPtr *new; int s= mb->vtop + MAXVARS; 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; + return; } memcpy((char*)new, (char*)mb->var, sizeof(VarPtr) * mb->vtop); GDKfree(mb->var); mb->vsize= s; mb->var= new; } -@ -@c +} + int newVariable(MalBlkPtr mb, str name, malType type) { @@ -1170,7 +1165,7 @@ newVariable(MalBlkPtr mb, str name, malT if (name == NULL) return -1; - @:makeVarSpace@ + makeVarSpace(mb); if (isTmpName(name)) { int i = atol(name+ (*name == TMPMARKER? 1:2)); @@ -1250,7 +1245,7 @@ newTmpVariable(MalBlkPtr mb, malType typ { int n; - @:makeVarSpace@ + makeVarSpace(mb); n = mb->vtop; if (getVar(mb, n) == NULL) getVar(mb, n) = (VarPtr) GDKzalloc(sizeof(VarRecord) + MAXARG * sizeof(int)); @@ -2059,675 +2054,6 @@ pushEndInstruction(MalBlkPtr mb) pushInstruction(mb, p); } -/* Reverse programming -Since MAL programs can be created on the fly by linked-in query -compilers, or transformed by optimizers, it becomes -mandatory to be able to produce textual correct MAL programs -from its internal representation. - -No guarantee is given to produce the exact input for a reversed -MAL program, except that the output can be fed back for -interpretation. Provided, the code did not produce an error. - -The hiddenInstruction operator assumes a sufficiently large block -to leave information on the signature behind. - -The protection against overflow is not tight. -*/ -#define advance(X,B,L) assert(X< B+L); while(*(X) && B+L>X)(X)++; - -str -instructionCall(MalBlkPtr mb, InstrPtr p, str s, str base, size_t len) -{ - int i, closing = 0; - str tpe; - if (p->retc > 1) { - *s++ = '('; - *s = 0; - } - for (i = 0; i <= p->argc; i++) { - if (i == p->retc) { - if (i > 1 && p->retc > 1) { - *s++ = ')'; - *s = 0; - } - if (p->blk && p->blk->binding) { - snprintf(s, (len - (s - base)), " := %s(", p->blk->binding); - closing = 1; - } else if (getFunctionId(p)) { - snprintf(s, (len - (s - base)), " := %s.%s(", getModuleId(p), getFunctionId(p)); - closing = 1; - } else if (p->argc > p->retc) - sprintf(s, " := "); - advance(s, base, len); - } - if (i < p->argc && p->argv[i] >= 0) { - str nme; - char nmebuf[PATHLENGTH]; - - tpe = getTypeName(getArgType(mb, p, i)); - if (isTmpVar(mb, getArg(p, i)) || isVarTypedef(mb, getArg(p, i))) { - snprintf(nmebuf, PATHLENGTH, "%c%d", TMPMARKER, getVarTmp(mb, getArg(p, i))); - nme = nmebuf; - } else - nme = getArgName(mb, p, i); - snprintf(s, (len - (s - base)), "%s:%s", (nme ? nme : "nil"), tpe); - advance(s, base, len); - if (i != p->retc - 1 && i < p->argc - 1) - sprintf(s, ", "); - - GDKfree(tpe); - advance(s, base, len); - } - } - if (closing) - *s++ = ')'; - *s = 0; - return s; -} - -static str -hiddenInstructionArgs(MalBlkPtr mb, InstrPtr p, str s, str start, int flg, str base, size_t len) -{ - int i; - - i= (int)(s-start); - while (i++< 40) *s++= ' '; /* to give a better look to most programs */ - *s = 0; - snprintf(s, (len-(s-base)), "#%3d ", getPC(mb, p)); - advance(s,base,len); - if (p->token == REMsymbol ) - return s; - s = instructionCall(mb,p,s, base, len); -/* -The instruction is complemented with simple flags to ease debugging. -To limit the impact on test output, we only display them when they -are set. - -D = debug the function call -U = types not yet resolved -P = polymorphic instruction -G = subject to garbage control -R = subject to recycler control -J = jump towards other statement -*/ - if (flg & LIST_MAL_STMT){ - *s++ =' '; - *s++ ='{'; - switch( p->typechk){ - case TYPE_UNKNOWN: - *s++ ='U'; break; - case TYPE_RESOLVED: - /* implicit *s++ =' '; */ break; - } - if ( mb->trap && mb->stmt[0] == p) - *s++ ='D'; - if (p->polymorphic) - *s++ ='P'; - if (p->gc) - *s++ ='G'; - if (p->recycle) - *s++ ='R'; - if (p->jump){ - sprintf(s, "J%d", p->jump); - advance(s,base,len); - } - if( *(s-1) != '{') - *s++ ='}'; - else s--; - *s=0; - } - advance(s,base,len); - return s; -} - -/* -It receives the space to store the definition -The MAL profiler dumps some performance data at the -beginning of each line. -*/ - -@= showParam - tpe= getTypeName(getArgType(mb,p,i)); - if (flg & LIST_MAL_PROPS) - pstring = varGetPropStr(mb, getArg(p,i)); - else pstring = 0; - advance(t,base,len); - snprintf(t,(len-(t-base)),"%s%s", (*getArgName(mb,p,i) == TMPMARKER?"X":""), getArgName(mb, p, i)); - advance(t,base,len); - snprintf(t,(len-(t-base)),":%s%s",tpe, (pstring?pstring:"")); - advance(t,base,len); _______________________________________________ Checkin-list mailing list Checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list