Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Provide a way to set a static value into a lexpad explicitly, and to …
…indicate when all static values are set.
  • Loading branch information
jnthn committed Mar 6, 2011
1 parent d36a4cd commit 94fc85c
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/pmc/nqplexinfo.pmc
Expand Up @@ -77,6 +77,43 @@ compiler calls this method in response to a ".lex STRING, PREG" directive.
GET_ATTR_name_to_register_map(INTERP, SELF, name_to_register_map);
VTABLE_set_integer_keyed_str(INTERP, name_to_register_map, name, preg);
}

METHOD set_static_lexpad_value(STRING *key, PMC *value) {
/* Stash static value in hash. */
PMC *svs;
GET_ATTR_static_values(INTERP, SELF, svs);
if (PMC_IS_NULL(svs)) {
svs = pmc_new(interp, enum_class_Hash);
SET_ATTR_static_values(INTERP, SELF, svs);
}
VTABLE_set_pmc_keyed_str(interp, svs, key, value);
}

METHOD finish_static_lexpad() {
/* Build caches from the static lexpad. */
PMC *svs;
GET_ATTR_static_values(INTERP, SELF, svs);
if (PMC_IS_NULL(svs) || !VTABLE_elements(interp, svs)) {
/* No values; clear caches. */
SET_ATTR_static_slots_cache(INTERP, SELF, PMCNULL);
SET_ATTR_static_values_cache(INTERP, SELF, PMCNULL);
}
else {
/* Build caches. */
PMC *slots = pmc_new(interp, enum_class_ResizableIntegerArray);
PMC *values = pmc_new(interp, enum_class_ResizablePMCArray);
PMC *iter = VTABLE_get_iter(interp, svs);
while (VTABLE_get_bool(interp, iter)) {
STRING *name = VTABLE_shift_string(interp, iter);
INTVAL slot = VTABLE_get_integer_keyed_str(interp, SELF, name);
PMC *value = VTABLE_get_pmc_keyed_str(interp, svs, name);
VTABLE_push_integer(interp, slots, slot);
VTABLE_push_pmc(interp, values, value);
}
SET_ATTR_static_slots_cache(INTERP, SELF, slots);
SET_ATTR_static_values_cache(INTERP, SELF, values);
}
}

/*

Expand Down

0 comments on commit 94fc85c

Please sign in to comment.