public static Obj CreateRecord(ushort[] labels, Obj[] values) { Obj[] labelObjs = new Obj[labels.Length]; for (int i = 0; i < labels.Length; i++) { labelObjs[i] = SymbObj.Get(labels[i]); } return(CreateMap(labelObjs, values)); }
public static Obj FileAppend_P(Obj fname, Obj data, object env) { try { IO.AppendAllBytes(fname.GetString(), data.GetByteArray()); return(SymbObj.Get(SymbObj.TrueSymbId)); } catch (Exception) { return(SymbObj.Get(SymbObj.FalseSymbId)); } }
public static Obj FileRead_P(Obj fname, object env) { try { byte[] content = IO.ReadAllBytes(fname.GetString()); Obj bytesObj = Builder.CreateSeq(content); return(Builder.CreateTaggedObj(SymbObj.JustSymbId, bytesObj)); } catch (Exception) { return(SymbObj.Get(SymbObj.NothingSymbId)); } }
public static Obj Save_P(Obj fname, RelAutoBase automaton, RelAutoUpdaterBase updater, object env) { try { DataWriter writer = IO.FileDataWriter(fname.GetString()); automaton.WriteState(writer); return(SymbObj.Get(true)); } catch (Exception e) { updater.lastException = e; return(SymbObj.Get(false)); } }
public static Obj GetChar_P(object env) { int ch = IO.StdInRead(-1, -1); if (ch != -1) { return(Builder.CreateTaggedObj(SymbObj.JustSymbId, IntObj.Get(ch))); } else { return(SymbObj.Get(SymbObj.NothingSymbId)); } }
////////////////////////////////////////////////////////////////////////////// public static Obj CreateSeq(bool[] vals, int len) { if (len == 0) { return(EmptySeqObj.singleton); } Obj[] objs = new Obj[len]; for (int i = 0; i < len; i++) { objs[i] = SymbObj.Get(vals[i]); } return(ArrayObjs.Create(objs)); }
private void BuildCol1() { if (col1 == null) { int len = fieldIds.Length; col1 = new Obj[len]; hashcodes1 = new uint[len]; for (int i = 0; i < len; i++) { Obj symbObj = SymbObj.Get(fieldIds[i]); col1[i] = symbObj; hashcodes1[i] = symbObj.Hashcode(); } } }
public override uint Hashcode() { if (hcode == Hashing.NULL_HASHCODE) { long hcode = 0; for (int i = 0; i < fieldIds.Length; i++) { hcode += Hashing.Hashcode(SymbObj.Get(fieldIds[i]).Hashcode(), col2[i].Hashcode()); } hcode = Hashing.Hashcode64(hcode); if (hcode == Hashing.NULL_HASHCODE) { hcode++; } } return(hcode); }
//////////////////////////////////////////////////////////////////////////////// // The opening parenthesis and the first label including // its trailing colon must have already been consumed Obj ParseRec(ushort firstLabelId) { ushort[] labels = new ushort[8]; Obj[] values = new Obj[8]; labels[0] = firstLabelId; values[0] = ParseObj(); int i = 1; while (TryConsumingComma()) { if (i >= labels.Length) { labels = Array.Extend(labels, 2 * labels.Length); values = Array.Extend(values, 2 * values.Length); } ushort labelId = TryReadingLabel(); if (labelId == SymbObj.InvalidSymbId) { throw Fail(); } //## BAD BAD BAD: WITH A LARGE RECORD... for (int j = 0; j < i; j++) { if (labels[j] == labelId) { throw Fail(); } } labels[i] = labelId; values[i++] = ParseObj(); } ConsumeClosePar(); Obj[] labelObjs = new Obj[i]; for (int j = 0; j < i; j++) { labelObjs[j] = SymbObj.Get(labels[j]); } //## IT WOULD BE BETTER TO CREATE A RecordObj, BUT THE LABELS WOULD NEED TO BE SORTED FIRST return(Builder.CreateMap(labelObjs, values, i)); }
public SymbObj GetTag() { return(SymbObj.Get(GetTagId())); }
//////////////////////////////////////////////////////////////////////////////// Obj ParseSymbOrTaggedObj() { ushort symbId = ReadSymbol(); if (!TryConsumingOpenPar()) { return(SymbObj.Get(symbId)); } TokenType type = PeekType(); Obj firstValue = null; if (type == TokenType.Int) { long value = ReadLong(); if (TryConsumingClosePar()) { return(Builder.CreateTaggedIntObj(symbId, value)); } // Here we've consumed the opening parenthesis and the integer // Since the opening parenthesis was not follow by a label, // we're dealing with a sequence, possibly a sequence of integers //## OPTIMIZE FOR SEQUENCES OF INTEGERS firstValue = IntObj.Get(value); } else if (type == TokenType.Symbol) { ushort labelId = TryReadingLabel(); if (labelId != SymbObj.InvalidSymbId) { return(CreateTaggedObj(symbId, ParseRec(labelId))); } firstValue = ParseObj(); } else { firstValue = ParseObj(); } if (TryConsumingClosePar()) { return(CreateTaggedObj(symbId, firstValue)); } Obj[] elts = new Obj[16]; elts[0] = firstValue; int i = 1; while (TryConsumingComma()) { if (i >= elts.Length) { elts = Array.Extend(elts, 2 * elts.Length); } elts[i++] = ParseObj(); } ConsumeClosePar(); return(CreateTaggedObj(symbId, Builder.CreateSeq(elts, i))); }