Permalink
Browse files

optional metadata elision during compilation

  • Loading branch information...
1 parent b8fbbac commit 87fa6c793592b7a3e99fcf9fb7cc08986889846a @richhickey richhickey committed Mar 1, 2012
Showing with 35 additions and 2 deletions.
  1. +2 −0 build.xml
  2. +5 −0 src/clj/clojure/core.clj
  3. +8 −1 src/jvm/clojure/lang/Compile.java
  4. +20 −1 src/jvm/clojure/lang/Compiler.java
View
@@ -47,6 +47,7 @@
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.compile.warn-on-reflection" value="true"/> -->
<arg value="clojure.core"/>
<arg value="clojure.core.protocols"/>
@@ -86,6 +87,7 @@
failonerror="true"
fork="true">
<sysproperty key="clojure.compile.path" value="${test-classes}"/>
+ <!--<sysproperty key="clojure.elide.meta" value="[:doc]"/>-->
<arg value="clojure.test-clojure.protocols.examples"/>
<arg value="clojure.test-clojure.genclass.examples"/>
</java>
View
@@ -5707,6 +5707,11 @@
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.
+ Alpha, subject to change."
+ {:added "1.4"})
+
(add-doc-and-meta *ns*
"A clojure.lang.Namespace object representing the current namespace."
{:added "1.0"})
@@ -25,10 +25,13 @@
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*");
public static void main(String[] args) throws IOException{
@@ -47,10 +50,14 @@ 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"));
try
{
- Var.pushThreadBindings(RT.map(compile_path, path, warn_on_reflection, warnOnReflection, unchecked_math, uncheckedMath));
+ Var.pushThreadBindings(RT.map(compile_path, path,
+ warn_on_reflection, warnOnReflection,
+ unchecked_math, uncheckedMath,
+ elide_meta, elide));
for(String lib : args)
{
@@ -239,6 +239,23 @@
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 Object elideMeta(Object m){
+ Collection<Object> elides = (Collection<Object>) ELIDE_META.get();
+ if(elides != null)
+ {
+ for(Object k : elides)
+ {
+ //System.out.println("Eliding:" + k + " : " + RT.get(m, k));
+ m = RT.dissoc(m, k);
+ }
+// System.out.println("Remaining: " + RT.keys(m));
+ }
+ return m;
+ }
//Integer
static final public Var LINE = Var.create(0).setDynamic();
@@ -490,6 +507,7 @@ else if(!(RT.second(form) instanceof Symbol))
// .without(Keyword.intern(null, "name"))
// .without(Keyword.intern(null, "added"))
// .without(Keyword.intern(null, "static"));
+ mm = (IPersistentMap) elideMeta(mm);
Expr meta = mm.count()==0 ? null:analyze(context == C.EVAL ? context : C.EXPRESSION, mm);
return new DefExpr((String) SOURCE.deref(), (Integer) LINE.deref(),
v, analyze(context == C.EVAL ? context : C.EXPRESSION, RT.third(form), v.sym.name),
@@ -4465,7 +4483,8 @@ else if(value instanceof Pattern)
if(value instanceof IObj && RT.count(((IObj) value).meta()) > 0)
{
gen.checkCast(IOBJ_TYPE);
- emitValue(((IObj) value).meta(), gen);
+ Object m = ((IObj) value).meta();
+ emitValue(elideMeta(m), gen);
gen.checkCast(IPERSISTENTMAP_TYPE);
gen.invokeInterface(IOBJ_TYPE,
Method.getMethod("clojure.lang.IObj withMeta(clojure.lang.IPersistentMap)"));

0 comments on commit 87fa6c7

Please sign in to comment.