diff options
Diffstat (limited to 'src/cli')
-rw-r--r-- | src/cli/runtime/RT.cs | 58 | ||||
-rw-r--r-- | src/cli/runtime/Reflector.cs | 2 |
2 files changed, 30 insertions, 30 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)
{
|