/** * Dump an error message using the exception structure */ void showException(stream *out, enum malexception type, const char *fcn, const char *format, ...) { va_list ap; str msg; va_start(ap, format); msg = createExceptionInternal(type, fcn, format, ap); va_end(ap); dumpExceptionsToStream(out, msg); freeException(msg); }
/** * Sends the exception as generated by a call to * createMalException(mb, pc, type, NULL, format, ...) to a stream */ void showScriptException(stream *out, MalBlkPtr mb, int pc, enum malexception type, const char *format, ...) { va_list ap; str msg; va_start(ap, format); msg = createMalExceptionInternal(mb, pc, type, NULL, format, ap); va_end(ap); dumpExceptionsToStream(out,msg); freeException(msg); }
str MALengine(Client c) { Symbol prg; str msg = MAL_SUCCEED; MalBlkRecord oldstate = *c->curprg->def; oldstate.stop = 0; if (c->blkmode) return MAL_SUCCEED; prg = c->curprg; if (prg == NULL) throw(SYNTAX, "mal.engine", SYNTAX_SIGNATURE); if (prg->def == NULL) throw(SYNTAX, "mal.engine", SYNTAX_SIGNATURE); if (prg->def->errors > 0) { showErrors(c); if (c->listing) printFunction(c->fdout, c->curprg->def, 0, c->listing); MSresetVariables(c, c->curprg->def, c->glb, oldstate.vtop); resetMalBlk(c->curprg->def, 1); throw(MAL, "mal.engine", PROGRAM_GENERAL); } if (prg->def->stop == 1 || MALcommentsOnly(prg->def)) return 0; /* empty block */ if (c->glb) { if (prg->def && c->glb->stksize < prg->def->vsize){ c->glb = reallocGlobalStack(c->glb, prg->def->vsize); if( c->glb == NULL) throw(MAL, "mal.engine", MAL_MALLOC_FAIL); } c->glb->stktop = prg->def->vtop; c->glb->blk = prg->def; c->glb->cmd = (c->itrace && c->itrace != 'C') ? 'n' : 0; } if (c->listing > 1) printFunction(c->fdout, c->curprg->def, 0, c->listing); /* * In interactive mode we should avoid early garbage collection of values. * This can be controlled by the clean up control at the instruction level * and marking all non-temporary variables as being (potentially) used. */ if (c->glb) { c->glb->pcup = 0; c->glb->keepAlive = TRUE; /* no garbage collection */ } if (prg->def->errors == 0) msg = (str) runMAL(c, prg->def, 0, c->glb); if (msg) { /* ignore "internal" exceptions */ str fcn = getExceptionPlace(msg); /* retrieves from "first" exception */ if (strcmp(fcn, "client.quit") != 0) dumpExceptionsToStream(c->fdout, msg); GDKfree(fcn); if (!c->listing) printFunction(c->fdout, c->curprg->def, 0, c->listing); showErrors(c); } MSresetVariables(c, prg->def, c->glb, 0); resetMalBlk(prg->def, 1); if (c->glb) { /* for global stacks avoid reinitialization from this point */ c->glb->stkbot = prg->def->vtop; } prg->def->errors = 0; if (c->itrace) mnstr_printf(c->fdout, "mdb>#EOD\n"); return msg; }