private static void walkTests(List<String> args, boolean verbose) throws UserError, IOException, Throwable { boolean _verbose = verbose; if (args.size() == 0) { throw new UserError("Need a file to run through the Fortress interpreter."); } String s = args.get(0); List<String> rest = args.subList(1, args.size()); if (s.startsWith("-")) { if (s.equals("-debug")) { rest = Debug.parseOptions(rest); } else if (s.equals("-verbose")) { _verbose = true; } else invalidFlag(s, "test"); walkTests(rest, _verbose); } else { for (String file : args) { try { Iterable<? extends StaticError> errors = IterUtil.empty(); try { if (!isComponent(file)) throw new UserError(file + " is not a component file."); APIName name = NodeUtil.apiName(file); Path path = sourcePath(file, name); GraphRepository bcr = specificInterpreterRepository(path); ComponentIndex cu = bcr.getLinkedComponent(name); Driver.runTests(bcr, cu, _verbose); } catch (Throwable th) { // TODO FIXME what is the proper treatment of errors/exceptions etc.? if (th instanceof FortressException) { FortressException pe = (FortressException) th; if (pe.getStaticErrors() != null) errors = pe.getStaticErrors(); } if (th instanceof RuntimeException) throw (RuntimeException) th; if (th instanceof Error) throw (Error) th; throw new WrappedException(th, Debug.stackTraceOn()); } for (StaticError error : errors) { System.err.println(error); } // If there are no errors, // all components will have been written to disk // by the CacheBasedRepository. } catch (StaticError e) { System.err.println(e); if (Debug.stackTraceOn()) { e.printStackTrace(); } } catch (RepositoryError e) { System.err.println(e.getMessage()); } catch (FortressException e) { failureBoilerplate(e); System.exit(1); } } } }
public static FValue eval(String file, List<String> args, boolean unCacheWhenDone) throws Throwable { setPhaseOrder(PhaseOrder.interpreterPhaseOrder); if (!isComponent(file)) throw new UserError(file + " is not a component file."); APIName name = NodeUtil.apiName(file); Path path = sourcePath(file, name); GraphRepository bcr = specificInterpreterRepository(path); ComponentIndex c = bcr.getLinkedComponent(name); FValue result = Driver.runProgram(bcr, c, args); bcr.deleteComponent(c.ast().getName(), unCacheWhenDone); return result; }
private static Iterable<? extends StaticError> compilerPhases( Path path, String file, Option<String> out, boolean link) throws UserError { GraphRepository bcr = null; Debug.debug(Debug.Type.FORTRESS, 2, "Compiling file ", file); APIName name = null; try { bcr = specificRepository(path); name = cuName(file); if (isApi(file)) { Api a = (Api) bcr.getApi(name).ast(); if (out.isSome()) ASTIO.writeJavaAst( a, // defaultRepository.getApi(name).ast(), out.unwrap()); } else if (isComponent(file)) { Component c; if (link) c = (Component) bcr.getLinkedComponent(name).ast(); else c = (Component) bcr.getComponent(name).ast(); if (out.isSome()) { ASTIO.writeJavaAst( c, // defaultRepository.getComponent(name).ast(), out.unwrap()); bcr.deleteComponent(name, true); } } else { throw new UserError( "What kind of file is " + file + "? Name should end with .fsi or .fss."); } } catch (ProgramError pe) { Iterable<? extends StaticError> se = pe.getStaticErrors(); if (se == null) return IterUtil.singleton(new WrappedException(pe, Debug.stackTraceOn())); else return flattenErrors(se); } catch (RepositoryError ex) { throw ex; } catch (FileNotFoundException ex) { throw new WrappedException(ex); } catch (IOException e) { throw new WrappedException(e); } catch (StaticError ex) { return flattenErrors(ex); } catch (CompilerBug e) { return IterUtil.singleton(new WrappedException(e, Debug.stackTraceOn())); } catch (InterpreterBug e) { return IterUtil.singleton(new WrappedException(e, Debug.stackTraceOn())); } catch (FortressException e) { failureBoilerplate(e); System.exit(1); } finally { if (bcr != null && name != null) bcr.deleteComponent(name, false); } if (bcr != null && bcr.verbose()) System.err.println("Compiling done."); return IterUtil.empty(); }