1
1
#include "pmc_nqplexinfo.h"
2
2
#include "../6model/sixmodelobject.h"
3
3
4
+ /* Flag for indicating that we initialized the lexpad state. */
5
+ #define PObj_LEXPAD_STATE_INIT_FLAG PObj_private1_FLAG
6
+
4
7
/* Possible options for boxed primitives. */
5
8
#define STORAGE_SPEC_BP_NONE 0
6
9
#define STORAGE_SPEC_BP_INT 1
@@ -136,14 +139,16 @@ Return the LexInfo PMC, if any or a Null PMC.
136
139
if (!PMC_IS_NULL(static_slots_cache)) {
137
140
/* Yes, we have some. Grab values/flags too, then iterate. */
138
141
PMC *static_values_cache, *static_flags_cache;
142
+ PMC *state = NULL;
139
143
INTVAL num_statics = VTABLE_elements(interp, static_slots_cache);
140
- INTVAL i;
144
+ INTVAL i, had_state = 0 ;
141
145
GETATTR_NQPLexInfo_static_values_cache(INTERP, info, static_values_cache);
142
146
GETATTR_NQPLexInfo_static_flags_cache(INTERP, info, static_flags_cache);
143
147
for (i = 0; i < num_statics; i++) {
144
148
INTVAL slot = VTABLE_get_integer_keyed_int(interp, static_slots_cache, i);
145
149
PMC *value = VTABLE_get_pmc_keyed_int(interp, static_values_cache, i);
146
150
INTVAL flag = VTABLE_get_integer_keyed_int(interp, static_flags_cache, i);
151
+
147
152
switch (flag) {
148
153
case 0:
149
154
CTX_REG_PMC(interp, (PMC *)ctx, slot) = value;
@@ -155,6 +160,32 @@ Return the LexInfo PMC, if any or a Null PMC.
155
160
CTX_REG_PMC(interp, (PMC *)ctx, slot) = cont;
156
161
break;
157
162
}
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;
158
189
default:
159
190
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
160
191
"Unknown flag in NQPLexPad.set_pointer");
0 commit comments