Responsible for parsing command-line arguments and executing the WhileyCompiler. @author David J. Pearce
| 33 | * |
| 34 | */ |
| 35 | public class Executor { |
| 36 | /** |
| 37 | * Destination directory of Wyil files. |
| 38 | */ |
| 39 | private File wyildir = new File("."); |
| 40 | /** |
| 41 | * Identify path for binary target to generate. |
| 42 | */ |
| 43 | private Trie target = Trie.fromString("main"); |
| 44 | /** |
| 45 | * WyIL dependencies to include during compilation. |
| 46 | */ |
| 47 | private List<File> whileypath = Collections.EMPTY_LIST; |
| 48 | |
| 49 | public Executor setTarget(Trie target) { |
| 50 | this.target = target; |
| 51 | return this; |
| 52 | } |
| 53 | |
| 54 | public Executor setWhileyPath(List<File> whileypath) { |
| 55 | this.whileypath = whileypath; |
| 56 | return this; |
| 57 | } |
| 58 | |
| 59 | public Executor setWyilDir(File wyildir) { |
| 60 | this.wyildir = wyildir; |
| 61 | return this; |
| 62 | } |
| 63 | |
| 64 | public boolean run(QualifiedName name, Type.Callable sig) throws IOException { |
| 65 | // |
| 66 | ArrayList<WyilFile> deps = new ArrayList<>(); |
| 67 | // Read target |
| 68 | deps.add(Compiler.readWyilFile(wyildir, this.target)); |
| 69 | // Extract any dependencies from zips |
| 70 | for(File dep : whileypath) { |
| 71 | Compiler.extractDependencies(dep,deps); |
| 72 | } |
| 73 | // Try to run the given function or method |
| 74 | Interpreter interpreter = new Interpreter(System.out, deps); |
| 75 | // Add native methods |
| 76 | addStdNatives(interpreter); |
| 77 | // Sanity check target method exists |
| 78 | Decl.Callable lambda = interpreter.getCallable(name, sig); |
| 79 | if(lambda == null) { |
| 80 | System.err.println("method not found: " + name + ", " + sig); |
| 81 | return false; |
| 82 | } else { |
| 83 | // Create the initial stack |
| 84 | Interpreter.CallStack stack = interpreter.new CallStack(); |
| 85 | try { |
| 86 | // |
| 87 | interpreter.execute(name, sig, stack); |
| 88 | return true; |
| 89 | } catch (Interpreter.RuntimeError e) { |
| 90 | e.printStackTrace(); |
| 91 | return false; |
| 92 | } |
nothing calls this directly
no test coverage detected