Skip to content

Commit 94e55ed

Browse files
committed
Work around Parrot's nuts keys implementation. This means the getting/setting keys in the capture bit now seems to work well, which gets us to the next error, which is just that NQPCapture needs some more implementation effort (exists). Also will need to make those v-tables overridable.
1 parent a484ca8 commit 94e55ed

File tree

1 file changed

+41
-25
lines changed

1 file changed

+41
-25
lines changed

src/pmc/rakudoobject.pmc

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,28 @@ pmclass RakudoObject manual_attrs dynpmc group nqp {
120120
}
121121

122122
VTABLE PMC * get_pmc_keyed(PMC *key) {
123-
PMC **vt = STABLE(SELF)->parrot_vtable_mapping;
124-
PMC *meth;
125-
if (vt && !PMC_IS_NULL(meth = vt[PARROT_VTABLE_SLOT_GET_PMC_KEYED])) {
126-
PMC *old_ctx = Parrot_pcc_get_signature(interp, CURRENT_CONTEXT(interp));
127-
PMC *cappy = Parrot_pmc_new(interp, enum_class_CallContext);
128-
VTABLE_push_pmc(interp, cappy, SELF);
129-
VTABLE_push_pmc(interp, cappy, key);
130-
Parrot_pcc_invoke_from_sig_object(interp, meth, cappy);
131-
cappy = Parrot_pcc_get_signature(interp, CURRENT_CONTEXT(interp));
132-
Parrot_pcc_set_signature(interp, CURRENT_CONTEXT(interp), old_ctx);
133-
return VTABLE_get_pmc_keyed_int(interp, cappy, 0);
123+
if (key->vtable->base_type == enum_class_Key) {
124+
if (PObj_get_FLAGS(key) & KEY_integer_FLAG)
125+
return SELF.get_pmc_keyed_int(VTABLE_get_integer(interp, key));
126+
else
127+
return SELF.get_pmc_keyed_str(VTABLE_get_string(interp, key));
128+
}
129+
else {
130+
PMC **vt = STABLE(SELF)->parrot_vtable_mapping;
131+
PMC *meth;
132+
if (vt && !PMC_IS_NULL(meth = vt[PARROT_VTABLE_SLOT_GET_PMC_KEYED])) {
133+
PMC *old_ctx = Parrot_pcc_get_signature(interp, CURRENT_CONTEXT(interp));
134+
PMC *cappy = Parrot_pmc_new(interp, enum_class_CallContext);
135+
VTABLE_push_pmc(interp, cappy, SELF);
136+
VTABLE_push_pmc(interp, cappy, key);
137+
Parrot_pcc_invoke_from_sig_object(interp, meth, cappy);
138+
cappy = Parrot_pcc_get_signature(interp, CURRENT_CONTEXT(interp));
139+
Parrot_pcc_set_signature(interp, CURRENT_CONTEXT(interp), old_ctx);
140+
return VTABLE_get_pmc_keyed_int(interp, cappy, 0);
141+
}
142+
else
143+
return SUPER(key);
134144
}
135-
else
136-
return SUPER(key);
137145
}
138146

139147
VTABLE PMC * get_pmc_keyed_int(INTVAL key) {
@@ -171,19 +179,27 @@ pmclass RakudoObject manual_attrs dynpmc group nqp {
171179
}
172180

173181
VTABLE void set_pmc_keyed(PMC *key, PMC *value) {
174-
PMC **vt = STABLE(SELF)->parrot_vtable_mapping;
175-
PMC *meth;
176-
if (vt && !PMC_IS_NULL(meth = vt[PARROT_VTABLE_SLOT_SET_PMC_KEYED])) {
177-
PMC *old_ctx = Parrot_pcc_get_signature(interp, CURRENT_CONTEXT(interp));
178-
PMC *cappy = Parrot_pmc_new(interp, enum_class_CallContext);
179-
VTABLE_push_pmc(interp, cappy, SELF);
180-
VTABLE_push_pmc(interp, cappy, key);
181-
VTABLE_push_pmc(interp, cappy, value);
182-
Parrot_pcc_invoke_from_sig_object(interp, meth, cappy);
183-
Parrot_pcc_set_signature(interp, CURRENT_CONTEXT(interp), old_ctx);
182+
if (key->vtable->base_type == enum_class_Key) {
183+
if (PObj_get_FLAGS(key) & KEY_integer_FLAG)
184+
SELF.set_pmc_keyed_int(VTABLE_get_integer(interp, key), value);
185+
else
186+
SELF.set_pmc_keyed_str(VTABLE_get_string(interp, key), value);
187+
}
188+
else {
189+
PMC **vt = STABLE(SELF)->parrot_vtable_mapping;
190+
PMC *meth;
191+
if (vt && !PMC_IS_NULL(meth = vt[PARROT_VTABLE_SLOT_SET_PMC_KEYED])) {
192+
PMC *old_ctx = Parrot_pcc_get_signature(interp, CURRENT_CONTEXT(interp));
193+
PMC *cappy = Parrot_pmc_new(interp, enum_class_CallContext);
194+
VTABLE_push_pmc(interp, cappy, SELF);
195+
VTABLE_push_pmc(interp, cappy, key);
196+
VTABLE_push_pmc(interp, cappy, value);
197+
Parrot_pcc_invoke_from_sig_object(interp, meth, cappy);
198+
Parrot_pcc_set_signature(interp, CURRENT_CONTEXT(interp), old_ctx);
199+
}
200+
else
201+
SUPER(key, value);
184202
}
185-
else
186-
SUPER(key, value);
187203
}
188204

189205
VTABLE void set_pmc_keyed_int(INTVAL key, PMC *value) {

0 commit comments

Comments
 (0)