* @param filename
   * @param ifexists
   * @param environment
   */
  public static void saveModule(Module module, String filename, String ifexists, Environment environment) {
    { boolean existsP = Stella.probeFileP(filename);

      if ((!existsP) ||
          Stella.stringEqualP(ifexists, "REPLACE")) {
      }
      else if (Stella.stringEqualP(ifexists, "ASK")) {
        if (!(Stella.yesOrNoP("File `" + filename + "' already exists.  Overwrite it? (yes or no) "))) {
          Stella.ensureFileDoesNotExist(filename, "save-module");
        }
      }
      else if (Stella.stringEqualP(ifexists, "WARN")) {
        Stella.STANDARD_WARNING.nativeStream.println("Warning: File `" + filename + "' already exists, overwriting.");
      }
      else if (Stella.stringEqualP(ifexists, "ERROR")) {
        Stella.ensureFileDoesNotExist(filename, "save-module");
      }
      else {
        { OutputStringStream stream000 = OutputStringStream.newOutputStringStream();

          stream000.nativeStream.print("Unrecognized ifexists option `" + ifexists + "'");
          throw ((BadArgumentException)(BadArgumentException.newBadArgumentException(stream000.theStringReader()).fillInStackTrace()));
        }
      }
      { Module mdl000 = module;
        Context cxt000 = mdl000;

        if (mdl000 == null) {
          mdl000 = ((Module)(Stella.$MODULE$.get()));
          cxt000 = ((Context)(Stella.$CONTEXT$.get()));
        }
        { Object old$Module$000 = Stella.$MODULE$.get();
          Object old$Context$000 = Stella.$CONTEXT$.get();

          try {
            Native.setSpecial(Stella.$MODULE$, mdl000);
            Native.setSpecial(Stella.$CONTEXT$, cxt000);
            environment = environment;
            synchronized (Logic.$POWERLOOM_LOCK$) {
              { OutputFileStream stream = null;

                try {
                  stream = Stella.openOutputFile(filename, Stella.NIL);
                  Logic.doSaveModule(((Module)(Stella.$MODULE$.get())), stream);

                } finally {
                  if (stream != null) {
                    stream.free();
                  }
                }
              }
            }

          } finally {
            Stella.$CONTEXT$.set(old$Context$000);
            Stella.$MODULE$.set(old$Module$000);
          }
        }
      }
    }
  }