Skip to content

Instantly share code, notes, and snippets.

@ninjudd
Created May 15, 2010 06:01
Show Gist options
  • Save ninjudd/402048 to your computer and use it in GitHub Desktop.
Save ninjudd/402048 to your computer and use it in GitHub Desktop.
diff --git a/src/jvm/clojure/lang/Compiler.java b/src/jvm/clojure/lang/Compiler.java
index be92476..6708f9d 100644
--- a/src/jvm/clojure/lang/Compiler.java
+++ b/src/jvm/clojure/lang/Compiler.java
@@ -568,38 +568,38 @@ public static class KeywordExpr implements Expr{
}
public Class getJavaClass() throws ClassNotFoundException{
return Keyword.class;
}
}
public static class ImportExpr implements Expr{
public final String c;
- final static Method forNameMethod = Method.getMethod("Class forName(String)");
+ final static Method forNameMethod = Method.getMethod("Class classForName(String)");
final static Method importClassMethod = Method.getMethod("Class importClass(Class)");
final static Method derefMethod = Method.getMethod("Object deref()");
public ImportExpr(String c){
this.c = c;
}
public Object eval() throws Exception{
Namespace ns = (Namespace) RT.CURRENT_NS.deref();
ns.importClass(RT.classForName(c));
return null;
}
public void emit(C context, ObjExpr objx, GeneratorAdapter gen){
gen.getStatic(RT_TYPE,"CURRENT_NS",VAR_TYPE);
gen.invokeVirtual(VAR_TYPE, derefMethod);
gen.checkCast(NS_TYPE);
gen.push(c);
- gen.invokeStatic(CLASS_TYPE, forNameMethod);
+ gen.invokeStatic(RT_TYPE, forNameMethod);
gen.invokeVirtual(NS_TYPE, importClassMethod);
if(context == C.STATEMENT)
gen.pop();
}
public boolean hasJavaClass(){
return false;
}
@ninjudd
Copy link
Author

ninjudd commented May 15, 2010

ImportExpr.emit should be consistent with ImportExpr.eval. ImportExpr.emit should generate bytecode that calls RT.classForName rather than Class.forName. This way, RT.baseLoader is used rather than using the ClassLoader of the caller, which is what Class.forName does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment