Skip to content

Commit dd13f30

Browse files
committed
Ensure that NQPLexPad can cope with a Parrot LexInfo as well as an NQPLexInfo.
1 parent a694c40 commit dd13f30

File tree

2 files changed

+46
-24
lines changed

2 files changed

+46
-24
lines changed

src/pmc/nqplexinfo.pmc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ pmclass NQPLexInfo
5858
Parrot_gc_mark_PMC_alive(INTERP, static_values_cache);
5959
}
6060

61+
VTABLE INTVAL elements() {
62+
PMC *name_to_register_map;
63+
GET_ATTR_name_to_register_map(INTERP, SELF, name_to_register_map);
64+
return VTABLE_elements(interp, name_to_register_map);
65+
}
66+
6167
VTABLE INTVAL get_integer_keyed_str(STRING *key) {
6268
PMC *name_to_register_map;
6369
GET_ATTR_name_to_register_map(INTERP, SELF, name_to_register_map);

src/pmc/nqplexpad.pmc

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,41 +72,47 @@ Return the LexInfo PMC, if any or a Null PMC.
7272

7373
VTABLE void set_pointer(void *ctx) {
7474
/* Check if we need to put any static values in place. */
75-
PMC *info, *static_slots_cache;
75+
PMC *info;
7676
GET_ATTR_lexinfo(INTERP, SELF, info);
77-
GETATTR_NQPLexInfo_static_slots_cache(INTERP, info, static_slots_cache);
78-
if (!PMC_IS_NULL(static_slots_cache)) {
79-
/* Yes, we have some. Grab values too, then iterate. */
80-
PMC *static_values_cache;
81-
INTVAL num_statics = VTABLE_elements(interp, static_slots_cache);
82-
INTVAL i;
83-
GETATTR_NQPLexInfo_static_values_cache(INTERP, info, static_values_cache);
84-
for (i = 0; i < num_statics; i++) {
85-
INTVAL slot = VTABLE_get_integer_keyed_int(interp, static_slots_cache, i);
86-
PMC *value = VTABLE_get_pmc_keyed_int(interp, static_values_cache, i);
87-
CTX_REG_PMC((PMC *)ctx, slot) = value;
77+
if (info->vtable->base_type != enum_class_LexInfo) {
78+
PMC *static_slots_cache;
79+
GETATTR_NQPLexInfo_static_slots_cache(INTERP, info, static_slots_cache);
80+
if (!PMC_IS_NULL(static_slots_cache)) {
81+
/* Yes, we have some. Grab values too, then iterate. */
82+
PMC *static_values_cache;
83+
INTVAL num_statics = VTABLE_elements(interp, static_slots_cache);
84+
INTVAL i;
85+
GETATTR_NQPLexInfo_static_values_cache(INTERP, info, static_values_cache);
86+
for (i = 0; i < num_statics; i++) {
87+
INTVAL slot = VTABLE_get_integer_keyed_int(interp, static_slots_cache, i);
88+
PMC *value = VTABLE_get_pmc_keyed_int(interp, static_values_cache, i);
89+
CTX_REG_PMC((PMC *)ctx, slot) = value;
90+
}
91+
PARROT_GC_WRITE_BARRIER(INTERP, (PMC *)ctx);
8892
}
89-
PARROT_GC_WRITE_BARRIER(INTERP, (PMC *)ctx);
9093
}
9194

9295
/* Stash the context pointer. */
9396
SET_ATTR_ctx(INTERP, SELF, (PMC *)ctx);
9497
}
9598

9699
VTABLE INTVAL elements() {
97-
PMC *info, *name_map;
100+
PMC *info;
98101
GET_ATTR_lexinfo(INTERP, SELF, info);
99-
GETATTR_NQPLexInfo_name_to_register_map(INTERP, info, name_map);
100-
return Parrot_hash_size(INTERP,
101-
(Hash *)VTABLE_get_pointer(INTERP, name_map));
102+
return VTABLE_elements(interp, info);
102103
}
103104

104105
VTABLE INTVAL exists_keyed_str(STRING *name) {
105106
PMC *info, *name_map;
106107
const Hash *hash;
107108
GET_ATTR_lexinfo(INTERP, SELF, info);
108-
GETATTR_NQPLexInfo_name_to_register_map(INTERP, info, name_map);
109-
hash = (const Hash *)VTABLE_get_pointer(INTERP, name_map);
109+
if (info->vtable->base_type != enum_class_LexInfo) {
110+
GETATTR_NQPLexInfo_name_to_register_map(INTERP, info, name_map);
111+
hash = (const Hash *)VTABLE_get_pointer(INTERP, name_map);
112+
}
113+
else {
114+
hash = (const Hash *)VTABLE_get_pointer(INTERP, info);
115+
}
110116

111117
return hash->entries
112118
? (Parrot_hash_get_bucket(INTERP, hash, name) != 0)
@@ -125,8 +131,13 @@ Return the LexInfo PMC, if any or a Null PMC.
125131
HashBucket *b;
126132

127133
GET_ATTR_lexinfo(INTERP, SELF, info);
128-
GETATTR_NQPLexInfo_name_to_register_map(INTERP, info, name_map);
129-
hash = (const Hash *)VTABLE_get_pointer(INTERP, name_map);
134+
if (info->vtable->base_type != enum_class_LexInfo) {
135+
GETATTR_NQPLexInfo_name_to_register_map(INTERP, info, name_map);
136+
hash = (const Hash *)VTABLE_get_pointer(INTERP, name_map);
137+
}
138+
else {
139+
hash = (const Hash *)VTABLE_get_pointer(INTERP, info);
140+
}
130141

131142
if (!hash->entries)
132143
return PMCNULL;
@@ -152,10 +163,15 @@ Return the LexInfo PMC, if any or a Null PMC.
152163
HashBucket * b;
153164

154165
GET_ATTR_lexinfo(INTERP, SELF, info);
155-
GETATTR_NQPLexInfo_name_to_register_map(INTERP, info, name_map);
156-
hash = (const Hash *)VTABLE_get_pointer(INTERP, name_map);
166+
if (info->vtable->base_type != enum_class_LexInfo) {
167+
GETATTR_NQPLexInfo_name_to_register_map(INTERP, info, name_map);
168+
hash = (const Hash *)VTABLE_get_pointer(INTERP, name_map);
169+
}
170+
else {
171+
hash = (const Hash *)VTABLE_get_pointer(INTERP, info);
172+
}
173+
157174
b = Parrot_hash_get_bucket(INTERP, hash, name);
158-
159175
if (!b)
160176
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_LEX_NOT_FOUND,
161177
"Lexical '%Ss' not found", name);

0 commit comments

Comments
 (0)