Commit | Line | Data |
d846ade3 |
1 | #ifndef __MOP_H__ |
2 | #define __MOP_H__ |
3 | |
e989c0df |
4 | #define PERL_NO_GET_CONTEXT |
d846ade3 |
5 | #include "EXTERN.h" |
6 | #include "perl.h" |
7 | #include "XSUB.h" |
8 | |
d846ade3 |
9 | #include "ppport.h" |
10 | |
25bcd95c |
11 | #define MOP_CALL_BOOT(name) mop_call_xs(aTHX_ name, cv, mark); |
d846ade3 |
12 | |
c97ec1de |
13 | #ifndef XSPROTO |
14 | #define XSPROTO(name) XS(name) |
15 | #endif |
16 | |
1be56175 |
17 | void mop_call_xs (pTHX_ XSPROTO(subaddr), CV *cv, SV **mark); |
d846ade3 |
18 | |
1bc0cb6b |
19 | |
20 | #define MAKE_KEYSV(name) newSVpvn_share(#name, sizeof(#name)-1, 0U) |
21 | |
206860b8 |
22 | XS(mop_xs_simple_accessor); |
7ec7b950 |
23 | XS(mop_xs_simple_reader); |
206860b8 |
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); |
7ec7b950 |
28 | |
e1f52a8a |
29 | extern SV *mop_method_metaclass; |
30 | extern SV *mop_associated_metaclass; |
daf9799b |
31 | extern SV *mop_associated_attribute; |
e1f52a8a |
32 | extern SV *mop_wrap; |
1bc0cb6b |
33 | extern SV *mop_methods; |
34 | extern SV *mop_name; |
35 | extern SV *mop_body; |
36 | extern SV *mop_package; |
37 | extern SV *mop_package_name; |
38 | extern SV *mop_package_cache_flag; |
87cfe982 |
39 | extern SV *mop_initialize; |
40 | extern SV *mop_can; |
41 | extern SV *mop_Class; |
1bc0cb6b |
42 | extern SV *mop_VERSION; |
43 | extern SV *mop_ISA; |
d846ade3 |
44 | |
5bd0f967 |
45 | /* MOP utilities */ |
46 | |
d846ade3 |
47 | UV mop_check_package_cache_flag(pTHX_ HV *stash); |
e1f52a8a |
48 | int mop_get_code_info (SV *coderef, char **pkg, char **name); |
d846ade3 |
49 | SV *mop_call0(pTHX_ SV *const self, SV *const method); |
e989c0df |
50 | SV *mop_call1(pTHX_ SV *const self, SV *const method, SV *const arg1); |
51 | |
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) |
54 | |
eaca1141 |
55 | bool mop_is_class_loaded(pTHX_ SV*); |
56 | #define is_class_loaded(klass) mop_is_class_loaded(aTHX_ klass) |
d846ade3 |
57 | |
00370481 |
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)) |
61 | |
d846ade3 |
62 | typedef enum { |
63 | TYPE_FILTER_NONE, |
64 | TYPE_FILTER_CODE, |
65 | TYPE_FILTER_ARRAY, |
66 | TYPE_FILTER_IO, |
67 | TYPE_FILTER_HASH, |
68 | TYPE_FILTER_SCALAR, |
69 | } type_filter_t; |
70 | |
71 | typedef bool (*get_package_symbols_cb_t) (const char *, STRLEN, SV *, void *); |
72 | |
e1f52a8a |
73 | void mop_get_package_symbols(HV *stash, type_filter_t filter, get_package_symbols_cb_t cb, void *ud); |
e989c0df |
74 | HV *mop_get_all_package_symbols (HV *stash, type_filter_t filter); |
75 | |
76 | |
5bd0f967 |
77 | #define MOPf_DIE_ON_FAIL 0x01 |
78 | MAGIC* mop_mg_find(pTHX_ SV* const sv, const MGVTBL* const vtbl, I32 const flags); |
79 | |
80 | #ifdef DEBUGGING |
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); |
83 | #else |
84 | #define MOP_av_at(av, ix) AvARRAY(av)[ix] |
85 | #endif |
86 | |
87 | #define IsObject(sv) (SvROK(sv) && SvOBJECT(SvRV(sv))) |
88 | |
89 | #define newSVsv_share(sv) mop_newSVsv_share(aTHX_ sv) |
90 | SV* mop_newSVsv_share(pTHX_ SV*); |
91 | |
92 | SV* mop_class_of(pTHX_ SV* const sv); |
e989c0df |
93 | |
5bd0f967 |
94 | |
95 | /* Class::MOP Magic stuff */ |
d83eddd0 |
96 | |
97 | /* All the MOP_mg_* macros require MAGIC* mg for the first argument */ |
d83eddd0 |
98 | |
e989c0df |
99 | typedef struct { |
87cfe982 |
100 | SV* (*create_instance)(pTHX_ HV* const stash); |
acdbc948 |
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); |
e989c0df |
106 | } mop_instance_vtbl; |
107 | |
5bd0f967 |
108 | /* Class::MOP::Instance stuff */ |
109 | |
87cfe982 |
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); |
e192207e |
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); |
117 | |
e989c0df |
118 | const mop_instance_vtbl* mop_get_default_instance_vtbl(pTHX); |
119 | |
19b618cb |
120 | #define MOP_mg_obj(mg) ((mg)->mg_obj) |
3ac9bef6 |
121 | #define MOP_mg_ptr(mg) ((mg)->mg_ptr) |
122 | #define MOP_mg_vtbl(mg) ((const mop_instance_vtbl*)MOP_mg_ptr(mg)) |
d83eddd0 |
123 | #define MOP_mg_flags(mg) ((mg)->mg_private) |
22b82ca0 |
124 | #define MOP_mg_virtual(mg) ((mg)->mg_virtual) |
d83eddd0 |
125 | |
3ac9bef6 |
126 | #define MOP_mg_obj_refcounted_on(mg) (void)((mg)->mg_flags |= MGf_REFCOUNTED); |
127 | |
19b618cb |
128 | #define MOP_mg_create_instance(mg, stash) MOP_mg_vtbl(mg)->create_instance (aTHX_ (stash)) |
87cfe982 |
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)) |
d83eddd0 |
134 | |
3ac9bef6 |
135 | /* Class::MOP::Attribute stuff */ |
136 | |
137 | MAGIC* mop_attr_get_mg(pTHX_ SV* const attr); |
e989c0df |
138 | |
139 | /* Class::MOP::Method::Accessor stuff */ |
140 | |
d83eddd0 |
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) |
e989c0df |
144 | |
145 | |
146 | SV* mop_accessor_get_self(pTHX_ I32 const ax, I32 const items, CV* const cv); |
e192207e |
147 | MAGIC* mop_attr_get_mg(pTHX_ SV* const attr); |
e989c0df |
148 | |
22b82ca0 |
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); |
e989c0df |
151 | |
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) |
154 | |
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) |
157 | |
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) |
160 | |
d846ade3 |
161 | #endif |