2 Copyright (C) 2005-2007, The Perl Foundation.
7 src/dynpmc/dynlexpad.pmc - DynLexPad PMC
11 DynLexPad provides a more dynamic lexpad that allows the addition of
22 pmclass DynLexPad dynpmc provides lexpad need_ext {
25 real_exception(interp, NULL, INVALID_OPERATION,
26 "don't create me like this");
31 =item C<init_pmc(PMC *lexinfo)>
33 Initialize the LexPad PMC and remember the associate
36 =item C<void set_pointer(void *)>
38 Initialize the LexPad PMC and remember the associate context.
40 =item C<INTVAL elements()>
42 Returns the number of elements in the hash.
44 =item C<INTVAL exists_keyed(PMC *name)>
46 =item C<INTVAL exists_keyed_str(STRING *name)>
48 Returns whether a lexical C<name> exists in the hash.
50 =item C<PMC *get_pmc_keyed_str(STRING *name)>
52 =item C<PMC *get_pmc_keyed(PMC *name)>
54 Return the lexical with the given name, or NULL (not PMCNULL), if the
55 lexical doesn't exist.
57 =item C<void set_pmc_keyed(PMC *name, PMC *value)>
59 =item C<void set_pmc_keyed_str(STRING *name, PMC *value)>
61 Set the lexical with the given name to value. If the lexical name
62 doesn't exist, it is created.
64 =item C<METHOD PMC* get_lexinfo()>
66 Return the LexInfo PMC, if any or a Null PMC.
71 void init_pmc(PMC* lexinfo) {
72 if (VTABLE_elements(interp, lexinfo)) {
74 pmc_new_init(interp, enum_class_LexPad, lexinfo);
77 PMC_pmc_val(SELF) = NULL;
78 parrot_new_pmc_hash(interp, SELF);
79 PObj_custom_mark_destroy_SETALL(SELF);
82 void set_pointer(void* ctx) {
83 PMC *std_pad = PMC_pmc_val(SELF);
85 VTABLE_set_pointer(interp, std_pad, ctx);
88 VTABLE void destroy() {
89 if (PMC_struct_val(SELF)) {
90 parrot_hash_destroy(interp, (Hash*) PMC_struct_val(SELF));
91 PMC_struct_val(SELF) = NULL;
98 Marks the lexpad hash as live.
105 PMC *std_pad = PMC_pmc_val(SELF);
107 pobject_lives(interp, (PObj *)std_pad);
108 if (PMC_struct_val(SELF))
109 parrot_mark_hash(interp, (Hash *)PMC_struct_val(SELF));
112 PMC* get_pmc_keyed_str(STRING* name) {
113 HashBucket *b = parrot_hash_get_bucket(interp,
114 (Hash *)PMC_struct_val(SELF), name);
117 PMC *std_pad = PMC_pmc_val(SELF);
120 return VTABLE_get_pmc_keyed_str(interp, std_pad, name);
125 return (PMC *)b->value;
128 INTVAL exists_keyed_str(STRING* name) {
130 if (parrot_hash_exists(interp, (Hash*) PMC_struct_val(SELF), name))
132 std_pad = PMC_pmc_val(SELF);
134 return VTABLE_exists_keyed_str(interp, std_pad, name);
138 INTVAL exists_keyed(PMC* name) {
139 STRING *s = key_string(interp, name);
140 return SELF.exists_keyed_str(s);
143 PMC* get_pmc_keyed(PMC* name) {
144 STRING *s = key_string(interp, name);
145 return SELF.get_pmc_keyed_str(s);
148 void set_pmc_keyed_str(STRING* name, PMC* value) {
149 PMC *std_pad = PMC_pmc_val(SELF);
151 if (std_pad && VTABLE_exists_keyed_str(interp, std_pad, name))
152 VTABLE_set_pmc_keyed_str(interp, std_pad, name, value);
154 parrot_hash_put(interp, (Hash *)PMC_struct_val(SELF), name, value);
157 void set_pmc_keyed(PMC* name, PMC* value) {
158 STRING *s = key_string(interp, name);
159 SELF.set_pmc_keyed_str(s, value);
171 F<docs/pdds/pdd20_lexical_vars.pod>, F<src/pmc/lexpad.pmc>,
172 F<src/pmc/lexinfo.pmc>.
180 * c-file-style: "parrot"
182 * vim: expandtab shiftwidth=4: