Mercurial > lasercutter
diff src/clojure/lang/Compile.java @ 10:ef7dbbd6452c
added clojure source goodness
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 21 Aug 2010 06:25:44 -0400 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/clojure/lang/Compile.java Sat Aug 21 06:25:44 2010 -0400 1.3 @@ -0,0 +1,73 @@ 1.4 +/** 1.5 + * Copyright (c) Rich Hickey. All rights reserved. 1.6 + * The use and distribution terms for this software are covered by the 1.7 + * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 1.8 + * which can be found in the file epl-v10.html at the root of this distribution. 1.9 + * By using this software in any fashion, you are agreeing to be bound by 1.10 + * the terms of this license. 1.11 + * You must not remove this notice, or any other, from this software. 1.12 + **/ 1.13 + 1.14 + 1.15 +package clojure.lang; 1.16 + 1.17 +import java.io.OutputStreamWriter; 1.18 +import java.io.PrintWriter; 1.19 +import java.io.IOException; 1.20 + 1.21 +// Compiles libs and generates class files stored within the directory 1.22 +// named by the Java System property "clojure.compile.path". Arguments are 1.23 +// strings naming the libs to be compiled. The libs and compile-path must 1.24 +// all be within CLASSPATH. 1.25 + 1.26 +public class Compile{ 1.27 + 1.28 +private static final String PATH_PROP = "clojure.compile.path"; 1.29 +private static final String REFLECTION_WARNING_PROP = "clojure.compile.warn-on-reflection"; 1.30 +private static final Var compile_path = RT.var("clojure.core", "*compile-path*"); 1.31 +private static final Var compile = RT.var("clojure.core", "compile"); 1.32 +private static final Var warn_on_reflection = RT.var("clojure.core", "*warn-on-reflection*"); 1.33 + 1.34 +public static void main(String[] args) throws Exception{ 1.35 + 1.36 + OutputStreamWriter out = (OutputStreamWriter) RT.OUT.deref(); 1.37 + PrintWriter err = RT.errPrintWriter(); 1.38 + String path = System.getProperty(PATH_PROP); 1.39 + int count = args.length; 1.40 + 1.41 + if(path == null) 1.42 + { 1.43 + err.println("ERROR: Must set system property " + PATH_PROP + 1.44 + "\nto the location for compiled .class files." + 1.45 + "\nThis directory must also be on your CLASSPATH."); 1.46 + System.exit(1); 1.47 + } 1.48 + 1.49 + boolean warnOnReflection = System.getProperty(REFLECTION_WARNING_PROP, "false").equals("true"); 1.50 + 1.51 + try 1.52 + { 1.53 + Var.pushThreadBindings(RT.map(compile_path, path, warn_on_reflection, warnOnReflection)); 1.54 + 1.55 + for(String lib : args) 1.56 + { 1.57 + out.write("Compiling " + lib + " to " + path + "\n"); 1.58 + out.flush(); 1.59 + compile.invoke(Symbol.intern(lib)); 1.60 + } 1.61 + } 1.62 + finally 1.63 + { 1.64 + Var.popThreadBindings(); 1.65 + try 1.66 + { 1.67 + out.flush(); 1.68 + out.close(); 1.69 + } 1.70 + catch(IOException e) 1.71 + { 1.72 + e.printStackTrace(err); 1.73 + } 1.74 + } 1.75 +} 1.76 +}