diff options
author | Rich Hickey <richhickey@gmail.com> | 2007-07-09 16:56:13 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2007-07-09 16:56:13 +0000 |
commit | f1a5eef2542f5b40778cfb317273b4d6006d3bd4 (patch) | |
tree | 2985d2043269782cafe0e62245800600264be502 | |
parent | 08df868c33388c2e045f567b44d083a81935ef61 (diff) |
Made IObj match Obj, made meta field final in Obj
21 files changed, 897 insertions, 676 deletions
diff --git a/src/jvm/clojure/lang/AFn.java b/src/jvm/clojure/lang/AFn.java index 6e79f307..e38a9916 100644 --- a/src/jvm/clojure/lang/AFn.java +++ b/src/jvm/clojure/lang/AFn.java @@ -12,113 +12,120 @@ package clojure.lang; -public class AFn extends Obj implements IFn, Cloneable { +public abstract class AFn extends Obj implements IFn{ -public Object invoke() throws Exception { - return throwArity(); +public AFn(IPersistentMap meta){ + super(meta); } -public Object invoke(Object arg1) throws Exception { - return throwArity(); +public AFn(){ } -public Object invoke(Object arg1, Object arg2) throws Exception { - return throwArity(); +public Object invoke() throws Exception{ + return throwArity(); } -public Object invoke(Object arg1, Object arg2, Object arg3) throws Exception { - return throwArity(); +public Object invoke(Object arg1) throws Exception{ + return throwArity(); } -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4) throws Exception { - return throwArity(); +public Object invoke(Object arg1, Object arg2) throws Exception{ + return throwArity(); } -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) throws Exception { - return throwArity(); +public Object invoke(Object arg1, Object arg2, Object arg3) throws Exception{ + return throwArity(); } -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) throws Exception { - return throwArity(); +public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4) throws Exception{ + return throwArity(); +} + +public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) throws Exception{ + return throwArity(); +} + +public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) throws Exception{ + return throwArity(); } public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7) - throws Exception { - return throwArity(); + throws Exception{ + return throwArity(); } public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, - Object arg8) throws Exception { - return throwArity(); + Object arg8) throws Exception{ + return throwArity(); } public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, - Object arg8, Object arg9) throws Exception { - return throwArity(); + Object arg8, Object arg9) throws Exception{ + return throwArity(); } public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, - Object arg8, Object arg9, Object arg10) throws Exception { - return throwArity(); + Object arg8, Object arg9, Object arg10) throws Exception{ + return throwArity(); } public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, - Object arg8, Object arg9, Object arg10, Object arg11) throws Exception { - return throwArity(); + Object arg8, Object arg9, Object arg10, Object arg11) throws Exception{ + return throwArity(); } public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12) throws Exception { - return throwArity(); + Object arg8, Object arg9, Object arg10, Object arg11, Object arg12) throws Exception{ + return throwArity(); } public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13) - throws Exception { - return throwArity(); + throws Exception{ + return throwArity(); } public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14) - throws Exception { - return throwArity(); + throws Exception{ + return throwArity(); } public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, - Object arg15) throws Exception { - return throwArity(); + Object arg15) throws Exception{ + return throwArity(); } public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, - Object arg15, Object arg16) throws Exception { - return throwArity(); + Object arg15, Object arg16) throws Exception{ + return throwArity(); } public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, - Object arg15, Object arg16, Object arg17) throws Exception { - return throwArity(); + Object arg15, Object arg16, Object arg17) throws Exception{ + return throwArity(); } public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, - Object arg15, Object arg16, Object arg17, Object arg18) throws Exception { - return throwArity(); + Object arg15, Object arg16, Object arg17, Object arg18) throws Exception{ + return throwArity(); } public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, - Object arg15, Object arg16, Object arg17, Object arg18, Object arg19) throws Exception { - return throwArity(); + Object arg15, Object arg16, Object arg17, Object arg18, Object arg19) throws Exception{ + return throwArity(); } public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, Object arg15, Object arg16, Object arg17, Object arg18, Object arg19, Object arg20) - throws Exception { - return throwArity(); + throws Exception{ + return throwArity(); } @@ -126,294 +133,294 @@ public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, Object arg15, Object arg16, Object arg17, Object arg18, Object arg19, Object arg20, Object... args) - throws Exception { - return throwArity(); + throws Exception{ + return throwArity(); } -public Object applyTo(ISeq arglist) throws Exception { - return applyToHelper(this, arglist); +public Object applyTo(ISeq arglist) throws Exception{ + return applyToHelper(this, arglist); } -static public Object applyToHelper(IFn ifn, ISeq arglist) throws Exception { - switch (RT.boundedLength(arglist, 20)) - { - case 0: - return ifn.invoke(); - case 1: - return ifn.invoke(arglist.first()); - case 2: - return ifn.invoke(arglist.first() - , (arglist = arglist.rest()).first() - ); - case 3: - return ifn.invoke(arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - ); - case 4: - return ifn.invoke(arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - ); - case 5: - return ifn.invoke(arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - ); - case 6: - return ifn.invoke(arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - ); - case 7: - return ifn.invoke(arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - ); - case 8: - return ifn.invoke(arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - ); - case 9: - return ifn.invoke(arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - ); - case 10: - return ifn.invoke(arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - ); - case 11: - return ifn.invoke(arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - ); - case 12: - return ifn.invoke(arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - ); - case 13: - return ifn.invoke(arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - ); - case 14: - return ifn.invoke(arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - ); - case 15: - return ifn.invoke(arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - ); - case 16: - return ifn.invoke(arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - ); - case 17: - return ifn.invoke(arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - ); - case 18: - return ifn.invoke(arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - ); - case 19: - return ifn.invoke(arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - ); - case 20: - return ifn.invoke(arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - ); - default: - return ifn.invoke(arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , RT.seqToArray(arglist.rest())); - } +static public Object applyToHelper(IFn ifn, ISeq arglist) throws Exception{ + switch(RT.boundedLength(arglist, 20)) + { + case 0: + return ifn.invoke(); + case 1: + return ifn.invoke(arglist.first()); + case 2: + return ifn.invoke(arglist.first() + , (arglist = arglist.rest()).first() + ); + case 3: + return ifn.invoke(arglist.first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + ); + case 4: + return ifn.invoke(arglist.first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + ); + case 5: + return ifn.invoke(arglist.first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + ); + case 6: + return ifn.invoke(arglist.first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + ); + case 7: + return ifn.invoke(arglist.first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + ); + case 8: + return ifn.invoke(arglist.first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + ); + case 9: + return ifn.invoke(arglist.first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + ); + case 10: + return ifn.invoke(arglist.first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + ); + case 11: + return ifn.invoke(arglist.first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + ); + case 12: + return ifn.invoke(arglist.first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + ); + case 13: + return ifn.invoke(arglist.first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + ); + case 14: + return ifn.invoke(arglist.first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + ); + case 15: + return ifn.invoke(arglist.first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + ); + case 16: + return ifn.invoke(arglist.first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + ); + case 17: + return ifn.invoke(arglist.first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + ); + case 18: + return ifn.invoke(arglist.first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + ); + case 19: + return ifn.invoke(arglist.first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + ); + case 20: + return ifn.invoke(arglist.first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + ); + default: + return ifn.invoke(arglist.first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , (arglist = arglist.rest()).first() + , RT.seqToArray(arglist.rest())); + } } -public static Object throwArity() { - throw new IllegalArgumentException("Wrong number of args passed"); +public static Object throwArity(){ + throw new IllegalArgumentException("Wrong number of args passed"); } } diff --git a/src/jvm/clojure/lang/APersistentMap.java b/src/jvm/clojure/lang/APersistentMap.java index b986358c..f43247c6 100644 --- a/src/jvm/clojure/lang/APersistentMap.java +++ b/src/jvm/clojure/lang/APersistentMap.java @@ -74,6 +74,11 @@ static public class KeySeq extends ASeq{ this.seq = seq;
}
+ private KeySeq(IPersistentMap meta, ISeq seq){
+ super(meta);
+ this.seq = seq;
+ }
+
public Object first(){
return ((IMapEntry) seq.first()).key();
}
@@ -81,6 +86,10 @@ static public class KeySeq extends ASeq{ public ISeq rest(){
return create(seq.rest());
}
+
+ public KeySeq withMeta(IPersistentMap meta){
+ return new KeySeq(meta, seq);
+ }
}
static public class ValSeq extends ASeq{
@@ -96,6 +105,11 @@ static public class ValSeq extends ASeq{ this.seq = seq;
}
+ private ValSeq(IPersistentMap meta, ISeq seq){
+ super(meta);
+ this.seq = seq;
+ }
+
public Object first(){
return ((IMapEntry) seq.first()).val();
}
@@ -103,6 +117,10 @@ static public class ValSeq extends ASeq{ public ISeq rest(){
return create(seq.rest());
}
+
+ public ValSeq withMeta(IPersistentMap meta){
+ return new ValSeq(meta, seq);
+ }
}
}
diff --git a/src/jvm/clojure/lang/ASeq.java b/src/jvm/clojure/lang/ASeq.java index aa2893d3..aa02aa98 100644 --- a/src/jvm/clojure/lang/ASeq.java +++ b/src/jvm/clojure/lang/ASeq.java @@ -11,55 +11,64 @@ package clojure.lang;
public abstract class ASeq extends Obj implements ISeq{
-int _hash = -1;
-
-public boolean equals(Object obj) {
-
- if(!(obj instanceof Sequential))
- return false;
- ISeq ms = ((IPersistentCollection)obj).seq();
- for(ISeq s = seq();s!=null;s = s.rest(), ms = ms.rest())
- {
- if(ms == null || !RT.equal(s.first(),ms.first()))
- return false;
- }
- if(ms.rest() != null)
- return false;
-
- return true;
+transient int _hash = -1;
+
+
+protected ASeq(IPersistentMap meta){
+ super(meta);
+}
+
+
+protected ASeq(){
+}
+
+public boolean equals(Object obj){
+
+ if(!(obj instanceof Sequential))
+ return false;
+ ISeq ms = ((IPersistentCollection) obj).seq();
+ for(ISeq s = seq(); s != null; s = s.rest(), ms = ms.rest())
+ {
+ if(ms == null || !RT.equal(s.first(), ms.first()))
+ return false;
+ }
+ if(ms.rest() != null)
+ return false;
+
+ return true;
}
-public int hashCode() {
- if(_hash == -1)
- {
- int hash = 0;
- for(ISeq s = seq();s!=null;s = s.rest())
- {
- hash = RT.hashCombine(hash, RT.hash(s.first()));
- }
- this._hash = hash;
- }
- return _hash;
+public int hashCode(){
+ if(_hash == -1)
+ {
+ int hash = 0;
+ for(ISeq s = seq(); s != null; s = s.rest())
+ {
+ hash = RT.hashCombine(hash, RT.hash(s.first()));
+ }
+ this._hash = hash;
+ }
+ return _hash;
}
-public Object peek() {
- return first();
+public Object peek(){
+ return first();
}
-public IPersistentList pop() {
- return rest();
+public IPersistentList pop(){
+ return rest();
}
-public int count() {
- return 1 + RT.count(rest());
+public int count(){
+ return 1 + RT.count(rest());
}
-public ISeq seq() {
- return this;
+public ISeq seq(){
+ return this;
}
-public ISeq cons(Object o) {
- return new Cons(o, this);
+public ISeq cons(Object o){
+ return new Cons(o, this);
}
}
diff --git a/src/jvm/clojure/lang/ArraySeq.java b/src/jvm/clojure/lang/ArraySeq.java index c3ee000a..43a42071 100644 --- a/src/jvm/clojure/lang/ArraySeq.java +++ b/src/jvm/clojure/lang/ArraySeq.java @@ -18,7 +18,7 @@ final int i; //ISeq _rest; static public ArraySeq create(){ - return null; + return null; } static public ArraySeq create(Object... array){ @@ -33,12 +33,18 @@ ArraySeq(Object[] array, int i){ // this._rest = this; } -public Object first() { +ArraySeq(IPersistentMap meta, Object[] array, int i){ + super(meta); + this.array = array; + this.i = i; +} + +public Object first(){ return array[i]; } -public ISeq rest() { - if(i+1 < array.length) +public ISeq rest(){ + if(i + 1 < array.length) return new ArraySeq(array, i + 1); return null; // if(_rest == this) @@ -50,11 +56,15 @@ public ISeq rest() { // return _rest; } -public int count() { - return array.length - i; - } +public int count(){ + return array.length - i; +} public int index(){ return i; } + +public ArraySeq withMeta(IPersistentMap meta){ + return new ArraySeq(meta, array, i); +} } diff --git a/src/jvm/clojure/lang/Compiler.java b/src/jvm/clojure/lang/Compiler.java index 432a60a8..120a6e06 100644 --- a/src/jvm/clojure/lang/Compiler.java +++ b/src/jvm/clojure/lang/Compiler.java @@ -68,29 +68,29 @@ static public TRef USES = new TRef(); static public TRef FNS = new TRef(); static public IPersistentMap CHAR_MAP = - new PersistentArrayMap('-', "_DSH_", - '.', "_DOT_", - ':', "_CLN_", - '+', "_PLS_", - '>', "_GT_", - '<', "_LT_", - '=', "_EQ_", - '~', "_TLD_", - '!', "_EXC_", - '@', "_AT_", - '#', "_SHP_", - '$', "_DS_", - '%', "_PCT_", - '^', "_CRT_", - '&', "_AMP_", - '*', "_STAR_", - '{', "_LBC_", - '}', "_RBC_", - '[', "_LBK_", - ']', "_RBK_", - '/', "_FSL_", - '\\', "_BSL_", - '?', "_QM_"); + new PersistentArrayMap(new Object[]{'-', "_DSH_", + '.', "_DOT_", + ':', "_CLN_", + '+', "_PLS_", + '>', "_GT_", + '<', "_LT_", + '=', "_EQ_", + '~', "_TLD_", + '!', "_EXC_", + '@', "_AT_", + '#', "_SHP_", + '$', "_DS_", + '%', "_PCT_", + '^', "_CRT_", + '&', "_AMP_", + '*', "_STAR_", + '{', "_LBC_", + '}', "_RBC_", + '[', "_LBK_", + ']', "_RBK_", + '/', "_FSL_", + '\\', "_BSL_", + '?', "_QM_"}); private static final int MAX_POSITIONAL_ARITY = 20; @@ -1532,21 +1532,21 @@ private static Expr analyzeSymbol(Symbol sym, boolean inFnPosition) throws Excep // return new HostStaticFieldExpr((StaticMemberInvoker) sym); // //todo have InstanceMemberSymbol yield accessor when expression // else + { + String typeHint = typeHint(sym); + sym = baseSymbol(sym); + LocalBinding b = referenceLocal(sym); + if(b != null) { - String typeHint = typeHint(sym); - sym = baseSymbol(sym); - LocalBinding b = referenceLocal(sym); - if(b != null) - { - if(!inFnPosition) - b.valueTaken = true; - return new LocalBindingExpr(b, typeHint); - } - TRef v = lookupVar(sym); - if(v != null) - return new VarExpr(v, typeHint); - throw new Exception("Unable to resolve symbol: " + sym.name + " in this context"); + if(!inFnPosition) + b.valueTaken = true; + return new LocalBindingExpr(b, typeHint); } + TRef v = lookupVar(sym); + if(v != null) + return new VarExpr(v, typeHint); + throw new Exception("Unable to resolve symbol: " + sym.name + " in this context"); + } } static TRef lookupVar(Symbol sym) throws Exception{ @@ -1673,7 +1673,7 @@ static class KeyParam{ public KeyParam(LocalBindingExpr b, Expr init) throws Exception{ this.bindingExpression = b; this.init = init; - //! kw = registerKeyword((Keyword) Symbol.intern(":" + bindingExpression.b.sym.name)); + //! kw = registerKeyword((Keyword) Symbol.intern(":" + bindingExpression.b.sym.name)); } public KeyParam(LocalBindingExpr b) throws Exception{ diff --git a/src/jvm/clojure/lang/Cons.java b/src/jvm/clojure/lang/Cons.java index 65cae175..f2362510 100644 --- a/src/jvm/clojure/lang/Cons.java +++ b/src/jvm/clojure/lang/Cons.java @@ -12,30 +12,40 @@ package clojure.lang; -public class Cons extends ASeq { +public class Cons extends ASeq{ private final Object _first; private final ISeq _rest; -public Cons(Object first, ISeq rest) - { +public Cons(Object first, ISeq rest){ this._first = first; this._rest = rest; - } +} + + +public Cons(IPersistentMap meta, Object _first, ISeq _rest){ + super(meta); + this._first = _first; + this._rest = _rest; +} + +public Object first(){ + return _first; +} -public Object first() { - return _first; +public ISeq rest(){ + return _rest; } -public ISeq rest() { - return _rest; +public int count(){ + return 1 + RT.count(_rest); } -public int count() { - return 1 + RT.count(_rest); +public ISeq seq(){ + return this; } -public ISeq seq() { - return this; +public Cons withMeta(IPersistentMap meta){ + return new Cons(meta, _first, _rest); } } diff --git a/src/jvm/clojure/lang/FnSeq.java b/src/jvm/clojure/lang/FnSeq.java index 236448db..e38cc01f 100644 --- a/src/jvm/clojure/lang/FnSeq.java +++ b/src/jvm/clojure/lang/FnSeq.java @@ -15,16 +15,22 @@ public class FnSeq extends ASeq{ final Object _first;
final Delay _rest;
-public FnSeq(Object first, Delay rest) {
- this._first = first;
- this._rest = rest;
+public FnSeq(Object first, Delay rest){
+ this._first = first;
+ this._rest = rest;
}
-public Object first() {
- return _first;
+public FnSeq(IPersistentMap meta, Object first, Delay rest){
+ super(meta);
+ this._first = first;
+ this._rest = rest;
}
-public ISeq rest() {
+public Object first(){
+ return _first;
+}
+
+public ISeq rest(){
try
{
return (ISeq) _rest.force();
@@ -34,4 +40,8 @@ public ISeq rest() { throw new Error(e.toString());
}
}
+
+public FnSeq withMeta(IPersistentMap meta){
+ return new FnSeq(meta, _first, _rest);
+}
}
diff --git a/src/jvm/clojure/lang/IObj.java b/src/jvm/clojure/lang/IObj.java index 09fd94fb..6a5dae6f 100644 --- a/src/jvm/clojure/lang/IObj.java +++ b/src/jvm/clojure/lang/IObj.java @@ -11,14 +11,10 @@ package clojure.lang;
-public interface IObj {
-Object putAttr( Object key, Object val) throws Exception;
+public interface IObj{
-Object getAttr( Object key) throws Exception;
+public IPersistentMap meta();
-boolean hasAttr( Object key) throws Exception;
+public IObj withMeta(IPersistentMap meta);
-IPersistentMap attrs() throws Exception;
-
-void removeAttr(Object key) throws Exception;
}
diff --git a/src/jvm/clojure/lang/Indexer.java b/src/jvm/clojure/lang/Indexer.java deleted file mode 100644 index c2c5b3f7..00000000 --- a/src/jvm/clojure/lang/Indexer.java +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Copyright (c) Rich Hickey. All rights reserved. - * The use and distribution terms for this software are covered by the - * Common Public License 1.0 (http://opensource.org/licenses/cpl.php) - * which can be found in the file CPL.TXT at the root of this distribution. - * By using this software in any fashion, you are agreeing to be bound by - * the terms of this license. - * You must not remove this notice, or any other, from this software. - **/ - -/* rich Apr 19, 2006 */ - -package clojure.lang; - -public class Indexer extends AFn{ -} diff --git a/src/jvm/clojure/lang/IteratorSeq.java b/src/jvm/clojure/lang/IteratorSeq.java index 8cc5d70d..6cdb0bb2 100644 --- a/src/jvm/clojure/lang/IteratorSeq.java +++ b/src/jvm/clojure/lang/IteratorSeq.java @@ -14,8 +14,12 @@ import java.util.Iterator; public class IteratorSeq extends ASeq{
final Iterator iter;
-volatile Object val;
-volatile ISeq _rest;
+final State state;
+
+static class State{
+ volatile Object val;
+ volatile Object _rest;
+}
public static IteratorSeq create(Iterator iter){
if(iter.hasNext())
@@ -25,30 +29,41 @@ public static IteratorSeq create(Iterator iter){ IteratorSeq(Iterator iter){
this.iter = iter;
- this.val = this;
- this._rest = this;
+ state = new State();
+ this.state.val = state;
+ this.state._rest = state;
+}
+
+IteratorSeq(IPersistentMap meta, Iterator iter, State state){
+ super(meta);
+ this.iter = iter;
+ this.state = state;
}
public Object first(){
- if(val == this)
- synchronized(this)
+ if(state.val == state)
+ synchronized(state)
{
- if(val == this)
- val = iter.next();
+ if(state.val == state)
+ state.val = iter.next();
}
- return val;
+ return state.val;
}
public ISeq rest(){
- if(_rest == this)
- synchronized(this)
+ if(state._rest == state)
+ synchronized(state)
{
- if(_rest == this)
+ if(state._rest == state)
{
first();
- _rest = create(iter);
+ state._rest = create(iter);
}
}
- return _rest;
+ return (ISeq) state._rest;
+}
+
+public IteratorSeq withMeta(IPersistentMap meta){
+ return new IteratorSeq(meta, iter, state);
}
}
diff --git a/src/jvm/clojure/lang/LispReader.java b/src/jvm/clojure/lang/LispReader.java index 4425f84d..2511e252 100644 --- a/src/jvm/clojure/lang/LispReader.java +++ b/src/jvm/clojure/lang/LispReader.java @@ -321,6 +321,9 @@ static class StringReader extends AFn{ return sb.toString();
}
+ public Obj withMeta(IPersistentMap meta){
+ throw new UnsupportedOperationException();
+ }
}
static class CommentReader extends AFn{
@@ -334,6 +337,9 @@ static class CommentReader extends AFn{ return r;
}
+ public Obj withMeta(IPersistentMap meta){
+ throw new UnsupportedOperationException();
+ }
}
static class QuoteReader extends AFn{
@@ -342,6 +348,10 @@ static class QuoteReader extends AFn{ Object o = read(r, true, null, true);
return RT.list(QUOTE, o);
}
+
+ public Obj withMeta(IPersistentMap meta){
+ throw new UnsupportedOperationException();
+ }
}
static class BackquoteReader extends AFn{
@@ -350,6 +360,11 @@ static class BackquoteReader extends AFn{ Object o = read(r, true, null, true);
return RT.list(BACKQUOTE, o);
}
+
+ public Obj withMeta(IPersistentMap meta){
+ throw new UnsupportedOperationException();
+
+ }
}
static class UnquoteReader extends AFn{
@@ -370,6 +385,11 @@ static class UnquoteReader extends AFn{ return RT.list(UNQUOTE, o);
}
}
+
+ public Obj withMeta(IPersistentMap meta){
+ throw new UnsupportedOperationException();
+
+ }
}
static class CharacterReader extends AFn{
@@ -390,6 +410,10 @@ static class CharacterReader extends AFn{ throw new Exception("Unsupported character: \\" + token);
}
+ public Obj withMeta(IPersistentMap meta){
+ throw new UnsupportedOperationException();
+
+ }
}
static class ListReader extends AFn{
@@ -398,6 +422,10 @@ static class ListReader extends AFn{ return readDelimitedList(')', r, true);
}
+ public Obj withMeta(IPersistentMap meta){
+ throw new UnsupportedOperationException();
+
+ }
}
static class UnmatchedDelimiterReader extends AFn{
@@ -405,6 +433,10 @@ static class UnmatchedDelimiterReader extends AFn{ throw new Exception("Unmatched delimiter: " + rightdelim);
}
+ public Obj withMeta(IPersistentMap meta){
+ throw new UnsupportedOperationException();
+
+ }
}
public static ISeq readDelimitedList(char delim, PushbackReader r, boolean isRecursive) throws Exception{
diff --git a/src/jvm/clojure/lang/MapEntry.java b/src/jvm/clojure/lang/MapEntry.java index ffdda6b1..1d99ace3 100644 --- a/src/jvm/clojure/lang/MapEntry.java +++ b/src/jvm/clojure/lang/MapEntry.java @@ -49,9 +49,9 @@ public IPersistentMap assoc(Object key, Object val){ {
if(_val == val)
return this;
- return (MapEntry) new MapEntry(meta(),key, val);
+ return new MapEntry(meta(), key, val);
}
- return new PersistentArrayMap(meta(),_key, _val, key, val);
+ return new PersistentArrayMap(meta(), new Object[]{_key, _val, key, val});
}
public Object valAt(Object key){
@@ -78,6 +78,10 @@ public Iterator iterator(){ return new Iter(this);
}
+public MapEntry withMeta(IPersistentMap meta){
+ return new MapEntry(meta, _key, _val);
+}
+
static class Iter implements Iterator{
MapEntry e;
@@ -112,6 +116,11 @@ static class Seq extends ASeq{ this.e = e;
}
+ public Seq(IPersistentMap meta, MapEntry e){
+ super(meta);
+ this.e = e;
+ }
+
public Object first(){
return e;
}
@@ -123,5 +132,9 @@ static class Seq extends ASeq{ public int count(){
return 1;
}
+
+ public Obj withMeta(IPersistentMap meta){
+ return new Seq(meta, e);
+ }
}
}
diff --git a/src/jvm/clojure/lang/Obj.java b/src/jvm/clojure/lang/Obj.java index 145a6e1c..3da9c59c 100644 --- a/src/jvm/clojure/lang/Obj.java +++ b/src/jvm/clojure/lang/Obj.java @@ -12,9 +12,9 @@ package clojure.lang; -public class Obj implements Cloneable{ +public abstract class Obj implements IObj{ -private IPersistentMap _meta; +final IPersistentMap _meta; public Obj(IPersistentMap meta){ this._meta = meta; @@ -28,18 +28,6 @@ final public IPersistentMap meta(){ return _meta; } -final public Obj withMeta(IPersistentMap meta){ - if(_meta == meta) - return this; - try - { - Obj ret = (Obj) clone(); - ret._meta = meta; - return ret; - } - catch(CloneNotSupportedException ignore) - { - return null; - } -} +abstract public Obj withMeta(IPersistentMap meta); + } diff --git a/src/jvm/clojure/lang/PersistentArrayMap.java b/src/jvm/clojure/lang/PersistentArrayMap.java index 93f56de3..2ed368da 100644 --- a/src/jvm/clojure/lang/PersistentArrayMap.java +++ b/src/jvm/clojure/lang/PersistentArrayMap.java @@ -34,12 +34,16 @@ protected PersistentArrayMap(){ this.array = new Object[]{};
}
+public PersistentArrayMap withMeta(IPersistentMap meta){
+ return new PersistentArrayMap(meta, array);
+}
+
PersistentArrayMap create(Object... init){
- return new PersistentArrayMap(meta(),init);
+ return new PersistentArrayMap(meta(), init);
}
IPersistentMap createHT(Object[] init){
- return PersistentHashMap.create(meta(),init);
+ return PersistentHashMap.create(meta(), init);
}
/**
@@ -47,12 +51,12 @@ IPersistentMap createHT(Object[] init){ *
* @param init {key1,val1,key2,val2,...}
*/
-public PersistentArrayMap(Object... init){
+public PersistentArrayMap(Object[] init){
this.array = init;
}
-public PersistentArrayMap(IPersistentMap meta, Object... init){
+public PersistentArrayMap(IPersistentMap meta, Object[] init){
super(meta);
this.array = init;
}
@@ -187,6 +191,12 @@ static class Seq extends ASeq implements IMapEntry{ this.i = i;
}
+ public Seq(IPersistentMap meta, Object[] array, int i){
+ super(meta);
+ this.array = array;
+ this.i = i;
+ }
+
public Object key(){
return array[i];
}
@@ -208,6 +218,10 @@ static class Seq extends ASeq implements IMapEntry{ public int count(){
return (array.length - i) / 2;
}
+
+ public Obj withMeta(IPersistentMap meta){
+ return new Seq(meta, array, i);
+ }
}
static class Iter implements Iterator, IMapEntry{
diff --git a/src/jvm/clojure/lang/PersistentHashMap.java b/src/jvm/clojure/lang/PersistentHashMap.java index 61cea6c9..243a9bc6 100644 --- a/src/jvm/clojure/lang/PersistentHashMap.java +++ b/src/jvm/clojure/lang/PersistentHashMap.java @@ -35,7 +35,7 @@ final INode root; final public static PersistentHashMap EMPTY = new PersistentHashMap(0, new EmptyNode()); -/** +/* * @param init {key1,val1,key2,val2,...} */ public static IPersistentMap create(Object... init){ @@ -47,11 +47,11 @@ public static IPersistentMap create(Object... init){ return ret; } -/** +/* * @param init {key1,val1,key2,val2,...} */ public static IPersistentMap create(IPersistentMap meta, Object... init){ - IPersistentMap ret = (IPersistentMap) EMPTY.withMeta(meta); + IPersistentMap ret = EMPTY.withMeta(meta); for(int i = 0; i < init.length; i += 2) { ret = ret.assoc(init[i], init[i + 1]); @@ -105,7 +105,7 @@ public IPersistentMap without(Object key){ if(newroot == root) return this; if(newroot == null) - return (IPersistentMap) EMPTY.withMeta(meta()); + return EMPTY.withMeta(meta()); return new PersistentHashMap(meta(), count - 1, newroot); } @@ -126,6 +126,10 @@ static int mask(int hash, int shift){ return (hash >>> shift) & 0x01f; } +public PersistentHashMap withMeta(IPersistentMap meta){ + return new PersistentHashMap(meta, count, root); +} + /* final static int[] pathmasks = new int[32]; static{ @@ -192,8 +196,6 @@ final static class FullNode implements INode{ final int _hash; - - static int bitpos(int hash, int shift){ return 1 << mask(hash, shift); } @@ -267,6 +269,13 @@ final static class FullNode implements INode{ this.node = node; } + Seq(IPersistentMap meta, ISeq s, int i, FullNode node){ + super(meta); + this.s = s; + this.i = i; + this.node = node; + } + static ISeq create(FullNode node, int i){ if(i >= node.nodes.length) return null; @@ -283,6 +292,10 @@ final static class FullNode implements INode{ return new Seq(nexts, i, node); return create(node, i + 1); } + + public Seq withMeta(IPersistentMap meta){ + return new Seq(meta, s, i, node); + } } @@ -414,6 +427,13 @@ final static class BitmapIndexedNode implements INode{ this.node = node; } + Seq(IPersistentMap meta, ISeq s, int i, BitmapIndexedNode node){ + super(meta); + this.s = s; + this.i = i; + this.node = node; + } + static ISeq create(BitmapIndexedNode node, int i){ if(i >= node.nodes.length) return null; @@ -430,6 +450,10 @@ final static class BitmapIndexedNode implements INode{ return new Seq(nexts, i, node); return create(node, i + 1); } + + public Seq withMeta(IPersistentMap meta){ + return new Seq(meta, s, i, node); + } } @@ -582,9 +606,9 @@ public static void main(String[] args){ System.out.println("Building map"); long startTime = System.nanoTime(); - for(int i = 0; i < words.size(); i++) + for(Object word5 : words) { - map = map.assoc(words.get(i), words.get(i)); + map = map.assoc(word5, word5); } rand = new Random(42); IPersistentMap snapshotMap = map; @@ -597,9 +621,9 @@ public static void main(String[] args){ System.out.println("Building ht"); startTime = System.nanoTime(); - for(int i = 0; i < words.size(); i++) + for(Object word1 : words) { - ht.put(words.get(i), words.get(i)); + ht.put(word1, word1); } rand = new Random(42); for(int i = 0; i < words.size() / 200; i++) @@ -612,9 +636,9 @@ public static void main(String[] args){ System.out.println("map lookup"); startTime = System.nanoTime(); int c = 0; - for(int i = 0; i < words.size(); i++) + for(Object word2 : words) { - if(!map.contains(words.get(i))) + if(!map.contains(word2)) ++c; } estimatedTime = System.nanoTime() - startTime; @@ -622,9 +646,9 @@ public static void main(String[] args){ System.out.println("ht lookup"); startTime = System.nanoTime(); c = 0; - for(int i = 0; i < words.size(); i++) + for(Object word3 : words) { - if(!ht.containsKey(words.get(i))) + if(!ht.containsKey(word3)) ++c; } estimatedTime = System.nanoTime() - startTime; @@ -632,9 +656,9 @@ public static void main(String[] args){ System.out.println("snapshotMap lookup"); startTime = System.nanoTime(); c = 0; - for(int i = 0; i < words.size(); i++) + for(Object word4 : words) { - if(!snapshotMap.contains(words.get(i))) + if(!snapshotMap.contains(word4)) ++c; } estimatedTime = System.nanoTime() - startTime; diff --git a/src/jvm/clojure/lang/PersistentList.java b/src/jvm/clojure/lang/PersistentList.java index b5c18719..728cbd10 100644 --- a/src/jvm/clojure/lang/PersistentList.java +++ b/src/jvm/clojure/lang/PersistentList.java @@ -10,41 +10,50 @@ package clojure.lang;
-public class PersistentList extends ASeq {
+public class PersistentList extends ASeq{
private final Object _first;
private final PersistentList _rest;
private final int _count;
-public PersistentList(Object first) {
- this._first = first;
- this._rest = null;
+public PersistentList(Object first){
+ this._first = first;
+ this._rest = null;
- this._count = 1;
+ this._count = 1;
}
-PersistentList(Object first, PersistentList rest) {
- this._first = first;
- this._rest = rest;
+PersistentList(Object first, PersistentList rest){
+ this._first = first;
+ this._rest = rest;
- this._count = 1 + rest.count();
- //this._meta = rest._meta;
+ this._count = 1 + rest.count();
}
-public Object first() {
- return _first;
+PersistentList(IPersistentMap meta, Object _first, PersistentList _rest, int _count){
+ super(meta);
+ this._first = _first;
+ this._rest = _rest;
+ this._count = _count;
}
-public ISeq rest() {
- return _rest;
+public Object first(){
+ return _first;
}
-public int count() {
- return _count;
+public ISeq rest(){
+ return _rest;
}
-public ISeq cons(Object o) {
- return new PersistentList(o,this);
+public int count(){
+ return _count;
}
+public ISeq cons(Object o){
+ return new PersistentList(o, this);
+}
+
+public PersistentList withMeta(IPersistentMap meta){
+ return new PersistentList(meta, _first, _rest, _count);
+}
}
diff --git a/src/jvm/clojure/lang/PersistentQueue.java b/src/jvm/clojure/lang/PersistentQueue.java index bacaa30e..7a4f23e4 100644 --- a/src/jvm/clojure/lang/PersistentQueue.java +++ b/src/jvm/clojure/lang/PersistentQueue.java @@ -21,9 +21,9 @@ import java.util.LinkedList; * so no reversing or suspensions required for persistent use
*/
-public class PersistentQueue extends Obj implements IPersistentList {
+public class PersistentQueue extends Obj implements IPersistentList{
-final public static PersistentQueue EMPTY = new PersistentQueue(null,null,null);
+final public static PersistentQueue EMPTY = new PersistentQueue(null, null, null);
//*
final ISeq f;
@@ -31,166 +31,179 @@ final PersistentVector r; //static final int INITIAL_REAR_SIZE = 4;
int _hash = -1;
-PersistentQueue(ISeq f, PersistentVector r, IPersistentMap meta){
+PersistentQueue(IPersistentMap meta, ISeq f, PersistentVector r){
super(meta);
this.f = f;
this.r = r;
}
-public boolean equals(Object obj) {
+public boolean equals(Object obj){
- if(!(obj instanceof Sequential))
- return false;
- ISeq ms = ((IPersistentCollection)obj).seq();
- for(ISeq s = seq();s!=null;s = s.rest(), ms = ms.rest())
- {
- if(ms == null || !RT.equal(s.first(),ms.first()))
- return false;
- }
- return ms.rest() == null;
+ if(!(obj instanceof Sequential))
+ return false;
+ ISeq ms = ((IPersistentCollection) obj).seq();
+ for(ISeq s = seq(); s != null; s = s.rest(), ms = ms.rest())
+ {
+ if(ms == null || !RT.equal(s.first(), ms.first()))
+ return false;
+ }
+ return ms.rest() == null;
}
-public int hashCode() {
- if(_hash == -1)
- {
- int hash = 0;
- for(ISeq s = seq();s!=null;s = s.rest())
- {
- hash = RT.hashCombine(hash, RT.hash(s.first()));
- }
- this._hash = hash;
- }
- return _hash;
+public int hashCode(){
+ if(_hash == -1)
+ {
+ int hash = 0;
+ for(ISeq s = seq(); s != null; s = s.rest())
+ {
+ hash = RT.hashCombine(hash, RT.hash(s.first()));
+ }
+ this._hash = hash;
+ }
+ return _hash;
}
-public Object peek() {
- return RT.first(f);
+public Object peek(){
+ return RT.first(f);
}
-public PersistentQueue pop() {
- if(f == null) //hmmm... pop of empty queue -> empty queue?
- return this;
- //throw new IllegalStateException("popping empty queue");
- ISeq f1 = f.rest();
- PersistentVector r1 = r;
- if(f1 == null)
- {
- f1 = RT.seq(r);
- r1 = null;
- }
- return new PersistentQueue(f1, r1,meta());
+public PersistentQueue pop(){
+ if(f == null) //hmmm... pop of empty queue -> empty queue?
+ return this;
+ //throw new IllegalStateException("popping empty queue");
+ ISeq f1 = f.rest();
+ PersistentVector r1 = r;
+ if(f1 == null)
+ {
+ f1 = RT.seq(r);
+ r1 = null;
+ }
+ return new PersistentQueue(meta(), f1, r1);
}
-public int count() {
- return RT.count(f) + RT.count(r);
+public int count(){
+ return RT.count(f) + RT.count(r);
}
-public ISeq seq() {
- if(f == null)
- return null;
- return new Seq(f, RT.seq(r));
+public ISeq seq(){
+ if(f == null)
+ return null;
+ return new Seq(f, RT.seq(r));
}
-public PersistentQueue cons(Object o) {
- if(f == null) //empty
- return new PersistentQueue(RT.list(o), null,meta());
- else
- return new PersistentQueue(f,(r != null ? r : PersistentVector.EMPTY).cons(o),meta());
+public PersistentQueue cons(Object o){
+ if(f == null) //empty
+ return new PersistentQueue(meta(), RT.list(o), null);
+ else
+ return new PersistentQueue(meta(), f, (r != null ? r : PersistentVector.EMPTY).cons(o));
}
-static class Seq extends ASeq {
- final ISeq f;
- final ISeq rseq;
-
- Seq(ISeq f, ISeq rseq) {
- this.f = f;
- this.rseq = rseq;
- }
-
- public Object first() {
- return f.first();
- }
-
- public ISeq rest() {
- ISeq f1 = f.rest();
- ISeq r1 = rseq;
- if (f1 == null)
- {
- if (rseq == null)
- return null;
- f1 = rseq;
- r1 = null;
- }
- return new Seq(f1, r1);
- }
-
- public int count() {
- return RT.count(f) + RT.count(rseq);
- }
+public PersistentQueue withMeta(IPersistentMap meta){
+ return new PersistentQueue(meta, f, r);
+}
+static class Seq extends ASeq{
+ final ISeq f;
+ final ISeq rseq;
+
+ Seq(ISeq f, ISeq rseq){
+ this.f = f;
+ this.rseq = rseq;
+ }
+
+ Seq(IPersistentMap meta, ISeq f, ISeq rseq){
+ super(meta);
+ this.f = f;
+ this.rseq = rseq;
+ }
+
+ public Object first(){
+ return f.first();
+ }
+
+ public ISeq rest(){
+ ISeq f1 = f.rest();
+ ISeq r1 = rseq;
+ if(f1 == null)
+ {
+ if(rseq == null)
+ return null;
+ f1 = rseq;
+ r1 = null;
+ }
+ return new Seq(f1, r1);
+ }
+
+ public int count(){
+ return RT.count(f) + RT.count(rseq);
+ }
+
+ public Seq withMeta(IPersistentMap meta){
+ return new Seq(meta, f, rseq);
+ }
}
-public static void main(String[] args) {
- if (args.length != 1)
- {
- System.err.println("Usage: PersistentQueue n");
- return;
- }
- int n = Integer.parseInt(args[0]);
-
-
- long startTime, estimatedTime;
-
- //*
- Queue list = new LinkedList();
- //Queue list = new ConcurrentLinkedQueue();
- System.out.println("Queue");
- startTime = System.nanoTime();
- for (int i = 0; i < n; i++)
- {
- list.add(i);
- list.add(i);
- list.remove();
- }
- for (int i = 0; i < n - 10; i++)
- {
- list.remove();
- }
- estimatedTime = System.nanoTime() - startTime;
- System.out.println("time: " + estimatedTime / 1000000);
- System.out.println("peek: " + list.peek());
+public static void main(String[] args){
+ if(args.length != 1)
+ {
+ System.err.println("Usage: PersistentQueue n");
+ return;
+ }
+ int n = Integer.parseInt(args[0]);
+
+
+ long startTime, estimatedTime;
+
+ //*
+ Queue list = new LinkedList();
+ //Queue list = new ConcurrentLinkedQueue();
+ System.out.println("Queue");
+ startTime = System.nanoTime();
+ for(int i = 0; i < n; i++)
+ {
+ list.add(i);
+ list.add(i);
+ list.remove();
+ }
+ for(int i = 0; i < n - 10; i++)
+ {
+ list.remove();
+ }
+ estimatedTime = System.nanoTime() - startTime;
+ System.out.println("time: " + estimatedTime / 1000000);
+ System.out.println("peek: " + list.peek());
//*/
//*
- PersistentQueue q = PersistentQueue.EMPTY;
- System.out.println("PersistentQueue");
- startTime = System.nanoTime();
- for (int i = 0; i < n; i++)
- {
- q = q.cons(i);
- q = q.cons(i);
- q = q.pop();
- }
+ PersistentQueue q = PersistentQueue.EMPTY;
+ System.out.println("PersistentQueue");
+ startTime = System.nanoTime();
+ for(int i = 0; i < n; i++)
+ {
+ q = q.cons(i);
+ q = q.cons(i);
+ q = q.pop();
+ }
// IPersistentList lastq = null;
// IPersistentList lastq2;
- for (int i = 0; i < n - 10; i++)
- {
- //lastq2 = lastq;
- //lastq = q;
- q = q.pop();
- }
- estimatedTime = System.nanoTime() - startTime;
- System.out.println("time: " + estimatedTime / 1000000);
- System.out.println("peek: " + q.peek());
- //*/
-
- IPersistentList q2 = q;
- for (int i = 0; i < 10; i++)
- {
- q2 = (IPersistentList) q2.cons(i);
- }
+ for(int i = 0; i < n - 10; i++)
+ {
+ //lastq2 = lastq;
+ //lastq = q;
+ q = q.pop();
+ }
+ estimatedTime = System.nanoTime() - startTime;
+ System.out.println("time: " + estimatedTime / 1000000);
+ System.out.println("peek: " + q.peek());
+ //*/
+
+ IPersistentList q2 = q;
+ for(int i = 0; i < 10; i++)
+ {
+ q2 = (IPersistentList) q2.cons(i);
+ }
/*
for(ISeq s = q.seq();s != null;s = s.rest())
System.out.println("q: " + s.first().toString());
diff --git a/src/jvm/clojure/lang/PersistentTreeMap.java b/src/jvm/clojure/lang/PersistentTreeMap.java index 5f4104df..d56a803e 100644 --- a/src/jvm/clojure/lang/PersistentTreeMap.java +++ b/src/jvm/clojure/lang/PersistentTreeMap.java @@ -32,8 +32,12 @@ public PersistentTreeMap(){ this(null); } +public PersistentTreeMap withMeta(IPersistentMap meta){ + return new PersistentTreeMap(meta, comp, tree, _count); +} + public PersistentTreeMap(Comparator comp){ - this(null,comp); + this(null, comp); } @@ -44,6 +48,13 @@ public PersistentTreeMap(IPersistentMap meta, Comparator comp){ _count = 0; } +PersistentTreeMap(IPersistentMap meta, Comparator comp, Node tree, int _count){ + super(meta); + this.comp = comp; + this.tree = tree; + this._count = _count; +} + public boolean contains(Object key){ return entryAt(key) != null; } @@ -80,7 +91,7 @@ public PersistentTreeMap without(Object key){ if(found.val == null)//null == doesn't contain key return this; //empty - return new PersistentTreeMap(meta(),comp); + return new PersistentTreeMap(meta(), comp); } return new PersistentTreeMap(comp, t.blacken(), _count - 1, meta()); } @@ -637,6 +648,13 @@ static public class Seq extends ASeq{ this.cnt = cnt; } + Seq(IPersistentMap meta, ISeq stack, boolean asc, int cnt){ + super(meta); + this.stack = stack; + this.asc = asc; + this.cnt = cnt; + } + static Seq create(Node t, boolean asc, int cnt){ return new Seq(push(t, null, asc), asc, cnt); } @@ -667,6 +685,10 @@ static public class Seq extends ASeq{ public int count(){ return cnt; } + + public Obj withMeta(IPersistentMap meta){ + return new Seq(meta, stack, asc, cnt); + } } static public class NodeIterator implements Iterator{ @@ -748,18 +770,19 @@ static public void main(String args[]){ Integer[] ints = new Integer[n]; for(int i = 0; i < ints.length; i++) { - ints[i] = new Integer(i); + ints[i] = i; } Collections.shuffle(Arrays.asList(ints)); //force the ListMap class loading now - try - { - //PersistentListMap.EMPTY.assocEx(1, null).assocEx(2,null).assocEx(3,null); - } - catch(Exception e) - { - e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. - } +// try +// { +// +// //PersistentListMap.EMPTY.assocEx(1, null).assocEx(2,null).assocEx(3,null); +// } +// catch(Exception e) +// { +// e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. +// } System.out.println("Building set"); //IPersistentMap set = new PersistentArrayMap(); //IPersistentMap set = new PersistentHashtableMap(1001); @@ -773,19 +796,17 @@ static public void main(String args[]){ // set = set.add(anInt); // } long startTime = System.nanoTime(); - for(int i = 0; i < ints.length; i++) + for(Integer anInt : ints) { - Integer anInt = ints[i]; set = set.assoc(anInt, anInt); } //System.out.println("_count = " + set.count()); // System.out.println("_count = " + set._count + ", min: " + set.minKey() + ", max: " + set.maxKey() // + ", depth: " + set.depth()); - Iterator it = set.iterator(); - while(it.hasNext()) + for(Object aSet : set) { - IMapEntry o = (IMapEntry) it.next(); + IMapEntry o = (IMapEntry) aSet; if(!set.contains(o.key())) System.err.println("Can't find: " + o.key()); //else if(n < 2000) @@ -812,16 +833,15 @@ static public void main(String args[]){ // Integer anInt = ints[i]; // ht.put(anInt,null); // } - for(int i = 0; i < ints.length; i++) + for(Integer anInt : ints) { - Integer anInt = ints[i]; ht.put(anInt, anInt); } //System.out.println("size = " + ht.size()); - it = ht.entrySet().iterator(); - while(it.hasNext()) + //Iterator it = ht.entrySet().iterator(); + for(Object o1 : ht.entrySet()) { - Map.Entry o = (Map.Entry) it.next(); + Map.Entry o = (Map.Entry) o1; if(!ht.containsKey(o.getKey())) System.err.println("Can't find: " + o); //else if(n < 2000) @@ -841,9 +861,8 @@ static public void main(String args[]){ System.out.println("set lookup"); startTime = System.nanoTime(); int c = 0; - for(int i = 0; i < ints.length; i++) + for(Integer anInt : ints) { - Integer anInt = ints[i]; if(!set.contains(anInt)) ++c; } @@ -853,9 +872,8 @@ static public void main(String args[]){ System.out.println("ht lookup"); startTime = System.nanoTime(); c = 0; - for(int i = 0; i < ints.length; i++) + for(Integer anInt : ints) { - Integer anInt = ints[i]; if(!ht.containsKey(anInt)) ++c; } diff --git a/src/jvm/clojure/lang/PersistentVector.java b/src/jvm/clojure/lang/PersistentVector.java index 37df090d..f99bac02 100644 --- a/src/jvm/clojure/lang/PersistentVector.java +++ b/src/jvm/clojure/lang/PersistentVector.java @@ -39,8 +39,9 @@ static public PersistentVector create(Object... items){ //todo - consider building tree directly if(items.length <= 32) return new PersistentVector(items.length, 0, items); - return create(ArraySeq.create((Object[])items)); + return create(ArraySeq.create((Object[]) items)); } + PersistentVector(int cnt, int shift, Object[] root){ this.cnt = cnt; this.shift = shift; @@ -150,6 +151,10 @@ public int hashCode(){ return _hash; } +public PersistentVector withMeta(IPersistentMap meta){ + return new PersistentVector(meta, cnt, shift, root); +} + static class Seq extends ASeq implements IndexedSeq{ final PersistentVector v; final int i; @@ -160,6 +165,12 @@ static class Seq extends ASeq implements IndexedSeq{ this.i = i; } + Seq(IPersistentMap meta, PersistentVector v, int i){ + super(meta); + this.v = v; + this.i = i; + } + public Object first(){ return v.nth(i); } @@ -177,6 +188,10 @@ static class Seq extends ASeq implements IndexedSeq{ public int count(){ return v.cnt - i; } + + public Seq withMeta(IPersistentMap meta){ + return new Seq(meta, v, i); + } } static class RSeq extends ASeq implements IndexedSeq{ @@ -188,6 +203,12 @@ static class RSeq extends ASeq implements IndexedSeq{ this.i = i; } + RSeq(IPersistentMap meta, PersistentVector v, int i){ + super(meta); + this.v = v; + this.i = i; + } + public Object first(){ return v.nth(i); } @@ -205,6 +226,10 @@ static class RSeq extends ASeq implements IndexedSeq{ public int count(){ return i + 1; } + + public RSeq withMeta(IPersistentMap meta){ + return new RSeq(meta, v, i); + } } public PersistentVector cons(Object val){ diff --git a/src/jvm/clojure/lang/TRef.java b/src/jvm/clojure/lang/TRef.java index 7adccaa1..a72f1480 100644 --- a/src/jvm/clojure/lang/TRef.java +++ b/src/jvm/clojure/lang/TRef.java @@ -25,6 +25,17 @@ public TRef(){ this.dvals = new AtomicReference<InheritableThreadLocal>(); } +public Obj withMeta(IPersistentMap meta){ + return new TRef(meta, tvals, dvals); +} + + +private TRef(IPersistentMap meta, AtomicReference<TVal> tvals, AtomicReference<InheritableThreadLocal> dvals){ + super(meta); + this.tvals = tvals; + this.dvals = dvals; +} + public TRef(T initVal){ this(); tvals.set(new TVal(initVal, Transaction.ZERO_POINT, null)); diff --git a/src/jvm/clojure/lang/Transaction.java b/src/jvm/clojure/lang/Transaction.java index af65cab1..14ca7fcc 100644 --- a/src/jvm/clojure/lang/Transaction.java +++ b/src/jvm/clojure/lang/Transaction.java @@ -325,6 +325,11 @@ public static void main(String[] args){ Integer i = (Integer) arg1; return i + 1; } + + public Obj withMeta(IPersistentMap meta){ + throw new UnsupportedOperationException(); + + } } class Commuter extends AFn implements Callable{ @@ -358,6 +363,11 @@ public static void main(String[] args){ } return null; } + + public Obj withMeta(IPersistentMap meta){ + throw new UnsupportedOperationException(); + + } } class Incrementer extends AFn implements Callable{ @@ -392,6 +402,11 @@ public static void main(String[] args){ } return null; } + + public Obj withMeta(IPersistentMap meta){ + throw new UnsupportedOperationException(); + + } } ArrayList<Callable<Long>> tasks = new ArrayList(nthreads); |