コード例 #1
0
        public override HeronValue Apply(VM vm, HeronValue[] args)
        {
            Object[] os = HeronDotNet.ObjectsToDotNetArray(args);
            Object   o  = self.GetSystemType().InvokeMember(name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, self.Unmarshal(), os);

            return(DotNetObject.Marshal(o));
        }
コード例 #2
0
        public override HeronValue Invoke(VM vm, HeronValue self, HeronValue[] args)
        {
            int nParams = method.GetParameters().Length;

            if (nParams != args.Length)
            {
                throw new Exception("Incorrect number of arguments " + args.Length + " expected " + nParams);
            }

            Object[] newArgs = new Object[args.Length];
            for (int i = 0; i < nParams; ++i)
            {
                ParameterInfo pi = method.GetParameters()[i];
                Type          pt = pi.ParameterType;
                Type          at = args[i].GetType();
                HeronValue    hv = args[i] as HeronValue;
                if (!pt.IsAssignableFrom(at))
                {
                    if (hv == null)
                    {
                        throw new Exception("Could not cast parameter " + i + " from " + at + " to " + pt);
                    }
                    newArgs[i] = hv.Unmarshal();
                }
                else
                {
                    newArgs[i] = hv;
                }
            }
            return(DotNetObject.Marshal(method.Invoke(self, newArgs)));
        }
コード例 #3
0
ファイル: HeronREPL.cs プロジェクト: catb0t/heron-language
        public void RegisterFunction(string s)
        {
            MethodInfo   mi = GetType().GetMethod(s);
            DotNetMethod m  = new DotNetMethod(mi, DotNetObject.Marshal(this));

            vm.AddVar(s, m);
        }
コード例 #4
0
        public override HeronValue Invoke(VM vm, HeronValue self, HeronValue[] args)
        {
            Trace.Assert(self == null);
            Object[] os = HeronDotNet.ObjectsToDotNetArray(args);
            Object   o  = this.self.GetSystemType().InvokeMember(name, BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod, null, null, os);

            return(DotNetObject.Marshal(o));
        }
コード例 #5
0
 public override HeronValue[] ToArray()
 {
     HeronValue[] r = new HeronValue[list.Count];
     for (int i = 0; i < list.Count; ++i)
     {
         r[i] = DotNetObject.Marshal(list[i]);
     }
     return(r);
 }
コード例 #6
0
 public ListValue(IList xs, HeronType elementType)
 {
     list = new List <HeronValue>();
     foreach (Object x in xs)
     {
         list.Add(DotNetObject.Marshal(x));
     }
     this.elementType = elementType;
 }
コード例 #7
0
        public override HeronValue GetAtIndex(HeronValue index)
        {
            IntValue iv = index as IntValue;

            if (iv == null)
            {
                throw new Exception("Can only use index lists using integers");
            }
            return(DotNetObject.Marshal(list[iv.GetValue()]));
        }
コード例 #8
0
        public override HeronValue Instantiate(VM vm, HeronValue[] args, ModuleInstance m)
        {
            Object[] objs = HeronDotNet.ObjectsToDotNetArray(args);
            Object   o    = GetSystemType().InvokeMember(null, BindingFlags.Instance | BindingFlags.Public
                                                         | BindingFlags.Default | BindingFlags.CreateInstance, null, null, objs);

            if (o == null)
            {
                throw new Exception("Unable to construct " + name);
            }
            return(DotNetObject.Marshal(o));
        }
コード例 #9
0
        public override HeronValue GetFieldOrMethod(string name)
        {
            Type type = GetSystemType();

            // We have to first look to see if there are static exposedFields
            FieldInfo[] fis = type.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetField);
            foreach (FieldInfo fi in fis)
            {
                if (fi.Name == name)
                {
                    return(DotNetObject.Marshal(fi.GetValue(obj)));
                }
            }

            // Look for methods
            MethodInfo[] mis = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod);
            if (mis.Length != 0)
            {
                return(new DotNetMethodGroup(this, name));
            }

            return(null);
        }
コード例 #10
0
 public HeronValue InternalAt(int n)
 {
     return(DotNetObject.Marshal(list[n]));
 }
コード例 #11
0
 public override HeronValue GetValue(HeronValue self)
 {
     return(DotNetObject.Marshal(fi.GetValue(self)));
 }