/
lexpad.pmc
164 lines (114 loc) · 3.41 KB
/
lexpad.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
Copyright (C) 2005, The Perl Foundation.
$Id$
=head1 NAME
src/pmc/lexpad.pmc - LexPad PMC
=head1 DESCRIPTION
These are the vtable functions for the lexpad PMC.
=head2 Functions
=over 4
=cut
*/
#include "parrot/parrot.h"
#include <assert.h>
/*
* LexPad provides a Hash interface for lexical fetch/store
* needed
*
* struct_val ... parrot_context_t *ctx
* pmc_val ... LexInfo
*/
pmclass LexPad does hash no_ro {
void init() {
real_exception(INTERP, NULL, INVALID_OPERATION,
"don't create me like this");
}
/*
=item C<init_pmc(PMC *lexinfo)>
Initialize the LexPad PMC and remember the associate
lexinfo.
=item C<void set_pointer(void *)>
Initialize the LexPad PMC and remember the associate context.
=item C<INTVAL elements()>
Returns the number of elements in the hash.
=item C<INTVAL exists_keyed(PMC *name)>
=item C<INTVAL exists_keyed_str(STRING *name)>
Returns whether a lexical C<name> exists in the hash.
=item C<PMC *get_pmc_keyed_str(STRING *name)>
=item C<PMC *get_pmc_keyed(PMC *name)>
Return the lexical with the given name, or NULL (not PMCNULL), if the
lexical doesn't exist.
=item C<void set_pmc_keyed(PMC *name, PMC *value)>
=item C<void set_pmc_keyed_str(STRING *name, PMC *value)>
Set the lexical with the given name to value. If the lexical name
doesn't exist, it is created.
=item C<METHOD PMC* get_lexinfo()>
Return the LexInfo PMC, if any or a Null PMC.
=cut
*/
void init_pmc(PMC* lexinfo) {
PMC_pmc_val(SELF) = lexinfo;
}
void set_pointer(void* ctx) {
PMC_struct_val(SELF) = ctx;
}
INTVAL elements() {
PMC *info = PMC_pmc_val(SELF);
return parrot_hash_size(INTERP, PMC_struct_val(info));
}
INTVAL exists_keyed_str(STRING* name) {
PMC *info = PMC_pmc_val(SELF);
return parrot_hash_get_bucket(INTERP,
(Hash*) PMC_struct_val(info), name) != 0;
}
INTVAL exists_keyed(PMC* name) {
STRING *s = key_string(INTERP, name);
return SELF.exists_keyed_str(s);
}
PMC* get_pmc_keyed_str(STRING* name) {
PMC *info = PMC_pmc_val(SELF);
Hash *hash = PMC_struct_val(info);
parrot_context_t *ctx = PMC_struct_val(SELF);
HashBucket *b = parrot_hash_get_bucket(INTERP, hash, name);
INTVAL regno;
if (!b)
return NULL;
regno = (INTVAL) b->value;
return CTX_REG_PMC(ctx, regno);
}
PMC* get_pmc_keyed(PMC* name) {
STRING *s = key_string(INTERP, name);
return SELF.get_pmc_keyed_str(s);
}
void set_pmc_keyed_str(STRING* name, PMC* value) {
PMC *info = PMC_pmc_val(SELF);
Hash *hash = PMC_struct_val(info);
parrot_context_t *ctx = PMC_struct_val(SELF);
HashBucket *b = parrot_hash_get_bucket(INTERP, hash, name);
INTVAL regno;
if (!b)
real_exception(interp, NULL, LEX_NOT_FOUND,
"Lexical '%Ss' not found", name);
regno = (INTVAL) b->value;
CTX_REG_PMC(ctx, regno) = value;
}
void set_pmc_keyed(PMC* name, PMC* value) {
STRING *s = key_string(INTERP, name);
SELF.set_pmc_keyed_str(s, value);
}
METHOD PMC* get_lexinfo() {
return PMC_pmc_val(SELF);
}
}
/*
=back
=head1 SEE ALSO
F<docs/pdds/pdd20_lecical_vars.pod>, F<src/pmc/lexinfo.pmc>.
=cut
*/
/*
* Local variables:
* c-file-style: "parrot"
* End:
* vim: expandtab shiftwidth=4:
*/