summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2007-09-15 13:34:24 +0000
committerRich Hickey <richhickey@gmail.com>2007-09-15 13:34:24 +0000
commit41a8f2db3807dc7ecb98b2fce3d9314c24e91d7d (patch)
tree77ef3a0d292e52b40169a0858b8a7f187757a00a /src
parentc945972ca77ddf5618de27bc7fadaa2c33a209c5 (diff)
added class special op
Diffstat (limited to 'src')
-rw-r--r--src/jvm/clojure/lang/Compiler.java37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/jvm/clojure/lang/Compiler.java b/src/jvm/clojure/lang/Compiler.java
index b6218e35..d58807a6 100644
--- a/src/jvm/clojure/lang/Compiler.java
+++ b/src/jvm/clojure/lang/Compiler.java
@@ -75,7 +75,7 @@ static IPersistentMap specials = RT.map(
MONITOR_EXIT, new MonitorExitExpr.Parser(),
INSTANCE, new InstanceExpr.Parser(),
THISFN, null,
- CLASS, null,
+ CLASS, new ClassExpr.Parser(),
// UNQUOTE, null,
// UNQUOTE_SPLICING, null,
// SYNTAX_QUOTE, null,
@@ -857,6 +857,41 @@ static class ThrowExpr implements Expr{
}
}
+static class ClassExpr implements Expr{
+ final String className;
+ final static Method forNameMethod = Method.getMethod("Class forName(String)");
+
+
+ public ClassExpr(String className){
+ this.className = className;
+ }
+
+ public Object eval() throws Exception{
+ return Class.forName(className);
+ }
+
+ public void emit(C context, FnExpr fn, GeneratorAdapter gen){
+ if(context != C.STATEMENT)
+ {
+ gen.push(className);
+ gen.invokeStatic(CLASS_TYPE, forNameMethod);
+ }
+ }
+
+ static class Parser implements IParser{
+ public Expr parse(C context, Object frm) throws Exception{
+ ISeq form = (ISeq) frm;
+ //(class Classname)
+ if(form.count() != 2)
+ throw new Exception("wrong number of arguments, expecting: (class Classname)");
+ String className = HostExpr.maybeClassName(RT.second(form));
+ if(className == null)
+ throw new IllegalArgumentException("Unable to resolve classname: " + RT.second(form));
+ return new ClassExpr(className);
+ }
+ }
+}
+
static class InstanceExpr implements Expr{
final Expr expr;
final String className;