summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2006-10-10 19:41:48 +0000
committerRich Hickey <richhickey@gmail.com>2006-10-10 19:41:48 +0000
commita53e41cd426ebd2181d036e83ab0f8e69de9a8bf (patch)
tree78ba55f826eb636f965e03f8d79c22a44021d8f2
parentad0302cd67dc50695a9348178065f0ec090b9890 (diff)
changed box functions to box for clojure consumption
-rw-r--r--src/cli/runtime/RT.cs58
-rw-r--r--src/cli/runtime/Reflector.cs2
-rw-r--r--src/jvm/clojure/lang/RT.java33
-rw-r--r--src/jvm/clojure/lang/Reflector.java14
4 files changed, 56 insertions, 51 deletions
diff --git a/src/cli/runtime/RT.cs b/src/cli/runtime/RT.cs
index 059bdad6..40626d62 100644
--- a/src/cli/runtime/RT.cs
+++ b/src/cli/runtime/RT.cs
@@ -302,41 +302,41 @@ static public Object assocN(int n, Object val, Object coll) {
return x;
}
- static public Object box(bool x)
- {
- return x;
- }
-
- static public Object box(byte x)
- {
- return x;
- }
+ static public Object box(bool x)
+ {
+ return x ? T : null;
+ }
- static public Object box(short x)
- {
- return x;
- }
+ static public Num box(byte x)
+ {
+ return Num.from(x);
+ }
- static public Object box(int x)
- {
- return x;
- }
+ static public Num box(short x)
+ {
+ return Num.from(x);
+ }
- static public Object box(long x)
- {
- return x;
- }
+ static public Num box(int x)
+ {
+ return Num.from(x);
+ }
- static public Object box(float x)
- {
- return x;
- }
+ static public Num box(long x)
+ {
+ return Num.from(x);
+ }
- static public Object box(double x)
- {
- return 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)
diff --git a/src/cli/runtime/Reflector.cs b/src/cli/runtime/Reflector.cs
index e198661b..483c4029 100644
--- a/src/cli/runtime/Reflector.cs
+++ b/src/cli/runtime/Reflector.cs
@@ -154,7 +154,7 @@ public static Object invokeInstanceMember(String name, Object target) //throws E
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 RT.box(n.intValue()); else if(paramType == typeof(float)) return RT.box(n.floatValue()); else if(paramType == typeof(double)) return RT.box(n.doubleValue()); else if(paramType == typeof(long)) return RT.box(n.longValue()); else if(paramType == typeof(char)) return RT.box((char) n.intValue()); else if(paramType == typeof(short)) return RT.box(n.shortValue()); else if(paramType == typeof(byte)) return RT.box(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 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)
{
diff --git a/src/jvm/clojure/lang/RT.java b/src/jvm/clojure/lang/RT.java
index 17b0999e..ae9f3e4a 100644
--- a/src/jvm/clojure/lang/RT.java
+++ b/src/jvm/clojure/lang/RT.java
@@ -285,39 +285,44 @@ static public Character box(char x)
return new Character(x);
}
-static public Boolean box(boolean x)
+static public Object box(boolean x)
{
- return Boolean.valueOf(x);
+ return x?T:null;
}
-static public Byte box(byte x)
+static public Object box(Boolean x)
{
- return new Byte(x);
+ return x?T:null;
}
-static public Short box(short x)
+static public Num box(byte x)
{
- return new Short(x);
+ return Num.from(x);
}
-static public Integer box(int x)
+static public Num box(short x)
{
- return new Integer(x);
+ return Num.from(x);
}
-static public Long box(long x)
+static public Num box(int x)
{
- return new Long(x);
+ return Num.from(x);
}
-static public Float box(float x)
+static public Num box(long x)
{
- return new Float(x);
+ return Num.from(x);
}
-static public Double box(double x)
+static public Num box(float x)
{
- return new Double(x);
+ return Num.from(x);
+ }
+
+static public Num box(double x)
+ {
+ return Num.from(x);
}
static public char charCast(Object x)
diff --git a/src/jvm/clojure/lang/Reflector.java b/src/jvm/clojure/lang/Reflector.java
index 90541232..cbf0aa14 100644
--- a/src/jvm/clojure/lang/Reflector.java
+++ b/src/jvm/clojure/lang/Reflector.java
@@ -197,19 +197,19 @@ static Object boxArg(Class paramType, Object arg)
{
Num n = (Num) arg;
if(paramType == int.class)
- return RT.box(n.intValue());
+ return n.intValue();
else if(paramType == float.class)
- return RT.box(n.floatValue());
+ return n.floatValue();
else if(paramType == double.class)
- return RT.box(n.doubleValue());
+ return n.doubleValue();
else if(paramType == long.class)
- return RT.box(n.longValue());
+ return n.longValue();
else if(paramType == char.class)
- return RT.box((char) n.intValue());
+ return (char) n.intValue();
else if(paramType == short.class)
- return RT.box(n.shortValue());
+ return n.shortValue();
else
- return RT.box(n.byteValue());
+ return n.byteValue();
}
else
return arg;