Esempio n. 1
0
        public override String ToString()
        {
            String lhs;
            String rhs;

            if (isNull())
            {
                return("()");
            }

            if (value.getType() == typeof(RacketPair))
            {
                lhs = ((RacketPair)value.getObj()).printList();
            }
            else
            {
                lhs = value.getObj().ToString();
            }

            if (rest.getType() == typeof(RacketPair))
            {
                rhs = ((RacketPair)rest.getObj()).printList();
            }
            else
            {
                if (rest.getType() == typeof(voidObj))
                {
                    return(lhs);
                }
                rhs = rest.getObj().ToString();
            }

            return("(" + lhs + " " + rhs + ")");
        }
Esempio n. 2
0
        public static ObjBox Apply(FunctionHolder function, RacketPair list)
        {
            int           param_num = function.param_num;
            List <Object> args      = new List <Object>();
            ObjBox        fun_call;

            if (list.length() != param_num)
            {
                throw new RuntimeException("The expected number of arguments does not match the given number");
            }
            int length = list.length();

            for (int i = 0; i < length; i++)
            {
                args.Add(list.car());
                ObjBox rest = list.cdr();

                if (rest.getType() == typeof(voidObj))
                {
                    break;
                }
                else
                {
                    list = (RacketPair)rest.getObj();
                }
            }
            fun_call = function.invoke(args);

            return(fun_call);
        }
Esempio n. 3
0
 public RacketPair(ObjBox _value, ObjBox _rest)
 {
     value = _value;
     rest  = _rest;
     Null  = false;
     if (_rest.getType() == typeof(voidObj))
     {
         Length = 1;
     }
     else
     {
         Length = 2;
     }
 }
Esempio n. 4
0
        private static void ConvertRacketNum(ObjBox o, List <Type> argTypes, List <object> objArray)
        {
            Type t = o.getType();

            if (t == typeof(RacketInt))
            {
                argTypes.Add(typeof(int));
                objArray.Add(((RacketInt)o.getObj()).value);
            }
            else if (t == typeof(RacketFloat))
            {
                argTypes.Add(typeof(double));
                objArray.Add(((RacketFloat)o.getObj()).value);
            }
            else if (t == typeof(RacketComplex))
            {
                argTypes.Add(typeof(Complex));
                objArray.Add(((RacketComplex)o.getObj()).value);
            }
        }
Esempio n. 5
0
        public static ObjBox call(ObjBox wrapper, String s, ObjBox[] args)
        {
            Object instance = null;
            Type   t;

            //if we have a static call the objBox will have a string that is the fully qualified type
            if (wrapper.getType() == (typeof(voidObj)))
            {
                String typename = (String)wrapper.getObj();
                t = typeResolver.resolve(typename);
            }
            else
            {
                t        = wrapper.getType();
                instance = wrapper.getObj();
            }

            if (t == null)
            {
                throw new RuntimeException("Could not resolve type: " + s);
            }

            // lets get all our object boxes into nice arrays
            List <Type>   argTypes = new List <Type>();
            List <Object> objArray = new List <Object>();

            unpackObjList(args, argTypes, objArray);

            MethodInfo   m = t.GetMethod(s, argTypes.ToArray());
            FieldInfo    f = t.GetField(s);
            PropertyInfo p = t.GetProperty(s);

            // Case where we are calling a method
            if (m != null)
            {
                return(callMethod(instance, m, argTypes, objArray));
            }

            // they may be trying to access a field
            if (f != null)
            {
                return(callField(instance, f, argTypes, objArray));
            }

            // lets check if we are trying to set a property
            if (p != null)
            {
                return(callProperty(instance, p, argTypes, objArray));
            }

            String exceptionMessage;

            if (argTypes.Count == 0)
            {
                exceptionMessage = "Type:" + t.ToString() + "does not contain matching method or property: " + s;
            }
            else
            {
                exceptionMessage = "Type:" + t.ToString() + "does not contain method matching signature: " + s + " with types: ";
                foreach (Type sig in argTypes)
                {
                    exceptionMessage += " " + sig.ToString() + " ";
                }
            }
            throw new RuntimeException(exceptionMessage);
        }
Esempio n. 6
0
 public RacketPair(ObjBox _value, ObjBox _rest)
 {
     value = _value;
     rest = _rest;
     Null = false;
     if (_rest.getType() == typeof(voidObj))
         Length = 1;
     else
         Length = 2;
 }
Esempio n. 7
0
 public Boolean isNull()
 {
     return(Null || value.getType() == typeof(voidObj));
 }