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()); }
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()); }
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()); } }
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); } }
public NeoValue RawGet(NeoValue key) { if (data.ContainsKey(key)) { return(data[key]); } else { return(NeoNil.NIL); } }
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}"); }
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}"); } }
public override NeoValue Get(NeoValue key) { var name = key.CheckString().Value; if (Scope.IsExported(name)) { return(Scope.Get(name)); } else { return(NeoNil.NIL); } }
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}"); } }
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}"); } }
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}"); } }
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}"); } }
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); } }
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; } }
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); }
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)); } }
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); } }
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); } } }
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); } } }
public override NeoValue BitXor(NeoValue other) => obj.BitXor(other);
public override NeoValue Concat(NeoValue other) => obj.Concat(other);
public override NeoValue BitAnd(NeoValue other) => obj.BitAnd(other);
public override NeoValue Rsh(NeoValue other) => obj.Rsh(other);
public override NeoValue Lsh(NeoValue other) => obj.Lsh(other);
public override NeoValue Mod(NeoValue other) => obj.Mod(other);
public override NeoValue Slice(NeoValue start, NeoValue end) => obj.Slice(start, end);
public override void Remove(NeoValue key) => throw new NeoError("attempt to modify frozen object");
public override NeoValue Div(NeoValue other) => obj.Div(other);
public void RawSet(NeoValue key, NeoValue value) { data[key] = value; }
public override NeoValue Pow(NeoValue other) => obj.Pow(other);