summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2009-10-30 12:19:39 -0400
committerRich Hickey <richhickey@gmail.com>2009-10-30 12:19:39 -0400
commit1c8e76b1a0e6616c780902a317a7ab9a8423288b (patch)
tree22b6d0ae65eb32a274c469a4f4c87cd89ce5743a
parenteea980a7c21525f1281acf41e2bf6a2c7ae1a3dc (diff)
newnew is now reify
-rw-r--r--src/clj/clojure/core.clj4
-rw-r--r--src/jvm/clojure/lang/Compiler.java48
2 files changed, 28 insertions, 24 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj
index 3c1b1fd9..46a7b233 100644
--- a/src/clj/clojure/core.clj
+++ b/src/clj/clojure/core.clj
@@ -4461,7 +4461,7 @@
not yet finished, calls to deref/@ will block."
[#^Callable f]
(let [fut (.submit clojure.lang.Agent/soloExecutor f)]
- (new [clojure.lang.IDeref java.util.concurrent.Future]
+ (reify [clojure.lang.IDeref java.util.concurrent.Future]
(deref [] (.get fut))
(get [] (.get fut))
(get [timeout unit] (.get fut timeout unit))
@@ -4564,7 +4564,7 @@
[]
(let [d (java.util.concurrent.CountDownLatch. 1)
v (atom nil)]
- (new [clojure.lang.IFn clojure.lang.IDeref] this
+ (reify this [clojure.lang.IFn clojure.lang.IDeref]
(deref [] (.await d) @v)
(invoke [x]
(locking d
diff --git a/src/jvm/clojure/lang/Compiler.java b/src/jvm/clojure/lang/Compiler.java
index 80458633..7d1a0633 100644
--- a/src/jvm/clojure/lang/Compiler.java
+++ b/src/jvm/clojure/lang/Compiler.java
@@ -62,6 +62,7 @@ static final Symbol CASE = Symbol.create("case*");
static final Symbol CLASS = Symbol.create("Class");
static final Symbol NEW = Symbol.create("new");
static final Symbol THIS = Symbol.create("this");
+static final Symbol REIFY = Symbol.create("reify");
//static final Symbol UNQUOTE = Symbol.create("unquote");
//static final Symbol UNQUOTE_SPLICING = Symbol.create("unquote-splicing");
//static final Symbol SYNTAX_QUOTE = Symbol.create("clojure.core", "syntax-quote");
@@ -104,6 +105,7 @@ static final public IPersistentMap specials = PersistentHashMap.create(
DOT, new HostExpr.Parser(),
ASSIGN, new AssignExpr.Parser(),
DEFCLASS, new NewInstanceExpr.DefclassParser(),
+ REIFY, new NewInstanceExpr.ReifyParser(),
// TRY_FINALLY, new TryFinallyExpr.Parser(),
TRY, new TryExpr.Parser(),
THROW, new ThrowExpr.Parser(),
@@ -2070,8 +2072,6 @@ public static class NewExpr implements Expr{
public Expr parse(C context, Object frm) throws Exception{
int line = (Integer) LINE.deref();
ISeq form = (ISeq) frm;
- if(RT.second(form) instanceof IPersistentVector)
- return NewInstanceExpr.parse(context, form);
//(new Classname args...)
if(form.count() < 2)
throw new Exception("wrong number of arguments, expecting: (new Classname args...)");
@@ -4894,6 +4894,7 @@ public static Object compile(Reader rdr, String sourcePath, String sourceName) t
CONSTANTS, PersistentVector.EMPTY,
KEYWORDS, PersistentHashMap.EMPTY,
VARS, PersistentHashMap.EMPTY
+ ,LOADER, RT.makeClassLoader()
));
try
@@ -5017,21 +5018,20 @@ static public class NewInstanceExpr extends ObjExpr{
}
}
- static Expr parse(C context, ISeq form) throws Exception{
- //(new [super then interfaces] this-name? {options}? (method-name [args] body)*)
-
+ static class ReifyParser implements IParser{
+ public Expr parse(C context, Object frm) throws Exception{
+ //(reify this-name? [interfaces] (method-name [args] body)*)
+ ISeq form = (ISeq) frm;
ObjMethod enclosingMethod = (ObjMethod) METHOD.deref();
String basename = enclosingMethod != null ?
(trimGenID(enclosingMethod.objx.name) + "$")
: (munge(currentNS().name.name) + "$");
- String simpleName = "obj__" + RT.nextID();
+ String simpleName = "reify__" + RT.nextID();
String classname = basename + simpleName;
- IPersistentVector interfaces = (IPersistentVector) RT.second(form);
-
- ISeq rform = RT.next(RT.next(form));
+ ISeq rform = RT.next(form);
- //supers might be followed by symbol naming this
+ //reify might be followed by symbol naming this
Symbol thisSym = null;
if(RT.first(rform) instanceof Symbol)
{
@@ -5039,8 +5039,15 @@ static public class NewInstanceExpr extends ObjExpr{
rform = RT.next(rform);
}
+ IPersistentVector interfaces = (IPersistentVector) RT.first(rform);
+
+
+ rform = RT.next(rform);
+
+
return build(interfaces, null, thisSym, classname, null, rform);
}
+ }
static Expr build(IPersistentVector interfaceSyms, IPersistentVector fieldSyms, Symbol thisSym, String className,
Symbol typeTag, ISeq methodForms) throws Exception{
@@ -5095,25 +5102,22 @@ static public class NewInstanceExpr extends ObjExpr{
String[] inames = interfaceNames(interfaces);
- Symbol thistag = null;
- Class stub = null;
- if(ret.isDefclass())
- {
- stub = compileStub(slashname(superClass),ret, inames);
- thistag = Symbol.intern(null,stub.getName());
- }
+ Class stub = compileStub(slashname(superClass),ret, inames);
+ Symbol thistag = Symbol.intern(null,stub.getName());
+
try
{
Var.pushThreadBindings(
RT.map(CONSTANTS, PersistentVector.EMPTY,
KEYWORDS, PersistentHashMap.EMPTY,
- VARS, PersistentHashMap.EMPTY));
+ VARS, PersistentHashMap.EMPTY
+ ));
if(ret.isDefclass())
{
- Var.pushThreadBindings(RT.map(METHOD,null,
- LOCAL_ENV,ret.fields
- ,COMPILE_STUB_SYM, Symbol.intern(null,stub.getSimpleName())
- ,COMPILE_STUB_CLASS, stub));
+ Var.pushThreadBindings(RT.map(METHOD, null,
+ LOCAL_ENV, ret.fields
+ , COMPILE_STUB_SYM, Symbol.intern(null, stub.getSimpleName())
+ , COMPILE_STUB_CLASS, stub));
}
//now (methodname [args] body)*