示例#1
0
        internal string Stringify(HashSet <NeoValue> seen)
        {
            if (data.Count == 0)
            {
                return("[]");
            }

            var builder = new StringBuilder();

            builder.Append("[ ");

            for (var i = 0; i < data.Count; i++)
            {
                builder.Append(NeoValue.StringifyElement(seen, data[i]));

                if (i + 1 < data.Count)
                {
                    builder.Append(", ");
                }
            }

            builder.Append(" ]");

            return(builder.ToString());
        }
示例#2
0
        internal string Stringify(HashSet <NeoValue> seen)
        {
            if (data.Count == 0)
            {
                return("{}");
            }

            var builder = new StringBuilder();

            builder.Append("{ ");

            var i = 1;

            foreach (var mapping in data)
            {
                builder.Append(NeoValue.StringifyElement(seen, mapping.Key));
                builder.Append(" = ");
                builder.Append(NeoValue.StringifyElement(seen, mapping.Value));

                if (i < data.Count)
                {
                    builder.Append(", ");
                }
                i++;
            }

            builder.Append(" }");

            return(builder.ToString());
        }
示例#3
0
 internal static string StringifyElement(HashSet <NeoValue> seen, NeoValue value)
 {
     if (value is NeoObject o)
     {
         if (seen.Contains(value))
         {
             return("<already-seen>");
         }
         else
         {
             seen.Add(value);
             return(o.Stringify(seen));
         }
     }
     else if (value is NeoArray a)
     {
         if (seen.Contains(value))
         {
             return("[already-seen]");
         }
         else
         {
             seen.Add(value);
             return(a.Stringify(seen));
         }
     }
     else
     {
         return(value.ToNeoString());
     }
 }
示例#4
0
        public override bool Equals(NeoValue value, bool deep)
        {
            if (!value.IsArray)
            {
                return(false);
            }

            var other = value.CheckArray();

            if (other.data.Count != data.Count)
            {
                return(false);
            }

            if (deep)
            {
                for (var i = 0; i < data.Count; i++)
                {
                    if (!other[i].Equals(this[i], true))
                    {
                        return(false);
                    }
                }
                return(true);
            }
            else
            {
                return(value == this);
            }
        }
示例#5
0
 public NeoValue RawGet(NeoValue key)
 {
     if (data.ContainsKey(key))
     {
         return(data[key]);
     }
     else
     {
         return(NeoNil.NIL);
     }
 }
示例#6
0
 public override int Compare(NeoValue other)
 {
     if (other.IsInt)
     {
         return(((double)other.CheckInt().Value).CompareTo(Value));
     }
     else if (other.IsFloat)
     {
         return(other.CheckFloat().Value.CompareTo(Value));
     }
     throw new NeoError($"Attempt to compare float to {other.Type}");
 }
示例#7
0
        public override NeoValue BitXor(NeoValue other)
        {
            var mm = GetMetaMethod("__bitxor", other);

            if (mm != null)
            {
                return(mm.Call(new [] { this, other }));
            }
            else
            {
                throw new NeoError($"attempt to bit-xor {Type} and {other.Type}");
            }
        }
示例#8
0
        public override NeoValue Get(NeoValue key)
        {
            var name = key.CheckString().Value;

            if (Scope.IsExported(name))
            {
                return(Scope.Get(name));
            }
            else
            {
                return(NeoNil.NIL);
            }
        }
示例#9
0
        public override NeoValue Pow(NeoValue other)
        {
            var mm = GetMetaMethod("__pow", other);

            if (mm != null)
            {
                return(mm.Call(new [] { this, other }));
            }
            else
            {
                throw new NeoError($"attempt to exponentiate {Type} and {other.Type}");
            }
        }
示例#10
0
        public override NeoValue Concat(NeoValue other)
        {
            var mm = GetMetaMethod("__concat", other);

            if (mm != null)
            {
                return(mm.Call(new [] { this, other }));
            }
            else
            {
                throw new NeoError($"attempt to concat {Type} and {other.Type}");
            }
        }
示例#11
0
        public override NeoValue Rsh(NeoValue other)
        {
            var mm = GetMetaMethod("__rsh", other);

            if (mm != null)
            {
                return(mm.Call(new [] { this, other }));
            }
            else
            {
                throw new NeoError($"attempt to right-shift {Type} and {other.Type}");
            }
        }
示例#12
0
        public override NeoValue Slice(NeoValue start, NeoValue end)
        {
            var mm = GetMetaMethod("__slice");

            if (mm != null)
            {
                return(mm.Call(new [] { this, start, end }));
            }
            else
            {
                throw new NeoError($"attenpt to slice {Type}");
            }
        }
示例#13
0
 public override bool Equals(NeoValue other, bool deep)
 {
     if (other.IsInt)
     {
         return(((double)other.CheckInt().Value) == Value);
     }
     else if (other.IsFloat)
     {
         return(other.CheckFloat().Value == Value);
     }
     else
     {
         return(false);
     }
 }
示例#14
0
        public override void Set(NeoValue key, NeoValue value)
        {
            var mm = GetMetaMethod("__set");

            if (mm != null)
            {
                mm.Call(new [] { this, key, value });
            }
            else
            {
                if (!data.ContainsKey(key))
                {
                    keys.Add(key);
                }
                data[key] = value;
            }
        }
示例#15
0
        public override NeoValue Slice(NeoValue start, NeoValue end)
        {
            var s = start.CheckInt().Value;
            var e = end.CheckInt().Value;
            var d = s > e ? -1 : 1;

            var a = new NeoArray();
            var i = s;

            while (i != e)
            {
                a.Insert(this[i]);
                i += d;
            }
            a.Insert(this[i]);

            return(a);
        }
示例#16
0
        public override int Compare(NeoValue other)
        {
            var mm = GetMetaMethod("__compare", other);

            if (mm != null)
            {
                var r = mm.Call(new [] { this, other });
                return(r.CheckInt().Value);
            }
            else
            {
                if (!other.IsObject)
                {
                    return(base.Compare(other));
                }

                return(base.Compare(other));
            }
        }
示例#17
0
        public override int Compare(NeoValue other)
        {
            var otherNumber = other.CheckNumber();
            var a           = AsDouble;
            var b           = otherNumber.AsDouble;

            if (a > b)
            {
                return(1);
            }
            else if (a < b)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
示例#18
0
        public override NeoValue Get(NeoValue key)
        {
            var mm = GetMetaMethod("__get");

            if (mm != null)
            {
                return(mm.Call(new [] { this, key }));
            }
            else
            {
                if (data.ContainsKey(key))
                {
                    return(data[key]);
                }
                else
                {
                    return(NeoNil.NIL);
                }
            }
        }
示例#19
0
        public override bool Equals(NeoValue value, bool deep)
        {
            var mm = GetMetaMethod("__equals", value);

            if (mm != null)
            {
                var r = mm.Call(new [] { this, value, NeoBool.ValueOf(deep) });
                return(r.CheckBool().Value);
            }
            else
            {
                if (!value.IsObject)
                {
                    return(false);
                }

                var other = value.CheckObject();
                if (other.data.Count != data.Count)
                {
                    return(false);
                }

                if (deep)
                {
                    foreach (var mapping in data)
                    {
                        if (!mapping.Value.Equals(other.Get(mapping.Key), true))
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
                else
                {
                    return(this == other);
                }
            }
        }
示例#20
0
 public override NeoValue BitXor(NeoValue other) => obj.BitXor(other);
示例#21
0
 public override NeoValue Concat(NeoValue other) => obj.Concat(other);
示例#22
0
 public override NeoValue BitAnd(NeoValue other) => obj.BitAnd(other);
示例#23
0
 public override NeoValue Rsh(NeoValue other) => obj.Rsh(other);
示例#24
0
 public override NeoValue Lsh(NeoValue other) => obj.Lsh(other);
示例#25
0
 public override NeoValue Mod(NeoValue other) => obj.Mod(other);
示例#26
0
 public override NeoValue Slice(NeoValue start, NeoValue end) => obj.Slice(start, end);
示例#27
0
 public override void Remove(NeoValue key) => throw new NeoError("attempt to modify frozen object");
示例#28
0
 public override NeoValue Div(NeoValue other) => obj.Div(other);
示例#29
0
 public void RawSet(NeoValue key, NeoValue value)
 {
     data[key] = value;
 }
示例#30
0
 public override NeoValue Pow(NeoValue other) => obj.Pow(other);