PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/src/jvm/clojure/lang/Compile.java

https://github.com/franks42/clojure
Java | 83 lines | 57 code | 13 blank | 13 comment | 3 complexity | 48c0701d00db4ca6324261bdfdd8d647 MD5 | raw file
  1. /**
  2. * Copyright (c) Rich Hickey. All rights reserved.
  3. * The use and distribution terms for this software are covered by the
  4. * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
  5. * which can be found in the file epl-v10.html at the root of this distribution.
  6. * By using this software in any fashion, you are agreeing to be bound by
  7. * the terms of this license.
  8. * You must not remove this notice, or any other, from this software.
  9. **/
  10. package clojure.lang;
  11. import java.io.OutputStreamWriter;
  12. import java.io.PrintWriter;
  13. import java.io.IOException;
  14. // Compiles libs and generates class files stored within the directory
  15. // named by the Java System property "clojure.compile.path". Arguments are
  16. // strings naming the libs to be compiled. The libs and compile-path must
  17. // all be within CLASSPATH.
  18. public class Compile{
  19. private static final String PATH_PROP = "clojure.compile.path";
  20. private static final String REFLECTION_WARNING_PROP = "clojure.compile.warn-on-reflection";
  21. private static final String UNCHECKED_MATH_PROP = "clojure.compile.unchecked-math";
  22. private static final String ELIDE_META_PROP = "clojure.elide.meta";
  23. private static final Var compile_path = RT.var("clojure.core", "*compile-path*");
  24. private static final Var compile = RT.var("clojure.core", "compile");
  25. private static final Var warn_on_reflection = RT.var("clojure.core", "*warn-on-reflection*");
  26. private static final Var unchecked_math = RT.var("clojure.core", "*unchecked-math*");
  27. private static final Var elide_meta = RT.var("clojure.core", "*elide-meta*");
  28. public static void main(String[] args) throws IOException{
  29. OutputStreamWriter out = (OutputStreamWriter) RT.OUT.deref();
  30. PrintWriter err = RT.errPrintWriter();
  31. String path = System.getProperty(PATH_PROP);
  32. int count = args.length;
  33. if(path == null)
  34. {
  35. err.println("ERROR: Must set system property " + PATH_PROP +
  36. "\nto the location for compiled .class files." +
  37. "\nThis directory must also be on your CLASSPATH.");
  38. System.exit(1);
  39. }
  40. boolean warnOnReflection = System.getProperty(REFLECTION_WARNING_PROP, "false").equals("true");
  41. boolean uncheckedMath = System.getProperty(UNCHECKED_MATH_PROP, "false").equals("true");
  42. Object elide = RT.readString(System.getProperty(ELIDE_META_PROP, "nil"));
  43. try
  44. {
  45. Var.pushThreadBindings(RT.map(compile_path, path,
  46. warn_on_reflection, warnOnReflection,
  47. unchecked_math, uncheckedMath,
  48. elide_meta, elide));
  49. for(String lib : args)
  50. {
  51. out.write("Compiling " + lib + " to " + path + "\n");
  52. out.flush();
  53. compile.invoke(Symbol.intern(lib));
  54. }
  55. }
  56. finally
  57. {
  58. Var.popThreadBindings();
  59. try
  60. {
  61. out.flush();
  62. out.close();
  63. }
  64. catch(IOException e)
  65. {
  66. e.printStackTrace(err);
  67. }
  68. }
  69. }
  70. }