Ejemplo 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);
        }
Ejemplo n.º 2
0
        internal static VarHash Thaw(ThawBuffer tb)
        {
            VarHash r = new VarHash();

            tb.Register(r);
            int c = tb.Int();

            for (int i = 0; i < c; i++)
            {
                r[tb.String()] = (Variable)tb.ObjRef();
            }
            return(r);
        }
Ejemplo n.º 3
0
        // throws on dispatch failure
        public MultiCandidate DoDispatch(Frame th, Variable[] pos, VarHash named)
        {
            MultiCandidate[] avail = GetCandidateList(pos.Length);

            int last_ix;

            for (last_ix = avail.Length - 1; last_ix >= 0; last_ix--)
            {
                if (avail[last_ix].Admissable(th, pos, named))
                {
                    break;
                }
            }

            if (last_ix < 0)
            {
                throw new NieczaException("No candidates for dispatch to " + name +
                                          "; candidates are:" + Console.Out.NewLine + "    " +
                                          Kernel.JoinS(Console.Out.NewLine + "    ", avail));
            }

            foreach (int ci in avail[last_ix].conflictors)
            {
                if (avail[ci].Admissable(th, pos, named))
                {
                    List <MultiCandidate> matched = new List <MultiCandidate>();

                    foreach (MultiCandidate mc in avail)
                    {
                        if (mc.Admissable(th, pos, named))
                        {
                            matched.Add(mc);
                        }
                    }

                    throw new NieczaException("Ambiguous dispatch for " + name +
                                              "; matched candidates are:" + Console.Out.NewLine + "    " +
                                              Kernel.JoinS(Console.Out.NewLine + "    ", matched));
                }
            }

            if (CLROpts.MMDDebug)
            {
                Console.WriteLine("Using {0}", avail[last_ix]);
            }

            return(avail[last_ix]);
        }
Ejemplo n.º 4
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());
     }
 }
Ejemplo n.º 5
0
        public VarHash(VarHash from)
        {
            hfree = from.hfree;
            count = from.count;
            int l = from.heap.Length;

            if (from.htab != null)
            {
                htab = new int[l];
                Array.Copy(from.htab, 0, htab, 0, l);
            }
            else
            {
                htab = null;
            }
            heap = new VarHashLink[l];
            Array.Copy(from.heap, 0, heap, 0, l);
        }
Ejemplo n.º 6
0
        // include the invocant in the positionals!  it will not usually be
        // this, rather a container of this
        public virtual Frame InvokeMethod(Frame caller, string name,
                                          Variable[] pos, VarHash named)
        {
            DispatchEnt m;

            //Kernel.LogNameLookup(name);
            if ((m = mo.FindMethod(name)) != null)
            {
                return(m.info.SetupCall(caller, m.outer, m.ip6,
                                        pos, named, false, m));
            }
            if (mo.mro_methods.TryGetValue("FALLBACK", out m))
            {
                Variable[] npos = new Variable[pos.Length + 1];
                Array.Copy(pos, 1, npos, 2, pos.Length - 1);
                npos[0] = pos[0];
                npos[1] = Kernel.BoxAnyMO(name, Kernel.StrMO);
                return(m.info.SetupCall(caller, m.outer, m.ip6,
                                        npos, named, false, m));
            }
            return(Fail(caller, "Unable to resolve method " + name));
        }
Ejemplo n.º 7
0
 public abstract Frame Invoke(P6any obj, Frame th, Variable[] pos, VarHash named);
Ejemplo n.º 8
0
 public Frame Invoke(Frame c, Variable[] p, VarHash n)
 {
     return(mo.mro_INVOKE.Invoke(this, c, p, n));
 }
Ejemplo n.º 9
0
 internal VarHashKeys(VarHash x)
 {
     th = x;
 }
Ejemplo n.º 10
0
 public abstract bool Admissable(Frame th, Variable[] pos, VarHash named);