diff options
author | Rich Hickey <richhickey@gmail.com> | 2007-09-22 22:32:46 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2007-09-22 22:32:46 +0000 |
commit | b6db84aea2db2ddebcef58918971258464cbf46f (patch) | |
tree | a02f6e2d758da84f1358c2e647464ff563a7f00c | |
parent | 07060b8e569c6fd9073da42bcb80f3ab26251195 (diff) |
refactoring dumping unused classes
120 files changed, 0 insertions, 17866 deletions
diff --git a/src/cli/TypeDump/Program.cs b/src/cli/TypeDump/Program.cs deleted file mode 100644 index 755a62e8..00000000 --- a/src/cli/TypeDump/Program.cs +++ /dev/null @@ -1,169 +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. - **/
-
-using System;
-using System.IO;
-using System.Reflection;
-
-namespace TypeDump
- {
- class Program
- {
- static void Main(string[] args)
- {
- if (args.Length < 2)
- {
- Console.Error.WriteLine("usage: typedump assembly namespace [namespace ...]");
- return;
- }
- Assembly a = Assembly.Load(new AssemblyName(args[0]));
- Console.WriteLine('(');
- foreach (Type t in a.GetExportedTypes())
- {
- if(Array.IndexOf(args,t.Namespace,1) >= 0
- //we don't deal with generics
- && !(t.IsGenericTypeDefinition || t.IsGenericType))
- dumpType(t, Console.Out);
- }
- Console.WriteLine(')');
- }
-
- static bool hasGenericOrRefParam(ParameterInfo[] args)
- {
- return Array.Find(args, delegate(ParameterInfo pi)
- {
- Type pit = pi.ParameterType;
- return pit.IsGenericTypeDefinition || pit.IsGenericType ||pit.IsByRef;
- })
- != null;
- }
-
- static void dumpType(Type t, TextWriter p)
- {
- p.Write('(');
- p.Write("(:name \"" + t + "\")");
- if(t.BaseType != null)
- p.Write(" (:super \"" + t.BaseType + "\")");
-
- Type[] interfaces = t.GetInterfaces();
- if (interfaces.Length > 0)
- {
- p.WriteLine();
- p.Write(" (:interfaces");
- foreach (Type it in interfaces)
- {
- if (!(it.IsGenericTypeDefinition || it.IsGenericType))
- p.Write(" \"" + it + "\"");
-
- }
- p.Write(')');
- }
- foreach (ConstructorInfo ci in t.GetConstructors(BindingFlags.Public|BindingFlags.Instance))
- {
- //this should filter for pointer args etc
- Object[] clsattr = ci.GetCustomAttributes(typeof(CLSCompliantAttribute), false);
- if (clsattr.Length > 0 && !((CLSCompliantAttribute)clsattr[0]).IsCompliant)
- continue;
- ParameterInfo[] args = ci.GetParameters();
- //we don't deal with generics
- if (hasGenericOrRefParam(args))
- continue;
- p.WriteLine();
- p.Write(" (:ctor (:arity " + args.Length + ")");
- if (args.Length > 0
- && args[args.Length - 1].GetCustomAttributes(typeof(ParamArrayAttribute), false).Length > 0)
- {
- p.Write("(:varargs t)");
- }
- if (args.Length > 0)
- {
- p.WriteLine();
- p.Write(" (:args");
- foreach (ParameterInfo pi in args)
- {
- p.Write(" \"" + pi.ParameterType + "\"");
- }
- p.Write(')');
- }
- p.Write(')');
- }
- foreach (MethodInfo mi in t.GetMethods(BindingFlags.Public | BindingFlags.Instance |BindingFlags.Static))
- {
- //this should filter for pointer args etc
- Object[] clsattr = mi.GetCustomAttributes(typeof(CLSCompliantAttribute), false);
- if (clsattr.Length > 0 && !((CLSCompliantAttribute)clsattr[0]).IsCompliant)
- continue;
- ParameterInfo[] args = mi.GetParameters();
- //we don't deal with generics
- if (hasGenericOrRefParam(args) ||mi.ReturnType.IsGenericType)
- continue;
- p.WriteLine();
- p.Write(" (:method (:name \"" + mi.Name + "\") (:arity " + args.Length + ")(:ret \"" + mi.ReturnType + "\")");
- if (mi.IsStatic)
- {
- p.Write(" (:static t)");
- }
- if (args.Length > 0
- && args[args.Length - 1].GetCustomAttributes(typeof(ParamArrayAttribute), false).Length > 0)
- {
- p.Write(" (:varargs t)");
- }
- if (mi.IsSpecialName)
- {
- p.Write(" (:special t)");
- }
- if (args.Length > 0)
- {
- p.WriteLine();
- p.Write(" (:args");
- foreach (ParameterInfo pi in args)
- {
- p.Write(" \"" + pi.ParameterType + "\"");
- }
- p.Write(')');
- }
- p.Write(')');
- }
- foreach (FieldInfo fi in t.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static))
- {
- p.WriteLine();
- p.Write(" (:field (:name \"");
- p.Write(fi.Name);
- p.Write("\") (:type \"");
- p.Write(fi.FieldType);
- p.Write("\")");
- if (fi.IsStatic)
- {
- p.Write(" (:static t)");
- if (fi.IsLiteral)
- {
- Object v = fi.GetRawConstantValue();
- p.Write(" (:const-value ");
- if (v is String)
- p.Write('"');
- p.Write(v);
- if (v is String)
- p.Write('"');
- p.Write(")");
-
- }
- }
- if (fi.IsSpecialName)
- {
- p.Write(" (:special t)");
- }
- p.Write(")");
-
- }
-
- p.WriteLine(')');
- }
- }
- }
diff --git a/src/cli/runtime/AFn.cs b/src/cli/runtime/AFn.cs deleted file mode 100644 index 728a7f19..00000000 --- a/src/cli/runtime/AFn.cs +++ /dev/null @@ -1,407 +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 Mar 25, 2006 4:05:37 PM */ - -using System;
- -namespace clojure.lang
-{ - -public class AFn : Obj , IFn
- { - -virtual public Object invoke()
- {
- return throwArity();
- }
-virtual public Object invoke(Object arg1)
- {
- return throwArity();
- }
-virtual public Object invoke(Object arg1, Object arg2)
- {
- return throwArity();
- }
-virtual public Object invoke(Object arg1, Object arg2, Object arg3)
- {
- return throwArity();
- }
-virtual public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4)
- {
- return throwArity();
- }
-virtual public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5)
- {
- return throwArity();
- }
-virtual public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6)
- {
- return throwArity();
- }
-virtual public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7)
- {
- return throwArity();
- }
-virtual public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8)
- {
- return throwArity();
- }
-virtual public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Object arg9)
- {
- return throwArity();
- }
-virtual public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10)
- {
- return throwArity();
- }
-virtual 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)
- {
- return throwArity();
- }
-virtual 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)
- {
- return throwArity();
- }
-virtual 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)
- {
- return throwArity();
- }
-virtual 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)
- {
- return throwArity();
- }
-virtual 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)
- {
- return throwArity();
- }
-virtual 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)
- {
- return throwArity();
- }
-virtual 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)
- {
- return throwArity();
- }
-virtual 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)
- {
- return throwArity();
- }
-virtual 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)
- {
- return throwArity();
- }
-virtual 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)
- {
- return throwArity();
- }
-
-virtual 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,
- params Object[] args)
- {
- return throwArity();
- } - -virtual public Object applyTo( ISeq arglist) -{ -return applyToHelper(this,arglist); -} - -static public Object applyToHelper(IFn ifn, ISeq arglist) {
- 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 throwArity() - { - throw new Exception("Wrong number of args passed"); - } - -public override Obj withMeta(IPersistentMap meta){
- Obj ret = (Obj) MemberwiseClone();
- ret._meta = meta;
- return ret;
}
-} -}
\ No newline at end of file diff --git a/src/cli/runtime/APersistentArray.cs b/src/cli/runtime/APersistentArray.cs deleted file mode 100644 index b78f502d..00000000 --- a/src/cli/runtime/APersistentArray.cs +++ /dev/null @@ -1,139 +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.
- **/
-
-using System;
-using System.Collections;
-
-namespace clojure.lang
-{
-public abstract class APersistentArray : Obj, IPersistentArray {
-int _hash = -1;
-
-public virtual IPersistentCollection cons(Object o) {
- PersistentArrayList ret = new PersistentArrayList(this, this.count() + 10);
- ret = (PersistentArrayList)ret.cons(o);
- ret._meta = _meta;
- return ret;
-}
-
- public override Obj withMeta(IPersistentMap meta)
- {
- if(_meta == meta)
- return this;
- Obj ret = (Obj)MemberwiseClone();
- ret._meta = meta;
- return ret;
- }
-
-override public bool Equals(Object obj) {
- if(obj is IPersistentArray)
- {
- IPersistentArray ma = (IPersistentArray) obj;
- if (ma.count() != count() || ma.GetHashCode() != GetHashCode())
- return false;
- for(int i=0;i<count();i++)
- {
- if(!RT.equal(nth(i),ma.nth(i)))
- return false;
- }
- }
- else
- {
- if(!(obj is Sequential))
- return false;
- ISeq ms = ((IPersistentCollection)obj).seq();
- for (int i = 0; i < count(); i++, ms = ms.rest())
- {
- if (ms == null || !RT.equal(nth(i), ms.first()))
- return false;
- }
- if(ms.rest() != null)
- return false;
- }
-
- return true;
-}
-
-override public int GetHashCode() {
- if(_hash == -1)
- {
- int hash = 0;
- for(int i=0;i<count();i++)
- {
- hash = RT.hashCombine(hash, RT.hash(nth(i)));
- }
- this._hash = hash;
- }
- return _hash;
-}
-
- #region IArray Members
-
- abstract public int length();
-
- abstract public object nth(int i);
-
- abstract public IPersistentArray assocN(int i, object val);
-
- #endregion
-
- #region IPersistentCollection Members
-
- abstract public int count();
-
- abstract public ISeq seq();
-
- #endregion
-
-public bool contains(Object key) {
- try{
- int i = Convert.ToInt32(key);
- return i >= 0 && i < count();
- }
- catch(Exception)
- {
- return false;
- }
-}
-
-public IMapEntry find(Object key) {
- try
- {
- int i = Convert.ToInt32(key);
- if(i >= 0 && i < count())
- return new MapEntry(key,nth(i));
- }
- catch(Exception)
- {
- }
- return null;
-}
-
-public Associative assoc(Object key, Object val) {
- int i = Convert.ToInt32(key);
- return (Associative)assocN(i, val);
-}
-
-public Object get(Object key) {
- try
- {
- int i = Convert.ToInt32(key);
- if(i >= 0 && i < count())
- return nth(i);
- }
- catch (Exception)
- {
- }
- return null;
- }
-
-}
-
-}
diff --git a/src/cli/runtime/APersistentMap.cs b/src/cli/runtime/APersistentMap.cs deleted file mode 100644 index e96cdad0..00000000 --- a/src/cli/runtime/APersistentMap.cs +++ /dev/null @@ -1,149 +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.
- **/
-
-using System;
-using System.Threading;
-using System.Collections;
-
-namespace clojure.lang
-{
-public abstract class APersistentMap : Obj, IPersistentMap{
- int _hash = -1;
-
- public override Obj withMeta(IPersistentMap meta)
- {
- if(_meta == meta)
- return this;
- Obj ret = (Obj)MemberwiseClone();
- ret._meta = meta;
- return ret;
- }
-
-override public bool Equals(Object obj) {
- IPersistentMap m = obj as IPersistentMap;
- if(obj == null)
- return false;
-
- if(m.count() != count() || m.GetHashCode() != GetHashCode())
- return false;
-
- for(ISeq s = seq();s!=null;s = s.rest())
- {
- IMapEntry e = (IMapEntry) s.first();
- IMapEntry me = m.find(e.key());
-
- if(me == null || !RT.equal(e.val(),me.val()))
- return false;
- }
-
- return true;
-}
-
-override public int GetHashCode() {
- if(_hash == -1)
- {
- int hash = count();
- for(ISeq s = seq();s!=null;s = s.rest())
- {
- IMapEntry e = (IMapEntry) s.first();
- hash ^= RT.hashCombine(RT.hash(e.key()), RT.hash(e.val()));
- }
- this._hash = hash;
- }
- return _hash;
-}
- #region IPersistentMap Members
-
- abstract public IPersistentMap assocEx(object key, object val);
-
-
- abstract public IPersistentMap without(object key);
-
-
- public class KeySeq : ASeq{
- ISeq _seq;
-
- static public KeySeq create(ISeq seq){
- if(seq == null)
- return null;
- return new KeySeq(seq);
- }
-
- private KeySeq(ISeq seq) {
- this._seq = seq;
- }
-
- public override Object first() {
- return ((IMapEntry)_seq.first()).key();
- }
-
- public override ISeq rest() {
- return create(_seq.rest());
- }
-}
-
-public class ValSeq : ASeq{
- ISeq _seq;
-
- static public ValSeq create(ISeq seq){
- if(seq == null)
- return null;
- return new ValSeq(seq);
- }
-
- private ValSeq(ISeq seq) {
- this._seq = seq;
- }
-
- public override Object first() {
- return ((IMapEntry)_seq.first()).val();
- }
-
- public override ISeq rest() {
- return create(_seq.rest());
- }
-}
-
- #endregion
-
- #region Associative Members
-
- abstract public bool contains(object key);
-
- abstract public IMapEntry find(object key);
-
- abstract public object get(object key);
-
- abstract public Associative assoc(object key, object val);
-
- #endregion
-
- #region IEnumerable Members
-
- abstract public IEnumerator GetEnumerator();
-
- #endregion
-
- #region IPersistentCollection Members
-
- abstract public int count();
-
- abstract public ISeq seq();
-
- public IPersistentCollection cons(Object o)
- {
- IMapEntry e = (IMapEntry)o;
- return (IPersistentCollection)assoc(e.key(), e.val());
- }
-
- #endregion
- }
-
-}
diff --git a/src/cli/runtime/ASeq.cs b/src/cli/runtime/ASeq.cs deleted file mode 100644 index 112c9f73..00000000 --- a/src/cli/runtime/ASeq.cs +++ /dev/null @@ -1,84 +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.
- **/
-
-using System;
-
-namespace clojure.lang
- {
-
-public abstract class ASeq : Obj, ISeq{
-int _hash = -1;
-
- public override Obj withMeta(IPersistentMap meta)
- {
- if(_meta == meta)
- return this;
- Obj ret = (Obj)MemberwiseClone();
- ret._meta = meta;
- return ret;
- }
-
-override public bool Equals(Object obj) {
- if(!(obj is 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;
-}
-
-override public int GetHashCode() {
- 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 virtual Object peek() {
- return first();
-}
-
-public virtual IPersistentList pop() {
- return rest();
-}
-
-public virtual int count() {
- return 1 + RT.count(rest());
-}
-
-public virtual ISeq seq() {
- return this;
-}
-
-public virtual IPersistentCollection cons(Object o) {
- return new Cons(o, this);
-}
-
-#region ISeq Members
-
-abstract public object first();
-
-abstract public ISeq rest();
-
-#endregion
- }
-
-}
diff --git a/src/cli/runtime/ArraySeq.cs b/src/cli/runtime/ArraySeq.cs deleted file mode 100644 index 3fb91560..00000000 --- a/src/cli/runtime/ArraySeq.cs +++ /dev/null @@ -1,66 +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 Jun 19, 2006 */
-
-using System;
- -namespace clojure.lang
-{ -
-public class ArraySeq : ASeq, IndexedSeq{
-readonly Object[] array;
-readonly int i;
-//ISeq _rest;
-
-static public ArraySeq create(){
- return null;
-}
-
-static public ArraySeq create(params Object[] array){
- if(array.Length == 0)
- return null;
- return new ArraySeq(array, 0);
-}
-
-ArraySeq(Object[] array, int i){
- this.array = array;
- this.i = i;
-// this._rest = this;
-}
-
-override public Object first() {
- return array[i];
-}
-
-override public ISeq rest() {
- if (i + 1 < array.Length)
- return new ArraySeq(array, i + 1);
- return null;
-
-// if(_rest == this)
-// {
-// if(i+1 < array.Length)
-// _rest = new ArraySeq(array, i + 1);
-// _rest = null;
-// }
-// return _rest;
-}
-
-public override int count() {
- return array.Length - i;
-}
-
-public int index(){
- return i;
-}
-}
-
-}
diff --git a/src/cli/runtime/Associative.cs b/src/cli/runtime/Associative.cs deleted file mode 100644 index 57b4cd56..00000000 --- a/src/cli/runtime/Associative.cs +++ /dev/null @@ -1,21 +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.
- */
-
-using System;
-namespace clojure.lang
- {
- public interface Associative : IPersistentCollection
- {
- bool contains(object key);
- IMapEntry find(object key);
- object get(object key);
- Associative assoc(object key, object val);
- }
- }
diff --git a/src/cli/runtime/BigNum.cs b/src/cli/runtime/BigNum.cs deleted file mode 100644 index 9bde7116..00000000 --- a/src/cli/runtime/BigNum.cs +++ /dev/null @@ -1,225 +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 Mar 28, 2006 10:08:33 AM */ - -using System;
-using java.math; - -namespace clojure.lang
-{ - - -public class BigNum : IntegerNum{ -public BigInteger val; - -override public Boolean Equals(Object arg0) - { - return arg0 != null - && arg0 is BigNum - && ((BigNum) arg0).val == val; - } - -override public int GetHashCode() - { - return val.GetHashCode(); - } - -override public String ToString() - { - return val.ToString(); - } - -public BigNum(long val) - { - this.val = BigInteger.valueOf(val); - } - -public BigNum(BigInteger val) - { - this.val = val; - } - -override public double doubleValue() - { - return val.doubleValue(); - } - -override public float floatValue() - { - return val.floatValue(); - } - -override public int intValue() - { - return val.intValue(); - } - -override public long longValue() - { - return val.longValue(); - } - -override public Boolean equiv(Num rhs) - { - return rhs.equivTo(val); - } - -override public Boolean equivTo(BigInteger x) - { - return x.Equals(val); - } - -override public Boolean equivTo(int x) - { - //must be outside of range of int or would be one itself - return false; - } - -override public Boolean equivTo(RatioNum x) - { - //wouldn't still be a RatioNum if it was an integer - return false; - } - -override public Boolean lt(Num rhs) - { - return rhs.gt(val); - } - -override public Boolean gt(BigInteger x) - { - return x.compareTo(val) < 0; - } - -override public Boolean gt(int x) - { - return BigInteger.valueOf(x).compareTo(val) < 0; - } - -override public Boolean gt(RatioNum x) - { - return x.numerator.lt(x.denominator.multiply(val)); - } - -override public Num add(Num rhs) - { - return rhs.addTo(val); - } - -override public Num addTo(BigInteger x) - { - return Num.from(x.add(val)); - } - -override public Num addTo(int x) - { - return Num.from(val.add(BigInteger.valueOf(x))); - } - -override public Num addTo(RatioNum x) - { - return x.addTo(val); - } - -override public Num subtractFrom(Num x) - { - return x.addTo(val.negate()); - } - -override public Num multiplyBy(Num rhs) - { - return rhs.multiply(val); - } - -override public Num multiply(BigInteger x) - { - return Num.from(x.multiply(val)); - } - -override public Num multiply(int x) - { - return Num.from(val.multiply(BigInteger.valueOf(x))); - } - -override public Num multiply(RatioNum x) - { - return x.multiply(val); - } - -override public Num divideBy(Num rhs) - { - return rhs.divide(val); - } - -override public Num divide(BigInteger n) - { - return Num.divide(n, val); - } - -override public Num divide(int n) - { - return Num.divide(BigInteger.valueOf(n), val); - } - -override public Num divide(RatioNum x) - { - return Num.divide(x.numerator, x.denominator.multiply(val)); - } - -override public Object truncateDivide( Num num) - { - return num.truncateBy( val); - } - -override public Object truncateBy( int div) - { - return Num.truncateBigints( val, BigInteger.valueOf(div)); - } - -override public Object truncateBy( BigInteger div) - { - return Num.truncateBigints( val, div); - } - -override public Object truncateBy( RatioNum div) - { - Num q = (Num) Num.truncate( div.denominator.multiply(val), div.numerator); - return RT.setValues( q, q.multiplyBy(div).subtractFrom(this)); - } - -override public Num negate() - { - return Num.from(val.negate()); - } - -override public Boolean minusp() - { - return val.signum() < 0; - } - -override public Boolean plusp() - { - return val.signum() > 0; - } - - -override public Num oneMinus() - { - return Num.from(val.subtract(BIG_ONE)); - } - -override public Num onePlus() - { - return Num.from(val.add(BIG_ONE)); - } -} -} - diff --git a/src/cli/runtime/Binding.cs b/src/cli/runtime/Binding.cs deleted file mode 100644 index c8c8d6f3..00000000 --- a/src/cli/runtime/Binding.cs +++ /dev/null @@ -1,29 +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.
- **/
-
-using System;
-
-namespace clojure.lang
-{
-public class Binding {
-public Object val;
-public Binding rest;
-
-public Binding(Object val) {
- this.val = val;
-}
-
-public Binding(Object val, Binding rest) {
- this.val = val;
- this.rest = rest;
-}
-}
-
-}
diff --git a/src/cli/runtime/Box.cs b/src/cli/runtime/Box.cs deleted file mode 100644 index d751786d..00000000 --- a/src/cli/runtime/Box.cs +++ /dev/null @@ -1,28 +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 Mar 27, 2006 8:40:19 PM */ - -using System;
-
-namespace clojure.lang
-{ - -public class Box
-{ - -public Object val; - -public Box(Object val) - { - this.val = val; - } -} -} diff --git a/src/cli/runtime/ClassSymbol.cs b/src/cli/runtime/ClassSymbol.cs deleted file mode 100644 index 484ce488..00000000 --- a/src/cli/runtime/ClassSymbol.cs +++ /dev/null @@ -1,24 +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.
- **/
-
-using System;
- -namespace clojure.lang
-{ -
-public class ClassSymbol :HostSymbol {
-readonly public String className;
-
-public ClassSymbol(String className) : base(className) {
-this.className = className.Substring(0, className.Length - 2); //strip trailing dot
-}
-}
-
-}
diff --git a/src/cli/runtime/Cons.cs b/src/cli/runtime/Cons.cs deleted file mode 100644 index 823c3fd8..00000000 --- a/src/cli/runtime/Cons.cs +++ /dev/null @@ -1,47 +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 Mar 25, 2006 11:01:29 AM */ - -using System;
- -namespace clojure.lang
-{ - -public class Cons : ASeq
- { - -private readonly Object _first; -private readonly ISeq _rest; - -public Cons(Object first, ISeq rest) - { - this._first = first; - this._rest = rest; - }
-
-
-#region ISeq Members
-
-override public object first()
- {
- return _first;
- }
-
-override public ISeq rest()
- {
- return _rest;
- }
-
-#endregion
-
- } - -} diff --git a/src/cli/runtime/DoubleNum.cs b/src/cli/runtime/DoubleNum.cs deleted file mode 100644 index ef9f3f75..00000000 --- a/src/cli/runtime/DoubleNum.cs +++ /dev/null @@ -1,242 +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 Mar 28, 2006 10:13:45 AM */ - -using System;
-using java.math;
-
-namespace clojure.lang
-{ - -public class DoubleNum : FloatNum{ -double val; - -public DoubleNum(double val) - { - this.val = val; - } - -override public double doubleValue() - { - return val; - } - -override public float floatValue() - { - return (float) val; - } - -override public int intValue() - { - return (int) val; - } - -override public long longValue() - { - return (long) val; - } - - -public Num toRational() - { - BigDecimal d = new BigDecimal(val); - return Num.divide(d.movePointRight(d.scale()).toBigInteger(), BIGTEN.pow(d.scale())); - } - -override public Boolean equiv(Num rhs) - { - if(rhs is RatioNum) - return equivTo((RatioNum) rhs); - return val == rhs.doubleValue(); - } - -override public Boolean equivTo(BigInteger x) - { - return val == x.doubleValue(); - } - -override public Boolean equivTo(int x) - { - return x == val; - } - -override public Boolean equivTo(RatioNum x) - { - return toRational().equivTo(x); - } - -override public Boolean lt(Num rhs) - { - if(rhs is RatioNum) - return toRational().lt(rhs); - return val < rhs.doubleValue(); - } - -override public Boolean gt(BigInteger x) - { - return val > x.doubleValue(); - } - -override public Boolean gt(int x) - { - return val > x; - } - -override public Boolean gt(RatioNum x) - { - return toRational().gt(x); - } - -override public Num add(Num rhs) - { - return Num.from(val + rhs.doubleValue()); - } - -override public Num addTo(int x) - { - return Num.from(val + x); - } - -override public Num addTo(BigInteger x) - { - return Num.from(val + x.doubleValue()); - } - -override public Num addTo(RatioNum x) - { - return Num.from(val + x.doubleValue()); - } - -override public Num subtractFrom(Num x) - { - return Num.from(x.doubleValue() - val); - } - -override public Num multiplyBy(Num rhs) - { - return Num.from(val * rhs.doubleValue()); - } - -override public Num multiply(int x) - { - return Num.from(val * x); - } - -override public Num multiply(BigInteger x) - { - return Num.from(val * x.doubleValue()); - } - -override public Num multiply(RatioNum x) - { - return Num.from(val * x.doubleValue()); - } - -override public Num divideBy(Num rhs) - { - return Num.from(val / rhs.doubleValue()); - } - -override public Num divide(int x) - { - return Num.from(x / val); - } - -override public Num divide(BigInteger x) - { - return Num.from(x.doubleValue() / val); - } - -override public Num divide(RatioNum x) - { - return Num.from(x.doubleValue() / val); - } - -static Object truncate( double n, double d) - { - double q = n / d; - if(q <= Int32.MaxValue && q >= Int32.MinValue) - { - return RT.setValues( Num.from((int) q), - Num.from(n - ((int) q) * d)); - } - else - { //bigint quotient - Num bq = Num.from(new BigDecimal(q).toBigInteger()); - return RT.setValues( bq, - Num.from(n - bq.doubleValue() * d)); - } - } - -override public Object truncateBy( BigInteger x) - { - return truncate( val, x.doubleValue()); - } - -override public Object truncateBy( int x) - { - return truncate( val, x); - } - -override public Object truncateBy( RatioNum x) - { - return truncate( val, x.doubleValue()); - } - -override public Object truncateDivide( Num num) - { - return truncate( num.doubleValue(), val); - } - -override public Num negate() - { - return Num.from(-val); - } - -override public Boolean Equals(Object arg0) - { - return arg0 != null - && arg0 is DoubleNum - &&((DoubleNum) arg0).val.Equals(val); - } - -override public int GetHashCode() - { - return val.GetHashCode(); - } - -override public String ToString() - { - return val.ToString(); - } - -override public Boolean minusp() - { - return val < 0; - } - -override public Boolean plusp() - { - return val > 0; - } - -override public Num oneMinus() - { - return Num.from(val - 1); - } - -override public Num onePlus() - { - return Num.from(val + 1); - } - -} -} diff --git a/src/cli/runtime/EnumeratorIter.cs b/src/cli/runtime/EnumeratorIter.cs deleted file mode 100644 index 2fb66c11..00000000 --- a/src/cli/runtime/EnumeratorIter.cs +++ /dev/null @@ -1,43 +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. - **/ -
-
-using System;
-using System.Collections;
-
-namespace clojure.lang
- {
- internal class EnumeratorIter:Iter
- {
- IEnumerator e;
-
- //presumes that e has already been successfully MovedNext()ed
- internal EnumeratorIter(IEnumerator e)
- {
- this.e = e;
- }
-
- #region Iter Members
-
- public object get()
- {
- return e.Current;
- }
-
- public Iter iterate()
- {
- if (e.MoveNext())
- return this;
- return null;
- }
-
- #endregion
- }
- }
diff --git a/src/cli/runtime/EnumeratorSeq.cs b/src/cli/runtime/EnumeratorSeq.cs deleted file mode 100644 index cd42d42a..00000000 --- a/src/cli/runtime/EnumeratorSeq.cs +++ /dev/null @@ -1,47 +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.
- **/
-
-using System;
-using System.Collections;
- -namespace clojure.lang
-{
- public class EnumeratorSeq : ASeq
- {
- IEnumerator e;
- ISeq _rest;
-
- public static EnumeratorSeq create(IEnumerator e) {
- if (e.MoveNext())
- return new EnumeratorSeq(e);
- return null;
- }
-
- EnumeratorSeq(IEnumerator e) {
- this.e = e;
- this._rest = this;
- }
-
- override public Object first() {
- return e.Current;
- }
-
- override public ISeq rest() {
- lock (this)
- {
- if (_rest == this)
- {
- _rest = create(e);
- }
- return _rest;
- }
- }
- }
-}
\ No newline at end of file diff --git a/src/cli/runtime/FixNum.cs b/src/cli/runtime/FixNum.cs deleted file mode 100644 index 6b0d6759..00000000 --- a/src/cli/runtime/FixNum.cs +++ /dev/null @@ -1,243 +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 Mar 28, 2006 10:09:27 AM */ - -using System;
-using java.math;
- -namespace clojure.lang
-{ - - -public class FixNum : IntegerNum{ -public int val; - -override public Boolean Equals(Object arg0) - { - return arg0 != null - && arg0 is FixNum - && ((FixNum) arg0).val == val; - } - -override public int GetHashCode() - { - return val; - } - -override public String ToString() - { - return val.ToString(); - } - -public FixNum(int val) - { - this.val = val; - } - -override public double doubleValue() - { - return (double) val; - } - -override public float floatValue() - { - return (float) val; - } - -override public int intValue() - { - return val; - } - -override public long longValue() - { - return (long) val; - } - -override public Boolean equiv(Num rhs) - { - return rhs.equivTo(val); - } - -override public Boolean equivTo(BigInteger x) - { - //wouldn't still be a BigInteger if it fit in int - return false; - } - -override public Boolean equivTo(int x) - { - return x == val; - } - -override public Boolean equivTo(RatioNum x) - { - //wouldn't still be a RatioNum if it was an integer - return false; - } - -override public Boolean lt(Num rhs) - { - return rhs.gt(val); - } - -override public Boolean gt(BigInteger x) - { - return x.compareTo(BigInteger.valueOf(val)) < 0; - } - -override public Boolean gt(int x) - { - return x < val; - } - -override public Boolean gt(RatioNum x) - { - return x.numerator.lt(x.denominator.multiply(val)); - } - -override public Num add(Num rhs) - { - return rhs.addTo(val); - } - -override public Num addTo(BigInteger x) - { - return Num.from(x.add(BigInteger.valueOf(val))); - } - -override public Num addTo(int x) - { - return Num.from((long) x + val); - } - -override public Num addTo(RatioNum x) - { - return x.addTo(val); - } - -override public Num subtractFrom(Num x) - { - return x.addTo(-val); - } - -override public Num multiplyBy(Num rhs) - { - return rhs.multiply(val); - } - -override public Num multiply(BigInteger x) - { - return Num.from(x.multiply(BigInteger.valueOf(val))); - } - -override public Num multiply(int x) - { - return Num.from((long) x * val); - } - -override public Num multiply(RatioNum x) - { - return x.multiply(val); - } - -override public Object truncateDivide( Num num) - { - return num.truncateBy( val); - } - -override public Object truncateBy( int div) - { - return RT.setValues( Num.from(val / div), Num.from(val % div)); - } - -override public Object truncateBy( BigInteger div) - { - return Num.truncateBigints( BigInteger.valueOf(val), div); - } - -override public Object truncateBy( RatioNum div) - { - Num q = (Num) Num.truncate( div.denominator.multiply(val), div.numerator); - return RT.setValues( q, q.multiplyBy(div).subtractFrom(this)); - } - -override public Num divideBy(Num rhs) - { - return rhs.divide(val); - } - -override public Num divide(BigInteger n) - { - return Num.divide(n, BigInteger.valueOf(val)); - } - -static int gcdf(int u, int v) - { - while(v != 0) - { - int r = u % v; - u = v; - v = r; - } - return u; - } - -override public Num divide(int n) - { - int gcd = gcdf(n, val); - if(gcd == 0) - return Num.ZERO; - - n = n / gcd; - int d = val / gcd; - if(d == 1) - return Num.from(n); - if(d < 0) - { - n = -n; - d = -d; - } - return new RatioNum((IntegerNum) Num.from(n), (IntegerNum) Num.from(d)); - } - -override public Num divide(RatioNum x) - { - return Num.divide(x.numerator, x.denominator.multiply(val)); - } - -override public Num negate() - { - return Num.from(-val); - } - -override public Boolean minusp() - { - return val < 0; - } - -override public Boolean plusp() - { - return val > 0; - } - -override public Num oneMinus() - { - return Num.from(val - 1); - } - -override public Num onePlus() - { - return Num.from(val + 1); - } - -} -} diff --git a/src/cli/runtime/FloatNum.cs b/src/cli/runtime/FloatNum.cs deleted file mode 100644 index 6b709c2b..00000000 --- a/src/cli/runtime/FloatNum.cs +++ /dev/null @@ -1,21 +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 Mar 28, 2006 10:17:21 AM */ - -using System;
-
-namespace clojure.lang
-{ - -public abstract class FloatNum : RealNum { - -} -} diff --git a/src/cli/runtime/FnSeq.cs b/src/cli/runtime/FnSeq.cs deleted file mode 100644 index 27374eea..00000000 --- a/src/cli/runtime/FnSeq.cs +++ /dev/null @@ -1,46 +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.
- **/
-
-using System;
- -namespace clojure.lang
-{ -
-public class FnSeq : ASeq{
-
-Object _first;
-IFn restFn;
-volatile ISeq _rest;
-
-public FnSeq(Object first, IFn restFn) {
- this._first = first;
- this.restFn = restFn;
- this._rest = this;
- }
-
-override public Object first() {
- return _first;
-}
-
-override public ISeq rest() {
- if(_rest != this)
- return _rest;
- lock(this){
- if(_rest == this)
- {
- _rest = (ISeq) restFn.invoke();
- restFn = null;
- }
- return _rest;
- }
- }
-}
-
-}
diff --git a/src/cli/runtime/HostSymbol.cs b/src/cli/runtime/HostSymbol.cs deleted file mode 100644 index 29d951c3..00000000 --- a/src/cli/runtime/HostSymbol.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace clojure.lang
- {
- public class HostSymbol : Symbol
- {
- public HostSymbol(string name) : base(name) {
- }
- }
- }
diff --git a/src/cli/runtime/IFn.cs b/src/cli/runtime/IFn.cs deleted file mode 100644 index a915ee9a..00000000 --- a/src/cli/runtime/IFn.cs +++ /dev/null @@ -1,47 +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 Mar 25, 2006 3:54:03 PM */
-
-using System;
-
-namespace clojure.lang
- {
- public interface IFn
- {
-
- Object invoke();
- Object invoke(Object arg1);
- Object invoke(Object arg1, Object arg2);
- Object invoke(Object arg1, Object arg2, Object arg3);
- Object invoke(Object arg1, Object arg2, Object arg3, Object arg4);
- Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5);
- Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6);
- Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7);
- Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8);
- Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Object arg9);
- Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10);
- 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 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 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 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 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 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 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 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 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 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);
-
- 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,
- params Object[] args);
-
- Object applyTo(ISeq arglist) /*throws Exception*/;
- }
- }
diff --git a/src/cli/runtime/IMapEntry.cs b/src/cli/runtime/IMapEntry.cs deleted file mode 100644 index 4a173c81..00000000 --- a/src/cli/runtime/IMapEntry.cs +++ /dev/null @@ -1,23 +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.
- */
-
-using System;
-
-namespace clojure.lang
-
-{
-
-public interface IMapEntry {
-Object key();
-
-Object val();
-}
-
-}
diff --git a/src/cli/runtime/IObj.cs b/src/cli/runtime/IObj.cs deleted file mode 100644 index 9e8d0d93..00000000 --- a/src/cli/runtime/IObj.cs +++ /dev/null @@ -1,26 +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.
- **/
-
-using System;
-namespace clojure.lang
- {
- interface IObj
- {
- Object putAttr(Object key, Object val);
-
- Object getAttr(Object key);
-
- bool hasAttr(Object key);
-
- IPersistentMap attrs();
-
- void removeAttr(Object key);
- }
- }
diff --git a/src/cli/runtime/IPersistentArray.cs b/src/cli/runtime/IPersistentArray.cs deleted file mode 100644 index 77e6290c..00000000 --- a/src/cli/runtime/IPersistentArray.cs +++ /dev/null @@ -1,24 +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.
- */
-
-using System;
- -namespace clojure.lang
-{ -
-public interface IPersistentArray : Associative, Sequential {
-int length();
-
-Object nth(int i);
-
-IPersistentArray assocN(int i,Object val);
-}
-
-}
diff --git a/src/cli/runtime/IPersistentCollection.cs b/src/cli/runtime/IPersistentCollection.cs deleted file mode 100644 index 929a419e..00000000 --- a/src/cli/runtime/IPersistentCollection.cs +++ /dev/null @@ -1,25 +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.
- */
-using System;
-
-
-namespace clojure.lang
- {
-
- public interface IPersistentCollection
- {
-
- int count();
-
- ISeq seq();
-
- IPersistentCollection cons(Object o);
- }
- }
diff --git a/src/cli/runtime/IPersistentList.cs b/src/cli/runtime/IPersistentList.cs deleted file mode 100644 index a5093471..00000000 --- a/src/cli/runtime/IPersistentList.cs +++ /dev/null @@ -1,23 +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.
- */
-
-using System;
- -namespace clojure.lang
-{
-public interface IPersistentList : IPersistentCollection, Sequential {
-
- Object peek();
-
- IPersistentList pop();
-
-}
-
-}
diff --git a/src/cli/runtime/IPersistentMap.cs b/src/cli/runtime/IPersistentMap.cs deleted file mode 100644 index b1f9ef94..00000000 --- a/src/cli/runtime/IPersistentMap.cs +++ /dev/null @@ -1,26 +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.
- */
-
-using System;
-using System.Collections;
-
-namespace clojure.lang
-{
-
-public interface IPersistentMap : Associative, IEnumerable{
-
-
-IPersistentMap assocEx(Object key, Object val);
-
-IPersistentMap without(Object key);
-
-}
-
-}
diff --git a/src/cli/runtime/ISeq.cs b/src/cli/runtime/ISeq.cs deleted file mode 100644 index 4cd7feea..00000000 --- a/src/cli/runtime/ISeq.cs +++ /dev/null @@ -1,22 +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.
- */
-
-using System;
-
-namespace clojure.lang
- {
- public interface ISeq : IPersistentList
- {
-
- Object first();
-
- ISeq rest();
- }
- }
diff --git a/src/cli/runtime/IndexedSeq.cs b/src/cli/runtime/IndexedSeq.cs deleted file mode 100644 index 49b5a297..00000000 --- a/src/cli/runtime/IndexedSeq.cs +++ /dev/null @@ -1,21 +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.
- */
-
-using System;
- -namespace clojure.lang
-{ -
-public interface IndexedSeq : ISeq{
-
-int index();
-}
-
-}
\ No newline at end of file diff --git a/src/cli/runtime/Indexer.cs b/src/cli/runtime/Indexer.cs deleted file mode 100644 index 8b2cb535..00000000 --- a/src/cli/runtime/Indexer.cs +++ /dev/null @@ -1,18 +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.
- **/
-
-using System;
-
-namespace clojure.lang
-{
- public class Indexer :AFn
- {
- }
-}
diff --git a/src/cli/runtime/InstanceMemberSymbol.cs b/src/cli/runtime/InstanceMemberSymbol.cs deleted file mode 100644 index d14cd528..00000000 --- a/src/cli/runtime/InstanceMemberSymbol.cs +++ /dev/null @@ -1,181 +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.
- **/
-
-using System;
- -namespace clojure.lang
-{ -
-public class InstanceMemberSymbol :HostSymbol, IFn {
-readonly public String className;
-readonly public String memberName;
-
-public InstanceMemberSymbol(String name) : base(name) {
-int lastDot = name.LastIndexOf('.');
-if (lastDot == 0)
- this.className = null;
-else
- this.className = name.Substring(1, lastDot-1);
-this.memberName = name.Substring(lastDot + 1);
-}
-
-public Object invoke() /**/ {
-return AFn.throwArity();
- }
-
-
-public Object invoke(Object obj) //
- {
-
- return Reflector.invokeInstanceMember(memberName, obj);
- }
-
-public Object invoke(Object obj, Object val) //
- {
-
- return Reflector.invokeInstanceMember(memberName, obj, val);
- }
-
-public Object invoke(Object arg1, Object arg2, Object arg3)
- {
- return Reflector.invokeInstanceMember(memberName, arg1, arg2, arg3);
- }
-
-public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4)
- {
- return Reflector.invokeInstanceMember(memberName, arg1, arg2, arg3, arg4);
- }
-
-public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5)
- {
- return Reflector.invokeInstanceMember(memberName, arg1, arg2, arg3, arg4, arg5);
- }
-
-public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6)
- {
- return Reflector.invokeInstanceMember(memberName, arg1, arg2, arg3, arg4, arg5, arg6);
- }
-
-public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7)
- {
- return Reflector.invokeInstanceMember(memberName, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
- }
-
-public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
- Object arg8)
- {
- return Reflector.invokeInstanceMember(memberName, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
- }
-
-public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
- Object arg8, Object arg9)
- {
- return Reflector.invokeInstanceMember(memberName, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
- }
-
-public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
- Object arg8, Object arg9, Object arg10)
- {
- return Reflector.invokeInstanceMember(memberName, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
- }
-
-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)
- {
- return Reflector
- .invokeInstanceMember(memberName, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11);
- }
-
-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)
- {
- return Reflector.invokeInstanceMember(memberName, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
- arg11, arg12);
- }
-
-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)
- {
- return Reflector.invokeInstanceMember(memberName, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
- arg11, arg12, arg13);
- }
-
-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)
- {
- return Reflector.invokeInstanceMember(memberName, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
- arg11, arg12, arg13, arg14);
- }
-
-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)
- {
- return Reflector.invokeInstanceMember(memberName, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
- arg11, arg12, arg13, arg14, arg15);
- }
-
-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)
- {
- return Reflector.invokeInstanceMember(memberName, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
- arg11, arg12, arg13, arg14, arg15, arg16);
- }
-
-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)
- {
- return Reflector.invokeInstanceMember(memberName, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
- arg11, arg12, arg13, arg14, arg15, arg16, arg17);
- }
-
-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)
- {
- return Reflector.invokeInstanceMember(memberName, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
- arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18);
- }
-
-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)
- {
- return Reflector.invokeInstanceMember(memberName, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
- arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19);
- }
-
-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)
- {
- return Reflector.invokeInstanceMember(memberName, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
- arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20);
- }
-
-
-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
- , params Object[] args)
- {
- throw new InvalidOperationException("Can't call functions of more than 20 arguments");
- }
-
-
-public Object applyTo(ISeq arglist) /**/ {
-return AFn.applyToHelper(this, arglist);
- } -
-}
-
-}
diff --git a/src/cli/runtime/IntegerNum.cs b/src/cli/runtime/IntegerNum.cs deleted file mode 100644 index 5e58a514..00000000 --- a/src/cli/runtime/IntegerNum.cs +++ /dev/null @@ -1,21 +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 Mar 28, 2006 10:11:55 AM */ - -using System;
- -namespace clojure.lang
-{ - -public abstract class IntegerNum : RationalNum { - -} -}
\ No newline at end of file diff --git a/src/cli/runtime/Iter.cs b/src/cli/runtime/Iter.cs deleted file mode 100644 index 605d2d61..00000000 --- a/src/cli/runtime/Iter.cs +++ /dev/null @@ -1,30 +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. - **/
-
-using System;
-
-namespace clojure.lang
- {
- public interface Iter
- {
-/**
- * * Multiple calls to get() are allowed prior to calling iterate()
- * * @return the currently referenced item/element/value
- * */
- Object get();
-
- /**
- * * This may destroy or otherwise invalidate the object it is called upon
- * * so always capture and use the return value (even though sometimes you may find it is the same object)
- * * @return The next iter to use, or null if at end of sequence
- * */
- Iter iterate();
- }
- }
diff --git a/src/cli/runtime/Keyword.cs b/src/cli/runtime/Keyword.cs deleted file mode 100644 index 432b4ac6..00000000 --- a/src/cli/runtime/Keyword.cs +++ /dev/null @@ -1,113 +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 Mar 29, 2006 10:39:05 AM */ - -using System;
-
- -namespace clojure.lang
-{ - -public class Keyword : Symbol, IFn{ - - -internal Keyword(String name):base(name)
{
}
public Object invoke() /*throws Exception*/ {
- return AFn.throwArity();
-}
/**
* Indexer implements IFn for attr access
* This single arg version is the getter
* @param tld
* @param obj - must be AMap
* @return the value of the attr or nil if not found
*/
public Object invoke( Object obj) /*throws Exception*/
{
- if (obj == null)
- return null;
- return ((IPersistentMap)obj).get(this);
}
/**
* Indexer implements IFn for attr access
* This two arg version is the setter
* @param tld
* @param obj - must be AMap
* @param val
* @return val
*/
public Object invoke( Object obj, Object val) /*throws Exception*/
{
- return RT.assoc(this, val,obj);
} - -public Object invoke(Object arg1, Object arg2, Object arg3)
- {
- return AFn.throwArity();
- }
-public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4)
- {
- return AFn.throwArity();
- }
-public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5)
- {
- return AFn.throwArity();
- }
-public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6)
- {
- return AFn.throwArity();
- }
-public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7)
- {
- return AFn.throwArity();
- }
-public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8)
- {
- return AFn.throwArity();
- }
-public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Object arg9)
- {
- return AFn.throwArity();
- }
-public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10)
- {
- return AFn.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)
- {
- return AFn.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)
- {
- return AFn.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)
- {
- return AFn.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)
- {
- return AFn.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)
- {
- return AFn.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)
- {
- return AFn.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)
- {
- return AFn.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)
- {
- return AFn.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)
- {
- return AFn.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)
- {
- return AFn.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
- , params Object[] args)
- {
- return AFn.throwArity();
- }
-
-public Object applyTo( ISeq arglist) /*throws Exception*/ {
- return AFn.applyToHelper(this, arglist);
-} -} -}
\ No newline at end of file diff --git a/src/cli/runtime/LineNumberingTextReader.cs b/src/cli/runtime/LineNumberingTextReader.cs deleted file mode 100644 index 71f05e8d..00000000 --- a/src/cli/runtime/LineNumberingTextReader.cs +++ /dev/null @@ -1,75 +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.
- **/
-
-using System;
-using System.IO;
-
-namespace clojure.lang
- {
-
-
-public class LineNumberingTextReader : TextReader, IDisposable
- {
- TextReader impl;
- int line = 0;
- int unreadChar;
- bool haveUnread = false;
-
- public LineNumberingTextReader(TextReader r){
- this.impl = r;
- }
-
- public int getLineNumber(){
- return line;
- }
-
- override public int Read(){
- int ret;
- if(haveUnread)
- {
- ret = unreadChar;
- haveUnread = false;
- }
- else
- ret = impl.Read();
- if(ret == '\n')
- ++line;
- return ret;
- }
-
- public void unread(int ch){
- if(haveUnread)
- throw new InvalidOperationException("Can't unread more than once in a row");
- unreadChar = ch;
- haveUnread = true;
- if (ch == '\n')
- --line;
- }
-
- override public int Peek(){
- return impl.Peek();
- }
-
- public override void Close()
- {
- base.Close();
- impl.Close();
- }
-
- void IDisposable.Dispose()
- {
- base.Dispose();
- impl.Dispose();
- }
-
- }
-
-
- }
diff --git a/src/cli/runtime/LispReader.cs b/src/cli/runtime/LispReader.cs deleted file mode 100644 index e1fcf36d..00000000 --- a/src/cli/runtime/LispReader.cs +++ /dev/null @@ -1,439 +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.
- **/
-
-using System;
-using System.IO;
-using System.Text.RegularExpressions;
-using java.math;
-using System.Text;
-using System.Collections;
- -namespace clojure.lang
-{ -
-
-public class LispReader {
-
-static Symbol QUOTE = Symbol.intern("quote");
-static Symbol BACKQUOTE = Symbol.intern("backquote");
-static Symbol UNQUOTE = Symbol.intern("unquote");
-static Symbol UNQUOTE_SPLICING = Symbol.intern("unquote-splicing");
-
-static IFn[] macros = new IFn[256];
-static Regex symbolPat = new Regex("[:]?[\\D-[:\\.]][^:\\.]*",RegexOptions.Compiled);
- static Regex varPat = new Regex("([\\D-[:\\.]][^:\\.]*):([\\D-[:\\.]][^:\\.]*)", RegexOptions.Compiled);
- static Regex intPat = new Regex("[-+]?[0-9]+\\.?", RegexOptions.Compiled);
- static Regex ratioPat = new Regex("([-+]?[0-9]+)/([0-9]+)", RegexOptions.Compiled);
- static Regex floatPat = new Regex("[-+]?[0-9]+(\\.[0-9]+)?([eE][-+]?[0-9]+)?", RegexOptions.Compiled);
-
- static Regex accessorPat = new Regex("\\.[a-zA-Z_]\\w*", RegexOptions.Compiled);
- static Regex instanceMemberPat = new Regex("\\.([a-zA-Z_][\\w\\.]*)\\.([a-zA-Z_]\\w*)", RegexOptions.Compiled);
- static Regex staticMemberPat = new Regex("([a-zA-Z_][\\w\\.]*)\\.([a-zA-Z_]\\w*)", RegexOptions.Compiled);
- static Regex classNamePat = new Regex("([a-zA-Z_][\\w\\.]*)\\.", RegexOptions.Compiled);
-
-static LispReader(){
-macros['"'] = new StringReader();
-macros[';'] = new CommentReader();
-macros['\''] = new QuoteReader();
-macros['`'] = new BackquoteReader();
-macros[','] = new UnquoteReader();
-macros['('] = new ListReader();
-macros[')'] = new UnmatchedDelimiterReader();
-macros['\\'] = new CharacterReader();
-}
-
-static public Object read(LineNumberingTextReader r, bool eofIsError, Object eofValue, bool isRecursive)
- {
-
- for (; ;)
- {
- int ch = r.Read();
-
- while (Char.IsWhiteSpace((char)ch))
- ch = r.Read();
-
- if (ch == -1)
- {
- if (eofIsError)
- throw new Exception("EOF while reading");
- return eofValue;
- }
-
- if (Char.IsDigit((char)ch))
- {
- Object n = readNumber(r, (char)ch);
- if (RT.suppressRead())
- return null;
- return n;
- }
-
- IFn macroFn = getMacro(ch);
- if (macroFn != null)
- {
- Object ret = macroFn.invoke(r, (char)ch);
- if(RT.suppressRead())
- return null;
- //no op macros return the reader
- if (ret == r)
- continue;
- return ret;
- }
-
- if (ch == '+' || ch == '-')
- {
- int ch2 = r.Read();
- if (Char.IsDigit((char)ch2))
- {
- r.unread(ch2);
- Object n = readNumber(r, (char)ch);
- if (RT.suppressRead())
- return null;
- return n;
- }
- r.unread(ch2);
- }
-
- String token = readToken(r,(char)ch);
- if (RT.suppressRead())
- return null;
- return interpretToken(token);
- }
-}
-
-static private String readToken(LineNumberingTextReader r, char initch) {
- StringBuilder sb = new StringBuilder();
- sb.Append(initch);
-
- for(;;)
- {
- int ch = r.Read();
- if(ch == -1 || Char.IsWhiteSpace((char)ch) || isMacro(ch))
- {
- r.unread(ch);
- return sb.ToString();
- }
- sb.Append((char)ch);
- }
-}
-
-static private Object readNumber(LineNumberingTextReader r, char initch){
- StringBuilder sb = new StringBuilder();
- sb.Append(initch);
-
- for(;;)
- {
- int ch = r.Read();
- if(ch == -1 || Char.IsWhiteSpace((char)ch) || isMacro(ch))
- {
- r.unread(ch);
- break;
- }
- sb.Append((char)ch);
- }
-
- String s = sb.ToString();
- Object n = matchNumber(s);
- if(n == null)
- throw new InvalidDataException("Invalid number: " + s);
- return n;
-}
-
-/*
-static private Object readSymbol(LineNumberingTextReader r, char initch) {
- StringBuilder sb = new StringBuilder();
- sb.Append(initch);
-
- for(;;)
- {
- int ch = r.Read();
- if(ch == -1 || Char.IsWhiteSpace((char)ch) || isMacro(ch))
- {
- r.unread(ch);
- return Symbol.intern(sb.ToString());
- }
- else if(ch == '.')
- {
- r.unread(ch);
- Object ret = Symbol.intern(sb.ToString());
- Object mem = null;
- while((mem = readMember(r)) != null)
- {
- //x.foo ==> (.foo x)
- if(mem is Symbol)
- ret = RT.list(mem, ret);
- else //x.foo(y z) ==> (.foo x y z)
- {
- ISeq rseq = RT.seq(mem);
- ret = RT.cons(rseq.first(), RT.cons(ret, RT.rest(rseq)));
- }
- }
- return ret;
- }
- sb.Append((char)ch);
- }
-}
-*/
-static private Object interpretToken(String s) {
- if (s.Equals("null"))
- {
- return null;
- }
- Object ret = null;
-
- ret = matchVar(s);
- if(ret != null)
- return ret;
-
- return Symbol.intern(s);
-}
-
-/*
-private static Object matchHostName(String s) {
- Match m = accessorPat.Match(s);
- if(m.Success && m.Length == s.Length)
- return new Accessor(s);
- m = classNamePat.Match(s);
- if(m.Success && m.Length == s.Length)
- return new ClassName(RT.resolveClassNameInContext(m.Groups[1].Value));
- m = instanceMemberPat.Match(s);
- if(m.Success && m.Length == s.Length)
- return new InstanceMemberName(RT.resolveClassNameInContext(m.Groups[1].Value),m.Groups[2].Value);
- m = staticMemberPat.Match(s);
- if(m.Success && m.Length == s.Length)
- return new StaticMemberName(RT.resolveClassNameInContext(m.Groups[1].Value),m.Groups[2].Value);
-
- return null;
-}
-
-private static Object matchSymbol(String s) {
- Match m = symbolPat.Match(s);
- if(m.Success && m.Length == s.Length)
- return Symbol.intern(s);
- return null;
-}
-*/
-
-private static Object matchVar(String s) {
- Match m = varPat.Match(s);
- if(m.Success && m.Length == s.Length)
- return Module.intern(m.Groups[1].Value,m.Groups[2].Value);
- return null;
-}
-
-private static Object matchNumber(String s) {
- Match m = intPat.Match(s);
- if(m.Success && m.Length == s.Length)
- return Num.from(new BigInteger(s));
- m = floatPat.Match(s);
- if(m.Success && m.Length == s.Length)
- return Num.from(Double.Parse(s));
- m = ratioPat.Match(s);
- if(m.Success && m.Length == s.Length)
- {
- return Num.divide(new BigInteger(m.Groups[1].Value),new BigInteger(m.Groups[2].Value));
- }
- return null;
-}
-
-static private IFn getMacro(int ch) {
- if (ch < macros.Length)
- return macros[ch];
- return null;
-}
-
-static private bool isMacro(int ch) {
- return (ch < macros.Length && macros[ch] != null);
-}
-
-
-class StringReader : AFn{
- override public Object invoke(Object reader, Object doublequote) {
- StringBuilder sb = new StringBuilder();
- LineNumberingTextReader r = (LineNumberingTextReader) reader;
-
- for(int ch = r.Read();ch != '"';ch = r.Read())
- {
- if(ch == -1)
- throw new Exception("EOF while reading string");
- if(ch == '\\') //escape
- {
- ch = r.Read();
- if(ch == -1)
- throw new Exception("EOF while reading string");
- switch(ch)
- {
- case 't':
- ch = '\t';
- break;
- case 'r':
- ch = '\r';
- break;
- case 'n':
- ch = '\n';
- break;
- case '\\':
- break;
- case '"':
- break;
- default:
- throw new Exception("Unsupported escape character: \\" + (char)ch);
- }
- }
- sb.Append((char)ch);
- }
- return sb.ToString();
- }
-
-}
-class CommentReader : AFn{
- override public Object invoke(Object reader, Object semicolon)
- {
- LineNumberingTextReader r = (LineNumberingTextReader) reader;
- int ch;
- do
- {
- ch = r.Read();
- } while (ch != -1 && ch != '\n' && ch != '\r');
- return r;
- }
-
-}
-
-class QuoteReader : AFn{
- override public Object invoke(Object reader, Object quote) {
- LineNumberingTextReader r = (LineNumberingTextReader)reader;
- Object o = read(r, true, null, true);
- return RT.list(QUOTE, o);
- }
-}
-
-class BackquoteReader : AFn{
- override public Object invoke(Object reader, Object backquote) {
- LineNumberingTextReader r = (LineNumberingTextReader)reader;
- Object o = read(r, true, null, true);
- return RT.list(BACKQUOTE, o);
- }
-}
-
-class UnquoteReader : AFn{
- override public Object invoke(Object reader, Object comma) {
- LineNumberingTextReader r = (LineNumberingTextReader)reader;
- int ch = r.Read();
- if(ch == -1)
- throw new Exception("EOF while reading character");
- if(ch == '^')
- {
- Object o = read(r, true, null, true);
- return RT.list(UNQUOTE_SPLICING, o);
- }
- else
- {
- r.unread(ch);
- Object o = read(r, true, null, true);
- return RT.list(UNQUOTE, o);
- }
- }
-}
-class CharacterReader : AFn{
- override public Object invoke(Object reader, Object backslash)
- {
- LineNumberingTextReader r = (LineNumberingTextReader) reader;
- int ch = r.Read();
- if(ch == -1)
- throw new Exception("EOF while reading character");
- String token = readToken(r,(char)ch);
- if(token.Length == 1)
- return token[0];
- else if(token.Equals("newline"))
- return '\n';
- else if(token.Equals("space"))
- return ' ';
- else if(token.Equals("tab"))
- return '\t';
- throw new Exception("Unsupported character: \\" + token);
- }
-
-}
-class ListReader : AFn{
- override public Object invoke(Object reader, Object leftparen) {
- LineNumberingTextReader r = (LineNumberingTextReader) reader;
- return readDelimitedList(')', r, true);
- }
-
-}
-class UnmatchedDelimiterReader : AFn{
- override public Object invoke(Object reader, Object rightdelim) {
- throw new Exception("Unmatched delimiter: " + rightdelim);
- }
-
-}
-public static ISeq readDelimitedList(char delim, LineNumberingTextReader r, bool isRecursive) {
- ArrayList a = new ArrayList();
-
- for (; ;)
- {
- int ch = r.Read();
-
- while (Char.IsWhiteSpace((char)ch))
- ch = r.Read();
-
- if (ch == -1)
- throw new Exception("EOF while reading");
-
- if(ch == delim)
- break;
-
- IFn macroFn = getMacro(ch);
- if (macroFn != null)
- {
- Object mret = macroFn.invoke(r, (char)ch);
- //no op macros return the reader
- if (mret != r)
- a.Add(mret);
- }
- else
- {
- r.unread(ch);
-
- Object o = read(r, true, null, isRecursive);
- if (o != r)
- a.Add(o);
- }
- }
-
- return RT.seq(a);
-}
-
-/*
-public static void Main(String[] args){
- LineNumberingTextReader r = new LineNumberingTextReader(Console.In);
- TextWriter w = Console.Out;
- Object ret = null;
- try{
- for(;;)
- {
- ret = LispReader.read(r, true, null, false);
- RT.print(ret, w);
- w.Write('\n');
- w.Flush();
- }
- }
- catch(Exception e)
- {
- //e.printStackTrace();
- Console.Error.WriteLine(e.StackTrace);
- }
-}
-//*/
-
-}
-
-}
-
diff --git a/src/cli/runtime/MapEntry.cs b/src/cli/runtime/MapEntry.cs deleted file mode 100644 index 1ff7f93a..00000000 --- a/src/cli/runtime/MapEntry.cs +++ /dev/null @@ -1,135 +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.
- **/
-
-using System;
-using System.Collections;
-
-namespace clojure.lang
-{
-public class MapEntry : APersistentMap , IMapEntry{
-readonly Object _key;
-readonly Object _val;
-
-public MapEntry(Object key, Object val) {
- this._key = key;
- this._val = val;
-}
-
-public Object key() {
- return _key;
-}
-
-public Object val() {
- return _val;
-}
-
-override public bool contains(Object key) {
- return RT.equal(_key, key);
-}
-
-override public IMapEntry find(Object key) {
- return RT.equal(_key, key)?this:null;
-}
-
-override public Associative assoc(Object key, Object val) {
- if(RT.equal(_key, key))
- {
- if(_val == val)
- return this;
- return (MapEntry) new MapEntry(key, val).withMeta(_meta);
- }
- return (IPersistentMap) new PersistentArrayMap(_key,_val,key,val).withMeta(_meta);
-}
-
-override public Object get(Object key) {
- return RT.equal(_key, key)?_val:null;
-}
-
-override public IPersistentMap assocEx(Object key, Object val) {
- if(RT.equal(_key, key))
- throw new Exception("Key already present");
- return (IPersistentMap)assoc(key, val);
-}
-
-override public IPersistentMap without(Object key) {
- if(RT.equal(_key, key))
- return (IPersistentMap) PersistentArrayMap.EMPTY.withMeta(_meta);
- return this;
-}
-
-override public int count() {
- return 1;
-}
-
-override public IEnumerator GetEnumerator() {
- return new Iter(this);
-}
-
-class Iter : IEnumerator{
- MapEntry e;
- bool first = true;
-
- public Iter(MapEntry e) {
- this.e = e;
- }
-
-#region IEnumerator Members
-
-public object Current
- {
- get {return e;}
- }
-
-public bool MoveNext()
- {
- if(first)
- {
- first = false;
- return true;
- }
- return false;
- }
-
-public void Reset()
- {
- throw new Exception("The method or operation is not implemented.");
- }
-
-#endregion
- }
-
-
-override public ISeq seq() {
- return new Seq(this);
-}
-
-class Seq : ASeq{
- readonly MapEntry e;
-
- public Seq(MapEntry e) {
- this.e = e;
- }
-
- override public Object first() {
- return e;
- }
-
- override public ISeq rest() {
- return null;
- }
-
- override public int count(){
- return 1;
- }
-
-}
-}
-
-}
diff --git a/src/cli/runtime/Module.cs b/src/cli/runtime/Module.cs deleted file mode 100644 index 3e396783..00000000 --- a/src/cli/runtime/Module.cs +++ /dev/null @@ -1,70 +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 Mar 27, 2006 1:29:39 PM */ - -using System;
-using System.Collections.Specialized;
- -namespace clojure.lang
-{ - -public class Module
-{ - -/** - * String->Module - */ -static public HybridDictionary table = new HybridDictionary(); - -/** - * Symbol->Var - */
-public HybridDictionary vars = new HybridDictionary();
-public String name; - - -Module(String name) - { - this.name = name; - table.Add(name, this); - } - -static public Module find(String name) - { - return (Module) table[name]; - } - -static public Module findOrCreate(String name) - { - lock(table) - { - Module ns = find(name); - if(ns == null) - table.Add(name,ns = new Module(name)); - return ns; - } - }
-
-public Var find(Symbol sym){
- lock(vars)
- {
- return (Var) vars[sym];
- }
-}
-
-static public Var intern(String ns, String name)
- {
- return findOrCreate(ns).intern(Symbol.intern(name));
- }
-
-public Var intern(Symbol sym)
{
lock(vars)
{
Var var = (Var) vars[sym];
if(var == null)
vars.Add(sym,var = new Var(sym, this));
return var;
}
}
-} -} diff --git a/src/cli/runtime/Num.cs b/src/cli/runtime/Num.cs deleted file mode 100644 index 6058ab93..00000000 --- a/src/cli/runtime/Num.cs +++ /dev/null @@ -1,351 +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 Mar 28, 2006 10:07:33 AM */ - -using System;
-using java.math;
-
-namespace clojure.lang
-{ - -public abstract class Num : IComparable , IConvertible
- { - -public static Num ZERO = from(0); -public static Num ONE = from(1); - -static public Num from(int val) - { - //todo - cache a bunch of small fixnums - return new FixNum(val); - } - -static public Num from(double val) - { - return new DoubleNum(val); - } - -static public Num from(long val) - { - if(val <= Int32.MaxValue && val >= Int32.MinValue) - return from((int) val); - else - return new BigNum(val); - } - -static public Num from(BigInteger val) - { - if(val.bitLength() < 32) - return from(val.intValue()); - else - return new BigNum(val); - } - - internal static BigInteger BIGTEN = BigInteger.valueOf(10); - -static public Num from(Object x) - { - if(x is Num) - return (Num) x; - else - { - IConvertible c = x as IConvertible; - if(c != null) - { - switch(c.GetTypeCode()) - { - case TypeCode.Int32: - return Num.from((Int32) x); - case TypeCode.Double: - case TypeCode.Single: - return Num.from(Convert.ToDouble(x)); - case TypeCode.Int64: - return Num.from((Int64) x); - //TODO: Decimal w/o string conversion - case TypeCode.Decimal: - BigDecimal d = new BigDecimal(x.ToString()); - return Num.divide(d.movePointRight(d.scale()).toBigInteger(), - BIGTEN.pow(d.scale())); - default: - return Num.from(Convert.ToInt32(x)); - } - } - else if(x is BigInteger) - return Num.from((BigInteger) x); - else - throw new ArgumentException("Cannot convert argument: " + x + " to Num"); - } - }
-
-
- virtual public byte byteValue()
- {
- return checked((byte)intValue());
- }
-
- virtual public short shortValue()
- {
- return checked((short)intValue());
- } - - abstract public double doubleValue(); - - abstract public float floatValue(); - - abstract public int intValue(); - - abstract public long longValue(); - -static public Num add(Object x, Object y) - { - //if(x instanceof Num && y instanceof Num) - //return ((Num)x).add((Num) y); - return Num.from(x).add(Num.from(y)); - } - -abstract public Num add(Num rhs); - -abstract public Num addTo(int x); - -abstract public Num addTo(BigInteger x); - -abstract public Num addTo(RatioNum x); - -static public Num subtract(Object x, Object y) - { - return Num.from(y).subtractFrom(Num.from(x)); - } - -//this double-dispatches to addTo(-self) -abstract public Num subtractFrom(Num rhs); - -static public Num multiply(Object x, Object y) - { - return Num.from(x).multiplyBy(Num.from(y)); - } - -abstract public Num multiplyBy(Num rhs); - -abstract public Num multiply(int x); - -abstract public Num multiply(BigInteger x); - -abstract public Num multiply(RatioNum x); - -static public Num divide(Object x, Object y) - { - return Num.from(x).divideBy(Num.from(y)); - } - -abstract public Num divideBy(Num rhs); - -abstract public Num divide(int x); - -abstract public Num divide(BigInteger x); - -abstract public Num divide(RatioNum x); - -static public Object truncate( Object num, Object div) - { - return Num.from(div).truncateDivide( Num.from(num)); - } - -abstract public Object truncateDivide( Num rhs); - -abstract public Object truncateBy( int x); - -abstract public Object truncateBy( BigInteger x); - -abstract public Object truncateBy( RatioNum x); - -static public Object truncateBigints( BigInteger n, BigInteger d) - { - BigInteger[] result = n.divideAndRemainder(d); - return RT.setValues( Num.from(result[0]), Num.from(result[1])); - } - - internal static BigInteger BIG_ONE = BigInteger.valueOf(1); - internal static BigInteger BIG_ZERO = BigInteger.valueOf(0); - -static public Num divide(BigInteger n, BigInteger d) - { - BigInteger gcd = n.gcd(d); - if(gcd.Equals(BIG_ZERO)) - return Num.ZERO; - n = n.divide(gcd); - d = d.divide(gcd); - if(d.Equals(BIG_ONE)) - return Num.from(n); - return new RatioNum((IntegerNum) Num.from(d.signum() < 0 ? n.negate() : n), - (IntegerNum) Num.from(d.signum() < 0 ? d.negate() : d)); - } - -static public Boolean equiv(Object x, Object y) - { - return Num.from(x).equiv(Num.from(y)); - } - -abstract public Boolean equiv(Num rhs); - -abstract public Boolean equivTo(int x); - -abstract public Boolean equivTo(BigInteger x); - -abstract public Boolean equivTo(RatioNum x); - -static public Boolean lt(Object x, Object y) - { - return Num.from(x).lt(Num.from(y)); - } - -static public Boolean lte(Object x, Object y) - { - Num lx = Num.from(x); - Num ly = Num.from(y); - return lx.lt(ly) || lx.equiv(ly); - } - -static public Boolean gt(Object x, Object y) - { - return Num.from(y).lt(Num.from(x)); - } - -static public Boolean gte(Object x, Object y) - { - Num lx = Num.from(x); - Num ly = Num.from(y); - return ly.lt(lx) || lx.equiv(ly); - } - -abstract public Boolean lt(Num rhs); - -abstract public Boolean gt(int x); - -abstract public Boolean gt(BigInteger x); - -abstract public Boolean gt(RatioNum x); - -static public Num negate(Object x) - { - return Num.from(x).negate(); - } - -abstract public Num negate(); - -abstract public Boolean minusp(); - -abstract public Boolean plusp(); - -abstract public Num oneMinus(); - -abstract public Num onePlus(); - -public int CompareTo(Object obj) - { - Num other = Num.from(obj); - if(this.equiv(other)) - return 0; - else if(this.lt(other)) - return -1; - else - return 1; - }
-
-#region IConvertible Members
-
-public TypeCode GetTypeCode()
- {
-throw new Exception("The method or operation is not implemented.");
- }
-
-public bool ToBoolean(IFormatProvider provider)
- {
- return true;
- }
-
-public byte ToByte(IFormatProvider provider)
- {
- return checked((byte)intValue());
- }
-
-public char ToChar(IFormatProvider provider)
- {
- return checked((char)intValue());
- }
-
-public DateTime ToDateTime(IFormatProvider provider)
- {
-throw new Exception("The method or operation is not implemented.");
- }
-
-public decimal ToDecimal(IFormatProvider provider)
- {
-throw new Exception("The method or operation is not implemented.");
- }
-
-public double ToDouble(IFormatProvider provider)
- {
- return doubleValue();
- }
-
-public short ToInt16(IFormatProvider provider)
- {
- return checked((short)intValue());
- }
-
-public int ToInt32(IFormatProvider provider)
- {
- return intValue();
- }
-
-public long ToInt64(IFormatProvider provider)
- {
- return longValue();
- }
-
-public sbyte ToSByte(IFormatProvider provider)
- {
- return checked((sbyte)intValue());
- }
-
-public float ToSingle(IFormatProvider provider)
- {
- return floatValue();
- }
-
-public string ToString(IFormatProvider provider)
- {
- return ToString();
- }
-
-public object ToType(Type conversionType, IFormatProvider provider)
- {
-throw new Exception("The method or operation is not implemented.");
- }
-
-public ushort ToUInt16(IFormatProvider provider)
- {
-throw new Exception("The method or operation is not implemented.");
- }
-
-public uint ToUInt32(IFormatProvider provider)
- {
-throw new Exception("The method or operation is not implemented.");
- }
-
-public ulong ToUInt64(IFormatProvider provider)
- {
-throw new Exception("The method or operation is not implemented.");
- }
-
-#endregion
- } -} diff --git a/src/cli/runtime/Obj.cs b/src/cli/runtime/Obj.cs deleted file mode 100644 index ebafc9c4..00000000 --- a/src/cli/runtime/Obj.cs +++ /dev/null @@ -1,32 +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 Mar 25, 2006 3:44:58 PM */ - -using System;
- -namespace clojure.lang
-{ - -public abstract class Obj{ - -internal volatile IPersistentMap _meta = null;
-
-
-public IPersistentMap meta() {
- return _meta;
-}
-
-abstract public Obj withMeta(IPersistentMap meta);
-
- -} - -}
\ No newline at end of file diff --git a/src/cli/runtime/PerisistentArrayList.cs b/src/cli/runtime/PerisistentArrayList.cs deleted file mode 100644 index 9c27932d..00000000 --- a/src/cli/runtime/PerisistentArrayList.cs +++ /dev/null @@ -1,115 +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.
- **/
-
-using System;
-using System.Collections;
-
-namespace clojure.lang
-{
-public class PersistentArrayList : PersistentArray, IPersistentList{
-
-int _count;
-
-public PersistentArrayList(int initialCapacity) : base(initialCapacity){
-
- _count = 0;
-}
-
-PersistentArrayList(Master master,int rev,int baseline, BitArray history, int count):base(master,rev,baseline,history){
-
- this._count = count;
-}
-
-PersistentArrayList(int size, Object defaultVal, float loadFactor, int count):base(size, defaultVal, loadFactor) {
-
- this._count = count;
-}
-
-public PersistentArrayList(IPersistentArray init, int initialCapacity):base(init,initialCapacity){
- _count = Math.Min(init.count(),initialCapacity);
-}
-
-override public Object nth(int i) {
- if(i >= _count)
- throw new IndexOutOfRangeException();
-
- return base.nth(i);
-}
-
-override public IPersistentArray assocN(int i,Object val) {
- if(i >= _count)
- throw new IndexOutOfRangeException();
-
- return base.assocN(i, val);
-}
-
-override public int length(){
- return _count;
-}
-
-override public int count(){
- return _count;
-}
-
-override public IPersistentCollection cons(Object val) {
- if(_count == data.master.array.Length) //full
- {
- lock(data.master){
- if(_count == data.master.array.Length) //still full
- grow();
- }
- }
- PersistentArrayList ret = (PersistentArrayList) base.assocN(_count, val);
- ret._count = _count + 1;
- return ret;
-}
-
-public Object peek(){
- if(_count > 0)
- return nth(_count - 1);
- return null;
-}
-
-public IPersistentList pop() {
- if(_count == 0)
- throw new InvalidOperationException();
- PersistentArrayList ret = new PersistentArrayList(data.master, data.rev, data.baseline, data.history, _count - 1);
- ret._meta = _meta;
- return ret;
-}
-
-
-private void grow() {
- //must be called inside lock of master
- if(data.master.next != null) //this master has been trimmed, but this rev is not yet propagated
- trim();
-
- Master newMaster = new Master(data.master.array.Length * 2, data.master.defaultVal, data.master.loadFactor, data.master.basis);
- newMaster.rev = data.master.rev;
- newMaster.load = data.master.load;
- for(int i=0;i<data.master.array.Length;i++)
- newMaster.array[i] = data.master.array[i];
- this.data = new Data(newMaster, data.rev, data.baseline, data.history);
-}
-
-override internal PersistentArray create(Master master,int rev,int baseline, BitArray history){
- PersistentArray ret = new PersistentArrayList(data.master, rev, baseline, history,_count);
- ret._meta = _meta;
- return ret;
- }
-
-override internal PersistentArray create(int size, Object defaultVal, float loadFactor) {
- PersistentArray ret = new PersistentArrayList(size, defaultVal, loadFactor,_count);
- ret._meta = _meta;
- return ret;
- }
-
-}
-}
diff --git a/src/cli/runtime/PersistentArray.cs b/src/cli/runtime/PersistentArray.cs deleted file mode 100644 index 40e1fbc0..00000000 --- a/src/cli/runtime/PersistentArray.cs +++ /dev/null @@ -1,597 +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 Jun 2, 2006 */
-
-using System;
-using System.Collections;
-
-namespace clojure.lang
-{
-/**
- * Note that instances of this class are constant values
- * i.e. set() returns a new array, old one is intact
- *
- * Multiple revisions (thread-safely) share the same master array
- *
- * Constant time most-recent-revision lookups
- * Amortized constant-time sequential revisions (when loadFactor > 1)
- * where a sequential revision is a revision of the most recent revision
- *
- * Non-sequential revisions are O(length), but with a small constant multiplier of 1/32
- * Worst-case O(r) lookups for oldest revs where r is number of revisions
- * at index i since last (automatic or manual) isolate. If set()s are roughly evenly
- * distributed, r should be approximately == loadFactor, i.e. constant
- * In pathological case (all mods to same index), r == (loadFactor * length)
- *
- * (loadFactor * length) old values are retained, even if the array revisions aren't
- * Default loadFactor is 2.1
- * When the load exceeds (loadFactor * length) the next revision is automatically isolated
- * You can determine how many values are in the shared master by calling load()
- * and can trim them by calling isolate() or resize(), which yield a new array with no
- * sharing and no old values
- *
- * See Cohen for basic idea
- * I added hybrid most-recent-sequential-range + shared-bitset idea, multi-thread-safety
- */
-
- public class PersistentArray : APersistentArray, IEnumerable
- {
-
- #region IEnumerable Members
-
- public IEnumerator GetEnumerator()
- {
- return new ValIter(this);
- }
-
- #endregion
-
- override public ISeq seq()
- {
- if (length() > 0)
- return new Seq(this, 0);
- return null;
- }
-
- public ISeq rseq()
- {
- if (count() > 0)
- return new RSeq(this, count() - 1);
- return null;
- }
-
-internal class Master{
- internal readonly Entry[] array;
- internal readonly Object defaultVal;
- internal int rev;
- internal int load;
- internal readonly int maxLoad;
- internal readonly float loadFactor;
- internal readonly int[] basis;
- internal Master next;
-
- internal Master(int size, Object defaultVal, float loadFactor, int[] basis)
- {
- this.array = new Entry[size];
- this.defaultVal = defaultVal;
- this.rev = 0;
- this.load = 0;
- this.maxLoad = (int)(size * loadFactor);
- this.basis = basis;
- this.loadFactor = loadFactor;
- }
- internal Master(Master parent)
- {
- this.array = new Entry[parent.array.Length];
- this.defaultVal = parent.defaultVal;
- this.rev = 0;
- this.load = 0;
- this.maxLoad = parent.maxLoad;
- this.loadFactor = parent.loadFactor;
- this.next = null;
-
- this.basis = new int[parent.array.Length];
- }
- }
-
-internal class Entry
- {
- internal readonly int rev;
- internal readonly Object val;
-
- internal Entry(int rev, Object val)
- {
- this.rev = rev;
- this.val = val;
- }
-
- internal virtual Entry rest()
- {
- return null;
- }
-
- internal static Entry create(int rev, Object val, Entry rest)
- {
- if (rest == null)
- return new Entry(rev, val);
- return new EntryLink(rev, val, rest);
- }
- }
-
-internal class EntryLink : Entry
- {
- internal readonly Entry _rest;
-
- internal EntryLink(int rev, Object val, Entry rest) :base(rev,val)
- {
- this._rest = rest;
- }
-
- override internal Entry rest(){
- return _rest;
- }
-}
-
-internal class Seq : ASeq, IndexedSeq{
- readonly PersistentArray p;
- readonly int i;
-
- internal Seq(PersistentArray p, int i){
- this.p = p;
- this.i = i;
- }
-
- override public Object first() {
- return p.nth(i);
- }
-
- override public ISeq rest() {
- if(i+1 < p.length())
- return new Seq(p, i + 1);
- return null;
- }
-
- public override int count() {
- return p.count() - i;
- }
-
-#region IndexedSeq Members
-
-public int index()
- {
- return i;
- }
-
-#endregion
- }
-
-class RSeq : ASeq, IndexedSeq{
- readonly PersistentArray p;
- readonly int i;
-
- internal RSeq(PersistentArray p, int i){
- this.p = p;
- this.i = i;
- }
-
- public override Object first() {
- return p.nth(i);
- }
-
- public override ISeq rest() {
- if(i > 0)
- return new RSeq(p, i - 1);
- return null;
- }
-
- public int index() {
- return i;
- }
-
- public override int count() {
- return i + 1;
- }
-}
-internal class ValIter : IEnumerator
- {
- internal PersistentArray p;
- internal int i;
-
- internal ValIter(PersistentArray p)
- {
- this.p = p;
- this.i = -1;
-}
-
-#region IEnumerator Members
-
-public object Current
- {
- get { return p.nth(i); }
- }
-
-public bool MoveNext()
- {
- ++i;
- return i < p.length();
- }
-
-public void Reset()
- {
- throw new Exception("The method or operation is not implemented.");
- }
-
-#endregion
- }
-
-internal class Data{
- internal readonly Master master;
- internal readonly int rev;
- internal readonly int baseline;
- internal readonly BitArray history;
-
- public Data(Master master, int rev, int baseline, BitArray history)
- {
- this.master = master;
- this.rev = rev;
- this.baseline = baseline;
- this.history = history;
- }
- }
-
-internal volatile Data data;
-
-public PersistentArray(int size)
- : this(size, (Object)null)
- {
- }
-
-public PersistentArray(int size, Object defaultVal)
- :this(size,defaultVal,2.1f)
- {
- }
-
-public PersistentArray(int size, Object defaultVal, float loadFactor){
- this.data = new Data(new Master(size, defaultVal, loadFactor,null), 0, 0, null);
-}
-
- internal PersistentArray(Master master, int rev, int baseline, BitArray history)
- {
- this.data = new Data(master, rev, baseline, history);
-}
-
-public PersistentArray(int size, ISeq seq) : this(size){
- int load = 0;
- for(int i=0;seq != null && i < size;i++, seq=seq.rest())
- {
- data.master.array[i] = new Entry(0,seq.first());
- ++load;
- }
-
- data.master.load = load;
-}
-
-public PersistentArray(IPersistentArray init) :this(init.length()) {
- int load = 0;
- for(int i=0;i < init.length();i++)
- {
- data.master.array[i] = new Entry(0, init.nth(i));
- ++load;
- }
-
- data.master.load = load;
-}
-
-public PersistentArray(IPersistentArray init, int size) :this(size) {
- int load = 0;
- for(int i=0;i < init.length() && i < size;i++)
- {
- data.master.array[i] = new Entry(0,init.nth(i));
- ++load;
- }
-
- data.master.load = load;
-}
-
-override public int count(){
-return data.master.array.Length;
-}
-
-override public int length(){
-return data.master.array.Length;
-}
-
-override public Object nth(int i){
- Entry e = getEntry(i);
- if(e != null)
- return e.val;
- return data.master.defaultVal;
-}
-
-public bool has(int i){
- return getEntry(i) != null;
-}
-
-public PersistentArray resize(int newLength)
- {
- PersistentArray ret = create(newLength, data.master.defaultVal, data.master.loadFactor);
- for (int i = 0; i < Math.Min(length(), newLength); i++)
- {
- Entry e = getEntry(i);
- if (e != null)
- {
- ret.data.master.array[i] = Entry.create(0, e.val, null);
- ++ret.data.master.load;
- }
- }
- return ret;
- }
-
-public int load(){
-return data.master.load;
-}
-
-public void isolate()
- {
- lock(data.master)
- {
- Master nextMaster = new Master(data.master);
- int load = 0;
- for(int i=0;i<length();i++)
- {
- Entry entry = getEntry(i);
- if(entry != null)
- {
- nextMaster.array[i] = new Entry(0,entry.val);
- ++load;
- }
- }
- nextMaster.load = load;
- this.data = new Data(nextMaster, 0, 0, null);
- }
- }
-
-Entry getEntry(int i){
-for (Entry e = data.master.array[i]; e != null; e = e.rest())
- {
- if (e.rev <= data.rev)
- {
- if (e.rev >= data.baseline
- || (data.history != null && e.rev < data.history.Length && data.history.Get(e.rev)))
- return e;
- }
- }
- return null;
-}
-
-override public IPersistentArray assocN(int i,Object val) {
-//if (data.master.load >= data.master.maxLoad)
-// {
-// isolate();
-// //set(i,val);
-// }
- lock (data.master)
- {
- if (data.master.load >= data.master.maxLoad)
- //isolate();
- trim();
- PersistentArray ret = getSetArray();
- ret.doSet(i, val);
- return ret;
- }
-}
-
-protected void trim(){
- //must be called inside lock of master
- if (data.master.next == null) //this master has never been trimmed
- {
- Master nextMaster = new Master(data.master);
- int load = 0;
- for(int i=0;i<length();i++)
- {
- Entry entry = getEntry(i);
- if(entry != null)
- {
- nextMaster.array[i] = new Entry(0,entry.val);
- nextMaster.basis[i] = entry.rev;
- ++load;
- }
- }
- nextMaster.load = load;
- Data nextData = new Data(nextMaster, 0, 0, null);
- data.master.next = nextMaster;
- data = nextData;
- }
- else //this master has been trimmed, but this rev is not yet propagated
- {
- Master nextMaster = data.master.next;
- int diff = 0;
- for(int i=0;i<length();i++)
- {
- Entry e = getEntry(i);
- if(e != null && e.rev != nextMaster.basis[i])
- ++diff;
- }
- if(diff >= length()/2 || nextMaster.load + diff > nextMaster.maxLoad)
- isolate();
- else
- {
- Data nextData;
- lock(nextMaster){
- int rev = ++nextMaster.rev;
- for(int i=0;i<length();i++)
- {
- Entry e = getEntry(i);
- if(e != null && e.rev != nextMaster.basis[i])
- {
- nextMaster.array[i] = Entry.create(rev, e.val, nextMaster.array[i]);
- ++nextMaster.load;
- }
- }
- BitArray history = new BitArray(rev);
- history.Set(0,true);
- nextData = new Data(nextMaster,rev,rev,history);
- }
- this.data = nextData;
- }
- }
-}
-
-override public bool Equals(Object key){
- if(this == key) return true;
- if(key == null || !(key is IPersistentArray)) return false;
-
- IPersistentArray a = (IPersistentArray) key;
-
- if(a.length() != length())
- return false;
-
- for(int i = 0; i < length(); i++)
- {
- if(!equalKey(nth(i),a.nth(i)))
- return false;
- }
-
- return true;
-}
-
-override public int GetHashCode()
- {
- int ret = 0;
- for (int i = 0; i < length(); i++)
- {
- Object o = nth(i);
- if (o != null)
- ret ^= o.GetHashCode();
- }
- return ret;
- }
-
-private bool equalKey(Object k1, Object k2)
- {
- if (k1 == null)
- return k2 == null;
- return k1.Equals(k2);
- }
-
-void doSet(int i, Object val){
- //must now be called inside lock of master
-data.master.array[i] = Entry.create(data.rev, val, data.master.array[i]);
-++data.master.load;
-}
-
-PersistentArray getSetArray(){
- //must now be called inside lock of master
- //is this a sequential update?
-if (data.master.rev == data.rev)
- {
- return create(data.master, ++data.master.rev, data.baseline, data.history);
- }
- else //gap
- {
-
- int nextRev = ++data.master.rev;
- BitArray nextHistory;
- if (data.history != null)
- {
- nextHistory = (BitArray)data.history.Clone();
- nextHistory.Length = data.rev + 1;
- }
- else
- nextHistory = new BitArray(data.rev + 1);
- for (int i = data.baseline; i <= data.rev; i++)
- nextHistory.Set(i,true);
- return create(data.master, nextRev, nextRev, nextHistory);
- }
-}
-
-internal virtual PersistentArray create(Master master, int rev, int baseline, BitArray history)
- {
- PersistentArray ret = new PersistentArray(data.master, rev, baseline, history);
- ret._meta = _meta;
- return ret;
- }
-
-internal virtual PersistentArray create(int size, Object defaultVal, float loadFactor)
- {
- PersistentArray ret = new PersistentArray(size, defaultVal, loadFactor);
- ret._meta = _meta;
- return ret;
- }
-
-
-/*
-[STAThread]
-static public void Main(String[] args){
- if(args.Length != 3)
- {
- Console.Error.WriteLine("Usage: PersistentArray size writes reads");
- return;
- }
- int size = Int32.Parse(args[0]);
- int writes = Int32.Parse(args[1]);
- int reads = Int32.Parse(args[2]);
- ArrayList v = ArrayList.Synchronized(new ArrayList(size));
- //v.setSize(size);
- //IArray p = new PersistentArray(size);
- IPersistentArray p = new PersistentArrayList(size);
-
- for(int i = 0; i < size; i++)
- {
- v.Add(0);
- //p = p.set(i, 0);
- p = (IPersistentArray)((PersistentArrayList)p).cons(0);
- }
-
- Random rand;
-
- rand = new Random(42);
- long tv = 0;
- Console.WriteLine("ArrayList");
- DateTime start = DateTime.Now;
- for(int i = 0; i < writes; i++)
- {
- v[rand.Next(size)] = i;
- }
- for(int i = 0; i < reads; i++)
- {
- tv += (int)v[rand.Next(size)];
- }
-
- Console.WriteLine("Time: " + (DateTime.Now - start));
-
- Console.WriteLine("PersistentArray");
- rand = new Random(42);
- long tp = 0;
- start = DateTime.Now;
- IPersistentArray oldp = p;
- for (int i = 0; i < writes; i++)
- {
- p = p.assocN(rand.Next(size), i);
- //dummy set to force perverse branching
- oldp = oldp.assocN(i%size, i);
- //p.set(i%size, i);
- }
- for(int i = 0; i < reads; i++)
- {
- tp += (int)p.nth(rand.Next(size));
- }
- Console.WriteLine("Time: " + (DateTime.Now - start));
- Console.WriteLine("Done: " + tv + ", " + tp);
-
-
-}
- //*/
-
-
-}
-
-}
diff --git a/src/cli/runtime/PersistentArrayMap.cs b/src/cli/runtime/PersistentArrayMap.cs deleted file mode 100644 index 68d4b2c1..00000000 --- a/src/cli/runtime/PersistentArrayMap.cs +++ /dev/null @@ -1,261 +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.
- **/
-
-using System;
-using System.Collections;
- -namespace clojure.lang
-{
-
-/**
- * Simple implementation of persistent map on an array
-
- * Note that instances of this class are constant values
- * i.e. add/remove etc return new values
- *
- * Copies array on every change, so only appropriate for _very_small_ maps
- *
- * null keys and values are ok, but you won't be able to distinguish a null value via get - use contains/find
- */
-
-public class PersistentArrayMap : APersistentMap {
-
-internal readonly Object[] array;
-
- public static PersistentArrayMap EMPTY = new PersistentArrayMap();
-
- internal const int HASHTABLE_THRESHOLD = 42;
-
-protected PersistentArrayMap(){
- this.array = new object[]{};
-}
-
-virtual internal PersistentArrayMap create(params Object[] init){
- PersistentArrayMap ret = new PersistentArrayMap(init);
- ret._meta = _meta;
- return ret;
-}
-
-virtual internal IPersistentMap createHT(Object[] init){
- PersistentHashtableMap ret = new PersistentHashtableMap(init);
- ret._meta = _meta;
- return ret;
- }
-
-/**
- * This ctor captures/aliases the passed array, so do not modify later
- * @param init {key1,val1,key2,val2,...}
- */
-public PersistentArrayMap(params Object[] init){
- this.array = init;
-}
-
-override public int count() {
- return array.Length/2;
-}
-
-override public bool contains(Object key){
- return indexOf(key) >= 0;
-}
-
-override public IMapEntry find(Object key) {
- int i = indexOf(key);
- if(i >= 0)
- return new Iter(array,i);
- return null;
-}
-
-override public IPersistentMap assocEx(Object key, Object val) {
- int i = indexOf(key);
- Object[] newArray;
- if(i >= 0)
- {
- throw new Exception("Key already present");
- }
- else //didn't have key, grow
- {
- if (array.Length > HASHTABLE_THRESHOLD)
- return createHT(array).assocEx(key, val);
- newArray = new Object[array.Length + 2];
- if(array.Length > 0)
- Array.Copy(array,0,newArray,2,array.Length);
- newArray[0] = key;
- newArray[1] = val;
- }
- return create(newArray);
- }
-
-override public Associative assoc(Object key, Object val) {
- int i = indexOf(key);
- Object[] newArray;
- if(i >= 0) //already have key, same-sized replacement
- {
- if(array[i+1] == val) //no change, no op
- return this;
- newArray = (Object[])array.Clone();
- newArray[i+1] = val;
- }
- else //didn't have key, grow
- {
- if (array.Length > HASHTABLE_THRESHOLD)
- return createHT(array).assoc(key, val);
- newArray = new Object[array.Length + 2];
- if(array.Length > 0)
- Array.Copy(array,0,newArray,2,array.Length);
- newArray[0] = key;
- newArray[1] = val;
- }
- return create(newArray);
-}
-
-override public IPersistentMap without(Object key) {
- int i = indexOf(key);
- if(i >= 0) //have key, will remove
- {
- int newlen = array.Length - 2;
- if (newlen == 0)
- return empty();
- Object[] newArray = new Object[newlen];
- for(int s=0,d=0;s<array.Length;s += 2)
- {
- if(!equalKey(array[s],key)) //skip removal key
- {
- newArray[d] = array[s];
- newArray[d+1] = array[s+1];
- d += 2;
- }
- }
- return create(newArray);
- }
- //don't have key, no op
- return this;
-}
-
-virtual public IPersistentMap empty() {
- if(_meta == null)
- return EMPTY;
- PersistentArrayMap ret = new PersistentArrayMap();
- ret._meta = _meta;
- return ret;
-}
-
-override public Object get(Object key) {
- int i = indexOf(key);
- if(i >= 0)
- return array[i + 1];
- return null;
-}
-
-public int capacity() {
- return count();
-}
-
-int indexOf(Object key){
- for(int i=0;i<array.Length;i+=2)
- {
- if(equalKey(array[i],key))
- return i;
- }
- return -1;
-}
-
-internal virtual bool equalKey(Object k1,Object k2){
- if(k1 == null)
- return k2 == null;
- return k1.Equals(k2);
-}
-
-override public IEnumerator GetEnumerator() {
- return new Iter(array);
-}
-
-override public ISeq seq() {
- if(array.Length > 0)
- return new Seq(array,0);
- return null;
-}
-
-internal class Seq : ASeq, IMapEntry{
- readonly Object[] array;
- readonly int i;
-
- internal Seq(Object[] array, int i){
- this.array = array;
- this.i = i;
- }
-
- public Object key() {
- return array[i];
- }
-
- public Object val() {
- return array[i+1];
- }
-
- override public Object first() {
- return this;
- }
-
- override public ISeq rest() {
- if(i+2 < array.Length)
- return new Seq(array, i + 2);
- return null;
- }
- override public int count() {
- return (array.Length - i)/2;
- }
-}
-internal class Iter : IEnumerator,IMapEntry{
- Object[] array;
- int i;
-
- //for iterator
- internal Iter(Object[] array): this(array,-2)
- {
- }
-
- //for find
- internal Iter(Object[] array, int i){
- this.array = array;
- this.i = i;
- }
-
- public Object key() {
- return array[i];
- }
-
- public Object val() {
- return array[i+1];
- }
-
-#region IEnumerator Members
-
-public object Current
- {
- get {return this;}
- }
-
-public bool MoveNext()
- {
- i += 2;
- return i < array.Length - 2;
- }
-
-public void Reset()
- {
- throw new Exception("The method or operation is not implemented.");
- }
-
-#endregion
- }
-}
-
-
-}
\ No newline at end of file diff --git a/src/cli/runtime/PersistentHashtableMap.cs b/src/cli/runtime/PersistentHashtableMap.cs deleted file mode 100644 index a14bcc2a..00000000 --- a/src/cli/runtime/PersistentHashtableMap.cs +++ /dev/null @@ -1,304 +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.
- **/
-
-
-using System;
-using System.Collections;
-
-namespace clojure.lang
- {
-
-
-public class PersistentHashtableMap : APersistentMap {
-
-static readonly float FILL_FACTOR = 0.75f;
-
-readonly internal PersistentArray array;
-readonly int _count;
-readonly int growAtCount;
-
-public PersistentHashtableMap(int initialCapacity) {
- array = new PersistentArray(calcPrimeCapacity(initialCapacity));
- _count = 0;
- this.growAtCount = (int) (this.array.length()*FILL_FACTOR);
-}
-
-/**
- * @param init {key1,val1,key2,val2,...}
- */
-public PersistentHashtableMap(Object[] init){
- //start halfway to a rehash
- PersistentArray narray = new PersistentArray(calcPrimeCapacity(init.Length));
- for(int i=0;i<init.Length;i+=2)
- {
- narray = doPut(bucketFor(init[i],narray),init[i], init[i + 1],narray);
- }
- this.array = narray;
- this._count = init.Length/2; //hmmm... presumes no dupe keys in init
- this.growAtCount = (int) (this.array.length()*FILL_FACTOR);
-}
-
-internal PersistentHashtableMap(int count,PersistentArray array) {
- this._count = count;
- this.array = array;
- this.growAtCount = (int) (this.array.length()*FILL_FACTOR);
-}
-
-internal PersistentHashtableMap(int count,PersistentArray array,int growAt) {
- this._count = count;
- this.array = array;
- this.growAtCount = growAt;
-}
-
-int calcPrimeCapacity(int capacity) {
- // No .Net equivalent
- //return BigInteger.valueOf((long) (capacity/FILL_FACTOR)).nextProbablePrime().intValue();
- int ret = (int)(capacity/FILL_FACTOR);
- if(ret%2 == 0)
- ++ret;
- return ret;
-}
-
-override public int count() {
- return _count;
-}
-
-override public bool contains(Object key) {
- IPersistentMap entries = entriesFor(key);
- return entries != null && entries.contains(key);
-}
-
-override public IMapEntry find(Object key) {
- IPersistentMap entries = entriesFor(key);
- if(entries != null)
- return entries.find(key);
- return null;
-}
-
-override public IPersistentMap assocEx(Object key, Object val) {
- if(_count > growAtCount)
- return grow().assocEx(key, val);
- int i = bucketFor(key,array);
- int incr = 1;
- PersistentArray newArray = doAdd(i, key, val, array);
- return create(_count + incr, newArray, growAtCount);
-}
-
-override public Associative assoc(Object key, Object val) {
- if(_count > growAtCount)
- return grow().assoc(key, val);
- int i = bucketFor(key,array);
- int incr = 1;
- PersistentArray newArray = doPut(i, key, val, array);
- if(newArray == array)
- return this;
- if(array.nth(i) != null && ((IPersistentMap)newArray.nth(i)).count() == ((IPersistentMap)array.nth(i)).count()) //key already there, no growth
- incr = 0;
- return create(_count + incr, newArray, growAtCount);
-}
-
-PersistentArray doPut(int i,Object key,Object val,PersistentArray array){
- IPersistentMap entries = (IPersistentMap) array.nth(i);
- IPersistentMap newEntries;
- if (entries != null)
- {
- newEntries = (IPersistentMap)entries.assoc(key, val);
- if(newEntries == entries) //already there with same value, no op
- return array;
- }
- else
- newEntries = createEntryMap(key, val);
- //newEntries = createArrayMap(new Object[]{key, val});
-
- return (PersistentArray)array.assocN(i, newEntries);
-}
-
-PersistentArray doAdd(int i,Object key,Object val,PersistentArray array) {
- IPersistentMap entries = (IPersistentMap) array.nth(i);
- IPersistentMap newEntries;
- if (entries != null)
- {
- newEntries = entries.assocEx(key, val);
- }
- else
- newEntries = createEntryMap(key, val);
-
- return (PersistentArray)array.assocN(i, newEntries);
-}
-override public IPersistentMap without(Object key) {
- int i = bucketFor(key,array);
- IPersistentMap entries = (IPersistentMap) array.nth(i);
- if (entries != null)
- {
- IPersistentMap newEntries = entries.without(key);
- if (newEntries != entries)
- return create(_count - 1, (PersistentArray)array.assocN(i, newEntries));
- }
- //not there, no op
- return this;
-}
-
-override public Object get(Object key) {
- IPersistentMap entries = entriesFor(key);
- if(entries != null)
- return entries.get(key);
- return null;
-}
-
-public int capacity() {
- return array.length();
-}
-
-IPersistentMap grow(){
- PersistentArray newArray = new PersistentArray(calcPrimeCapacity(_count * 2));
- foreach (IMapEntry e in this)
- {
- newArray = doPut(bucketFor(e.key(),newArray),e.key(), e.val(),newArray);
- }
- return create(_count,newArray);
-}
-
-override public IEnumerator GetEnumerator() {
- return new Iter(array);
-}
-
-override public ISeq seq() {
- if(count() == 0)
- return null;
- return Seq.create(array,count());
-}
-
-class Seq : ASeq{
- readonly PersistentArray buckets;
- readonly int b;
- readonly ISeq e;
- readonly int cnt;
-
-
- static public Seq create(PersistentArray buckets,int cnt) {
- return next(buckets, -1, null,cnt);
- }
-
- static Seq next(PersistentArray buckets, int b, ISeq e, int cnt)
- {
- if(e != null && e.rest() != null)
- return new Seq(buckets,b,e.rest(),cnt);
- for(b = b+1;b<buckets.length();b++)
- {
- IPersistentCollection a = (IPersistentCollection) buckets.nth(b);
- if(a != null && a.seq() != null)
- return new Seq(buckets,b,a.seq(),cnt);
- }
- return null;
- }
-
- Seq(PersistentArray buckets, int b, ISeq e, int cnt)
- {
- this.buckets = buckets;
- this.b = b;
- this.e = e;
- this.cnt = cnt;
- }
-
- override public Object first() {
- return e.first();
- }
-
- override public ISeq rest() {
- return next(buckets,b,e,cnt-1);
- }
-
- public override int count()
- {
- return cnt;
- }
-}
-
-internal class Iter : IEnumerator{
- PersistentArray buckets;
- int b;
- ISeq e;
-
- internal Iter(PersistentArray buckets){
- this.buckets = buckets;
- this.b = -1;
- }
-
- private void nextBucket() {
- e = null;
- for(b = b+1;b<buckets.length();b++)
- {
- IPersistentCollection a = (IPersistentCollection)buckets.nth(b);
- if(a != null && a.seq() != null)
- {
- e = a.seq();
- break;
- }
- }
- }
-
-#region IEnumerator Members
-
-public object Current
- {
- get { return e.first(); }
- }
-
-public bool MoveNext()
- {
- if (e == null || (e = e.rest()) == null)
- nextBucket();
- return e != null;
- }
-
-public void Reset()
- {
- throw new Exception("The method or operation is not implemented.");
- }
-
-#endregion
- }
-
-IPersistentMap entriesFor(Object key){
- return (IPersistentMap) array.nth(bucketFor(key,array));
-}
-
-static int bucketFor(Object key, PersistentArray array) {
- return (RT.hash(key) & 0x7fffffff) % array.length();
-}
-
-virtual internal IPersistentMap create(int capacity) {
- PersistentHashtableMap ret = new PersistentHashtableMap(capacity);
- ret._meta = _meta;
- return ret;
-}
-
-virtual internal IPersistentMap create(int count,PersistentArray array) {
- PersistentHashtableMap ret = new PersistentHashtableMap(count, array);
- ret._meta = _meta;
- return ret;
- }
-
-virtual internal IPersistentMap create(int i, PersistentArray newArray, int growAtCount){
- PersistentHashtableMap ret = new PersistentHashtableMap(i, newArray, growAtCount);
- ret._meta = _meta;
- return ret;
- }
-
-
-virtual internal IPersistentMap createEntryMap(Object key, Object val){
- return new MapEntry(key, val);
-//return PersistentListMap.create(key, val);
-}
-
-}
-
-
-}
\ No newline at end of file diff --git a/src/cli/runtime/PersistentList.cs b/src/cli/runtime/PersistentList.cs deleted file mode 100644 index b29c0908..00000000 --- a/src/cli/runtime/PersistentList.cs +++ /dev/null @@ -1,55 +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.
- **/
-
-using System;
- -namespace clojure.lang
-{ -
-public class PersistentList : ASeq {
-
-private readonly Object _first;
-private readonly PersistentList _rest;
-private readonly int _count;
-
-public PersistentList(Object first) {
- this._first = first;
- this._rest = null;
-
- this._count = 1;
-}
-
-internal PersistentList(Object first, PersistentList rest) {
- this._first = first;
- this._rest = rest;
-
- this._count = 1 + rest.count();
- this._meta = rest._meta;
-}
-
-override public Object first() {
- return _first;
-}
-
-override public ISeq rest() {
- return _rest;
-}
-
-override public int count() {
- return _count;
-}
-
-override public IPersistentCollection cons(Object o) {
- return new PersistentList(o,this);
-}
-
-}
-
-}
diff --git a/src/cli/runtime/PersistentQueue.cs b/src/cli/runtime/PersistentQueue.cs deleted file mode 100644 index 78635448..00000000 --- a/src/cli/runtime/PersistentQueue.cs +++ /dev/null @@ -1,214 +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.
- **/
-
-using System;
-using System.Collections;
-
-namespace clojure.lang
- {
-
-/**
- * conses onto rear, peeks/pops from front
- * See Okasaki's Batched Queues
- * This differs in that it uses a PersistentArrayList as the rear, which is in-order,
- * so no reversing or suspensions required for persistent use
- */
-
-public class PersistentQueue : Obj, IPersistentList {
-
-readonly public static PersistentQueue EMPTY = new PersistentQueue(null,null,null);
-
-readonly ISeq f;
-readonly PersistentArrayList r;
-static readonly int INITIAL_REAR_SIZE = 4;
-int _hash = -1;
-
-
-PersistentQueue(ISeq f, PersistentArrayList r, IPersistentMap meta) {
- this.f = f;
- this.r = r;
- this._meta = meta;
-}
-
-override public bool Equals(Object obj)
- {
- if (!(obj is 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;
- }
-
-override public int GetHashCode()
- {
- 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 IPersistentList pop() {
- if(f == null) //hmmm... pop of empty queue -> empty queue?
- return this;
- //throw new IllegalStateException("popping empty queue");
- ISeq f1 = f.rest();
- PersistentArrayList r1 = r;
- if(f1 == null)
- {
- f1 = RT.seq(r);
- r1 = null;
- }
- return new PersistentQueue(f1, r1,_meta);
-}
-
-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 IPersistentCollection cons(Object o) {
- if(f == null) //empty
- return new PersistentQueue(RT.list(o), null,_meta);
- else
- return new PersistentQueue(f,
- (PersistentArrayList) (r != null ? r : new PersistentArrayList(INITIAL_REAR_SIZE)).cons(o),
- _meta);
-}
-
-public override Obj withMeta(IPersistentMap meta)
- {
- if(_meta == meta)
- return this;
- Obj ret = (Obj)MemberwiseClone();
- ret._meta = meta;
- return ret;
- }
-
-class Seq : ASeq {
- readonly ISeq f;
- readonly ISeq rseq;
-
- internal Seq(ISeq f, ISeq rseq) {
- this.f = f;
- this.rseq = rseq;
- }
-
- public override Object first() {
- return f.first();
- }
-
- public override 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 override int count() {
- return RT.count(f) + RT.count(rseq);
- }
-}
-
-/*
-public static void Main(String[] args) {
- if (args.Length != 1)
- {
- Console.Error.WriteLine("Usage: PersistentQueue n");
- return;
- }
- int n = Int32.Parse(args[0]);
-
-
- Random rand;
-
- rand = new Random(42);
-
- DateTime startTime;
- TimeSpan estimatedTime;
-
- //Queue list = new LinkedList();
- Queue list = Queue.Synchronized(new Queue());
- Console.WriteLine("Queue");
- startTime = DateTime.Now;
- for (int i = 0; i < n; i++)
- {
- list.Enqueue(i);
- list.Enqueue(i);
- list.Dequeue();
- }
- for (int i = 0; i < n - 10; i++)
- {
- list.Dequeue();
- }
- estimatedTime = DateTime.Now - startTime;
- Console.WriteLine("time: " + estimatedTime.Ticks / 10000);
- Console.WriteLine("peek: " + list.Peek());
-
-
- PersistentQueue q = PersistentQueue.EMPTY;
- Console.WriteLine("PersistentQueue");
- startTime = DateTime.Now;
- for (int i = 0; i < n; i++)
- {
- q = (PersistentQueue) q.cons(i);
- q = (PersistentQueue) q.cons(i);
- q = (PersistentQueue) q.pop();
- }
- IPersistentList lastq = null;
- IPersistentList lastq2;
- for (int i = 0; i < n - 10; i++)
- {
- //lastq2 = lastq;
- //lastq = q;
- q = (PersistentQueue) q.pop();
- }
- estimatedTime = DateTime.Now - startTime;
- Console.WriteLine("time: " + estimatedTime.Ticks / 10000);
- Console.WriteLine("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())
-// Console.WriteLine("q: " + s.first());
-// for(ISeq s = q2.seq();s != null;s = s.rest())
-// Console.WriteLine("q2: " + s.first());
-}
-//*/
-
-}
-
- }
diff --git a/src/cli/runtime/PersistentTreeMap.cs b/src/cli/runtime/PersistentTreeMap.cs deleted file mode 100644 index 743cb06d..00000000 --- a/src/cli/runtime/PersistentTreeMap.cs +++ /dev/null @@ -1,869 +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 May 20, 2006 */ - -using System;
-using System.Collections;
-using System.Collections.Specialized;
- -namespace clojure.lang
-{ - -/** - * Persistent Red Black Tree - * Note that instances of this class are constant values - * i.e. add/remove etc return new values - * <p/> - * See Okasaki, Kahrs, Larsen et al - */ - -public class PersistentTreeMap : APersistentMap{ - -public readonly IComparer comp; -public readonly Node tree; -public readonly int _count; - -public PersistentTreeMap():this(null){ -} - -public PersistentTreeMap(IComparer comp){ - this.comp = comp; - tree = null; - _count = 0; -} - -override public int count(){ - return _count; - } - -override public bool contains(Object key){ - return find(key) != null; -}
-
-override public IPersistentMap assocEx(Object key,Object val){ - Box found = new Box(null); - Node t = add(tree, key, val, found); - if(t == null) //null == already contains key - { - throw new Exception("Key already present");
- } - return new PersistentTreeMap(comp, t.blacken(), _count + 1, _meta); -} - -override public Associative assoc(Object key, Object val){ - Box found = new Box(null); - Node t = add(tree, key, val, found); - if(t == null) //null == already contains key - { - Node foundNode = (Node) found.val; - if(foundNode.val() == val) //note only get same collection on identity of val, not equals() - return this;
- return new PersistentTreeMap(comp, replace(tree, key, val), _count, _meta); - }
- return new PersistentTreeMap(comp, t.blacken(), _count + 1, _meta); -} - - -override public IPersistentMap without(Object key){ - Box found = new Box(null); - Node t = remove(tree, key, found); - if(t == null) - { - if(found.val == null)//null == doesn't contain key - return this; - //empty
- PersistentTreeMap ret = new PersistentTreeMap(comp);
- ret._meta = _meta;
- return ret;
- }
- return new PersistentTreeMap(comp, t.blacken(), _count - 1, _meta); -} - -override public ISeq seq() {
- if(_count > 0)
- return Seq.create(tree, true,_count);
- return null;
-} - -public ISeq rseq() {
- if(_count > 0)
- return Seq.create(tree, false,_count);
- return null;
-} - -override public IEnumerator GetEnumerator(){ - return new NodeIEnumerator(tree, true); -} - -public NodeIEnumerator reverseIEnumerator(){ - return new NodeIEnumerator(tree, false); -} - -public IEnumerator keys(){
-return keys((NodeIEnumerator)GetEnumerator()); -} - -public IEnumerator vals(){
-return vals((NodeIEnumerator)GetEnumerator()); -} - -public IEnumerator keys(NodeIEnumerator it){ - return new KeyIEnumerator(it); -} - -public IEnumerator vals(NodeIEnumerator it){ - return new ValIEnumerator(it); -} - -public Object minKey(){ - Node t = min(); - return t!=null?t._key:null; -} - -public Node min(){ - Node t = tree; - if(t != null) - { - while(t.left() != null) - t = t.left(); - } - return t; -} - -public Object maxKey(){ - Node t = max(); - return t!=null?t._key:null; -} - -public Node max(){ - Node t = tree; - if(t != null) - { - while(t.right() != null) - t = t.right(); - } - return t; -} - -public int depth(){ - return depth(tree); -} - -int depth(Node t){ - if(t == null) - return 0; - return 1 + Math.Max(depth(t.left()), depth(t.right())); -} - -override public Object get(Object key){ - Node n = (Node)find(key); - return (n != null) ? n.val() : null; -} - -override public IMapEntry find(Object key){ - Node t = tree; - while(t != null) - { - int c = compare(key, t._key); - if(c == 0) - return t; - else if(c < 0) - t = t.left(); - else - t = t.right(); - } - return t; -} - -int compare(Object k1, Object k2){ - if(comp != null) - return comp.Compare(k1, k2); - return ((IComparable) k1).CompareTo(k2); -} - -Node add(Node t, Object key, Object val, Box found){ - if(t == null) - { - if(val == null) - return new Red(key); - return new RedVal(key, val); - } - int c = compare(key, t._key); - if(c == 0) - { - found.val = t; - return null; - } - Node ins = c < 0 ? add(t.left(), key, val, found) : add(t.right(), key, val, found); - if(ins == null) //found below - return null; - if(c < 0) - return t.addLeft(ins); - return t.addRight(ins); -} - -Node remove(Node t, Object key, Box found){ - if(t == null) - return null; //not found indicator - int c = compare(key, t._key); - if(c == 0) - { - found.val = t; - return append(t.left(), t.right()); - } - Node del = c < 0 ? remove(t.left(), key, found) : remove(t.right(), key, found); - if(del == null && found.val == null) //not found below - return null; - if(c < 0) - { - if(t.left() is Black) - return balanceLeftDel(t._key, t.val(), del, t.right()); - else - return red(t._key, t.val(), del, t.right()); - } - if(t.right() is Black) - return balanceRightDel(t._key, t.val(), t.left(), del); - return red(t._key, t.val(), t.left(), del); -// return t.removeLeft(del); -// return t.removeRight(del); -} - -static Node append(Node left, Node right){ - if(left == null) - return right; - else if(right == null) - return left; - else if(left is Red) - { - if(right is Red) - { - Node app = append(left.right(), right.left()); - if(app is Red) - return red(app._key, app.val(), - red(left._key, left.val(), left.left(), app.left()), - red(right._key, right.val(), app.right(), right.right())); - else - return red(left._key, left.val(), left.left(), red(right._key, right.val(), app, right.right())); - } - else - return red(left._key, left.val(), left.left(), append(left.right(), right)); - } - else if(right is Red) - return red(right._key, right.val(), append(left, right.left()), right.right()); - else //black/black - { - Node app = append(left.right(), right.left()); - if(app is Red) - return red(app._key, app.val(), - black(left._key, left.val(), left.left(), app.left()), - black(right._key, right.val(), app.right(), right.right())); - else - return balanceLeftDel(left._key, left.val(), left.left(), black(right._key, right.val(), app, right.right())); - } -} - -static Node balanceLeftDel(Object key, Object val, Node del, Node right){ - if(del is Red) - return red(key, val, del.blacken(), right); - else if(right is Black) - return rightBalance(key, val, del, right.redden()); - else if(right is Red && right.left() is Black) - return red(right.left()._key, right.left().val(), - black(key, val, del, right.left().left()), - rightBalance(right._key, right.val(), right.left().right(), right.right().redden())); - else - throw new InvalidOperationException("Invariant violation"); -} - -static Node balanceRightDel(Object key, Object val, Node left, Node del){ - if(del is Red) - return red(key, val, left, del.blacken()); - else if(left is Black) - return leftBalance(key, val, left.redden(), del); - else if(left is Red && left.right() is Black) - return red(left.right()._key, left.right().val(), - leftBalance(left._key, left.val(), left.left().redden(), left.right().left()), - black(key, val, left.right().right(), del)); - else - throw new InvalidOperationException("Invariant violation"); -} - -static Node leftBalance(Object key, Object val, Node ins, Node right){ - if(ins is Red && ins.left() is Red) - return red(ins._key, ins.val(), ins.left().blacken(), black(key, val, ins.right(), right)); - else if(ins is Red && ins.right() is Red) - return red(ins.right()._key, ins.right().val(), - black(ins._key, ins.val(), ins.left(), ins.right().left()), - black(key, val, ins.right().right(), right)); - else - return black(key, val, ins, right); -} - - -static Node rightBalance(Object key, Object val, Node left, Node ins){ - if(ins is Red && ins.right() is Red) - return red(ins._key, ins.val(), black(key, val, left, ins.left()), ins.right().blacken()); - else if(ins is Red && ins.left() is Red) - return red(ins.left()._key, ins.left().val(), - black(key, val, left, ins.left().left()), - black(ins._key, ins.val(), ins.left().right(), ins.right())); - else - return black(key, val, left, ins); -} - -Node replace(Node t, Object key, Object val){ - int c = compare(key, t._key); - return t.replace(t._key, - c == 0 ? val : t.val(), - c < 0 ? replace(t.left(), key, val) : t.left(), - c > 0 ? replace(t.right(), key, val) : t.right()); -} - -PersistentTreeMap(IComparer comp, Node tree, int count,IPersistentMap meta){ - this.comp = comp; - this.tree = tree; - this._count = count; - this._meta = meta; -} - -static Red red(Object key, Object val, Node left, Node right){ - if(left == null && right == null) - { - if(val == null) - return new Red(key); - return new RedVal(key, val); - } - if(val == null) - return new RedBranch(key, left, right); - return new RedBranchVal(key, val, left, right); -} - -static Black black(Object key, Object val, Node left, Node right){ - if(left == null && right == null) - { - if(val == null) - return new Black(key); - return new BlackVal(key, val); - } - if(val == null) - return new BlackBranch(key, left, right); - return new BlackBranchVal(key, val, left, right); -} - - -public abstract class Node : IMapEntry{ - internal readonly Object _key; - - internal Node(Object key){ - this._key = key; - } - - public Object key(){ - return _key; - } - - virtual public Object val(){ - return null; - }
-
- internal virtual Node left()
- { - return null; - }
-
- internal virtual Node right()
- { - return null; - } - - internal abstract Node addLeft(Node ins);
-
- internal abstract Node addRight(Node ins);
-
- internal abstract Node removeLeft(Node del);
-
- internal abstract Node removeRight(Node del);
-
- internal abstract Node blacken();
-
- internal abstract Node redden();
-
- internal virtual Node balanceLeft(Node parent)
- { - return black(parent._key, parent.val(), this, parent.right()); - }
-
- internal virtual Node balanceRight(Node parent)
- { - return black(parent._key, parent.val(), parent.left(), this); - }
-
- internal abstract Node replace(Object key, Object val, Node left, Node right); -} - -class Black : Node{ - public Black(Object key):base(key){ - } - - internal override Node addLeft(Node ins){ - return ins.balanceLeft(this); - }
-
- internal override Node addRight(Node ins)
- { - return ins.balanceRight(this); - }
-
- internal override Node removeLeft(Node del)
- { - return balanceLeftDel(_key, val(), del, right()); - }
-
- internal override Node removeRight(Node del)
- { - return balanceRightDel(_key, val(), left(), del); - }
-
- internal override Node blacken()
- { - return this; - }
-
- internal override Node redden()
- { - return new Red(_key); - }
-
- internal override Node replace(Object key, Object val, Node left, Node right)
- { - return black(key, val, left, right); - } -} - -class BlackVal : Black{ - readonly Object _val; - - public BlackVal(Object key, Object val):base(key){ - this._val = val; - } - - override public Object val(){ - return _val; - }
-
- internal override Node redden()
- { - return new RedVal(_key, _val); - } - -} - -class BlackBranch : Black{ - internal readonly Node _left; - internal readonly Node _right; - - public BlackBranch(Object key, Node left, Node right):base(key){ - this._left = left; - this._right = right; - }
-
- internal override Node left()
- { - return _left; - }
-
- internal override Node right()
- { - return _right; - }
-
- internal override Node redden()
- { - return new RedBranch(_key, _left, _right); - } - -} - -class BlackBranchVal : BlackBranch{ - readonly Object _val; - - public BlackBranchVal(Object key, Object val, Node left, Node right): base(key, left, right){ - this._val = val; - } - - override public Object val(){ - return _val; - }
-
- internal override Node redden()
- { - return new RedBranchVal(_key, _val, _left, _right); - } - -} - -class Red : Node{ - public Red(Object key):base(key){ - }
-
- internal override Node addLeft(Node ins)
- { - return red(_key, val(), ins, right()); - }
-
- internal override Node addRight(Node ins)
- { - return red(_key, val(), left(), ins); - }
-
- internal override Node removeLeft(Node del)
- { - return red(_key, val(), del, right()); - }
-
- internal override Node removeRight(Node del)
- { - return red(_key, val(), left(), del); - }
-
- internal override Node blacken()
- { - return new Black(_key); - }
-
- internal override Node redden()
- { - throw new InvalidOperationException("Invariant violation"); - }
-
- internal override Node replace(Object key, Object val, Node left, Node right)
- { - return red(key, val, left, right); - } -} - -class RedVal : Red{ - readonly Object _val; - - public RedVal(Object key, Object val):base(key){ - this._val = val; - } - - override public Object val(){ - return _val; - }
-
- internal override Node blacken()
- { - return new BlackVal(_key, _val); - } -} - -class RedBranch : Red{ - internal readonly Node _left; - internal readonly Node _right; - - public RedBranch(Object key, Node left, Node right):base(key){ - this._left = left; - this._right = right; - }
-
- internal override Node left()
- { - return _left; - }
-
- internal override Node right()
- { - return _right; - }
-
- internal override Node balanceLeft(Node parent)
- { - if(_left is Red) - return red(_key, val(), _left.blacken(), black(parent._key, parent.val(), _right, parent.right())); - else if(_right is Red) - return red(_right._key, _right.val(), black(_key, val(), _left, _right.left()), - black(parent._key, parent.val(), _right.right(), parent.right())); - else - return base.balanceLeft(parent); - - }
-
- internal override Node balanceRight(Node parent)
- { - if(_right is Red) - return red(_key, val(), black(parent._key, parent.val(), parent.left(), _left), _right.blacken()); - else if(_left is Red) - return red(_left._key, _left.val(), black(parent._key, parent.val(), parent.left(), _left.left()), - black(_key, val(), _left.right(), _right)); - else - return base.balanceRight(parent); - }
-
- internal override Node blacken()
- { - return new BlackBranch(_key, _left, _right); - } -} - -class RedBranchVal : RedBranch{ - readonly Object _val; - - public RedBranchVal(Object key, Object val, Node left, Node right):base(key, left, right){ - - this._val = val; - } - - override public Object val(){ - return _val; - }
-
- internal override Node blacken()
- { - return new BlackBranchVal(_key, _val, _left, _right); - } -} - -public class Seq : ASeq{
- readonly ISeq stack;
- readonly bool asc;
- readonly int cnt;
-
- Seq(ISeq stack, bool asc, int cnt) {
- this.stack = stack;
- this.asc = asc;
- this.cnt = cnt;
- }
-
- internal static Seq create(Node t, bool asc,int cnt){
- return new Seq(push(t, null, asc),asc,cnt);
- }
-
- static ISeq push(Node t, ISeq stack, bool asc){
- while(t != null)
- {
- stack = RT.cons(t,stack);
- t = asc ? t.left() : t.right();
- }
- return stack;
- }
-
- override public Object first() {
- return stack.first();
- }
-
- override public ISeq rest() {
- Node t = (Node)stack.first();
- ISeq nextstack = push(asc ? t.right() : t.left(), stack.rest(), asc);
- if(nextstack != null)
- {
- return new Seq(nextstack,asc,cnt-1);
- }
- return null;
- }
-
- public override int count()
- {
- return cnt;
- }
-}
- - -public class NodeIEnumerator : IEnumerator{ - Stack stack = new Stack(); - bool asc;
- object curr; - - internal NodeIEnumerator(Node t, bool asc){ - this.asc = asc; - push(t); - } - - void push(Node t){ - while(t != null) - { - stack.Push(t); - t = asc ? t.left() : t.right(); - } - } - - bool hasNext(){ - return !(stack.Count == 0); - } - - Object next(){ - Node t = (Node) stack.Pop(); - push(asc ? t.right() : t.left()); - return t; - } - - public void remove(){ - throw new InvalidOperationException(); - }
-
-#region IEnumerator Members
-
-public object Current
- {
- get { return curr; }
- }
-
-public bool MoveNext()
- {
- if (hasNext())
- {
- curr = next();
- return true;
- }
- return false;
- }
-
-public void Reset()
- {
- throw new Exception("The method or operation is not implemented.");
- }
-
-#endregion
- } - -class KeyIEnumerator : IEnumerator{ - NodeIEnumerator it; - - internal KeyIEnumerator(NodeIEnumerator it){ - this.it = it; - } -
-#region IEnumerator Members
-
-public object Current
-{
-get { return ((Node)it.Current)._key; }
-}
-
-public bool MoveNext()
-{
-return it.MoveNext();
-}
-
-public void Reset()
-{
- throw new Exception("The method or operation is not implemented.");
-}
-
-#endregion
-} - -class ValIEnumerator : IEnumerator{ - NodeIEnumerator it; - - internal ValIEnumerator(NodeIEnumerator it){ - this.it = it; - }
-
-#region IEnumerator Members
-
-public object Current
- {
- get { return ((Node)it.Current).val(); }
- }
-
-public bool MoveNext()
- {
- return it.MoveNext();
- }
-
-public void Reset()
- {
- throw new Exception("The method or operation is not implemented.");
- }
-
-#endregion
- } - - //*
- [STAThread] -static public void Main(String[] args){ - if(args.Length != 1)
- Console.Error.WriteLine("Usage: PersistentTree n"); - int n = Int32.Parse(args[0]); - Object[] ints = new Object[n]; - for(int i = 0; i < ints.Length; i++) - { - ints[i] = i; - } - //Collections.shuffle(Arrays.asList(ints));
- Array.Reverse(ints); - Console.WriteLine("Building set");
- //IPersistentMap set = new PersistentTree();
- //IPersistentMap set = new PersistentArrayMap();
- //IPersistentMap set = new PersistentListMap();
- IPersistentMap set = new PersistentHashtableMap(1001);
- //IPersistentMap set = new PersistentHybridMap(1001); - //for(int i = 0; i < ints.Length; i++) - // { - // Object anInt = ints[i]; - // set = set.add(anInt); - // }
- DateTime start = DateTime.Now;
- for (int i = 0; i < ints.Length; i++) - { - Object anInt = ints[i]; - set = (IPersistentMap) set.assoc(anInt, anInt); - }
-
- foreach(IMapEntry e in set) - { - if(!set.contains(e.key())) - Console.Error.WriteLine("Can't find: " + e.key()); - //else if(n < 2000) - // Console.Write(e.key().ToString() + ","); - } - - for(int i = 0; i < ints.Length/2; i++) - { - Object anInt = ints[i]; - set = set.without(anInt); - }
-
- Console.WriteLine("Time: " + (DateTime.Now - start));
- Console.Error.WriteLine("count = " + set.count());
-
- Console.WriteLine("Building Hashtable");
- Hashtable od = Hashtable.Synchronized(new Hashtable(1001));
- start = DateTime.Now;
- for (int i = 0; i < ints.Length; i++)
- {
- Object anInt = ints[i];
- od.Add(anInt, anInt);
- }
-
- foreach (DictionaryEntry e in od)
- {
- if (!od.Contains(e.Key))
- Console.Error.WriteLine("Can't find: " + e.Key);
- //else if (n < 2000)
- // Console.Write(e.key().ToString() + ",");
- }
-
- for (int i = 0; i < ints.Length / 2; i++)
- {
- Object anInt = ints[i];
- od.Remove(anInt);
- }
-
- Console.WriteLine("Time: " + (DateTime.Now - start));
- Console.Error.WriteLine("count = " + od.Count);
- -} - //*/ -} - } diff --git a/src/cli/runtime/RT.cs b/src/cli/runtime/RT.cs deleted file mode 100644 index 75659413..00000000 --- a/src/cli/runtime/RT.cs +++ /dev/null @@ -1,682 +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 Mar 25, 2006 4:28:27 PM */
-
-using System;
-using System.Collections;
-using System.IO;
-using System.Threading;
-
-namespace clojure.lang
-{
-
-public class RT
-{
-
- public static Symbol T = Symbol.intern(":t");
- static public Var OUT = Module.intern("clojure", "^out");
- static public Var _CT_MODULE = Module.intern("clojure", "^module");
- public static Object[] EMPTY_ARRAY = new Object[0];
-
-
- static public readonly Object[] chars;
-
- static int id = 1;
- static public int nextID()
- {
- return Interlocked.Increment(ref id);
- }
-
- static RT(){
- chars = new Object[256];
- for(int i=0;i<chars.Length;i++)
- chars[i] = (char)i;
- OUT.bind(Console.Out);
- _CT_MODULE.bind((Module.findOrCreate("clj-user")));
- }
-
-static public bool equal(Object k1,Object k2){
- return k1 == k2 ||
- (k1 != null && k1.Equals(k2));
-}
- static public Object eq(Object arg1, Object arg2) {
- return (arg1 == arg2)?T:null;
- }
-
- static public Object eql(Object arg1, Object arg2) {
- if(arg1 == arg2)
- return T;
- if(arg1 == null || arg2 == null)
- return null;
- if(arg1 is Num
- && arg1.GetType() == arg2.GetType()
- && arg1.Equals(arg2))
- return T;
- if(arg1 is Char
- && arg2 is Char
- && arg1.Equals(arg2))
- return T;
- return null;
- }
-
- //static public Object equal(Object arg1, Object arg2) {
- // if(arg1 == null)
- // return arg2 == null ? T : null;
- // else if(arg2 == null)
- // return null;
- // return (eql(arg1,arg2) != null
- // || (arg1 is Cons
- // && arg2 is Cons
- // && equal(((Cons)arg1).first(),((Cons)arg2).first())!=null
- // && equal(((Cons)arg1).rest(),((Cons)arg2).rest())!=null))
- // ?T:null;
- // }
-
-static public int hash(Object o){
- if(o == null)
- return 0;
- return o.GetHashCode();
-}
-
-static public int hashCombine(int seed, int hash){
- //a la boost
- seed ^= (int)(hash + 0x9e3779b9 + (seed << 6) + (seed >> 2));
- return seed;
-}
-
-static public ISeq seq(Object coll) {
- if(coll == null)
- return null;
- else if(coll is IPersistentCollection)
- return ((IPersistentCollection) coll).seq();
- else if (coll is IEnumerable)
- return EnumeratorSeq.create(((IEnumerable)coll).GetEnumerator());
- else if(coll is Object[])
- return ArraySeq.create((Object[]) coll);
- else
- throw new ArgumentException("Don't know how to create ISeq from arg");
-}
-
-static public ISeq keys(Object coll)
- {
- return APersistentMap.KeySeq.create(seq(coll));
- }
-
-static public ISeq vals(Object coll)
- {
- return APersistentMap.ValSeq.create(seq(coll));
- }
-
-static public Object meta(Object x)
- {
- if (x == null)
- return null;
- return ((Obj)x).meta();
- }
-
-public static int count(Object o)
- {
- if (o == null)
- return 0;
- return ((IPersistentCollection)o).count();
- }
-
-static public IPersistentCollection cons(Object x, IPersistentCollection y)
- {
- if (y == null)
- return new PersistentList(x);
- return y.cons(x);
- }
-
-static public ISeq cons(Object x, ISeq y)
- {
- if (y == null)
- return new PersistentList(x);
- return (ISeq)y.cons(x);
- }
-
-static public Object first(Object x)
- {
- if (x == null)
- return null;
- return seq(x).first();
- }
-
-static public Object second(Object x)
- {
- return first(rest(x));
- }
-
-static public Object third(Object x)
- {
- return first(rest(rest(x)));
- }
-
-static public Object fourth(Object x) {
- return first(rest(rest(rest(x))));
-}
-
-static public ISeq rest(Object x)
- {
- if (x == null)
- return null;
- return seq(x).rest();
- }
-
-static public ISeq rrest(Object x) {
- return rest(rest(x));
-}
-
-static public Object peek(Object x)
- {
- if (x == null)
- return null;
- return ((IPersistentList)x).peek();
- }
-
-static public Object pop(Object x)
- {
- if (x == null)
- return null;
- return ((IPersistentList)x).pop();
- }
-
-static public Object get(Object key, Object coll)
- {
- if (coll == null)
- return null;
- return ((Associative)coll).get(key);
- }
-
-static public Object assoc(Object key, Object val, Object coll)
- {
- if (coll == null)
- return new MapEntry(key, val);
- return ((Associative)coll).assoc(key, val);
- }
-
-static public Object contains(Object key, Object coll)
- {
- if (coll == null)
- return false;
- return ((Associative)coll).contains(key);
- }
-
-static public Object find(Object key, Object coll)
- {
- if (coll == null)
- return null;
- return ((Associative)coll).find(key);
- }
-
- //takes a seq of key,val,key,val
-//returns tail starting at val of matching key if found, else null
-static public ISeq findKey(Keyword key,ISeq keyvals) {
- while(keyvals != null)
- {
- ISeq r = keyvals.rest();
- if (r == null)
- throw new Exception("Malformed keyword argslist");
- if (keyvals.first() == key)
- return r;
- keyvals = r.rest();
- }
- return null;
-}
-
-static public Object without(Object key, Object coll)
- {
- if (coll == null)
- return null;
- return ((IPersistentMap)coll).without(key);
- }
-
-static public Object nth(int n, Object coll) {
- if(coll == null)
- return null;
- else if(coll is IPersistentArray)
- return ((IPersistentArray)coll).nth(n);
- else if(coll is Object[])
- return ((Object[])coll)[n];
- else if(coll is Sequential)
- {
- ISeq seq = ((IPersistentCollection) coll).seq();
- for(int i=0;i<=n && seq != null;++i, seq = seq.rest())
- {
- if(i == n)
- return seq.first();
- }
- return null;
- }
- else
- return null;
-}
-
-static public Object assocN(int n, Object val, Object coll) {
- if(coll == null)
- return null;
- else if(coll is IPersistentArray)
- return ((IPersistentArray)coll).assocN(n,val);
- else if(coll is Object[])
- {
- //hmm... this is not persistent
- Object[] array = ((Object[])coll);
- array[n] = val;
- return array;
- }
- else
- return null;
-}
-
- static public Iter iter(Object coll)
- {
- if (coll == null || coll is Iter)
- return (Iter)coll;
- else if (coll is IEnumerable)
- {
- IEnumerator e = ((IEnumerable)coll).GetEnumerator();
- if (e.MoveNext())
- return new EnumeratorIter(e);
- return null;
- }
- else
- {
- throw new ArgumentException("Don't know how to create Iter from arg");
- }
-
- }
-
- static public Object box(Object x)
- {
- return x;
- }
-
- static public Object box(char x)
- {
- if (x < chars.Length)
- return chars[x];
- return x;
- }
-
- static public Object box(bool x)
- {
- return x ? T : null;
- }
-
- static public Num box(byte x)
- {
- return Num.from(x);
- }
-
- static public Num box(short x)
- {
- return Num.from(x);
- }
-
- static public Num box(int x)
- {
- return Num.from(x);
- }
-
- static public Num box(long x)
- {
- return Num.from(x);
- }
-
- static public Num box(float x)
- {
- return Num.from(x);
- }
-
- static public Num box(double x)
- {
- return Num.from(x);
- }
-
- static public char charCast(Object x)
{
return Convert.ToChar(x);
}
-
- static public bool booleanCast(Object x)
{
if(x is Boolean)
- return (bool)x; ;
return x != null;
}
-
- static public byte byteCast(Object x)
- {
- return Convert.ToByte(x);
- }
-
- static public short shortCast(Object x)
- {
- return Convert.ToInt16(x);
}
-
- static public int intCast(Object x)
- {
- return Convert.ToInt32(x);
- }
-
- static public long longCast(Object x)
- {
- return Convert.ToInt64(x);
- }
-
- static public float floatCast(Object x)
- {
- return Convert.ToSingle(x);
- }
-
- static public double doubleCast(Object x)
- {
- return Convert.ToDouble(x);
- }
-
-static public ISeq list()
- {
- return null;
- }
-
-static public ISeq list(Object arg1)
- {
- return new PersistentList(arg1);
- }
-
-static public ISeq list(Object arg1, Object arg2)
- {
- return listStar(arg1, arg2, null);
- }
-
-static public ISeq list(Object arg1, Object arg2, Object arg3)
- {
- return listStar(arg1, arg2, arg3, null);
- }
-
-static public ISeq list(Object arg1, Object arg2, Object arg3, Object arg4)
- {
- return listStar(arg1, arg2, arg3, arg4, null);
- }
-
-static public ISeq list(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5)
- {
- return listStar(arg1, arg2, arg3, arg4, arg5, null);
- }
-
-static public ISeq listStar(Object arg1, ISeq rest)
- {
- return cons(arg1, rest);
- }
-
-static public ISeq listStar(Object arg1, Object arg2, ISeq rest)
- {
- return cons(arg1, cons(arg2, rest));
- }
-
-static public ISeq listStar(Object arg1, Object arg2, Object arg3, ISeq rest)
- {
- return cons(arg1, cons(arg2, cons(arg3, rest)));
- }
-
-static public ISeq listStar(Object arg1, Object arg2, Object arg3, Object arg4, ISeq rest)
- {
- return cons(arg1, cons(arg2, cons(arg3, cons(arg4, rest))));
- }
-
-static public ISeq listStar(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, ISeq rest)
- {
- return cons(arg1, cons(arg2, cons(arg3, cons(arg4, cons(arg5, rest)))));
- }
-
-static public ISeq arrayToList(Object[] a)
- {
- ISeq ret = null;
- for (int i = a.Length - 1; i >= 0; --i)
- ret = cons(a[i], ret);
- return ret;
- }
-
-static public Object[] seqToArray(ISeq seq) {
- int len = length(seq);
- Object[] ret = new Object[len];
- for(int i=0;seq != null;++i, seq = seq.rest())
- ret[i] = seq.first();
- return ret;
-}
-
-static public int length(ISeq list)
- {
- int i = 0;
- for(ISeq c = list; c != null; c = c.rest())
- {
- i++;
- }
- return i;
- }
-
-static public int boundedLength(ISeq list, int limit)
- {
- int i = 0;
- for(ISeq c = list; c != null && i <= limit; c = c.rest())
- {
- i++;
- }
- return i;
- }
-
-
-///////////////////////////////// reader support ////////////////////////////////
-
-static Object readRet(int ret){
- if(ret == -1)
- return null;
- return box((char) ret);
-}
-
-static public Object readChar(TextReader r) {
- int ret = r.Read();
- return readRet(ret);
-}
-
-static public Object peekChar(TextReader r) {
- return readRet(r.Peek());
-}
-
-static public int getLineNumber(TextReader r)
- {
- if (r is LineNumberingTextReader)
- return ((LineNumberingTextReader)r).getLineNumber();
- return 0;
- }
-
-static public TextReader getLineNumberingReader(TextReader r)
- {
- if (isLineNumberingReader(r))
- return r;
- return new LineNumberingTextReader(r);
- }
-
-static public bool isLineNumberingReader(TextReader r)
- {
- return r is LineNumberingTextReader;
- }
-
-
-static public String resolveClassNameInContext(String className) {
- //todo - look up in context var
- return className;
-}
-
-static public bool suppressRead(){
- //todo - look up in suppress-read var
- return false;
-}
-
-static public void print(Object x, TextWriter w) {
- //todo - make extensible
- if(x == null)
- w.Write("null");
- else if(x is ISeq)
- {
- w.Write('(');
- for(ISeq s = (ISeq)x;s != null;s = s.rest())
- {
- print(s.first(), w);
- if(s.rest()!=null)
- w.Write(' ');
- }
- w.Write(')');
- }
- else if(x is String)
- {
- w.Write('"');
- w.Write(x.ToString());
- w.Write('"');
- }
- else if(x is Char)
- {
- w.Write('\\');
- char c = (char)x;
- switch(c){
- case '\n':
- w.Write("newline");
- break;
- case '\t':
- w.Write("tab");
- break;
- case ' ':
- w.Write("space");
- break;
- default:
- w.Write(c);
- break;
- }
- }
- else w.Write(x.ToString());
-}
-
-static public void formatAesthetic(TextWriter w, Object obj) {
- if(obj == null)
- w.Write("null");
- else
- w.Write(obj.ToString());
-}
-
-static public void formatStandard(TextWriter w,Object obj) {
- if(obj == null)
- w.Write("null");
- else if(obj is String)
- {
- w.Write('"');
- w.Write((String)obj);
- w.Write('"');
- }
- else if(obj is Char)
- {
- w.Write('\\');
- char c = (Char)obj;
- switch(c){
- case '\n':
- w.Write("newline");
- break;
- case '\t':
- w.Write("tab");
- break;
- case ' ':
- w.Write("space");
- break;
- default:
- w.Write(c);
- break;
- }
- }
- else
- w.Write(obj.ToString());
-}
-
-static public Object format(Object o, String s, params Object[] args) {
- TextWriter w;
- if(o == null)
- w = new StringWriter();
- else if(equal(o,T))
- w = (TextWriter)OUT.getValue();
- else
- w = (TextWriter)o;
- doFormat(w,s,ArraySeq.create(args));
- if(o == null)
- return w.ToString();
- return null;
-}
-
-static public ISeq doFormat(TextWriter w, String s, ISeq args) {
- for (int i = 0; i < s.Length;)
- {
- char c = s[i++];
- switch (Char.ToLower(c))
- {
- case '~':
- char d = s[i++];
- switch (Char.ToLower(d))
- {
- case '%':
- w.Write('\n');
- break;
- case 't':
- w.Write('\t');
- break;
- case 'a':
- if(args == null)
- throw new Exception("Missing argument");
- RT.formatAesthetic(w, RT.first(args));
- args = RT.rest(args);
- break;
- case 's':
- if(args == null)
- throw new Exception("Missing argument");
- RT.formatStandard(w, RT.first(args));
- args = RT.rest(args);
- break;
- case '{':
- int j = s.IndexOf("~}", i); //note - does not nest
- if(j == -1)
- throw new Exception("Missing ~}");
- String subs = s.Substring(i, j-i);
- for (ISeq sargs = RT.seq(RT.first(args)); sargs != null; )
- sargs = doFormat(w, subs, sargs);
- args = RT.rest(args);
- i = j+2; //skip ~}
- break;
- case '^':
- if(args == null)
- return null;
- break;
- case '~':
- w.Write('~');
- break;
- default:
- throw new Exception("Unsupported ~ directive: " + d);
- break;
- }
- break;
- default:
- w.Write(c);
- break;
- }
- }
- return args;
-}
-
-/*-------------------------------- values --------------*/
-
-static public Object setValues(params Object[] vals)
- {
- ThreadLocalData.setValues(vals);
- if(vals.Length > 0)
- return vals[0];
- return null;
- }
-
-}
-}
\ No newline at end of file diff --git a/src/cli/runtime/RatioNum.cs b/src/cli/runtime/RatioNum.cs deleted file mode 100644 index 7838b84c..00000000 --- a/src/cli/runtime/RatioNum.cs +++ /dev/null @@ -1,229 +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 Mar 28, 2006 10:14:44 AM */ - -using System;
-using java.math;
- -namespace clojure.lang
-{ - -public class RatioNum : RationalNum{ -override public Boolean Equals(Object arg0) - { - return arg0 != null - && arg0 is RatioNum - && ((RatioNum) arg0).numerator.Equals(numerator) - && ((RatioNum) arg0).denominator.Equals(denominator); - } - -override public int GetHashCode() - { - return numerator.GetHashCode() ^ denominator.GetHashCode(); - } - -override public String ToString() - { - return numerator.ToString() + "/" + denominator.ToString(); - } - -public IntegerNum numerator; -public IntegerNum denominator; - -public RatioNum(IntegerNum n, IntegerNum d) - { - this.numerator = n; - this.denominator = d; - } - -override public double doubleValue() - { - return numerator.doubleValue() / denominator.doubleValue(); - } - -override public float floatValue() - { - return (float) doubleValue(); - } - -override public int intValue() - { - return (int) doubleValue(); - } - -override public long longValue() - { - return (long) doubleValue(); - } - -override public Boolean equiv(Num rhs) - { - return rhs.equivTo(this); - } - -override public Boolean equivTo(BigInteger x) - { - return false; - } - -override public Boolean equivTo(int x) - { - return false; - } - -override public Boolean equivTo(RatioNum x) - { - return numerator.equiv(x.numerator) && denominator.equiv(x.denominator); - } - -override public Boolean lt(Num rhs) - { - return rhs.gt(this); - } - -override public Boolean gt(BigInteger x) - { - return denominator.multiply(x).lt(numerator); - } - -override public Boolean gt(int x) - { - return denominator.multiply(x).lt(numerator); - } - -override public Boolean gt(RatioNum x) - { - return x.numerator.multiplyBy(denominator).lt(numerator.multiplyBy(x.denominator)); - } - -override public Num add(Num rhs) - { - return rhs.addTo(this); - } - -override public Num addTo(BigInteger x) - { - return Num.divide(numerator.add(denominator.multiply(x)), denominator); - } - -override public Num addTo(int x) - { - return Num.divide(numerator.add(denominator.multiply(x)), denominator); - } - -override public Num addTo(RatioNum x) - { - return Num.divide(numerator.multiplyBy(x.denominator) - .add(x.numerator.multiplyBy(denominator)) - , denominator.multiplyBy(x.denominator)); - } - -override public Num subtractFrom(Num x) - { - return x.add(this.multiply(-1)); - } - -override public Num multiplyBy(Num rhs) - { - return rhs.multiply(this); - } - -override public Num multiply(BigInteger x) - { - return Num.divide(numerator.multiply(x), denominator); - } - -override public Num multiply(int x) - { - return Num.divide(numerator.multiply(x), denominator); - } - -override public Num multiply(RatioNum x) - { - return Num.divide(numerator.multiplyBy(x.numerator) - , denominator.multiplyBy(x.denominator)); - } - -override public Num divideBy(Num rhs) - { - return rhs.divide(this); - } - -override public Num divide(BigInteger n) - { - return Num.divide(denominator.multiply(n), numerator); - } - -override public Num divide(int n) - { - return Num.divide(denominator.multiply(n), numerator); - } - -override public Num divide(RatioNum n) - { - return Num.divide(denominator.multiplyBy(n.numerator) - , numerator.multiplyBy(n.denominator)); - } - - -override public Object truncateDivide( Num num) - { - return num.truncateBy( this); - } - -override public Object truncateBy( int div) - { - Num q = (Num) Num.truncate( numerator, denominator.multiply(div)); - return RT.setValues( q, q.multiply(div).subtractFrom(this)); - } - -override public Object truncateBy( BigInteger div) - { - Num q = (Num) Num.truncate( numerator, denominator.multiply(div)); - return RT.setValues( q, q.multiply(div).subtractFrom(this)); - } - -override public Object truncateBy( RatioNum div) - { - Num q = (Num) Num.truncate( numerator.multiplyBy(div.denominator), - denominator.multiplyBy(div.numerator)); - return RT.setValues( q, q.multiplyBy(div).subtractFrom(this)); - } - - -override public Num negate() - { - return Num.divide(numerator.negate(), denominator); - } - -override public Boolean minusp() - { - return numerator.minusp(); - } - -override public Boolean plusp() - { - return numerator.plusp(); - } - -override public Num oneMinus() - { - return addTo(-1); - } - -override public Num onePlus() - { - return addTo(1); - } - -} -} - diff --git a/src/cli/runtime/RationalNum.cs b/src/cli/runtime/RationalNum.cs deleted file mode 100644 index fb5398d1..00000000 --- a/src/cli/runtime/RationalNum.cs +++ /dev/null @@ -1,21 +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 Mar 28, 2006 10:12:30 AM */ - -using System;
- -namespace clojure.lang
-{ - -public abstract class RationalNum : RealNum { - -} -} diff --git a/src/cli/runtime/RealNum.cs b/src/cli/runtime/RealNum.cs deleted file mode 100644 index d29a404b..00000000 --- a/src/cli/runtime/RealNum.cs +++ /dev/null @@ -1,21 +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 Mar 28, 2006 10:13:00 AM */ - -using System;
- -namespace clojure.lang
-{ - -public abstract class RealNum : Num { - -} -}
\ No newline at end of file diff --git a/src/cli/runtime/Reflector.cs b/src/cli/runtime/Reflector.cs deleted file mode 100644 index 483c4029..00000000 --- a/src/cli/runtime/Reflector.cs +++ /dev/null @@ -1,168 +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.
- **/
-
-using System;
-using System.Reflection;
-using System.Collections;
-
-namespace clojure.lang
-{
-public class Reflector{
-
-public static Object invokeInstanceMethod(String name, Object target, Object[] args) //throws Exception
{
Type t = target.GetType();
IList methods = getMethods(t, args.Length, name,false);
- return invokeMatchingMethod(name, target, args, t, methods,false);
- }
-
- private static object invokeMatchingMethod(String name, Object target, Object[] args, Type t, IList methods, bool statics)
- {
- if (methods.Count == 0)
- {
- throw new InvalidOperationException("No matching field or method found");
- }
- else if (methods.Count == 1)
- {
- MethodInfo m = (MethodInfo)methods[0];
- return prepRet(m.Invoke(target, boxArgs(m.GetParameters(), args)));
- }
- else //overloaded w/same arity, let reflection choose most specific match
- {
- return prepRet(t.InvokeMember(name, BindingFlags.Public | (statics ? BindingFlags.Static : BindingFlags.Instance)
- | BindingFlags.FlattenHierarchy | BindingFlags.InvokeMethod,
- null, target, args));
- }
- }
-
-public static Object invokeConstructor(Type t, Object[] args) //throws Exception
- {
- ConstructorInfo[] allctors = t.GetConstructors();
- ArrayList ctors = new ArrayList();
- foreach (ConstructorInfo ctor in allctors)
- {
- if (ctor.GetParameters().Length == args.Length)
- ctors.Add(ctor);
- }
- if (ctors.Count == 0)
- {
- throw new InvalidOperationException("No matching ctor found");
- }
- else if (ctors.Count == 1)
- {
- ConstructorInfo ctor = (ConstructorInfo)ctors[0];
- return ctor.Invoke(boxArgs(ctor.GetParameters(), args));
- }
- else //overloaded w/same arity, let reflection choose most specific match
- {
- return t.InvokeMember(null, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance,
- null, null, args);
- }
- }
-public static Object invokeStaticMethod(String name, String className, params Object[] args) //throws Exception
- {
- Type t = Type.GetType(className);
- if (name.Equals("new"))
- return invokeConstructor(t, args);
- IList methods = getMethods(t, args.Length, name, true);
- return invokeMatchingMethod(name, null, args, t, methods,true);
- }
-
-public static Object getStaticField(String name, String className) //throws Exception
- {
- //check for field first
- Type t = Type.GetType(className);
- FieldInfo f = getField(t, name, true);
- if (f != null) //field get
- {
- return prepRet(f.GetValue(null));
- }
- PropertyInfo p = getProperty(t, name, true);
- if (p != null)
- {
- return prepRet(p.GetValue(null, null));
- }
- throw new InvalidOperationException("No matching field or property found");
- }
-
-public static Object setStaticField(String name, String className, Object arg1) //throws Exception
- {
- //check for field first
- Type t = Type.GetType(className);
- FieldInfo f = getField(t, name, true);
- if (f != null) //field get
- {
- f.SetValue(null, boxArg(f.FieldType, arg1));
- return arg1;
- }
- PropertyInfo p = getProperty(t, name, true);
- if (p != null)
- {
- p.SetValue(null, boxArg(p.PropertyType, arg1), null);
- return arg1;
- }
- throw new InvalidOperationException("No matching field or property found");
- }
-
-public static Object invokeInstanceMember(String name, Object target) //throws Exception
{
//check for field first
Type t = target.GetType();
FieldInfo f = getField(t, name,false);
if(f != null) //field get
{
return prepRet(f.GetValue(target));
}
- PropertyInfo p = getProperty(t, name,false);
- if (p != null)
- {
- return prepRet(p.GetValue(target, null));
- }
return invokeInstanceMethod(name, target, RT.EMPTY_ARRAY);
}
public static Object invokeInstanceMember(String name, Object target, Object arg1) //throws Exception
{
//check for field first
Type t = target.GetType();
FieldInfo f = getField(t, name,false);
- if (f != null) //field get
- {
- f.SetValue(target,boxArg(f.FieldType,arg1));
- return arg1;
- }
- PropertyInfo p = getProperty(t, name,false);
- if (p != null)
- {
- //could be indexed property, which we otherwise aren't dealing with yet
- if(p.GetIndexParameters() != null && p.GetIndexParameters().Length == 1)
- return prepRet(p.GetValue(target, new Object[]{boxArg(p.GetIndexParameters()[0].ParameterType,arg1)}));
- p.SetValue(target,boxArg(p.PropertyType,arg1),null);
- return arg1;
- }
return invokeInstanceMethod(name, target, new Object[]{arg1});
}
public static Object invokeInstanceMember(String name, Object target, params Object[] args) //throws Exception
{
return invokeInstanceMethod(name, target, args);
}
-
- public static FieldInfo getField(Type t, string name,bool statics)
- {
- return t.GetField(name, BindingFlags.Public | (statics ? BindingFlags.Static : BindingFlags.Instance) | BindingFlags.FlattenHierarchy);
- }
- public static PropertyInfo getProperty(Type t, string name, bool statics)
- {
- return t.GetProperty(name, BindingFlags.Public | (statics ? BindingFlags.Static : BindingFlags.Instance) | BindingFlags.FlattenHierarchy);
- }
-
- static public IList getMethods(Type t, int arity, String name, bool getStatics)
- {
- MethodInfo[] allmethods = t.GetMethods(BindingFlags.Public | (getStatics?BindingFlags.Static : BindingFlags.Instance)
- | BindingFlags.FlattenHierarchy);
- ArrayList methods = new ArrayList();
- for (int i = 0; i < allmethods.Length; i++)
- {
- if (name.Equals(allmethods[i].Name)
- && allmethods[i].GetParameters().Length == arity)
- {
- methods.Add(allmethods[i]);
- }
- }
- return methods;
- }
-
-static Object boxArg(Type paramType, Object arg)
{
Type argType = arg.GetType();
if(paramType == argType)
return arg;
if(paramType == typeof(bool))
{
return arg != null;
}
else if(paramType.IsPrimitive && arg is Num)
{
Num n = (Num) arg;
if(paramType == typeof(int))
return n.intValue();
else if(paramType == typeof(float))
return n.floatValue();
else if(paramType == typeof(double))
return n.doubleValue();
else if(paramType == typeof(long))
return n.longValue();
else if(paramType == typeof(char))
return (char) n.intValue();
else if(paramType == typeof(short))
return n.shortValue();
else if(paramType == typeof(byte))
return n.byteValue();
else
throw new ArgumentException("Cannot convert to primitive type: " + paramType.Name);
}
else
return arg;
}
static Object[] boxArgs(ParameterInfo[] parms, Object[] args)
{
if(parms.Length == 0)
return null;
Object[] ret = new Object[parms.Length];
for(int i = 0; i < parms.Length; i++)
{
Object arg = args[i];
Type paramType = parms[i].ParameterType;
ret[i] = boxArg(paramType, arg);
}
return ret;
}
-
-static Object prepRet(Object x)
- {
- if(x is Boolean)
- return ((Boolean)x)?RT.T:null;
- return x;
- }
-
-
- }
-}
diff --git a/src/cli/runtime/RestFn.cs b/src/cli/runtime/RestFn.cs deleted file mode 100644 index b83bf057..00000000 --- a/src/cli/runtime/RestFn.cs +++ /dev/null @@ -1,1336 +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.
- **/
-using System;
-
-namespace clojure.lang
-{
-public abstract class RestFn : AFn {
-
-protected int reqArity;
-
-public RestFn(int reqArity) {
- this.reqArity = reqArity;
-}
-
-protected virtual Object doInvoke(ISeq args) {
- return null;
-}
-
-protected virtual Object doInvoke(Object arg1, ISeq args) {
- return null;
-}
-
-protected virtual Object doInvoke(Object arg1, Object arg2, ISeq args) {
- return null;
-}
-
-protected virtual Object doInvoke(Object arg1, Object arg2, Object arg3, ISeq args) {
- return null;
-}
-
-protected virtual Object doInvoke(Object arg1, Object arg2, Object arg3, Object arg4, ISeq args) {
- return null;
-}
-
-protected virtual Object doInvoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, ISeq args) {
- return null;
-}
-
-protected virtual Object doInvoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, ISeq args)
- {
- return null;
-}
-
-protected virtual Object doInvoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
- ISeq args) {
- return null;
-}
-
-protected virtual Object doInvoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
- Object arg8, ISeq args) {
- return null;
-}
-
-protected virtual Object doInvoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
- Object arg8, Object arg9, ISeq args) {
- return null;
-}
-
-protected virtual Object doInvoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
- Object arg8, Object arg9, Object arg10, ISeq args) {
- return null;
-}
-
-protected virtual Object doInvoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
- Object arg8, Object arg9, Object arg10, Object arg11, ISeq args) {
- return null;
-}
-
-protected virtual Object doInvoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
- Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, ISeq args)
- {
- return null;
-}
-
-protected virtual Object doInvoke(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, ISeq args)
- {
- return null;
-}
-
-protected virtual Object doInvoke(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, ISeq args) {
- return null;
-}
-
-protected virtual Object doInvoke(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, ISeq args) {
- return null;
-}
-
-protected virtual Object doInvoke(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, ISeq args) {
- return null;
-}
-
-protected virtual Object doInvoke(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, ISeq args) {
- return null;
-}
-
-protected virtual Object doInvoke(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, ISeq args)
- {
- return null;
-}
-
-protected virtual Object doInvoke(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, ISeq args)
- {
- return null;
-}
-
-protected virtual Object doInvoke(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, ISeq args) {
- return null;
-}
-
-
-
-override public Object applyTo(ISeq args) {
- if (RT.boundedLength(args, reqArity) <= reqArity)
- {
- return applyToHelper(this, args);
- }
- switch (reqArity)
- {
- case 0:
- return invoke(args);
- case 1:
- return invoke(args.first()
- , args.rest());
- case 2:
- return invoke(args.first()
- , (args = args.rest()).first()
- , args.rest());
- case 3:
- return invoke(args.first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , args.rest());
- case 4:
- return invoke(args.first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , args.rest());
- case 5:
- return invoke(args.first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , args.rest());
- case 6:
- return invoke(args.first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , args.rest());
- case 7:
- return invoke(args.first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , args.rest());
- case 8:
- return invoke(args.first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , args.rest());
- case 9:
- return invoke(args.first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , args.rest());
- case 10:
- return invoke(args.first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , args.rest());
- case 11:
- return invoke(args.first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , args.rest());
- case 12:
- return invoke(args.first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , args.rest());
- case 13:
- return invoke(args.first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , args.rest());
- case 14:
- return invoke(args.first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , args.rest());
- case 15:
- return invoke(args.first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , args.rest());
- case 16:
- return invoke(args.first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , args.rest());
- case 17:
- return invoke(args.first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , args.rest());
- case 18:
- return invoke(args.first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , args.rest());
- case 19:
- return invoke(args.first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , args.rest());
- case 20:
- return invoke(args.first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , (args = args.rest()).first()
- , args.rest());
-
- }
- return throwArity();
-}
-
-override public Object invoke() {
- switch (reqArity)
- {
- case 0:
- return doInvoke(null);
- default:
- return throwArity();
- }
-
-}
-
-override public Object invoke(Object arg1) {
- switch (reqArity)
- {
- case 0:
- return doInvoke(ArraySeq.create(arg1));
- case 1:
- return doInvoke(arg1, null);
- default:
- return throwArity();
- }
-
-}
-
-override public Object invoke(Object arg1, Object arg2) {
- switch (reqArity)
- {
- case 0:
- return doInvoke(ArraySeq.create(arg1, arg2));
- case 1:
- return doInvoke(arg1, ArraySeq.create(arg2));
- case 2:
- return doInvoke(arg1, arg2, null);
- default:
- return throwArity();
- }
-
-}
-
-override public Object invoke(Object arg1, Object arg2, Object arg3) {
- switch (reqArity)
- {
- case 0:
- return doInvoke(ArraySeq.create(arg1, arg2, arg3));
- case 1:
- return doInvoke(arg1, ArraySeq.create(arg2, arg3));
- case 2:
- return doInvoke(arg1, arg2, ArraySeq.create(arg3));
- case 3:
- return doInvoke(arg1, arg2, arg3, null);
- default:
- return throwArity();
- }
-
-}
-
-override public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4) {
- switch (reqArity)
- {
- case 0:
- return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4));
- case 1:
- return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4));
- case 2:
- return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4));
- case 3:
- return doInvoke(arg1, arg2, arg3, ArraySeq.create(arg4));
- case 4:
- return doInvoke(arg1, arg2, arg3, arg4, null);
- default:
- return throwArity();
- }
-
-}
-
-override public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) {
- switch (reqArity)
- {
- case 0:
- return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5));
- case 1:
- return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5));
- case 2:
- return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5));
- case 3:
- return doInvoke(arg1, arg2, arg3, ArraySeq.create(arg4, arg5));
- case 4:
- return doInvoke(arg1, arg2, arg3, arg4, ArraySeq.create(arg5));
- case 5:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, null);
- default:
- return throwArity();
- }
-
-}
-
-override public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) {
- switch (reqArity)
- {
- case 0:
- return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6));
- case 1:
- return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6));
- case 2:
- return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5, arg6));
- case 3:
- return doInvoke(arg1, arg2, arg3, ArraySeq.create(arg4, arg5, arg6));
- case 4:
- return doInvoke(arg1, arg2, arg3, arg4, ArraySeq.create(arg5, arg6));
- case 5:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, ArraySeq.create(arg6));
- case 6:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, null);
- default:
- return throwArity();
- }
-
-}
-
-override public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7)
- {
- switch (reqArity)
- {
- case 0:
- return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7));
- case 1:
- return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7));
- case 2:
- return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5, arg6, arg7));
- case 3:
- return doInvoke(arg1, arg2, arg3, ArraySeq.create(arg4, arg5, arg6, arg7));
- case 4:
- return doInvoke(arg1, arg2, arg3, arg4, ArraySeq.create(arg5, arg6, arg7));
- case 5:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, ArraySeq.create(arg6, arg7));
- case 6:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, ArraySeq.create(arg7));
- case 7:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, null);
- default:
- return throwArity();
- }
-
-}
-
-override public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
- Object arg8) {
- switch (reqArity)
- {
- case 0:
- return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8));
- case 1:
- return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7, arg8));
- case 2:
- return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5, arg6, arg7, arg8));
- case 3:
- return doInvoke(arg1, arg2, arg3, ArraySeq.create(arg4, arg5, arg6, arg7, arg8));
- case 4:
- return doInvoke(arg1, arg2, arg3, arg4, ArraySeq.create(arg5, arg6, arg7, arg8));
- case 5:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, ArraySeq.create(arg6, arg7, arg8));
- case 6:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, ArraySeq.create(arg7, arg8));
- case 7:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, ArraySeq.create(arg8));
- case 8:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, null);
- default:
- return throwArity();
- }
-
-}
-
-override public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
- Object arg8, Object arg9) {
- switch (reqArity)
- {
- case 0:
- return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9));
- case 1:
- return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9));
- case 2:
- return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5, arg6, arg7, arg8, arg9));
- case 3:
- return doInvoke(arg1, arg2, arg3, ArraySeq.create(arg4, arg5, arg6, arg7, arg8, arg9));
- case 4:
- return doInvoke(arg1, arg2, arg3, arg4, ArraySeq.create(arg5, arg6, arg7, arg8, arg9));
- case 5:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, ArraySeq.create(arg6, arg7, arg8, arg9));
- case 6:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, ArraySeq.create(arg7, arg8, arg9));
- case 7:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, ArraySeq.create(arg8, arg9));
- case 8:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, ArraySeq.create(arg9));
- case 9:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, null);
- default:
- return throwArity();
- }
-
-}
-
-override public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
- Object arg8, Object arg9, Object arg10) {
- switch (reqArity)
- {
- case 0:
- return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10));
- case 1:
- return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10));
- case 2:
- return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10));
- case 3:
- return doInvoke(arg1, arg2, arg3, ArraySeq.create(arg4, arg5, arg6, arg7, arg8, arg9, arg10));
- case 4:
- return doInvoke(arg1, arg2, arg3, arg4, ArraySeq.create(arg5, arg6, arg7, arg8, arg9, arg10));
- case 5:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, ArraySeq.create(arg6, arg7, arg8, arg9, arg10));
- case 6:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, ArraySeq.create(arg7, arg8, arg9, arg10));
- case 7:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, ArraySeq.create(arg8, arg9, arg10));
- case 8:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, ArraySeq.create(arg9, arg10));
- case 9:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, ArraySeq.create(arg10));
- case 10:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, null);
- default:
- return throwArity();
- }
-
-}
-
-override 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) {
- switch (reqArity)
- {
- case 0:
- return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11));
- case 1:
- return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11));
- case 2:
- return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11));
- case 3:
- return doInvoke(arg1, arg2, arg3, ArraySeq.create(arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11));
- case 4:
- return doInvoke(arg1, arg2, arg3, arg4, ArraySeq.create(arg5, arg6, arg7, arg8, arg9, arg10, arg11));
- case 5:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, ArraySeq.create(arg6, arg7, arg8, arg9, arg10, arg11));
- case 6:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, ArraySeq.create(arg7, arg8, arg9, arg10, arg11));
- case 7:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, ArraySeq.create(arg8, arg9, arg10, arg11));
- case 8:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, ArraySeq.create(arg9, arg10, arg11));
- case 9:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, ArraySeq.create(arg10, arg11));
- case 10:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, ArraySeq.create(arg11));
- case 11:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, null);
- default:
- return throwArity();
- }
-
-}
-
-override 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) {
- switch (reqArity)
- {
- case 0:
- return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12));
- case 1:
- return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12));
- case 2:
- return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12));
- case 3:
- return doInvoke(arg1, arg2, arg3, ArraySeq.create(arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12));
- case 4:
- return doInvoke(arg1, arg2, arg3, arg4, ArraySeq.create(arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12));
- case 5:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, ArraySeq.create(arg6, arg7, arg8, arg9, arg10, arg11, arg12));
- case 6:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, ArraySeq.create(arg7, arg8, arg9, arg10, arg11, arg12));
- case 7:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, ArraySeq.create(arg8, arg9, arg10, arg11, arg12));
- case 8:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, ArraySeq.create(arg9, arg10, arg11, arg12));
- case 9:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, ArraySeq.create(arg10, arg11, arg12));
- case 10:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, ArraySeq.create(arg11, arg12));
- case 11:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, ArraySeq.create(arg12));
- case 12:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, null);
- default:
- return throwArity();
- }
-
-}
-
-override 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)
- {
- switch (reqArity)
- {
- case 0:
- return doInvoke(
- ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13));
- case 1:
- return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13));
- case 2:
- return doInvoke(arg1, arg2,
- ArraySeq.create(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13));
- case 3:
- return doInvoke(arg1, arg2, arg3,
- ArraySeq.create(arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13));
- case 4:
- return doInvoke(arg1, arg2, arg3, arg4,
- ArraySeq.create(arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13));
- case 5:
- return doInvoke(arg1, arg2, arg3, arg4, arg5,
- ArraySeq.create(arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13));
- case 6:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6,
- ArraySeq.create(arg7, arg8, arg9, arg10, arg11, arg12, arg13));
- case 7:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7,
- ArraySeq.create(arg8, arg9, arg10, arg11, arg12, arg13));
- case 8:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8,
- ArraySeq.create(arg9, arg10, arg11, arg12, arg13));
- case 9:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9,
- ArraySeq.create(arg10, arg11, arg12, arg13));
- case 10:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
- ArraySeq.create(arg11, arg12, arg13));
- case 11:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11,
- ArraySeq.create(arg12, arg13));
- case 12:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- ArraySeq.create(arg13));
- case 13:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, null);
- default:
- return throwArity();
- }
-
-}
-
-override 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)
- {
- switch (reqArity)
- {
- case 0:
- return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14));
- case 1:
- return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14));
- case 2:
- return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14));
- case 3:
- return doInvoke(arg1, arg2, arg3,
- ArraySeq.create(arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14));
- case 4:
- return doInvoke(arg1, arg2, arg3, arg4,
- ArraySeq.create(arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14));
- case 5:
- return doInvoke(arg1, arg2, arg3, arg4, arg5,
- ArraySeq.create(arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14));
- case 6:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6,
- ArraySeq.create(arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14));
- case 7:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7,
- ArraySeq.create(arg8, arg9, arg10, arg11, arg12, arg13, arg14));
- case 8:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8,
- ArraySeq.create(arg9, arg10, arg11, arg12, arg13, arg14));
- case 9:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9,
- ArraySeq.create(arg10, arg11, arg12, arg13, arg14));
- case 10:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
- ArraySeq.create(arg11, arg12, arg13, arg14));
- case 11:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11,
- ArraySeq.create(arg12, arg13, arg14));
- case 12:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- ArraySeq.create(arg13, arg14));
- case 13:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13,
- ArraySeq.create(arg14));
- case 14:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- null);
- default:
- return throwArity();
- }
-
-}
-
-override 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) {
- switch (reqArity)
- {
- case 0:
- return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15));
- case 1:
- return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15));
- case 2:
- return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15));
- case 3:
- return doInvoke(arg1, arg2, arg3, ArraySeq.create(arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15));
- case 4:
- return doInvoke(arg1, arg2, arg3, arg4,
- ArraySeq.create(arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15));
- case 5:
- return doInvoke(arg1, arg2, arg3, arg4, arg5,
- ArraySeq.create(arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15));
- case 6:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6,
- ArraySeq.create(arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15));
- case 7:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7,
- ArraySeq.create(arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15));
- case 8:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8,
- ArraySeq.create(arg9, arg10, arg11, arg12, arg13, arg14, arg15));
- case 9:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9,
- ArraySeq.create(arg10, arg11, arg12, arg13, arg14, arg15));
- case 10:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
- ArraySeq.create(arg11, arg12, arg13, arg14, arg15));
- case 11:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11,
- ArraySeq.create(arg12, arg13, arg14, arg15));
- case 12:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- ArraySeq.create(arg13, arg14, arg15));
- case 13:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13,
- ArraySeq.create(arg14, arg15));
- case 14:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- ArraySeq.create(arg15));
- case 15:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- arg15, null);
- default:
- return throwArity();
- }
-
-}
-
-override 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) {
- switch (reqArity)
- {
- case 0:
- return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16));
- case 1:
- return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16));
- case 2:
- return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16));
- case 3:
- return doInvoke(arg1, arg2, arg3, ArraySeq.create(arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16));
- case 4:
- return doInvoke(arg1, arg2, arg3, arg4, ArraySeq.create(arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16));
- case 5:
- return doInvoke(arg1, arg2, arg3, arg4, arg5,
- ArraySeq.create(arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16));
- case 6:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6,
- ArraySeq.create(arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16));
- case 7:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7,
- ArraySeq.create(arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16));
- case 8:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8,
- ArraySeq.create(arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16));
- case 9:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9,
- ArraySeq.create(arg10, arg11, arg12, arg13, arg14, arg15, arg16));
- case 10:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
- ArraySeq.create(arg11, arg12, arg13, arg14, arg15, arg16));
- case 11:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11,
- ArraySeq.create(arg12, arg13, arg14, arg15, arg16));
- case 12:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- ArraySeq.create(arg13, arg14, arg15, arg16));
- case 13:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13,
- ArraySeq.create(arg14, arg15, arg16));
- case 14:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- ArraySeq.create(arg15, arg16));
- case 15:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- arg15, ArraySeq.create(arg16));
- case 16:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- arg15, arg16, null);
- default:
- return throwArity();
- }
-
-}
-
-override 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) {
- switch (reqArity)
- {
- case 0:
- return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17));
- case 1:
- return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17));
- case 2:
- return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17));
- case 3:
- return doInvoke(arg1, arg2, arg3, ArraySeq.create(arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17));
- case 4:
- return doInvoke(arg1, arg2, arg3, arg4, ArraySeq.create(arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17));
- case 5:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, ArraySeq.create(arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17));
- case 6:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6,
- ArraySeq.create(arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17));
- case 7:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7,
- ArraySeq.create(arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17));
- case 8:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8,
- ArraySeq.create(arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17));
- case 9:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9,
- ArraySeq.create(arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17));
- case 10:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
- ArraySeq.create(arg11, arg12, arg13, arg14, arg15, arg16, arg17));
- case 11:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11,
- ArraySeq.create(arg12, arg13, arg14, arg15, arg16, arg17));
- case 12:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- ArraySeq.create(arg13, arg14, arg15, arg16, arg17));
- case 13:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13,
- ArraySeq.create(arg14, arg15, arg16, arg17));
- case 14:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- ArraySeq.create(arg15, arg16, arg17));
- case 15:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- arg15, ArraySeq.create(arg16, arg17));
- case 16:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- arg15, arg16, ArraySeq.create(arg17));
- case 17:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- arg15, arg16, arg17, null);
- default:
- return throwArity();
- }
-
-}
-
-override 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) {
- switch (reqArity)
- {
- case 0:
- return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17, arg18));
- case 1:
- return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17, arg18));
- case 2:
- return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17, arg18));
- case 3:
- return doInvoke(arg1, arg2, arg3, ArraySeq.create(arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17, arg18));
- case 4:
- return doInvoke(arg1, arg2, arg3, arg4, ArraySeq.create(arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17, arg18));
- case 5:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, ArraySeq.create(arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17, arg18));
- case 6:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, ArraySeq.create(arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17,
- arg18));
- case 7:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7,
- ArraySeq.create(arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18));
- case 8:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8,
- ArraySeq.create(arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18));
- case 9:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9,
- ArraySeq.create(arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18));
- case 10:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
- ArraySeq.create(arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18));
- case 11:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11,
- ArraySeq.create(arg12, arg13, arg14, arg15, arg16, arg17, arg18));
- case 12:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- ArraySeq.create(arg13, arg14, arg15, arg16, arg17, arg18));
- case 13:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13,
- ArraySeq.create(arg14, arg15, arg16, arg17, arg18));
- case 14:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- ArraySeq.create(arg15, arg16, arg17, arg18));
- case 15:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- arg15, ArraySeq.create(arg16, arg17, arg18));
- case 16:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- arg15, arg16, ArraySeq.create(arg17, arg18));
- case 17:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- arg15, arg16, arg17, ArraySeq.create(arg18));
- case 18:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- arg15, arg16, arg17, arg18, null);
- default:
- return throwArity();
- }
-
-}
-
-override 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) {
- switch (reqArity)
- {
- case 0:
- return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17, arg18, arg19));
- case 1:
- return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17, arg18, arg19));
- case 2:
- return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17, arg18, arg19));
- case 3:
- return doInvoke(arg1, arg2, arg3, ArraySeq.create(arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17, arg18, arg19));
- case 4:
- return doInvoke(arg1, arg2, arg3, arg4, ArraySeq.create(arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17, arg18, arg19));
- case 5:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, ArraySeq.create(arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17, arg18,
- arg19));
- case 6:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, ArraySeq.create(arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17,
- arg18, arg19));
- case 7:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, ArraySeq.create(arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17,
- arg18, arg19));
- case 8:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, ArraySeq.create(arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16,
- arg17, arg18, arg19));
- case 9:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9,
- ArraySeq.create(arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19));
- case 10:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
- ArraySeq.create(arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19));
- case 11:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11,
- ArraySeq.create(arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19));
- case 12:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- ArraySeq.create(arg13, arg14, arg15, arg16, arg17, arg18, arg19));
- case 13:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13,
- ArraySeq.create(arg14, arg15, arg16, arg17, arg18, arg19));
- case 14:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- ArraySeq.create(arg15, arg16, arg17, arg18, arg19));
- case 15:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- arg15, ArraySeq.create(arg16, arg17, arg18, arg19));
- case 16:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- arg15, arg16, ArraySeq.create(arg17, arg18, arg19));
- case 17:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- arg15, arg16, arg17, ArraySeq.create(arg18, arg19));
- case 18:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- arg15, arg16, arg17, arg18, ArraySeq.create(arg19));
- case 19:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- arg15, arg16, arg17, arg18, arg19, null);
- default:
- return throwArity();
- }
-
-}
-
-override 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)
- {
- switch (reqArity)
- {
- case 0:
- return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20));
- case 1:
- return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20));
- case 2:
- return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20));
- case 3:
- return doInvoke(arg1, arg2, arg3, ArraySeq.create(arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20));
- case 4:
- return doInvoke(arg1, arg2, arg3, arg4, ArraySeq.create(arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17, arg18, arg19,
- arg20));
- case 5:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, ArraySeq.create(arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17, arg18,
- arg19, arg20));
- case 6:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, ArraySeq.create(arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17,
- arg18, arg19, arg20));
- case 7:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, ArraySeq.create(arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16, arg17,
- arg18, arg19, arg20));
- case 8:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, ArraySeq.create(arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16,
- arg17, arg18, arg19,
- arg20));
- case 9:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, ArraySeq.create(arg10, arg11, arg12,
- arg13, arg14, arg15,
- arg16, arg17, arg18,
- arg19, arg20));
- case 10:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
- ArraySeq.create(arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20));
- case 11:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11,
- ArraySeq.create(arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20));
- case 12:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- ArraySeq.create(arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20));
- case 13:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13,
- ArraySeq.create(arg14, arg15, arg16, arg17, arg18, arg19, arg20));
- case 14:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- ArraySeq.create(arg15, arg16, arg17, arg18, arg19, arg20));
- case 15:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- arg15, ArraySeq.create(arg16, arg17, arg18, arg19, arg20));
- case 16:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- arg15, arg16, ArraySeq.create(arg17, arg18, arg19, arg20));
- case 17:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- arg15, arg16, arg17, ArraySeq.create(arg18, arg19, arg20));
- case 18:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- arg15, arg16, arg17, arg18, ArraySeq.create(arg19, arg20));
- case 19:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- arg15, arg16, arg17, arg18, arg19, ArraySeq.create(arg20));
- case 20:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- arg15, arg16, arg17, arg18, arg19, arg20, null);
- default:
- return throwArity();
- }
-
-}
-
-override 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, params Object[] args)
- {
- switch (reqArity)
- {
- case 0:
- return doInvoke(ontoArrayPrepend(args, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11,
- arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20));
- case 1:
- return doInvoke(arg1, ontoArrayPrepend(args, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11,
- arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20));
- case 2:
- return doInvoke(arg1, arg2, ontoArrayPrepend(args, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11,
- arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19,
- arg20));
- case 3:
- return doInvoke(arg1, arg2, arg3, ontoArrayPrepend(args, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11,
- arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19,
- arg20));
- case 4:
- return doInvoke(arg1, arg2, arg3, arg4, ontoArrayPrepend(args, arg5, arg6, arg7, arg8, arg9, arg10, arg11,
- arg12, arg13, arg14, arg15, arg16, arg17, arg18,
- arg19, arg20));
- case 5:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, ontoArrayPrepend(args, arg6, arg7, arg8, arg9, arg10, arg11,
- arg12, arg13, arg14, arg15, arg16, arg17,
- arg18, arg19, arg20));
- case 6:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, ontoArrayPrepend(args, arg7, arg8, arg9, arg10, arg11,
- arg12, arg13, arg14, arg15, arg16,
- arg17, arg18, arg19, arg20));
- case 7:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, ontoArrayPrepend(args, arg8, arg9, arg10, arg11,
- arg12, arg13, arg14, arg15,
- arg16, arg17, arg18, arg19,
- arg20));
- case 8:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, ontoArrayPrepend(args, arg9, arg10, arg11,
- arg12, arg13, arg14, arg15,
- arg16, arg17, arg18, arg19,
- arg20));
- case 9:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, ontoArrayPrepend(args, arg10, arg11,
- arg12, arg13, arg14,
- arg15, arg16, arg17,
- arg18, arg19,
- arg20));
- case 10:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, ontoArrayPrepend(args, arg11,
- arg12, arg13,
- arg14, arg15,
- arg16, arg17,
- arg18, arg19,
- arg20));
- case 11:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11,
- ontoArrayPrepend(args, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20));
- case 12:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- ontoArrayPrepend(args, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20));
- case 13:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13,
- ontoArrayPrepend(args, arg14, arg15, arg16, arg17, arg18, arg19, arg20));
- case 14:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- ontoArrayPrepend(args, arg15, arg16, arg17, arg18, arg19, arg20));
- case 15:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- arg15, ontoArrayPrepend(args, arg16, arg17, arg18, arg19, arg20));
- case 16:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- arg15, arg16, ontoArrayPrepend(args, arg17, arg18, arg19, arg20));
- case 17:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- arg15, arg16, arg17, ontoArrayPrepend(args, arg18, arg19, arg20));
- case 18:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- arg15, arg16, arg17, arg18, ontoArrayPrepend(args, arg19, arg20));
- case 19:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- arg15, arg16, arg17, arg18, arg19, ontoArrayPrepend(args, arg20));
- case 20:
- return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14,
- arg15, arg16, arg17, arg18, arg19, arg20, ArraySeq.create(args));
- default:
- return throwArity();
- }
-
-}
-
-
-protected static ISeq ontoArrayPrepend(Object[] array, params Object[] args) {
- ISeq ret = ArraySeq.create(array);
- for (int i = args.Length - 1; i >= 0; --i)
- ret = RT.cons(args[i], ret);
- return ret;
-}
-
-protected static ISeq findKey(Object key, ISeq args){
- while(args != null)
- {
- if(key == args.first())
- return args.rest();
- args = RT.rest(args);
- args = RT.rest(args);
- }
- return null;
-}
-}
-
-}
diff --git a/src/cli/runtime/Sequential.cs b/src/cli/runtime/Sequential.cs deleted file mode 100644 index a8b48e96..00000000 --- a/src/cli/runtime/Sequential.cs +++ /dev/null @@ -1,18 +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.
- */
-
-namespace clojure.lang
-{ -
-
-public interface Sequential {
-}
-
-}
diff --git a/src/cli/runtime/StaticMemberSymbol.cs b/src/cli/runtime/StaticMemberSymbol.cs deleted file mode 100644 index 18393f60..00000000 --- a/src/cli/runtime/StaticMemberSymbol.cs +++ /dev/null @@ -1,160 +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.
- **/
-
-using System;
- -namespace clojure.lang
-{ -
-public class StaticMemberSymbol : HostSymbol, IFn{
-readonly public String className;
-readonly public String memberName;
-
-public StaticMemberSymbol(String name) : base(name) {
- int lastDot = name.LastIndexOf('.');
- this.className = name.Substring(0,lastDot);
- this.memberName = name.Substring(lastDot + 1);
-}
-
-public Object invoke() {
- return Reflector.invokeStaticMethod(memberName, className );
-}
-
-public Object invoke(Object obj) {
-
- return Reflector.invokeStaticMethod(memberName, className , obj);
-}
-
-public Object invoke(Object obj, Object val) {
-
- return Reflector.invokeStaticMethod(memberName, className , obj, val);
-}
-
-public Object invoke(Object arg1, Object arg2, Object arg3) {
- return Reflector.invokeStaticMethod(memberName, className , arg1, arg2, arg3);
-}
-
-public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4) {
- return Reflector.invokeStaticMethod(memberName, className , arg1, arg2, arg3, arg4);
-}
-
-public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) {
- return Reflector.invokeStaticMethod(memberName, className , arg1, arg2, arg3, arg4, arg5);
-}
-
-public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) {
- return Reflector.invokeStaticMethod(memberName, className , arg1, arg2, arg3, arg4, arg5, arg6);
-}
-
-public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7)
- {
- return Reflector.invokeStaticMethod(memberName, className , arg1, arg2, arg3, arg4, arg5, arg6, arg7);
-}
-
-public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
- Object arg8) {
- return Reflector.invokeStaticMethod(memberName, className , arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
-}
-
-public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
- Object arg8, Object arg9) {
- return Reflector.invokeStaticMethod(memberName, className , arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
-}
-
-public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
- Object arg8, Object arg9, Object arg10) {
- return Reflector.invokeStaticMethod(memberName, className , arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
-}
-
-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) {
- return Reflector
- .invokeStaticMethod(memberName, className , arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11);
-}
-
-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) {
- return Reflector.invokeStaticMethod(memberName, className , arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
- arg11, arg12);
-}
-
-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)
- {
- return Reflector.invokeStaticMethod(memberName, className , arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
- arg11, arg12, arg13);
-}
-
-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)
- {
- return Reflector.invokeStaticMethod(memberName, className , arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
- arg11, arg12, arg13, arg14);
-}
-
-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) {
- return Reflector.invokeStaticMethod(memberName, className , arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
- arg11, arg12, arg13, arg14, arg15);
-}
-
-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) {
- return Reflector.invokeStaticMethod(memberName, className , arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
- arg11, arg12, arg13, arg14, arg15, arg16);
-}
-
-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) {
- return Reflector.invokeStaticMethod(memberName, className , arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
- arg11, arg12, arg13, arg14, arg15, arg16, arg17);
-}
-
-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) {
- return Reflector.invokeStaticMethod(memberName, className , arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
- arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18);
-}
-
-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) {
- return Reflector.invokeStaticMethod(memberName, className , arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
- arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19);
-}
-
-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)
- {
- return Reflector.invokeStaticMethod(memberName, className , arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
- arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20);
-}
-
-
-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
- , params Object[] args)
- {
- throw new InvalidOperationException("Can't call functions of more than 20 arguments");
-}
-
-public Object applyTo(ISeq arglist) {
- return AFn.applyToHelper(this, arglist);
-}
-
-}
-
-}
diff --git a/src/cli/runtime/Symbol.cs b/src/cli/runtime/Symbol.cs deleted file mode 100644 index 1a72b60e..00000000 --- a/src/cli/runtime/Symbol.cs +++ /dev/null @@ -1,100 +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 Mar 25, 2006 11:42:47 AM */ - -using System;
-using System.Collections;
- -namespace clojure.lang
-{ -public class Symbol
-// : Obj, IComparable
-{
-
-static public readonly Hashtable table = new Hashtable(1001);
-//static public readonly Hashtable hashes = new Hashtable(1001); -//static readonly Random rand = new Random(42);
- - -public readonly String name;
-//int hash = 0; - -override public String ToString() - { - return name; - } - -public static Symbol intern(String name)
{
lock(table)
{
Symbol sym = (Symbol) table[name];
- int dot = 0;
- if (sym == null)
- {
- if (name[0] == ':')
- sym = new Keyword(name);
- else if ((dot = name.IndexOf('.')) != -1)
- {
- if (dot == 0)
- sym = new InstanceMemberSymbol(name);
- else if (name.LastIndexOf('.') == name.Length - 1)
- sym = new ClassSymbol(name);
- else
- sym = new StaticMemberSymbol(name);
- }
- else
- sym = new Symbol(name);
if(table[name] != null) //defend against recursive static init
- return (Symbol)table[name];
table.Add(name, sym);
}
return sym;
}
} -/** - * Used by Module.intern() - * @param name - * @param ns - */ -internal Symbol(String name) - { - this.name = name; - } - -/* -public override int GetHashCode()
- {
- if(hash == 0)
- {
- lock (hashes)
- {
- while (hash == 0)
- {
- int h = rand.Next();
- if (h != 0 && !hashes.ContainsKey(h))
- {
- hash = h;
- hashes.Add(h,null);
- }
- }
- }
- }
- return hash;
- }
-
-
-#region IComparable Members
-
-public int CompareTo(object obj)
- {
- return GetHashCode() - ((Symbol)obj).GetHashCode();
- }
-
-#endregion
-
-override public Obj withMeta(IPersistentMap meta) {
- this._meta = meta;
- return this;
-}
-*/
- } -} diff --git a/src/cli/runtime/TObj.cs b/src/cli/runtime/TObj.cs deleted file mode 100644 index 0fe6b471..00000000 --- a/src/cli/runtime/TObj.cs +++ /dev/null @@ -1,51 +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.
- **/
-
-using System;
-
-namespace clojure.lang
- {
-
-public class TObj : IObj{
-TRef _attrs;
-
-public TObj(){
- this._attrs = Transaction.tref(PersistentArrayMap.EMPTY);
-}
-
-
-public Object putAttr( Object key, Object val) {
- IPersistentMap t = (IPersistentMap) Transaction.get( _attrs);
- t = (IPersistentMap)t.assoc(key, val);
- Transaction.set(_attrs,t);
- return val;
-}
-
-public Object getAttr( Object key) {
- IPersistentMap t = (IPersistentMap) Transaction.get( _attrs);
- return t.get(key);
-}
-
-public bool hasAttr( Object key) {
- IPersistentMap t = (IPersistentMap) Transaction.get( _attrs);
- return t.contains(key);
-}
-
-public IPersistentMap attrs() {
- return (IPersistentMap) Transaction.get(_attrs);
-}
-
-public void removeAttr(Object key) {
- IPersistentMap t = (IPersistentMap) Transaction.get( _attrs);
- t = t.without(key);
- Transaction.set(_attrs,t);
-}
-}
-}
diff --git a/src/cli/runtime/TRef.cs b/src/cli/runtime/TRef.cs deleted file mode 100644 index d749793f..00000000 --- a/src/cli/runtime/TRef.cs +++ /dev/null @@ -1,32 +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 May 30, 2006 */
-
-using System;
-using System.Threading;
-
-namespace clojure.lang
-{
-
-public class TRef : TVal, IComparable{
-static int nextSeq = 0;
-
-readonly int lockSeq;
-
-public TRef() {
- this.lockSeq = Interlocked.Increment(ref nextSeq);
-}
-
-public int CompareTo(Object o){
- return lockSeq - ((TRef) o).lockSeq;
-}
-}
-}
diff --git a/src/cli/runtime/TVal.cs b/src/cli/runtime/TVal.cs deleted file mode 100644 index 26ee74a6..00000000 --- a/src/cli/runtime/TVal.cs +++ /dev/null @@ -1,42 +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 May 30, 2006 */
-
-using System;
-
-namespace clojure.lang
-{
-public class TVal{
-internal volatile Object val;
-internal volatile Transaction.Info tinfo;
-internal volatile TVal prior;
-
-internal TVal(){
-
-}
-
-internal TVal(Object val, Transaction.Info tinfo, TVal prior) {
- this.val = val;
- this.tinfo = tinfo;
- this.prior = prior;
-}
-
-internal void push(Object val,Transaction.Info tinfo) {
- if(tinfo != null) //not newly created, clone tval part
- {
- this.prior = new TVal(this.val,this.tinfo,this.prior);
- }
- this.tinfo = tinfo;
- this.val = val;
-}
-
-}
-}
diff --git a/src/cli/runtime/ThreadLocalData.cs b/src/cli/runtime/ThreadLocalData.cs deleted file mode 100644 index 8d866bda..00000000 --- a/src/cli/runtime/ThreadLocalData.cs +++ /dev/null @@ -1,34 +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 Mar 25, 2006 11:45:22 AM */ - -using System;
-using System.Collections.Specialized;
-
-namespace clojure.lang
-{ -public class ThreadLocalData{
-
-[ThreadStatic]
-private static Object[] values;
-
-static public Object[] getValues(){
- return values;
-}
-
-static public void setValues(Object[] vals) {
- values = vals;
-}
-
-
- -} -} diff --git a/src/cli/runtime/Transaction.cs b/src/cli/runtime/Transaction.cs deleted file mode 100644 index b761b9e2..00000000 --- a/src/cli/runtime/Transaction.cs +++ /dev/null @@ -1,267 +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 May 30, 2006 */
-
-using System;
-using System.Threading;
-using System.Collections.Generic;
-
-namespace clojure.lang
-{
-public class Transaction{
-
-public const int COMMITTED = 0;
-public const int WORKING = 1;
-static readonly Object lockObj = new Object();
-[ThreadStatic]
-private static Transaction transaction;
-
-static volatile int tcount = 0;
-
-static Transaction getTransaction()
- {
- if(tcount == 0)
- return null;
- return transaction;
- }
-
-static void setTransaction(Transaction t)
- {
- transaction = t;
- }
-
-
-volatile static int nextSeq = 1;
-
-static int getNextSeq(){
-lock (lockObj)
-{
- return nextSeq++;
- }
-}
-
-public class Info{
-internal int seq;
-internal int status;
-
-
-internal Info(int seq,int status){
- this.seq = seq;
- this.status = status;
-}
-}
-
-static Info bigbang = new Info(0,COMMITTED);
-
-Info info;
-int startSeq;
-
-Dictionary<TRef,Object> sets;
-Dictionary<TRef,ISeq> commutates;
-
-
-static public Object runInTransaction(ThreadLocalData tld,IFn fn) {
- if(getTransaction() != null)
- return fn.invoke(tld);
- Transaction t = new Transaction();
- setTransaction(t);
- Interlocked.Increment(ref tcount);
- try
- {
- return t.run(fn);
- }
- finally{
- setTransaction(null);
- Interlocked.Decrement(ref tcount);
- }
-}
-
-static public TRef tref(Object val) {
- Transaction trans = getTransaction();
- TRef tref = new TRef();
- if(trans == null)
- tref.push(val,bigbang);
- else
- trans.doSet(tref, val);
- return tref;
-}
-
-static public Object get(TRef tref) {
- Transaction trans = getTransaction();
- if(trans != null)
- return trans.doGet(tref);
- return getCurrent(tref).val;
- }
-
-static public Object set(TRef tref, Object val) {
- return getTransaction().doSet(tref,val);
-}
-
-static public void touch(TRef tref) {
- getTransaction().doTouch(tref);
-}
-
-static public void commutate(TRef tref, IFn fn) {
- getTransaction().doCommutate(tref, fn);
-}
-
-
-Object run(IFn fn) {
- bool done = false;
- Object ret = null;
- List<TRef> locks = null;
- List<TRef> locked = null;
-
- while(!done){
- try
- {
- ret = fn.invoke();
- if(locks == null && (sets != null || commutates != null))
- locks = new List<TRef>();
- if(sets != null)
- locks.AddRange(sets.Keys);
- if(commutates != null)
- locks.AddRange(commutates.Keys);
- if(locks != null)
- {
- if(locked == null)
- locked = new List<TRef>(locks.Count);
- //lock in order, to avoid deadlocks
- locks.Sort();
- foreach(TRef tref in locks)
- {
- //will block here
- Monitor.Enter(tref);
- locked.Add(tref);
- if(sets.ContainsKey(tref))
- {
- //try again if the thing we are trying to set has changed since we started
- TVal curr = getCurrent(tref);
- if(curr != null && curr.tinfo.seq > startSeq)
- goto loop;
- }
- }
- }
-
- //at this point all write targets are locked
- //turn commutates into sets
- foreach(KeyValuePair<TRef, ISeq> e in commutates)
- {
- TRef tref = e.Key;
- //note this will npe if tref has never been set, as designed
- Object val = getCurrent(tref).val;
- for(ISeq c = e.Value;c!=null;c = c.rest())
- {
- IFn f = (IFn) c.first();
- val = f.invoke(val);
- }
- sets[tref] = val;
- }
-
- //set the new vals
- foreach(KeyValuePair<TRef, Object> entry in sets)
- {
- TRef tref = entry.Key;
- tref.push(entry.Value, info);
- }
-
- //atomic commit
- lock(lockObj){
- info.seq = getNextSeq();
- info.status = COMMITTED;
- }
-
- done = true;
- loop:
- ;
- }
- finally{
- if(locked != null)
- {
- foreach(TRef tref in locked)
- {
- Monitor.Exit(tref);
- }
- locked.Clear();
- }
- reset();
- if(locks != null)
- locks.Clear();
- }
- }
- return ret;
-}
-
-private void reset(){
- if(sets != null)
- sets.Clear();
- if(commutates != null)
- commutates.Clear();
-
-}
-
-
-Transaction(){
- lock(lockObj){
- int seq = getNextSeq();
- this.info = new Info(seq, WORKING);
- this.startSeq = seq;
- }
-}
-
-Object doGet(TRef tref) {
- if(sets != null && sets.ContainsKey(tref))
- return sets[tref];
-
- for(TVal ver = tref;ver != null;ver = ver.prior)
- {
- //note this will npe if tref has never been set, as designed
- if(ver.tinfo.status == COMMITTED && ver.tinfo.seq <= startSeq)
- return ver.val;
- }
-
- throw new Exception("Version not found");
-}
-
-static TVal getCurrent(TRef tref) {
- for(TVal ver = tref;ver != null;ver = ver.prior)
- {
- if(ver.tinfo != null && ver.tinfo.status == COMMITTED)
- return ver;
- }
- //this return only if no value was ever successfully set
- return null;
-}
-
-Object doSet(TRef tref, Object val) {
- if(sets == null)
- sets = new Dictionary<TRef,Object>();
- if(commutates != null && commutates.ContainsKey(tref))
- throw new Exception("Can't commutate and set a TRef in the same transaction");
-
- sets[tref] =val;
- return val;
- }
-
-void doTouch(TRef tref) {
- doSet(tref, doGet(tref));
- }
-
-void doCommutate(TRef tref, IFn fn) {
- if(commutates == null)
- commutates = new Dictionary<TRef,ISeq>();
- if(sets != null && sets.ContainsKey(tref))
- throw new Exception("Can't commutate and set a TRef in the same transaction");
- commutates[tref] = RT.cons(fn, commutates[tref]);
- }
-
-}
-}
diff --git a/src/cli/runtime/Tuple.cs b/src/cli/runtime/Tuple.cs deleted file mode 100644 index 24f7f760..00000000 --- a/src/cli/runtime/Tuple.cs +++ /dev/null @@ -1,91 +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 Jun 19, 2006 */
-
-using System;
- -namespace clojure.lang
-{ -
-public class Tuple : APersistentArray{
-
-readonly Object[] array;
-
-readonly public static Tuple EMPTY = new Tuple();
-
-/**
- * This ctor captures/aliases the passed array, so do not modify later !
- * @param init {key1,val1,key2,val2,...}
- */
-public Tuple(params Object[] init){
- this.array = init;
-}
-
-override public int count() {
- return array.Length;
-}
-
-override public int length() {
- return array.Length;
-}
-
-override public Object nth(int i){
- return array[i];
-}
-
-
-override public IPersistentArray assocN(int i, Object val) {
- Object[] newArray = (Object[])array.Clone();
- newArray[i] = val;
- return new Tuple(newArray);
-}
-
-override public bool Equals(Object key){
- if(this == key) return true;
- if(key == null || !(key is IPersistentArray)) return false;
-
- IPersistentArray a = (IPersistentArray) key;
-
- if(a.length() != array.Length)
- return false;
-
- for(int i = 0; i < array.Length; i++)
- {
- if(!equalKey(array[i],a.nth(i)))
- return false;
- }
-
- return true;
-}
-
-override public int GetHashCode(){
- int ret = 0;
- for(int i = 0; i < array.Length; i++)
- {
- Object o = array[i];
- if(o != null)
- ret ^= o.GetHashCode();
- }
- return ret;
-}
-
-private bool equalKey(Object k1,Object k2){
- if(k1 == null)
- return k2 == null;
- return k1.Equals(k2);
-}
-
-override public ISeq seq() {
- return ArraySeq.create(array);
-}
-}
-
-}
diff --git a/src/cli/runtime/Var.cs b/src/cli/runtime/Var.cs deleted file mode 100644 index d2fae255..00000000 --- a/src/cli/runtime/Var.cs +++ /dev/null @@ -1,123 +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.
- **/
-
-using System;
-using System.Threading;
-
-namespace clojure.lang
-{
-public class Var : AFn
- {
-public readonly Symbol name;
public Module module;
public Binding binding;
-public bool hidden = false;
IPersistentMap threadBindings = PersistentArrayMap.EMPTY;
int tcount = 0;
internal Var(Symbol sym, Module ns)
{
if(sym.GetType() != typeof(Symbol))
throw new ArgumentException("Only simple symbols can be var names");
this.module = ns;
this.name = sym;
}
override public String ToString()
{
if(module == null)
return "#:" + name;
return module.name + ":" + name;
}
public Var bind(Object val)
{
lock(this){
if(binding == null)
- binding = new Binding(val);
else
binding.val = val;
-
- return this;
}
}
public Object getValue()
{
- Binding b = getBinding();
if(b != null)
return b.val;
throw new InvalidOperationException(this.ToString() + " is unbound.");
}
public Object setValue(Object val)
{
- Binding b = getThreadBinding();
if(b != null)
return b.val = val;
if(binding == null)
- throw new InvalidOperationException(this.ToString() + " is unbound.");
return binding.val = val;
}
-
-public Binding pushThreadBinding(Object val) {
- Binding ret = new Binding(val, getThreadBinding());
- setThreadBinding(ret);
- Interlocked.Increment(ref tcount);
- return ret;
-}
-
-public void popThreadBinding() {
- setThreadBinding(getThreadBinding().rest);
- Interlocked.Decrement(ref tcount);
-}
-
-Binding getBinding()
{
- Binding b = getThreadBinding();
if(b != null)
return b;
return binding;
}
-Binding getThreadBinding()
{
- if (tcount != 0)
- return (Binding)threadBindings.get(Thread.CurrentThread);
return null;
}
void setThreadBinding(Binding b) {
- Thread thread = Thread.CurrentThread;
- IPersistentMap tb;
- IPersistentMap newtb;
- do
- {
- tb = threadBindings;
- if (b == null)
- newtb = tb.without(thread);
- else
- newtb = (IPersistentMap)tb.assoc(thread, b);
- } while (tb != Interlocked.CompareExchange(ref threadBindings, newtb, tb));
-}
public IFn fn(){
return (IFn)getValue();
}
override public Object invoke(){
- return fn().invoke();
-}
-override public Object invoke(Object arg1){
- return fn().invoke(arg1);
-}
-override public Object invoke(Object arg1, Object arg2){
- return fn().invoke(arg1, arg2);
-}
-override public Object invoke(Object arg1, Object arg2, Object arg3){
- return fn().invoke(arg1, arg2, arg3);
-}
-override public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4){
- return fn().invoke(arg1, arg2, arg3, arg4);
-}
-override public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5){
- return fn().invoke(arg1, arg2, arg3, arg4, arg5);
-}
-override public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6){
- return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6);
-}
-override public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7){
- return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
-}
-override public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8){
- return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
-}
-override public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Object arg9){
- return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
-}
-override public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10){
- return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
-}
-override 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){
- return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11);
-}
-override 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){
- return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12);
-}
-override 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){
- return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13);
-}
-override 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){
- return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14);
-}
-override 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){
- return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15);
-}
-override 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){
- return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16);
-}
-override 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){
- return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17);
-}
-override 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){
- return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18);
-}
-override 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){
- return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19);
-}
-override 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){
- return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20);
-}
-
override 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
- , params Object[] args){
- return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20,args);
-}
-
}
-}
diff --git a/src/lisp/clojure.lisp b/src/lisp/clojure.lisp deleted file mode 100644 index 1d9952de..00000000 --- a/src/lisp/clojure.lisp +++ /dev/null @@ -1,1597 +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. -; **/ - -(defpackage "clojure" - (:export :load-types :*namespace-separator* - :newobj :@ :compile-to :*clojure-source-path* :*clojure-target-path* - "in-module" - "defn*" "def" "defn" "fn" - "if" "and" "or" "not" "when" "unless" - "block" "let" "let*" "letfn" - "set" "pset" "set*" "do" - "try" "ex" - "char" "boolean" "byte" "short" "int" "long" "float" "double" - "import")) - -(in-package "clojure") - -(defvar *namespace-separator* nil - "set to #\/ for JVM, #\. for CLI") - - -(defconstant +MAX-POSITIONAL-ARITY+ 5) - -(defvar *host* nil) ; :jvm or :cli -(defvar *clojure-source-path*) -(defvar *clojure-target-path*) -(defvar *symbols*) -(defvar *keywords*) -(defvar *vars*) -(defvar *accessors*) -(defvar *defvars*) -(defvar *defns*) -(defvar *quoted-aggregates* nil) -(defvar *nested-fn-bindings*) -(defvar *var-env* nil) -(defvar *frame* nil) -(defvar *next-id*) - -(defvar *imports*) - -;dynamic functions -(defvar *reference-var*) - -#| -;build the library -(let ((*clojure-source-path* #p"/dev/clojure/src/lisp/") - (*clojure-target-path* #p"/dev/clojure/classes/")) - (compile-to :jvm "clojure.lib" "Clojure" - "lib.lisp")) -(let ((*clojure-source-path* #p"/dev/clojure/src/lisp/") - (*clojure-target-path* #p"/dev/clojure/classes/test/")) - (compile-to :cli "clojure.lib" "Clojure" - "lib.lisp")) - -|# - - -; a simple attribute object lib -(defun newobj (&rest attrs) - (let ((obj (make-hash-table))) - (do* ((attrs attrs (nthcdr 2 attrs))) - ((null attrs)) - (let ((attr (first attrs)) - (val (second attrs))) - (setf (gethash attr obj) val))) - obj)) - -(defmacro @ (attr obj) - `(gethash ',attr ,obj)) - - -(defun file-type () - (ecase *host* - (:jvm "java") - (:cli "cs"))) - -;from c.l.l. -(defun lex-string (string &key (whitespace - '(#\space #\newline))) - "Separates a string at whitespace and returns a list of strings" - (flet ((whitespace? (char - - ) (member char whitespace :test #'char=))) - (let ((tokens nil)) - (do* ((token-start - (position-if-not #'whitespace? string) - (when token-end - (position-if-not #'whitespace? string :start (1+ token-end)))) - (token-end - (when token-start - (position-if #'whitespace? string :start token-start)) - (when token-start - (position-if #'whitespace? - string :start token-start)))) - ((null token-start) (nreverse tokens)) - (push (subseq string token-start token-end) tokens))))) - -(defun file-path (package-name) - (ecase *host* - (:jvm (lex-string package-name :whitespace '(#\.))) - (:cli (list "")))) - -(defun package-open-format-string () - (ecase *host* - (:jvm "package ~A;~2%") - (:cli "namespace ~A {~2%"))) - -(defun package-close-string () - (ecase *host* - (:jvm "") - (:cli "}"))) - -(defun package-import-format-string () - (ecase *host* - (:jvm "import ~A.*;~2%") - (:cli "using ~A;~2%"))) - -(defun system-import-string () - (ecase *host* - (:jvm "") - (:cli "using System;~2%"))) - -(defun var-member-name (symbol) - (format nil "~A__~A" - (munge-name (package-name (symbol-package symbol))) - (munge-name (symbol-name symbol)))) - -(defun accessor-member-name (symbol) - (format nil "ACC__~A" - (subseq (symbol-name symbol) 1))) - -(defun symbol-member-name (symbol) - (format nil "SYM__~A" - (munge-name (symbol-name symbol)))) - -(defun keyword-member-name (symbol) - (format nil "KEY__~A" - (munge-name (symbol-name symbol)))) - -(defun munge-name (name) - (setf name (string name)) - (when (digit-char-p (char name 0)) - (setf name (concatenate 'string "NUM__" name))) - (labels ((rep (c) - (second (assoc c - '((#\- #\_) - (#\. #\_) - (#\+ "PLUS__") - (#\> "GT__") - (#\< "LT__") - (#\= "EQ__") - (#\~ "TILDE__") - (#\! "BANG__") - (#\@ "AT__") - (#\# "SHARP__") - (#\$ "DOLLAR__") - (#\% "PCT__") - (#\^ "CARAT__") - (#\& "AMP__") - (#\* "STAR__") - (#\{ "LBRACE__") - (#\} "RBRACE__") - (#\[ "LBRACKET__") - (#\] "RBRACKET__") - (#\/ "SLASH__") - (#\\ "BSLASH__") - (#\? "QMARK__"))))) - (translate (c) - (let ((r (rep c))) - (or r c)))) - (if (find-if #'rep name) - (format nil "~{~A~}" (map 'list #'translate name)) - name))) - -(defun begin-static-block (class-name) - (ecase *host* - (:jvm (format nil "static {~%")) - (:cli (format nil "static ~A(){~%" class-name)))) - - -(defun compile-to (host package-name class-name &rest files) - (let* ((*host* host) - (orig-package *package*) - (*features* (list* :clojure host *features*)) - (outpath (make-pathname - :name class-name - :type (file-type) - :defaults (merge-pathnames - (make-pathname :directory - (list* :relative (file-path package-name))) - *clojure-target-path*))) - (*symbols* (list '|t|)) - (*defns* nil) - (*defvars* nil) - (*vars* nil) - (*keywords* nil) - (*accessors* nil)) - (with-open-file (target outpath :direction :output :if-exists :supersede) - (format target "/* Generated by Clojure */~2%") - (format target (package-open-format-string) package-name) - (format target (system-import-string)) - (format target (package-import-format-string) "clojure.lang") - (format target "public class ~A{~%" class-name) - (unwind-protect - (dolist (file files) - (with-open-file (source (merge-pathnames file *clojure-source-path*)) - (labels - ((process-form (form) - (case (first form) - (|in-module| (setf *package* (find-package (second form)))) - (|import| (|import| (second form) (second (third form)))) - ((|block|) (mapc #'process-form (rest form))) - ((|defn*| |def| |defparameter| |defmain|) - (let* ((target-sym (second form))) - (princ target-sym) - (terpri) - (let ((*standard-output* target)) - (convert form)))) - (t - (if (macro-function (car form)) - (process-form (macroexpand-1 form)) - (error "Unsupported form ~A" form)))))) - (let ((*readtable* (copy-readtable nil)) - (*imports* (make-hash-table :test #'equal))) - (setf (readtable-case *readtable*) :preserve) - (do ((form (read source nil 'eof) (read source nil 'eof))) - ((eql form 'eof)) - (process-form form)))))) - (setf *package* orig-package)) - (dolist (sym *symbols*) - (format target "static Symbol ~A = Symbol.intern(~S);~%" - (symbol-member-name sym) - (munge-name (symbol-name sym)))) - (dolist (keyword *keywords*) - (format target "static Keyword ~A = (Keyword)Symbol.intern(~S);~%" - (keyword-member-name keyword) - (concatenate 'string ":" (munge-name (symbol-name keyword))))) - (dolist (var *vars*) - (format target "static Var ~A = Namespace.intern(~S,~S);~%" - (var-member-name var) - (munge-name (package-name (symbol-package var))) - (munge-name (symbol-name var)))) - (dolist (accessor *accessors*) - (format target "static Accessor ~A = (Accessor)Symbol.intern(~S);~%" - (accessor-member-name accessor) - (symbol-name accessor))) - (format target "~Atry{~%" (begin-static-block class-name)) - ;(format target "~%static public void __load() ~A{~%" (exception-declaration-string lang)) - (dolist (var *defns*) - (format target "Namespace.intern(~S,~S).bind(new ~A());~%" - (munge-name (package-name (symbol-package var))) - (munge-name (symbol-name var)) - (munge-name var))) - (dolist (var-and-init *defvars*) - (let ((var (@ :var var-and-init)) - (init (@ :init var-and-init))) - (format target "Namespace.internVar(~S,~S).bind((new ~A()).invoke());~%" - (munge-name (package-name (symbol-package var))) - (munge-name (symbol-name var)) - (munge-name init)))) - (format target "}catch(Exception e){}~%}~%") - ;(format target "}~%") - (format target "public static void __init(){}~%") - (format target "}~%") - (format target "~A~%" (package-close-string))))) - -(defun convert (form) - (let ((tree (analyze :top (macroexpand form))) - (*next-id* 0)) - ;(print tree) - (format t "/* Generated by Clojure from the following Lisp:~%") - (pprint form) - (format t "~%~%*/~2%") - (emit :top tree) - ;tree - )) - -(defun get-next-id () - (incf *next-id*)) - -(defun listize (x) - (if (listp x) - x - (list x))) - -(defun |import| (package-string class-symbols) - (dolist (c (listize class-symbols)) - (when (gethash (symbol-name c) *imports*) - (error "Class ~A already imported from ~A" (symbol-name c) (gethash (symbol-name c) *imports*))) - (setf (gethash (symbol-name c) *imports*) package-string))) - -(defun fully-qualified-class-name (class-name) - (let ((package-string (gethash class-name *imports*))) - (if package-string - (let* ((assembly-point (position #\, package-string)) - (package (subseq package-string 0 assembly-point))) - (concatenate 'string package "." class-name - (when assembly-point (subseq package-string assembly-point)))) - (error "Can't find class ~A in imports" class-name)))) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; macros ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defmacro |defn| (name params &body body) - `(|defn*| ,name (,params ,@body))) - -(defmacro |fn| (params &body body) - `(|fn*| (,params ,@body))) - -(defmacro |when| (test &rest result) - `(|if| ,test (|block| ,@result))) - -(defmacro |unless| (test &rest result) - `(|if| ,test nil (|block| ,@result))) - -(defmacro |cond| (&rest args) - (if (null args) - nil - (let ((clause (first args))) - (if (rest clause) - `(|if| ,(first clause) - (|block| ,@(rest clause)) - (|cond| ,@(rest args))) - `(|or| ,(first clause) - (|cond| ,@(rest args))))))) - -(defun pairize (lst) - (if (null lst) - nil - (cons (cons (first lst) (second lst)) - (pairize (rest (rest lst)))))) - -(defmacro |set*| (&rest args) - (unless (evenp (length args)) - (error "odd number of arguments")) - (labels ((recurse (sets) - (when sets - (cons (list '|set| (first sets) (second sets)) - (recurse (rest (rest sets))))))) - (when args - `(|block| ,@(recurse args))))) - -(defmacro |pset| (&rest args) - (unless (evenp (length args)) - (error "odd number of arguments")) - (let* ((pairs (pairize args)) - (syms (mapcar #'(lambda (x) (declare (ignore x))(gensym)) - pairs))) - `(|let| ,(mapcar #'list - syms - (mapcar #'rest pairs)) - (|set*| ,@(mapcan #'list - (mapcar #'first pairs) - syms))))) - -(defmacro |do| (binds (test &optional result) &rest body) - `(|let| ,(mapcar #'list (mapcar #'first binds) (mapcar #'second binds)) - (|loop| - (|when| ,test - (|break| ,result)) - ,@body - (|pset| ,@(mapcan #'list - (mapcar #'first binds) - (mapcar #'third binds)))))) - - - -(defmacro |defcomparator| (op prim) - `(|defn*| ,op - ((x) t) - ((x y) - (,prim x y)) - ((x y & rest) - (|and| (,prim x y) - (|apply| ,op y rest))))) - -;(defmacro |block| (&body body) -; `(|let| nil ,@body)) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; analyze and emit ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defun analyze (context form) - "context - one of :top :return :statement :expression :fn" - (cond - ((consp form) (analyze-op context (first form) form)) - ((or (null form)(eql '|nil| form)) nil) - ((eql '|t| form) t) - ((symbolp form) (analyze-symbol context form)) - (t form))) - -(defun analyze-op (context op form) - (case op - (quote (analyze-quote context form)) - (|defn*| (analyze-defn* context form)) - (|def| (analyze-def context form)) - (|defmain| (analyze-defmain context form)) - (|block| (analyze-block context form)) - (|fn*| (analyze-fn* context form)) - (|if| (analyze-if context form)) - ((|not| |null|) (analyze-not context form)) - (|and| (analyze-and context form)) - (|or| (analyze-or context form)) - (|set| (analyze-set context form)) - (|let| (analyze-let context form)) - (|letfn| (analyze-letfn context form)) - (|let*| (analyze-let* context form)) - (|loop| (analyze-loop context form)) - (|break| (analyze-break context form)) - (|try| (analyze-try context form)) - (|bind| (analyze-bind context form)) - (|instance?| (analyze-instance? context form)) - ((|char| |boolean| |byte| |short| |int| |long| |float| |double|) - (analyze-cast context form)) - (t (analyze-invoke context op form)))) - -(defmacro emit-to-string (&body body) - `(with-output-to-string (s) - (let ((*standard-output* s)) - ,@body))) - -(defun emit (context expr) - (cond - ((null expr) (emit-nil context)) - ((typep expr 'hash-table) ;objs - (ccase (@ :type expr) - (:defn* (emit-defn* context expr)) - (:main (emit-main context expr)) - (:fn* (emit-fn* context expr)) - (:binding (emit-binding context expr)) - (:accessor (emit-accessor context expr)) - (:keyword (emit-keyword context expr)) - (:global-binding (emit-global-binding context expr)) - (:block (emit-block context expr)) - (:invoke (emit-invoke context expr)) - (:let (emit-let context expr)) - (:if (emit-if context expr)) - (:not (emit-not context expr)) - (:or (emit-or context expr)) - (:and (emit-and context expr)) - (:set (emit-set context expr)) - (:loop (emit-loop context expr)) - (:break (emit-break context expr)) - (:try (emit-try context expr)) - (:bind(emit-bind context expr)) - (:quoted-aggregate (emit-quoted-aggregate context expr)) - (:host-symbol (emit-host-static-member context expr)) - (:cast (emit-cast context expr)) - (:instance? (emit-instance? context expr)))) - (t (emit-other context expr)))) - -(defun emit-other (context expr) - (ccase context - (:statement);no-op - (:return (emit-return expr)) - (:expression - (cond - ((null expr) (emit-nil context)) - ((eql t expr) (format t "RT.T")) - ((stringp expr) (format t "~S" expr)) - ((characterp expr) (format t "RT.box('~A')" expr)) - ((numberp expr) - (case expr - (0 (format t "Num.ZERO")) - (1 (format t "Num.ONE")) - (t (format t "Num.from(~A)" expr)))) - ((symbolp expr) - (cond - ((keywordp expr) - (format t "~A" (keyword-member-name expr))) - ((accessor? expr) - (format t "~A" (accessor-member-name expr))) - ((host-symbol? expr) - (multiple-value-bind (class-name member-name) - (host-class-and-member-strings expr) - (format t "Reflector.getStaticField(~S,~S)" member-name class-name))) - (t (format t "~A" (var-member-name expr))))) - ((consp expr) - (format t "RT.arrayToList(new Object[]{~{~A~^, ~}})" - (mapcar (lambda (e) - (emit-to-string (emit :expression e))) - expr))))))) - -(defun emit-host-static-member (context expr) - (ccase context - (:statement);no-op - (:return (emit-return expr)) - (:expression - (multiple-value-bind (class-name member-name) - (host-class-and-member-strings (@ :symbol expr)) - (format t "Reflector.getStaticField(~S,~S)" member-name class-name))))) - -(defun emit-return (expr) - (format t "return ") - (emit :expression expr) - (format t ";~%")) - - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; quote ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defun analyze-quote (context form) - (let ((q (second form))) - (cond - ((symbolp q) - (cond - ((keywordp q) - (register-keyword-reference q)) - ((host-symbol? q) (error "Can't quote host symbols")) - ((accessor? q) - (register-accessor-reference q)) - (t (register-var-reference q))) - q) - ((atom q) q) - (t - (let* ((ql (newobj :type :quoted-aggregate :symbol (gensym "QA__") :form q))) - (register-quoted-aggregate ql) - ql))))) - -(defun emit-quoted-aggregate (context expr) - (ccase context - (:return (emit-return expr)) - (:expression - (format t "~A" (munge-name (@ :symbol expr)))))) - - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; cast/instance? ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defun analyze-cast (context form) - (declare (ignore context)) - (newobj :type :cast - :to (first form) - :expr (analyze :expression (macroexpand (second form))))) - -(defun emit-cast (context expr) - (ccase context - (:return (emit-return expr)) - (:expression - (format t "RT.box(RT.~ACast(" (symbol-name (@ :to expr))) - (emit :expression (@ :expr expr)) - (format t "))")))) - -(defun analyze-instance? (context form) - (declare (ignore context)) - (assert (host-type-symbol? (third form))) - (newobj :type :instance? - :expr (analyze :expression (macroexpand (second form))) - :sym (analyze-symbol :statement (third form)))) - -(defun emit-instance? (context expr) - (ccase context - (:return (emit-return expr)) - (:expression - (format t "(") - (emit :expression (@ :expr expr)) - (format t" ~A ~A?RT.T:null)" - (instanceof-string) - (multiple-value-bind (class-name member-name) - (host-class-and-member-strings (@ :symbol (@ :sym expr))) - ;trim off any assembly cruft - (subseq class-name 0 (position #\, class-name))))))) - -(defun instanceof-string () - (ccase *host* - (:jvm "instanceof") - (:cli "is"))) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; set ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defun analyze-set (context form) - ;expecting one of - ;(set local val) => local = val; - ;(set var val) => var.setValue(val); - ;(set class.member val) => Reflector.setStaticField("member","java.lang.Class",val); - ;(set (:key x) val) => key.invoke(x,val); - ;(set (.accessor x) val) => accessor.invoke(x, val); - ;(set (global x y z ...) val)) => global.setfn.invoke(val, x, y, z) - (declare (ignore context)) - (let ((val (analyze :expression (macroexpand (third form))))) - (if (atom (second form)) - (let ((target (analyze-symbol :statement (second form)))) - (when (eql (@ :type target) :binding) - (setf (@ :assigned? target) t)) - (newobj :type :set - :target target - :val val)) - (let* ((place (second form)) - (name (analyze-symbol :statement (first place))) - (args (mapcar (lambda (e) - (analyze :expression (macroexpand e))) - (rest place)))) - (ccase (@ :type name) - ((:keyword :accessor :global-binding) - (newobj :type :set - :name name - :args args - :val val))))))) - -(defun emit-set (context expr) - (if (eql context :return) - (emit-return expr) - (progn - (when (member context '(:expression :fn)) - (format t "(")) - (let ((val (@ :val expr)) - (name (@ :name expr))) - (if name ;must be a place - (ccase (@ :type name) - ((:keyword :accessor) - (emit :expression name) - (format t ".invoke(") - (emit :expression (first (@ :args expr))) - (format t ", ") - (emit :expression val) - (format t ")")) - (:global-binding - (format t "~A.setfn.invoke(" (var-member-name (@ :symbol name))) - (emit :expression val) - (format t "~{, ~A~}" - (mapcar (lambda (e) - (emit-to-string (emit :expression e))) - (@ :args expr))) - (format t ")"))) - (let ((target (@ :target expr))) - (ccase (@ :type target) - (:binding - (emit :expression target) - (format t " = ") - (emit :expression val)) - (:global-binding - (format t "~A.setValue(" (var-member-name (@ :symbol target))) - (emit :expression val) - (format t ")")) - (:host-symbol - (multiple-value-bind (class-name member-name) - (host-class-and-member-strings (@ :symbol target)) - (format t "Reflector.setStaticField(~S, ~S, " member-name class-name) - (emit :expression val) - (format t ")"))))))) - (when (member context '(:expression :fn)) - (format t ")")) - (when (eql context :statement) - (format t ";~%"))))) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; if ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defun analyze-if (context form) - (if (eql (second form) '|t|) - ;optimize macro-generated (if t ...) forms - (analyze context (macroexpand (third form))) - (let* ((test (analyze :expression (macroexpand (second form)))) - (negate (and (hash-table-p test)(eql :not (@ :type test))))) - (newobj :type :if - :test (if negate (@ :expr test) test) - :comp (if negate "==" "!=") - :then (analyze context (macroexpand (third form))) - :else (when (fourth form) - (analyze context (macroexpand (fourth form)))) - :else-p (= 4 (length form)))))) - -(defun emit-if (context expr) - (let ((test (@ :test expr)) - (then (@ :then expr)) - (else (@ :else expr)) - (else-p (@ :else-p expr)) - (comp (@ :comp expr))) - (ccase context - (:expression - (format t "(") - (emit :expression test) - (format t " ~A null?" comp) - (emit :expression then) - (format t ":") - (emit :expression else) - (format t ")")) - (:statement - (format t "if(") - (emit :expression test) - (format t " ~A null)~%{~%" comp) - (emit context then) - (format t "}~%") - (when (and else-p else) - (format t "else~%{~%") - (emit context else) - (format t "}~%"))) - (:return - (format t "if(") - (emit :expression test) - (format t " ~A null)~%{~%" comp) - (emit context then) - (format t "}~%") - (format t "else~%{~%") - (if else-p - (emit context else) - (format t "return null;~%")) - (format t "}~%"))))) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; not/null ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defun analyze-not (context form) - (declare (ignore context)) - (newobj :type :not :expr (analyze :expression (macroexpand (second form))))) - -(defun emit-not (context expr) - (ccase context - ;just for side effects if statement, no negation - (:return (emit-return expr)) - (:statement - (emit context (@ :expr expr))) - ((:fn :expression) - (format t "((") - (emit :expression (@ :expr expr)) - (format t ")==null?RT.T:null)")))) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; or ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defun analyze-or (context form) - (let ((temp (newobj :type :binding :symbol (gensym)))) - (unless (eql context :statement) - (register-local-binding temp)) - (newobj :type :or - :temp temp - :exprs (mapcar (lambda (e) - (analyze :expression (macroexpand e))) - (rest form))))) - -(defun emit-or (context expr) - (let ((temp (@ :temp expr)) - (exprs (@ :exprs expr))) - (ccase context - (:return (emit-return expr)) - (:statement - (format t "if(~{(~A != null)~^||~})~%;~%" - (mapcar (lambda (e) - (emit-to-string (emit :expression e))) - exprs))) - ((:expression :fn) - (format t "((~{((~A = ~A) != null)~^||~})?~A:null)" - (mapcan (lambda (e) - (list (binding-name temp) (emit-to-string (emit :expression e)))) - exprs) - (binding-name temp)))))) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; and ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - - -(defun analyze-and (context form) - (declare (ignore context)) - (newobj :type :and - :exprs (mapcar (lambda (e) - (analyze :expression (macroexpand e))) - (rest form)))) - -(defun emit-and (context expr) - (let ((exprs (@ :exprs expr))) - (ccase context - (:return (emit-return expr)) - (:statement - (format t "if(~{(~A != null)~^&&~})~%;~%" - (mapcar (lambda (e) - (emit-to-string (emit :expression e))) - exprs))) - ((:expression :fn) - (format t "((~{(~A != null)~^&&~})?~A:null)" - (mapcar (lambda (e) - (emit-to-string (emit :expression e))) - (butlast exprs)) - (emit-to-string (emit :expression (first (last exprs))))))))) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; invoke ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defun analyze-invoke (context op form) - (declare (ignore context)) - ;if we hit this unspecialized method, it is not a special op, presume function invocation - (newobj :type :invoke - :fexpr (if (symbolp op) - (analyze-symbol :fn op) - (analyze :fn op)) - :args (mapcar (lambda (e) - (analyze :expression e)) - (rest form)))) - -(defun emit-invoke (context expr) - (ccase context - (:statement - (emit :expression expr) - (format t ";~%")) - (:return - (emit-return expr)) - ((:expression :fn) - (let* ((fexpr (@ :fexpr expr)) - (global-binding? (eql :global-binding (@ :type fexpr))) - (host-symbol? (eql :host-symbol (@ :type fexpr))) - (static-method? (will-be-static-method fexpr)) - (args (@ :args expr))) - (cond - (host-symbol? - (multiple-value-bind (class-name member-name) - (host-class-and-member-strings (@ :symbol fexpr)) - (format t "Reflector.invokeStaticMethod(~S,~S,new Object[]{~{~A~^,~}})" - member-name - class-name - (mapcar (lambda (e) - (emit-to-string - (emit :expression e))) - args)))) - (t - (when (not (or global-binding? static-method?)) - (format t "((IFn)")) - (emit :fn fexpr) - (when (not (or global-binding? static-method?)) - (format t ")")) - (unless static-method? - (format t ".invoke")) - (format t "(") - (when static-method? - (let ((closes (@ :closes (first (@ :methods (@ :fn fexpr)))))) - (format t "~{~A~^, ~}" - (mapcar (lambda (b) - (binding-name b)) - closes)))) - (format t "~{~A~^, ~}" - (mapcar (lambda (e) - (emit-to-string - (emit :expression e))) - args)) - (format t ")"))))))) - - - -(defun emit-global-binding (context expr) - (ccase context - (:return - (emit-return expr)) - ((:expression :return) - (format t "~A.getValue()" (var-member-name (@ :symbol expr)))) - (:fn - (format t "~A.fn()" (var-member-name (@ :symbol expr)))) - (:statement))) - -(defun emit-accessor (context expr) - (declare (ignore context)) - (format t "~A" (accessor-member-name (@ :symbol expr)))) - -(defun emit-keyword (context expr) - (declare (ignore context)) - (format t "~A" (keyword-member-name (@ :symbol expr)))) - -(defun emit-new-closure-instance (name-binding-fn) - (format t "(new ~A(~{~A~^, ~}))" - (binding-name name-binding-fn) - (mapcar (lambda (b) - (binding-name b)) - (@ :closes (first (@ :methods (@ :fn name-binding-fn))))))) - -(defun emit-binding (context expr) - (ccase context - (:statement) ;var statement is a no-op - ((:expression :fn) - (if (and (@ :anonymous-fn? expr) (not (will-be-static-method expr))) - (emit-new-closure-instance expr) - (format t "~A~:[~;.val~]" (binding-name expr) (needs-box expr)))) - (:return (emit-return expr)))) - -;;;;;;;;;;;;;;;;;;;;;;;;;; let ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defun normalize-let-bindings (binding-list) - (mapcar (lambda (b) - (if (atom b) - (list b nil) - b)) - binding-list)) - -(defun analyze-let (context form) - (let ((bindings (normalize-let-bindings (second form))) - (body (rest (rest form)))) - (cond - ;special case of (let () expr) ==> expr - ((not (or bindings (> (length body) 1))) - (analyze context (macroexpand (third form)))) - ((eql context :expression) - (analyze :expression `((|fn*| (,(mapcar #' first bindings) ,@body)) - ,@(mapcar #'second bindings)))) - (t (let* ((binding-inits - ;init exprs are analyzed prior to adding bindings to env - (mapcar (lambda (b) - (newobj :binding (newobj :type :binding :symbol (first b)) - :init (analyze :expression (second b)))) - bindings)) - (*var-env* *var-env*)) - (mapc (lambda (binit) - (register-local-binding (@ :binding binit)) - (add-to-var-env (@ :binding binit))) - binding-inits) - (newobj :type :let - :binding-inits binding-inits - :body (analyze-body context body))))))) - -(defun analyze-let* (context form) - (let ((bindings (normalize-let-bindings (second form))) - (body (rest (rest form)))) - (cond - ;special case of (let () expr) ==> expr - ((not (or bindings (> (length body) 1))) - (analyze context (macroexpand (third form)))) - ((eql context :expression) - (analyze :expression `((|fn*| (() ,form))))) - (t (let* ((*var-env* *var-env*) - (binding-inits - (mapcar (lambda (b) - ;sequential binding - (let ((binit - (newobj :binding (newobj :type :binding :symbol (first b)) - :init (analyze :expression (second b))))) - (register-local-binding (@ :binding binit)) - (add-to-var-env (@ :binding binit)) - binit)) - bindings))) - (newobj :type :let - :binding-inits binding-inits - :body (analyze-body context body))))))) - -(defun analyze-letfn (context form) - (cond - ((eql context :expression) - (analyze :expression `((|fn*| (() ,form))))) - (t - (let* ((*var-env* *var-env*) - (binding-exprs - ;adding all bindings to env first, mark as assigned to allow for recursion and mutual reference - (mapcar (lambda (b) - (destructuring-bind (name params &rest body) b - (let ((binding (newobj :type :binding :symbol name - :assigned? t - ))) - (register-local-binding binding) - ;(register-nested-fn-binding binding) - (add-to-var-env binding) - ;don't analyze lambdas yet - (list binding `(|fn*| (,params ,@body)))))) - (second form)))) - (newobj :type :let - :binding-inits (mapcar (lambda (be) - (let ((binding (first be)) - (fn (analyze :expression (second be)))) - (setf (@ :fn binding) fn) - (setf (@ :binding fn) binding) - (newobj :binding binding :init fn))) - binding-exprs) - :body (analyze-body context (rest (rest form)))))))) - -(defun emit-let (context expr) - (let ((binding-inits (@ :binding-inits expr)) - (body (@ :body expr))) - (dolist (bi binding-inits) - (unless (will-be-static-method (@ :binding bi)) - (emit :expression (@ :binding bi)) - (format t " = ") - (emit :expression (@ :init bi)) - (format t ";~%"))) - (emit-body context body))) - -(defun analyze-body (context exprs) - (when exprs - (case context - (:statement - (mapcar (lambda (expr) - (analyze :statement (macroexpand expr))) - exprs)) - (:return - (append (mapcar (lambda (expr) - (analyze :statement (macroexpand expr))) - (butlast exprs)) - (list (analyze :return (macroexpand (first (last exprs)))))))))) - -(defun emit-body (context body) - (case context - (:return - (dolist (e (butlast body)) - (emit :statement e)) - (if body - (emit :return (first (last body))) - (format t "return null;~%"))) - (:statement - (dolist (e body) - (emit :statement e))))) - - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; bind ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defun analyze-bind (context form) - (let ((bindings (normalize-let-bindings (second form))) - (body (rest (rest form)))) - (ccase context - ((:expression :fn) - (analyze :expression `((|fn*| (() ,form))))) - ((:statement :return) - (let* ((binding-inits - (mapcar (lambda (b) - (register-var-reference (first b)) - (newobj :binding (newobj :type :global-binding :symbol (first b)) - :init (analyze :expression (second b)))) - bindings))) - ;(register-needs-tls) - (newobj :type :bind - :binding-inits binding-inits - :body (analyze-body context (macroexpand body)))))))) - -(defun emit-bind (context expr) - (ccase context - ((:statement :return) - (let ((binding-inits (@ :binding-inits expr)) - (body (@ :body expr))) - (format t "try {~%") - (dolist (bi binding-inits) - (format t "~A.pushDynamicBinding(" (var-member-name (@ :symbol (@ :binding bi)))) - (emit :expression (@ :init bi)) - (format t ");~%")) - (emit-body context body) - (format t "}~%finally {~%") - (dolist (bi binding-inits) - (format t "~A.popDynamicBinding();~%" (var-member-name (@ :symbol (@ :binding bi))))) - (format t "}~%"))))) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; block ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defun emit-block (context expr) - (when (@ :body expr) - ;(format t "{~%") - (emit-body context (@ :body expr)) - ;(format t "}~%") - )) - -(defun analyze-block (context form) - (cond - ((null (rest form)) - (analyze context '|nil|)) - ((null (rest (rest form))) - (analyze context (macroexpand (second form)))) - (t (ccase context - (:expression (analyze context `((|fn*| (() ,@(rest form)))))) - ((:statement :return) (newobj :type :block - :body (analyze-body context (rest form)))))))) - - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; loop/break ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defvar *loop-context*) - -(defun analyze-loop (context form) - (ccase context - ((:expression :fn) - (analyze :expression `((|fn*| (() ,form))))) - ((:statement :return) - (newobj :type :loop - :body (analyze-body context (rest form)))))) - -(defun emit-loop (context expr) - (let ((*loop-context* context)) - (format t "for(;;)~%{~%") - (emit-body :statement (@ :body expr)) - (format t "}~%"))) - -(defun analyze-break (context form) - (ccase context - ((:statement :return) - (newobj :type :break - :result (analyze context (macroexpand (second form))))))) - -(defun emit-break (context expr) - (declare (ignore context)) - (ccase *loop-context* - (:statement - (emit :statement (@ :result expr)) - (format t "break;~%")) - (:return - (emit :return (@ :result expr))))) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; try ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -#| -(try - (body 1 2 3) - (some-catch-code-presuming-ex-bound-to-exception ...) - (do-something-finally)) -|# - -(defun analyze-try (context form) - (ccase context - ((:expression :fn) - (analyze :expression `((|fn*| (() ,form))))) - ((:statement :return) - (let* ((catch-clause (macroexpand (third form))) - (ex-binding (when catch-clause - (newobj :type :binding - :symbol '|ex| - :ex-name? t)))) - (newobj :type :try - :body (analyze context (macroexpand (second form))) - :catch (when catch-clause - (let ((*var-env* *var-env*)) - (register-local-binding ex-binding) - (add-to-var-env ex-binding) - (analyze context catch-clause))) - :ex ex-binding - :finally (analyze :statement (macroexpand (fourth form)))))))) - -(defun emit-try (context expr) - (ccase context - ((:statement :return) - (let ((body (@ :body expr)) - (catch-clause (@ :catch expr)) - (ex (@ :ex expr)) - (finally-clause (@ :finally expr))) - (format t "try{~%") - (emit context body) - (format t "}~%") - (when catch-clause - (format t "catch (Exception ~A){~%" (binding-name ex)) - (emit context catch-clause) - (format t "}~%")) - (format t "finally{~%") - (emit :statement finally-clause) - (format t "}~%"))))) - - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; defmain ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defun analyze-defmain (context form) - (ccase context - (:top - (register-var-reference (second form)) - (newobj :type :main - :fname (second form))))) - -(defun emit-main (context expr) - (ccase context - (:top - (format t "static public void ~A(String[] args){~%try{~%~A.fn().invoke(args);~%}~%catch(Exception ex){}~%}~%" - (main-string) (var-member-name (@ :fname expr)))))) - -(defun main-string () - (ccase *host* - (:jvm "main") - (:cli "Main"))) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; defn ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defun analyze-defn* (context form) - (assert (eql context :top)) - (let* ((*quoted-aggregates* nil) - (*nested-fn-bindings* nil) - (fn (analyze :top `(|fn*| ,@(rest (rest form)))))) - (setf (@ :quoted-aggregates fn) *quoted-aggregates*) - (setf (@ :nested-fn-bindings fn) *nested-fn-bindings*) - (newobj :type :defn* - :name (second form) - :fn fn))) - -(defun register-defn (name) - (push name *defns*)) - -(defun emit-defn* (context expr) - (declare (ignore context)) - (let ((name (@ :name expr))) - (register-defn name) - (emit-fn-declaration :top (munge-name name) (@ :fn expr) nil))) - -(defun emit-nil (context) - (ccase context - (:expression (format t "null")) - (:statement) - (:return (emit-return nil)))) - -(defun reference-var (sym) - (let ((b (first (member sym *var-env* :key (lambda (b) - (@ :symbol b)))))) - (labels - ((check-closed (b frame) - (when (and b frame - (not (member b (@ :local-bindings frame)))) ;closed over - (setf (@ :closed? b) t) - (pushnew b (@ :closes frame)) - (check-closed b (@ :parent frame))))) - (check-closed b *frame*)) - b)) - -(defun add-to-var-env (b) - (push b *var-env*)) - -(defun register-nested-fn-binding (b) - (push b *nested-fn-bindings*)) - -(defun analyze-fn* (context form) - (let ((fn (newobj :type :fn* - :methods (mapcar (lambda (m) - (analyze-method (first m) (rest m))) - (rest form))))) - (if (member context '(:return :expression :fn)) - ;presume anonymous fn - (let ((b (newobj :type :binding - :fn fn - :symbol (gensym "FN__") - :anonymous-fn? t - :value-taken? (not (eql context :fn))))) - (setf (@ :binding fn) b) - (register-nested-fn-binding b) - b) - fn))) - -(defun emit-fn* (context expr) - (emit-binding context (@ :binding expr))) - -(defun analyze-method (params body) - (let* ((*frame* (newobj :parent *frame*)) - (*var-env* *var-env*) - (state :reqs)) - (flet ((create-param-binding (p) - (let ((b (newobj :type :binding :symbol p :param? t))) - (add-to-var-env b) - (register-local-binding b) - b))) - (dolist (p params) - (case p - (& (setf state :rest)) - (t (case state - (:reqs - (push (create-param-binding p) (@ :reqs *frame*))) - (:rest - (setf (@ :rest *frame*) (create-param-binding p))))))) - - (when (> (length (@ :reqs *frame*)) +MAX-POSITIONAL-ARITY+) - (error "sorry, can't have more than ~S required args" +MAX-POSITIONAL-ARITY+)) - (setf (@ :reqs *frame*) (nreverse (@ :reqs *frame*))) - (setf (@ :body *frame*) (analyze :return `(|block| ,@body))) - - *frame*))) - -(defun analyze-def (context form) - (assert (eql context :top)) - (destructuring-bind (name init init-provided) (rest form) - (newobj :type :def - :name name - :init-fn (when init-provided - (analyze :top `(|fn*| (() ,init))))))) - -(defun needs-box (binding) - (and binding (@ :closed? binding) (@ :assigned? binding))) - -(defun binding-type-decl (binding) - (cond - ((needs-box binding) "Box") - (t "Object"))) - -(defun fn-decl-string () - (case *host* - (:jvm "static") - (:cli ""))) - -(defun extends-string () - (case *host* - (:jvm "extends") - (:cli ":"))) - -(defun overrides-string () - (case *host* - (:jvm "") - (:cli "override "))) - -(defun fn-name (fn) - (if (@ :rest fn) - "doInvoke" - "invoke")) - -(defun exception-declaration-string () - (case *host* - (:jvm "throws Exception") - (:cli ""))) - -(defun binding-name (b) - (format nil "~A~@[__~A~]" - (munge-name (@ :symbol b)) - (@ :id b))) - -(defun can-be-static-method (fn) - (and (= (length (@ :methods fn)) 1) - (not (@ :rest (first (@ :methods fn)))))) - -(defun will-be-static-method (b) - (and (eql (@ :type b) :binding) - (@ :fn b) - (not (or (@ :value-taken? b) (@ :closed? b))) - (can-be-static-method (@ :fn b)))) - -(defun emit-binding-declaration (b &optional (init nil init-supplied)) - (format t "~A " (binding-type-decl b)) - (format t "~A" - (binding-name b)) - (cond - ((needs-box b) - (format t " = new Box(~A)" (or init "null"))) - (init-supplied (format t " = ~A" (or init "null")))) - (format t ";~%")) - -(defun munge-closed-over-assigned-arg (b) - (concatenate 'string (munge-name (@ :symbol b)) "__arg")) - -(defun fn-base-class (fn) - (let ((rest-method (find-if (lambda (m) - (@ :rest m)) - (@ :methods fn)))) - (if rest-method - (format nil "RestFn~A" (length (@ :reqs rest-method))) - "AFn"))) - -(defun emit-fn-declaration (context name fn as-static-method?) - (let* ((methods (@ :methods fn)) - (base (fn-base-class fn)) - (closes-decls (mapcan (lambda (b) - (list (binding-type-decl b) (binding-name b))) - ;expecting only one method if closure - (@ :closes (first methods))))) - (unless as-static-method? - ;emit a class declaration - (format t "~@[~A ~]public class ~A ~A ~A{~%" - (fn-decl-string) - name (extends-string) base) - ;and members and a ctor if closure - (when closes-decls - (format t "~{~A ~A;~%~}" closes-decls) - (format t "public ~A (~{~A ~A~^, ~}){~%" name closes-decls) - (format t "~{this.~A = ~A;~%~}" - (mapcan - (lambda (b) - (let ((s (binding-name b))) - (list s s))) - (@ :closes (first methods)))) - (format t "}~%"))) - - (when as-static-method? - ;function gets the supplied name, prefix params with closed vars - (format t "static public Object ~A(~{~A ~A~^, ~}" - name - closes-decls)) - - (dolist (m methods) - ;if static, we are expecting this to run once - (unless as-static-method? - (format t "~Apublic Object ~A(" (overrides-string) (fn-name m))) - - ;params - (let ((rest (@ :rest m))) - (format t "~{~A ~A~@[~A~]~^, ~}" - (mapcan (lambda (b) - (list - (binding-type-decl b) - (binding-name b) - (when (needs-box b) - "__arg"))) - (@ :reqs m))) - (when rest - (when (@ :reqs m) - (format t ", ")) - (format t "ISeq ~A~@[~A~]" - (binding-name rest) - (when (needs-box rest) "__arg")))) - - (format t ") ~A ~%{~%" (exception-declaration-string)) - - ;tls - ;(when (@ :needs-tls m) - ; (format t "if(__tld == null) __tld = ThreadLocalData.get();~%")) - - ;parameter binding declarations,if needed - ;reqs - (dolist (b (@ :reqs m)) - (when (needs-box b) - (emit-binding-declaration b (munge-closed-over-assigned-arg b)))) - - ;rest - (let ((rest (@ :rest m))) - (when (needs-box rest) - (emit-binding-declaration rest (munge-closed-over-assigned-arg rest)))) - - ;non-param local bindings - (dolist (b (@ :local-bindings m)) - ; fixup the names, numbering all locals - (unless (@ :param? b) - (setf (@ :id b) (get-next-id)) - (unless (or (@ :anonymous-lambda? b) - (@ :ex-name? b) - (will-be-static-method b)) - (emit-binding-declaration b)))) - - ;body - (emit :return (@ :body m)) - - ;end of invoke function - (format t "}~%")) - - - (unless as-static-method? - ;these will only be set on toplevel defn - (dolist (fb (@ :nested-fn-bindings fn)) - (emit-fn-declaration :statement - (binding-name fb) - (@ :fn fb) - (will-be-static-method fb))) - (dolist (qa (@ :quoted-aggregates fn)) - (with-slots (symbol form) qa - (format t "static public Object ~A = " (munge-name (@ :symbol qa))) - (emit :expression (@ :form qa)) - (format t ";~%"))) - ;(when (eql context :top) - ;anonymous lambdas are named w/gensyms - ;todo - change, this is fragile - ; (when (and (symbolp name) (not (symbol-package name))) - ; (format t "static public IFn fn = new ~A();~%" name))) - ;end of class - (format t "}~%")))) - -(defun register-var-reference (sym) - (pushnew sym *vars*)) - -(defun register-quoted-aggregate (qa) - (pushnew qa *quoted-aggregates*)) - -(defun register-accessor-reference (sym) - (pushnew sym *accessors*)) - -(defun register-keyword-reference (sym) - (pushnew sym *keywords*)) - -;(defun register-needs-tls () -; (setf (@ :needs-tls *frame*) t)) - -(defun register-local-binding (b) - (push b (@ :local-bindings *frame*))) - -(defun host-symbol? (sym) - (find #\. (string sym) :start 1)) - -(defun host-type-symbol? (sym) - (and (host-symbol? sym) - (= 1 (length (subseq (string sym) (position #\. (string sym) :from-end t)))))) - -(defun host-class-and-member-strings (host-symbol) - (let* ((host-name (symbol-name host-symbol)) - (dot-pos (position #\. host-name :from-end t )) - (class-name (subseq host-name 0 dot-pos)) - (member-name (subseq host-name (1+ dot-pos)))) - (values (fully-qualified-class-name class-name) member-name))) - -(defun accessor? (sym) - (eql (char (string sym) 0) #\.)) - -(defun analyze-symbol (context sym) - (cond - ((keywordp sym) - (register-keyword-reference sym) - (newobj :type :keyword :symbol sym)) - ((host-symbol? sym) (newobj :type :host-symbol :symbol sym)) - ((accessor? sym) - (register-accessor-reference sym) - (newobj :type :accessor :symbol sym)) - (t (or (reference-var sym) - ;not a local var - (progn - (register-var-reference sym) - ;(unless (eql context :fn) - ; (register-needs-tls)) - (newobj :type :global-binding :symbol sym) - ))))) - - -;load-types is for typed host references -;current thinking is that bootstrap compiler will only generate -;reflective host calls, so this will not be needed - -#| - -(defun ensure-package (name) - "find the package or create it if it doesn't exist" - (or (find-package name) - (make-package name :use '()))) - - -(defun primitive-name (tn) - (or (cdr (assoc tn - '(("Z" . "boolean") - ("B" . "byte") - ("C" . "char") - ("S" . "short") - ("I" . "int") - ("J" . "long") - ("F" . "float") - ("D" . "double") - ("V" . "void")) - :test #'string-equal)) - tn)) - -(defun java-array-name? (tn) - (eql (schar tn 0) #\[)) -(defun load-types (type-file) -"generates symbols for types/classes and members in supplied typedump file - see typedump in the Java/C# side - uses *namespace-separator* - note that this interns symbols and pushes plist entries on them, - is destructive and not idempotent, so delete-package any packages prior to re-running" - (unless *namespace-separator* - (error "*namespace-separator* must be set")) - (labels - ((type-name (td) - (second (assoc :name td))) - (arity (entry) - (second (assoc :arity (rest entry)))) - (name (entry) - (second (assoc :name (rest entry)))) - (static? (entry) - (second (assoc :static (rest entry)))) - (simple-name (tn) - (when tn - (let ((base-name (if (find *namespace-separator* tn) - (subseq tn - (1+ (position *namespace-separator* tn :from-end t)) - (position #\; tn :from-end t)) - (primitive-name (subseq tn (if (java-array-name? tn) - (1+ (position #\[ tn :from-end t)) - 0)))))) - (if (java-array-name? tn) - (with-output-to-string (s) - (write-string base-name s) - (dotimes (x (1+ (position #\[ tn :from-end t))) - (write-string "[]" s))) - base-name)))) - (sig (entry) - (format nil "<~{~A~^*~}>" - (mapcar #'simple-name (rest (assoc :args (rest entry))))))) - (let ((type-descriptors (with-open-file (f type-file) - (read f)))) - (dolist (td type-descriptors) - (let* ((split (position *namespace-separator* (type-name td) :from-end t)) - (package-name (subseq (type-name td) 0 split)) - (class-name (string-append (subseq (type-name td) (1+ split)) ".")) - (package (ensure-package package-name)) - (class-sym (intern class-name package))) - (export class-sym package) - (dolist (entry td) - (case (first entry) - (:field - (let ((field-sym (intern (concatenate 'string - (unless (static? entry) - ".") - class-name - (name entry)) - package))) - (export field-sym package) - (setf (get field-sym 'type-info) entry))) - (:ctor - (let* ((ar (arity entry)) - (overloaded (member-if (lambda (e) - (and (not (equal e entry)) - (eql (first e) :ctor) - (eql (arity e) ar))) - td)) - (ctor-sym (intern (concatenate 'string - class-name - "new" - (when overloaded - (sig entry))) - package))) - (export ctor-sym package) - (push entry (get ctor-sym 'type-info)))) - (:method - (let* ((ar (arity entry)) - (nm (name entry)) - (overloaded (member-if (lambda (e) - (and (not (equal e entry)) - (eql (first e) :method) - (string= (name e) nm) - (eql (arity e) ar) - (eql (static? e) (static? entry`)))) - td)) - (method-sym (intern (concatenate 'string - (unless (static? entry) - ".") - class-name - nm - (when overloaded - (sig entry))) - package))) - (export method-sym package) - (push entry (get method-sym 'type-info))))))))) - t)) -|#
\ No newline at end of file diff --git a/src/lisp/lib.lisp b/src/lisp/lib.lisp deleted file mode 100644 index fecc0bfc..00000000 --- a/src/lisp/lib.lisp +++ /dev/null @@ -1,235 +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. -; **/ - -(in-module "clojure") -(import "clojure.lang" '(Num RT IntegerNum Cons)) -#+:JVM(import "java.lang" '(System)) -#+:CLI(import "System" '(Console)) - - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; data and control flow ;;;;;;;;;;;;;;;;;;;; - -(defn apply (fn & args+) - (.applyTo fn __tld (spread* args+))) - -(defn complement (fn) - (fn (& args) - (not (apply fn args)))) - -(defn constantly (x) - (fn (& args) x)) - -(defn identity (x) x) - -(defn eq (x y) - (RT.eq x y)) - -(defn eql (x y) - (RT.eql x y)) - -(defn equal (x y) - (RT.equal x y)) - -(defn equals (x y) - #+:JVM (.equals x y) - #+:CLI (.Equals x y)) - -(defn not (x) - (if x nil t)) - -(defn null? (x) - (if x nil t)) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; lists ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defn acons (key val alist) - (cons (cons key val) alist)) - -(defn* adjoin - ((x list) - (if (member x list) - list - (cons x list))) - ((x list keys) - (if (member x list keys) - list - (cons x list)))) - -(defn* append - (() nil) - ((first) first) - ((first & rest) - (nconc (copy-list first) (apply append rest)))) - -(defn* assoc - ((item alist) (assoc item alist nil)) - ((item alist keys) - (assoc-if (fn (y) - ((or (:test keys) eql) item y)) - alist - keys))) - -(defn* assoc-if - ((fun alist) (assoc-if fun alist nil)) - ((fun alist keys) - (cond ((atom? alist) nil) - ((and (cons? (first alist)) - (fun (if (:key keys) - ((:key keys) (ffirst alist)) - (ffirst alist)))) - (first alist)) - (t (assoc-if fun (rest alist) keys))))) - -(defn atom? (x) (not (cons? x))) - -(defn* butlast - ((list) (butlast list 1)) - ((list n) - (nreverse (nthcdr n (reverse list))))) - -(defn first (x) - (when x - (.first x))) - -(defn rest (x) - (when x - (.rest x))) - -(defn ffirst (x) - (when x - (first (first x)))) - -(defn frest (x) - (when x - (first (rest x)))) - -(defn rrest (x) - (when x - (rest (rest x)))) - -(defn cons (x y) - (RT.cons x y)) - -(defn cons? (x) - (instance? x Cons.)) - -(defn copy-list (list) - (letfn ((cl (x) - (if (atom? x) - x - (cons (first x) - (cl (rest x)))))) - (cons (first list) - (cl (rest list))))) - -(defn copy-tree (tree) - (if (atom? tree) - tree - (cons (copy-tree (first tree)) - (copy-tree (rest tree))))) - -(defn* last - ((list) (last list 1)) - ((list n) - (do ((l list (rest l)) - (r list) - (i 0 (1+ i))) - ((null? l) r) - (if (>= i n) (pop r))))) - -(defn list (&rest args) - args) - -(defn spread* (args) - (cond - ((null? args) nil) - ((null? (rest args)) (first args)) - (t (cons (first args) (rest (rest args)))))) - -(defn list* (& args) - (spread* args)) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; numbers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defn* + - (() 0) - ((x) x) - ((x y) - (Num.add x y)) - ((x y & nums) - (Num.add (Num.add x y) (apply + nums)))) - -(defn* - - ((x) (Num.negate x)) - ((x y) - (Num.subtract x y)) - ((x y & nums) - (apply - (Num.subtract x y) nums))) - -(defn* * - (() 1) - ((x) x) - ((x y) - (Num.multiply x y)) - ((x y & nums) - (Num.multiply (Num.multiply x y) (apply + nums)))) - -(defn 1+ (x) - (.onePlus x)) - -(defn 1- (x) - (.oneMinus x)) - - - -(defn integer? (x) - (instance? x IntegerNum.)) - -(defn neg? (x) - (.minusp x)) - -(defn num? (x) - (instance? x Num.)) - -(defn pos? (x) - (.plusp x)) - -(defn zerop (x) - ;todo implement in Num - (= x Num.ZERO)) - -(defn* = - ((x) t) - ((x y) - (Num.equiv x y)) - ((x y & rest) - (and (Num.equiv x y) - (apply = y rest)))) - -(defcomparator < Num.lt) -(defcomparator <= Num.lte) -(defcomparator > Num.gt) -(defcomparator >= Num.gte) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; printer ;;;;;;;;;;;;;;;;;;;;;;;;;; -(defn prn (x) - #+:JVM (.println System.out x) - #+:CLI (Console.WriteLine x)) - - - -(defn fact (n) - (if (= n 1) - 1 - (* n (fact (1- n))))) - -(defn fmain (args) - (prn (fact 50))) - -(defmain fmain)
\ No newline at end of file diff --git a/src/lisp/test.lisp b/src/lisp/test.lisp deleted file mode 100644 index a469186e..00000000 --- a/src/lisp/test.lisp +++ /dev/null @@ -1,152 +0,0 @@ -(in-module "clojure") - -#+:JVM(import "java.lang" '(String Class Math System)) -#+:CLI(import "System, mscorlib" '(String Type Math Console)) - -(defn f0 ()) - -(defn f1 (x) x) - -(defn f2 (x y) y) - -(defn f5 (a b c d e) (d e) (f1 a)) - - -(defn* f01 - (()) - ((x) x)) - -(defn fa (x) - (.foo x)) - -(defn fk (x) - (:foo x)) - -(defn fl (a b c) - (let ((d (let ((x a)) - x))) - d) - (let ((e c)) - e)) - -(defn fl* (a b c) - (let* ((d b) - (e d)) - e)) - -(defn always (x) - (fn () x)) - -(defn fletfn (x) - (letfn ((a (b) b) - (c (d) (a d)) - (d (x) (d a))) - (c x))) - - -(defn fif (a b x y z) - (if a - (if (if x y z) - 0 - z) - b)) - -(defn fr (a b & c) c) - -(defn fnot (x y z) - (if (not x) - (not y) - (not z))) - -(defn forf (x y z) - (if (or x y) - x - (or x y z))) - - -(defn fand (x y z) - (if (and x y) - x - (and x y z))) - -(defn fset (x y z) - (set x 1) - (set b #\y) - (if (set (:foo x) z) - (set (.bar y) z) - (set (foo x y) z))) - -(defn fdo (a b c) - (do ((a b a) - (b c b)) - (c) - a b c) - (do ((a b a) - (b c b)) - (c b) - a b c)) - -(defn fg (x) - y) - -(defn ftry (x) - (try - (foo x) - nil - (bar x)) - (try - (let ((ex x)) - (try - (foo x 2) - (fred ex "string") - (bar x))) - (foo x) - (fred ex) - (bar x)) - (try - (foo x) - (fred ex) - (bar x) - "foo")) - -(defn fbind (a b c x) - (bind ((x t) - (y 17)) - c) - (bind ((x nil) - (y b)) - c)) - -(defn fq (x) - (if ':key '.foo 'a)) - -(defn fql () - '(1 2 3 (4 5))) - -(defn fcast () - (if (int 7) (char 17) (long 29999))) - -(defn fmem () - #+:JVM - (if (Class.forName "Object") - (String.valueOf 7) - Math.PI) - #+:CLI - (if (Type.GetType "Object") - (String.Intern "fred") - Math.PI) - (set Math.PI 3.14)) - -(defn finst (x) - (if (instance? x String.) - 1 - 2)) - -(defn prn (x) - #+:JVM (.println System.out x) - #+:CLI (Console.WriteLine x)) - -(defn fmain (args) - (prn "Hello World!")) - -(defmain fmain)
\ No newline at end of file diff --git a/src/org/clojure/runtime/AFn.java b/src/org/clojure/runtime/AFn.java deleted file mode 100644 index 6cfd3324..00000000 --- a/src/org/clojure/runtime/AFn.java +++ /dev/null @@ -1,101 +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 Mar 25, 2006 4:05:37 PM */ - -package org.clojure.runtime; - -public class AFn extends Obj implements IFn{ - -public Object invoke() throws Exception - { - return throwArity(); - } - -public Object invoke( Object arg1) throws Exception - { - return throwArity(); - } - -public Object invoke( Object arg1, Object arg2) 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) 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, ISeq args) - throws Exception - { - return throwArity(); - } - -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, 5)) - { - 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() - ); - default: - return ifn.invoke( arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , arglist.rest()); - } - } - -public static Object throwArity() - { - throw new IllegalArgumentException("Wrong number of args passed"); - } -} diff --git a/src/org/clojure/runtime/AGenerator.java b/src/org/clojure/runtime/AGenerator.java deleted file mode 100644 index 03b35dac..00000000 --- a/src/org/clojure/runtime/AGenerator.java +++ /dev/null @@ -1,25 +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 3, 2006 */ - -package org.clojure.runtime; - -public abstract class AGenerator implements Iter{ - -Object __val; -int __state = 0; - -public Object get() - { - return __val; - } - -} diff --git a/src/org/clojure/runtime/Accessor.java b/src/org/clojure/runtime/Accessor.java deleted file mode 100644 index 2fb5dc20..00000000 --- a/src/org/clojure/runtime/Accessor.java +++ /dev/null @@ -1,81 +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 org.clojure.runtime; - -public class Accessor extends Symbol implements IFn{ - -String memberName; -Accessor(String name) - { - super(name); - memberName = name.substring(1); - } - - -public Object invoke() throws Exception { - return AFn.throwArity(); -} -/** - * Indexer implements IFn for attr access - * This single arg version is the getter - * @param obj - must be Obj - * @return the value of the attr or nil if not found - * @throws Exception - */ -public Object invoke( Object obj) throws Exception - { - - return Reflector.invokeInstanceMember(memberName,obj); - } - -/** - * Indexer implements IFn for attr access - * This two arg version is the setter - * @param obj - must be Obj - * @param val - * @return val - * @throws Exception - */ -public Object invoke( Object obj, Object val) throws Exception - { - - return Reflector.invokeInstanceMember(memberName,obj,val); - } - -public Object invoke( Object arg1, Object arg2, Object arg3) throws Exception - { - return Reflector.invokeInstanceMember(memberName,arg1,arg2,arg3); - } - -public Object invoke( Object arg1, Object arg2, Object arg3, Object arg4) throws Exception - { - return Reflector.invokeInstanceMember(memberName,arg1,arg2,arg3,arg4); - } - -public Object invoke( Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) - throws Exception - { - return Reflector.invokeInstanceMember(memberName,arg1,arg2,arg3,arg4,arg5); - } - -public Object invoke( Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, ISeq args) - throws Exception - { - return Reflector.invokeInstanceMember(memberName,arg1,arg2,arg3,arg4,arg5,args); - } - -public Object applyTo( ISeq arglist) throws Exception { - return AFn.applyToHelper(this, arglist); -} - -} diff --git a/src/org/clojure/runtime/BigNum.java b/src/org/clojure/runtime/BigNum.java deleted file mode 100644 index a032ca89..00000000 --- a/src/org/clojure/runtime/BigNum.java +++ /dev/null @@ -1,220 +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 Mar 28, 2006 10:08:33 AM */ - -package org.clojure.runtime; - -import java.math.BigInteger; - -public class BigNum extends IntegerNum{ -public BigInteger val; - -public boolean equals(Object arg0) - { - return arg0 != null - && arg0 instanceof BigNum - && ((BigNum) arg0).val == val; - } - -public int hashCode() - { - return val.hashCode(); - } - -public String toString() - { - return val.toString(); - } - -public BigNum(long val) - { - this.val = BigInteger.valueOf(val); - } - -public BigNum(BigInteger val) - { - this.val = val; - } - -public double doubleValue() - { - return val.doubleValue(); - } - -public float floatValue() - { - return val.floatValue(); - } - -public int intValue() - { - return val.intValue(); - } - -public long longValue() - { - return val.longValue(); - } - -public boolean equiv(Num rhs) - { - return rhs.equivTo(val); - } - -public boolean equivTo(BigInteger x) - { - return x.equals(val); - } - -public boolean equivTo(int x) - { - //must be outside of range of int or would be one itself - return false; - } - -public boolean equivTo(RatioNum x) - { - //wouldn't still be a RatioNum if it was an integer - return false; - } - -public boolean lt(Num rhs) - { - return rhs.gt(val); - } - -public boolean gt(BigInteger x) - { - return x.compareTo(val) < 0; - } - -public boolean gt(int x) - { - return BigInteger.valueOf(x).compareTo(val) < 0; - } - -public boolean gt(RatioNum x) - { - return x.numerator.lt(x.denominator.multiply(val)); - } - -public Num add(Num rhs) - { - return rhs.addTo(val); - } - -public Num addTo(BigInteger x) - { - return Num.from(x.add(val)); - } - -public Num addTo(int x) - { - return Num.from(val.add(BigInteger.valueOf(x))); - } - -public Num addTo(RatioNum x) - { - return x.addTo(val); - } - -public Num subtractFrom(Num x) - { - return x.addTo(val.negate()); - } - -public Num multiplyBy(Num rhs) - { - return rhs.multiply(val); - } - -public Num multiply(BigInteger x) - { - return Num.from(x.multiply(val)); - } - -public Num multiply(int x) - { - return Num.from(val.multiply(BigInteger.valueOf(x))); - } - -public Num multiply(RatioNum x) - { - return x.multiply(val); - } - -public Num divideBy(Num rhs) - { - return rhs.divide(val); - } - -public Num divide(BigInteger n) - { - return Num.divide(n, val); - } - -public Num divide(int n) - { - return Num.divide(BigInteger.valueOf(n), val); - } - -public Num divide(RatioNum x) - { - return Num.divide(x.numerator, x.denominator.multiply(val)); - } - -public Object truncateDivide( Num num) - { - return num.truncateBy( val); - } - -public Object truncateBy( int div) - { - return Num.truncateBigints( val, BigInteger.valueOf(div)); - } - -public Object truncateBy( BigInteger div) - { - return Num.truncateBigints( val, div); - } - -public Object truncateBy( RatioNum div) - { - Num q = (Num) Num.truncate( div.denominator.multiply(val), div.numerator); - return RT.setValues( q, q.multiplyBy(div).subtractFrom(this)); - } - -public Num negate() - { - return Num.from(val.negate()); - } - -public boolean minusp() - { - return val.signum() < 0; - } - -public boolean plusp() - { - return val.signum() > 0; - } - -public Num oneMinus() - { - return Num.from(val.subtract(BigInteger.ONE)); - } - -public Num onePlus() - { - return Num.from(val.add(BigInteger.ONE)); - } -} - diff --git a/src/org/clojure/runtime/Binding.java b/src/org/clojure/runtime/Binding.java deleted file mode 100644 index 86fcd5fa..00000000 --- a/src/org/clojure/runtime/Binding.java +++ /dev/null @@ -1,25 +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.
- **/
-
-package org.clojure.runtime;
-
-public class Binding {
-public Object val;
-public Binding rest;
-
-public Binding(Object val) {
- this.val = val;
-}
-
-public Binding(Object val, Binding rest) {
- this.val = val;
- this.rest = rest;
-}
-}
diff --git a/src/org/clojure/runtime/Box.java b/src/org/clojure/runtime/Box.java deleted file mode 100644 index e1129029..00000000 --- a/src/org/clojure/runtime/Box.java +++ /dev/null @@ -1,23 +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 Mar 27, 2006 8:40:19 PM */ - -package org.clojure.runtime; - -public class Box{ - -public Object val; - -public Box(Object val) - { - this.val = val; - } -} diff --git a/src/org/clojure/runtime/Cons.java b/src/org/clojure/runtime/Cons.java deleted file mode 100644 index 1a1c1de9..00000000 --- a/src/org/clojure/runtime/Cons.java +++ /dev/null @@ -1,37 +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 Mar 25, 2006 11:01:29 AM */ - -package org.clojure.runtime; - -public class Cons implements ISeq, ISequential{ - -private final Object _first; -private final ISeq _rest; - -public Cons(Object first, ISeq rest) - { - this._first = first; - this._rest = rest; - } - -public Object first() { - return _first; -} - -public ISeq rest() { - return _rest; -} - -public ISeq seq() { - return this; -} -} diff --git a/src/org/clojure/runtime/DoubleNum.java b/src/org/clojure/runtime/DoubleNum.java deleted file mode 100644 index 59ff1428..00000000 --- a/src/org/clojure/runtime/DoubleNum.java +++ /dev/null @@ -1,244 +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 Mar 28, 2006 10:13:45 AM */ - -package org.clojure.runtime; - -import java.math.BigInteger; -import java.math.BigDecimal; - -public class DoubleNum extends FloatNum{ -double val; - -public DoubleNum(double val) - { - this.val = val; - } - -public double doubleValue() - { - return val; - } - -public float floatValue() - { - return (float) val; - } - -public int intValue() - { - return (int) val; - } - -public long longValue() - { - return (long) val; - } - -final static BigInteger BIGTEN = BigInteger.valueOf(10); - -public Num toRational() - { - BigDecimal d = new BigDecimal(val); - return Num.divide(d.unscaledValue(), BIGTEN.pow(d.scale())); - } - -public boolean equiv(Num rhs) - { - if(rhs instanceof RatioNum) - return equivTo((RatioNum) rhs); - return val == rhs.doubleValue(); - } - -public boolean equivTo(BigInteger x) - { - return val == x.doubleValue(); - } - -public boolean equivTo(int x) - { - return x == val; - } - -public boolean equivTo(RatioNum x) - { - return toRational().equivTo(x); - } - -public boolean lt(Num rhs) - { - if(rhs instanceof RatioNum) - return toRational().lt(rhs); - return val < rhs.doubleValue(); - } - -public boolean gt(BigInteger x) - { - return val > x.doubleValue(); - } - -public boolean gt(int x) - { - return val > x; - } - -public boolean gt(RatioNum x) - { - return toRational().gt(x); - } - -public Num add(Num rhs) - { - return Num.from(val + rhs.doubleValue()); - } - -public Num addTo(int x) - { - return Num.from(val + x); - } - -public Num addTo(BigInteger x) - { - return Num.from(val + x.doubleValue()); - } - -public Num addTo(RatioNum x) - { - return Num.from(val + x.doubleValue()); - } - -public Num subtractFrom(Num x) - { - return Num.from(x.doubleValue() - val); - } - -public Num multiplyBy(Num rhs) - { - return Num.from(val * rhs.doubleValue()); - } - -public Num multiply(int x) - { - return Num.from(val * x); - } - -public Num multiply(BigInteger x) - { - return Num.from(val * x.doubleValue()); - } - -public Num multiply(RatioNum x) - { - return Num.from(val * x.doubleValue()); - } - -public Num divideBy(Num rhs) - { - return Num.from(val / rhs.doubleValue()); - } - -public Num divide(int x) - { - return Num.from(x / val); - } - -public Num divide(BigInteger x) - { - return Num.from(x.doubleValue() / val); - } - -public Num divide(RatioNum x) - { - return Num.from(x.doubleValue() / val); - } - -static Object truncate(double n, double d) - { - double q = n / d; - if(q <= Integer.MAX_VALUE && q >= Integer.MIN_VALUE) - { - return RT.setValues(Num.from((int) q), - Num.from(n - ((int) q) * d)); - } - else - { //bigint quotient - Num bq = Num.from(new BigDecimal(q).toBigInteger()); - return RT.setValues(bq, - Num.from(n - bq.doubleValue() * d)); - } - } - -public Object truncateBy( BigInteger x) - { - return truncate( val, x.doubleValue()); - } - -public Object truncateBy( int x) - { - return truncate( val, x); - } - -public Object truncateBy( RatioNum x) - { - return truncate( val, x.doubleValue()); - } - -public Object truncateDivide( Num num) - { - return truncate( num.doubleValue(), val); - } - -public Num negate() - { - return Num.from(-val); - } - -public boolean equals(Object arg0) - { - return arg0 != null - && arg0 instanceof DoubleNum - && Double.doubleToLongBits(((DoubleNum) arg0).val) == - Double.doubleToLongBits(val); - } - -public int hashCode() - { - long v = Double.doubleToLongBits(val); - return (int) (v ^ (v >>> 32)); - } - -public String toString() - { - return Double.toString(val); - } - -public boolean minusp() - { - return val < 0; - } - -public boolean plusp() - { - return val > 0; - } - -public Num oneMinus() - { - return Num.from(val - 1); - } - -public Num onePlus() - { - return Num.from(val + 1); - } - -} - diff --git a/src/org/clojure/runtime/FixNum.java b/src/org/clojure/runtime/FixNum.java deleted file mode 100644 index c34557cd..00000000 --- a/src/org/clojure/runtime/FixNum.java +++ /dev/null @@ -1,239 +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 Mar 28, 2006 10:09:27 AM */ - -package org.clojure.runtime; - -import java.math.BigInteger; - -public class FixNum extends IntegerNum{ -public int val; - -public boolean equals(Object arg0) - { - return arg0 != null - && arg0 instanceof FixNum - && ((FixNum) arg0).val == val; - } - -public int hashCode() - { - return val; - } - -public String toString() - { - return Integer.toString(val); - } - -public FixNum(int val) - { - this.val = val; - } - -public double doubleValue() - { - return (double) val; - } - -public float floatValue() - { - return (float) val; - } - -public int intValue() - { - return val; - } - -public long longValue() - { - return (long) val; - } - -public boolean equiv(Num rhs) - { - return rhs.equivTo(val); - } - -public boolean equivTo(BigInteger x) - { - //wouldn't still be a BigInteger if it fit in int - return false; - } - -public boolean equivTo(int x) - { - return x == val; - } - -public boolean equivTo(RatioNum x) - { - //wouldn't still be a RatioNum if it was an integer - return false; - } - -public boolean lt(Num rhs) - { - return rhs.gt(val); - } - -public boolean gt(BigInteger x) - { - return x.compareTo(BigInteger.valueOf(val)) < 0; - } - -public boolean gt(int x) - { - return x < val; - } - -public boolean gt(RatioNum x) - { - return x.numerator.lt(x.denominator.multiply(val)); - } - -public Num add(Num rhs) - { - return rhs.addTo(val); - } - -public Num addTo(BigInteger x) - { - return Num.from(x.add(BigInteger.valueOf(val))); - } - -public Num addTo(int x) - { - return Num.from((long) x + val); - } - -public Num addTo(RatioNum x) - { - return x.addTo(val); - } - -public Num subtractFrom(Num x) - { - return x.addTo(-val); - } - -public Num multiplyBy(Num rhs) - { - return rhs.multiply(val); - } - -public Num multiply(BigInteger x) - { - return Num.from(x.multiply(BigInteger.valueOf(val))); - } - -public Num multiply(int x) - { - return Num.from((long) x * val); - } - -public Num multiply(RatioNum x) - { - return x.multiply(val); - } - -public Object truncateDivide( Num num) - { - return num.truncateBy( val); - } - -public Object truncateBy( int div) - { - return RT.setValues( Num.from(val / div), Num.from(val % div)); - } - -public Object truncateBy( BigInteger div) - { - return Num.truncateBigints( BigInteger.valueOf(val), div); - } - -public Object truncateBy( RatioNum div) - { - Num q = (Num) Num.truncate( div.denominator.multiply(val), div.numerator); - return RT.setValues( q, q.multiplyBy(div).subtractFrom(this)); - } - -public Num divideBy(Num rhs) - { - return rhs.divide(val); - } - -public Num divide(BigInteger n) - { - return Num.divide(n, BigInteger.valueOf(val)); - } - -static int gcd(int u, int v) - { - while(v != 0) - { - int r = u % v; - u = v; - v = r; - } - return u; - } - -public Num divide(int n) - { - int gcd = gcd(n, val); - if(gcd == 0) - return Num.ZERO; - - n = n / gcd; - int d = val / gcd; - if(d == 1) - return Num.from(n); - if(d < 0) - { - n = -n; - d = -d; - } - return new RatioNum((IntegerNum) Num.from(n), (IntegerNum) Num.from(d)); - } - -public Num divide(RatioNum x) - { - return Num.divide(x.numerator, x.denominator.multiply(val)); - } - -public Num negate() - { - return Num.from(-val); - } - -public boolean minusp() - { - return val < 0; - } - -public boolean plusp() - { - return val > 0; - } - -public Num oneMinus() - { - return Num.from(val - 1); - } - -public Num onePlus() - { - return Num.from(val + 1); - } - -} diff --git a/src/org/clojure/runtime/FloatNum.java b/src/org/clojure/runtime/FloatNum.java deleted file mode 100644 index 8ea7b6de..00000000 --- a/src/org/clojure/runtime/FloatNum.java +++ /dev/null @@ -1,17 +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 Mar 28, 2006 10:17:21 AM */ - -package org.clojure.runtime; - -public abstract class FloatNum extends RealNum { - -} diff --git a/src/org/clojure/runtime/FnSeq.java b/src/org/clojure/runtime/FnSeq.java deleted file mode 100644 index 84e65b48..00000000 --- a/src/org/clojure/runtime/FnSeq.java +++ /dev/null @@ -1,30 +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.
- **/
-
-package org.clojure.runtime;
-
-public class FnSeq implements ISeq{
-
-Object _first;
-IFn restFn;
-
-public FnSeq(Object first, IFn restFn) {
- this._first = first;
- this.restFn = restFn;
-}
-
-public Object first() {
- return _first;
-}
-
-public ISeq rest() throws Exception {
- return (ISeq) restFn.invoke();
-}
-}
diff --git a/src/org/clojure/runtime/IFn.java b/src/org/clojure/runtime/IFn.java deleted file mode 100644 index 7b94d509..00000000 --- a/src/org/clojure/runtime/IFn.java +++ /dev/null @@ -1,34 +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 Mar 25, 2006 3:54:03 PM */ - -package org.clojure.runtime; - -public interface IFn{ - -public Object invoke() throws Exception; - -public Object invoke(Object arg1) throws Exception; - -public Object invoke(Object arg1, Object arg2) throws Exception; - -public Object invoke(Object arg1, Object arg2, Object arg3) throws Exception; - -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4) throws Exception; - -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) - throws Exception; - -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, - ISeq args) throws Exception; - -public Object applyTo(ISeq arglist) throws Exception; -} diff --git a/src/org/clojure/runtime/IMapEntry.java b/src/org/clojure/runtime/IMapEntry.java deleted file mode 100644 index fcf93a8b..00000000 --- a/src/org/clojure/runtime/IMapEntry.java +++ /dev/null @@ -1,17 +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.
- */
-
-package org.clojure.runtime;
-
-public interface IMapEntry {
-Object key();
-
-Object val();
-}
diff --git a/src/org/clojure/runtime/IObj.java b/src/org/clojure/runtime/IObj.java deleted file mode 100644 index 30e72025..00000000 --- a/src/org/clojure/runtime/IObj.java +++ /dev/null @@ -1,26 +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.
- **/
-
-package org.clojure.runtime;
-
-/**
- * Created by IntelliJ IDEA.
- * User: rich
- * Date: May 31, 2006
- * Time: 3:41:10 PM
- * To change this template use File | Settings | File Templates.
- */
-public interface IObj {
-Object put( Comparable key, Object val) throws Exception;
-
-Object get( Comparable key) throws Exception;
-
-boolean has( Comparable key) throws Exception;
-}
diff --git a/src/org/clojure/runtime/IPersistentMap.java b/src/org/clojure/runtime/IPersistentMap.java deleted file mode 100644 index 0f4ee467..00000000 --- a/src/org/clojure/runtime/IPersistentMap.java +++ /dev/null @@ -1,31 +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.
- */
-
-package org.clojure.runtime;
-
-
-public interface IPersistentMap extends Iterable, ISequential {
-
-int count();
-
-boolean contains(Object key);
-
-IMapEntry find(Object key);
-
-IPersistentMap add(Object key);
-
-IPersistentMap put(Object key, Object val);
-
-IPersistentMap remove(Object key);
-
-Object get(Object key);
-
-int capacity();
-}
diff --git a/src/org/clojure/runtime/ISeq.java b/src/org/clojure/runtime/ISeq.java deleted file mode 100644 index 882f404b..00000000 --- a/src/org/clojure/runtime/ISeq.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.clojure.runtime;
-
-/**
- * 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.
- */
-
-/**
- * A persistent, functional, sequence interface
- *
- * ISeqs are immutable values, i.e. neither first(), nor rest() changes
- * or invalidates the ISeq
- */
-public interface ISeq {
-
-Object first() throws Exception;
-
-ISeq rest() throws Exception;
-}
diff --git a/src/org/clojure/runtime/ISequential.java b/src/org/clojure/runtime/ISequential.java deleted file mode 100644 index d55a6b3a..00000000 --- a/src/org/clojure/runtime/ISequential.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.clojure.runtime;
-
-/**
- * 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.
- */
-
-
-public interface ISequential {
-
-ISeq seq() throws Exception;
-
-}
diff --git a/src/org/clojure/runtime/Indexer.java b/src/org/clojure/runtime/Indexer.java deleted file mode 100644 index 5eebe489..00000000 --- a/src/org/clojure/runtime/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 org.clojure.runtime; - -public class Indexer extends AFn{ -} diff --git a/src/org/clojure/runtime/IntegerNum.java b/src/org/clojure/runtime/IntegerNum.java deleted file mode 100644 index 6c801dd3..00000000 --- a/src/org/clojure/runtime/IntegerNum.java +++ /dev/null @@ -1,17 +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 Mar 28, 2006 10:11:55 AM */ - -package org.clojure.runtime; - -public abstract class IntegerNum extends RationalNum { - -}
\ No newline at end of file diff --git a/src/org/clojure/runtime/Iter.java b/src/org/clojure/runtime/Iter.java deleted file mode 100644 index 82e1db5a..00000000 --- a/src/org/clojure/runtime/Iter.java +++ /dev/null @@ -1,38 +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 3, 2006 10:54:14 AM */ - -package org.clojure.runtime; - - -/** - * Implements a sequential iteration protocol - * <pre> - * for(Iter i = getAnIter();i!=null;i = i.iterate()) - * { - * //use i.get() - * } - * </pre> - */ -public interface Iter{ -/** - * Multiple calls to get() are allowed prior to calling iterate() - * @return the currently referenced item/element/value - */ -public Object get(); - -/** - * This may destroy or otherwise invalidate the object it is called upon - * so always capture and use the return value (even though sometimes you may find it is the same object) - * @return The next iter to use, or null if at end of sequence - */ -public Iter iterate(); -} diff --git a/src/org/clojure/runtime/IteratorIter.java b/src/org/clojure/runtime/IteratorIter.java deleted file mode 100644 index bfcec41a..00000000 --- a/src/org/clojure/runtime/IteratorIter.java +++ /dev/null @@ -1,44 +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 3, 2006 */ - -package org.clojure.runtime; - -import java.util.Iterator; - -public class IteratorIter implements Iter{ - -Iterator i; -Object val; - -IteratorIter(Iterator i) - { - if(!i.hasNext()) - throw new IllegalStateException("Iterator must have elements to construct Iter"); - this.i = i; - val = i.next(); - } - -public Object get() - { - return val; - } - -public Iter iterate() - { - if(i.hasNext()) - { - val = i.next(); - return this; - } - return null; - } -} diff --git a/src/org/clojure/runtime/Keyword.java b/src/org/clojure/runtime/Keyword.java deleted file mode 100644 index 4229e5ee..00000000 --- a/src/org/clojure/runtime/Keyword.java +++ /dev/null @@ -1,89 +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 Mar 29, 2006 10:39:05 AM */ - -package org.clojure.runtime; - - -public class Keyword extends Symbol implements IFn{ - - -/** - * Used by intern() - * - * @param name - - */ -Keyword(String name) - { - super(name); - } - - -public Object invoke() throws Exception { - return AFn.throwArity(); -} - -/** - * Indexer implements IFn for attr access - * This single arg version is the getter - * @param tld - * @param obj - must be Obj - * @return the value of the attr or nil if not found - * @throws Exception - */ -public Object invoke(Object obj) throws Exception - { - if (obj == null) - return null; - return ((IObj)obj).get(this); - } - -/** - * Indexer implements IFn for attr access - * This two arg version is the setter - * @param tld - * @param obj - must be Obj - * @param val - * @return val - * @throws Exception - */ -public Object invoke(Object obj, Object val) throws Exception - { - return ((IObj)obj).put(this,val); - } - -public Object invoke( Object arg1, Object arg2, Object arg3) throws Exception - { - return AFn.throwArity(); - } - -public Object invoke( Object arg1, Object arg2, Object arg3, Object arg4) throws Exception - { - return AFn.throwArity(); - } - -public Object invoke( Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) - throws Exception - { - return AFn.throwArity(); - } - -public Object invoke( Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, ISeq args) - throws Exception - { - return AFn.throwArity(); - } - -public Object applyTo( ISeq arglist) throws Exception { - return AFn.applyToHelper(this, arglist); -} -} diff --git a/src/org/clojure/runtime/LineNumberingPushbackReader.java b/src/org/clojure/runtime/LineNumberingPushbackReader.java deleted file mode 100644 index a3a10e1a..00000000 --- a/src/org/clojure/runtime/LineNumberingPushbackReader.java +++ /dev/null @@ -1,27 +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.
- */
-
-package org.clojure.runtime;
-
-import java.io.PushbackReader;
-import java.io.Reader;
-import java.io.LineNumberReader;
-
-
-public class LineNumberingPushbackReader extends PushbackReader {
-
-public LineNumberingPushbackReader(Reader r){
- super(new LineNumberReader(r));
-}
-
-public int getLineNumber(){
- return ((LineNumberReader)in).getLineNumber();
-}
-}
diff --git a/src/org/clojure/runtime/Namespace.java b/src/org/clojure/runtime/Namespace.java deleted file mode 100644 index 04a7d40e..00000000 --- a/src/org/clojure/runtime/Namespace.java +++ /dev/null @@ -1,70 +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 Mar 27, 2006 1:29:39 PM */ - -package org.clojure.runtime; - -import java.util.HashMap; -import java.util.IdentityHashMap; - -public class Namespace{ - -/** - * String->Namespace - */ -static final public HashMap table = new HashMap(); - -/** - * Symbol->Var - */ -final public IdentityHashMap vars = new IdentityHashMap(); -final public String name; - -Namespace(String name) - { - this.name = name; - table.put(name, this); - } - -static public Namespace find(String name) - { - return (Namespace) table.get(name); - } - -static public Namespace findOrCreate(String name) - { - synchronized(table) - { - Namespace ns = find(name); - if(ns == null) - ns = new Namespace(name); - return ns; - } - } - -static public Var intern(String ns,String name) - { - return findOrCreate(ns).intern(Symbol.intern(name)); - } - - -public Var intern(Symbol sym) - { - synchronized(vars) - { - Var var = (Var) vars.get(sym); - if(var == null) - vars.put(sym, var = new Var(sym, this)); - return var; - } - } - -} diff --git a/src/org/clojure/runtime/Num.java b/src/org/clojure/runtime/Num.java deleted file mode 100644 index a5a2d6b5..00000000 --- a/src/org/clojure/runtime/Num.java +++ /dev/null @@ -1,220 +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 Mar 28, 2006 10:07:33 AM */ - -package org.clojure.runtime; - -import java.math.BigInteger; - -public abstract class Num extends Number implements Comparable{ - -public final static Num ZERO = from(0); -public final static Num ONE = from(1); - -static public Num from(int val) - { - //todo - cache a bunch of small fixnums - return new FixNum(val); - } - -static public Num from(double val) - { - return new DoubleNum(val); - } - -static public Num from(long val) - { - if(val <= Integer.MAX_VALUE && val >= Integer.MIN_VALUE) - return from((int) val); - else - return new BigNum(val); - } - -static public Num from(BigInteger val) - { - if(val.bitLength() < 32) - return from(val.intValue()); - else - return new BigNum(val); - } - -static public Num from(Object x) - { - if(x instanceof Num) - return (Num) x; - else - { - Class c = x.getClass(); - if(c == Integer.class) - return Num.from(((Integer) x).intValue()); - else if(c == Double.class || c == Float.class) - return Num.from(((Number) x).doubleValue()); - else if(c == Long.class) - return Num.from(((Long) x).longValue()); - else if(c == BigInteger.class) - return Num.from((BigInteger) x); - else - return Num.from(((Number) x).intValue()); - } - } - -static public Num add(Object x, Object y) - { - //if(x instanceof Num && y instanceof Num) - //return ((Num)x).add((Num) y); - return Num.from(x).add(Num.from(y)); - } - -abstract public Num add(Num rhs); - -abstract public Num addTo(int x); - -abstract public Num addTo(BigInteger x); - -abstract public Num addTo(RatioNum x); - -static public Num subtract(Object x, Object y) - { - return Num.from(y).subtractFrom(Num.from(x)); - } - -//this double-dispatches to addTo(-self) -abstract public Num subtractFrom(Num rhs); - -static public Num multiply(Object x, Object y) - { - return Num.from(x).multiplyBy(Num.from(y)); - } - -abstract public Num multiplyBy(Num rhs); - -abstract public Num multiply(int x); - -abstract public Num multiply(BigInteger x); - -abstract public Num multiply(RatioNum x); - -static public Num divide(Object x, Object y) - { - return Num.from(x).divideBy(Num.from(y)); - } - -abstract public Num divideBy(Num rhs); - -abstract public Num divide(int x); - -abstract public Num divide(BigInteger x); - -abstract public Num divide(RatioNum x); - -static public Object truncate(Object num, Object div) - { - return Num.from(div).truncateDivide( Num.from(num)); - } - -abstract public Object truncateDivide(Num rhs); - -abstract public Object truncateBy(int x); - -abstract public Object truncateBy(BigInteger x); - -abstract public Object truncateBy(RatioNum x); - -static public Object truncateBigints(BigInteger n, BigInteger d) - { - BigInteger[] result = n.divideAndRemainder(d); - return RT.setValues(Num.from(result[0]), Num.from(result[1])); - } - -static public Num divide(BigInteger n, BigInteger d) - { - BigInteger gcd = n.gcd(d); - if(gcd.equals(BigInteger.ZERO)) - return Num.ZERO; - n = n.divide(gcd); - d = d.divide(gcd); - if(d.equals(BigInteger.ONE)) - return Num.from(n); - return new RatioNum((IntegerNum) Num.from(d.signum() < 0 ? n.negate() : n), - (IntegerNum) Num.from(d.signum() < 0 ? d.negate() : d)); - } - -static public boolean equiv(Object x, Object y) - { - return Num.from(x).equiv(Num.from(y)); - } - -abstract public boolean equiv(Num rhs); - -abstract public boolean equivTo(int x); - -abstract public boolean equivTo(BigInteger x); - -abstract public boolean equivTo(RatioNum x); - -static public boolean lt(Object x, Object y) - { - return Num.from(x).lt(Num.from(y)); - } - -static public boolean lte(Object x, Object y) - { - Num lx = Num.from(x); - Num ly = Num.from(y); - return lx.lt(ly) || lx.equiv(ly); - } - -static public boolean gt(Object x, Object y) - { - return Num.from(y).lt(Num.from(x)); - } - -static public boolean gte(Object x, Object y) - { - Num lx = Num.from(x); - Num ly = Num.from(y); - return ly.lt(lx) || lx.equiv(ly); - } - -abstract public boolean lt(Num rhs); - -abstract public boolean gt(int x); - -abstract public boolean gt(BigInteger x); - -abstract public boolean gt(RatioNum x); - -static public Num negate(Object x) - { - return Num.from(x).negate(); - } - -abstract public Num negate(); - -abstract public boolean minusp(); - -abstract public boolean plusp(); - -abstract public Num oneMinus(); - -abstract public Num onePlus(); - -public int compareTo(Object object) - { - Num other = Num.from(object); - if(this.equiv(other)) - return 0; - else if(this.lt(other)) - return -1; - else - return 1; - } -} diff --git a/src/org/clojure/runtime/Obj.java b/src/org/clojure/runtime/Obj.java deleted file mode 100644 index f0f2a3a4..00000000 --- a/src/org/clojure/runtime/Obj.java +++ /dev/null @@ -1,44 +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 Mar 25, 2006 3:44:58 PM */ - -package org.clojure.runtime; - -import java.util.IdentityHashMap; - -public class Obj implements IObj { - -IdentityHashMap attrs; -public static final int INITIAL_SIZE = 7; - -public Object put( Comparable key, Object val) - { - if(attrs == null) - attrs = new IdentityHashMap(INITIAL_SIZE); - attrs.put(key, val); - return val; - } - -public Object get( Comparable key) - { - if(attrs == null) - return null; - return attrs.get(key); - } - -public boolean has( Comparable key){ - if(attrs == null) - return false; - return attrs.containsKey(key); - } - - -} diff --git a/src/org/clojure/runtime/PersistentArray.java b/src/org/clojure/runtime/PersistentArray.java deleted file mode 100644 index 06ae9195..00000000 --- a/src/org/clojure/runtime/PersistentArray.java +++ /dev/null @@ -1,350 +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 Jun 2, 2006 */ - -package org.clojure.runtime; - -//import java.util.concurrent.atomic.AtomicInteger; -//import java.util.concurrent.atomic.AtomicReferenceArray; -import java.util.BitSet; -import java.util.Iterator; -import java.util.Vector; -import java.util.Random; - -/** - * Note that instances of this class are constant values - * i.e. set() returns a new array, old one is intact - * - * Multiple revisions (thread-safely) share the same master array - * - * Constant time most-recent-revision lookups - * Amortized constant-time sequential revisions (when loadFactor > 1) - * where a sequential revision is a revision of the most recent revision - * - * Non-sequential revisions are O(length), but with a small constant multiplier of 1/32 - * Worst-case O(r) lookups for oldest revs where r is number of revisions - * at index i since last (automatic or manual) isolate. If set()s are roughly evenly - * distributed, r should be approximately == loadFactor, i.e. constant - * In pathological case (all mods to same index), r == (loadFactor * length) - * - * (loadFactor * length) old values are retained, even if the array revisions aren't - * Default loadFactor is 2.1 - * When the load exceeds (loadFactor * length) the next revision is automatically isolated - * You can determine how many values are in the shared master by calling load() - * and can trim them by calling isolate() or resize(), which yield a new array with no - * sharing and no old values - * - * See Cohen for basic idea - * I added hybrid most-recent-sequential-range + shared-bitset idea, multi-thread-safety - */ - -public class PersistentArray implements Iterable, ISequential{ - -public Iterator iterator(){ - return new ValIter(this); -} - -public ISeq seq() { - if(length() > 0) - return new Seq(this, 0); - return null; -} - -static class Master{ - final Entry[] array; - final Object defaultVal; - int rev; - int load; - final int maxLoad; - final float loadFactor; - - Master(int size,Object defaultVal, float loadFactor){ - this.array = new Entry[size];//new AtomicReferenceArray(size); - this.defaultVal = defaultVal; - this.rev = 0;//new AtomicInteger(0); - this.load = 0;//new AtomicInteger(0); - this.maxLoad = (int) (size * loadFactor); - this.loadFactor = loadFactor; - } -} - -static class Entry{ - final int rev; - final Object val; - - Entry(int rev,Object val){ - this.rev = rev; - this.val = val; - } - - Entry rest(){ - return null; - } - - static Entry create(int rev,Object val,Entry rest){ - if(rest == null) - return new Entry(rev,val); - return new EntryLink(rev, val, rest); - } -} - -static class EntryLink extends Entry{ - final Entry _rest; - - EntryLink(int rev,Object val,Entry rest){ - super(rev,val); - this._rest = rest; - } - - Entry rest(){ - return _rest; - } -} - -static class Seq implements ISeq{ - final PersistentArray p; - final int i; - - Seq(PersistentArray p, int i){ - this.p = p; - this.i = i; - } - - public Object first() { - return p.get(i); - } - - public ISeq rest() { - if(i+1 < p.length()) - return new Seq(p, i + 1); - return null; - } -} - -static class ValIter implements Iterator{ - PersistentArray p; - int i; - - ValIter(PersistentArray p){ - this.p = p; - this.i = 0; - } - - public boolean hasNext(){ - return i < p.length(); - } - - public Object next(){ - return p.get(i++); - } - - public void remove(){ - throw new UnsupportedOperationException(); - } -} - -final Master master; -final int rev; -final int baseline; -final BitSet history; - -public PersistentArray(int size){ - this(size, null); -} - -public PersistentArray(int size, Object defaultVal){ - this(size,defaultVal,2.1f); -} - -public PersistentArray(int size, Object defaultVal, float loadFactor){ - this.master = new Master(size, defaultVal,loadFactor); - this.rev = 0; - this.baseline = 0; - this.history = null; -} - -PersistentArray(Master master,int rev,int baseline, BitSet history){ - this.master = master; - this.rev = rev; - this.baseline = baseline; - this.history = history; -} - - - -final public int length(){ - return master.array.length; - //return master.array.length(); -} - -final public Object get(int i) { - Entry e = getEntry(i); - if(e != null) - return e.val; - return master.defaultVal; -} - -final public boolean has(int i){ - return getEntry(i) != null; -} - -final public PersistentArray resize(int newLength) { - PersistentArray ret = new PersistentArray(newLength, master.defaultVal, master.loadFactor); - int load = 0; - for(int i=0;i< Math.min(length(),newLength);i++) - { - Entry e = getEntry(i); - if(e != null) - { - ret.master.array[i] = new Entry(0,e.val); - //ret.master.array.set(i,Entry.create(0,e.val, null)); - ++load; - } - } - - ret.master.load = load; - //ret.master.load.set(load); - - return ret; -} - -/** - * - * @return number of values (of all revisions) stored in shared array - */ -final public int load(){ - return master.load; - //return master.load.get(); -} - -final public PersistentArray isolate() { - return resize(length()); -} - -final Entry getEntry(int i){ - for(Entry e = master.array[i];e != null;e = e.rest()) - // for(Entry e = (Entry) master.array.get(i);e != null;e = e.rest()) - { - if(e.rev <= rev) - { - if(e.rev >= baseline - || (history != null && history.get(e.rev))) - return e; - } - } - return null; -} - -final public PersistentArray set(int i,Object val) { - if(master.load >= master.maxLoad) - //if(master.load.get() >= master.maxLoad) - return isolate().set(i,val); - synchronized(master){ - PersistentArray ret = getSetArray(); - ret.doSet(i, val); - return ret; - } -} - -final void doSet(int i, Object val){ -// Entry oldEntry, newEntry; -// do -// { -// oldEntry = (Entry) master.array.get(i); -// newEntry = Entry.create(rev, val, oldEntry); -// } while(!master.array.compareAndSet(i, oldEntry, newEntry)); - - //must now be called inside lock of master - master.array[i] = Entry.create(rev, val, master.array[i]); - //master.load.incrementAndGet(); - ++master.load; -} - -final PersistentArray getSetArray(){ - //must now be called inside lock of master - //is this a sequential update? - if(master.rev == rev) - //if(master.rev.compareAndSet(rev, rev + 1)) - { - return new PersistentArray(master, ++master.rev, baseline, history); - } - else //gap - { - //nextRev = master.rev.incrementAndGet(); - int nextRev = ++master.rev; - BitSet nextHistory; - if(history != null) - nextHistory = (BitSet) history.clone(); - else - nextHistory = new BitSet(rev+1); - nextHistory.set(baseline,rev+1); - return new PersistentArray(master, nextRev, nextRev, nextHistory); - } - -} - - -static public void main(String[] args){ - if(args.length != 3) - { - System.err.println("Usage: PersistentArray size writes reads"); - return; - } - int size = Integer.parseInt(args[0]); - int writes = Integer.parseInt(args[1]); - int reads = Integer.parseInt(args[2]); - Vector v = new Vector(size); - v.setSize(size); - PersistentArray p = new PersistentArray(size); - - for(int i = 0; i < size; i++) - { - v.set(i, 0); - p = p.set(i, 0); - } - - Random rand; - - rand = new Random(42); - long tv = 0; - System.out.println("Vector"); - long startTime = System.nanoTime(); - for(int i = 0; i < writes; i++) - { - v.set(rand.nextInt(size), i); - } - for(int i = 0; i < reads; i++) - { - tv += (Integer)v.get(rand.nextInt(size)); - } - long estimatedTime = System.nanoTime() - startTime; - System.out.println("time: " + estimatedTime/1000000); - System.out.println("PersistentArray"); - rand = new Random(42); - startTime = System.nanoTime(); - long tp = 0; - for(int i = 0; i < writes; i++) - { - p = p.set(rand.nextInt(size), i); - //dummy set to force perverse branching - //p.set(i%size, i); - } - for(int i = 0; i < reads; i++) - { - tp += (Integer)p.get(rand.nextInt(size)); - } - estimatedTime = System.nanoTime() - startTime; - System.out.println("time: " + estimatedTime/1000000); - System.out.println("Done: " + tv + ", " + tp); - - -} -} diff --git a/src/org/clojure/runtime/PersistentArrayIdentityMap.java b/src/org/clojure/runtime/PersistentArrayIdentityMap.java deleted file mode 100644 index 681a27cf..00000000 --- a/src/org/clojure/runtime/PersistentArrayIdentityMap.java +++ /dev/null @@ -1,35 +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.
- **/
-
-package org.clojure.runtime;
-
-/**
- * ArrayMap using identity (==) comparison instead of equals
- */
-public class PersistentArrayIdentityMap extends PersistentArrayMap {
-
-public static PersistentArrayIdentityMap EMPTY = new PersistentArrayIdentityMap();
-
-
-private PersistentArrayIdentityMap() {
-}
-
-IPersistentMap empty() {
- return EMPTY;
-}
-
-public PersistentArrayIdentityMap(Object[] init) {
- super(init);
-}
-
-boolean equalKey(Object k1, Object k2) {
- return k1 == k2;
-}
-}
diff --git a/src/org/clojure/runtime/PersistentArrayMap.java b/src/org/clojure/runtime/PersistentArrayMap.java deleted file mode 100644 index a2ce4a12..00000000 --- a/src/org/clojure/runtime/PersistentArrayMap.java +++ /dev/null @@ -1,212 +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.
- **/
-
-package org.clojure.runtime;
-
-import java.util.Iterator;
-
-/**
- * Simple implementation of persistent map on an array
-
- * Note that instances of this class are constant values
- * i.e. add/remove etc return new values
- *
- * Copies array on every change, so only appropriate for _very_small_ maps
- *
- * null keys and values are ok, but you won't be able to distinguish a null value via get - use contains/find
- */
-
-public class PersistentArrayMap implements IPersistentMap, ISequential {
-
-final Object[] array;
-
-public static PersistentArrayMap EMPTY = new PersistentArrayMap();
-
-protected PersistentArrayMap(){
- this.array = RT.EMPTY_ARRAY;
-}
-
-/**
- * This ctor captures/aliases the passed array, so do not modify later
- * @param init {key1,val1,key2,val2,...}
- */
-public PersistentArrayMap(Object[] init){
- this.array = init;
-}
-
-public int count() {
- return array.length/2;
-}
-
-public boolean contains(Object key){
- return indexOf(key) >= 0;
-}
-
-public IMapEntry find(Object key) {
- int i = indexOf(key);
- if(i >= 0)
- return new Iter(array,i);
- return null;
-}
-
-public IPersistentMap add(Object key) {
-
- return put(key,null);
-}
-
-public IPersistentMap put(Object key, Object val) {
- int i = indexOf(key);
- Object[] newArray;
- if(i >= 0) //already have key, same-sized replacement
- {
- if(array[i+1] == val) //no change, no op
- return this;
- newArray = array.clone();
- newArray[i+1] = val;
- }
- else //didn't have key, grow
- {
- newArray = new Object[array.length + 2];
- if(array.length > 0)
- System.arraycopy(array,0,newArray,2,array.length);
- newArray[0] = key;
- newArray[1] = val;
- }
- return new PersistentArrayMap(newArray);
-}
-
-public IPersistentMap remove(Object key) {
- int i = indexOf(key);
- if(i >= 0) //have key, will remove
- {
- int newlen = array.length - 2;
- if(newlen == 0)
- return empty();
- Object[] newArray = new Object[newlen];
- for(int s=0,d=0;s<array.length;s += 2)
- {
- if(!equalKey(array[s],key)) //skip removal key
- {
- newArray[d] = array[s];
- newArray[d+1] = array[s+1];
- d += 2;
- }
- }
- return new PersistentArrayMap(newArray);
- }
- //don't have key, no op
- return this;
-}
-
-IPersistentMap empty() {
- return EMPTY;
-}
-
-public Object get(Object key) {
- int i = indexOf(key);
- if(i >= 0)
- return array[i + 1];
- return null;
-}
-
-public int capacity() {
- return count();
-}
-
-int indexOf(Object key){
- for(int i=0;i<array.length;i+=2)
- {
- if(equalKey(array[i],key))
- return i;
- }
- return -1;
-}
-
-boolean equalKey(Object k1,Object k2){
- if(k1 == null)
- return k2 == null;
- return k1.equals(k2);
-}
-
-public Iterator iterator() {
- return new Iter(array);
-}
-
-public ISeq seq() {
- if(array.length > 0)
- return new Seq(array,0);
- return null;
-}
-
-static class Seq implements ISeq, IMapEntry{
- final Object[] array;
- final int i;
-
- Seq(Object[] array, int i){
- this.array = array;
- this.i = i;
- }
-
- public Object key() {
- return array[i];
- }
-
- public Object val() {
- return array[i+1];
- }
-
- public Object first() {
- return this;
- }
-
- public ISeq rest() {
- if(i+2 < array.length)
- return new Seq(array, i + 2);
- return null;
- }
-}
-
-static class Iter implements Iterator,IMapEntry{
- Object[] array;
- int i;
-
- //for iterator
- Iter(Object[] array){
- this(array,-2);
- }
-
- //for find
- Iter(Object[] array, int i){
- this.array = array;
- this.i = i;
- }
-
- public boolean hasNext() {
- return i < array.length - 2;
- }
-
- public Object next() {
- i+=2;
- return this;
- }
-
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
- public Object key() {
- return array[i];
- }
-
- public Object val() {
- return array[i+1];
- }
-}
-}
diff --git a/src/org/clojure/runtime/PersistentHashtableIdentityMap.java b/src/org/clojure/runtime/PersistentHashtableIdentityMap.java deleted file mode 100644 index 01b1f19d..00000000 --- a/src/org/clojure/runtime/PersistentHashtableIdentityMap.java +++ /dev/null @@ -1,96 +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.
- **/
-
-package org.clojure.runtime;
-
-import java.util.Iterator;
-
-public class PersistentHashtableIdentityMap extends PersistentHashtableMap {
-
-public PersistentHashtableIdentityMap(int initialCapacity) {
- super(initialCapacity);
-}
-
-public PersistentHashtableIdentityMap(Object[] init) {
- super(init);
-}
-
-PersistentHashtableIdentityMap(int count, PersistentArray array) {
- super(count, array);
-}
-
-PersistentHashtableIdentityMap(int i, PersistentArray newArray, int growAtCount) {
- super(i, newArray, growAtCount);
-}
-
-
-public Iterator<IMapEntry> iterator() {
- return new Iter(array);
-}
-
-
-static class Iter implements Iterator{
- PersistentArray buckets;
- int b;
- PersistentListIdentityMap e;
-
- Iter(PersistentArray buckets){
- this.buckets = buckets;
- this.b = -1;
- nextBucket();
- }
-
- private void nextBucket() {
- e = null;
- for(b = b+1;b<buckets.length();b++)
- {
- PersistentListIdentityMap a = (PersistentListIdentityMap) buckets.get(b);
- if(a != null && a != PersistentListIdentityMap.EMPTY)
- {
- e = a;
- break;
- }
- }
- }
-
- public boolean hasNext() {
- return e != null;
- }
-
- public Object next() {
- PersistentListIdentityMap ret = e;
- e = e.next();
- if(e == PersistentListIdentityMap.EMPTY)
- nextBucket();
- return ret;
- }
-
- public void remove() {
- throw new UnsupportedOperationException();
- }
-}
-
-IPersistentMap create(int capacity) {
- return new PersistentHashtableIdentityMap(capacity);
-}
-
-IPersistentMap create(int count, PersistentArray array) {
- return new PersistentHashtableIdentityMap(count, array);
-}
-
-IPersistentMap create(int i, PersistentArray newArray, int growAtCount){
- return new PersistentHashtableIdentityMap(i, newArray, growAtCount);
-}
-
-IPersistentMap createListMap(Object key, Object val){
- return PersistentListIdentityMap.create(key,val);
-}
-
-}
diff --git a/src/org/clojure/runtime/PersistentHashtableMap.java b/src/org/clojure/runtime/PersistentHashtableMap.java deleted file mode 100644 index 0fb71b64..00000000 --- a/src/org/clojure/runtime/PersistentHashtableMap.java +++ /dev/null @@ -1,255 +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.
- **/
-
-package org.clojure.runtime;
-
-import java.util.Iterator;
-import java.math.BigInteger;
-
-public class PersistentHashtableMap implements IPersistentMap {
-
-static final float FILL_FACTOR = 0.75f;
-
-final PersistentArray array;
-final int _count;
-final int growAtCount;
-
-public PersistentHashtableMap(int initialCapacity) {
- array = new PersistentArray(calcPrimeCapacity(initialCapacity));
- _count = 0;
- this.growAtCount = (int) (this.array.length()*FILL_FACTOR);
-}
-
-/**
- * @param init {key1,val1,key2,val2,...}
- */
-public PersistentHashtableMap(Object[] init){
- //start halfway to a rehash
- PersistentArray narray = new PersistentArray(calcPrimeCapacity(init.length));
- for(int i=0;i<init.length;i+=2)
- {
- narray = doPut(bucketFor(init[i],narray),init[i], init[i + 1],narray);
- }
- this.array = narray;
- this._count = init.length/2; //hmmm... presumes no dupe keys in init
- this.growAtCount = (int) (this.array.length()*FILL_FACTOR);
-}
-
-PersistentHashtableMap(int count,PersistentArray array) {
- this._count = count;
- this.array = array;
- this.growAtCount = (int) (this.array.length()*FILL_FACTOR);
-}
-
-PersistentHashtableMap(int count,PersistentArray array,int growAt) {
- this._count = count;
- this.array = array;
- this.growAtCount = growAt;
-}
-
-int calcPrimeCapacity(int capacity) {
- return BigInteger.valueOf((long) (capacity/FILL_FACTOR)).nextProbablePrime().intValue();
-}
-
-public int count() {
- return _count;
-}
-
-public boolean contains(Object key) {
- IPersistentMap entries = entriesFor(key);
- return entries != null && entries.contains(key);
-}
-
-public IMapEntry find(Object key) {
- IPersistentMap entries = entriesFor(key);
- if(entries != null)
- return entries.find(key);
- return null;
-}
-
-public IPersistentMap add(Object key) {
- return put(key, null);
-}
-
-public IPersistentMap put(Object key, Object val) {
- if(_count > growAtCount)
- return grow().put(key, val);
- int i = bucketFor(key,array);
- int incr = 1;
- PersistentArray newArray = doPut(i, key, val, array);
- if(newArray == array)
- return this;
- if(array.get(i) != null && ((IPersistentMap)newArray.get(i)).count() == ((IPersistentMap)array.get(i)).count()) //key already there, no growth
- incr = 0;
- return create(_count + incr, newArray, growAtCount);
-}
-
-PersistentArray doPut(int i,Object key,Object val,PersistentArray array){
- IPersistentMap entries = (IPersistentMap) array.get(i);
- IPersistentMap newEntries;
- if (entries != null)
- {
- newEntries = entries.put(key, val);
- if(newEntries == entries) //already there with same value, no op
- return array;
- }
- else
- newEntries = createListMap(key, val);
- //newEntries = createArrayMap(new Object[]{key, val});
-
- return array.set(i, newEntries);
-}
-
-public IPersistentMap remove(Object key) {
- int i = bucketFor(key,array);
- IPersistentMap entries = (IPersistentMap) array.get(i);
- if (entries != null)
- {
- IPersistentMap newEntries = entries.remove(key);
- if (newEntries != entries)
- return create(_count - 1, array.set(i, newEntries));
- }
- //not there, no op
- return this;
-}
-
-public Object get(Object key) {
- IPersistentMap entries = entriesFor(key);
- if(entries != null)
- return entries.get(key);
- return null;
-}
-
-public int capacity() {
- return array.length();
-}
-
-IPersistentMap grow(){
- PersistentArray newArray = new PersistentArray(calcPrimeCapacity(_count * 2));
- for (Object o : this)
- {
- IMapEntry e = (IMapEntry) o;
- newArray = doPut(bucketFor(e.key(),newArray),e.key(), e.val(),newArray);
- }
- return create(_count,newArray);
-}
-
-public Iterator iterator() {
- return new Iter(array);
-}
-
-public ISeq seq() throws Exception {
- return Seq.create(array);
-}
-
-static class Seq implements ISeq{
- PersistentArray buckets;
- int b;
- ISeq e;
-
-
- static public Seq create(PersistentArray buckets) throws Exception {
- return next(buckets, -1, null);
- }
-
- static Seq next(PersistentArray buckets, int b, ISeq e) throws Exception {
- if(e != null && e.rest() != null)
- return new Seq(buckets,b,e.rest());
- for(b = b+1;b<buckets.length();b++)
- {
- ISequential a = (ISequential) buckets.get(b);
- if(a != null && a.seq() != null)
- return new Seq(buckets,b,a.seq());
- }
- return null;
- }
-
- Seq(PersistentArray buckets, int b, ISeq e) {
- this.buckets = buckets;
- this.b = b;
- this.e = e;
- }
-
- public Object first() throws Exception {
- return e.first();
- }
-
- public ISeq rest() throws Exception {
- return next(buckets,b,e);
- }
-}
-
-static class Iter implements Iterator{
- PersistentArray buckets;
- int b;
- PersistentListMap e;
-
- Iter(PersistentArray buckets){
- this.buckets = buckets;
- this.b = -1;
- nextBucket();
- }
-
- private void nextBucket() {
- e = null;
- for(b = b+1;b<buckets.length();b++)
- {
- PersistentListMap a = (PersistentListMap) buckets.get(b);
- if(a != null && a != PersistentListMap.EMPTY)
- {
- e = a;
- break;
- }
- }
- }
-
- public boolean hasNext() {
- return e != null;
- }
-
- public Object next() {
- PersistentListMap ret = e;
- e = e.next();
- if(e == PersistentListMap.EMPTY)
- nextBucket();
- return ret;
- }
-
- public void remove() {
- throw new UnsupportedOperationException();
- }
-}
-
-final IPersistentMap entriesFor(Object key){
- return (IPersistentMap) array.get(bucketFor(key,array));
-}
-
-static int bucketFor(Object key, PersistentArray array) {
- return (key.hashCode() & 0x7fffffff)%array.length();
-}
-
-IPersistentMap create(int capacity) {
- return new PersistentHashtableMap(capacity);
-}
-
-IPersistentMap create(int count,PersistentArray array) {
- return new PersistentHashtableMap(count, array);
-}
-
-IPersistentMap create(int i, PersistentArray newArray, int growAtCount){
- return new PersistentHashtableMap(i, newArray, growAtCount);
-}
-
-
-IPersistentMap createListMap(Object key, Object val){
- return PersistentListMap.create(key,val);
-}
-
-}
diff --git a/src/org/clojure/runtime/PersistentHybridIdentityMap.java b/src/org/clojure/runtime/PersistentHybridIdentityMap.java deleted file mode 100644 index 2d432146..00000000 --- a/src/org/clojure/runtime/PersistentHybridIdentityMap.java +++ /dev/null @@ -1,47 +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.
- **/
-
-package org.clojure.runtime;
-
-public class PersistentHybridIdentityMap extends PersistentHybridMap{
-
-public PersistentHybridIdentityMap(Object[] init) {
- super(init);
-}
-
-public PersistentHybridIdentityMap(int initialCapacity) {
- super(initialCapacity);
-}
-
-PersistentHybridIdentityMap(IPersistentMap impl) {
- super(impl);
-}
-
-public IPersistentMap create(IPersistentMap impl) {
- return new PersistentHybridIdentityMap(impl);
-}
-
-public PersistentArrayMap createArrayMap(Object[] init) {
- return new PersistentArrayIdentityMap(init);
-}
-
-IPersistentMap createArrayMap() {
- return PersistentArrayIdentityMap.EMPTY;
-}
-
-IPersistentMap createHashtableMap(Object[] init) {
- return new PersistentHashtableIdentityMap(init);
-}
-
-IPersistentMap createHashtableMap(int initialCapacity) {
- return new PersistentHashtableIdentityMap(initialCapacity);
-}
-
-}
diff --git a/src/org/clojure/runtime/PersistentHybridMap.java b/src/org/clojure/runtime/PersistentHybridMap.java deleted file mode 100644 index 54e153ed..00000000 --- a/src/org/clojure/runtime/PersistentHybridMap.java +++ /dev/null @@ -1,104 +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.
- **/
-
-package org.clojure.runtime;
-
-import java.util.Iterator;
-
-public class PersistentHybridMap implements IPersistentMap{
-
-IPersistentMap impl;
-static final int CAPACITY_THRESHOLD = 42;
-
-public PersistentHybridMap(Object[] init){
- if(init.length/2 < CAPACITY_THRESHOLD)
- impl = createArrayMap(init);
- impl = createHashtableMap(init);
-}
-
-public PersistentHybridMap(int initialCapacity){
- if(initialCapacity < CAPACITY_THRESHOLD)
- impl = createArrayMap();
- else
- impl = createHashtableMap(initialCapacity);
-}
-
-PersistentHybridMap(IPersistentMap impl){
- this.impl = impl;
-}
-
-public int count() {
- return impl.count();
-}
-
-public boolean contains(Object key) {
- return impl.contains(key);
-}
-
-public IMapEntry find(Object key) {
- return impl.find(key);
-}
-
-public IPersistentMap add(Object key) {
- return put(key, null);
-}
-
-public IPersistentMap put(Object key, Object val) {
- IPersistentMap newImpl = impl.put(key,val);
- if(newImpl.capacity() == CAPACITY_THRESHOLD)
- {
- newImpl = createHashtableMap(((PersistentArrayMap)newImpl).array);
- }
- return create(newImpl);
-}
-
-public IPersistentMap remove(Object key) {
- IPersistentMap newImpl = impl.remove(key);
- if(newImpl != impl)
- return create(newImpl);
- return this;
-}
-
-public Object get(Object key) {
- return impl.get(key);
-}
-
-public int capacity() {
- return impl.capacity();
-}
-
-public Iterator iterator() {
- return ((Iterable)impl).iterator();
-}
-
-public IPersistentMap create(IPersistentMap impl) {
- return new PersistentHybridMap(impl);
-}
-
-public PersistentArrayMap createArrayMap(Object[] init) {
- return new PersistentArrayMap(init);
-}
-
-IPersistentMap createArrayMap() {
- return PersistentArrayMap.EMPTY;
-}
-
-IPersistentMap createHashtableMap(Object[] init) {
- return new PersistentHashtableMap(init);
-}
-
-IPersistentMap createHashtableMap(int initialCapacity) {
- return new PersistentHashtableMap(initialCapacity);
-}
-
-public ISeq seq() throws Exception {
- return impl.seq();
-}
-}
diff --git a/src/org/clojure/runtime/PersistentListIdentityMap.java b/src/org/clojure/runtime/PersistentListIdentityMap.java deleted file mode 100644 index bd3bd4d4..00000000 --- a/src/org/clojure/runtime/PersistentListIdentityMap.java +++ /dev/null @@ -1,286 +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.
- **/
-
-package org.clojure.runtime;
-
-import java.util.Iterator;
-
-/**
- * Implementation of persistent map on a linked list
- * Uses identity (==) comparison, vs equals() of PersistentListMap
-
- * Note that instances of this class are constant values
- * i.e. add/remove etc return new values
- *
- * Lookups/changes are linear, so only appropriate for _very_small_ maps
- * PersistentArrayMap is generally faster, but this class avoids the double allocation,
- * and so is better/faster as a bucket for hash tables
- *
- * null keys and values are ok, but you won't be able to distinguish a null value via get - use contains/find
- *
- * code duplication here is kind of gross, but most efficient
- */
-
-public class PersistentListIdentityMap implements IPersistentMap, IMapEntry, ISeq, ISequential
-{
-
-static public PersistentListIdentityMap EMPTY = new PersistentListIdentityMap();
-
-static public PersistentListIdentityMap create(Object key, Object val){
- return new Tail(key, val);
-}
-
-public Object key(){
- return null;
-}
-
-public Object val(){
- return null;
-}
-
-PersistentListIdentityMap next(){
- return this;
- }
-
-public int count(){
- return 0;
-}
-
-public boolean contains(Object key){
- return false;
-}
-
-public IMapEntry find(Object key){
- return null;
-}
-
-public IPersistentMap add(Object key){
- return put(key, null);
-}
-
-public PersistentListIdentityMap put(Object key, Object val){
- return new Tail(key, val);
-}
-
-public PersistentListIdentityMap remove(Object key){
- return this;
-}
-
-public Object get(Object key){
- return null;
-}
-
-public int capacity(){
- return 0;
-}
-
-public Object first() {
- return null;
-}
-
-public ISeq rest() {
- return null;
-}
-
-public ISeq seq() {
- return null;
-}
-
-
-static class Iter implements Iterator{
- PersistentListIdentityMap e;
-
- Iter(PersistentListIdentityMap e)
- {
- this.e = e;
- }
-
- public boolean hasNext(){
- return e != EMPTY;
- }
-
- public Object next(){
- PersistentListIdentityMap ret = e;
- e = e.next();
- return ret;
- }
-
- public void remove(){
- throw new UnsupportedOperationException();
- }
-}
-
-public Iterator iterator(){
- return new Iter(this);
-}
-
-static class Tail extends PersistentListIdentityMap {
- final Object _key;
- final Object _val;
-
- Tail(Object key,Object val){
- this._key = key;
- this._val = val;
- }
-
- PersistentListIdentityMap next(){
- return EMPTY;
- }
-
- public int count(){
- return 1;
- }
-
- public Object get(Object key){
- if(key ==_key)
- return _val;
- return null;
- }
-
- public int capacity(){
- return 1;
- }
-
- public Object key(){
- return _key;
- }
-
- public Object val(){
- return _val;
- }
-
- public boolean contains(Object key){
- return key ==_key;
- }
-
- public IMapEntry find(Object key){
- if(key ==_key)
- return this;
- return null;
- }
-
- public PersistentListIdentityMap put(Object key, Object val){
- if(key == _key) //replace
- {
- if(val == _val)
- return this;
- return new Tail(key,val);
- }
- return new Link(key,val,this);
- }
-
- public PersistentListIdentityMap remove(Object key){
- if(key == _key)
- return EMPTY;
- return this;
- }
-
- public Object first() {
- return this;
- }
-
- public ISeq rest() {
- return null;
- }
-
- public ISeq seq() {
- return this;
- }
-}
-
-static class Link extends PersistentListIdentityMap {
- final Object _key;
- final Object _val;
- final PersistentListIdentityMap _rest;
-
- Link(Object key,Object val,PersistentListIdentityMap next){
- this._key = key;
- this._val = val;
- this._rest = next;
- }
-
- public Object key(){
- return _key;
- }
-
- public Object val(){
- return _val;
- }
-
- PersistentListIdentityMap next(){
- return _rest;
- }
-
- public int count(){
- return 1 + _rest.count();
- }
-
- public boolean contains(Object key){
- return find(key) != null;
- }
-
- public IMapEntry find(Object key){
- if(key ==_key)
- return this;
- return _rest.find(key);
- }
-
- public PersistentListIdentityMap put(Object key, Object val){
- IMapEntry e = find(key);
- if(e != null)
- {
- if(e.val() == val)
- return this;
- return create(_key,_val,remove(key));
- }
- return new Link(key,val,this);
- }
-
- public PersistentListIdentityMap remove(Object key){
- if(key == _key)
- return _rest;
- PersistentListIdentityMap r = _rest.remove(key);
- if(r == _rest) //not there
- return this;
- return create(_key,_val,r);
- }
-
- public Object get(Object key){
- IMapEntry e = find(key);
- if(e != null)
- return e.val();
- return null;
- }
-
- public int capacity(){
- return count();
- }
-
- public Object first() {
- return this;
- }
-
- public ISeq rest() {
- return _rest;
- }
-
- public ISeq seq() {
- return this;
- }
-
- PersistentListIdentityMap create(Object k,Object v,PersistentListIdentityMap r){
- if(r == EMPTY)
- return new Tail(k,v);
- return new Link(k, v, r);
- }
-
-}
-
-}
diff --git a/src/org/clojure/runtime/PersistentListMap.java b/src/org/clojure/runtime/PersistentListMap.java deleted file mode 100644 index 314da4cc..00000000 --- a/src/org/clojure/runtime/PersistentListMap.java +++ /dev/null @@ -1,290 +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 Jun 6, 2006 */ - -package org.clojure.runtime; - -import java.util.Iterator; - -/** - * Implementation of persistent map on a linked list - - * Note that instances of this class are constant values - * i.e. add/remove etc return new values - * - * Lookups/changes are linear, so only appropriate for _very_small_ maps - * PersistentArrayMap is generally faster, but this class avoids the double allocation, - * and so is better/faster as a bucket for hash tables - * - * null keys and values are ok, but you won't be able to distinguish a null value via get - use contains/find - */ -public class PersistentListMap implements IPersistentMap, IMapEntry, ISeq, ISequential -{ - -static public PersistentListMap EMPTY = new PersistentListMap(); - -static public PersistentListMap create(Object key, Object val){ - return new Tail(key, val); -} - - -public Object key(){ - return null; -} - -public Object val(){ - return null; -} - -PersistentListMap next(){ - return this; - } - -public int count(){ - return 0; -} - -public boolean contains(Object key){ - return false; -} - -public IMapEntry find(Object key){ - return null; -} - -public IPersistentMap add(Object key){ - return put(key, null); -} - -public PersistentListMap put(Object key, Object val){ - return new Tail(key, val); -} - -public PersistentListMap remove(Object key){ - return this; -} - -public Object get(Object key){ - return null; -} - -public int capacity(){ - return 0; -} - -public Object first() { - return null; -} - -public ISeq rest() { - return null; -} - -public ISeq seq() { - return null; -} - -static class Iter implements Iterator{ - PersistentListMap e; - - Iter(PersistentListMap e) - { - this.e = e; - } - - public boolean hasNext(){ - return e != EMPTY; - } - - public Object next(){ - PersistentListMap ret = e; - e = e.next(); - return ret; - } - - public void remove(){ - throw new UnsupportedOperationException(); - } -} - -public Iterator iterator(){ - return new Iter(this); -} - -static class Tail extends PersistentListMap { - final Object _key; - final Object _val; - - Tail(Object key,Object val){ - this._key = key; - this._val = val; - } - - PersistentListMap next(){ - return EMPTY; - } - - public int count(){ - return 1; - } - - public Object get(Object key){ - if(equalKey(key,_key)) - return _val; - return null; - } - - public int capacity(){ - return 1; - } - - public Object key(){ - return _key; - } - - public Object val(){ - return _val; - } - - public boolean contains(Object key){ - return equalKey(key,_key); - } - - public IMapEntry find(Object key){ - if(equalKey(key,_key)) - return this; - return null; - } - - public PersistentListMap put(Object key, Object val){ - if(equalKey(key,_key)) //replace - { - if(val == _val) - return this; - return new Tail(key,val); - } - return new Link(key,val,this); - } - - public PersistentListMap remove(Object key){ - if(equalKey(key,_key)) - return EMPTY; - return this; - } - - public Object first() { - return this; - } - - public ISeq rest() { - return null; - } - - public ISeq seq() { - return this; - } - -} - -static class Link extends PersistentListMap { - final Object _key; - final Object _val; - final PersistentListMap _rest; - - Link(Object key,Object val,PersistentListMap next){ - this._key = key; - this._val = val; - this._rest = next; - } - - public Object key(){ - return _key; - } - - public Object val(){ - return _val; - } - - PersistentListMap next(){ - return _rest; - } - - public int count(){ - return 1 + _rest.count(); - } - - public boolean contains(Object key){ - return find(key) != null; - } - - public IMapEntry find(Object key){ - if(equalKey(key,_key)) - return this; - return _rest.find(key); - } - - public PersistentListMap put(Object key, Object val){ - IMapEntry e = find(key); - if(e != null) - { - if(e.val() == val) - return this; - return create(_key,_val,remove(key)); - } - return new Link(key,val,this); - } - - public PersistentListMap remove(Object key){ - if(equalKey(key,_key)) - return _rest; - PersistentListMap r = _rest.remove(key); - if(r == _rest) //not there - return this; - return create(_key,_val,r); - } - - public Object get(Object key){ - IMapEntry e = find(key); - if(e != null) - return e.val(); - return null; - } - - public int capacity(){ - return count(); - } - - public Object first() { - return this; - } - - public ISeq rest() { - return _rest; - } - - public ISeq seq() { - return this; - } - - PersistentListMap create(Object k,Object v,PersistentListMap r){ - if(r == EMPTY) - return new Tail(k,v); - return new Link(k, v, r); - } - -} - -boolean equalKey(Object k1,Object k2){ - if(k1 == null) - return k2 == null; - return k1.equals(k2); -} -} diff --git a/src/org/clojure/runtime/PersistentTree.java b/src/org/clojure/runtime/PersistentTree.java deleted file mode 100644 index 2281f1f2..00000000 --- a/src/org/clojure/runtime/PersistentTree.java +++ /dev/null @@ -1,809 +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 May 20, 2006 */ - -package org.clojure.runtime; - -import java.util.*; - -/** - * Persistent Red Black Tree - * Note that instances of this class are constant values - * i.e. add/remove etc return new values - * <p/> - * See Okasaki, Kahrs, Larsen et al - */ - -public class PersistentTree implements IPersistentMap, ISequential { - -public final Comparator comp; -public final Node tree; -public final int _count; - -public PersistentTree(){ - this(null); -} - -public PersistentTree(Comparator comp){ - this.comp = comp; - tree = null; - _count = 0; -} - -public boolean contains(Object key){ - return find(key) != null; -} - -public PersistentTree add(Object key){ - return put(key, null); -} - -public PersistentTree put(Object key, Object val){ - Box found = new Box(null); - Node t = add(tree, key, val, found); - if(t == null) //null == already contains key - { - Node foundNode = (Node) found.val; - if(foundNode.val() == val) //note only get same collection on identity of val, not equals() - return this; - return new PersistentTree(comp, replace(tree, key, val), _count); - } - return new PersistentTree(comp, t.blacken(), _count + 1); -} - - -public PersistentTree remove(Object key){ - Box found = new Box(null); - Node t = remove(tree, key, found); - if(t == null) - { - if(found.val == null)//null == doesn't contain key - return this; - //empty - return new PersistentTree(comp); - } - return new PersistentTree(comp, t.blacken(), _count - 1); -} - -public ISeq seq() { - if(_count > 0) - return Seq.create(tree, true); - return null; -} - -public ISeq rseq() { - if(_count > 0) - return Seq.create(tree, false); - return null; -} - - -public NodeIterator iterator(){ - return new NodeIterator(tree, true); -} - -public NodeIterator reverseIterator(){ - return new NodeIterator(tree, false); -} - -public Iterator keys(){ - return keys(iterator()); -} - -public Iterator vals(){ - return vals(iterator()); -} - -public Iterator keys(NodeIterator it){ - return new KeyIterator(it); -} - -public Iterator vals(NodeIterator it){ - return new ValIterator(it); -} - -public Object minKey(){ - Node t = min(); - return t!=null?t.key:null; -} - -public Node min(){ - Node t = tree; - if(t != null) - { - while(t.left() != null) - t = t.left(); - } - return t; -} - -public Object maxKey(){ - Node t = max(); - return t!=null?t.key:null; -} - -public Node max(){ - Node t = tree; - if(t != null) - { - while(t.right() != null) - t = t.right(); - } - return t; -} - -public int depth(){ - return depth(tree); -} - -int depth(Node t){ - if(t == null) - return 0; - return 1 + Math.max(depth(t.left()), depth(t.right())); -} - -public Object get(Object key){ - Node n = find(key); - return (n != null) ? n.val() : null; -} - -public int capacity() { - return _count; -} - -public int count() { - return _count; -} - -public Node find(Object key){ - Node t = tree; - while(t != null) - { - int c = compare(key, t.key); - if(c == 0) - return t; - else if(c < 0) - t = t.left(); - else - t = t.right(); - } - return t; -} - -int compare(Object k1, Object k2){ - if(comp != null) - return comp.compare(k1, k2); - return ((Comparable) k1).compareTo(k2); -} - -Node add(Node t, Object key, Object val, Box found){ - if(t == null) - { - if(val == null) - return new Red(key); - return new RedVal(key, val); - } - int c = compare(key, t.key); - if(c == 0) - { - found.val = t; - return null; - } - Node ins = c < 0 ? add(t.left(), key, val, found) : add(t.right(), key, val, found); - if(ins == null) //found below - return null; - if(c < 0) - return t.addLeft(ins); - return t.addRight(ins); -} - -Node remove(Node t, Object key, Box found){ - if(t == null) - return null; //not found indicator - int c = compare(key, t.key); - if(c == 0) - { - found.val = t; - return append(t.left(), t.right()); - } - Node del = c < 0 ? remove(t.left(), key, found) : remove(t.right(), key, found); - if(del == null && found.val == null) //not found below - return null; - if(c < 0) - { - if(t.left() instanceof Black) - return balanceLeftDel(t.key, t.val(), del, t.right()); - else - return red(t.key, t.val(), del, t.right()); - } - if(t.right() instanceof Black) - return balanceRightDel(t.key, t.val(), t.left(), del); - return red(t.key, t.val(), t.left(), del); -// return t.removeLeft(del); -// return t.removeRight(del); -} - -static Node append(Node left, Node right){ - if(left == null) - return right; - else if(right == null) - return left; - else if(left instanceof Red) - { - if(right instanceof Red) - { - Node app = append(left.right(), right.left()); - if(app instanceof Red) - return red(app.key, app.val(), - red(left.key, left.val(), left.left(), app.left()), - red(right.key, right.val(), app.right(), right.right())); - else - return red(left.key, left.val(), left.left(), red(right.key, right.val(), app, right.right())); - } - else - return red(left.key, left.val(), left.left(), append(left.right(), right)); - } - else if(right instanceof Red) - return red(right.key, right.val(), append(left, right.left()), right.right()); - else //black/black - { - Node app = append(left.right(), right.left()); - if(app instanceof Red) - return red(app.key, app.val(), - black(left.key, left.val(), left.left(), app.left()), - black(right.key, right.val(), app.right(), right.right())); - else - return balanceLeftDel(left.key, left.val(), left.left(), black(right.key, right.val(), app, right.right())); - } -} - -static Node balanceLeftDel(Object key, Object val, Node del, Node right){ - if(del instanceof Red) - return red(key, val, del.blacken(), right); - else if(right instanceof Black) - return rightBalance(key, val, del, right.redden()); - else if(right instanceof Red && right.left() instanceof Black) - return red(right.left().key, right.left().val(), - black(key, val, del, right.left().left()), - rightBalance(right.key, right.val(), right.left().right(), right.right().redden())); - else - throw new UnsupportedOperationException("Invariant violation"); -} - -static Node balanceRightDel(Object key, Object val, Node left, Node del){ - if(del instanceof Red) - return red(key, val, left, del.blacken()); - else if(left instanceof Black) - return leftBalance(key, val, left.redden(), del); - else if(left instanceof Red && left.right() instanceof Black) - return red(left.right().key, left.right().val(), - leftBalance(left.key, left.val(), left.left().redden(), left.right().left()), - black(key, val, left.right().right(), del)); - else - throw new UnsupportedOperationException("Invariant violation"); -} - -static Node leftBalance(Object key, Object val, Node ins, Node right){ - if(ins instanceof Red && ins.left() instanceof Red) - return red(ins.key, ins.val(), ins.left().blacken(), black(key, val, ins.right(), right)); - else if(ins instanceof Red && ins.right() instanceof Red) - return red(ins.right().key, ins.right().val(), - black(ins.key, ins.val(), ins.left(), ins.right().left()), - black(key, val, ins.right().right(), right)); - else - return black(key, val, ins, right); -} - - -static Node rightBalance(Object key, Object val, Node left, Node ins){ - if(ins instanceof Red && ins.right() instanceof Red) - return red(ins.key, ins.val(), black(key, val, left, ins.left()), ins.right().blacken()); - else if(ins instanceof Red && ins.left() instanceof Red) - return red(ins.left().key, ins.left().val(), - black(key, val, left, ins.left().left()), - black(ins.key, ins.val(), ins.left().right(), ins.right())); - else - return black(key, val, left, ins); -} - -Node replace(Node t, Object key, Object val){ - int c = compare(key, t.key); - return t.replace(t.key, - c == 0 ? val : t.val(), - c < 0 ? replace(t.left(), key, val) : t.left(), - c > 0 ? replace(t.right(), key, val) : t.right()); -} - -PersistentTree(Comparator comp, Node tree, int count){ - this.comp = comp; - this.tree = tree; - this._count = count; -} - -static Red red(Object key, Object val, Node left, Node right){ - if(left == null && right == null) - { - if(val == null) - return new Red(key); - return new RedVal(key, val); - } - if(val == null) - return new RedBranch(key, left, right); - return new RedBranchVal(key, val, left, right); -} - -static Black black(Object key, Object val, Node left, Node right){ - if(left == null && right == null) - { - if(val == null) - return new Black(key); - return new BlackVal(key, val); - } - if(val == null) - return new BlackBranch(key, left, right); - return new BlackBranchVal(key, val, left, right); -} - -static abstract class Node implements IMapEntry { - final Object key; - - Node(Object key){ - this.key = key; - } - - public Object key(){ - return key; - } - - public Object val(){ - return null; - } - - Node left(){ - return null; - } - - Node right(){ - return null; - } - - abstract Node addLeft(Node ins); - - abstract Node addRight(Node ins); - - abstract Node removeLeft(Node del); - - abstract Node removeRight(Node del); - - abstract Node blacken(); - - abstract Node redden(); - - Node balanceLeft(Node parent){ - return black(parent.key, parent.val(), this, parent.right()); - } - - Node balanceRight(Node parent){ - return black(parent.key, parent.val(), parent.left(), this); - } - - abstract Node replace(Object key, Object val, Node left, Node right); - -} -static class Black extends Node{ - public Black(Object key){ - super(key); - } - - Node addLeft(Node ins){ - return ins.balanceLeft(this); - } - - Node addRight(Node ins){ - return ins.balanceRight(this); - } - - Node removeLeft(Node del){ - return balanceLeftDel(key, val(), del, right()); - } - - Node removeRight(Node del){ - return balanceRightDel(key, val(), left(), del); - } - - Node blacken(){ - return this; - } - - Node redden(){ - return new Red(key); - } - - Node replace(Object key, Object val, Node left, Node right){ - return black(key, val, left, right); - } - -} -static class BlackVal extends Black{ - final Object val; - - public BlackVal(Object key, Object val){ - super(key); - this.val = val; - } - - public Object val(){ - return val; - } - - Node redden(){ - return new RedVal(key, val); - } - -} -static class BlackBranch extends Black{ - final Node left; - - final Node right; - - public BlackBranch(Object key, Node left, Node right){ - super(key); - this.left = left; - this.right = right; - } - - public Node left(){ - return left; - } - - public Node right(){ - return right; - } - - Node redden(){ - return new RedBranch(key, left, right); - } - -} -static class BlackBranchVal extends BlackBranch{ - final Object val; - - public BlackBranchVal(Object key, Object val, Node left, Node right){ - super(key, left, right); - this.val = val; - } - - public Object val(){ - return val; - } - - Node redden(){ - return new RedBranchVal(key, val, left, right); - } - -} -static class Red extends Node{ - public Red(Object key){ - super(key); - } - - Node addLeft(Node ins){ - return red(key, val(), ins, right()); - } - - Node addRight(Node ins){ - return red(key, val(), left(), ins); - } - - Node removeLeft(Node del){ - return red(key, val(), del, right()); - } - - Node removeRight(Node del){ - return red(key, val(), left(), del); - } - - Node blacken(){ - return new Black(key); - } - - Node redden(){ - throw new UnsupportedOperationException("Invariant violation"); - } - - Node replace(Object key, Object val, Node left, Node right){ - return red(key, val, left, right); - } - -} -static class RedVal extends Red{ - final Object val; - - public RedVal(Object key, Object val){ - super(key); - this.val = val; - } - - public Object val(){ - return val; - } - - Node blacken(){ - return new BlackVal(key, val); - } - -} -static class RedBranch extends Red{ - final Node left; - - final Node right; - - public RedBranch(Object key, Node left, Node right){ - super(key); - this.left = left; - this.right = right; - } - - public Node left(){ - return left; - } - - public Node right(){ - return right; - } - - Node balanceLeft(Node parent){ - if(left instanceof Red) - return red(key, val(), left.blacken(), black(parent.key, parent.val(), right, parent.right())); - else if(right instanceof Red) - return red(right.key, right.val(), black(key, val(), left, right.left()), - black(parent.key, parent.val(), right.right(), parent.right())); - else - return super.balanceLeft(parent); - - } - - Node balanceRight(Node parent){ - if(right instanceof Red) - return red(key, val(), black(parent.key, parent.val(), parent.left(), left), right.blacken()); - else if(left instanceof Red) - return red(left.key, left.val(), black(parent.key, parent.val(), parent.left(), left.left()), - black(key, val(), left.right(), right)); - else - return super.balanceRight(parent); - } - - Node blacken(){ - return new BlackBranch(key, left, right); - } - -} - - -static class RedBranchVal extends RedBranch{ - final Object val; - - public RedBranchVal(Object key, Object val, Node left, Node right){ - super(key, left, right); - this.val = val; - } - - public Object val(){ - return val; - } - - Node blacken(){ - return new BlackBranchVal(key, val, left, right); - } -} - - -static public class Seq implements ISeq{ - final ISeq stack; - final boolean asc; - - public Seq(ISeq stack, boolean asc) { - this.stack = stack; - this.asc = asc; - } - - static Seq create(Node t, boolean asc){ - return new Seq(push(t, null, asc),asc); - } - - static ISeq push(Node t, ISeq stack, boolean asc){ - while(t != null) - { - stack = RT.cons(t,stack); - t = asc ? t.left() : t.right(); - } - return stack; - } - - public Object first() throws Exception { - return stack.first(); - } - - public ISeq rest() throws Exception { - Node t = (Node)stack.first(); - ISeq nextstack = push(asc ? t.right() : t.left(), stack.rest(), asc); - if(nextstack != null) - { - return new Seq(nextstack,asc); - } - return null; - } -} - -static public class NodeIterator implements Iterator{ - Stack stack = new Stack(); - boolean asc; - - NodeIterator(Node t, boolean asc){ - this.asc = asc; - push(t); - } - - void push(Node t){ - while(t != null) - { - stack.push(t); - t = asc ? t.left() : t.right(); - } - } - - public boolean hasNext(){ - return !stack.isEmpty(); - } - - public Object next(){ - Node t = (Node) stack.pop(); - push(asc ? t.right() : t.left()); - return t; - } - - public void remove(){ - throw new UnsupportedOperationException(); - } -} - -static class KeyIterator implements Iterator{ - NodeIterator it; - - KeyIterator(NodeIterator it){ - this.it = it; - } - - public boolean hasNext(){ - return it.hasNext(); - } - - public Object next(){ - return ((Node) it.next()).key; - } - - public void remove(){ - throw new UnsupportedOperationException(); - } -} - -static class ValIterator implements Iterator{ - NodeIterator it; - - ValIterator(NodeIterator it){ - this.it = it; - } - - public boolean hasNext(){ - return it.hasNext(); - } - - public Object next(){ - return ((Node) it.next()).val(); - } - - public void remove(){ - throw new UnsupportedOperationException(); - } -} - -static public void main(String args[]){ - if(args.length != 1) - System.err.println("Usage: RBTree n"); - int n = Integer.parseInt(args[0]); - Integer[] ints = new Integer[n]; - for(int i = 0; i < ints.length; i++) - { - ints[i] = new Integer(i); - } - Collections.shuffle(Arrays.asList(ints)); - //force the ListMap class loading now - PersistentListMap.EMPTY.add(1).add(2).add(3); - System.out.println("Building set"); - //IPersistentMap set = new PersistentHybridMap(1001); - IPersistentMap set = new PersistentHashtableMap(1001); - //IPersistentMap set = new ListMap(); - //IPersistentMap set = new ArrayMap(); - //IPersistentMap set = new RBTree(); -// for(int i = 0; i < ints.length; i++) -// { -// Integer anInt = ints[i]; -// set = set.add(anInt); -// } - long startTime = System.nanoTime(); - for(int i = 0; i < ints.length; i++) - { - Integer anInt = ints[i]; - set = set.put(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()) - { - IMapEntry o = (IMapEntry) it.next(); - if(!set.contains(o.key())) - System.err.println("Can't find: " + o); - //else if(n < 2000) - // System.out.print(o.key().toString() + ","); - } - - for(int i = 0; i < ints.length/2; i++) - { - Integer anInt = ints[i]; - set = set.remove(anInt); - } - - long estimatedTime = System.nanoTime() - startTime; - System.out.println(); - - System.out.println("_count = " + set.count() + ", time: " + estimatedTime/10000); - - System.out.println("Building ht"); - Hashtable ht = new Hashtable(1001); - startTime = System.nanoTime(); -// for(int i = 0; i < ints.length; i++) -// { -// Integer anInt = ints[i]; -// ht.put(anInt,null); -// } - for(int i = 0; i < ints.length; i++) - { - Integer anInt = ints[i]; - ht.put(anInt, anInt); - } - //System.out.println("size = " + ht.size()); - it = ht.entrySet().iterator(); - while(it.hasNext()) - { - Map.Entry o = (Map.Entry) it.next(); - if(!ht.containsKey(o.getKey())) - System.err.println("Can't find: " + o); - //else if(n < 2000) - // System.out.print(o.toString() + ","); - } - - for(int i = 0; i < ints.length/2; i++) - { - Integer anInt = ints[i]; - ht.remove(anInt); - } - estimatedTime = System.nanoTime() - startTime; - System.out.println(); - System.out.println("size = " + ht.size() + ", time: " + estimatedTime/10000); - -// System.out.println("_count = " + set._count + ", min: " + set.minKey() + ", max: " + set.maxKey() -// + ", depth: " + set.depth()); -} -} diff --git a/src/org/clojure/runtime/RT.java b/src/org/clojure/runtime/RT.java deleted file mode 100644 index 33c86974..00000000 --- a/src/org/clojure/runtime/RT.java +++ /dev/null @@ -1,319 +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 Mar 25, 2006 4:28:27 PM */ - -package org.clojure.runtime; - -import java.util.Iterator; -import java.io.Reader; -import java.io.PushbackReader; - -public class RT{ - - static public Symbol T = Symbol.intern("t"); - static public final Object[] EMPTY_ARRAY = new Object[]{}; - static public final Character[] chars; - - static { - chars = new Character[256]; - for(int i=0;i<chars.length;i++) - chars[i] = new Character((char)i); - } - - - static public Object eq(Object arg1, Object arg2) { - return (arg1 == arg2)?Boolean.TRUE:null; - } - - static public Object eql(Object arg1, Object arg2) { - if(arg1 == arg2) - return Boolean.TRUE; - if(arg1 == null || arg2 == null) - return null; - if(arg1 instanceof Num - && arg1.getClass() == arg2.getClass() - && arg1.equals(arg2)) - return Boolean.TRUE; - if(arg1.getClass() == Character.class - && arg2.getClass() == Character.class - && arg1.equals(arg2)) - return Boolean.TRUE; - return null; - } - -// static public Object equal(Object arg1, Object arg2) { -// if(arg1 == null) -// return arg2 == null ? Boolean.TRUE : null; -// else if(arg2 == null) -// return null; -// return (eql(arg1,arg2) != null -// || (arg1.getClass() == Cons.class -// && arg2.getClass() == Cons.class -// && equal(((Cons)arg1)._first,((Cons)arg2)._first)!=null -// && equal(((Cons)arg1)._rest,((Cons)arg2)._rest)!=null)) -// ?Boolean.TRUE:null; -// } - -static public Iter iter(Object coll) - { - if(coll == null || coll instanceof Iter) - return (Iter) coll; - else if(coll instanceof Iterator) - { - Iterator i = (Iterator) coll; - if(i.hasNext()) - return new IteratorIter(i); - return null; - } - else if(coll instanceof Iterable) - return new IteratorIter(((Iterable) coll).iterator()); - - else - throw new IllegalArgumentException("Don't know how to create Iter from arg"); - } - -/************************ Boxing/casts *******************************/ -static public Object box(Object x) - { - return x; - } - -static public Character box(char x) - { - if(x < chars.length) - return chars[x]; - return new Character(x); - } - -static public Boolean box(boolean x) - { - return Boolean.valueOf(x); - } - -static public Byte box(byte x) - { - return new Byte(x); - } - -static public Short box(short x) - { - return new Short(x); - } - -static public Integer box(int x) - { - return new Integer(x); - } - -static public Long box(long x) - { - return new Long(x); - } - -static public Float box(float x) - { - return new Float(x); - } - -static public Double box(double x) - { - return new Double(x); - } - -static public char charCast(Object x) - { - if(x instanceof Character) - return ((Character)x).charValue(); - return (char) ((Number)x).intValue(); - } - -static public boolean booleanCast(Object x) - { - if(x instanceof Boolean) - return ((Boolean)x).booleanValue(); - return x != null; - } - -static public byte byteCast(Object x) - { - return ((Number)x).byteValue(); - } - -static public short shortCast(Object x) - { - return ((Number)x).shortValue(); - } - -static public int intCast(Object x) - { - return ((Number)x).intValue(); - } - -static public long longCast(Object x) - { - return ((Number)x).longValue(); - } - -static public float floatCast(Object x) - { - return ((Number)x).floatValue(); - } - -static public double doubleCast(Object x) - { - return ((Number)x).doubleValue(); - } - - -/******************************************* list support ********************************/ -static public Cons cons(Object x, ISeq y) - { - return new Cons(x, y); - } - -static public Cons list() - { - return null; - } - -static public Cons list(Object arg1) - { - return cons(arg1, null); - } - -static public Cons list(Object arg1, Object arg2) - { - return listStar(arg1, arg2, null); - } - -static public Cons list(Object arg1, Object arg2, Object arg3) - { - return listStar(arg1, arg2, arg3, null); - } - -static public Cons list(Object arg1, Object arg2, Object arg3, Object arg4) - { - return listStar(arg1, arg2, arg3, arg4, null); - } - -static public Cons list(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) - { - return listStar(arg1, arg2, arg3, arg4, arg5, null); - } - -static public Cons listStar(Object arg1, ISeq rest) - { - return cons(arg1, rest); - } - -static public Cons listStar(Object arg1, Object arg2, ISeq rest) - { - return cons(arg1, cons(arg2, rest)); - } - -static public Cons listStar(Object arg1, Object arg2, Object arg3, ISeq rest) - { - return cons(arg1, cons(arg2, cons(arg3, rest))); - } - -static public Cons listStar(Object arg1, Object arg2, Object arg3, Object arg4, ISeq rest) - { - return cons(arg1, cons(arg2, cons(arg3, cons(arg4, rest)))); - } - -static public Cons listStar(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, ISeq rest) - { - return cons(arg1, cons(arg2, cons(arg3, cons(arg4, cons(arg5, rest))))); - } - -static public Cons arrayToList(Object[] a){ - Cons ret = null; - for(int i=a.length-1;i>=0;--i) - ret = cons(a[i], ret); - return ret; -} - -static public int length(ISeq list) throws Exception { -int i = 0; -for(ISeq c = list; c != null; c = c.rest()) - { - i++; - } -return i; -} - -static public int boundedLength(ISeq list, int limit) throws Exception { -int i = 0; -for(ISeq c = list; c != null && i <= limit; c = c.rest()) - { - i++; - } -return i; -} - - -///////////////////////////////// reader support //////////////////////////////// - -static Object readRet(int ret){ - if(ret == -1) - return null; - return box((char) ret); -} - -static public Object readChar(Reader r) throws Exception { - int ret = r.read(); - return readRet(ret); -} - -static public Object peekChar(Reader r) throws Exception { - int ret; - if(r instanceof PushbackReader) - { - ret = r.read(); - ((PushbackReader) r).unread(ret); - } - else - { - r.mark(1); - ret = r.read(); - r.reset(); - } - - return readRet(ret); -} - -static public int getLineNumber(Reader r){ - if(r instanceof LineNumberingPushbackReader) - return ((LineNumberingPushbackReader)r).getLineNumber(); - return 0; -} - -static public Reader getLineNumberingReader(Reader r) { - if(isLineNumberingReader(r)) - return r; - return new LineNumberingPushbackReader(r); -} - -static public boolean isLineNumberingReader(Reader r) { - return r instanceof LineNumberingPushbackReader; -} - -///////////////////////////////// values ////////////////////////// - -static public Object setValues(Object... vals) - { - ThreadLocalData.setValues(vals); - if(vals.length > 0) - return vals[0]; - return null; - } - -} diff --git a/src/org/clojure/runtime/RatioNum.java b/src/org/clojure/runtime/RatioNum.java deleted file mode 100644 index 9bc5e7d0..00000000 --- a/src/org/clojure/runtime/RatioNum.java +++ /dev/null @@ -1,226 +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 Mar 28, 2006 10:14:44 AM */ - -package org.clojure.runtime; - -import java.math.BigInteger; - -public class RatioNum extends RationalNum{ -public boolean equals(Object arg0) - { - return arg0 != null - && arg0 instanceof RatioNum - && ((RatioNum) arg0).numerator.equals(numerator) - && ((RatioNum) arg0).denominator.equals(denominator); - } - -public int hashCode() - { - return numerator.hashCode() ^ denominator.hashCode(); - } - -public String toString() - { - return numerator.toString() + "/" + denominator.toString(); - } - -public IntegerNum numerator; -public IntegerNum denominator; - -public RatioNum(IntegerNum n, IntegerNum d) - { - this.numerator = n; - this.denominator = d; - } - -public double doubleValue() - { - return numerator.doubleValue() / denominator.doubleValue(); - } - -public float floatValue() - { - return (float) doubleValue(); - } - -public int intValue() - { - return (int) doubleValue(); - } - -public long longValue() - { - return (long) doubleValue(); - } - -public boolean equiv(Num rhs) - { - return rhs.equivTo(this); - } - -public boolean equivTo(BigInteger x) - { - return false; - } - -public boolean equivTo(int x) - { - return false; - } - -public boolean equivTo(RatioNum x) - { - return numerator.equiv(x.numerator) && denominator.equiv(x.denominator); - } - -public boolean lt(Num rhs) - { - return rhs.gt(this); - } - -public boolean gt(BigInteger x) - { - return denominator.multiply(x).lt(numerator); - } - -public boolean gt(int x) - { - return denominator.multiply(x).lt(numerator); - } - -public boolean gt(RatioNum x) - { - return x.numerator.multiplyBy(denominator).lt(numerator.multiplyBy(x.denominator)); - } - -public Num add(Num rhs) - { - return rhs.addTo(this); - } - -public Num addTo(BigInteger x) - { - return Num.divide(numerator.add(denominator.multiply(x)), denominator); - } - -public Num addTo(int x) - { - return Num.divide(numerator.add(denominator.multiply(x)), denominator); - } - -public Num addTo(RatioNum x) - { - return Num.divide(numerator.multiplyBy(x.denominator) - .add(x.numerator.multiplyBy(denominator)) - , denominator.multiplyBy(x.denominator)); - } - -public Num subtractFrom(Num x) - { - return x.add(this.multiply(-1)); - } - -public Num multiplyBy(Num rhs) - { - return rhs.multiply(this); - } - -public Num multiply(BigInteger x) - { - return Num.divide(numerator.multiply(x), denominator); - } - -public Num multiply(int x) - { - return Num.divide(numerator.multiply(x), denominator); - } - -public Num multiply(RatioNum x) - { - return Num.divide(numerator.multiplyBy(x.numerator) - , denominator.multiplyBy(x.denominator)); - } - -public Num divideBy(Num rhs) - { - return rhs.divide(this); - } - -public Num divide(BigInteger n) - { - return Num.divide(denominator.multiply(n), numerator); - } - -public Num divide(int n) - { - return Num.divide(denominator.multiply(n), numerator); - } - -public Num divide(RatioNum n) - { - return Num.divide(denominator.multiplyBy(n.numerator) - , numerator.multiplyBy(n.denominator)); - } - - -public Object truncateDivide( Num num) - { - return num.truncateBy( this); - } - -public Object truncateBy( int div) - { - Num q = (Num) Num.truncate( numerator, denominator.multiply(div)); - return RT.setValues( q, q.multiply(div).subtractFrom(this)); - } - -public Object truncateBy( BigInteger div) - { - Num q = (Num) Num.truncate( numerator, denominator.multiply(div)); - return RT.setValues( q, q.multiply(div).subtractFrom(this)); - } - -public Object truncateBy( RatioNum div) - { - Num q = (Num) Num.truncate( numerator.multiplyBy(div.denominator), - denominator.multiplyBy(div.numerator)); - return RT.setValues( q, q.multiplyBy(div).subtractFrom(this)); - } - - -public Num negate() - { - return Num.divide(numerator.negate(), denominator); - } - -public boolean minusp() - { - return numerator.minusp(); - } - -public boolean plusp() - { - return numerator.plusp(); - } - -public Num oneMinus() - { - return addTo(-1); - } - -public Num onePlus() - { - return addTo(1); - } - -} - diff --git a/src/org/clojure/runtime/RationalNum.java b/src/org/clojure/runtime/RationalNum.java deleted file mode 100644 index 81cd16b5..00000000 --- a/src/org/clojure/runtime/RationalNum.java +++ /dev/null @@ -1,17 +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 Mar 28, 2006 10:12:30 AM */ - -package org.clojure.runtime; - -public abstract class RationalNum extends RealNum { - -} diff --git a/src/org/clojure/runtime/RealNum.java b/src/org/clojure/runtime/RealNum.java deleted file mode 100644 index 387f0a23..00000000 --- a/src/org/clojure/runtime/RealNum.java +++ /dev/null @@ -1,17 +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 Mar 28, 2006 10:13:00 AM */ - -package org.clojure.runtime; - -public abstract class RealNum extends Num { - -} diff --git a/src/org/clojure/runtime/Reflector.java b/src/org/clojure/runtime/Reflector.java deleted file mode 100644 index f101b3b5..00000000 --- a/src/org/clojure/runtime/Reflector.java +++ /dev/null @@ -1,320 +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 org.clojure.runtime; - -import java.lang.reflect.*; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -public class Reflector{ - -public static Object invokeInstanceMethod(String name, Object target, Object[] args) throws Exception - { - Class c = target.getClass(); - List methods = getMethods(c, args.length, name,false); - return prepRet(invokeMatchingMethod(methods, target, args)); - } - -private static Object invokeMatchingMethod(List methods, Object target, Object[] args) - throws IllegalAccessException, InvocationTargetException { - if(methods.isEmpty()) - { - throw new IllegalArgumentException("No matching field or method found"); - } - else if(methods.size() == 1) - { - Method m = (Method) methods.get(0); - return prepRet(m.invoke(target, boxArgs(m.getParameterTypes(), args))); - } - else //overloaded w/same arity - { - for(Iterator i = methods.iterator(); i.hasNext();) - { - Method m = (Method) i.next(); - - Class[] params = m.getParameterTypes(); - if(isCongruent(params, args)) - { - Object[] boxedArgs = boxArgs(params, args); - return prepRet(m.invoke(target, boxedArgs)); - } - } - throw new IllegalArgumentException("No matching field or method found"); - - } -} - -public static Object invokeConstructor(Class c, Object[] args) throws Exception - { - Constructor[] allctors = c.getConstructors(); - ArrayList ctors = new ArrayList(); - for(int i = 0; i < allctors.length; i++) - { - Constructor ctor = allctors[i]; - if(ctor.getParameterTypes().length == args.length) - ctors.add(ctor); - } - if(ctors.isEmpty()) - { - throw new IllegalArgumentException("No matching ctor found"); - } - else if(ctors.size() == 1) - { - Constructor ctor = (Constructor) ctors.get(0); - return ctor.newInstance(boxArgs(ctor.getParameterTypes(), args)); - } - else //overloaded w/same arity - { - for(Iterator iterator = ctors.iterator(); iterator.hasNext();) - { - Constructor ctor = (Constructor) iterator.next(); - Class[] params = ctor.getParameterTypes(); - if(isCongruent(params, args)) - { - Object[] boxedArgs = boxArgs(params, args); - return ctor.newInstance(boxedArgs); - } - } - throw new IllegalArgumentException("No matching ctor found"); - } - } - -public static Object invokeStaticMethod(String name, String className, Object[] args) throws Exception - { - Class c = Class.forName(className); - if(name.equals("new")) - return invokeConstructor(c, args); - List methods = getMethods(c, args.length, name,true); - return invokeMatchingMethod(methods, null, args); - } - -public static Object getStaticField(String name, String className) throws Exception - { - Class c = Class.forName(className); - Field f = getField(c, name,true); - if(f != null) - { - return prepRet(f.get(null)); - } - throw new IllegalArgumentException("No matching field found"); - } - - public static Object setStaticField(String name, String className, Object arg1) throws Exception - { - Class c = Class.forName(className); - Field f = getField(c, name,true); - if(f != null) - { - f.set(null, boxArg(f.getType(), arg1)); - return arg1; - } - throw new IllegalArgumentException("No matching field found"); - } - -public static Object invokeInstanceMember(String name, Object target) throws Exception - { - //check for field first - Class c = target.getClass(); - Field f = getField(c, name,false); - if(f != null) //field get - { - return prepRet(f.get(target)); - } - return invokeInstanceMethod(name, target, RT.EMPTY_ARRAY); - } - -public static Object invokeInstanceMember(String name, Object target, Object arg1) throws Exception - { - //check for field first - Class c = target.getClass(); - Field f = getField(c, name,false); - if(f != null) //field set - { - f.set(target, boxArg(f.getType(), arg1)); - return arg1; - } - return invokeInstanceMethod(name, target, new Object[]{arg1}); - } - -public static Object invokeInstanceMember(String name, Object target, Object arg1, Object arg2) throws Exception - { - return invokeInstanceMethod(name, target, new Object[]{arg1, arg2}); - } - -public static Object invokeInstanceMember(String name, Object target, Object arg1, Object arg2, Object arg3) - throws Exception - { - return invokeInstanceMethod(name, target, new Object[]{arg1, arg2, arg3}); - } - -public static Object invokeInstanceMember(String name, Object target, Object arg1, Object arg2, Object arg3, - Object arg4) - throws Exception - { - return invokeInstanceMethod(name, target, new Object[]{arg1, arg2, arg3, arg4}); - } - -public static Object invokeInstanceMember(String name, Object target, Object arg1, Object arg2, Object arg3, - Object arg4, - ISeq arglist) - throws Exception - { - Object[] args = new Object[4 + RT.length(arglist)]; - args[0] = arg1; - args[1] = arg2; - args[2] = arg3; - args[3] = arg4; - for(int i = 4; arglist != null; i++, arglist = arglist.rest()) - args[i] = arglist.first(); - return invokeInstanceMethod(name, target, args); - } - - -static public Field getField(Class c, String name, boolean getStatics) - { - Field[] allfields = c.getFields(); - for(int i = 0; i < allfields.length; i++) - { - if(name.equals(allfields[i].getName()) - && Modifier.isStatic(allfields[i].getModifiers()) == getStatics) - return allfields[i]; - } - return null; - } - -static public List getMethods(Class c, int arity, String name, boolean getStatics) - { - Method[] allmethods = c.getMethods(); - ArrayList methods = new ArrayList(); - for(int i = 0; i < allmethods.length; i++) - { - if(name.equals(allmethods[i].getName()) - && Modifier.isStatic(allmethods[i].getModifiers()) == getStatics - && allmethods[i].getParameterTypes().length == arity) - { - methods.add(allmethods[i]); - } - } - return methods; - } - - -static Object boxArg(Class paramType, Object arg) - { - Class argType = arg.getClass(); - if(primBoxTypeMatch(paramType, argType)) - return arg; - if(paramType == boolean.class) - { - if(arg == null) - return Boolean.FALSE; - return Boolean.TRUE; - } - else if(paramType.isPrimitive() && arg instanceof Num) - { - Num n = (Num) arg; - if(paramType == int.class) - return RT.box(n.intValue()); - else if(paramType == float.class) - return RT.box(n.floatValue()); - else if(paramType == double.class) - return RT.box(n.doubleValue()); - else if(paramType == long.class) - return RT.box(n.longValue()); - else if(paramType == char.class) - return RT.box((char) n.intValue()); - else if(paramType == short.class) - return RT.box(n.shortValue()); - else - return RT.box(n.byteValue()); - } - else - return arg; - } - -static Object[] boxArgs(Class[] params, Object[] args) - { - if(params.length == 0) - return null; - Object[] ret = new Object[params.length]; - for(int i = 0; i < params.length; i++) - { - Object arg = args[i]; - Class paramType = params[i]; - ret[i] = boxArg(paramType, arg); - } - return ret; - } - -static public boolean primBoxTypeMatch(Class primType, Class boxType) - { - if(primType == int.class) - return boxType == Integer.class; - else if(primType == float.class) - return boxType == Float.class; - else if(primType == double.class) - return boxType == Double.class; - else if(primType == long.class) - return boxType == Long.class; - else if(primType == char.class) - return boxType == Character.class; - else if(primType == short.class) - return boxType == Short.class; - else if(primType == byte.class) - return boxType == Byte.class; - return false; - } - -static boolean isCongruent(Class[] params, Object[] args) - { - boolean ret = false; - if(args == null) - return params.length == 0; - if(params.length == args.length) - { - ret = true; - for(int i = 0; ret && i < params.length; i++) - { - Object arg = args[i]; - Class argType = (arg == null) ? null : arg.getClass(); - Class paramType = params[i]; - if(paramType == boolean.class) - { - ret = arg == null || argType == Boolean.class; - } - else if(paramType.isPrimitive()) - { - if(arg == null) - ret = false; - else - ret = primBoxTypeMatch(paramType, argType); - } - else - { - ret = arg == null - || argType == paramType - || paramType.isAssignableFrom(argType); - } - } - } - return ret; - } - -static Object prepRet(Object x) - { - if(x instanceof Boolean) - return ((Boolean)x).booleanValue()?RT.T:null; - return x; - } -} diff --git a/src/org/clojure/runtime/RestFn0.java b/src/org/clojure/runtime/RestFn0.java deleted file mode 100644 index 5dc8f2a1..00000000 --- a/src/org/clojure/runtime/RestFn0.java +++ /dev/null @@ -1,60 +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 Mar 27, 2006 7:34:25 PM */ - -package org.clojure.runtime; - -public abstract class RestFn0 extends AFn{ - -protected abstract Object doInvoke( ISeq rest) throws Exception; - -public Object applyTo( ISeq arglist) throws Exception - { - return doInvoke( arglist); - } - -public Object invoke() throws Exception - { - return doInvoke( null); - } - -public Object invoke( Object arg1) throws Exception - { - return doInvoke( RT.list(arg1)); - } - -public Object invoke( Object arg1, Object arg2) throws Exception - { - return doInvoke( RT.list(arg1, arg2)); - } - -public Object invoke( Object arg1, Object arg2, Object arg3) throws Exception - { - return doInvoke( RT.list(arg1, arg2, arg3)); - } - -public Object invoke( Object arg1, Object arg2, Object arg3, Object arg4) throws Exception - { - return doInvoke( RT.list(arg1, arg2, arg3, arg4)); - } - -public Object invoke( Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) - throws Exception - { - return doInvoke( RT.list(arg1, arg2, arg3, arg4, arg5)); - } - -public Object invoke( Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, ISeq args) - throws Exception - { - return doInvoke( RT.listStar(arg1, arg2, arg3, arg4, arg5, args)); - } -} diff --git a/src/org/clojure/runtime/RestFn1.java b/src/org/clojure/runtime/RestFn1.java deleted file mode 100644 index 15e78635..00000000 --- a/src/org/clojure/runtime/RestFn1.java +++ /dev/null @@ -1,65 +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 Mar 27, 2006 8:00:28 PM */ - -package org.clojure.runtime; - -public abstract class RestFn1 extends AFn{ - -protected abstract Object doInvoke( Object arg1, ISeq rest) throws Exception; - -public Object applyTo( ISeq arglist) throws Exception - { - switch(RT.boundedLength(arglist, 1)) - { - case 0: - return invoke(); - case 1: - return invoke(arglist.first()); - default: - return doInvoke( arglist.first() - , arglist.rest()); - } - } - -public Object invoke( Object arg1) throws Exception - { - return doInvoke( arg1, null); - } - -public Object invoke( Object arg1, Object arg2) throws Exception - { - return doInvoke( arg1, RT.list(arg2)); - } - -public Object invoke( Object arg1, Object arg2, Object arg3) throws Exception - { - return doInvoke( arg1, RT.list(arg2, arg3)); - } - -public Object invoke( Object arg1, Object arg2, Object arg3, Object arg4) throws Exception - { - return doInvoke( arg1, RT.list(arg2, arg3, arg4)); - } - -public Object invoke( Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) - throws Exception - { - return doInvoke( arg1, RT.list(arg2, arg3, arg4, arg5)); - } - -public Object invoke( Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, ISeq args) - throws Exception - { - return doInvoke( arg1, RT.listStar(arg2, arg3, arg4, arg5, args)); - } -} - diff --git a/src/org/clojure/runtime/RestFn2.java b/src/org/clojure/runtime/RestFn2.java deleted file mode 100644 index 51a0d55b..00000000 --- a/src/org/clojure/runtime/RestFn2.java +++ /dev/null @@ -1,66 +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 Mar 27, 2006 8:05:10 PM */ - -package org.clojure.runtime; - -public abstract class RestFn2 extends AFn{ - -protected abstract Object doInvoke( Object arg1, Object arg2, ISeq rest) throws Exception; - -public Object applyTo( ISeq arglist) throws Exception - { - switch(RT.boundedLength(arglist, 2)) - { - case 0: - return invoke(); - case 1: - return invoke(arglist.first()); - case 2: - return invoke(arglist.first() - , (arglist = arglist.rest()).first() - ); - default: - return doInvoke( arglist.first() - , (arglist = arglist.rest()).first() - , arglist.rest()); - - } - } - -public Object invoke( Object arg1, Object arg2) throws Exception - { - return doInvoke( arg1, arg2, null); - } - -public Object invoke( Object arg1, Object arg2, Object arg3) throws Exception - { - return doInvoke( arg1, arg2, RT.list(arg3)); - } - -public Object invoke( Object arg1, Object arg2, Object arg3, Object arg4) throws Exception - { - return doInvoke( arg1, arg2, RT.list(arg3, arg4)); - } - -public Object invoke( Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) - throws Exception - { - return doInvoke( arg1, arg2, RT.list(arg3, arg4, arg5)); - } - -public Object invoke( Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, ISeq args) - throws Exception - { - return doInvoke( arg1, arg2, RT.listStar(arg3, arg4, arg5, args)); - } -} - diff --git a/src/org/clojure/runtime/RestFn3.java b/src/org/clojure/runtime/RestFn3.java deleted file mode 100644 index 4f16297b..00000000 --- a/src/org/clojure/runtime/RestFn3.java +++ /dev/null @@ -1,67 +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 Mar 27, 2006 8:19:54 PM */ - -package org.clojure.runtime; - -public abstract class RestFn3 extends AFn{ - -protected abstract Object doInvoke( Object arg1, Object arg2, Object arg3, ISeq rest) throws Exception; - -public Object applyTo( ISeq arglist) throws Exception - { - switch(RT.boundedLength(arglist, 3)) - { - case 0: - return invoke(); - case 1: - return invoke(arglist.first()); - case 2: - return invoke(arglist.first() - , (arglist = arglist.rest()).first() - ); - case 3: - return invoke(arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - ); - default: - return doInvoke( arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , arglist.rest()); - - } - } - - -public Object invoke( Object arg1, Object arg2, Object arg3) throws Exception - { - return doInvoke( arg1, arg2, arg3,null); - } - -public Object invoke( Object arg1, Object arg2, Object arg3, Object arg4) throws Exception - { - return doInvoke( arg1, arg2, arg3, RT.list(arg4)); - } - -public Object invoke( Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) - throws Exception - { - return doInvoke( arg1, arg2, arg3, RT.list(arg4, arg5)); - } - -public Object invoke( Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, ISeq args) - throws Exception - { - return doInvoke( arg1, arg2, arg3, RT.listStar(arg4, arg5, args)); - } -} diff --git a/src/org/clojure/runtime/RestFn4.java b/src/org/clojure/runtime/RestFn4.java deleted file mode 100644 index 368d90e8..00000000 --- a/src/org/clojure/runtime/RestFn4.java +++ /dev/null @@ -1,70 +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 Mar 27, 2006 8:21:51 PM */ - -package org.clojure.runtime; - -public abstract class RestFn4 extends AFn{ - -protected abstract Object doInvoke( Object arg1, Object arg2, Object arg3, Object arg4, ISeq rest) - throws Exception; - -public Object applyTo( ISeq arglist) throws Exception - { - switch(RT.boundedLength(arglist, 4)) - { - case 0: - return invoke(); - case 1: - return invoke(arglist.first()); - case 2: - return invoke(arglist.first() - , (arglist = arglist.rest()).first() - ); - case 3: - return invoke(arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - ); - case 4: - return invoke(arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - ); - default: - return doInvoke( arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , arglist.rest()); - - } - } - -public Object invoke( Object arg1, Object arg2, Object arg3, Object arg4) throws Exception - { - return doInvoke( arg1, arg2, arg3, arg4, null); - } - -public Object invoke( Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) - throws Exception - { - return doInvoke( arg1, arg2, arg3, arg4, RT.list(arg5)); - } - -public Object invoke( Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, ISeq args) - throws Exception - { - return doInvoke( arg1, arg2, arg3, arg4, RT.listStar(arg5, args)); - } -} - diff --git a/src/org/clojure/runtime/RestFn5.java b/src/org/clojure/runtime/RestFn5.java deleted file mode 100644 index 319dc336..00000000 --- a/src/org/clojure/runtime/RestFn5.java +++ /dev/null @@ -1,73 +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 Mar 27, 2006 8:24:31 PM */ - -package org.clojure.runtime; - -public abstract class RestFn5 extends AFn{ - -protected abstract Object doInvoke( Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, - ISeq rest) - throws Exception; - -public Object applyTo( ISeq arglist) throws Exception - { - switch(RT.boundedLength(arglist, 5)) - { - case 0: - return invoke(); - case 1: - return invoke(arglist.first()); - case 2: - return invoke(arglist.first() - , (arglist = arglist.rest()).first() - ); - case 3: - return invoke(arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - ); - case 4: - return invoke(arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - ); - case 5: - return invoke(arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - ); - default: - return doInvoke( arglist.first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , (arglist = arglist.rest()).first() - , arglist.rest()); - - } - } - -public Object invoke( Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) - throws Exception - { - return doInvoke( arg1, arg2, arg3, arg4, arg5, null); - } - -public Object invoke( Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, ISeq args) - throws Exception - { - return doInvoke( arg1, arg2, arg3, arg4, arg5, args); - } -} diff --git a/src/org/clojure/runtime/Symbol.java b/src/org/clojure/runtime/Symbol.java deleted file mode 100644 index 269becfa..00000000 --- a/src/org/clojure/runtime/Symbol.java +++ /dev/null @@ -1,84 +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 Mar 25, 2006 11:42:47 AM */ - -package org.clojure.runtime; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Random; - -public class Symbol extends Obj implements Comparable{ - -final public static HashMap table = new HashMap(); -final public static HashSet hashes = new HashSet(); -final static Random rand = new Random(42); - -public final String name; -int hash = 0; - -public String toString() - { - return name; - } - -public static Symbol intern(String name) - { - synchronized(table) - { - Symbol sym = (Symbol) table.get(name); - if(sym == null) - { - if(name.charAt(0) == ':') - sym = new Keyword(name); - else if(name.charAt(0) == '.') - sym = new Accessor(name); - else - sym = new Symbol(name); - table.put(name, sym); - } - return sym; - } - } - -/** - * Used by intern() - * @param name - */ -Symbol(String name) - { - this.name = name; - } - - public int hashCode(){ - if(hash == 0) - { - synchronized (hashes) - { - while (hash == 0) - { - int h = rand.nextInt(); - if (h != 0 && !hashes.contains(h)) - { - hash = h; - hashes.add(h); - } - } - } - } - return hash; - } - - -public int compareTo(Object o) { - return hashCode() - ((Symbol)o).hashCode(); -} -} diff --git a/src/org/clojure/runtime/TObj.java b/src/org/clojure/runtime/TObj.java deleted file mode 100644 index 74069b3d..00000000 --- a/src/org/clojure/runtime/TObj.java +++ /dev/null @@ -1,37 +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.
- **/
-
-package org.clojure.runtime;
-
-public class TObj implements IObj{
-TRef attrs;
-
-public TObj() throws Exception{
- this.attrs = Transaction.tref(new PersistentTree());
-}
-
-
-public Object put( Comparable key, Object val) throws Exception {
- PersistentTree t = (PersistentTree) Transaction.get2( attrs);
- t = t.put(key, val);
- Transaction.set2(attrs,t);
- return val;
-}
-
-public Object get( Comparable key) throws Exception {
- PersistentTree t = (PersistentTree) Transaction.get2( attrs);
- return t.get(key);
-}
-
-public boolean has( Comparable key) throws Exception {
- PersistentTree t = (PersistentTree) Transaction.get2( attrs);
- return t.contains(key);
-}
-}
diff --git a/src/org/clojure/runtime/TRef.java b/src/org/clojure/runtime/TRef.java deleted file mode 100644 index a955cdf5..00000000 --- a/src/org/clojure/runtime/TRef.java +++ /dev/null @@ -1,33 +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 May 30, 2006 */ - -package org.clojure.runtime; - -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; -import java.util.concurrent.atomic.AtomicInteger; - -public class TRef extends TVal implements Comparable{ -static AtomicInteger nextSeq = new AtomicInteger(1); - -final int lockSeq; -Lock lock; - -public TRef() { - this.lockSeq = nextSeq.getAndIncrement(); - this.lock = new ReentrantLock(); -} - -public int compareTo(Object o){ - return lockSeq - ((TRef) o).lockSeq; -} -} diff --git a/src/org/clojure/runtime/TVal.java b/src/org/clojure/runtime/TVal.java deleted file mode 100644 index 1bc72a9b..00000000 --- a/src/org/clojure/runtime/TVal.java +++ /dev/null @@ -1,39 +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 May 30, 2006 */ - -package org.clojure.runtime; - -public class TVal{ -volatile Object val; -volatile Transaction.Info tinfo; -volatile TVal prior; - -TVal(){ - -} - -TVal(Object val, Transaction.Info tinfo, TVal prior) { - this.val = val; - this.tinfo = tinfo; - this.prior = prior; -} - -void push(Object val,Transaction.Info tinfo) throws Exception{ - if(tinfo != null) //not newly created, clone tval part - { - this.prior = new TVal(this.val,this.tinfo,this.prior); - } - this.tinfo = tinfo; - this.val = val; -} - -} diff --git a/src/org/clojure/runtime/ThreadLocalData.java b/src/org/clojure/runtime/ThreadLocalData.java deleted file mode 100644 index bb63d217..00000000 --- a/src/org/clojure/runtime/ThreadLocalData.java +++ /dev/null @@ -1,37 +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 Mar 25, 2006 11:45:22 AM */ - -package org.clojure.runtime; - -public class ThreadLocalData{ - -private static ThreadLocal<Transaction> transaction = new ThreadLocal<Transaction>(); -private static ThreadLocal<Object[]> values = new ThreadLocal<Object[]>(); - -static public Object[] getValues(){ - return values.get(); -} - -static public void setValues(Object[] vals) { - values.set(vals); -} - -static public Transaction getTransaction() { - return transaction.get(); - -} - -static public void setTransaction(Transaction t){ - transaction.set(t); -} - -} diff --git a/src/org/clojure/runtime/Transaction.java b/src/org/clojure/runtime/Transaction.java deleted file mode 100644 index e3239c2a..00000000 --- a/src/org/clojure/runtime/Transaction.java +++ /dev/null @@ -1,236 +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 May 30, 2006 */ - -package org.clojure.runtime; - -import java.util.*; - -public class Transaction{ - -public static final int COMMITTED = 0; -public static final int WORKING = 1; -static final Object lock = new Object(); - -volatile static int nextSeq = 1; - -static int getNextSeq(){ - synchronized(lock){ - return nextSeq++; - } -} - -public static class Info{ -int seq; -int status; - - -Info(int seq,int status){ - this.seq = seq; - this.status = status; -} -} - - -Info info; -int startSeq; - -IdentityHashMap<TRef,Object> sets; -IdentityHashMap<TRef,ISeq> commutates; - - -static public Object runInTransaction(IFn fn) throws Exception{ - if(ThreadLocalData.getTransaction() != null) - return fn.invoke(); - Transaction t = new Transaction(); - ThreadLocalData.setTransaction(t); - try{ - return t.run(fn); - } - finally{ - ThreadLocalData.setTransaction(null); - } -} - -static public TRef tref(Object val) throws Exception{ - Transaction trans = ThreadLocalData.getTransaction(); - TRef tref = new TRef(); - trans.set(tref, val); - return tref; -} - -//* -static public Object get2(TRef tref) throws Exception{ - return ThreadLocalData.getTransaction().get(tref); -} - -static public Object set2(TRef tref, Object val) throws Exception{ - return ThreadLocalData.getTransaction().set(tref,val); -} - -static public void touch2(TRef tref) throws Exception{ - ThreadLocalData.getTransaction().touch(tref); -} - -static public void commutate2(TRef tref, IFn fn) throws Exception{ - ThreadLocalData.getTransaction().commutate(tref, fn); -} -//*/ - -Object run(IFn fn) throws Exception{ - boolean done = false; - Object ret = null; - ArrayList<TRef> locks = null; - ArrayList<TRef> locked = null; - - loop: - while(!done){ - try - { - ret = fn.invoke(); - if(locks == null && (sets != null || commutates != null)) - locks = new ArrayList<TRef>(); - if(sets != null) - locks.addAll(sets.keySet()); - if(commutates != null) - locks.addAll(commutates.keySet()); - if(locks != null) - { - if(locked == null) - locked = new ArrayList<TRef>(locks.size()); - //lock in order, to avoid deadlocks - Collections.sort(locks); - for(TRef tref : locks) - { - //will block here - tref.lock.lock(); - locked.add(tref); - if(sets.containsKey(tref)) - { - //try again if the thing we are trying to set has changed since we started - TVal curr = getCurrent(tref); - if(curr != null && curr.tinfo.seq > startSeq) - continue loop; - } - } - } - - //at this point all write targets are locked - //turn commutates into sets - for(Map.Entry<TRef, ISeq> e : commutates.entrySet()) - { - TRef tref = e.getKey(); - //note this will npe if tref has never been set, as designed - Object val = getCurrent(tref).val; - for(ISeq c = e.getValue();c!=null;c = c.rest()) - { - IFn f = (IFn) c.first(); - val = f.invoke(val); - } - sets.put(tref, val); - } - - //set the new vals - for(Map.Entry<TRef, Object> entry : sets.entrySet()) - { - TRef tref = entry.getKey(); - tref.push(entry.getValue(), info); - } - - //atomic commit - synchronized(lock){ - info.seq = getNextSeq(); - info.status = COMMITTED; - } - - done = true; - } - finally{ - if(locked != null) - { - for(TRef tref : locked) - { - tref.lock.unlock(); - } - locked.clear(); - } - reset(); - if(locks != null) - locks.clear(); - } - } - return ret; -} - -private void reset(){ - if(sets != null) - sets.clear(); - if(commutates != null) - commutates.clear(); - -} - - -Transaction(){ - synchronized(lock){ - int seq = getNextSeq(); - this.info = new Info(seq, WORKING); - this.startSeq = seq; - } -} - -Object get(TRef tref) throws Exception{ - if(sets != null && sets.containsKey(tref)) - return sets.get(tref); - - for(TVal ver = tref;ver != null;ver = ver.prior) - { - //note this will npe if tref has never been set, as designed - if(ver.tinfo.status == COMMITTED && ver.tinfo.seq <= startSeq) - return ver.val; - } - - throw new Exception("Version not found"); -} - -static TVal getCurrent(TRef tref) throws Exception{ - for(TVal ver = tref;ver != null;ver = ver.prior) - { - if(ver.tinfo != null && ver.tinfo.status == COMMITTED) - return ver; - } - //this return only if no value was ever successfully set - return null; -} - -Object set(TRef tref, Object val) throws Exception{ - if(sets == null) - sets = new IdentityHashMap<TRef,Object>(); - if(commutates != null && commutates.containsKey(tref)) - throw new Exception("Can't commutate and set a TRef in the same transaction"); - - sets.put(tref,val); - return val; - } - -void touch(TRef tref) throws Exception{ - set(tref, get(tref)); - } - -void commutate(TRef tref, IFn fn) throws Exception{ - if(commutates == null) - commutates = new IdentityHashMap<TRef,ISeq>(); - if(sets != null && sets.containsKey(tref)) - throw new Exception("Can't commutate and set a TRef in the same transaction"); - commutates.put(tref, RT.cons(fn, commutates.get(tref))); - } - -} diff --git a/src/org/clojure/runtime/Var.java b/src/org/clojure/runtime/Var.java deleted file mode 100644 index 6d17bafa..00000000 --- a/src/org/clojure/runtime/Var.java +++ /dev/null @@ -1,142 +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 org.clojure.runtime; - -import java.util.concurrent.atomic.AtomicReference; - -public class Var extends AFn { - -public final Symbol sym; -public Namespace namespace; -public Binding binding; -public IFn fn; //todo, bind to throw stub? -public IFn setfn; -AtomicReference<IPersistentMap> threadBindings = new AtomicReference(PersistentArrayIdentityMap.EMPTY); - -Var(Symbol sym, Namespace ns) { - if (!(sym.getClass() == Symbol.class)) - throw new IllegalArgumentException("Only simple symbols can be vars"); - this.namespace = ns; - this.sym = sym; -} - -public String toString() { - if (namespace == null) - return "#:" + sym; - return namespace.name + ":" + sym; -} - -public Var bind(Object val) { - if (binding == null) - binding = new Binding(val); - else - binding.val = val; - - if (val instanceof IFn) - this.fn = (IFn) val; - else - this.fn = null; //todo, bind to throw stub? - - return this; -} - -public Object getValue() { - Binding binding = getBinding(); - if (binding != null) - return binding.val; - throw new IllegalStateException(this.toString() + " is unbound."); -} - -public Object setValue(Object val) { - Binding b = getThreadBinding(); - if (b != null) - return b.val = val; - if (binding == null) - throw new IllegalStateException(this.toString() + " is unbound."); - - if (val instanceof IFn) - this.fn = (IFn) val; - else - this.fn = null; //todo, bind to throw stub? - - return binding.val = val; -} - -public Binding pushThreadBinding(Object val) { - Binding ret = new Binding(val, getThreadBinding()); - setThreadBinding(ret); - return ret; -} - -public void popThreadBinding() { - setThreadBinding(getThreadBinding().rest); -} - -private Binding getThreadBinding() { - if (threadBindings.get().count() > 0) - return (Binding) threadBindings.get().get(Thread.currentThread()); - return null; -} - -private Binding getBinding() { - Binding b = getThreadBinding(); - if (b != null) - return b; - return binding; -} - -private void setThreadBinding(Binding b) { - Thread thread = Thread.currentThread(); - IPersistentMap tb; - IPersistentMap newtb; - do - { - tb = threadBindings.get(); - if (b == null) - newtb = tb.remove(thread); - else - newtb = tb.put(thread, b); - } while (!threadBindings.compareAndSet(tb, newtb)); -} - -public Object invoke() throws Exception { - return fn.invoke(); -} - -public Object invoke(Object arg1) throws Exception { - return fn.invoke(arg1); -} - -public Object invoke(Object arg1, Object arg2) throws Exception { - return fn.invoke(arg1, arg2); -} - -public Object invoke(Object arg1, Object arg2, Object arg3) throws Exception { - return fn.invoke(arg1, arg2, arg3); -} - -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4) throws Exception { - return fn.invoke(arg1, arg2, arg3, arg4); -} - -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) - throws Exception { - return fn.invoke(arg1, arg2, arg3, arg4, arg5); -} - -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, ISeq args) - throws Exception { - return fn.invoke(arg1, arg2, arg3, arg4, arg5, args); -} - -} diff --git a/src/org/clojure/tools/TypeDump.java b/src/org/clojure/tools/TypeDump.java deleted file mode 100644 index 14fe5645..00000000 --- a/src/org/clojure/tools/TypeDump.java +++ /dev/null @@ -1,199 +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 Mar 31, 2006 11:03:27 AM */ - -package org.clojure.tools; - -import org.objectweb.asm.*; - -import java.io.IOException; -import java.io.PrintStream; -import java.util.Arrays; -import java.util.Enumeration; -import java.util.List; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -/** - * Creates an sexpr dump of type info - */ -public class TypeDump implements ClassVisitor{ - -PrintStream p; -boolean ignore; -static List packages; - -public TypeDump(PrintStream p) - { - this.p = p; - } - -static public void main(String args[]) - { - if(args.length < 2) - { - System.err.println("Usage: java org.clojure.tools.TypeDump jarfile package [package ...]"); - return; - } - packages = Arrays.asList(args).subList(1, args.length); - try - { - TypeDump v = new TypeDump(System.out); - ZipFile f = new ZipFile(args[0]); - Enumeration en = f.entries(); - System.out.println('('); - while(en.hasMoreElements()) - { - ZipEntry e = (ZipEntry) en.nextElement(); - String name = e.getName(); - if(name.endsWith(".class")) - { - ClassReader cr = new ClassReader(f.getInputStream(e)); - cr.accept(v, false); - } - } - System.out.println(')'); - } - catch(IOException e) - { - e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. - } - } - -public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) - { - String pkg = name.substring(0,name.lastIndexOf('/')).replace('/','.'); - if((access & Opcodes.ACC_PUBLIC) == 0 - || !packages.contains(pkg)) - { - ignore = true; - return; - } - else - ignore = false; - p.print('('); - p.println("(:name \"" + name + "\")"); - p.print(" (:super \"" + superName + "\")"); - if(interfaces.length > 0) - { - p.println(); - p.print(" (:interfaces"); - for(int i = 0; i < interfaces.length; i++) - { - String anInterface = interfaces[i]; - p.print(" \"" + anInterface + "\""); - } - p.print(')'); - } - } - -public void visitSource(String source, String debug) - { - } - -public void visitOuterClass(String owner, String name, String desc) - { - } - -public AnnotationVisitor visitAnnotation(String desc, boolean visible) - { - return null; - } - -public void visitAttribute(Attribute attribute) - { - } - -public void visitInnerClass(String name, String outerName, String innerName, int access) - { - } - -public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) - { - if(!ignore && (access & Opcodes.ACC_PUBLIC) != 0) - { - p.println(); - p.print(" (:field (:name \""); - p.print(name); - p.print("\") (:type \""); - p.print(internalName(Type.getType(desc))); - p.print("\")"); - if((access & Opcodes.ACC_STATIC) != 0) - { - p.print(" (:static t)"); - if(value != null && (access & Opcodes.ACC_FINAL) != 0) - { - p.print(" (:const-value "); - if(value instanceof String) - p.print('"'); - p.print(value); - if(value instanceof String) - p.print('"'); - p.print(")"); - } - } - p.print(")"); - } - return null; - } - -String internalName(Type t) - { - if(t.getSort() == Type.OBJECT) - return t.getInternalName(); - return t.toString(); - } - -public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) - { - if(!ignore && (access & Opcodes.ACC_PUBLIC) != 0) - { - Type args[] = Type.getArgumentTypes(desc); - - p.println(); - if(name.equals("<init>")) - p.print(" (:ctor "); - else - p.print(" (:method (:name \"" + name + "\") (:ret \"" + - internalName(Type.getReturnType(desc)) + "\")"); - p.print("(:arity " + args.length + ")"); - if((access & Opcodes.ACC_STATIC) != 0) - { - p.print(" (:static t)"); - } - if((access & Opcodes.ACC_VARARGS) != 0) - { - p.print(" (:varargs t)"); - } - p.println(); - p.print(" (:desc \"" + desc + "\")"); - if(args.length > 0) - { - p.println(); - p.print(" (:args"); - for(int i = 0; i < args.length; i++) - { - Type arg = args[i]; - p.print(" \"" + internalName(arg) + "\""); - } - p.print(')'); - } - p.print(')'); - } - return null; - } - -public void visitEnd() - { - if(!ignore) - p.println(')'); - } -} |