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"
23 /* included manually to prevent breaking C++ builds -- see RT #56534*/
27 * LexInfo contains a constant Hash with constant string
28 * keys and integer indices - no marking and no pmc_ext
29 * needed (except for freeze/thaw
32 pmclass LexInfo need_ext provides hash no_ro {
36 =item C<void class_init()>
38 Manipulate vtable->flags so that constant PMCs are created.
39 If your inherited LexInfo is not so constant, then don't
40 do that and provide a mark() method and set the custom_mark flag.
42 =item C<init_pmc(PMC *sub)>
44 Initialize the LexInfo PMC and remember the associate
53 /* there is no pmclass const_pmc flag yet */
55 interp->vtables[entry]->flags |= VTABLE_IS_CONST_PMC_FLAG;
60 real_exception(INTERP, NULL, INVALID_OPERATION,
61 "Cannot create a LexInfo PMC without an initializer");
64 VTABLE void init_pmc(PMC *sub) {
65 PARROT_ASSERT(PObj_constant_TEST(SELF));
66 PMC_pmc_val(SELF) = sub;
68 parrot_new_pmc_hash_x(SELF,
69 (PARROT_DATA_TYPE)enum_hash_int,
71 (hash_comp_fn)string_equal, /* STRING compare */
72 (hash_hash_key_fn)string_hash); /* hash */
74 PObj_active_destroy_SET(SELF);
79 =item C<void destroy()>
81 Frees any malloced memory held by this PMC.
88 if (PMC_struct_val(SELF))
89 parrot_hash_destroy(INTERP, (Hash *)PMC_struct_val(SELF));
94 =item C<void declare_lex_preg(STRING *name, INTVAL preg)>
96 Declare a lexical variable that is an alias for a PMC register. The PIR
97 compiler calls this method in response to a ".lex STRING, PREG" directive.
99 =item C<INTVAL elements()>
101 Returns the number of elements in the LexInfo hash.
107 METHOD declare_lex_preg(STRING *name, INTVAL preg) {
108 parrot_hash_put(INTERP, (Hash*)PMC_struct_val(SELF), name, (void*)preg);
111 VTABLE INTVAL elements() {
112 return parrot_hash_size(INTERP, (Hash *)PMC_struct_val(SELF));
117 =item C<void visit(visit_info *info)>
119 =item C<void freeze(visit_info *info)>
121 =item C<void thaw(visit_info *info)>
123 Freeze/thaw interface used during freeze/thaw of the Sub PMC.
124 The implementation of the Hash PMC is called.
130 VTABLE void visit(visit_info *info) {
131 Parrot_Hash_visit(INTERP, SELF, info);
134 VTABLE void freeze(visit_info *info) {
135 Parrot_Hash_freeze(INTERP, SELF, info);
138 VTABLE void thaw(visit_info *info) {
139 IMAGE_IO * const io = info->image_io;
141 if (info->extra_flags == EXTRA_IS_NULL) {
142 const INTVAL elems = VTABLE_shift_integer(INTERP, io);
143 const INTVAL k_type = VTABLE_shift_integer(INTERP, io);
144 const INTVAL v_type = VTABLE_shift_integer(INTERP, io);
150 PARROT_ASSERT(v_type == enum_hash_int);
151 /* TODO make a better interface for hash creation
152 * TODO create hash with needed types in the first place
156 hash = (Hash *)PMC_struct_val(SELF);
157 hash->entries = elems;
172 F<docs/pdds/pdd20_lexical_vars.pod>, F<src/classes/lexpad.pmc>.
180 * c-file-style: "parrot"
182 * vim: expandtab shiftwidth=4: