Example #1
0
  static {
    heap = new GlobalEnvironment();
    root = heap.addModule(new ModuleEnvironment("___test___", heap));
    modules = new TestModuleResolver();

    stderr = new PrintWriter(System.err);
    stdout = new PrintWriter(System.out);
    evaluator = new Evaluator(ValueFactoryFactory.getValueFactory(), stderr, stdout, root, heap);

    evaluator.addRascalSearchPathContributor(StandardLibraryContributor.getInstance());
    URIResolverRegistry resolverRegistry = URIResolverRegistry.getInstance();

    evaluator.addRascalSearchPath(URIUtil.rootLocation("test-modules"));
    resolverRegistry.registerInput(modules);

    evaluator.addRascalSearchPath(URIUtil.rootLocation("benchmarks"));
    resolverRegistry.registerInput(
        new ClassResourceInput("benchmarks", Evaluator.class, "/org/rascalmpl/benchmark"));
    try {
      assert (false);
      throw new RuntimeException(
          "Make sure you enable the assert statement in your run configuration ( add -ea )");
    } catch (AssertionError e) {

    }
  }
Example #2
0
 @After
 public void assureEvaluatorIsSane() {
   assertTrue(evaluator.getCurrentEnvt().isRootScope());
   assertTrue(evaluator.getCurrentEnvt().isRootStackFrame());
   assertTrue(
       "When we are at the root scope and stack frame, the accumulators should be empty as well",
       evaluator.getAccumulators().empty());
 }
Example #3
0
 public RascalTutor() {
   GlobalEnvironment heap = new GlobalEnvironment();
   ModuleEnvironment root = heap.addModule(new ModuleEnvironment("___TUTOR___", heap));
   PrintWriter stderr = new PrintWriter(System.err);
   PrintWriter stdout = new PrintWriter(System.out);
   eval = new Evaluator(ValueFactoryFactory.getValueFactory(), stderr, stdout, root, heap);
   eval.addRascalSearchPathContributor(StandardLibraryContributor.getInstance());
   eval.addRascalSearchPath(URIUtil.rootScheme("tutor"));
   eval.addRascalSearchPath(URIUtil.rootScheme("courses"));
 }
Example #4
0
 public boolean runRascalTests(String command) {
   try {
     reset();
     execute(command);
     return evaluator.runTests(evaluator.getMonitor());
   } finally {
     stderr.flush();
     stdout.flush();
   }
 }
Example #5
0
 public IValue getLog(IEvaluatorContext e) {
   if (logger == null) {
     throw RuntimeExceptionFactory.permissionDenied(
         vf.string("getLog called before startLog"), e.getCurrentAST(), null);
   }
   IString result = vf.string(logger.getBuffer().toString());
   Evaluator eval = (Evaluator) e;
   eval.revertToDefaultWriters();
   logger = null;
   return result;
 }
Example #6
0
 public void test(String moduleName, int nTests) {
   testResultListener.start(nTests);
   try {
     ISourceLocation src = eval.getRascalResolver().resolveModule(moduleName);
     System.err.println("TestExecutor.test: testing " + moduleName + ", " + nTests + " tests");
     eval.call("executeTests", src);
     // System.err.println("TestExecutor.test: testing " + moduleName + " ... done");
   } catch (Exception e) {
     System.err.println(
         "TestExecutor.test: " + moduleName + " unexpected exception: " + e.getMessage());
     throw e;
   } finally {
     testResultListener.done();
   }
 }
 ComprehensionWriter(java.util.List<Expression> resultExprs, IEvaluator<Result<IValue>> ev) {
   this.ev = ev;
   this.resultExprs = resultExprs;
   this.writer = null;
   this.TF = Evaluator.__getTf();
   this.VF = ev.__getVf();
 }
Example #8
0
  public void run(String module, String[] args) throws IOException {
    if (module.endsWith(".rsc")) {
      module = module.substring(0, module.length() - 4);
    }
    module = module.replaceAll("/", "::");

    eval.doImport(null, module);
    // eval.eval("")
    IValue v = eval.main(null, module, "main", args);

    if (v != null) {
      new StandardTextWriter(true).write(v, eval.getStdOut());
      eval.getStdOut().flush();
    }

    return;
  }
Example #9
0
  private void reset() {
    heap.clear();
    root.reset();

    modules.reset();

    evaluator.getAccumulators().clear();
  }
Example #10
0
  @Override
  public void run() {
    while (running) {
      AbstractAST current = eval.getCurrentAST();
      Environment env = eval.getCurrentEnvt();
      String name = env.getName();

      if (current != null) {
        ISourceLocation stat = current.getLocation();
        if (stat != null) {
          Count currentCount = ast.get(stat);
          if (currentCount == null) {
            ast.put(stat, new Count());
            names.put(stat, name);
          } else {
            currentCount.increment();
          }
        }
        while (env.getParent() != null && !env.getParent().isRootScope()) {
          env = env.getParent();
        }
        if (env != null) {
          Count currentCount = frame.get(env.getLocation());
          if (currentCount == null) {
            frame.put(env.getLocation(), new Count());
            names.put(env.getLocation(), env.getName());
          } else {
            currentCount.increment();
          }
        }
      }
      try {
        sleep(resolution);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
  }
  /* (non-Javadoc)
   * @see org.eclipse.debug.internal.core.sourcelookup.ISourcePathComputerDelegate#computeSourceContainers(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.core.runtime.IProgressMonitor)
   */
  public ISourceContainer[] computeSourceContainers(
      ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException {
    String project =
        configuration.getAttribute(IRascalResources.ATTR_RASCAL_PROJECT, (String) null);

    if (project != null) {
      IProject associatedProject = ResourcesPlugin.getWorkspace().getRoot().getProject(project);
      Evaluator eval = ProjectEvaluatorFactory.getInstance().getEvaluator(associatedProject);
      List<ISourceLocation> path = eval.getRascalResolver().collect();
      ISourceContainer[] result = new ISourceContainer[path.size() + 1];

      int i = 0;
      for (ISourceLocation elem : path) {
        result[i++] = new URISourceContainer(elem);
      }

      result[i++] = new DummyConsoleSourceContainer();

      return result;
    } else {
      /* default case */
      return new ISourceContainer[] {new DummyConsoleSourceContainer()};
    }
  }
Example #12
0
  private boolean execute(String command) {
    Result<IValue> result = evaluator.eval(null, command, URIUtil.rootLocation("stdin"));

    if (result.getType().isBottom()) {
      return true;
    }
    if (result.getValue() == null) {
      return false;
    }

    if (result.getType() == TypeFactory.getInstance().boolType()) {
      return ((IBool) result.getValue()).getValue();
    }

    return false;
  }
Example #13
0
 @Override
 public void run() {
   while (running) {
     AbstractAST stat = eval.getCurrentAST();
     if (stat != null) {
       Count currentCount = data.get(stat);
       if (currentCount == null) data.put(stat, new Count());
       else currentCount.increment();
     }
     try {
       sleep(resolution);
     } catch (InterruptedException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   }
 }
Example #14
0
  public void report() {

    List<Map.Entry<AbstractAST, Count>> sortedData = sortData();

    int maxURL = 1;
    long nTicks = 0;

    for (Map.Entry<AbstractAST, Count> e : sortedData) {
      URI url = e.getKey().getLocation().getURI();
      int sz = url.toString().length();
      if (sz > maxURL) maxURL = sz;
      nTicks += e.getValue().getTicks();
    }
    PrintWriter out = eval.getStdOut();
    String URLFormat = "%" + maxURL + "s";
    out.printf(
        "PROFILE: %d data points, %d ticks, tick = %d milliSecs\n",
        data.size(), nTicks, resolution);
    out.printf(URLFormat + "%11s%8s%9s  %s\n", " Source File", "Lines", "Ticks", "%", "Source");

    for (Map.Entry<AbstractAST, Count> e : sortedData) {
      ISourceLocation L = e.getKey().getLocation();

      String uri = L.getURI().toString();
      String filePrefix = "file://";
      if (uri.startsWith(filePrefix)) uri = uri.substring(filePrefix.length());

      int bgn = L.getBeginLine();
      int end = L.getEndLine();
      String range = (end == bgn) ? Integer.toString(bgn) : bgn + ".." + end;

      int ticks = e.getValue().getTicks();
      double perc = (ticks * 100.0) / nTicks;

      String source =
          String.format(
              "%-30.30s",
              e.getKey().toString().replaceFirst("^[\\s]+", "").replaceAll("[\\s]+", " "));

      out.printf(URLFormat + "%11s%8d%8.1f%%  %s\n", uri, range, ticks, perc, source);
    }
    // Make sure that our output is seen:
    out.flush();
  }
Example #15
0
  private void report(String title, Map<ISourceLocation, Count> data) {
    List<Map.Entry<ISourceLocation, Count>> sortedData = sortData(data);

    int maxName = 1;
    long nTicks = 0;

    for (Map.Entry<ISourceLocation, Count> e : sortedData) {
      int sz = names.get(e.getKey()).length();
      if (sz > maxName) {
        maxName = sz;
      }
      nTicks += e.getValue().getTicks();
    }

    PrintWriter out = eval.getStdOut();
    String nameFormat = "%" + maxName + "s";
    out.printf(
        title + " PROFILE: %d data points, %d ticks, tick = %d milliSecs\n",
        ast.size(),
        nTicks,
        resolution);
    out.printf(nameFormat + "%8s%9s  %s\n", " Scope", "Ticks", "%", "Source");

    for (Map.Entry<ISourceLocation, Count> e : sortedData) {
      String L = e.getKey().toString();
      String name = names.get(e.getKey());

      int ticks = e.getValue().getTicks();
      double perc = (ticks * 100.0) / nTicks;

      if (perc < 1.0) {
        break;
      }

      String source = String.format("%s", L);

      out.printf(nameFormat + "%8d%8.1f%%  %s\n", name, ticks, perc, source);
    }

    // Make sure that our output is seen:
    out.flush();
  }
Example #16
0
 public void addRascalSearchPathContributor(ISourceLocation loc) {
   eval.addRascalSearchPath(loc);
 }
Example #17
0
 public void report() {
   report("FRAMES", frame);
   eval.getStdOut().println();
   report("ASTS", ast);
 }
Example #18
0
 public void startLog(IEvaluatorContext e) {
   Evaluator eval = (Evaluator) e;
   logger = new StringWriter();
   eval.overrideDefaultWriters(new PrintWriter(logger), eval.getStdErr());
 }
Example #19
0
 public URIResolverRegistry getResolverRegistry() {
   return eval.getResolverRegistry();
 }
Example #20
0
  public void start(final int port, IRascalMonitor monitor) throws Exception {
    monitor.startJob("Loading Course Manager");
    eval.eval(monitor, "import " + "CourseManager" + ";", URIUtil.rootScheme("stdin"));
    monitor.endJob(true);

    Log.setLog(
        new Logger() {

          @Override
          public String getName() {
            return "no logger";
          }

          @Override
          public void warn(String msg, Object... args) {}

          @Override
          public void warn(Throwable thrown) {}

          @Override
          public void warn(String msg, Throwable thrown) {}

          @Override
          public void info(String msg, Object... args) {}

          @Override
          public void info(Throwable thrown) {}

          @Override
          public void info(String msg, Throwable thrown) {}

          @Override
          public boolean isDebugEnabled() {
            return false;
          }

          @Override
          public void setDebugEnabled(boolean enabled) {}

          @Override
          public void debug(String msg, Object... args) {}

          @Override
          public void debug(Throwable thrown) {}

          @Override
          public void debug(String msg, Throwable thrown) {}

          @Override
          public Logger getLogger(String name) {
            return this;
          }

          @Override
          public void ignore(Throwable ignored) {}
        });

    monitor.startJob("Starting Webserver");
    server = new Server();

    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);
    connector.setMaxIdleTime(30000);
    connector.setResponseHeaderSize(1000 * 1000);
    connector.setRequestBufferSize(1000 * 1000);
    connector.setConfidentialPort(8443);

    server.setConnectors(new Connector[] {connector});
    server.setHandler(getTutorHandler());
    server.start();
    monitor.endJob(true);
  }