return data;
}
+/* Return whether or not the judgment is the conclusion of the rule. */
bool
conclusion_p(struct rule *rule, struct judgment *judgment)
{
return judgment == rule->conclusion ? TRUE : FALSE;
}
+/*
+ * Remove entries with contextual scope. This is the end of the line for
+ * variables.
+ */
void
clear_contextuals(GHashTable *temporaries)
{
}
}
+/*
+ * Remove all temporaries and generic contexts/theses. This is the end of the
+ * line for both contextual and local names.
+ */
void
clear_locals(struct state *state)
{
g_hash_table_steal_all(state->temporaries);
}
+/*
+ * List all names involved (origin or replacement) in the reference,
+ * recursively.
+ */
GSList *
-reference_list_type_names(GSList *list, struct reference *ref)
+list_reference_type_names(GSList *list, struct reference *ref)
{
GSList *l;
list = g_slist_prepend(list, ref->origin);
l = ref->replacements;
while (l) {
- list = reference_list_type_names(list, l->data);
+ list = list_reference_type_names(list, l->data);
l = l->next;
}
return list;
}
+/*
+ * List all names involved (origin or through a reference — see
+ * `list_reference_type_name') in the wrap, recursively.
+ */
GSList *
-wrap_list_type_names(GSList *list, struct wrap *wrap)
+list_wrap_names(GSList *list, struct wrap *wrap)
{
+ if (!wrap)
+ return NULL;
if (wrap->is_origin)
list = g_slist_prepend(list, wrap->ptr);
else
- list = reference_list_type_names(list, wrap->ptr);
+ list = list_reference_type_names(list, wrap->ptr);
return list;
}
* type's dependencies first then the element's dependencies)
*/
GSList *
-list_dependencies(struct name *ptr, GHashTable *temporaries,
- GSList *type_names)
+list_dependencies(struct name *ptr, GHashTable *temporaries)
{
- GSList *deps, *types, *l, *prev;
+ GSList *deps, *types, *l, *prev, *type_names;
GHashTableIter iter;
gpointer key, value;
struct name *name;
deps = NULL;
+ type_names = !ptr ? NULL : list_wrap_names(NULL, ptr->type);
g_hash_table_iter_init(&iter, temporaries);
while (g_hash_table_iter_next(&iter, &key, &value)) {
name = value;
if (name != ptr && !g_slist_find(type_names, name))
deps = g_slist_prepend(deps, name);
}
+ g_slist_free(g_steal_pointer(&type_names));
/* Remove names that are types of other names in the dependency list. */
prev = NULL;
return deps;
}
+void
+insert_name(GHashTable *temporaries, struct name *name)
+{
+ if (name->scope != scope_global)
+ g_hash_table_insert(temporaries, name->str, name);
+}
+
void
next_slot(struct state *state)
{
GSList *l;
- struct name *name;
+ struct name *name, *ptr;
+ struct wrap *wrap;
switch (state->st) {
case slot_type_rule_dots:
state->st = slot_type_ctx_dots;
state->caret += 1;
name = (struct name *)g_slist_last(state->judgment->vdecls)->data;
- g_hash_table_insert(state->temporaries, name->str, name);
- if (name->type->is_origin) {
- name = name->type->ptr;
- g_hash_table_insert(state->temporaries, name->str, name);
- }
+ insert_name(state->temporaries, name);
+ if (name->type->is_origin)
+ insert_name(state->temporaries, name->type->ptr);
break;
case slot_type_ctx_dots:
state->st = slot_type_ctx_r;
else
state->st = slot_type_rule_dots;
state->caret += 1;
- if (state->judgment->a->is_origin) {
- name = state->judgment->a->ptr;
- if (name->scope != scope_global)
- g_hash_table_insert(state->temporaries, name->str, name);
- }
+ if (state->judgment->a->is_origin)
+ insert_name(state->temporaries, state->judgment->a->ptr);
clear_contextuals(state->temporaries);
break;
case slot_type_element_thesis_element:
else
state->st = slot_type_rule_dots;
state->caret += 1;
- if (state->judgment->a->is_origin)
- name = state->judgment->a->ptr;
- else
- name = ((struct reference *)state->judgment->a->ptr)->origin;
+ name = get_wrap_name(state->judgment->a);
if (state->judgment->a->is_origin) {
- l = wrap_list_type_names(NULL, name->type);
- name->dependencies = list_dependencies(name, state->temporaries, l);
- g_slist_free(g_steal_pointer(&l));
- if (name->scope != scope_global)
- g_hash_table_insert(state->temporaries, name->str, name);
- }
- if (name->type->is_origin) {
- name = name->type->ptr;
- g_hash_table_insert(state->temporaries, name->str, name);
+ name->dependencies = list_dependencies(name, state->temporaries);
+ insert_name(state->temporaries, name);
}
+ if (name->type->is_origin)
+ insert_name(state->temporaries, name->type->ptr);
clear_contextuals(state->temporaries);
break;
case slot_type_type_equal_thesis_type_1:
state->st = slot_type_type_equal_thesis_type_2;
state->caret += 1;
- if (state->judgment->a->is_origin) {
- name = state->judgment->a->ptr;
- g_hash_table_insert(state->temporaries, name->str, name);
- }
+ if (state->judgment->a->is_origin)
+ insert_name(state->temporaries, state->judgment->a->ptr);
break;
case slot_type_type_equal_thesis_type_2:
if (conclusion_p(state->rule, state->judgment))
else
state->st = slot_type_rule_dots;
state->caret += 1;
- if (state->judgment->b->is_origin) {
- name = state->judgment->b->ptr;
- g_hash_table_insert(state->temporaries, name->str, name);
- }
+ if (state->judgment->b->is_origin)
+ insert_name(state->temporaries, state->judgment->b->ptr);
clear_contextuals(state->temporaries);
break;
case slot_type_element_equal_thesis_element_1:
state->caret += 1;
break;
case slot_type_element_equal_thesis_element_2:
- if (state->judgment->a->is_origin) {
+ if (state->judgment->a->is_origin && state->judgment->b->is_origin) {
state->st = slot_type_element_equal_thesis_type;
state->caret += 1;
}
state->st = slot_type_rule_dots;
state->caret += 2;
- /* Since we skip the type slot we should add the dependencies and
- temporaries here if needed. */
- *get_wrap_type_addr(state->judgment->b) =
- copy_wrap(get_wrap_type(state->judgment->a));
+ /* Since we skip the type slot we should add dependencies to originals,
+ here. */
+ ptr = NULL;
if (state->judgment->a->is_origin) {
name = state->judgment->a->ptr;
- l = wrap_list_type_names(NULL, name->type);
- name->dependencies = list_dependencies(name, state->temporaries, l);
- g_slist_free(g_steal_pointer(&l));
- g_hash_table_insert(state->temporaries, name->str, name);
+ name->type = copy_wrap(get_wrap_type(state->judgment->b));
+ name->dependencies = list_dependencies(name, state->temporaries);
+ ptr = name; /* Don't insert `a' before we listed `b's deps */
}
if (state->judgment->b->is_origin) {
name = state->judgment->b->ptr;
- l = wrap_list_type_names(NULL, name->type);
- name->dependencies = list_dependencies(name, state->temporaries, l);
- g_slist_free(g_steal_pointer(&l));
- g_hash_table_insert(state->temporaries, name->str, name);
+ name->type = copy_wrap(get_wrap_type(state->judgment->a));
+ name->dependencies = list_dependencies(name, state->temporaries);
+ insert_name(state->temporaries, name);
}
+ if (ptr) insert_name(state->temporaries, ptr);
}
break;
case slot_type_element_equal_thesis_type:
else
state->st = slot_type_rule_dots;
state->caret += 1;
- *get_wrap_type_addr(state->judgment->b) =
- copy_wrap(get_wrap_type(state->judgment->a));
+
+ ptr = NULL;
if (state->judgment->a->is_origin) {
name = state->judgment->a->ptr;
- l = wrap_list_type_names(NULL, name->type);
- name->dependencies = list_dependencies(name, state->temporaries, l);
- g_slist_free(g_steal_pointer(&l));
- g_hash_table_insert(state->temporaries, name->str, name);
+ name->type = copy_wrap(get_wrap_type(state->judgment->b));
+ name->dependencies = list_dependencies(name, state->temporaries);
+ ptr = name; /* Don't insert `a' before we listed `b's deps */
}
if (state->judgment->b->is_origin) {
name = state->judgment->b->ptr;
- l = wrap_list_type_names(NULL, name->type);
- name->dependencies = list_dependencies(name, state->temporaries, l);
- g_slist_free(g_steal_pointer(&l));
- g_hash_table_insert(state->temporaries, name->str, name);
- }
- if (state->judgment->a->is_origin)
- name = state->judgment->a->ptr;
- else
- name = ((struct reference *)state->judgment->a->ptr)->origin;
- if (name->type->is_origin) {
- name = name->type->ptr;
- g_hash_table_insert(state->temporaries, name->str, name);
+ name->type = copy_wrap(get_wrap_type(state->judgment->a));
+ name->dependencies = list_dependencies(name, state->temporaries);
+ insert_name(state->temporaries, name);
}
-
+ if (ptr) insert_name(state->temporaries, ptr);
+ wrap = get_wrap_type(state->judgment->a);
+ if (wrap->is_origin)
+ insert_name(state->temporaries, wrap->ptr);
clear_contextuals(state->temporaries);
break;
case slot_type_rule_name:
if (l) {
draw_slot(w, y, x, virtual, FALSE, PAIR_NORMAL, "[");
while (l) {
+ /* dep = TBD; */
+ /* l1 = list_out_of_scope_dependencies(name, temporaries); */
+ /* while (l1) { */
+ /* set_ctp_and_pair(&ctp, &pair, caret, (*point)++); */
+ /* draw_slot(w, y, x, virtual, FALSE, pair, NULL); */
+ /* if (l1->next) */
+ /* draw_slot(w, y, x, virtual, FALSE, PAIR_NORMAL, ", "); */
+ /* else */
+ /* draw_slot(w, y, x, virtual, FALSE, PAIR_NORMAL, ". "); */
+ /* l1 = l1->next; */
+ /* } */
+
draw_ref(w, y, x, virtual, caret, point, inputstr, l->data);
l = l->next;
if (l)
nk,
NULL,
state->rule,
- list_dependencies(NULL, state->temporaries, NULL),
+ list_dependencies(NULL, state->temporaries),
strdup(state->input->str));
wrap = create_wrap(TRUE, name);
if (is_left)
nk_generic_thesis,
NULL,
state->rule,
- list_dependencies(NULL, state->temporaries, NULL),
+ list_dependencies(NULL, state->temporaries),
strdup(state->input->str));
wrap = create_wrap(TRUE, name);
state->judgment->a = wrap;
scope = scope_local;
name = create_name(scope, nk_vet, NULL, state->rule,
no_deps ? NULL :
- list_dependencies(NULL, state->temporaries, NULL),
+ list_dependencies(NULL, state->temporaries),
strdup(state->input->str));
state->input = g_string_erase(state->input, 0, -1);
if (vetk == vetk_variable)