Example #1
0
 public RacketPair()
 {
     value  = null;
     rest   = null;
     Null   = true;
     Length = 0;
 }
Example #2
0
 private void Form1_KeyDown(object sender, KeyEventArgs e)
 {
     List<object> obj = new List<object>();
     switch (e.KeyCode)
     {
         case Keys.W://up
             obj.Add((object)Board);
             Board = (ObjBox) DLL2048.move_board_up_helper(env, obj);
            // DLL2048.debug_display(env, obj);
             redraw_gui(Board);
             break;
         case Keys.A://left
             obj.Add((object)Board);
             Board = (ObjBox) DLL2048.move_board_left_helper(env, obj);
           //  DLL2048.debug_display(env, obj);
             redraw_gui(Board);
             break;
         case Keys.S://down
             obj.Add((object)Board);
             Board = (ObjBox) DLL2048.move_board_down_helper(env, obj);
            // DLL2048.net_debug_display(env, obj);
             redraw_gui(Board);
             break;
         case Keys.D://right
             obj.Add((object)Board);
             Board = (ObjBox) DLL2048.move_board_right_helper(env, obj);
           //  DLL2048.debug_display(env, obj);
             redraw_gui(Board);
             break;
     }
 }
Example #3
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);
        }
Example #4
0
 public override bool Equals(object obj)
 {
     if (obj.GetType() == typeof(ObjBox))
     {
         ObjBox other = (ObjBox)obj;
         return((this.type == other.type) && (this.getObj().Equals(other.getObj())));
     }
     return(base.Equals(obj));
 }
Example #5
0
        public static ObjBox Foldl(FunctionHolder function, ObjBox init_param, List <RacketPair> lists)
        {
            ObjBox        init     = init_param;
            List <Object> args     = new List <Object>();
            bool          restNull = lists[0].isNull();
            int           listLength;

            if (function.param_num != lists.Count + 1)
            {
                throw new RuntimeException("Wrong number of arguments for given procedure");
            }

            while (!lists[0].isNull())
            {
                args.Clear();
                //    args.Add(init);
                listLength = -1;
                for (int i = 0; i < lists.Count; i++)
                {
                    if (listLength == -1)
                    {
                        listLength = lists[i].length();
                    }
                    if (lists[i].length() != listLength)
                    {
                        throw new RuntimeException("Lists must be of same length");
                    }
                    if (lists[i].isNull())
                    {
                        throw new RuntimeException("Lists must be of same length");
                    }

                    args.Add(lists[i].car());
                    ObjBox rest = lists[i].cdr();

                    /*
                     * if (rest.getType() == typeof(voidObj))
                     * {
                     *  restNull = true;
                     * }
                     * else
                     * { */
                    lists[i] = (RacketPair)rest.getObj();
                }
                args.Add(init);
                init = function.invoke(args); // should be okay if making copies
                //    returnedValues.Add(function.invoke(args));
            }

            return(init);
        }
Example #6
0
 public RacketPair(ObjBox _value, ObjBox _rest)
 {
     value = _value;
     rest  = _rest;
     Null  = false;
     if (_rest.getType() == typeof(voidObj))
     {
         Length = 1;
     }
     else
     {
         Length = 2;
     }
 }
Example #7
0
 public void set(String name, ObjBox newValue)
 {
     if (env.ContainsKey(name))
     {
         env[name] = newValue;
     }
     else
     {
         if (parent == null)
         {
             throw new RuntimeException("variable reference to unscoped variable: " + name.ToString());
         }
         parent.set(name, newValue);
     }
 }
Example #8
0
 public RacketPair(List <ObjBox> list)
 {
     if (list.Count == 0)
     {
         value  = null;
         rest   = null;
         Null   = true;
         Length = 0;
         return;
     }
     value = list[0];
     Null  = false;
     list.RemoveAt(0);
     Length = list.Count;
     rest   = new ObjBox(new RacketPair(list), typeof(RacketPair));
 }
Example #9
0
        public static ObjBox Foldl(FunctionHolder function, ObjBox init_param, List<RacketPair> lists)
        {
            ObjBox init = init_param;
            List<Object> args = new List<Object>();
            bool restNull = lists[0].isNull();
            int listLength;

            if (function.param_num != lists.Count + 1)
                throw new RuntimeException("Wrong number of arguments for given procedure");

            while (!lists[0].isNull())
            {
                args.Clear();
            //    args.Add(init);
                listLength = -1;
                for (int i = 0; i < lists.Count; i++)
                {
                    if (listLength == -1)
                        listLength = lists[i].length();
                    if (lists[i].length() != listLength)
                        throw new RuntimeException("Lists must be of same length");
                    if (lists[i].isNull())
                        throw new RuntimeException("Lists must be of same length");

                    args.Add(lists[i].car());
                    ObjBox rest = lists[i].cdr();
                    /*
                    if (rest.getType() == typeof(voidObj))
                    {
                        restNull = true;
                    }
                    else
                    { */
                        lists[i] = (RacketPair)rest.getObj();
                }
                args.Add(init);
                init = function.invoke(args); // should be okay if making copies
            //    returnedValues.Add(function.invoke(args));
            }

            return init;
        }
Example #10
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);
            }
        }
Example #11
0
        public static ObjBox Map(FunctionHolder function, List <RacketPair> lists)
        {
            List <ObjBox> returnedValues = new List <ObjBox>();
            List <Object> args           = new List <Object>();
            bool          restNull       = lists[0].isNull();
            int           listLength     = -1;

            while (!restNull)
            {
                args.Clear();
                for (int i = 0; i < lists.Count; i++)
                {
                    if (listLength == -1)
                    {
                        listLength = lists[i].length();
                    }
                    if (lists[i].length() != listLength)
                    {
                        throw new RuntimeException("Lists must be of same length");
                    }

                    args.Add(lists[i].car());
                    ObjBox rest = lists[i].cdr();

                    if (((RacketPair)rest.getObj()).isNull())
                    {
                        restNull = true;
                    }
                    else
                    {
                        lists[i] = (RacketPair)rest.getObj();
                    }
                }
                returnedValues.Add(function.invoke(args));
            }

            return(new ObjBox(new RacketPair(returnedValues), typeof(RacketPair)));
        }
Example #12
0
 static RacketPair getRP(ObjBox val)
 {
     return (RacketPair)val.getObj();
 }
Example #13
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);
        }
Example #14
0
 public RacketPair(List<ObjBox> list)
 {
     if (list.Count == 0)
     {
         value = null;
         rest = null;
         Null = true;
         Length = 0;
         return;
     }
     value = list[0];
     Null = false;
     list.RemoveAt(0);
     Length = list.Count;
     rest = new ObjBox(new RacketPair(list), typeof(RacketPair));
 }
Example #15
0
 public RacketPair()
 {
     value = null;
     rest = null;
     Null = true;
     Length = 0;
 }
Example #16
0
 public RacketPair(ObjBox _value, ObjBox _rest)
 {
     value = _value;
     rest = _rest;
     Null = false;
     if (_rest.getType() == typeof(voidObj))
         Length = 1;
     else
         Length = 2;
 }
Example #17
0
 public void add(String name, ObjBox value)
 {
     env.Add(name, value);
 }
Example #18
0
 private void Form1_Load(object sender, EventArgs e)
 {
     this.BringToFront();
     this.Focus();
     this.KeyPreview = true;
     this.KeyDown += new KeyEventHandler(Form1_KeyDown);
     env = DLL2048.init();
     Board = (ObjBox) DLL2048.init_board(env, new List<object>());
     redraw_gui(Board);
 }
Example #19
0
        private void redraw_gui(ObjBox board)
        {
            RacketPair rp = getRP(board);
            int temp = 0;
            int holder = 0;
            System.Drawing.Color c;

            for (int i = 0; i < 4; i++)
            {
                RacketPair row = getRP(rp.car());
                rp = getRP(rp.cdr());

                for (int j = 0; j < 4; j++)
                {
                    holder = getVal(row.car());
                    c = num2Color(holder);
                    ((RectangleShape) this.shapeContainer1.Shapes.get_Item(temp+j)).BackColor = c;
                    labelGrid[temp + j].Text = (holder == 0) ? "" : (holder + "");
                    if (holder > 4)
                    {
                        labelGrid[temp + j].ForeColor = System.Drawing.ColorTranslator.FromHtml("#F9F6F2");
                    }
                    else
                    {
                        labelGrid[temp + j].ForeColor = System.Drawing.ColorTranslator.FromHtml("#776E65");
                    }
                    labelGrid[temp+j].BackColor = c;
                    row = getRP(row.cdr());
                }
                temp+=4;
            }
        }
Example #20
0
 public void add(String name, ObjBox value)
 {
     env.Add(name, value);
 }
Example #21
0
 public void set(String name, ObjBox newValue)
 {
     if (env.ContainsKey(name))
     {
         env[name] = newValue;
     }
     else
     {
         if (parent == null)
         {
             throw new RuntimeException("variable reference to unscoped variable: " + name.ToString());
         }
         parent.set(name, newValue);
     }
 }
Example #22
0
 static int getVal(ObjBox val)
 {
     RacketInt rint = (RacketInt) val.getObj();
     return rint.value;
 }