/
lexinfo.pmc
132 lines (84 loc) · 2.58 KB
/
lexinfo.pmc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
Copyright (C) 2008-2010, Parrot Foundation.
$Id$
=head1 NAME
src/pmc/lexinfo.pmc - LexInfo PMC
=head1 DESCRIPTION
These are the vtable functions for the lexinfo PMC.
=head2 Functions
=over 4
=cut
*/
#include "pmc/pmc_hash.h"
/* HEADERIZER HFILE: none */
/* HEADERIZER BEGIN: static */
/* HEADERIZER END: static */
/*
* LexInfo contains a constant Hash with constant string
* keys and integer indices
*/
pmclass LexInfo extends Hash provides hash no_ro auto_attrs {
/*
=item C<void class_init()>
Manipulate vtable->flags so that constant PMCs are created.
If your inherited LexInfo is not so constant, then don't
do that and provide a mark() method and set the custom_mark flag.
=item C<init_pmc(PMC *sub)>
Initialize the LexInfo PMC and remember the associate
subroutine.
=cut
*/
void class_init() {
/* there is no pmclass const_pmc flag yet */
INTERP->vtables[entry]->flags |= VTABLE_IS_CONST_PMC_FLAG;
}
VTABLE void init() {
SELF.init_pmc(PMCNULL);
}
VTABLE void init_pmc(PMC *sub) {
PARROT_ASSERT(PObj_constant_TEST(SELF));
/* Set value type to INTVAL */
SELF.init_int((INTVAL)enum_type_INTVAL);
PObj_custom_mark_destroy_SETALL(SELF);
}
/*
=item C<void declare_lex_preg(STRING *name, INTVAL preg)>
Declare a lexical variable that is an alias for a PMC register. The PIR
compiler calls this method in response to a ".lex STRING, PREG" directive.
=cut
*/
METHOD declare_lex_preg(STRING *name, INTVAL preg) {
VTABLE_set_integer_keyed_str(INTERP, SELF, name, preg);
}
/*
=item C<PMC *inspect_str(STRING *what)>
Introspects this LexInfo structure. The only valid introspection key is
C<symbols>, which gets an array of the names of the symbols in this lexpad.
=cut
*/
VTABLE PMC *inspect_str(STRING *what) {
if (STRING_equal(INTERP, what, CONST_STRING(INTERP, "symbols"))) {
PMC * const result = Parrot_pmc_new(INTERP, enum_class_ResizableStringArray);
const Hash *hash = (Hash *)SELF.get_pointer();
parrot_hash_iterate(hash,
PARROT_ASSERT(_bucket->key);
VTABLE_push_string(INTERP, result, (STRING *)_bucket->key););
return result;
}
else
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
"Unknown introspection value '%S'", what);
}
}
/*
=back
=head1 SEE ALSO
F<docs/pdds/pdd20_lexical_vars.pod>, F<src/classes/lexpad.pmc>.
=cut
*/
/*
* Local variables:
* c-file-style: "parrot"
* End:
* vim: expandtab shiftwidth=4:
*/