2 Copyright (C) 2004-2009, Parrot Foundation.
21 #include "parrot/parrot.h"
23 #include "pmc/pmc_sub.h"
24 #include "pmc/pmc_callcontext.h"
26 /* HEADERIZER HFILE: include/parrot/global.h */
27 /* HEADERIZER BEGIN: static */
28 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
30 PARROT_WARN_UNUSED_RESULT
31 PARROT_CAN_RETURN_NULL
32 static PMC
* get_namespace_pmc(PARROT_INTERP
, ARGIN(PMC
*sub_pmc
))
33 __attribute__nonnull__(1)
34 __attribute__nonnull__(2);
36 PARROT_WARN_UNUSED_RESULT
37 PARROT_CAN_RETURN_NULL
38 static PMC
* internal_ns_keyed(PARROT_INTERP
,
42 __attribute__nonnull__(1)
43 __attribute__nonnull__(2)
44 __attribute__nonnull__(3);
46 PARROT_WARN_UNUSED_RESULT
47 PARROT_CAN_RETURN_NULL
48 static PMC
* internal_ns_keyed_key(PARROT_INTERP
,
52 __attribute__nonnull__(1)
53 __attribute__nonnull__(2)
54 __attribute__nonnull__(3);
56 PARROT_WARN_UNUSED_RESULT
57 PARROT_CAN_RETURN_NULL
58 static PMC
* internal_ns_keyed_str(PARROT_INTERP
,
62 __attribute__nonnull__(1)
63 __attribute__nonnull__(2)
64 __attribute__nonnull__(3);
66 PARROT_WARN_UNUSED_RESULT
67 PARROT_CAN_RETURN_NULL
68 static PMC
* internal_ns_maybe_create(PARROT_INTERP
,
72 __attribute__nonnull__(1)
73 __attribute__nonnull__(2)
74 __attribute__nonnull__(3);
76 static void store_sub_in_multi(PARROT_INTERP
,
79 __attribute__nonnull__(1)
80 __attribute__nonnull__(2)
81 __attribute__nonnull__(3);
83 #define ASSERT_ARGS_get_namespace_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
84 PARROT_ASSERT_ARG(interp) \
85 , PARROT_ASSERT_ARG(sub_pmc))
86 #define ASSERT_ARGS_internal_ns_keyed __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
87 PARROT_ASSERT_ARG(interp) \
88 , PARROT_ASSERT_ARG(base_ns) \
89 , PARROT_ASSERT_ARG(pmc_key))
90 #define ASSERT_ARGS_internal_ns_keyed_key __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
91 PARROT_ASSERT_ARG(interp) \
92 , PARROT_ASSERT_ARG(ns) \
93 , PARROT_ASSERT_ARG(key))
94 #define ASSERT_ARGS_internal_ns_keyed_str __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
95 PARROT_ASSERT_ARG(interp) \
96 , PARROT_ASSERT_ARG(base_ns) \
97 , PARROT_ASSERT_ARG(key))
98 #define ASSERT_ARGS_internal_ns_maybe_create __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
99 PARROT_ASSERT_ARG(interp) \
100 , PARROT_ASSERT_ARG(ns) \
101 , PARROT_ASSERT_ARG(key))
102 #define ASSERT_ARGS_store_sub_in_multi __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
103 PARROT_ASSERT_ARG(interp) \
104 , PARROT_ASSERT_ARG(sub_pmc) \
105 , PARROT_ASSERT_ARG(ns))
106 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
107 /* HEADERIZER END: static */
109 #define DEBUG_GLOBAL 0
111 /* flags for internal_ns_keyed */
112 #define INTERN_NS_CREAT 1 /* I'm a fan of the classics */
116 =item C<static PMC * internal_ns_keyed_str(PARROT_INTERP, PMC *base_ns, STRING
119 Internal function to do keyed namespace lookup relative to a given namespace
120 PMC. Understands STRINGs.
126 PARROT_WARN_UNUSED_RESULT
127 PARROT_CAN_RETURN_NULL
129 internal_ns_keyed_str(PARROT_INTERP
, ARGIN(PMC
*base_ns
),
130 ARGIN(STRING
*key
), int flags
)
132 ASSERT_ARGS(internal_ns_keyed_str
)
133 PMC
* const ns
= VTABLE_get_pmc_keyed_str(interp
, base_ns
, key
);
135 if (!PMC_IS_NULL(ns
) && VTABLE_isa(interp
, ns
, CONST_STRING(interp
, "NameSpace")))
138 return internal_ns_maybe_create(interp
, base_ns
, key
, flags
);
143 =item C<static PMC * internal_ns_keyed_key(PARROT_INTERP, PMC *ns, PMC *key, int
146 Internal function to do keyed namespace lookup relative to a given namespace
147 PMC. Understands Key PMCs. Used from C<internal_ns_keyed>.
153 PARROT_WARN_UNUSED_RESULT
154 PARROT_CAN_RETURN_NULL
156 internal_ns_keyed_key(PARROT_INTERP
, ARGIN(PMC
*ns
), ARGIN(PMC
*key
), int flags
)
158 ASSERT_ARGS(internal_ns_keyed_key
)
160 STRING
* const part
= VTABLE_get_string(interp
, key
);
161 PMC
*sub_ns
= VTABLE_get_pmc_keyed_str(interp
, ns
, part
);
163 if (PMC_IS_NULL(sub_ns
) || !VTABLE_isa(interp
, sub_ns
, CONST_STRING(interp
, "NameSpace"))) {
164 sub_ns
= internal_ns_maybe_create(interp
, ns
, part
, flags
);
166 if (PMC_IS_NULL(sub_ns
))
171 key
= VTABLE_shift_pmc(interp
, key
);
179 =item C<static PMC * internal_ns_keyed(PARROT_INTERP, PMC *base_ns, PMC
180 *pmc_key, int flags)>
182 internal_ns_keyed: Internal function to do keyed namespace lookup relative to a
183 given namespace PMC. Understands String, Key, and array PMCs containing
190 PARROT_WARN_UNUSED_RESULT
191 PARROT_CAN_RETURN_NULL
193 internal_ns_keyed(PARROT_INTERP
, ARGIN(PMC
*base_ns
), ARGIN(PMC
*pmc_key
), int flags
)
195 ASSERT_ARGS(internal_ns_keyed
)
197 if (VTABLE_isa(interp
, pmc_key
, CONST_STRING(interp
, "String"))) {
198 STRING
* const str_key
= VTABLE_get_string(interp
, pmc_key
);
199 return internal_ns_keyed_str(interp
, base_ns
, str_key
, flags
);
201 else if (pmc_key
->vtable
->base_type
== enum_class_Key
)
202 return internal_ns_keyed_key(interp
, base_ns
, pmc_key
, flags
);
204 /* array of strings */
205 STRING
* const isans
= CONST_STRING(interp
, "NameSpace");
206 const INTVAL n
= VTABLE_elements(interp
, pmc_key
);
210 for (i
= 0; i
< n
; ++i
) {
211 STRING
* const part
= VTABLE_get_string_keyed_int(interp
, pmc_key
, i
);
212 PMC
*sub_ns
= VTABLE_get_pmc_keyed_str(interp
, ns
, part
);
214 if (PMC_IS_NULL(sub_ns
) || !VTABLE_isa(interp
, sub_ns
, isans
)) {
215 sub_ns
= internal_ns_maybe_create(interp
, ns
, part
, flags
);
216 if (PMC_IS_NULL(sub_ns
))
227 =item C<static PMC * internal_ns_maybe_create(PARROT_INTERP, PMC *ns, STRING
230 Given the a namespace PMC, a STRING containing a name, and flags from
231 C<internal_ns_keyed> or C<internal_ns_keyed_str>, creates and returns a new
232 namespace with the given name in the given namespace. This is an internal
239 PARROT_WARN_UNUSED_RESULT
240 PARROT_CAN_RETURN_NULL
242 internal_ns_maybe_create(PARROT_INTERP
, ARGIN(PMC
*ns
), ARGIN(STRING
*key
), int flags
)
244 ASSERT_ARGS(internal_ns_maybe_create
)
247 /* TT #1220 - stop depending on typed namespace */
248 if (!(flags
& INTERN_NS_CREAT
))
251 /* TT #1221 - match HLL of enclosing namespace? */
252 sub_ns
= Parrot_pmc_new(interp
, Parrot_get_ctx_HLL_type(interp
,
253 enum_class_NameSpace
));
255 if (PMC_IS_NULL(sub_ns
))
258 VTABLE_set_pmc_keyed_str(interp
, ns
, key
, sub_ns
);
266 =item C<PMC * Parrot_get_namespace_keyed(PARROT_INTERP, PMC *base_ns, PMC
269 Find the namespace relative to the namespace C<base_ns> with the key
270 C<pmc_key>, which may be a String, a Key, or an array of strings. Return
271 the namespace, or NULL if not found.
278 PARROT_WARN_UNUSED_RESULT
279 PARROT_CAN_RETURN_NULL
281 Parrot_get_namespace_keyed(PARROT_INTERP
, ARGIN(PMC
*base_ns
), ARGIN(PMC
*pmc_key
))
283 ASSERT_ARGS(Parrot_get_namespace_keyed
)
284 return internal_ns_keyed(interp
, base_ns
, pmc_key
, 0);
289 =item C<PMC * Parrot_get_namespace_keyed_str(PARROT_INTERP, PMC *base_ns, STRING
292 Find the namespace relative to the namespace C<base_ns> with the string key
293 C<str_key>. Return the namespace, or NULL if not found.
300 PARROT_WARN_UNUSED_RESULT
301 PARROT_CAN_RETURN_NULL
303 Parrot_get_namespace_keyed_str(PARROT_INTERP
, ARGIN(PMC
*base_ns
),
304 ARGIN_NULLOK(STRING
*str_key
))
306 ASSERT_ARGS(Parrot_get_namespace_keyed_str
)
307 return internal_ns_keyed_str(interp
, base_ns
, str_key
, 0);
312 =item C<PMC * Parrot_make_namespace_keyed(PARROT_INTERP, PMC *base_ns, PMC
315 Find, or create if necessary, the namespace relative to the namespace
316 C<base_ns> with the key C<pmc_key>, which may be a String, a Key, or an
317 array of strings. Return the namespace. Errors will result in exceptions.
324 PARROT_WARN_UNUSED_RESULT
325 PARROT_CAN_RETURN_NULL
327 Parrot_make_namespace_keyed(PARROT_INTERP
, ARGIN(PMC
*base_ns
),
330 ASSERT_ARGS(Parrot_make_namespace_keyed
)
331 return internal_ns_keyed(interp
, base_ns
, pmc_key
, INTERN_NS_CREAT
);
336 =item C<PMC * Parrot_make_namespace_keyed_str(PARROT_INTERP, PMC *base_ns,
339 Find, or create if necessary, the namespace relative to the namespace
340 C<base_ns> with the string key C<str_key>. Return the namespace. Errors
341 will result in exceptions.
348 PARROT_WARN_UNUSED_RESULT
349 PARROT_CAN_RETURN_NULL
351 Parrot_make_namespace_keyed_str(PARROT_INTERP
, ARGIN(PMC
*base_ns
),
352 ARGIN(STRING
*str_key
))
354 ASSERT_ARGS(Parrot_make_namespace_keyed_str
)
355 return internal_ns_keyed_str(interp
, base_ns
, str_key
, INTERN_NS_CREAT
);
361 =item C<PMC * Parrot_make_namespace_autobase(PARROT_INTERP, PMC *key)>
363 Find, or create if necessary, a namespace with the key C<key>, which may be a
364 String, a Key, or an array of strings. If it is a String, then the lookup is
365 relative to the current namespace. Otherwise, it is relative to the current HLL
366 root namespace. Return the namespace. Errors will result in exceptions.
373 PARROT_WARN_UNUSED_RESULT
374 PARROT_CAN_RETURN_NULL
376 Parrot_make_namespace_autobase(PARROT_INTERP
, ARGIN_NULLOK(PMC
*key
))
378 ASSERT_ARGS(Parrot_make_namespace_autobase
)
380 if (VTABLE_isa(interp
, key
, CONST_STRING(interp
, "String")))
381 base_ns
= Parrot_pcc_get_namespace(interp
, CURRENT_CONTEXT(interp
));
383 base_ns
= VTABLE_get_pmc_keyed_int(interp
, interp
->HLL_namespace
,
384 Parrot_pcc_get_HLL(interp
, CURRENT_CONTEXT(interp
)));
385 return Parrot_make_namespace_keyed(interp
, base_ns
, key
);
390 =item C<PMC * Parrot_ns_get_name(PARROT_INTERP, PMC *_namespace)>
392 Retrieve an array of names from a namespace object.
399 PARROT_WARN_UNUSED_RESULT
400 PARROT_CAN_RETURN_NULL
402 Parrot_ns_get_name(PARROT_INTERP
, ARGIN(PMC
*_namespace
))
404 ASSERT_ARGS(Parrot_ns_get_name
)
406 Parrot_pcc_invoke_method_from_c_args(interp
, _namespace
, CONST_STRING(interp
, "get_name"), "->P", &names
);
412 =item C<PMC * Parrot_get_global(PARROT_INTERP, PMC *ns, STRING *globalname)>
414 Parrot_get_global allows a null namespace without throwing an exception; it
415 simply returns PMCNULL in that case.
417 NOTE: At present the use of the {get, set}_global functions is mandatory due to the
418 wacky namespace typing of the default Parrot namespace. Eventually it will be
419 safe to just use the standard hash interface (if desired).
421 Look up the global named C<globalname> in the namespace C<ns>. Return the
422 global, or return PMCNULL if C<ns> is null or if the global is not found.
424 KLUDGE ALERT: Currently prefers non-namespaces in case of collision.
434 * Parrot_get_global allows a null namespace without throwing an exception; it
435 * simply returns PMCNULL in that case.
437 * NOTE: At present the use of the {get, set}_global functions is mandatory due to the
438 * wacky namespace typing of the default Parrot namespace. Eventually it will be
439 * safe to just use the standard hash interface (if desired).
443 PARROT_WARN_UNUSED_RESULT
444 PARROT_CAN_RETURN_NULL
446 Parrot_get_global(PARROT_INTERP
, ARGIN_NULLOK(PMC
*ns
), ARGIN_NULLOK(STRING
*globalname
))
448 ASSERT_ARGS(Parrot_get_global
)
452 return (PMC
*)VTABLE_get_pointer_keyed_str(interp
, ns
, globalname
);
457 =item C<void Parrot_set_global(PARROT_INTERP, PMC *ns, STRING *globalname, PMC
460 Set the global named C<globalname> in the namespace C<ns> to the value C<val>.
468 Parrot_set_global(PARROT_INTERP
, ARGIN_NULLOK(PMC
*ns
),
469 ARGIN_NULLOK(STRING
*globalname
), ARGIN_NULLOK(PMC
*val
))
471 ASSERT_ARGS(Parrot_set_global
)
472 VTABLE_set_pmc_keyed_str(interp
, ns
, globalname
, val
);
478 =item C<PMC * Parrot_find_global_n(PARROT_INTERP, PMC *ns, STRING *globalname)>
480 Search the namespace PMC C<ns> for an object with name C<globalname>.
481 Return the object, or NULL if not found.
483 TT #1222 - For now this function prefers non-namespaces, it will eventually
484 entirely use the untyped interface.
491 PARROT_WARN_UNUSED_RESULT
492 PARROT_CAN_RETURN_NULL
494 Parrot_find_global_n(PARROT_INTERP
, ARGIN_NULLOK(PMC
*ns
), ARGIN_NULLOK(STRING
*globalname
))
496 ASSERT_ARGS(Parrot_find_global_n
)
501 Parrot_io_printf(interp
, "find_global name '%Ss'\n", globalname
);
508 * TT #1219 - we should be able to use 'get_pmc_keyed' here,
509 * but we can't because Parrot's default namespaces are not
510 * fully typed and there's a pseudo-typed interface that
511 * distinguishes 'get_pmc_keyed' from 'get_pointer_keyed';
512 * the former is for NS and the latter is for non-NS.
514 res
= (PMC
*)VTABLE_get_pointer_keyed_str(interp
, ns
, globalname
);
517 return PMC_IS_NULL(res
) ? NULL
: res
;
522 =item C<PMC * Parrot_find_global_cur(PARROT_INTERP, STRING *globalname)>
524 Finds and returns the data time named C<globalname> in the current namespace.
531 PARROT_WARN_UNUSED_RESULT
532 PARROT_CAN_RETURN_NULL
534 Parrot_find_global_cur(PARROT_INTERP
, ARGIN_NULLOK(STRING
*globalname
))
536 ASSERT_ARGS(Parrot_find_global_cur
)
537 PMC
* const ns
= Parrot_pcc_get_namespace(interp
, CURRENT_CONTEXT(interp
));
538 return Parrot_find_global_n(interp
, ns
, globalname
);
543 =item C<PMC * Parrot_find_global_s(PARROT_INTERP, STRING *str_key, STRING
546 Search the namespace designated by C<str_key>, or the HLL root if
547 C<str_key> is NULL, for an object with name C<globalname>. Return the
548 object, or NULL if not found.
550 TT #1222 - For now this function prefers non-namespaces, it will eventually
551 entirely use the untyped interface.
558 PARROT_WARN_UNUSED_RESULT
559 PARROT_CAN_RETURN_NULL
561 Parrot_find_global_s(PARROT_INTERP
, ARGIN_NULLOK(STRING
*str_key
),
562 ARGIN_NULLOK(STRING
*globalname
))
564 ASSERT_ARGS(Parrot_find_global_s
)
566 Parrot_get_namespace_keyed_str(interp
,
567 Parrot_get_ctx_HLL_namespace(interp
),
569 return Parrot_find_global_n(interp
, ns
, globalname
);
574 =item C<void Parrot_store_global_n(PARROT_INTERP, PMC *ns, STRING *globalname,
577 Store the PMC C<val> into the namespace PMC C<ns> with name C<globalname>.
585 Parrot_store_global_n(PARROT_INTERP
, ARGIN_NULLOK(PMC
*ns
),
586 ARGIN_NULLOK(STRING
*globalname
), ARGIN_NULLOK(PMC
*val
))
588 ASSERT_ARGS(Parrot_store_global_n
)
591 Parrot_io_printf(interp
, "store_global name '%Ss'\n", globalname
);
597 VTABLE_set_pmc_keyed_str(interp
, ns
, globalname
, val
);
602 =item C<void Parrot_store_global_s(PARROT_INTERP, STRING *str_key, STRING
603 *globalname, PMC *val)>
605 Store the PMC C<val> into the namespace designated by C<str_key>, or
606 the HLL root if C<str_key> is NULL, with the name C<globalname>.
614 Parrot_store_global_s(PARROT_INTERP
, ARGIN_NULLOK(STRING
*str_key
),
615 ARGIN_NULLOK(STRING
*globalname
), ARGIN_NULLOK(PMC
*val
))
617 ASSERT_ARGS(Parrot_store_global_s
)
618 PMC
* const ns
= Parrot_make_namespace_keyed_str(interp
,
619 Parrot_get_ctx_HLL_namespace(interp
),
622 Parrot_store_global_n(interp
, ns
, globalname
, val
);
624 /* TT #1225 - method cache invalidation should be a namespace function */
625 Parrot_invalidate_method_cache(interp
, str_key
);
631 =item C<PMC * Parrot_find_global_op(PARROT_INTERP, PMC *ns, STRING *globalname,
634 If the global exists in the given namespace PMC, return it. If not, return
642 PARROT_WARN_UNUSED_RESULT
643 PARROT_CANNOT_RETURN_NULL
645 Parrot_find_global_op(PARROT_INTERP
, ARGIN(PMC
*ns
),
646 ARGIN_NULLOK(STRING
*globalname
), ARGIN_NULLOK(void *next
))
648 ASSERT_ARGS(Parrot_find_global_op
)
652 Parrot_ex_throw_from_c_args(interp
, next
, EXCEPTION_GLOBAL_NOT_FOUND
,
653 "Tried to get null global");
655 res
= Parrot_find_global_n(interp
, ns
, globalname
);
665 =item C<PMC * Parrot_find_name_op(PARROT_INTERP, STRING *name, void *next)>
667 TT #1223 - THIS IS BROKEN - it doesn't walk up the scopes yet
669 Find the given C<name> in lexicals, then the current namespace, then the HLL
670 root namespace, and finally Parrot builtins. If the name isn't found
671 anywhere, return PMCNULL.
678 PARROT_WARN_UNUSED_RESULT
679 PARROT_CAN_RETURN_NULL
681 Parrot_find_name_op(PARROT_INTERP
, ARGIN(STRING
*name
), SHIM(void *next
))
683 ASSERT_ARGS(Parrot_find_name_op
)
684 PMC
* const ctx
= CURRENT_CONTEXT(interp
);
685 PMC
* const lex_pad
= Parrot_find_pad(interp
, name
, ctx
);
688 if (PMC_IS_NULL(lex_pad
))
691 g
= VTABLE_get_pmc_keyed_str(interp
, lex_pad
, name
);
693 /* TT #1223 - walk up the scopes! duh!! */
696 g
= Parrot_find_global_cur(interp
, name
);
699 g
= Parrot_find_global_n(interp
, Parrot_get_ctx_HLL_namespace(interp
), name
);
709 =item C<static PMC * get_namespace_pmc(PARROT_INTERP, PMC *sub_pmc)>
711 Return the namespace PMC associated with the PMC C<sub>. If C<sub> is NULL,
712 return the Associated HLL namespace PMC instead.
718 PARROT_WARN_UNUSED_RESULT
719 PARROT_CAN_RETURN_NULL
721 get_namespace_pmc(PARROT_INTERP
, ARGIN(PMC
*sub_pmc
))
723 ASSERT_ARGS(get_namespace_pmc
)
724 Parrot_Sub_attributes
*sub
;
725 PMC
*nsname
, *nsroot
;
727 PMC_get_sub(interp
, sub_pmc
, sub
);
728 nsname
= sub
->namespace_name
;
729 nsroot
= Parrot_get_HLL_namespace(interp
, sub
->HLL_id
);
731 /* If we have a NULL, return the HLL namespace */
732 if (PMC_IS_NULL(nsname
))
734 /* If we have a String, do a string lookup */
735 else if (nsname
->vtable
->base_type
== enum_class_String
)
736 return Parrot_make_namespace_keyed_str(interp
, nsroot
,
737 VTABLE_get_string(interp
, nsname
));
738 /* Otherwise, do a PMC lookup */
740 return Parrot_make_namespace_keyed(interp
, nsroot
, nsname
);
745 =item C<static void store_sub_in_multi(PARROT_INTERP, PMC *sub_pmc, PMC *ns)>
747 Adds the sub C<sub> into a mulisub of the same name in the namespace C<ns>.
748 If no multisub by that name currently exists, we create one.
755 store_sub_in_multi(PARROT_INTERP
, ARGIN(PMC
*sub_pmc
), ARGIN(PMC
*ns
))
757 ASSERT_ARGS(store_sub_in_multi
)
758 Parrot_Sub_attributes
*sub
;
759 STRING
*ns_entry_name
;
762 PMC_get_sub(interp
, sub_pmc
, sub
);
763 ns_entry_name
= sub
->ns_entry_name
;
764 multisub
= VTABLE_get_pmc_keyed_str(interp
, ns
, ns_entry_name
);
766 /* is there an existing MultiSub PMC? or do we need to create one? */
767 if (PMC_IS_NULL(multisub
)) {
768 multisub
= Parrot_pmc_new(interp
, Parrot_get_ctx_HLL_type(interp
, enum_class_MultiSub
));
769 /* we have to push the sub onto the MultiSub before we try to store
770 it because storing requires information from the sub */
771 VTABLE_push_pmc(interp
, multisub
, sub_pmc
);
772 VTABLE_set_pmc_keyed_str(interp
, ns
, ns_entry_name
, multisub
);
775 VTABLE_push_pmc(interp
, multisub
, sub_pmc
);
780 =item C<void Parrot_store_sub_in_namespace(PARROT_INTERP, PMC *sub_pmc)>
782 Adds the PMC C<sub> into the current namespace. Adds the sub to a multi of the
783 same name if it's defined as a multi.
791 Parrot_store_sub_in_namespace(PARROT_INTERP
, ARGIN(PMC
*sub_pmc
))
793 ASSERT_ARGS(Parrot_store_sub_in_namespace
)
794 const INTVAL cur_id
= Parrot_pcc_get_HLL(interp
, CURRENT_CONTEXT(interp
));
797 Parrot_Sub_attributes
*sub
;
799 /* PF structures aren't fully constructed yet */
800 Parrot_block_GC_mark(interp
);
802 /* store relative to HLL namespace */
803 PMC_get_sub(interp
, sub_pmc
, sub
);
804 Parrot_pcc_set_HLL(interp
, CURRENT_CONTEXT(interp
), sub
->HLL_id
);
806 ns
= get_namespace_pmc(interp
, sub_pmc
);
808 /* attach a namespace to the sub for lookups */
809 sub
->namespace_stash
= ns
;
811 /* store a :multi sub */
812 if (!PMC_IS_NULL(sub
->multi_signature
))
813 store_sub_in_multi(interp
, sub_pmc
, ns
);
815 /* store other subs (as long as they're not :anon) */
816 else if (!(PObj_get_FLAGS(sub_pmc
) & SUB_FLAG_PF_ANON
)
817 || sub
->vtable_index
!= -1) {
818 STRING
* const ns_entry_name
= sub
->ns_entry_name
;
819 PMC
* const nsname
= sub
->namespace_name
;
821 Parrot_store_global_n(interp
, ns
, ns_entry_name
, sub_pmc
);
824 TEMPORARY HACK - cache invalidation should be a namespace function */
825 if (!PMC_IS_NULL(nsname
)) {
826 STRING
* const nsname_s
= VTABLE_get_string(interp
, nsname
);
827 Parrot_invalidate_method_cache(interp
, nsname_s
);
832 Parrot_pcc_set_HLL(interp
, CURRENT_CONTEXT(interp
), cur_id
);
833 Parrot_unblock_GC_mark(interp
);
842 F<include/parrot/global.h>
851 * c-file-style: "parrot"
853 * vim: expandtab shiftwidth=4: