public static Obj Ticks_P(object env) { long tick = IO.UnixTimeMs(); if (startTick == -1) { startTick = tick; } return(IntObj.Get(tick - startTick)); }
public static Obj CreateTaggedIntObj(ushort tag, long value) { if (TaggedIntObj.Fits(value)) { return(new TaggedIntObj(tag, value)); } else { return(new TaggedObj(tag, IntObj.Get(value))); } }
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 Obj ParseObj() { TokenType type = PeekType(); switch (type) { case TokenType.Comma: case TokenType.Colon: case TokenType.Semicolon: case TokenType.Arrow: case TokenType.ClosePar: case TokenType.CloseBracket: throw Fail(); case TokenType.Int: return(IntObj.Get(ReadLong())); case TokenType.Float: return(new FloatObj(ReadDouble())); case TokenType.Symbol: return(ParseSymbOrTaggedObj()); case TokenType.OpenPar: ConsumeOpenPar(); return(ParseSeqOrRecord(PeekType())); case TokenType.OpenBracket: return(ParseUnordColl()); case TokenType.String: return(ReadString()); case TokenType.Literal: return(ReadLiteral()); default: throw ErrorHandler.InternalFail(); // Unreachable code } }
public Obj ReadLiteral() { Debug.Assert(NextIs('`')); Read(); int ch1 = Read(); int ch2 = Read(); if (ch1 == '\\') { Read('`'); if (ch2 == 'n') { return(IntObj.Get('\n')); } else if (ch2 == '`') { return(IntObj.Get('`')); } else if (ch2 == 't') { return(IntObj.Get('\t')); } else if (ch2 == '\\') { return(IntObj.Get('\\')); } else { throw Fail(); } } else if (ch2 == '`') { return(IntObj.Get(ch1)); } else { Check(IsDigit(ch1) & IsDigit(ch2)); int year = 1000 * (ch1 - '0') + 100 * (ch2 - '0') + 10 * ReadDigit() + ReadDigit(); Read('-'); int month = 10 * ReadDigit() + ReadDigit(); Read('-'); int day = 10 * ReadDigit() + ReadDigit(); Check(DateTimeUtils.IsValidDate(year, month, day)); int daysSinceEpoc = DateTimeUtils.DaysSinceEpoc(year, month, day); if (TryReading('`')) { return(Builder.CreateTaggedIntObj(SymbObj.DateSymbId, daysSinceEpoc)); } Read(' '); int hours = 10 * ReadDigit() + ReadDigit(); Check(hours >= 0 & hours < 24); Read(':'); int minutes = 10 * ReadDigit() + ReadDigit(); Check(minutes >= 0 & minutes < 60); Read(':'); int seconds = 10 * ReadDigit() + ReadDigit(); Check(seconds >= 0 & minutes < 60); int nanosecs = 0; if (TryReading('.')) { int pow10 = 100000000; for (int i = 0; i < 9 && NextIsDigit(); i++) { nanosecs = nanosecs + pow10 * ReadDigit(); pow10 /= 10; } } Read('`'); long dayTimeNs = 1000000000L * (60L * (60L * hours + minutes) + seconds) + nanosecs; Check(DateTimeUtils.IsWithinRange(daysSinceEpoc, dayTimeNs)); long epocTimeNs = DateTimeUtils.EpocTimeNs(daysSinceEpoc, dayTimeNs); return(Builder.CreateTaggedIntObj(SymbObj.TimeSymbId, epocTimeNs)); } }
//////////////////////////////////////////////////////////////////////////////// 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))); }
////////////////////////////////////////////////////////////////////////////// public override Obj SurrToObjValue(int surr) { return(IntObj.Get(SurrToValue(surr))); }