4 #define PERL_NO_GET_CONTEXT
11 #define MOP_CALL_BOOT(name) mop_call_xs(aTHX_ name, cv, mark);
14 #define XSPROTO(name) XS(name)
17 void mop_call_xs (pTHX_ XSPROTO(subaddr), CV *cv, SV **mark);
20 #define MAKE_KEYSV(name) newSVpvn_share(#name, sizeof(#name)-1, 0U)
22 XS(mop_xs_simple_accessor);
23 XS(mop_xs_simple_reader);
24 XS(mop_xs_simple_writer);
25 XS(mop_xs_simple_predicate);
26 XS(mop_xs_simple_predicate_for_metaclass);
27 XS(mop_xs_simple_clearer);
29 extern SV *mop_method_metaclass;
30 extern SV *mop_associated_metaclass;
31 extern SV *mop_associated_attribute;
33 extern SV *mop_methods;
36 extern SV *mop_package;
37 extern SV *mop_package_name;
38 extern SV *mop_package_cache_flag;
39 extern SV *mop_initialize;
42 extern SV *mop_VERSION;
47 UV mop_check_package_cache_flag(pTHX_ HV *stash);
48 int mop_get_code_info (SV *coderef, char **pkg, char **name);
49 SV *mop_call0(pTHX_ SV *const self, SV *const method);
50 SV *mop_call1(pTHX_ SV *const self, SV *const method, SV *const arg1);
52 #define mop_call0_pvs(o, m) mop_call0(aTHX_ o, newSVpvs_flags(m, SVs_TEMP))
53 #define mop_call1_pvs(o, m, a) mop_call1(aTHX_ o, newSVpvs_flags(m, SVs_TEMP), a)
55 bool mop_is_class_loaded(pTHX_ SV*);
56 #define is_class_loaded(klass) mop_is_class_loaded(aTHX_ klass)
58 bool mop_is_instance_of(pTHX_ SV*, SV*);
59 #define is_instance_of(sv, klass) mop_is_instance_of(aTHX_ sv, klass)
60 #define is_instance_of_pvs(sv, klass) mop_is_instance_of(aTHX_ sv, newSVpvs_flags(klass, SVs_TEMP))
71 typedef bool (*get_package_symbols_cb_t) (const char *, STRLEN, SV *, void *);
73 void mop_get_package_symbols(HV *stash, type_filter_t filter, get_package_symbols_cb_t cb, void *ud);
74 HV *mop_get_all_package_symbols (HV *stash, type_filter_t filter);
77 #define MOPf_DIE_ON_FAIL 0x01
78 MAGIC* mop_mg_find(pTHX_ SV* const sv, const MGVTBL* const vtbl, I32 const flags);
81 #define MOP_av_at(av, ix) *mop_av_at_safe(aTHX_ (av) , (ix))
82 SV** mop_av_at_safe(pTHX_ AV* const mi, I32 const ix);
84 #define MOP_av_at(av, ix) AvARRAY(av)[ix]
87 #define IsObject(sv) (SvROK(sv) && SvOBJECT(SvRV(sv)))
89 #define newSVsv_share(sv) mop_newSVsv_share(aTHX_ sv)
90 SV* mop_newSVsv_share(pTHX_ SV*);
92 SV* mop_class_of(pTHX_ SV* const sv);
95 /* Class::MOP Magic stuff */
97 /* All the MOP_mg_* macros require MAGIC* mg for the first argument */
100 SV* (*create_instance)(pTHX_ HV* const stash);
101 bool (*has_slot) (pTHX_ SV* const mi, SV* const instance);
102 SV* (*get_slot) (pTHX_ SV* const mi, SV* const instance);
103 SV* (*set_slot) (pTHX_ SV* const mi, SV* const instance, SV* const value);
104 SV* (*delete_slot) (pTHX_ SV* const mi, SV* const instance);
105 void (*weaken_slot) (pTHX_ SV* const mi, SV* const instance);
108 /* Class::MOP::Instance stuff */
110 SV* mop_instance_create (pTHX_ HV* const stash);
111 SV* mop_instance_slot (pTHX_ SV* const meta_instance, SV* const attr);
112 bool mop_instance_has_slot (pTHX_ SV* const instance, SV* const slot);
113 SV* mop_instance_get_slot (pTHX_ SV* const instance, SV* const slot);
114 SV* mop_instance_set_slot (pTHX_ SV* const instance, SV* const slot, SV* const value);
115 SV* mop_instance_delete_slot(pTHX_ SV* const instance, SV* const slot);
116 void mop_instance_weaken_slot(pTHX_ SV* const instance, SV* const slot);
118 const mop_instance_vtbl* mop_get_default_instance_vtbl(pTHX);
120 #define MOP_mg_obj(mg) ((mg)->mg_obj)
121 #define MOP_mg_ptr(mg) ((mg)->mg_ptr)
122 #define MOP_mg_vtbl(mg) ((const mop_instance_vtbl*)MOP_mg_ptr(mg))
123 #define MOP_mg_flags(mg) ((mg)->mg_private)
124 #define MOP_mg_virtual(mg) ((mg)->mg_virtual)
126 #define MOP_mg_obj_refcounted_on(mg) (void)((mg)->mg_flags |= MGf_REFCOUNTED);
128 #define MOP_mg_create_instance(mg, stash) MOP_mg_vtbl(mg)->create_instance (aTHX_ (stash))
129 #define MOP_mg_has_slot(mg, o, slot) MOP_mg_vtbl(mg)->has_slot (aTHX_ (o), (slot))
130 #define MOP_mg_get_slot(mg, o, slot) MOP_mg_vtbl(mg)->get_slot (aTHX_ (o), (slot))
131 #define MOP_mg_set_slot(mg, o, slot, v) MOP_mg_vtbl(mg)->set_slot (aTHX_ (o), (slot), (v))
132 #define MOP_mg_delete_slot(mg, o, slot) MOP_mg_vtbl(mg)->delete_slot (aTHX_ (o), (slot))
133 #define MOP_mg_weaken_slot(mg, o, slot) MOP_mg_vtbl(mg)->weaken_slot (aTHX_ (o), (slot))
135 /* Class::MOP::Attribute stuff */
137 MAGIC* mop_attr_get_mg(pTHX_ SV* const attr);
139 /* Class::MOP::Method::Accessor stuff */
141 #define dMOP_self SV* const self = mop_accessor_get_self(aTHX_ ax, items, cv)
142 #define dMOP_mg(xsub) MAGIC* mg = (MAGIC*)CvXSUBANY(xsub).any_ptr
143 #define dMOP_METHOD_COMMON dMOP_self; dMOP_mg(cv)
146 SV* mop_accessor_get_self(pTHX_ I32 const ax, I32 const items, CV* const cv);
147 MAGIC* mop_attr_get_mg(pTHX_ SV* const attr);
149 CV* mop_install_accessor(pTHX_ const char* const fq_name, const char* const key, I32 const keylen, XSUBADDR_t const accessor_impl, const mop_instance_vtbl* vtbl);
150 CV* mop_instantiate_xs_accessor(pTHX_ SV* const accessor, XSUBADDR_t const accessor_impl, mop_instance_vtbl* const vtbl);
152 #define INSTALL_SIMPLE_READER(klass, name) INSTALL_SIMPLE_READER_WITH_KEY(klass, name, name)
153 #define INSTALL_SIMPLE_READER_WITH_KEY(klass, name, key) (void)mop_install_accessor(aTHX_ "Class::MOP::" #klass "::" #name, #key, sizeof(#key)-1, mop_xs_simple_reader, NULL)
155 #define INSTALL_SIMPLE_WRITER(klass, name) INSTALL_SIMPLE_WRITER_WITH_KEY(klass, name, name)
156 #define INSTALL_SIMPLE_WRITER_WITH_KEY(klass, name, key) (void)mop_install_accessor(aTHX_ "Class::MOP::" #klass "::" #name, #key, sizeof(#key)-1, mop_xs_simple_writer, NULL)
158 #define INSTALL_SIMPLE_PREDICATE(klass, name) INSTALL_SIMPLE_PREDICATE_WITH_KEY(klass, name, name)
159 #define INSTALL_SIMPLE_PREDICATE_WITH_KEY(klass, name, key) (void)mop_install_accessor(aTHX_ "Class::MOP::" #klass "::has_" #name, #key, sizeof(#key)-1, mop_xs_simple_predicate_for_metaclass, NULL)