Esempio n. 1
0
        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");
        }
Esempio n. 2
0
 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));
     }
 }
Esempio n. 3
0
        private static TinymoeObject Print(TinymoeObject a)
        {
            var value = CastToString(a);

            Console.WriteLine(value.Value);
            return(null);
        }
Esempio n. 4
0
 public TinymoeObject SetFields(TinymoeObject[] values)
 {
     foreach (var x in this.fieldNames.Zip(values, Tuple.Create))
     {
         this.fields[x.Item1] = x.Item2;
     }
     return this;
 }
Esempio n. 5
0
 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)));
     }
 }
Esempio n. 6
0
 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)));
     }
 }
Esempio n. 7
0
 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);
     }
 }
Esempio n. 8
0
 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);
     }
 }
Esempio n. 9
0
 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)));
         }
     }
 }
Esempio n. 10
0
 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)));
     }
 }
Esempio n. 11
0
 public static TinymoeObject ArrayLength(TinymoeObject array)
 {
     return new TinymoeInteger(((TinymoeArray)array).Elements.Length);
 }
Esempio n. 12
0
 public static void SetExtension(Type type, string name, TinymoeObject value)
 {
     extensions[Tuple.Create(type, name)] = value;
 }
Esempio n. 13
0
        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");
        }
Esempio n. 14
0
 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));
         }
     }
 }
Esempio n. 15
0
 private static bool o_e_o(TinymoeObject a, TinymoeObject b)
 {
     return(a == b);
 }
Esempio n. 16
0
 private static bool o_e_o(TinymoeObject a, TinymoeObject b)
 {
     return a == b;
 }
Esempio n. 17
0
 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));
     }
 }
Esempio n. 18
0
 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));
     }
 }
Esempio n. 19
0
 private static TinymoeObject Print(TinymoeObject a)
 {
     var value = CastToString(a);
     Console.WriteLine(value.Value);
     return null;
 }
Esempio n. 20
0
 public static void SetExtension(Type type, string name, TinymoeObject value)
 {
     extensions[Tuple.Create(type, name)] = value;
 }
Esempio n. 21
0
 public static TinymoeContinuation Invoke(TinymoeObject function, TinymoeObject[] arguments)
 {
     return(((TinymoeFunction)function).Handler(arguments));
 }
Esempio n. 22
0
 public static TinymoeObject ArrayLength(TinymoeObject array)
 {
     return(new TinymoeInteger(((TinymoeArray)array).Elements.Length));
 }
Esempio n. 23
0
 public static TinymoeBoolean CastToBoolean(TinymoeObject a)
 {
     return((TinymoeBoolean)a);
 }
Esempio n. 24
0
 public static TinymoeObject ArrayGet(TinymoeObject array, TinymoeObject index)
 {
     return(((TinymoeArray)array).Elements[CastToInteger(index).Value - 1]);
 }
Esempio n. 25
0
 public static TinymoeObject ArrayGet(TinymoeObject array, TinymoeObject index)
 {
     return ((TinymoeArray)array).Elements[CastToInteger(index).Value - 1];
 }
Esempio n. 26
0
 public static TinymoeObject Invoke(TinymoeObject function, TinymoeObject[] arguments)
 {
     throw new NotImplementedException();
 }
Esempio n. 27
0
 public static void ArraySet(TinymoeObject array, TinymoeObject index, TinymoeObject value)
 {
     ((TinymoeArray)array).Elements[CastToInteger(index).Value - 1] = value;
 }
Esempio n. 28
0
 public TinymoeArray(TinymoeObject[] values)
 {
     this.Elements = values.ToArray();
 }
Esempio n. 29
0
 public static TinymoeObject Positive(TinymoeObject a)
 {
     throw new NotImplementedException();
 }
Esempio n. 30
0
 public static TinymoeObject Sub(TinymoeObject a, TinymoeObject b)
 {
     throw new NotImplementedException();
 }
Esempio n. 31
0
 public static TinymoeBoolean CastToBoolean(TinymoeObject a)
 {
     return (TinymoeBoolean)a;
 }
Esempio n. 32
0
 public static TinymoeContinuation Invoke(TinymoeObject function, TinymoeObject[] arguments)
 {
     return ((TinymoeFunction)function).Handler(arguments);
 }
Esempio n. 33
0
 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));
     }
 }
Esempio n. 34
0
 public static void ArraySet(TinymoeObject array, TinymoeObject index, TinymoeObject value)
 {
     ((TinymoeArray)array).Elements[CastToInteger(index).Value - 1] = value;
 }
Esempio n. 35
0
 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));
     }
 }
Esempio n. 36
0
        private static TinymoeObject Sqrt(TinymoeObject a)
        {
            var value = CastToFloat(a);

            return(new TinymoeFloat(Math.Sqrt(value.Value)));
        }
Esempio n. 37
0
 private static TinymoeObject Sqrt(TinymoeObject a)
 {
     var value = CastToFloat(a);
     return new TinymoeFloat(Math.Sqrt(value.Value));
 }
Esempio n. 38
0
 public static TinymoeObject CastToString(TinymoeObject a)
 {
     throw new NotImplementedException();
 }