public RacketPair() { value = null; rest = null; Null = true; Length = 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; } }
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); }
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)); }
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); }
public RacketPair(ObjBox _value, ObjBox _rest) { value = _value; rest = _rest; Null = false; if (_rest.getType() == typeof(voidObj)) { Length = 1; } else { Length = 2; } }
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); } }
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)); }
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; }
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); } }
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))); }
static RacketPair getRP(ObjBox val) { return (RacketPair)val.getObj(); }
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); }
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)); }
public RacketPair(ObjBox _value, ObjBox _rest) { value = _value; rest = _rest; Null = false; if (_rest.getType() == typeof(voidObj)) Length = 1; else Length = 2; }
public void add(String name, ObjBox value) { env.Add(name, value); }
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); }
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; } }
static int getVal(ObjBox val) { RacketInt rint = (RacketInt) val.getObj(); return rint.value; }