📄 mal_interpreter.c
字号:
ret = createScriptException(mb, stkpc, MAL, NULL, "%s: Unknown barrier type", getVarName(mb, getDestVar(pci))); }}#line 743 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_interpreter.mx" stkpc++; break; case LEAVEsymbol: case REDOsymbol: v= &stk->stk[getDestVar(pci)]; /* skip to end of barrier, depending on the type */ switch(v->vtype){ case TYPE_bit: if( v->val.cval[0] == TRUE && v->val.cval[0] != bit_nil) stkpc= pci->jump; else stkpc++; break; case TYPE_chr: if( v->val.cval[0] ) stkpc= pci->jump; else stkpc++; break; case TYPE_str: if( v->len > 0 && v->val.pval!= str_nil ) stkpc= pci->jump; else stkpc++; break; case TYPE_sht: if( v->val.shval >= 0 && v->val.shval!= sht_nil ) stkpc= pci->jump; else stkpc++; break; case TYPE_bat: if( v->val.bval > 0 ) stkpc= pci->jump; else stkpc++; break; case TYPE_int: if( v->val.ival >= 0 && v->val.ival!= int_nil ) stkpc= pci->jump; else stkpc++; break; case TYPE_wrd: if( v->val.wval >= 0 && v->val.wval!= wrd_nil ) stkpc= pci->jump; else stkpc++; break; case TYPE_bte: if( v->val.btval >= 0 && v->val.btval!= bte_nil ) stkpc= pci->jump; else stkpc++; break; case TYPE_lng: if( v->val.lval >= 0 && v->val.lval!= lng_nil) stkpc= pci->jump; else default: stkpc++; } break; case CATCHsymbol: /* catch blocks are skipped unless searched for explicitly*/ if(exceptionVar < 0) { stkpc= pci->jump; break; } exceptionVar = -1; stkpc++; break; case EXITsymbol: if( getDestVar(pci) == exceptionVar) exceptionVar = -1; stkpc++; break; case RAISEsymbol: exceptionPC = stkpc; exceptionVar = getDestVar(pci); if (getVarType(mb, getDestVar(pci)) == TYPE_str) { ret = createScriptException(mb, stkpc, MAL, NULL, stk->stk[getDestVar(pci)].val.sval); } else ret = createScriptException(mb, stkpc, MAL, NULL, "Exception raised"); #line 1188 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_interpreter.mx" if( stk->cmd == 'C') { stk->cmd = 'n'; mdbStep(cntxt,mb,stk,stkpc); if( stk->cmd == 'x') { stkpc = mb->stop; continue; } } /* skip to catch block or end */ for( ; stkpc<mb->stop; stkpc++){ InstrPtr l= getInstrPtr(mb,stkpc); if( l->barrier == CATCHsymbol ){ int j= -1; for(j=0;j<l->retc; j++) if( getArg(l,j) == exceptionVar) break; if(j>=0) break; } } if( stkpc== mb->stop) { #line 1484 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_interpreter.mx"#ifdef MALprofiler if( malProfileMode == 0) /* mostly true */; else{ if( mb->profiler== NULL) initProfiler(mb); newclk= GDKusec(); mb->profiler[stkpc].counter++; mb->profiler[stkpc].ticks += (long) (newclk - mb->profiler[stkpc].clk); if( mb->profiler[stkpc].clk) profilerEvent(cntxt->nspace,mb,stk,stkpc); }#endif#line 1207 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_interpreter.mx" continue; }#line 822 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_interpreter.mx" break; case YIELDsymbol: /* to be defined */ if( oldtimer) cntxt->timer= oldtimer; return yieldFactory( mb, pci, stkpc); case RETURNsymbol: /* Return from factory involves cleanup */ if( getInstrPtr(mb,0)->token == FACTORYsymbol){ yieldResult(mb,pci,stkpc); shutdownFactory(mb); } else /* a fake multi-assignment */ if( env != NULL && pcicaller != NULL){ InstrPtr pp=pci; #line 1484 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_interpreter.mx"#ifdef MALprofiler if( malProfileMode == 0) /* mostly true */; else{ if( mb->profiler== NULL) initProfiler(mb); newclk= GDKusec(); mb->profiler[stkpc].counter++; mb->profiler[stkpc].ticks += (long) (newclk - mb->profiler[stkpc].clk); if( mb->profiler[stkpc].clk) profilerEvent(cntxt->nspace,mb,stk,stkpc); }#endif#line 838 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_interpreter.mx" pci= pcicaller; for(i=0;i < pci->retc; i++){ rhs = &stk->stk[pp->argv[i]]; lhs = &env->stk[pci->argv[i]]; VALcopy2(lhs,rhs); if( lhs->vtype == TYPE_bat ) BBPincref(lhs->val.br.id, TRUE); } if( garbageControl(getInstrPtr(mb,0)) ) garbageCollector(mb, stk, TRUE); /* reset the clock */ if( oldtimer) cntxt->timer= oldtimer; } else { #line 1484 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_interpreter.mx"#ifdef MALprofiler if( malProfileMode == 0) /* mostly true */; else{ if( mb->profiler== NULL) initProfiler(mb); newclk= GDKusec(); mb->profiler[stkpc].counter++; mb->profiler[stkpc].ticks += (long) (newclk - mb->profiler[stkpc].clk); if( mb->profiler[stkpc].clk) profilerEvent(cntxt->nspace,mb,stk,stkpc); }#endif#line 853 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_interpreter.mx" } stkpc= mb->stop; continue; default: stkpc++; }#line 452 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_interpreter.mx" #line 1484 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_interpreter.mx"#ifdef MALprofiler if( malProfileMode == 0) /* mostly true */; else{ if( mb->profiler== NULL) initProfiler(mb); newclk= GDKusec(); mb->profiler[stkpc].counter++; mb->profiler[stkpc].ticks += (long) (newclk - mb->profiler[stkpc].clk); if( mb->profiler[stkpc].clk) profilerEvent(cntxt->nspace,mb,stk,stkpc); }#endif#line 453 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_interpreter.mx" } #line 660 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_interpreter.mx" if( exceptionVar >= 0) { if (ret) { ret = createScriptException(mb, mb->stop-1, getExceptionType(getVarName(mb,exceptionVar)), ret, "Exception not catched"); } else { if (stk->stk[exceptionVar].vtype == TYPE_str) { ret = createScriptException(mb, mb->stop-1, MAL, stk->stk[exceptionVar].val.sval, "Exception not catched"); } else { ret = createScriptException(mb, mb->stop-1, MAL, NULL, "Exception not catched"); } } }#line 455 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_interpreter.mx" return ret;}#line 474 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_interpreter.mx"typedef struct{ InstrPtr p; int pending; lng cost;} *FlowStep, FlowStepRec;#define DEBUG_FLOW#line 485 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_interpreter.mx"lngMALflowCost(MalBlkPtr mb, MalStkPtr stk, InstrPtr p){ int i,bid; lng cost=0; BAT *b; for(i= p->retc; i<p->argc; i++) if( isaBatType(getArgType(mb,p,i)) && (bid= ABS(stk->stk[getArg(p,i)].val.bval)) ){ b= BATdescriptor(bid); if( b == NULL) continue; cost += BATcount(b); BBPreleaseref(bid); } return cost;}voidaddMALflowStep(FlowStep flow, int top, char *pending, MalBlkPtr mb, MalStkPtr stk, InstrPtr p){ int j; flow[top].p= p; flow[top].pending= 0L; for(j=p->retc; j< p->argc; j++) flow[top].pending+= pending[getArg(p,j)]; for(j=0; j<p->retc; j++) pending[getArg(p,j)]= 1; flow[top].cost= MALflowCost(mb, stk,p);#ifdef DEBUG_FLOW stream_printf(GDKout,"#[%d]cost %d ",top,flow[top].cost); stream_printf(GDKout,"pending %d",flow[top].pending); printInstruction(GDKout,mb,p, 0);#endif}voiddropMALflowStep(FlowStep flow, int first, int last, char *pending, MalBlkPtr mb, MalStkPtr stk){ int i,j; InstrPtr p= flow[first].p;#ifdef DEBUG_FLOW stream_printf(GDKout,"#adjust %d ",first); printInstruction(GDKout,mb,p, 0);#endif for(j=0; j<p->retc; j++) pending[getArg(p,j)]= 0; for(i=first+1; i<last; i++){ flow[i].cost= MALflowCost(mb, stk,flow[i].p); flow[i].pending= 0; for(j=flow[i].p->retc; j< flow[i].p->argc; j++){ flow[i].pending+= pending[getArg(flow[i].p,j)]; }#ifdef DEBUG_FLOW stream_printf(GDKout,"#adjust %d cost %d ",i,flow[i].cost); stream_printf(GDKout,"pending %d",flow[i].pending); printInstruction(GDKout,mb,flow[i].p, 0);#endif }}#line 547 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_interpreter.mx"voidnxtMALflowStep(FlowStep flow, int first, int last, MalBlkPtr mb){ int i; FlowStepRec f; for( i= first; i<last; i++) if( flow[i].pending == 0 && flow[first].cost > flow[i].cost){ f= flow[first]; flow[first]= flow[i]; flow[i]= f; }#ifdef DEBUG_FLOW stream_printf(GDKout,"#next instruction %d: cost %d pending %d\n", first, flow[first].cost,flow[first].pending); printInstruction(GDKout,mb,flow[first].p, 0);#endif}str runMALdataflow( Client cntxt, MalBlkPtr mb, int startpc, int stoppc, MalStkPtr stk, MalStkPtr env, InstrPtr pcicaller){ ValPtr lhs,rhs,v; int stkpc,i,k,n; InstrPtr pci=0; int exceptionVar, exceptionPC; str ret=0; int stamp= -1; int backup[MAXARG]; str sbackup[MAXARG]; lng oldtimer=0; struct mallinfo oldMemory;#ifdef HAVE_SYS_RESOURCE_H int oldinblock=0; int oldoublock=0; struct rusage oldResource;#endif #line 1466 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_interpreter.mx"#ifdef MALprofiler lng newclk=0;#endif#line 584 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_interpreter.mx"#line 590 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_interpreter.mx" FlowStep flow; char *pending; (void) env; (void)pcicaller; assert(stoppc > startpc); flow= (FlowStep) alloca(sizeof(FlowStepRec) * (stoppc-startpc+1)); pending= (char*) alloca(sizeof(mb->vtop)); memset((char*) pending, 0, sizeof(mb->vtop)); for(n=0, i= startpc+1; i<stoppc; i++,n++) addMALflowStep(flow,n,pending, mb,stk,getInstrPtr(mb,i)); if( cntxt->flags & timerFlag) oldtimer= cntxt->timer= GDKusec(); oldMemory.arena= 0;#line 611 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_interpreter.mx" /* select the first eligible instruction */ stkpc= -1; exceptionPC = exceptionVar = -1; (void)exceptionPC; /* TODO maybe we should use this variable somewhere*/ while( ++stkpc < n ){ nxtMALflowStep(flow, stkpc,n,mb); pci = flow[stkpc].p; if( stk->cmd ) { lng t=0; if( oldtimer) t= GDKusec(); mdbStep(cntxt,mb,stk,getPC(mb,pci)); if( stk->cmd == 'x') { stkpc= mb->stop; continue; } if( oldtimer ) { /* ignore debugger waiting time*/ t= GDKusec()-t; oldtimer += t;#ifdef HAVE_SYS_RESOURCE_H getrusage(RUSAGE_SELF, &oldResource);#endif oldMemory= MT_mallinfo(); } } #line 1470 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_interpreter.mx"#ifdef MALprofiler if( malProfileMode == 0) /* mostly true */; else { if( mb->profiler== NULL) initProfiler(mb); mb->profiler[stkpc].clk= GDKusec(); time(&mb->profiler[stkpc].clock);#ifdef HAVE_TIMES times(&mb->profiler[stkpc].timer);#endif }#endif#line 638 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_interpreter.mx" ret = 0;#line 644 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_interpreter.mx" switch( pci->token){ case ASSIGNsymbol: #line 875 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_interpreter.mx"{ #line 928 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_interpreter.mx"#ifdef STACKTRACE printf("safeTarget %d\n", needsCleanup(pci)); printInstruction(GDKout,mb,pci, LIST_MAL_ALL);#endif if( needsCleanup(pci) ){ for(i=0; i<pci->retc; i++) { sbackup[i]= 0; backup[i]= 0; if( stk->stk[getArg(pci,i)].vtype == TYPE_bat){ backup[i]= stk->stk[getArg(pci,i)].val.br.id; stamp= BBPcurstamp(); } else if( stk->stk[getArg(pci,i)].vtype == TYPE_str){ backup[i]= stk->stk[getArg(pci,i)].len; sbackup[i]= stk->stk[getArg(pci,i)].val.sval; } } } #line 876 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_interpreter.mx" for(k=0, i=pci->retc; k<pci->retc && i<pci
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -