public bool DoOneInteractive(Frame topFrame) { bool continueInteraction; Stmt s = ReadStatement(out continueInteraction); if (continueInteraction == false) { return(false); } // 's' is null when we parse a line composed only of a NEWLINE (interactive_input grammar); // we don't generate anything when 's' is null if (s != null) { FrameCode code = OutputGenerator.GenerateSnippet(context, s, true); if (ExecWrapper != null) { CallTarget0 t = delegate() { try { code.Run(topFrame); } catch (Exception e) { DumpException(e); } return(null); }; object callable = new Function0(topFrame.__module__, "wrapper", t, new string[0], new object[0]); Ops.Call(ExecWrapper, callable); } else { code.Run(topFrame); } } return(true); }
public object RichEquals(object other) { object func; if (Ops.TryGetAttr(this, SymbolTable.OpEqual, out func)) { return(Ops.Call(func, other)); } if (Ops.TryGetAttr(this, SymbolTable.Cmp, out func)) { object ret = Ops.Call(func, other); if (ret is int) { return(((int)ret) == 0); } else if (ret is ExtensibleInt) { return(((ExtensibleInt)ret).value == 0); } throw Ops.TypeError("comparison did not return an int"); } object coerce = OldInstanceType.Instance.Coerce(this, other); if (coerce != Ops.NotImplemented && !(coerce is OldInstance)) { return(Ops.Equal(((Tuple)coerce)[0], ((Tuple)coerce)[1])); } return(Ops.NotImplemented); }
public override object NotEqual(object self, object other) { object func; if (PythonType.TryLookupSpecialMethod(self, SymbolTable.OpNotEqual, out func)) { object ret; if (Ops.TryCall(func, other, out ret) && ret != Ops.NotImplemented) { return(ret); } } if (PythonType.TryLookupSpecialMethod(self, SymbolTable.Cmp, out func) && func != __cmp__F) { object ret = Ops.Call(func, other); if (ret != Ops.NotImplemented) { return(Ops.CompareToZero(ret) != 0); } //if (ret is int) { // return ((int)ret) != 0; //} else if (ret is ExtensibleInt) { // return ((ExtensibleInt)ret)._value != 0; //} //throw Ops.TypeError("comparison did not return an int"); } return(Ops.NotImplemented); }
public object Call(object arg0, object arg1, object arg2, object arg3, object arg4) { PythonFunction f = func as PythonFunction; if (inst != null) { if (f != null) { return(f.Call(inst, arg0, arg1, arg2, arg3, arg4)); } return(Ops.Call(func, inst, arg0, arg1, arg2, arg3, arg4)); } else { if (!Modules.Builtin.IsInstance(arg0, DeclaringClass)) { throw BadSelf(arg0); } if (f != null) { return(f.Call(arg0, arg1, arg2, arg3, arg4)); } return(Ops.Call(func, arg0, arg1, arg2, arg3, arg4)); } }
public object CompareTo(object other) { IDictionary <object, object> oth = other as IDictionary <object, object>; // CompareTo is allowed to throw (string, int, etc... all do it if they don't get a matching type) if (oth == null) { object len, iteritems; if (!Ops.TryGetAttr(other, SymbolTable.Length, out len) || !Ops.TryGetAttr(other, SymbolTable.StringToId("iteritems"), out iteritems)) { return(Ops.NotImplemented); } // user-defined dictionary... int lcnt = this.Count; int rcnt = Converter.ConvertToInt32(Ops.Call(len)); if (lcnt != rcnt) { return(lcnt > rcnt ? 1 : -1); } return(DictOps.CompareToWorker(this, rcnt, new List(Ops.Call(iteritems)))); } return(DictOps.CompareTo(this, oth)); }
public static object Reversed(object o) { object reversed; if (Ops.TryGetAttr(o, SymbolTable.Reversed, out reversed)) { return(Ops.Call(reversed)); } object getitem; object len; //!!! OldClass check: we currently are in a strange state where we partially support // descriptors on old-style classes, although we're not supposed to. We special // case it here until that's fixed. if (o is OldClass || !Ops.TryGetAttr(o, SymbolTable.GetItem, out getitem) || !Ops.TryGetAttr(o, SymbolTable.Length, out len) || o is Dict) { throw Ops.TypeError("argument to reversed() must be a sequence"); } object length = Ops.Call(len); if (!(length is int)) { throw Ops.ValueError("__len__ must return int"); } return(new ReversedEnumerator(o, (int)length, getitem)); }
public bool TryGetAttr(ICallerContext context, SymbolId name, out object value) { if (name.Id == SymbolTable.DictId) { //!!! user code can modify __del__ property of __dict__ behind our back value = __dict__; return(true); } else if (name.Id == SymbolTable.Class.Id) { value = __class__; return(true); } if (TryRawGetAttr(name, out value)) { return(true); } if (name.Id != SymbolTable.GetAttrId) { object getattr; if (TryRawGetAttr(SymbolTable.GetAttr, out getattr)) { value = Ops.Call(getattr, SymbolTable.IdToString(name)); return(true); } } return(false); }
public object ToPythonException() { DynamicType exType = ExceptionConverter.GetPythonExceptionByName(PythonExceptionName); object inst = Ops.Call(exType); Ops.SetAttr(DefaultContext.Default, inst, SymbolTable.ExceptionMessage, base.Message); Ops.SetAttr(DefaultContext.Default, inst, SymbolTable.Arguments, Tuple.MakeTuple( base.Message, Tuple.MakeTuple( file, lineNo, columnNo == 0 ? null : (object)columnNo, lineText ) )); Ops.SetAttr(DefaultContext.Default, inst, SymbolTable.ExceptionFilename, file); Ops.SetAttr(DefaultContext.Default, inst, SymbolTable.ExceptionLineNumber, lineNo); if (columnNo != 0) { Ops.SetAttr(DefaultContext.Default, inst, SymbolTable.ExceptionOffset, columnNo); } else { Ops.SetAttr(DefaultContext.Default, inst, SymbolTable.ExceptionOffset, null); } Ops.SetAttr(DefaultContext.Default, inst, SymbolTable.Text, lineText); // print_file_and_line return(inst); }
public object Call(params object[] args) { if (func == null) { throw Ops.AttributeError("{0} not defined on instance of {1}", name, pythonType.__name__); } return(Ops.Call(func, args)); }
static bool ShouldYield(object predicate, object current) { if (predicate == null) { return(!Ops.IsTrue(current)); } return(!Ops.IsTrue(Ops.Call(predicate, current))); }
static object GetKey(object val, object keyFunc) { if (keyFunc == null) { return(val); } return(Ops.Call(keyFunc, val)); }
// *** BEGIN GENERATED CODE *** public object Call() { if (inst != null) { return(Ops.Call(func, inst)); } throw BadSelf(null); }
private static object TryCoerce(object x, object y) { object func; if (Ops.TryGetAttr(x, SymbolTable.Coerce, out func)) { return(Ops.Call(func, y)); } return(null); }
public override object Power(object self, object other) { object func; if (Ops.TryGetAttr(self, SymbolTable.OpPower, out func)) { return(Ops.Call(func, other)); } return(Ops.NotImplemented); }
public override object InPlaceSubtract(object self, object other) { object func; if (Ops.TryGetAttr(self, SymbolTable.OpInPlaceSubtract, out func)) { return(Ops.Call(func, other)); } return(Ops.NotImplemented); }
public override object LessThanOrEqual(object self, object other) { object func; if (Ops.TryGetAttr(self, SymbolTable.OpLessThanOrEqual, out func)) { return(Ops.Call(func, other)); } return(Ops.NotImplemented); }
public static object NewMethod(object type, params object[] prms) { if (type == InstanceOfNoneType) { throw Ops.TypeError("cannot create instances of 'NoneType'"); } // someone is using None.__new__ or type(None).__new__ to create // a new instance. Call the type they want to create the instance for. return(Ops.Call(type, prms)); }
public object RichGetHashCode() { object func; if (Ops.TryGetAttr(this, SymbolTable.Hash, out func)) { return(Ops.ConvertTo(Ops.Call(func), typeof(int))); } return(Ops.NotImplemented); }
public override object ReverseBitwiseAnd(object self, object other) { object func; if (Ops.TryGetAttr(self, SymbolTable.OpReverseBitwiseAnd, out func)) { return(Ops.Call(func, other)); } return(Ops.NotImplemented); }
public override object OnesComplement(object self) { object func; if (Ops.TryGetAttr(self, SymbolTable.OpOnesComplement, out func)) { return(Ops.Call(func)); } return(Ops.NotImplemented); }
private object InternalCompare(SymbolId cmp, object other) { object meth; if (TryGetAttr(DefaultContext.Default, cmp, out meth)) { return(Ops.Call(meth, other)); } return(Ops.NotImplemented); }
public object Call(params object[] args) { object o; if (instance.TryGetAttr(DefaultContext.Default, SymbolTable.Unassign, out o)) { Ops.Call(o); } return(null); }
public override object GreaterThanOrEqual(object self, object other) { object func; if (Ops.TryGetAttr(self, SymbolTable.OpGreaterThanOrEqual, out func)) { return(Ops.Call(func, other)); } return(base.GreaterThanOrEqual(self, other)); }
public override object Coerce(object self, object other) { object meth; if (Ops.TryGetAttr(DefaultContext.Default, self, SymbolTable.Coerce, out meth)) { return(Ops.Call(meth, other)); } return(Ops.NotImplemented); }
public override object LessThan(object self, object other) { object func; if (Ops.TryGetAttr(self, SymbolTable.OpLessThan, out func)) { return(Ops.Call(func, other)); } return(base.LessThan(self, other)); }
IEnumerator <object> Yielder(object predicate, IEnumerator iter) { while (MoveNextHelper(iter)) { if (!Ops.IsTrue(Ops.Call(predicate, iter.Current))) { break; } yield return(iter.Current); } }
public static object Reduce(object func, object seq, object initializer) { IEnumerator i = Ops.GetEnumerator(seq); object ret = initializer; while (i.MoveNext()) { ret = Ops.Call(func, ret, i.Current); } return(ret); }
public int Compare(object o1, object o2) { object res = Ops.Call(cmpfunc, o1, o2); if (res is int) { return((int)res); } return(Converter.ConvertToInt32(res)); }
public virtual object Call(object func, params object[] args) { object call; if (Ops.TryGetAttr(func, SymbolTable.Call, out call)) { return(Ops.Call(call, args)); } throw Ops.TypeError("{0} object is not callable", Ops.GetDynamicType(func).__name__); }
public override object CompareTo(object self, object other) { object func; if (PythonType.TryLookupSpecialMethod(self, SymbolTable.Cmp, out func)) { return(Ops.Call(func, other)); } return(Ops.NotImplemented); }