(QualifiedName name, Type.Callable sig)
| 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 | } |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | private void addStdNatives(Interpreter interpreter) { |
| 97 | interpreter.bindNative(QualifiedName.fromString("std::io::print"), Executor::stdIoPrint); |
no test coverage detected