ActualiseArbitraryObject(IntPtr ptr) { IntPtr typePtr = CPyMarshal.ReadPtrField(ptr, typeof(PyObject), "ob_type"); PythonType type_ = (PythonType)this.Retrieve(typePtr); object[] args = new object[] {}; if (Builtin.issubclass(this.scratchContext, type_, TypeCache.Int32)) { args = new object[] { CPyMarshal.ReadIntField(ptr, typeof(PyIntObject), "ob_ival") }; } if (Builtin.issubclass(this.scratchContext, type_, TypeCache.Double)) { args = new object[] { CPyMarshal.ReadDoubleField(ptr, typeof(PyFloatObject), "ob_fval") }; } if (Builtin.issubclass(this.scratchContext, type_, TypeCache.String)) { args = new object[] { this.ReadPyString(ptr) }; } if (Builtin.issubclass(this.scratchContext, type_, TypeCache.PythonType)) { string name = CPyMarshal.ReadCStringField(ptr, typeof(PyTypeObject), "tp_name"); PythonTuple tp_bases = this.ExtractBases(typePtr); args = new object[] { name, tp_bases, new PythonDictionary() }; } object obj = PythonCalls.Call(this.classStubs[typePtr], args); Builtin.setattr(this.scratchContext, obj, "__class__", type_); this.StoreBridge(ptr, obj); this.IncRef(ptr); GC.KeepAlive(obj); // TODO: please test me, if you can work out how to }
InitialiseScope() { this.tp_name = CPyMarshal.ReadCStringField(this.ptr, typeof(PyTypeObject), "tp_name"); CallableBuilder.ExtractNameModule(this.tp_name, ref this.__name__, ref this.__module__); this.tablePrefix = this.__name__ + "."; this.code.Append("_ironclad_class_attrs = dict()"); }
GenerateClass() { string __doc__ = CPyMarshal.ReadCStringField(this.ptr, typeof(PyTypeObject), "tp_doc").Replace("\\", "\\\\"); this.code.Append(String.Format(CodeSnippets.CLASS_TEMPLATE, this.__name__, this.__module__, __doc__)); this.ConnectTypeField("tp_new", typeof(dgt_ptr_ptrptrptr)); }
AttemptToMap(IntPtr ptr) { if (this.HasPtr(ptr)) { return; } if (ptr == IntPtr.Zero) { throw new CannotInterpretException("cannot map IntPtr.Zero"); } IntPtr typePtr = CPyMarshal.ReadPtrField(ptr, typeof(PyTypeObject), "ob_type"); this.AttemptToMap(typePtr); if (!this.actualisableTypes.ContainsKey(typePtr)) { string msg = "cannot map object at {0} with type at {1} ({2})"; string type_ = CPyMarshal.ReadCStringField(typePtr, typeof(PyTypeObject), "tp_name"); throw new CannotInterpretException(String.Format(msg, ptr.ToString("x"), typePtr.ToString("x"), type_)); } this.actualisableTypes[typePtr](ptr); }