2 Copyright (C) 2008, The Perl Foundation.
7 src/pmc/lexinfo.pmc - LexInfo PMC
11 These are the vtable functions for the lexinfo PMC.
21 #include "parrot/parrot.h"
25 * LexInfo contains a constant Hash with constant string
26 * keys and integer indices - no marking and no pmc_ext
27 * needed (except for freeze/thaw
30 pmclass LexInfo need_ext provides hash no_ro {
34 =item C<void class_init()>
36 Manipulate vtable->flags so that constant PMCs are created.
37 If your inherited LexInfo is not so constant, then don't
38 do that and provide a mark() method and set the custom_mark flag.
40 =item C<init_pmc(PMC *sub)>
42 Initialize the LexInfo PMC and remember the associate
51 /* there is no pmclass const_pmc flag yet */
53 interp->vtables[entry]->flags |= VTABLE_IS_CONST_PMC_FLAG;
58 real_exception(INTERP, NULL, INVALID_OPERATION,
59 "Cannot create a LexInfo PMC without an initializer");
62 VTABLE void init_pmc(PMC *sub) {
63 PARROT_ASSERT(PObj_constant_TEST(SELF));
64 PMC_pmc_val(SELF) = sub;
66 parrot_new_pmc_hash_x(SELF,
67 (PARROT_DATA_TYPE)enum_hash_int,
69 (hash_comp_fn)string_equal, /* STRING compare */
70 (hash_hash_key_fn)string_hash); /* hash */
72 PObj_active_destroy_SET(SELF);
77 =item C<void destroy()>
79 Frees any malloced memory held by this PMC.
86 if (PMC_struct_val(SELF))
87 parrot_hash_destroy(INTERP, (Hash *)PMC_struct_val(SELF));
92 =item C<void declare_lex_preg(STRING *name, INTVAL preg)>
94 Declare a lexical variable that is an alias for a PMC register. The PIR
95 compiler calls this method in response to a ".lex STRING, PREG" directive.
97 =item C<INTVAL elements()>
99 Returns the number of elements in the LexInfo hash.
105 METHOD declare_lex_preg(STRING *name, INTVAL preg) {
106 parrot_hash_put(INTERP, (Hash*)PMC_struct_val(SELF), name, (void*)preg);
109 VTABLE INTVAL elements() {
110 return parrot_hash_size(INTERP, (Hash *)PMC_struct_val(SELF));
115 =item C<void visit(visit_info *info)>
117 =item C<void freeze(visit_info *info)>
119 =item C<void thaw(visit_info *info)>
121 Freeze/thaw interface used during freeze/thaw of the Sub PMC.
122 The implementation of the Hash PMC is called.
128 VTABLE void visit(visit_info *info) {
129 Parrot_Hash_visit(INTERP, SELF, info);
132 VTABLE void freeze(visit_info *info) {
133 Parrot_Hash_freeze(INTERP, SELF, info);
136 VTABLE void thaw(visit_info *info) {
137 IMAGE_IO * const io = info->image_io;
139 if (info->extra_flags == EXTRA_IS_NULL) {
140 const INTVAL elems = VTABLE_shift_integer(INTERP, io);
141 const INTVAL k_type = VTABLE_shift_integer(INTERP, io);
142 const INTVAL v_type = VTABLE_shift_integer(INTERP, io);
148 PARROT_ASSERT(v_type == enum_hash_int);
149 /* TODO make a better interface for hash creation
150 * TODO create hash with needed types in the first place
154 hash = (Hash *)PMC_struct_val(SELF);
155 hash->entries = elems;
170 F<docs/pdds/pdd20_lexical_vars.pod>, F<src/classes/lexpad.pmc>.
178 * c-file-style: "parrot"
180 * vim: expandtab shiftwidth=4: