Skip to content

Commit 94fc85c

Browse files
committed
Provide a way to set a static value into a lexpad explicitly, and to indicate when all static values are set.
1 parent d36a4cd commit 94fc85c

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/pmc/nqplexinfo.pmc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,43 @@ compiler calls this method in response to a ".lex STRING, PREG" directive.
7777
GET_ATTR_name_to_register_map(INTERP, SELF, name_to_register_map);
7878
VTABLE_set_integer_keyed_str(INTERP, name_to_register_map, name, preg);
7979
}
80+
81+
METHOD set_static_lexpad_value(STRING *key, PMC *value) {
82+
/* Stash static value in hash. */
83+
PMC *svs;
84+
GET_ATTR_static_values(INTERP, SELF, svs);
85+
if (PMC_IS_NULL(svs)) {
86+
svs = pmc_new(interp, enum_class_Hash);
87+
SET_ATTR_static_values(INTERP, SELF, svs);
88+
}
89+
VTABLE_set_pmc_keyed_str(interp, svs, key, value);
90+
}
91+
92+
METHOD finish_static_lexpad() {
93+
/* Build caches from the static lexpad. */
94+
PMC *svs;
95+
GET_ATTR_static_values(INTERP, SELF, svs);
96+
if (PMC_IS_NULL(svs) || !VTABLE_elements(interp, svs)) {
97+
/* No values; clear caches. */
98+
SET_ATTR_static_slots_cache(INTERP, SELF, PMCNULL);
99+
SET_ATTR_static_values_cache(INTERP, SELF, PMCNULL);
100+
}
101+
else {
102+
/* Build caches. */
103+
PMC *slots = pmc_new(interp, enum_class_ResizableIntegerArray);
104+
PMC *values = pmc_new(interp, enum_class_ResizablePMCArray);
105+
PMC *iter = VTABLE_get_iter(interp, svs);
106+
while (VTABLE_get_bool(interp, iter)) {
107+
STRING *name = VTABLE_shift_string(interp, iter);
108+
INTVAL slot = VTABLE_get_integer_keyed_str(interp, SELF, name);
109+
PMC *value = VTABLE_get_pmc_keyed_str(interp, svs, name);
110+
VTABLE_push_integer(interp, slots, slot);
111+
VTABLE_push_pmc(interp, values, value);
112+
}
113+
SET_ATTR_static_slots_cache(INTERP, SELF, slots);
114+
SET_ATTR_static_values_cache(INTERP, SELF, values);
115+
}
116+
}
80117

81118
/*
82119

0 commit comments

Comments
 (0)