diff options
author | Rich Hickey <richhickey@gmail.com> | 2006-03-25 22:14:51 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2006-03-25 22:14:51 +0000 |
commit | 2081b7e8bbffe24ffa422dfd84262ff35e2aaa35 (patch) | |
tree | cec9b5c29904dd32d75c13b7402ed2854603704d /src | |
parent | d0aa19b1da4d796b3638c1dc8a43a314b9f62ff0 (diff) |
added AFn, RT
Diffstat (limited to 'src')
-rw-r--r-- | src/org/clojure/runtime/AFn.java | 98 | ||||
-rw-r--r-- | src/org/clojure/runtime/RT.java | 96 |
2 files changed, 194 insertions, 0 deletions
diff --git a/src/org/clojure/runtime/AFn.java b/src/org/clojure/runtime/AFn.java new file mode 100644 index 00000000..a4ace498 --- /dev/null +++ b/src/org/clojure/runtime/AFn.java @@ -0,0 +1,98 @@ +/** + * 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 AMap implements IFn{ + +public Object invoke(ThreadLocalData tld) throws Exception + { + return throwArity(); + } + +public Object invoke(ThreadLocalData tld, Object arg1) throws Exception + { + return throwArity(); + } + +public Object invoke(ThreadLocalData tld, Object arg1, Object arg2) throws Exception + { + return throwArity(); + } + +public Object invoke(ThreadLocalData tld, Object arg1, Object arg2, Object arg3) throws Exception + { + return throwArity(); + } + +public Object invoke(ThreadLocalData tld, Object arg1, Object arg2, Object arg3, Object arg4) throws Exception + { + return throwArity(); + } + +public Object invoke(ThreadLocalData tld, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) + throws Exception + { + return throwArity(); + } + +public Object invoke(ThreadLocalData tld, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Cons args) + throws Exception + { + return throwArity(); + } + +public Object applyTo(ThreadLocalData tld, Cons arglist) throws Exception + { + switch(RT.boundedLength(arglist, 5)) + { + case 0: + return invoke(tld); + case 1: + return invoke(tld, arglist.first); + case 2: + return invoke(tld, arglist.first + , (arglist = arglist.rest).first + ); + case 3: + return invoke(tld, arglist.first + , (arglist = arglist.rest).first + , (arglist = arglist.rest).first + ); + case 4: + return invoke(tld, arglist.first + , (arglist = arglist.rest).first + , (arglist = arglist.rest).first + , (arglist = arglist.rest).first + ); + case 5: + return invoke(tld, arglist.first + , (arglist = arglist.rest).first + , (arglist = arglist.rest).first + , (arglist = arglist.rest).first + , (arglist = arglist.rest).first + ); + default: + return invoke(tld, arglist.first + , (arglist = arglist.rest).first + , (arglist = arglist.rest).first + , (arglist = arglist.rest).first + , (arglist = arglist.rest).first + , arglist.rest); + } + } + +protected Object throwArity() + { + throw new IllegalArgumentException("Wrong number of args passed"); + } +} diff --git a/src/org/clojure/runtime/RT.java b/src/org/clojure/runtime/RT.java new file mode 100644 index 00000000..9a5945b7 --- /dev/null +++ b/src/org/clojure/runtime/RT.java @@ -0,0 +1,96 @@ +/** + * 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; + +public class RT{ + +static public Cons cons(Object x, Cons 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, Cons rest) + { + return cons(arg1, rest); + } + +static public Cons listStar(Object arg1, Object arg2, Cons rest) + { + return cons(arg1, cons(arg2, rest)); + } + +static public Cons listStar(Object arg1, Object arg2, Object arg3, Cons rest) + { + return cons(arg1, cons(arg2, cons(arg3, rest))); + } + +static public Cons listStar(Object arg1, Object arg2, Object arg3, Object arg4, Cons 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, Cons rest) + { + return cons(arg1, cons(arg2, cons(arg3, cons(arg4, cons(arg5, rest))))); + } + +static public int length(Cons list) + { + int i = 0; + for(Cons c = list; c != null; c = c.rest) + { + i++; + } + return i; + } + +static public int boundedLength(Cons list, int limit) + { + int i = 0; + for(Cons c = list; c != null && i <= limit; c = c.rest) + { + i++; + } + return i; + } +} |