public TinymoeObject GetField(TinymoeObject target, string name) { TinymoeObject value = null; if (target != null) { if (target.fields.TryGetValue(name, out value)) { return(value); } } Type type = target == null ? typeof(TinymoeObject) : target.GetType(); while (type != null) { if (extensions.TryGetValue(Tuple.Create(type, name), out value)) { return(value); } type = type.BaseType; } throw new ArgumentOutOfRangeException("name"); }
private static object FromTinymoe(TinymoeObject v, Type type) { if (type == typeof(bool)) { return(((TinymoeBoolean)v).Value); } else if (type == typeof(int)) { return(((TinymoeInteger)v).Value); } else if (type == typeof(double)) { return(((TinymoeFloat)v).Value); } else if (type == typeof(string)) { return(((TinymoeString)v).Value); } else if (type == typeof(TinymoeObject)) { return(v); } else { throw new ArgumentException(string.Format("A TinymoeObject cannot be converted to A value of {0}.", v.GetType().FullName)); } }
private static TinymoeObject Print(TinymoeObject a) { var value = CastToString(a); Console.WriteLine(value.Value); return(null); }
public TinymoeObject SetFields(TinymoeObject[] values) { foreach (var x in this.fieldNames.Zip(values, Tuple.Create)) { this.fields[x.Item1] = x.Item2; } return this; }
public static TinymoeInteger CastToInteger(TinymoeObject a) { if (a is TinymoeInteger) { return((TinymoeInteger)a); } else if (a is TinymoeFloat) { return(new TinymoeInteger((int)((TinymoeFloat)a).Value)); } else { return(new TinymoeInteger(int.Parse(((TinymoeString)a).Value))); } }
public static TinymoeFloat CastToFloat(TinymoeObject a) { if (a is TinymoeInteger) { return(new TinymoeFloat((double)((TinymoeInteger)a).Value)); } else if (a is TinymoeFloat) { return((TinymoeFloat)a); } else { return(new TinymoeFloat(double.Parse(((TinymoeString)a).Value))); } }
public void SetField(string name, TinymoeObject value) { if (finishedConstruction) { if (!this.fieldNames.Contains(name)) { throw new ArgumentOutOfRangeException("name"); } this.fields[name] = value; } else { this.fields[name] = value; this.fieldNames.Add(name); } }
public static TinymoeObject CastToNumber(TinymoeObject a) { if (a is TinymoeInteger || a is TinymoeFloat) { return(a); } else { var value = (TinymoeString)a; int i; if (int.TryParse(value.Value, out i)) { return(new TinymoeInteger(i)); } else { return(new TinymoeFloat(double.Parse(value.Value))); } } }
public static TinymoeString CastToString(TinymoeObject a) { if (a == null) { return(new TinymoeString("<null>")); } if (a is TinymoeInteger) { return(new TinymoeString(((TinymoeInteger)a).Value.ToString())); } else if (a is TinymoeFloat) { return(new TinymoeString(((TinymoeFloat)a).Value.ToString())); } else if (a is TinymoeBoolean) { return(new TinymoeString(((TinymoeBoolean)a).Value.ToString())); } else if (a is TinymoeSymbol) { return(new TinymoeString(((TinymoeSymbol)a).Value.ToString())); } else if (a is TinymoeString) { return((TinymoeString)a); } else if (a is TinymoeArray) { return(new TinymoeString("<array>")); } else if (a is TinymoeFunction) { return(new TinymoeString("<function>")); } else { return(new TinymoeString(string.Format("<{0}>", a.GetType().Name))); } }
public static TinymoeObject ArrayLength(TinymoeObject array) { return new TinymoeInteger(((TinymoeArray)array).Elements.Length); }
public static void SetExtension(Type type, string name, TinymoeObject value) { extensions[Tuple.Create(type, name)] = value; }
public TinymoeObject GetField(TinymoeObject target, string name) { TinymoeObject value = null; if (target != null) { if (target.fields.TryGetValue(name, out value)) { return value; } } Type type = target == null ? typeof(TinymoeObject) : target.GetType(); while (type != null) { if (extensions.TryGetValue(Tuple.Create(type, name), out value)) { return value; } type = type.BaseType; } throw new ArgumentOutOfRangeException("name"); }
public static TinymoeObject CastToNumber(TinymoeObject a) { if (a is TinymoeInteger || a is TinymoeFloat) { return a; } else { var value = (TinymoeString)a; int i; if (int.TryParse(value.Value, out i)) { return new TinymoeInteger(i); } else { return new TinymoeFloat(double.Parse(value.Value)); } } }
private static bool o_e_o(TinymoeObject a, TinymoeObject b) { return(a == b); }
private static bool o_e_o(TinymoeObject a, TinymoeObject b) { return a == b; }
private static object FromTinymoe(TinymoeObject v, Type type) { if (type == typeof(bool)) { return ((TinymoeBoolean)v).Value; } else if (type == typeof(int)) { return ((TinymoeInteger)v).Value; } else if (type == typeof(double)) { return ((TinymoeFloat)v).Value; } else if (type == typeof(string)) { return ((TinymoeString)v).Value; } else if (type == typeof(TinymoeObject)) { return v; } else { throw new ArgumentException(string.Format("A TinymoeObject cannot be converted to A value of {0}.", v.GetType().FullName)); } }
public static TinymoeFloat CastToFloat(TinymoeObject a) { if (a is TinymoeInteger) { return new TinymoeFloat((double)((TinymoeInteger)a).Value); } else if (a is TinymoeFloat) { return (TinymoeFloat)a; } else { return new TinymoeFloat(double.Parse(((TinymoeString)a).Value)); } }
private static TinymoeObject Print(TinymoeObject a) { var value = CastToString(a); Console.WriteLine(value.Value); return null; }
public static TinymoeContinuation Invoke(TinymoeObject function, TinymoeObject[] arguments) { return(((TinymoeFunction)function).Handler(arguments)); }
public static TinymoeObject ArrayLength(TinymoeObject array) { return(new TinymoeInteger(((TinymoeArray)array).Elements.Length)); }
public static TinymoeBoolean CastToBoolean(TinymoeObject a) { return((TinymoeBoolean)a); }
public static TinymoeObject ArrayGet(TinymoeObject array, TinymoeObject index) { return(((TinymoeArray)array).Elements[CastToInteger(index).Value - 1]); }
public static TinymoeObject ArrayGet(TinymoeObject array, TinymoeObject index) { return ((TinymoeArray)array).Elements[CastToInteger(index).Value - 1]; }
public static TinymoeObject Invoke(TinymoeObject function, TinymoeObject[] arguments) { throw new NotImplementedException(); }
public static void ArraySet(TinymoeObject array, TinymoeObject index, TinymoeObject value) { ((TinymoeArray)array).Elements[CastToInteger(index).Value - 1] = value; }
public TinymoeArray(TinymoeObject[] values) { this.Elements = values.ToArray(); }
public static TinymoeObject Positive(TinymoeObject a) { throw new NotImplementedException(); }
public static TinymoeObject Sub(TinymoeObject a, TinymoeObject b) { throw new NotImplementedException(); }
public static TinymoeBoolean CastToBoolean(TinymoeObject a) { return (TinymoeBoolean)a; }
public static TinymoeContinuation Invoke(TinymoeObject function, TinymoeObject[] arguments) { return ((TinymoeFunction)function).Handler(arguments); }
public static TinymoeInteger CastToInteger(TinymoeObject a) { if (a is TinymoeInteger) { return (TinymoeInteger)a; } else if (a is TinymoeFloat) { return new TinymoeInteger((int)((TinymoeFloat)a).Value); } else { return new TinymoeInteger(int.Parse(((TinymoeString)a).Value)); } }
public static TinymoeString CastToString(TinymoeObject a) { if (a == null) { return new TinymoeString("<null>"); } if (a is TinymoeInteger) { return new TinymoeString(((TinymoeInteger)a).Value.ToString()); } else if (a is TinymoeFloat) { return new TinymoeString(((TinymoeFloat)a).Value.ToString()); } else if (a is TinymoeBoolean) { return new TinymoeString(((TinymoeBoolean)a).Value.ToString()); } else if (a is TinymoeSymbol) { return new TinymoeString(((TinymoeSymbol)a).Value.ToString()); } else if (a is TinymoeString) { return (TinymoeString)a; } else if (a is TinymoeArray) { return new TinymoeString("<array>"); } else if (a is TinymoeFunction) { return new TinymoeString("<function>"); } else { return new TinymoeString(string.Format("<{0}>", a.GetType().Name)); } }
private static TinymoeObject Sqrt(TinymoeObject a) { var value = CastToFloat(a); return(new TinymoeFloat(Math.Sqrt(value.Value))); }
private static TinymoeObject Sqrt(TinymoeObject a) { var value = CastToFloat(a); return new TinymoeFloat(Math.Sqrt(value.Value)); }
public static TinymoeObject CastToString(TinymoeObject a) { throw new NotImplementedException(); }