Skip to content

Commit 07fa71f

Browse files
committed
Add state variable support to NQPLexPad.
1 parent c6a5294 commit 07fa71f

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/vm/parrot/pmc/nqplexpad.pmc

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include "pmc_nqplexinfo.h"
22
#include "../6model/sixmodelobject.h"
33

4+
/* Flag for indicating that we initialized the lexpad state. */
5+
#define PObj_LEXPAD_STATE_INIT_FLAG PObj_private1_FLAG
6+
47
/* Possible options for boxed primitives. */
58
#define STORAGE_SPEC_BP_NONE 0
69
#define STORAGE_SPEC_BP_INT 1
@@ -136,14 +139,16 @@ Return the LexInfo PMC, if any or a Null PMC.
136139
if (!PMC_IS_NULL(static_slots_cache)) {
137140
/* Yes, we have some. Grab values/flags too, then iterate. */
138141
PMC *static_values_cache, *static_flags_cache;
142+
PMC *state = NULL;
139143
INTVAL num_statics = VTABLE_elements(interp, static_slots_cache);
140-
INTVAL i;
144+
INTVAL i, had_state = 0;
141145
GETATTR_NQPLexInfo_static_values_cache(INTERP, info, static_values_cache);
142146
GETATTR_NQPLexInfo_static_flags_cache(INTERP, info, static_flags_cache);
143147
for (i = 0; i < num_statics; i++) {
144148
INTVAL slot = VTABLE_get_integer_keyed_int(interp, static_slots_cache, i);
145149
PMC *value = VTABLE_get_pmc_keyed_int(interp, static_values_cache, i);
146150
INTVAL flag = VTABLE_get_integer_keyed_int(interp, static_flags_cache, i);
151+
147152
switch (flag) {
148153
case 0:
149154
CTX_REG_PMC(interp, (PMC *)ctx, slot) = value;
@@ -155,6 +160,32 @@ Return the LexInfo PMC, if any or a Null PMC.
155160
CTX_REG_PMC(interp, (PMC *)ctx, slot) = cont;
156161
break;
157162
}
163+
case 2: {
164+
if (!state) {
165+
PMC *sub = Parrot_pcc_get_sub(interp, (PMC *)ctx);
166+
state = Parrot_pmc_getprop(interp, sub, CONST_STRING(interp, "state_vars"));
167+
if (PMC_IS_NULL(state)) {
168+
state = Parrot_pmc_new(interp, enum_class_ResizablePMCArray);
169+
Parrot_pmc_getprop(interp, sub, CONST_STRING(interp, "state_vars"), state);
170+
had_state = 0;
171+
PObj_flag_SET(LEXPAD_STATE_INIT, (PMC *)ctx);
172+
}
173+
else {
174+
had_state = 1;
175+
}
176+
}
177+
if (had_state) {
178+
CTX_REG_PMC(interp, (PMC *)ctx, slot) = VTABLE_get_pmc_keyed_int(interp, state, i);
179+
}
180+
else {
181+
PMC *cont = REPR(value)->allocate(interp, STABLE(value));
182+
REPR(value)->copy_to(interp, STABLE(value), OBJECT_BODY(value), OBJECT_BODY(cont));
183+
PARROT_GC_WRITE_BARRIER(INTERP, cont);
184+
VTABLE_set_pmc_keyed_int(interp, state, i, cont);
185+
CTX_REG_PMC(interp, (PMC *)ctx, slot) = cont;
186+
}
187+
}
188+
break;
158189
default:
159190
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
160191
"Unknown flag in NQPLexPad.set_pointer");

0 commit comments

Comments
 (0)