From 5f12389a22bac1700e623eada774f066f7bf6461 Mon Sep 17 00:00:00 2001 From: Graham Nelson Date: Tue, 25 May 2021 23:18:46 +0100 Subject: [PATCH] Started in on grammar compilation --- docs/if-module/5-cg.html | 4 +- docs/if-module/5-pp.html | 1 + docs/imperative-module/2-cr.html | 2 +- docs/runtime-module/2-ea.html | 6 +- docs/runtime-module/2-ec.html | 14 +- docs/runtime-module/2-emt.html | 4 +- docs/runtime-module/2-gpr.html | 8 +- docs/runtime-module/2-hrr.html | 31 +- docs/runtime-module/3-gm.html | 2 +- docs/runtime-module/5-prp.html | 2 +- docs/runtime-module/6-pnp.html | 5 +- docs/runtime-module/7-cg.html | 527 +++++++++--------- docs/runtime-module/7-cgl.html | 59 +- docs/runtime-module/7-tpv.html | 8 +- inform7/Figures/memory-diagnostics.txt | 36 +- inform7/Figures/timings-diagnostics.txt | 30 +- .../if-module/Chapter 5/Command Grammars.w | 4 +- inform7/if-module/Chapter 5/Parsing Plugin.w | 1 + .../Chapter 2/Compile Rvalues.w | 2 +- inform7/runtime-module/Chapter 2/Hierarchy.w | 22 +- .../Chapter 6/Parse Name Properties.w | 3 +- .../Chapter 7/Command Grammar Lines.w | 45 +- .../Chapter 7/Command Grammars.w | 489 ++++++++-------- 23 files changed, 677 insertions(+), 628 deletions(-) diff --git a/docs/if-module/5-cg.html b/docs/if-module/5-cg.html index d40320f96..4477a17fa 100644 --- a/docs/if-module/5-cg.html +++ b/docs/if-module/5-cg.html @@ -165,7 +165,7 @@ form, so this is not as bloated a structure as it looks. cg->where_cg_created = current_sentence; cg->slashed = FALSE; cg->determined = FALSE; - cg->compilation_data = RTCommandGrammars::new_compilation_data(); + cg->compilation_data = RTCommandGrammars::new_compilation_data(cg); return cg; } @@ -343,7 +343,6 @@ token called "[suitable colour]". if (cg == NULL) { cg = CommandGrammars::cg_new(CG_IS_TOKEN); cg->token_name = W; - RTCommandGrammars::new_CG_IS_TOKEN(cg, W); } return cg; } @@ -497,7 +496,6 @@ property value used adjectivally like this can be given a CG. command_grammar *cg = CommandGrammars::cg_new(CG_IS_PROPERTY_NAME); EitherOrProperties::set_parsing_grammar(prn, cg); cg->prn_understood = prn; - RTCommandGrammars::new_CG_IS_PROPERTY_NAME(cg, prn); return cg; } diff --git a/docs/if-module/5-pp.html b/docs/if-module/5-pp.html index a271409fe..0b3d1e8d5 100644 --- a/docs/if-module/5-pp.html +++ b/docs/if-module/5-pp.html @@ -123,6 +123,7 @@ for generating that is a little delicate. BENCH(UnderstandFilterTokens::compile); } if (stage == INTER4_CSEQ) { + BENCH(CommandGrammars::prepare); BENCH(RTCommandGrammars::compile_all); BENCH(UnderstandFilterTokens::compile); } diff --git a/docs/imperative-module/2-cr.html b/docs/imperative-module/2-cr.html index 50d45d76f..07694f712 100644 --- a/docs/imperative-module/2-cr.html +++ b/docs/imperative-module/2-cr.html @@ -484,7 +484,7 @@ code, and we don't want to repeat that: return; } command_grammar *cg = Understand::consultation(W); - inter_name *iname = RTCommandGrammars::consult_iname(cg); + inter_name *iname = RTCommandGrammars::get_consult_fn_iname(cg); if (iname) { cu = CREATE(cached_understanding); cu->understanding_text = W; diff --git a/docs/runtime-module/2-ea.html b/docs/runtime-module/2-ea.html index ad0358bd0..509c77865 100644 --- a/docs/runtime-module/2-ea.html +++ b/docs/runtime-module/2-ea.html @@ -126,7 +126,7 @@ enforced; it's fine to store arbitrary data with return save; } -packaging_state EmitArrays::begin_late_verb(inter_name *name, kind *K) { +packaging_state EmitArrays::begin_late_verb(inter_name *name, kind *K) { packaging_state save = Packaging::enter_home_of(name); EmitArrays::begin_inner(name, K, FALSE); Produce::annotate_iname_i(name, VERBARRAY_IANN, 1); @@ -181,7 +181,7 @@ which would be a typesafe list in I7, so they can be absolutely any data, EmitArrays::entry_inner(v1, v2); } -void EmitArrays::dword_entry(text_stream *content) { +void EmitArrays::dword_entry(text_stream *content) { inter_ti v1 = 0, v2 = 0; Produce::dword_value(Emit::tree(), &v1, &v2, content); EmitArrays::entry_inner(v1, v2); @@ -213,7 +213,7 @@ difference to compiled code.

-void EmitArrays::end(packaging_state save) {
+void EmitArrays::end(packaging_state save) {
     EmitArrays::end_inner();
     Packaging::exit(Emit::tree(), save);
 }
diff --git a/docs/runtime-module/2-ec.html b/docs/runtime-module/2-ec.html
index 31b85d717..0e9fbcc2c 100644
--- a/docs/runtime-module/2-ec.html
+++ b/docs/runtime-module/2-ec.html
@@ -108,10 +108,10 @@ instruction last emitted, not after it.
 
  • EmitCode::up then returns us back to where we were.
  • -void EmitCode::up(void) {
    +void EmitCode::up(void) {
         Produce::up(Emit::tree());
     }
    -void EmitCode::down(void) {
    +void EmitCode::down(void) {
         Produce::down(Emit::tree());
     }
     
    @@ -165,7 +165,7 @@ start of a function. Produce::val(Emit::tree(), K_truth_state, LITERAL_IVAL, 0); } -void EmitCode::val_iname(kind *K, inter_name *iname) { +void EmitCode::val_iname(kind *K, inter_name *iname) { Produce::val_iname(Emit::tree(), K, iname); } @@ -185,7 +185,7 @@ start of a function. Produce::val_nothing(Emit::tree()); } -void EmitCode::val_symbol(kind *K, inter_symbol *S) { +void EmitCode::val_symbol(kind *K, inter_symbol *S) { Produce::val_symbol(Emit::tree(), K, S); }
    @@ -310,11 +310,11 @@ in such cases, this function must exist in the kits somewhere.

    -void EmitCode::ref_iname(kind *K, inter_name *iname) {
    +void EmitCode::ref_iname(kind *K, inter_name *iname) {
         Produce::ref_iname(Emit::tree(), K, iname);
     }
     
    -void EmitCode::ref_symbol(kind *K, inter_symbol *S) {
    +void EmitCode::ref_symbol(kind *K, inter_symbol *S) {
         Produce::ref_symbol(Emit::tree(), K, S);
     }
     
    @@ -322,7 +322,7 @@ in such cases, this function must exist in the kits somewhere.

    -void EmitCode::inv(inter_ti bip) {
    +void EmitCode::inv(inter_ti bip) {
         Produce::inv_primitive(Emit::tree(), bip);
     }
     
    diff --git a/docs/runtime-module/2-emt.html b/docs/runtime-module/2-emt.html
    index 06b6f6fe9..d8a0076fa 100644
    --- a/docs/runtime-module/2-emt.html
    +++ b/docs/runtime-module/2-emt.html
    @@ -97,7 +97,7 @@ reference points. But as newly-created packages they are initially empty.
         Packaging::incarnate(Packaging::get_unit(main_emission_tree, I"synoptic", I"_module")->the_package);
         return main_emission_tree;
     }
    -inter_tree *Emit::tree(void) {
    +inter_tree *Emit::tree(void) {
         return main_emission_tree;
     }
     
    @@ -329,7 +329,7 @@ it represents an actual number at run-time, the second if not:
     

    -inter_name *Emit::numeric_constant(inter_name *con_iname, inter_ti val) {
    +inter_name *Emit::numeric_constant(inter_name *con_iname, inter_ti val) {
         return Emit::numeric_constant_inner(con_iname, val, int_interk, INVALID_IANN);
     }
     
    diff --git a/docs/runtime-module/2-gpr.html b/docs/runtime-module/2-gpr.html
    index fbe3663ef..c5ec91539 100644
    --- a/docs/runtime-module/2-gpr.html
    +++ b/docs/runtime-module/2-gpr.html
    @@ -153,7 +153,7 @@ variables needed inside GPRs, which tend to be large, wrangly functions:
     

    -gpr_kit GPRs::new_kit(void) {
    +gpr_kit GPRs::new_kit(void) {
         gpr_kit kit;
         kit.cur_addr_s = NULL;
         kit.cur_len_s = NULL;
    @@ -191,7 +191,7 @@ following convenience functions.
     

    -void GPRs::add_standard_vars(gpr_kit *kit) {
    +void GPRs::add_standard_vars(gpr_kit *kit) {
         kit->group_wn_s = LocalVariables::new_internal_as_symbol(I"group_wn");
         kit->v_s = LocalVariables::new_internal_as_symbol(I"v");
         kit->w_s = LocalVariables::new_internal_as_symbol(I"w");
    @@ -203,14 +203,14 @@ following convenience functions.
         kit->instance_s = LocalVariables::new_other_as_symbol(I"instance");
     }
     
    -void GPRs::add_range_vars(gpr_kit *kit) {
    +void GPRs::add_range_vars(gpr_kit *kit) {
         kit->range_from_s = LocalVariables::new_internal_commented_as_symbol(I"range_from",
             I"call parameter: word number of snippet start");
         kit->range_words_s = LocalVariables::new_internal_commented_as_symbol(I"range_words",
             I"call parameter: snippet length");
     }
     
    -void GPRs::add_original_var(gpr_kit *kit) {
    +void GPRs::add_original_var(gpr_kit *kit) {
         kit->original_wn_s = LocalVariables::new_internal_as_symbol(I"original_wn");
     }
     
    diff --git a/docs/runtime-module/2-hrr.html b/docs/runtime-module/2-hrr.html
    index 395ce4f1e..fe0d452c3 100644
    --- a/docs/runtime-module/2-hrr.html
    +++ b/docs/runtime-module/2-hrr.html
    @@ -689,8 +689,6 @@ that the compiler can refer to it.
     
     
    enum COND_TOKENS_HAP
     enum CONDITIONAL_TOKEN_FN_HL
    -enum CONSULT_TOKENS_HAP
    -enum CONSULT_FN_HL
     enum TESTS_HAP
     enum SCRIPT_HL
     enum TEST_MD_HL
    @@ -699,9 +697,7 @@ that the compiler can refer to it.
     enum REQUIREMENTS_HL
     enum MISTAKES_HAP
     enum MISTAKE_FN_HL
    -enum NAMED_TOKENS_HAP
     enum NO_VERB_VERB_DEFINED_HL
    -enum PARSE_LINE_FN_HL
     enum NOUN_FILTERS_HAP
     enum NOUN_FILTER_FN_HL
     enum PARSE_NAMES_HAP
    @@ -730,6 +726,10 @@ that the compiler can refer to it.
     enum VERB_DECLARATION_ARRAY_HL
     enum MISTAKEACTION_HL
     enum MISTAKEACTIONSUB_HL
    +enum COMMAND_GRAMMARS_HAP
    +enum PROPERTY_GPR_FN_HL
    +enum PARSE_LINE_FN_HL
    +enum CONSULT_FN_HL
     

    §8.1.22. Establish grammar8.1.22 =

    @@ -759,9 +759,6 @@ that the compiler can refer to it. H_BEGIN_AP(COND_TOKENS_HAP, I"conditional_token", I"_conditional_token") H_F_G(CONDITIONAL_TOKEN_FN_HL, I"conditional_token_fn", I"Cond_Token") H_END - H_BEGIN_AP(CONSULT_TOKENS_HAP, I"consult_token", I"_consult_token") - H_F_G(CONSULT_FN_HL, I"consult_fn", I"Consult_Grammar") - H_END H_BEGIN_AP(TESTS_HAP, I"test", I"_test") H_C_U(TEST_NAME_MD_HL, I"^name") H_C_U(TEST_LENGTH_MD_HL, I"^length") @@ -771,9 +768,6 @@ that the compiler can refer to it. H_BEGIN_AP(MISTAKES_HAP, I"mistake", I"_mistake") H_F_G(MISTAKE_FN_HL, I"mistake_fn", I"Mistake_Token") H_END - H_BEGIN_AP(NAMED_TOKENS_HAP, I"named_token", I"_named_token") - H_F_G(PARSE_LINE_FN_HL, I"parse_line_fn", I"GPR_Line") - H_END H_BEGIN_AP(NOUN_FILTERS_HAP, I"noun_filter", I"_noun_filter") H_F_G(NOUN_FILTER_FN_HL, I"filter_fn", I"Noun_Filter") H_END @@ -795,6 +789,11 @@ that the compiler can refer to it. H_BEGIN_AP(COMMANDS_HAP, I"command", I"_command") H_F_G(VERB_DECLARATION_ARRAY_HL, NULL, I"GV_Grammar") H_END + H_BEGIN_AP(COMMAND_GRAMMARS_HAP, I"command_grammar", I"_command_grammar") + H_F_G(PROPERTY_GPR_FN_HL, I"either_or_GPR_fn", I"PRN_PN") + H_F_G(PARSE_LINE_FN_HL, I"parse_line_fn", I"GPR_Line") + H_F_G(CONSULT_FN_HL, I"consult_fn", I"Consult_Grammar") + H_END H_F_T(MISTAKEACTIONSUB_HL, I"MistakeActionSub_fn", I"MistakeActionSub") H_C_T(NO_VERB_VERB_DEFINED_HL, I"NO_VERB_VERB_DEFINED") H_END @@ -1101,7 +1100,6 @@ that the compiler can refer to it. enum PROPERTY_NAME_MD_HL enum PROPERTY_ID_HL enum PROPERTY_HL -enum EITHER_OR_GPR_FN_HL

    §8.1.34. Establish properties8.1.34 =

    @@ -1114,7 +1112,6 @@ that the compiler can refer to it. H_C_U(PROPERTY_NAME_MD_HL, I"^name") H_C_U(PROPERTY_ID_HL, I"property_id") H_C_T(PROPERTY_HL, I"P") - H_F_G(EITHER_OR_GPR_FN_HL, I"either_or_GPR_fn", I"PRN_PN") H_END H_END
    @@ -1617,7 +1614,7 @@ at which this array should be placed, by calling, e.g.,
    -inter_name *Hierarchy::find(int id) {
    +inter_name *Hierarchy::find(int id) {
         return HierarchyLocations::find(Emit::tree(), id);
     }
     
    @@ -1640,7 +1637,7 @@ package holding it. (P

    -inter_name *Hierarchy::make_iname_in(int id, package_request *P) {
    +inter_name *Hierarchy::make_iname_in(int id, package_request *P) {
         return HierarchyLocations::find_in_package(Emit::tree(), id, P, EMPTY_WORDING,
             NULL, -1, NULL);
     }
    @@ -1702,7 +1699,7 @@ available", using the following, which creates a socket. Again, see
     

    -void Hierarchy::make_available(inter_name *iname) {
    +void Hierarchy::make_available(inter_name *iname) {
         text_stream *ma_as = Produce::get_translation(iname);
         if (Str::len(ma_as) == 0) ma_as = InterNames::to_text(iname);
         PackageTypes::get(Emit::tree(), I"_linkage");
    @@ -1742,7 +1739,7 @@ such _kind pack
     

    -package_request *Hierarchy::local_package(int hap_id) {
    +package_request *Hierarchy::local_package(int hap_id) {
         return Hierarchy::local_package_to(hap_id, current_sentence);
     }
     
    @@ -1760,7 +1757,7 @@ compilation unit is meant: that's why it's "synoptic".
         return HierarchyLocations::attach_new_package(Emit::tree(), NULL, NULL, hap_id);
     }
     
    -package_request *Hierarchy::completion_package(int hap_id) {
    +package_request *Hierarchy::completion_package(int hap_id) {
         return HierarchyLocations::attach_new_package(Emit::tree(), NULL, NULL, hap_id);
     }
     
    diff --git a/docs/runtime-module/3-gm.html b/docs/runtime-module/3-gm.html index 55db6f9ae..0251a9ed1 100644 --- a/docs/runtime-module/3-gm.html +++ b/docs/runtime-module/3-gm.html @@ -79,7 +79,7 @@ function togglePopup(material_id) { Emit::rudimentary_kinds(); GenericModule::compile_basic_constants(); RTVerbs::compile_generic_constants(); - RTCommandGrammars::compile_generic_constants(); + RTCommandGrammars::compile_generic_constants(); RTPlayer::compile_generic_constants(); RTRelations::compile_generic_constants(); } diff --git a/docs/runtime-module/5-prp.html b/docs/runtime-module/5-prp.html index c0bbc3d23..634d1199f 100644 --- a/docs/runtime-module/5-prp.html +++ b/docs/runtime-module/5-prp.html @@ -111,7 +111,7 @@ package already supplied:

    -package_request *RTProperties::package(property *prn) {
    +package_request *RTProperties::package(property *prn) {
         if (prn == NULL) internal_error("tried to find package for null property");
         if ((Properties::is_either_or(prn)) && (prn->compilation_data.store_in_negation))
             return RTProperties::package(EitherOrProperties::get_negation(prn));
    diff --git a/docs/runtime-module/6-pnp.html b/docs/runtime-module/6-pnp.html
    index 19e67bdf2..3cbb1d10e 100644
    --- a/docs/runtime-module/6-pnp.html
    +++ b/docs/runtime-module/6-pnp.html
    @@ -147,7 +147,7 @@ all of the work is delegated:
         gpr_kit kit = GPRs::new_kit();
         packaging_state save = Functions::begin(Name::get_parse_name_fn_iname(subj));
         ParseName::compile_head(&kit, subj, TRUE);
    -    RTCommandGrammars::cg_compile_parse_name_lines(&kit, cg);
    +    RTCommandGrammars::cg_compile_parse_name_lines(&kit, cg);
         ParseName::compile_tail(&kit);
         Functions::end(save);
     }
    @@ -1213,7 +1213,6 @@ alter the value of self        EmitCode::up();
         EmitCode::up();
         if (cg) {
    -        if (cg->compilation_data.cg_prn_iname == NULL) internal_error("no PRN iname");
             Begin a PVP test10.1;
             EmitCode::inv(IF_BIP);
             EmitCode::down();
    @@ -1222,7 +1221,7 @@ alter the value of self                EmitCode::test_if_iname_has_property(K_value, Hierarchy::find(SELF_HL), prn);
                     EmitCode::inv(EQ_BIP);
                     EmitCode::down();
    -                    EmitCode::call(cg->compilation_data.cg_prn_iname);
    +                    EmitCode::call(RTCommandGrammars::get_property_GPR_fn_iname(cg));
                         EmitCode::val_iname(K_value, Hierarchy::find(GPR_PREPOSITION_HL));
                     EmitCode::up();
                 EmitCode::up();
    diff --git a/docs/runtime-module/7-cg.html b/docs/runtime-module/7-cg.html
    index 2fe6f6f30..4549dc657 100644
    --- a/docs/runtime-module/7-cg.html
    +++ b/docs/runtime-module/7-cg.html
    @@ -72,58 +72,140 @@ function togglePopup(material_id) {
         
     

    Runtime support for CGs.

    -
    +
    -

    §1.

    +

    §1. Generic constants.

    + +
    +void RTCommandGrammars::compile_generic_constants(void) {
    +    RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_REVERSE_HL, 1);
    +    RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_SLASH_HL, 1);
    +    RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_DIVIDER_HL, 1);
    +    RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_RESULT_HL, 2);
    +    RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_SPECIAL_HL, 3);
    +    RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_NUMBER_HL, 4);
    +    RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_NOUN_HL, 5);
    +    RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_MULTI_HL, 6);
    +    RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_MULTIINSIDE_HL, 7);
    +    RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_MULTIHELD_HL, 8);
    +    RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_HELD_HL, 9);
    +    RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_CREATURE_HL, 10);
    +    RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_TOPIC_HL, 11);
    +    RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_MULTIEXCEPT_HL, 12);
    +}
    +
    +inter_name *RTCommandGrammars::iname_for_I6_parser_token(cg_token *cgt) {
    +    switch (cgt->grammar_token_code) {
    +        case NOUN_TOKEN_GTC:        return Hierarchy::find(VERB_DIRECTIVE_NOUN_HL);
    +        case MULTI_TOKEN_GTC:       return Hierarchy::find(VERB_DIRECTIVE_MULTI_HL);
    +        case MULTIINSIDE_TOKEN_GTC: return Hierarchy::find(VERB_DIRECTIVE_MULTIINSIDE_HL);
    +        case MULTIHELD_TOKEN_GTC:   return Hierarchy::find(VERB_DIRECTIVE_MULTIHELD_HL);
    +        case HELD_TOKEN_GTC:        return Hierarchy::find(VERB_DIRECTIVE_HELD_HL);
    +        case CREATURE_TOKEN_GTC:    return Hierarchy::find(VERB_DIRECTIVE_CREATURE_HL);
    +        case TOPIC_TOKEN_GTC:       return Hierarchy::find(VERB_DIRECTIVE_TOPIC_HL);
    +        case MULTIEXCEPT_TOKEN_GTC: return Hierarchy::find(VERB_DIRECTIVE_MULTIEXCEPT_HL);
    +        default: internal_error("tried to find inter name for invalid GTC");
    +    }
    +    return NULL;  to prevent a compiler error: never reached
    +}
    +
    +inter_name *RTCommandGrammars::grammar_constant(int N, int V) {
    +    inter_name *iname = Hierarchy::find(N);
    +    Emit::numeric_constant(iname, 1);
    +    Hierarchy::make_available(iname);
    +    return iname;
    +}
    +
    +

    §2. Compilation data. Each command_grammar object contains this data: +

     typedef struct cg_compilation_data {
    +    struct package_request *cg_package;
    +
         struct inter_name *cg_token_iname;  CG_IS_TOKEN
    -    struct inter_name *cg_parse_name_iname;  CG_IS_VALUE
    -    struct inter_name *cg_prn_iname;  CG_IS_PROPERTY_NAME: the relevant GPR is called this
    -    struct inter_name *cg_consult_iname;  for the consult parsing routine if needed
    -    struct text_stream *cg_I6_identifier;  when a token is delegated to an I6 routine
    +
    +    struct inter_name *property_GPR_fn_iname;  CG_IS_PROPERTY_NAME
    +    struct text_stream *CG_IS_TOKEN_identifier;  CG_IS_PROPERTY_NAME
    +
    +    struct inter_name *consult_fn_iname;  CG_IS_CONSULT
     } cg_compilation_data;
     
    -cg_compilation_data RTCommandGrammars::new_compilation_data(void) {
    +cg_compilation_data RTCommandGrammars::new_compilation_data(command_grammar *cg) {
         cg_compilation_data cgcd;
    -    cgcd.cg_parse_name_iname = NULL;
    -    cgcd.cg_consult_iname = NULL;
    -    cgcd.cg_prn_iname = NULL;
    +    cgcd.cg_package = NULL;
    +    cgcd.consult_fn_iname = NULL;
    +    cgcd.property_GPR_fn_iname = NULL;
         cgcd.cg_token_iname = NULL;
    -    cgcd.cg_I6_identifier = Str::new();
    +    cgcd.CG_IS_TOKEN_identifier = Str::new();
         return cgcd;
     }
     
    -inter_name *RTCommandGrammars::i6_token_as_iname(command_grammar *cg) {
    -    if (Str::len(cg->compilation_data.cg_I6_identifier) > 0)
    -        return Produce::find_by_name(Emit::tree(), cg->compilation_data.cg_I6_identifier);
    -    if (cg->compilation_data.cg_token_iname == NULL) internal_error("no token GPR");
    +package_request *RTCommandGrammars::package(command_grammar *cg) {
    +    if (cg->compilation_data.cg_package == NULL)
    +        cg->compilation_data.cg_package =
    +            Hierarchy::completion_package(COMMAND_GRAMMARS_HAP);
    +    return cg->compilation_data.cg_package;
    +}
    +
    +inter_name *RTCommandGrammars::get_property_GPR_fn_iname(command_grammar *cg) {
    +    if ((cg == NULL) || (cg->cg_is != CG_IS_PROPERTY_NAME))
    +        internal_error("prn_iname unavailable");
    +    if (cg->compilation_data.property_GPR_fn_iname == NULL)
    +        cg->compilation_data.property_GPR_fn_iname =
    +            Hierarchy::make_iname_in(PROPERTY_GPR_FN_HL,
    +                RTCommandGrammars::package(cg));
    +    return cg->compilation_data.property_GPR_fn_iname;
    +}
    +
    +inter_name *RTCommandGrammars::get_cg_token_iname(command_grammar *cg) {
    +    if ((cg == NULL) || (cg->cg_is != CG_IS_TOKEN))
    +        internal_error("cg_token_iname unavailable");
    +    if (cg->compilation_data.cg_token_iname == NULL) {
    +        if (Str::len(cg->compilation_data.CG_IS_TOKEN_identifier) > 0)
    +            cg->compilation_data.cg_token_iname =
    +                Produce::find_by_name(Emit::tree(),
    +                    cg->compilation_data.CG_IS_TOKEN_identifier);
    +        else
    +            cg->compilation_data.cg_token_iname =
    +                Hierarchy::make_iname_in(PARSE_LINE_FN_HL,
    +                    RTCommandGrammars::package(cg));
    +    }
         return cg->compilation_data.cg_token_iname;
     }
     
    -void RTCommandGrammars::new_CG_IS_PROPERTY_NAME(command_grammar *cg, property *prn) {
    -    cg->compilation_data.cg_prn_iname =
    -        Hierarchy::make_iname_in(EITHER_OR_GPR_FN_HL, RTProperties::package(prn));
    -}
    -
    -void RTCommandGrammars::new_CG_IS_TOKEN(command_grammar *cg, wording W) {
    -    package_request *PR = Hierarchy::local_package(NAMED_TOKENS_HAP);
    -    cg->compilation_data.cg_token_iname = Hierarchy::make_iname_in(PARSE_LINE_FN_HL, PR);
    -}
    -
     void RTCommandGrammars::set_CG_IS_TOKEN_identifier(command_grammar *cg, wording W) {
    -    WRITE_TO(cg->compilation_data.cg_I6_identifier, "%N", Wordings::first_wn(W));
    +    if (cg->compilation_data.cg_token_iname) internal_error("too late to translate");
    +    WRITE_TO(cg->compilation_data.CG_IS_TOKEN_identifier, "%N", Wordings::first_wn(W));
    +}
    +
    +
    • The structure cg_compilation_data is private to this section.
    +

    §3. These are used to parse an explicit range of words (such as traditionally +found in the CONSULT command) at run time, and they are not I6 grammar +tokens, and do not appear in Verb declarations: otherwise, such +routines are very similar to GPRs. +

    + +

    First, we need to look after a pointer to the CG used to hold the grammar +being matched against the snippet of words. +

    + +
    +inter_name *RTCommandGrammars::get_consult_fn_iname(command_grammar *cg) {
    +    if ((cg == NULL) || (cg->cg_is != CG_IS_CONSULT))
    +        internal_error("cg_token_iname unavailable");
    +    if (cg->compilation_data.consult_fn_iname == NULL)
    +        cg->compilation_data.consult_fn_iname =
    +            Hierarchy::make_iname_in(CONSULT_FN_HL, RTCommandGrammars::package(cg));
    +    return cg->compilation_data.consult_fn_iname;
     }
     
     void RTCommandGrammars::create_no_verb_verb(command_grammar *cg) {
    -    inter_name *iname = Hierarchy::find(NO_VERB_VERB_DEFINED_HL);
    -    Emit::numeric_constant(iname, (inter_ti) 1);
    +    Emit::numeric_constant(Hierarchy::find(NO_VERB_VERB_DEFINED_HL), (inter_ti) 1);
         global_compilation_settings.no_verb_verb_exists = TRUE;
     }
     
    -
    • The structure cg_compilation_data is accessed in 6/pnp and here.
    -

    §2. Phases III and IV: Sort and Compile Grammar. At this highest level phases III and IV are intermingled, in that Phase III +

    §4. Phases III and IV: Sort and Compile Grammar. At this highest level phases III and IV are intermingled, in that Phase III always precedes Phase IV for any given list of grammar lines, but each CG goes through both Phase III and IV before the next begins Phase III. So it would not be appropriate to print banners like "Phase III begins here" @@ -146,91 +228,173 @@ in the final I6 output.

    -inter_name *VERB_DIRECTIVE_REVERSE_iname = NULL;
    -inter_name *VERB_DIRECTIVE_SLASH_iname = NULL;
    -inter_name *VERB_DIRECTIVE_DIVIDER_iname = NULL;
    -inter_name *VERB_DIRECTIVE_RESULT_iname = NULL;
    -inter_name *VERB_DIRECTIVE_SPECIAL_iname = NULL;
    -inter_name *VERB_DIRECTIVE_NUMBER_iname = NULL;
    -inter_name *VERB_DIRECTIVE_NOUN_iname = NULL;
    -inter_name *VERB_DIRECTIVE_MULTI_iname = NULL;
    -inter_name *VERB_DIRECTIVE_MULTIINSIDE_iname = NULL;
    -inter_name *VERB_DIRECTIVE_MULTIHELD_iname = NULL;
    -inter_name *VERB_DIRECTIVE_HELD_iname = NULL;
    -inter_name *VERB_DIRECTIVE_CREATURE_iname = NULL;
    -inter_name *VERB_DIRECTIVE_TOPIC_iname = NULL;
    -inter_name *VERB_DIRECTIVE_MULTIEXCEPT_iname = NULL;
    -
    -void RTCommandGrammars::compile_generic_constants(void) {
    -    VERB_DIRECTIVE_REVERSE_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_REVERSE_HL, 1);
    -    VERB_DIRECTIVE_SLASH_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_SLASH_HL, 1);
    -    VERB_DIRECTIVE_DIVIDER_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_DIVIDER_HL, 1);
    -    VERB_DIRECTIVE_RESULT_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_RESULT_HL, 2);
    -    VERB_DIRECTIVE_SPECIAL_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_SPECIAL_HL, 3);
    -    VERB_DIRECTIVE_NUMBER_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_NUMBER_HL, 4);
    -    VERB_DIRECTIVE_NOUN_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_NOUN_HL, 5);
    -    VERB_DIRECTIVE_MULTI_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_MULTI_HL, 6);
    -    VERB_DIRECTIVE_MULTIINSIDE_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_MULTIINSIDE_HL, 7);
    -    VERB_DIRECTIVE_MULTIHELD_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_MULTIHELD_HL, 8);
    -    VERB_DIRECTIVE_HELD_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_HELD_HL, 9);
    -    VERB_DIRECTIVE_CREATURE_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_CREATURE_HL, 10);
    -    VERB_DIRECTIVE_TOPIC_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_TOPIC_HL, 11);
    -    VERB_DIRECTIVE_MULTIEXCEPT_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_MULTIEXCEPT_HL, 12);
    -}
    -
    -inter_name *RTCommandGrammars::iname_for_I6_parser_token(cg_token *cgt) {
    -    switch (cgt->grammar_token_code) {
    -        case NOUN_TOKEN_GTC: return VERB_DIRECTIVE_NOUN_iname;
    -        case MULTI_TOKEN_GTC: return VERB_DIRECTIVE_MULTI_iname;
    -        case MULTIINSIDE_TOKEN_GTC: return VERB_DIRECTIVE_MULTIINSIDE_iname;
    -        case MULTIHELD_TOKEN_GTC: return VERB_DIRECTIVE_MULTIHELD_iname;
    -        case HELD_TOKEN_GTC: return VERB_DIRECTIVE_HELD_iname;
    -        case CREATURE_TOKEN_GTC: return VERB_DIRECTIVE_CREATURE_iname;
    -        case TOPIC_TOKEN_GTC: return VERB_DIRECTIVE_TOPIC_iname;
    -        case MULTIEXCEPT_TOKEN_GTC: return VERB_DIRECTIVE_MULTIEXCEPT_iname;
    -        default: internal_error("tried to find inter name for invalid GTC");
    -    }
    -    return NULL;  to prevent a gcc error: never reached
    -}
    -
    -inter_name *RTCommandGrammars::grammar_constant(int N, int V) {
    -    inter_name *iname = Hierarchy::find(N);
    -    Emit::numeric_constant(iname, 1);
    -    Hierarchy::make_available(iname);
    -    return iname;
    -}
    -
     void RTCommandGrammars::compile_all(void) {
         command_grammar *cg;
    -    CommandGrammars::prepare();
    -
    -    Log::new_stage(I"Sorting and compiling non-value grammar (G3, G4)");
    -
     
         LOOP_OVER(cg, command_grammar)
    -        if (cg->cg_is == CG_IS_TOKEN)
    -            RTCommandGrammars::compile(cg);  makes GPRs for designed tokens
    +        if (cg->cg_is == CG_IS_TOKEN) {
    +            text_stream *desc = Str::new();
    +            WRITE_TO(desc, "command grammar for token");
    +            Sequence::queue(&RTCommandGrammars::compile,
    +                STORE_POINTER_command_grammar(cg), desc);
    +        }
     
         LOOP_OVER(cg, command_grammar)
    -        if (cg->cg_is == CG_IS_COMMAND)
    -            RTCommandGrammars::compile(cg);  makes Verb directives
    +        if (cg->cg_is == CG_IS_COMMAND) {
    +            text_stream *desc = Str::new();
    +            WRITE_TO(desc, "command grammar for command '%W'", cg->command);
    +            Sequence::queue(&RTCommandGrammars::compile,
    +                STORE_POINTER_command_grammar(cg), desc);
    +        }
     
         LOOP_OVER(cg, command_grammar)
    -        if (cg->cg_is == CG_IS_SUBJECT)
    -            RTCommandGrammars::compile(cg);  makes routines for use in parse_name
    +        if (cg->cg_is == CG_IS_SUBJECT) {
    +            text_stream *desc = Str::new();
    +            WRITE_TO(desc, "command grammar for parse_name on '%W'",
    +                InferenceSubjects::get_name_text(cg->subj_understood));
    +            Sequence::queue(&RTCommandGrammars::compile,
    +                STORE_POINTER_command_grammar(cg), desc);
    +        }
     
         LOOP_OVER(cg, command_grammar)
    -        if (cg->cg_is == CG_IS_CONSULT)
    -            RTCommandGrammars::compile(cg);  routines to parse snippets, used as values
    +        if (cg->cg_is == CG_IS_CONSULT) {
    +            text_stream *desc = Str::new();
    +            WRITE_TO(desc, "command grammar for consult at '%W'",
    +                Node::get_text(cg->where_cg_created));
    +            Sequence::queue(&RTCommandGrammars::compile,
    +                STORE_POINTER_command_grammar(cg), desc);
    +        }
     
         LOOP_OVER(cg, command_grammar)
    -        if (cg->cg_is == CG_IS_PROPERTY_NAME)
    -            RTCommandGrammars::compile(cg);  makes routines for use in parse_name
    -
    -    RTCommandGrammarLines::compile_slash_gprs();
    +        if (cg->cg_is == CG_IS_PROPERTY_NAME) {
    +            text_stream *desc = Str::new();
    +            WRITE_TO(desc, "command grammar for property '%W'",
    +                cg->prn_understood->name);
    +            Sequence::queue(&RTCommandGrammars::compile,
    +                STORE_POINTER_command_grammar(cg), desc);
    +        }
     }
     
    -

    §3. Some tokens require suitable I6 routines to have already been compiled, +

    §5. The following function unites, so far as possible, the different forms of +CG by compiling each of them as a sandwich: top slice, filling, bottom slice. +

    + +

    The interesting case is of a CG representing names for an object: the +name-behaviour needs to be inherited from the object's kind, and so on up +the kinds hierarchy, but this is a case where I7's kind hierarchy does not +agree with I6's class hierarchy. I6 has no (nice) way to inherit parse_name +behaviour from a class to an instance. So we will simply pile up extra +fillings into the sandwich. The order of these is important: by getting +in first, grammar for the instance takes priority; its immediate kind has +next priority, and so on up the hierarchy. +

    + +
    +void RTCommandGrammars::compile(compilation_subtask *t) {
    +    command_grammar *cg = RETRIEVE_POINTER_command_grammar(t->data);
    +    if (CGLines::list_length(cg) == 0) return;
    +
    +    LOGIF(GRAMMAR, "Compiling command grammar $G\n", cg);
    +
    +    current_sentence = cg->where_cg_created;
    +
    +    RTCommandGrammarLines::reset_labels();
    +    switch(cg->cg_is) {
    +        case CG_IS_COMMAND: {
    +            package_request *PR = Hierarchy::completion_package(COMMANDS_HAP);
    +            inter_name *array_iname = Hierarchy::make_iname_in(VERB_DECLARATION_ARRAY_HL, PR);
    +            packaging_state save = RTCommandGrammars::cg_compile_Verb_directive_header(cg, array_iname);
    +            RTCommandGrammars::cg_compile_lines(NULL, cg);
    +            EmitArrays::end(save);
    +            break;
    +        }
    +        case CG_IS_TOKEN: {
    +            gpr_kit gprk = GPRs::new_kit();
    +            inter_name *iname = RTCommandGrammars::get_cg_token_iname(cg);
    +            packaging_state save = Functions::begin(iname);
    +            GPRs::add_original_var(&gprk);
    +            GPRs::add_standard_vars(&gprk);
    +            EmitCode::inv(STORE_BIP);
    +            EmitCode::down();
    +                EmitCode::ref_symbol(K_value, gprk.original_wn_s);
    +                EmitCode::val_iname(K_value, Hierarchy::find(WN_HL));
    +            EmitCode::up();
    +            EmitCode::inv(STORE_BIP);
    +            EmitCode::down();
    +                EmitCode::ref_symbol(K_value, gprk.rv_s);
    +                EmitCode::val_iname(K_value, Hierarchy::find(GPR_PREPOSITION_HL));
    +            EmitCode::up();
    +            RTCommandGrammars::cg_compile_lines(&gprk, cg);
    +            EmitCode::inv(RETURN_BIP);
    +            EmitCode::down();
    +                EmitCode::val_iname(K_value, Hierarchy::find(GPR_FAIL_HL));
    +            EmitCode::up();
    +            Functions::end(save);
    +            break;
    +        }
    +        case CG_IS_CONSULT: {
    +            gpr_kit gprk = GPRs::new_kit();
    +            inter_name *iname = RTCommandGrammars::get_consult_fn_iname(cg);
    +            packaging_state save = Functions::begin(iname);
    +            GPRs::add_range_vars(&gprk);
    +            GPRs::add_original_var(&gprk);
    +            GPRs::add_standard_vars(&gprk);
    +            EmitCode::inv(STORE_BIP);
    +            EmitCode::down();
    +                EmitCode::ref_iname(K_value, Hierarchy::find(WN_HL));
    +                EmitCode::val_symbol(K_value, gprk.range_from_s);
    +            EmitCode::up();
    +            EmitCode::inv(STORE_BIP);
    +            EmitCode::down();
    +                EmitCode::ref_symbol(K_value, gprk.original_wn_s);
    +                EmitCode::val_iname(K_value, Hierarchy::find(WN_HL));
    +            EmitCode::up();
    +            EmitCode::inv(STORE_BIP);
    +            EmitCode::down();
    +                EmitCode::ref_symbol(K_value, gprk.rv_s);
    +                EmitCode::val_iname(K_value, Hierarchy::find(GPR_PREPOSITION_HL));
    +            EmitCode::up();
    +            RTCommandGrammars::cg_compile_lines(&gprk, cg);
    +            EmitCode::inv(RETURN_BIP);
    +            EmitCode::down();
    +                EmitCode::val_iname(K_value, Hierarchy::find(GPR_FAIL_HL));
    +            EmitCode::up();
    +            Functions::end(save);
    +            break;
    +        }
    +        case CG_IS_SUBJECT:
    +            break;
    +        case CG_IS_VALUE:
    +            internal_error("iv");
    +            break;
    +        case CG_IS_PROPERTY_NAME: {
    +            gpr_kit gprk = GPRs::new_kit();
    +            inter_name *iname = RTCommandGrammars::get_property_GPR_fn_iname(cg);
    +            packaging_state save = Functions::begin(iname);
    +            GPRs::add_original_var(&gprk);
    +            GPRs::add_standard_vars(&gprk);
    +            EmitCode::inv(STORE_BIP);
    +            EmitCode::down();
    +                EmitCode::ref_symbol(K_value, gprk.original_wn_s);
    +                EmitCode::val_iname(K_value, Hierarchy::find(WN_HL));
    +            EmitCode::up();
    +            EmitCode::inv(STORE_BIP);
    +            EmitCode::down();
    +                EmitCode::ref_symbol(K_value, gprk.rv_s);
    +                EmitCode::val_iname(K_value, Hierarchy::find(GPR_PREPOSITION_HL));
    +            EmitCode::up();
    +            RTCommandGrammars::cg_compile_lines(&gprk, cg);
    +            EmitCode::inv(RETURN_BIP);
    +            EmitCode::down();
    +                EmitCode::val_iname(K_value, Hierarchy::find(GPR_FAIL_HL));
    +            EmitCode::up();
    +            Functions::end(save);
    +            break;
    +        }
    +    }
    +}
    +
    +

    §6. Some tokens require suitable I6 routines to have already been compiled, if they are to work nicely: the following routine goes through the tokens by exploring each CG in turn.

    @@ -247,11 +411,11 @@ by exploring each CG in turn. } }
    -

    §4. Command CGs are destined to be compiled into Verb directives, as follows. +

    §7. Command CGs are destined to be compiled into Verb directives, as follows.

    -packaging_state RTCommandGrammars::cg_compile_Verb_directive_header(command_grammar *cg, inter_name *array_iname) {
    +packaging_state RTCommandGrammars::cg_compile_Verb_directive_header(command_grammar *cg, inter_name *array_iname) {
         if (cg->cg_is != CG_IS_COMMAND)
             internal_error("tried to compile Verb from non-command CG");
         if (CGLines::list_length(cg) == 0)
    @@ -276,7 +440,7 @@ by exploring each CG in turn.
         return save;
     }
     
    -

    §5. The special thing about CG_IS_SUBJECT grammars is that each is attached +

    §8. The special thing about CG_IS_SUBJECT grammars is that each is attached to an inference subject, and when we compile them we recurse up the subject hierarchy: thus if the red ball is of kind ball which is of kind thing, then the parse_name for the red ball consists of grammar lines specified @@ -285,14 +449,14 @@ specified for all things. (This mimics I6 class-to-instance inheritance.)

    -void RTCommandGrammars::cg_compile_parse_name_lines(gpr_kit *gprk, command_grammar *cg) {
    +void RTCommandGrammars::cg_compile_parse_name_lines(gpr_kit *gprk, command_grammar *cg) {
         inference_subject *subj = cg->subj_understood;
     
         if (PARSING_DATA_FOR_SUBJ(subj)->understand_as_this_subject != cg)
             internal_error("link between subject and CG broken");
     
         LOGIF(GRAMMAR, "Parse_name content for $j:\n", subj);
    -    RTCommandGrammars::cg_compile_lines(gprk, PARSING_DATA_FOR_SUBJ(subj)->understand_as_this_subject);
    +    RTCommandGrammars::cg_compile_lines(gprk, PARSING_DATA_FOR_SUBJ(subj)->understand_as_this_subject);
     
         inference_subject *infs;
         for (infs = InferenceSubjects::narrowest_broader_subject(subj);
    @@ -300,175 +464,36 @@ specified for all things. (This mimics I6 class-to-instance inheritance.)
             if (PARSING_DATA_FOR_SUBJ(infs))
                 if (PARSING_DATA_FOR_SUBJ(infs)->understand_as_this_subject) {
                     LOGIF(GRAMMAR, "And parse_name content inherited from $j:\n", infs);
    -                RTCommandGrammars::cg_compile_lines(gprk, PARSING_DATA_FOR_SUBJ(infs)->understand_as_this_subject);
    +                RTCommandGrammars::cg_compile_lines(gprk, PARSING_DATA_FOR_SUBJ(infs)->understand_as_this_subject);
                 }
         }
     }
     
    -

    §6. All other grammars are compiled just as they are: +

    §9. All other grammars are compiled just as they are:

    -void RTCommandGrammars::cg_compile_lines(gpr_kit *gprk, command_grammar *cg) {
    +void RTCommandGrammars::cg_compile_lines(gpr_kit *gprk, command_grammar *cg) {
         CommandsIndex::list_assert_ownership(cg);  Mark for later indexing
         CommandGrammars::sort_command_grammar(cg);  Phase III for the CGLs in the CG happens here
         RTCommandGrammarLines::sorted_line_list_compile(gprk,
             cg->cg_is, cg, CommandGrammars::cg_is_genuinely_verbal(cg));  And Phase IV here
     }
    -
    -

    §7. The following function unites, so far as possible, the different forms of -CG by compiling each of them as a sandwich: top slice, filling, bottom slice. -

    -

    The interesting case is of a CG representing names for an object: the -name-behaviour needs to be inherited from the object's kind, and so on up -the kinds hierarchy, but this is a case where I7's kind hierarchy does not -agree with I6's class hierarchy. I6 has no (nice) way to inherit parse_name -behaviour from a class to an instance. So we will simply pile up extra -fillings into the sandwich. The order of these is important: by getting -in first, grammar for the instance takes priority; its immediate kind has -next priority, and so on up the hierarchy. -

    - -
    -void RTCommandGrammars::compile(command_grammar *cg) {
    -    if (CGLines::list_length(cg) == 0) return;
    -
    -    LOGIF(GRAMMAR, "Compiling command grammar $G\n", cg);
    -
    -    current_sentence = cg->where_cg_created;
    -
    -    RTCommandGrammarLines::reset_labels();
    -    switch(cg->cg_is) {
    -        case CG_IS_COMMAND: {
    -            package_request *PR = Hierarchy::completion_package(COMMANDS_HAP);
    -            inter_name *array_iname = Hierarchy::make_iname_in(VERB_DECLARATION_ARRAY_HL, PR);
    -            packaging_state save = RTCommandGrammars::cg_compile_Verb_directive_header(cg, array_iname);
    -            RTCommandGrammars::cg_compile_lines(NULL, cg);
    -            EmitArrays::end(save);
    -            break;
    -        }
    -        case CG_IS_TOKEN: {
    -            gpr_kit gprk = GPRs::new_kit();
    -            if (cg->compilation_data.cg_token_iname == NULL) internal_error("cg token not ready");
    -            packaging_state save = Functions::begin(cg->compilation_data.cg_token_iname);
    -            GPRs::add_original_var(&gprk);
    -            GPRs::add_standard_vars(&gprk);
    -            EmitCode::inv(STORE_BIP);
    -            EmitCode::down();
    -                EmitCode::ref_symbol(K_value, gprk.original_wn_s);
    -                EmitCode::val_iname(K_value, Hierarchy::find(WN_HL));
    -            EmitCode::up();
    -            EmitCode::inv(STORE_BIP);
    -            EmitCode::down();
    -                EmitCode::ref_symbol(K_value, gprk.rv_s);
    -                EmitCode::val_iname(K_value, Hierarchy::find(GPR_PREPOSITION_HL));
    -            EmitCode::up();
    -            RTCommandGrammars::cg_compile_lines(&gprk, cg);
    -            EmitCode::inv(RETURN_BIP);
    -            EmitCode::down();
    -                EmitCode::val_iname(K_value, Hierarchy::find(GPR_FAIL_HL));
    -            EmitCode::up();
    -            Functions::end(save);
    -            break;
    -        }
    -        case CG_IS_CONSULT: {
    -            gpr_kit gprk = GPRs::new_kit();
    -            inter_name *iname = RTCommandGrammars::consult_iname(cg);
    -            packaging_state save = Functions::begin(iname);
    -            GPRs::add_range_vars(&gprk);
    -            GPRs::add_original_var(&gprk);
    -            GPRs::add_standard_vars(&gprk);
    -            EmitCode::inv(STORE_BIP);
    -            EmitCode::down();
    -                EmitCode::ref_iname(K_value, Hierarchy::find(WN_HL));
    -                EmitCode::val_symbol(K_value, gprk.range_from_s);
    -            EmitCode::up();
    -            EmitCode::inv(STORE_BIP);
    -            EmitCode::down();
    -                EmitCode::ref_symbol(K_value, gprk.original_wn_s);
    -                EmitCode::val_iname(K_value, Hierarchy::find(WN_HL));
    -            EmitCode::up();
    -            EmitCode::inv(STORE_BIP);
    -            EmitCode::down();
    -                EmitCode::ref_symbol(K_value, gprk.rv_s);
    -                EmitCode::val_iname(K_value, Hierarchy::find(GPR_PREPOSITION_HL));
    -            EmitCode::up();
    -            RTCommandGrammars::cg_compile_lines(&gprk, cg);
    -            EmitCode::inv(RETURN_BIP);
    -            EmitCode::down();
    -                EmitCode::val_iname(K_value, Hierarchy::find(GPR_FAIL_HL));
    -            EmitCode::up();
    -            Functions::end(save);
    -            break;
    -        }
    -        case CG_IS_SUBJECT:
    -            break;
    -        case CG_IS_VALUE:
    -            internal_error("iv");
    -            break;
    -        case CG_IS_PROPERTY_NAME: {
    -            gpr_kit gprk = GPRs::new_kit();
    -            if (cg->compilation_data.cg_prn_iname == NULL) internal_error("PRN PN not ready");
    -            packaging_state save = Functions::begin(cg->compilation_data.cg_prn_iname);
    -            GPRs::add_original_var(&gprk);
    -            GPRs::add_standard_vars(&gprk);
    -            EmitCode::inv(STORE_BIP);
    -            EmitCode::down();
    -                EmitCode::ref_symbol(K_value, gprk.original_wn_s);
    -                EmitCode::val_iname(K_value, Hierarchy::find(WN_HL));
    -            EmitCode::up();
    -            EmitCode::inv(STORE_BIP);
    -            EmitCode::down();
    -                EmitCode::ref_symbol(K_value, gprk.rv_s);
    -                EmitCode::val_iname(K_value, Hierarchy::find(GPR_PREPOSITION_HL));
    -            EmitCode::up();
    -            RTCommandGrammars::cg_compile_lines(&gprk, cg);
    -            EmitCode::inv(RETURN_BIP);
    -            EmitCode::down();
    -                EmitCode::val_iname(K_value, Hierarchy::find(GPR_FAIL_HL));
    -            EmitCode::up();
    -            Functions::end(save);
    -            break;
    -        }
    -    }
    -}
    -
    -void RTCommandGrammars::compile_iv(gpr_kit *gprk, command_grammar *cg) {
    +void RTCommandGrammars::compile_iv(gpr_kit *gprk, command_grammar *cg) {
         if (CGLines::list_length(cg) > 0) {
             LOGIF(GRAMMAR, "Compiling command grammar $G\n", cg);
             current_sentence = cg->where_cg_created;
             RTCommandGrammarLines::reset_labels();
             if (cg->cg_is != CG_IS_VALUE) internal_error("not iv");
    -        RTCommandGrammars::cg_compile_lines(gprk, cg);
    +        RTCommandGrammars::cg_compile_lines(gprk, cg);
         }
     }
     
    -void RTCommandGrammars::emit_determination_type(determination_type *gty) {
    +void RTCommandGrammars::emit_determination_type(determination_type *gty) {
         CompileValues::to_code_val(gty->term[0].what);
     }
     
    -

    §8. These are used to parse an explicit range of words (such as traditionally -found in the CONSULT command) at run time, and they are not I6 grammar -tokens, and do not appear in Verb declarations: otherwise, such -routines are very similar to GPRs. -

    - -

    First, we need to look after a pointer to the CG used to hold the grammar -being matched against the snippet of words. -

    - -
    -inter_name *RTCommandGrammars::consult_iname(command_grammar *cg) {
    -    if (cg == NULL) return NULL;
    -    if (cg->compilation_data.cg_consult_iname == NULL) {
    -        current_sentence = cg->where_cg_created;
    -        package_request *PR = Hierarchy::local_package(CONSULT_TOKENS_HAP);
    -        cg->compilation_data.cg_consult_iname = Hierarchy::make_iname_in(CONSULT_FN_HL, PR);
    -    }
    -    return cg->compilation_data.cg_consult_iname;
    -}
    -
    diff --git a/docs/runtime-module/7-cgl.html b/docs/runtime-module/7-cgl.html index 94251d989..9c0df4628 100644 --- a/docs/runtime-module/7-cgl.html +++ b/docs/runtime-module/7-cgl.html @@ -123,7 +123,7 @@ the mistake. } } -void RTCommandGrammarLines::cgl_compile_mistake_token_as_needed(cg_line *cgl) { +void RTCommandGrammarLines::cgl_compile_mistake_token_as_needed(cg_line *cgl) { if (cgl->mistaken) { packaging_state save = Functions::begin(cgl->compilation_data.mistake_iname); @@ -172,7 +172,7 @@ the mistake. int RTCommandGrammarLines::cgl_compile_result_of_mistake(gpr_kit *gprk, cg_line *cgl) { if (cgl->mistaken) { if (MistakeAction_iname == NULL) internal_error("no MistakeAction yet"); - EmitArrays::iname_entry(VERB_DIRECTIVE_RESULT_iname); + EmitArrays::iname_entry(Hierarchy::find(VERB_DIRECTIVE_RESULT_HL)); EmitArrays::iname_entry(MistakeAction_iname); return TRUE; } @@ -238,7 +238,7 @@ the mistake. Hierarchy::make_available(MistakeAction_iname); } -void RTCommandGrammarLines::cgl_compile_condition_token_as_needed(cg_line *cgl) { +void RTCommandGrammarLines::cgl_compile_condition_token_as_needed(cg_line *cgl) { if (CGLines::conditional(cgl)) { current_sentence = cgl->where_grammar_specified; @@ -322,7 +322,7 @@ of the name pro

    -void RTCommandGrammarLines::sorted_line_list_compile(gpr_kit *gprk,
    +void RTCommandGrammarLines::sorted_line_list_compile(gpr_kit *gprk,
         int cg_is, command_grammar *cg, int genuinely_verbal) {
         LOG_INDENT;
         LOOP_THROUGH_SORTED_CG_LINES(cgl, cg)
    @@ -342,7 +342,7 @@ purely cosmetic effect.
     int current_label = 1;
     int GV_IS_VALUE_instance_mode = FALSE;
     
    -void RTCommandGrammarLines::reset_labels(void) {
    +void RTCommandGrammarLines::reset_labels(void) {
         current_label = 1;
     }
     
    @@ -384,7 +384,7 @@ command CGs) have not yet been type-checked, whereas all others have. token_values = 0; for (i=0; i<2; i++) token_value_kinds[i] = NULL; - if (code_mode == FALSE) EmitArrays::iname_entry(VERB_DIRECTIVE_DIVIDER_iname); + if (code_mode == FALSE) EmitArrays::iname_entry(Hierarchy::find(VERB_DIRECTIVE_DIVIDER_HL)); inter_symbol *fail_label = NULL; @@ -416,7 +416,7 @@ command CGs) have not yet been type-checked, whereas all others have. EmitCode::inv(EQ_BIP); EmitCode::down(); EmitCode::val_symbol(K_value, gprk->instance_s); - RTCommandGrammars::emit_determination_type(&(cgl->cgl_type)); + RTCommandGrammars::emit_determination_type(&(cgl->cgl_type)); EmitCode::up(); EmitCode::code(); EmitCode::down(); @@ -429,7 +429,7 @@ command CGs) have not yet been type-checked, whereas all others have. switch (cg_is) { case CG_IS_COMMAND: if (RTCommandGrammarLines::cgl_compile_result_of_mistake(gprk, cgl)) break; - EmitArrays::iname_entry(VERB_DIRECTIVE_RESULT_iname); + EmitArrays::iname_entry(Hierarchy::find(VERB_DIRECTIVE_RESULT_HL)); EmitArrays::iname_entry(RTActions::double_sharp(cgl->resulting_action)); if (cgl->reversed) { @@ -443,7 +443,7 @@ command CGs) have not yet been type-checked, whereas all others have. kind *swap = token_value_kinds[0]; token_value_kinds[0] = token_value_kinds[1]; token_value_kinds[1] = swap; - EmitArrays::iname_entry(VERB_DIRECTIVE_REVERSE_iname); + EmitArrays::iname_entry(Hierarchy::find(VERB_DIRECTIVE_REVERSE_HL)); } ActionSemantics::check_valid_application(cgl->resulting_action, token_values, @@ -515,7 +515,7 @@ command CGs) have not yet been type-checked, whereas all others have. EmitCode::inv(STORE_BIP); EmitCode::down(); EmitCode::ref_iname(K_value, Hierarchy::find(PARSED_NUMBER_HL)); - RTCommandGrammars::emit_determination_type(&(cgl->cgl_type)); + RTCommandGrammars::emit_determination_type(&(cgl->cgl_type)); EmitCode::up(); EmitCode::inv(RETURN_BIP); EmitCode::down(); @@ -642,6 +642,10 @@ command CGs) have not yet been type-checked, whereas all others have. sgpr->sgpr_iname = Hierarchy::make_iname_in(SLASH_FN_HL, PR); EmitArrays::iname_entry(sgpr->sgpr_iname); last_token_in_lexeme = TRUE; + text_stream *desc = Str::new(); + WRITE_TO(desc, "slash GPR %d", sgpr->allocation_id); + Sequence::queue(&RTCommandGrammarLines::slash_GPR_agent, + STORE_POINTER_slash_gpr(sgpr), desc); } else { kind *grammar_token_kind = RTCommandGrammarLines::compile_token(gprk, cgt, code_mode, jump_on_fail, consult_mode); @@ -678,7 +682,8 @@ command CGs) have not yet been type-checked, whereas all others have. Jump to end of group7.1; } } else { - if (last_token_in_lexeme == FALSE) EmitArrays::iname_entry(VERB_DIRECTIVE_SLASH_iname); + if (last_token_in_lexeme == FALSE) + EmitArrays::iname_entry(Hierarchy::find(VERB_DIRECTIVE_SLASH_HL)); } } @@ -706,21 +711,19 @@ command CGs) have not yet been type-checked, whereas all others have.

    §8.

    -void RTCommandGrammarLines::compile_slash_gprs(void) {
    -    slash_gpr *sgpr;
    -    LOOP_OVER(sgpr, slash_gpr) {
    -        packaging_state save = Functions::begin(sgpr->sgpr_iname);
    -        gpr_kit gprk = GPRs::new_kit();
    -        GPRs::add_original_var(&gprk);
    -        GPRs::add_standard_vars(&gprk);
    +void RTCommandGrammarLines::slash_GPR_agent(compilation_subtask *t) {
    +    slash_gpr *sgpr = RETRIEVE_POINTER_slash_gpr(t->data);
    +    packaging_state save = Functions::begin(sgpr->sgpr_iname);
    +    gpr_kit gprk = GPRs::new_kit();
    +    GPRs::add_original_var(&gprk);
    +    GPRs::add_standard_vars(&gprk);
     
    -        RTCommandGrammarLines::compile_token_line(&gprk, TRUE, sgpr->first_choice, sgpr->last_choice, CG_IS_TOKEN, FALSE, NULL, NULL, gprk.group_wn_s, NULL);
    -        EmitCode::inv(RETURN_BIP);
    -        EmitCode::down();
    -            EmitCode::val_iname(K_value, Hierarchy::find(GPR_PREPOSITION_HL));
    -        EmitCode::up();
    -        Functions::end(save);
    -    }
    +    RTCommandGrammarLines::compile_token_line(&gprk, TRUE, sgpr->first_choice, sgpr->last_choice, CG_IS_TOKEN, FALSE, NULL, NULL, gprk.group_wn_s, NULL);
    +    EmitCode::inv(RETURN_BIP);
    +    EmitCode::down();
    +        EmitCode::val_iname(K_value, Hierarchy::find(GPR_PREPOSITION_HL));
    +    EmitCode::up();
    +    Functions::end(save);
     }
     

    §9. This function looks through a CGL list and marks to suppress all those @@ -1399,7 +1402,7 @@ nothing else. } else { kind *K = NULL; if (CGTokens::is_I6_parser_token(cgt)) { - inter_name *i6_token_iname = RTCommandGrammars::iname_for_I6_parser_token(cgt); + inter_name *i6_token_iname = RTCommandGrammars::iname_for_I6_parser_token(cgt); K = Descriptions::explicit_kind(cgt->what_token_describes); if (code_mode) { if ((consult_mode) && (CGTokens::is_topic(cgt))) { @@ -1543,7 +1546,7 @@ nothing else. EmitCode::call(Hierarchy::find(PARSETOKENSTOPPED_HL)); EmitCode::down(); EmitCode::val_iname(K_value, Hierarchy::find(GPR_TT_HL)); - EmitCode::val_iname(K_value, RTCommandGrammars::i6_token_as_iname(cg)); + EmitCode::val_iname(K_value, RTCommandGrammars::get_cg_token_iname(cg)); EmitCode::up(); EmitCode::up(); EmitCode::inv(IF_BIP); @@ -1573,7 +1576,7 @@ nothing else. EmitCode::up(); EmitCode::up(); } else { - EmitArrays::iname_entry(RTCommandGrammars::i6_token_as_iname(cg)); + EmitArrays::iname_entry(RTCommandGrammars::get_cg_token_iname(cg)); } K = CommandGrammars::get_kind_matched(cg); } else diff --git a/docs/runtime-module/7-tpv.html b/docs/runtime-module/7-tpv.html index b719f758d..3dc1eeddb 100644 --- a/docs/runtime-module/7-tpv.html +++ b/docs/runtime-module/7-tpv.html @@ -83,7 +83,7 @@ function togglePopup(material_id) { gpr_kit gprk = GPRs::new_kit(); GPRs::add_original_var(&gprk); command_grammar *cg = CommandGrammars::get_parsing_grammar(K_number); - if (cg) RTCommandGrammars::compile_iv(&gprk, cg); + if (cg) RTCommandGrammars::compile_iv(&gprk, cg); EmitCode::inv(RETURN_BIP); EmitCode::down(); EmitCode::val_iname(K_value, Hierarchy::find(GPR_FAIL_HL)); @@ -100,7 +100,7 @@ function togglePopup(material_id) { kind *K = TimesOfDay::kind(); if (K) { command_grammar *cg = CommandGrammars::get_parsing_grammar(K); - if (cg) RTCommandGrammars::compile_iv(&gprk, cg); + if (cg) RTCommandGrammars::compile_iv(&gprk, cg); } EmitCode::inv(RETURN_BIP); EmitCode::down(); @@ -116,7 +116,7 @@ function togglePopup(material_id) { gpr_kit gprk = GPRs::new_kit(); GPRs::add_original_var(&gprk); command_grammar *cg = CommandGrammars::get_parsing_grammar(K_truth_state); - if (cg) RTCommandGrammars::compile_iv(&gprk, cg); + if (cg) RTCommandGrammars::compile_iv(&gprk, cg); EmitCode::inv(RETURN_BIP); EmitCode::down(); EmitCode::val_iname(K_value, Hierarchy::find(GPR_FAIL_HL)); @@ -231,7 +231,7 @@ function togglePopup(material_id) { cg = CommandGrammars::get_parsing_grammar(K); if (cg != NULL) { - RTCommandGrammars::compile_iv(&gprk, cg); + RTCommandGrammars::compile_iv(&gprk, cg); Reset word number1.1.2; } longest = 0; diff --git a/inform7/Figures/memory-diagnostics.txt b/inform7/Figures/memory-diagnostics.txt index 5e45b1d2d..99948a83a 100644 --- a/inform7/Figures/memory-diagnostics.txt +++ b/inform7/Figures/memory-diagnostics.txt @@ -1,9 +1,9 @@ -Total memory consumption was 303822K = 297 MB +Total memory consumption was 303908K = 297 MB -63.7% was used for 1504444 objects, in 320547 frames in 242 x 800K = 193600K = 189 MB: +63.7% was used for 1504665 objects, in 320669 frames in 242 x 800K = 193600K = 189 MB: - 9.5% inter_tree_node_array 41 x 8192 = 335872 objects, 29558048 bytes - 6.1% text_stream_array 3387 x 100 = 338700 objects, 19075584 bytes + 9.4% inter_tree_node_array 41 x 8192 = 335872 objects, 29558048 bytes + 6.1% text_stream_array 3388 x 100 = 338800 objects, 19081216 bytes 5.2% linked_list 29346 objects, 16433760 bytes 3.3% parse_node 129374 objects, 10349920 bytes 2.8% inter_symbol_array 89 x 1024 = 91136 objects, 8751904 bytes @@ -17,16 +17,16 @@ Total memory consumption was 303822K = 297 MB 0.4% inter_name_array 32 x 1000 = 32000 objects, 1537024 bytes 0.4% i6_schema_array 23 x 100 = 2300 objects, 1380736 bytes 0.4% match_trie_array 10 x 1000 = 10000 objects, 1360320 bytes - 0.3% inter_package 15429 objects, 1110888 bytes + 0.3% inter_package 15427 objects, 1110744 bytes 0.3% id_body 940 objects, 1075360 bytes 0.3% inter_name_generator_array 26 x 1000 = 26000 objects, 1040832 bytes 0.3% adjective_meaning 202 objects, 1000304 bytes - 0.3% inter_symbols_table 15429 objects, 987456 bytes - 0.3% dictionary 20442 objects, 981216 bytes + 0.3% inter_symbols_table 15427 objects, 987328 bytes + 0.3% dictionary 20439 objects, 981072 bytes 0.3% excerpt_meaning 3098 objects, 966576 bytes 0.2% dict_entry_array 281 x 100 = 28100 objects, 908192 bytes 0.2% production 3871 objects, 898072 bytes - 0.2% package_request 10003 objects, 880264 bytes + 0.2% package_request 10001 objects, 880088 bytes 0.2% ptoken 8379 objects, 871416 bytes 0.2% grammatical_usage 3610 objects, 866400 bytes 0.2% individual_form 2560 objects, 860160 bytes @@ -39,7 +39,7 @@ Total memory consumption was 303822K = 297 MB 0.1% verb_form 386 objects, 345856 bytes ---- noun 2379 objects, 285480 bytes ---- inference_subject 665 objects, 260680 bytes - ---- compilation_subtask 2773 objects, 221840 bytes + ---- compilation_subtask 2903 objects, 232240 bytes ---- inter_annotation_array 1 x 8192 objects, 196640 bytes ---- binary_predicate 321 objects, 169488 bytes ---- linguistic_stock_item 3315 objects, 159120 bytes @@ -54,7 +54,7 @@ Total memory consumption was 303822K = 297 MB ---- anl_entry_array 2 x 1000 = 2000 objects, 96064 bytes ---- noun_usage 2401 objects, 96040 bytes ---- preposition 273 objects, 87360 bytes - ---- inter_tree 6 objects, 84528 bytes + ---- inter_tree 6 objects, 84480 bytes ---- lexical_cluster 2516 objects, 80512 bytes ---- pcalc_term_array 2 x 1000 = 2000 objects, 80064 bytes ---- kind_variable_declaration 1652 objects, 79296 bytes @@ -110,7 +110,7 @@ Total memory consumption was 303822K = 297 MB ---- booking_list 407 objects, 13024 bytes ---- adjective_iname_holder 320 objects, 12800 bytes ---- pathname 292 objects, 11680 bytes - ---- stopwatch_timer 109 objects, 8720 bytes + ---- stopwatch_timer 110 objects, 8800 bytes ---- filename 208 objects, 8320 bytes ---- uniqueness_count 328 objects, 7872 bytes ---- equation_node 68 objects, 7616 bytes @@ -119,7 +119,7 @@ Total memory consumption was 303822K = 297 MB ---- determiner 22 objects, 7216 bytes ---- verb 108 objects, 6048 bytes ---- text_literal_holder 144 objects, 5760 bytes - ---- hierarchy_attachment_point 54 objects, 5184 bytes + ---- hierarchy_attachment_point 53 objects, 5088 bytes ---- inbuild_work 78 objects, 4992 bytes ---- explicit_action_array 1 x 100 objects, 4832 bytes ---- value_property_data 84 objects, 4704 bytes @@ -238,15 +238,15 @@ Total memory consumption was 303822K = 297 MB 36.2% was used for memory not allocated for objects: - 17.0% text stream storage 52937068 bytes in 350617 claims - 3.6% dictionary storage 11337728 bytes in 20442 claims - ---- sorting 720 bytes in 3 claims + 17.0% text stream storage 53026808 bytes in 350844 claims + 3.6% dictionary storage 11336192 bytes in 20439 claims + ---- sorting 728 bytes in 3 claims 2.3% source text 7200000 bytes in 3 claims 3.4% source text details 10800000 bytes in 2 claims ---- linguistic stock array 81920 bytes in 2 claims ---- small word set array 105600 bytes in 22 claims - 0.8% inter symbols storage 2671296 bytes in 16401 claims - 5.4% inter bytecode storage 16802796 bytes in 14 claims + 0.8% inter symbols storage 2671040 bytes in 16399 claims + 5.3% inter bytecode storage 16802796 bytes in 14 claims 2.8% inter links storage 8866944 bytes in 265 claims ---- inter tree location list storage 166656 bytes in 26 claims 0.5% instance-of-kind counting 1695204 bytes in 1 claim @@ -255,5 +255,5 @@ Total memory consumption was 303822K = 297 MB ---- code generation workspace for objects 9648 bytes in 9 claims ---- emitter array storage 154432 bytes in 2037 claims -20.2% was overhead - 63008400 bytes = 61531K = 60 MB +20.2% was overhead - 62993024 bytes = 61516K = 60 MB diff --git a/inform7/Figures/timings-diagnostics.txt b/inform7/Figures/timings-diagnostics.txt index b3bf6a61b..082ef0532 100644 --- a/inform7/Figures/timings-diagnostics.txt +++ b/inform7/Figures/timings-diagnostics.txt @@ -1,33 +1,33 @@ 100.0% in inform7 run - 53.7% in compilation to Inter - 40.3% in //Sequence::undertake_queued_tasks// - 3.7% in //MajorNodes::pre_pass// - 3.0% in //MajorNodes::pass_1// + 53.9% in compilation to Inter + 40.5% in //Sequence::undertake_queued_tasks// + 3.4% in //MajorNodes::pre_pass// + 2.9% in //MajorNodes::pass_1// 1.6% in //ImperativeDefinitions::assess_all// - 0.5% in //ImperativeDefinitions::compile_first_block// - 0.5% in //MajorNodes::pass_2// - 0.5% in //RTKindConstructors::compile// - 0.5% in //World::stage_V// + 0.4% in //ImperativeDefinitions::compile_first_block// + 0.4% in //MajorNodes::pass_2// + 0.4% in //RTKindConstructors::compile// + 0.4% in //World::stage_V// 0.3% in //Sequence::undertake_queued_tasks// 0.1% in //InferenceSubjects::emit_all// 0.1% in //RTKindConstructors::compile_permissions// 0.1% in //Task::make_built_in_kind_constructors// 0.1% in //World::stages_II_and_III// - 2.0% not specifically accounted for + 2.3% not specifically accounted for 43.8% in running Inter pipeline 11.2% in inter step 7/14: consolidate-text - 10.6% in step preparation - 9.4% in inter step 2/14: link - 7.4% in inter step 14/14: generate inform6 -> auto.inf + 10.9% in step preparation + 9.3% in inter step 2/14: link + 7.1% in inter step 14/14: generate inform6 -> auto.inf 0.8% in inter step 10/14: make-identifiers-unique 0.3% in inter step 11/14: reconcile-verbs 0.3% in inter step 13/14: eliminate-redundant-operations - 0.3% in inter step 6/14: assimilate 0.1% in inter step 12/14: eliminate-redundant-labels 0.1% in inter step 4/14: parse-linked-matter 0.1% in inter step 5/14: resolve-conditional-compilation + 0.1% in inter step 6/14: assimilate 0.1% in inter step 8/14: resolve-external-symbols 0.1% in inter step 9/14: inspect-plugs - 2.4% not specifically accounted for - 2.0% in supervisor + 2.7% not specifically accounted for + 1.8% in supervisor 0.4% not specifically accounted for diff --git a/inform7/if-module/Chapter 5/Command Grammars.w b/inform7/if-module/Chapter 5/Command Grammars.w index e928a6b99..8c0647552 100644 --- a/inform7/if-module/Chapter 5/Command Grammars.w +++ b/inform7/if-module/Chapter 5/Command Grammars.w @@ -82,7 +82,7 @@ command_grammar *CommandGrammars::cg_new(int cg_is) { cg->where_cg_created = current_sentence; cg->slashed = FALSE; cg->determined = FALSE; - cg->compilation_data = RTCommandGrammars::new_compilation_data(); + cg->compilation_data = RTCommandGrammars::new_compilation_data(cg); return cg; } @@ -252,7 +252,6 @@ command_grammar *CommandGrammars::new_named_token(wording W) { if (cg == NULL) { cg = CommandGrammars::cg_new(CG_IS_TOKEN); cg->token_name = W; - RTCommandGrammars::new_CG_IS_TOKEN(cg, W); } return cg; } @@ -397,7 +396,6 @@ command_grammar *CommandGrammars::for_prn(property *prn) { command_grammar *cg = CommandGrammars::cg_new(CG_IS_PROPERTY_NAME); EitherOrProperties::set_parsing_grammar(prn, cg); cg->prn_understood = prn; - RTCommandGrammars::new_CG_IS_PROPERTY_NAME(cg, prn); return cg; } diff --git a/inform7/if-module/Chapter 5/Parsing Plugin.w b/inform7/if-module/Chapter 5/Parsing Plugin.w index 4f3db32a6..33f0413f2 100644 --- a/inform7/if-module/Chapter 5/Parsing Plugin.w +++ b/inform7/if-module/Chapter 5/Parsing Plugin.w @@ -45,6 +45,7 @@ int ParsingPlugin::production_line(int stage, int debugging, BENCH(UnderstandFilterTokens::compile); } if (stage == INTER4_CSEQ) { + BENCH(CommandGrammars::prepare); BENCH(RTCommandGrammars::compile_all); BENCH(UnderstandFilterTokens::compile); } diff --git a/inform7/imperative-module/Chapter 2/Compile Rvalues.w b/inform7/imperative-module/Chapter 2/Compile Rvalues.w index 6989fb573..e28d66eb1 100644 --- a/inform7/imperative-module/Chapter 2/Compile Rvalues.w +++ b/inform7/imperative-module/Chapter 2/Compile Rvalues.w @@ -363,7 +363,7 @@ void CompileRvalues::compile_understanding(inter_ti *val1, inter_ti *val2, wordi return; } command_grammar *cg = Understand::consultation(W); - inter_name *iname = RTCommandGrammars::consult_iname(cg); + inter_name *iname = RTCommandGrammars::get_consult_fn_iname(cg); if (iname) { cu = CREATE(cached_understanding); cu->understanding_text = W; diff --git a/inform7/runtime-module/Chapter 2/Hierarchy.w b/inform7/runtime-module/Chapter 2/Hierarchy.w index 461b5328b..ba8f37797 100644 --- a/inform7/runtime-module/Chapter 2/Hierarchy.w +++ b/inform7/runtime-module/Chapter 2/Hierarchy.w @@ -554,8 +554,6 @@ void Hierarchy::establish(void) { @e COND_TOKENS_HAP @e CONDITIONAL_TOKEN_FN_HL -@e CONSULT_TOKENS_HAP -@e CONSULT_FN_HL @e TESTS_HAP @e SCRIPT_HL @e TEST_MD_HL @@ -564,9 +562,7 @@ void Hierarchy::establish(void) { @e REQUIREMENTS_HL @e MISTAKES_HAP @e MISTAKE_FN_HL -@e NAMED_TOKENS_HAP @e NO_VERB_VERB_DEFINED_HL -@e PARSE_LINE_FN_HL @e NOUN_FILTERS_HAP @e NOUN_FILTER_FN_HL @e PARSE_NAMES_HAP @@ -599,6 +595,11 @@ void Hierarchy::establish(void) { @e MISTAKEACTION_HL @e MISTAKEACTIONSUB_HL +@e COMMAND_GRAMMARS_HAP +@e PROPERTY_GPR_FN_HL +@e PARSE_LINE_FN_HL +@e CONSULT_FN_HL + @ = submodule_identity *grammar = Packaging::register_submodule(I"grammar"); @@ -624,9 +625,6 @@ void Hierarchy::establish(void) { H_BEGIN_AP(COND_TOKENS_HAP, I"conditional_token", I"_conditional_token") H_F_G(CONDITIONAL_TOKEN_FN_HL, I"conditional_token_fn", I"Cond_Token") H_END - H_BEGIN_AP(CONSULT_TOKENS_HAP, I"consult_token", I"_consult_token") - H_F_G(CONSULT_FN_HL, I"consult_fn", I"Consult_Grammar") - H_END H_BEGIN_AP(TESTS_HAP, I"test", I"_test") H_C_U(TEST_NAME_MD_HL, I"^name") H_C_U(TEST_LENGTH_MD_HL, I"^length") @@ -636,9 +634,6 @@ void Hierarchy::establish(void) { H_BEGIN_AP(MISTAKES_HAP, I"mistake", I"_mistake") H_F_G(MISTAKE_FN_HL, I"mistake_fn", I"Mistake_Token") H_END - H_BEGIN_AP(NAMED_TOKENS_HAP, I"named_token", I"_named_token") - H_F_G(PARSE_LINE_FN_HL, I"parse_line_fn", I"GPR_Line") - H_END H_BEGIN_AP(NOUN_FILTERS_HAP, I"noun_filter", I"_noun_filter") H_F_G(NOUN_FILTER_FN_HL, I"filter_fn", I"Noun_Filter") H_END @@ -660,6 +655,11 @@ void Hierarchy::establish(void) { H_BEGIN_AP(COMMANDS_HAP, I"command", I"_command") H_F_G(VERB_DECLARATION_ARRAY_HL, NULL, I"GV_Grammar") H_END + H_BEGIN_AP(COMMAND_GRAMMARS_HAP, I"command_grammar", I"_command_grammar") + H_F_G(PROPERTY_GPR_FN_HL, I"either_or_GPR_fn", I"PRN_PN") + H_F_G(PARSE_LINE_FN_HL, I"parse_line_fn", I"GPR_Line") + H_F_G(CONSULT_FN_HL, I"consult_fn", I"Consult_Grammar") + H_END H_F_T(MISTAKEACTIONSUB_HL, I"MistakeActionSub_fn", I"MistakeActionSub") H_C_T(NO_VERB_VERB_DEFINED_HL, I"NO_VERB_VERB_DEFINED") H_END @@ -949,7 +949,6 @@ void Hierarchy::establish(void) { @e PROPERTY_NAME_MD_HL @e PROPERTY_ID_HL @e PROPERTY_HL -@e EITHER_OR_GPR_FN_HL @ = submodule_identity *properties = Packaging::register_submodule(I"properties"); @@ -959,7 +958,6 @@ void Hierarchy::establish(void) { H_C_U(PROPERTY_NAME_MD_HL, I"^name") H_C_U(PROPERTY_ID_HL, I"property_id") H_C_T(PROPERTY_HL, I"P") - H_F_G(EITHER_OR_GPR_FN_HL, I"either_or_GPR_fn", I"PRN_PN") H_END H_END diff --git a/inform7/runtime-module/Chapter 6/Parse Name Properties.w b/inform7/runtime-module/Chapter 6/Parse Name Properties.w index e0ac02991..a8ba4ac16 100644 --- a/inform7/runtime-module/Chapter 6/Parse Name Properties.w +++ b/inform7/runtime-module/Chapter 6/Parse Name Properties.w @@ -1070,7 +1070,6 @@ void ParseName::parse_visible_either_or(gpr_kit *kit, property *prn, int visibil EmitCode::up(); EmitCode::up(); if (cg) { - if (cg->compilation_data.cg_prn_iname == NULL) internal_error("no PRN iname"); @; EmitCode::inv(IF_BIP); EmitCode::down(); @@ -1079,7 +1078,7 @@ void ParseName::parse_visible_either_or(gpr_kit *kit, property *prn, int visibil EmitCode::test_if_iname_has_property(K_value, Hierarchy::find(SELF_HL), prn); EmitCode::inv(EQ_BIP); EmitCode::down(); - EmitCode::call(cg->compilation_data.cg_prn_iname); + EmitCode::call(RTCommandGrammars::get_property_GPR_fn_iname(cg)); EmitCode::val_iname(K_value, Hierarchy::find(GPR_PREPOSITION_HL)); EmitCode::up(); EmitCode::up(); diff --git a/inform7/runtime-module/Chapter 7/Command Grammar Lines.w b/inform7/runtime-module/Chapter 7/Command Grammar Lines.w index b3d502612..5a25406e5 100644 --- a/inform7/runtime-module/Chapter 7/Command Grammar Lines.w +++ b/inform7/runtime-module/Chapter 7/Command Grammar Lines.w @@ -96,7 +96,7 @@ inter_name *MistakeAction_iname = NULL; int RTCommandGrammarLines::cgl_compile_result_of_mistake(gpr_kit *gprk, cg_line *cgl) { if (cgl->mistaken) { if (MistakeAction_iname == NULL) internal_error("no MistakeAction yet"); - EmitArrays::iname_entry(VERB_DIRECTIVE_RESULT_iname); + EmitArrays::iname_entry(Hierarchy::find(VERB_DIRECTIVE_RESULT_HL)); EmitArrays::iname_entry(MistakeAction_iname); return TRUE; } @@ -305,7 +305,7 @@ void RTCommandGrammarLines::compile_cg_line(gpr_kit *gprk, cg_line *cgl, int cg_ token_values = 0; for (i=0; i<2; i++) token_value_kinds[i] = NULL; - if (code_mode == FALSE) EmitArrays::iname_entry(VERB_DIRECTIVE_DIVIDER_iname); + if (code_mode == FALSE) EmitArrays::iname_entry(Hierarchy::find(VERB_DIRECTIVE_DIVIDER_HL)); inter_symbol *fail_label = NULL; @@ -350,7 +350,7 @@ void RTCommandGrammarLines::compile_cg_line(gpr_kit *gprk, cg_line *cgl, int cg_ switch (cg_is) { case CG_IS_COMMAND: if (RTCommandGrammarLines::cgl_compile_result_of_mistake(gprk, cgl)) break; - EmitArrays::iname_entry(VERB_DIRECTIVE_RESULT_iname); + EmitArrays::iname_entry(Hierarchy::find(VERB_DIRECTIVE_RESULT_HL)); EmitArrays::iname_entry(RTActions::double_sharp(cgl->resulting_action)); if (cgl->reversed) { @@ -364,7 +364,7 @@ void RTCommandGrammarLines::compile_cg_line(gpr_kit *gprk, cg_line *cgl, int cg_ kind *swap = token_value_kinds[0]; token_value_kinds[0] = token_value_kinds[1]; token_value_kinds[1] = swap; - EmitArrays::iname_entry(VERB_DIRECTIVE_REVERSE_iname); + EmitArrays::iname_entry(Hierarchy::find(VERB_DIRECTIVE_REVERSE_HL)); } ActionSemantics::check_valid_application(cgl->resulting_action, token_values, @@ -558,6 +558,10 @@ void RTCommandGrammarLines::compile_token_line(gpr_kit *gprk, int code_mode, cg_ sgpr->sgpr_iname = Hierarchy::make_iname_in(SLASH_FN_HL, PR); EmitArrays::iname_entry(sgpr->sgpr_iname); last_token_in_lexeme = TRUE; + text_stream *desc = Str::new(); + WRITE_TO(desc, "slash GPR %d", sgpr->allocation_id); + Sequence::queue(&RTCommandGrammarLines::slash_GPR_agent, + STORE_POINTER_slash_gpr(sgpr), desc); } else { kind *grammar_token_kind = RTCommandGrammarLines::compile_token(gprk, cgt, code_mode, jump_on_fail, consult_mode); @@ -594,7 +598,8 @@ void RTCommandGrammarLines::compile_token_line(gpr_kit *gprk, int code_mode, cg_ @; } } else { - if (last_token_in_lexeme == FALSE) EmitArrays::iname_entry(VERB_DIRECTIVE_SLASH_iname); + if (last_token_in_lexeme == FALSE) + EmitArrays::iname_entry(Hierarchy::find(VERB_DIRECTIVE_SLASH_HL)); } } @@ -616,21 +621,19 @@ void RTCommandGrammarLines::compile_token_line(gpr_kit *gprk, int code_mode, cg_ EmitCode::up(); @ = -void RTCommandGrammarLines::compile_slash_gprs(void) { - slash_gpr *sgpr; - LOOP_OVER(sgpr, slash_gpr) { - packaging_state save = Functions::begin(sgpr->sgpr_iname); - gpr_kit gprk = GPRs::new_kit(); - GPRs::add_original_var(&gprk); - GPRs::add_standard_vars(&gprk); +void RTCommandGrammarLines::slash_GPR_agent(compilation_subtask *t) { + slash_gpr *sgpr = RETRIEVE_POINTER_slash_gpr(t->data); + packaging_state save = Functions::begin(sgpr->sgpr_iname); + gpr_kit gprk = GPRs::new_kit(); + GPRs::add_original_var(&gprk); + GPRs::add_standard_vars(&gprk); - RTCommandGrammarLines::compile_token_line(&gprk, TRUE, sgpr->first_choice, sgpr->last_choice, CG_IS_TOKEN, FALSE, NULL, NULL, gprk.group_wn_s, NULL); - EmitCode::inv(RETURN_BIP); - EmitCode::down(); - EmitCode::val_iname(K_value, Hierarchy::find(GPR_PREPOSITION_HL)); - EmitCode::up(); - Functions::end(save); - } + RTCommandGrammarLines::compile_token_line(&gprk, TRUE, sgpr->first_choice, sgpr->last_choice, CG_IS_TOKEN, FALSE, NULL, NULL, gprk.group_wn_s, NULL); + EmitCode::inv(RETURN_BIP); + EmitCode::down(); + EmitCode::val_iname(K_value, Hierarchy::find(GPR_PREPOSITION_HL)); + EmitCode::up(); + Functions::end(save); } @ This function looks through a CGL list and marks to suppress all those @@ -1453,7 +1456,7 @@ kind *RTCommandGrammarLines::compile_token(gpr_kit *gprk, cg_token *cgt, int cod EmitCode::call(Hierarchy::find(PARSETOKENSTOPPED_HL)); EmitCode::down(); EmitCode::val_iname(K_value, Hierarchy::find(GPR_TT_HL)); - EmitCode::val_iname(K_value, RTCommandGrammars::i6_token_as_iname(cg)); + EmitCode::val_iname(K_value, RTCommandGrammars::get_cg_token_iname(cg)); EmitCode::up(); EmitCode::up(); EmitCode::inv(IF_BIP); @@ -1483,7 +1486,7 @@ kind *RTCommandGrammarLines::compile_token(gpr_kit *gprk, cg_token *cgt, int cod EmitCode::up(); EmitCode::up(); } else { - EmitArrays::iname_entry(RTCommandGrammars::i6_token_as_iname(cg)); + EmitArrays::iname_entry(RTCommandGrammars::get_cg_token_iname(cg)); } K = CommandGrammars::get_kind_matched(cg); } else diff --git a/inform7/runtime-module/Chapter 7/Command Grammars.w b/inform7/runtime-module/Chapter 7/Command Grammars.w index c40e1cf8b..6f6bbf9d2 100644 --- a/inform7/runtime-module/Chapter 7/Command Grammars.w +++ b/inform7/runtime-module/Chapter 7/Command Grammars.w @@ -2,51 +2,133 @@ Runtime support for CGs. -@ +@h Generic constants. + += +void RTCommandGrammars::compile_generic_constants(void) { + RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_REVERSE_HL, 1); + RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_SLASH_HL, 1); + RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_DIVIDER_HL, 1); + RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_RESULT_HL, 2); + RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_SPECIAL_HL, 3); + RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_NUMBER_HL, 4); + RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_NOUN_HL, 5); + RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_MULTI_HL, 6); + RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_MULTIINSIDE_HL, 7); + RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_MULTIHELD_HL, 8); + RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_HELD_HL, 9); + RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_CREATURE_HL, 10); + RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_TOPIC_HL, 11); + RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_MULTIEXCEPT_HL, 12); +} + +inter_name *RTCommandGrammars::iname_for_I6_parser_token(cg_token *cgt) { + switch (cgt->grammar_token_code) { + case NOUN_TOKEN_GTC: return Hierarchy::find(VERB_DIRECTIVE_NOUN_HL); + case MULTI_TOKEN_GTC: return Hierarchy::find(VERB_DIRECTIVE_MULTI_HL); + case MULTIINSIDE_TOKEN_GTC: return Hierarchy::find(VERB_DIRECTIVE_MULTIINSIDE_HL); + case MULTIHELD_TOKEN_GTC: return Hierarchy::find(VERB_DIRECTIVE_MULTIHELD_HL); + case HELD_TOKEN_GTC: return Hierarchy::find(VERB_DIRECTIVE_HELD_HL); + case CREATURE_TOKEN_GTC: return Hierarchy::find(VERB_DIRECTIVE_CREATURE_HL); + case TOPIC_TOKEN_GTC: return Hierarchy::find(VERB_DIRECTIVE_TOPIC_HL); + case MULTIEXCEPT_TOKEN_GTC: return Hierarchy::find(VERB_DIRECTIVE_MULTIEXCEPT_HL); + default: internal_error("tried to find inter name for invalid GTC"); + } + return NULL; /* to prevent a compiler error: never reached */ +} + +inter_name *RTCommandGrammars::grammar_constant(int N, int V) { + inter_name *iname = Hierarchy::find(N); + Emit::numeric_constant(iname, 1); + Hierarchy::make_available(iname); + return iname; +} + +@h Compilation data. +Each |command_grammar| object contains this data: + += = typedef struct cg_compilation_data { + struct package_request *cg_package; + struct inter_name *cg_token_iname; /* |CG_IS_TOKEN| */ - struct inter_name *cg_parse_name_iname; /* |CG_IS_VALUE| */ - struct inter_name *cg_prn_iname; /* CG_IS_PROPERTY_NAME|: the relevant GPR is called this */ - struct inter_name *cg_consult_iname; /* for the consult parsing routine if needed */ - struct text_stream *cg_I6_identifier; /* when a token is delegated to an I6 routine */ + + struct inter_name *property_GPR_fn_iname; /* CG_IS_PROPERTY_NAME| */ + struct text_stream *CG_IS_TOKEN_identifier; /* CG_IS_PROPERTY_NAME| */ + + struct inter_name *consult_fn_iname; /* CG_IS_CONSULT| */ } cg_compilation_data; -cg_compilation_data RTCommandGrammars::new_compilation_data(void) { +cg_compilation_data RTCommandGrammars::new_compilation_data(command_grammar *cg) { cg_compilation_data cgcd; - cgcd.cg_parse_name_iname = NULL; - cgcd.cg_consult_iname = NULL; - cgcd.cg_prn_iname = NULL; + cgcd.cg_package = NULL; + cgcd.consult_fn_iname = NULL; + cgcd.property_GPR_fn_iname = NULL; cgcd.cg_token_iname = NULL; - cgcd.cg_I6_identifier = Str::new(); + cgcd.CG_IS_TOKEN_identifier = Str::new(); return cgcd; } -inter_name *RTCommandGrammars::i6_token_as_iname(command_grammar *cg) { - if (Str::len(cg->compilation_data.cg_I6_identifier) > 0) - return Produce::find_by_name(Emit::tree(), cg->compilation_data.cg_I6_identifier); - if (cg->compilation_data.cg_token_iname == NULL) internal_error("no token GPR"); +package_request *RTCommandGrammars::package(command_grammar *cg) { + if (cg->compilation_data.cg_package == NULL) + cg->compilation_data.cg_package = + Hierarchy::completion_package(COMMAND_GRAMMARS_HAP); + return cg->compilation_data.cg_package; +} + +inter_name *RTCommandGrammars::get_property_GPR_fn_iname(command_grammar *cg) { + if ((cg == NULL) || (cg->cg_is != CG_IS_PROPERTY_NAME)) + internal_error("prn_iname unavailable"); + if (cg->compilation_data.property_GPR_fn_iname == NULL) + cg->compilation_data.property_GPR_fn_iname = + Hierarchy::make_iname_in(PROPERTY_GPR_FN_HL, + RTCommandGrammars::package(cg)); + return cg->compilation_data.property_GPR_fn_iname; +} + +inter_name *RTCommandGrammars::get_cg_token_iname(command_grammar *cg) { + if ((cg == NULL) || (cg->cg_is != CG_IS_TOKEN)) + internal_error("cg_token_iname unavailable"); + if (cg->compilation_data.cg_token_iname == NULL) { + if (Str::len(cg->compilation_data.CG_IS_TOKEN_identifier) > 0) + cg->compilation_data.cg_token_iname = + Produce::find_by_name(Emit::tree(), + cg->compilation_data.CG_IS_TOKEN_identifier); + else + cg->compilation_data.cg_token_iname = + Hierarchy::make_iname_in(PARSE_LINE_FN_HL, + RTCommandGrammars::package(cg)); + } return cg->compilation_data.cg_token_iname; } -void RTCommandGrammars::new_CG_IS_PROPERTY_NAME(command_grammar *cg, property *prn) { - cg->compilation_data.cg_prn_iname = - Hierarchy::make_iname_in(EITHER_OR_GPR_FN_HL, RTProperties::package(prn)); -} - -void RTCommandGrammars::new_CG_IS_TOKEN(command_grammar *cg, wording W) { - package_request *PR = Hierarchy::local_package(NAMED_TOKENS_HAP); - cg->compilation_data.cg_token_iname = Hierarchy::make_iname_in(PARSE_LINE_FN_HL, PR); -} - void RTCommandGrammars::set_CG_IS_TOKEN_identifier(command_grammar *cg, wording W) { - WRITE_TO(cg->compilation_data.cg_I6_identifier, "%N", Wordings::first_wn(W)); + if (cg->compilation_data.cg_token_iname) internal_error("too late to translate"); + WRITE_TO(cg->compilation_data.CG_IS_TOKEN_identifier, "%N", Wordings::first_wn(W)); +} + +@ These are used to parse an explicit range of words (such as traditionally +found in the CONSULT command) at run time, and they are not I6 grammar +tokens, and do not appear in |Verb| declarations: otherwise, such +routines are very similar to GPRs. + +First, we need to look after a pointer to the CG used to hold the grammar +being matched against the snippet of words. + += +inter_name *RTCommandGrammars::get_consult_fn_iname(command_grammar *cg) { + if ((cg == NULL) || (cg->cg_is != CG_IS_CONSULT)) + internal_error("cg_token_iname unavailable"); + if (cg->compilation_data.consult_fn_iname == NULL) + cg->compilation_data.consult_fn_iname = + Hierarchy::make_iname_in(CONSULT_FN_HL, RTCommandGrammars::package(cg)); + return cg->compilation_data.consult_fn_iname; } void RTCommandGrammars::create_no_verb_verb(command_grammar *cg) { - inter_name *iname = Hierarchy::find(NO_VERB_VERB_DEFINED_HL); - Emit::numeric_constant(iname, (inter_ti) 1); + Emit::numeric_constant(Hierarchy::find(NO_VERB_VERB_DEFINED_HL), (inter_ti) 1); global_compilation_settings.no_verb_verb_exists = TRUE; } @@ -70,88 +152,168 @@ Sequence is important here: in particular the GPRs must exist before the |Verb| directives, because otherwise I6 will throw not-declared-yet errors. = -inter_name *VERB_DIRECTIVE_REVERSE_iname = NULL; -inter_name *VERB_DIRECTIVE_SLASH_iname = NULL; -inter_name *VERB_DIRECTIVE_DIVIDER_iname = NULL; -inter_name *VERB_DIRECTIVE_RESULT_iname = NULL; -inter_name *VERB_DIRECTIVE_SPECIAL_iname = NULL; -inter_name *VERB_DIRECTIVE_NUMBER_iname = NULL; -inter_name *VERB_DIRECTIVE_NOUN_iname = NULL; -inter_name *VERB_DIRECTIVE_MULTI_iname = NULL; -inter_name *VERB_DIRECTIVE_MULTIINSIDE_iname = NULL; -inter_name *VERB_DIRECTIVE_MULTIHELD_iname = NULL; -inter_name *VERB_DIRECTIVE_HELD_iname = NULL; -inter_name *VERB_DIRECTIVE_CREATURE_iname = NULL; -inter_name *VERB_DIRECTIVE_TOPIC_iname = NULL; -inter_name *VERB_DIRECTIVE_MULTIEXCEPT_iname = NULL; - -void RTCommandGrammars::compile_generic_constants(void) { - VERB_DIRECTIVE_REVERSE_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_REVERSE_HL, 1); - VERB_DIRECTIVE_SLASH_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_SLASH_HL, 1); - VERB_DIRECTIVE_DIVIDER_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_DIVIDER_HL, 1); - VERB_DIRECTIVE_RESULT_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_RESULT_HL, 2); - VERB_DIRECTIVE_SPECIAL_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_SPECIAL_HL, 3); - VERB_DIRECTIVE_NUMBER_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_NUMBER_HL, 4); - VERB_DIRECTIVE_NOUN_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_NOUN_HL, 5); - VERB_DIRECTIVE_MULTI_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_MULTI_HL, 6); - VERB_DIRECTIVE_MULTIINSIDE_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_MULTIINSIDE_HL, 7); - VERB_DIRECTIVE_MULTIHELD_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_MULTIHELD_HL, 8); - VERB_DIRECTIVE_HELD_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_HELD_HL, 9); - VERB_DIRECTIVE_CREATURE_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_CREATURE_HL, 10); - VERB_DIRECTIVE_TOPIC_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_TOPIC_HL, 11); - VERB_DIRECTIVE_MULTIEXCEPT_iname = RTCommandGrammars::grammar_constant(VERB_DIRECTIVE_MULTIEXCEPT_HL, 12); -} - -inter_name *RTCommandGrammars::iname_for_I6_parser_token(cg_token *cgt) { - switch (cgt->grammar_token_code) { - case NOUN_TOKEN_GTC: return VERB_DIRECTIVE_NOUN_iname; - case MULTI_TOKEN_GTC: return VERB_DIRECTIVE_MULTI_iname; - case MULTIINSIDE_TOKEN_GTC: return VERB_DIRECTIVE_MULTIINSIDE_iname; - case MULTIHELD_TOKEN_GTC: return VERB_DIRECTIVE_MULTIHELD_iname; - case HELD_TOKEN_GTC: return VERB_DIRECTIVE_HELD_iname; - case CREATURE_TOKEN_GTC: return VERB_DIRECTIVE_CREATURE_iname; - case TOPIC_TOKEN_GTC: return VERB_DIRECTIVE_TOPIC_iname; - case MULTIEXCEPT_TOKEN_GTC: return VERB_DIRECTIVE_MULTIEXCEPT_iname; - default: internal_error("tried to find inter name for invalid GTC"); - } - return NULL; /* to prevent a gcc error: never reached */ -} - -inter_name *RTCommandGrammars::grammar_constant(int N, int V) { - inter_name *iname = Hierarchy::find(N); - Emit::numeric_constant(iname, 1); - Hierarchy::make_available(iname); - return iname; -} - void RTCommandGrammars::compile_all(void) { command_grammar *cg; - CommandGrammars::prepare(); - - Log::new_stage(I"Sorting and compiling non-value grammar (G3, G4)"); - LOOP_OVER(cg, command_grammar) - if (cg->cg_is == CG_IS_TOKEN) - RTCommandGrammars::compile(cg); /* makes GPRs for designed tokens */ + if (cg->cg_is == CG_IS_TOKEN) { + text_stream *desc = Str::new(); + WRITE_TO(desc, "command grammar for token"); + Sequence::queue(&RTCommandGrammars::compile, + STORE_POINTER_command_grammar(cg), desc); + } LOOP_OVER(cg, command_grammar) - if (cg->cg_is == CG_IS_COMMAND) - RTCommandGrammars::compile(cg); /* makes |Verb| directives */ + if (cg->cg_is == CG_IS_COMMAND) { + text_stream *desc = Str::new(); + WRITE_TO(desc, "command grammar for command '%W'", cg->command); + Sequence::queue(&RTCommandGrammars::compile, + STORE_POINTER_command_grammar(cg), desc); + } LOOP_OVER(cg, command_grammar) - if (cg->cg_is == CG_IS_SUBJECT) - RTCommandGrammars::compile(cg); /* makes routines for use in |parse_name| */ + if (cg->cg_is == CG_IS_SUBJECT) { + text_stream *desc = Str::new(); + WRITE_TO(desc, "command grammar for parse_name on '%W'", + InferenceSubjects::get_name_text(cg->subj_understood)); + Sequence::queue(&RTCommandGrammars::compile, + STORE_POINTER_command_grammar(cg), desc); + } LOOP_OVER(cg, command_grammar) - if (cg->cg_is == CG_IS_CONSULT) - RTCommandGrammars::compile(cg); /* routines to parse snippets, used as values */ + if (cg->cg_is == CG_IS_CONSULT) { + text_stream *desc = Str::new(); + WRITE_TO(desc, "command grammar for consult at '%W'", + Node::get_text(cg->where_cg_created)); + Sequence::queue(&RTCommandGrammars::compile, + STORE_POINTER_command_grammar(cg), desc); + } LOOP_OVER(cg, command_grammar) - if (cg->cg_is == CG_IS_PROPERTY_NAME) - RTCommandGrammars::compile(cg); /* makes routines for use in |parse_name| */ + if (cg->cg_is == CG_IS_PROPERTY_NAME) { + text_stream *desc = Str::new(); + WRITE_TO(desc, "command grammar for property '%W'", + cg->prn_understood->name); + Sequence::queue(&RTCommandGrammars::compile, + STORE_POINTER_command_grammar(cg), desc); + } +} - RTCommandGrammarLines::compile_slash_gprs(); +@ The following function unites, so far as possible, the different forms of +CG by compiling each of them as a sandwich: top slice, filling, bottom slice. + +The interesting case is of a CG representing names for an object: the +name-behaviour needs to be inherited from the object's kind, and so on up +the kinds hierarchy, but this is a case where I7's kind hierarchy does not +agree with I6's class hierarchy. I6 has no (nice) way to inherit |parse_name| +behaviour from a class to an instance. So we will simply pile up extra +fillings into the sandwich. The order of these is important: by getting +in first, grammar for the instance takes priority; its immediate kind has +next priority, and so on up the hierarchy. + += +void RTCommandGrammars::compile(compilation_subtask *t) { + command_grammar *cg = RETRIEVE_POINTER_command_grammar(t->data); + if (CGLines::list_length(cg) == 0) return; + + LOGIF(GRAMMAR, "Compiling command grammar $G\n", cg); + + current_sentence = cg->where_cg_created; + + RTCommandGrammarLines::reset_labels(); + switch(cg->cg_is) { + case CG_IS_COMMAND: { + package_request *PR = Hierarchy::completion_package(COMMANDS_HAP); + inter_name *array_iname = Hierarchy::make_iname_in(VERB_DECLARATION_ARRAY_HL, PR); + packaging_state save = RTCommandGrammars::cg_compile_Verb_directive_header(cg, array_iname); + RTCommandGrammars::cg_compile_lines(NULL, cg); + EmitArrays::end(save); + break; + } + case CG_IS_TOKEN: { + gpr_kit gprk = GPRs::new_kit(); + inter_name *iname = RTCommandGrammars::get_cg_token_iname(cg); + packaging_state save = Functions::begin(iname); + GPRs::add_original_var(&gprk); + GPRs::add_standard_vars(&gprk); + EmitCode::inv(STORE_BIP); + EmitCode::down(); + EmitCode::ref_symbol(K_value, gprk.original_wn_s); + EmitCode::val_iname(K_value, Hierarchy::find(WN_HL)); + EmitCode::up(); + EmitCode::inv(STORE_BIP); + EmitCode::down(); + EmitCode::ref_symbol(K_value, gprk.rv_s); + EmitCode::val_iname(K_value, Hierarchy::find(GPR_PREPOSITION_HL)); + EmitCode::up(); + RTCommandGrammars::cg_compile_lines(&gprk, cg); + EmitCode::inv(RETURN_BIP); + EmitCode::down(); + EmitCode::val_iname(K_value, Hierarchy::find(GPR_FAIL_HL)); + EmitCode::up(); + Functions::end(save); + break; + } + case CG_IS_CONSULT: { + gpr_kit gprk = GPRs::new_kit(); + inter_name *iname = RTCommandGrammars::get_consult_fn_iname(cg); + packaging_state save = Functions::begin(iname); + GPRs::add_range_vars(&gprk); + GPRs::add_original_var(&gprk); + GPRs::add_standard_vars(&gprk); + EmitCode::inv(STORE_BIP); + EmitCode::down(); + EmitCode::ref_iname(K_value, Hierarchy::find(WN_HL)); + EmitCode::val_symbol(K_value, gprk.range_from_s); + EmitCode::up(); + EmitCode::inv(STORE_BIP); + EmitCode::down(); + EmitCode::ref_symbol(K_value, gprk.original_wn_s); + EmitCode::val_iname(K_value, Hierarchy::find(WN_HL)); + EmitCode::up(); + EmitCode::inv(STORE_BIP); + EmitCode::down(); + EmitCode::ref_symbol(K_value, gprk.rv_s); + EmitCode::val_iname(K_value, Hierarchy::find(GPR_PREPOSITION_HL)); + EmitCode::up(); + RTCommandGrammars::cg_compile_lines(&gprk, cg); + EmitCode::inv(RETURN_BIP); + EmitCode::down(); + EmitCode::val_iname(K_value, Hierarchy::find(GPR_FAIL_HL)); + EmitCode::up(); + Functions::end(save); + break; + } + case CG_IS_SUBJECT: + break; + case CG_IS_VALUE: + internal_error("iv"); + break; + case CG_IS_PROPERTY_NAME: { + gpr_kit gprk = GPRs::new_kit(); + inter_name *iname = RTCommandGrammars::get_property_GPR_fn_iname(cg); + packaging_state save = Functions::begin(iname); + GPRs::add_original_var(&gprk); + GPRs::add_standard_vars(&gprk); + EmitCode::inv(STORE_BIP); + EmitCode::down(); + EmitCode::ref_symbol(K_value, gprk.original_wn_s); + EmitCode::val_iname(K_value, Hierarchy::find(WN_HL)); + EmitCode::up(); + EmitCode::inv(STORE_BIP); + EmitCode::down(); + EmitCode::ref_symbol(K_value, gprk.rv_s); + EmitCode::val_iname(K_value, Hierarchy::find(GPR_PREPOSITION_HL)); + EmitCode::up(); + RTCommandGrammars::cg_compile_lines(&gprk, cg); + EmitCode::inv(RETURN_BIP); + EmitCode::down(); + EmitCode::val_iname(K_value, Hierarchy::find(GPR_FAIL_HL)); + EmitCode::up(); + Functions::end(save); + break; + } + } } @ Some tokens require suitable I6 routines to have already been compiled, @@ -236,122 +398,6 @@ void RTCommandGrammars::cg_compile_lines(gpr_kit *gprk, command_grammar *cg) { cg->cg_is, cg, CommandGrammars::cg_is_genuinely_verbal(cg)); /* And Phase IV here */ } -@ The following function unites, so far as possible, the different forms of -CG by compiling each of them as a sandwich: top slice, filling, bottom slice. - -The interesting case is of a CG representing names for an object: the -name-behaviour needs to be inherited from the object's kind, and so on up -the kinds hierarchy, but this is a case where I7's kind hierarchy does not -agree with I6's class hierarchy. I6 has no (nice) way to inherit |parse_name| -behaviour from a class to an instance. So we will simply pile up extra -fillings into the sandwich. The order of these is important: by getting -in first, grammar for the instance takes priority; its immediate kind has -next priority, and so on up the hierarchy. - -= -void RTCommandGrammars::compile(command_grammar *cg) { - if (CGLines::list_length(cg) == 0) return; - - LOGIF(GRAMMAR, "Compiling command grammar $G\n", cg); - - current_sentence = cg->where_cg_created; - - RTCommandGrammarLines::reset_labels(); - switch(cg->cg_is) { - case CG_IS_COMMAND: { - package_request *PR = Hierarchy::completion_package(COMMANDS_HAP); - inter_name *array_iname = Hierarchy::make_iname_in(VERB_DECLARATION_ARRAY_HL, PR); - packaging_state save = RTCommandGrammars::cg_compile_Verb_directive_header(cg, array_iname); - RTCommandGrammars::cg_compile_lines(NULL, cg); - EmitArrays::end(save); - break; - } - case CG_IS_TOKEN: { - gpr_kit gprk = GPRs::new_kit(); - if (cg->compilation_data.cg_token_iname == NULL) internal_error("cg token not ready"); - packaging_state save = Functions::begin(cg->compilation_data.cg_token_iname); - GPRs::add_original_var(&gprk); - GPRs::add_standard_vars(&gprk); - EmitCode::inv(STORE_BIP); - EmitCode::down(); - EmitCode::ref_symbol(K_value, gprk.original_wn_s); - EmitCode::val_iname(K_value, Hierarchy::find(WN_HL)); - EmitCode::up(); - EmitCode::inv(STORE_BIP); - EmitCode::down(); - EmitCode::ref_symbol(K_value, gprk.rv_s); - EmitCode::val_iname(K_value, Hierarchy::find(GPR_PREPOSITION_HL)); - EmitCode::up(); - RTCommandGrammars::cg_compile_lines(&gprk, cg); - EmitCode::inv(RETURN_BIP); - EmitCode::down(); - EmitCode::val_iname(K_value, Hierarchy::find(GPR_FAIL_HL)); - EmitCode::up(); - Functions::end(save); - break; - } - case CG_IS_CONSULT: { - gpr_kit gprk = GPRs::new_kit(); - inter_name *iname = RTCommandGrammars::consult_iname(cg); - packaging_state save = Functions::begin(iname); - GPRs::add_range_vars(&gprk); - GPRs::add_original_var(&gprk); - GPRs::add_standard_vars(&gprk); - EmitCode::inv(STORE_BIP); - EmitCode::down(); - EmitCode::ref_iname(K_value, Hierarchy::find(WN_HL)); - EmitCode::val_symbol(K_value, gprk.range_from_s); - EmitCode::up(); - EmitCode::inv(STORE_BIP); - EmitCode::down(); - EmitCode::ref_symbol(K_value, gprk.original_wn_s); - EmitCode::val_iname(K_value, Hierarchy::find(WN_HL)); - EmitCode::up(); - EmitCode::inv(STORE_BIP); - EmitCode::down(); - EmitCode::ref_symbol(K_value, gprk.rv_s); - EmitCode::val_iname(K_value, Hierarchy::find(GPR_PREPOSITION_HL)); - EmitCode::up(); - RTCommandGrammars::cg_compile_lines(&gprk, cg); - EmitCode::inv(RETURN_BIP); - EmitCode::down(); - EmitCode::val_iname(K_value, Hierarchy::find(GPR_FAIL_HL)); - EmitCode::up(); - Functions::end(save); - break; - } - case CG_IS_SUBJECT: - break; - case CG_IS_VALUE: - internal_error("iv"); - break; - case CG_IS_PROPERTY_NAME: { - gpr_kit gprk = GPRs::new_kit(); - if (cg->compilation_data.cg_prn_iname == NULL) internal_error("PRN PN not ready"); - packaging_state save = Functions::begin(cg->compilation_data.cg_prn_iname); - GPRs::add_original_var(&gprk); - GPRs::add_standard_vars(&gprk); - EmitCode::inv(STORE_BIP); - EmitCode::down(); - EmitCode::ref_symbol(K_value, gprk.original_wn_s); - EmitCode::val_iname(K_value, Hierarchy::find(WN_HL)); - EmitCode::up(); - EmitCode::inv(STORE_BIP); - EmitCode::down(); - EmitCode::ref_symbol(K_value, gprk.rv_s); - EmitCode::val_iname(K_value, Hierarchy::find(GPR_PREPOSITION_HL)); - EmitCode::up(); - RTCommandGrammars::cg_compile_lines(&gprk, cg); - EmitCode::inv(RETURN_BIP); - EmitCode::down(); - EmitCode::val_iname(K_value, Hierarchy::find(GPR_FAIL_HL)); - EmitCode::up(); - Functions::end(save); - break; - } - } -} - void RTCommandGrammars::compile_iv(gpr_kit *gprk, command_grammar *cg) { if (CGLines::list_length(cg) > 0) { LOGIF(GRAMMAR, "Compiling command grammar $G\n", cg); @@ -365,22 +411,3 @@ void RTCommandGrammars::compile_iv(gpr_kit *gprk, command_grammar *cg) { void RTCommandGrammars::emit_determination_type(determination_type *gty) { CompileValues::to_code_val(gty->term[0].what); } - -@ These are used to parse an explicit range of words (such as traditionally -found in the CONSULT command) at run time, and they are not I6 grammar -tokens, and do not appear in |Verb| declarations: otherwise, such -routines are very similar to GPRs. - -First, we need to look after a pointer to the CG used to hold the grammar -being matched against the snippet of words. - -= -inter_name *RTCommandGrammars::consult_iname(command_grammar *cg) { - if (cg == NULL) return NULL; - if (cg->compilation_data.cg_consult_iname == NULL) { - current_sentence = cg->where_cg_created; - package_request *PR = Hierarchy::local_package(CONSULT_TOKENS_HAP); - cg->compilation_data.cg_consult_iname = Hierarchy::make_iname_in(CONSULT_FN_HL, PR); - } - return cg->compilation_data.cg_consult_iname; -}