Example #1
0
void setupDescr() {
    property_cls->instances_are_nonzero = true;

    property_cls->giveAttr(
        "__init__",
        new BoxedFunction(BoxedCode::create((void*)propertyInit, UNKNOWN, 5, false, false, "property.__init__", "",
                                            ParamNames({ "", "fget", "fset", "fdel", "doc" }, "", "")),
                          { Py_None, Py_None, Py_None, NULL }));
    property_cls->giveAttr("__get__",
                           new BoxedFunction(BoxedCode::create((void*)propertyGet, UNKNOWN, 3, "property.__get__", "",
                                                               ParamNames({ "self", "obj", "type" }, "", ""))));
    property_cls->giveAttr("__set__",
                           new BoxedFunction(BoxedCode::create((void*)propertySet, UNKNOWN, 3, "property.__set__", "",
                                                               ParamNames({ "self", "obj", "value" }, "", ""))));
    property_cls->giveAttr("__delete__",
                           new BoxedFunction(BoxedCode::create((void*)propertyDel, UNKNOWN, 2, "property.__delete__",
                                                               "", ParamNames({ "self", "obj" }, "", ""))));
    property_cls->giveAttr("getter",
                           new BoxedFunction(BoxedCode::create((void*)propertyGetter, UNKNOWN, 2, "property.getter")));
    property_cls->giveAttr("setter",
                           new BoxedFunction(BoxedCode::create((void*)propertySetter, UNKNOWN, 2, "property.setter")));
    property_cls->giveAttr(
        "deleter", new BoxedFunction(BoxedCode::create((void*)propertyDeleter, UNKNOWN, 2, "property.deleter")));
    property_cls->giveAttrMember("fget", T_OBJECT, offsetof(BoxedProperty, prop_get));
    property_cls->giveAttrMember("fset", T_OBJECT, offsetof(BoxedProperty, prop_set));
    property_cls->giveAttrMember("fdel", T_OBJECT, offsetof(BoxedProperty, prop_del));
    property_cls->giveAttrMember("__doc__", T_OBJECT, offsetof(BoxedProperty, prop_doc));
    property_cls->freeze();

    staticmethod_cls->giveAttrMember("__func__", T_OBJECT, offsetof(BoxedStaticmethod, sm_callable));
    staticmethod_cls->giveAttr("__init__", new BoxedFunction(BoxedCode::create((void*)staticmethodInit, UNKNOWN, 5,
                                                                               false, false, "staticmethod.__init__"),
                                                             { Py_None, Py_None, Py_None, Py_None }));
    staticmethod_cls->giveAttr("__get__", new BoxedFunction(BoxedCode::create((void*)staticmethodGet, UNKNOWN, 3, false,
                                                                              false, "staticmethod.__get__"),
                                                            { Py_None }));
    staticmethod_cls->freeze();


    classmethod_cls->giveAttrMember("__func__", T_OBJECT, offsetof(BoxedClassmethod, cm_callable));
    classmethod_cls->giveAttr("__init__", new BoxedFunction(BoxedCode::create((void*)classmethodInit, UNKNOWN, 5, false,
                                                                              false, "classmethod.__init__"),
                                                            { Py_None, Py_None, Py_None, Py_None }));
    classmethod_cls->giveAttr("__get__", new BoxedFunction(BoxedCode::create((void*)classmethodGet, UNKNOWN, 3, false,
                                                                             false, "classmethod.__get__"),
                                                           { Py_None }));
    classmethod_cls->freeze();

    PyType_Ready(&PyGetSetDescr_Type);
    PyType_Ready(&PyMemberDescr_Type);

    wrappertype.tpp_call.capi_val = wrapperObjectTppCall<CAPI>;
    wrappertype.tpp_call.cxx_val = wrapperObjectTppCall<CXX>;
    wrappertype.tp_call = proxyToTppCall;
    PyType_Ready(&wrappertype);

    PyWrapperDescr_Type.tpp_call.capi_val = wrapperDescrTppCall<CAPI>;
    PyWrapperDescr_Type.tpp_call.cxx_val = wrapperDescrTppCall<CXX>;
    PyWrapperDescr_Type.tp_call = proxyToTppCall;
    PyType_Ready(&PyWrapperDescr_Type);

    PyMethodDescr_Type.tpp_call.capi_val = methodDescrTppCall<CAPI>;
    PyMethodDescr_Type.tpp_call.cxx_val = methodDescrTppCall<CXX>;
    PyMethodDescr_Type.tp_call = proxyToTppCall;
    PyType_Ready(&PyMethodDescr_Type);

    PyClassMethodDescr_Type.tpp_call.capi_val = methodDescrTppCall<CAPI>;
    PyClassMethodDescr_Type.tpp_call.cxx_val = methodDescrTppCall<CXX>;
    PyClassMethodDescr_Type.tp_call = proxyToTppCall;
    PyType_Ready(&PyClassMethodDescr_Type);
}
Example #2
0
void setupDescr() {
    member_descriptor_cls->giveAttr("__get__", new BoxedFunction(boxRTFunction((void*)memberGet, UNKNOWN, 3)));
    member_descriptor_cls->freeze();

    property_cls->giveAttr("__init__",
                           new BoxedFunction(boxRTFunction((void*)propertyInit, UNKNOWN, 5, 4, false, false,
                                                           ParamNames({ "", "fget", "fset", "fdel", "doc" }, "", "")),
                                             { NULL, NULL, NULL, NULL }));
    property_cls->giveAttr("__get__", new BoxedFunction(boxRTFunction((void*)propertyGet, UNKNOWN, 3)));
    property_cls->giveAttr("__set__", new BoxedFunction(boxRTFunction((void*)propertySet, UNKNOWN, 3)));
    property_cls->giveAttr("__delete__", new BoxedFunction(boxRTFunction((void*)propertyDel, UNKNOWN, 2)));
    property_cls->giveAttr("getter", new BoxedFunction(boxRTFunction((void*)propertyGetter, UNKNOWN, 2)));
    property_cls->giveAttr("setter", new BoxedFunction(boxRTFunction((void*)propertySetter, UNKNOWN, 2)));
    property_cls->giveAttr("deleter", new BoxedFunction(boxRTFunction((void*)propertyDeleter, UNKNOWN, 2)));
    property_cls->giveAttr("fget",
                           new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT, offsetof(BoxedProperty, prop_get)));
    property_cls->giveAttr("fset",
                           new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT, offsetof(BoxedProperty, prop_set)));
    property_cls->giveAttr("fdel",
                           new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT, offsetof(BoxedProperty, prop_del)));
    property_cls->giveAttr("__doc__",
                           new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT, offsetof(BoxedProperty, prop_doc)));
    property_cls->freeze();

    staticmethod_cls->giveAttr("__init__",
                               new BoxedFunction(boxRTFunction((void*)staticmethodInit, UNKNOWN, 5, 4, false, false),
                                                 { None, None, None, None }));
    staticmethod_cls->giveAttr(
        "__get__", new BoxedFunction(boxRTFunction((void*)staticmethodGet, UNKNOWN, 3, 1, false, false), { None }));
    staticmethod_cls->freeze();


    classmethod_cls->giveAttr("__init__",
                              new BoxedFunction(boxRTFunction((void*)classmethodInit, UNKNOWN, 5, 4, false, false),
                                                { None, None, None, None }));
    classmethod_cls->giveAttr(
        "__get__", new BoxedFunction(boxRTFunction((void*)classmethodGet, UNKNOWN, 3, 1, false, false), { None }));
    classmethod_cls->freeze();

    method_cls->giveAttr("__get__",
                         new BoxedFunction(boxRTFunction((void*)BoxedMethodDescriptor::__get__, UNKNOWN, 3)));
    CLFunction* method_call_cl = boxRTFunction((void*)BoxedMethodDescriptor::__call__, UNKNOWN, 2, 0, true, true);
    method_cls->giveAttr("__call__", new BoxedFunction(method_call_cl));
    method_cls->tpp_call = BoxedMethodDescriptor::tppCall;
    method_cls->giveAttr("__doc__", new (pyston_getset_cls) BoxedGetsetDescriptor(methodGetDoc, NULL, NULL));
    method_cls->freeze();

    wrapperdescr_cls->giveAttr("__get__",
                               new BoxedFunction(boxRTFunction((void*)BoxedWrapperDescriptor::__get__, UNKNOWN, 3)));
    wrapperdescr_cls->giveAttr("__call__", new BoxedFunction(boxRTFunction((void*)BoxedWrapperDescriptor::__call__,
                                                                           UNKNOWN, 2, 0, true, true)));
    wrapperdescr_cls->giveAttr("__doc__",
                               new (pyston_getset_cls) BoxedGetsetDescriptor(wrapperdescrGetDoc, NULL, NULL));
    wrapperdescr_cls->freeze();
    wrapperdescr_cls->tp_descr_get = BoxedWrapperDescriptor::descr_get;

    wrapperobject_cls->giveAttr(
        "__call__", new BoxedFunction(boxRTFunction((void*)BoxedWrapperObject::__call__, UNKNOWN, 1, 0, true, true)));
    wrapperobject_cls->tpp_call = BoxedWrapperObject::tppCall;
    wrapperobject_cls->freeze();
}