Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 1134 lines (821 sloc) 33.098 kb
7c873ca Namespaces 1 - stub in NameSpace PMC
Leopold Toetsch authored
1 /*
e6f5751 Andy Lester protecting more function args with ARG*() macros
petdance authored
2 Copyright (C) 2005-2010, Parrot Foundation.
6351e77 Namespaces 2 - remove Stash structure
Leopold Toetsch authored
3 $Id$
7c873ca Namespaces 1 - stub in NameSpace PMC
Leopold Toetsch authored
4
5 =head1 NAME
6
7 src/pmc/namespace.pmc - NameSpace PMC
8
9 =head1 DESCRIPTION
10
11 These are the vtable functions for the namespace PMC.
12
13 =head2 Functions
14
15 =over 4
16
17 =cut
18
19 */
20
2578309 Vasily Chekalkin Merge branch pmc_headers_move back to trunk.
bacek authored
21 #include "pmc/pmc_sub.h"
7c873ca Namespaces 1 - stub in NameSpace PMC
Leopold Toetsch authored
22
e6f5751 Andy Lester protecting more function args with ARG*() macros
petdance authored
23 /* HEADERIZER HFILE: none */
24 /* HEADERIZER BEGIN: static */
25 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
26
27 static void add_multi_to_namespace(PARROT_INTERP,
28 ARGIN(PMC *SELF),
29 ARGIN(STRING *key),
30 ARGIN_NULLOK(PMC *value))
31 __attribute__nonnull__(1)
32 __attribute__nonnull__(2)
33 __attribute__nonnull__(3);
34
35 static void add_nci_to_namespace(PARROT_INTERP,
36 ARGIN(PMC *SELF),
37 ARGIN(STRING *key),
38 ARGIN_NULLOK(PMC *value))
39 __attribute__nonnull__(1)
40 __attribute__nonnull__(2)
41 __attribute__nonnull__(3);
42
43 static void add_to_class(PARROT_INTERP,
44 ARGMOD(Parrot_NameSpace_attributes *nsinfo),
45 ARGMOD(PMC *classobj),
46 ARGIN(STRING *key),
47 ARGIN(PMC *value))
48 __attribute__nonnull__(1)
49 __attribute__nonnull__(2)
50 __attribute__nonnull__(3)
51 __attribute__nonnull__(4)
52 __attribute__nonnull__(5)
53 FUNC_MODIFIES(*nsinfo)
54 FUNC_MODIFIES(*classobj);
55
56 static int maybe_add_sub_to_namespace(PARROT_INTERP,
57 ARGIN(PMC *SELF),
58 ARGIN(STRING *key),
59 ARGIN(PMC *value))
60 __attribute__nonnull__(1)
61 __attribute__nonnull__(2)
62 __attribute__nonnull__(3)
63 __attribute__nonnull__(4);
64
65 static int ns_insert_sub_keyed_str(PARROT_INTERP,
66 ARGIN(PMC *self),
67 ARGIN(STRING *key),
68 ARGIN_NULLOK(PMC *value))
69 __attribute__nonnull__(1)
70 __attribute__nonnull__(2)
71 __attribute__nonnull__(3);
72
73 #define ASSERT_ARGS_add_multi_to_namespace __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
74 PARROT_ASSERT_ARG(interp) \
75 , PARROT_ASSERT_ARG(SELF) \
76 , PARROT_ASSERT_ARG(key))
77 #define ASSERT_ARGS_add_nci_to_namespace __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
78 PARROT_ASSERT_ARG(interp) \
79 , PARROT_ASSERT_ARG(SELF) \
80 , PARROT_ASSERT_ARG(key))
81 #define ASSERT_ARGS_add_to_class __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
82 PARROT_ASSERT_ARG(interp) \
83 , PARROT_ASSERT_ARG(nsinfo) \
84 , PARROT_ASSERT_ARG(classobj) \
85 , PARROT_ASSERT_ARG(key) \
86 , PARROT_ASSERT_ARG(value))
87 #define ASSERT_ARGS_maybe_add_sub_to_namespace __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
88 PARROT_ASSERT_ARG(interp) \
89 , PARROT_ASSERT_ARG(SELF) \
90 , PARROT_ASSERT_ARG(key) \
91 , PARROT_ASSERT_ARG(value))
92 #define ASSERT_ARGS_ns_insert_sub_keyed_str __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
93 PARROT_ASSERT_ARG(interp) \
94 , PARROT_ASSERT_ARG(self) \
95 , PARROT_ASSERT_ARG(key))
96 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
97 /* HEADERIZER END: static */
98
6bdd5f9 Andy Lester headerizer now runs on PMC files
petdance authored
99 static void
e6f5751 Andy Lester protecting more function args with ARG*() macros
petdance authored
100 add_to_class(PARROT_INTERP, ARGMOD(Parrot_NameSpace_attributes *nsinfo),
e7ebd21 Vasily Chekalkin Fix Namespace.add_to_class arg guard.
bacek authored
101 ARGMOD_NULLOK(PMC *classobj), ARGIN(STRING *key), ARGIN(PMC *value))
0f5b65f chromatic [PMC] Extracted static ns_insert_sub_keyed_str() from set_pmc_keyed_str(...
chromatic authored
102 {
b9dae4f Michael H. Hind fix codetest failure - unused assert macros
mikehh authored
103 ASSERT_ARGS(add_to_class)
104
9dad88c tewk Refactor to eliminate code duplication
tewk authored
105 /* Insert it in class, if there is a class */
106 if (!PMC_IS_NULL(classobj) && PObj_is_class_TEST(classobj))
107 VTABLE_add_method(interp, classobj, key, value);
108
109 /* Otherwise, store it in the namespace for the class to
110 * retrieve later */
111 else {
112 /* If we don't have a place to hang methods, make one. */
113 if (PMC_IS_NULL(nsinfo->methods))
083213a Andrew Whitworth start rename of pmc_new to Parrot_pmc_new
Whiteknight authored
114 nsinfo->methods = Parrot_pmc_new(interp, enum_class_Hash);
9dad88c tewk Refactor to eliminate code duplication
tewk authored
115
116 /* Insert it. */
117 VTABLE_set_pmc_keyed_str(interp, nsinfo->methods, key, value);
118 }
119 }
120
0f5b65f chromatic [PMC] Extracted static ns_insert_sub_keyed_str() from set_pmc_keyed_str(...
chromatic authored
121 static int
e6f5751 Andy Lester protecting more function args with ARG*() macros
petdance authored
122 ns_insert_sub_keyed_str(PARROT_INTERP, ARGIN(PMC *self), ARGIN(STRING *key),
123 ARGIN_NULLOK(PMC *value))
0f5b65f chromatic [PMC] Extracted static ns_insert_sub_keyed_str() from set_pmc_keyed_str(...
chromatic authored
124 {
b9dae4f Michael H. Hind fix codetest failure - unused assert macros
mikehh authored
125 ASSERT_ARGS(ns_insert_sub_keyed_str)
126
0f5b65f chromatic [PMC] Extracted static ns_insert_sub_keyed_str() from set_pmc_keyed_str(...
chromatic authored
127 Parrot_NameSpace_attributes * const nsinfo = PARROT_NAMESPACE(self);
128 PMC * vtable = nsinfo->vtable;
129 PMC * const classobj = VTABLE_get_class(interp, self);
da30436 [OO] Check for an explicitly set vtable index when overriding a vtable m...
Jeff Horwitz authored
130 STRING * vtable_key = NULL;
e55e5ab Vasily Chekalkin Merge tt795_kill_parrot_sub_structure back to trunk.
bacek authored
131 Parrot_Sub_attributes *sub;
63889c2 cotto [PMC] replace PMC_struct_val and derivatives with ATTR accessors for the...
cotto authored
132
133 PMC_get_sub(interp, value, sub);
0f5b65f chromatic [PMC] Extracted static ns_insert_sub_keyed_str() from set_pmc_keyed_str(...
chromatic authored
134
135 if (sub->vtable_index != -1) {
136 /* Insert it in class, if there is a class */
da30436 [OO] Check for an explicitly set vtable index when overriding a vtable m...
Jeff Horwitz authored
137 if (!PMC_IS_NULL(classobj) && PObj_is_class_TEST(classobj)) {
894577a Andy Lester lots of consting, and using NULL instead of 0 for pointers
petdance authored
138 const char * const vtable_key_c =
b48651e chromatic [src] Tidied some code; no functional changes.
chromatic authored
139 Parrot_get_vtable_name(interp, sub->vtable_index);
da30436 [OO] Check for an explicitly set vtable index when overriding a vtable m...
Jeff Horwitz authored
140 PARROT_ASSERT(vtable_key_c);
141 vtable_key = Parrot_str_new(interp, vtable_key_c,
142 strlen(vtable_key_c));
143 VTABLE_add_vtable_override(interp, classobj, vtable_key, value);
144 }
0f5b65f chromatic [PMC] Extracted static ns_insert_sub_keyed_str() from set_pmc_keyed_str(...
chromatic authored
145
146 /* Otherwise, store it in the namespace for the class to
147 * retrieve later */
148 else {
149 /* If we don't have a place to hang vtable methods, make one. */
150 if (PMC_IS_NULL(vtable))
083213a Andrew Whitworth start rename of pmc_new to Parrot_pmc_new
Whiteknight authored
151 nsinfo->vtable = vtable = Parrot_pmc_new(interp, enum_class_Hash);
0f5b65f chromatic [PMC] Extracted static ns_insert_sub_keyed_str() from set_pmc_keyed_str(...
chromatic authored
152
153 /* Insert it. */
154 VTABLE_set_pmc_keyed_int(interp, vtable, sub->vtable_index, value);
155 }
156 }
157
849b32d tewk [nsentry] The infrastructure is in place, make realclean
tewk authored
158 if (sub->comp_flags & SUB_COMP_FLAG_METHOD) {
159 STRING *method_name = key;
160
da30436 [OO] Check for an explicitly set vtable index when overriding a vtable m...
Jeff Horwitz authored
161 if (Parrot_str_equal(interp, sub->method_name, CONST_STRING(interp, ""))) {
162 if (sub->vtable_index != -1 && vtable_key != NULL) {
163 method_name = Parrot_str_copy(interp, vtable_key);
164 }
165 }
166 else {
849b32d tewk [nsentry] The infrastructure is in place, make realclean
tewk authored
167 method_name = sub->method_name;
da30436 [OO] Check for an explicitly set vtable index when overriding a vtable m...
Jeff Horwitz authored
168 }
849b32d tewk [nsentry] The infrastructure is in place, make realclean
tewk authored
169 add_to_class(interp, nsinfo, classobj, method_name, value);
170 }
0f5b65f chromatic [PMC] Extracted static ns_insert_sub_keyed_str() from set_pmc_keyed_str(...
chromatic authored
171
172 return 0;
173 }
174
ef20a98 chromatic [PMC] Extracted several static functions from NameSpace's set_pmc_keyed_...
chromatic authored
175 static int
e6f5751 Andy Lester protecting more function args with ARG*() macros
petdance authored
176 maybe_add_sub_to_namespace(PARROT_INTERP, ARGIN(PMC *SELF), ARGIN(STRING *key),
177 ARGIN(PMC *value))
ef20a98 chromatic [PMC] Extracted several static functions from NameSpace's set_pmc_keyed_...
chromatic authored
178 {
b9dae4f Michael H. Hind fix codetest failure - unused assert macros
mikehh authored
179 ASSERT_ARGS(maybe_add_sub_to_namespace)
180
e6f5751 Andy Lester protecting more function args with ARG*() macros
petdance authored
181 STRING * const sub_str = CONST_STRING(interp, "Sub");
ef20a98 chromatic [PMC] Extracted several static functions from NameSpace's set_pmc_keyed_...
chromatic authored
182
183 if (!PMC_IS_NULL(value)
184 && VTABLE_isa(interp, value, sub_str)
185 && value->vtable->base_type != enum_class_Object)
186 return ns_insert_sub_keyed_str(interp, SELF, key, value);
187
188 return 0;
189 }
190
191 static void
e6f5751 Andy Lester protecting more function args with ARG*() macros
petdance authored
192 add_nci_to_namespace(PARROT_INTERP, ARGIN(PMC *SELF), ARGIN(STRING *key),
193 ARGIN_NULLOK(PMC *value))
ef20a98 chromatic [PMC] Extracted several static functions from NameSpace's set_pmc_keyed_...
chromatic authored
194 {
b9dae4f Michael H. Hind fix codetest failure - unused assert macros
mikehh authored
195 ASSERT_ARGS(add_nci_to_namespace)
196
e6f5751 Andy Lester protecting more function args with ARG*() macros
petdance authored
197 STRING * const nci_str = CONST_STRING(interp, "NCI");
ef20a98 chromatic [PMC] Extracted several static functions from NameSpace's set_pmc_keyed_...
chromatic authored
198
199 if (!PMC_IS_NULL(value)
200 && VTABLE_isa(interp, value, nci_str)) {
201 Parrot_NameSpace_attributes * const nsinfo = PARROT_NAMESPACE(SELF);
202 PMC * const classobj = VTABLE_get_class(interp, SELF);
203
204 /* Insert it in class, if there is a class */
205 add_to_class(interp, nsinfo, classobj, key, value);
206 }
207 }
208
209 static void
e6f5751 Andy Lester protecting more function args with ARG*() macros
petdance authored
210 add_multi_to_namespace(PARROT_INTERP, ARGIN(PMC *SELF), ARGIN(STRING *key),
211 ARGIN_NULLOK(PMC *value))
ef20a98 chromatic [PMC] Extracted several static functions from NameSpace's set_pmc_keyed_...
chromatic authored
212 {
b9dae4f Michael H. Hind fix codetest failure - unused assert macros
mikehh authored
213 ASSERT_ARGS(add_multi_to_namespace)
214
e6f5751 Andy Lester protecting more function args with ARG*() macros
petdance authored
215 STRING * const multi_str = CONST_STRING(interp, "MultiSub");
ef20a98 chromatic [PMC] Extracted several static functions from NameSpace's set_pmc_keyed_...
chromatic authored
216
217 if (!PMC_IS_NULL(value)
218 && VTABLE_isa(interp, value, multi_str)) {
219
220 /* TT #10; work around that Sub doesn't use PMC ATTRs */
221 if (value->vtable->base_type != enum_class_Object
222 && VTABLE_elements(interp, value) > 0) {
223 Parrot_NameSpace_attributes * const nsinfo = PARROT_NAMESPACE(SELF);
224 PMC * const classobj = VTABLE_get_class(interp, SELF);
225
226 /* Extract the first alternate and check if it is a method */
e6f5751 Andy Lester protecting more function args with ARG*() macros
petdance authored
227 PMC * const pmc_sub = VTABLE_get_pmc_keyed_int(interp, value, 0);
ef20a98 chromatic [PMC] Extracted several static functions from NameSpace's set_pmc_keyed_...
chromatic authored
228 Parrot_Sub_attributes *sub;
229 PMC_get_sub(interp, pmc_sub, sub);
230
231 if (sub->comp_flags & SUB_COMP_FLAG_METHOD) {
e6f5751 Andy Lester protecting more function args with ARG*() macros
petdance authored
232 STRING * const empty_str = CONST_STRING(interp, "");
ef20a98 chromatic [PMC] Extracted several static functions from NameSpace's set_pmc_keyed_...
chromatic authored
233 STRING *method_name = key;
234 Hash *hash;
235
236 if (Parrot_str_not_equal(interp, sub->method_name, empty_str))
237 method_name = sub->method_name;
238
239 add_to_class(interp, nsinfo, classobj, method_name, value);
240
241 GETATTR_NameSpace_hash(interp, SELF, hash);
242
243 parrot_hash_put(interp, hash,
244 hash_key_from_string(interp, hash, key),
245 hash_value_from_pmc(interp, hash, value));
246 }
247 }
248 }
249 }
250
251
6334469 Namespaces 13 - implement half-typed namespace storage
Leopold Toetsch authored
252 /*
d6bc087 chromatic [src] Cache all PIR-level vtable overrides in Namespace PMC.
chromatic authored
253 * Typically a named slot contains either another namespace or a
bf41b66 Jerry Gay [PDD07]: ws cleanup in src/, src/dynpmc/, and src/pmc/
particle authored
254 * var/sub (not both).
6334469 Namespaces 13 - implement half-typed namespace storage
Leopold Toetsch authored
255 * In case that the bucket->value is occupied, a FixedPMCArray is
256 * created, and the items are moved over to that extra storage.
257 * The array is flagged with FPA_is_ns_ext to distinguish it from a
258 * plain array variable.
259 *
d6bc087 chromatic [src] Cache all PIR-level vtable overrides in Namespace PMC.
chromatic authored
260 * This could easily expand to a full-fledged typed namespace if needed.
6334469 Namespaces 13 - implement half-typed namespace storage
Leopold Toetsch authored
261 */
262
caa0cdd Infinoid "enum { blah blab } foo_t" creates a variable named foo_t.
Infinoid authored
263 typedef enum {
6334469 Namespaces 13 - implement half-typed namespace storage
Leopold Toetsch authored
264 NS_slot_ns,
265 NS_slot_var_sub, /* unspecified ~half-raw slot */
266 NS_max_slots
267 } NS_slot_enum;
268
269 #define FPA_is_ns_ext PObj_private0_FLAG
270
e897870 NotFound [pmc] set auto_attrs on Hash and derived PMCs
NotFound authored
271 pmclass NameSpace extends Hash provides hash no_ro auto_attrs {
fdba9f5 Jonathan Worthington [PDD15]: Modify the NameSpace PMC so that we can hang a class or role of...
jnthn authored
272
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
273 ATTR STRING *name; /* Name of this namespace part. */
274 ATTR PMC *_class; /* The class or role attached to this namespace. */
275 ATTR PMC *methods; /* A Hash of methods, keyed on the method name. This
276 * goes away when the methods are sucked in by a
277 * class. */
278 ATTR PMC *vtable; /* A Hash of vtable subs, keyed on the vtable index */
70bfe8b cotto [PMC] remove PMC_pmc_val from NameSpace PMC
cotto authored
279 ATTR PMC *parent; /* This NameSpace's parent NameSpace */
cb1fcaa Namespaces 3 - add namespace vtable function
Leopold Toetsch authored
280
a13623c Namespaces 6 - remember namespace parent and name
Leopold Toetsch authored
281 /*
282
6f1f12e Jerry Gay [PDD21]: correct NameSpace PMC to implement 'hash' role
particle authored
283 =item C<void init()>
a13623c Namespaces 6 - remember namespace parent and name
Leopold Toetsch authored
284
20c9fef cotto [PMC] switch Hash-like PMCs to ATTRs
cotto authored
285 Initialize a C<NameSpace> PMC.
a13623c Namespaces 6 - remember namespace parent and name
Leopold Toetsch authored
286
287 =cut
288
289 */
290
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
291 VTABLE void init() {
292 PARROT_NAMESPACE(SELF)->vtable = PMCNULL;
82f8d0e chromatic [PMC] Fixed a segfault when accessing the class of a NameSpace without a...
chromatic authored
293 PARROT_NAMESPACE(SELF)->_class = PMCNULL;
20c9fef cotto [PMC] switch Hash-like PMCs to ATTRs
cotto authored
294 SELF.set_pointer(parrot_new_hash(INTERP));
295 PObj_custom_mark_destroy_SETALL(SELF);
cb1fcaa Namespaces 3 - add namespace vtable function
Leopold Toetsch authored
296 }
297
a13623c Namespaces 6 - remember namespace parent and name
Leopold Toetsch authored
298 /*
299
ffadb54 Namespaces 11 - implement NameSpace.mark
Leopold Toetsch authored
300 =item C<void mark()>
301
302 Marks the namespace as live.
303
304 =cut
305
306 */
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
307 VTABLE void mark() {
971e997 NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attribu...
NotFound authored
308 Parrot_NameSpace_attributes * const nsinfo = PARROT_NAMESPACE(SELF);
a69b4e4 chromatic [PMC] Replaced a SUPER() call from NameSpace's mark() with a direct mark...
chromatic authored
309
310 if (nsinfo->hash)
311 parrot_mark_hash(interp, nsinfo->hash);
312
313 Parrot_gc_mark_PMC_alive(interp, nsinfo->parent);
314 Parrot_gc_mark_PMC_alive(interp, nsinfo->_class);
315 Parrot_gc_mark_PMC_alive(interp, nsinfo->vtable);
316 Parrot_gc_mark_PMC_alive(interp, nsinfo->methods);
317 Parrot_gc_mark_STRING_alive(interp, nsinfo->name);
fdba9f5 Jonathan Worthington [PDD15]: Modify the NameSpace PMC so that we can hang a class or role of...
jnthn authored
318 }
319
320 /*
321
f013366 Infinoid [pmc] PDD07-ize function signatures and local variable declarations,
Infinoid authored
322 =item C<PMC *get_class()>
a54d453 allisonrandal [pdd15] Further implementation of the new object model:
allisonrandal authored
323
324 Returns the class or role PMC that is associated with this namespace.
325
326 =cut
327
328 */
329
60338bd Infinoid [PMC] Back out vtable consting patches r27028 and r27029, per design dis...
Infinoid authored
330 PMC *get_class() {
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
331 return PARROT_NAMESPACE(SELF)->_class;
a54d453 allisonrandal [pdd15] Further implementation of the new object model:
allisonrandal authored
332 }
333
334 /*
335
a13623c Namespaces 6 - remember namespace parent and name
Leopold Toetsch authored
336 =item C<void set_pmc_keyed_str(STRING *key, PMC *value)>
337
338 Sets C<*value> as the namespace item for C<*key>. This is part of the
339 raw interface. If the PMC C<value> is exactly a NameSpace, C<SELF>
340 will be set as the parent of that namespace and the name C<key> of
341 C<value> is stored too.
342
d0b24de Namespaces 9 - implement NameSpace.name()
Leopold Toetsch authored
343 =item C<void set_pmc_keyed(PMC *key, PMC *value)>
344
345 If C<key> is a simple key, it works like above. If C<key> is an array
346 of strings or a chained key, add all components to the namespace.
347
f013366 Infinoid [pmc] PDD07-ize function signatures and local variable declarations,
Infinoid authored
348 =item C<PMC *get_pmc_keyed(PMC *key)>
91f4991 Namespaces 11 - get_namespace Px, Py
Leopold Toetsch authored
349
bf41b66 Jerry Gay [PDD07]: ws cleanup in src/, src/dynpmc/, and src/pmc/
particle authored
350 Return the given namespace or PMCNULL. C<key> is either an array of
91f4991 Namespaces 11 - get_namespace Px, Py
Leopold Toetsch authored
351 strings, or a possibly nested key.
352
f013366 Infinoid [pmc] PDD07-ize function signatures and local variable declarations,
Infinoid authored
353 =item C<PMC *get_pmc_keyed_str(STRING *key)>
6334469 Namespaces 13 - implement half-typed namespace storage
Leopold Toetsch authored
354
b996545 Fix #38907
Leopold Toetsch authored
355 Return the given namespace item or PMCNULL. If the named item is either
6334469 Namespaces 13 - implement half-typed namespace storage
Leopold Toetsch authored
356 a NameSpace or a var, the NameSpace is returned.
357
d6bc087 chromatic [src] Cache all PIR-level vtable overrides in Namespace PMC.
chromatic authored
358 =item C<PMC *get_pmc_keyed_int(INTVAL key)>
359
360 Return a Sub representing an overridden vtable entry or PMCNULL. This is not
361 really a public API.
362
a13623c Namespaces 6 - remember namespace parent and name
Leopold Toetsch authored
363 =cut
364
365 */
366
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
367 VTABLE void set_pmc_keyed_str(STRING *key, PMC *value) {
f9a6cf7 chromatic [PMC] Fixed the final C++ casting warnings found by gcc.
chromatic authored
368 PMC *new_tuple = NULL;
49a4ed4 chromatic [PMC] Added PMC_IS_NULL checks to set_pmc_keyed_str vtable entry of Name...
chromatic authored
369 const int val_is_NS = PMC_IS_NULL(value)
370 ? 0
371 :value->vtable->base_type == enum_class_NameSpace;
372
373 /* don't need this everywhere yet */
894577a Andy Lester lots of consting, and using NULL instead of 0 for pointers
petdance authored
374 PMC * const old = (PMC *)parrot_hash_get(INTERP, (Hash *)SELF.get_pointer(), key);
ec7ec20 Andy Lester fixed trailing whitespace
petdance authored
375
807af8f Jonathan Worthington Build hash of methods in the namespace so we can pull them into a class....
jnthn authored
376 /* If it's a sub... */
ef20a98 chromatic [PMC] Extracted several static functions from NameSpace's set_pmc_keyed_...
chromatic authored
377 if (maybe_add_sub_to_namespace(interp, SELF, key, value))
378 return;
8e57fe8 allisonrandal [pdd15oo] Merging the pdd15oo branch at r22176 back into trunk.
allisonrandal authored
379
380 /* If it's an NCI method */
ef20a98 chromatic [PMC] Extracted several static functions from NameSpace's set_pmc_keyed_...
chromatic authored
381 add_nci_to_namespace(interp, SELF, key, value);
807af8f Jonathan Worthington Build hash of methods in the namespace so we can pull them into a class....
jnthn authored
382
f345b75 chromatic [PMC] Made set_pmc_keyed_str in NameSpace only add MultiSubs to a class ...
chromatic authored
383 /* If it's a multi-sub and the first in this NS... */
ef20a98 chromatic [PMC] Extracted several static functions from NameSpace's set_pmc_keyed_...
chromatic authored
384 add_multi_to_namespace(interp, SELF, key, value);
badd187 Chip Salzenberg PDD21 reloaded, phase 1.
chipdude authored
385
a1beaff chromatic [PMC] Made NameSpace PMC use the hash function interface, rather than po...
chromatic authored
386 if (!old)
6334469 Namespaces 13 - implement half-typed namespace storage
Leopold Toetsch authored
387 SUPER(key, value);
2d334db Jonathan Worthington Clean up some confusing whitespace.
jnthn authored
388 else {
d83a3cc Paul Cochrane [pmc]
paultcochrane authored
389 if ((old->vtable->base_type == enum_class_NameSpace) == val_is_NS) {
2d334db Jonathan Worthington Clean up some confusing whitespace.
jnthn authored
390 /* simple ns or simple var/sub changed */
391 SUPER(key, value);
392 }
6334469 Namespaces 13 - implement half-typed namespace storage
Leopold Toetsch authored
393 else if ((PObj_get_FLAGS(old) & FPA_is_ns_ext) &&
394 old->vtable->base_type == enum_class_FixedPMCArray) {
395 /* we have a tuple extension already */
57c5846 Jerry Gay [core]: remove unused variables and do whitespace fixes
particle authored
396 VTABLE_set_pmc_keyed_int(INTERP, old,
397 val_is_NS ? NS_slot_ns : NS_slot_var_sub,
398 value);
6334469 Namespaces 13 - implement half-typed namespace storage
Leopold Toetsch authored
399 }
400 else {
e9d98f3 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
401 /* create new tuple */
083213a Andrew Whitworth start rename of pmc_new to Parrot_pmc_new
Whiteknight authored
402 new_tuple = Parrot_pmc_new(INTERP, enum_class_FixedPMCArray);
f9a6cf7 chromatic [PMC] Fixed the final C++ casting warnings found by gcc.
chromatic authored
403
6334469 Namespaces 13 - implement half-typed namespace storage
Leopold Toetsch authored
404 /* flag it as special */
badd187 Chip Salzenberg PDD21 reloaded, phase 1.
chipdude authored
405 PObj_get_FLAGS(new_tuple) |= FPA_is_ns_ext;
f9a6cf7 chromatic [PMC] Fixed the final C++ casting warnings found by gcc.
chromatic authored
406
6334469 Namespaces 13 - implement half-typed namespace storage
Leopold Toetsch authored
407 /* for a fully typed namespace, we'd need 3 or 4 */
badd187 Chip Salzenberg PDD21 reloaded, phase 1.
chipdude authored
408 VTABLE_set_integer_native(INTERP, new_tuple, NS_max_slots);
6334469 Namespaces 13 - implement half-typed namespace storage
Leopold Toetsch authored
409 }
410 }
badd187 Chip Salzenberg PDD21 reloaded, phase 1.
chipdude authored
411
6334469 Namespaces 13 - implement half-typed namespace storage
Leopold Toetsch authored
412 if (val_is_NS) {
57c5846 Jerry Gay [core]: remove unused variables and do whitespace fixes
particle authored
413 /* TODO - this hack needs to go */
971e997 NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attribu...
NotFound authored
414 Parrot_NameSpace_attributes *nsinfo = PARROT_NAMESPACE(value);
70bfe8b cotto [PMC] remove PMC_pmc_val from NameSpace PMC
cotto authored
415 nsinfo->parent = SELF; /* set parent */
416 nsinfo->name = key; /* and name */
badd187 Chip Salzenberg PDD21 reloaded, phase 1.
chipdude authored
417
418 if (new_tuple) {
e9d98f3 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
419 VTABLE_set_pmc_keyed_int(INTERP, new_tuple, NS_slot_ns, value);
bf41b66 Jerry Gay [PDD07]: ws cleanup in src/, src/dynpmc/, and src/pmc/
particle authored
420 VTABLE_set_pmc_keyed_int(INTERP, new_tuple, NS_slot_var_sub,
a1beaff chromatic [PMC] Made NameSpace PMC use the hash function interface, rather than po...
chromatic authored
421 old);
422
2b72451 cotto [PMC] replace most remaining PMC_struct_val instances in Hash-like PMCs,...
cotto authored
423 parrot_hash_put(INTERP, (Hash *)SELF.get_pointer(), key, new_tuple);
6334469 Namespaces 13 - implement half-typed namespace storage
Leopold Toetsch authored
424 /* distinction from a plain FPA, which doesn't extend the
a1beaff chromatic [PMC] Made NameSpace PMC use the hash function interface, rather than po...
chromatic authored
425 * namespace storage */
6334469 Namespaces 13 - implement half-typed namespace storage
Leopold Toetsch authored
426 }
427 }
badd187 Chip Salzenberg PDD21 reloaded, phase 1.
chipdude authored
428 else if (new_tuple) {
a1beaff chromatic [PMC] Made NameSpace PMC use the hash function interface, rather than po...
chromatic authored
429 VTABLE_set_pmc_keyed_int(INTERP, new_tuple, NS_slot_ns, old);
badd187 Chip Salzenberg PDD21 reloaded, phase 1.
chipdude authored
430 VTABLE_set_pmc_keyed_int(INTERP, new_tuple, NS_slot_var_sub, value);
2b72451 cotto [PMC] replace most remaining PMC_struct_val instances in Hash-like PMCs,...
cotto authored
431 parrot_hash_put(INTERP, (Hash *)SELF.get_pointer(), key, new_tuple);
a13623c Namespaces 6 - remember namespace parent and name
Leopold Toetsch authored
432 }
433 }
434
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
435 VTABLE void set_pmc_keyed(PMC *key, PMC *value) {
49a4ed4 chromatic [PMC] Added PMC_IS_NULL checks to set_pmc_keyed_str vtable entry of Name...
chromatic authored
436 PMC *ns = SELF;
badd187 Chip Salzenberg PDD21 reloaded, phase 1.
chipdude authored
437
3085c75 Namespaces 28 - hierarchical class namespaces 4
Leopold Toetsch authored
438 if (key->vtable->base_type == enum_class_String) {
439 SELF.set_pmc_keyed_str(VTABLE_get_string(INTERP, key), value);
440 return;
441 }
badd187 Chip Salzenberg PDD21 reloaded, phase 1.
chipdude authored
442
0579ef7 Namespaces 17 - implement set_pmc_keyed with complex keys
Leopold Toetsch authored
443 if (key->vtable->base_type == enum_class_Key) {
444 while (1) {
b95c63d chromatic [PMC] Replaced the abomination which is a call to key_string() from outs...
chromatic authored
445 STRING * const part = VTABLE_get_string(INTERP, key);
d3f2211 chromatic [PMC] Changed some key_next() calls to VTABLE_shift_pmc calls on Key PMC...
chromatic authored
446 key = VTABLE_shift_pmc(INTERP, key);
e9d98f3 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
447
badd187 Chip Salzenberg PDD21 reloaded, phase 1.
chipdude authored
448 if (!key) {
57c5846 Jerry Gay [core]: remove unused variables and do whitespace fixes
particle authored
449 Parrot_set_global(INTERP, ns, part, value);
badd187 Chip Salzenberg PDD21 reloaded, phase 1.
chipdude authored
450 return;
57c5846 Jerry Gay [core]: remove unused variables and do whitespace fixes
particle authored
451 }
e9d98f3 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
452
57c5846 Jerry Gay [core]: remove unused variables and do whitespace fixes
particle authored
453 ns = Parrot_make_namespace_keyed_str(INTERP, ns, part);
454 }
d0b24de Namespaces 9 - implement NameSpace.name()
Leopold Toetsch authored
455 }
badd187 Chip Salzenberg PDD21 reloaded, phase 1.
chipdude authored
456
8e57fe8 allisonrandal [pdd15oo] Merging the pdd15oo branch at r22176 back into trunk.
allisonrandal authored
457 if (key->vtable->base_type == enum_class_ResizableStringArray) {
b5e5fd1 Andy Lester consting and localizing
petdance authored
458 const INTVAL elements = VTABLE_elements(interp, key);
8e57fe8 allisonrandal [pdd15oo] Merging the pdd15oo branch at r22176 back into trunk.
allisonrandal authored
459 INTVAL i;
460 for (i = 0; i < elements; ++i) {
b5e5fd1 Andy Lester consting and localizing
petdance authored
461 STRING * const part = VTABLE_get_string_keyed_int(interp, key, i);
8e57fe8 allisonrandal [pdd15oo] Merging the pdd15oo branch at r22176 back into trunk.
allisonrandal authored
462
463 if ((i + 1) >= elements) { /* Last entry in the array */
464 Parrot_set_global(INTERP, ns, part, value);
465 return;
466 }
467
468 ns = Parrot_make_namespace_keyed_str(INTERP, ns, part);
469 }
470 }
471
2255840 allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
472 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_GLOBAL_NOT_FOUND,
e9d98f3 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
473 "Invalid namespace key in set_pmc_keyed");
d0b24de Namespaces 9 - implement NameSpace.name()
Leopold Toetsch authored
474 }
475
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
476 VTABLE PMC *get_pmc_keyed_str(STRING *key) {
4772d2e Andrew Whitworth initial fix for TT #1449. Left in some C++ comments as flags to keep tra...
Whiteknight authored
477 Hash * const hash = (Hash *)SELF.get_pointer();
478 PMC *ns = (PMC *)parrot_hash_get(INTERP, hash, key);
e9d98f3 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
479
6334469 Namespaces 13 - implement half-typed namespace storage
Leopold Toetsch authored
480 if (!ns)
b996545 Fix #38907
Leopold Toetsch authored
481 return PMCNULL;
f9a6cf7 chromatic [PMC] Fixed the final C++ casting warnings found by gcc.
chromatic authored
482
6334469 Namespaces 13 - implement half-typed namespace storage
Leopold Toetsch authored
483 if ((PObj_get_FLAGS(ns) & FPA_is_ns_ext) &&
484 ns->vtable->base_type == enum_class_FixedPMCArray)
485 ns = VTABLE_get_pmc_keyed_int(INTERP, ns, NS_slot_ns);
f9a6cf7 chromatic [PMC] Fixed the final C++ casting warnings found by gcc.
chromatic authored
486
0d3a865 Namespaces 14 - use NameSpace PMC for global ops
Leopold Toetsch authored
487 return ns;
91f4991 Namespaces 11 - get_namespace Px, Py
Leopold Toetsch authored
488 }
badd187 Chip Salzenberg PDD21 reloaded, phase 1.
chipdude authored
489
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
490 VTABLE PMC *get_pmc_keyed(PMC *key) {
4772d2e Andrew Whitworth initial fix for TT #1449. Left in some C++ comments as flags to keep tra...
Whiteknight authored
491 PMC *ns = SUPER(key);
c10fadd Andrew Whitworth remove c++ comments. mikehh++
Whiteknight authored
492 /* Is this equivalent?
493 PMC *ns = INTERP->vtables[enum_class_Hash]->get_pmc_keyed(INTERP, SELF, key);
494 */
94be2d8 chromatic [PMC] Fixed co-recursion bug in NameSpace, when iterating through its co...
chromatic authored
495
496 if (!PMC_IS_NULL(ns))
497 return ns;
57c5846 Jerry Gay [core]: remove unused variables and do whitespace fixes
particle authored
498
94be2d8 chromatic [PMC] Fixed co-recursion bug in NameSpace, when iterating through its co...
chromatic authored
499 ns = SELF;
badd187 Chip Salzenberg PDD21 reloaded, phase 1.
chipdude authored
500
501 if (key->vtable->base_type == enum_class_Key) {
b95c63d chromatic [PMC] Replaced the abomination which is a call to key_string() from outs...
chromatic authored
502 STRING * const part = VTABLE_get_string(INTERP, key);
d3f2211 chromatic [PMC] Changed some key_next() calls to VTABLE_shift_pmc calls on Key PMC...
chromatic authored
503 key = VTABLE_shift_pmc(INTERP, key);
e9d98f3 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
504
94be2d8 chromatic [PMC] Fixed co-recursion bug in NameSpace, when iterating through its co...
chromatic authored
505 if (!key)
506 return VTABLE_get_pmc_keyed_str(INTERP, ns, part);
e9d98f3 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
507
94be2d8 chromatic [PMC] Fixed co-recursion bug in NameSpace, when iterating through its co...
chromatic authored
508 ns = Parrot_get_namespace_keyed_str(INTERP, ns, part);
e9d98f3 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
509
94be2d8 chromatic [PMC] Fixed co-recursion bug in NameSpace, when iterating through its co...
chromatic authored
510 if (PMC_IS_NULL(ns))
511 return PMCNULL;
e9d98f3 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
512
94be2d8 chromatic [PMC] Fixed co-recursion bug in NameSpace, when iterating through its co...
chromatic authored
513 return VTABLE_get_pmc_keyed(INTERP, ns, key);
91f4991 Namespaces 11 - get_namespace Px, Py
Leopold Toetsch authored
514 }
fbec7cf Andrew Whitworth Add use of array types to key NameSpace, on suggestion from NotFound++
Whiteknight authored
515 else if (VTABLE_does(INTERP, key, CONST_STRING(INTERP, "array"))) {
516 INTVAL i = 0;
517 while (!PMC_IS_NULL(ns) && VTABLE_elements(INTERP, key)) {
518 STRING * const name = VTABLE_get_string_keyed_int(INTERP, key, i);
4b0cc9b Andrew Whitworth [tt_1449] some error handling, need to check what Parrot_get_namespace_k...
Whiteknight authored
519 if (name == NULL || name == STRINGNULL) {
520 ns = PMCNULL;
c10fadd Andrew Whitworth remove c++ comments. mikehh++
Whiteknight authored
521 /* What to do here? Throw an exception or something? */
4b0cc9b Andrew Whitworth [tt_1449] some error handling, need to check what Parrot_get_namespace_k...
Whiteknight authored
522 break;
523 }
fbec7cf Andrew Whitworth Add use of array types to key NameSpace, on suggestion from NotFound++
Whiteknight authored
524 ns = Parrot_get_namespace_keyed_str(INTERP, ns, name);
525 i++;
526 }
527 return ns;
528 }
4772d2e Andrew Whitworth initial fix for TT #1449. Left in some C++ comments as flags to keep tra...
Whiteknight authored
529 else {
530 STRING * const name = VTABLE_get_string(INTERP, key);
531 ns = Parrot_get_namespace_keyed_str(INTERP, ns, name);
532 return ns;
533 }
c10fadd Andrew Whitworth remove c++ comments. mikehh++
Whiteknight authored
534 /* If we get the wrong type, should we throw an exception?
535 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_GLOBAL_NOT_FOUND,
536 "Invalid namespace key in get_pmc_keyed_str");
537 */
91f4991 Namespaces 11 - get_namespace Px, Py
Leopold Toetsch authored
538 }
539
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
540 VTABLE PMC *get_pmc_keyed_int(INTVAL key) {
971e997 NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attribu...
NotFound authored
541 Parrot_NameSpace_attributes * const nsinfo = PARROT_NAMESPACE(SELF);
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
542 PMC * const vtable = nsinfo->vtable;
d6bc087 chromatic [src] Cache all PIR-level vtable overrides in Namespace PMC.
chromatic authored
543
544 if (PMC_IS_NULL(vtable))
545 return PMCNULL;
546
547 return VTABLE_get_pmc_keyed_int(interp, vtable, key);
548 }
549
a13623c Namespaces 6 - remember namespace parent and name
Leopold Toetsch authored
550 /*
551
f013366 Infinoid [pmc] PDD07-ize function signatures and local variable declarations,
Infinoid authored
552 =item C<void *get_pointer_keyed_str(STRING *key)>
3085c75 Namespaces 28 - hierarchical class namespaces 4
Leopold Toetsch authored
553
f013366 Infinoid [pmc] PDD07-ize function signatures and local variable declarations,
Infinoid authored
554 =item C<void *get_pointer_keyed(PMC *key)>
0d3a865 Namespaces 14 - use NameSpace PMC for global ops
Leopold Toetsch authored
555
b996545 Fix #38907
Leopold Toetsch authored
556 Return the given namespace item or PMCNULL. If the named item is either
0d3a865 Namespaces 14 - use NameSpace PMC for global ops
Leopold Toetsch authored
557 a NameSpace or a var, the var is returned.
558
79954cd Andrew Whitworth add note about TT #1472
Whiteknight authored
559 TT #1472
badd187 Chip Salzenberg PDD21 reloaded, phase 1.
chipdude authored
560 TOTAL KLUDGE. ON THE CHOPPING BLOCK.
561
0d3a865 Namespaces 14 - use NameSpace PMC for global ops
Leopold Toetsch authored
562 =cut
563
564 */
565
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
566 VTABLE void *get_pointer_keyed_str(STRING *key) {
2b72451 cotto [PMC] replace most remaining PMC_struct_val instances in Hash-like PMCs,...
cotto authored
567 PMC *ns = (PMC *)parrot_hash_get(INTERP, (Hash *)SELF.get_pointer(), key);
e9d98f3 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
568
01e804c Bruce Gray [pmc] Typo corrections
Util authored
569 /* Be extra careful about returning PMCNULL */
5a6bcf2 NotFound [cage] make get_pointer_keyed_str in the Namespace pmc more robust about...
NotFound authored
570 if (! PMC_IS_NULL(ns)) {
571 if ((PObj_get_FLAGS(ns) & FPA_is_ns_ext) &&
572 ns->vtable->base_type == enum_class_FixedPMCArray)
573 ns = VTABLE_get_pmc_keyed_int(INTERP, ns, NS_slot_var_sub);
574 }
0191503 Jerry Gay [pmc]: add a few null checks in NameSpace PMC
particle authored
575 if (PMC_IS_NULL(ns))
5a6bcf2 NotFound [cage] make get_pointer_keyed_str in the Namespace pmc more robust about...
NotFound authored
576 ns = PMCNULL;
0d3a865 Namespaces 14 - use NameSpace PMC for global ops
Leopold Toetsch authored
577 return ns;
578 }
3085c75 Namespaces 28 - hierarchical class namespaces 4
Leopold Toetsch authored
579
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
580 VTABLE void *get_pointer_keyed(PMC *key) {
e9d98f3 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
581 PMC *ns = SELF;
8bb005b chromatic [PDD 07] Removed trailing whitespace.
chromatic authored
582
0191503 Jerry Gay [pmc]: add a few null checks in NameSpace PMC
particle authored
583 if (PMC_IS_NULL(key))
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
584 return PMCNULL;
57c5846 Jerry Gay [core]: remove unused variables and do whitespace fixes
particle authored
585
4976fab Andrew Whitworth [Core] Some quick-hack fixes for TT#8. ResizableStringArray should now b...
Whiteknight authored
586 switch (key->vtable->base_type) {
587 case enum_class_String:
588 return SELF.get_pointer_keyed_str(VTABLE_get_string(INTERP, key));
589 case enum_class_Key: {
590 /* this loop (and function) could use a rewrite for clarity */
591 while (1) {
592 STRING * const part = VTABLE_get_string(INTERP, key);
d3f2211 chromatic [PMC] Changed some key_next() calls to VTABLE_shift_pmc calls on Key PMC...
chromatic authored
593 key = VTABLE_shift_pmc(INTERP, key);
4976fab Andrew Whitworth [Core] Some quick-hack fixes for TT#8. ResizableStringArray should now b...
Whiteknight authored
594
595 if (!key)
596 return VTABLE_get_pointer_keyed_str(INTERP, ns, part);
597
598 ns = Parrot_get_namespace_keyed_str(INTERP, ns, part);
599
600 if (PMC_IS_NULL(ns))
601 return PMCNULL;
602 }
3085c75 Namespaces 28 - hierarchical class namespaces 4
Leopold Toetsch authored
603 }
4976fab Andrew Whitworth [Core] Some quick-hack fixes for TT#8. ResizableStringArray should now b...
Whiteknight authored
604 case enum_class_ResizableStringArray: {
894577a Andy Lester lots of consting, and using NULL instead of 0 for pointers
petdance authored
605 const INTVAL elements = VTABLE_elements(interp, key);
4976fab Andrew Whitworth [Core] Some quick-hack fixes for TT#8. ResizableStringArray should now b...
Whiteknight authored
606 INTVAL i;
607 for (i = 0; i < elements; ++i) {
608 STRING * const part = VTABLE_get_string_keyed_int(interp, key, i);
e9d98f3 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
609
4976fab Andrew Whitworth [Core] Some quick-hack fixes for TT#8. ResizableStringArray should now b...
Whiteknight authored
610 /* Last entry in the array */
611 if ((i + 1) >= elements)
612 return VTABLE_get_pointer_keyed_str(INTERP, ns, part);
badd187 Chip Salzenberg PDD21 reloaded, phase 1.
chipdude authored
613
4976fab Andrew Whitworth [Core] Some quick-hack fixes for TT#8. ResizableStringArray should now b...
Whiteknight authored
614 ns = Parrot_get_namespace_keyed_str(INTERP, ns, part);
8e57fe8 allisonrandal [pdd15oo] Merging the pdd15oo branch at r22176 back into trunk.
allisonrandal authored
615
4976fab Andrew Whitworth [Core] Some quick-hack fixes for TT#8. ResizableStringArray should now b...
Whiteknight authored
616 if (PMC_IS_NULL(ns))
617 return PMCNULL;
618 }
619 return ns;
8e57fe8 allisonrandal [pdd15oo] Merging the pdd15oo branch at r22176 back into trunk.
allisonrandal authored
620 }
4976fab Andrew Whitworth [Core] Some quick-hack fixes for TT#8. ResizableStringArray should now b...
Whiteknight authored
621 default:
622 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_GLOBAL_NOT_FOUND,
b218c89 Andrew Whitworth [get_class] a few cleanups with the get_class stuff
Whiteknight authored
623 "Invalid namespace key of type '%S' in get_pointer_keyed",
624 key->vtable->whoami);
8e57fe8 allisonrandal [pdd15oo] Merging the pdd15oo branch at r22176 back into trunk.
allisonrandal authored
625 }
3085c75 Namespaces 28 - hierarchical class namespaces 4
Leopold Toetsch authored
626 }
57c5846 Jerry Gay [core]: remove unused variables and do whitespace fixes
particle authored
627
0d3a865 Namespaces 14 - use NameSpace PMC for global ops
Leopold Toetsch authored
628 /*
629
f013366 Infinoid [pmc] PDD07-ize function signatures and local variable declarations,
Infinoid authored
630 =item C<STRING *get_string()>
a13623c Namespaces 6 - remember namespace parent and name
Leopold Toetsch authored
631
632 Return the name of this namespace part.
633
634 =cut
635
636 */
637
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
638 VTABLE STRING *get_string() {
971e997 NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attribu...
NotFound authored
639 const Parrot_NameSpace_attributes * const nsinfo = PARROT_NAMESPACE(SELF);
fdba9f5 Jonathan Worthington [PDD15]: Modify the NameSpace PMC so that we can hang a class or role of...
jnthn authored
640 return nsinfo->name;
cb1fcaa Namespaces 3 - add namespace vtable function
Leopold Toetsch authored
641 }
642
d0b24de Namespaces 9 - implement NameSpace.name()
Leopold Toetsch authored
643 /*
644
645 =back
646
647 =head2 Methods
648
649 =over 4
650
651 =cut
652
653 */
654
655 /*
656
f947c40 Stephen Weeks [core]: Add 'make_namespace' method to NameSpace PMC (RT #56616)
tene authored
657 =item C<METHOD make_namespace(PMC* key)>
658
659 Create and retrieve the namespace given by C<key>. If the namespace
660 already exists, only retrieve it.
661
662 =cut
663
664 */
665
666 METHOD make_namespace(PMC *key) {
667 PMC *ns = Parrot_get_namespace_keyed(INTERP, SELF, key);
668 if (PMC_IS_NULL(ns)) {
669 ns = Parrot_make_namespace_keyed(INTERP, SELF, key);
670 }
671 RETURN(PMC *ns);
672 }
673
674 /*
675
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
676 =item C<METHOD add_namespace(STRING *name, PMC *namespace)>
0f5fb35 chromatic Added add_namespace() method to NameSpace PMCs.
chromatic authored
677
dde4ec2 chromatic r1457@waterwheel: chromatic | 2007-01-20 15:38:16 -0800
chromatic authored
678 Stores the given namespace under this namespace, with the given name. Throws
679 an invalid type exception if C<namespace> is not a NameSpace PMC or subclass.
0f5fb35 chromatic Added add_namespace() method to NameSpace PMCs.
chromatic authored
680
afa8aba chromatic [PMC] Fixed POD formatting so as not to display source code accidentally...
chromatic authored
681 =cut
682
0f5fb35 chromatic Added add_namespace() method to NameSpace PMCs.
chromatic authored
683 */
684
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
685 METHOD add_namespace(STRING *name, PMC *_namespace) {
b5e5fd1 Andy Lester consting and localizing
petdance authored
686 STRING * const s_ns = CONST_STRING(INTERP, "NameSpace");
e9d98f3 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
687
ce63aa4 chromatic Clean up additional C++ keyword uses (Steve Peters, Mark Glines, RT #426...
chromatic authored
688 if (!VTABLE_isa(INTERP, _namespace, s_ns))
2255840 allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
689 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
3749cfc chromatic r1456@waterwheel: chromatic | 2007-01-20 15:08:25 -0800
chromatic authored
690 "Invalid type %d in add_namespace()",
ce63aa4 chromatic Clean up additional C++ keyword uses (Steve Peters, Mark Glines, RT #426...
chromatic authored
691 _namespace->vtable->base_type);
3749cfc chromatic r1456@waterwheel: chromatic | 2007-01-20 15:08:25 -0800
chromatic authored
692
ce63aa4 chromatic Clean up additional C++ keyword uses (Steve Peters, Mark Glines, RT #426...
chromatic authored
693 VTABLE_set_pmc_keyed_str(INTERP, SELF, name, _namespace);
0f5fb35 chromatic Added add_namespace() method to NameSpace PMCs.
chromatic authored
694 }
695
696 /*
697
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
698 =item C<METHOD add_sub(STRING *name, PMC *sub)>
9748360 chromatic Added add_sub() method to NameSpace PMC.
chromatic authored
699
dde4ec2 chromatic r1457@waterwheel: chromatic | 2007-01-20 15:38:16 -0800
chromatic authored
700 Stores the given sub under this namespace, with the given name. Throws an
701 invalid type exception if C<sub> is not a Sub PMC or subclass.
9748360 chromatic Added add_sub() method to NameSpace PMC.
chromatic authored
702
afa8aba chromatic [PMC] Fixed POD formatting so as not to display source code accidentally...
chromatic authored
703 =cut
704
9748360 chromatic Added add_sub() method to NameSpace PMC.
chromatic authored
705 */
706
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
707 METHOD add_sub(STRING *name, PMC *sub) {
b48651e chromatic [src] Tidied some code; no functional changes.
chromatic authored
708 STRING * const s_sub = CONST_STRING(INTERP, "Sub");
8ed4770 Patrick R. Michaud [core]:
pmichaud authored
709 STRING * const s_multisub = CONST_STRING(INTERP, "MultiSub");
e9d98f3 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
710
b48651e chromatic [src] Tidied some code; no functional changes.
chromatic authored
711 if (!VTABLE_isa(INTERP, sub, s_sub)
712 && !VTABLE_isa(INTERP, sub, s_multisub))
713 Parrot_ex_throw_from_c_args(INTERP, NULL,
714 EXCEPTION_INVALID_OPERATION,
dde4ec2 chromatic r1457@waterwheel: chromatic | 2007-01-20 15:38:16 -0800
chromatic authored
715 "Invalid type %d in add_sub()", sub->vtable->base_type);
716
9748360 chromatic Added add_sub() method to NameSpace PMC.
chromatic authored
717 VTABLE_set_pmc_keyed_str(INTERP, SELF, name, sub);
718 }
719
720 /*
721
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
722 =item C<METHOD add_var(STRING *name, PMC *var)>
e248cc3 chromatic Added add_var() method to NameSpace PMC.
chromatic authored
723
8f3ad51 Jerry Gay [src] fix pod copy/paste error
particle authored
724 Stores the given variable under this namespace, with the given name.
e248cc3 chromatic Added add_var() method to NameSpace PMC.
chromatic authored
725
afa8aba chromatic [PMC] Fixed POD formatting so as not to display source code accidentally...
chromatic authored
726 =cut
727
e248cc3 chromatic Added add_var() method to NameSpace PMC.
chromatic authored
728 */
729
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
730 METHOD add_var(STRING *name, PMC *var) {
e248cc3 chromatic Added add_var() method to NameSpace PMC.
chromatic authored
731 VTABLE_set_pmc_keyed_str(INTERP, SELF, name, var);
732 }
733
734 /*
735
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
736 =item C<METHOD get_name()>
d0b24de Namespaces 9 - implement NameSpace.name()
Leopold Toetsch authored
737
738 Returns the name of the namespace as an array of strings.
739
9c38638 chromatic Renamed NameSpace PMC name() method to get_name(), per PDD 21.
chromatic authored
740 $P2 = $P3.'get_name'()
d0b24de Namespaces 9 - implement NameSpace.name()
Leopold Toetsch authored
741 $S0 = join '::', $P2 # '::Foo::Bar'
742
743 =cut
744
745 */
746
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
747 METHOD get_name() {
083213a Andrew Whitworth start rename of pmc_new to Parrot_pmc_new
Whiteknight authored
748 PMC * const ar = Parrot_pmc_new(INTERP, enum_class_ResizableStringArray);
36e9097 Andrew Whitworth [get_class] some updates to get_class to try and standardize the way obj...
Whiteknight authored
749 INTVAL elements = 0;
b5e5fd1 Andy Lester consting and localizing
petdance authored
750 PMC *ns = SELF;
d0b24de Namespaces 9 - implement NameSpace.name()
Leopold Toetsch authored
751
752 while (ns) {
971e997 NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attribu...
NotFound authored
753 Parrot_NameSpace_attributes *nsinfo = PARROT_NAMESPACE(ns);
fdba9f5 Jonathan Worthington [PDD15]: Modify the NameSpace PMC so that we can hang a class or role of...
jnthn authored
754 VTABLE_unshift_string(INTERP, ar, nsinfo->name);
70bfe8b cotto [PMC] remove PMC_pmc_val from NameSpace PMC
cotto authored
755 ns = nsinfo->parent;
36e9097 Andrew Whitworth [get_class] some updates to get_class to try and standardize the way obj...
Whiteknight authored
756 elements++;
d0b24de Namespaces 9 - implement NameSpace.name()
Leopold Toetsch authored
757 }
57c5846 Jerry Gay [core]: remove unused variables and do whitespace fixes
particle authored
758
442c8fc Matt Diephouse Don't return the NULL namespace root as part of Namespace.name()
mdiep authored
759 /* remove the NULL string of the namespace root */
36e9097 Andrew Whitworth [get_class] some updates to get_class to try and standardize the way obj...
Whiteknight authored
760 if (elements > 0)
761 VTABLE_shift_string(INTERP, ar);
57c5846 Jerry Gay [core]: remove unused variables and do whitespace fixes
particle authored
762
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
763 RETURN(PMC *ar);
d0b24de Namespaces 9 - implement NameSpace.name()
Leopold Toetsch authored
764 }
4994bce chromatic Added find_namespace(), find_sub(), and find_var() to NameSpace PMC with...
chromatic authored
765 /*
766
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
767 =item C<METHOD find_namespace(STRING *name)>
4994bce chromatic Added find_namespace(), find_sub(), and find_var() to NameSpace PMC with...
chromatic authored
768
769 Return the namespace with the given name.
770
771 =cut
772
773 */
774
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
775 METHOD find_namespace(STRING *key) {
b5e5fd1 Andy Lester consting and localizing
petdance authored
776 STRING * const s_ns = CONST_STRING(INTERP, "NameSpace");
2b72451 cotto [PMC] replace most remaining PMC_struct_val instances in Hash-like PMCs,...
cotto authored
777 PMC * const ns = (PMC *)parrot_hash_get(INTERP, (Hash *)SELF.get_pointer(),
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
778 key);
4994bce chromatic Added find_namespace(), find_sub(), and find_var() to NameSpace PMC with...
chromatic authored
779
780 if (!ns)
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
781 RETURN(PMC *PMCNULL);
4994bce chromatic Added find_namespace(), find_sub(), and find_var() to NameSpace PMC with...
chromatic authored
782
783 /* it's a NameSpace */
784 if (VTABLE_isa(INTERP, ns, s_ns))
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
785 RETURN(PMC *ns);
4994bce chromatic Added find_namespace(), find_sub(), and find_var() to NameSpace PMC with...
chromatic authored
786
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
787 RETURN(PMC *PMCNULL);
4994bce chromatic Added find_namespace(), find_sub(), and find_var() to NameSpace PMC with...
chromatic authored
788 }
789
790 /*
791
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
792 =item C<METHOD find_sub(STRING *name)>
4994bce chromatic Added find_namespace(), find_sub(), and find_var() to NameSpace PMC with...
chromatic authored
793
794 Return the Sub PMC with the given name.
795
796 =cut
797
798 */
799
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
800 METHOD find_sub(STRING *key) {
b5e5fd1 Andy Lester consting and localizing
petdance authored
801 STRING * const s_sub = CONST_STRING(INTERP, "Sub");
2b72451 cotto [PMC] replace most remaining PMC_struct_val instances in Hash-like PMCs,...
cotto authored
802 PMC * const sub = (PMC *)parrot_hash_get(INTERP, (Hash *)SELF.get_pointer(),
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
803 key);
4994bce chromatic Added find_namespace(), find_sub(), and find_var() to NameSpace PMC with...
chromatic authored
804
805 if (!sub)
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
806 RETURN(PMC *PMCNULL);
4994bce chromatic Added find_namespace(), find_sub(), and find_var() to NameSpace PMC with...
chromatic authored
807
808 /* it's a Sub */
809 if (VTABLE_isa(INTERP, sub, s_sub))
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
810 RETURN(PMC *sub);
4994bce chromatic Added find_namespace(), find_sub(), and find_var() to NameSpace PMC with...
chromatic authored
811
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
812 RETURN(PMC *PMCNULL);
4994bce chromatic Added find_namespace(), find_sub(), and find_var() to NameSpace PMC with...
chromatic authored
813 }
814
815 /*
816
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
817 =item C<METHOD find_var(STRING *name)>
4994bce chromatic Added find_namespace(), find_sub(), and find_var() to NameSpace PMC with...
chromatic authored
818
819 Return the PMC with the given name.
820
821 =cut
822
823 */
824
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
825 METHOD find_var(STRING *key) {
2b72451 cotto [PMC] replace most remaining PMC_struct_val instances in Hash-like PMCs,...
cotto authored
826 PMC * const val = (PMC *)parrot_hash_get(INTERP, (Hash *)SELF.get_pointer(), key);
4994bce chromatic Added find_namespace(), find_sub(), and find_var() to NameSpace PMC with...
chromatic authored
827
828 if (!val)
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
829 RETURN(PMC *PMCNULL);
4994bce chromatic Added find_namespace(), find_sub(), and find_var() to NameSpace PMC with...
chromatic authored
830
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
831 RETURN(PMC *val);
4994bce chromatic Added find_namespace(), find_sub(), and find_var() to NameSpace PMC with...
chromatic authored
832 }
7c873ca Namespaces 1 - stub in NameSpace PMC
Leopold Toetsch authored
833
834 /*
835
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
836 =item C<METHOD del_namespace(STRING *name)>
df53358 chromatic Added del_namespace() method to NameSpace PMC.
chromatic authored
837
2d63451 chromatic r1458@waterwheel: chromatic | 2007-01-20 15:57:50 -0800
chromatic authored
838 Deletes the contained NameSpace PMC with the given name. Throws an invalid
0d030c3 chromatic r1459@waterwheel: chromatic | 2007-01-20 16:01:37 -0800
chromatic authored
839 type exception if the item to delete is not a NameSpace PMC or subclass, and
2d63451 chromatic r1458@waterwheel: chromatic | 2007-01-20 15:57:50 -0800
chromatic authored
840 does not delete the PMC.
df53358 chromatic Added del_namespace() method to NameSpace PMC.
chromatic authored
841
842 =cut
843
844 */
845
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
846 METHOD del_namespace(STRING *name) {
2b72451 cotto [PMC] replace most remaining PMC_struct_val instances in Hash-like PMCs,...
cotto authored
847 Hash * const hash = (Hash *)SELF.get_pointer();
b5e5fd1 Andy Lester consting and localizing
petdance authored
848 PMC * const ns = (PMC *)parrot_hash_get(INTERP, hash, name);
849 STRING * const s_ns = CONST_STRING(INTERP, "NameSpace");
2d63451 chromatic r1458@waterwheel: chromatic | 2007-01-20 15:57:50 -0800
chromatic authored
850
e9d98f3 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
851 if (PMC_IS_NULL(ns))
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
852 RETURN(void);
2d63451 chromatic r1458@waterwheel: chromatic | 2007-01-20 15:57:50 -0800
chromatic authored
853
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
854 if (!VTABLE_isa(INTERP, ns, s_ns))
2255840 allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
855 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
dbc9a08 Paul Cochrane [core,ops,pmc] Using the Parrot '%Ss' printf format instead of
paultcochrane authored
856 "Invalid type %d for '%Ss' in del_namespace()",
857 ns->vtable->base_type, name);
2d63451 chromatic r1458@waterwheel: chromatic | 2007-01-20 15:57:50 -0800
chromatic authored
858
859 parrot_hash_delete(INTERP, hash, name);
df53358 chromatic Added del_namespace() method to NameSpace PMC.
chromatic authored
860 }
861
862 /*
863
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
864 =item C<METHOD del_sub(STRING *name)>
56d8485 chromatic Added del_sub() method to NameSpace PMC.
chromatic authored
865
0d030c3 chromatic r1459@waterwheel: chromatic | 2007-01-20 16:01:37 -0800
chromatic authored
866 Deletes the contained Sub PMC with the given name. Throws an invalid type
867 exception if the item to delete is not a Sub PMC or subclass, and does not
868 delete the PMC.
56d8485 chromatic Added del_sub() method to NameSpace PMC.
chromatic authored
869
870 =cut
871
872 */
873
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
874 METHOD del_sub(STRING *name) {
2b72451 cotto [PMC] replace most remaining PMC_struct_val instances in Hash-like PMCs,...
cotto authored
875 Hash * const hash = (Hash *)SELF.get_pointer();
b5e5fd1 Andy Lester consting and localizing
petdance authored
876 PMC * const sub = (PMC *)parrot_hash_get(INTERP, hash, name);
877 STRING * const s_sub = CONST_STRING(INTERP, "Sub");
0d030c3 chromatic r1459@waterwheel: chromatic | 2007-01-20 16:01:37 -0800
chromatic authored
878
e9d98f3 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
879 if (PMC_IS_NULL(sub))
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
880 RETURN(void);
0d030c3 chromatic r1459@waterwheel: chromatic | 2007-01-20 16:01:37 -0800
chromatic authored
881
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
882 if (!VTABLE_isa(INTERP, sub, s_sub))
2255840 allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
883 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
dbc9a08 Paul Cochrane [core,ops,pmc] Using the Parrot '%Ss' printf format instead of
paultcochrane authored
884 "Invalid type %d for '%Ss' in del_sub()",
885 sub->vtable->base_type, name);
0d030c3 chromatic r1459@waterwheel: chromatic | 2007-01-20 16:01:37 -0800
chromatic authored
886
887 parrot_hash_delete(INTERP, hash, name);
56d8485 chromatic Added del_sub() method to NameSpace PMC.
chromatic authored
888 }
889
890 /*
891
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
892 =item C<METHOD del_var(STRING *name)>
b12a1fe chromatic Added del_var() method to NameSpace PMC.
chromatic authored
893
894 Deletes the contained variable-like PMC with the given name.
895
896 =cut
897
898 */
899
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
900 METHOD del_var(STRING *name) {
2b72451 cotto [PMC] replace most remaining PMC_struct_val instances in Hash-like PMCs,...
cotto authored
901 parrot_hash_delete(INTERP, (Hash *)SELF.get_pointer(), name);
b12a1fe chromatic Added del_var() method to NameSpace PMC.
chromatic authored
902 }
903
904 /*
905
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
906 =item C<METHOD get_sym(STRING *name)>
d21bb82 Namespace iteration (see also #39778) - 2
Leopold Toetsch authored
907
908 Return the symbol (var or sub) with the given name. This can be used
bf41b66 Jerry Gay [PDD07]: ws cleanup in src/, src/dynpmc/, and src/pmc/
particle authored
909 to retrieve symbols, if a NameSpace with the same name exists.
d21bb82 Namespace iteration (see also #39778) - 2
Leopold Toetsch authored
910
911 =cut
912
913 */
914
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
915 METHOD get_sym(STRING *key) {
2b72451 cotto [PMC] replace most remaining PMC_struct_val instances in Hash-like PMCs,...
cotto authored
916 PMC *ns = (PMC *)parrot_hash_get(INTERP, (Hash *)SELF.get_pointer(), key);
f9a6cf7 chromatic [PMC] Fixed the final C++ casting warnings found by gcc.
chromatic authored
917
d21bb82 Namespace iteration (see also #39778) - 2
Leopold Toetsch authored
918 if (!ns)
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
919 RETURN(PMC *PMCNULL);
f9a6cf7 chromatic [PMC] Fixed the final C++ casting warnings found by gcc.
chromatic authored
920
921 /* it's a NameSpace */
922 if (ns->vtable == SELF->vtable)
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
923 RETURN(PMC *PMCNULL);
f9a6cf7 chromatic [PMC] Fixed the final C++ casting warnings found by gcc.
chromatic authored
924
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
925 if ((PObj_get_FLAGS(ns) & FPA_is_ns_ext)
926 && ns->vtable->base_type == enum_class_FixedPMCArray)
d21bb82 Namespace iteration (see also #39778) - 2
Leopold Toetsch authored
927 ns = VTABLE_get_pmc_keyed_int(INTERP, ns, NS_slot_var_sub);
f9a6cf7 chromatic [PMC] Fixed the final C++ casting warnings found by gcc.
chromatic authored
928
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
929 RETURN(PMC *ns);
d21bb82 Namespace iteration (see also #39778) - 2
Leopold Toetsch authored
930 }
badd187 Chip Salzenberg PDD21 reloaded, phase 1.
chipdude authored
931
932 /*
933
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
934 =item C<METHOD export_to(PMC *dest, PMC *what)>
d34b325 Namespaces 24 - bugfix, export_to
Leopold Toetsch authored
935
d332814 Jerry Gay [pmc]: added functionality to NameSpace PMC 'export_to' method
particle authored
936 Export items from this NameSpace into the C<dest> NameSpace. The items to
937 export are named in C<what>, which may be an array of strings, a hash, or null.
938 If C<what> is an array of strings, interpretation of items in an array follows
939 the conventions of the source (exporting) namespace.
940 If C<what> is a hash, the keys correspond to the names in the source namespace,
941 and the values correspond to the names in the destination namespace.
942 if a hash value is null or an empty string, the name in the hash key is used.
943 A null C<what> requests the 'default' set of items.
944 Any other type passed in C<what> throws an exception.
945
946 NOTE: exporting 'default' set of items is not yet implemented.
d34b325 Namespaces 24 - bugfix, export_to
Leopold Toetsch authored
947
948 =cut
949
950 */
951
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
952 METHOD export_to(PMC *dest, PMC *what) {
b5e5fd1 Andy Lester consting and localizing
petdance authored
953 STRING * const s_hash = CONST_STRING(interp, "hash");
954 STRING * const s_array = CONST_STRING(interp, "array");
d34b325 Namespaces 24 - bugfix, export_to
Leopold Toetsch authored
955
cb5e3da chromatic [PMC] Plugged a few memory leaks in NameSpace PMC.
chromatic authored
956 if (PMC_IS_NULL(dest))
2255840 allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
957 Parrot_ex_throw_from_c_args(interp, NULL, 0,
958 "destination namespace not specified");
d332814 Jerry Gay [pmc]: added functionality to NameSpace PMC 'export_to' method
particle authored
959
cb5e3da chromatic [PMC] Plugged a few memory leaks in NameSpace PMC.
chromatic authored
960 if (PMC_IS_NULL(what) || !VTABLE_elements(interp, what))
2255840 allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
961 Parrot_ex_throw_from_c_args(interp, NULL, 0,
962 "exporting default object set not yet implemented");
a516048 Jerry Gay [pmc]: added null guard to NameSpace PMC 'export_to' method
particle authored
963
d332814 Jerry Gay [pmc]: added functionality to NameSpace PMC 'export_to' method
particle authored
964 /* if "what" does "hash", we extract string key/value pairs,
965 * lookup the object with the name specified in the key,
966 * and export it with the name specified as value. */
967 if (VTABLE_does(INTERP, what, s_hash)) {
968 PMC * const iter = VTABLE_get_iter(interp, what);
969 const INTVAL n = VTABLE_elements(interp, what);
970 INTVAL i;
971
972 for (i = 0; i < n; ++i) {
973 STRING *dest_name;
974 PMC *object;
b5e5fd1 Andy Lester consting and localizing
petdance authored
975 STRING * const src_name = VTABLE_shift_string(interp, iter);
d332814 Jerry Gay [pmc]: added functionality to NameSpace PMC 'export_to' method
particle authored
976
cb5e3da chromatic [PMC] Plugged a few memory leaks in NameSpace PMC.
chromatic authored
977 if (STRING_IS_NULL(src_name) || STRING_IS_EMPTY(src_name))
2255840 allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
978 Parrot_ex_throw_from_c_args(interp, NULL, 0,
e9d98f3 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
979 "source object name not specified");
d332814 Jerry Gay [pmc]: added functionality to NameSpace PMC 'export_to' method
particle authored
980
cf259ef Jerry Gay [pmc]: fix export_to when passed a hash with a null value (code + test)
particle authored
981 if (PMC_IS_NULL(VTABLE_get_pmc_keyed_str(interp, what, src_name))) {
d332814 Jerry Gay [pmc]: added functionality to NameSpace PMC 'export_to' method
particle authored
982 dest_name = src_name;
983 }
cf259ef Jerry Gay [pmc]: fix export_to when passed a hash with a null value (code + test)
particle authored
984 else {
985 dest_name = VTABLE_get_string_keyed_str(interp, what, src_name);
e9d98f3 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
986 if (STRING_IS_NULL(dest_name) || STRING_IS_EMPTY(dest_name))
cf259ef Jerry Gay [pmc]: fix export_to when passed a hash with a null value (code + test)
particle authored
987 dest_name = src_name;
988 }
d332814 Jerry Gay [pmc]: added functionality to NameSpace PMC 'export_to' method
particle authored
989
990 object = VTABLE_get_pmc_keyed_str(interp, SELF, src_name);
e9d98f3 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
991
cb5e3da chromatic [PMC] Plugged a few memory leaks in NameSpace PMC.
chromatic authored
992 if (PMC_IS_NULL(object))
2255840 allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
993 Parrot_ex_throw_from_c_args(interp, NULL, 0,
cb5e3da chromatic [PMC] Plugged a few memory leaks in NameSpace PMC.
chromatic authored
994 "object '%Ss' not found in current namespace", src_name);
d332814 Jerry Gay [pmc]: added functionality to NameSpace PMC 'export_to' method
particle authored
995
996 VTABLE_set_pmc_keyed_str(interp, dest, dest_name, object);
997 }
998 }
999 else if (VTABLE_does(INTERP, what, s_array)) {
1000 const INTVAL n = VTABLE_elements(interp, what);
e9d98f3 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
1001 INTVAL i;
d332814 Jerry Gay [pmc]: added functionality to NameSpace PMC 'export_to' method
particle authored
1002
1003 for (i = 0; i < n; ++i) {
1004 PMC *object;
b5e5fd1 Andy Lester consting and localizing
petdance authored
1005 STRING * const name = VTABLE_get_string_keyed_int(interp, what, i);
d332814 Jerry Gay [pmc]: added functionality to NameSpace PMC 'export_to' method
particle authored
1006
cb5e3da chromatic [PMC] Plugged a few memory leaks in NameSpace PMC.
chromatic authored
1007 if (STRING_IS_NULL(name) || STRING_IS_EMPTY(name))
2255840 allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
1008 Parrot_ex_throw_from_c_args(interp, NULL, 0,
1009 "object name not specified");
d34b325 Namespaces 24 - bugfix, export_to
Leopold Toetsch authored
1010
d332814 Jerry Gay [pmc]: added functionality to NameSpace PMC 'export_to' method
particle authored
1011 object = VTABLE_get_pmc_keyed_str(interp, SELF, name);
e9d98f3 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
1012
cb5e3da chromatic [PMC] Plugged a few memory leaks in NameSpace PMC.
chromatic authored
1013 if (PMC_IS_NULL(object))
2255840 allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
1014 Parrot_ex_throw_from_c_args(interp, NULL, 0,
cb5e3da chromatic [PMC] Plugged a few memory leaks in NameSpace PMC.
chromatic authored
1015 "object '%Ss' not found in current namespace", name);
d332814 Jerry Gay [pmc]: added functionality to NameSpace PMC 'export_to' method
particle authored
1016
1017 VTABLE_set_pmc_keyed_str(interp, dest, name, object);
1018 }
1019 }
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
1020 else
2255840 allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
1021 Parrot_ex_throw_from_c_args(interp, NULL, 0,
e9d98f3 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
1022 "can't handle argument of type %s", what->vtable->base_type);
d34b325 Namespaces 24 - bugfix, export_to
Leopold Toetsch authored
1023 }
cb6a495 add NameSpace.parent method; test
Leopold Toetsch authored
1024
1025 /*
1026
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
1027 =item C<METHOD get_parent()>
cb6a495 add NameSpace.parent method; test
Leopold Toetsch authored
1028
ab1fc3d fix typo
Leopold Toetsch authored
1029 Return the parent NameSpace or PMCNULL, if none.
cb6a495 add NameSpace.parent method; test
Leopold Toetsch authored
1030
1031 =cut
1032
1033 */
1034
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
1035 METHOD get_parent() {
70bfe8b cotto [PMC] remove PMC_pmc_val from NameSpace PMC
cotto authored
1036 PMC *parent = PARROT_NAMESPACE(SELF)->parent ? PARROT_NAMESPACE(SELF)->parent : PMCNULL;
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
1037 RETURN(PMC *parent);
cb6a495 add NameSpace.parent method; test
Leopold Toetsch authored
1038 }
1039
84d641a Jonathan Worthington [PDD15]: Initial work on associating classes with namespaces. Add get_cl...
jnthn authored
1040 /*
1041
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
1042 =item C<METHOD get_class()>
84d641a Jonathan Worthington [PDD15]: Initial work on associating classes with namespaces. Add get_cl...
jnthn authored
1043
1044 Returns the class or role PMC that is associated with this namespace.
1045
1046 =cut
1047
1048 */
1049
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
1050 METHOD get_class() {
971e997 NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attribu...
NotFound authored
1051 Parrot_NameSpace_attributes * const nsinfo = PARROT_NAMESPACE(SELF);
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
1052 PMC *ret_class = nsinfo->_class;
e9d98f3 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
1053
a54d453 allisonrandal [pdd15] Further implementation of the new object model:
allisonrandal authored
1054 if (PMC_IS_NULL(ret_class))
1055 ret_class = PMCNULL;
1056
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
1057 RETURN(PMC *ret_class);
84d641a Jonathan Worthington [PDD15]: Initial work on associating classes with namespaces. Add get_cl...
jnthn authored
1058 }
1059
1060 /*
1061
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
1062 =item C<METHOD set_class(PMC *class_or_role)>
84d641a Jonathan Worthington [PDD15]: Initial work on associating classes with namespaces. Add get_cl...
jnthn authored
1063
1064 Sets the class or role PMC that is associated with this namespace.
1065
1066 =cut
1067
1068 */
1069
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
1070 METHOD set_class(PMC *class_or_role) {
1071 PARROT_NAMESPACE(SELF)->_class = class_or_role;
84d641a Jonathan Worthington [PDD15]: Initial work on associating classes with namespaces. Add get_cl...
jnthn authored
1072 }
1073
e76e3d9 Jonathan Worthington [PDD15] Import methods from namespaces when instantiating a class for th...
jnthn authored
1074 /*
1075
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
1076 =item C<METHOD get_associated_methods()>
e76e3d9 Jonathan Worthington [PDD15] Import methods from namespaces when instantiating a class for th...
jnthn authored
1077
1078 Gets the Hash of methods associated with this namespace and removes it from
1079 the namespace.
1080
1081 =cut
1082
1083 */
1084
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
1085 METHOD get_associated_methods() {
971e997 NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attribu...
NotFound authored
1086 Parrot_NameSpace_attributes * const nsinfo = PARROT_NAMESPACE(SELF);
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
1087 PMC * const ret_methods = nsinfo->methods;
b5e5fd1 Andy Lester consting and localizing
petdance authored
1088
1089 nsinfo->methods = PMCNULL;
e9d98f3 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
1090
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
1091 RETURN(PMC *ret_methods);
e76e3d9 Jonathan Worthington [PDD15] Import methods from namespaces when instantiating a class for th...
jnthn authored
1092 }
1093
1094 /*
1095
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
1096 =item C<METHOD get_associated_vtable_methods()>
e76e3d9 Jonathan Worthington [PDD15] Import methods from namespaces when instantiating a class for th...
jnthn authored
1097
1098 Gets the Hash of vtable methods associated with this namespace and removes it
1099 from the namespace.
1100
1101 =cut
1102
1103 */
1104
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
1105 METHOD get_associated_vtable_methods() {
971e997 NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attribu...
NotFound authored
1106 Parrot_NameSpace_attributes * const nsinfo = PARROT_NAMESPACE(SELF);
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
1107 PMC * const ret_methods = nsinfo->vtable;
b5e5fd1 Andy Lester consting and localizing
petdance authored
1108
1109 nsinfo->vtable = PMCNULL;
e9d98f3 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
1110
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
1111 RETURN(PMC *ret_methods);
e76e3d9 Jonathan Worthington [PDD15] Import methods from namespaces when instantiating a class for th...
jnthn authored
1112 }
1113
d34b325 Namespaces 24 - bugfix, export_to
Leopold Toetsch authored
1114 }
e9d98f3 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
1115
d34b325 Namespaces 24 - bugfix, export_to
Leopold Toetsch authored
1116 /*
1117
7c873ca Namespaces 1 - stub in NameSpace PMC
Leopold Toetsch authored
1118 =back
1119
1120 =head1 SEE ALSO
1121
d647e42 Alberto Simões Namespace PMC: svn props, corrected POD name link.
ambs authored
1122 F<docs/pdds/pdd21_namespaces.pod>
7c873ca Namespaces 1 - stub in NameSpace PMC
Leopold Toetsch authored
1123
1124 =cut
1125
1126 */
1127
1128 /*
1129 * Local variables:
72575ae Bernhard Schmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored
1130 * c-file-style: "parrot"
7c873ca Namespaces 1 - stub in NameSpace PMC
Leopold Toetsch authored
1131 * End:
1132 * vim: expandtab shiftwidth=4:
72575ae Bernhard Schmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored
1133 */
Something went wrong with that request. Please try again.