コード例 #1
0
ファイル: Shell.java プロジェクト: dbremner/fortress
 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;
 }
コード例 #2
0
  /* (non-Javadoc)
   * @see junit.framework.TestCase#setUp()
   */
  @Override
  protected void setUp() throws Exception {
    Shell.setPhaseOrder(PhaseOrder.interpreterPhaseOrder);
    Shell.setScala(false);
    fssFiles = new String[4];
    fsiFiles = new String[3];

    fssFiles[0] = "TestCompiledEnvironments";
    fssFiles[1] = "TestCompiledImports";
    fssFiles[2] = "TestCompiledNestedImports";
    fssFiles[3] = WellKnownNames.fortressLibrary();

    for (String fssFile : fssFiles) {
      compileTestProgram(fssFile + ".fss");
    }
    testCompiledEnv = SimpleClassLoader.loadEnvironment(fssFiles[0], false);
    testCompiledImportEnv = SimpleClassLoader.loadEnvironment(fssFiles[1], false);
    testCompiledNestedImportEnv = SimpleClassLoader.loadEnvironment(fssFiles[2], false);
    testLibraryEnv = SimpleClassLoader.loadEnvironment(fssFiles[3], false);

    fsiFiles[0] = "AsciiVal";
    fsiFiles[1] = "a.b.NestedOne";
    fsiFiles[2] = "a.b.c.d.NestedTwo";
  }
コード例 #3
0
ファイル: Shell.java プロジェクト: dbremner/fortress
  /**
   * @param tokens
   * @return
   * @throws InterruptedException
   * @throws Throwable
   */
  public static int subMain(String[] tokens) throws InterruptedException, Throwable {
    int return_code = 0;

    // Now match the assembled string.
    try {
      String what = tokens[0];
      List<String> args = Arrays.asList(tokens).subList(1, tokens.length);
      if (what.equals("compile")) {
        useCompilerLibraries();
        setTypeChecking(true);
        setPhaseOrder(PhaseOrder.compilerPhaseOrder);
        return_code = compilerPhases(args, Option.<String>none(), what);
      } else if (what.equals("junit")) {
        return_code = junit(args);
      } else if (what.equals("link")) {
        useCompilerLibraries();
        setTypeChecking(true);
        setPhaseOrder(PhaseOrder.compilerPhaseOrder);
        return_code = link(args);
      } else if (what.equals("build")) {
        useCompilerLibraries();
        setTypeChecking(true);
        setPhaseOrder(PhaseOrder.compilerPhaseOrder);
        return_code = link(args);
      } else if (what.equals("walk")) {
        useInterpreterLibraries();
        setScala(false);
        setPhaseOrder(PhaseOrder.interpreterPhaseOrder);
        walk(args);
      } else if (what.equals("api")) {
        useCompilerLibraries();
        api(args, Option.<String>none(), Option.<String>none());
      } else if (what.equals("compare")) {
        useCompilerLibraries();
        compare(args);
      } else if (what.equals("parse")) {
        useCompilerLibraries();
        return_code = parse(args, Option.<String>none());
      } else if (what.equals("unparse")) {
        useCompilerLibraries();
        unparse(args, Option.<String>none(), false, false);
      } else if (what.equals("disambiguate")) {
        useCompilerLibraries();
        setPhaseOrder(PhaseOrder.disambiguatePhaseOrder);
        return_code = compilerPhases(args, Option.<String>none(), what);
      } else if (what.equals("desugar")) {
        useCompilerLibraries();
        setTypeChecking(true);
        setObjExprDesugaring(true);
        setPhaseOrder(PhaseOrder.desugarPhaseOrder);

        return_code = compilerPhases(args, Option.<String>none(), what);
      } else if (what.equals("grammar")) {
        useCompilerLibraries();
        setPhaseOrder(PhaseOrder.grammarPhaseOrder);

        return_code = compilerPhases(args, Option.<String>none(), what);
      } else if (what.equals("typecheck")) {
        useCompilerLibraries();
        setTypeChecking(true);
        setPhaseOrder(PhaseOrder.typecheckPhaseOrder);

        return_code = compilerPhases(args, Option.<String>none(), what);
      } else if (what.equals("test-coercion")) {
        useCompilerLibraries();
        setTypeChecking(true);
        setPhaseOrder(PhaseOrder.typecheckPhaseOrder);

        return_code = compilerPhases(args, Option.<String>none(), what);
      } else if (what.equals("typecheck-old")) {
        useInterpreterLibraries();
        setScala(false);
        /* TODO: remove the next line once type checking is permanently turned on */
        setTypeChecking(true);
        setPhaseOrder(PhaseOrder.typecheckPhaseOrder);

        return_code = compilerPhases(args, Option.<String>none(), what);
      } else if (what.equals("test")) {
        useInterpreterLibraries();
        setScala(false);
        setPhaseOrder(PhaseOrder.interpreterPhaseOrder);
        walkTests(args, false);
      } else if (what.contains(ProjectProperties.COMP_SOURCE_SUFFIX)
          || (what.startsWith("-") && tokens.length > 1)) {
        useInterpreterLibraries();
        setScala(false);
        setPhaseOrder(PhaseOrder.interpreterPhaseOrder);
        walk(Arrays.asList(tokens));
      } else if (what.equals("help")) {
        useCompilerLibraries();
        printHelpMessage();
      } else if (what.equals("expand") && tokens.length == 2) {
        System.out.println(ProjectProperties.get(tokens[1], ""));
      } else {
        useCompilerLibraries();
        printUsageMessage();
      }
    } catch (StaticError e) {
      System.err.println(e);
      if (Debug.stackTraceOn()) {
        e.printStackTrace();
      }
      return_code = -1;
    } catch (UserError error) {
      System.err.println(error.getMessage());
      return_code = -1;
    } catch (IOException error) {
      System.err.println(error.getMessage());
      return_code = -2;
    } catch (CompilerBug error) {
      System.err.println(error.getMessage());
      if (Debug.stackTraceOn()) {
        error.printStackTrace();
      }
      return_code = -3;
    }

    Init.allowForLeakChecks();
    return return_code;
  }