From 1d3227ccded626ec76d6acb2d622e2fc857c32a1 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 18 Oct 2024 20:56:49 -0400 Subject: [PATCH] Implement generic theses --- src/v.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/src/v.c b/src/v.c index c76e252..17aa16c 100644 --- a/src/v.c +++ b/src/v.c @@ -1340,7 +1340,42 @@ validate_generic_context(struct state *state, bool is_left) } int -/* validate_vet_input(struct wrap **wrap, struct state *state, enum name_kind nk) */ +validate_generic_thesis(struct state *state) +{ + enum name_kind nk; + struct name *name; + struct wrap *wrap; + + if (*state->input->str == '\0') + return 1; + name = g_hash_table_lookup(state->gtheses, state->input->str); + if (name) { + wrap = create_wrap(FALSE, + create_reference(name, + g_slist_copy_deep(name->dependencies, + copy_user_data, + NULL))); + state->judgment->a = wrap; + state->input = g_string_erase(state->input, 0, -1); + return 0; + } + else if (conclusion_p(state->rule, state->judgment)) + return 3; + name = create_name(s_local, + nk_generic_thesis, + NULL, + state->rule, + list_dependencies(state->vets, nk_generic_thesis, + s_local, NULL), + strdup(state->input->str)); + wrap = create_wrap(TRUE, name); + state->judgment->a = wrap; + g_hash_table_insert(state->gtheses, name->str, name); + state->input = g_string_erase(state->input, 0, -1); + return 0; +} + +int validate_vet_input(void *addr, struct state *state, enum name_kind nk) { bool is_c; @@ -1423,10 +1458,14 @@ validate_replacement(struct state *state) dep = g_slist_nth_data(ref->origin->dependencies, idx); if (name->kind != dep->kind) return 6; + /* TODO: check that the types of (the input) `name' and of `dep' are + compatible + */ + + l = g_slist_nth(ref->replacements, idx); reps = g_slist_copy_deep(name->dependencies, copy_user_data, NULL); l->data = create_reference(name, reps); - if (reps) state->stack = g_slist_prepend(state->stack, l->data); else { @@ -1716,7 +1755,19 @@ main() } break; case st_generic_thesis: - state.err = -1; + if (key == KEY_TAB) { + addr = &state.judgment->a; + if (!(state.err = validate_generic_thesis(&state))) { + if (requires_replacements(*addr)) + handle_replacements(&state, *addr); + else + next_slot(&state); + } + } + else if (key == KEY_BACKSPACE) + handle_backspace(&state); + else + handle_input(&state, key); break; case st_type_thesis: if (key == KEY_TAB) { -- 2.39.5