{
super.init(config);
servletContext = config.getServletContext();
interPool = new Stack();
Interpreter interp;
synchronized (servletContext) {
AppContext ctx = (AppContext)servletContext.getAttribute(appCtxAttrName);
if (ctx == null) {
ctx = new AppContext();
servletContext.setAttribute(appCtxAttrName, ctx);
interp = getInterpreter();
// Read the heap file
String realPath = servletContext.getRealPath("/");
String heapFileName = realPath + config.getInitParameter("heap");
System.out.println("loading heap " + heapFileName);
File heapFile = new File(heapFileName);
try {
FileInputStream fis = new FileInputStream(heapFileName);
BufferedInputStream bis
= new BufferedInputStream(fis, (int)heapFile.length());
GZIPInputStream gzis = new GZIPInputStream(bis);
DataInputStream dis
= new DataInputStream(new BufferedInputStream(gzis));
ctx.loadEnv(interp, dis);
} catch (IOException ex) {
System.err.println("Error loading heap:" + ex);
ex.printStackTrace();
throw new ServletException(ex);
}
ctx.setEvaluator("eval");
}
else {
interp = getInterpreter();
}
}
initExpression = config.getInitParameter("init-expression");
destroyExpression = config.getInitParameter("destroy-expression");
String main = config.getInitParameter("main-function");
if (main != null)
mainFunction = Symbol.get(main);
// = new FreeReferenceExp(Symbol.get(main), -1, interp.ctx.toplevel_env);
// Evaluate the init expression, discard the returned value and
// any exception thrown
try {
if (initExpression != null && !initExpression.equals(""))
interp.eval(initExpression);
}
catch (Exception ex) {
System.out.println("Exception evaluating the init expression: " + ex);
}