Skip to content

Commit

Permalink
added compiler-options map, moved elide-meta to use that, added disab…
Browse files Browse the repository at this point in the history
…le-locals-clearing
  • Loading branch information
richhickey committed Mar 13, 2012
1 parent 0131c58 commit 4036c77
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 14 deletions.
6 changes: 4 additions & 2 deletions build.xml
Expand Up @@ -47,7 +47,8 @@
failonerror="true"
fork="true">
<sysproperty key="clojure.compile.path" value="${build}"/>
<!--<sysproperty key="clojure.elide.meta" value="[:doc :file :line :added :static :private :arglists]"/>-->
<!--<sysproperty key="clojure.compiler.elide-meta" value="[:doc :file :line :added]"/>-->
<!--<sysproperty key="clojure.compiler.disable-locals-clearing" value="true"/>-->
<!-- <sysproperty key="clojure.compile.warn-on-reflection" value="true"/> -->
<arg value="clojure.core"/>
<arg value="clojure.core.protocols"/>
Expand Down Expand Up @@ -86,7 +87,8 @@
failonerror="true"
fork="true">
<sysproperty key="clojure.compile.path" value="${test-classes}"/>
<!--<sysproperty key="clojure.elide.meta" value="[:doc]"/>-->
<!--<sysproperty key="clojure.compiler.elide-meta" value="[:doc]"/>-->
<!--<sysproperty key="clojure.compiler.disable-locals-clearing" value="true"/>-->
<arg value="clojure.test-clojure.protocols.examples"/>
<arg value="clojure.test-clojure.genclass.examples"/>
</java>
Expand Down
8 changes: 6 additions & 2 deletions src/clj/clojure/core.clj
Expand Up @@ -5707,8 +5707,12 @@
coercions will be done without overflow checks. Default: false."
{:added "1.3"})

(add-doc-and-meta *elide-meta*
"Bind to a collection of metadata keys to elide during compilation.
(add-doc-and-meta *compiler-options*
"A map of keys to options.
Note, when binding dynamically make sure to merge with previous value.
Supported options:
:elide-meta - a collection of metadata keys to elide during compilation.
:disable-locals-clearing - set to true to disable clearing, useful for using a debugger
Alpha, subject to change."
{:added "1.4"})

Expand Down
23 changes: 19 additions & 4 deletions src/jvm/clojure/lang/Compile.java
Expand Up @@ -14,6 +14,9 @@
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Map;

// Compiles libs and generates class files stored within the directory
// named by the Java System property "clojure.compile.path". Arguments are
Expand All @@ -25,13 +28,12 @@ public class Compile{
private static final String PATH_PROP = "clojure.compile.path";
private static final String REFLECTION_WARNING_PROP = "clojure.compile.warn-on-reflection";
private static final String UNCHECKED_MATH_PROP = "clojure.compile.unchecked-math";
private static final String ELIDE_META_PROP = "clojure.elide.meta";

private static final Var compile_path = RT.var("clojure.core", "*compile-path*");
private static final Var compile = RT.var("clojure.core", "compile");
private static final Var warn_on_reflection = RT.var("clojure.core", "*warn-on-reflection*");
private static final Var unchecked_math = RT.var("clojure.core", "*unchecked-math*");
private static final Var elide_meta = RT.var("clojure.core", "*elide-meta*");
private static final Var compiler_options = RT.var("clojure.core", "*compiler-options*");

public static void main(String[] args) throws IOException{

Expand All @@ -50,14 +52,27 @@ public static void main(String[] args) throws IOException{

boolean warnOnReflection = System.getProperty(REFLECTION_WARNING_PROP, "false").equals("true");
boolean uncheckedMath = System.getProperty(UNCHECKED_MATH_PROP, "false").equals("true");
Object elide = RT.readString(System.getProperty(ELIDE_META_PROP, "nil"));

Object compilerOptions = null;

for(Map.Entry e : System.getProperties().entrySet())
{
String name = (String) e.getKey();
String v = (String) e.getValue();
if(name.startsWith("clojure.compiler."))
{
compilerOptions = RT.assoc(compilerOptions
,RT.keyword(null,name.substring(1 + name.lastIndexOf('.')))
,RT.readString(v));
}
}

try
{
Var.pushThreadBindings(RT.map(compile_path, path,
warn_on_reflection, warnOnReflection,
unchecked_math, uncheckedMath,
elide_meta, elide));
compiler_options, compilerOptions));

for(String lib : args)
{
Expand Down
18 changes: 12 additions & 6 deletions src/jvm/clojure/lang/Compiler.java
Expand Up @@ -239,17 +239,23 @@ public class Compiler implements Opcodes{
static final public Var ADD_ANNOTATIONS = Var.intern(Namespace.findOrCreate(Symbol.intern("clojure.core")),
Symbol.intern("add-annotations"));

//collection of keys
static final public Var ELIDE_META = Var.intern(Namespace.findOrCreate(Symbol.intern("clojure.core")),
Symbol.intern("*elide-meta*"), null).setDynamic();
static final public Keyword disableLocalsClearingKey = Keyword.intern("disable-locals-clearing");
static final public Keyword elideMetaKey = Keyword.intern("elide-meta");

static final public Var COMPILER_OPTIONS = Var.intern(Namespace.findOrCreate(Symbol.intern("clojure.core")),
Symbol.intern("*compiler-options*"), null).setDynamic();

static public Object getCompilerOption(Keyword k){
return RT.get(COMPILER_OPTIONS.deref(),k);
}

static Object elideMeta(Object m){
Collection<Object> elides = (Collection<Object>) ELIDE_META.get();
Collection<Object> elides = (Collection<Object>) getCompilerOption(elideMetaKey);
if(elides != null)
{
for(Object k : elides)
{
//System.out.println("Eliding:" + k + " : " + RT.get(m, k));
// System.out.println("Eliding:" + k + " : " + RT.get(m, k));
m = RT.dissoc(m, k);
}
// System.out.println("Remaining: " + RT.keys(m));
Expand Down Expand Up @@ -5450,7 +5456,7 @@ public static class LocalBinding{
public final String name;
public final boolean isArg;
public final PathNode clearPathRoot;
public boolean canBeCleared = true;
public boolean canBeCleared = !RT.booleanCast(getCompilerOption(disableLocalsClearingKey));
public boolean recurMistmatch = false;

public LocalBinding(int num, Symbol sym, Symbol tag, Expr init, boolean isArg,PathNode clearPathRoot)
Expand Down

0 comments on commit 4036c77

Please sign in to comment.