public static object MatchIndex(RubyScope /*!*/ scope, RubyRegex /*!*/ self, [DefaultProtocol] MutableString /*!*/ str) { MatchData match = RubyRegex.SetCurrentMatchData(scope, self, str); return((match != null) ? ScriptingRuntimeHelpers.Int32ToObject(match.Index) : null); }
protected override object Calculate(object l, object r) { return(ScriptingRuntimeHelpers.Int32ToObject(unchecked ((Int32)l % (Int32)r))); }
private static object FastNew(CodeContext /*!*/ context, object o, int @base = 10) { Extensible <BigInteger> el; if (o is string) { return(__new__(null, (string)o, @base)); } if (o is double) { return(DoubleOps.__int__((double)o)); } if (o is int) { return(o); } if (o is bool) { return(((bool)o) ? 1 : 0); } if (o is BigInteger) { int res; if (((BigInteger)o).AsInt32(out res)) { return(ScriptingRuntimeHelpers.Int32ToObject(res)); } return(o); } if ((el = o as Extensible <BigInteger>) != null) { int res; if (el.Value.AsInt32(out res)) { return(ScriptingRuntimeHelpers.Int32ToObject(res)); } return(el.Value); } if (o is float) { return(DoubleOps.__int__((double)(float)o)); } if (o is Complex) { throw PythonOps.TypeError("can't convert complex to int; use int(abs(z))"); } if (o is Int64) { Int64 val = (Int64)o; if (Int32.MinValue <= val && val <= Int32.MaxValue) { return((Int32)val); } else { return((BigInteger)val); } } else if (o is UInt32) { UInt32 val = (UInt32)o; if (val <= Int32.MaxValue) { return((Int32)val); } else { return((BigInteger)val); } } else if (o is UInt64) { UInt64 val = (UInt64)o; if (val <= Int32.MaxValue) { return((Int32)val); } else { return((BigInteger)val); } } else if (o is Decimal) { Decimal val = (Decimal)o; if (Int32.MinValue <= val && val <= Int32.MaxValue) { return((Int32)val); } else { return((BigInteger)val); } } else if (o is Enum) { return(((IConvertible)o).ToInt32(null)); } if (o is Extensible <string> es) { // __int__ takes precedence, call it if it's available... object value; if (PythonTypeOps.TryInvokeUnaryOperator(DefaultContext.Default, es, "__int__", out value)) { return(value); } // otherwise call __new__ on the string value return(__new__(null, es.Value, @base)); } object result; int intRes; BigInteger bigintRes; if (PythonTypeOps.TryInvokeUnaryOperator(context, o, "__int__", out result) && !Object.ReferenceEquals(result, NotImplementedType.Value)) { if (result is int || result is BigInteger || result is Extensible <int> || result is Extensible <BigInteger> ) { return(result); } else { throw PythonOps.TypeError("__int__ returned non-Integral (type {0})", PythonTypeOps.GetName(result)); } } else if (PythonOps.TryGetBoundAttr(context, o, "__trunc__", out result)) { result = PythonOps.CallWithContext(context, result); if (result is int || result is BigInteger || result is Extensible <int> || result is Extensible <BigInteger> ) { return(result); } else if (Converter.TryConvertToInt32(result, out intRes)) { return(intRes); } else if (Converter.TryConvertToBigInteger(result, out bigintRes)) { return(bigintRes); } else { throw PythonOps.TypeError("__trunc__ returned non-Integral (type {0})", PythonTypeOps.GetName(result)); } } throw PythonOps.TypeError("int() argument must be a string or a number, not '{0}'", PythonTypeOps.GetName(o)); }
public void Push(int value) { Data[StackIndex++] = ScriptingRuntimeHelpers.Int32ToObject(value); }
public static object End(MatchData /*!*/ self, [DefaultProtocol] int groupIndex) { self.RequireExistingGroup(groupIndex); return(self.GroupSuccess(groupIndex) ? ScriptingRuntimeHelpers.Int32ToObject(self.GetGroupEnd(groupIndex)) : null); }
private static object GetIntReturn(int value) { return(ScriptingRuntimeHelpers.Int32ToObject((int)value)); }
public Enumerate(object iter) { _iter = PythonOps.GetEnumerator(iter); _index = ScriptingRuntimeHelpers.Int32ToObject(-1); }
public Enumerate(CodeContext context, object iter, object start) { object index; if (!Converter.TryConvertToIndex(start, out index)) { throw PythonOps.TypeErrorForUnIndexableObject(start); } _iter = PythonOps.GetEnumerator(iter); _index = context.LanguageContext.Operation(Binding.PythonOperationKind.Subtract, index, ScriptingRuntimeHelpers.Int32ToObject(1)); }
public object /*!*/ ToObject() { return((object)_bignum ?? ScriptingRuntimeHelpers.Int32ToObject(_fixnum)); }
public static object End(MatchData /*!*/ self, [DefaultProtocol] int groupIndex) { var group = self.GetExistingGroup(groupIndex); return(group.Success ? ScriptingRuntimeHelpers.Int32ToObject(group.Index + group.Length) : null); }
public static Literal /*!*/ Integer(int value, SourceSpan location) { return(new Literal(ScriptingRuntimeHelpers.Int32ToObject(value), location)); }
public static object Getc(RubyIO /*!*/ self) { int c = self.ReadByteNormalizeEoln(); return((c != -1) ? ScriptingRuntimeHelpers.Int32ToObject(c) : null); }
private static object CharmapDecodeWorker(string input, string errors, IDictionary <object, object> map, bool isDecode) { if (input.Length == 0) { return(PythonTuple.MakeTuple(String.Empty, 0)); } StringBuilder res = new StringBuilder(); for (int i = 0; i < input.Length; i++) { object val; if (map == null) { res.Append(input[i]); continue; } object charObj = ScriptingRuntimeHelpers.Int32ToObject((int)input[i]); if (!map.TryGetValue(charObj, out val)) { if (errors == "strict" && isDecode) { throw PythonOps.UnicodeDecodeError("failed to find key in mapping"); } else if (!isDecode) { throw PythonOps.UnicodeEncodeError("failed to find key in mapping"); } res.Append("\ufffd"); } else if (val == null) { if (errors == "strict" && isDecode) { throw PythonOps.UnicodeDecodeError("'charmap' codec can't decode characters at index {0} because charmap maps to None", i); } else if (!isDecode) { throw PythonOps.UnicodeEncodeError("charmap", input[i], i, "'charmap' codec can't encode characters at index {0} because charmap maps to None", i); } res.Append("\ufffd"); } else if (val is string) { res.Append((string)val); } else if (val is int) { res.Append((char)(int)val); } else { throw PythonOps.TypeError("charmap must be an int, str, or None"); } } return(PythonTuple.MakeTuple(res.ToString(), res.Length)); }