Esempio n. 1
0
        public override bool Admissable(Frame th, Variable[] pos, VarHash named)
        {
            if (named != null && named.IsNonEmpty)
            {
                return(false);
            }
            if (!AdmissableArity(pos.Length))
            {
                return(false);
            }

            object dummy;

            for (int i = 0; i < args.Length; i++)
            {
                if (!CLRWrapperProvider.CoerceArgument(out dummy, args[i], pos[i]) ||
                    (refs[i] && !pos[i].rw))
                {
                    return(false);
                }
            }
            // XXX: maybe param arrays should be treated as slurpies?
            for (int i = args.Length; i < pos.Length; i++)
            {
                if (!CLRWrapperProvider.CoerceArgument(out dummy, param_array, pos[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 2
0
 void WritebackRefs(Variable[] pos, object[] argv)
 {
     for (int i = 0; i < args.Length; i++)
     {
         if (refs[i])
         {
             pos[i].Store(CLRWrapperProvider.BoxResult(args[i],
                                                       argv[i]).Fetch());
         }
     }
 }
Esempio n. 3
0
        public override P6any Fetch()
        {
            if (!prop.CanRead)
            {
                throw new NieczaException("Property " + prop.Name + " is write-only");
            }
            MethodInfo mi  = prop.GetGetMethod();
            object     ret = mi.Invoke(obj, argv);

            return(CLRWrapperProvider.BoxResult(mi.ReturnType, ret).Fetch());
        }
Esempio n. 4
0
        public override void Store(P6any v)
        {
            if (field.IsInitOnly || field.IsLiteral)
            {
                throw new NieczaException("Field " + field.Name + " is read-only");
            }
            object clr;

            if (!CLRWrapperProvider.CoerceArgument(out clr, field.FieldType,
                                                   Kernel.NewROScalar(v)))
            {
                throw new NieczaException("Unable to coerce value of type " + v.mo.name + " for " + field.Name); // could also be a range problem
            }
            field.SetValue(obj, clr);
        }
Esempio n. 5
0
 public Variable Invoke(object obj, Variable[] pos, VarHash named)
 {
     object[] argv = new object[args.Length +
                                (param_array != null ? 1 : 0)];
     for (int i = 0; i < args.Length; i++)
     {
         CLRWrapperProvider.CoerceArgument(out argv[i], args[i], pos[i]);
     }
     if (param_array != null)
     {
         int   npa = pos.Length - args.Length;
         Array pa  = Array.CreateInstance(param_array, npa);
         for (int j = 0; j < npa; j++)
         {
             object arg;
             CLRWrapperProvider.CoerceArgument(out arg, param_array, pos[j + args.Length]);
             pa.SetValue(arg, j);
         }
         argv[args.Length] = pa;
     }
     if (what_call is MethodInfo)
     {
         MethodInfo mi  = (MethodInfo)what_call;
         object     ret = mi.Invoke((mi.IsStatic ? null : obj), argv);
         WritebackRefs(pos, argv);
         return(CLRWrapperProvider.BoxResult(mi.ReturnType, ret));
     }
     else if (what_call is ConstructorInfo)
     {
         ConstructorInfo ci  = (ConstructorInfo)what_call;
         object          ret = ci.Invoke(argv);
         WritebackRefs(pos, argv);
         return(CLRWrapperProvider.BoxResult(ci.DeclaringType, ret));
     }
     else if (what_call is FieldInfo)
     {
         return(new FieldProxy((FieldInfo)what_call, obj));
     }
     else if (what_call is PropertyInfo)
     {
         return(new PropertyProxy((PropertyInfo)what_call, obj, argv));
     }
     else
     {
         throw new NieczaException("Unhandled member type " + what_call.GetType());
     }
 }
Esempio n. 6
0
        public override void Store(P6any v)
        {
            if (!prop.CanWrite)
            {
                throw new NieczaException("Property " + prop.Name + " is read-only");
            }
            MethodInfo mi = prop.GetSetMethod();

            object[] argv_ = argv;
            Array.Resize(ref argv_, argv.Length + 1);
            if (!CLRWrapperProvider.CoerceArgument(out argv_[argv.Length],
                                                   prop.PropertyType, Kernel.NewROScalar(v)))
            {
                throw new NieczaException("Unable to coerce value of type " + v.mo.name + " for " + prop.Name); // could also be a range problem
            }
            mi.Invoke(obj, argv_);
        }
Esempio n. 7
0
        public override P6any Fetch()
        {
            object ret = field.GetValue(obj);

            return(CLRWrapperProvider.BoxResult(field.FieldType, ret).Fetch());
        }