private static GraceObject getByteObject(byte b) { if (byteObjects[b] == null) { byteObjects[b] = GraceNumber.Create((int)b); } return(byteObjects[b]); }
/// <summary>Native method for Grace -</summary> /// <param name="self">Receiver of the method</param> /// <param name="other">Argument to the method</param> private static GraceObject mSubtract( GraceNumber self, GraceObject other ) { var oth = other.FindNativeParent <GraceNumber>(); return(GraceNumber.Create(self.Value - oth.Value)); }
/// <summary>Native method for Grace <=</summary> /// <param name="self">Receiver of the method</param> /// <param name="other">Argument to the method</param> private static GraceObject mLessEqual( GraceNumber self, GraceObject other ) { var oth = other.FindNativeParent <GraceNumber>(); return(GraceBoolean.Create(self.Value <= oth.Value)); }
/// <summary>Native method for Grace ^</summary> /// <param name="self">Receiver of the method</param> /// <param name="other">Argument to the method</param> private static GraceObject mExponentiate( GraceNumber self, GraceObject other ) { var oth = other.FindNativeParent <GraceNumber>(); return(GraceNumber.Create(self.Value.Exponentiate(oth.Value))); }
private static GraceObject mDigit(EvaluationContext ctx, MethodRequest req, CodepointObject self) { // By convention, return -1 for non-numeric codepoints. if (self.parts[6] == "") { return(GraceNumber.Create(-1)); } return(GraceNumber.Create(int.Parse(self.parts[6]))); }
/// <summary>Native method for Grace match</summary> /// <param name="ctx">Current interpreter</param> /// <param name="self">Receiver of the method</param> /// <param name="target">Target of the match</param> private static GraceObject mMatch( EvaluationContext ctx, GraceNumber self, GraceObject target ) { if (mEqualsEquals(self, target) == GraceBoolean.True) { return(Matching.SuccessfulMatch(ctx, target)); } return(Matching.FailedMatch(ctx, target)); }
/// <summary>Native method for Grace !=</summary> /// <param name="self">Receiver of the method</param> /// <param name="other">Argument to the method</param> private static GraceObject mNotEquals( GraceNumber self, GraceObject other ) { var oth = other.FindNativeParent <GraceNumber>(); if (oth == null) { return(GraceBoolean.True); } return(GraceBoolean.Create(self.Value != oth.Value)); }
/// <summary>Native method for Grace /</summary> /// <param name="ctx">Current interpreter</param> /// <param name="self">Receiver of the method</param> /// <param name="other">Argument to the method</param> private static GraceObject mDivide( EvaluationContext ctx, GraceNumber self, GraceObject other ) { var oth = other.FindNativeParent <GraceNumber>(); if (oth.Value == Rational.Zero) { ErrorReporting.RaiseError(ctx, "R2012", new Dictionary <string, string> { { "dividend", self.Value.ToString() }, }, "ZeroDivisionError: Division by zero."); } return(GraceNumber.Create(self.Value / oth.Value)); }
/// <summary>Make a proxy for an object</summary> /// <param name="o">Object to proxy</param> public static GraceObject Create(Object o) { if (o is bool) { return(GraceBoolean.Create((dynamic)o)); } if (o is int) { return(GraceNumber.Create((dynamic)o)); } var s = o as string; if (s != null) { return(GraceString.Create(s)); } return(new GraceObjectProxy(o)); }
private static GraceObject mAt(EvaluationContext ctx, MethodRequest req, UTF32CodepointsView self) { MethodHelper.CheckArity(ctx, req, 1); var arg = req[0].Arguments[0]; var index = arg.FindNativeParent <GraceNumber>(); var idx = index.GetInt() - 1; if (idx < 0 || idx >= self.utf32.Count) { ErrorReporting.RaiseError(ctx, "R2013", new Dictionary <string, string> { { "index", "" + (idx + 1) }, { "valid", self.utf32.Count > 0 ? "1 .. " + self.utf32.Count : "none (empty)" } }, "IndexError: Index out of range"); } return(GraceNumber.Create(self.utf32[idx])); }
private static GraceObject mNumeric(EvaluationContext ctx, MethodRequest req, CodepointObject self) { // By convention, return -1 for non-numeric codepoints. if (self.parts[7] == "") { return(GraceNumber.Create(-1)); } int val; if (int.TryParse(self.parts[7], out val)) { return(GraceNumber.Create(val)); } // At this point, it must be a fraction n/m. var bits = self.parts[7].Split('/'); var rat = Rational.Create(int.Parse(bits[0]), int.Parse(bits[1])); return(GraceNumber.Create(rat)); }
/// <summary>Native method for Grace ..</summary> /// <param name="ctx">Current interpreter</param> /// <param name="self">Receiver of the method</param> /// <param name="other">Argument to the method</param> private static GraceObject mDotDot( EvaluationContext ctx, GraceNumber self, GraceObject other ) { var n = other.FindNativeParent <GraceNumber>(); if (n == null) { ErrorReporting.RaiseError(ctx, "R2001", new Dictionary <string, string> { { "method", ".." }, { "index", "1" }, { "part", ".." }, { "required", "Number" } }, "ArgumentTypeError: .. requires a Number argument" ); } return(new GraceRange(self.Value, n.Value, 1)); }
private GraceObject mDo(EvaluationContext ctx, GraceObject block) { var apply = MethodRequest.Single("apply", null); Rational v = _low; if (_step < 0) { while (v >= _high) { apply[0].Arguments[0] = GraceNumber.Create(v); block.Request(ctx, apply); v += _step; } return(GraceObject.Done); } while (v <= _high) { apply[0].Arguments[0] = GraceNumber.Create(v); block.Request(ctx, apply); v += _step; } return(GraceObject.Done); }
/// <summary>Native method for Grace numerator</summary> private static GraceObject mNumerator(GraceNumber self) { return(Create(self.Value.Numerator)); }
private static GraceObject mSize(GraceString self) { return(GraceNumber.Create(self.graphemeIndices.Length)); }
private static GraceObject mCombining(EvaluationContext ctx, MethodRequest req, CodepointObject self) { return(GraceNumber.Create(int.Parse(self.parts[2]))); }
private static GraceObject mCodepoint(EvaluationContext ctx, MethodRequest req, CodepointObject self) { return(GraceNumber.Create(self.codepoint)); }
private static GraceObject mSize(EvaluationContext ctx, MethodRequest req, StringCodepoints self) { return(GraceNumber.Create(self.utf32.Count)); }
private GraceObject mHash() { return(GraceNumber.Create(Boolean.GetHashCode())); }
/// <summary>Native method for Grace asString</summary> private static GraceObject mAsString(GraceNumber self) { return(GraceString.Create("" + self.Value)); }
/// <summary>Native method for Grace unary negation</summary> private static GraceObject mNegate(GraceNumber self) { return(GraceNumber.Create(-self.Value)); }
/// <summary>Native method for Grace integral</summary> private static GraceObject mIntegral(GraceNumber self) { return(Create(self.Value.Integral)); }
/// <summary>Native method for Grace denominator</summary> private static GraceObject mDenominator(GraceNumber self) { return(Create(self.Value.Denominator)); }
private static GraceObject mHash(GraceString self) { return(GraceNumber.Create(self.nfc.GetHashCode())); }
private static GraceObject mSize(EvaluationContext ctx, MethodRequest req, ByteString self) { return(GraceNumber.Create(self.data.Length)); }
private static GraceObject mHash(GraceNumber self) { return(GraceNumber.Create(self.Value.GetHashCode())); }